Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function der2raw (derSignature: Uint8Array, { signatureCurve }: WebCryptoAlgorithmSuite): Uint8Array {
/* Precondition: Do not attempt to RAW format if the suite does not support signing. */
if (!signatureCurve) throw new Error('AlgorithmSuite does not support signing')
const _keyLengthBytes = keyLengthBytes[signatureCurve]
// A little more portable than Buffer.from, but not much
const { r, s } = ECDSASignature.decode(new asn.bignum.BN(derSignature).toArrayLike(Buffer), 'der')
const rLength = r.byteLength()
const sLength = r.byteLength()
return concatBuffers(
new Uint8Array(_keyLengthBytes - rLength),
r.toArrayLike(Uint8Array),
new Uint8Array(_keyLengthBytes - sLength),
s.toArrayLike(Uint8Array)
)
}
var asn = require('asn1.js')
var factor = require('./factor')
var one = new asn.bignum(1)
function urlize(base64) {
return base64.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '')
}
function hex2b64url(str) {
return urlize(Buffer.from(str, 'hex').toString('base64'))
}
function fromPEM(data) {
var text = data.toString().split(/(\r\n|\r|\n)+/g);
text = text.filter(function(line) {
return line.trim().length !== 0;
});
function string2bn(str) {
if (/^[0-9]+$/.test(str)) {
return new asn.bignum(str, 10)
}
return base64url2bn(str)
}
function string2bn(str) {
if (/^[0-9]+$/.test(str)) {
return new asn.bignum(str, 10)
}
return base64url2bn(str)
}
/**
* Package dependencies
*/
const asn = require('asn1.js')
//var factor = require('./factor')
const one = new asn.bignum(1)
const fs = require('fs')
/*
* Test Data
*/
const public_test = fs.readFileSync('./ecdsa_public.pem').toString("ascii")
const private_test = fs.readFileSync('./ecdsa_private.pem').toString("ascii")
function urlize(base64) {
return base64.replace(/\+/g, '-')
.replace(/\//g, '_')
.replace(/=/g, '')
}
function hex2b64url(str) {
return urlize(Buffer(str, 'hex').toString('base64'))
function base64url2bn(str) {
return new asn.bignum(Buffer(str, 'base64'))
}
function unmarshalPublicKey (curve, key) {
const byteLen = curveLengths[curve]
if (!key.slice(0, 1).equals(Buffer.from([4]))) {
throw new Error('Invalid key format')
}
const x = new BN(key.slice(1, byteLen + 1))
const y = new BN(key.slice(1 + byteLen))
return {
kty: 'EC',
crv: curve,
x: toBase64(x, byteLen),
y: toBase64(y, byteLen),
ext: true
}
}
function base64url2bn(str) {
return new asn.bignum(Buffer.from(str, 'base64'))
}