From b4f19cc59ca8ee80d01de958708020f32726a58d Mon Sep 17 00:00:00 2001 From: Ravi Hegde Date: Tue, 14 Oct 2025 17:00:44 +0530 Subject: [PATCH] feat(sdk-coin-canton): removed non-required fields from builders Ticket: COIN-6047 --- modules/sdk-coin-canton/src/lib/iface.ts | 19 +--- .../src/lib/oneStepPreApprovalBuilder.ts | 86 +------------------ .../src/lib/walletInitBuilder.ts | 18 ---- modules/sdk-coin-canton/test/resources.ts | 6 -- .../oneStepEnablementBuilder.ts | 28 ++---- .../builder/walletInit/walletInitBuilder.ts | 4 +- 6 files changed, 10 insertions(+), 151 deletions(-) diff --git a/modules/sdk-coin-canton/src/lib/iface.ts b/modules/sdk-coin-canton/src/lib/iface.ts index 4df4130d14..24a79c56bd 100644 --- a/modules/sdk-coin-canton/src/lib/iface.ts +++ b/modules/sdk-coin-canton/src/lib/iface.ts @@ -49,7 +49,6 @@ export interface IPublicKey { } export interface WalletInitRequest { - synchronizer: string; partyHint: string; publicKey: IPublicKey; localParticipantObservationOnly: boolean; @@ -58,26 +57,10 @@ export interface WalletInitRequest { observingParticipantUids: string[]; } -interface PreApprovalCreateCommand { - templateId: string; - createArguments: { - receiver: string; - provider: string; - expectedDso: string; - }; -} - export interface OneStepEnablementRequest { commandId: string; - commands: [ - { - CreateCommand: PreApprovalCreateCommand; - } - ]; - disclosedContracts: []; - synchronizerId: string; + receiverId: string; verboseHashing: boolean; actAs: string[]; readAs: string[]; - packageIdSelectionPreference: string[]; } diff --git a/modules/sdk-coin-canton/src/lib/oneStepPreApprovalBuilder.ts b/modules/sdk-coin-canton/src/lib/oneStepPreApprovalBuilder.ts index 676c119265..7d80bfd992 100644 --- a/modules/sdk-coin-canton/src/lib/oneStepPreApprovalBuilder.ts +++ b/modules/sdk-coin-canton/src/lib/oneStepPreApprovalBuilder.ts @@ -5,12 +5,8 @@ import { TransactionBuilder } from './transactionBuilder'; import { Transaction } from './transaction/transaction'; export class OneStepPreApprovalBuilder extends TransactionBuilder { - private _synchronizerId: string; private _commandId: string; - private _templateId: string; private _receiverPartyId: string; - private _providerPartyId: string; - private _expectedDso: string; constructor(_coinConfig: Readonly) { super(_coinConfig); } @@ -32,21 +28,6 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder { this.transaction.prepareCommand = transaction; } - /** - * Sets the synchronizer ID for the pre-approval builder. - * - * @param id - The synchronizer identifier (must be a non-empty string). - * @returns The current builder instance for chaining. - * @throws Error if the synchronizer ID is empty. - */ - synchronizerId(id: string): this { - if (!id.trim()) { - throw new Error('synchronizer must be a non-empty string'); - } - this._synchronizerId = id.trim(); - return this; - } - /** * Sets the unique id for the 1-step enablement * Also sets the _id of the transaction @@ -65,21 +46,6 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder { return this; } - /** - * Sets the template id for the 1-step enablement - * - * @param id - the template if of the form `#splice-wallet:Splice.Wallet.TransferPreapproval:TransferPreapprovalProposal` - * @returns The current builder instance for chaining. - * @throws Error if id is empty. - */ - templateId(id: string): this { - if (!id.trim()) { - throw new Error('templateId must be a non-empty string'); - } - this._templateId = id.trim(); - return this; - } - /** * Sets the receiver for the 1-step enablement * @@ -95,36 +61,6 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder { return this; } - /** - * Sets the provider for the 1-step enablement - * - * @param id - the validator party id (address) - * @returns The current builder instance for chaining. - * @throws Error if id is empty. - */ - providerPartyId(id: string): this { - if (!id.trim()) { - throw new Error('providerPartyId must be a non-empty string'); - } - this._providerPartyId = id.trim(); - return this; - } - - /** - * Sets the dso id for the 1-step enablement - * - * @param id - the dso id of the validator - * @returns The current builder instance for chaining. - * @throws Error if id is empty. - */ - expectedDso(id: string): this { - if (!id.trim()) { - throw new Error('expectedDso must be a non-empty string'); - } - this._expectedDso = id.trim(); - return this; - } - /** * Builds and returns the OneStepEnablementRequest object from the builder's internal state. * @@ -139,24 +75,10 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder { return { commandId: this._commandId, - commands: [ - { - CreateCommand: { - templateId: this._templateId, - createArguments: { - receiver: this._receiverPartyId, - provider: this._providerPartyId, - expectedDso: this._expectedDso, - }, - }, - }, - ], - disclosedContracts: [], - synchronizerId: this._synchronizerId, + receiverId: this._receiverPartyId, verboseHashing: false, actAs: [this._receiverPartyId], readAs: [], - packageIdSelectionPreference: [], }; } @@ -167,11 +89,7 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder { * @throws {Error} If any required field is missing or invalid. */ private validate(): void { - if (!this._receiverPartyId) throw new Error('receiver partyId is missing'); - if (!this._providerPartyId) throw new Error('provider partyId is missing'); - if (!this._expectedDso) throw new Error('expectedDso is missing'); if (!this._commandId) throw new Error('commandId is missing'); - if (!this._templateId) throw new Error('templateId is missing'); - if (!this._synchronizerId) throw new Error('synchronizerId is missing'); + if (!this._receiverPartyId) throw new Error('receiver partyId is missing'); } } diff --git a/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts b/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts index 0eab8d7a0e..6939c5c103 100644 --- a/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts +++ b/modules/sdk-coin-canton/src/lib/walletInitBuilder.ts @@ -13,7 +13,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder { private _transaction: WalletInitTransaction; private _publicKey: IPublicKey; - private _synchronizer: string; private _partyHint: string; private _localParticipantObservationOnly = false; private _otherConfirmingParticipantUids: string[] = []; @@ -109,21 +108,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder { return this; } - /** - * Sets the synchronizer ID for the wallet initialization. - * - * @param id - The synchronizer identifier (must be a non-empty string). - * @returns The current builder instance for chaining. - * @throws Error if the synchronizer ID is empty. - */ - synchronizer(id: string): this { - if (!id.trim()) { - throw new Error('synchronizer must be a non-empty string'); - } - this._synchronizer = id.trim(); - return this; - } - /** * Sets the party hint (alias or name) used during wallet initialization. * @@ -220,7 +204,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder { this.validate(); return { publicKey: this._publicKey, - synchronizer: this._synchronizer, partyHint: this._partyHint, localParticipantObservationOnly: this._localParticipantObservationOnly, otherConfirmingParticipantUids: this._otherConfirmingParticipantUids, @@ -243,7 +226,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder { * @throws {Error} If any required field is missing or invalid. */ private validate(): void { - if (!this._synchronizer) throw new Error('Missing synchronizer'); if (!this._partyHint || this._partyHint.length > 5) throw new Error('Invalid partyHint'); if (!this._publicKey || !this._publicKey.keyData || !this._publicKey.format || !this._publicKey.keySpec) { throw new Error('Invalid publicKey'); diff --git a/modules/sdk-coin-canton/test/resources.ts b/modules/sdk-coin-canton/test/resources.ts index 01cff323de..b513d65356 100644 --- a/modules/sdk-coin-canton/test/resources.ts +++ b/modules/sdk-coin-canton/test/resources.ts @@ -34,19 +34,13 @@ export const PrepareSubmissionResponse = { }; export const WalletInitRequestData = { - synchronizer: 'global-domain::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a', partyHint: '1220b', publicKey: 'zs4J2IrVpfYNHN0bR7EHS0Fb3rETUyyu2L2QwxucPjg=', }; export const OneStepEnablement = { - synchronizer: 'global-domain::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a', partyId: 'ravi-test-party-1::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d', - validatorPartyId: 'Bitgo-devnet-validator-1::1220a0a0f60b0e62b5d750c484b18c091dba23080c133d944614ba75a5858cba3045', - templateId: '#splice-wallet:Splice.Wallet.TransferPreapproval:TransferPreapprovalProposal', - expectedDsoId: 'DSO::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a', commandId: '3935a06d-3b03-41be-99a5-95b2ecaabf7d', - synchronizerId: 'global-domain::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a', }; export const OneStepPreApprovalPrepareResponse = { diff --git a/modules/sdk-coin-canton/test/unit/builder/oneStepEnablement/oneStepEnablementBuilder.ts b/modules/sdk-coin-canton/test/unit/builder/oneStepEnablement/oneStepEnablementBuilder.ts index 9a3404804d..574c4c8502 100644 --- a/modules/sdk-coin-canton/test/unit/builder/oneStepEnablement/oneStepEnablementBuilder.ts +++ b/modules/sdk-coin-canton/test/unit/builder/oneStepEnablement/oneStepEnablementBuilder.ts @@ -18,31 +18,15 @@ describe('Wallet Pre-approval Enablement Builder', () => { const txBuilder = new OneStepPreApprovalBuilder(coins.get('tcanton')); const oneStepEnablementTx = new Transaction(coins.get('tcanton')); txBuilder.initBuilder(oneStepEnablementTx); - const { synchronizer, commandId, partyId, validatorPartyId, expectedDsoId, templateId, synchronizerId } = - OneStepEnablement; - txBuilder - .commandId(commandId) - .templateId(templateId) - .expectedDso(expectedDsoId) - .templateId(templateId) - .providerPartyId(validatorPartyId) - .receiverPartyId(partyId) - .synchronizerId(synchronizerId); + const { commandId, partyId } = OneStepEnablement; + txBuilder.commandId(commandId).receiverPartyId(partyId); const requestObj: OneStepEnablementRequest = txBuilder.toRequestObject(); should.exist(requestObj); - assert.equal(requestObj.synchronizerId, synchronizer); assert.equal(requestObj.commandId, commandId); - assert.equal(requestObj.commands.length, 1); - const command = requestObj.commands[0]; - should.exist(command); - const createCommand = command.CreateCommand; - should.exist(createCommand); - assert.equal(createCommand.templateId, templateId); - const createArguments = createCommand.createArguments; - should.exist(createArguments); - assert.equal(createArguments.expectedDso, expectedDsoId); - assert.equal(createArguments.provider, validatorPartyId); - assert.equal(createArguments.receiver, partyId); + assert.equal(requestObj.receiverId, partyId); + assert.equal(requestObj.actAs.length, 1); + const actAs = requestObj.actAs[0]; + assert.equal(actAs, partyId); }); it('should validate raw transaction', function () { diff --git a/modules/sdk-coin-canton/test/unit/builder/walletInit/walletInitBuilder.ts b/modules/sdk-coin-canton/test/unit/builder/walletInit/walletInitBuilder.ts index 1f5c92c44c..12d2ac8e34 100644 --- a/modules/sdk-coin-canton/test/unit/builder/walletInit/walletInitBuilder.ts +++ b/modules/sdk-coin-canton/test/unit/builder/walletInit/walletInitBuilder.ts @@ -12,13 +12,11 @@ import { GenerateTopologyResponse, InvalidGenerateTopologyResponse, WalletInitRe describe('Wallet Initialization Builder', () => { it('should get the wallet init request object', function () { const txBuilder = new WalletInitBuilder(coins.get('tcanton')); - const { publicKey, synchronizer, partyHint } = WalletInitRequestData; + const { publicKey, partyHint } = WalletInitRequestData; txBuilder.publicKey(publicKey); - txBuilder.synchronizer(synchronizer); txBuilder.partyHint(partyHint); const requestObj: WalletInitRequest = txBuilder.toRequestObject(); should.exist(requestObj); - assert.equal(requestObj.synchronizer, synchronizer); assert.equal(requestObj.partyHint, partyHint); assert.equal(requestObj.localParticipantObservationOnly, false); assert.equal(requestObj.confirmationThreshold, 1);