Skip to content

Commit fa256e6

Browse files
Merge pull request #7761 from BitGo/BTC-2656.add-bch-btg-support
feat(abstract-utxo): enable wasm support for multiple UTXO coins
2 parents dbfa7a9 + 8c2bb89 commit fa256e6

File tree

9 files changed

+32
-24
lines changed

9 files changed

+32
-24
lines changed

modules/abstract-utxo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"@bitgo/utxo-core": "^1.27.0",
6969
"@bitgo/utxo-lib": "^11.18.0",
7070
"@bitgo/utxo-ord": "^1.22.19",
71-
"@bitgo/wasm-utxo": "1.11.0",
71+
"@bitgo/wasm-utxo": "1.14.0",
7272
"@types/lodash": "^4.14.121",
7373
"@types/superagent": "4.1.15",
7474
"bignumber.js": "^9.0.2",

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
WalletSignTransactionOptions,
1414
} from '@bitgo/sdk-core';
1515

16-
import { AbstractUtxoCoin, getReplayProtectionAddresses, generateAddress } from '../../src';
16+
import { AbstractUtxoCoin, getReplayProtectionAddresses, generateAddress, getReplayProtectionPubkeys } from '../../src';
1717
import { SdkBackend } from '../../src/transaction/types';
1818

1919
import { hasWasmUtxoSupport } from './transaction/fixedScript/util';
@@ -176,7 +176,9 @@ describe(`UTXO coin signTransaction`, async function () {
176176
}));
177177
const unspentSum = inputs.reduce((prev: bigint, curr) => prev + curr.value, BigInt(0));
178178
const outputs: testutil.Output[] = [{ scriptType: 'p2sh', value: unspentSum - BigInt(1000) }];
179-
const psbt = testutil.constructPsbt(inputs, outputs, coin.network, rootWalletKeys, 'unsigned');
179+
const psbt = testutil.constructPsbt(inputs, outputs, coin.network, rootWalletKeys, 'unsigned', {
180+
p2shP2pkKey: getReplayProtectionPubkeys(coin.network)[0],
181+
});
180182

181183
for (const v of [false, true]) {
182184
await signTransaction(psbt, v);
@@ -402,7 +404,9 @@ function run<TNumber extends number | bigint = number>(
402404
const outputs: testutil.Output[] = [
403405
{ address: getOutputAddress(getWalletKeys('test')), value: unspentSum - BigInt(1000) },
404406
];
405-
const psbt = testutil.constructPsbt(inputs, outputs, coin.network, walletKeys, 'unsigned');
407+
const psbt = testutil.constructPsbt(inputs, outputs, coin.network, walletKeys, 'unsigned', {
408+
p2shP2pkKey: getReplayProtectionPubkeys(coin.network)[0],
409+
});
406410
utxolib.bitgo.addXpubsToPsbt(psbt, walletKeys);
407411
return psbt;
408412
}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import * as utxolib from '@bitgo/utxo-lib';
22

33
export function hasWasmUtxoSupport(network: utxolib.Network): boolean {
4-
return ![
5-
utxolib.networks.bitcoincash,
6-
utxolib.networks.bitcoingold,
7-
utxolib.networks.bitcoinsv,
8-
utxolib.networks.ecash,
9-
utxolib.networks.zcash,
10-
].includes(utxolib.getMainnet(network));
4+
return utxolib.getMainnet(network) !== utxolib.networks.zcash;
115
}

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.50.12",
3232
"@bitgo/utxo-core": "^1.27.0",
3333
"@bitgo/utxo-lib": "^11.18.0",
34-
"@bitgo/wasm-utxo": "1.11.0",
34+
"@bitgo/wasm-utxo": "1.14.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.7.0",
8282
"@bitgo/unspents": "^0.50.12",
8383
"@bitgo/utxo-lib": "^11.18.0",
84-
"@bitgo/wasm-utxo": "1.11.0",
84+
"@bitgo/wasm-utxo": "1.14.0",
8585
"bip174": "npm:@bitgo-forks/[email protected]",
8686
"bitcoinjs-message": "npm:@bitgo-forks/[email protected]",
8787
"fast-sha256": "^1.3.0"

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ export function isReplayProtectionUnspent<TNumber extends bigint | number>(
7676
export function mockReplayProtectionUnspent<TNumber extends number | bigint>(
7777
network: Network,
7878
value: TNumber,
79-
{ key = replayProtectionKeyPair, vout = 0 }: { key?: BIP32Interface; vout?: number } = {}
79+
{ key = replayProtectionKeyPair, vout = 0 }: { key?: BIP32Interface | Buffer; vout?: number } = {}
8080
): UnspentWithPrevTx<TNumber> {
81-
const outputScript = createOutputScriptP2shP2pk(key.publicKey).scriptPubKey;
81+
if (!Buffer.isBuffer(key)) {
82+
key = key.publicKey;
83+
}
84+
const outputScript = createOutputScriptP2shP2pk(key).scriptPubKey;
8285
const prevTransaction = mockPrevTx(vout, outputScript, BigInt(value), network);
8386
return { ...fromOutputWithPrevTx(prevTransaction, vout), value };
8487
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,14 @@ export function toUnspent(
8686
input: Input,
8787
index: number,
8888
network: Network,
89-
rootWalletKeys: RootWalletKeys
89+
rootWalletKeys: RootWalletKeys,
90+
{ p2shP2pkKey }: { p2shP2pkKey?: Buffer } = {}
9091
): Unspent<bigint> {
9192
if (input.scriptType === 'p2shP2pk') {
92-
return mockReplayProtectionUnspent(network, input.value, { key: rootWalletKeys['user'], vout: index });
93+
return mockReplayProtectionUnspent(network, input.value, {
94+
key: p2shP2pkKey ?? rootWalletKeys['user'],
95+
vout: index,
96+
});
9397
} else {
9498
const chain = getInternalChainCode(input.scriptType === 'taprootKeyPathSpend' ? 'p2trMusig2' : input.scriptType);
9599
return mockWalletUnspent(network, input.value, {
@@ -177,6 +181,7 @@ export function constructPsbt(
177181
rootWalletKeys: RootWalletKeys,
178182
signStage: SignStage,
179183
params?: {
184+
p2shP2pkKey?: Buffer;
180185
signers?: { signerName: KeyName; cosignerName?: KeyName };
181186
deterministic?: boolean;
182187
skipNonWitnessUtxo?: boolean;
@@ -194,14 +199,16 @@ export function constructPsbt(
194199
addXpubsToPsbt(psbt, rootWalletKeys);
195200
}
196201

197-
const unspents = inputs.map((input, i) => toUnspent(input, i, network, rootWalletKeys));
202+
const unspents = inputs.map((input, i) =>
203+
toUnspent(input, i, network, rootWalletKeys, { p2shP2pkKey: params?.p2shP2pkKey })
204+
);
198205

199206
unspents.forEach((u, i) => {
200207
const { signerName, cosignerName } = signers ? signers : getSigners(inputs[i].scriptType);
201208
if (isWalletUnspent(u) && cosignerName) {
202209
addWalletUnspentToPsbt(psbt, u, rootWalletKeys, signerName, cosignerName, { skipNonWitnessUtxo });
203210
} else {
204-
const { redeemScript } = createOutputScriptP2shP2pk(rootWalletKeys.user.publicKey);
211+
const { redeemScript } = createOutputScriptP2shP2pk(params?.p2shP2pkKey ?? rootWalletKeys.user.publicKey);
205212
assert(redeemScript);
206213
addReplayProtectionUnspentToPsbt(psbt, u, redeemScript, { skipNonWitnessUtxo });
207214
}

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.2.1",
6464
"@bitgo/utxo-core": "^1.27.0",
6565
"@bitgo/utxo-lib": "^11.18.0",
66-
"@bitgo/wasm-utxo": "1.11.0",
66+
"@bitgo/wasm-utxo": "1.14.0",
6767
"bip174": "npm:@bitgo-forks/[email protected]",
6868
"bip322-js": "^2.0.0",
6969
"bitcoinjs-lib": "^6.1.7",

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -968,10 +968,10 @@
968968
monocle-ts "^2.3.13"
969969
newtype-ts "^0.3.5"
970970

971-
"@bitgo/wasm-utxo@1.11.0":
972-
version "1.11.0"
973-
resolved "https://registry.npmjs.org/@bitgo/wasm-utxo/-/wasm-utxo-1.11.0.tgz#e6b90de37c8afac17b51d20403ba1fa102198e39"
974-
integrity sha512-yLORJZR8iD96WowF9lvBIFq4su6LUlIooOuG7awX6dNaTgHStPiRUEJbbKW1cSXAzTOSscl6wNHzgTaKkxYM5A==
971+
"@bitgo/wasm-utxo@1.14.0":
972+
version "1.14.0"
973+
resolved "https://registry.npmjs.org/@bitgo/wasm-utxo/-/wasm-utxo-1.14.0.tgz#d4447ddf47a38b0e471ccffbf13540c1eaf30a44"
974+
integrity sha512-8h0iImoUmK2Z0tdDLyfX/RfXKxb83qcRZSUhH+YFATo6SDlKpA1TpV+OjEY4Xrvte7abvVuezxU5Wq820xJcNQ==
975975

976976
"@brandonblack/musig@^0.0.1-alpha.0":
977977
version "0.0.1-alpha.1"

0 commit comments

Comments
 (0)