Skip to content

Commit a54c549

Browse files
perf: Tweak precompute window size for secp256k1
1 parent 9b89a7e commit a54c549

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/curves/secp256k1.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,28 @@ export const isValidPrivateKey = (privateKey: Uint8Array): boolean => {
1919
return secp256k1.utils.isValidPrivateKey(privateKey);
2020
};
2121

22-
export const getPublicKey = (
22+
const getGetPublicKey = (): ((
2323
privateKey: Uint8Array,
24-
compressed = false,
25-
): Uint8Array => secp256k1.getPublicKey(privateKey, compressed);
24+
compressed?: boolean,
25+
) => Uint8Array) => {
26+
let hasSetWindowSize = false;
27+
28+
const getPublicKey = (
29+
privateKey: Uint8Array,
30+
compressed = false,
31+
): Uint8Array => {
32+
if (!hasSetWindowSize) {
33+
secp256k1.ProjectivePoint.BASE._setWindowSize(4);
34+
hasSetWindowSize = true;
35+
}
36+
return secp256k1.getPublicKey(privateKey, compressed);
37+
};
38+
39+
return getPublicKey;
40+
};
41+
42+
43+
export const getPublicKey = getGetPublicKey();
2644

2745
export const publicAdd = (
2846
publicKey: Uint8Array,

0 commit comments

Comments
 (0)