@partylayer/sdk 0.22.0 → 0.22.1

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.
@@ -0,0 +1,16 @@
1
+ import * as _partylayer_core from '@partylayer/core';
2
+
3
+ interface HostedWalletOptions {
4
+ walletUrl: string;
5
+ networkId: string;
6
+ providerId?: string;
7
+ name?: string;
8
+ icon?: string;
9
+ connectPath?: string;
10
+ timeoutMs?: number;
11
+ popupFeatures?: string;
12
+ }
13
+
14
+ declare function createOneSwapHostedAdapter(options: HostedWalletOptions): _partylayer_core.OfficialProviderAdapter;
15
+
16
+ export { createOneSwapHostedAdapter };
@@ -0,0 +1,16 @@
1
+ import * as _partylayer_core from '@partylayer/core';
2
+
3
+ interface HostedWalletOptions {
4
+ walletUrl: string;
5
+ networkId: string;
6
+ providerId?: string;
7
+ name?: string;
8
+ icon?: string;
9
+ connectPath?: string;
10
+ timeoutMs?: number;
11
+ popupFeatures?: string;
12
+ }
13
+
14
+ declare function createOneSwapHostedAdapter(options: HostedWalletOptions): _partylayer_core.OfficialProviderAdapter;
15
+
16
+ export { createOneSwapHostedAdapter };
@@ -0,0 +1,337 @@
1
+ 'use strict';
2
+
3
+ // src/hosted-popup.ts
4
+ function hostedRpcError(code, message, data) {
5
+ return Object.assign(new Error(message), { code, ...data === void 0 ? {} : { data } });
6
+ }
7
+ var HostedPopupChannel = class {
8
+ constructor(options) {
9
+ this.options = options;
10
+ const base = new URL(options.walletUrl);
11
+ if (base.username || base.password || base.hash || base.search || base.origin !== options.walletUrl || !["https:", "http:"].includes(base.protocol)) throw new Error("Hosted wallet URL must be an exact HTTP(S) origin");
12
+ if (!options.connectPath.startsWith("/") || options.connectPath.startsWith("//")) throw new Error("Hosted wallet path must begin with a single /");
13
+ this.origin = base.origin;
14
+ this.url = new URL(options.connectPath, base).href;
15
+ if (new URL(this.url).origin !== this.origin) throw new Error("Hosted wallet path must remain on the wallet origin");
16
+ }
17
+ origin;
18
+ url;
19
+ popup = null;
20
+ listening = false;
21
+ ready = false;
22
+ handshake = null;
23
+ pending = /* @__PURE__ */ new Map();
24
+ channelId;
25
+ nextId = 1;
26
+ revision = 0;
27
+ closedTimer;
28
+ get isOpen() {
29
+ return !!this.popup && !this.popup.closed && this.ready;
30
+ }
31
+ /** This method reaches window.open synchronously, before its first await. */
32
+ async request(method, params) {
33
+ const opened = this.open();
34
+ const revision = this.revision;
35
+ await opened;
36
+ const popup = this.popup;
37
+ if (!popup || popup.closed || !this.ready || revision !== this.revision) throw hostedRpcError(4900, "Hosted wallet connection closed");
38
+ try {
39
+ popup.focus();
40
+ } catch {
41
+ }
42
+ const id = `${this.identity()}:${this.nextId++}`;
43
+ return new Promise((resolve, reject) => {
44
+ const timer = setTimeout(() => {
45
+ this.pending.delete(id);
46
+ this.stopClosedMonitorIfIdle();
47
+ reject(hostedRpcError(4900, "Hosted wallet request timed out"));
48
+ }, this.options.timeoutMs);
49
+ this.pending.set(id, { resolve, reject, timer });
50
+ this.monitorClosed();
51
+ try {
52
+ popup.postMessage({ id, method, ...params === void 0 ? {} : { params } }, this.origin);
53
+ } catch (error) {
54
+ this.pending.delete(id);
55
+ clearTimeout(timer);
56
+ this.stopClosedMonitorIfIdle();
57
+ reject(error);
58
+ }
59
+ });
60
+ }
61
+ close() {
62
+ ++this.revision;
63
+ this.ready = false;
64
+ const popup = this.popup;
65
+ this.popup = null;
66
+ if (this.listening && typeof window !== "undefined") window.removeEventListener("message", this.receive);
67
+ this.listening = false;
68
+ this.finishHandshake(hostedRpcError(4900, "Hosted wallet connection closed"));
69
+ for (const request of this.pending.values()) {
70
+ clearTimeout(request.timer);
71
+ request.reject(hostedRpcError(4900, "Hosted wallet connection closed"));
72
+ }
73
+ this.pending.clear();
74
+ this.stopClosedMonitorIfIdle();
75
+ try {
76
+ popup?.close();
77
+ } catch {
78
+ }
79
+ }
80
+ open() {
81
+ if (typeof window === "undefined") return Promise.reject(hostedRpcError(4100, "Hosted wallet requires a browser"));
82
+ if (this.isOpen) return Promise.resolve();
83
+ if (this.handshake && this.popup && !this.popup.closed) return this.handshake.promise;
84
+ if (this.popup || this.handshake) this.close();
85
+ if (!this.listening) {
86
+ window.addEventListener("message", this.receive);
87
+ this.listening = true;
88
+ }
89
+ let resolve;
90
+ let reject;
91
+ const promise = new Promise((yes, no) => {
92
+ resolve = yes;
93
+ reject = no;
94
+ });
95
+ const timer = setTimeout(() => {
96
+ this.finishHandshake(hostedRpcError(4100, "Hosted wallet did not become ready"));
97
+ this.close();
98
+ }, this.options.timeoutMs);
99
+ this.handshake = { promise, resolve, reject, timer };
100
+ try {
101
+ this.popup = window.open(this.url, `${this.options.popupName}-${this.identity()}`, this.options.popupFeatures);
102
+ } catch (error) {
103
+ this.finishHandshake(error);
104
+ this.close();
105
+ return promise;
106
+ }
107
+ if (!this.popup) {
108
+ this.finishHandshake(hostedRpcError(4100, "Hosted wallet popup was blocked"));
109
+ this.close();
110
+ } else this.monitorClosed();
111
+ return promise;
112
+ }
113
+ receive = (event) => {
114
+ if (!this.popup || event.source !== this.popup || event.origin !== this.origin || !event.data || typeof event.data !== "object") return;
115
+ const message = event.data;
116
+ if (this.handshake && message.type === this.options.readyType) {
117
+ this.ready = true;
118
+ this.finishHandshake();
119
+ return;
120
+ }
121
+ if (typeof message.id !== "string") return;
122
+ const request = this.pending.get(message.id);
123
+ if (!request) return;
124
+ if (message.error !== void 0 && message.error !== null) {
125
+ const error = message.error;
126
+ if (!error || typeof error !== "object" || typeof error.code !== "number" || !Number.isInteger(error.code) || typeof error.message !== "string") return;
127
+ this.pending.delete(message.id);
128
+ clearTimeout(request.timer);
129
+ const rpc = error;
130
+ request.reject(hostedRpcError(rpc.code, rpc.message, rpc.data));
131
+ } else {
132
+ this.pending.delete(message.id);
133
+ clearTimeout(request.timer);
134
+ request.resolve(message.result);
135
+ }
136
+ this.stopClosedMonitorIfIdle();
137
+ };
138
+ identity() {
139
+ if (!this.channelId) {
140
+ const words = globalThis.crypto.getRandomValues(new Uint32Array(4));
141
+ this.channelId = Array.from(words, (word) => word.toString(16).padStart(8, "0")).join("");
142
+ }
143
+ return this.channelId;
144
+ }
145
+ finishHandshake(error) {
146
+ const handshake = this.handshake;
147
+ if (!handshake) return;
148
+ this.handshake = null;
149
+ clearTimeout(handshake.timer);
150
+ if (error !== void 0) handshake.reject(error);
151
+ else handshake.resolve();
152
+ this.stopClosedMonitorIfIdle();
153
+ }
154
+ monitorClosed() {
155
+ if (this.closedTimer !== void 0) return;
156
+ this.closedTimer = setInterval(() => {
157
+ if (this.popup?.closed) this.close();
158
+ }, 100);
159
+ }
160
+ stopClosedMonitorIfIdle() {
161
+ if (this.handshake || this.pending.size) return;
162
+ if (this.closedTimer !== void 0) clearInterval(this.closedTimer);
163
+ this.closedTimer = void 0;
164
+ }
165
+ };
166
+
167
+ // src/hosted-wallet.ts
168
+ function createHostedWalletAdapter(profile2, options) {
169
+ const providerId = options.providerId ?? profile2.providerId;
170
+ const timeoutMs = Math.max(5e3, options.timeoutMs ?? 6e4);
171
+ if (!Number.isFinite(timeoutMs)) throw new Error("Hosted wallet timeout must be finite");
172
+ const channel = new HostedPopupChannel({
173
+ walletUrl: options.walletUrl,
174
+ connectPath: options.connectPath ?? profile2.connectPath,
175
+ timeoutMs,
176
+ popupName: profile2.popupName,
177
+ readyType: profile2.readyType,
178
+ popupFeatures: options.popupFeatures ?? profile2.popupFeatures
179
+ });
180
+ const listeners = /* @__PURE__ */ new Map();
181
+ let account = null;
182
+ let revision = 0;
183
+ const status = () => ({
184
+ connection: { isConnected: account !== null, isNetworkConnected: account !== null },
185
+ provider: { id: providerId, version: profile2.version, providerType: "remote" },
186
+ network: { networkId: options.networkId }
187
+ });
188
+ const changed = () => {
189
+ provider.emit("statusChanged", status());
190
+ provider.emit("accountsChanged", account ? [account] : []);
191
+ };
192
+ const clear = (notifyDisconnected = false) => {
193
+ ++revision;
194
+ if (!account && !notifyDisconnected) return;
195
+ account = null;
196
+ provider.emit("disconnected");
197
+ changed();
198
+ };
199
+ const requireAccount = () => {
200
+ if (!account) throw hostedRpcError(4100, "No active hosted wallet connection");
201
+ return account;
202
+ };
203
+ const paramsObject = (value) => {
204
+ if (value === void 0) return {};
205
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw hostedRpcError(-32602, "Method parameters must be an object");
206
+ return value;
207
+ };
208
+ const provider = {
209
+ request: async (args) => {
210
+ try {
211
+ if (!args || typeof args !== "object" || Array.isArray(args) || typeof args.method !== "string") throw hostedRpcError(-32600, "Request must have a string method");
212
+ const params = paramsObject(args.params);
213
+ let result;
214
+ switch (args.method) {
215
+ case "connect": {
216
+ const captured = revision;
217
+ const connected = await channel.request(profile2.methods.connect, {
218
+ appName: typeof params.appName === "string" ? params.appName : "Canton application",
219
+ network: options.networkId,
220
+ ...typeof params.requestId === "string" || typeof params.requestId === "number" ? { requestId: params.requestId } : {},
221
+ origin: window.location.origin
222
+ });
223
+ if (captured !== revision) throw hostedRpcError(4900, "Hosted wallet connection was cancelled");
224
+ account = profile2.account(connected, options.networkId);
225
+ provider.emit("connected", account);
226
+ changed();
227
+ result = { isConnected: true, isNetworkConnected: true };
228
+ break;
229
+ }
230
+ case "disconnect":
231
+ try {
232
+ if (account && channel.isOpen) await channel.request(profile2.methods.disconnect);
233
+ } finally {
234
+ channel.close();
235
+ clear(true);
236
+ }
237
+ break;
238
+ case "isConnected":
239
+ result = account !== null;
240
+ break;
241
+ case "status":
242
+ result = status();
243
+ break;
244
+ case "listAccounts":
245
+ result = [requireAccount()];
246
+ break;
247
+ case "getPrimaryAccount":
248
+ result = requireAccount();
249
+ break;
250
+ case "getActiveNetwork":
251
+ requireAccount();
252
+ result = { networkId: options.networkId };
253
+ break;
254
+ case "signMessage":
255
+ requireAccount();
256
+ if (typeof params.message !== "string" || !params.message) throw hostedRpcError(-32602, "message must be a non-empty UTF-8 string");
257
+ result = await channel.request(profile2.methods.signMessage, { message: params.message });
258
+ break;
259
+ case "prepareExecute":
260
+ requireAccount();
261
+ if (!Array.isArray(params.commands) || params.commands.length === 0) throw hostedRpcError(-32602, "commands must be a non-empty array");
262
+ result = await channel.request(profile2.methods.prepareExecute, { commands: params.commands });
263
+ break;
264
+ default:
265
+ throw hostedRpcError(4200, `Unsupported CIP-0103 method: ${args.method}`);
266
+ }
267
+ return result;
268
+ } catch (error) {
269
+ if (error && typeof error === "object" && typeof error.code === "number") throw error;
270
+ throw hostedRpcError(-32603, error instanceof Error ? error.message : "Hosted wallet request failed");
271
+ }
272
+ },
273
+ on(event, listener) {
274
+ const set = listeners.get(event) ?? /* @__PURE__ */ new Set();
275
+ set.add(listener);
276
+ listeners.set(event, set);
277
+ return provider;
278
+ },
279
+ emit(event, ...args) {
280
+ const set = listeners.get(event);
281
+ if (!set?.size) return false;
282
+ for (const listener of set) listener(...args);
283
+ return true;
284
+ },
285
+ removeListener(event, listener) {
286
+ listeners.get(event)?.delete(listener);
287
+ return provider;
288
+ }
289
+ };
290
+ return {
291
+ providerId,
292
+ name: options.name ?? profile2.name,
293
+ type: "remote",
294
+ icon: options.icon,
295
+ detect: async () => typeof window !== "undefined",
296
+ provider: () => provider,
297
+ restore: async () => null,
298
+ teardown: () => {
299
+ channel.close();
300
+ clear();
301
+ }
302
+ };
303
+ }
304
+
305
+ // src/hosted-wallet-profiles.ts
306
+ var profile = {
307
+ providerId: "oneswap-v2",
308
+ name: "OneSwap V2 Wallet",
309
+ version: "0.1.0",
310
+ popupName: "oneswap-cip0103",
311
+ readyType: "oneswap:cip0103:ready",
312
+ connectPath: "/connect",
313
+ popupFeatures: "popup=yes,width=520,height=760,resizable=yes,scrollbars=yes",
314
+ methods: { connect: "canton_connect", disconnect: "canton_disconnect", signMessage: "canton_signMessage", prepareExecute: "canton_prepareSignExecute" },
315
+ account(result, networkId) {
316
+ const raw = result;
317
+ const primary = raw?.primaryAccount;
318
+ if (typeof primary?.partyId !== "string" || !primary.partyId.trim()) throw hostedRpcError(-32603, "Hosted wallet returned no primary party");
319
+ return {
320
+ primary: true,
321
+ partyId: primary.partyId,
322
+ status: "allocated",
323
+ hint: "OneSwap V2 wallet",
324
+ publicKey: typeof primary.publicKey === "string" ? primary.publicKey : "",
325
+ namespace: "oneswap",
326
+ networkId,
327
+ signingProviderId: "oneswap-v2"
328
+ };
329
+ }
330
+ };
331
+ function createOneSwapHostedAdapter(options) {
332
+ return createHostedWalletAdapter(profile, options);
333
+ }
334
+
335
+ exports.createOneSwapHostedAdapter = createOneSwapHostedAdapter;
336
+ //# sourceMappingURL=hosted-wallet-profiles.js.map
337
+ //# sourceMappingURL=hosted-wallet-profiles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/hosted-popup.ts","../../src/hosted-wallet.ts","../../src/hosted-wallet-profiles.ts"],"names":["profile"],"mappings":";;;AAWO,SAAS,cAAA,CAAe,IAAA,EAAc,OAAA,EAAiB,IAAA,EAA0D;AACtH,EAAA,OAAO,OAAO,MAAA,CAAO,IAAI,KAAA,CAAM,OAAO,GAAG,EAAE,IAAA,EAAM,GAAI,IAAA,KAAS,SAAY,EAAC,GAAI,EAAE,IAAA,IAAS,CAAA;AAC5F;AAKO,IAAM,qBAAN,MAAyB;AAAA,EAa9B,YAA6B,OAAA,EAA6B;AAA7B,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AAC3B,IAAA,MAAM,IAAA,GAAO,IAAI,GAAA,CAAI,OAAA,CAAQ,SAAS,CAAA;AACtC,IAAA,IAAI,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,QAAA,IAAY,IAAA,CAAK,QAAQ,IAAA,CAAK,MAAA,IAAU,IAAA,CAAK,MAAA,KAAW,OAAA,CAAQ,SAAA,IACxF,CAAC,CAAC,QAAA,EAAU,OAAO,CAAA,CAAE,QAAA,CAAS,IAAA,CAAK,QAAQ,CAAA,EAAG,MAAM,IAAI,KAAA,CAAM,mDAAmD,CAAA;AACnH,IAAA,IAAI,CAAC,OAAA,CAAQ,WAAA,CAAY,UAAA,CAAW,GAAG,CAAA,IAAK,OAAA,CA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,EAAmB;AAAA,KAAa;AAAA,EAC/C;AACF,CAAA;AAEO,SAAS,2BAA2B,OAAA,EAA8B;AACvE,EAAA,OAAO,yBAAA,CAA0B,SAAS,OAAO,CAAA;AACnD","file":"hosted-wallet-profiles.js","sourcesContent":["/** Persistent, origin-bound hosted RPC channel. Wallet wire names are profile data. */\nexport interface HostedPopupOptions {\n walletUrl: string;\n connectPath: string;\n /** Namespace prefix; each channel owns a distinct nonce-suffixed browser target. */\n popupName: string;\n readyType: string;\n timeoutMs: number;\n popupFeatures: string;\n}\n\nexport function hostedRpcError(code: number, message: string, data?: unknown): Error & { code: number; data?: unknown } {\n return Object.assign(new Error(message), { code, ...(data === undefined ? {} : { data }) });\n}\n\ntype Pending = { resolve(value: unknown): void; reject(error: unknown): void; timer: ReturnType<typeof setTimeout> };\ntype Handshake = { promise: Promise<void>; resolve(): void; reject(error: unknown): void; timer: ReturnType<typeof setTimeout> };\n\nexport class HostedPopupChannel {\n private readonly origin: string;\n private readonly url: string;\n private popup: Window | null = null;\n private listening = false;\n private ready = false;\n private handshake: Handshake | null = null;\n private pending = new Map<string, Pending>();\n private channelId: string | undefined;\n private nextId = 1;\n private revision = 0;\n private closedTimer: ReturnType<typeof setInterval> | undefined;\n\n constructor(private readonly options: HostedPopupOptions) {\n const base = new URL(options.walletUrl);\n if (base.username || base.password || base.hash || base.search || base.origin !== options.walletUrl ||\n !['https:', 'http:'].includes(base.protocol)) throw new Error('Hosted wallet URL must be an exact HTTP(S) origin');\n if (!options.connectPath.startsWith('/') || options.connectPath.startsWith('//')) throw new Error('Hosted wallet path must begin with a single /');\n this.origin = base.origin;\n this.url = new URL(options.connectPath, base).href;\n if (new URL(this.url).origin !== this.origin) throw new Error('Hosted wallet path must remain on the wallet origin');\n }\n\n get isOpen(): boolean { return !!this.popup && !this.popup.closed && this.ready; }\n\n /** This method reaches window.open synchronously, before its first await. */\n async request(method: string, params?: Record<string, unknown>): Promise<unknown> {\n const opened = this.open();\n const revision = this.revision;\n await opened;\n const popup = this.popup;\n if (!popup || popup.closed || !this.ready || revision !== this.revision) throw hostedRpcError(4900, 'Hosted wallet connection closed');\n try { popup.focus(); } catch { /* Browser focus is best effort. */ }\n const id = `${this.identity()}:${this.nextId++}`;\n return new Promise((resolve, reject) => {\n const timer = setTimeout(() => {\n this.pending.delete(id);\n this.stopClosedMonitorIfIdle();\n reject(hostedRpcError(4900, 'Hosted wallet request timed out'));\n }, this.options.timeoutMs);\n this.pending.set(id, { resolve, reject, timer });\n this.monitorClosed();\n try { popup.postMessage({ id, method, ...(params === undefined ? {} : { params }) }, this.origin); }\n catch (error) {\n this.pending.delete(id);\n clearTimeout(timer);\n this.stopClosedMonitorIfIdle();\n reject(error);\n }\n });\n }\n\n close(): void {\n ++this.revision;\n this.ready = false;\n const popup = this.popup;\n this.popup = null;\n if (this.listening && typeof window !== 'undefined') window.removeEventListener('message', this.receive);\n this.listening = false;\n this.finishHandshake(hostedRpcError(4900, 'Hosted wallet connection closed'));\n for (const request of this.pending.values()) {\n clearTimeout(request.timer);\n request.reject(hostedRpcError(4900, 'Hosted wallet connection closed'));\n }\n this.pending.clear();\n this.stopClosedMonitorIfIdle();\n try { popup?.close(); } catch { /* Cleanup must still reject every waiter. */ }\n }\n\n private open(): Promise<void> {\n if (typeof window === 'undefined') return Promise.reject(hostedRpcError(4100, 'Hosted wallet requires a browser'));\n if (this.isOpen) return Promise.resolve();\n if (this.handshake && this.popup && !this.popup.closed) return this.handshake.promise;\n // An old window cannot retain pending requests when a later call reopens it.\n if (this.popup || this.handshake) this.close();\n if (!this.listening) { window.addEventListener('message', this.receive); this.listening = true; }\n let resolve!: () => void;\n let reject!: (error: unknown) => void;\n const promise = new Promise<void>((yes, no) => { resolve = yes; reject = no; });\n const timer = setTimeout(() => {\n this.finishHandshake(hostedRpcError(4100, 'Hosted wallet did not become ready'));\n this.close();\n }, this.options.timeoutMs);\n this.handshake = { promise, resolve, reject, timer };\n try { this.popup = window.open(this.url, `${this.options.popupName}-${this.identity()}`, this.options.popupFeatures); }\n catch (error) { this.finishHandshake(error); this.close(); return promise; }\n if (!this.popup) {\n this.finishHandshake(hostedRpcError(4100, 'Hosted wallet popup was blocked'));\n this.close();\n } else this.monitorClosed();\n return promise;\n }\n\n private readonly receive = (event: MessageEvent): void => {\n if (!this.popup || event.source !== this.popup || event.origin !== this.origin || !event.data || typeof event.data !== 'object') return;\n const message = event.data as Record<string, unknown>;\n if (this.handshake && message.type === this.options.readyType) {\n this.ready = true;\n this.finishHandshake();\n return;\n }\n // The channel nonce prevents cross-instance replies even if a browser target is reused.\n if (typeof message.id !== 'string') return;\n const request = this.pending.get(message.id);\n if (!request) return;\n if (message.error !== undefined && message.error !== null) {\n const error = message.error;\n if (!error || typeof error !== 'object' || typeof (error as { code?: unknown }).code !== 'number' ||\n !Number.isInteger((error as { code: number }).code) || typeof (error as { message?: unknown }).message !== 'string') return;\n this.pending.delete(message.id);\n clearTimeout(request.timer);\n const rpc = error as { code: number; message: string; data?: unknown };\n request.reject(hostedRpcError(rpc.code, rpc.message, rpc.data));\n } else {\n this.pending.delete(message.id);\n clearTimeout(request.timer);\n request.resolve(message.result);\n }\n this.stopClosedMonitorIfIdle();\n };\n\n private identity(): string {\n if (!this.channelId) {\n // Created only when opening, so constructing a provider remains SSR safe.\n const words = globalThis.crypto.getRandomValues(new Uint32Array(4));\n this.channelId = Array.from(words, word => word.toString(16).padStart(8, '0')).join('');\n }\n return this.channelId;\n }\n\n private finishHandshake(error?: unknown): void {\n const handshake = this.handshake;\n if (!handshake) return;\n this.handshake = null;\n clearTimeout(handshake.timer);\n if (error !== undefined) handshake.reject(error); else handshake.resolve();\n this.stopClosedMonitorIfIdle();\n }\n\n private monitorClosed(): void {\n if (this.closedTimer !== undefined) return;\n this.closedTimer = setInterval(() => { if (this.popup?.closed) this.close(); }, 100);\n }\n\n private stopClosedMonitorIfIdle(): void {\n if (this.handshake || this.pending.size) return;\n if (this.closedTimer !== undefined) clearInterval(this.closedTimer);\n this.closedTimer = undefined;\n }\n}\n","import type { CIP0103Account, CIP0103Provider, OfficialProviderAdapter } from '@partylayer/core';\nimport { HostedPopupChannel, hostedRpcError } from './hosted-popup';\n\nexport interface HostedWalletProfile {\n providerId: string;\n name: string;\n version: string;\n popupName: string;\n readyType: string;\n connectPath: string;\n popupFeatures: string;\n methods: { connect: string; disconnect: string; signMessage: string; prepareExecute: string };\n account(result: unknown, networkId: string): CIP0103Account;\n}\n\nexport interface HostedWalletOptions {\n walletUrl: string;\n networkId: string;\n providerId?: string;\n name?: string;\n icon?: string;\n connectPath?: string;\n timeoutMs?: number;\n popupFeatures?: string;\n}\n\n/**\n * Internal ProviderAdapter. Discovery/native ownership stays with the SDK owner.\n * Account/status are the last wallet-approved identity, not a remote freshness\n * check. Closing an idle UI window does not establish server logout; the next\n * explicit request can reopen it. Only an actual connect reply changes identity.\n * Disconnect/teardown clear it. A lost write reply never triggers replay.\n */\nexport function createHostedWalletAdapter(profile: HostedWalletProfile, options: HostedWalletOptions): OfficialProviderAdapter {\n const providerId = options.providerId ?? profile.providerId;\n const timeoutMs = Math.max(5_000, options.timeoutMs ?? 60_000);\n if (!Number.isFinite(timeoutMs)) throw new Error('Hosted wallet timeout must be finite');\n const channel = new HostedPopupChannel({ walletUrl: options.walletUrl, connectPath: options.connectPath ?? profile.connectPath,\n timeoutMs, popupName: profile.popupName, readyType: profile.readyType, popupFeatures: options.popupFeatures ?? profile.popupFeatures });\n const listeners = new Map<string, Set<(...args: unknown[]) => void>>();\n let account: CIP0103Account | null = null;\n let revision = 0;\n const status = () => ({ connection: { isConnected: account !== null, isNetworkConnected: account !== null },\n provider: { id: providerId, version: profile.version, providerType: 'remote' }, network: { networkId: options.networkId } });\n const changed = () => { provider.emit('statusChanged', status()); provider.emit('accountsChanged', account ? [account] : []); };\n const clear = (notifyDisconnected = false) => {\n ++revision;\n if (!account && !notifyDisconnected) return;\n account = null;\n provider.emit('disconnected');\n changed();\n };\n const requireAccount = () => { if (!account) throw hostedRpcError(4100, 'No active hosted wallet connection'); return account; };\n const paramsObject = (value: unknown): Record<string, unknown> => {\n if (value === undefined) return {};\n if (!value || typeof value !== 'object' || Array.isArray(value)) throw hostedRpcError(-32602, 'Method parameters must be an object');\n return value as Record<string, unknown>;\n };\n const provider: CIP0103Provider = {\n request: async <T>(args: Parameters<CIP0103Provider['request']>[0]): Promise<T> => {\n try {\n if (!args || typeof args !== 'object' || Array.isArray(args) || typeof args.method !== 'string') throw hostedRpcError(-32600, 'Request must have a string method');\n const params = paramsObject(args.params);\n let result: unknown;\n switch (args.method) {\n case 'connect': {\n const captured = revision;\n const connected = await channel.request(profile.methods.connect, {\n appName: typeof params.appName === 'string' ? params.appName : 'Canton application',\n network: options.networkId,\n ...(typeof params.requestId === 'string' || typeof params.requestId === 'number' ? { requestId: params.requestId } : {}),\n origin: window.location.origin,\n });\n if (captured !== revision) throw hostedRpcError(4900, 'Hosted wallet connection was cancelled');\n account = profile.account(connected, options.networkId);\n provider.emit('connected', account);\n changed();\n result = { isConnected: true, isNetworkConnected: true };\n break;\n }\n case 'disconnect':\n try { if (account && channel.isOpen) await channel.request(profile.methods.disconnect); }\n finally { channel.close(); clear(true); }\n break;\n case 'isConnected': result = account !== null; break;\n case 'status': result = status(); break;\n case 'listAccounts': result = [requireAccount()]; break;\n case 'getPrimaryAccount': result = requireAccount(); break;\n case 'getActiveNetwork': requireAccount(); result = { networkId: options.networkId }; break;\n case 'signMessage':\n requireAccount();\n if (typeof params.message !== 'string' || !params.message) throw hostedRpcError(-32602, 'message must be a non-empty UTF-8 string');\n result = await channel.request(profile.methods.signMessage, { message: params.message });\n break;\n case 'prepareExecute':\n requireAccount();\n if (!Array.isArray(params.commands) || params.commands.length === 0) throw hostedRpcError(-32602, 'commands must be a non-empty array');\n result = await channel.request(profile.methods.prepareExecute, { commands: params.commands });\n break;\n default: throw hostedRpcError(4200, `Unsupported CIP-0103 method: ${args.method}`);\n }\n return result as T;\n } catch (error) {\n if (error && typeof error === 'object' && typeof (error as { code?: unknown }).code === 'number') throw error;\n throw hostedRpcError(-32603, error instanceof Error ? error.message : 'Hosted wallet request failed');\n }\n },\n on(event, listener) {\n const set = listeners.get(event) ?? new Set();\n set.add(listener as (...args: unknown[]) => void);\n listeners.set(event, set);\n return provider;\n },\n emit(event, ...args) {\n const set = listeners.get(event);\n if (!set?.size) return false;\n for (const listener of set) listener(...args);\n return true;\n },\n removeListener(event, listener) { listeners.get(event)?.delete(listener as (...args: unknown[]) => void); return provider; },\n };\n return { providerId, name: options.name ?? profile.name, type: 'remote', icon: options.icon,\n detect: async () => typeof window !== 'undefined', provider: () => provider,\n restore: async () => null, teardown: () => { channel.close(); clear(); } };\n}\n","import type { CIP0103Account } from '@partylayer/core';\nimport { createHostedWalletAdapter, type HostedWalletOptions, type HostedWalletProfile } from './hosted-wallet';\nimport { hostedRpcError } from './hosted-popup';\n\n/**\n * Documented OneSwap hosted protocol, independently implemented (no vendor code).\n * https://www.npmjs.com/package/@oneswap/wallet-cip0103-adapter\n * See Low-level popup client, provider methods, options, and popup security model.\n * The published 0.2.0 package is a dev-only blackbox interoperability oracle.\n */\nconst profile: HostedWalletProfile = {\n providerId: 'oneswap-v2', name: 'OneSwap V2 Wallet', version: '0.1.0',\n popupName: 'oneswap-cip0103', readyType: 'oneswap:cip0103:ready', connectPath: '/connect',\n popupFeatures: 'popup=yes,width=520,height=760,resizable=yes,scrollbars=yes',\n methods: { connect: 'canton_connect', disconnect: 'canton_disconnect', signMessage: 'canton_signMessage', prepareExecute: 'canton_prepareSignExecute' },\n account(result, networkId): CIP0103Account {\n const raw = result as { primaryAccount?: { partyId?: unknown; publicKey?: unknown } } | null;\n const primary = raw?.primaryAccount;\n if (typeof primary?.partyId !== 'string' || !primary.partyId.trim()) throw hostedRpcError(-32603, 'Hosted wallet returned no primary party');\n return { primary: true, partyId: primary.partyId, status: 'allocated', hint: 'OneSwap V2 wallet',\n publicKey: typeof primary.publicKey === 'string' ? primary.publicKey : '', namespace: 'oneswap',\n networkId, signingProviderId: 'oneswap-v2' };\n },\n};\n\nexport function createOneSwapHostedAdapter(options: HostedWalletOptions) {\n return createHostedWalletAdapter(profile, options);\n}\n"]}