INNER CODE UNIT · JavaScript
parseSignature
mylofi/webauthn-local-client · src/walc.js:731
function parseSignature(algoCOSE,signature) {
if (isPublicKeyAlgorithm("ES256",algoCOSE)) {
// this algorithm's signature comes back ASN.1 encoded, per spec:
// https://www.w3.org/TR/webauthn-2/#sctn-signature-attestation-types
let der = ASN1.parseVerbose(signature);
return new Uint8Array([ ...der.children[0].value, ...der.children[1].value, ]);
}
// also per spec, other signature algorithms SHOULD NOT come back
// in ASN.1, so for those, we just pass through without any parsing
return signature;
}
function byteArrayTo32Int(byteArray) {
// not enough bytes for 32-bit integer?
if (byteArray.byteLength < 4) {
// zero-pad byte(s) at start of array
let tmp = new Uint8Array(4);
tmp.set(byteArray,4 - byteArray.byteLength);