Skip to content

Commit

Permalink
feat: initEccLib skip verification
Browse files Browse the repository at this point in the history
  • Loading branch information
fboucquez committed Dec 2, 2024
1 parent 0c38a66 commit ea07097
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ecc_lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { TinySecp256k1Interface } from './types';
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
*
* @param eccLib The instance of the ECC library to initialize.
* @param skipVerification If the ecc verification should not be executed.
*/
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined): void;
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, skipVerification?: boolean): void;
/**
* Retrieves the ECC Library instance.
* Throws an error if the ECC Library is not provided.
Expand Down
8 changes: 5 additions & 3 deletions src/ecc_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ const _ECCLIB_CACHE = {};
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
*
* @param eccLib The instance of the ECC library to initialize.
* @param skipVerification If the ecc verification should not be executed.
*/
function initEccLib(eccLib) {
function initEccLib(eccLib, skipVerification) {
if (!eccLib) {
// allow clearing the library
_ECCLIB_CACHE.eccLib = eccLib;
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
// new instance, verify it
verifyEcc(eccLib);
if (!skipVerification)
// new instance, verify it
verifyEcc(eccLib);
_ECCLIB_CACHE.eccLib = eccLib;
}
}
Expand Down
11 changes: 8 additions & 3 deletions ts_src/ecc_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ const _ECCLIB_CACHE: { eccLib?: TinySecp256k1Interface } = {};
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
*
* @param eccLib The instance of the ECC library to initialize.
* @param skipVerification If the ecc verification should not be executed.
*/
export function initEccLib(eccLib: TinySecp256k1Interface | undefined): void {
export function initEccLib(
eccLib: TinySecp256k1Interface | undefined,
skipVerification?: boolean,
): void {
if (!eccLib) {
// allow clearing the library
_ECCLIB_CACHE.eccLib = eccLib;
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
// new instance, verify it
verifyEcc(eccLib!);
if (!skipVerification)
// new instance, verify it
verifyEcc(eccLib!);
_ECCLIB_CACHE.eccLib = eccLib;
}
}
Expand Down

0 comments on commit ea07097

Please sign in to comment.