@@ -18,10 +18,11 @@ import {
1818 isStandardUnlockableUtxo ,
1919 StandardUnlockableUtxo ,
2020 VmResourceUsage ,
21- isContractUnlocker ,
22- BchChangeOutputOptions ,
23- TokenChangeOutputOptions ,
24- } from './interfaces.js' ;
21+ isContractUnlocker ,
22+ BchChangeOutputOptions ,
23+ TokenChangeOutputOptions ,
24+ isPlaceholderUnlocker ,
25+ } from './interfaces.js' ;
2526import { NetworkProvider } from './network/index.js' ;
2627import {
2728 calculateDust ,
@@ -36,7 +37,13 @@ import {
3637import { FailedTransactionError } from './Errors.js' ;
3738import { DebugResults } from './debugging.js' ;
3839import { debugLibauthTemplate , getLibauthTemplate , getBitauthUri } from './libauth-template/LibauthTemplate.js' ;
39- import { getWcContractInfo , WcSourceOutput , WcTransactionOptions } from './walletconnect-utils.js' ;
40+ import {
41+ getWcContractInfo ,
42+ WcSourceOutput ,
43+ WcTransactionOptions ,
44+ WizardConnectInputPath ,
45+ WizardConnectTransactionObject ,
46+ } from './walletconnect-utils.js' ;
4047import semver from 'semver' ;
4148import { WcTransactionObject } from './walletconnect-utils.js' ;
4249
@@ -561,9 +568,9 @@ export class TransactionBuilder {
561568 * @returns A WalletConnect transaction object ready to be sent to a WalletConnect wallet.
562569 * @throws If the transaction cannot be built (fee exceeds limit or fungible tokens burned).
563570 */
564- generateWcTransactionObject ( options ?: WcTransactionOptions ) : WcTransactionObject {
565- const encodedTransaction = this . build ( ) ;
566- const transaction = decodeTransactionUnsafe ( hexToBin ( encodedTransaction ) ) ;
571+ generateWcTransactionObject ( options ?: WcTransactionOptions ) : WcTransactionObject {
572+ const encodedTransaction = this . build ( ) ;
573+ const transaction = decodeTransactionUnsafe ( hexToBin ( encodedTransaction ) ) ;
567574
568575 const libauthSourceOutputs = generateLibauthSourceOutputs ( this . inputs ) ;
569576 const sourceOutputs : WcSourceOutput [ ] = libauthSourceOutputs . map ( ( sourceOutput , index ) => {
@@ -572,7 +579,41 @@ export class TransactionBuilder {
572579 ...transaction . inputs [ index ] ,
573580 ...getWcContractInfo ( this . inputs [ index ] ) ,
574581 } ;
575- } ) ;
576- return { ...options , transaction, sourceOutputs } ;
577- }
578- }
582+ } ) ;
583+ return { ...options , transaction, sourceOutputs } ;
584+ }
585+
586+ /**
587+ * Build the transaction and format it as a WizardConnect transaction request.
588+ *
589+ * WizardConnect uses the standard BCH WalletConnect transaction object plus HD path metadata for
590+ * each placeholder P2PKH input that the wallet must sign.
591+ *
592+ * @param options - Optional WalletConnect options such as `broadcast` and `userPrompt`.
593+ * @returns A WizardConnect transaction object ready to be sent to a WizardConnect wallet.
594+ * @throws If the transaction cannot be built, or if a placeholder input is missing HD path metadata.
595+ */
596+ generateWizardConnectTransactionObject ( options ?: WcTransactionOptions ) : WizardConnectTransactionObject {
597+ const transaction = this . generateWcTransactionObject ( options ) ;
598+ const inputPaths = this . generateWizardConnectInputPaths ( ) ;
599+
600+ return { transaction, inputPaths } ;
601+ }
602+
603+ private generateWizardConnectInputPaths ( ) : WizardConnectInputPath [ ] {
604+ const inputPaths : WizardConnectInputPath [ ] = [ ] ;
605+
606+ this . inputs . forEach ( ( input , inputIndex ) => {
607+ if ( ! isPlaceholderUnlocker ( input . unlocker ) ) return ;
608+
609+ const hdPath = input . unlocker . hdPath ;
610+ if ( ! hdPath ) {
611+ throw new Error ( `Placeholder P2PKH input ${ inputIndex } is missing WizardConnect HD path metadata` ) ;
612+ }
613+
614+ inputPaths . push ( [ inputIndex , hdPath . name , hdPath . addressIndex ] ) ;
615+ } ) ;
616+
617+ return inputPaths ;
618+ }
619+ }
0 commit comments