Skip to content

Commit f1e5d93

Browse files
Merge pull request #8141 from BitGo/BTC-2768.default-to-psbt-lite
feat(abstract-utxo): default to psbt-lite for all coin formats
2 parents 3805169 + de81aa5 commit f1e5d93

2 files changed

Lines changed: 6 additions & 52 deletions

File tree

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { randomBytes } from 'crypto';
44
import _ from 'lodash';
55
import * as utxolib from '@bitgo/utxo-lib';
66
import { bip32 } from '@bitgo/secp256k1';
7-
import { bitgo, getMainnet, isMainnet } from '@bitgo/utxo-lib';
7+
import { bitgo, getMainnet } from '@bitgo/utxo-lib';
88
import {
99
AddressCoinSpecific,
1010
BaseCoin,
@@ -1001,22 +1001,7 @@ export abstract class AbstractUtxoCoin
10011001
return requestedFormat;
10021002
}
10031003

1004-
if (isTestnetCoin(this.name)) {
1005-
return 'psbt-lite';
1006-
}
1007-
1008-
const walletFlagMusigKp = wallet.flag('musigKp') === 'true';
1009-
const isHotWallet = wallet.type() === 'hot';
1010-
1011-
// Determine if we should default to psbt format
1012-
const shouldDefaultToPsbt =
1013-
wallet.subType() === 'distributedCustody' ||
1014-
// if mainnet, only default to psbt for btc hot wallets
1015-
(isMainnet(this.network) && getMainnet(this.network) === utxolib.networks.bitcoin && isHotWallet) ||
1016-
// default to psbt if it has the wallet flag
1017-
walletFlagMusigKp;
1018-
1019-
return shouldDefaultToPsbt ? 'psbt' : undefined;
1004+
return 'psbt-lite';
10201005
}
10211006

10221007
async getExtraPrebuildParams(buildParams: ExtraPrebuildParamsOptions & { wallet: Wallet }): Promise<{

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

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as assert from 'assert';
33
import { Wallet } from '@bitgo/sdk-core';
44

55
import { AbstractUtxoCoin, ErrorDeprecatedTxFormat, TxFormat } from '../../src';
6-
import { getMainnetCoinName, isMainnetCoin, isTestnetCoin } from '../../src/names';
6+
import { isMainnetCoin, isTestnetCoin } from '../../src/names';
77

88
import { utxoCoins, defaultBitGo } from './util';
99

@@ -110,42 +110,11 @@ describe('txFormat', function () {
110110
expectedTxFormat: 'psbt-lite',
111111
});
112112

113-
// DistributedCustody wallets default to PSBT (mainnet only, testnet already covered)
113+
// All mainnet wallets default to psbt-lite
114114
runTest({
115-
description: 'should return psbt for distributedCustody wallets on mainnet',
115+
description: 'should return psbt-lite for all mainnet wallets',
116116
coinFilter: (coin) => isMainnetCoin(coin.name),
117-
walletFilter: (w) => w.options.subType === 'distributedCustody',
118-
expectedTxFormat: 'psbt',
119-
});
120-
121-
// MuSig2 wallets default to PSBT (mainnet only, testnet already covered)
122-
runTest({
123-
description: 'should return psbt for wallets with musigKp flag on mainnet',
124-
coinFilter: (coin) => isMainnetCoin(coin.name),
125-
walletFilter: (w) => Boolean(w.options.walletFlags?.some((f) => f.name === 'musigKp' && f.value === 'true')),
126-
expectedTxFormat: 'psbt',
127-
});
128-
129-
// Mainnet Bitcoin hot wallets default to PSBT
130-
runTest({
131-
description: 'should return psbt for mainnet bitcoin hot wallets',
132-
coinFilter: (coin) => isMainnetCoin(coin.name) && getMainnetCoinName(coin.name) === 'btc',
133-
walletFilter: (w) => w.options.type === 'hot',
134-
expectedTxFormat: 'psbt',
135-
});
136-
137-
// Other mainnet wallets do NOT default to PSBT
138-
runTest({
139-
description: 'should return undefined for other mainnet wallets',
140-
coinFilter: (coin) => isMainnetCoin(coin.name),
141-
walletFilter: (w) => {
142-
const isHotBitcoin = w.options.type === 'hot'; // This will be bitcoin hot wallets
143-
const isDistributedCustody = w.options.subType === 'distributedCustody';
144-
const hasMusigKpFlag = Boolean(w.options.walletFlags?.some((f) => f.name === 'musigKp' && f.value === 'true'));
145-
// Only test "other" wallets - exclude the special cases
146-
return !isHotBitcoin && !isDistributedCustody && !hasMusigKpFlag;
147-
},
148-
expectedTxFormat: undefined,
117+
expectedTxFormat: 'psbt-lite',
149118
});
150119

151120
// Test explicitly requested formats

0 commit comments

Comments
 (0)