Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function keyPair(seed) {
const key = sign.keyPair.fromSeed(seed);
// TODO const toString = () => ``;
const signBytes = bytes => sign.detached(bytes, key.secretKey);
return def({
// TODO toString,
signBytes,
signBytesHex: bytes => b2h(signBytes(bytes)),
signText: text => signBytes(t2b(text)),
signTextHex: text => b2h(signBytes(t2b(text))),
publicKey: () => b2h(key.publicKey),
// TODO label: () => state.label,
// TODO [inspect.custom]: toString
});
}
function init(label) {
const key = sign.keyPair.fromSeed(randomBytes(32));
state = context.state;
state.label = label;
state.publicKey = b2h(key.publicKey);
state.secretKey = b2h(key.secretKey);
}
function privateKey() {
return sign.keyPair.fromSecretKey(h2b(state.secretKey)).secretKey;
}
}
getPublicKey(sk, encoding = 'hex') {
const skBytes = toUint8Array(sk);
const pk = ed25519.keyPair.fromSecretKey(skBytes).publicKey;
return encode(pk, encoding);
}
throw new Error('Cannot read X.509 private key: ' + err.message)
}
this.version = ASN1.parseIntegerNum(captures.privateKeyVersion.bytes) + 1
this.oid = ASN1.parseOID(captures.privateKeyOID.bytes)
this.algo = getOIDName(this.oid)
this._pkcs8 = obj
this._keyRaw = captures.privateKey.bytes
this._publicKeyRaw = null
this._finalKey = this._keyRaw
this._finalPEM = ''
if (EdDSAPrivateKeyOIDs.includes(this.oid)) {
this._finalKey = this._keyRaw = ASN1.parseDER(this._keyRaw, Class.UNIVERSAL, Tag.OCTETSTRING).bytes
if (this.oid === '1.3.101.112') {
const keypair = ed25519.keyPair.fromSeed(this._keyRaw)
this._publicKeyRaw = Buffer.from(keypair.publicKey)
this._finalKey = Buffer.from(keypair.secretKey)
} else if (this.version === 2) {
for (const val of obj.mustCompound()) {
if (val.class === Class.CONTEXT_SPECIFIC && val.tag === 1) {
this._publicKeyRaw = ASN1.parseBitString(val.bytes).buf
this._finalKey = Buffer.concat([this._keyRaw, this._publicKeyRaw as Buffer])
}
}
}
}
}