Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions modules/sdk-coin-canton/src/lib/iface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface IPublicKey {
}

export interface WalletInitRequest {
synchronizer: string;
partyHint: string;
publicKey: IPublicKey;
localParticipantObservationOnly: boolean;
Expand All @@ -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[];
}
86 changes: 2 additions & 84 deletions modules/sdk-coin-canton/src/lib/oneStepPreApprovalBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoinConfig>) {
super(_coinConfig);
}
Expand All @@ -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
Expand All @@ -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
*
Expand All @@ -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.
*
Expand All @@ -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: [],
};
}

Expand All @@ -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');
}
}
18 changes: 0 additions & 18 deletions modules/sdk-coin-canton/src/lib/walletInitBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down
6 changes: 0 additions & 6 deletions modules/sdk-coin-canton/test/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down