Skip to content

Commit d90fb51

Browse files
authored
Merge pull request #2184 from fboucquez/fboucquez/feat/skipVerificationV6
feat: initEccLib skip verification (v6)
2 parents 0c38a66 + 00c3f59 commit d90fb51

File tree

7 files changed

+46
-10
lines changed

7 files changed

+46
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 6.1.7
2+
__added__
3+
- skip ecc library verification via DANGER_DO_NOT_VERIFY_ECCLIB flag
4+
15
# 6.1.6
26
__fixed__
37
- Fix sighash treatment when signing taproot script sign scripts using Psbt (#2104)

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitcoinjs-lib",
3-
"version": "6.1.6",
3+
"version": "6.1.7",
44
"description": "Client-side Bitcoin JavaScript library",
55
"main": "./src/index.js",
66
"types": "./src/index.d.ts",

src/ecc_lib.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +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 opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
89
*/
9-
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined): void;
10+
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, opts?: {
11+
DANGER_DO_NOT_VERIFY_ECCLIB: boolean;
12+
}): void;
1013
/**
1114
* Retrieves the ECC Library instance.
1215
* Throws an error if the ECC Library is not provided.

src/ecc_lib.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ 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 opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
1112
*/
12-
function initEccLib(eccLib) {
13+
function initEccLib(eccLib, opts) {
1314
if (!eccLib) {
1415
// allow clearing the library
1516
_ECCLIB_CACHE.eccLib = eccLib;
1617
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
17-
// new instance, verify it
18-
verifyEcc(eccLib);
18+
if (!opts?.DANGER_DO_NOT_VERIFY_ECCLIB)
19+
// new instance, verify it
20+
verifyEcc(eccLib);
1921
_ECCLIB_CACHE.eccLib = eccLib;
2022
}
2123
}

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: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ 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 opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
1112
*/
12-
export function initEccLib(eccLib: TinySecp256k1Interface | undefined): void {
13+
export function initEccLib(
14+
eccLib: TinySecp256k1Interface | undefined,
15+
opts?: { DANGER_DO_NOT_VERIFY_ECCLIB: boolean },
16+
): void {
1317
if (!eccLib) {
1418
// allow clearing the library
1519
_ECCLIB_CACHE.eccLib = eccLib;
1620
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
17-
// new instance, verify it
18-
verifyEcc(eccLib!);
21+
if (!opts?.DANGER_DO_NOT_VERIFY_ECCLIB)
22+
// new instance, verify it
23+
verifyEcc(eccLib!);
1924
_ECCLIB_CACHE.eccLib = eccLib;
2025
}
2126
}

0 commit comments

Comments
 (0)