@@ -105,7 +105,15 @@ export type AddWalletOutputOptions = {
105105} ;
106106
107107export class BitGoPsbt {
108- protected constructor ( protected wasm : WasmBitGoPsbt ) { }
108+ protected constructor ( protected _wasm : WasmBitGoPsbt ) { }
109+
110+ /**
111+ * Get the underlying WASM instance
112+ * @internal - for use by other wasm-utxo modules
113+ */
114+ get wasm ( ) : WasmBitGoPsbt {
115+ return this . _wasm ;
116+ }
109117
110118 /**
111119 * Create an empty PSBT for the given network with wallet keys
@@ -135,13 +143,13 @@ export class BitGoPsbt {
135143 options ?: CreateEmptyOptions ,
136144 ) : BitGoPsbt {
137145 const keys = RootWalletKeys . from ( walletKeys ) ;
138- const wasm = WasmBitGoPsbt . create_empty (
146+ const wasmPsbt = WasmBitGoPsbt . create_empty (
139147 network ,
140148 keys . wasm ,
141149 options ?. version ,
142150 options ?. lockTime ,
143151 ) ;
144- return new BitGoPsbt ( wasm ) ;
152+ return new BitGoPsbt ( wasmPsbt ) ;
145153 }
146154
147155 /**
@@ -175,7 +183,7 @@ export class BitGoPsbt {
175183 * ```
176184 */
177185 addInput ( options : AddInputOptions , script : Uint8Array ) : number {
178- return this . wasm . add_input (
186+ return this . _wasm . add_input (
179187 options . txid ,
180188 options . vout ,
181189 options . value ,
@@ -200,7 +208,7 @@ export class BitGoPsbt {
200208 * ```
201209 */
202210 addOutput ( options : AddOutputOptions ) : number {
203- return this . wasm . add_output ( options . script , options . value ) ;
211+ return this . _wasm . add_output ( options . script , options . value ) ;
204212 }
205213
206214 /**
@@ -248,7 +256,7 @@ export class BitGoPsbt {
248256 walletOptions : AddWalletInputOptions ,
249257 ) : number {
250258 const keys = RootWalletKeys . from ( walletKeys ) ;
251- return this . wasm . add_wallet_input (
259+ return this . _wasm . add_wallet_input (
252260 inputOptions . txid ,
253261 inputOptions . vout ,
254262 inputOptions . value ,
@@ -294,7 +302,7 @@ export class BitGoPsbt {
294302 */
295303 addWalletOutput ( walletKeys : WalletKeysArg , options : AddWalletOutputOptions ) : number {
296304 const keys = RootWalletKeys . from ( walletKeys ) ;
297- return this . wasm . add_wallet_output ( options . chain , options . index , options . value , keys . wasm ) ;
305+ return this . _wasm . add_wallet_output ( options . chain , options . index , options . value , keys . wasm ) ;
298306 }
299307
300308 /**
@@ -318,7 +326,7 @@ export class BitGoPsbt {
318326 */
319327 addReplayProtectionInput ( inputOptions : AddInputOptions , key : ECPairArg ) : number {
320328 const ecpair = ECPair . from ( key ) ;
321- return this . wasm . add_replay_protection_input (
329+ return this . _wasm . add_replay_protection_input (
322330 ecpair . wasm ,
323331 inputOptions . txid ,
324332 inputOptions . vout ,
@@ -332,23 +340,23 @@ export class BitGoPsbt {
332340 * @returns The unsigned transaction ID
333341 */
334342 unsignedTxid ( ) : string {
335- return this . wasm . unsigned_txid ( ) ;
343+ return this . _wasm . unsigned_txid ( ) ;
336344 }
337345
338346 /**
339347 * Get the transaction version
340348 * @returns The transaction version number
341349 */
342350 get version ( ) : number {
343- return this . wasm . version ( ) ;
351+ return this . _wasm . version ( ) ;
344352 }
345353
346354 /**
347355 * Get the transaction lock time
348356 * @returns The transaction lock time
349357 */
350358 get lockTime ( ) : number {
351- return this . wasm . lock_time ( ) ;
359+ return this . _wasm . lock_time ( ) ;
352360 }
353361
354362 /**
@@ -364,9 +372,9 @@ export class BitGoPsbt {
364372 payGoPubkeys ?: ECPairArg [ ] ,
365373 ) : ParsedTransaction {
366374 const keys = RootWalletKeys . from ( walletKeys ) ;
367- const rp = ReplayProtection . from ( replayProtection , this . wasm . network ( ) ) ;
375+ const rp = ReplayProtection . from ( replayProtection , this . _wasm . network ( ) ) ;
368376 const pubkeys = payGoPubkeys ?. map ( ( arg ) => ECPair . from ( arg ) . wasm ) ;
369- return this . wasm . parse_transaction_with_wallet_keys (
377+ return this . _wasm . parse_transaction_with_wallet_keys (
370378 keys . wasm ,
371379 rp . wasm ,
372380 pubkeys ,
@@ -391,7 +399,7 @@ export class BitGoPsbt {
391399 ) : ParsedOutput [ ] {
392400 const keys = RootWalletKeys . from ( walletKeys ) ;
393401 const pubkeys = payGoPubkeys ?. map ( ( arg ) => ECPair . from ( arg ) . wasm ) ;
394- return this . wasm . parse_outputs_with_wallet_keys ( keys . wasm , pubkeys ) as ParsedOutput [ ] ;
402+ return this . _wasm . parse_outputs_with_wallet_keys ( keys . wasm , pubkeys ) as ParsedOutput [ ] ;
395403 }
396404
397405 /**
@@ -406,7 +414,7 @@ export class BitGoPsbt {
406414 * @throws Error if output index is out of bounds or entropy is not 64 bytes
407415 */
408416 addPayGoAttestation ( outputIndex : number , entropy : Uint8Array , signature : Uint8Array ) : void {
409- this . wasm . add_paygo_attestation ( outputIndex , entropy , signature ) ;
417+ this . _wasm . add_paygo_attestation ( outputIndex , entropy , signature ) ;
410418 }
411419
412420 /**
@@ -448,12 +456,12 @@ export class BitGoPsbt {
448456 // Try to parse as BIP32Arg first (string or BIP32 instance)
449457 if ( typeof key === "string" || ( "derive" in key && typeof key . derive === "function" ) ) {
450458 const wasmKey = BIP32 . from ( key as BIP32Arg ) . wasm ;
451- return this . wasm . verify_signature_with_xpub ( inputIndex , wasmKey ) ;
459+ return this . _wasm . verify_signature_with_xpub ( inputIndex , wasmKey ) ;
452460 }
453461
454462 // Otherwise it's an ECPairArg (Uint8Array, ECPair, or WasmECPair)
455463 const wasmECPair = ECPair . from ( key as ECPairArg ) . wasm ;
456- return this . wasm . verify_signature_with_pub ( inputIndex , wasmECPair ) ;
464+ return this . _wasm . verify_signature_with_pub ( inputIndex , wasmECPair ) ;
457465 }
458466
459467 /**
@@ -508,11 +516,11 @@ export class BitGoPsbt {
508516 ) {
509517 // It's a BIP32Arg
510518 const wasmKey = BIP32 . from ( key as BIP32Arg ) ;
511- this . wasm . sign_with_xpriv ( inputIndex , wasmKey . wasm ) ;
519+ this . _wasm . sign_with_xpriv ( inputIndex , wasmKey . wasm ) ;
512520 } else {
513521 // It's an ECPairArg
514522 const wasmKey = ECPair . from ( key as ECPairArg ) ;
515- this . wasm . sign_with_privkey ( inputIndex , wasmKey . wasm ) ;
523+ this . _wasm . sign_with_privkey ( inputIndex , wasmKey . wasm ) ;
516524 }
517525 }
518526
@@ -540,8 +548,8 @@ export class BitGoPsbt {
540548 inputIndex : number ,
541549 replayProtection : ReplayProtectionArg ,
542550 ) : boolean {
543- const rp = ReplayProtection . from ( replayProtection , this . wasm . network ( ) ) ;
544- return this . wasm . verify_replay_protection_signature ( inputIndex , rp . wasm ) ;
551+ const rp = ReplayProtection . from ( replayProtection , this . _wasm . network ( ) ) ;
552+ return this . _wasm . verify_replay_protection_signature ( inputIndex , rp . wasm ) ;
545553 }
546554
547555 /**
@@ -550,7 +558,7 @@ export class BitGoPsbt {
550558 * @returns The serialized PSBT as a byte array
551559 */
552560 serialize ( ) : Uint8Array {
553- return this . wasm . serialize ( ) ;
561+ return this . _wasm . serialize ( ) ;
554562 }
555563
556564 /**
@@ -593,7 +601,7 @@ export class BitGoPsbt {
593601 */
594602 generateMusig2Nonces ( key : BIP32Arg , sessionId ?: Uint8Array ) : void {
595603 const wasmKey = BIP32 . from ( key ) ;
596- this . wasm . generate_musig2_nonces ( wasmKey . wasm , sessionId ) ;
604+ this . _wasm . generate_musig2_nonces ( wasmKey . wasm , sessionId ) ;
597605 }
598606
599607 /**
@@ -616,7 +624,7 @@ export class BitGoPsbt {
616624 * ```
617625 */
618626 combineMusig2Nonces ( sourcePsbt : BitGoPsbt ) : void {
619- this . wasm . combine_musig2_nonces ( sourcePsbt . wasm ) ;
627+ this . _wasm . combine_musig2_nonces ( sourcePsbt . wasm ) ;
620628 }
621629
622630 /**
@@ -625,7 +633,7 @@ export class BitGoPsbt {
625633 * @throws Error if any input failed to finalize
626634 */
627635 finalizeAllInputs ( ) : void {
628- this . wasm . finalize_all_inputs ( ) ;
636+ this . _wasm . finalize_all_inputs ( ) ;
629637 }
630638
631639 /**
@@ -635,6 +643,6 @@ export class BitGoPsbt {
635643 * @throws Error if the PSBT is not fully finalized or extraction fails
636644 */
637645 extractTransaction ( ) : Uint8Array {
638- return this . wasm . extract_transaction ( ) ;
646+ return this . _wasm . extract_transaction ( ) ;
639647 }
640648}
0 commit comments