Skip to content

Commit ad46a25

Browse files
committed
feat: handling new type of intents in prebuild
Ticket: COIN-6265
1 parent cdda048 commit ad46a25

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import {
1515
VerifyTransactionOptions,
1616
TransactionExplanation as BaseTransactionExplanation,
1717
BaseTransaction,
18+
PopulatedIntent,
19+
PrebuildTransactionWithIntentOptions,
1820
} from '@bitgo/sdk-core';
1921
import { auditEddsaPrivateKey } from '@bitgo/sdk-lib-mpc';
2022
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
@@ -173,4 +175,11 @@ export class Canton extends BaseCoin {
173175
}
174176
auditEddsaPrivateKey(prv, publicKey ?? '');
175177
}
178+
179+
/** @inheritDoc */
180+
setCoinSpecificFieldsInIntent(intent: PopulatedIntent, params: PrebuildTransactionWithIntentOptions): void {
181+
if (params.txRequestId) {
182+
intent.txRequestId = params.txRequestId;
183+
}
184+
}
176185
}

modules/sdk-core/src/bitgo/utils/mpcUtils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,21 @@ export abstract class MpcUtils {
137137
);
138138
}
139139

140-
if (!['acceleration', 'fillNonce', 'transferToken', 'tokenApproval', 'customTx'].includes(params.intentType)) {
140+
if (['transferAccept', 'transferReject'].includes(params.intentType) && baseCoin.getFamily() === 'canton') {
141+
assert(params.txRequestId, `'txRequestId' is required parameter for ${params.intentType} intent`);
142+
}
143+
144+
if (
145+
![
146+
'acceleration',
147+
'fillNonce',
148+
'transferToken',
149+
'tokenApproval',
150+
'customTx',
151+
'transferAccept',
152+
'transferReject',
153+
].includes(params.intentType)
154+
) {
141155
assert(params.recipients, `'recipients' is a required parameter for ${params.intentType} intent`);
142156
}
143157
const intentRecipients = params.recipients?.map((recipient) => {

modules/sdk-core/src/bitgo/utils/tss/baseTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ export interface PrebuildTransactionWithIntentOptions extends IntentOptionsBase
268268
functionArguments?: any[];
269269
abi?: any;
270270
};
271+
txRequestId?: string;
271272
}
272273
export interface IntentRecipient {
273274
address: {
@@ -336,6 +337,7 @@ export interface PopulatedIntent extends PopulatedIntentBase {
336337
* Custom Aptos transaction for use with the customTx intent type.
337338
*/
338339
aptosCustomTransactionParams?: aptosCustomTransactionParams;
340+
txRequestId?: string;
339341
}
340342

341343
export type TxRequestState =

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ export interface PrebuildTransactionOptions {
215215
functionArguments?: any[];
216216
abi?: any;
217217
};
218+
txRequestId?: string;
218219
}
219220

220221
export interface PrebuildAndSignTransactionOptions extends PrebuildTransactionOptions, WalletSignTransactionOptions {

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,6 +3499,30 @@ export class Wallet implements IWallet {
34993499
params.preview
35003500
);
35013501
break;
3502+
case 'transferAccept': {
3503+
txRequest = await this.tssUtils!.prebuildTxWithIntent(
3504+
{
3505+
reqId,
3506+
intentType: 'transferAccept',
3507+
txRequestId: params.txRequestId,
3508+
},
3509+
apiVersion,
3510+
params.preview
3511+
);
3512+
break;
3513+
}
3514+
case 'transferReject': {
3515+
txRequest = await this.tssUtils!.prebuildTxWithIntent(
3516+
{
3517+
reqId,
3518+
intentType: 'transferReject',
3519+
txRequestId: params.txRequestId,
3520+
},
3521+
apiVersion,
3522+
params.preview
3523+
);
3524+
break;
3525+
}
35023526
case 'customTx':
35033527
txRequest = await this.tssUtils!.prebuildTxWithIntent(
35043528
{

0 commit comments

Comments
 (0)