@partylayer/provider 0.5.0 → 0.5.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 CHANGED
@@ -55,7 +55,7 @@ declare function isCIP0103Provider(obj: unknown): obj is CIP0103Provider;
55
55
  * Scans well-known window paths and their sub-properties for objects
56
56
  * that implement the Provider interface.
57
57
  */
58
- declare function discoverInjectedProviders(): DiscoveredProvider[];
58
+ declare function discoverInjectedProviders(extraPaths?: readonly string[]): DiscoveredProvider[];
59
59
  /**
60
60
  * Wait for a specific provider to be injected (with timeout).
61
61
  *
@@ -88,6 +88,13 @@ interface AnnounceDiscoveryOptions {
88
88
  * `@canton-network/dapp-sdk` `ExtensionAdapter`, and tests a mock.
89
89
  */
90
90
  createProvider?: (announced: AnnouncedWallet) => CIP0103Provider | Promise<CIP0103Provider>;
91
+ /**
92
+ * Extra window global paths to scan for an injected provider, on top of the
93
+ * built-in list. The SDK passes the window globals that announce-transport
94
+ * registry entries declare, so a wallet at its own dedicated global is found.
95
+ * Deduplicated against the built-in paths; an unknown path is simply absent.
96
+ */
97
+ injectionPaths?: readonly string[];
91
98
  }
92
99
  /**
93
100
  * Discover wallets that advertise via `canton:announceProvider` (EIP-6963-style).
package/dist/index.d.ts CHANGED
@@ -55,7 +55,7 @@ declare function isCIP0103Provider(obj: unknown): obj is CIP0103Provider;
55
55
  * Scans well-known window paths and their sub-properties for objects
56
56
  * that implement the Provider interface.
57
57
  */
58
- declare function discoverInjectedProviders(): DiscoveredProvider[];
58
+ declare function discoverInjectedProviders(extraPaths?: readonly string[]): DiscoveredProvider[];
59
59
  /**
60
60
  * Wait for a specific provider to be injected (with timeout).
61
61
  *
@@ -88,6 +88,13 @@ interface AnnounceDiscoveryOptions {
88
88
  * `@canton-network/dapp-sdk` `ExtensionAdapter`, and tests a mock.
89
89
  */
90
90
  createProvider?: (announced: AnnouncedWallet) => CIP0103Provider | Promise<CIP0103Provider>;
91
+ /**
92
+ * Extra window global paths to scan for an injected provider, on top of the
93
+ * built-in list. The SDK passes the window globals that announce-transport
94
+ * registry entries declare, so a wallet at its own dedicated global is found.
95
+ * Deduplicated against the built-in paths; an unknown path is simply absent.
96
+ */
97
+ injectionPaths?: readonly string[];
91
98
  }
92
99
  /**
93
100
  * Discover wallets that advertise via `canton:announceProvider` (EIP-6963-style).
package/dist/index.js CHANGED
@@ -514,7 +514,7 @@ var PartyLayerProvider = class {
514
514
  };
515
515
 
516
516
  // src/bridge.ts
517
- var PROVIDER_VERSION = "0.5.0" ;
517
+ var PROVIDER_VERSION = "0.5.2" ;
518
518
  function createProviderBridge(client) {
519
519
  const eventBus = new CIP0103EventBus();
520
520
  const pendingEmitted = /* @__PURE__ */ new Set();
@@ -905,12 +905,13 @@ function isCIP0103Provider(obj) {
905
905
  const p = obj;
906
906
  return typeof p.request === "function" && typeof p.on === "function" && typeof p.emit === "function" && typeof p.removeListener === "function";
907
907
  }
908
- function discoverInjectedProviders() {
908
+ function discoverInjectedProviders(extraPaths) {
909
909
  if (typeof window === "undefined") return [];
910
910
  const discovered = [];
911
911
  const seen = /* @__PURE__ */ new Set();
912
912
  const win = window;
913
- for (const path of KNOWN_INJECTION_PATHS) {
913
+ const paths = extraPaths && extraPaths.length > 0 ? [.../* @__PURE__ */ new Set([...KNOWN_INJECTION_PATHS, ...extraPaths])] : KNOWN_INJECTION_PATHS;
914
+ for (const path of paths) {
914
915
  const candidate = win[path];
915
916
  if (candidate === void 0 || candidate === null) continue;
916
917
  if (isCIP0103Provider(candidate) && !seen.has(candidate)) {
@@ -971,6 +972,41 @@ var CANTON_ANNOUNCE_PROVIDER_EVENT = "canton:announceProvider";
971
972
  function defaultAnnounceProvider(announced) {
972
973
  return createExtensionChannelProvider({ target: announced.target ?? announced.id });
973
974
  }
975
+ function firstNonEmptyString(...vals) {
976
+ for (const v of vals) {
977
+ if (typeof v === "string" && v.length > 0) return v;
978
+ }
979
+ return void 0;
980
+ }
981
+ var warnedAnnounceShapes = /* @__PURE__ */ new Set();
982
+ function announceShapeKey(detail, info) {
983
+ const top = Object.keys(detail).sort().join(",");
984
+ const inner = info ? Object.keys(info).sort().join(",") : "";
985
+ return `${top}|${inner}`;
986
+ }
987
+ function readAnnouncedWallet(detail) {
988
+ if (!detail) return void 0;
989
+ const info = typeof detail.info === "object" && detail.info !== null ? detail.info : void 0;
990
+ const id = firstNonEmptyString(detail.providerId, detail.id, info?.uuid, info?.rdns);
991
+ if (id === void 0) {
992
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
993
+ const key = announceShapeKey(detail, info);
994
+ if (!warnedAnnounceShapes.has(key)) {
995
+ warnedAnnounceShapes.add(key);
996
+ console.warn(
997
+ "[PartyLayer] Ignored a canton:announceProvider event: no readable provider id (expected a non-empty string at detail.providerId, detail.id, or detail.info.uuid). See https://partylayer.xyz/docs/generic-bridge"
998
+ );
999
+ }
1000
+ }
1001
+ return void 0;
1002
+ }
1003
+ return {
1004
+ id,
1005
+ name: firstNonEmptyString(detail.name, info?.name),
1006
+ icon: firstNonEmptyString(detail.icon, info?.icon),
1007
+ target: firstNonEmptyString(detail.target)
1008
+ };
1009
+ }
974
1010
  async function discoverAnnouncedProviders(options = {}) {
975
1011
  if (typeof window === "undefined") return [];
976
1012
  const timeoutMs = options.timeoutMs ?? 300;
@@ -978,16 +1014,10 @@ async function discoverAnnouncedProviders(options = {}) {
978
1014
  const announced = /* @__PURE__ */ new Map();
979
1015
  const onAnnounce = (event) => {
980
1016
  const detail = event.detail;
981
- if (!detail) return;
982
- const rawId = detail.providerId ?? detail.id;
983
- if (typeof rawId !== "string" || rawId.length === 0) return;
984
- if (announced.has(rawId)) return;
985
- announced.set(rawId, {
986
- id: rawId,
987
- name: typeof detail.name === "string" ? detail.name : void 0,
988
- icon: typeof detail.icon === "string" ? detail.icon : void 0,
989
- target: typeof detail.target === "string" ? detail.target : void 0
990
- });
1017
+ const wallet = readAnnouncedWallet(detail);
1018
+ if (!wallet) return;
1019
+ if (announced.has(wallet.id)) return;
1020
+ announced.set(wallet.id, wallet);
991
1021
  };
992
1022
  window.addEventListener(
993
1023
  CANTON_ANNOUNCE_PROVIDER_EVENT,
@@ -1028,17 +1058,10 @@ function subscribeAnnouncedProviders(onProvider, options = {}) {
1028
1058
  const seen = /* @__PURE__ */ new Set();
1029
1059
  const onAnnounce = (event) => {
1030
1060
  const detail = event.detail;
1031
- if (!detail) return;
1032
- const rawId = detail.providerId ?? detail.id;
1033
- if (typeof rawId !== "string" || rawId.length === 0) return;
1034
- if (seen.has(rawId)) return;
1035
- seen.add(rawId);
1036
- const wallet = {
1037
- id: rawId,
1038
- name: typeof detail.name === "string" ? detail.name : void 0,
1039
- icon: typeof detail.icon === "string" ? detail.icon : void 0,
1040
- target: typeof detail.target === "string" ? detail.target : void 0
1041
- };
1061
+ const wallet = readAnnouncedWallet(detail);
1062
+ if (!wallet) return;
1063
+ if (seen.has(wallet.id)) return;
1064
+ seen.add(wallet.id);
1042
1065
  void Promise.resolve().then(() => make(wallet)).then((provider) => {
1043
1066
  if (!isCIP0103Provider(provider)) return;
1044
1067
  onProvider({
@@ -1109,7 +1132,7 @@ async function resolveInjectedKey(d) {
1109
1132
  return { key: d.id, resolved: false };
1110
1133
  }
1111
1134
  async function discoverProviders(options = {}) {
1112
- const injected = discoverInjectedProviders();
1135
+ const injected = discoverInjectedProviders(options.injectionPaths);
1113
1136
  const announcedResults = await discoverAnnouncedProviders(options);
1114
1137
  const injectedKeys = await Promise.all(injected.map(resolveInjectedKey));
1115
1138
  const out = [];