Skip to content

Commit f86f3aa

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): prohibit legacy tx format on testnet
This adds a safeguard to prevent use of the deprecated legacy tx format on testnet environments. The new ErrorDeprecatedTxFormat class provides clear messaging to users about using PSBT instead. BTC-2732 Co-authored-by: llm-git <[email protected]>
1 parent b3fa864 commit f86f3aa

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ export type TxFormat =
9797
// While this prevents us to fully verify the transaction fee, we have other checks in place to ensure the fee is within bounds.
9898
| 'psbt-lite';
9999

100+
export class ErrorDeprecatedTxFormat extends Error {
101+
constructor(txFormat: TxFormat) {
102+
super(`SDK support for txFormat=${txFormat} is deprecated on this environment. Please use psbt instead.`);
103+
}
104+
}
105+
100106
type UtxoCustomSigningFunction<TNumber extends number | bigint> = {
101107
(params: {
102108
coin: IBaseCoin;
@@ -979,6 +985,10 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
979985
getDefaultTxFormat(wallet: Wallet, requestedFormat?: TxFormat): TxFormat | undefined {
980986
// If format is explicitly requested, use it
981987
if (requestedFormat !== undefined) {
988+
if (isTestnet(this.network) && requestedFormat === 'legacy') {
989+
throw new ErrorDeprecatedTxFormat(requestedFormat);
990+
}
991+
982992
return requestedFormat;
983993
}
984994

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

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

6-
import { AbstractUtxoCoin, TxFormat } from '../../src';
6+
import { AbstractUtxoCoin, ErrorDeprecatedTxFormat, TxFormat } from '../../src';
77

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

@@ -151,7 +151,8 @@ describe('txFormat', function () {
151151

152152
// Test explicitly requested formats
153153
runTest({
154-
description: 'should respect explicitly requested legacy format',
154+
description: 'should respect explicitly requested legacy format on mainnet',
155+
coinFilter: (coin) => utxolib.isMainnet(coin.network),
155156
expectedTxFormat: 'legacy',
156157
requestedTxFormat: 'legacy',
157158
});
@@ -167,5 +168,21 @@ describe('txFormat', function () {
167168
expectedTxFormat: 'psbt-lite',
168169
requestedTxFormat: 'psbt-lite',
169170
});
171+
172+
// Test that legacy format is prohibited on testnet
173+
it('should throw ErrorDeprecatedTxFormat when legacy format is requested on testnet', function () {
174+
for (const coin of utxoCoins) {
175+
if (!utxolib.isTestnet(coin.network)) {
176+
continue;
177+
}
178+
179+
const wallet = createMockWallet(coin, { type: 'hot' });
180+
assert.throws(
181+
() => getTxFormat(coin, wallet, 'legacy'),
182+
ErrorDeprecatedTxFormat,
183+
`Expected ErrorDeprecatedTxFormat for ${coin.getChain()}`
184+
);
185+
}
186+
});
170187
});
171188
});

0 commit comments

Comments
 (0)