@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 +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +48 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
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.
|
|
516
|
+
var PROVIDER_VERSION = "0.5.2" ;
|
|
517
517
|
function createProviderBridge(client) {
|
|
518
518
|
const eventBus = new CIP0103EventBus();
|
|
519
519
|
const pendingEmitted = /* @__PURE__ */ new Set();
|
|
@@ -904,12 +904,13 @@ function isCIP0103Provider(obj) {
|
|
|
904
904
|
const p = obj;
|
|
905
905
|
return typeof p.request === "function" && typeof p.on === "function" && typeof p.emit === "function" && typeof p.removeListener === "function";
|
|
906
906
|
}
|
|
907
|
-
function discoverInjectedProviders() {
|
|
907
|
+
function discoverInjectedProviders(extraPaths) {
|
|
908
908
|
if (typeof window === "undefined") return [];
|
|
909
909
|
const discovered = [];
|
|
910
910
|
const seen = /* @__PURE__ */ new Set();
|
|
911
911
|
const win = window;
|
|
912
|
-
|
|
912
|
+
const paths = extraPaths && extraPaths.length > 0 ? [.../* @__PURE__ */ new Set([...KNOWN_INJECTION_PATHS, ...extraPaths])] : KNOWN_INJECTION_PATHS;
|
|
913
|
+
for (const path of paths) {
|
|
913
914
|
const candidate = win[path];
|
|
914
915
|
if (candidate === void 0 || candidate === null) continue;
|
|
915
916
|
if (isCIP0103Provider(candidate) && !seen.has(candidate)) {
|
|
@@ -970,6 +971,41 @@ var CANTON_ANNOUNCE_PROVIDER_EVENT = "canton:announceProvider";
|
|
|
970
971
|
function defaultAnnounceProvider(announced) {
|
|
971
972
|
return createExtensionChannelProvider({ target: announced.target ?? announced.id });
|
|
972
973
|
}
|
|
974
|
+
function firstNonEmptyString(...vals) {
|
|
975
|
+
for (const v of vals) {
|
|
976
|
+
if (typeof v === "string" && v.length > 0) return v;
|
|
977
|
+
}
|
|
978
|
+
return void 0;
|
|
979
|
+
}
|
|
980
|
+
var warnedAnnounceShapes = /* @__PURE__ */ new Set();
|
|
981
|
+
function announceShapeKey(detail, info) {
|
|
982
|
+
const top = Object.keys(detail).sort().join(",");
|
|
983
|
+
const inner = info ? Object.keys(info).sort().join(",") : "";
|
|
984
|
+
return `${top}|${inner}`;
|
|
985
|
+
}
|
|
986
|
+
function readAnnouncedWallet(detail) {
|
|
987
|
+
if (!detail) return void 0;
|
|
988
|
+
const info = typeof detail.info === "object" && detail.info !== null ? detail.info : void 0;
|
|
989
|
+
const id = firstNonEmptyString(detail.providerId, detail.id, info?.uuid, info?.rdns);
|
|
990
|
+
if (id === void 0) {
|
|
991
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
992
|
+
const key = announceShapeKey(detail, info);
|
|
993
|
+
if (!warnedAnnounceShapes.has(key)) {
|
|
994
|
+
warnedAnnounceShapes.add(key);
|
|
995
|
+
console.warn(
|
|
996
|
+
"[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"
|
|
997
|
+
);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
return void 0;
|
|
1001
|
+
}
|
|
1002
|
+
return {
|
|
1003
|
+
id,
|
|
1004
|
+
name: firstNonEmptyString(detail.name, info?.name),
|
|
1005
|
+
icon: firstNonEmptyString(detail.icon, info?.icon),
|
|
1006
|
+
target: firstNonEmptyString(detail.target)
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
973
1009
|
async function discoverAnnouncedProviders(options = {}) {
|
|
974
1010
|
if (typeof window === "undefined") return [];
|
|
975
1011
|
const timeoutMs = options.timeoutMs ?? 300;
|
|
@@ -977,16 +1013,10 @@ async function discoverAnnouncedProviders(options = {}) {
|
|
|
977
1013
|
const announced = /* @__PURE__ */ new Map();
|
|
978
1014
|
const onAnnounce = (event) => {
|
|
979
1015
|
const detail = event.detail;
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
if (
|
|
983
|
-
|
|
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
|
-
});
|
|
1016
|
+
const wallet = readAnnouncedWallet(detail);
|
|
1017
|
+
if (!wallet) return;
|
|
1018
|
+
if (announced.has(wallet.id)) return;
|
|
1019
|
+
announced.set(wallet.id, wallet);
|
|
990
1020
|
};
|
|
991
1021
|
window.addEventListener(
|
|
992
1022
|
CANTON_ANNOUNCE_PROVIDER_EVENT,
|
|
@@ -1027,17 +1057,10 @@ function subscribeAnnouncedProviders(onProvider, options = {}) {
|
|
|
1027
1057
|
const seen = /* @__PURE__ */ new Set();
|
|
1028
1058
|
const onAnnounce = (event) => {
|
|
1029
1059
|
const detail = event.detail;
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
if (
|
|
1033
|
-
|
|
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
|
-
};
|
|
1060
|
+
const wallet = readAnnouncedWallet(detail);
|
|
1061
|
+
if (!wallet) return;
|
|
1062
|
+
if (seen.has(wallet.id)) return;
|
|
1063
|
+
seen.add(wallet.id);
|
|
1041
1064
|
void Promise.resolve().then(() => make(wallet)).then((provider) => {
|
|
1042
1065
|
if (!isCIP0103Provider(provider)) return;
|
|
1043
1066
|
onProvider({
|
|
@@ -1108,7 +1131,7 @@ async function resolveInjectedKey(d) {
|
|
|
1108
1131
|
return { key: d.id, resolved: false };
|
|
1109
1132
|
}
|
|
1110
1133
|
async function discoverProviders(options = {}) {
|
|
1111
|
-
const injected = discoverInjectedProviders();
|
|
1134
|
+
const injected = discoverInjectedProviders(options.injectionPaths);
|
|
1112
1135
|
const announcedResults = await discoverAnnouncedProviders(options);
|
|
1113
1136
|
const injectedKeys = await Promise.all(injected.map(resolveInjectedKey));
|
|
1114
1137
|
const out = [];
|