Skip to content

Commit 7b299dd

Browse files
committedApr 29, 2022
Enforce 32-byte private key length (2926).

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎packages/signing-key/src.ts/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { EC } from "./elliptic";
44

5-
import { arrayify, BytesLike, hexlify, hexZeroPad, Signature, SignatureLike, splitSignature } from "@ethersproject/bytes";
5+
import { arrayify, BytesLike, hexDataLength, hexlify, hexZeroPad, Signature, SignatureLike, splitSignature } from "@ethersproject/bytes";
66
import { defineReadOnly } from "@ethersproject/properties";
77

88
import { Logger } from "@ethersproject/logger";
@@ -33,6 +33,9 @@ export class SigningKey {
3333
defineReadOnly(this, "curve", "secp256k1");
3434

3535
defineReadOnly(this, "privateKey", hexlify(privateKey));
36+
if (hexDataLength(this.privateKey) !== 32) {
37+
logger.throwArgumentError("invalid private key", "privateKey", "[[ REDACTED ]]");
38+
}
3639

3740
const keyPair = getCurve().keyFromPrivate(arrayify(this.privateKey));
3841

0 commit comments

Comments
 (0)
Please sign in to comment.