@partylayer/sdk 0.21.0 → 0.22.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/README.md +44 -0
- package/dist/application-ledger-reader-DYaIuRCD.d.mts +774 -0
- package/dist/application-ledger-reader-DYaIuRCD.d.ts +774 -0
- package/dist/index.d.mts +14 -707
- package/dist/index.d.ts +14 -707
- package/dist/index.js +1008 -984
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1010 -987
- package/dist/index.mjs.map +1 -1
- package/dist/internal/hosted-wallet-profiles.d.mts +16 -0
- package/dist/internal/hosted-wallet-profiles.d.ts +16 -0
- package/dist/internal/hosted-wallet-profiles.js +337 -0
- package/dist/internal/hosted-wallet-profiles.js.map +1 -0
- package/dist/internal/hosted-wallet-profiles.mjs +335 -0
- package/dist/internal/hosted-wallet-profiles.mjs.map +1 -0
- package/dist/native.d.mts +18 -0
- package/dist/native.d.ts +18 -0
- package/dist/native.js +2832 -0
- package/dist/native.js.map +1 -0
- package/dist/native.mjs +2827 -0
- package/dist/native.mjs.map +1 -0
- package/package.json +24 -12
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { toWalletId, toPartyId, isRecognizedNetwork, detectNetworkMismatch, ledgerApiBodyToObject, normalizeLedgerMethodLower, hashForPrivacy, createMetricsPayload, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, NetworkMismatchError, METRICS, WalletNotFoundError, AdapterNotRegisteredError, capabilityGuard, installGuard,
|
|
1
|
+
import { toWalletId, toPartyId, isRecognizedNetwork, detectNetworkMismatch, ledgerApiBodyToObject, normalizeLedgerMethodLower, hashForPrivacy, createMetricsPayload, TransportError, toSignature, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, NetworkMismatchError, METRICS, WalletNotFoundError, AdapterNotRegisteredError, OriginNotAllowedError, capabilityGuard, installGuard, CapabilityNotSupportedError, toTransferIntent, errorMetricName, parseTokenHoldingV2, parseTokenHoldingV1, toCAIP2Network, toTransactionHash, generateSessionId, toSessionId } from '@partylayer/core';
|
|
2
2
|
export { AdapterNotRegisteredError, PartyLayerError as CantonConnectError, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, InternalError, METRICS, OriginNotAllowedError, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, SessionExpiredError, TRANSFER_INTENT_FIELDS, TimeoutError, TransportError, UserRejectedError, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter, toTransferIntent } from '@partylayer/core';
|
|
3
3
|
import { RegistryClient } from '@partylayer/registry-client';
|
|
4
4
|
export { deriveGenericWalletName, findMatchingWallet, findMatchingWalletInfo, isCip0103Native, matchesProviderDetection } from '@partylayer/registry-client';
|
|
5
|
-
import { subscribeAnnouncedProviders, createExtensionChannelProvider, discoverProviders, createProviderBridge, CIP0103EventBus, toProviderRpcError } from '@partylayer/provider';
|
|
5
|
+
import { subscribeAnnouncedProviders, createExtensionChannelProvider, discoverProviders, createProviderBridge, CIP0103EventBus, ProviderRpcError, JSON_RPC_ERRORS, toProviderRpcError } from '@partylayer/provider';
|
|
6
6
|
export { CANTON_NETWORKS, CIP0103EventBus, CIP0103_EVENTS, CIP0103_MANDATORY_METHODS, CIP0103_METHODS, JSON_RPC_ERRORS, PartyLayerProvider, ProviderRpcError, RPC_ERRORS, createProviderBridge, discoverInjectedProviders, fromCAIP2Network, isCIP0103Provider, isValidCAIP2, toCAIP2Network, waitForProvider } from '@partylayer/provider';
|
|
7
7
|
export { ConsoleAdapter } from '@partylayer/adapter-console';
|
|
8
8
|
import { LoopAdapter } from '@partylayer/adapter-loop';
|
|
@@ -14,50 +14,7 @@ export { NightlyAdapter } from '@partylayer/adapter-nightly';
|
|
|
14
14
|
export { SendAdapter } from '@partylayer/adapter-send';
|
|
15
15
|
export { BronAdapter } from '@partylayer/adapter-bron';
|
|
16
16
|
|
|
17
|
-
// src/
|
|
18
|
-
var loaders = {
|
|
19
|
-
walley: async () => {
|
|
20
|
-
const { WalleyAdapter } = await import('@k2flabs/walley-dapp-sdk');
|
|
21
|
-
return { providerId: "walley", create: (host) => new WalleyAdapter({ host }) };
|
|
22
|
-
},
|
|
23
|
-
cauri: async () => {
|
|
24
|
-
const { cauriAdapterFactory } = await import('@lithiumdigital/cauri-dapp-sdk');
|
|
25
|
-
return cauriAdapterFactory;
|
|
26
|
-
},
|
|
27
|
-
oneswap: async (network) => {
|
|
28
|
-
const { createOneSwapProviderAdapter } = await import('@oneswap/wallet-cip0103-adapter');
|
|
29
|
-
return {
|
|
30
|
-
providerId: "oneswap",
|
|
31
|
-
create: (host) => createOneSwapProviderAdapter({
|
|
32
|
-
walletUrl: host,
|
|
33
|
-
networkId: toCAIP2Network(network).networkId
|
|
34
|
-
})
|
|
35
|
-
};
|
|
36
|
-
},
|
|
37
|
-
vala: async () => {
|
|
38
|
-
const { valaAdapterFactory } = await import('@vala-wallet/dapp-sdk');
|
|
39
|
-
return valaAdapterFactory;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
async function loadDefaultWallet(id, config, origin) {
|
|
43
|
-
if (id === "walletconnect" && config.walletConnect?.projectId.trim()) {
|
|
44
|
-
const { WalletConnectAdapter } = await import('@partylayer/adapter-walletconnect');
|
|
45
|
-
return new WalletConnectAdapter({
|
|
46
|
-
...config.walletConnect,
|
|
47
|
-
metadata: config.walletConnect.metadata ?? {
|
|
48
|
-
name: config.app.name,
|
|
49
|
-
description: config.app.name,
|
|
50
|
-
url: origin === "unknown" ? "" : origin,
|
|
51
|
-
icons: []
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
if (id === "bron" && config.bron) {
|
|
56
|
-
const { BronAdapter: BronAdapter2 } = await import('@partylayer/adapter-bron');
|
|
57
|
-
return new BronAdapter2(config.bron);
|
|
58
|
-
}
|
|
59
|
-
return Object.prototype.hasOwnProperty.call(loaders, id) ? loaders[id](config.network) : void 0;
|
|
60
|
-
}
|
|
17
|
+
// src/client-base.ts
|
|
61
18
|
var UNSUPPORTED_METHOD = 4200;
|
|
62
19
|
var METHOD_NOT_FOUND = -32601;
|
|
63
20
|
function isUnsupportedMethod(err) {
|
|
@@ -178,722 +135,324 @@ function assertConnectionAccepted(result) {
|
|
|
178
135
|
function assertPrimaryParty(account) {
|
|
179
136
|
if (typeof account?.partyId !== "string" || !account.partyId.trim()) throw new TransportError("The wallet did not return a primary party");
|
|
180
137
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
138
|
+
|
|
139
|
+
// src/native-owner-bindings.ts
|
|
140
|
+
var nativeOwnerBindings = /* @__PURE__ */ new WeakMap();
|
|
141
|
+
var nativeAdapterCopies = /* @__PURE__ */ new WeakMap();
|
|
142
|
+
|
|
143
|
+
// src/announce-adapter.ts
|
|
144
|
+
function getAnnounceCapabilities(config = {}) {
|
|
145
|
+
const caps = ["connect"];
|
|
146
|
+
if (config.signMessage !== false) caps.push("signMessage");
|
|
147
|
+
caps.push("submitTransaction");
|
|
148
|
+
if (config.restore) caps.push("restore");
|
|
149
|
+
if (config.ledgerApi) caps.push("ledgerApi");
|
|
150
|
+
if (config.events) caps.push("events");
|
|
151
|
+
return caps;
|
|
190
152
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (signal.aborted) {
|
|
195
|
-
reject(disconnected());
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
199
|
-
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
200
|
-
});
|
|
153
|
+
var ANNOUNCED_WALLET_ID_PREFIX = "browser:ext:";
|
|
154
|
+
function announcedWalletId(announceId) {
|
|
155
|
+
return toWalletId(`${ANNOUNCED_WALLET_ID_PREFIX}${announceId}`);
|
|
201
156
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
157
|
+
function mapTxStatus(status) {
|
|
158
|
+
switch (status) {
|
|
159
|
+
case "pending":
|
|
160
|
+
return "pending";
|
|
161
|
+
case "signed":
|
|
162
|
+
return "submitted";
|
|
163
|
+
case "executed":
|
|
164
|
+
return "committed";
|
|
165
|
+
case "failed":
|
|
166
|
+
default:
|
|
167
|
+
return "failed";
|
|
213
168
|
}
|
|
214
|
-
if (status?.isConnected === false || status?.connection?.isConnected === false)
|
|
215
|
-
throw disconnected();
|
|
216
|
-
const network = [status?.network?.networkId, account.networkId, registration.network].find(
|
|
217
|
-
(value) => typeof value === "string" && isRecognizedNetwork(value)
|
|
218
|
-
) ?? registration.network;
|
|
219
|
-
if (registration.expected && (account.partyId !== registration.expected.partyId || detectNetworkMismatch(registration.expected.network, network)))
|
|
220
|
-
throw disconnected();
|
|
221
|
-
if (signal.aborted) throw disconnected();
|
|
222
|
-
return { account, network, status };
|
|
223
169
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
170
|
+
function toBase64Message(message) {
|
|
171
|
+
const bytes = new TextEncoder().encode(message);
|
|
172
|
+
let binary = "";
|
|
173
|
+
for (const b of bytes) binary += String.fromCharCode(b);
|
|
174
|
+
return btoa(binary);
|
|
175
|
+
}
|
|
176
|
+
var GenericAnnounceAdapter = class _GenericAnnounceAdapter {
|
|
177
|
+
walletId;
|
|
178
|
+
name;
|
|
179
|
+
/** Icon surfaced to the picker (announce detail). */
|
|
180
|
+
icon;
|
|
181
|
+
rawProvider;
|
|
182
|
+
metadataEnabled;
|
|
183
|
+
staticMetadata;
|
|
184
|
+
mapError;
|
|
185
|
+
signMessageBase64;
|
|
186
|
+
/**
|
|
187
|
+
* Which execute verb this wallet turned out to support. Resolved on the first
|
|
188
|
+
* submit and reused, so the wallet is asked at most once.
|
|
189
|
+
*/
|
|
190
|
+
executeVerb = {};
|
|
191
|
+
// Optional WalletAdapter surface — assigned in the ctor ONLY when configured,
|
|
192
|
+
// so `getCapabilities()` and `'x' in adapter` feature-detection stay honest.
|
|
193
|
+
restore;
|
|
194
|
+
on;
|
|
195
|
+
ledgerApi;
|
|
196
|
+
// signMessage is optional too: assigned in the ctor only when the wallet
|
|
197
|
+
// declares support, so a wallet that cannot sign is not advertised as able to.
|
|
198
|
+
signMessage;
|
|
199
|
+
constructor(args) {
|
|
200
|
+
const configuration = { ...args, config: args.config && {
|
|
201
|
+
...args.config,
|
|
202
|
+
staticMetadata: args.config.staticMetadata && { ...args.config.staticMetadata }
|
|
203
|
+
} };
|
|
204
|
+
nativeAdapterCopies.set(this, () => new _GenericAnnounceAdapter(configuration));
|
|
205
|
+
this.walletId = args.walletId ?? announcedWalletId(args.announceId);
|
|
206
|
+
this.name = args.name && args.name.length > 0 ? args.name : `Canton Wallet (${args.announceId.slice(0, 6)}\u2026)`;
|
|
207
|
+
this.icon = args.icon;
|
|
208
|
+
this.rawProvider = args.provider;
|
|
209
|
+
const config = args.config;
|
|
210
|
+
this.metadataEnabled = config?.metadata === true;
|
|
211
|
+
this.staticMetadata = config?.staticMetadata;
|
|
212
|
+
this.mapError = config?.mapError;
|
|
213
|
+
this.signMessageBase64 = config?.signMessageBase64 === true;
|
|
214
|
+
if (config?.events) this.on = this.makeOn();
|
|
215
|
+
if (config?.restore) this.restore = this.makeRestore();
|
|
216
|
+
if (config?.ledgerApi) this.ledgerApi = this.makeLedgerApi();
|
|
217
|
+
if (config?.signMessage !== false) this.signMessage = this.signMessageImpl.bind(this);
|
|
228
218
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
registrations = /* @__PURE__ */ new Map();
|
|
232
|
-
operation = null;
|
|
233
|
-
pending = null;
|
|
234
|
-
closing = null;
|
|
235
|
-
projection = null;
|
|
236
|
-
unsubscribers = [];
|
|
237
|
-
disposed = false;
|
|
238
|
-
refreshRevision = 0;
|
|
239
|
-
identityRefreshing = false;
|
|
240
|
-
probes = /* @__PURE__ */ new Set();
|
|
241
|
-
get busy() {
|
|
242
|
-
return this.operation !== null || this.closing !== null;
|
|
219
|
+
get provider() {
|
|
220
|
+
return nativeOwnerBindings.get(this)?.getProvider(String(this.walletId)) ?? this.rawProvider;
|
|
243
221
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
222
|
+
/** @internal Register the discovered transport with the one official owner. */
|
|
223
|
+
async prepareNativeConnection(network) {
|
|
224
|
+
const owner = nativeOwnerBindings.get(this);
|
|
225
|
+
if (!owner) return;
|
|
226
|
+
await owner.prepare(String(this.walletId), {
|
|
227
|
+
providerId: String(this.walletId),
|
|
228
|
+
name: this.name,
|
|
229
|
+
type: "browser",
|
|
230
|
+
icon: this.icon,
|
|
231
|
+
provider: () => this.rawProvider,
|
|
232
|
+
detect: async () => true
|
|
233
|
+
}, network);
|
|
247
234
|
}
|
|
248
|
-
/**
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
})();
|
|
262
|
-
}
|
|
263
|
-
await this.initialization;
|
|
264
|
-
if (this.disposed || !this.client) throw disconnected();
|
|
265
|
-
for (const registration of this.registrations.values())
|
|
266
|
-
this.client.registerAdapter(this.wrap(registration));
|
|
235
|
+
/**
|
|
236
|
+
* Capabilities derived from actual presence: connect and submitTransaction are
|
|
237
|
+
* always present; signMessage, restore, ledgerApi, and events are each included
|
|
238
|
+
* only when the matching method was assigned, so the set is never advertised
|
|
239
|
+
* beyond what the adapter can do.
|
|
240
|
+
*/
|
|
241
|
+
getCapabilities() {
|
|
242
|
+
return getAnnounceCapabilities({
|
|
243
|
+
signMessage: !!this.signMessage,
|
|
244
|
+
restore: !!this.restore,
|
|
245
|
+
ledgerApi: !!this.ledgerApi,
|
|
246
|
+
events: !!this.on
|
|
247
|
+
});
|
|
267
248
|
}
|
|
268
|
-
|
|
269
|
-
|
|
249
|
+
/**
|
|
250
|
+
* The adapter is only ever constructed for a wallet that just announced, so
|
|
251
|
+
* its presence is established by the announce handshake itself.
|
|
252
|
+
*/
|
|
253
|
+
async detectInstalled() {
|
|
270
254
|
return {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
type: "browser",
|
|
279
|
-
icon: source.icon
|
|
280
|
-
}),
|
|
281
|
-
detect: () => source.detect(),
|
|
282
|
-
provider: () => this.guard(source.provider(), registration),
|
|
283
|
-
teardown: () => teardown(source),
|
|
284
|
-
restore: async () => {
|
|
285
|
-
const operation = this.operation;
|
|
286
|
-
if (!operation) throw disconnected();
|
|
287
|
-
try {
|
|
288
|
-
const raw = source.restore ? await abortable(source.restore(), operation.abort.signal) : source.provider();
|
|
289
|
-
if (!raw) return null;
|
|
290
|
-
const provider = raw;
|
|
291
|
-
operation.identity = await readIdentity(provider, registration, operation.abort.signal);
|
|
292
|
-
return this.guard(provider, registration);
|
|
293
|
-
} catch (error) {
|
|
294
|
-
teardown(source);
|
|
295
|
-
throw error;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
guard(raw, registration) {
|
|
301
|
-
const provider = {
|
|
302
|
-
request: async (args) => {
|
|
303
|
-
if (this.disposed) throw disconnected();
|
|
304
|
-
if (args.method !== "connect") {
|
|
305
|
-
if (this.client?.getActiveSession()?.provider !== provider) throw disconnected();
|
|
306
|
-
if (!this.projection && args.method !== "disconnect") throw disconnected();
|
|
307
|
-
if (this.identityRefreshing && ![
|
|
308
|
-
"status",
|
|
309
|
-
"getPrimaryAccount",
|
|
310
|
-
"listAccounts",
|
|
311
|
-
"getActiveNetwork",
|
|
312
|
-
"isConnected"
|
|
313
|
-
].includes(args.method)) {
|
|
314
|
-
throw new Error("Native wallet identity is being refreshed");
|
|
315
|
-
}
|
|
316
|
-
const result = await (args.method === "disconnect" && this.operation ? abortable(raw.request(args), this.operation.abort.signal) : raw.request(args));
|
|
317
|
-
if (args.method === "status") {
|
|
318
|
-
const status = result;
|
|
319
|
-
if (status?.isConnected === false || status?.connection?.isConnected === false) {
|
|
320
|
-
this.invalidate(registration.id);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
return result;
|
|
324
|
-
}
|
|
325
|
-
const operation = this.operation;
|
|
326
|
-
if (!operation || operation.abort.signal.aborted) throw disconnected();
|
|
327
|
-
const response = await abortable(raw.request(args), operation.abort.signal);
|
|
328
|
-
assertConnectionAccepted(response);
|
|
329
|
-
operation.identity = await readIdentity(raw, registration, operation.abort.signal);
|
|
330
|
-
return response;
|
|
331
|
-
},
|
|
332
|
-
on: (event, listener) => {
|
|
333
|
-
raw.on(event, listener);
|
|
334
|
-
return provider;
|
|
335
|
-
},
|
|
336
|
-
emit: (event, ...args) => raw.emit(event, ...args),
|
|
337
|
-
removeListener: (event, listener) => {
|
|
338
|
-
raw.removeListener(event, listener);
|
|
339
|
-
return provider;
|
|
340
|
-
}
|
|
255
|
+
installed: true,
|
|
256
|
+
// Presence by CONSTRUCTION: this adapter only exists because an announce
|
|
257
|
+
// arrived on the wallet's own target channel. There is no probe to be
|
|
258
|
+
// wrong about, which is why this is the one path that cannot report a
|
|
259
|
+
// wallet that is not there.
|
|
260
|
+
availability: { kind: "installed" },
|
|
261
|
+
reason: "Announced via canton:announceProvider"
|
|
341
262
|
};
|
|
342
|
-
return provider;
|
|
343
263
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
const previousId = this.projection?.id;
|
|
355
|
-
this.projection = null;
|
|
356
|
-
if (previousId) this.changed(previousId, null);
|
|
357
|
-
const abort = () => operation.abort.abort();
|
|
358
|
-
if (signal?.aborted) abort();
|
|
359
|
-
signal?.addEventListener("abort", abort, { once: true });
|
|
360
|
-
const task = (async () => {
|
|
264
|
+
async connect(ctx, options) {
|
|
265
|
+
return this.guarded(async () => {
|
|
266
|
+
const owner = nativeOwnerBindings.get(this);
|
|
267
|
+
const native = owner ? await owner.connect(String(this.walletId), options?.signal) : void 0;
|
|
268
|
+
if (!owner) assertConnectionAccepted(await this.provider.request({ method: "connect" }));
|
|
269
|
+
const account = native?.account ?? await this.provider.request({
|
|
270
|
+
method: "getPrimaryAccount"
|
|
271
|
+
});
|
|
272
|
+
assertPrimaryParty(account);
|
|
273
|
+
let status;
|
|
361
274
|
try {
|
|
362
|
-
await this.
|
|
363
|
-
|
|
364
|
-
throw disconnected();
|
|
365
|
-
this.projection = { id, identity: operation.identity };
|
|
366
|
-
this.attach(id);
|
|
367
|
-
return operation.identity;
|
|
368
|
-
} catch (error) {
|
|
369
|
-
this.client?.destroy();
|
|
370
|
-
this.client = null;
|
|
371
|
-
this.initialization = null;
|
|
372
|
-
teardown(this.registrations.get(id)?.source);
|
|
373
|
-
throw error;
|
|
374
|
-
} finally {
|
|
375
|
-
signal?.removeEventListener("abort", abort);
|
|
376
|
-
if (this.operation === operation) this.operation = null;
|
|
275
|
+
status = native?.status ?? await this.provider.request({ method: "status" });
|
|
276
|
+
} catch {
|
|
377
277
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
278
|
+
const reportedNetwork = status?.network?.networkId;
|
|
279
|
+
const partyId = toPartyId(account.partyId);
|
|
280
|
+
const network = [reportedNetwork, account.networkId, ctx.network].find(
|
|
281
|
+
(n) => typeof n === "string" && isRecognizedNetwork(n)
|
|
282
|
+
) ?? ctx.network;
|
|
283
|
+
const session = {
|
|
284
|
+
walletId: this.walletId,
|
|
285
|
+
partyId,
|
|
286
|
+
network
|
|
287
|
+
};
|
|
288
|
+
if (this.metadataEnabled) {
|
|
289
|
+
session.metadata = { ...this.staticMetadata ?? {}, ...buildMetadata(status, account) };
|
|
386
290
|
}
|
|
387
|
-
|
|
388
|
-
|
|
291
|
+
return { partyId, session, capabilities: this.getCapabilities() };
|
|
292
|
+
});
|
|
389
293
|
}
|
|
390
|
-
async
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
const timeout = setTimeout(() => operation.abort.abort(), SILENT_PROBE_TIMEOUT_MS);
|
|
397
|
-
const task = (async () => {
|
|
398
|
-
try {
|
|
399
|
-
await this.client.restorePersistedSessionIfNeeded();
|
|
400
|
-
const active = this.client?.getActiveSession();
|
|
401
|
-
if (!active || !operation.identity || operation.abort.signal.aborted || this.disposed)
|
|
402
|
-
return null;
|
|
403
|
-
if (expected && active.providerId !== expected.id) {
|
|
404
|
-
teardown(active.adapter);
|
|
405
|
-
this.client.destroy();
|
|
406
|
-
this.client = null;
|
|
407
|
-
this.initialization = null;
|
|
408
|
-
return null;
|
|
409
|
-
}
|
|
410
|
-
const id = String(active.providerId);
|
|
411
|
-
this.projection = { id, identity: operation.identity };
|
|
412
|
-
this.attach(id);
|
|
413
|
-
return this.getSession();
|
|
414
|
-
} finally {
|
|
415
|
-
clearTimeout(timeout);
|
|
416
|
-
if (registration) delete registration.expected;
|
|
417
|
-
if (this.operation === operation) this.operation = null;
|
|
418
|
-
}
|
|
419
|
-
})();
|
|
420
|
-
this.pending = task;
|
|
294
|
+
async disconnect() {
|
|
295
|
+
const owner = nativeOwnerBindings.get(this);
|
|
296
|
+
if (owner) {
|
|
297
|
+
await owner.disconnect();
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
421
300
|
try {
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
if (this.pending === task) this.pending = null;
|
|
301
|
+
await this.provider.request({ method: "disconnect" });
|
|
302
|
+
} catch {
|
|
425
303
|
}
|
|
426
304
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
305
|
+
// Real signMessage implementation. Exposed as `this.signMessage` from the ctor
|
|
306
|
+
// only when the wallet declares support, so getCapabilities and feature
|
|
307
|
+
// detection stay honest for a wallet that cannot sign.
|
|
308
|
+
async signMessageImpl(_ctx, session, params) {
|
|
309
|
+
return this.guarded(async () => {
|
|
310
|
+
const rpcParams = this.signMessageBase64 ? { message: toBase64Message(params.message) } : { message: params.message };
|
|
311
|
+
const res = await this.provider.request({ method: "signMessage", params: rpcParams });
|
|
312
|
+
return normalizeSignedMessage(res, session, params);
|
|
313
|
+
});
|
|
430
314
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
315
|
+
async submitTransaction(ctx, _session, params) {
|
|
316
|
+
return this.guarded(
|
|
317
|
+
() => submitViaPrepareExecute(this.provider, params, {
|
|
318
|
+
walletId: String(this.walletId),
|
|
319
|
+
state: this.executeVerb,
|
|
320
|
+
logger: ctx.logger
|
|
321
|
+
})
|
|
322
|
+
);
|
|
434
323
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
324
|
+
// ── Optional-method factories (assigned only when configured) ──────────────
|
|
325
|
+
/** events: bridge the provider's CIP-0103 `txChanged` push event → `txStatus`. */
|
|
326
|
+
makeOn() {
|
|
327
|
+
return (event, handler) => {
|
|
328
|
+
if (event !== "txStatus") return () => {
|
|
329
|
+
};
|
|
330
|
+
const listener = (...args) => {
|
|
331
|
+
const tx = args[0];
|
|
332
|
+
if (!tx) return;
|
|
333
|
+
handler({ status: mapTxStatus(tx.status), commandId: tx.commandId, raw: tx });
|
|
334
|
+
};
|
|
335
|
+
try {
|
|
336
|
+
this.provider.on("txChanged", listener);
|
|
337
|
+
} catch {
|
|
338
|
+
return () => {
|
|
339
|
+
};
|
|
450
340
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
throw error;
|
|
454
|
-
} finally {
|
|
455
|
-
if (revision === this.refreshRevision) this.identityRefreshing = false;
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
async probe(provider, registration) {
|
|
459
|
-
const abort = new AbortController();
|
|
460
|
-
this.probes.add(abort);
|
|
461
|
-
const timeout = setTimeout(() => abort.abort(), SILENT_PROBE_TIMEOUT_MS);
|
|
462
|
-
try {
|
|
463
|
-
return await readIdentity(provider, registration, abort.signal);
|
|
464
|
-
} finally {
|
|
465
|
-
clearTimeout(timeout);
|
|
466
|
-
this.probes.delete(abort);
|
|
467
|
-
}
|
|
341
|
+
return () => this.provider.removeListener("txChanged", listener);
|
|
342
|
+
};
|
|
468
343
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
this.
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
344
|
+
/** restore: silent status()/getPrimaryAccount() probe + expiry + party-match. */
|
|
345
|
+
makeRestore() {
|
|
346
|
+
return (_ctx, persisted) => this.guarded(async () => {
|
|
347
|
+
const owner = nativeOwnerBindings.get(this);
|
|
348
|
+
if (owner) {
|
|
349
|
+
await this.prepareNativeConnection(_ctx.network);
|
|
350
|
+
const restored = await owner.restore({ id: String(this.walletId), partyId: persisted.partyId, network: persisted.network });
|
|
351
|
+
return restored?.id === String(this.walletId) ? { ...persisted, capabilitiesSnapshot: this.getCapabilities() } : null;
|
|
352
|
+
}
|
|
353
|
+
if (persisted.expiresAt && Date.now() >= persisted.expiresAt) return null;
|
|
354
|
+
let status;
|
|
475
355
|
try {
|
|
476
|
-
|
|
356
|
+
status = await this.provider.request({ method: "status" });
|
|
477
357
|
} catch {
|
|
478
358
|
}
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
return;
|
|
488
|
-
}
|
|
489
|
-
const revision = ++this.refreshRevision;
|
|
490
|
-
this.identityRefreshing = true;
|
|
491
|
-
const registration = this.registrations.get(id);
|
|
492
|
-
void this.probe(provider, registration).then(
|
|
493
|
-
(identity2) => {
|
|
494
|
-
if (revision !== this.refreshRevision || this.projection?.id !== id || this.disposed)
|
|
495
|
-
return;
|
|
496
|
-
this.identityRefreshing = false;
|
|
497
|
-
this.projection = { id, identity: identity2 };
|
|
498
|
-
this.changed(id, identity2);
|
|
499
|
-
},
|
|
500
|
-
() => {
|
|
501
|
-
if (revision === this.refreshRevision) this.invalidate(id);
|
|
502
|
-
}
|
|
359
|
+
const connected = status?.isConnected ?? status?.connection?.isConnected;
|
|
360
|
+
if (connected === false) return null;
|
|
361
|
+
const account = await this.provider.request({
|
|
362
|
+
method: "getPrimaryAccount"
|
|
363
|
+
});
|
|
364
|
+
if (account.partyId !== persisted.partyId) return null;
|
|
365
|
+
const network = [status?.network?.networkId, account.networkId].find(
|
|
366
|
+
(value) => typeof value === "string" && isRecognizedNetwork(value)
|
|
503
367
|
);
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
this.client = null;
|
|
517
|
-
this.initialization = null;
|
|
518
|
-
this.changed(id, null);
|
|
519
|
-
}
|
|
520
|
-
/** Local transport cleanup when switching to a proprietary integration. */
|
|
521
|
-
release() {
|
|
522
|
-
this.assertAvailable();
|
|
523
|
-
const id = this.projection?.id;
|
|
524
|
-
this.detach();
|
|
525
|
-
this.projection = null;
|
|
526
|
-
teardown(this.client?.getActiveSession()?.adapter);
|
|
527
|
-
this.client?.destroy();
|
|
528
|
-
this.client = null;
|
|
529
|
-
this.initialization = null;
|
|
530
|
-
if (id) this.changed(id, null);
|
|
368
|
+
if (network && detectNetworkMismatch(persisted.network, network)) return null;
|
|
369
|
+
return {
|
|
370
|
+
...persisted,
|
|
371
|
+
walletId: this.walletId,
|
|
372
|
+
// persisted (lowest) → static config → runtime RPC (wins).
|
|
373
|
+
metadata: {
|
|
374
|
+
...persisted.metadata ?? {},
|
|
375
|
+
...this.staticMetadata ?? {},
|
|
376
|
+
...buildMetadata(status, account)
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
});
|
|
531
380
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
this.
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const operation = { abort: new AbortController() };
|
|
542
|
-
this.operation = operation;
|
|
543
|
-
const timeout = setTimeout(() => operation.abort.abort(), SILENT_PROBE_TIMEOUT_MS);
|
|
544
|
-
try {
|
|
545
|
-
await this.client?.disconnect();
|
|
546
|
-
} finally {
|
|
547
|
-
clearTimeout(timeout);
|
|
548
|
-
if (this.client?.getActiveSession()) {
|
|
549
|
-
this.client.destroy();
|
|
550
|
-
this.client = null;
|
|
551
|
-
this.initialization = null;
|
|
381
|
+
/** ledgerApi: proxy the standard CIP-0103 ledgerApi call; shape to {response:string}. */
|
|
382
|
+
makeLedgerApi() {
|
|
383
|
+
return (_ctx, _session, params) => this.guarded(async () => {
|
|
384
|
+
const result = await this.provider.request({
|
|
385
|
+
method: "ledgerApi",
|
|
386
|
+
params: {
|
|
387
|
+
requestMethod: normalizeLedgerMethodLower(params.requestMethod),
|
|
388
|
+
resource: params.resource,
|
|
389
|
+
body: ledgerApiBodyToObject(params.body)
|
|
552
390
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
}
|
|
556
|
-
})
|
|
557
|
-
this.closing = task;
|
|
558
|
-
void task.then(
|
|
559
|
-
() => {
|
|
560
|
-
if (this.closing === task) this.closing = null;
|
|
561
|
-
},
|
|
562
|
-
() => {
|
|
563
|
-
if (this.closing === task) this.closing = null;
|
|
564
|
-
}
|
|
565
|
-
);
|
|
566
|
-
return task;
|
|
391
|
+
});
|
|
392
|
+
if (result && typeof result.response === "string") return { response: result.response };
|
|
393
|
+
return { response: JSON.stringify(result ?? null) };
|
|
394
|
+
});
|
|
567
395
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
if (!this.
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Run an operation, giving the optional `mapError` hook first crack at any
|
|
398
|
+
* thrown error. With NO hook configured this is a direct pass-through (no
|
|
399
|
+
* try/catch) — byte-identical to the baseline, and the SDK's built-in standard
|
|
400
|
+
* error mapping still applies downstream.
|
|
401
|
+
*/
|
|
402
|
+
async guarded(op) {
|
|
403
|
+
if (!this.mapError) return op();
|
|
404
|
+
try {
|
|
405
|
+
return await op();
|
|
406
|
+
} catch (err) {
|
|
407
|
+
const mapped = this.mapError(err);
|
|
408
|
+
throw mapped ?? err;
|
|
409
|
+
}
|
|
579
410
|
}
|
|
580
411
|
};
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
function announcedWalletId(announceId) {
|
|
596
|
-
return toWalletId(`${ANNOUNCED_WALLET_ID_PREFIX}${announceId}`);
|
|
597
|
-
}
|
|
598
|
-
function mapTxStatus(status) {
|
|
599
|
-
switch (status) {
|
|
600
|
-
case "pending":
|
|
601
|
-
return "pending";
|
|
602
|
-
case "signed":
|
|
603
|
-
return "submitted";
|
|
604
|
-
case "executed":
|
|
605
|
-
return "committed";
|
|
606
|
-
case "failed":
|
|
607
|
-
default:
|
|
608
|
-
return "failed";
|
|
609
|
-
}
|
|
412
|
+
function buildMetadata(status, account) {
|
|
413
|
+
const meta = {};
|
|
414
|
+
const put = (k, v) => {
|
|
415
|
+
if (typeof v === "string" && v.length > 0) meta[k] = v;
|
|
416
|
+
};
|
|
417
|
+
put("kernelId", status?.kernel?.id);
|
|
418
|
+
put("publicKey", account.publicKey);
|
|
419
|
+
put("namespace", account.namespace);
|
|
420
|
+
put("networkId", account.networkId);
|
|
421
|
+
put("signingProviderId", account.signingProviderId);
|
|
422
|
+
put("hint", account.hint);
|
|
423
|
+
put("ledgerApiBaseUrl", status?.network?.ledgerApi?.baseUrl);
|
|
424
|
+
put("userId", status?.session?.userId);
|
|
425
|
+
return meta;
|
|
610
426
|
}
|
|
611
|
-
function
|
|
612
|
-
const
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
427
|
+
function getDiscoveryCapabilities(declared) {
|
|
428
|
+
const capabilities = ["connect", "disconnect"];
|
|
429
|
+
if (declared?.signMessage !== false) capabilities.push("signMessage");
|
|
430
|
+
if (declared?.submitTransaction !== false) capabilities.push("submitTransaction");
|
|
431
|
+
if (declared?.ledgerApi) capabilities.push("ledgerApi");
|
|
432
|
+
return capabilities;
|
|
616
433
|
}
|
|
617
|
-
var
|
|
434
|
+
var GenericDiscoveryAdapter = class _GenericDiscoveryAdapter {
|
|
618
435
|
walletId;
|
|
619
436
|
name;
|
|
620
|
-
/** Icon surfaced to the picker (announce detail). */
|
|
621
437
|
icon;
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Resolved official adapter. Set at construction for the instance form; for
|
|
440
|
+
* the factory form it stays null until {@link resolveOfficial} constructs it
|
|
441
|
+
* with the network-resolved host.
|
|
442
|
+
*/
|
|
443
|
+
official;
|
|
444
|
+
/** Factory form (null for the instance form). */
|
|
445
|
+
factory;
|
|
446
|
+
/** Network→host map for the factory form; injected by the SDK post-registry. */
|
|
447
|
+
networkHosts;
|
|
448
|
+
/** Lazily resolved from `official.provider()` — NOT at construction (SSR-safe). */
|
|
449
|
+
providerInstance = null;
|
|
627
450
|
/**
|
|
628
451
|
* Which execute verb this wallet turned out to support. Resolved on the first
|
|
629
452
|
* submit and reused, so the wallet is asked at most once.
|
|
630
453
|
*/
|
|
631
454
|
executeVerb = {};
|
|
632
|
-
|
|
633
|
-
// so `getCapabilities()` and `'x' in adapter` feature-detection stay honest.
|
|
634
|
-
restore;
|
|
635
|
-
on;
|
|
636
|
-
ledgerApi;
|
|
637
|
-
// signMessage is optional too: assigned in the ctor only when the wallet
|
|
638
|
-
// declares support, so a wallet that cannot sign is not advertised as able to.
|
|
639
|
-
signMessage;
|
|
640
|
-
constructor(args) {
|
|
641
|
-
const configuration = { ...args, config: args.config && {
|
|
642
|
-
...args.config,
|
|
643
|
-
staticMetadata: args.config.staticMetadata && { ...args.config.staticMetadata }
|
|
644
|
-
} };
|
|
645
|
-
nativeAdapterCopies.set(this, () => new _GenericAnnounceAdapter(configuration));
|
|
646
|
-
this.walletId = args.walletId ?? announcedWalletId(args.announceId);
|
|
647
|
-
this.name = args.name && args.name.length > 0 ? args.name : `Canton Wallet (${args.announceId.slice(0, 6)}\u2026)`;
|
|
648
|
-
this.icon = args.icon;
|
|
649
|
-
this.rawProvider = args.provider;
|
|
650
|
-
const config = args.config;
|
|
651
|
-
this.metadataEnabled = config?.metadata === true;
|
|
652
|
-
this.staticMetadata = config?.staticMetadata;
|
|
653
|
-
this.mapError = config?.mapError;
|
|
654
|
-
this.signMessageBase64 = config?.signMessageBase64 === true;
|
|
655
|
-
if (config?.events) this.on = this.makeOn();
|
|
656
|
-
if (config?.restore) this.restore = this.makeRestore();
|
|
657
|
-
if (config?.ledgerApi) this.ledgerApi = this.makeLedgerApi();
|
|
658
|
-
if (config?.signMessage !== false) this.signMessage = this.signMessageImpl.bind(this);
|
|
659
|
-
}
|
|
660
|
-
get provider() {
|
|
661
|
-
return nativeOwnerBindings.get(this)?.getProvider(String(this.walletId)) ?? this.rawProvider;
|
|
662
|
-
}
|
|
663
|
-
/** @internal Register the discovered transport with the one official owner. */
|
|
664
|
-
async prepareNativeConnection(network) {
|
|
665
|
-
const owner = nativeOwnerBindings.get(this);
|
|
666
|
-
if (!owner) return;
|
|
667
|
-
await owner.prepare(String(this.walletId), {
|
|
668
|
-
providerId: String(this.walletId),
|
|
669
|
-
name: this.name,
|
|
670
|
-
type: "browser",
|
|
671
|
-
icon: this.icon,
|
|
672
|
-
provider: () => this.rawProvider,
|
|
673
|
-
detect: async () => true
|
|
674
|
-
}, network);
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* Capabilities derived from actual presence: connect and submitTransaction are
|
|
678
|
-
* always present; signMessage, restore, ledgerApi, and events are each included
|
|
679
|
-
* only when the matching method was assigned, so the set is never advertised
|
|
680
|
-
* beyond what the adapter can do.
|
|
681
|
-
*/
|
|
682
|
-
getCapabilities() {
|
|
683
|
-
return getAnnounceCapabilities({
|
|
684
|
-
signMessage: !!this.signMessage,
|
|
685
|
-
restore: !!this.restore,
|
|
686
|
-
ledgerApi: !!this.ledgerApi,
|
|
687
|
-
events: !!this.on
|
|
688
|
-
});
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* The adapter is only ever constructed for a wallet that just announced, so
|
|
692
|
-
* its presence is established by the announce handshake itself.
|
|
693
|
-
*/
|
|
694
|
-
async detectInstalled() {
|
|
695
|
-
return {
|
|
696
|
-
installed: true,
|
|
697
|
-
// Presence by CONSTRUCTION: this adapter only exists because an announce
|
|
698
|
-
// arrived on the wallet's own target channel. There is no probe to be
|
|
699
|
-
// wrong about, which is why this is the one path that cannot report a
|
|
700
|
-
// wallet that is not there.
|
|
701
|
-
availability: { kind: "installed" },
|
|
702
|
-
reason: "Announced via canton:announceProvider"
|
|
703
|
-
};
|
|
704
|
-
}
|
|
705
|
-
async connect(ctx, options) {
|
|
706
|
-
return this.guarded(async () => {
|
|
707
|
-
const owner = nativeOwnerBindings.get(this);
|
|
708
|
-
const native = owner ? await owner.connect(String(this.walletId), options?.signal) : void 0;
|
|
709
|
-
if (!owner) assertConnectionAccepted(await this.provider.request({ method: "connect" }));
|
|
710
|
-
const account = native?.account ?? await this.provider.request({
|
|
711
|
-
method: "getPrimaryAccount"
|
|
712
|
-
});
|
|
713
|
-
assertPrimaryParty(account);
|
|
714
|
-
let status;
|
|
715
|
-
try {
|
|
716
|
-
status = native?.status ?? await this.provider.request({ method: "status" });
|
|
717
|
-
} catch {
|
|
718
|
-
}
|
|
719
|
-
const reportedNetwork = status?.network?.networkId;
|
|
720
|
-
const partyId = toPartyId(account.partyId);
|
|
721
|
-
const network = [reportedNetwork, account.networkId, ctx.network].find(
|
|
722
|
-
(n) => typeof n === "string" && isRecognizedNetwork(n)
|
|
723
|
-
) ?? ctx.network;
|
|
724
|
-
const session = {
|
|
725
|
-
walletId: this.walletId,
|
|
726
|
-
partyId,
|
|
727
|
-
network
|
|
728
|
-
};
|
|
729
|
-
if (this.metadataEnabled) {
|
|
730
|
-
session.metadata = { ...this.staticMetadata ?? {}, ...buildMetadata(status, account) };
|
|
731
|
-
}
|
|
732
|
-
return { partyId, session, capabilities: this.getCapabilities() };
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
async disconnect() {
|
|
736
|
-
const owner = nativeOwnerBindings.get(this);
|
|
737
|
-
if (owner) {
|
|
738
|
-
await owner.disconnect();
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
try {
|
|
742
|
-
await this.provider.request({ method: "disconnect" });
|
|
743
|
-
} catch {
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
// Real signMessage implementation. Exposed as `this.signMessage` from the ctor
|
|
747
|
-
// only when the wallet declares support, so getCapabilities and feature
|
|
748
|
-
// detection stay honest for a wallet that cannot sign.
|
|
749
|
-
async signMessageImpl(_ctx, session, params) {
|
|
750
|
-
return this.guarded(async () => {
|
|
751
|
-
const rpcParams = this.signMessageBase64 ? { message: toBase64Message(params.message) } : { message: params.message };
|
|
752
|
-
const res = await this.provider.request({ method: "signMessage", params: rpcParams });
|
|
753
|
-
return normalizeSignedMessage(res, session, params);
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
|
-
async submitTransaction(ctx, _session, params) {
|
|
757
|
-
return this.guarded(
|
|
758
|
-
() => submitViaPrepareExecute(this.provider, params, {
|
|
759
|
-
walletId: String(this.walletId),
|
|
760
|
-
state: this.executeVerb,
|
|
761
|
-
logger: ctx.logger
|
|
762
|
-
})
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
|
-
// ── Optional-method factories (assigned only when configured) ──────────────
|
|
766
|
-
/** events: bridge the provider's CIP-0103 `txChanged` push event → `txStatus`. */
|
|
767
|
-
makeOn() {
|
|
768
|
-
return (event, handler) => {
|
|
769
|
-
if (event !== "txStatus") return () => {
|
|
770
|
-
};
|
|
771
|
-
const listener = (...args) => {
|
|
772
|
-
const tx = args[0];
|
|
773
|
-
if (!tx) return;
|
|
774
|
-
handler({ status: mapTxStatus(tx.status), commandId: tx.commandId, raw: tx });
|
|
775
|
-
};
|
|
776
|
-
try {
|
|
777
|
-
this.provider.on("txChanged", listener);
|
|
778
|
-
} catch {
|
|
779
|
-
return () => {
|
|
780
|
-
};
|
|
781
|
-
}
|
|
782
|
-
return () => this.provider.removeListener("txChanged", listener);
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
/** restore: silent status()/getPrimaryAccount() probe + expiry + party-match. */
|
|
786
|
-
makeRestore() {
|
|
787
|
-
return (_ctx, persisted) => this.guarded(async () => {
|
|
788
|
-
const owner = nativeOwnerBindings.get(this);
|
|
789
|
-
if (owner) {
|
|
790
|
-
await this.prepareNativeConnection(_ctx.network);
|
|
791
|
-
const restored = await owner.restore({ id: String(this.walletId), partyId: persisted.partyId, network: persisted.network });
|
|
792
|
-
return restored?.id === String(this.walletId) ? { ...persisted, capabilitiesSnapshot: this.getCapabilities() } : null;
|
|
793
|
-
}
|
|
794
|
-
if (persisted.expiresAt && Date.now() >= persisted.expiresAt) return null;
|
|
795
|
-
let status;
|
|
796
|
-
try {
|
|
797
|
-
status = await this.provider.request({ method: "status" });
|
|
798
|
-
} catch {
|
|
799
|
-
}
|
|
800
|
-
const connected = status?.isConnected ?? status?.connection?.isConnected;
|
|
801
|
-
if (connected === false) return null;
|
|
802
|
-
const account = await this.provider.request({
|
|
803
|
-
method: "getPrimaryAccount"
|
|
804
|
-
});
|
|
805
|
-
if (account.partyId !== persisted.partyId) return null;
|
|
806
|
-
const network = [status?.network?.networkId, account.networkId].find(
|
|
807
|
-
(value) => typeof value === "string" && isRecognizedNetwork(value)
|
|
808
|
-
);
|
|
809
|
-
if (network && detectNetworkMismatch(persisted.network, network)) return null;
|
|
810
|
-
return {
|
|
811
|
-
...persisted,
|
|
812
|
-
walletId: this.walletId,
|
|
813
|
-
// persisted (lowest) → static config → runtime RPC (wins).
|
|
814
|
-
metadata: {
|
|
815
|
-
...persisted.metadata ?? {},
|
|
816
|
-
...this.staticMetadata ?? {},
|
|
817
|
-
...buildMetadata(status, account)
|
|
818
|
-
}
|
|
819
|
-
};
|
|
820
|
-
});
|
|
821
|
-
}
|
|
822
|
-
/** ledgerApi: proxy the standard CIP-0103 ledgerApi call; shape to {response:string}. */
|
|
823
|
-
makeLedgerApi() {
|
|
824
|
-
return (_ctx, _session, params) => this.guarded(async () => {
|
|
825
|
-
const result = await this.provider.request({
|
|
826
|
-
method: "ledgerApi",
|
|
827
|
-
params: {
|
|
828
|
-
requestMethod: normalizeLedgerMethodLower(params.requestMethod),
|
|
829
|
-
resource: params.resource,
|
|
830
|
-
body: ledgerApiBodyToObject(params.body)
|
|
831
|
-
}
|
|
832
|
-
});
|
|
833
|
-
if (result && typeof result.response === "string") return { response: result.response };
|
|
834
|
-
return { response: JSON.stringify(result ?? null) };
|
|
835
|
-
});
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Run an operation, giving the optional `mapError` hook first crack at any
|
|
839
|
-
* thrown error. With NO hook configured this is a direct pass-through (no
|
|
840
|
-
* try/catch) — byte-identical to the baseline, and the SDK's built-in standard
|
|
841
|
-
* error mapping still applies downstream.
|
|
842
|
-
*/
|
|
843
|
-
async guarded(op) {
|
|
844
|
-
if (!this.mapError) return op();
|
|
845
|
-
try {
|
|
846
|
-
return await op();
|
|
847
|
-
} catch (err) {
|
|
848
|
-
const mapped = this.mapError(err);
|
|
849
|
-
throw mapped ?? err;
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
};
|
|
853
|
-
function buildMetadata(status, account) {
|
|
854
|
-
const meta = {};
|
|
855
|
-
const put = (k, v) => {
|
|
856
|
-
if (typeof v === "string" && v.length > 0) meta[k] = v;
|
|
857
|
-
};
|
|
858
|
-
put("kernelId", status?.kernel?.id);
|
|
859
|
-
put("publicKey", account.publicKey);
|
|
860
|
-
put("namespace", account.namespace);
|
|
861
|
-
put("networkId", account.networkId);
|
|
862
|
-
put("signingProviderId", account.signingProviderId);
|
|
863
|
-
put("hint", account.hint);
|
|
864
|
-
put("ledgerApiBaseUrl", status?.network?.ledgerApi?.baseUrl);
|
|
865
|
-
put("userId", status?.session?.userId);
|
|
866
|
-
return meta;
|
|
867
|
-
}
|
|
868
|
-
function getDiscoveryCapabilities(declared) {
|
|
869
|
-
const capabilities = ["connect", "disconnect"];
|
|
870
|
-
if (declared?.signMessage !== false) capabilities.push("signMessage");
|
|
871
|
-
if (declared?.submitTransaction !== false) capabilities.push("submitTransaction");
|
|
872
|
-
if (declared?.ledgerApi) capabilities.push("ledgerApi");
|
|
873
|
-
return capabilities;
|
|
874
|
-
}
|
|
875
|
-
var GenericDiscoveryAdapter = class _GenericDiscoveryAdapter {
|
|
876
|
-
walletId;
|
|
877
|
-
name;
|
|
878
|
-
icon;
|
|
879
|
-
/**
|
|
880
|
-
* Resolved official adapter. Set at construction for the instance form; for
|
|
881
|
-
* the factory form it stays null until {@link resolveOfficial} constructs it
|
|
882
|
-
* with the network-resolved host.
|
|
883
|
-
*/
|
|
884
|
-
official;
|
|
885
|
-
/** Factory form (null for the instance form). */
|
|
886
|
-
factory;
|
|
887
|
-
/** Network→host map for the factory form; injected by the SDK post-registry. */
|
|
888
|
-
networkHosts;
|
|
889
|
-
/** Lazily resolved from `official.provider()` — NOT at construction (SSR-safe). */
|
|
890
|
-
providerInstance = null;
|
|
891
|
-
/**
|
|
892
|
-
* Which execute verb this wallet turned out to support. Resolved on the first
|
|
893
|
-
* submit and reused, so the wallet is asked at most once.
|
|
894
|
-
*/
|
|
895
|
-
executeVerb = {};
|
|
896
|
-
capabilities;
|
|
455
|
+
capabilities;
|
|
897
456
|
ledgerApi;
|
|
898
457
|
constructor(args) {
|
|
899
458
|
const configuration = { ...args, capabilities: args.capabilities && { ...args.capabilities } };
|
|
@@ -1129,6 +688,12 @@ function createSessionProvider(options) {
|
|
|
1129
688
|
const provider = {
|
|
1130
689
|
request: async (args) => {
|
|
1131
690
|
try {
|
|
691
|
+
if (args === null || typeof args !== "object" || Array.isArray(args) || typeof args.method !== "string") {
|
|
692
|
+
throw new ProviderRpcError("Request must be an object with a string method", JSON_RPC_ERRORS.INVALID_REQUEST);
|
|
693
|
+
}
|
|
694
|
+
if (args.params !== void 0 && (args.params === null || typeof args.params !== "object")) {
|
|
695
|
+
throw new ProviderRpcError("Request params must be an object or array", JSON_RPC_ERRORS.INVALID_PARAMS);
|
|
696
|
+
}
|
|
1132
697
|
if (disposed) throw new Error("PartyLayer client was destroyed");
|
|
1133
698
|
if (args.method === "connect" || args.method === "disconnect" || args.method === "signMessage") {
|
|
1134
699
|
return options.bridge.request(args);
|
|
@@ -1218,7 +783,7 @@ function createSessionProvider(options) {
|
|
|
1218
783
|
};
|
|
1219
784
|
}
|
|
1220
785
|
|
|
1221
|
-
// src/config.ts
|
|
786
|
+
// src/config-base.ts
|
|
1222
787
|
var DEFAULT_REGISTRY_URL = "https://registry.partylayer.xyz";
|
|
1223
788
|
|
|
1224
789
|
// src/adapters.ts
|
|
@@ -1249,54 +814,36 @@ var DefaultCrypto = class {
|
|
|
1249
814
|
);
|
|
1250
815
|
}
|
|
1251
816
|
async encrypt(data, key) {
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
encoded
|
|
1264
|
-
);
|
|
1265
|
-
const combined = new Uint8Array(iv.length + encrypted.byteLength);
|
|
1266
|
-
combined.set(iv);
|
|
1267
|
-
combined.set(new Uint8Array(encrypted), iv.length);
|
|
1268
|
-
return btoa(String.fromCharCode(...combined));
|
|
1269
|
-
} catch {
|
|
1270
|
-
return btoa(data);
|
|
1271
|
-
}
|
|
817
|
+
const iv = new Uint8Array(this.randomBytes(12));
|
|
818
|
+
const cryptoKey = await this.getKey(key);
|
|
819
|
+
const encrypted = await globalThis.crypto.subtle.encrypt(
|
|
820
|
+
{ name: "AES-GCM", iv },
|
|
821
|
+
cryptoKey,
|
|
822
|
+
new TextEncoder().encode(data)
|
|
823
|
+
);
|
|
824
|
+
const combined = new Uint8Array(iv.length + encrypted.byteLength);
|
|
825
|
+
combined.set(iv);
|
|
826
|
+
combined.set(new Uint8Array(encrypted), iv.length);
|
|
827
|
+
return btoa(String.fromCharCode(...combined));
|
|
1272
828
|
}
|
|
1273
829
|
async decrypt(encrypted, key) {
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
return decoder.decode(decrypted);
|
|
1289
|
-
} catch {
|
|
1290
|
-
return atob(encrypted);
|
|
1291
|
-
}
|
|
830
|
+
const cryptoKey = await this.getKey(key);
|
|
831
|
+
const combined = Uint8Array.from(atob(encrypted), (character) => character.charCodeAt(0));
|
|
832
|
+
if (combined.length < 28) throw new Error("Invalid AES-GCM session ciphertext");
|
|
833
|
+
const decrypted = await globalThis.crypto.subtle.decrypt(
|
|
834
|
+
{ name: "AES-GCM", iv: combined.slice(0, 12) },
|
|
835
|
+
cryptoKey,
|
|
836
|
+
combined.slice(12)
|
|
837
|
+
);
|
|
838
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(decrypted);
|
|
839
|
+
}
|
|
840
|
+
randomBytes(byteLength) {
|
|
841
|
+
if (!globalThis.crypto?.getRandomValues) throw new Error("Secure random entropy is unavailable");
|
|
842
|
+
if (!Number.isInteger(byteLength) || byteLength < 1 || byteLength > 65536) throw new Error("Invalid secure byte length");
|
|
843
|
+
return globalThis.crypto.getRandomValues(new Uint8Array(byteLength));
|
|
1292
844
|
}
|
|
1293
845
|
async generateKey() {
|
|
1294
|
-
|
|
1295
|
-
return Math.random().toString(36).substring(2, 15);
|
|
1296
|
-
}
|
|
1297
|
-
const array = new Uint8Array(32);
|
|
1298
|
-
crypto.getRandomValues(array);
|
|
1299
|
-
return Array.from(array, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
846
|
+
return Array.from(this.randomBytes(32), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1300
847
|
}
|
|
1301
848
|
};
|
|
1302
849
|
var DefaultStorage = class {
|
|
@@ -1357,22 +904,6 @@ var DefaultTelemetry = class {
|
|
|
1357
904
|
error(_error, _properties) {
|
|
1358
905
|
}
|
|
1359
906
|
};
|
|
1360
|
-
function getBuiltinAdapters() {
|
|
1361
|
-
return [
|
|
1362
|
-
new LoopAdapter(),
|
|
1363
|
-
// 5N Loop - QR code / popup
|
|
1364
|
-
new Cantor8Adapter(),
|
|
1365
|
-
// Cantor8 - deep link transport
|
|
1366
|
-
new NightlyAdapter()
|
|
1367
|
-
// Nightly - multichain wallet (injected)
|
|
1368
|
-
// Console is served via the generic CIP-0103 announce path (registry
|
|
1369
|
-
// transport:'announce') — no longer in defaults; ConsoleAdapter stays
|
|
1370
|
-
// exported below for opt-in manual/bespoke use.
|
|
1371
|
-
// Send is served via the generic CIP-0103 announce path (registry
|
|
1372
|
-
// transport:'announce') — no longer in defaults; SendAdapter stays exported
|
|
1373
|
-
// below for opt-in manual/bespoke use.
|
|
1374
|
-
];
|
|
1375
|
-
}
|
|
1376
907
|
var SDK_VERSION = "0.3.0";
|
|
1377
908
|
var MetricsTelemetryAdapter = class {
|
|
1378
909
|
config;
|
|
@@ -1636,6 +1167,23 @@ function eventLogLevel(type) {
|
|
|
1636
1167
|
return "info";
|
|
1637
1168
|
}
|
|
1638
1169
|
}
|
|
1170
|
+
var SESSION_ENTROPY_BYTES = 32;
|
|
1171
|
+
function createSecureSessionId(crypto2) {
|
|
1172
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") return generateSessionId();
|
|
1173
|
+
if (!crypto2.randomBytes) throw new Error("Secure session entropy requires platform getRandomValues or CryptoAdapter.randomBytes");
|
|
1174
|
+
const encode = (bytes2) => {
|
|
1175
|
+
if (!(bytes2 instanceof Uint8Array) || bytes2.byteLength !== SESSION_ENTROPY_BYTES) {
|
|
1176
|
+
throw new Error("Session entropy must be a Uint8Array of exactly 32 bytes");
|
|
1177
|
+
}
|
|
1178
|
+
return toSessionId(`session_${Date.now()}_${Array.from(bytes2, (byte) => byte.toString(16).padStart(2, "0")).join("")}`);
|
|
1179
|
+
};
|
|
1180
|
+
const bytes = crypto2.randomBytes(SESSION_ENTROPY_BYTES);
|
|
1181
|
+
if (bytes instanceof Uint8Array) return encode(bytes);
|
|
1182
|
+
if (bytes && typeof bytes.then === "function") return Promise.resolve(bytes).then(encode);
|
|
1183
|
+
throw new Error("Session entropy must be a Uint8Array of exactly 32 bytes");
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// src/client-base.ts
|
|
1639
1187
|
var SESSION_STORAGE_KEY = "active_session";
|
|
1640
1188
|
var WALLETS_CHANGED_DEBOUNCE_MS = 50;
|
|
1641
1189
|
function deriveAnnounceConfig(entry) {
|
|
@@ -1668,7 +1216,55 @@ function matchKnownByIdentity(providerId, base) {
|
|
|
1668
1216
|
});
|
|
1669
1217
|
}
|
|
1670
1218
|
var DEFAULT_CONNECT_TIMEOUT_MS = 12e4;
|
|
1671
|
-
var
|
|
1219
|
+
var PartyLayerClientBase = class {
|
|
1220
|
+
constructor(config, runtime = {}) {
|
|
1221
|
+
this.runtime = runtime;
|
|
1222
|
+
this.config = config;
|
|
1223
|
+
if (config.app.origin) {
|
|
1224
|
+
this.origin = config.app.origin;
|
|
1225
|
+
} else if (typeof window !== "undefined") {
|
|
1226
|
+
this.origin = window.location.origin;
|
|
1227
|
+
} else {
|
|
1228
|
+
this.origin = "unknown";
|
|
1229
|
+
}
|
|
1230
|
+
this.logger = config.logger || new DefaultLogger();
|
|
1231
|
+
this.logLevel = config.logLevel ?? "info";
|
|
1232
|
+
this.crypto = config.crypto || new DefaultCrypto();
|
|
1233
|
+
this.storage = config.storage || new DefaultStorage();
|
|
1234
|
+
if (typeof window !== "undefined" && runtime.createOwner) {
|
|
1235
|
+
this.nativeOwner = runtime.createOwner((id, identity2) => this.onNativeIdentityChanged(id, identity2));
|
|
1236
|
+
}
|
|
1237
|
+
const telemetryAdapter = createTelemetryAdapter(config.telemetry);
|
|
1238
|
+
this.telemetry = telemetryAdapter || new DefaultTelemetry();
|
|
1239
|
+
const defaults = config.adapters ?? runtime.getBuiltinAdapters?.() ?? [];
|
|
1240
|
+
const adaptersToRegister = [...defaults, ...config.additionalAdapters ?? []];
|
|
1241
|
+
for (const adapterOrClass of adaptersToRegister) {
|
|
1242
|
+
let adapter;
|
|
1243
|
+
if (typeof adapterOrClass === "function") {
|
|
1244
|
+
adapter = new adapterOrClass();
|
|
1245
|
+
} else if (isOfficialAdapterFactory(adapterOrClass)) {
|
|
1246
|
+
adapter = new GenericDiscoveryAdapter({ factory: adapterOrClass });
|
|
1247
|
+
} else if (isOfficialProviderAdapter(adapterOrClass)) {
|
|
1248
|
+
adapter = new GenericDiscoveryAdapter({ official: adapterOrClass });
|
|
1249
|
+
} else {
|
|
1250
|
+
adapter = adapterOrClass;
|
|
1251
|
+
}
|
|
1252
|
+
this.registerAdapter(adapter);
|
|
1253
|
+
this.log("debug", "adapter:registered", "Registered wallet adapter", {
|
|
1254
|
+
walletId: adapter.walletId,
|
|
1255
|
+
name: adapter.name,
|
|
1256
|
+
capabilities: adapter.getCapabilities()
|
|
1257
|
+
});
|
|
1258
|
+
}
|
|
1259
|
+
this.registryClient = new RegistryClient({
|
|
1260
|
+
registryUrl: config.registryUrl || DEFAULT_REGISTRY_URL,
|
|
1261
|
+
channel: config.channel || "stable",
|
|
1262
|
+
registryPublicKeys: config.registryPublicKeys,
|
|
1263
|
+
storage: this.storage
|
|
1264
|
+
});
|
|
1265
|
+
this.updateRegistryStatus();
|
|
1266
|
+
if (!config.deferInitialization) this.initialize();
|
|
1267
|
+
}
|
|
1672
1268
|
config;
|
|
1673
1269
|
adapters = /* @__PURE__ */ new Map();
|
|
1674
1270
|
destroyed = false;
|
|
@@ -1718,53 +1314,6 @@ var PartyLayerClient = class {
|
|
|
1718
1314
|
origin;
|
|
1719
1315
|
nativeOwner;
|
|
1720
1316
|
sessionProvider;
|
|
1721
|
-
constructor(config) {
|
|
1722
|
-
this.config = config;
|
|
1723
|
-
if (config.app.origin) {
|
|
1724
|
-
this.origin = config.app.origin;
|
|
1725
|
-
} else if (typeof window !== "undefined") {
|
|
1726
|
-
this.origin = window.location.origin;
|
|
1727
|
-
} else {
|
|
1728
|
-
this.origin = "unknown";
|
|
1729
|
-
}
|
|
1730
|
-
this.logger = config.logger || new DefaultLogger();
|
|
1731
|
-
this.logLevel = config.logLevel ?? "info";
|
|
1732
|
-
this.crypto = config.crypto || new DefaultCrypto();
|
|
1733
|
-
this.storage = config.storage || new DefaultStorage();
|
|
1734
|
-
if (typeof window !== "undefined") {
|
|
1735
|
-
this.nativeOwner = new NativeConnectionOwner((id, identity2) => this.onNativeIdentityChanged(id, identity2));
|
|
1736
|
-
}
|
|
1737
|
-
const telemetryAdapter = createTelemetryAdapter(config.telemetry);
|
|
1738
|
-
this.telemetry = telemetryAdapter || new DefaultTelemetry();
|
|
1739
|
-
const defaults = config.adapters ?? getBuiltinAdapters();
|
|
1740
|
-
const adaptersToRegister = [...defaults, ...config.additionalAdapters ?? []];
|
|
1741
|
-
for (const adapterOrClass of adaptersToRegister) {
|
|
1742
|
-
let adapter;
|
|
1743
|
-
if (typeof adapterOrClass === "function") {
|
|
1744
|
-
adapter = new adapterOrClass();
|
|
1745
|
-
} else if (isOfficialAdapterFactory(adapterOrClass)) {
|
|
1746
|
-
adapter = new GenericDiscoveryAdapter({ factory: adapterOrClass });
|
|
1747
|
-
} else if (isOfficialProviderAdapter(adapterOrClass)) {
|
|
1748
|
-
adapter = new GenericDiscoveryAdapter({ official: adapterOrClass });
|
|
1749
|
-
} else {
|
|
1750
|
-
adapter = adapterOrClass;
|
|
1751
|
-
}
|
|
1752
|
-
this.registerAdapter(adapter);
|
|
1753
|
-
this.log("debug", "adapter:registered", "Registered wallet adapter", {
|
|
1754
|
-
walletId: adapter.walletId,
|
|
1755
|
-
name: adapter.name,
|
|
1756
|
-
capabilities: adapter.getCapabilities()
|
|
1757
|
-
});
|
|
1758
|
-
}
|
|
1759
|
-
this.registryClient = new RegistryClient({
|
|
1760
|
-
registryUrl: config.registryUrl || DEFAULT_REGISTRY_URL,
|
|
1761
|
-
channel: config.channel || "stable",
|
|
1762
|
-
registryPublicKeys: config.registryPublicKeys,
|
|
1763
|
-
storage: this.storage
|
|
1764
|
-
});
|
|
1765
|
-
this.updateRegistryStatus();
|
|
1766
|
-
if (!config.deferInitialization) this.initialize();
|
|
1767
|
-
}
|
|
1768
1317
|
/** Start browser discovery/restoration once; safe for framework effect replay. */
|
|
1769
1318
|
initialize() {
|
|
1770
1319
|
if (this.initialized || this.destroyed) return;
|
|
@@ -1893,7 +1442,7 @@ var PartyLayerClient = class {
|
|
|
1893
1442
|
}
|
|
1894
1443
|
/** Resolve only reviewed default SDKs present in the active registry. */
|
|
1895
1444
|
async ensureDefaultWallets() {
|
|
1896
|
-
if (this.config.adapters !== void 0) return;
|
|
1445
|
+
if (this.config.adapters !== void 0 || !this.runtime.loadDefaultWallet) return;
|
|
1897
1446
|
let registry;
|
|
1898
1447
|
try {
|
|
1899
1448
|
registry = await this.registryClient.getRegistry();
|
|
@@ -1907,7 +1456,7 @@ var PartyLayerClient = class {
|
|
|
1907
1456
|
if (!pending) {
|
|
1908
1457
|
pending = (async () => {
|
|
1909
1458
|
try {
|
|
1910
|
-
const entryAdapter = await loadDefaultWallet(entry.id, this.config, this.origin);
|
|
1459
|
+
const entryAdapter = await this.runtime.loadDefaultWallet(entry.id, this.config, this.origin);
|
|
1911
1460
|
if (!entryAdapter || this.destroyed) return;
|
|
1912
1461
|
const adapter = isOfficialAdapterFactory(entryAdapter) ? new GenericDiscoveryAdapter({
|
|
1913
1462
|
factory: entryAdapter,
|
|
@@ -1954,12 +1503,13 @@ var PartyLayerClient = class {
|
|
|
1954
1503
|
* adapters-only) or every non-announce entry is registered.
|
|
1955
1504
|
*/
|
|
1956
1505
|
async gateUnconnectableEntries(wallets) {
|
|
1506
|
+
if (!this.runtime.browserDiscovery) return wallets.filter((wallet) => this.adapters.has(wallet.walletId));
|
|
1957
1507
|
let hidden = null;
|
|
1958
1508
|
const announceCapabilities = /* @__PURE__ */ new Map();
|
|
1959
1509
|
try {
|
|
1960
1510
|
const registry = await this.registryClient.getRegistry();
|
|
1961
1511
|
for (const entry of registry.wallets) {
|
|
1962
|
-
if (entry.adapter?.transport === "announce") {
|
|
1512
|
+
if (entry.adapter?.transport === "announce" && this.runtime.browserDiscovery) {
|
|
1963
1513
|
announceCapabilities.set(entry.id, getAnnounceCapabilities(deriveAnnounceConfig(entry)));
|
|
1964
1514
|
continue;
|
|
1965
1515
|
}
|
|
@@ -2002,7 +1552,7 @@ var PartyLayerClient = class {
|
|
|
2002
1552
|
* ON in the browser and OFF under SSR (no `window`). Canonical: provider.md.
|
|
2003
1553
|
*/
|
|
2004
1554
|
get announceEnabled() {
|
|
2005
|
-
if (typeof window === "undefined") return false;
|
|
1555
|
+
if (typeof window === "undefined" || !this.runtime.browserDiscovery) return false;
|
|
2006
1556
|
return this.config.discovery?.announce ?? true;
|
|
2007
1557
|
}
|
|
2008
1558
|
/**
|
|
@@ -2263,7 +1813,7 @@ var PartyLayerClient = class {
|
|
|
2263
1813
|
}
|
|
2264
1814
|
}
|
|
2265
1815
|
} else if (availableWallets.length === 0) {
|
|
2266
|
-
throw new WalletNotFoundError("No wallets available");
|
|
1816
|
+
throw new WalletNotFoundError(this.runtime.noWalletsMessage ?? "No wallets available");
|
|
2267
1817
|
} else {
|
|
2268
1818
|
selectedWallet = availableWallets[0];
|
|
2269
1819
|
}
|
|
@@ -2276,8 +1826,7 @@ var PartyLayerClient = class {
|
|
|
2276
1826
|
const walletEntry = await this.registryClient.getWalletEntry(String(selectedWallet.walletId));
|
|
2277
1827
|
if (walletEntry.originAllowlist && walletEntry.originAllowlist.length > 0) {
|
|
2278
1828
|
if (!walletEntry.originAllowlist.includes(this.origin)) {
|
|
2279
|
-
|
|
2280
|
-
throw new OriginNotAllowedError2(
|
|
1829
|
+
throw new OriginNotAllowedError(
|
|
2281
1830
|
this.origin,
|
|
2282
1831
|
walletEntry.originAllowlist
|
|
2283
1832
|
);
|
|
@@ -2312,8 +1861,8 @@ var PartyLayerClient = class {
|
|
|
2312
1861
|
return { selectedWallet, adapter, ctx, isNativeWallet };
|
|
2313
1862
|
}
|
|
2314
1863
|
/**
|
|
2315
|
-
*
|
|
2316
|
-
* build / persist / emit the session. Separated from plan resolution so the
|
|
1864
|
+
* Generate secure entropy, invoke `adapter.connect()` without awaiting the
|
|
1865
|
+
* platform RNG path, then build / persist / emit the session. Separated from plan resolution so the
|
|
2317
1866
|
* popup-safe fast-path can call it gesture-synchronously.
|
|
2318
1867
|
*/
|
|
2319
1868
|
async completeConnect(plan, options, correlationId = newCorrelationId(), attempt) {
|
|
@@ -2323,6 +1872,9 @@ var PartyLayerClient = class {
|
|
|
2323
1872
|
if (attempt === void 0) ++this.sessionRevision;
|
|
2324
1873
|
if (this.destroyed || currentAttempt !== this.connectionAttempt) throw new Error("Wallet connection was superseded");
|
|
2325
1874
|
const { selectedWallet, adapter, ctx } = plan;
|
|
1875
|
+
const entropy = createSecureSessionId(this.crypto);
|
|
1876
|
+
const sessionId = typeof entropy === "string" ? entropy : await entropy;
|
|
1877
|
+
if (this.destroyed || currentAttempt !== this.connectionAttempt) throw new Error("Wallet connection was superseded");
|
|
2326
1878
|
if (!nativeOwnerBindings.has(adapter) && this.nativeOwner?.getSession()) this.nativeOwner.release();
|
|
2327
1879
|
const timeoutMs = options?.timeoutMs || DEFAULT_CONNECT_TIMEOUT_MS;
|
|
2328
1880
|
const abort = new AbortController();
|
|
@@ -2348,7 +1900,7 @@ var PartyLayerClient = class {
|
|
|
2348
1900
|
}
|
|
2349
1901
|
if (this.destroyed || currentAttempt !== this.connectionAttempt) throw new Error("Wallet connection was superseded");
|
|
2350
1902
|
const session = {
|
|
2351
|
-
sessionId
|
|
1903
|
+
sessionId,
|
|
2352
1904
|
walletId: selectedWallet.walletId,
|
|
2353
1905
|
partyId: result.partyId,
|
|
2354
1906
|
// The wallet's reported network (adapters that read the live wallet —
|
|
@@ -2963,107 +2515,580 @@ var PartyLayerClient = class {
|
|
|
2963
2515
|
this.emit("session:expired", { type: "session:expired", sessionId: session.sessionId }, correlationId);
|
|
2964
2516
|
return null;
|
|
2965
2517
|
}
|
|
2966
|
-
this.activeSession = session;
|
|
2967
|
-
this.activeSessionNeedsProbe = true;
|
|
2968
|
-
return session;
|
|
2969
|
-
} catch (err) {
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2518
|
+
this.activeSession = session;
|
|
2519
|
+
this.activeSessionNeedsProbe = true;
|
|
2520
|
+
return session;
|
|
2521
|
+
} catch (err) {
|
|
2522
|
+
if (!current()) return this.activeSession;
|
|
2523
|
+
await this.removeSession();
|
|
2524
|
+
this.log("warn", "session:restore_failed", "Failed to restore session", {
|
|
2525
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2526
|
+
}, correlationId);
|
|
2527
|
+
return null;
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
/**
|
|
2531
|
+
* Update registry status and emit event
|
|
2532
|
+
*/
|
|
2533
|
+
updateRegistryStatus() {
|
|
2534
|
+
const status = this.registryClient.getStatus();
|
|
2535
|
+
if (status) {
|
|
2536
|
+
if (status.source === "network") {
|
|
2537
|
+
this.telemetry?.increment?.(METRICS.REGISTRY_FETCH);
|
|
2538
|
+
} else if (status.source === "cache") {
|
|
2539
|
+
this.telemetry?.increment?.(METRICS.REGISTRY_CACHE_HIT);
|
|
2540
|
+
}
|
|
2541
|
+
if (status.stale) {
|
|
2542
|
+
this.telemetry?.increment?.(METRICS.REGISTRY_STALE);
|
|
2543
|
+
}
|
|
2544
|
+
this.emit("registry:status", {
|
|
2545
|
+
type: "registry:status",
|
|
2546
|
+
status: {
|
|
2547
|
+
source: status.source,
|
|
2548
|
+
verified: status.verified,
|
|
2549
|
+
channel: status.channel,
|
|
2550
|
+
sequence: status.sequence,
|
|
2551
|
+
stale: status.stale,
|
|
2552
|
+
fetchedAt: status.fetchedAt,
|
|
2553
|
+
etag: status.etag,
|
|
2554
|
+
error: status.error
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
}
|
|
2559
|
+
/**
|
|
2560
|
+
* Get registry status
|
|
2561
|
+
*/
|
|
2562
|
+
getRegistryStatus() {
|
|
2563
|
+
return this.registryClient.getStatus();
|
|
2564
|
+
}
|
|
2565
|
+
/**
|
|
2566
|
+
* Emit event to handlers
|
|
2567
|
+
*/
|
|
2568
|
+
/**
|
|
2569
|
+
* Central structured log. Filters by the configured level here, before the adapter
|
|
2570
|
+
* is called, so adapters never filter themselves; skips entirely when no real
|
|
2571
|
+
* logger was configured (the no-op default), so a silent client pays only a check.
|
|
2572
|
+
* Every line carries a machine readable payload `{ event, correlationId?, ...fields }`.
|
|
2573
|
+
* Privacy: callers pass only non identifying fields, the same rule as telemetry.
|
|
2574
|
+
*/
|
|
2575
|
+
log(level, event, message, fields, correlationId) {
|
|
2576
|
+
if (this.logger instanceof DefaultLogger) return;
|
|
2577
|
+
if (!shouldLog(level, this.logLevel)) return;
|
|
2578
|
+
const payload = {
|
|
2579
|
+
event,
|
|
2580
|
+
...correlationId ? { correlationId } : {},
|
|
2581
|
+
...fields ?? {}
|
|
2582
|
+
};
|
|
2583
|
+
switch (level) {
|
|
2584
|
+
case "debug":
|
|
2585
|
+
this.logger.debug(message, payload);
|
|
2586
|
+
break;
|
|
2587
|
+
case "info":
|
|
2588
|
+
this.logger.info(message, payload);
|
|
2589
|
+
break;
|
|
2590
|
+
case "warn":
|
|
2591
|
+
this.logger.warn(message, payload);
|
|
2592
|
+
break;
|
|
2593
|
+
case "error":
|
|
2594
|
+
this.logger.error(message, payload);
|
|
2595
|
+
break;
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
emit(event, payload, correlationId) {
|
|
2599
|
+
if (event === "error" && "error" in payload) {
|
|
2600
|
+
const error = payload.error;
|
|
2601
|
+
if (error.code) {
|
|
2602
|
+
this.telemetry?.increment?.(errorMetricName(error.code));
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
if (this.telemetry && !(this.telemetry instanceof DefaultTelemetry)) {
|
|
2606
|
+
this.telemetry.track(event, eventTelemetryProperties(payload));
|
|
2607
|
+
}
|
|
2608
|
+
this.log(eventLogLevel(event), event, event, eventTelemetryProperties(payload), correlationId);
|
|
2609
|
+
const handlers = this.eventHandlers.get(event);
|
|
2610
|
+
if (handlers) {
|
|
2611
|
+
for (const handler of handlers) {
|
|
2612
|
+
try {
|
|
2613
|
+
handler(payload);
|
|
2614
|
+
} catch (err) {
|
|
2615
|
+
this.log("error", "event:handler_error", "Error in event handler", {
|
|
2616
|
+
error: err instanceof Error ? err.message : String(err)
|
|
2617
|
+
});
|
|
2618
|
+
}
|
|
2619
|
+
}
|
|
2620
|
+
}
|
|
2621
|
+
}
|
|
2622
|
+
};
|
|
2623
|
+
function getBuiltinAdapters() {
|
|
2624
|
+
return [
|
|
2625
|
+
new LoopAdapter(),
|
|
2626
|
+
// 5N Loop - QR code / popup
|
|
2627
|
+
new Cantor8Adapter(),
|
|
2628
|
+
// Cantor8 - deep link transport
|
|
2629
|
+
new NightlyAdapter()
|
|
2630
|
+
// Nightly - multichain wallet (injected)
|
|
2631
|
+
// Console is served via the generic CIP-0103 announce path (registry
|
|
2632
|
+
// transport:'announce') — no longer in defaults; ConsoleAdapter stays
|
|
2633
|
+
// exported below for opt-in manual/bespoke use.
|
|
2634
|
+
// Send is served via the generic CIP-0103 announce path (registry
|
|
2635
|
+
// transport:'announce') — no longer in defaults; SendAdapter stays exported
|
|
2636
|
+
// below for opt-in manual/bespoke use.
|
|
2637
|
+
];
|
|
2638
|
+
}
|
|
2639
|
+
var loaders = {
|
|
2640
|
+
walley: async () => {
|
|
2641
|
+
const { WalleyAdapter } = await import('@k2flabs/walley-dapp-sdk');
|
|
2642
|
+
return { providerId: "walley", create: (host) => new WalleyAdapter({ host }) };
|
|
2643
|
+
},
|
|
2644
|
+
cauri: async () => {
|
|
2645
|
+
const { cauriAdapterFactory } = await import('@lithiumdigital/cauri-dapp-sdk');
|
|
2646
|
+
return cauriAdapterFactory;
|
|
2647
|
+
},
|
|
2648
|
+
oneswap: async (network) => {
|
|
2649
|
+
const { createOneSwapHostedAdapter } = await import('#partylayer-hosted-wallet-profiles');
|
|
2650
|
+
return {
|
|
2651
|
+
providerId: "oneswap",
|
|
2652
|
+
create: (host) => createOneSwapHostedAdapter({
|
|
2653
|
+
walletUrl: host,
|
|
2654
|
+
networkId: toCAIP2Network(network).networkId
|
|
2655
|
+
})
|
|
2656
|
+
};
|
|
2657
|
+
},
|
|
2658
|
+
vala: async () => {
|
|
2659
|
+
const { valaAdapterFactory } = await import('@vala-wallet/dapp-sdk');
|
|
2660
|
+
return valaAdapterFactory;
|
|
2661
|
+
}
|
|
2662
|
+
};
|
|
2663
|
+
async function loadDefaultWallet(id, config, origin) {
|
|
2664
|
+
if (id === "walletconnect" && config.walletConnect?.projectId.trim()) {
|
|
2665
|
+
const { WalletConnectAdapter } = await import('@partylayer/adapter-walletconnect');
|
|
2666
|
+
return new WalletConnectAdapter({
|
|
2667
|
+
...config.walletConnect,
|
|
2668
|
+
metadata: config.walletConnect.metadata ?? {
|
|
2669
|
+
name: config.app.name,
|
|
2670
|
+
description: config.app.name,
|
|
2671
|
+
url: origin === "unknown" ? "" : origin,
|
|
2672
|
+
icons: []
|
|
2673
|
+
}
|
|
2674
|
+
});
|
|
2675
|
+
}
|
|
2676
|
+
if (id === "bron" && config.bron) {
|
|
2677
|
+
const { BronAdapter: BronAdapter2 } = await import('@partylayer/adapter-bron');
|
|
2678
|
+
return new BronAdapter2(config.bron);
|
|
2679
|
+
}
|
|
2680
|
+
return Object.prototype.hasOwnProperty.call(loaders, id) ? loaders[id](config.network) : void 0;
|
|
2681
|
+
}
|
|
2682
|
+
var SILENT_PROBE_TIMEOUT_MS = 1e4;
|
|
2683
|
+
function disconnected() {
|
|
2684
|
+
return new Error("Native wallet connection is no longer active");
|
|
2685
|
+
}
|
|
2686
|
+
function teardown(source) {
|
|
2687
|
+
try {
|
|
2688
|
+
source?.teardown?.();
|
|
2689
|
+
} catch {
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
function abortable(promise, signal) {
|
|
2693
|
+
return new Promise((resolve, reject) => {
|
|
2694
|
+
const abort = () => reject(disconnected());
|
|
2695
|
+
if (signal.aborted) {
|
|
2696
|
+
reject(disconnected());
|
|
2697
|
+
return;
|
|
2698
|
+
}
|
|
2699
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2700
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", abort));
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2703
|
+
async function readIdentity(provider, registration, signal) {
|
|
2704
|
+
const account = await abortable(
|
|
2705
|
+
provider.request({ method: "getPrimaryAccount" }),
|
|
2706
|
+
signal
|
|
2707
|
+
);
|
|
2708
|
+
assertPrimaryParty(account);
|
|
2709
|
+
let status;
|
|
2710
|
+
try {
|
|
2711
|
+
status = await abortable(provider.request({ method: "status" }), signal);
|
|
2712
|
+
} catch (error) {
|
|
2713
|
+
if (signal.aborted) throw error;
|
|
2714
|
+
}
|
|
2715
|
+
if (status?.isConnected === false || status?.connection?.isConnected === false)
|
|
2716
|
+
throw disconnected();
|
|
2717
|
+
const network = [status?.network?.networkId, account.networkId, registration.network].find(
|
|
2718
|
+
(value) => typeof value === "string" && isRecognizedNetwork(value)
|
|
2719
|
+
) ?? registration.network;
|
|
2720
|
+
if (registration.expected && (account.partyId !== registration.expected.partyId || detectNetworkMismatch(registration.expected.network, network)))
|
|
2721
|
+
throw disconnected();
|
|
2722
|
+
if (signal.aborted) throw disconnected();
|
|
2723
|
+
return { account, network, status };
|
|
2724
|
+
}
|
|
2725
|
+
var NativeConnectionOwner = class {
|
|
2726
|
+
constructor(changed = () => {
|
|
2727
|
+
}) {
|
|
2728
|
+
this.changed = changed;
|
|
2729
|
+
}
|
|
2730
|
+
client = null;
|
|
2731
|
+
initialization = null;
|
|
2732
|
+
registrations = /* @__PURE__ */ new Map();
|
|
2733
|
+
operation = null;
|
|
2734
|
+
pending = null;
|
|
2735
|
+
closing = null;
|
|
2736
|
+
projection = null;
|
|
2737
|
+
unsubscribers = [];
|
|
2738
|
+
disposed = false;
|
|
2739
|
+
refreshRevision = 0;
|
|
2740
|
+
identityRefreshing = false;
|
|
2741
|
+
probes = /* @__PURE__ */ new Set();
|
|
2742
|
+
get busy() {
|
|
2743
|
+
return this.operation !== null || this.closing !== null;
|
|
2744
|
+
}
|
|
2745
|
+
assertAvailable() {
|
|
2746
|
+
if (this.disposed) throw disconnected();
|
|
2747
|
+
if (this.busy) throw new Error("A native wallet operation is already in progress");
|
|
2748
|
+
}
|
|
2749
|
+
/** Run during picker preparation, never between a click and provider.connect. */
|
|
2750
|
+
async prepare(id, source, network) {
|
|
2751
|
+
if (this.disposed) throw disconnected();
|
|
2752
|
+
this.registrations.set(id, { id, source, network });
|
|
2753
|
+
if (!this.initialization) {
|
|
2754
|
+
this.initialization = (async () => {
|
|
2755
|
+
const { DiscoveryClient } = await import('@canton-network/core-wallet-discovery');
|
|
2756
|
+
const client = await DiscoveryClient.create({ adapters: [] });
|
|
2757
|
+
if (this.disposed) {
|
|
2758
|
+
client.destroy();
|
|
2759
|
+
return;
|
|
2760
|
+
}
|
|
2761
|
+
this.client = client;
|
|
2762
|
+
})();
|
|
2763
|
+
}
|
|
2764
|
+
await this.initialization;
|
|
2765
|
+
if (this.disposed || !this.client) throw disconnected();
|
|
2766
|
+
for (const registration of this.registrations.values())
|
|
2767
|
+
this.client.registerAdapter(this.wrap(registration));
|
|
2768
|
+
}
|
|
2769
|
+
wrap(registration) {
|
|
2770
|
+
const source = registration.source;
|
|
2771
|
+
return {
|
|
2772
|
+
providerId: registration.id,
|
|
2773
|
+
name: source.name,
|
|
2774
|
+
type: source.type === "desktop" || source.type === "mobile" || source.type === "remote" ? source.type : "browser",
|
|
2775
|
+
icon: source.icon,
|
|
2776
|
+
getInfo: () => ({
|
|
2777
|
+
providerId: registration.id,
|
|
2778
|
+
name: source.name,
|
|
2779
|
+
type: "browser",
|
|
2780
|
+
icon: source.icon
|
|
2781
|
+
}),
|
|
2782
|
+
detect: () => source.detect(),
|
|
2783
|
+
provider: () => this.guard(source.provider(), registration),
|
|
2784
|
+
teardown: () => teardown(source),
|
|
2785
|
+
restore: async () => {
|
|
2786
|
+
const operation = this.operation;
|
|
2787
|
+
if (!operation) throw disconnected();
|
|
2788
|
+
try {
|
|
2789
|
+
const raw = source.restore ? await abortable(source.restore(), operation.abort.signal) : source.provider();
|
|
2790
|
+
if (!raw) return null;
|
|
2791
|
+
const provider = raw;
|
|
2792
|
+
operation.identity = await readIdentity(provider, registration, operation.abort.signal);
|
|
2793
|
+
return this.guard(provider, registration);
|
|
2794
|
+
} catch (error) {
|
|
2795
|
+
teardown(source);
|
|
2796
|
+
throw error;
|
|
2797
|
+
}
|
|
2798
|
+
}
|
|
2799
|
+
};
|
|
2800
|
+
}
|
|
2801
|
+
guard(raw, registration) {
|
|
2802
|
+
const provider = {
|
|
2803
|
+
request: async (args) => {
|
|
2804
|
+
if (this.disposed) throw disconnected();
|
|
2805
|
+
if (args.method !== "connect") {
|
|
2806
|
+
if (this.client?.getActiveSession()?.provider !== provider) throw disconnected();
|
|
2807
|
+
if (!this.projection && args.method !== "disconnect") throw disconnected();
|
|
2808
|
+
if (this.identityRefreshing && ![
|
|
2809
|
+
"status",
|
|
2810
|
+
"getPrimaryAccount",
|
|
2811
|
+
"listAccounts",
|
|
2812
|
+
"getActiveNetwork",
|
|
2813
|
+
"isConnected"
|
|
2814
|
+
].includes(args.method)) {
|
|
2815
|
+
throw new Error("Native wallet identity is being refreshed");
|
|
2816
|
+
}
|
|
2817
|
+
const result = await (args.method === "disconnect" && this.operation ? abortable(raw.request(args), this.operation.abort.signal) : raw.request(args));
|
|
2818
|
+
if (args.method === "status") {
|
|
2819
|
+
const status = result;
|
|
2820
|
+
if (status?.isConnected === false || status?.connection?.isConnected === false) {
|
|
2821
|
+
this.invalidate(registration.id);
|
|
2822
|
+
}
|
|
2823
|
+
}
|
|
2824
|
+
return result;
|
|
2825
|
+
}
|
|
2826
|
+
const operation = this.operation;
|
|
2827
|
+
if (!operation || operation.abort.signal.aborted) throw disconnected();
|
|
2828
|
+
const response = await abortable(raw.request(args), operation.abort.signal);
|
|
2829
|
+
assertConnectionAccepted(response);
|
|
2830
|
+
operation.identity = await readIdentity(raw, registration, operation.abort.signal);
|
|
2831
|
+
return response;
|
|
2832
|
+
},
|
|
2833
|
+
on: (event, listener) => {
|
|
2834
|
+
raw.on(event, listener);
|
|
2835
|
+
return provider;
|
|
2836
|
+
},
|
|
2837
|
+
emit: (event, ...args) => raw.emit(event, ...args),
|
|
2838
|
+
removeListener: (event, listener) => {
|
|
2839
|
+
raw.removeListener(event, listener);
|
|
2840
|
+
return provider;
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
return provider;
|
|
2844
|
+
}
|
|
2845
|
+
/** No await precedes the official client's connect call. */
|
|
2846
|
+
connect(id, signal) {
|
|
2847
|
+
this.assertAvailable();
|
|
2848
|
+
if (!this.client || !this.registrations.has(id))
|
|
2849
|
+
return Promise.reject(new Error("Native wallet was not prepared"));
|
|
2850
|
+
const operation = { abort: new AbortController(), id };
|
|
2851
|
+
this.operation = operation;
|
|
2852
|
+
this.detach();
|
|
2853
|
+
const previous = this.client.getActiveSession();
|
|
2854
|
+
teardown(previous?.adapter);
|
|
2855
|
+
const previousId = this.projection?.id;
|
|
2856
|
+
this.projection = null;
|
|
2857
|
+
if (previousId) this.changed(previousId, null);
|
|
2858
|
+
const abort = () => operation.abort.abort();
|
|
2859
|
+
if (signal?.aborted) abort();
|
|
2860
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
2861
|
+
const task = (async () => {
|
|
2862
|
+
try {
|
|
2863
|
+
await this.client.connect(id);
|
|
2864
|
+
if (operation.abort.signal.aborted || this.disposed || !operation.identity)
|
|
2865
|
+
throw disconnected();
|
|
2866
|
+
this.projection = { id, identity: operation.identity };
|
|
2867
|
+
this.attach(id);
|
|
2868
|
+
return operation.identity;
|
|
2869
|
+
} catch (error) {
|
|
2870
|
+
this.client?.destroy();
|
|
2871
|
+
this.client = null;
|
|
2872
|
+
this.initialization = null;
|
|
2873
|
+
teardown(this.registrations.get(id)?.source);
|
|
2874
|
+
throw error;
|
|
2875
|
+
} finally {
|
|
2876
|
+
signal?.removeEventListener("abort", abort);
|
|
2877
|
+
if (this.operation === operation) this.operation = null;
|
|
2878
|
+
}
|
|
2879
|
+
})();
|
|
2880
|
+
this.pending = task;
|
|
2881
|
+
void task.then(
|
|
2882
|
+
() => {
|
|
2883
|
+
if (this.pending === task) this.pending = null;
|
|
2884
|
+
},
|
|
2885
|
+
() => {
|
|
2886
|
+
if (this.pending === task) this.pending = null;
|
|
2887
|
+
}
|
|
2888
|
+
);
|
|
2889
|
+
return task;
|
|
2890
|
+
}
|
|
2891
|
+
async restore(expected) {
|
|
2892
|
+
if (!this.client || this.projection || this.busy || this.disposed) return this.getSession();
|
|
2893
|
+
const registration = expected && this.registrations.get(expected.id);
|
|
2894
|
+
if (registration) registration.expected = expected;
|
|
2895
|
+
const operation = { abort: new AbortController() };
|
|
2896
|
+
this.operation = operation;
|
|
2897
|
+
const timeout = setTimeout(() => operation.abort.abort(), SILENT_PROBE_TIMEOUT_MS);
|
|
2898
|
+
const task = (async () => {
|
|
2899
|
+
try {
|
|
2900
|
+
await this.client.restorePersistedSessionIfNeeded();
|
|
2901
|
+
const active = this.client?.getActiveSession();
|
|
2902
|
+
if (!active || !operation.identity || operation.abort.signal.aborted || this.disposed)
|
|
2903
|
+
return null;
|
|
2904
|
+
if (expected && active.providerId !== expected.id) {
|
|
2905
|
+
teardown(active.adapter);
|
|
2906
|
+
this.client.destroy();
|
|
2907
|
+
this.client = null;
|
|
2908
|
+
this.initialization = null;
|
|
2909
|
+
return null;
|
|
2910
|
+
}
|
|
2911
|
+
const id = String(active.providerId);
|
|
2912
|
+
this.projection = { id, identity: operation.identity };
|
|
2913
|
+
this.attach(id);
|
|
2914
|
+
return this.getSession();
|
|
2915
|
+
} finally {
|
|
2916
|
+
clearTimeout(timeout);
|
|
2917
|
+
if (registration) delete registration.expected;
|
|
2918
|
+
if (this.operation === operation) this.operation = null;
|
|
2919
|
+
}
|
|
2920
|
+
})();
|
|
2921
|
+
this.pending = task;
|
|
2922
|
+
try {
|
|
2923
|
+
return await task;
|
|
2924
|
+
} finally {
|
|
2925
|
+
if (this.pending === task) this.pending = null;
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
getSession() {
|
|
2929
|
+
if (this.disposed || !this.client?.getActiveSession() || !this.projection) return null;
|
|
2930
|
+
return this.projection;
|
|
2931
|
+
}
|
|
2932
|
+
getProvider(id) {
|
|
2933
|
+
if (!this.getSession() || id && this.projection?.id !== id) throw disconnected();
|
|
2934
|
+
return this.client.getProvider();
|
|
2935
|
+
}
|
|
2936
|
+
/** A bare signature must not be attributed to an old, eventless primary party. */
|
|
2937
|
+
async validateIdentity(id, partyId, network) {
|
|
2938
|
+
const provider = this.getProvider(id);
|
|
2939
|
+
const revision = ++this.refreshRevision;
|
|
2940
|
+
this.identityRefreshing = true;
|
|
2941
|
+
let verified = false;
|
|
2942
|
+
try {
|
|
2943
|
+
const identity2 = await this.probe(provider, this.registrations.get(id));
|
|
2944
|
+
if (revision !== this.refreshRevision || this.getProvider(id) !== provider)
|
|
2945
|
+
throw disconnected();
|
|
2946
|
+
verified = true;
|
|
2947
|
+
this.projection = { id, identity: identity2 };
|
|
2948
|
+
if (identity2.account.partyId !== partyId || detectNetworkMismatch(network, identity2.network)) {
|
|
2949
|
+
this.changed(id, identity2);
|
|
2950
|
+
throw new Error("Wallet identity changed during message signing");
|
|
2951
|
+
}
|
|
2952
|
+
} catch (error) {
|
|
2953
|
+
if (!verified && revision === this.refreshRevision) this.invalidate(id);
|
|
2954
|
+
throw error;
|
|
2955
|
+
} finally {
|
|
2956
|
+
if (revision === this.refreshRevision) this.identityRefreshing = false;
|
|
2974
2957
|
}
|
|
2975
2958
|
}
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2959
|
+
async probe(provider, registration) {
|
|
2960
|
+
const abort = new AbortController();
|
|
2961
|
+
this.probes.add(abort);
|
|
2962
|
+
const timeout = setTimeout(() => abort.abort(), SILENT_PROBE_TIMEOUT_MS);
|
|
2963
|
+
try {
|
|
2964
|
+
return await readIdentity(provider, registration, abort.signal);
|
|
2965
|
+
} finally {
|
|
2966
|
+
clearTimeout(timeout);
|
|
2967
|
+
this.probes.delete(abort);
|
|
2968
|
+
}
|
|
2969
|
+
}
|
|
2970
|
+
detach() {
|
|
2971
|
+
++this.refreshRevision;
|
|
2972
|
+
this.identityRefreshing = false;
|
|
2973
|
+
for (const probe of this.probes) probe.abort();
|
|
2974
|
+
this.probes.clear();
|
|
2975
|
+
this.unsubscribers.splice(0).forEach((unsubscribe) => {
|
|
2976
|
+
try {
|
|
2977
|
+
unsubscribe();
|
|
2978
|
+
} catch {
|
|
2986
2979
|
}
|
|
2987
|
-
|
|
2988
|
-
|
|
2980
|
+
});
|
|
2981
|
+
}
|
|
2982
|
+
attach(id) {
|
|
2983
|
+
const provider = this.getProvider(id);
|
|
2984
|
+
const update = (payload) => {
|
|
2985
|
+
const status = payload;
|
|
2986
|
+
if (status?.connection?.isConnected === false || status?.isConnected === false || Array.isArray(payload) && payload.length === 0) {
|
|
2987
|
+
this.invalidate(id);
|
|
2988
|
+
return;
|
|
2989
2989
|
}
|
|
2990
|
-
this.
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
2990
|
+
const revision = ++this.refreshRevision;
|
|
2991
|
+
this.identityRefreshing = true;
|
|
2992
|
+
const registration = this.registrations.get(id);
|
|
2993
|
+
void this.probe(provider, registration).then(
|
|
2994
|
+
(identity2) => {
|
|
2995
|
+
if (revision !== this.refreshRevision || this.projection?.id !== id || this.disposed)
|
|
2996
|
+
return;
|
|
2997
|
+
this.identityRefreshing = false;
|
|
2998
|
+
this.projection = { id, identity: identity2 };
|
|
2999
|
+
this.changed(id, identity2);
|
|
3000
|
+
},
|
|
3001
|
+
() => {
|
|
3002
|
+
if (revision === this.refreshRevision) this.invalidate(id);
|
|
3001
3003
|
}
|
|
3002
|
-
|
|
3004
|
+
);
|
|
3005
|
+
};
|
|
3006
|
+
for (const event of ["accountsChanged", "statusChanged"]) {
|
|
3007
|
+
provider.on(event, update);
|
|
3008
|
+
this.unsubscribers.push(() => provider.removeListener(event, update));
|
|
3003
3009
|
}
|
|
3004
3010
|
}
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3011
|
+
invalidate(id) {
|
|
3012
|
+
if (this.projection?.id !== id) return;
|
|
3013
|
+
this.detach();
|
|
3014
|
+
this.projection = null;
|
|
3015
|
+
teardown(this.client?.getActiveSession()?.adapter);
|
|
3016
|
+
this.client?.destroy();
|
|
3017
|
+
this.client = null;
|
|
3018
|
+
this.initialization = null;
|
|
3019
|
+
this.changed(id, null);
|
|
3010
3020
|
}
|
|
3011
|
-
/**
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
if (this.logger instanceof DefaultLogger) return;
|
|
3023
|
-
if (!shouldLog(level, this.logLevel)) return;
|
|
3024
|
-
const payload = {
|
|
3025
|
-
event,
|
|
3026
|
-
...correlationId ? { correlationId } : {},
|
|
3027
|
-
...fields ?? {}
|
|
3028
|
-
};
|
|
3029
|
-
switch (level) {
|
|
3030
|
-
case "debug":
|
|
3031
|
-
this.logger.debug(message, payload);
|
|
3032
|
-
break;
|
|
3033
|
-
case "info":
|
|
3034
|
-
this.logger.info(message, payload);
|
|
3035
|
-
break;
|
|
3036
|
-
case "warn":
|
|
3037
|
-
this.logger.warn(message, payload);
|
|
3038
|
-
break;
|
|
3039
|
-
case "error":
|
|
3040
|
-
this.logger.error(message, payload);
|
|
3041
|
-
break;
|
|
3042
|
-
}
|
|
3021
|
+
/** Local transport cleanup when switching to a proprietary integration. */
|
|
3022
|
+
release() {
|
|
3023
|
+
this.assertAvailable();
|
|
3024
|
+
const id = this.projection?.id;
|
|
3025
|
+
this.detach();
|
|
3026
|
+
this.projection = null;
|
|
3027
|
+
teardown(this.client?.getActiveSession()?.adapter);
|
|
3028
|
+
this.client?.destroy();
|
|
3029
|
+
this.client = null;
|
|
3030
|
+
this.initialization = null;
|
|
3031
|
+
if (id) this.changed(id, null);
|
|
3043
3032
|
}
|
|
3044
|
-
|
|
3045
|
-
if (
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
}
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
this.
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
this.
|
|
3062
|
-
|
|
3063
|
-
|
|
3033
|
+
disconnect() {
|
|
3034
|
+
if (this.closing) return this.closing;
|
|
3035
|
+
this.operation?.abort.abort();
|
|
3036
|
+
const task = (async () => {
|
|
3037
|
+
await this.pending?.catch(() => {
|
|
3038
|
+
});
|
|
3039
|
+
this.detach();
|
|
3040
|
+
const id = this.projection?.id;
|
|
3041
|
+
this.projection = null;
|
|
3042
|
+
const operation = { abort: new AbortController() };
|
|
3043
|
+
this.operation = operation;
|
|
3044
|
+
const timeout = setTimeout(() => operation.abort.abort(), SILENT_PROBE_TIMEOUT_MS);
|
|
3045
|
+
try {
|
|
3046
|
+
await this.client?.disconnect();
|
|
3047
|
+
} finally {
|
|
3048
|
+
clearTimeout(timeout);
|
|
3049
|
+
if (this.client?.getActiveSession()) {
|
|
3050
|
+
this.client.destroy();
|
|
3051
|
+
this.client = null;
|
|
3052
|
+
this.initialization = null;
|
|
3064
3053
|
}
|
|
3054
|
+
this.operation = null;
|
|
3055
|
+
if (id) this.changed(id, null);
|
|
3065
3056
|
}
|
|
3066
|
-
}
|
|
3057
|
+
})();
|
|
3058
|
+
this.closing = task;
|
|
3059
|
+
void task.then(
|
|
3060
|
+
() => {
|
|
3061
|
+
if (this.closing === task) this.closing = null;
|
|
3062
|
+
},
|
|
3063
|
+
() => {
|
|
3064
|
+
if (this.closing === task) this.closing = null;
|
|
3065
|
+
}
|
|
3066
|
+
);
|
|
3067
|
+
return task;
|
|
3068
|
+
}
|
|
3069
|
+
destroy() {
|
|
3070
|
+
if (this.disposed) return;
|
|
3071
|
+
this.disposed = true;
|
|
3072
|
+
this.operation?.abort.abort();
|
|
3073
|
+
this.detach();
|
|
3074
|
+
this.projection = null;
|
|
3075
|
+
teardown(this.client?.getActiveSession()?.adapter);
|
|
3076
|
+
if (!this.client?.getActiveSession() && this.operation?.id)
|
|
3077
|
+
teardown(this.registrations.get(this.operation.id)?.source);
|
|
3078
|
+
this.client?.destroy();
|
|
3079
|
+
this.client = null;
|
|
3080
|
+
}
|
|
3081
|
+
};
|
|
3082
|
+
|
|
3083
|
+
// src/client.ts
|
|
3084
|
+
var PartyLayerClient = class extends PartyLayerClientBase {
|
|
3085
|
+
constructor(config) {
|
|
3086
|
+
super(config, {
|
|
3087
|
+
getBuiltinAdapters,
|
|
3088
|
+
loadDefaultWallet: (id, _sharedConfig, origin) => loadDefaultWallet(id, config, origin),
|
|
3089
|
+
createOwner: (onIdentityChanged) => new NativeConnectionOwner(onIdentityChanged),
|
|
3090
|
+
browserDiscovery: true
|
|
3091
|
+
});
|
|
3067
3092
|
}
|
|
3068
3093
|
};
|
|
3069
3094
|
function createPartyLayer(config) {
|
|
@@ -3086,8 +3111,14 @@ function createWalletLedgerReader(client, options) {
|
|
|
3086
3111
|
function createScopedLedgerReader(client, options, applicationRequest) {
|
|
3087
3112
|
const networkId = text(options.networkId);
|
|
3088
3113
|
if (!/^canton:[a-zA-Z0-9_-]+$/.test(networkId)) throw new Error("Expected a Canton CAIP-2 network id");
|
|
3089
|
-
|
|
3090
|
-
|
|
3114
|
+
function configuredInterface(value) {
|
|
3115
|
+
if (value === void 0) return void 0;
|
|
3116
|
+
const id = text(value);
|
|
3117
|
+
if (!/^[^:#\s]+:[^:\s]+:[^:\s]+$/.test(id)) throw new Error("Use an exact package-id-qualified holding interface id");
|
|
3118
|
+
return id;
|
|
3119
|
+
}
|
|
3120
|
+
const interfaceId = configuredInterface(options.holdingInterfaceId);
|
|
3121
|
+
const v2InterfaceId = configuredInterface(options.holdingV2InterfaceId);
|
|
3091
3122
|
const timeoutMs = options.timeoutMs ?? 3e4;
|
|
3092
3123
|
const maxContracts = options.maxContracts ?? 1e3;
|
|
3093
3124
|
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 3e5) throw new Error("Invalid ledger read timeout");
|
|
@@ -3145,63 +3176,49 @@ function createScopedLedgerReader(client, options, applicationRequest) {
|
|
|
3145
3176
|
if (stop) signal?.removeEventListener("abort", stop);
|
|
3146
3177
|
}
|
|
3147
3178
|
}
|
|
3179
|
+
function readHoldings(requestedInterface, parse, include, signal) {
|
|
3180
|
+
return read(signal, async (session, request) => {
|
|
3181
|
+
if (!requestedInterface) throw new Error("Configure the version-specific holding interface id before reading holdings");
|
|
3182
|
+
const end = object(await request("/v2/state/ledger-end"));
|
|
3183
|
+
if (!Number.isSafeInteger(end.offset) || end.offset < 0) throw new Error("Unsafe or invalid ledger offset");
|
|
3184
|
+
const rows = await request("/v2/state/active-contracts", {
|
|
3185
|
+
activeAtOffset: end.offset,
|
|
3186
|
+
eventFormat: { filtersByParty: { [String(session.partyId)]: { cumulative: [{
|
|
3187
|
+
identifierFilter: { InterfaceFilter: { value: { interfaceId: requestedInterface, includeInterfaceView: true } } }
|
|
3188
|
+
}] } }, verbose: false }
|
|
3189
|
+
});
|
|
3190
|
+
if (!Array.isArray(rows) || rows.length >= maxContracts) throw new Error("Incomplete or oversized holdings snapshot");
|
|
3191
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3192
|
+
const holdings = [];
|
|
3193
|
+
for (const row of rows) {
|
|
3194
|
+
const entry = object(object(row).contractEntry);
|
|
3195
|
+
if (Object.keys(entry).length !== 1 || !entry.JsActiveContract) throw new Error("Snapshot contains an incomplete reassignment");
|
|
3196
|
+
const created = object(object(entry.JsActiveContract).createdEvent);
|
|
3197
|
+
const cid = text(created.contractId);
|
|
3198
|
+
if (seen.has(cid)) throw new Error("Duplicate holding contract in snapshot");
|
|
3199
|
+
seen.add(cid);
|
|
3200
|
+
if (!Array.isArray(created.interfaceViews)) throw new Error("Missing holding interface view");
|
|
3201
|
+
const views = created.interfaceViews.filter((v) => object(v).interfaceId === requestedInterface);
|
|
3202
|
+
if (views.length !== 1) throw new Error("Missing or ambiguous holding interface view");
|
|
3203
|
+
const view = object(views[0]);
|
|
3204
|
+
if (object(view.viewStatus).code !== 0) throw new Error("Holding interface view failed");
|
|
3205
|
+
const holding = parse(view.viewValue);
|
|
3206
|
+
if (include(holding, String(session.partyId))) holdings.push({ cid, holding });
|
|
3207
|
+
}
|
|
3208
|
+
return { walletId: String(session.walletId), partyId: String(session.partyId), networkId, offset: end.offset, holdings };
|
|
3209
|
+
});
|
|
3210
|
+
}
|
|
3148
3211
|
return {
|
|
3149
3212
|
/** A bounded, complete ACS snapshot of the connected party's configured HoldingV1 interface. */
|
|
3150
3213
|
readHoldings(signal) {
|
|
3151
|
-
return
|
|
3152
|
-
if (
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
}] } }, verbose: false }
|
|
3160
|
-
});
|
|
3161
|
-
if (!Array.isArray(rows) || rows.length >= maxContracts) throw new Error("Incomplete or oversized holdings snapshot");
|
|
3162
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3163
|
-
const holdings = rows.map((row) => {
|
|
3164
|
-
const entry = object(object(row).contractEntry);
|
|
3165
|
-
if (Object.keys(entry).length !== 1 || !entry.JsActiveContract) throw new Error("Snapshot contains an incomplete reassignment");
|
|
3166
|
-
const created = object(object(entry.JsActiveContract).createdEvent);
|
|
3167
|
-
const cid = text(created.contractId);
|
|
3168
|
-
if (seen.has(cid)) throw new Error("Duplicate holding contract in snapshot");
|
|
3169
|
-
seen.add(cid);
|
|
3170
|
-
if (!Array.isArray(created.interfaceViews)) throw new Error("Missing holding interface view");
|
|
3171
|
-
const views = created.interfaceViews.filter((v) => object(v).interfaceId === interfaceId);
|
|
3172
|
-
if (views.length !== 1) throw new Error("Missing or ambiguous holding interface view");
|
|
3173
|
-
const view = object(views[0]);
|
|
3174
|
-
if (object(view.viewStatus).code !== 0) throw new Error("Holding interface view failed");
|
|
3175
|
-
const value = object(view.viewValue);
|
|
3176
|
-
if (value.owner !== String(session.partyId)) throw new Error("Holding belongs to another party");
|
|
3177
|
-
const instrument = object(value.instrumentId);
|
|
3178
|
-
if (typeof value.amount !== "string" || !/^(?:0|[1-9]\d{0,27})(?:\.\d{1,10})?$/.test(value.amount)) throw new Error("Invalid token decimal");
|
|
3179
|
-
let lock;
|
|
3180
|
-
if (value.lock !== null && value.lock !== void 0) {
|
|
3181
|
-
const raw = object(value.lock);
|
|
3182
|
-
if (!Array.isArray(raw.holders)) throw new Error("Invalid holding lock");
|
|
3183
|
-
lock = { holders: raw.holders.map(text) };
|
|
3184
|
-
for (const key of ["expiresAt", "expiresAfter", "context"]) {
|
|
3185
|
-
if (raw[key] !== void 0 && raw[key] !== null) lock[key] = text(raw[key]);
|
|
3186
|
-
}
|
|
3187
|
-
}
|
|
3188
|
-
let meta;
|
|
3189
|
-
if (value.meta !== void 0 && value.meta !== null) {
|
|
3190
|
-
const raw = object(value.meta);
|
|
3191
|
-
const values = Object.hasOwn(raw, "values") ? object(raw.values) : raw;
|
|
3192
|
-
if (Object.values(values).some((v) => typeof v !== "string")) throw new Error("Invalid holding metadata");
|
|
3193
|
-
meta = { ...values };
|
|
3194
|
-
}
|
|
3195
|
-
return { cid, holding: {
|
|
3196
|
-
owner: String(session.partyId),
|
|
3197
|
-
instrumentId: { admin: text(instrument.admin), id: text(instrument.id) },
|
|
3198
|
-
amount: value.amount,
|
|
3199
|
-
...lock ? { lock } : {},
|
|
3200
|
-
...meta ? { meta } : {}
|
|
3201
|
-
} };
|
|
3202
|
-
});
|
|
3203
|
-
return { walletId: String(session.walletId), partyId: String(session.partyId), networkId, offset: end.offset, holdings };
|
|
3204
|
-
});
|
|
3214
|
+
return readHoldings(interfaceId, parseTokenHoldingV1, (holding, owner) => {
|
|
3215
|
+
if (holding.owner !== owner) throw new Error("Holding belongs to another party");
|
|
3216
|
+
return true;
|
|
3217
|
+
}, signal);
|
|
3218
|
+
},
|
|
3219
|
+
/** Owned V2 accounts only. Provider visibility and ownerless admin accounts do not confer ownership. */
|
|
3220
|
+
readHoldingsV2(signal) {
|
|
3221
|
+
return readHoldings(v2InterfaceId, parseTokenHoldingV2, (holding, owner) => holding.account.owner === owner, signal);
|
|
3205
3222
|
},
|
|
3206
3223
|
/** One read, never polling or resubmission. Unknown remains unknown if ids cannot be correlated. */
|
|
3207
3224
|
async confirmTransaction({ transaction, signal }) {
|
|
@@ -3273,6 +3290,12 @@ function createApplicationLedgerReader(client, options) {
|
|
|
3273
3290
|
});
|
|
3274
3291
|
}
|
|
3275
3292
|
|
|
3276
|
-
|
|
3293
|
+
// src/bron-authorization.ts
|
|
3294
|
+
async function completeBronAuthorization(redirectUri) {
|
|
3295
|
+
const { completeBronAuthorization: complete } = await import('@partylayer/adapter-bron');
|
|
3296
|
+
complete(redirectUri);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
export { ANNOUNCED_WALLET_ID_PREFIX, PartyLayerClient as CantonConnectClient, DEFAULT_REGISTRY_URL, GenericAnnounceAdapter, GenericDiscoveryAdapter, MetricsTelemetryAdapter, PartyLayerClient, announcedWalletId, completeBronAuthorization, createApplicationLedgerReader, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, createWalletLedgerReader, getBuiltinAdapters, getDiscoveryCapabilities, isTelemetryConfig };
|
|
3277
3300
|
//# sourceMappingURL=index.mjs.map
|
|
3278
3301
|
//# sourceMappingURL=index.mjs.map
|