Skip to content

Commit 18c1c5f

Browse files
fix(utxo-lib): update assert imports for Node 22
Replace "*" imports with specific imports from assert module. When upgrading the test runner from ts-node to tsx, we need to fix imports to be strictly ESM to avoid: "TypeError: assert is not a function" TICKET: WP-5599 TICKET: WP-5599
1 parent ea180b4 commit 18c1c5f

File tree

24 files changed

+47
-47
lines changed

24 files changed

+47
-47
lines changed

modules/utxo-lib/src/bitgo/UtxoPsbt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { ok as assert } from 'assert';
22
import { Psbt as PsbtBase } from 'bip174';
33
import {
44
Bip32Derivation,

modules/utxo-lib/src/bitgo/UtxoTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { ok as assert } from 'assert';
22
import * as bitcoinjs from 'bitcoinjs-lib';
33
import * as varuint from 'varuint-bitcoin';
44
import { toTNumber } from './tnumber';

modules/utxo-lib/src/bitgo/legacysafe/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ export function createLegacySafeOutputScript2of3(
5858
});
5959

6060
const script2of3 = bitcoinjs.payments.p2ms({ m: 2, pubkeys });
61-
assert(script2of3.output);
61+
assert.ok(script2of3.output);
6262

6363
const scriptPubKey = bitcoinjs.payments.p2sh({ redeem: script2of3 });
64-
assert(scriptPubKey);
65-
assert(scriptPubKey.output);
64+
assert.ok(scriptPubKey);
65+
assert.ok(scriptPubKey.output);
6666

6767
return {
6868
scriptPubKey: scriptPubKey.output,

modules/utxo-lib/src/bitgo/nonStandardHalfSigned.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { ok as assert } from 'assert';
22
import * as opcodes from 'bitcoin-ops';
33
import { classify, script as bscript, TxInput } from '../';
44

modules/utxo-lib/src/bitgo/outputScripts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { ok as assert } from 'assert';
22
import * as bitcoinjs from 'bitcoinjs-lib';
33

44
import { Network, supportsSegwit, supportsTaproot } from '../networks';

modules/utxo-lib/src/bitgo/wallet/Psbt.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ export function isPsbtInputArray(inputs: PsbtInput[] | TxInput[]): inputs is Psb
463463
* @return true iff inputs array is of TxInput type
464464
* */
465465
export function isTxInputArray(inputs: PsbtInput[] | TxInput[]): inputs is TxInput[] {
466-
assert(!!inputs.length, 'empty inputs array');
466+
assert.ok(!!inputs.length, 'empty inputs array');
467467
return 'hash' in inputs[0];
468468
}
469469

@@ -532,7 +532,7 @@ export function getSignatureValidationArrayPsbt(psbt: UtxoPsbt, rootWalletKeys:
532532
* The purpose is to provide backward compatibility to keyternal (KRS) that only supports network transaction and p2ms script types.
533533
*/
534534
export function extractP2msOnlyHalfSignedTx(psbt: UtxoPsbt): UtxoTransaction<bigint> {
535-
assert(!!(psbt.data.inputs.length && psbt.data.outputs.length), 'empty inputs or outputs');
535+
assert.ok(!!(psbt.data.inputs.length && psbt.data.outputs.length), 'empty inputs or outputs');
536536
const tx = psbt.getUnsignedTx();
537537

538538
function isP2msParsedPsbtInput(
@@ -543,10 +543,10 @@ export function extractP2msOnlyHalfSignedTx(psbt: UtxoPsbt): UtxoTransaction<big
543543

544544
psbt.data.inputs.forEach((input, i) => {
545545
const parsed = parsePsbtInput(input);
546-
assert(isP2msParsedPsbtInput(parsed), `unsupported script type ${parsed.scriptType}`);
547-
assert(input.partialSig?.length === 1, `unexpected signature count ${input.partialSig?.length}`);
546+
assert.ok(isP2msParsedPsbtInput(parsed), `unsupported script type ${parsed.scriptType}`);
547+
assert.ok(input.partialSig?.length === 1, `unexpected signature count ${input.partialSig?.length}`);
548548
const [partialSig] = input.partialSig;
549-
assert(
549+
assert.ok(
550550
input.sighashType !== undefined && input.sighashType === bscript.signature.decode(partialSig.signature).hashType,
551551
'signature sighash does not match input sighash type'
552552
);

modules/utxo-lib/src/bitgo/wallet/WalletOutput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { ok as assert } from 'assert';
22

33
import { Payment, taproot } from 'bitcoinjs-lib';
44
import { PsbtOutput, PsbtOutputUpdate } from 'bip174/src/lib/interfaces';

modules/utxo-lib/src/bitgo/wallet/psbt/RootNodes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Contains helper methods for getting and sorting root nodes from a PSBT.
33
*/
44

5-
import * as assert from 'assert';
5+
import { ok as assert } from 'assert';
66
import * as bs58check from 'bs58check';
77

88
import { UtxoPsbt } from '../../UtxoPsbt';

modules/utxo-lib/src/noble_ecc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import * as createHash from 'create-hash';
2-
import * as createHmac from 'create-hmac';
31
import { ECPairAPI, ECPairFactory, ECPairInterface } from 'ecpair';
42
import * as necc from '@noble/secp256k1';
53
import { BIP32API, BIP32Factory, BIP32Interface } from 'bip32';
64
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
75
// @ts-ignore base_crypto is exported as a subPath export, ignoring since compiler complains about importing like this
86
import * as baseCrypto from '@brandonblack/musig/base_crypto';
97
import { MuSig, MuSigFactory } from '@brandonblack/musig';
8+
const createHmac = require('create-hmac');
9+
const createHash = require('create-hash');
1010

1111
necc.utils.sha256Sync = (...messages: Uint8Array[]): Uint8Array => {
1212
const sha256 = createHash('sha256');

modules/utxo-lib/src/testutil/mock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as assert from 'assert';
1+
import { ok as assert } from 'assert';
22
import { BIP32Interface } from 'bip32';
33
import * as noble from '@noble/secp256k1';
44
import * as utxolib from '..';

0 commit comments

Comments
 (0)