From 72ed94554845f56b567f31272e544e30cf67876d Mon Sep 17 00:00:00 2001 From: Otto Allmendinger Date: Fri, 22 May 2026 15:50:14 +0200 Subject: [PATCH] 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 --- .../src/offlineVault/descriptor/transaction.ts | 5 ++--- .../abstract-utxo/src/transaction/descriptor/parse.ts | 9 ++++++--- .../src/transaction/descriptor/verifyTransaction.ts | 3 +-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts b/modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts index ec54140c23..ae4f17768f 100644 --- a/modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts +++ b/modules/abstract-utxo/src/offlineVault/descriptor/transaction.ts @@ -12,7 +12,6 @@ import { import { explainPsbt, signPsbt } from '../../transaction/descriptor'; import { TransactionExplanation } from '../TransactionExplanation'; import { UtxoCoinName } from '../../names'; -import { toWasmPsbt } from '../../wasmUtil'; export const DescriptorTransaction = t.intersection( [OfflineVaultSignable, t.type({ descriptors: t.array(NamedDescriptor) })], @@ -34,7 +33,7 @@ export function getDescriptorsFromDescriptorTransaction(tx: DescriptorTransactio } export function getHalfSignedPsbt(tx: DescriptorTransaction, prv: bip32.BIP32Interface, coinName: UtxoCoinName): Psbt { - const psbt = toWasmPsbt(Buffer.from(tx.coinSpecific.txHex, 'hex')); + const psbt = Psbt.deserialize(Buffer.from(tx.coinSpecific.txHex, 'hex')); const descriptorMap = getDescriptorsFromDescriptorTransaction(tx); signPsbt(psbt, descriptorMap, prv, { onUnknownInput: 'throw' }); return psbt; @@ -44,7 +43,7 @@ export function getTransactionExplanationFromPsbt( tx: DescriptorTransaction, coinName: UtxoCoinName ): TransactionExplanation { - const psbt = toWasmPsbt(Buffer.from(tx.coinSpecific.txHex, 'hex')); + const psbt = Psbt.deserialize(Buffer.from(tx.coinSpecific.txHex, 'hex')); const descriptorMap = getDescriptorsFromDescriptorTransaction(tx); const { outputs, changeOutputs, fee } = explainPsbt(psbt, descriptorMap, coinName); return { diff --git a/modules/abstract-utxo/src/transaction/descriptor/parse.ts b/modules/abstract-utxo/src/transaction/descriptor/parse.ts index f0a1d6eb20..82261cb964 100644 --- a/modules/abstract-utxo/src/transaction/descriptor/parse.ts +++ b/modules/abstract-utxo/src/transaction/descriptor/parse.ts @@ -9,9 +9,12 @@ import { IDescriptorWallet } from '../../descriptor/descriptorWallet'; import { fromExtendedAddressFormatToScript, toExtendedAddressFormat } from '../recipient'; import { outputDifferencesWithExpected, OutputDifferenceWithExpected } from '../outputDifference'; import { UtxoCoinName } from '../../names'; -import { sumValues, toWasmPsbt, UtxoLibPsbt } from '../../wasmUtil'; import { decodeDescriptorPsbt } from '../decode'; +function sumValues(arr: { value: bigint }[]): bigint { + return arr.reduce((sum, e) => sum + e.value, 0n); +} + type ParsedOutput = Omit & { script: Buffer }; export type RecipientOutput = Omit & { @@ -88,12 +91,12 @@ function toBaseParsedTransactionOutputs( } export function toBaseParsedTransactionOutputsFromPsbt( - psbt: Psbt | UtxoLibPsbt | Uint8Array, + psbt: Psbt | Uint8Array, descriptorMap: descriptorWallet.DescriptorMap, recipients: ITransactionRecipient[], coinName: UtxoCoinName ): ParsedOutputsBigInt { - const wasmPsbt = toWasmPsbt(psbt); + const wasmPsbt = psbt instanceof Psbt ? psbt : Psbt.deserialize(psbt); return toBaseParsedTransactionOutputs( parseOutputsWithPsbt( wasmPsbt, diff --git a/modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts b/modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts index 645dcea578..7f81479a90 100644 --- a/modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts +++ b/modules/abstract-utxo/src/transaction/descriptor/verifyTransaction.ts @@ -4,7 +4,6 @@ import type { Psbt, descriptorWallet } from '@bitgo/wasm-utxo'; import { AbstractUtxoCoin, VerifyTransactionOptions } from '../../abstractUtxoCoin'; import { BaseOutput, BaseParsedTransactionOutputs } from '../types'; import { UtxoCoinName } from '../../names'; -import { UtxoLibPsbt } from '../../wasmUtil'; import { decodeDescriptorPsbt } from '../decode'; import { toBaseParsedTransactionOutputsFromPsbt } from './parse'; @@ -52,7 +51,7 @@ export function assertExpectedOutputDifference( } export function assertValidTransaction( - psbt: Psbt | UtxoLibPsbt | Uint8Array, + psbt: Psbt | Uint8Array, descriptors: descriptorWallet.DescriptorMap, recipients: ITransactionRecipient[], coinName: UtxoCoinName