Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function generateECDSAKeyPairFromSeed(originSeed) {
//This method is here to replace the SecureRandom generator native to jsrasign with
//a seeded version. They both use prng random numbers.
//seed the prng random generator
var seededRandom = new SeedRandom(CryptoJS.SHA512(originSeed).toString());
//save the original random generator.
var oldNextBytes = jrsa.SecureRandom.prototype.nextBytes;
//create a new nextBytes function based on a SeedRandom method
var SeededRandomNextBytes = function(ba) {
var i;
for (i = 0; i < ba.length; i++) {
ba[i] = Math.floor(seededRandom() * 256); // make it bytes.
}
}
//Replace the random function
jrsa.SecureRandom.prototype.nextBytes = SeededRandomNextBytes;
var ecKeypair = jrsa.KEYUTIL.generateKeypair("EC", "secp256k1");
//just put back the old random function after generation.
jrsa.SecureRandom.prototype.nextBytes = oldNextBytes;
//create a new nextBytes function based on a SeedRandom method
var SeededRandomNextBytes = function(ba) {
var i;
for (i = 0; i < ba.length; i++) {
ba[i] = Math.floor(seededRandom() * 256); // make it bytes.
}
}
//Replace the random function
jrsa.SecureRandom.prototype.nextBytes = SeededRandomNextBytes;
var ecKeypair = jrsa.KEYUTIL.generateKeypair("EC", "secp256k1");
//just put back the old random function after generation.
jrsa.SecureRandom.prototype.nextBytes = oldNextBytes;
// debugger;
// var jwkPrivate = jrsa.KEYUTIL.getJWKFromKey(ecKeypair.prvKeyObj);
// var jwkPublic = jrsa.KEYUTIL.getJWKFromKey(ecKeypair.prvKeyObj);
// debugger;
return {
privateKey: jrsa.KEYUTIL.getPEM(ecKeypair.prvKeyObj, "PKCS8PRV"),
publicKey: jrsa.KEYUTIL.getPEM(ecKeypair.pubKeyObj)
};;
}