Skip to content

Commit 46f56d7

Browse files
committed
feat: added createAccount intent for canton wallet init
Ticket: COIN-6101
1 parent 40dae3b commit 46f56d7

File tree

6 files changed

+74
-0
lines changed

6 files changed

+74
-0
lines changed

modules/sdk-coin-canton/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
22
.idea/
33
dist/
4+
.DS_Store

modules/sdk-coin-canton/src/canton.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export class Canton extends BaseCoin {
6565
return multisigTypes.tss;
6666
}
6767

68+
/** inherited doc */
69+
requiresWalletInitializationTransaction(): boolean {
70+
return true;
71+
}
72+
6873
getMPCAlgorithm(): MPCAlgorithm {
6974
return 'eddsa';
7075
}

modules/sdk-core/src/bitgo/baseCoin/baseCoin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,14 @@ export abstract class BaseCoin implements IBaseCoin {
381381
return false;
382382
}
383383

384+
/**
385+
* Check whether a coin requires wallet initialization
386+
* @returns {boolean}
387+
*/
388+
requiresWalletInitializationTransaction(): boolean {
389+
return false;
390+
}
391+
384392
/**
385393
* Check whether a coin supports signing of Typed data
386394
* @returns {boolean}

modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,5 @@ export interface IBaseCoin {
604604
* @param {string} params.multiSigType - The type of multisig (e.g. 'onchain' or 'tss')
605605
*/
606606
assertIsValidKey({ publicKey, encryptedPrv, walletPassphrase, multiSigType }: AuditKeyParams): void;
607+
requiresWalletInitializationTransaction(): boolean;
607608
}

modules/sdk-core/src/bitgo/wallet/iWallet.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,11 @@ export type SendNFTResult = {
893893
pendingApproval: PendingApprovalData;
894894
};
895895

896+
export type WalletInitResult = {
897+
success: PrebuildTransactionResult[];
898+
failure: Error[];
899+
};
900+
896901
export interface IWallet {
897902
bitgo: BitGoBase;
898903
baseCoin: IBaseCoin;
@@ -985,6 +990,7 @@ export interface IWallet {
985990
buildTokenEnablements(params?: BuildTokenEnablementOptions): Promise<PrebuildTransactionResult[]>;
986991
sendTokenEnablement(params?: PrebuildAndSignTransactionOptions): Promise<any>;
987992
sendTokenEnablements(params?: BuildTokenEnablementOptions): Promise<any>;
993+
sendWalletInitialization(params?: PrebuildTransactionOptions): Promise<WalletInitResult>;
988994
signMessage(params: WalletSignMessageOptions): Promise<SignedMessage>;
989995
buildSignMessageRequest(params: WalletSignMessageOptions): Promise<TxRequest>;
990996
signTypedData(params: WalletSignTypedDataOptions): Promise<SignedMessage>;

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ import {
123123
WalletSignTypedDataOptions,
124124
WalletType,
125125
BuildTokenApprovalResponse,
126+
WalletInitResult,
126127
} from './iWallet';
127128

128129
const 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

Comments
 (0)