Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/abstract-utxo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"@bitgo/utxo-core": "^1.27.0",
"@bitgo/utxo-lib": "^11.18.0",
"@bitgo/utxo-ord": "^1.22.19",
"@bitgo/wasm-utxo": "1.11.0",
"@bitgo/wasm-utxo": "1.14.0",
"@types/lodash": "^4.14.121",
"@types/superagent": "4.1.15",
"bignumber.js": "^9.0.2",
Expand Down
10 changes: 7 additions & 3 deletions modules/abstract-utxo/test/unit/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
WalletSignTransactionOptions,
} from '@bitgo/sdk-core';

import { AbstractUtxoCoin, getReplayProtectionAddresses, generateAddress } from '../../src';
import { AbstractUtxoCoin, getReplayProtectionAddresses, generateAddress, getReplayProtectionPubkeys } from '../../src';
import { SdkBackend } from '../../src/transaction/types';

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

for (const v of [false, true]) {
await signTransaction(psbt, v);
Expand Down Expand Up @@ -402,7 +404,9 @@ function run<TNumber extends number | bigint = number>(
const outputs: testutil.Output[] = [
{ address: getOutputAddress(getWalletKeys('test')), value: unspentSum - BigInt(1000) },
];
const psbt = testutil.constructPsbt(inputs, outputs, coin.network, walletKeys, 'unsigned');
const psbt = testutil.constructPsbt(inputs, outputs, coin.network, walletKeys, 'unsigned', {
p2shP2pkKey: getReplayProtectionPubkeys(coin.network)[0],
});
utxolib.bitgo.addXpubsToPsbt(psbt, walletKeys);
return psbt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import * as utxolib from '@bitgo/utxo-lib';

export function hasWasmUtxoSupport(network: utxolib.Network): boolean {
return ![
utxolib.networks.bitcoincash,
utxolib.networks.bitcoingold,
utxolib.networks.bitcoinsv,
utxolib.networks.ecash,
utxolib.networks.zcash,
].includes(utxolib.getMainnet(network));
return utxolib.getMainnet(network) !== utxolib.networks.zcash;
}
2 changes: 1 addition & 1 deletion modules/utxo-bin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@bitgo/unspents": "^0.50.12",
"@bitgo/utxo-core": "^1.27.0",
"@bitgo/utxo-lib": "^11.18.0",
"@bitgo/wasm-utxo": "1.11.0",
"@bitgo/wasm-utxo": "1.14.0",
"@noble/curves": "1.8.1",
"archy": "^1.0.0",
"bech32": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion modules/utxo-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"@bitgo/secp256k1": "^1.7.0",
"@bitgo/unspents": "^0.50.12",
"@bitgo/utxo-lib": "^11.18.0",
"@bitgo/wasm-utxo": "1.11.0",
"@bitgo/wasm-utxo": "1.14.0",
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"bitcoinjs-message": "npm:@bitgo-forks/bitcoinjs-message@1.0.0-master.3",
"fast-sha256": "^1.3.0"
Expand Down
7 changes: 5 additions & 2 deletions modules/utxo-lib/src/testutil/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,12 @@ export function isReplayProtectionUnspent<TNumber extends bigint | number>(
export function mockReplayProtectionUnspent<TNumber extends number | bigint>(
network: Network,
value: TNumber,
{ key = replayProtectionKeyPair, vout = 0 }: { key?: BIP32Interface; vout?: number } = {}
{ key = replayProtectionKeyPair, vout = 0 }: { key?: BIP32Interface | Buffer; vout?: number } = {}
): UnspentWithPrevTx<TNumber> {
const outputScript = createOutputScriptP2shP2pk(key.publicKey).scriptPubKey;
if (!Buffer.isBuffer(key)) {
key = key.publicKey;
}
const outputScript = createOutputScriptP2shP2pk(key).scriptPubKey;
const prevTransaction = mockPrevTx(vout, outputScript, BigInt(value), network);
return { ...fromOutputWithPrevTx(prevTransaction, vout), value };
}
Expand Down
15 changes: 11 additions & 4 deletions modules/utxo-lib/src/testutil/psbt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ export function toUnspent(
input: Input,
index: number,
network: Network,
rootWalletKeys: RootWalletKeys
rootWalletKeys: RootWalletKeys,
{ p2shP2pkKey }: { p2shP2pkKey?: Buffer } = {}
): Unspent<bigint> {
if (input.scriptType === 'p2shP2pk') {
return mockReplayProtectionUnspent(network, input.value, { key: rootWalletKeys['user'], vout: index });
return mockReplayProtectionUnspent(network, input.value, {
key: p2shP2pkKey ?? rootWalletKeys['user'],
vout: index,
});
} else {
const chain = getInternalChainCode(input.scriptType === 'taprootKeyPathSpend' ? 'p2trMusig2' : input.scriptType);
return mockWalletUnspent(network, input.value, {
Expand Down Expand Up @@ -177,6 +181,7 @@ export function constructPsbt(
rootWalletKeys: RootWalletKeys,
signStage: SignStage,
params?: {
p2shP2pkKey?: Buffer;
signers?: { signerName: KeyName; cosignerName?: KeyName };
deterministic?: boolean;
skipNonWitnessUtxo?: boolean;
Expand All @@ -194,14 +199,16 @@ export function constructPsbt(
addXpubsToPsbt(psbt, rootWalletKeys);
}

const unspents = inputs.map((input, i) => toUnspent(input, i, network, rootWalletKeys));
const unspents = inputs.map((input, i) =>
toUnspent(input, i, network, rootWalletKeys, { p2shP2pkKey: params?.p2shP2pkKey })
);

unspents.forEach((u, i) => {
const { signerName, cosignerName } = signers ? signers : getSigners(inputs[i].scriptType);
if (isWalletUnspent(u) && cosignerName) {
addWalletUnspentToPsbt(psbt, u, rootWalletKeys, signerName, cosignerName, { skipNonWitnessUtxo });
} else {
const { redeemScript } = createOutputScriptP2shP2pk(rootWalletKeys.user.publicKey);
const { redeemScript } = createOutputScriptP2shP2pk(params?.p2shP2pkKey ?? rootWalletKeys.user.publicKey);
assert(redeemScript);
addReplayProtectionUnspentToPsbt(psbt, u, redeemScript, { skipNonWitnessUtxo });
}
Expand Down
2 changes: 1 addition & 1 deletion modules/utxo-staking/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@bitgo/babylonlabs-io-btc-staking-ts": "^3.2.1",
"@bitgo/utxo-core": "^1.27.0",
"@bitgo/utxo-lib": "^11.18.0",
"@bitgo/wasm-utxo": "1.11.0",
"@bitgo/wasm-utxo": "1.14.0",
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"bip322-js": "^2.0.0",
"bitcoinjs-lib": "^6.1.7",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -968,10 +968,10 @@
monocle-ts "^2.3.13"
newtype-ts "^0.3.5"

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

"@brandonblack/musig@^0.0.1-alpha.0":
version "0.0.1-alpha.1"
Expand Down