@partylayer/provider 0.5.1 → 0.6.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.mjs CHANGED
@@ -513,7 +513,7 @@ var PartyLayerProvider = class {
513
513
  };
514
514
 
515
515
  // src/bridge.ts
516
- var PROVIDER_VERSION = "0.5.1" ;
516
+ var PROVIDER_VERSION = "0.6.0" ;
517
517
  function createProviderBridge(client) {
518
518
  const eventBus = new CIP0103EventBus();
519
519
  const pendingEmitted = /* @__PURE__ */ new Set();
@@ -615,15 +615,17 @@ async function handleRequest(client, args, eventBus, pendingEmitted) {
615
615
  const signResult = await client.signTransaction({ tx: p });
616
616
  const session = await client.getActiveSession();
617
617
  const partyId = String(signResult.partyId ?? session?.partyId ?? "unknown");
618
- eventBus.emit(CIP0103_EVENTS.TX_CHANGED, {
619
- status: "signed",
620
- commandId: cmdId,
621
- payload: {
622
- signature: String(signResult.transactionHash),
623
- signedBy: partyId,
624
- party: partyId
625
- }
626
- });
618
+ if (signResult.transactionHash !== void 0) {
619
+ eventBus.emit(CIP0103_EVENTS.TX_CHANGED, {
620
+ status: "signed",
621
+ commandId: cmdId,
622
+ payload: {
623
+ signature: String(signResult.transactionHash),
624
+ signedBy: partyId,
625
+ party: partyId
626
+ }
627
+ });
628
+ }
627
629
  try {
628
630
  const receipt = await client.submitTransaction({
629
631
  signedTx: signResult.signedTx ?? signResult.transactionHash
@@ -633,7 +635,11 @@ async function handleRequest(client, args, eventBus, pendingEmitted) {
633
635
  status: "executed",
634
636
  commandId: cmdId,
635
637
  payload: {
636
- updateId: receipt.updateId ?? receipt.commandId ?? String(receipt.transactionHash),
638
+ // All three are real identifiers — the receipt's update id, the
639
+ // wallet's command id, or the bridge's own command id for this
640
+ // operation. `String(receipt.transactionHash)` was the old tail
641
+ // and would now stringify `undefined`.
642
+ updateId: receipt.updateId ?? receipt.commandId ?? cmdId,
637
643
  completionOffset: 0
638
644
  }
639
645
  });
@@ -904,12 +910,13 @@ function isCIP0103Provider(obj) {
904
910
  const p = obj;
905
911
  return typeof p.request === "function" && typeof p.on === "function" && typeof p.emit === "function" && typeof p.removeListener === "function";
906
912
  }
907
- function discoverInjectedProviders() {
913
+ function discoverInjectedProviders(extraPaths) {
908
914
  if (typeof window === "undefined") return [];
909
915
  const discovered = [];
910
916
  const seen = /* @__PURE__ */ new Set();
911
917
  const win = window;
912
- for (const path of KNOWN_INJECTION_PATHS) {
918
+ const paths = extraPaths && extraPaths.length > 0 ? [.../* @__PURE__ */ new Set([...KNOWN_INJECTION_PATHS, ...extraPaths])] : KNOWN_INJECTION_PATHS;
919
+ for (const path of paths) {
913
920
  const candidate = win[path];
914
921
  if (candidate === void 0 || candidate === null) continue;
915
922
  if (isCIP0103Provider(candidate) && !seen.has(candidate)) {
@@ -970,6 +977,41 @@ var CANTON_ANNOUNCE_PROVIDER_EVENT = "canton:announceProvider";
970
977
  function defaultAnnounceProvider(announced) {
971
978
  return createExtensionChannelProvider({ target: announced.target ?? announced.id });
972
979
  }
980
+ function firstNonEmptyString(...vals) {
981
+ for (const v of vals) {
982
+ if (typeof v === "string" && v.length > 0) return v;
983
+ }
984
+ return void 0;
985
+ }
986
+ var warnedAnnounceShapes = /* @__PURE__ */ new Set();
987
+ function announceShapeKey(detail, info) {
988
+ const top = Object.keys(detail).sort().join(",");
989
+ const inner = info ? Object.keys(info).sort().join(",") : "";
990
+ return `${top}|${inner}`;
991
+ }
992
+ function readAnnouncedWallet(detail) {
993
+ if (!detail) return void 0;
994
+ const info = typeof detail.info === "object" && detail.info !== null ? detail.info : void 0;
995
+ const id = firstNonEmptyString(detail.providerId, detail.id, info?.uuid, info?.rdns);
996
+ if (id === void 0) {
997
+ if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
998
+ const key = announceShapeKey(detail, info);
999
+ if (!warnedAnnounceShapes.has(key)) {
1000
+ warnedAnnounceShapes.add(key);
1001
+ console.warn(
1002
+ "[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"
1003
+ );
1004
+ }
1005
+ }
1006
+ return void 0;
1007
+ }
1008
+ return {
1009
+ id,
1010
+ name: firstNonEmptyString(detail.name, info?.name),
1011
+ icon: firstNonEmptyString(detail.icon, info?.icon),
1012
+ target: firstNonEmptyString(detail.target)
1013
+ };
1014
+ }
973
1015
  async function discoverAnnouncedProviders(options = {}) {
974
1016
  if (typeof window === "undefined") return [];
975
1017
  const timeoutMs = options.timeoutMs ?? 300;
@@ -977,16 +1019,10 @@ async function discoverAnnouncedProviders(options = {}) {
977
1019
  const announced = /* @__PURE__ */ new Map();
978
1020
  const onAnnounce = (event) => {
979
1021
  const detail = event.detail;
980
- if (!detail) return;
981
- const rawId = detail.providerId ?? detail.id;
982
- if (typeof rawId !== "string" || rawId.length === 0) return;
983
- if (announced.has(rawId)) return;
984
- announced.set(rawId, {
985
- id: rawId,
986
- name: typeof detail.name === "string" ? detail.name : void 0,
987
- icon: typeof detail.icon === "string" ? detail.icon : void 0,
988
- target: typeof detail.target === "string" ? detail.target : void 0
989
- });
1022
+ const wallet = readAnnouncedWallet(detail);
1023
+ if (!wallet) return;
1024
+ if (announced.has(wallet.id)) return;
1025
+ announced.set(wallet.id, wallet);
990
1026
  };
991
1027
  window.addEventListener(
992
1028
  CANTON_ANNOUNCE_PROVIDER_EVENT,
@@ -1027,17 +1063,10 @@ function subscribeAnnouncedProviders(onProvider, options = {}) {
1027
1063
  const seen = /* @__PURE__ */ new Set();
1028
1064
  const onAnnounce = (event) => {
1029
1065
  const detail = event.detail;
1030
- if (!detail) return;
1031
- const rawId = detail.providerId ?? detail.id;
1032
- if (typeof rawId !== "string" || rawId.length === 0) return;
1033
- if (seen.has(rawId)) return;
1034
- seen.add(rawId);
1035
- const wallet = {
1036
- id: rawId,
1037
- name: typeof detail.name === "string" ? detail.name : void 0,
1038
- icon: typeof detail.icon === "string" ? detail.icon : void 0,
1039
- target: typeof detail.target === "string" ? detail.target : void 0
1040
- };
1066
+ const wallet = readAnnouncedWallet(detail);
1067
+ if (!wallet) return;
1068
+ if (seen.has(wallet.id)) return;
1069
+ seen.add(wallet.id);
1041
1070
  void Promise.resolve().then(() => make(wallet)).then((provider) => {
1042
1071
  if (!isCIP0103Provider(provider)) return;
1043
1072
  onProvider({
@@ -1108,7 +1137,7 @@ async function resolveInjectedKey(d) {
1108
1137
  return { key: d.id, resolved: false };
1109
1138
  }
1110
1139
  async function discoverProviders(options = {}) {
1111
- const injected = discoverInjectedProviders();
1140
+ const injected = discoverInjectedProviders(options.injectionPaths);
1112
1141
  const announcedResults = await discoverAnnouncedProviders(options);
1113
1142
  const injectedKeys = await Promise.all(injected.map(resolveInjectedKey));
1114
1143
  const out = [];