Published
Edited
Feb 28, 2022
Importers
Insert cell
# AuthData
Insert cell
Insert cell
Insert cell
Insert cell
reader = new BinaryReader(toArrayBuffer(AuthData))
Insert cell
Insert cell
Insert cell
Insert cell
offset = reader.readerOffset
Insert cell
length = reader.byteLength
Insert cell
rest = length-offset
Insert cell
PositiveInteger = 0;
Insert cell
NegativeInteger = 1;
Insert cell
ByteString = 2;
Insert cell
TextString = 3;
Insert cell
_Array = 4;
Insert cell
_Map = 5;
Insert cell
Insert cell
Insert cell
Insert cell
coseToJwk=(data)=> {
let alg, crv;
switch (data[1]) {
case 2: // EC
switch (data[3]) {
case -7: alg = "ES256"; break;
default: throw new Error("invalid argument");
}
switch (data[-1]) {
case 1: crv = "P-256"; break;
default: throw new Error("invalid argument");
}
if (!data[-2] || !data[-3]) throw new Error("invalid argument");
return {
"kty": "EC",
"alg": alg,
"crv": crv,
"x": encodeArray(data[-2]),
"y": encodeArray(data[-3]),
};
case 3: // RSA
switch (data[3]) {
case -37: alg = "PS256"; break;
case -257: alg = "RS256"; break;
default: throw new Error("invalid argument");
}
if (!data[-1] || !data[-2]) throw new Error("invalid argument");
return {
"kty": "RSA",
"alg": alg,
"n": encodeArray(data[-1]),
"e": encodeArray(data[-2]),
};
default: throw new Error("invalid argument");
}
}
Insert cell
function encodeArray(array) {
array = toUint8Array(array);
return btoaUrlSafe(Array.from(array, t => String.fromCharCode(t)).join(""));
}
Insert cell
function btoaUrlSafe(text) {
if (text == null) {
return null;
}
text = btoa(text)
.replace(/\+/g, "-") // replace '+' with '-'
.replace(/\//g, "_") // replace '/' with '_'
.replace(/=+$/, ""); // remove trailing padding characters
return text;
}
Insert cell
function toUint8Array(data) {
if (data instanceof Uint8Array) {
return data;
}
if (data instanceof ArrayBuffer) {
return new Uint8Array(data);
}
throw new Error("invalid argument");
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more