Use bls-keygen to generate random private keys

This commit is contained in:
Gerald Nash 2020-01-15 15:55:26 -05:00
parent 645f88ffec
commit 4966e0beab
2 changed files with 4 additions and 4 deletions

View File

@ -38,6 +38,7 @@
"benchmark": "node -r ./.babel-register test/benchmarks" "benchmark": "node -r ./.babel-register test/benchmarks"
}, },
"dependencies": { "dependencies": {
"@chainsafe/bls-keygen": "^0.0.2",
"@chainsafe/eth2-bls-wasm": "^0.2.0", "@chainsafe/eth2-bls-wasm": "^0.2.0",
"@chainsafe/eth2.0-types": "^0.1.0", "@chainsafe/eth2.0-types": "^0.1.0",
"assert": "^1.4.1", "assert": "^1.4.1",

View File

@ -2,6 +2,7 @@ import {SECRET_KEY_LENGTH} from "./constants";
import assert from "assert"; import assert from "assert";
import {BLSSecretKey, Domain, Hash} from "@chainsafe/eth2.0-types"; import {BLSSecretKey, Domain, Hash} from "@chainsafe/eth2.0-types";
import {SecretKeyType} from "@chainsafe/eth2-bls-wasm"; import {SecretKeyType} from "@chainsafe/eth2-bls-wasm";
import {generateRandomSecretKey} from "@chainsafe/bls-keygen";
import {getContext} from "./context"; import {getContext} from "./context";
import {PublicKey} from "./publicKey"; import {PublicKey} from "./publicKey";
import {Signature} from "./signature"; import {Signature} from "./signature";
@ -38,10 +39,8 @@ export class PrivateKey {
} }
public static random(): PrivateKey { public static random(): PrivateKey {
const context = getContext(); const randomKey: Buffer = generateRandomSecretKey();
const secretKey = new context.SecretKey(); return this.fromBytes(randomKey);
secretKey.setByCSPRNG();
return new PrivateKey(secretKey);
} }
public getValue(): SecretKeyType { public getValue(): SecretKeyType {