Skip to content

Commit af1f2d7

Browse files
committed
feat: initEccLib skip verification
1 parent 32e08aa commit af1f2d7

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

src/cjs/ecc_lib.cjs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,16 @@ const _ECCLIB_CACHE = {};
5454
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
5555
*
5656
* @param eccLib The instance of the ECC library to initialize.
57+
* @param skipVerification If the ecc verification should not be executed
5758
*/
58-
function initEccLib(eccLib) {
59+
function initEccLib(eccLib, skipVerification) {
5960
if (!eccLib) {
6061
// allow clearing the library
6162
_ECCLIB_CACHE.eccLib = eccLib;
6263
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
63-
// new instance, verify it
64-
verifyEcc(eccLib);
64+
if (!skipVerification)
65+
// new instance, verify it
66+
verifyEcc(eccLib);
6567
_ECCLIB_CACHE.eccLib = eccLib;
6668
}
6769
}

src/cjs/ecc_lib.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import { TinySecp256k1Interface } from './types.js';
55
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
66
*
77
* @param eccLib The instance of the ECC library to initialize.
8+
* @param skipVerification If the ecc verification should not be executed
89
*/
9-
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined): void;
10+
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, skipVerification?: boolean): void;
1011
/**
1112
* Retrieves the ECC Library instance.
1213
* Throws an error if the ECC Library is not provided.

src/esm/ecc_lib.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@ const _ECCLIB_CACHE = {};
66
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
77
*
88
* @param eccLib The instance of the ECC library to initialize.
9+
* @param skipVerification If the ecc verification should not be executed
910
*/
10-
export function initEccLib(eccLib) {
11+
export function initEccLib(eccLib, skipVerification) {
1112
if (!eccLib) {
1213
// allow clearing the library
1314
_ECCLIB_CACHE.eccLib = eccLib;
1415
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
15-
// new instance, verify it
16-
verifyEcc(eccLib);
16+
if (!skipVerification)
17+
// new instance, verify it
18+
verifyEcc(eccLib);
1719
_ECCLIB_CACHE.eccLib = eccLib;
1820
}
1921
}

ts_src/ecc_lib.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,19 @@ const _ECCLIB_CACHE: { eccLib?: TinySecp256k1Interface } = {};
99
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
1010
*
1111
* @param eccLib The instance of the ECC library to initialize.
12+
* @param skipVerification If the ecc verification should not be executed
1213
*/
13-
export function initEccLib(eccLib: TinySecp256k1Interface | undefined): void {
14+
export function initEccLib(
15+
eccLib: TinySecp256k1Interface | undefined,
16+
skipVerification?: boolean,
17+
): void {
1418
if (!eccLib) {
1519
// allow clearing the library
1620
_ECCLIB_CACHE.eccLib = eccLib;
1721
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
18-
// new instance, verify it
19-
verifyEcc(eccLib!);
22+
if (!skipVerification)
23+
// new instance, verify it
24+
verifyEcc(eccLib!);
2025
_ECCLIB_CACHE.eccLib = eccLib;
2126
}
2227
}

0 commit comments

Comments
 (0)