@canton-network/core-ledger-client 0.19.0 → 0.20.1
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/index.cjs +80 -326
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +81 -325
- package/dist/index.js.map +1 -1
- package/dist/ledger-api-utils.d.ts +0 -3
- package/dist/ledger-api-utils.d.ts.map +1 -1
- package/dist/ledger-client.d.ts +15 -2
- package/dist/ledger-client.d.ts.map +1 -1
- package/dist/token-standard-service.d.ts +7 -2
- package/dist/token-standard-service.d.ts.map +1 -1
- package/package.json +24 -22
- package/dist/topology-write-service.d.ts +0 -45
- package/dist/topology-write-service.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,oBAAoB,CAAA;AAClC,cAAc,+CAA+C,CAAA;AAC7D,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,YAAY,EACR,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,cAAc,EACd,qBAAqB,EACrB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,SAAS,EACT,KAAK,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,UAAU,EACV,UAAU,EACV,SAAS,GACZ,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EACH,eAAe,EACf,kBAAkB,EAClB,eAAe,EACf,eAAe,EACf,aAAa,EACb,uBAAuB,GAC1B,MAAM,uBAAuB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { createHash } from 'crypto';
|
|
2
|
-
import { TopologyManagerWriteServiceClient, TopologyManagerReadServiceClient, SignedTopologyTransaction, MultiTransactionSignatures, Signature, SigningAlgorithmSpec, SignatureFormat, TopologyMapping, NamespaceDelegation, PartyToParticipant_HostingParticipant, PartyToParticipant, PartyToKeyMapping, GenerateTransactionsRequest, GenerateTransactionsRequest_Proposal, Enums_TopologyChangeOp, Enums_ParticipantPermission, AddTransactionsRequest, ListPartyToParticipantRequest, BaseQuery, Empty, AuthorizeRequest, ErrorInfo, RetryInfo, SigningKeySpec, SigningKeyScheme, CryptoKeyFormat, StoreId, StoreId_Synchronizer } from '@canton-network/core-ledger-proto';
|
|
3
|
-
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
|
|
4
|
-
import { ChannelCredentials } from '@grpc/grpc-js';
|
|
5
|
-
import fs from 'fs';
|
|
6
1
|
import { TokenStandardClient, HOLDING_INTERFACE_ID, TRANSFER_FACTORY_INTERFACE_ID, TRANSFER_INSTRUCTION_INTERFACE_ID, ALLOCATION_FACTORY_INTERFACE_ID, ALLOCATION_INSTRUCTION_INTERFACE_ID, ALLOCATION_INTERFACE_ID, ALLOCATION_REQUEST_INTERFACE_ID, FEATURED_APP_DELEGATE_PROXY_INTERFACE_ID } from '@canton-network/core-token-standard';
|
|
2
|
+
import { ErrorInfo, RetryInfo } from '@canton-network/core-ledger-proto';
|
|
7
3
|
import BigNumber from 'bignumber.js';
|
|
8
4
|
import createClient from 'openapi-fetch';
|
|
9
5
|
import { LRUCache } from 'typescript-lru-cache';
|
|
@@ -11,291 +7,6 @@ import { LRUCache } from 'typescript-lru-cache';
|
|
|
11
7
|
var __defProp = Object.defineProperty;
|
|
12
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
9
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
14
|
-
function prefixedInt(value, bytes) {
|
|
15
|
-
const buffer = Buffer.alloc(4 + bytes.length);
|
|
16
|
-
buffer.writeUInt32BE(value, 0);
|
|
17
|
-
Buffer.from(bytes).copy(buffer, 4);
|
|
18
|
-
return buffer;
|
|
19
|
-
}
|
|
20
|
-
function signingPublicKeyFromEd25519(publicKey) {
|
|
21
|
-
return {
|
|
22
|
-
format: CryptoKeyFormat.RAW,
|
|
23
|
-
publicKey: Buffer.from(publicKey, "base64"),
|
|
24
|
-
scheme: SigningKeyScheme.ED25519,
|
|
25
|
-
keySpec: SigningKeySpec.EC_CURVE25519,
|
|
26
|
-
usage: []
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function computeSha256CantonHash(purpose, bytes) {
|
|
30
|
-
const hashInput = prefixedInt(purpose, bytes);
|
|
31
|
-
const hash = createHash("sha256").update(hashInput).digest();
|
|
32
|
-
const multiprefix = Buffer.from([18, 32]);
|
|
33
|
-
return Buffer.concat([multiprefix, hash]).toString("hex");
|
|
34
|
-
}
|
|
35
|
-
function createGrpcTransport(options) {
|
|
36
|
-
const { useTls = false, tls } = options;
|
|
37
|
-
if (useTls) {
|
|
38
|
-
const readMaybeFile = (value) => typeof value === "string" ? fs.readFileSync(value) : value;
|
|
39
|
-
const rootCert = readMaybeFile(tls?.rootCert);
|
|
40
|
-
const clientCert = readMaybeFile(tls?.clientCert);
|
|
41
|
-
const clientKey = readMaybeFile(tls?.clientKey);
|
|
42
|
-
if (tls?.mutual) {
|
|
43
|
-
if (!clientCert || !clientKey) {
|
|
44
|
-
throw new Error(
|
|
45
|
-
"mTLS enabled but clientCert or clientKey are missing"
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return ChannelCredentials.createSsl(rootCert, clientKey, clientCert);
|
|
49
|
-
} else {
|
|
50
|
-
return ChannelCredentials.createSsl(rootCert);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
return ChannelCredentials.createInsecure();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
var TopologyWriteService = class _TopologyWriteService {
|
|
57
|
-
constructor(synchronizerId, userAdminUrl, ledgerClient, accessToken = "", accessTokenProvider, grpcClientOptions) {
|
|
58
|
-
this.synchronizerId = synchronizerId;
|
|
59
|
-
__publicField(this, "topologyClient");
|
|
60
|
-
__publicField(this, "topologyReadService");
|
|
61
|
-
__publicField(this, "ledgerClient");
|
|
62
|
-
__publicField(this, "accessTokenProvider");
|
|
63
|
-
__publicField(this, "accessToken");
|
|
64
|
-
__publicField(this, "storeId", () => StoreId.create({
|
|
65
|
-
store: {
|
|
66
|
-
oneofKind: "synchronizer",
|
|
67
|
-
synchronizer: StoreId_Synchronizer.create({
|
|
68
|
-
id: this.synchronizerId
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
let transport;
|
|
73
|
-
if (grpcClientOptions) {
|
|
74
|
-
transport = new GrpcTransport({
|
|
75
|
-
host: userAdminUrl,
|
|
76
|
-
channelCredentials: createGrpcTransport(grpcClientOptions)
|
|
77
|
-
});
|
|
78
|
-
} else {
|
|
79
|
-
transport = new GrpcTransport({
|
|
80
|
-
host: userAdminUrl,
|
|
81
|
-
channelCredentials: ChannelCredentials.createInsecure()
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
this.topologyClient = new TopologyManagerWriteServiceClient(transport);
|
|
85
|
-
this.topologyReadService = new TopologyManagerReadServiceClient(
|
|
86
|
-
transport
|
|
87
|
-
);
|
|
88
|
-
this.ledgerClient = ledgerClient;
|
|
89
|
-
this.accessTokenProvider = accessTokenProvider;
|
|
90
|
-
this.accessToken = accessToken;
|
|
91
|
-
}
|
|
92
|
-
static combineHashes(hashes) {
|
|
93
|
-
const sortedHashes = hashes.sort(
|
|
94
|
-
(a, b) => a.toString("hex").localeCompare(b.toString("hex"))
|
|
95
|
-
);
|
|
96
|
-
const combinedHashes = Buffer.alloc(4);
|
|
97
|
-
combinedHashes.writeUInt32BE(sortedHashes.length, 0);
|
|
98
|
-
let concatenatedHashes = combinedHashes;
|
|
99
|
-
for (const h of sortedHashes) {
|
|
100
|
-
const lengthBuffer = Buffer.alloc(4);
|
|
101
|
-
lengthBuffer.writeUInt32BE(h.length, 0);
|
|
102
|
-
concatenatedHashes = Buffer.concat([
|
|
103
|
-
concatenatedHashes,
|
|
104
|
-
lengthBuffer,
|
|
105
|
-
h
|
|
106
|
-
]);
|
|
107
|
-
}
|
|
108
|
-
const predefineHashPurpose = computeSha256CantonHash(
|
|
109
|
-
55,
|
|
110
|
-
concatenatedHashes
|
|
111
|
-
);
|
|
112
|
-
return Buffer.from(predefineHashPurpose, "hex").toString("base64");
|
|
113
|
-
}
|
|
114
|
-
static createFingerprintFromKey(publicKey) {
|
|
115
|
-
let key;
|
|
116
|
-
if (typeof publicKey === "string") {
|
|
117
|
-
key = signingPublicKeyFromEd25519(publicKey);
|
|
118
|
-
} else {
|
|
119
|
-
key = publicKey;
|
|
120
|
-
}
|
|
121
|
-
const hashPurpose = 12;
|
|
122
|
-
return computeSha256CantonHash(hashPurpose, key.publicKey);
|
|
123
|
-
}
|
|
124
|
-
/** @deprecated only for grpc/protobuf implementation */
|
|
125
|
-
static toSignedTopologyTransaction(txHashes, serializedTransaction, signature, namespace) {
|
|
126
|
-
return SignedTopologyTransaction.create({
|
|
127
|
-
transaction: serializedTransaction,
|
|
128
|
-
proposal: true,
|
|
129
|
-
signatures: [],
|
|
130
|
-
multiTransactionSignatures: [
|
|
131
|
-
MultiTransactionSignatures.create({
|
|
132
|
-
transactionHashes: txHashes,
|
|
133
|
-
signatures: [
|
|
134
|
-
Signature.create({
|
|
135
|
-
format: SignatureFormat.RAW,
|
|
136
|
-
signature: Buffer.from(signature, "base64"),
|
|
137
|
-
signedBy: namespace,
|
|
138
|
-
signingAlgorithmSpec: SigningAlgorithmSpec.ED25519
|
|
139
|
-
})
|
|
140
|
-
]
|
|
141
|
-
})
|
|
142
|
-
]
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
/** @deprecated */
|
|
146
|
-
generateTransactionsRequest(namespace, partyId, publicKey, confirmingThreshold = 1, hostingParticipantRights) {
|
|
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: void 0
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
const hostingParticipants = [...hostingParticipantRights].map(
|
|
161
|
-
([participantUid, permission]) => PartyToParticipant_HostingParticipant.create({
|
|
162
|
-
participantUid,
|
|
163
|
-
permission
|
|
164
|
-
})
|
|
165
|
-
);
|
|
166
|
-
const partyToParticipant = TopologyMapping.create({
|
|
167
|
-
mapping: {
|
|
168
|
-
oneofKind: "partyToParticipant",
|
|
169
|
-
partyToParticipant: PartyToParticipant.create({
|
|
170
|
-
party: partyId,
|
|
171
|
-
threshold: confirmingThreshold,
|
|
172
|
-
participants: hostingParticipants
|
|
173
|
-
})
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
const partyToKeyMapping = TopologyMapping.create({
|
|
177
|
-
mapping: {
|
|
178
|
-
oneofKind: "partyToKeyMapping",
|
|
179
|
-
partyToKeyMapping: PartyToKeyMapping.create({
|
|
180
|
-
party: partyId,
|
|
181
|
-
threshold: 1,
|
|
182
|
-
signingKeys: [publicKey]
|
|
183
|
-
})
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return GenerateTransactionsRequest.create({
|
|
187
|
-
proposals: [
|
|
188
|
-
namespaceDelegation,
|
|
189
|
-
partyToParticipant,
|
|
190
|
-
partyToKeyMapping
|
|
191
|
-
].map(
|
|
192
|
-
(mapping) => GenerateTransactionsRequest_Proposal.create({
|
|
193
|
-
mapping,
|
|
194
|
-
serial: 1,
|
|
195
|
-
store: this.storeId(),
|
|
196
|
-
operation: Enums_TopologyChangeOp.ADD_REPLACE
|
|
197
|
-
})
|
|
198
|
-
)
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
/** @deprecated use allocateExternalParty() instead */
|
|
202
|
-
async submitExternalPartyTopology(signedTopologyTxs, partyId) {
|
|
203
|
-
await this.addTransactions(signedTopologyTxs);
|
|
204
|
-
await this.authorizePartyToParticipant(partyId);
|
|
205
|
-
}
|
|
206
|
-
/** @deprecated use generateTopology() */
|
|
207
|
-
async generateTransactions(publicKey, partyId, confirmingThreshold = 1, hostingParticipantRights) {
|
|
208
|
-
const signingPublicKey = signingPublicKeyFromEd25519(publicKey);
|
|
209
|
-
const namespace = _TopologyWriteService.createFingerprintFromKey(signingPublicKey);
|
|
210
|
-
let participantRights = hostingParticipantRights;
|
|
211
|
-
if (!participantRights || participantRights.size === 0) {
|
|
212
|
-
const { participantId } = await this.ledgerClient.getWithRetry(
|
|
213
|
-
"/v2/parties/participant-id"
|
|
214
|
-
);
|
|
215
|
-
participantRights = /* @__PURE__ */ new Map([
|
|
216
|
-
[participantId, Enums_ParticipantPermission.CONFIRMATION]
|
|
217
|
-
]);
|
|
218
|
-
}
|
|
219
|
-
const req = this.generateTransactionsRequest(
|
|
220
|
-
namespace,
|
|
221
|
-
partyId,
|
|
222
|
-
signingPublicKey,
|
|
223
|
-
confirmingThreshold,
|
|
224
|
-
participantRights
|
|
225
|
-
);
|
|
226
|
-
const adminAccessToken = this.accessTokenProvider ? await this.accessTokenProvider.getAdminAccessToken() : this.accessToken;
|
|
227
|
-
return this.topologyClient.generateTransactions(req, {
|
|
228
|
-
meta: {
|
|
229
|
-
Authorization: `Bearer ${adminAccessToken}`
|
|
230
|
-
}
|
|
231
|
-
}).response;
|
|
232
|
-
}
|
|
233
|
-
/** @deprecated */
|
|
234
|
-
async addTransactions(signedTopologyTxs) {
|
|
235
|
-
const request = AddTransactionsRequest.create({
|
|
236
|
-
transactions: signedTopologyTxs,
|
|
237
|
-
forceChanges: [],
|
|
238
|
-
store: this.storeId()
|
|
239
|
-
});
|
|
240
|
-
const adminAccessToken = this.accessTokenProvider ? await this.accessTokenProvider.getAdminAccessToken() : this.accessToken;
|
|
241
|
-
return this.topologyClient.addTransactions(request, {
|
|
242
|
-
meta: {
|
|
243
|
-
Authorization: `Bearer ${adminAccessToken}`
|
|
244
|
-
}
|
|
245
|
-
}).response;
|
|
246
|
-
}
|
|
247
|
-
/** @deprecated */
|
|
248
|
-
async waitForPartyToParticipantProposal(partyId) {
|
|
249
|
-
let counter = 0;
|
|
250
|
-
return new Promise((resolve, reject) => {
|
|
251
|
-
const interval = setInterval(async () => {
|
|
252
|
-
const result = await this.topologyReadService.listPartyToParticipant(
|
|
253
|
-
ListPartyToParticipantRequest.create({
|
|
254
|
-
baseQuery: BaseQuery.create({
|
|
255
|
-
store: this.storeId(),
|
|
256
|
-
proposals: true,
|
|
257
|
-
timeQuery: {
|
|
258
|
-
oneofKind: "headState",
|
|
259
|
-
headState: Empty.create()
|
|
260
|
-
}
|
|
261
|
-
}),
|
|
262
|
-
filterParty: partyId
|
|
263
|
-
})
|
|
264
|
-
);
|
|
265
|
-
if (result.response.results.length > 0) {
|
|
266
|
-
clearInterval(interval);
|
|
267
|
-
resolve(result.response.results[0].context?.transactionHash);
|
|
268
|
-
}
|
|
269
|
-
counter += 1;
|
|
270
|
-
if (counter > 10) {
|
|
271
|
-
clearInterval(interval);
|
|
272
|
-
reject("Timeout waiting for party to participant proposal");
|
|
273
|
-
}
|
|
274
|
-
}, 1e3);
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
/** @deprecated */
|
|
278
|
-
async authorizePartyToParticipant(partyId) {
|
|
279
|
-
const hash = await this.waitForPartyToParticipantProposal(partyId);
|
|
280
|
-
if (!hash) {
|
|
281
|
-
throw new Error("No topology transaction found for authorization");
|
|
282
|
-
}
|
|
283
|
-
const request = AuthorizeRequest.create({
|
|
284
|
-
type: {
|
|
285
|
-
oneofKind: "transactionHash",
|
|
286
|
-
transactionHash: Buffer.from(hash).toString("hex")
|
|
287
|
-
},
|
|
288
|
-
mustFullyAuthorize: false,
|
|
289
|
-
store: this.storeId()
|
|
290
|
-
});
|
|
291
|
-
const adminAccessToken = this.accessTokenProvider ? await this.accessTokenProvider.getAdminAccessToken() : this.accessToken;
|
|
292
|
-
return this.topologyClient.authorize(request, {
|
|
293
|
-
meta: {
|
|
294
|
-
Authorization: `Bearer ${adminAccessToken}`
|
|
295
|
-
}
|
|
296
|
-
}).response;
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
10
|
function splitInterfaceId(interfaceId) {
|
|
300
11
|
const regExp = /^#?([^:]+):([^:]+):([^:]+)$/;
|
|
301
12
|
const match = regExp.exec(interfaceId);
|
|
@@ -1574,6 +1285,10 @@ var CoreService = class _CoreService {
|
|
|
1574
1285
|
fetchedAtOffset: offset
|
|
1575
1286
|
};
|
|
1576
1287
|
}
|
|
1288
|
+
toQualifiedMemberId(memberId) {
|
|
1289
|
+
if (!memberId) throw new Error("memberId is required");
|
|
1290
|
+
return /^(PAR|MED)::/.test(memberId) ? memberId : `PAR::${memberId}`;
|
|
1291
|
+
}
|
|
1577
1292
|
};
|
|
1578
1293
|
var AllocationService = class {
|
|
1579
1294
|
constructor(core, logger) {
|
|
@@ -2154,12 +1869,13 @@ var TransferService = class {
|
|
|
2154
1869
|
}
|
|
2155
1870
|
};
|
|
2156
1871
|
var TokenStandardService = class {
|
|
2157
|
-
constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser) {
|
|
1872
|
+
constructor(ledgerClient, scanProxyClient, logger, accessTokenProvider, isMasterUser, scanClient) {
|
|
2158
1873
|
this.ledgerClient = ledgerClient;
|
|
2159
1874
|
this.scanProxyClient = scanProxyClient;
|
|
2160
1875
|
this.logger = logger;
|
|
2161
1876
|
this.accessTokenProvider = accessTokenProvider;
|
|
2162
1877
|
this.isMasterUser = isMasterUser;
|
|
1878
|
+
this.scanClient = scanClient;
|
|
2163
1879
|
__publicField(this, "core");
|
|
2164
1880
|
__publicField(this, "allocation");
|
|
2165
1881
|
__publicField(this, "transfer");
|
|
@@ -2168,7 +1884,9 @@ var TokenStandardService = class {
|
|
|
2168
1884
|
scanProxyClient,
|
|
2169
1885
|
logger,
|
|
2170
1886
|
accessTokenProvider,
|
|
2171
|
-
isMasterUser
|
|
1887
|
+
isMasterUser,
|
|
1888
|
+
void 0,
|
|
1889
|
+
void 0
|
|
2172
1890
|
);
|
|
2173
1891
|
this.allocation = new AllocationService(this.core, this.logger);
|
|
2174
1892
|
this.transfer = new TransferService(this.core, this.logger);
|
|
@@ -2257,7 +1975,7 @@ var TokenStandardService = class {
|
|
|
2257
1975
|
value: cid
|
|
2258
1976
|
})),
|
|
2259
1977
|
provider,
|
|
2260
|
-
memberId,
|
|
1978
|
+
memberId: this.core.toQualifiedMemberId(memberId),
|
|
2261
1979
|
synchronizerId,
|
|
2262
1980
|
migrationId,
|
|
2263
1981
|
trafficAmount,
|
|
@@ -2271,6 +1989,20 @@ var TokenStandardService = class {
|
|
|
2271
1989
|
};
|
|
2272
1990
|
return [exercise, disclosed];
|
|
2273
1991
|
}
|
|
1992
|
+
async getMemberTrafficStatus(domainId, memberId) {
|
|
1993
|
+
if (!this.scanClient) {
|
|
1994
|
+
throw new Error("Scan API URL was not provided");
|
|
1995
|
+
}
|
|
1996
|
+
return this.scanClient.get(
|
|
1997
|
+
"/v0/domains/{domain_id}/members/{member_id}/traffic-status",
|
|
1998
|
+
{
|
|
1999
|
+
path: {
|
|
2000
|
+
domain_id: domainId,
|
|
2001
|
+
member_id: this.core.toQualifiedMemberId(memberId)
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
);
|
|
2005
|
+
}
|
|
2274
2006
|
async getInstrumentAdmin(registryUrl) {
|
|
2275
2007
|
const client = this.core.getTokenStandardClient(registryUrl);
|
|
2276
2008
|
const info = await client.get("/registry/metadata/v1/info");
|
|
@@ -3005,7 +2737,16 @@ var ACSHelper = class _ACSHelper {
|
|
|
3005
2737
|
// src/ledger-client.ts
|
|
3006
2738
|
var supportedVersions = ["3.3", "3.4"];
|
|
3007
2739
|
var LedgerClient = class {
|
|
3008
|
-
constructor(
|
|
2740
|
+
constructor({
|
|
2741
|
+
baseUrl,
|
|
2742
|
+
logger,
|
|
2743
|
+
isAdmin,
|
|
2744
|
+
accessToken,
|
|
2745
|
+
accessTokenProvider,
|
|
2746
|
+
version,
|
|
2747
|
+
acsHelperOptions,
|
|
2748
|
+
...options
|
|
2749
|
+
}) {
|
|
3009
2750
|
// privately manage the active connected version and associated client codegen
|
|
3010
2751
|
__publicField(this, "clients");
|
|
3011
2752
|
__publicField(this, "clientVersion", "3.4");
|
|
@@ -3015,39 +2756,32 @@ var LedgerClient = class {
|
|
|
3015
2756
|
__publicField(this, "accessTokenProvider");
|
|
3016
2757
|
__publicField(this, "acsHelper");
|
|
3017
2758
|
__publicField(this, "logger");
|
|
2759
|
+
__publicField(this, "synchronizerId");
|
|
3018
2760
|
__publicField(this, "baseUrl");
|
|
3019
|
-
this.logger =
|
|
2761
|
+
this.logger = logger.child({ component: "LedgerClient" });
|
|
3020
2762
|
this.accessTokenProvider = accessTokenProvider;
|
|
2763
|
+
const baseFetch = options.fetch ?? fetch;
|
|
2764
|
+
const authenticatedFetch = async (url, options2 = {}) => {
|
|
2765
|
+
let token = accessToken;
|
|
2766
|
+
if (this.accessTokenProvider) {
|
|
2767
|
+
token = isAdmin ?? false ? await this.accessTokenProvider.getAdminAccessToken() : await this.accessTokenProvider.getUserAccessToken();
|
|
2768
|
+
}
|
|
2769
|
+
return baseFetch(url, {
|
|
2770
|
+
...options2,
|
|
2771
|
+
headers: {
|
|
2772
|
+
...options2.headers || {},
|
|
2773
|
+
...token && { Authorization: `Bearer ${token}` }
|
|
2774
|
+
}
|
|
2775
|
+
});
|
|
2776
|
+
};
|
|
3021
2777
|
this.clients = {
|
|
3022
2778
|
"3.3": createClient({
|
|
3023
2779
|
baseUrl: baseUrl.href,
|
|
3024
|
-
fetch:
|
|
3025
|
-
if (this.accessTokenProvider) {
|
|
3026
|
-
accessToken = isAdmin ? await this.accessTokenProvider.getAdminAccessToken() : await this.accessTokenProvider.getUserAccessToken();
|
|
3027
|
-
}
|
|
3028
|
-
return fetch(url, {
|
|
3029
|
-
...options,
|
|
3030
|
-
headers: {
|
|
3031
|
-
...options.headers || {},
|
|
3032
|
-
Authorization: `Bearer ${accessToken}`
|
|
3033
|
-
}
|
|
3034
|
-
});
|
|
3035
|
-
}
|
|
2780
|
+
fetch: authenticatedFetch
|
|
3036
2781
|
}),
|
|
3037
2782
|
"3.4": createClient({
|
|
3038
2783
|
baseUrl: baseUrl.href,
|
|
3039
|
-
fetch:
|
|
3040
|
-
if (this.accessTokenProvider) {
|
|
3041
|
-
accessToken = isAdmin ? await this.accessTokenProvider.getAdminAccessToken() : await this.accessTokenProvider.getUserAccessToken();
|
|
3042
|
-
}
|
|
3043
|
-
return fetch(url, {
|
|
3044
|
-
...options,
|
|
3045
|
-
headers: {
|
|
3046
|
-
...options.headers || {},
|
|
3047
|
-
Authorization: `Bearer ${accessToken}`
|
|
3048
|
-
}
|
|
3049
|
-
});
|
|
3050
|
-
}
|
|
2784
|
+
fetch: authenticatedFetch
|
|
3051
2785
|
})
|
|
3052
2786
|
};
|
|
3053
2787
|
this.clientVersion = version ?? this.clientVersion;
|
|
@@ -3055,7 +2789,7 @@ var LedgerClient = class {
|
|
|
3055
2789
|
this.baseUrl = baseUrl;
|
|
3056
2790
|
this.acsHelper = new ACSHelper(
|
|
3057
2791
|
this,
|
|
3058
|
-
|
|
2792
|
+
logger,
|
|
3059
2793
|
acsHelperOptions,
|
|
3060
2794
|
SharedACSCache
|
|
3061
2795
|
);
|
|
@@ -3182,20 +2916,23 @@ var LedgerClient = class {
|
|
|
3182
2916
|
*
|
|
3183
2917
|
* @param userId The ID of the user to grant rights to.
|
|
3184
2918
|
* @param partyId The ID of the party to grant rights for.
|
|
2919
|
+
* @param maxTries Optional max number of retries with default 30. May be increased if expecting heavy load.
|
|
2920
|
+
* @param retryIntervalMs Optional interval between retries to verify that party exists with default 2000ms. May be increased if expecting heavy load.
|
|
3185
2921
|
* @returns A promise that resolves when the rights have been granted.
|
|
3186
2922
|
*/
|
|
3187
|
-
async waitForPartyAndGrantUserRights(userId, partyId) {
|
|
2923
|
+
async waitForPartyAndGrantUserRights(userId, partyId, maxTries = 30, retryIntervalMs = 2e3) {
|
|
3188
2924
|
await this.init();
|
|
3189
2925
|
let partyFound = false;
|
|
3190
2926
|
let tries = 0;
|
|
3191
|
-
const maxTries = 30;
|
|
3192
2927
|
while (!partyFound && tries < maxTries) {
|
|
3193
2928
|
partyFound = await this.checkIfPartyExists(partyId);
|
|
3194
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
2929
|
+
await new Promise((resolve) => setTimeout(resolve, retryIntervalMs));
|
|
3195
2930
|
tries++;
|
|
3196
2931
|
}
|
|
3197
2932
|
if (tries >= maxTries) {
|
|
3198
|
-
throw new Error(
|
|
2933
|
+
throw new Error(
|
|
2934
|
+
`timed out waiting for new party to appear after ${maxTries} tries`
|
|
2935
|
+
);
|
|
3199
2936
|
}
|
|
3200
2937
|
const result = await this.grantRights(userId, {
|
|
3201
2938
|
actAs: [partyId]
|
|
@@ -3453,6 +3190,25 @@ var LedgerClient = class {
|
|
|
3453
3190
|
}
|
|
3454
3191
|
return filter;
|
|
3455
3192
|
}
|
|
3193
|
+
// Retrieve an (arbitrary) synchronizer id from the validator.
|
|
3194
|
+
// This synchronizer id is cached for the remainder of this object's life.
|
|
3195
|
+
async getSynchronizerId() {
|
|
3196
|
+
if (this.synchronizerId) return this.synchronizerId;
|
|
3197
|
+
const response = await this.getWithRetry(
|
|
3198
|
+
"/v2/state/connected-synchronizers"
|
|
3199
|
+
);
|
|
3200
|
+
if (!response.connectedSynchronizers?.[0]) {
|
|
3201
|
+
throw new Error("No connected synchronizers found");
|
|
3202
|
+
}
|
|
3203
|
+
const synchronizerId = response.connectedSynchronizers[0].synchronizerId;
|
|
3204
|
+
if (response.connectedSynchronizers.length > 1) {
|
|
3205
|
+
this.logger.warn(
|
|
3206
|
+
`Found ${response.connectedSynchronizers.length} synchronizers, defaulting to ${synchronizerId}`
|
|
3207
|
+
);
|
|
3208
|
+
}
|
|
3209
|
+
this.synchronizerId = synchronizerId;
|
|
3210
|
+
return synchronizerId;
|
|
3211
|
+
}
|
|
3456
3212
|
async postWithRetry(path, body, retryOptions = defaultRetryableOptions, params, additionalOptions) {
|
|
3457
3213
|
return await retryable(
|
|
3458
3214
|
() => this.post(path, body, params, additionalOptions),
|
|
@@ -3533,6 +3289,6 @@ var WSSupportWithBackOffSwitch = class {
|
|
|
3533
3289
|
}
|
|
3534
3290
|
};
|
|
3535
3291
|
|
|
3536
|
-
export { ACSContainer, ACS_UPDATE_CONFIG, CoreService, LedgerClient, TokenStandardService,
|
|
3292
|
+
export { ACSContainer, ACS_UPDATE_CONFIG, CoreService, LedgerClient, TokenStandardService, WSSupportWithBackOffSwitch, asJsCantonError, awaitCompletion, defaultRetryableOptions, isJsCantonError, promiseWithTimeout, supportedVersions };
|
|
3537
3293
|
//# sourceMappingURL=index.js.map
|
|
3538
3294
|
//# sourceMappingURL=index.js.map
|