@@ -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,61 @@ 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 . requiresWalletInitialization ( ) ) {
3331+ throw new Error ( `Wallet initialization is not required for ${ this . baseCoin . getFullName ( ) } ` ) ;
3332+ }
3333+ if ( params . reqId ) {
3334+ this . bitgo . setRequestTracer ( params . reqId ) ;
3335+ }
3336+ const buildParams : PrebuildTransactionOptions = _ . pick ( params , this . prebuildWhitelistedParams ( ) ) ;
3337+ if ( ! buildParams . type ) {
3338+ buildParams . type = 'createAccount' ;
3339+ }
3340+ const prebuildTx = await this . prebuildTransaction ( buildParams ) ;
3341+ const unsignedBuildWithOptions : PrebuildAndSignTransactionOptions = {
3342+ ...params ,
3343+ prebuildTx,
3344+ } ;
3345+ if ( typeof params . prebuildTx === 'string' || params . prebuildTx ?. buildParams ?. type !== 'createAccount' ) {
3346+ throw new Error ( 'Invalid build of wallet init' ) ;
3347+ }
3348+ const successfulTxs : PrebuildTransactionResult [ ] = [ ] ;
3349+ const failedTxs = new Array < Error > ( ) ;
3350+ try {
3351+ if ( this . _wallet . multisigType === 'tss' ) {
3352+ const sendTx = await this . sendManyTxRequests ( unsignedBuildWithOptions ) ;
3353+ successfulTxs . push ( sendTx ) ;
3354+ } else {
3355+ switch ( this . _wallet . type ) {
3356+ case 'hot' :
3357+ case 'cold' :
3358+ const signedPrebuild = await this . prebuildAndSignTransaction ( params ) ;
3359+ const sendTxCold = await this . submitTransaction ( signedPrebuild , params . reqId ) ;
3360+ successfulTxs . push ( sendTxCold ) ;
3361+ break ;
3362+ case 'custodial' :
3363+ case 'backing' :
3364+ const sendTxCustodial = await this . initiateTransaction ( params . prebuildTx . buildParams , params . reqId ) ;
3365+ successfulTxs . push ( sendTxCustodial ) ;
3366+ break ;
3367+ }
3368+ }
3369+ } catch ( e ) {
3370+ failedTxs . push ( e ) ;
3371+ }
3372+ return {
3373+ success : successfulTxs ,
3374+ failure : failedTxs ,
3375+ } ;
3376+ }
3377+
33223378 /* MARK: TSS Helpers */
33233379
33243380 /**
@@ -3439,6 +3495,16 @@ export class Wallet implements IWallet {
34393495 params . preview
34403496 ) ;
34413497 break ;
3498+ case 'createAccount' :
3499+ txRequest = await this . tssUtils ! . prebuildTxWithIntent (
3500+ {
3501+ reqId,
3502+ intentType : 'createAccount' ,
3503+ } ,
3504+ apiVersion ,
3505+ params . preview
3506+ ) ;
3507+ break ;
34423508 case 'customTx' :
34433509 txRequest = await this . tssUtils ! . prebuildTxWithIntent (
34443510 {
0 commit comments