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
10 changes: 10 additions & 0 deletions modules/abstract-utxo/src/abstractUtxoCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ export type TxFormat =
// While this prevents us to fully verify the transaction fee, we have other checks in place to ensure the fee is within bounds.
| 'psbt-lite';

export class ErrorDeprecatedTxFormat extends Error {
constructor(txFormat: TxFormat) {
super(`SDK support for txFormat=${txFormat} is deprecated on this environment. Please use psbt instead.`);
}
}

type UtxoCustomSigningFunction<TNumber extends number | bigint> = {
(params: {
coin: IBaseCoin;
Expand Down Expand Up @@ -979,6 +985,10 @@ export abstract class AbstractUtxoCoin extends BaseCoin {
getDefaultTxFormat(wallet: Wallet, requestedFormat?: TxFormat): TxFormat | undefined {
// If format is explicitly requested, use it
if (requestedFormat !== undefined) {
if (isTestnet(this.network) && requestedFormat === 'legacy') {
throw new ErrorDeprecatedTxFormat(requestedFormat);
}

return requestedFormat;
}

Expand Down
21 changes: 19 additions & 2 deletions modules/abstract-utxo/test/unit/txFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as assert from 'assert';
import * as utxolib from '@bitgo/utxo-lib';
import { Wallet } from '@bitgo/sdk-core';

import { AbstractUtxoCoin, TxFormat } from '../../src';
import { AbstractUtxoCoin, ErrorDeprecatedTxFormat, TxFormat } from '../../src';

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

Expand Down Expand Up @@ -151,7 +151,8 @@ describe('txFormat', function () {

// Test explicitly requested formats
runTest({
description: 'should respect explicitly requested legacy format',
description: 'should respect explicitly requested legacy format on mainnet',
coinFilter: (coin) => utxolib.isMainnet(coin.network),
expectedTxFormat: 'legacy',
requestedTxFormat: 'legacy',
});
Expand All @@ -167,5 +168,21 @@ describe('txFormat', function () {
expectedTxFormat: 'psbt-lite',
requestedTxFormat: 'psbt-lite',
});

// Test that legacy format is prohibited on testnet
it('should throw ErrorDeprecatedTxFormat when legacy format is requested on testnet', function () {
for (const coin of utxoCoins) {
if (!utxolib.isTestnet(coin.network)) {
continue;
}

const wallet = createMockWallet(coin, { type: 'hot' });
assert.throws(
() => getTxFormat(coin, wallet, 'legacy'),
ErrorDeprecatedTxFormat,
`Expected ErrorDeprecatedTxFormat for ${coin.getChain()}`
);
}
});
});
});