@@ -123,6 +123,7 @@ import {
123123 WalletSignTypedDataOptions ,
124124 WalletType ,
125125 BuildTokenApprovalResponse ,
126+ WalletInitResult ,
126127} from './iWallet' ;
127128
128129const debug = require ( 'debug' ) ( 'bitgo:v2:wallet' ) ;
@@ -3319,6 +3320,48 @@ export class Wallet implements IWallet {
33193320 } ;
33203321 }
33213322
3323+ /**
3324+ * The chain canton, requires the wallet to be initialized by sending out a transaction
3325+ * to be onboarded onto the validator.
3326+ * Builds, Signs and sends a transaction that initializes the canton wallet
3327+ * @param params
3328+ */
3329+ public async sendWalletInitialization ( params : PrebuildAndSignTransactionOptions = { } ) : Promise < WalletInitResult > {
3330+ if ( ! this . baseCoin . requiresWalletInitializationTransaction ( ) ) {
3331+ throw new Error ( `Wallet initialization is not required for ${ this . baseCoin . getFullName ( ) } ` ) ;
3332+ }
3333+ if ( this . _wallet . multisigType !== 'tss' ) {
3334+ throw new Error ( 'Wallet initialization transaction is only supported for TSS wallets' ) ;
3335+ }
3336+ if ( params . reqId ) {
3337+ this . bitgo . setRequestTracer ( params . reqId ) ;
3338+ }
3339+ const buildParams : PrebuildTransactionOptions = _ . pick ( params , this . prebuildWhitelistedParams ( ) ) ;
3340+ if ( ! buildParams . type ) {
3341+ buildParams . type = 'createAccount' ;
3342+ }
3343+ const prebuildTx = await this . prebuildTransaction ( buildParams ) ;
3344+ const unsignedBuildWithOptions : PrebuildAndSignTransactionOptions = {
3345+ ...params ,
3346+ prebuildTx,
3347+ } ;
3348+ if ( typeof params . prebuildTx === 'string' || params . prebuildTx ?. buildParams ?. type !== 'createAccount' ) {
3349+ throw new Error ( 'Invalid build of wallet init' ) ;
3350+ }
3351+ const successfulTxs : PrebuildTransactionResult [ ] = [ ] ;
3352+ const failedTxs = new Array < Error > ( ) ;
3353+ try {
3354+ const sendTx = await this . sendManyTxRequests ( unsignedBuildWithOptions ) ;
3355+ successfulTxs . push ( sendTx ) ;
3356+ } catch ( e ) {
3357+ failedTxs . push ( e ) ;
3358+ }
3359+ return {
3360+ success : successfulTxs ,
3361+ failure : failedTxs ,
3362+ } ;
3363+ }
3364+
33223365 /* MARK: TSS Helpers */
33233366
33243367 /**
@@ -3439,6 +3482,16 @@ export class Wallet implements IWallet {
34393482 params . preview
34403483 ) ;
34413484 break ;
3485+ case 'createAccount' :
3486+ txRequest = await this . tssUtils ! . prebuildTxWithIntent (
3487+ {
3488+ reqId,
3489+ intentType : 'createAccount' ,
3490+ } ,
3491+ apiVersion ,
3492+ params . preview
3493+ ) ;
3494+ break ;
34423495 case 'customTx' :
34433496 txRequest = await this . tssUtils ! . prebuildTxWithIntent (
34443497 {
0 commit comments