@partylayer/sdk 0.10.0 → 0.10.2
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 +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +50 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { toWalletId, toPartyId, isRecognizedNetwork, hashForPrivacy, createMetricsPayload, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, detectNetworkMismatch, NetworkMismatchError, METRICS, WalletNotFoundError, capabilityGuard, installGuard, toSessionId, CapabilityNotSupportedError, errorMetricName } from '@partylayer/core';
|
|
2
|
-
export { 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';
|
|
1
|
+
import { toWalletId, toPartyId, isRecognizedNetwork, hashForPrivacy, createMetricsPayload, isOfficialAdapterFactory, isOfficialProviderAdapter, mapUnknownErrorToPartyLayerError, findMatchingWalletInfo, detectNetworkMismatch, NetworkMismatchError, METRICS, AdapterNotRegisteredError, WalletNotFoundError, capabilityGuard, installGuard, toSessionId, CapabilityNotSupportedError, errorMetricName } from '@partylayer/core';
|
|
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';
|
|
@@ -605,6 +605,12 @@ var PartyLayerClient = class {
|
|
|
605
605
|
telemetry;
|
|
606
606
|
/** Cached announce-discovery picker entries (one-shot; cleared by refreshDiscovery). */
|
|
607
607
|
announceEntriesCache = null;
|
|
608
|
+
// Persistent announce accumulator (option 1): one window subscription mounted
|
|
609
|
+
// at construction so LATE / inject-time `canton:announceProvider` replies are
|
|
610
|
+
// captured (not just a one-shot window). Read by aggregateAnnouncedWallets;
|
|
611
|
+
// torn down in destroy(). Empty → listWallets() output is byte-identical.
|
|
612
|
+
announceRegistry = /* @__PURE__ */ new Map();
|
|
613
|
+
announceUnsubscribe = null;
|
|
608
614
|
origin;
|
|
609
615
|
constructor(config) {
|
|
610
616
|
this.config = config;
|
|
@@ -646,6 +652,12 @@ var PartyLayerClient = class {
|
|
|
646
652
|
storage: this.storage
|
|
647
653
|
});
|
|
648
654
|
this.updateRegistryStatus();
|
|
655
|
+
if (this.announceEnabled) {
|
|
656
|
+
this.announceUnsubscribe = subscribeAnnouncedProviders(
|
|
657
|
+
(p) => this.announceRegistry.set(p.id, p),
|
|
658
|
+
{ createProvider: (a) => createExtensionChannelProvider({ target: a.target ?? a.id }) }
|
|
659
|
+
);
|
|
660
|
+
}
|
|
649
661
|
this.restoreSession().catch((err) => {
|
|
650
662
|
this.emit("error", {
|
|
651
663
|
type: "error",
|
|
@@ -753,6 +765,27 @@ var PartyLayerClient = class {
|
|
|
753
765
|
if (!hidden || hidden.size === 0) return wallets;
|
|
754
766
|
return wallets.filter((w) => !hidden.has(String(w.walletId)));
|
|
755
767
|
}
|
|
768
|
+
/**
|
|
769
|
+
* If `walletId` maps to a registry entry with `transport: 'discovery-adapter'`,
|
|
770
|
+
* return the bits to build an actionable "register its adapter" error; else
|
|
771
|
+
* null (truly-unknown or non-discovery → plain WalletNotFoundError). Reads the
|
|
772
|
+
* UNGATED registry (SWR-cached); registry-unavailable → null (safe fallback).
|
|
773
|
+
*/
|
|
774
|
+
async unregisteredDiscoveryInfo(walletId) {
|
|
775
|
+
try {
|
|
776
|
+
const registry = await this.registryClient.getRegistry();
|
|
777
|
+
const entry = registry.wallets.find((w) => toWalletId(w.id) === walletId);
|
|
778
|
+
if (entry?.adapter?.transport !== "discovery-adapter") return null;
|
|
779
|
+
const pid = entry.adapter?.config?.providerId;
|
|
780
|
+
return {
|
|
781
|
+
name: entry.name,
|
|
782
|
+
providerId: typeof pid === "string" ? pid : entry.id,
|
|
783
|
+
adapterPackage: typeof entry.adapter?.type === "string" ? entry.adapter.type : void 0
|
|
784
|
+
};
|
|
785
|
+
} catch {
|
|
786
|
+
return null;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
756
789
|
/**
|
|
757
790
|
* Whether announce discovery is active: explicit `discovery.announce`, else
|
|
758
791
|
* ON in the browser and OFF under SSR (no `window`). Canonical: provider.md.
|
|
@@ -785,12 +818,17 @@ var PartyLayerClient = class {
|
|
|
785
818
|
if (!this.announceEnabled) return base;
|
|
786
819
|
if (this.announceEntriesCache === null) {
|
|
787
820
|
try {
|
|
788
|
-
const
|
|
821
|
+
const snapshot = await discoverProviders({
|
|
789
822
|
timeoutMs: this.config.discovery?.announceTimeoutMs,
|
|
790
823
|
// Working provider over the announce target channel; G4 (provider.md):
|
|
791
824
|
// target defaults to id when omitted — never a shared slot.
|
|
792
825
|
createProvider: (a) => createExtensionChannelProvider({ target: a.target ?? a.id })
|
|
793
826
|
});
|
|
827
|
+
const byId = /* @__PURE__ */ new Map();
|
|
828
|
+
for (const d of snapshot) byId.set(d.id, d);
|
|
829
|
+
for (const d of this.announceRegistry.values())
|
|
830
|
+
if (!byId.has(d.id)) byId.set(d.id, d);
|
|
831
|
+
const discovered = [...byId.values()];
|
|
794
832
|
const entries = [];
|
|
795
833
|
for (const d of discovered) {
|
|
796
834
|
if (d.identityResolved === false) continue;
|
|
@@ -916,6 +954,10 @@ var PartyLayerClient = class {
|
|
|
916
954
|
metadata: { source: "native-cip0103" }
|
|
917
955
|
};
|
|
918
956
|
} else {
|
|
957
|
+
const info = await this.unregisteredDiscoveryInfo(options.walletId);
|
|
958
|
+
if (info) {
|
|
959
|
+
throw new AdapterNotRegisteredError(String(options.walletId), info);
|
|
960
|
+
}
|
|
919
961
|
throw new WalletNotFoundError(String(options.walletId));
|
|
920
962
|
}
|
|
921
963
|
}
|
|
@@ -1296,6 +1338,9 @@ var PartyLayerClient = class {
|
|
|
1296
1338
|
this.telemetry.flush().catch(() => {
|
|
1297
1339
|
});
|
|
1298
1340
|
}
|
|
1341
|
+
this.announceUnsubscribe?.();
|
|
1342
|
+
this.announceUnsubscribe = null;
|
|
1343
|
+
this.announceRegistry.clear();
|
|
1299
1344
|
this.eventHandlers.clear();
|
|
1300
1345
|
this.activeSession = null;
|
|
1301
1346
|
}
|