@canton-network/core-ledger-client 0.15.0 → 0.16.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.
- package/dist/acs/acs-container.d.ts +33 -0
- package/dist/acs/acs-container.d.ts.map +1 -0
- package/dist/acs/acs-helper.d.ts +37 -0
- package/dist/acs/acs-helper.d.ts.map +1 -0
- package/dist/acs/types.d.ts +10 -0
- package/dist/acs/types.d.ts.map +1 -0
- package/dist/acs/ws-support.d.ts +18 -0
- package/dist/acs/ws-support.d.ts.map +1 -0
- package/dist/index.cjs +3317 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3297 -7
- package/dist/index.js.map +1 -0
- package/dist/ledger-api-utils.d.ts +3 -1
- package/dist/ledger-api-utils.d.ts.map +1 -1
- package/dist/ledger-client.d.ts +31 -3
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts +10 -7
- package/dist/token-standard-service.d.ts.map +1 -1
- package/dist/topology-write-service.d.ts +4 -2
- package/dist/topology-write-service.d.ts.map +1 -1
- package/dist/txparse/parser.d.ts.map +1 -1
- package/dist/txparse/test-data/mock/eventsByContractIdResponses.d.ts +153 -0
- package/dist/txparse/test-data/mock/eventsByContractIdResponses.d.ts.map +1 -1
- package/dist/txparse/types.d.ts +5 -2
- package/dist/txparse/types.d.ts.map +1 -1
- package/package.json +23 -11
- package/dist/constants.js +0 -47
- package/dist/generated-clients/openapi-3.3.0-SNAPSHOT.js +0 -5
- package/dist/generated-clients/openapi-3.4.0-SNAPSHOT.js +0 -5
- package/dist/ledger-api-utils.js +0 -432
- package/dist/ledger-client.js +0 -321
- package/dist/token-standard-service.js +0 -871
- package/dist/topology-write-service.js +0 -283
- package/dist/txparse/parser.js +0 -581
- package/dist/txparse/parser.test.d.ts +0 -2
- package/dist/txparse/parser.test.d.ts.map +0 -1
- package/dist/txparse/parser.test.js +0 -97
- package/dist/txparse/strict.js +0 -19
- package/dist/txparse/test-data/expected/txs.js +0 -2303
- package/dist/txparse/test-data/mock/eventsByContractIdResponses.js +0 -2973
- package/dist/txparse/test-data/mock/txs.js +0 -6788
- package/dist/txparse/types.js +0 -58
package/dist/ledger-client.js
DELETED
|
@@ -1,321 +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 createClient from 'openapi-fetch';
|
|
4
|
-
import { defaultRetryableOptions, retryable, } from './ledger-api-utils.js';
|
|
5
|
-
export const supportedVersions = ['3.3', '3.4'];
|
|
6
|
-
export class LedgerClient {
|
|
7
|
-
// privately manage the active connected version and associated client codegen
|
|
8
|
-
clients;
|
|
9
|
-
clientVersion = '3.3'; // default to 3.3 if not provided
|
|
10
|
-
currentClient;
|
|
11
|
-
initialized = false;
|
|
12
|
-
logger;
|
|
13
|
-
constructor(baseUrl, token, _logger, version) {
|
|
14
|
-
this.logger = _logger.child({ component: 'LedgerClient' });
|
|
15
|
-
this.clients = {
|
|
16
|
-
'3.3': createClient({
|
|
17
|
-
baseUrl: baseUrl.href,
|
|
18
|
-
fetch: async (url, options = {}) => {
|
|
19
|
-
return fetch(url, {
|
|
20
|
-
...options,
|
|
21
|
-
headers: {
|
|
22
|
-
...(options.headers || {}),
|
|
23
|
-
Authorization: `Bearer ${token}`,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
},
|
|
27
|
-
}),
|
|
28
|
-
'3.4': createClient({
|
|
29
|
-
baseUrl: baseUrl.href,
|
|
30
|
-
fetch: async (url, options = {}) => {
|
|
31
|
-
return fetch(url, {
|
|
32
|
-
...options,
|
|
33
|
-
headers: {
|
|
34
|
-
...(options.headers || {}),
|
|
35
|
-
Authorization: `Bearer ${token}`,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
},
|
|
39
|
-
}),
|
|
40
|
-
};
|
|
41
|
-
this.clientVersion = version ?? this.clientVersion;
|
|
42
|
-
this.currentClient = this.clients[this.clientVersion];
|
|
43
|
-
}
|
|
44
|
-
async init() {
|
|
45
|
-
if (!this.initialized) {
|
|
46
|
-
const versionFromClient = await this.currentClient.GET('/v2/version');
|
|
47
|
-
this.clientVersion = this.parseSupportedVersions(versionFromClient.data?.version);
|
|
48
|
-
this.initialized = true;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getCurrentClientVersion() {
|
|
52
|
-
return this.clientVersion;
|
|
53
|
-
}
|
|
54
|
-
parseSupportedVersions(version) {
|
|
55
|
-
if (!version) {
|
|
56
|
-
throw new Error('Client version missing from response');
|
|
57
|
-
}
|
|
58
|
-
const match = supportedVersions.find((v) => version.startsWith(v));
|
|
59
|
-
if (!match) {
|
|
60
|
-
throw new Error(`Unsupported version - found ${version}`);
|
|
61
|
-
}
|
|
62
|
-
return match;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Check if a party exists
|
|
66
|
-
*
|
|
67
|
-
* @param partyId The ID of the party to look for
|
|
68
|
-
* @returns A promise to resolves to a boolean.
|
|
69
|
-
*/
|
|
70
|
-
async checkIfPartyExists(partyId) {
|
|
71
|
-
try {
|
|
72
|
-
const party = await this.get('/v2/parties/{party}', {
|
|
73
|
-
path: { party: partyId },
|
|
74
|
-
});
|
|
75
|
-
return (party.partyDetails !== undefined &&
|
|
76
|
-
party.partyDetails[0].party === partyId);
|
|
77
|
-
}
|
|
78
|
-
catch {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* grant "Master User" rights to a user.
|
|
84
|
-
*
|
|
85
|
-
* this require running with an admin token.
|
|
86
|
-
*
|
|
87
|
-
* @param userId The ID of the user to grant rights to.
|
|
88
|
-
* @param canReadAsAnyParty define if the user can read as any party.
|
|
89
|
-
* @param canExecuteAsAnyParty define if the user can execute as any party.
|
|
90
|
-
*/
|
|
91
|
-
async grantMasterUserRights(userId, canReadAsAnyParty, canExecuteAsAnyParty) {
|
|
92
|
-
const rights = [];
|
|
93
|
-
if (canReadAsAnyParty) {
|
|
94
|
-
rights.push({
|
|
95
|
-
kind: {
|
|
96
|
-
CanReadAsAnyParty: { value: {} },
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
if (canExecuteAsAnyParty) {
|
|
101
|
-
rights.push({
|
|
102
|
-
kind: {
|
|
103
|
-
CanExecuteAsAnyParty: {
|
|
104
|
-
value: {},
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
const result = await this.post('/v2/users/{user-id}/rights', {
|
|
110
|
-
identityProviderId: '',
|
|
111
|
-
userId,
|
|
112
|
-
rights,
|
|
113
|
-
}, {
|
|
114
|
-
path: {
|
|
115
|
-
'user-id': userId,
|
|
116
|
-
},
|
|
117
|
-
});
|
|
118
|
-
if (!result.newlyGrantedRights) {
|
|
119
|
-
throw new Error('Failed to grant user rights');
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Create a new user.
|
|
124
|
-
*
|
|
125
|
-
* @param userId The ID of the user to create.
|
|
126
|
-
* @param primaryParty The primary party of the user.
|
|
127
|
-
*/
|
|
128
|
-
async createUser(userId, primaryParty) {
|
|
129
|
-
try {
|
|
130
|
-
const existing = await this.get('/v2/users/{user-id}', {
|
|
131
|
-
path: { 'user-id': userId },
|
|
132
|
-
});
|
|
133
|
-
if (existing && existing.user) {
|
|
134
|
-
return existing.user;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch {
|
|
138
|
-
//TODO: proper error handling based on daml code
|
|
139
|
-
// we continue if code is:
|
|
140
|
-
// code: 'USER_NOT_FOUND',
|
|
141
|
-
// cause: 'getting user failed for unknown user "master-user"',
|
|
142
|
-
}
|
|
143
|
-
return (await this.post('/v2/users', {
|
|
144
|
-
user: {
|
|
145
|
-
identityProviderId: '',
|
|
146
|
-
id: userId,
|
|
147
|
-
isDeactivated: false,
|
|
148
|
-
primaryParty: primaryParty,
|
|
149
|
-
},
|
|
150
|
-
rights: [
|
|
151
|
-
{
|
|
152
|
-
kind: {
|
|
153
|
-
ParticipantAdmin: {
|
|
154
|
-
value: {},
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
],
|
|
159
|
-
})).user;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Grants a user the right to act as a party, while ensuring the party exists.
|
|
163
|
-
*
|
|
164
|
-
* @param userId The ID of the user to grant rights to.
|
|
165
|
-
* @param partyId The ID of the party to grant rights for.
|
|
166
|
-
* @returns A promise that resolves when the rights have been granted.
|
|
167
|
-
*/
|
|
168
|
-
async grantUserRights(userId, partyId) {
|
|
169
|
-
await this.init();
|
|
170
|
-
// Wait for party to appear on participant
|
|
171
|
-
let partyFound = false;
|
|
172
|
-
let tries = 0;
|
|
173
|
-
const maxTries = 30;
|
|
174
|
-
while (!partyFound && tries < maxTries) {
|
|
175
|
-
partyFound = await this.checkIfPartyExists(partyId);
|
|
176
|
-
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
177
|
-
tries++;
|
|
178
|
-
}
|
|
179
|
-
if (tries >= maxTries) {
|
|
180
|
-
throw new Error('timed out waiting for new party to appear');
|
|
181
|
-
}
|
|
182
|
-
// Assign user rights to party
|
|
183
|
-
const result = await this.post('/v2/users/{user-id}/rights', {
|
|
184
|
-
identityProviderId: '',
|
|
185
|
-
userId,
|
|
186
|
-
rights: [
|
|
187
|
-
{
|
|
188
|
-
kind: {
|
|
189
|
-
CanActAs: {
|
|
190
|
-
value: {
|
|
191
|
-
party: partyId,
|
|
192
|
-
},
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
}, {
|
|
198
|
-
path: {
|
|
199
|
-
'user-id': userId,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
if (!result.newlyGrantedRights) {
|
|
203
|
-
throw new Error('Failed to grant user rights');
|
|
204
|
-
}
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
async grantRights(userId, readAs, actAs) {
|
|
208
|
-
await this.init();
|
|
209
|
-
const rights = [];
|
|
210
|
-
for (const partyId of readAs ?? []) {
|
|
211
|
-
rights.push({
|
|
212
|
-
kind: {
|
|
213
|
-
CanReadAs: {
|
|
214
|
-
value: {
|
|
215
|
-
party: partyId,
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
for (const partyId of actAs ?? []) {
|
|
222
|
-
rights.push({
|
|
223
|
-
kind: {
|
|
224
|
-
CanActAs: {
|
|
225
|
-
value: {
|
|
226
|
-
party: partyId,
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
const result = await this.post('/v2/users/{user-id}/rights', {
|
|
233
|
-
identityProviderId: '',
|
|
234
|
-
userId,
|
|
235
|
-
rights,
|
|
236
|
-
}, {
|
|
237
|
-
path: {
|
|
238
|
-
'user-id': userId,
|
|
239
|
-
},
|
|
240
|
-
});
|
|
241
|
-
if (!result.newlyGrantedRights) {
|
|
242
|
-
throw new Error('Failed to grant user rights');
|
|
243
|
-
}
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
247
|
-
async allocateExternalParty(synchronizerId, onboardingTransactions, multiHashSignatures) {
|
|
248
|
-
await this.init();
|
|
249
|
-
if (this.clientVersion !== '3.3') {
|
|
250
|
-
throw new Error('allocateExternalParty is only supported on 3.3 clients');
|
|
251
|
-
}
|
|
252
|
-
const client = this.clients['3.3'];
|
|
253
|
-
const resp = await client.POST('/v2/parties/external/allocate', {
|
|
254
|
-
body: {
|
|
255
|
-
synchronizer: synchronizerId,
|
|
256
|
-
identityProviderId: '',
|
|
257
|
-
onboardingTransactions,
|
|
258
|
-
multiHashSignatures,
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
return this.valueOrError(resp);
|
|
262
|
-
}
|
|
263
|
-
/** TODO: simplify once 3.4 snapshot contains this endpoint */
|
|
264
|
-
async generateTopology(synchronizerId, publicKey, partyHint, localParticipantObservationOnly = false, confirmationThreshold = 1, otherConfirmingParticipantUids = []) {
|
|
265
|
-
await this.init();
|
|
266
|
-
if (this.clientVersion !== '3.3') {
|
|
267
|
-
throw new Error('allocateExternalParty is only supported on 3.3 clients');
|
|
268
|
-
}
|
|
269
|
-
const client = this.clients['3.3'];
|
|
270
|
-
const body = {
|
|
271
|
-
synchronizer: synchronizerId,
|
|
272
|
-
partyHint,
|
|
273
|
-
publicKey: {
|
|
274
|
-
format: 'CRYPTO_KEY_FORMAT_RAW',
|
|
275
|
-
keyData: publicKey,
|
|
276
|
-
keySpec: 'SIGNING_KEY_SPEC_EC_CURVE25519',
|
|
277
|
-
},
|
|
278
|
-
localParticipantObservationOnly,
|
|
279
|
-
confirmationThreshold,
|
|
280
|
-
otherConfirmingParticipantUids,
|
|
281
|
-
};
|
|
282
|
-
this.logger.debug(body, 'generateTopology request body');
|
|
283
|
-
const resp = await client.POST('/v2/parties/external/generate-topology', { body });
|
|
284
|
-
return this.valueOrError(resp);
|
|
285
|
-
}
|
|
286
|
-
async postWithRetry(path, body, retryOptions = defaultRetryableOptions, params, additionalOptions) {
|
|
287
|
-
return await retryable(() => this.post(path, body, params, additionalOptions), retryOptions, this.logger);
|
|
288
|
-
}
|
|
289
|
-
async getWithRetry(path, retryOptions = defaultRetryableOptions, params) {
|
|
290
|
-
return await retryable(() => this.get(path, params), retryOptions, this.logger);
|
|
291
|
-
}
|
|
292
|
-
/**
|
|
293
|
-
* @deprecated use postWithRetry instead, should be made private
|
|
294
|
-
*/
|
|
295
|
-
async post(path, body, params,
|
|
296
|
-
// needed when posting to /packages, so content type and jsonification of bytes can be overriden
|
|
297
|
-
additionalOptions) {
|
|
298
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- (cant align this with openapi-fetch generics :shrug:)
|
|
299
|
-
const options = { body, params, ...additionalOptions };
|
|
300
|
-
const resp = await this.currentClient.POST(path, options);
|
|
301
|
-
return this.valueOrError(resp);
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* @deprecated use getWithRetry instead, should be made private
|
|
305
|
-
*/
|
|
306
|
-
async get(path, params) {
|
|
307
|
-
await this.init();
|
|
308
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- (cant align this with openapi-fetch generics :shrug:)
|
|
309
|
-
const options = { params };
|
|
310
|
-
const resp = await this.currentClient.GET(path, options);
|
|
311
|
-
return this.valueOrError(resp);
|
|
312
|
-
}
|
|
313
|
-
async valueOrError(response) {
|
|
314
|
-
if (response.data === undefined) {
|
|
315
|
-
return Promise.reject(response.error);
|
|
316
|
-
}
|
|
317
|
-
else {
|
|
318
|
-
return Promise.resolve(response.data);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|