Skip to content

Commit

Permalink
Enforce 32-byte private key length (2926).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Apr 29, 2022
1 parent 9bf17fa commit 7b299dd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/signing-key/src.ts/index.ts
Expand Up @@ -2,7 +2,7 @@

import { EC } from "./elliptic";

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

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

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

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

Expand Down

0 comments on commit 7b299dd

Please sign in to comment.