Skip to content

Commit 53dd7ca

Browse files
committed
feedback fix, added tests
1 parent ea07097 commit 53dd7ca

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

src/ecc_lib.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { TinySecp256k1Interface } from './types';
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.
8+
* @param skipVerification Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
99
*/
10-
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, skipVerification?: boolean): void;
10+
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, skipVerification?: {
11+
DANGER_DO_NOT_VERIFY_ECCLIB: boolean;
12+
}): void;
1113
/**
1214
* Retrieves the ECC Library instance.
1315
* Throws an error if the ECC Library is not provided.

src/ecc_lib.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const _ECCLIB_CACHE = {};
88
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
99
*
1010
* @param eccLib The instance of the ECC library to initialize.
11-
* @param skipVerification If the ecc verification should not be executed.
11+
* @param skipVerification Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
1212
*/
1313
function initEccLib(eccLib, skipVerification) {
1414
if (!eccLib) {
1515
// allow clearing the library
1616
_ECCLIB_CACHE.eccLib = eccLib;
1717
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
18-
if (!skipVerification)
18+
if (!skipVerification?.DANGER_DO_NOT_VERIFY_ECCLIB)
1919
// new instance, verify it
2020
verifyEcc(eccLib);
2121
_ECCLIB_CACHE.eccLib = eccLib;

test/ecc_lib.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { initEccLib } from '../src';
2+
import { describe, test } from 'mocha';
3+
import * as assert from 'assert';
4+
5+
describe(`initEccLib`, () => {
6+
beforeEach(() => {
7+
initEccLib(undefined);
8+
});
9+
10+
test('initEccLib should fail when invalid', () => {
11+
assert.throws(() => {
12+
initEccLib({ isXOnlyPoint: () => false } as any);
13+
}, 'Error: ecc library invalid');
14+
});
15+
16+
test('initEccLib should not fail when DANGER_DO_NOT_VERIFY_ECCLIB = true', () => {
17+
initEccLib({ isXOnlyPoint: () => false } as any, {
18+
DANGER_DO_NOT_VERIFY_ECCLIB: true,
19+
});
20+
assert.ok('it does not fail, verification is excluded');
21+
});
22+
});

ts_src/ecc_lib.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const _ECCLIB_CACHE: { eccLib?: TinySecp256k1Interface } = {};
88
* If `eccLib` is a new instance, it will be verified before setting it as the active library.
99
*
1010
* @param eccLib The instance of the ECC library to initialize.
11-
* @param skipVerification If the ecc verification should not be executed.
11+
* @param skipVerification Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
1212
*/
1313
export function initEccLib(
1414
eccLib: TinySecp256k1Interface | undefined,
15-
skipVerification?: boolean,
15+
skipVerification?: { DANGER_DO_NOT_VERIFY_ECCLIB: boolean },
1616
): void {
1717
if (!eccLib) {
1818
// allow clearing the library
1919
_ECCLIB_CACHE.eccLib = eccLib;
2020
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
21-
if (!skipVerification)
21+
if (!skipVerification?.DANGER_DO_NOT_VERIFY_ECCLIB)
2222
// new instance, verify it
2323
verifyEcc(eccLib!);
2424
_ECCLIB_CACHE.eccLib = eccLib;

0 commit comments

Comments
 (0)