Skip to content

Commit 72ed945

Browse files
refactor(abstract-utxo): narrow descriptor PSBT type unions to wasm-only
assertValidTransaction / toBaseParsedTransactionOutputsFromPsbt only get called with wasm Psbt or Buffer; the UtxoLibPsbt branch was unused. Replace toWasmPsbt(...) with Psbt.deserialize(...) inline. Refs: T1-3279
1 parent d68cfc4 commit 72ed945

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
import { explainPsbt, signPsbt } from '../../transaction/descriptor';
1313
import { TransactionExplanation } from '../TransactionExplanation';
1414
import { UtxoCoinName } from '../../names';
15-
import { toWasmPsbt } from '../../wasmUtil';
1615

1716
export const DescriptorTransaction = t.intersection(
1817
[OfflineVaultSignable, t.type({ descriptors: t.array(NamedDescriptor) })],
@@ -34,7 +33,7 @@ export function getDescriptorsFromDescriptorTransaction(tx: DescriptorTransactio
3433
}
3534

3635
export function getHalfSignedPsbt(tx: DescriptorTransaction, prv: bip32.BIP32Interface, coinName: UtxoCoinName): Psbt {
37-
const psbt = toWasmPsbt(Buffer.from(tx.coinSpecific.txHex, 'hex'));
36+
const psbt = Psbt.deserialize(Buffer.from(tx.coinSpecific.txHex, 'hex'));
3837
const descriptorMap = getDescriptorsFromDescriptorTransaction(tx);
3938
signPsbt(psbt, descriptorMap, prv, { onUnknownInput: 'throw' });
4039
return psbt;
@@ -44,7 +43,7 @@ export function getTransactionExplanationFromPsbt(
4443
tx: DescriptorTransaction,
4544
coinName: UtxoCoinName
4645
): TransactionExplanation<string> {
47-
const psbt = toWasmPsbt(Buffer.from(tx.coinSpecific.txHex, 'hex'));
46+
const psbt = Psbt.deserialize(Buffer.from(tx.coinSpecific.txHex, 'hex'));
4847
const descriptorMap = getDescriptorsFromDescriptorTransaction(tx);
4948
const { outputs, changeOutputs, fee } = explainPsbt(psbt, descriptorMap, coinName);
5049
return {

modules/abstract-utxo/src/transaction/descriptor/parse.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import { IDescriptorWallet } from '../../descriptor/descriptorWallet';
99
import { fromExtendedAddressFormatToScript, toExtendedAddressFormat } from '../recipient';
1010
import { outputDifferencesWithExpected, OutputDifferenceWithExpected } from '../outputDifference';
1111
import { UtxoCoinName } from '../../names';
12-
import { sumValues, toWasmPsbt, UtxoLibPsbt } from '../../wasmUtil';
1312
import { decodeDescriptorPsbt } from '../decode';
1413

14+
function sumValues(arr: { value: bigint }[]): bigint {
15+
return arr.reduce((sum, e) => sum + e.value, 0n);
16+
}
17+
1518
type ParsedOutput = Omit<descriptorWallet.ParsedOutput, 'script'> & { script: Buffer };
1619

1720
export type RecipientOutput = Omit<ParsedOutput, 'value'> & {
@@ -88,12 +91,12 @@ function toBaseParsedTransactionOutputs(
8891
}
8992

9093
export function toBaseParsedTransactionOutputsFromPsbt(
91-
psbt: Psbt | UtxoLibPsbt | Uint8Array,
94+
psbt: Psbt | Uint8Array,
9295
descriptorMap: descriptorWallet.DescriptorMap,
9396
recipients: ITransactionRecipient[],
9497
coinName: UtxoCoinName
9598
): ParsedOutputsBigInt {
96-
const wasmPsbt = toWasmPsbt(psbt);
99+
const wasmPsbt = psbt instanceof Psbt ? psbt : Psbt.deserialize(psbt);
97100
return toBaseParsedTransactionOutputs(
98101
parseOutputsWithPsbt(
99102
wasmPsbt,

modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { Psbt, descriptorWallet } from '@bitgo/wasm-utxo';
44
import { AbstractUtxoCoin, VerifyTransactionOptions } from '../../abstractUtxoCoin';
55
import { BaseOutput, BaseParsedTransactionOutputs } from '../types';
66
import { UtxoCoinName } from '../../names';
7-
import { UtxoLibPsbt } from '../../wasmUtil';
87
import { decodeDescriptorPsbt } from '../decode';
98

109
import { toBaseParsedTransactionOutputsFromPsbt } from './parse';
@@ -52,7 +51,7 @@ export function assertExpectedOutputDifference(
5251
}
5352

5453
export function assertValidTransaction(
55-
psbt: Psbt | UtxoLibPsbt | Uint8Array,
54+
psbt: Psbt | Uint8Array,
5655
descriptors: descriptorWallet.DescriptorMap,
5756
recipients: ITransactionRecipient[],
5857
coinName: UtxoCoinName

0 commit comments

Comments
 (0)