Skip to content

Commit e3e70b7

Browse files
Merge pull request #8633 from BitGo/BTC-0.bump-wasm-utxo-4.7.0
feat(abstract-utxo): bump wasm-utxo
2 parents e205066 + d09ec7a commit e3e70b7

10 files changed

Lines changed: 50 additions & 18 deletions

File tree

modules/abstract-utxo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@bitgo/utxo-core": "^1.36.0",
6767
"@bitgo/utxo-lib": "^11.22.0",
6868
"@bitgo/utxo-ord": "^1.29.0",
69-
"@bitgo/wasm-utxo": "^4.1.0",
69+
"@bitgo/wasm-utxo": "^4.7.0",
7070
"@types/lodash": "^4.14.121",
7171
"@types/superagent": "4.1.15",
7272
"bignumber.js": "^9.0.2",

modules/abstract-utxo/src/transaction/fixedScript/signLegacyTransaction.ts

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,20 @@ import { BIP32, bip32 } from '@bitgo/wasm-utxo';
77
import debugLib from 'debug';
88

99
import { UtxoCoinName } from '../../names';
10-
import type { Unspent, WalletUnspent } from '../../unspent';
10+
import { isWalletUnspent, type Unspent } from '../../unspent';
1111
import { toUtxolibBIP32 } from '../../wasmUtil';
1212

1313
import { getReplayProtectionAddresses } from './replayProtection';
1414
import { InputSigningError, TransactionSigningError } from './SigningError';
1515

1616
const debug = debugLib('bitgo:v2:utxo');
1717

18-
const { isWalletUnspent, signInputWithUnspent, toOutput } = utxolib.bitgo;
18+
const { signInputWithUnspent, toOutput } = utxolib.bitgo;
1919

2020
type RootWalletKeys = utxolib.bitgo.RootWalletKeys;
2121

22+
const UTXOLIB_VALID_CHAIN_CODES = new Set([0, 1, 10, 11, 20, 21, 30, 31, 40, 41] as const);
23+
2224
/**
2325
* Sign all inputs of a wallet transaction and verify signatures after signing.
2426
* Collects and logs signing errors and verification errors, throws error in the end if any of them
@@ -71,8 +73,21 @@ export function signAndVerifyWalletTransaction<TNumber extends number | bigint>(
7173
if (!isWalletUnspent<TNumber>(unspent)) {
7274
return InputSigningError.expectedWalletUnspent<TNumber>(inputIndex, null, unspent);
7375
}
76+
if (!UTXOLIB_VALID_CHAIN_CODES.has(unspent.chain as utxolib.bitgo.ChainCode)) {
77+
return new InputSigningError<TNumber>(
78+
inputIndex,
79+
null,
80+
unspent,
81+
new Error(`Chain code ${unspent.chain} is not supported for legacy signing`)
82+
);
83+
}
7484
try {
75-
signInputWithUnspent<TNumber>(txBuilder, inputIndex, unspent as WalletUnspent<TNumber>, walletSigner);
85+
signInputWithUnspent<TNumber>(
86+
txBuilder,
87+
inputIndex,
88+
unspent as unknown as utxolib.bitgo.WalletUnspent<TNumber>,
89+
walletSigner
90+
);
7691
debug('Successfully signed input %d of %d', inputIndex + 1, unspents.length);
7792
} catch (e) {
7893
return new InputSigningError<TNumber>(inputIndex, null, unspent, e);
@@ -96,10 +111,20 @@ export function signAndVerifyWalletTransaction<TNumber extends number | bigint>(
96111
if (!isWalletUnspent<TNumber>(unspent)) {
97112
return InputSigningError.expectedWalletUnspent<TNumber>(inputIndex, null, unspent);
98113
}
99-
const walletUnspent = unspent as WalletUnspent<TNumber>;
114+
if (!UTXOLIB_VALID_CHAIN_CODES.has(unspent.chain as utxolib.bitgo.ChainCode)) {
115+
return new InputSigningError<TNumber>(
116+
inputIndex,
117+
null,
118+
unspent,
119+
new Error(`Chain code ${unspent.chain} is not supported for legacy verification`)
120+
);
121+
}
122+
const walletUnspent = unspent;
100123
try {
101-
const publicKey = walletSigner.deriveForChainAndIndex(walletUnspent.chain, walletUnspent.index).signer
102-
.publicKey;
124+
const publicKey = walletSigner.deriveForChainAndIndex(
125+
walletUnspent.chain as utxolib.bitgo.ChainCode,
126+
walletUnspent.index
127+
).signer.publicKey;
103128
if (
104129
!utxolib.bitgo.verifySignatureWithPublicKey<TNumber>(signedTransaction, inputIndex, prevOutputs, publicKey)
105130
) {

modules/abstract-utxo/src/unspent.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { fixedScriptWallet } from '@bitgo/wasm-utxo';
22

3+
/**
4+
* Type guard to check if an Unspent is a WalletUnspent
5+
*/
6+
export function isWalletUnspent<T extends number | bigint>(u: Unspent<T>): u is WalletUnspent<T> {
7+
return 'chain' in u && 'index' in u && fixedScriptWallet.ChainCode.is((u as WalletUnspent<T>).chain);
8+
}
9+
310
/**
411
* Unspent transaction output (UTXO) type definition
512
*

modules/abstract-utxo/test/unit/util/transaction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as utxolib from '@bitgo/utxo-lib';
44
import { ECPair, fixedScriptWallet, hasPsbtMagic, address as wasmAddress } from '@bitgo/wasm-utxo';
55

66
import type { UtxoCoinName } from '../../../src/names';
7-
import type { Unspent, WalletUnspent } from '../../../src/unspent';
7+
import type { Unspent } from '../../../src/unspent';
88

99
import { getCoinNameForNetwork } from './utxoCoins';
1010
const { isWalletUnspent, signInputWithUnspent } = utxolib.bitgo;
@@ -123,7 +123,7 @@ function createTransactionBuilderWithSignedInputs<TNumber extends number | bigin
123123
);
124124
unspents.forEach((u, inputIndex) => {
125125
if (isWalletUnspent<TNumber>(u)) {
126-
signInputWithUnspent<TNumber>(txBuilder, inputIndex, u as WalletUnspent<TNumber>, signer);
126+
signInputWithUnspent<TNumber>(txBuilder, inputIndex, u, signer);
127127
}
128128
});
129129
return txBuilder;

modules/utxo-bin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"@bitgo/unspents": "^0.51.3",
3232
"@bitgo/utxo-core": "^1.36.0",
3333
"@bitgo/utxo-lib": "^11.22.0",
34-
"@bitgo/wasm-utxo": "^4.1.0",
34+
"@bitgo/wasm-utxo": "^4.7.0",
3535
"@noble/curves": "1.8.1",
3636
"archy": "^1.0.0",
3737
"bech32": "^2.0.0",

modules/utxo-core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@bitgo/secp256k1": "^1.11.0",
8282
"@bitgo/unspents": "^0.51.3",
8383
"@bitgo/utxo-lib": "^11.22.0",
84-
"@bitgo/wasm-utxo": "^4.1.0",
84+
"@bitgo/wasm-utxo": "^4.7.0",
8585
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
8686
"fast-sha256": "^1.3.0"
8787
},

modules/utxo-ord/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"directory": "modules/utxo-ord"
4646
},
4747
"dependencies": {
48-
"@bitgo/wasm-utxo": "^4.1.0"
48+
"@bitgo/wasm-utxo": "^4.7.0"
4949
},
5050
"devDependencies": {
5151
"@bitgo/utxo-lib": "^11.22.0"

modules/utxo-staking/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"@bitgo/babylonlabs-io-btc-staking-ts": "^3.5.0",
6464
"@bitgo/utxo-core": "^1.36.0",
6565
"@bitgo/utxo-lib": "^11.22.0",
66-
"@bitgo/wasm-utxo": "^4.1.0",
66+
"@bitgo/wasm-utxo": "^4.7.0",
6767
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
6868
"bip322-js": "^2.0.0",
6969
"bitcoinjs-lib": "^6.1.7",

modules/utxo-staking/test/unit/babylon/bug71.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('btc-staking-ts bug #71', function () {
3434
const psbt = wasmMiniscript.Psbt.deserialize(buf);
3535
assert.throws(() => {
3636
psbt.finalize();
37-
}, /CouldNotSatisfyTr/);
37+
}, /Could not satisfy Tr descriptor/);
3838
});
3939

4040
it('cannot finalize with bitcoind', async function (this: Mocha.Context) {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,10 @@
10301030
resolved "https://registry.npmjs.org/@bitgo/wasm-ton/-/wasm-ton-1.1.1.tgz"
10311031
integrity sha512-Y4x2V2ZcYWlmx42v7dlrKDtT2DuUt8smk8E98mh7RhpiifJhLk2v5RmXDwBl0A3v9TzUOU6qMOnSS/iZ8Pq52w==
10321032

1033-
"@bitgo/wasm-utxo@^4.1.0":
1034-
version "4.1.0"
1035-
resolved "https://registry.npmjs.org/@bitgo/wasm-utxo/-/wasm-utxo-4.1.0.tgz"
1036-
integrity sha512-J6tKdfhJggt8LHKSh+KScz6/Q6VcX59D/1ycbUw/w+zWVOSKt+Z2+FFbYTJIVatxc4gA2bGqvHftC9dSbZBAwA==
1033+
"@bitgo/wasm-utxo@^4.7.0":
1034+
version "4.7.0"
1035+
resolved "https://registry.npmjs.org/@bitgo/wasm-utxo/-/wasm-utxo-4.7.0.tgz#2ec1103c840b3be1a2ed29fae4ebc03fd57160a6"
1036+
integrity sha512-7T1vZNxM1dGPi2EqbWAFzHN0A8uWlR05c9Q7UAmZv1dQt6SBTsGc5rPyoEmwvkyPJSdbvcPS3NCoTyWIcbqUUA==
10371037

10381038
"@brandonblack/musig@^0.0.1-alpha.0":
10391039
version "0.0.1-alpha.1"

0 commit comments

Comments
 (0)