@canton-network/core-ledger-client 0.10.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,43 @@
1
1
  import { LedgerClient } from './ledger-client.js';
2
- import { SigningPublicKey, Enums_ParticipantPermission, SignedTopologyTransaction, AuthorizeResponse, GenerateTransactionsResponse } from '@canton-network/core-ledger-proto';
3
2
  import { PartyId } from '@canton-network/core-types';
3
+ import { SigningPublicKey, Enums_ParticipantPermission, SignedTopologyTransaction, AuthorizeResponse, GenerateTransactionsResponse } from '@canton-network/core-ledger-proto';
4
+ export interface TlsOptions {
5
+ rootCert?: string | Buffer;
6
+ clientCert?: string | Buffer;
7
+ clientKey?: string | Buffer;
8
+ mutual?: boolean;
9
+ }
10
+ export interface GrpcClientOptions {
11
+ useTls?: boolean;
12
+ tls: TlsOptions;
13
+ }
4
14
  export declare class TopologyWriteService {
15
+ private synchronizerId;
5
16
  private userAdminToken;
6
17
  private topologyClient;
7
18
  private topologyReadService;
8
19
  private ledgerClient;
9
- private store;
10
- constructor(synchronizerId: string, userAdminUrl: string, userAdminToken: string, ledgerClient: LedgerClient);
20
+ private storeId;
21
+ constructor(synchronizerId: string, userAdminUrl: string, userAdminToken: string, ledgerClient: LedgerClient, grpcClientOptions?: GrpcClientOptions);
11
22
  static combineHashes(hashes: Buffer[]): string;
12
- static createFingerprintFromKey: (publicKey: SigningPublicKey | string) => string;
23
+ static createFingerprintFromKey(publicKey: string): string;
24
+ /** @deprecated using the protobuf publickey is no longer supported -- use the string parameter instead */
25
+ static createFingerprintFromKey(publicKey: SigningPublicKey): string;
26
+ /** @deprecated using the protobuf publickey is no longer supported -- use the string parameter instead */
27
+ static createFingerprintFromKey(publicKey: SigningPublicKey | string): string;
28
+ /** @deprecated only for grpc/protobuf implementation */
13
29
  static toSignedTopologyTransaction(txHashes: Buffer<ArrayBuffer>[], serializedTransaction: Uint8Array<ArrayBufferLike>, signature: string, namespace: string): SignedTopologyTransaction;
30
+ /** @deprecated */
14
31
  private generateTransactionsRequest;
32
+ /** @deprecated use allocateExternalParty() instead */
15
33
  submitExternalPartyTopology(signedTopologyTxs: SignedTopologyTransaction[], partyId: PartyId): Promise<void>;
34
+ /** @deprecated use generateTopology() */
16
35
  generateTransactions(publicKey: string, partyId: PartyId, confirmingThreshold?: number, hostingParticipantRights?: Map<string, Enums_ParticipantPermission>): Promise<GenerateTransactionsResponse>;
36
+ /** @deprecated */
17
37
  private addTransactions;
38
+ /** @deprecated */
18
39
  waitForPartyToParticipantProposal(partyId: PartyId): Promise<Uint8Array | undefined>;
40
+ /** @deprecated */
19
41
  authorizePartyToParticipant(partyId: PartyId): Promise<AuthorizeResponse>;
20
42
  }
21
43
  //# sourceMappingURL=topology-write-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"topology-write-service.d.ts","sourceRoot":"","sources":["../src/topology-write-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAIH,gBAAgB,EAOhB,2BAA2B,EAM3B,yBAAyB,EAMzB,iBAAiB,EAGjB,4BAA4B,EAK/B,MAAM,mCAAmC,CAAA;AAI1C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AA6BpD,qBAAa,oBAAoB;IAUzB,OAAO,CAAC,cAAc;IAT1B,OAAO,CAAC,cAAc,CAAmC;IACzD,OAAO,CAAC,mBAAmB,CAAkC;IAC7D,OAAO,CAAC,YAAY,CAAc;IAElC,OAAO,CAAC,KAAK,CAAS;gBAGlB,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EAC9B,YAAY,EAAE,YAAY;IAuB9B,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;IAgC9C,MAAM,CAAC,wBAAwB,GAC3B,WAAW,gBAAgB,GAAG,MAAM,KACrC,MAAM,CAeR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IAkCxC,kBAAkB;YACJ,eAAe;IAgB7B,kBAAkB;IACZ,iCAAiC,CACnC,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAiClC,kBAAkB;IACZ,2BAA2B,CAC7B,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,iBAAiB,CAAC;CAqBhC"}
@@ -1,15 +1,19 @@
1
1
  // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
+ import { createHash } from 'node:crypto';
3
4
  import { CryptoKeyFormat, SigningKeyScheme, SigningKeySpec, Signature, SignatureFormat, SigningAlgorithmSpec, TopologyManagerWriteServiceClient, StoreId, StoreId_Synchronizer, Enums_ParticipantPermission, Enums_TopologyChangeOp, NamespaceDelegation, PartyToKeyMapping, PartyToParticipant, PartyToParticipant_HostingParticipant, SignedTopologyTransaction, TopologyMapping, MultiTransactionSignatures, AddTransactionsRequest, AuthorizeRequest, GenerateTransactionsRequest, GenerateTransactionsRequest_Proposal, BaseQuery, ListPartyToParticipantRequest, Empty, TopologyManagerReadServiceClient, } from '@canton-network/core-ledger-proto';
4
5
  import { GrpcTransport } from '@protobuf-ts/grpc-transport';
5
6
  import { ChannelCredentials } from '@grpc/grpc-js';
6
- import { createHash } from 'node:crypto';
7
+ import fs from 'fs';
7
8
  function prefixedInt(value, bytes) {
8
9
  const buffer = Buffer.alloc(4 + bytes.length);
9
10
  buffer.writeUInt32BE(value, 0);
10
11
  Buffer.from(bytes).copy(buffer, 4);
11
12
  return buffer;
12
13
  }
14
+ /**
15
+ * @deprecated used only to convert public key into grpc protobuf representation
16
+ */
13
17
  function signingPublicKeyFromEd25519(publicKey) {
14
18
  return {
15
19
  format: CryptoKeyFormat.RAW,
@@ -25,30 +29,60 @@ function computeSha256CantonHash(purpose, bytes) {
25
29
  const multiprefix = Buffer.from([0x12, 0x20]);
26
30
  return Buffer.concat([multiprefix, hash]).toString('hex');
27
31
  }
28
- // TODO(#180): remove or rewrite after grpc is gone
32
+ function createGrpcTransport(options) {
33
+ const { useTls = false, tls } = options;
34
+ if (useTls) {
35
+ const readMaybeFile = (value) => typeof value === 'string' ? fs.readFileSync(value) : value;
36
+ const rootCert = readMaybeFile(tls?.rootCert);
37
+ const clientCert = readMaybeFile(tls?.clientCert);
38
+ const clientKey = readMaybeFile(tls?.clientKey);
39
+ if (tls?.mutual) {
40
+ if (!clientCert || !clientKey) {
41
+ throw new Error('mTLS enabled but clientCert or clientKey are missing');
42
+ }
43
+ return ChannelCredentials.createSsl(rootCert, clientKey, clientCert);
44
+ }
45
+ else {
46
+ return ChannelCredentials.createSsl(rootCert);
47
+ }
48
+ }
49
+ else {
50
+ return ChannelCredentials.createInsecure();
51
+ }
52
+ }
29
53
  export class TopologyWriteService {
54
+ synchronizerId;
30
55
  userAdminToken;
31
56
  topologyClient;
32
57
  topologyReadService;
33
58
  ledgerClient;
34
- store;
35
- constructor(synchronizerId, userAdminUrl, userAdminToken, ledgerClient) {
59
+ storeId = () => StoreId.create({
60
+ store: {
61
+ oneofKind: 'synchronizer',
62
+ synchronizer: StoreId_Synchronizer.create({
63
+ id: this.synchronizerId,
64
+ }),
65
+ },
66
+ });
67
+ constructor(synchronizerId, userAdminUrl, userAdminToken, ledgerClient, grpcClientOptions) {
68
+ this.synchronizerId = synchronizerId;
36
69
  this.userAdminToken = userAdminToken;
37
- const transport = new GrpcTransport({
38
- host: userAdminUrl,
39
- channelCredentials: ChannelCredentials.createInsecure(),
40
- });
70
+ let transport;
71
+ if (grpcClientOptions) {
72
+ transport = new GrpcTransport({
73
+ host: userAdminUrl,
74
+ channelCredentials: createGrpcTransport(grpcClientOptions),
75
+ });
76
+ }
77
+ else {
78
+ transport = new GrpcTransport({
79
+ host: userAdminUrl,
80
+ channelCredentials: ChannelCredentials.createInsecure(),
81
+ });
82
+ }
41
83
  this.topologyClient = new TopologyManagerWriteServiceClient(transport);
42
84
  this.topologyReadService = new TopologyManagerReadServiceClient(transport);
43
85
  this.ledgerClient = ledgerClient;
44
- this.store = StoreId.create({
45
- store: {
46
- oneofKind: 'synchronizer',
47
- synchronizer: StoreId_Synchronizer.create({
48
- id: synchronizerId,
49
- }),
50
- },
51
- });
52
86
  }
53
87
  static combineHashes(hashes) {
54
88
  // Sort the hashes by their hex representation
@@ -72,7 +106,7 @@ export class TopologyWriteService {
72
106
  //convert to base64
73
107
  return Buffer.from(predefineHashPurpose, 'hex').toString('base64');
74
108
  }
75
- static createFingerprintFromKey = (publicKey) => {
109
+ static createFingerprintFromKey(publicKey) {
76
110
  let key;
77
111
  if (typeof publicKey === 'string') {
78
112
  key = signingPublicKeyFromEd25519(publicKey);
@@ -85,7 +119,8 @@ export class TopologyWriteService {
85
119
  const hashPurpose = 12; // For `PublicKeyFingerprint`
86
120
  // Implementation for creating a fingerprint from the public key
87
121
  return computeSha256CantonHash(hashPurpose, key.publicKey);
88
- };
122
+ }
123
+ /** @deprecated only for grpc/protobuf implementation */
89
124
  static toSignedTopologyTransaction(txHashes, serializedTransaction, signature, namespace) {
90
125
  return SignedTopologyTransaction.create({
91
126
  transaction: serializedTransaction,
@@ -106,6 +141,7 @@ export class TopologyWriteService {
106
141
  ],
107
142
  });
108
143
  }
144
+ /** @deprecated */
109
145
  generateTransactionsRequest(namespace, partyId, publicKey, confirmingThreshold = 1, hostingParticipantRights) {
110
146
  // Implementation for generating transactions request
111
147
  const namespaceDelegation = TopologyMapping.create({
@@ -153,15 +189,17 @@ export class TopologyWriteService {
153
189
  ].map((mapping) => GenerateTransactionsRequest_Proposal.create({
154
190
  mapping,
155
191
  serial: 1,
156
- store: this.store,
192
+ store: this.storeId(),
157
193
  operation: Enums_TopologyChangeOp.ADD_REPLACE,
158
194
  })),
159
195
  });
160
196
  }
197
+ /** @deprecated use allocateExternalParty() instead */
161
198
  async submitExternalPartyTopology(signedTopologyTxs, partyId) {
162
199
  await this.addTransactions(signedTopologyTxs);
163
200
  await this.authorizePartyToParticipant(partyId);
164
201
  }
202
+ /** @deprecated use generateTopology() */
165
203
  async generateTransactions(publicKey, partyId, confirmingThreshold = 1, hostingParticipantRights) {
166
204
  const signingPublicKey = signingPublicKeyFromEd25519(publicKey);
167
205
  const namespace = TopologyWriteService.createFingerprintFromKey(signingPublicKey);
@@ -181,11 +219,12 @@ export class TopologyWriteService {
181
219
  },
182
220
  }).response;
183
221
  }
222
+ /** @deprecated */
184
223
  async addTransactions(signedTopologyTxs) {
185
224
  const request = AddTransactionsRequest.create({
186
225
  transactions: signedTopologyTxs,
187
226
  forceChanges: [],
188
- store: this.store,
227
+ store: this.storeId(),
189
228
  });
190
229
  return this.topologyClient.addTransactions(request, {
191
230
  meta: {
@@ -193,13 +232,14 @@ export class TopologyWriteService {
193
232
  },
194
233
  }).response;
195
234
  }
235
+ /** @deprecated */
196
236
  async waitForPartyToParticipantProposal(partyId) {
237
+ let counter = 0;
197
238
  return new Promise((resolve, reject) => {
198
239
  const interval = setInterval(async () => {
199
- let counter = 0;
200
240
  const result = await this.topologyReadService.listPartyToParticipant(ListPartyToParticipantRequest.create({
201
241
  baseQuery: BaseQuery.create({
202
- store: this.store,
242
+ store: this.storeId(),
203
243
  proposals: true,
204
244
  timeQuery: {
205
245
  oneofKind: 'headState',
@@ -220,6 +260,7 @@ export class TopologyWriteService {
220
260
  }, 1000);
221
261
  });
222
262
  }
263
+ /** @deprecated */
223
264
  async authorizePartyToParticipant(partyId) {
224
265
  const hash = await this.waitForPartyToParticipantProposal(partyId);
225
266
  if (!hash) {
@@ -231,7 +272,7 @@ export class TopologyWriteService {
231
272
  transactionHash: Buffer.from(hash).toString('hex'),
232
273
  },
233
274
  mustFullyAuthorize: false,
234
- store: this.store,
275
+ store: this.storeId(),
235
276
  });
236
277
  return this.topologyClient.authorize(request, {
237
278
  meta: {
@@ -7,7 +7,8 @@ export declare class TransactionParser {
7
7
  private readonly ledgerClient;
8
8
  private readonly partyId;
9
9
  private readonly transaction;
10
- constructor(transaction: JsTransaction, ledgerClient: LedgerClient, partyId: PartyId);
10
+ private readonly isMasterUser;
11
+ constructor(transaction: JsTransaction, ledgerClient: LedgerClient, partyId: PartyId, isMasterUser: boolean);
11
12
  parseTransaction(): Promise<Transaction>;
12
13
  private parseEvents;
13
14
  private parseRawCreate;
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/txparse/parser.ts"],"names":[],"mappings":"AAuBA,OAAO,EAOH,WAAW,EAId,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAMpD,KAAK,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAA;AAI3D,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;gBAGvC,WAAW,EAAE,aAAa,EAC1B,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,OAAO;IAOd,gBAAgB,IAAI,OAAO,CAAC,WAAW,CAAC;YAYhC,WAAW;IAyDzB,OAAO,CAAC,cAAc;YAkBR,eAAe;IA4B7B,OAAO,CAAC,aAAa;YA4FP,aAAa;YAgFb,cAAc;YAsBd,aAAa;YAuFb,eAAe;YAmCf,oCAAoC;YA4DpC,UAAU;YAsBV,WAAW;YAuGX,mBAAmB;CAoDpC"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/txparse/parser.ts"],"names":[],"mappings":"AAqBA,OAAO,EAOH,WAAW,EAId,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAA;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAUpD,KAAK,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAAA;AAI3D,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAC3C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAGlC,WAAW,EAAE,aAAa,EAC1B,YAAY,EAAE,YAAY,EAC1B,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,OAAO;IAQnB,gBAAgB,IAAI,OAAO,CAAC,WAAW,CAAC;YAYhC,WAAW;IAyDzB,OAAO,CAAC,cAAc;YAkBR,eAAe;IA4B7B,OAAO,CAAC,aAAa;YA4FP,aAAa;YAgFb,cAAc;YAsBd,aAAa;YA0Fb,eAAe;YAmCf,oCAAoC;YA4DpC,UAAU;YAsBV,WAAW;YAuGX,mBAAmB;CAqDpC"}
@@ -1,18 +1,21 @@
1
1
  // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  /* eslint-disable @typescript-eslint/no-explicit-any */
4
- import { ensureInterfaceViewIsPresent, filtersByParty, getInterfaceView, getKnownInterfaceView, getMetaKeyValue, hasInterface, mergeMetas, removeParsedMetaKeys, } from '../ledger-api-utils.js';
5
- import { BurnedMetaKey, HoldingInterface, matchInterfaceIds, ReasonMetaKey, SenderMetaKey, TransferInstructionInterface, TxKindMetaKey, } from '../constants.js';
4
+ import { ensureInterfaceViewIsPresent, getInterfaceView, getKnownInterfaceView, getMetaKeyValue, hasInterface, mergeMetas, removeParsedMetaKeys, EventFilterBySetup, } from '../ledger-api-utils.js';
5
+ import { BurnedMetaKey, matchInterfaceIds, ReasonMetaKey, SenderMetaKey, TxKindMetaKey, } from '../constants.js';
6
6
  import { EmptyHoldingsChangeSummary, } from './types.js';
7
7
  import BigNumber from 'bignumber.js';
8
+ import { HOLDING_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID, } from '@canton-network/core-token-standard';
8
9
  export class TransactionParser {
9
10
  ledgerClient;
10
11
  partyId;
11
12
  transaction;
12
- constructor(transaction, ledgerClient, partyId) {
13
+ isMasterUser;
14
+ constructor(transaction, ledgerClient, partyId, isMasterUser) {
13
15
  this.ledgerClient = ledgerClient;
14
16
  this.partyId = partyId;
15
17
  this.transaction = transaction;
18
+ this.isMasterUser = isMasterUser;
16
19
  }
17
20
  async parseTransaction() {
18
21
  const tx = this.transaction;
@@ -255,11 +258,11 @@ export class TransactionParser {
255
258
  throw new Error(`Unknown tx-kind '${txKind}' in ${JSON.stringify(exercisedEvent)}`);
256
259
  }
257
260
  }
258
- async buildTransfer(exercisedEvent, tokenStandardChoice, senderFromTransferInstruction) {
259
- const meta = mergeMetas(exercisedEvent);
261
+ async buildTransfer(exercisedEvent, tokenStandardChoice, transferInstructions) {
262
+ const meta = mergeMetas(exercisedEvent, transferInstructions?.transfer?.meta);
260
263
  const reason = getMetaKeyValue(ReasonMetaKey, meta);
261
264
  const choiceArgumentTransfer = exercisedEvent.choiceArgument.transfer;
262
- const sender = senderFromTransferInstruction ||
265
+ const sender = transferInstructions?.transfer?.sender ||
263
266
  getMetaKeyValue(SenderMetaKey, meta) ||
264
267
  choiceArgumentTransfer.sender;
265
268
  if (!sender) {
@@ -358,7 +361,7 @@ export class TransactionParser {
358
361
  // but will not see the create of a TransferInstruction.
359
362
  return null;
360
363
  }
361
- const transferInstructionView = ensureInterfaceViewIsPresent(transferInstructionEvents.created.createdEvent, TransferInstructionInterface).viewValue;
364
+ const transferInstructionView = ensureInterfaceViewIsPresent(transferInstructionEvents.created.createdEvent, TRANSFER_INSTRUCTION_INTERFACE_ID).viewValue;
362
365
  const transferInstruction = {
363
366
  originalInstructionCid: transferInstructionView.originalInstructionCid,
364
367
  transfer: transferInstructionView.transfer,
@@ -375,7 +378,7 @@ export class TransactionParser {
375
378
  result = await this.buildMergeSplit(exercisedEvent, tokenStandardChoice);
376
379
  break;
377
380
  case 'TransferInstructionResult_Completed':
378
- result = await this.buildTransfer(exercisedEvent, tokenStandardChoice, transferInstruction.transfer.sender);
381
+ result = await this.buildTransfer(exercisedEvent, tokenStandardChoice, transferInstruction);
379
382
  break;
380
383
  default:
381
384
  throw new Error(`Unknown TransferInstructionResult: ${exerciseResultOutputTag}`);
@@ -409,10 +412,10 @@ export class TransactionParser {
409
412
  .filter(({ nodeId }) => nodeId > exercisedEvent.nodeId &&
410
413
  nodeId <= exercisedEvent.lastDescendantNodeId);
411
414
  if (exercisedEvent.consuming &&
412
- hasInterface(HoldingInterface, exercisedEvent)) {
415
+ hasInterface(HOLDING_INTERFACE_ID, exercisedEvent)) {
413
416
  const selfEvent = await this.getEventsForArchive(exercisedEvent);
414
417
  if (selfEvent) {
415
- const holdingView = ensureInterfaceViewIsPresent(selfEvent.created.createdEvent, HoldingInterface).viewValue;
418
+ const holdingView = ensureInterfaceViewIsPresent(selfEvent.created.createdEvent, HOLDING_INTERFACE_ID).viewValue;
416
419
  mutatingResult.archives.push({
417
420
  amount: holdingView.amount,
418
421
  instrumentId: holdingView.instrumentId,
@@ -427,7 +430,7 @@ export class TransactionParser {
427
430
  if (createdEvent) {
428
431
  const interfaceView = getInterfaceView(createdEvent);
429
432
  if (interfaceView &&
430
- matchInterfaceIds(HoldingInterface, interfaceView.interfaceId)) {
433
+ matchInterfaceIds(HOLDING_INTERFACE_ID, interfaceView.interfaceId)) {
431
434
  const holdingView = interfaceView.viewValue;
432
435
  mutatingResult.creates.push({
433
436
  amount: holdingView.amount,
@@ -440,13 +443,13 @@ export class TransactionParser {
440
443
  }
441
444
  }
442
445
  else if ((archivedEvent &&
443
- hasInterface(HoldingInterface, archivedEvent)) ||
446
+ hasInterface(HOLDING_INTERFACE_ID, archivedEvent)) ||
444
447
  (exercisedEvent &&
445
448
  exercisedEvent.consuming &&
446
- hasInterface(HoldingInterface, exercisedEvent))) {
449
+ hasInterface(HOLDING_INTERFACE_ID, exercisedEvent))) {
447
450
  const contractEvents = await this.getEventsForArchive(archivedEvent || exercisedEvent);
448
451
  if (contractEvents) {
449
- const holdingView = ensureInterfaceViewIsPresent(contractEvents.created?.createdEvent, HoldingInterface).viewValue;
452
+ const holdingView = ensureInterfaceViewIsPresent(contractEvents.created?.createdEvent, HOLDING_INTERFACE_ID).viewValue;
450
453
  mutatingResult.archives.push({
451
454
  amount: holdingView.amount,
452
455
  instrumentId: holdingView.instrumentId,
@@ -471,10 +474,11 @@ export class TransactionParser {
471
474
  }
472
475
  const basePayload = {
473
476
  contractId: archivedEvent.contractId,
474
- eventFormat: {
475
- filtersByParty: filtersByParty(this.partyId, [HoldingInterface, TransferInstructionInterface], true),
476
- verbose: false,
477
- },
477
+ eventFormat: EventFilterBySetup([HOLDING_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID], {
478
+ isMasterUser: this.isMasterUser,
479
+ partyId: this.partyId,
480
+ verbose: true,
481
+ }),
478
482
  };
479
483
  const payload = this.ledgerClient.getCurrentClientVersion() === '3.3'
480
484
  ? { ...basePayload, requestingParties: [] }
@@ -41,7 +41,7 @@ describe('TransactionParser', () => {
41
41
  synchronizerId: 'sync-1',
42
42
  events: [],
43
43
  };
44
- const parser = new TransactionParser(tx, mockLedgerClient, partyId);
44
+ const parser = new TransactionParser(tx, mockLedgerClient, partyId, false);
45
45
  const parsed = await parser.parseTransaction();
46
46
  const expected = {
47
47
  updateId: 'update-1',
@@ -56,7 +56,7 @@ describe('TransactionParser', () => {
56
56
  it('parses the full mock input and matches the expected output from JSON fixtures', async () => {
57
57
  const partyId = 'alice::normalized';
58
58
  const actual = await Promise.all(txsMock.map((txMock) => {
59
- const parser = new TransactionParser(txMock, mockLedgerClient, partyId);
59
+ const parser = new TransactionParser(txMock, mockLedgerClient, partyId, false);
60
60
  return parser.parseTransaction();
61
61
  }));
62
62
  expect(actual).toEqual(txsExpected);
@@ -84,7 +84,7 @@ describe('TransactionParser', () => {
84
84
  },
85
85
  ],
86
86
  };
87
- const parser = new TransactionParser(tx, mockLedgerClient, partyId);
87
+ const parser = new TransactionParser(tx, mockLedgerClient, partyId, false);
88
88
  const parsed = await parser.parseTransaction();
89
89
  expect(parsed.events).toEqual([]);
90
90
  // ensure we actually tried to fetch and got the 404 path
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canton-network/core-ledger-client",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "type": "module",
5
5
  "description": "Provides a TypeScript Canton Network ledger client, generated by the OpenAPI spec",
6
6
  "repository": "github:hyperledger-labs/splice-wallet-kernel",
@@ -28,14 +28,12 @@
28
28
  "typescript": "^5.8.3"
29
29
  },
30
30
  "dependencies": {
31
- "@canton-network/core-ledger-proto": "^0.6.0",
32
- "@canton-network/core-splice-client": "^0.7.0",
33
- "@canton-network/core-token-standard": "^0.6.0",
34
- "@canton-network/core-types": "^0.5.0",
35
- "@grpc/grpc-js": "^1.13.4",
31
+ "@canton-network/core-ledger-proto": "^0.8.0",
32
+ "@canton-network/core-splice-client": "^0.9.0",
33
+ "@canton-network/core-token-standard": "^0.8.0",
34
+ "@canton-network/core-types": "^0.7.0",
35
+ "@grpc/grpc-js": "^1.14.0",
36
36
  "@protobuf-ts/grpc-transport": "^2.11.1",
37
- "@protobuf-ts/runtime": "^2.11.1",
38
- "@protobuf-ts/runtime-rpc": "^2.11.1",
39
37
  "bignumber.js": "^9.2.1",
40
38
  "dayjs": "^1.11.13",
41
39
  "openapi-fetch": "^0.14.0",