@canton-network/core-ledger-client 0.15.0 → 0.17.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.
Files changed (44) hide show
  1. package/dist/acs/acs-container.d.ts +36 -0
  2. package/dist/acs/acs-container.d.ts.map +1 -0
  3. package/dist/acs/acs-helper.d.ts +39 -0
  4. package/dist/acs/acs-helper.d.ts.map +1 -0
  5. package/dist/acs/types.d.ts +10 -0
  6. package/dist/acs/types.d.ts.map +1 -0
  7. package/dist/acs/ws-support.d.ts +18 -0
  8. package/dist/acs/ws-support.d.ts.map +1 -0
  9. package/dist/index.cjs +3306 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.ts +3 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +3286 -7
  14. package/dist/index.js.map +1 -0
  15. package/dist/ledger-api-utils.d.ts +3 -1
  16. package/dist/ledger-api-utils.d.ts.map +1 -1
  17. package/dist/ledger-client.d.ts +32 -4
  18. package/dist/ledger-client.d.ts.map +1 -1
  19. package/dist/token-standard-service.d.ts +11 -9
  20. package/dist/token-standard-service.d.ts.map +1 -1
  21. package/dist/topology-write-service.d.ts +4 -2
  22. package/dist/topology-write-service.d.ts.map +1 -1
  23. package/dist/txparse/parser.d.ts.map +1 -1
  24. package/dist/txparse/test-data/mock/eventsByContractIdResponses.d.ts +153 -0
  25. package/dist/txparse/test-data/mock/eventsByContractIdResponses.d.ts.map +1 -1
  26. package/dist/txparse/types.d.ts +5 -2
  27. package/dist/txparse/types.d.ts.map +1 -1
  28. package/package.json +23 -11
  29. package/dist/constants.js +0 -47
  30. package/dist/generated-clients/openapi-3.3.0-SNAPSHOT.js +0 -5
  31. package/dist/generated-clients/openapi-3.4.0-SNAPSHOT.js +0 -5
  32. package/dist/ledger-api-utils.js +0 -432
  33. package/dist/ledger-client.js +0 -321
  34. package/dist/token-standard-service.js +0 -871
  35. package/dist/topology-write-service.js +0 -283
  36. package/dist/txparse/parser.js +0 -581
  37. package/dist/txparse/parser.test.d.ts +0 -2
  38. package/dist/txparse/parser.test.d.ts.map +0 -1
  39. package/dist/txparse/parser.test.js +0 -97
  40. package/dist/txparse/strict.js +0 -19
  41. package/dist/txparse/test-data/expected/txs.js +0 -2303
  42. package/dist/txparse/test-data/mock/eventsByContractIdResponses.js +0 -2973
  43. package/dist/txparse/test-data/mock/txs.js +0 -6788
  44. package/dist/txparse/types.js +0 -58
@@ -1,283 +0,0 @@
1
- // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import { createHash } from 'node:crypto';
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';
5
- import { GrpcTransport } from '@protobuf-ts/grpc-transport';
6
- import { ChannelCredentials } from '@grpc/grpc-js';
7
- import fs from 'fs';
8
- function prefixedInt(value, bytes) {
9
- const buffer = Buffer.alloc(4 + bytes.length);
10
- buffer.writeUInt32BE(value, 0);
11
- Buffer.from(bytes).copy(buffer, 4);
12
- return buffer;
13
- }
14
- /**
15
- * @deprecated used only to convert public key into grpc protobuf representation
16
- */
17
- function signingPublicKeyFromEd25519(publicKey) {
18
- return {
19
- format: CryptoKeyFormat.RAW,
20
- publicKey: Buffer.from(publicKey, 'base64'),
21
- scheme: SigningKeyScheme.ED25519,
22
- keySpec: SigningKeySpec.EC_CURVE25519,
23
- usage: [],
24
- };
25
- }
26
- function computeSha256CantonHash(purpose, bytes) {
27
- const hashInput = prefixedInt(purpose, bytes);
28
- const hash = createHash('sha256').update(hashInput).digest();
29
- const multiprefix = Buffer.from([0x12, 0x20]);
30
- return Buffer.concat([multiprefix, hash]).toString('hex');
31
- }
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
- }
53
- export class TopologyWriteService {
54
- synchronizerId;
55
- userAdminToken;
56
- topologyClient;
57
- topologyReadService;
58
- 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;
69
- this.userAdminToken = userAdminToken;
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
- }
83
- this.topologyClient = new TopologyManagerWriteServiceClient(transport);
84
- this.topologyReadService = new TopologyManagerReadServiceClient(transport);
85
- this.ledgerClient = ledgerClient;
86
- }
87
- static combineHashes(hashes) {
88
- // Sort the hashes by their hex representation
89
- const sortedHashes = hashes.sort((a, b) => a.toString('hex').localeCompare(b.toString('hex')));
90
- // Start with the number of hashes encoded as a 4-byte integer in big-endian
91
- const combinedHashes = Buffer.alloc(4);
92
- combinedHashes.writeUInt32BE(sortedHashes.length, 0);
93
- // Concatenate each hash, prefixing them with their size as a 4-byte integer in big-endian
94
- let concatenatedHashes = combinedHashes;
95
- for (const h of sortedHashes) {
96
- const lengthBuffer = Buffer.alloc(4);
97
- lengthBuffer.writeUInt32BE(h.length, 0);
98
- concatenatedHashes = Buffer.concat([
99
- concatenatedHashes,
100
- lengthBuffer,
101
- h,
102
- ]);
103
- }
104
- // 55 is the hash purpose for multi topology transaction hashes
105
- const predefineHashPurpose = computeSha256CantonHash(55, concatenatedHashes);
106
- //convert to base64
107
- return Buffer.from(predefineHashPurpose, 'hex').toString('base64');
108
- }
109
- static createFingerprintFromKey(publicKey) {
110
- let key;
111
- if (typeof publicKey === 'string') {
112
- key = signingPublicKeyFromEd25519(publicKey);
113
- }
114
- else {
115
- key = publicKey;
116
- }
117
- // Hash purpose codes can be looked up in the Canton codebase:
118
- // https://github.com/DACH-NY/canton/blob/62e9ccd3f1743d2c9422d863cfc2ca800405c71b/community/base/src/main/scala/com/digitalasset/canton/crypto/HashPurpose.scala#L52
119
- const hashPurpose = 12; // For `PublicKeyFingerprint`
120
- // Implementation for creating a fingerprint from the public key
121
- return computeSha256CantonHash(hashPurpose, key.publicKey);
122
- }
123
- /** @deprecated only for grpc/protobuf implementation */
124
- static toSignedTopologyTransaction(txHashes, serializedTransaction, signature, namespace) {
125
- return SignedTopologyTransaction.create({
126
- transaction: serializedTransaction,
127
- proposal: true,
128
- signatures: [],
129
- multiTransactionSignatures: [
130
- MultiTransactionSignatures.create({
131
- transactionHashes: txHashes,
132
- signatures: [
133
- Signature.create({
134
- format: SignatureFormat.RAW,
135
- signature: Buffer.from(signature, 'base64'),
136
- signedBy: namespace,
137
- signingAlgorithmSpec: SigningAlgorithmSpec.ED25519,
138
- }),
139
- ],
140
- }),
141
- ],
142
- });
143
- }
144
- /** @deprecated */
145
- generateTransactionsRequest(namespace, partyId, publicKey, confirmingThreshold = 1, hostingParticipantRights) {
146
- // Implementation for generating transactions request
147
- const namespaceDelegation = TopologyMapping.create({
148
- mapping: {
149
- oneofKind: 'namespaceDelegation',
150
- namespaceDelegation: NamespaceDelegation.create({
151
- namespace,
152
- targetKey: publicKey,
153
- isRootDelegation: true,
154
- restriction: {
155
- oneofKind: undefined,
156
- },
157
- }),
158
- },
159
- });
160
- const hostingParticipants = [...hostingParticipantRights].map(([participantUid, permission]) => PartyToParticipant_HostingParticipant.create({
161
- participantUid,
162
- permission,
163
- }));
164
- const partyToParticipant = TopologyMapping.create({
165
- mapping: {
166
- oneofKind: 'partyToParticipant',
167
- partyToParticipant: PartyToParticipant.create({
168
- party: partyId,
169
- threshold: confirmingThreshold,
170
- participants: hostingParticipants,
171
- }),
172
- },
173
- });
174
- const partyToKeyMapping = TopologyMapping.create({
175
- mapping: {
176
- oneofKind: 'partyToKeyMapping',
177
- partyToKeyMapping: PartyToKeyMapping.create({
178
- party: partyId,
179
- threshold: 1,
180
- signingKeys: [publicKey],
181
- }),
182
- },
183
- });
184
- return GenerateTransactionsRequest.create({
185
- proposals: [
186
- namespaceDelegation,
187
- partyToParticipant,
188
- partyToKeyMapping,
189
- ].map((mapping) => GenerateTransactionsRequest_Proposal.create({
190
- mapping,
191
- serial: 1,
192
- store: this.storeId(),
193
- operation: Enums_TopologyChangeOp.ADD_REPLACE,
194
- })),
195
- });
196
- }
197
- /** @deprecated use allocateExternalParty() instead */
198
- async submitExternalPartyTopology(signedTopologyTxs, partyId) {
199
- await this.addTransactions(signedTopologyTxs);
200
- await this.authorizePartyToParticipant(partyId);
201
- }
202
- /** @deprecated use generateTopology() */
203
- async generateTransactions(publicKey, partyId, confirmingThreshold = 1, hostingParticipantRights) {
204
- const signingPublicKey = signingPublicKeyFromEd25519(publicKey);
205
- const namespace = TopologyWriteService.createFingerprintFromKey(signingPublicKey);
206
- let participantRights = hostingParticipantRights;
207
- // if no participantRights have been supplied, this party will be hosted on 1 validator (not multi-hosted)
208
- // the default is to get the participantId from ledger client with Confirmation rights
209
- if (!participantRights || participantRights.size === 0) {
210
- const { participantId } = await this.ledgerClient.getWithRetry('/v2/parties/participant-id');
211
- participantRights = new Map([
212
- [participantId, Enums_ParticipantPermission.CONFIRMATION],
213
- ]);
214
- }
215
- const req = this.generateTransactionsRequest(namespace, partyId, signingPublicKey, confirmingThreshold, participantRights);
216
- return this.topologyClient.generateTransactions(req, {
217
- meta: {
218
- Authorization: `Bearer ${this.userAdminToken}`,
219
- },
220
- }).response;
221
- }
222
- /** @deprecated */
223
- async addTransactions(signedTopologyTxs) {
224
- const request = AddTransactionsRequest.create({
225
- transactions: signedTopologyTxs,
226
- forceChanges: [],
227
- store: this.storeId(),
228
- });
229
- return this.topologyClient.addTransactions(request, {
230
- meta: {
231
- Authorization: `Bearer ${this.userAdminToken}`,
232
- },
233
- }).response;
234
- }
235
- /** @deprecated */
236
- async waitForPartyToParticipantProposal(partyId) {
237
- let counter = 0;
238
- return new Promise((resolve, reject) => {
239
- const interval = setInterval(async () => {
240
- const result = await this.topologyReadService.listPartyToParticipant(ListPartyToParticipantRequest.create({
241
- baseQuery: BaseQuery.create({
242
- store: this.storeId(),
243
- proposals: true,
244
- timeQuery: {
245
- oneofKind: 'headState',
246
- headState: Empty.create(),
247
- },
248
- }),
249
- filterParty: partyId,
250
- }));
251
- if (result.response.results.length > 0) {
252
- clearInterval(interval);
253
- resolve(result.response.results[0].context?.transactionHash);
254
- }
255
- counter += 1;
256
- if (counter > 10) {
257
- clearInterval(interval);
258
- reject('Timeout waiting for party to participant proposal');
259
- }
260
- }, 1000);
261
- });
262
- }
263
- /** @deprecated */
264
- async authorizePartyToParticipant(partyId) {
265
- const hash = await this.waitForPartyToParticipantProposal(partyId);
266
- if (!hash) {
267
- throw new Error('No topology transaction found for authorization');
268
- }
269
- const request = AuthorizeRequest.create({
270
- type: {
271
- oneofKind: 'transactionHash',
272
- transactionHash: Buffer.from(hash).toString('hex'),
273
- },
274
- mustFullyAuthorize: false,
275
- store: this.storeId(),
276
- });
277
- return this.topologyClient.authorize(request, {
278
- meta: {
279
- Authorization: `Bearer ${this.userAdminToken}`,
280
- },
281
- }).response;
282
- }
283
- }