@swype-org/deposit 0.3.13 → 0.3.15
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/{chunk-7Y4RWJI3.js → chunk-MA7CVDFD.js} +518 -29
- package/dist/chunk-MA7CVDFD.js.map +1 -0
- package/dist/index.cjs +520 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +160 -3
- package/dist/index.d.ts +160 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +515 -26
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +2 -2
- package/dist/{types-CCi4cpnQ.d.cts → types-DYsZwNXq.d.cts} +10 -3
- package/dist/{types-CCi4cpnQ.d.ts → types-DYsZwNXq.d.ts} +10 -3
- package/package.json +2 -2
- package/dist/chunk-7Y4RWJI3.js.map +0 -1
|
@@ -22,6 +22,396 @@ function getDisplayMessage(error) {
|
|
|
22
22
|
return DISPLAY_MESSAGES[error.code] ?? error.message;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// src/walletBridge/discover.ts
|
|
26
|
+
function createWalletDiscoverer() {
|
|
27
|
+
if (typeof window === "undefined") {
|
|
28
|
+
return makeNoopHandle();
|
|
29
|
+
}
|
|
30
|
+
const registry = /* @__PURE__ */ new Map();
|
|
31
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
32
|
+
let destroyed = false;
|
|
33
|
+
const onAnnounce = (event) => {
|
|
34
|
+
if (destroyed) return;
|
|
35
|
+
const detail = event.detail;
|
|
36
|
+
if (!isValidProviderDetail(detail)) {
|
|
37
|
+
console.info("[blink-bridge:parent] dropping malformed EIP-6963 announcement", {
|
|
38
|
+
rawInfo: event.detail && event.detail.info
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const existing = registry.get(detail.info.uuid);
|
|
43
|
+
if (existing && existing.provider === detail.provider) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
console.info("[blink-bridge:parent] EIP-6963 announceProvider", {
|
|
47
|
+
rdns: detail.info.rdns,
|
|
48
|
+
name: detail.info.name,
|
|
49
|
+
uuid: detail.info.uuid
|
|
50
|
+
});
|
|
51
|
+
registry.set(detail.info.uuid, {
|
|
52
|
+
info: { ...detail.info },
|
|
53
|
+
provider: detail.provider
|
|
54
|
+
});
|
|
55
|
+
notify();
|
|
56
|
+
};
|
|
57
|
+
window.addEventListener("eip6963:announceProvider", onAnnounce);
|
|
58
|
+
requestProviders();
|
|
59
|
+
const RESWEEP_INTERVALS_MS = [500, 1500, 3e3, 6e3];
|
|
60
|
+
const reSweepTimers = [];
|
|
61
|
+
for (const ms of RESWEEP_INTERVALS_MS) {
|
|
62
|
+
reSweepTimers.push(
|
|
63
|
+
setTimeout(() => {
|
|
64
|
+
if (!destroyed) requestProviders();
|
|
65
|
+
}, ms)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function requestProviders() {
|
|
69
|
+
try {
|
|
70
|
+
window.dispatchEvent(new Event("eip6963:requestProvider"));
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function notify() {
|
|
75
|
+
const snapshot = list();
|
|
76
|
+
for (const listener of listeners) {
|
|
77
|
+
try {
|
|
78
|
+
listener(snapshot);
|
|
79
|
+
} catch {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function list() {
|
|
84
|
+
return [...registry.values()];
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
list,
|
|
88
|
+
get(uuid) {
|
|
89
|
+
return registry.get(uuid)?.provider;
|
|
90
|
+
},
|
|
91
|
+
subscribe(listener) {
|
|
92
|
+
listeners.add(listener);
|
|
93
|
+
return () => {
|
|
94
|
+
listeners.delete(listener);
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
requestProviders,
|
|
98
|
+
destroy() {
|
|
99
|
+
if (destroyed) return;
|
|
100
|
+
destroyed = true;
|
|
101
|
+
window.removeEventListener("eip6963:announceProvider", onAnnounce);
|
|
102
|
+
for (const t of reSweepTimers) clearTimeout(t);
|
|
103
|
+
registry.clear();
|
|
104
|
+
listeners.clear();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function makeNoopHandle() {
|
|
109
|
+
return {
|
|
110
|
+
list: () => [],
|
|
111
|
+
get: () => void 0,
|
|
112
|
+
subscribe: () => () => {
|
|
113
|
+
},
|
|
114
|
+
requestProviders: () => {
|
|
115
|
+
},
|
|
116
|
+
destroy: () => {
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function isValidProviderDetail(value) {
|
|
121
|
+
if (!value || typeof value !== "object") return false;
|
|
122
|
+
const detail = value;
|
|
123
|
+
const info = detail.info;
|
|
124
|
+
const provider = detail.provider;
|
|
125
|
+
if (!info || !provider) return false;
|
|
126
|
+
if (typeof info.uuid !== "string" || info.uuid.length === 0) return false;
|
|
127
|
+
if (typeof info.name !== "string") return false;
|
|
128
|
+
if (typeof info.rdns !== "string") return false;
|
|
129
|
+
if (typeof provider.request !== "function") return false;
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/walletBridge/protocol.ts
|
|
134
|
+
var BRIDGE_PROTOCOL_VERSION = 1;
|
|
135
|
+
var ALLOWED_RPC_METHODS = /* @__PURE__ */ new Set([
|
|
136
|
+
// Read
|
|
137
|
+
"eth_accounts",
|
|
138
|
+
"eth_blockNumber",
|
|
139
|
+
"eth_call",
|
|
140
|
+
"eth_chainId",
|
|
141
|
+
"eth_estimateGas",
|
|
142
|
+
"eth_gasPrice",
|
|
143
|
+
"eth_getBalance",
|
|
144
|
+
"eth_getCode",
|
|
145
|
+
"eth_getStorageAt",
|
|
146
|
+
"eth_getTransactionByHash",
|
|
147
|
+
"eth_getTransactionCount",
|
|
148
|
+
"eth_getTransactionReceipt",
|
|
149
|
+
"net_version",
|
|
150
|
+
"wallet_getCapabilities",
|
|
151
|
+
"wallet_getCallsStatus",
|
|
152
|
+
// Write / sign
|
|
153
|
+
"eth_requestAccounts",
|
|
154
|
+
"eth_sendTransaction",
|
|
155
|
+
"eth_sendRawTransaction",
|
|
156
|
+
"eth_sign",
|
|
157
|
+
"personal_sign",
|
|
158
|
+
"eth_signTypedData",
|
|
159
|
+
"eth_signTypedData_v3",
|
|
160
|
+
"eth_signTypedData_v4",
|
|
161
|
+
"wallet_addEthereumChain",
|
|
162
|
+
"wallet_switchEthereumChain",
|
|
163
|
+
"wallet_sendCalls",
|
|
164
|
+
"wallet_watchAsset"
|
|
165
|
+
]);
|
|
166
|
+
var FORWARDED_PROVIDER_EVENTS = [
|
|
167
|
+
"accountsChanged",
|
|
168
|
+
"chainChanged",
|
|
169
|
+
"connect",
|
|
170
|
+
"disconnect",
|
|
171
|
+
"message"
|
|
172
|
+
];
|
|
173
|
+
function parseBridgeMessage(data) {
|
|
174
|
+
if (!data || typeof data !== "object") return null;
|
|
175
|
+
const msg = data;
|
|
176
|
+
if (msg.protocolVersion !== BRIDGE_PROTOCOL_VERSION) return null;
|
|
177
|
+
switch (msg.type) {
|
|
178
|
+
case "blink:bridge-hello":
|
|
179
|
+
return msg;
|
|
180
|
+
case "blink:wallets-advertised":
|
|
181
|
+
return Array.isArray(msg.wallets) ? msg : null;
|
|
182
|
+
case "blink:rpc-request":
|
|
183
|
+
if (typeof msg.uuid !== "string" || typeof msg.id !== "string" || typeof msg.method !== "string") {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return msg;
|
|
187
|
+
case "blink:rpc-response":
|
|
188
|
+
if (typeof msg.id !== "string") return null;
|
|
189
|
+
return msg;
|
|
190
|
+
case "blink:rpc-event":
|
|
191
|
+
if (typeof msg.uuid !== "string" || typeof msg.event !== "string" || !Array.isArray(msg.args)) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
return msg;
|
|
195
|
+
case "blink:resolve-by-flag":
|
|
196
|
+
if (typeof msg.id !== "string" || !Array.isArray(msg.flags)) return null;
|
|
197
|
+
if (!msg.flags.every((f) => typeof f === "string" && f.length > 0)) return null;
|
|
198
|
+
return msg;
|
|
199
|
+
case "blink:resolve-by-flag-response":
|
|
200
|
+
if (typeof msg.id !== "string") return null;
|
|
201
|
+
if (msg.match !== null && (typeof msg.match !== "object" || !msg.match)) return null;
|
|
202
|
+
return msg;
|
|
203
|
+
default:
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/walletBridge/rpcHost.ts
|
|
209
|
+
function attachRpcHost(options) {
|
|
210
|
+
const { iframeWindow, iframeOrigin, discoverer } = options;
|
|
211
|
+
const log = options.log ?? noopLog;
|
|
212
|
+
if (typeof window === "undefined") {
|
|
213
|
+
return { detach: () => {
|
|
214
|
+
} };
|
|
215
|
+
}
|
|
216
|
+
let detached = false;
|
|
217
|
+
const subscriptions = /* @__PURE__ */ new Map();
|
|
218
|
+
const unsubscribeFromDiscoverer = discoverer.subscribe((snapshot) => {
|
|
219
|
+
if (detached) return;
|
|
220
|
+
advertiseWallets(snapshot);
|
|
221
|
+
});
|
|
222
|
+
function postToIframe(message) {
|
|
223
|
+
if (detached) return;
|
|
224
|
+
try {
|
|
225
|
+
iframeWindow.postMessage(message, iframeOrigin);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
log("postMessage to iframe failed", {
|
|
228
|
+
error: err instanceof Error ? err.message : String(err)
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function advertiseWallets(snapshot) {
|
|
233
|
+
const wallets = snapshot.map((entry) => ({
|
|
234
|
+
uuid: entry.info.uuid,
|
|
235
|
+
rdns: entry.info.rdns,
|
|
236
|
+
name: entry.info.name,
|
|
237
|
+
icon: entry.info.icon
|
|
238
|
+
}));
|
|
239
|
+
console.info("[blink-bridge:parent] advertising wallets", wallets.map((w) => ({
|
|
240
|
+
rdns: w.rdns,
|
|
241
|
+
name: w.name
|
|
242
|
+
})));
|
|
243
|
+
const message = {
|
|
244
|
+
type: "blink:wallets-advertised",
|
|
245
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
246
|
+
wallets
|
|
247
|
+
};
|
|
248
|
+
postToIframe(message);
|
|
249
|
+
}
|
|
250
|
+
function ensureSubscription(uuid, provider) {
|
|
251
|
+
if (subscriptions.has(uuid)) return;
|
|
252
|
+
if (typeof provider.on !== "function") {
|
|
253
|
+
subscriptions.set(uuid, { provider, listeners: /* @__PURE__ */ new Map() });
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const record = { provider, listeners: /* @__PURE__ */ new Map() };
|
|
257
|
+
for (const event of FORWARDED_PROVIDER_EVENTS) {
|
|
258
|
+
const listener = (...args) => {
|
|
259
|
+
const eventMessage = {
|
|
260
|
+
type: "blink:rpc-event",
|
|
261
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
262
|
+
uuid,
|
|
263
|
+
event,
|
|
264
|
+
args
|
|
265
|
+
};
|
|
266
|
+
postToIframe(eventMessage);
|
|
267
|
+
};
|
|
268
|
+
try {
|
|
269
|
+
provider.on(event, listener);
|
|
270
|
+
record.listeners.set(event, listener);
|
|
271
|
+
} catch (err) {
|
|
272
|
+
log(`provider.on('${event}') threw \u2014 skipping that event`, {
|
|
273
|
+
uuid,
|
|
274
|
+
error: err instanceof Error ? err.message : String(err)
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
subscriptions.set(uuid, record);
|
|
279
|
+
}
|
|
280
|
+
function unsubscribeAll() {
|
|
281
|
+
for (const [, record] of subscriptions) {
|
|
282
|
+
const provider = record.provider;
|
|
283
|
+
if (typeof provider.removeListener !== "function") continue;
|
|
284
|
+
for (const [event, listener] of record.listeners) {
|
|
285
|
+
try {
|
|
286
|
+
provider.removeListener(event, listener);
|
|
287
|
+
} catch {
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
subscriptions.clear();
|
|
292
|
+
}
|
|
293
|
+
function sendError(id, code, message, data) {
|
|
294
|
+
const response = {
|
|
295
|
+
type: "blink:rpc-response",
|
|
296
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
297
|
+
id,
|
|
298
|
+
error: data === void 0 ? { code, message } : { code, message, data }
|
|
299
|
+
};
|
|
300
|
+
postToIframe(response);
|
|
301
|
+
}
|
|
302
|
+
function sendResult(id, result) {
|
|
303
|
+
const response = {
|
|
304
|
+
type: "blink:rpc-response",
|
|
305
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
306
|
+
id,
|
|
307
|
+
result
|
|
308
|
+
};
|
|
309
|
+
postToIframe(response);
|
|
310
|
+
}
|
|
311
|
+
const onMessage = (event) => {
|
|
312
|
+
if (detached) return;
|
|
313
|
+
if (event.source !== iframeWindow) return;
|
|
314
|
+
if (event.origin !== iframeOrigin) return;
|
|
315
|
+
const message = parseBridgeMessage(event.data);
|
|
316
|
+
if (!message) return;
|
|
317
|
+
switch (message.type) {
|
|
318
|
+
case "blink:bridge-hello": {
|
|
319
|
+
advertiseWallets(discoverer.list());
|
|
320
|
+
discoverer.requestProviders();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
case "blink:rpc-request": {
|
|
324
|
+
const { id, uuid, method, params } = message;
|
|
325
|
+
console.info("[blink-bridge:parent] rpc-request", { uuid, method });
|
|
326
|
+
if (!ALLOWED_RPC_METHODS.has(method)) {
|
|
327
|
+
log("rejecting non-allowlisted method", { uuid, method });
|
|
328
|
+
sendError(id, -32601, `Method not allowed: ${method}`);
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
const provider = discoverer.get(uuid);
|
|
332
|
+
if (!provider) {
|
|
333
|
+
log("no provider for uuid", { uuid, method });
|
|
334
|
+
sendError(id, -32602, `Unknown wallet: ${uuid}`);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
ensureSubscription(uuid, provider);
|
|
338
|
+
provider.request({ method, params }).then((result) => {
|
|
339
|
+
console.info("[blink-bridge:parent] rpc-result", { uuid, method, ok: true });
|
|
340
|
+
sendResult(id, result);
|
|
341
|
+
}).catch((err) => {
|
|
342
|
+
const { code, message: errMessage, data } = normalizeProviderError(err);
|
|
343
|
+
console.info("[blink-bridge:parent] rpc-error", { uuid, method, code, message: errMessage });
|
|
344
|
+
sendError(id, code, errMessage, data);
|
|
345
|
+
});
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
case "blink:resolve-by-flag": {
|
|
349
|
+
const match = resolveByFlag(discoverer.list(), message.flags, log);
|
|
350
|
+
console.info("[blink-bridge:parent] resolveByFlag", {
|
|
351
|
+
flags: message.flags,
|
|
352
|
+
match: match ? { rdns: match.rdns, flag: match.flag } : null
|
|
353
|
+
});
|
|
354
|
+
const response = {
|
|
355
|
+
type: "blink:resolve-by-flag-response",
|
|
356
|
+
protocolVersion: BRIDGE_PROTOCOL_VERSION,
|
|
357
|
+
id: message.id,
|
|
358
|
+
match
|
|
359
|
+
};
|
|
360
|
+
postToIframe(response);
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
case "blink:wallets-advertised":
|
|
364
|
+
case "blink:rpc-response":
|
|
365
|
+
case "blink:rpc-event":
|
|
366
|
+
case "blink:resolve-by-flag-response":
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
window.addEventListener("message", onMessage);
|
|
371
|
+
return {
|
|
372
|
+
detach() {
|
|
373
|
+
if (detached) return;
|
|
374
|
+
detached = true;
|
|
375
|
+
window.removeEventListener("message", onMessage);
|
|
376
|
+
unsubscribeFromDiscoverer();
|
|
377
|
+
unsubscribeAll();
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
function noopLog() {
|
|
382
|
+
}
|
|
383
|
+
function resolveByFlag(snapshot, flags, log) {
|
|
384
|
+
for (const flag of flags) {
|
|
385
|
+
for (const entry of snapshot) {
|
|
386
|
+
let value;
|
|
387
|
+
try {
|
|
388
|
+
value = entry.provider[flag];
|
|
389
|
+
} catch (err) {
|
|
390
|
+
log("provider threw on flag read \u2014 skipping", {
|
|
391
|
+
rdns: entry.info.rdns,
|
|
392
|
+
flag,
|
|
393
|
+
error: err instanceof Error ? err.message : String(err)
|
|
394
|
+
});
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
if (value) {
|
|
398
|
+
return { rdns: entry.info.rdns, uuid: entry.info.uuid, flag };
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return null;
|
|
403
|
+
}
|
|
404
|
+
function normalizeProviderError(err) {
|
|
405
|
+
if (err && typeof err === "object") {
|
|
406
|
+
const e = err;
|
|
407
|
+
const code = typeof e.code === "number" ? e.code : -32603;
|
|
408
|
+
const message = typeof e.message === "string" ? e.message : err instanceof Error ? err.message : "Provider error";
|
|
409
|
+
const data = "data" in e ? e.data : void 0;
|
|
410
|
+
return data === void 0 ? { code, message } : { code, message, data };
|
|
411
|
+
}
|
|
412
|
+
return { code: -32603, message: typeof err === "string" ? err : "Provider error" };
|
|
413
|
+
}
|
|
414
|
+
|
|
25
415
|
// src/messages.ts
|
|
26
416
|
function parseTransferComplete(data) {
|
|
27
417
|
if (!data || typeof data !== "object") {
|
|
@@ -88,6 +478,24 @@ function parseCloseRequest(data) {
|
|
|
88
478
|
}
|
|
89
479
|
return { type: "blink:close-request" };
|
|
90
480
|
}
|
|
481
|
+
function parseIframeReady(data) {
|
|
482
|
+
if (!data || typeof data !== "object") {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
const msg = data;
|
|
486
|
+
if (msg.type !== "blink:iframe-ready") {
|
|
487
|
+
return null;
|
|
488
|
+
}
|
|
489
|
+
return { type: "blink:iframe-ready" };
|
|
490
|
+
}
|
|
491
|
+
function buildSignedPayloadMessage(merchantId, payload, signature) {
|
|
492
|
+
return {
|
|
493
|
+
type: "blink:signed-payload",
|
|
494
|
+
merchantId,
|
|
495
|
+
payload,
|
|
496
|
+
signature
|
|
497
|
+
};
|
|
498
|
+
}
|
|
91
499
|
|
|
92
500
|
// src/iframe.ts
|
|
93
501
|
var STYLE_ID = "blink-deposit-styles";
|
|
@@ -124,13 +532,26 @@ function createIframe(url, containerElement) {
|
|
|
124
532
|
const iframe = document.createElement("iframe");
|
|
125
533
|
iframe.src = url;
|
|
126
534
|
const iframeOrigin = new URL(url).origin;
|
|
127
|
-
iframe.allow = `publickey-credentials-get ${iframeOrigin}; publickey-credentials-create ${iframeOrigin}`;
|
|
535
|
+
iframe.allow = `publickey-credentials-get ${iframeOrigin}; publickey-credentials-create ${iframeOrigin}; clipboard-write ${iframeOrigin}`;
|
|
128
536
|
const handle = document.createElement("div");
|
|
129
537
|
container.appendChild(handle);
|
|
130
538
|
container.appendChild(iframe);
|
|
131
539
|
overlay.appendChild(container);
|
|
132
540
|
const mountTarget = containerElement ?? document.body;
|
|
133
541
|
mountTarget.appendChild(overlay);
|
|
542
|
+
const discoverer = createWalletDiscoverer();
|
|
543
|
+
let rpcHostHandle = null;
|
|
544
|
+
const attachBridge = () => {
|
|
545
|
+
if (rpcHostHandle) return;
|
|
546
|
+
if (!iframe.contentWindow) return;
|
|
547
|
+
rpcHostHandle = attachRpcHost({
|
|
548
|
+
iframeWindow: iframe.contentWindow,
|
|
549
|
+
iframeOrigin,
|
|
550
|
+
discoverer
|
|
551
|
+
});
|
|
552
|
+
};
|
|
553
|
+
attachBridge();
|
|
554
|
+
iframe.addEventListener("load", attachBridge);
|
|
134
555
|
const savedOverflow = document.body.style.overflow;
|
|
135
556
|
document.body.style.overflow = "hidden";
|
|
136
557
|
const onBackdropClick = (event) => {
|
|
@@ -157,6 +578,7 @@ function createIframe(url, containerElement) {
|
|
|
157
578
|
if (closed) return;
|
|
158
579
|
closed = true;
|
|
159
580
|
removeListeners();
|
|
581
|
+
detachBridge();
|
|
160
582
|
overlay.setAttribute("data-blink-closing", "");
|
|
161
583
|
let removed = false;
|
|
162
584
|
const removeOverlay = () => {
|
|
@@ -169,6 +591,14 @@ function createIframe(url, containerElement) {
|
|
|
169
591
|
container.addEventListener("animationend", removeOverlay, { once: true });
|
|
170
592
|
setTimeout(removeOverlay, CLOSE_DURATION_MS + 50);
|
|
171
593
|
}
|
|
594
|
+
function detachBridge() {
|
|
595
|
+
iframe.removeEventListener("load", attachBridge);
|
|
596
|
+
if (rpcHostHandle) {
|
|
597
|
+
rpcHostHandle.detach();
|
|
598
|
+
rpcHostHandle = null;
|
|
599
|
+
}
|
|
600
|
+
discoverer.destroy();
|
|
601
|
+
}
|
|
172
602
|
return {
|
|
173
603
|
get contentWindow() {
|
|
174
604
|
return iframe.contentWindow;
|
|
@@ -187,6 +617,7 @@ function createIframe(url, containerElement) {
|
|
|
187
617
|
if (!closed) {
|
|
188
618
|
closed = true;
|
|
189
619
|
removeListeners();
|
|
620
|
+
detachBridge();
|
|
190
621
|
overlay.remove();
|
|
191
622
|
unlockScroll();
|
|
192
623
|
}
|
|
@@ -309,8 +740,10 @@ function isValidTokenAddress(value) {
|
|
|
309
740
|
return TOKEN_ADDRESS_RE.test(value) || SOLANA_ADDRESS_RE.test(value);
|
|
310
741
|
}
|
|
311
742
|
function validateDepositRequest(request) {
|
|
312
|
-
if (
|
|
313
|
-
|
|
743
|
+
if (request.amount !== null) {
|
|
744
|
+
if (typeof request.amount !== "number" || !Number.isFinite(request.amount) || request.amount <= 0) {
|
|
745
|
+
throw new DepositError("INVALID_REQUEST", "amount must be a positive number or null.");
|
|
746
|
+
}
|
|
314
747
|
}
|
|
315
748
|
if (!Number.isInteger(request.chainId) || request.chainId <= 0) {
|
|
316
749
|
throw new DepositError("INVALID_REQUEST", "chainId must be a positive integer.");
|
|
@@ -501,30 +934,16 @@ var Deposit = class {
|
|
|
501
934
|
async runSignerFlow(request, requestId, onComplete, onError) {
|
|
502
935
|
try {
|
|
503
936
|
const webviewBaseUrl = this.config.webviewBaseUrl ?? DEFAULT_WEBVIEW_BASE_URL;
|
|
937
|
+
this.hostedOrigin = this.config.hostedFlowOrigin ?? new URL(webviewBaseUrl).origin;
|
|
504
938
|
this.log("Calling signer", {
|
|
505
939
|
signer: typeof this.config.signer === "string" ? this.config.signer : "<function>"
|
|
506
940
|
});
|
|
507
941
|
const signerRequest = buildSignerRequest(request, webviewBaseUrl);
|
|
508
|
-
const
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
)
|
|
513
|
-
this.lastSignerResponse = signerResponse;
|
|
514
|
-
this.log("Signer responded", { merchantId: signerResponse.merchantId });
|
|
515
|
-
if (this.requestId !== requestId) {
|
|
516
|
-
this.log("Request superseded after signer response");
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
const hostedUrl = new URL(webviewBaseUrl);
|
|
520
|
-
hostedUrl.searchParams.set("merchantId", signerResponse.merchantId);
|
|
521
|
-
hostedUrl.searchParams.set("payload", signerResponse.payload);
|
|
522
|
-
hostedUrl.searchParams.set("signature", signerResponse.signature);
|
|
523
|
-
const targetUrl = hostedUrl.toString();
|
|
524
|
-
this.hostedOrigin = this.config.hostedFlowOrigin ?? hostedUrl.origin;
|
|
525
|
-
const iframeHandle = createIframe(targetUrl, this.config.containerElement);
|
|
526
|
-
this.iframe = iframeHandle;
|
|
527
|
-
iframeHandle.onClose(() => {
|
|
942
|
+
const preloadUrl = new URL(webviewBaseUrl);
|
|
943
|
+
preloadUrl.searchParams.set("preload", "true");
|
|
944
|
+
const preloadIframe = createIframe(preloadUrl.toString(), this.config.containerElement);
|
|
945
|
+
this.iframe = preloadIframe;
|
|
946
|
+
preloadIframe.onClose(() => {
|
|
528
947
|
onError(
|
|
529
948
|
new DepositError(
|
|
530
949
|
"DEPOSIT_DISMISSED",
|
|
@@ -534,9 +953,60 @@ var Deposit = class {
|
|
|
534
953
|
this.cleanup();
|
|
535
954
|
this.emit("close");
|
|
536
955
|
});
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
956
|
+
const signerPromise = callSigner(
|
|
957
|
+
this.config.signer,
|
|
958
|
+
signerRequest,
|
|
959
|
+
this.config.signerTimeoutMs
|
|
960
|
+
);
|
|
961
|
+
const iframeReadyPromise = this.waitForIframeReady(preloadIframe);
|
|
962
|
+
const [signerResponse, iframeReady] = await Promise.all([
|
|
963
|
+
signerPromise,
|
|
964
|
+
iframeReadyPromise
|
|
965
|
+
]);
|
|
966
|
+
this.lastSignerResponse = signerResponse;
|
|
967
|
+
this.log("Signer responded", { merchantId: signerResponse.merchantId });
|
|
968
|
+
if (this.requestId !== requestId || preloadIframe.isClosed()) {
|
|
969
|
+
this.log("Request superseded or iframe dismissed during signer call");
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (iframeReady) {
|
|
973
|
+
const contentWindow = preloadIframe.contentWindow;
|
|
974
|
+
if (contentWindow) {
|
|
975
|
+
contentWindow.postMessage(
|
|
976
|
+
buildSignedPayloadMessage(
|
|
977
|
+
signerResponse.merchantId,
|
|
978
|
+
signerResponse.payload,
|
|
979
|
+
signerResponse.signature
|
|
980
|
+
),
|
|
981
|
+
this.hostedOrigin
|
|
982
|
+
);
|
|
983
|
+
}
|
|
984
|
+
this.startMessageListener(preloadIframe, onComplete);
|
|
985
|
+
this.setStatus("iframe-active");
|
|
986
|
+
this.log("Payload delivered via postMessage (preload path)");
|
|
987
|
+
} else {
|
|
988
|
+
preloadIframe.destroy();
|
|
989
|
+
const hostedUrl = new URL(webviewBaseUrl);
|
|
990
|
+
hostedUrl.searchParams.set("merchantId", signerResponse.merchantId);
|
|
991
|
+
hostedUrl.searchParams.set("payload", signerResponse.payload);
|
|
992
|
+
hostedUrl.searchParams.set("signature", signerResponse.signature);
|
|
993
|
+
const targetUrl = hostedUrl.toString();
|
|
994
|
+
const iframeHandle = createIframe(targetUrl, this.config.containerElement);
|
|
995
|
+
this.iframe = iframeHandle;
|
|
996
|
+
iframeHandle.onClose(() => {
|
|
997
|
+
onError(
|
|
998
|
+
new DepositError(
|
|
999
|
+
"DEPOSIT_DISMISSED",
|
|
1000
|
+
"The deposit was dismissed before the transfer completed."
|
|
1001
|
+
)
|
|
1002
|
+
);
|
|
1003
|
+
this.cleanup();
|
|
1004
|
+
this.emit("close");
|
|
1005
|
+
});
|
|
1006
|
+
this.startMessageListener(iframeHandle, onComplete);
|
|
1007
|
+
this.setStatus("iframe-active");
|
|
1008
|
+
this.log("Iframe opened with hosted flow (fallback path)", { url: targetUrl });
|
|
1009
|
+
}
|
|
540
1010
|
} catch (err) {
|
|
541
1011
|
if (this.requestId !== requestId) return;
|
|
542
1012
|
this.log("Signer flow failed", { error: err instanceof Error ? err.message : String(err) });
|
|
@@ -552,6 +1022,25 @@ var Deposit = class {
|
|
|
552
1022
|
}
|
|
553
1023
|
}
|
|
554
1024
|
}
|
|
1025
|
+
waitForIframeReady(iframeHandle) {
|
|
1026
|
+
return new Promise((resolve) => {
|
|
1027
|
+
const handler = (event) => {
|
|
1028
|
+
if (event.origin !== this.hostedOrigin) return;
|
|
1029
|
+
if (event.source !== iframeHandle.contentWindow) return;
|
|
1030
|
+
if (parseIframeReady(event.data)) {
|
|
1031
|
+
window.removeEventListener("message", handler);
|
|
1032
|
+
clearTimeout(timeout);
|
|
1033
|
+
resolve(true);
|
|
1034
|
+
}
|
|
1035
|
+
};
|
|
1036
|
+
window.addEventListener("message", handler);
|
|
1037
|
+
const timeout = setTimeout(() => {
|
|
1038
|
+
window.removeEventListener("message", handler);
|
|
1039
|
+
this.log("Iframe ready timeout \u2014 falling back to URL params");
|
|
1040
|
+
resolve(false);
|
|
1041
|
+
}, 2e3);
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
555
1044
|
startMessageListener(iframeHandle, onComplete) {
|
|
556
1045
|
const handler = (event) => {
|
|
557
1046
|
if (this.hostedOrigin && event.origin !== this.hostedOrigin) {
|
|
@@ -622,6 +1111,6 @@ var Deposit = class {
|
|
|
622
1111
|
};
|
|
623
1112
|
var Checkout = Deposit;
|
|
624
1113
|
|
|
625
|
-
export { Checkout, CheckoutError, DEFAULT_WEBVIEW_BASE_URL, Deposit, DepositError, getDisplayMessage };
|
|
626
|
-
//# sourceMappingURL=chunk-
|
|
627
|
-
//# sourceMappingURL=chunk-
|
|
1114
|
+
export { ALLOWED_RPC_METHODS, BRIDGE_PROTOCOL_VERSION, Checkout, CheckoutError, DEFAULT_WEBVIEW_BASE_URL, Deposit, DepositError, attachRpcHost, createWalletDiscoverer, getDisplayMessage, parseBridgeMessage };
|
|
1115
|
+
//# sourceMappingURL=chunk-MA7CVDFD.js.map
|
|
1116
|
+
//# sourceMappingURL=chunk-MA7CVDFD.js.map
|