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