Skip to content

Commit

Permalink
feat: kadenaKeyPairsFromRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
javadkh2 committed Nov 10, 2023
1 parent 0346834 commit 8c8387b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/libs/hd-wallet/src/bip44/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './kadenaGenKeypairFromSeed';
export * from './kadenaGetPublic';
export * from './kadenaKeyPairsFromRandom';
export * from './mnemonic';
export * from './sign';
25 changes: 25 additions & 0 deletions packages/libs/hd-wallet/src/bip44/kadenaKeyPairsFromRandom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { randomBytes } from 'crypto';
import { deriveKeyPair } from './utils/sign';
/**
* Generates random key pairs without updating the internal state.
*
* @param {number} [count=1] - The number of key pairs to generate.
* @returns {{ publicKey: string; secretKey: string }[]} An array of generated key pairs.
*/
export function kadenaKeyPairsFromRandom(
count: number = 1,
): { publicKey: string; secretKey: string }[] {
const keyPairs: { publicKey: string; secretKey: string }[] = [];
for (let i = 0; i < count; i++) {
const randomSeedBuffer = randomBytes(32);
const derivationPath = `m'/44'/626'/${i}'/0'/0'`;
const pair = deriveKeyPair(randomSeedBuffer, derivationPath);

keyPairs.push({
publicKey: pair.publicKey,
secretKey: pair.privateKey,
});
}

return keyPairs;
}

0 comments on commit 8c8387b

Please sign in to comment.