Skip to content

Commit

Permalink
feedback fixes from v6
Browse files Browse the repository at this point in the history
  • Loading branch information
fboucquez committed Dec 3, 2024
1 parent 14e066c commit 628a2d7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.1.7
__added__
- skip ecc library verification via DANGER_DO_NOT_VERIFY_ECCLIB flag

# 6.1.6
__fixed__
- Fix sighash treatment when signing taproot script sign scripts using Psbt (#2104)
Expand Down
6 changes: 3 additions & 3 deletions src/cjs/ecc_lib.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ 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.
* @param opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
*/
function initEccLib(eccLib, skipVerification) {
function initEccLib(eccLib, opts) {
if (!eccLib) {
// allow clearing the library
_ECCLIB_CACHE.eccLib = eccLib;
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
if (!skipVerification)
if (!opts?.DANGER_DO_NOT_VERIFY_ECCLIB)
// new instance, verify it
verifyEcc(eccLib);
_ECCLIB_CACHE.eccLib = eccLib;
Expand Down
6 changes: 4 additions & 2 deletions src/cjs/ecc_lib.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import { TinySecp256k1Interface } from './types.js';
* 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.
* @param opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
*/
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, skipVerification?: boolean): void;
export declare function initEccLib(eccLib: TinySecp256k1Interface | undefined, opts?: {
DANGER_DO_NOT_VERIFY_ECCLIB: boolean;
}): void;
/**
* Retrieves the ECC Library instance.
* Throws an error if the ECC Library is not provided.
Expand Down
6 changes: 3 additions & 3 deletions src/esm/ecc_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ 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.
* @param opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
*/
export function initEccLib(eccLib, skipVerification) {
export function initEccLib(eccLib, opts) {
if (!eccLib) {
// allow clearing the library
_ECCLIB_CACHE.eccLib = eccLib;
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
if (!skipVerification)
if (!opts?.DANGER_DO_NOT_VERIFY_ECCLIB)
// new instance, verify it
verifyEcc(eccLib);
_ECCLIB_CACHE.eccLib = eccLib;
Expand Down
22 changes: 22 additions & 0 deletions test/ecc_lib.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { initEccLib } from 'bitcoinjs-lib';
import { describe, test } from 'mocha';
import * as assert from 'assert';

describe(`initEccLib`, () => {
beforeEach(() => {
initEccLib(undefined);
});

test('initEccLib should fail when invalid', () => {
assert.throws(() => {
initEccLib({ isXOnlyPoint: () => false } as any);
}, 'Error: ecc library invalid');
});

test('initEccLib should not fail when DANGER_DO_NOT_VERIFY_ECCLIB = true', () => {
initEccLib({ isXOnlyPoint: () => false } as any, {
DANGER_DO_NOT_VERIFY_ECCLIB: true,
});
assert.ok('it does not fail, verification is excluded');
});
});
6 changes: 3 additions & 3 deletions ts_src/ecc_lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ 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.
* @param opts Extra initialization options. Use {DANGER_DO_NOT_VERIFY_ECCLIB:true} if ecc verification should not be executed. Not recommended!
*/
export function initEccLib(
eccLib: TinySecp256k1Interface | undefined,
skipVerification?: boolean,
opts?: { DANGER_DO_NOT_VERIFY_ECCLIB: boolean },
): void {
if (!eccLib) {
// allow clearing the library
_ECCLIB_CACHE.eccLib = eccLib;
} else if (eccLib !== _ECCLIB_CACHE.eccLib) {
if (!skipVerification)
if (!opts?.DANGER_DO_NOT_VERIFY_ECCLIB)
// new instance, verify it
verifyEcc(eccLib!);
_ECCLIB_CACHE.eccLib = eccLib;
Expand Down

0 comments on commit 628a2d7

Please sign in to comment.