@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.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { toWalletId, toPartyId, isRecognizedNetwork, hashForPrivacy, createMetri
|
|
|
2
2
|
export { AdapterNotRegisteredError, PartyLayerError as CantonConnectError, CapabilityNotSupportedError, ENABLEMENT_METRICS, ERROR_METRICS, InternalError, METRICS, OriginNotAllowedError, PartyLayerError, REGISTRY_METRICS, RegistryFetchFailedError, RegistrySchemaInvalidError, RegistryVerificationFailedError, SessionExpiredError, TimeoutError, TransportError, UserRejectedError, WalletNotFoundError, WalletNotInstalledError, errorMetricName, isOfficialAdapterFactory, isOfficialProviderAdapter } 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 {
|
|
5
|
+
import { subscribeAnnouncedProviders, createExtensionChannelProvider, discoverProviders, createProviderBridge } 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
|
import { ConsoleAdapter } from '@partylayer/adapter-console';
|
|
8
8
|
export { ConsoleAdapter } from '@partylayer/adapter-console';
|
|
@@ -585,6 +585,7 @@ function createTelemetryAdapter(config) {
|
|
|
585
585
|
return config;
|
|
586
586
|
}
|
|
587
587
|
var SESSION_STORAGE_KEY = "active_session";
|
|
588
|
+
var WALLETS_CHANGED_DEBOUNCE_MS = 50;
|
|
588
589
|
var PartyLayerClient = class {
|
|
589
590
|
config;
|
|
590
591
|
adapters = /* @__PURE__ */ new Map();
|
|
@@ -605,6 +606,14 @@ var PartyLayerClient = class {
|
|
|
605
606
|
telemetry;
|
|
606
607
|
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
607
608
|
announceEntriesCache = null;
|
|
609
|
+
// Persistent announce accumulator (option 1): one window subscription mounted
|
|
610
|
+
// at construction so LATE / inject-time `canton:announceProvider` replies are
|
|
611
|
+
// captured (not just a one-shot window). Read by aggregateAnnouncedWallets;
|
|
612
|
+
// torn down in destroy(). Empty → listWallets() output is byte-identical.
|
|
613
|
+
announceRegistry = /* @__PURE__ */ new Map();
|
|
614
|
+
announceUnsubscribe = null;
|
|
615
|
+
/** Pending debounced `wallets:changed` emit (coalesces an announce burst). */
|
|
616
|
+
walletsChangedTimer = null;
|
|
608
617
|
origin;
|
|
609
618
|
constructor(config) {
|
|
610
619
|
this.config = config;
|
|
@@ -646,6 +655,12 @@ var PartyLayerClient = class {
|
|
|
646
655
|
storage: this.storage
|
|
647
656
|
});
|
|
648
657
|
this.updateRegistryStatus();
|
|
658
|
+
if (this.announceEnabled) {
|
|
659
|
+
this.announceUnsubscribe = subscribeAnnouncedProviders(
|
|
660
|
+
(p) => this.onAnnounceAccumulated(p),
|
|
661
|
+
{ createProvider: (a) => createExtensionChannelProvider({ target: a.target ?? a.id }) }
|
|
662
|
+
);
|
|
663
|
+
}
|
|
649
664
|
this.restoreSession().catch((err) => {
|
|
650
665
|
this.emit("error", {
|
|
651
666
|
type: "error",
|
|
@@ -789,6 +804,30 @@ var PartyLayerClient = class {
|
|
|
789
804
|
refreshDiscovery() {
|
|
790
805
|
this.announceEntriesCache = null;
|
|
791
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* Persistent-accumulator callback (mounted at construction). On each newly
|
|
809
|
+
* announced provider:
|
|
810
|
+
* 1. record it in the live `announceRegistry` (unchanged);
|
|
811
|
+
* 2. invalidate the one-shot `announceEntriesCache` — the SAME invalidation
|
|
812
|
+
* as {@link refreshDiscovery}, so the next `listWallets()` re-aggregates
|
|
813
|
+
* and surfaces the wallet. This does NOT touch `warmPlans` (those hold
|
|
814
|
+
* only GenericDiscoveryAdapter popup plans — a disjoint set);
|
|
815
|
+
* 3. emit a DEBOUNCED `wallets:changed` signal so a reactive consumer (e.g.
|
|
816
|
+
* the React provider) re-lists. The debounce coalesces a burst — and the
|
|
817
|
+
* construction-time reply storm — into one emit (no re-discovery storm).
|
|
818
|
+
*
|
|
819
|
+
* Byte-identical idle: with zero announces this never fires — no invalidation,
|
|
820
|
+
* no emit, no re-list.
|
|
821
|
+
*/
|
|
822
|
+
onAnnounceAccumulated(p) {
|
|
823
|
+
this.announceRegistry.set(p.id, p);
|
|
824
|
+
this.announceEntriesCache = null;
|
|
825
|
+
if (this.walletsChangedTimer !== null) return;
|
|
826
|
+
this.walletsChangedTimer = setTimeout(() => {
|
|
827
|
+
this.walletsChangedTimer = null;
|
|
828
|
+
this.emit("wallets:changed", { type: "wallets:changed", reason: "announced" });
|
|
829
|
+
}, WALLETS_CHANGED_DEBOUNCE_MS);
|
|
830
|
+
}
|
|
792
831
|
/**
|
|
793
832
|
* Aggregate `canton:announceProvider` wallets into the picker list (A2).
|
|
794
833
|
*
|
|
@@ -806,12 +845,17 @@ var PartyLayerClient = class {
|
|
|
806
845
|
if (!this.announceEnabled) return base;
|
|
807
846
|
if (this.announceEntriesCache === null) {
|
|
808
847
|
try {
|
|
809
|
-
const
|
|
848
|
+
const snapshot = await discoverProviders({
|
|
810
849
|
timeoutMs: this.config.discovery?.announceTimeoutMs,
|
|
811
850
|
// Working provider over the announce target channel; G4 (provider.md):
|
|
812
851
|
// target defaults to id when omitted — never a shared slot.
|
|
813
852
|
createProvider: (a) => createExtensionChannelProvider({ target: a.target ?? a.id })
|
|
814
853
|
});
|
|
854
|
+
const byId = /* @__PURE__ */ new Map();
|
|
855
|
+
for (const d of snapshot) byId.set(d.id, d);
|
|
856
|
+
for (const d of this.announceRegistry.values())
|
|
857
|
+
if (!byId.has(d.id)) byId.set(d.id, d);
|
|
858
|
+
const discovered = [...byId.values()];
|
|
815
859
|
const entries = [];
|
|
816
860
|
for (const d of discovered) {
|
|
817
861
|
if (d.identityResolved === false) continue;
|
|
@@ -1321,6 +1365,13 @@ var PartyLayerClient = class {
|
|
|
1321
1365
|
this.telemetry.flush().catch(() => {
|
|
1322
1366
|
});
|
|
1323
1367
|
}
|
|
1368
|
+
this.announceUnsubscribe?.();
|
|
1369
|
+
this.announceUnsubscribe = null;
|
|
1370
|
+
this.announceRegistry.clear();
|
|
1371
|
+
if (this.walletsChangedTimer !== null) {
|
|
1372
|
+
clearTimeout(this.walletsChangedTimer);
|
|
1373
|
+
this.walletsChangedTimer = null;
|
|
1374
|
+
}
|
|
1324
1375
|
this.eventHandlers.clear();
|
|
1325
1376
|
this.activeSession = null;
|
|
1326
1377
|
}
|