11import {
22 BitGoPsbt as WasmBitGoPsbt ,
33 FixedScriptWalletNamespace ,
4- WasmBIP32 ,
5- type PsbtInputData ,
6- type PsbtOutputData ,
74 type PsbtOutputDataWithAddress ,
85} from "../wasm/wasm_utxo.js" ;
96import type { IPsbtWithAddress } from "../psbt.js" ;
7+ import { PsbtBase } from "../psbtBase.js" ;
108import { type WalletKeysArg , RootWalletKeys } from "./RootWalletKeys.js" ;
119import { type ReplayProtectionArg , ReplayProtection } from "./ReplayProtection.js" ;
1210import { type BIP32Arg , BIP32 , isBIP32Arg } from "../bip32.js" ;
1311import { type ECPairArg , ECPair } from "../ecpair.js" ;
1412import type { UtxolibName } from "../utxolibCompat.js" ;
1513import type { CoinName } from "../coinName.js" ;
1614import type { InputScriptType } from "./scriptType.js" ;
17- import type { PsbtKvKey } from "./BitGoKeySubtype.js" ;
1815import {
1916 Transaction ,
2017 DashTransaction ,
@@ -133,8 +130,10 @@ export type HydrationUnspent = {
133130 value : bigint ;
134131} ;
135132
136- export class BitGoPsbt implements IPsbtWithAddress {
137- protected constructor ( protected _wasm : WasmBitGoPsbt ) { }
133+ export class BitGoPsbt extends PsbtBase < WasmBitGoPsbt > implements IPsbtWithAddress {
134+ protected constructor ( wasm : WasmBitGoPsbt ) {
135+ super ( wasm ) ;
136+ }
138137
139138 /**
140139 * Get the underlying WASM instance
@@ -532,64 +531,6 @@ export class BitGoPsbt implements IPsbtWithAddress {
532531 ) ;
533532 }
534533
535- removeInput ( index : number ) : void {
536- this . _wasm . remove_input ( index ) ;
537- }
538-
539- removeOutput ( index : number ) : void {
540- this . _wasm . remove_output ( index ) ;
541- }
542-
543- /**
544- * Get the unsigned transaction ID
545- * @returns The unsigned transaction ID
546- */
547- unsignedTxId ( ) : string {
548- return this . _wasm . unsigned_txid ( ) ;
549- }
550-
551- /**
552- * Get the transaction version
553- * @returns The transaction version number
554- */
555- version ( ) : number {
556- return this . _wasm . version ( ) ;
557- }
558-
559- lockTime ( ) : number {
560- return this . _wasm . lock_time ( ) ;
561- }
562-
563- /** Set an arbitrary KV pair on the PSBT global map. */
564- setKV ( key : PsbtKvKey , value : Uint8Array ) : void {
565- this . _wasm . set_kv ( key , value ) ;
566- }
567-
568- /** Get a KV value from the PSBT global map. Returns `undefined` if not present. */
569- getKV ( key : PsbtKvKey ) : Uint8Array | undefined {
570- return this . _wasm . get_kv ( key ) ?? undefined ;
571- }
572-
573- /** Set an arbitrary KV pair on a specific PSBT input. */
574- setInputKV ( index : number , key : PsbtKvKey , value : Uint8Array ) : void {
575- this . _wasm . set_input_kv ( index , key , value ) ;
576- }
577-
578- /** Get a KV value from a specific PSBT input. Returns `undefined` if not present. */
579- getInputKV ( index : number , key : PsbtKvKey ) : Uint8Array | undefined {
580- return this . _wasm . get_input_kv ( index , key ) ?? undefined ;
581- }
582-
583- /** Set an arbitrary KV pair on a specific PSBT output. */
584- setOutputKV ( index : number , key : PsbtKvKey , value : Uint8Array ) : void {
585- this . _wasm . set_output_kv ( index , key , value ) ;
586- }
587-
588- /** Get a KV value from a specific PSBT output. Returns `undefined` if not present. */
589- getOutputKV ( index : number , key : PsbtKvKey ) : Uint8Array | undefined {
590- return this . _wasm . get_output_kv ( index , key ) ?? undefined ;
591- }
592-
593534 /**
594535 * Parse transaction with wallet keys to identify wallet inputs/outputs
595536 * @param walletKeys - The wallet keys to use for identification
@@ -850,15 +791,6 @@ export class BitGoPsbt implements IPsbtWithAddress {
850791 return this . _wasm . verify_replay_protection_signature ( inputIndex , rp . wasm ) ;
851792 }
852793
853- /**
854- * Serialize the PSBT to bytes
855- *
856- * @returns The serialized PSBT as a byte array
857- */
858- serialize ( ) : Uint8Array {
859- return this . _wasm . serialize ( ) ;
860- }
861-
862794 /**
863795 * Generate and store MuSig2 nonces for all MuSig2 inputs
864796 *
@@ -983,43 +915,6 @@ export class BitGoPsbt implements IPsbtWithAddress {
983915 return this . _wasm . extract_half_signed_legacy_tx ( ) ;
984916 }
985917
986- /**
987- * Get the number of inputs in the PSBT
988- * @returns The number of inputs
989- */
990- inputCount ( ) : number {
991- return this . _wasm . input_count ( ) ;
992- }
993-
994- outputCount ( ) : number {
995- return this . _wasm . output_count ( ) ;
996- }
997-
998- /**
999- * Get all PSBT inputs as an array
1000- *
1001- * Returns raw PSBT input data including witness_utxo and derivation info.
1002- * For parsed transaction data with address identification, use
1003- * parseTransactionWithWalletKeys() instead.
1004- *
1005- * @returns Array of PsbtInputData objects
1006- */
1007- getInputs ( ) : PsbtInputData [ ] {
1008- return this . _wasm . get_inputs ( ) as PsbtInputData [ ] ;
1009- }
1010-
1011- /**
1012- * Get all PSBT outputs as an array
1013- *
1014- * Returns raw PSBT output data without address resolution.
1015- * For output data with addresses, use getOutputsWithAddress().
1016- *
1017- * @returns Array of PsbtOutputData objects
1018- */
1019- getOutputs ( ) : PsbtOutputData [ ] {
1020- return this . _wasm . get_outputs ( ) as PsbtOutputData [ ] ;
1021- }
1022-
1023918 /**
1024919 * Get all PSBT outputs with resolved address strings
1025920 *
@@ -1039,14 +934,6 @@ export class BitGoPsbt implements IPsbtWithAddress {
1039934 getOutputsWithAddress ( ) : PsbtOutputDataWithAddress [ ] {
1040935 return this . _wasm . get_outputs_with_address ( ) as PsbtOutputDataWithAddress [ ] ;
1041936 }
1042-
1043- /**
1044- * Returns the unordered global xpubs from this PSBT as BIP32 instances.
1045- */
1046- getGlobalXpubs ( ) : BIP32 [ ] {
1047- const result = this . _wasm . get_global_xpubs ( ) as WasmBIP32 [ ] ;
1048- return result . map ( ( w ) => BIP32 . fromWasm ( w ) ) ;
1049- }
1050937}
1051938
1052939/**
0 commit comments