Skip to content

Commit

Permalink
fix(RREL-013): create random seed using randomBytes rather than the p…
Browse files Browse the repository at this point in the history
…rivate key of a random wallet (#115)
  • Loading branch information
antomor authored Jul 24, 2023
1 parent c7483ce commit 51d682c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"register": "ts-node src/commands/Register.ts",
"start": "ts-node src/commands/Start.ts",
"tdd": "npm run test -- --watch --watch-files src,test",
"test": "ALLOW_CONFIG_MUTATIONS=true npx mocha -r ts-node/register --extensions ts 'test/**/*.{test,spec}.ts'"
"test": "ALLOW_CONFIG_MUTATIONS=true npx mocha -r ts-node/register --extensions ts 'test/**/*.{test,spec}.ts'"
},
"lint-staged": {
"*": "npx embedme \"*.md\"",
Expand Down
10 changes: 7 additions & 3 deletions src/KeyManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class KeyManager {
) as keystore;
genseed = seedObject.seed;
} else {
genseed = Wallet.createRandom().privateKey;
genseed = this.generateRandomSeed();
fs.writeFileSync(keyStorePath, JSON.stringify({ seed: genseed }), {
flag: 'w',
});
Expand All @@ -56,15 +56,19 @@ export class KeyManager {
} else {
// no workdir: working in-memory
if (seed == null) {
seed = Wallet.createRandom().privateKey;
seed = this.generateRandomSeed();
}
this._hdkey = utils.HDNode.fromSeed(seed ?? Buffer.from(''));
}

this.generateKeys(count);
}

generateKeys(count: number): void {
private generateRandomSeed() {
return Buffer.from(utils.randomBytes(16).buffer).toString('hex');
}

private generateKeys(count: number): void {
this._privateKeys = {};
this._nonces = {};
for (let index = 0; index < count; index++) {
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"extends": "./tsconfig.json",
"exclude": [
"test"
]
]
}

0 comments on commit 51d682c

Please sign in to comment.