@partylayer/sdk 0.10.1 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +37 -2
- package/dist/index.d.ts +37 -2
- package/dist/index.js +52 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -299,10 +299,25 @@ interface ErrorEvent {
|
|
|
299
299
|
type: 'error';
|
|
300
300
|
error: Error;
|
|
301
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Wallet-list changed event — the set of listable wallets changed since the last
|
|
304
|
+
* `listWallets()` (e.g. a wallet announced late via `canton:announceProvider`,
|
|
305
|
+
* after the picker already loaded). SIGNAL-ONLY: it carries no wallet payload
|
|
306
|
+
* because `listWallets()` does registry-merge + discovery-gating + identity-
|
|
307
|
+
* bridging + filtering that a raw announce doesn't reflect — the authoritative
|
|
308
|
+
* read is to re-call `listWallets()` (mirrors EIP-6963/mipd: store emits, UI
|
|
309
|
+
* re-reads). Emitted debounced (coalesces a burst into one). Never emitted when
|
|
310
|
+
* nothing announces (byte-identical idle).
|
|
311
|
+
*/
|
|
312
|
+
interface WalletsChangedEvent {
|
|
313
|
+
type: 'wallets:changed';
|
|
314
|
+
/** Why the list changed. Currently only late/inject-time announce discovery. */
|
|
315
|
+
reason: 'announced';
|
|
316
|
+
}
|
|
302
317
|
/**
|
|
303
318
|
* All event types
|
|
304
319
|
*/
|
|
305
|
-
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | ErrorEvent;
|
|
320
|
+
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | WalletsChangedEvent | ErrorEvent;
|
|
306
321
|
/**
|
|
307
322
|
* Event handler type
|
|
308
323
|
*/
|
|
@@ -332,6 +347,10 @@ declare class PartyLayerClient {
|
|
|
332
347
|
private telemetry?;
|
|
333
348
|
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
334
349
|
private announceEntriesCache;
|
|
350
|
+
private readonly announceRegistry;
|
|
351
|
+
private announceUnsubscribe;
|
|
352
|
+
/** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
|
|
353
|
+
private walletsChangedTimer;
|
|
335
354
|
private origin;
|
|
336
355
|
constructor(config: PartyLayerConfig);
|
|
337
356
|
/**
|
|
@@ -388,6 +407,22 @@ declare class PartyLayerClient {
|
|
|
388
407
|
* `canton:requestProvider` handshake (e.g. after a wallet is installed).
|
|
389
408
|
*/
|
|
390
409
|
refreshDiscovery(): void;
|
|
410
|
+
/**
|
|
411
|
+
* Persistent-accumulator callback (mounted at construction). On each newly
|
|
412
|
+
* announced provider:
|
|
413
|
+
* 1. record it in the live `announceRegistry` (unchanged);
|
|
414
|
+
* 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
|
|
415
|
+
* as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
|
|
416
|
+
* and surfaces the wallet. This does NOT touch `warmPlans` (those hold
|
|
417
|
+
* only GenericDiscoveryAdapter popup plans — a disjoint set);
|
|
418
|
+
* 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
|
|
419
|
+
* the React provider) re-lists. The debounce coalesces a burst — and the
|
|
420
|
+
* construction-time reply storm — into one emit (no re-discovery storm).
|
|
421
|
+
*
|
|
422
|
+
* Byte-identical idle: with zero announces this never fires — no invalidation,
|
|
423
|
+
* no emit, no re-list.
|
|
424
|
+
*/
|
|
425
|
+
private onAnnounceAccumulated;
|
|
391
426
|
/**
|
|
392
427
|
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
393
428
|
*
|
|
@@ -848,4 +883,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
|
|
|
848
883
|
*/
|
|
849
884
|
declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
|
|
850
885
|
|
|
851
|
-
export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
|
|
886
|
+
export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, type WalletsChangedEvent, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -299,10 +299,25 @@ interface ErrorEvent {
|
|
|
299
299
|
type: 'error';
|
|
300
300
|
error: Error;
|
|
301
301
|
}
|
|
302
|
+
/**
|
|
303
|
+
* Wallet-list changed event — the set of listable wallets changed since the last
|
|
304
|
+
* `listWallets()` (e.g. a wallet announced late via `canton:announceProvider`,
|
|
305
|
+
* after the picker already loaded). SIGNAL-ONLY: it carries no wallet payload
|
|
306
|
+
* because `listWallets()` does registry-merge + discovery-gating + identity-
|
|
307
|
+
* bridging + filtering that a raw announce doesn't reflect — the authoritative
|
|
308
|
+
* read is to re-call `listWallets()` (mirrors EIP-6963/mipd: store emits, UI
|
|
309
|
+
* re-reads). Emitted debounced (coalesces a burst into one). Never emitted when
|
|
310
|
+
* nothing announces (byte-identical idle).
|
|
311
|
+
*/
|
|
312
|
+
interface WalletsChangedEvent {
|
|
313
|
+
type: 'wallets:changed';
|
|
314
|
+
/** Why the list changed. Currently only late/inject-time announce discovery. */
|
|
315
|
+
reason: 'announced';
|
|
316
|
+
}
|
|
302
317
|
/**
|
|
303
318
|
* All event types
|
|
304
319
|
*/
|
|
305
|
-
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | ErrorEvent;
|
|
320
|
+
type PartyLayerEvent = RegistryUpdatedEvent | RegistryStatusEvent | SessionConnectedEvent | SessionDisconnectedEvent | SessionExpiredEvent | SessionNetworkMismatchEvent | TxStatusEvent | WalletsChangedEvent | ErrorEvent;
|
|
306
321
|
/**
|
|
307
322
|
* Event handler type
|
|
308
323
|
*/
|
|
@@ -332,6 +347,10 @@ declare class PartyLayerClient {
|
|
|
332
347
|
private telemetry?;
|
|
333
348
|
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
334
349
|
private announceEntriesCache;
|
|
350
|
+
private readonly announceRegistry;
|
|
351
|
+
private announceUnsubscribe;
|
|
352
|
+
/** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
|
|
353
|
+
private walletsChangedTimer;
|
|
335
354
|
private origin;
|
|
336
355
|
constructor(config: PartyLayerConfig);
|
|
337
356
|
/**
|
|
@@ -388,6 +407,22 @@ declare class PartyLayerClient {
|
|
|
388
407
|
* `canton:requestProvider` handshake (e.g. after a wallet is installed).
|
|
389
408
|
*/
|
|
390
409
|
refreshDiscovery(): void;
|
|
410
|
+
/**
|
|
411
|
+
* Persistent-accumulator callback (mounted at construction). On each newly
|
|
412
|
+
* announced provider:
|
|
413
|
+
* 1. record it in the live `announceRegistry` (unchanged);
|
|
414
|
+
* 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
|
|
415
|
+
* as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
|
|
416
|
+
* and surfaces the wallet. This does NOT touch `warmPlans` (those hold
|
|
417
|
+
* only GenericDiscoveryAdapter popup plans — a disjoint set);
|
|
418
|
+
* 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
|
|
419
|
+
* the React provider) re-lists. The debounce coalesces a burst — and the
|
|
420
|
+
* construction-time reply storm — into one emit (no re-discovery storm).
|
|
421
|
+
*
|
|
422
|
+
* Byte-identical idle: with zero announces this never fires — no invalidation,
|
|
423
|
+
* no emit, no re-list.
|
|
424
|
+
*/
|
|
425
|
+
private onAnnounceAccumulated;
|
|
391
426
|
/**
|
|
392
427
|
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
393
428
|
*
|
|
@@ -848,4 +883,4 @@ declare function isTelemetryConfig(value: unknown): value is TelemetryConfig;
|
|
|
848
883
|
*/
|
|
849
884
|
declare function createTelemetryAdapter(config: TelemetryAdapter | TelemetryConfig | undefined): TelemetryAdapter | undefined;
|
|
850
885
|
|
|
851
|
-
export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
|
|
886
|
+
export { ANNOUNCED_WALLET_ID_PREFIX, type AdapterClass, PartyLayerClient as CantonConnectClient, type PartyLayerConfig as CantonConnectConfig, type PartyLayerEvent as CantonConnectEvent, type ConnectOptions, DEFAULT_REGISTRY_URL, type ErrorEvent, type EventHandler, GenericAnnounceAdapter, type GenericAnnounceAdapterArgs, GenericDiscoveryAdapter, type GenericDiscoveryAdapterArgs, MetricsTelemetryAdapter, PartyLayerClient, type PartyLayerConfig, type PartyLayerEvent, type RegistryUpdatedEvent, type SessionConnectedEvent, type SessionDisconnectedEvent, type SessionExpiredEvent, type TelemetryConfig, type TxStatusEvent, type WalletFilter, type WalletsChangedEvent, PartyLayerClient as _PartyLayerClientInternal, announcedWalletId, createPartyLayer as createCantonConnect, createPartyLayer, createTelemetryAdapter, getBuiltinAdapters, isTelemetryConfig };
|
package/dist/index.js
CHANGED
|
@@ -579,6 +579,7 @@ function createTelemetryAdapter(config) {
|
|
|
579
579
|
return config;
|
|
580
580
|
}
|
|
581
581
|
var SESSION_STORAGE_KEY = "active_session";
|
|
582
|
+
var WALLETS_CHANGED_DEBOUNCE_MS = 50;
|
|
582
583
|
var PartyLayerClient = class {
|
|
583
584
|
config;
|
|
584
585
|
adapters = /* @__PURE__ */ new Map();
|
|
@@ -599,6 +600,14 @@ var PartyLayerClient = class {
|
|
|
599
600
|
telemetry;
|
|
600
601
|
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
601
602
|
announceEntriesCache = null;
|
|
603
|
+
// Persistent announce accumulator (option 1): one window subscription mounted
|
|
604
|
+
// at construction so LATE / inject-time `canton:announceProvider` replies are
|
|
605
|
+
// captured (not just a one-shot window). Read by aggregateAnnouncedWallets;
|
|
606
|
+
// torn down in destroy(). Empty → listWallets() output is byte-identical.
|
|
607
|
+
announceRegistry = /* @__PURE__ */ new Map();
|
|
608
|
+
announceUnsubscribe = null;
|
|
609
|
+
/** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
|
|
610
|
+
walletsChangedTimer = null;
|
|
602
611
|
origin;
|
|
603
612
|
constructor(config) {
|
|
604
613
|
this.config = config;
|
|
@@ -640,6 +649,12 @@ var PartyLayerClient = class {
|
|
|
640
649
|
storage: this.storage
|
|
641
650
|
});
|
|
642
651
|
this.updateRegistryStatus();
|
|
652
|
+
if (this.announceEnabled) {
|
|
653
|
+
this.announceUnsubscribe = provider.subscribeAnnouncedProviders(
|
|
654
|
+
(p) => this.onAnnounceAccumulated(p),
|
|
655
|
+
{ createProvider: (a) => provider.createExtensionChannelProvider({ target: a.target ?? a.id }) }
|
|
656
|
+
);
|
|
657
|
+
}
|
|
643
658
|
this.restoreSession().catch((err) => {
|
|
644
659
|
this.emit("error", {
|
|
645
660
|
type: "error",
|
|
@@ -783,6 +798,30 @@ var PartyLayerClient = class {
|
|
|
783
798
|
refreshDiscovery() {
|
|
784
799
|
this.announceEntriesCache = null;
|
|
785
800
|
}
|
|
801
|
+
/**
|
|
802
|
+
* Persistent-accumulator callback (mounted at construction). On each newly
|
|
803
|
+
* announced provider:
|
|
804
|
+
* 1. record it in the live `announceRegistry` (unchanged);
|
|
805
|
+
* 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
|
|
806
|
+
* as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
|
|
807
|
+
* and surfaces the wallet. This does NOT touch `warmPlans` (those hold
|
|
808
|
+
* only GenericDiscoveryAdapter popup plans — a disjoint set);
|
|
809
|
+
* 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
|
|
810
|
+
* the React provider) re-lists. The debounce coalesces a burst — and the
|
|
811
|
+
* construction-time reply storm — into one emit (no re-discovery storm).
|
|
812
|
+
*
|
|
813
|
+
* Byte-identical idle: with zero announces this never fires — no invalidation,
|
|
814
|
+
* no emit, no re-list.
|
|
815
|
+
*/
|
|
816
|
+
onAnnounceAccumulated(p) {
|
|
817
|
+
this.announceRegistry.set(p.id, p);
|
|
818
|
+
this.announceEntriesCache = null;
|
|
819
|
+
if (this.walletsChangedTimer !== null) return;
|
|
820
|
+
this.walletsChangedTimer = setTimeout(() => {
|
|
821
|
+
this.walletsChangedTimer = null;
|
|
822
|
+
this.emit("wallets:changed", { type: "wallets:changed", reason: "announced" });
|
|
823
|
+
}, WALLETS_CHANGED_DEBOUNCE_MS);
|
|
824
|
+
}
|
|
786
825
|
/**
|
|
787
826
|
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
788
827
|
*
|
|
@@ -800,12 +839,17 @@ var PartyLayerClient = class {
|
|
|
800
839
|
if (!this.announceEnabled) return base;
|
|
801
840
|
if (this.announceEntriesCache === null) {
|
|
802
841
|
try {
|
|
803
|
-
const
|
|
842
|
+
const snapshot = await provider.discoverProviders({
|
|
804
843
|
timeoutMs: this.config.discovery?.announceTimeoutMs,
|
|
805
844
|
// Working provider over the announce target channel; G4 (provider.md):
|
|
806
845
|
// target defaults to id when omitted — never a shared slot.
|
|
807
846
|
createProvider: (a) => provider.createExtensionChannelProvider({ target: a.target ?? a.id })
|
|
808
847
|
});
|
|
848
|
+
const byId = /* @__PURE__ */ new Map();
|
|
849
|
+
for (const d of snapshot) byId.set(d.id, d);
|
|
850
|
+
for (const d of this.announceRegistry.values())
|
|
851
|
+
if (!byId.has(d.id)) byId.set(d.id, d);
|
|
852
|
+
const discovered = [...byId.values()];
|
|
809
853
|
const entries = [];
|
|
810
854
|
for (const d of discovered) {
|
|
811
855
|
if (d.identityResolved === false) continue;
|
|
@@ -1315,6 +1359,13 @@ var PartyLayerClient = class {
|
|
|
1315
1359
|
this.telemetry.flush().catch(() => {
|
|
1316
1360
|
});
|
|
1317
1361
|
}
|
|
1362
|
+
this.announceUnsubscribe?.();
|
|
1363
|
+
this.announceUnsubscribe = null;
|
|
1364
|
+
this.announceRegistry.clear();
|
|
1365
|
+
if (this.walletsChangedTimer !== null) {
|
|
1366
|
+
clearTimeout(this.walletsChangedTimer);
|
|
1367
|
+
this.walletsChangedTimer = null;
|
|
1368
|
+
}
|
|
1318
1369
|
this.eventHandlers.clear();
|
|
1319
1370
|
this.activeSession = null;
|
|
1320
1371
|
}
|