Skip to content

Commit 04a19ec

Browse files
authored
Merge pull request #7232 from BitGo/COIN-6047
feat(sdk-coin-canton): removed non-required fields from builders
2 parents 12f1fef + b4f19cc commit 04a19ec

File tree

6 files changed

+10
-151
lines changed

6 files changed

+10
-151
lines changed

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

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export interface IPublicKey {
4949
}
5050

5151
export interface WalletInitRequest {
52-
synchronizer: string;
5352
partyHint: string;
5453
publicKey: IPublicKey;
5554
localParticipantObservationOnly: boolean;
@@ -58,26 +57,10 @@ export interface WalletInitRequest {
5857
observingParticipantUids: string[];
5958
}
6059

61-
interface PreApprovalCreateCommand {
62-
templateId: string;
63-
createArguments: {
64-
receiver: string;
65-
provider: string;
66-
expectedDso: string;
67-
};
68-
}
69-
7060
export interface OneStepEnablementRequest {
7161
commandId: string;
72-
commands: [
73-
{
74-
CreateCommand: PreApprovalCreateCommand;
75-
}
76-
];
77-
disclosedContracts: [];
78-
synchronizerId: string;
62+
receiverId: string;
7963
verboseHashing: boolean;
8064
actAs: string[];
8165
readAs: string[];
82-
packageIdSelectionPreference: string[];
8366
}

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

Lines changed: 2 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ import { TransactionBuilder } from './transactionBuilder';
55
import { Transaction } from './transaction/transaction';
66

77
export class OneStepPreApprovalBuilder extends TransactionBuilder {
8-
private _synchronizerId: string;
98
private _commandId: string;
10-
private _templateId: string;
119
private _receiverPartyId: string;
12-
private _providerPartyId: string;
13-
private _expectedDso: string;
1410
constructor(_coinConfig: Readonly<CoinConfig>) {
1511
super(_coinConfig);
1612
}
@@ -32,21 +28,6 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder {
3228
this.transaction.prepareCommand = transaction;
3329
}
3430

35-
/**
36-
* Sets the synchronizer ID for the pre-approval builder.
37-
*
38-
* @param id - The synchronizer identifier (must be a non-empty string).
39-
* @returns The current builder instance for chaining.
40-
* @throws Error if the synchronizer ID is empty.
41-
*/
42-
synchronizerId(id: string): this {
43-
if (!id.trim()) {
44-
throw new Error('synchronizer must be a non-empty string');
45-
}
46-
this._synchronizerId = id.trim();
47-
return this;
48-
}
49-
5031
/**
5132
* Sets the unique id for the 1-step enablement
5233
* Also sets the _id of the transaction
@@ -65,21 +46,6 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder {
6546
return this;
6647
}
6748

68-
/**
69-
* Sets the template id for the 1-step enablement
70-
*
71-
* @param id - the template if of the form `#splice-wallet:Splice.Wallet.TransferPreapproval:TransferPreapprovalProposal`
72-
* @returns The current builder instance for chaining.
73-
* @throws Error if id is empty.
74-
*/
75-
templateId(id: string): this {
76-
if (!id.trim()) {
77-
throw new Error('templateId must be a non-empty string');
78-
}
79-
this._templateId = id.trim();
80-
return this;
81-
}
82-
8349
/**
8450
* Sets the receiver for the 1-step enablement
8551
*
@@ -95,36 +61,6 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder {
9561
return this;
9662
}
9763

98-
/**
99-
* Sets the provider for the 1-step enablement
100-
*
101-
* @param id - the validator party id (address)
102-
* @returns The current builder instance for chaining.
103-
* @throws Error if id is empty.
104-
*/
105-
providerPartyId(id: string): this {
106-
if (!id.trim()) {
107-
throw new Error('providerPartyId must be a non-empty string');
108-
}
109-
this._providerPartyId = id.trim();
110-
return this;
111-
}
112-
113-
/**
114-
* Sets the dso id for the 1-step enablement
115-
*
116-
* @param id - the dso id of the validator
117-
* @returns The current builder instance for chaining.
118-
* @throws Error if id is empty.
119-
*/
120-
expectedDso(id: string): this {
121-
if (!id.trim()) {
122-
throw new Error('expectedDso must be a non-empty string');
123-
}
124-
this._expectedDso = id.trim();
125-
return this;
126-
}
127-
12864
/**
12965
* Builds and returns the OneStepEnablementRequest object from the builder's internal state.
13066
*
@@ -139,24 +75,10 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder {
13975

14076
return {
14177
commandId: this._commandId,
142-
commands: [
143-
{
144-
CreateCommand: {
145-
templateId: this._templateId,
146-
createArguments: {
147-
receiver: this._receiverPartyId,
148-
provider: this._providerPartyId,
149-
expectedDso: this._expectedDso,
150-
},
151-
},
152-
},
153-
],
154-
disclosedContracts: [],
155-
synchronizerId: this._synchronizerId,
78+
receiverId: this._receiverPartyId,
15679
verboseHashing: false,
15780
actAs: [this._receiverPartyId],
15881
readAs: [],
159-
packageIdSelectionPreference: [],
16082
};
16183
}
16284

@@ -167,11 +89,7 @@ export class OneStepPreApprovalBuilder extends TransactionBuilder {
16789
* @throws {Error} If any required field is missing or invalid.
16890
*/
16991
private validate(): void {
170-
if (!this._receiverPartyId) throw new Error('receiver partyId is missing');
171-
if (!this._providerPartyId) throw new Error('provider partyId is missing');
172-
if (!this._expectedDso) throw new Error('expectedDso is missing');
17392
if (!this._commandId) throw new Error('commandId is missing');
174-
if (!this._templateId) throw new Error('templateId is missing');
175-
if (!this._synchronizerId) throw new Error('synchronizerId is missing');
93+
if (!this._receiverPartyId) throw new Error('receiver partyId is missing');
17694
}
17795
}

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder {
1313
private _transaction: WalletInitTransaction;
1414

1515
private _publicKey: IPublicKey;
16-
private _synchronizer: string;
1716
private _partyHint: string;
1817
private _localParticipantObservationOnly = false;
1918
private _otherConfirmingParticipantUids: string[] = [];
@@ -109,21 +108,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder {
109108
return this;
110109
}
111110

112-
/**
113-
* Sets the synchronizer ID for the wallet initialization.
114-
*
115-
* @param id - The synchronizer identifier (must be a non-empty string).
116-
* @returns The current builder instance for chaining.
117-
* @throws Error if the synchronizer ID is empty.
118-
*/
119-
synchronizer(id: string): this {
120-
if (!id.trim()) {
121-
throw new Error('synchronizer must be a non-empty string');
122-
}
123-
this._synchronizer = id.trim();
124-
return this;
125-
}
126-
127111
/**
128112
* Sets the party hint (alias or name) used during wallet initialization.
129113
*
@@ -220,7 +204,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder {
220204
this.validate();
221205
return {
222206
publicKey: this._publicKey,
223-
synchronizer: this._synchronizer,
224207
partyHint: this._partyHint,
225208
localParticipantObservationOnly: this._localParticipantObservationOnly,
226209
otherConfirmingParticipantUids: this._otherConfirmingParticipantUids,
@@ -243,7 +226,6 @@ export class WalletInitBuilder extends BaseTransactionBuilder {
243226
* @throws {Error} If any required field is missing or invalid.
244227
*/
245228
private validate(): void {
246-
if (!this._synchronizer) throw new Error('Missing synchronizer');
247229
if (!this._partyHint || this._partyHint.length > 5) throw new Error('Invalid partyHint');
248230
if (!this._publicKey || !this._publicKey.keyData || !this._publicKey.format || !this._publicKey.keySpec) {
249231
throw new Error('Invalid publicKey');

modules/sdk-coin-canton/test/resources.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,13 @@ export const PrepareSubmissionResponse = {
3434
};
3535

3636
export const WalletInitRequestData = {
37-
synchronizer: 'global-domain::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a',
3837
partyHint: '1220b',
3938
publicKey: 'zs4J2IrVpfYNHN0bR7EHS0Fb3rETUyyu2L2QwxucPjg=',
4039
};
4140

4241
export const OneStepEnablement = {
43-
synchronizer: 'global-domain::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a',
4442
partyId: 'ravi-test-party-1::12205b4e3537a95126d90604592344d8ad3c3ddccda4f79901954280ee19c576714d',
45-
validatorPartyId: 'Bitgo-devnet-validator-1::1220a0a0f60b0e62b5d750c484b18c091dba23080c133d944614ba75a5858cba3045',
46-
templateId: '#splice-wallet:Splice.Wallet.TransferPreapproval:TransferPreapprovalProposal',
47-
expectedDsoId: 'DSO::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a',
4843
commandId: '3935a06d-3b03-41be-99a5-95b2ecaabf7d',
49-
synchronizerId: 'global-domain::1220be58c29e65de40bf273be1dc2b266d43a9a002ea5b18955aeef7aac881bb471a',
5044
};
5145

5246
export const OneStepPreApprovalPrepareResponse = {

modules/sdk-coin-canton/test/unit/builder/oneStepEnablement/oneStepEnablementBuilder.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,15 @@ describe('Wallet Pre-approval Enablement Builder', () => {
1818
const txBuilder = new OneStepPreApprovalBuilder(coins.get('tcanton'));
1919
const oneStepEnablementTx = new Transaction(coins.get('tcanton'));
2020
txBuilder.initBuilder(oneStepEnablementTx);
21-
const { synchronizer, commandId, partyId, validatorPartyId, expectedDsoId, templateId, synchronizerId } =
22-
OneStepEnablement;
23-
txBuilder
24-
.commandId(commandId)
25-
.templateId(templateId)
26-
.expectedDso(expectedDsoId)
27-
.templateId(templateId)
28-
.providerPartyId(validatorPartyId)
29-
.receiverPartyId(partyId)
30-
.synchronizerId(synchronizerId);
21+
const { commandId, partyId } = OneStepEnablement;
22+
txBuilder.commandId(commandId).receiverPartyId(partyId);
3123
const requestObj: OneStepEnablementRequest = txBuilder.toRequestObject();
3224
should.exist(requestObj);
33-
assert.equal(requestObj.synchronizerId, synchronizer);
3425
assert.equal(requestObj.commandId, commandId);
35-
assert.equal(requestObj.commands.length, 1);
36-
const command = requestObj.commands[0];
37-
should.exist(command);
38-
const createCommand = command.CreateCommand;
39-
should.exist(createCommand);
40-
assert.equal(createCommand.templateId, templateId);
41-
const createArguments = createCommand.createArguments;
42-
should.exist(createArguments);
43-
assert.equal(createArguments.expectedDso, expectedDsoId);
44-
assert.equal(createArguments.provider, validatorPartyId);
45-
assert.equal(createArguments.receiver, partyId);
26+
assert.equal(requestObj.receiverId, partyId);
27+
assert.equal(requestObj.actAs.length, 1);
28+
const actAs = requestObj.actAs[0];
29+
assert.equal(actAs, partyId);
4630
});
4731

4832
it('should validate raw transaction', function () {

modules/sdk-coin-canton/test/unit/builder/walletInit/walletInitBuilder.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ import { GenerateTopologyResponse, InvalidGenerateTopologyResponse, WalletInitRe
1212
describe('Wallet Initialization Builder', () => {
1313
it('should get the wallet init request object', function () {
1414
const txBuilder = new WalletInitBuilder(coins.get('tcanton'));
15-
const { publicKey, synchronizer, partyHint } = WalletInitRequestData;
15+
const { publicKey, partyHint } = WalletInitRequestData;
1616
txBuilder.publicKey(publicKey);
17-
txBuilder.synchronizer(synchronizer);
1817
txBuilder.partyHint(partyHint);
1918
const requestObj: WalletInitRequest = txBuilder.toRequestObject();
2019
should.exist(requestObj);
21-
assert.equal(requestObj.synchronizer, synchronizer);
2220
assert.equal(requestObj.partyHint, partyHint);
2321
assert.equal(requestObj.localParticipantObservationOnly, false);
2422
assert.equal(requestObj.confirmationThreshold, 1);

0 commit comments

Comments
 (0)