@fastnear/wallet 0.9.9

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,2776 @@
1
+ /* ⋈ 🏃🏻💨 FastNear Wallet Connector - IIFE/UMD (@fastnear/wallet version 0.9.9) */
2
+ /* https://www.npmjs.com/package/@fastnear/wallet/v/0.9.9 */
3
+ "use strict";
4
+ var nearWallet = (() => {
5
+ var __create = Object.create;
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __getOwnPropNames = Object.getOwnPropertyNames;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __commonJS = (cb, mod) => function __require() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
14
+ };
15
+ var __export = (target, all) => {
16
+ for (var name in all)
17
+ __defProp(target, name, { get: all[name], enumerable: true });
18
+ };
19
+ var __copyProps = (to, from, except, desc) => {
20
+ if (from && typeof from === "object" || typeof from === "function") {
21
+ for (let key of __getOwnPropNames(from))
22
+ if (!__hasOwnProp.call(to, key) && key !== except)
23
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
24
+ }
25
+ return to;
26
+ };
27
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
28
+ // If the importer is in node compatibility mode or this is not an ESM
29
+ // file that has been converted to a CommonJS file using a Babel-
30
+ // compatible transform (i.e. "__esModule" has not been set), then set
31
+ // "default" to the CommonJS "module.exports" for node compatibility.
32
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
33
+ mod
34
+ ));
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // ../../node_modules/@fastnear/near-connect/build/helpers/storage.js
38
+ var require_storage = __commonJS({
39
+ "../../node_modules/@fastnear/near-connect/build/helpers/storage.js"(exports) {
40
+ "use strict";
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.LocalStorage = void 0;
43
+ var LocalStorage = class {
44
+ static {
45
+ __name(this, "LocalStorage");
46
+ }
47
+ async get(key) {
48
+ if (typeof window === "undefined")
49
+ return null;
50
+ return localStorage.getItem(key);
51
+ }
52
+ async set(key, value) {
53
+ if (typeof window === "undefined")
54
+ return;
55
+ localStorage.setItem(key, value);
56
+ }
57
+ async remove(key) {
58
+ if (typeof window === "undefined")
59
+ return;
60
+ localStorage.removeItem(key);
61
+ }
62
+ };
63
+ exports.LocalStorage = LocalStorage;
64
+ }
65
+ });
66
+
67
+ // ../../node_modules/@fastnear/near-connect/build/helpers/base58.js
68
+ var require_base58 = __commonJS({
69
+ "../../node_modules/@fastnear/near-connect/build/helpers/base58.js"(exports) {
70
+ "use strict";
71
+ Object.defineProperty(exports, "__esModule", { value: true });
72
+ exports.encodeBase58 = encodeBase58;
73
+ var BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
74
+ function encodeBase58(bytes) {
75
+ if (bytes.length === 0)
76
+ return "";
77
+ let zeros = 0;
78
+ let i = 0;
79
+ while (i < bytes.length && bytes[i] === 0) {
80
+ zeros++;
81
+ i++;
82
+ }
83
+ let digits = [0];
84
+ for (; i < bytes.length; i++) {
85
+ let carry = bytes[i];
86
+ for (let j = 0; j < digits.length; ++j) {
87
+ carry += digits[j] << 8;
88
+ digits[j] = carry % 58;
89
+ carry = carry / 58 | 0;
90
+ }
91
+ while (carry > 0) {
92
+ digits.push(carry % 58);
93
+ carry = carry / 58 | 0;
94
+ }
95
+ }
96
+ while (digits.length > 0 && digits[digits.length - 1] === 0)
97
+ digits.pop();
98
+ let result = "";
99
+ for (let k = 0; k < zeros; k++) {
100
+ result += BASE58_ALPHABET[0];
101
+ }
102
+ for (let q = digits.length - 1; q >= 0; --q) {
103
+ result += BASE58_ALPHABET[digits[q]];
104
+ }
105
+ return result;
106
+ }
107
+ __name(encodeBase58, "encodeBase58");
108
+ }
109
+ });
110
+
111
+ // ../../node_modules/@fastnear/near-connect/build/actions/index.js
112
+ var require_actions = __commonJS({
113
+ "../../node_modules/@fastnear/near-connect/build/actions/index.js"(exports) {
114
+ "use strict";
115
+ Object.defineProperty(exports, "__esModule", { value: true });
116
+ exports.nearActionsToConnectorActions = void 0;
117
+ var base58_1 = require_base58();
118
+ var deserializeArgs = /* @__PURE__ */ __name((args) => {
119
+ try {
120
+ return JSON.parse(new TextDecoder().decode(args));
121
+ } catch {
122
+ return args;
123
+ }
124
+ }, "deserializeArgs");
125
+ var nearActionsToConnectorActions = /* @__PURE__ */ __name((actions) => {
126
+ return actions.map((action) => {
127
+ if ("type" in action)
128
+ return action;
129
+ if (action.functionCall) {
130
+ return {
131
+ type: "FunctionCall",
132
+ params: {
133
+ methodName: action.functionCall.methodName,
134
+ args: deserializeArgs(action.functionCall.args),
135
+ gas: action.functionCall.gas.toString(),
136
+ deposit: action.functionCall.deposit.toString()
137
+ }
138
+ };
139
+ }
140
+ if (action.deployGlobalContract) {
141
+ return {
142
+ type: "DeployGlobalContract",
143
+ params: {
144
+ code: action.deployGlobalContract.code,
145
+ deployMode: action.deployGlobalContract.deployMode.AccountId ? "AccountId" : "CodeHash"
146
+ }
147
+ };
148
+ }
149
+ if (action.createAccount) {
150
+ return { type: "CreateAccount" };
151
+ }
152
+ if (action.useGlobalContract) {
153
+ return {
154
+ type: "UseGlobalContract",
155
+ params: {
156
+ contractIdentifier: action.useGlobalContract.contractIdentifier.AccountId ? { accountId: action.useGlobalContract.contractIdentifier.AccountId } : { codeHash: (0, base58_1.encodeBase58)(action.useGlobalContract.contractIdentifier.CodeHash) }
157
+ }
158
+ };
159
+ }
160
+ if (action.deployContract) {
161
+ return {
162
+ type: "DeployContract",
163
+ params: { code: action.deployContract.code }
164
+ };
165
+ }
166
+ if (action.deleteAccount) {
167
+ return {
168
+ type: "DeleteAccount",
169
+ params: { beneficiaryId: action.deleteAccount.beneficiaryId }
170
+ };
171
+ }
172
+ if (action.deleteKey) {
173
+ return {
174
+ type: "DeleteKey",
175
+ params: { publicKey: action.deleteKey.publicKey.toString() }
176
+ };
177
+ }
178
+ if (action.transfer) {
179
+ return {
180
+ type: "Transfer",
181
+ params: { deposit: action.transfer.deposit.toString() }
182
+ };
183
+ }
184
+ if (action.stake) {
185
+ return {
186
+ type: "Stake",
187
+ params: {
188
+ stake: action.stake.stake.toString(),
189
+ publicKey: action.stake.publicKey.toString()
190
+ }
191
+ };
192
+ }
193
+ if (action.addKey) {
194
+ return {
195
+ type: "AddKey",
196
+ params: {
197
+ publicKey: action.addKey.publicKey.toString(),
198
+ accessKey: {
199
+ nonce: Number(action.addKey.accessKey.nonce),
200
+ permission: action.addKey.accessKey.permission.functionCall ? {
201
+ receiverId: action.addKey.accessKey.permission.functionCall.receiverId,
202
+ allowance: action.addKey.accessKey.permission.functionCall.allowance?.toString(),
203
+ methodNames: action.addKey.accessKey.permission.functionCall.methodNames
204
+ } : "FullAccess"
205
+ }
206
+ }
207
+ };
208
+ }
209
+ throw new Error("Unsupported action type");
210
+ });
211
+ }, "nearActionsToConnectorActions");
212
+ exports.nearActionsToConnectorActions = nearActionsToConnectorActions;
213
+ }
214
+ });
215
+
216
+ // ../../node_modules/@fastnear/near-connect/build/helpers/uuid.js
217
+ var require_uuid = __commonJS({
218
+ "../../node_modules/@fastnear/near-connect/build/helpers/uuid.js"(exports) {
219
+ "use strict";
220
+ Object.defineProperty(exports, "__esModule", { value: true });
221
+ exports.uuid4 = void 0;
222
+ var uuid4 = /* @__PURE__ */ __name(() => {
223
+ if (typeof window !== "undefined" && typeof window.crypto !== "undefined" && typeof window.crypto.randomUUID === "function")
224
+ return window.crypto.randomUUID();
225
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
226
+ const r = Math.random() * 16 | 0;
227
+ const v = c === "x" ? r : r & 3 | 8;
228
+ return v.toString(16);
229
+ });
230
+ }, "uuid4");
231
+ exports.uuid4 = uuid4;
232
+ }
233
+ });
234
+
235
+ // ../../node_modules/@fastnear/near-connect/build/ParentFrameWallet.js
236
+ var require_ParentFrameWallet = __commonJS({
237
+ "../../node_modules/@fastnear/near-connect/build/ParentFrameWallet.js"(exports) {
238
+ "use strict";
239
+ Object.defineProperty(exports, "__esModule", { value: true });
240
+ exports.ParentFrameWallet = void 0;
241
+ var actions_1 = require_actions();
242
+ var uuid_1 = require_uuid();
243
+ var ParentFrameWallet = class {
244
+ static {
245
+ __name(this, "ParentFrameWallet");
246
+ }
247
+ connector;
248
+ manifest;
249
+ constructor(connector2, manifest) {
250
+ this.connector = connector2;
251
+ this.manifest = manifest;
252
+ }
253
+ callParentFrame(method, params) {
254
+ const id = (0, uuid_1.uuid4)();
255
+ window.parent.postMessage({ type: "near-wallet-injected-request", id, method, params }, "*");
256
+ return new Promise((resolve, reject) => {
257
+ const handler = /* @__PURE__ */ __name((event) => {
258
+ if (event.data.type === "near-wallet-injected-response" && event.data.id === id) {
259
+ window.removeEventListener("message", handler);
260
+ if (event.data.success)
261
+ resolve(event.data.result);
262
+ else
263
+ reject(event.data.error);
264
+ }
265
+ }, "handler");
266
+ window.addEventListener("message", handler);
267
+ });
268
+ }
269
+ async signIn(data) {
270
+ const result = await this.callParentFrame("near:signIn", {
271
+ network: data?.network || this.connector.network,
272
+ contractId: data?.contractId,
273
+ methodNames: data?.methodNames
274
+ });
275
+ if (Array.isArray(result))
276
+ return result;
277
+ return [result];
278
+ }
279
+ async signInAndSignMessage(data) {
280
+ const result = await this.callParentFrame("near:signInAndSignMessage", {
281
+ network: data?.network || this.connector.network,
282
+ contractId: data?.contractId,
283
+ methodNames: data?.methodNames,
284
+ messageParams: data.messageParams
285
+ });
286
+ if (Array.isArray(result))
287
+ return result;
288
+ return [result];
289
+ }
290
+ async signOut(data) {
291
+ const args = { ...data, network: data?.network || this.connector.network };
292
+ await this.callParentFrame("near:signOut", args);
293
+ }
294
+ async getAccounts(data) {
295
+ const args = { ...data, network: data?.network || this.connector.network };
296
+ return this.callParentFrame("near:getAccounts", args);
297
+ }
298
+ async signAndSendTransaction(params) {
299
+ const connectorActions = (0, actions_1.nearActionsToConnectorActions)(params.actions);
300
+ const args = { ...params, actions: connectorActions, network: params.network || this.connector.network };
301
+ return this.callParentFrame("near:signAndSendTransaction", args);
302
+ }
303
+ async signAndSendTransactions(params) {
304
+ const args = { ...params, network: params.network || this.connector.network };
305
+ args.transactions = args.transactions.map((transaction) => ({
306
+ actions: (0, actions_1.nearActionsToConnectorActions)(transaction.actions),
307
+ receiverId: transaction.receiverId
308
+ }));
309
+ return this.callParentFrame("near:signAndSendTransactions", args);
310
+ }
311
+ async signMessage(params) {
312
+ const args = { ...params, network: params.network || this.connector.network };
313
+ return this.callParentFrame("near:signMessage", args);
314
+ }
315
+ async signDelegateActions(params) {
316
+ const args = {
317
+ ...params,
318
+ delegateActions: params.delegateActions.map((delegateAction) => ({
319
+ ...delegateAction,
320
+ actions: (0, actions_1.nearActionsToConnectorActions)(delegateAction.actions)
321
+ })),
322
+ network: params.network || this.connector.network
323
+ };
324
+ return this.callParentFrame("near:signDelegateActions", args);
325
+ }
326
+ };
327
+ exports.ParentFrameWallet = ParentFrameWallet;
328
+ }
329
+ });
330
+
331
+ // ../../node_modules/@fastnear/near-connect/build/helpers/url.js
332
+ var require_url = __commonJS({
333
+ "../../node_modules/@fastnear/near-connect/build/helpers/url.js"(exports) {
334
+ "use strict";
335
+ Object.defineProperty(exports, "__esModule", { value: true });
336
+ exports.parseUrl = void 0;
337
+ var parseUrl = /* @__PURE__ */ __name((url) => {
338
+ try {
339
+ return new URL(url);
340
+ } catch {
341
+ return null;
342
+ }
343
+ }, "parseUrl");
344
+ exports.parseUrl = parseUrl;
345
+ }
346
+ });
347
+
348
+ // ../../node_modules/@fastnear/near-connect/build/helpers/events.js
349
+ var require_events = __commonJS({
350
+ "../../node_modules/@fastnear/near-connect/build/helpers/events.js"(exports) {
351
+ "use strict";
352
+ Object.defineProperty(exports, "__esModule", { value: true });
353
+ exports.EventEmitter = void 0;
354
+ var EventEmitter = class {
355
+ static {
356
+ __name(this, "EventEmitter");
357
+ }
358
+ /** Internal storage for event callbacks */
359
+ events = {};
360
+ /**
361
+ * Subscribe to an event
362
+ * @template K Event name type
363
+ * @param event Name of the event to subscribe to
364
+ * @param callback Function to be called when event is emitted
365
+ */
366
+ on(event, callback) {
367
+ if (!this.events[event])
368
+ this.events[event] = [];
369
+ this.events[event].push(callback);
370
+ }
371
+ /**
372
+ * Emit an event with payload
373
+ * @template K Event name type
374
+ * @param event Name of the event to emit
375
+ * @param payload Data to pass to event handlers
376
+ */
377
+ emit(event, payload) {
378
+ this.events[event]?.forEach((cb) => cb(payload));
379
+ }
380
+ /**
381
+ * Unsubscribe from an event
382
+ * @template K Event name type
383
+ * @param event Name of the event to unsubscribe from
384
+ * @param callback Function to remove from event handlers
385
+ */
386
+ off(event, callback) {
387
+ this.events[event] = this.events[event]?.filter((cb) => cb !== callback);
388
+ }
389
+ /**
390
+ * Subscribe to an event for a single emission
391
+ * @template K Event name type
392
+ * @param event Name of the event to subscribe to
393
+ * @param callback Function to be called when event is emitted
394
+ */
395
+ once(event, callback) {
396
+ const onceWrapper = /* @__PURE__ */ __name((payload) => {
397
+ callback(payload);
398
+ this.off(event, onceWrapper);
399
+ }, "onceWrapper");
400
+ this.on(event, onceWrapper);
401
+ }
402
+ /**
403
+ * Remove all event listeners
404
+ * @template K Event name type
405
+ * @param event Optional event name to remove listeners for. If not provided, removes all listeners for all events
406
+ */
407
+ removeAllListeners(event) {
408
+ if (event) {
409
+ delete this.events[event];
410
+ } else {
411
+ this.events = {};
412
+ }
413
+ }
414
+ };
415
+ exports.EventEmitter = EventEmitter;
416
+ }
417
+ });
418
+
419
+ // ../../node_modules/@fastnear/near-connect/build/helpers/html.js
420
+ var require_html = __commonJS({
421
+ "../../node_modules/@fastnear/near-connect/build/helpers/html.js"(exports) {
422
+ "use strict";
423
+ Object.defineProperty(exports, "__esModule", { value: true });
424
+ exports.escapeHtml = escapeHtml;
425
+ exports.html = html;
426
+ function escapeHtml(unsafe) {
427
+ return unsafe.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
428
+ }
429
+ __name(escapeHtml, "escapeHtml");
430
+ var htmlTag = Symbol("htmlTag");
431
+ function html(strings, ...values) {
432
+ let result = strings[0];
433
+ for (let i = 0; i < values.length; i++) {
434
+ for (const value of Array.isArray(values[i]) ? values[i] : [values[i]]) {
435
+ const escaped = value?.[htmlTag] ? value[htmlTag] : escapeHtml(String(value ?? ""));
436
+ result += escaped;
437
+ }
438
+ result += strings[i + 1];
439
+ }
440
+ return Object.freeze({
441
+ [htmlTag]: result,
442
+ get html() {
443
+ return result;
444
+ }
445
+ });
446
+ }
447
+ __name(html, "html");
448
+ }
449
+ });
450
+
451
+ // ../../node_modules/@fastnear/near-connect/build/popups/styles.js
452
+ var require_styles = __commonJS({
453
+ "../../node_modules/@fastnear/near-connect/build/popups/styles.js"(exports) {
454
+ "use strict";
455
+ Object.defineProperty(exports, "__esModule", { value: true });
456
+ exports.css = void 0;
457
+ var css = /* @__PURE__ */ __name((id) => (
458
+ /*css*/
459
+ `
460
+ ${id} * {
461
+ box-sizing: border-box;
462
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
463
+ -ms-overflow-style: none;
464
+ scrollbar-width: none;
465
+ color: #fff;
466
+ }
467
+
468
+ ${id} *::-webkit-scrollbar {
469
+ display: none;
470
+ }
471
+
472
+ ${id} p,
473
+ ${id} h1,
474
+ ${id} h2,
475
+ ${id} h3,
476
+ ${id} h4,
477
+ ${id} h5,
478
+ ${id} h6 {
479
+ margin: 0;
480
+ }
481
+
482
+ ${id} .modal-container {
483
+ position: fixed;
484
+ top: 0;
485
+ left: 0;
486
+ width: 100%;
487
+ height: 100%;
488
+ z-index: 100000000;
489
+ background-color: rgba(0, 0, 0, 0.5);
490
+ display: flex;
491
+ justify-content: center;
492
+ align-items: center;
493
+ flex-direction: column;
494
+ transition: opacity 0.2s ease-in-out;
495
+ }
496
+
497
+ @media (max-width: 600px) {
498
+ ${id} .modal-container {
499
+ justify-content: flex-end;
500
+ }
501
+ }
502
+
503
+ ${id} .modal-content {
504
+ display: flex;
505
+ flex-direction: column;
506
+ align-items: center;
507
+
508
+ max-width: 420px;
509
+ max-height: 615px;
510
+ width: 100%;
511
+ border-radius: 24px;
512
+ background: #0d0d0d;
513
+ border: 1.5px solid rgba(255, 255, 255, 0.1);
514
+ transition: transform 0.2s ease-in-out;
515
+ }
516
+
517
+ @media (max-width: 600px) {
518
+ ${id} .modal-content {
519
+ max-width: 100%;
520
+ width: 100%;
521
+ max-height: 80%;
522
+ border-bottom-left-radius: 0;
523
+ border-bottom-right-radius: 0;
524
+ border: none;
525
+ border-top: 1.5px solid rgba(255, 255, 255, 0.1);
526
+ }
527
+ }
528
+
529
+
530
+ ${id} .modal-header {
531
+ display: flex;
532
+ padding: 16px;
533
+ gap: 16px;
534
+ align-self: stretch;
535
+ align-items: center;
536
+ justify-content: center;
537
+ position: relative;
538
+ }
539
+
540
+ ${id} .modal-header button {
541
+ position: absolute;
542
+ right: 16px;
543
+ top: 16px;
544
+ width: 32px;
545
+ height: 32px;
546
+ border-radius: 12px;
547
+ cursor: pointer;
548
+ transition: background 0.2s ease-in-out;
549
+ border: none;
550
+ background: none;
551
+ display: flex;
552
+ align-items: center;
553
+ justify-content: center;
554
+ }
555
+
556
+ ${id} .modal-header button:hover {
557
+ background: rgba(255, 255, 255, 0.04);
558
+ }
559
+
560
+ ${id} .modal-header p {
561
+ color: #fff;
562
+ text-align: center;
563
+ font-size: 24px;
564
+ font-style: normal;
565
+ font-weight: 600;
566
+ line-height: normal;
567
+ margin: 0;
568
+ }
569
+
570
+
571
+ ${id} .modal-body {
572
+ display: flex;
573
+ padding: 16px;
574
+ flex-direction: column;
575
+ align-items: flex-start;
576
+ text-align: center;
577
+ gap: 8px;
578
+ overflow: auto;
579
+
580
+ border-radius: 24px;
581
+ background: rgba(255, 255, 255, 0.08);
582
+ width: 100%;
583
+ flex: 1;
584
+ }
585
+
586
+ ${id} .modal-body textarea {
587
+ width: 100%;
588
+ padding: 12px;
589
+ border-radius: 12px;
590
+ background: #0d0d0d;
591
+ color: #fff;
592
+ border: 1px solid rgba(255, 255, 255, 0.1);
593
+ outline: none;
594
+ font-size: 16px;
595
+ transition: background 0.2s ease-in-out;
596
+ font-family: monospace;
597
+ font-size: 12px;
598
+ }
599
+
600
+ ${id} .modal-body button {
601
+ width: 100%;
602
+ padding: 12px;
603
+ border-radius: 12px;
604
+ background: #fff;
605
+ color: #000;
606
+ border: none;
607
+ cursor: pointer;
608
+ font-size: 16px;
609
+ transition: background 0.2s ease-in-out;
610
+ margin-top: 16px;
611
+ }
612
+
613
+ ${id} .footer {
614
+ width: 100%;
615
+ display: flex;
616
+ align-items: center;
617
+ justify-content: flex-start;
618
+ padding: 16px 24px;
619
+ color: #fff;
620
+ gap: 12px;
621
+ }
622
+
623
+ ${id} .modal-body p {
624
+ color: rgba(255, 255, 255, 0.9);
625
+ text-align: center;
626
+ font-size: 16px;
627
+ font-style: normal;
628
+ font-weight: 500;
629
+ line-height: normal;
630
+ letter-spacing: -0.8px;
631
+ }
632
+
633
+ ${id} .footer img {
634
+ width: 24px;
635
+ height: 24px;
636
+ border-radius: 50%;
637
+ object-fit: cover;
638
+ }
639
+
640
+ ${id} .get-wallet-link {
641
+ color: rgba(255, 255, 255, 0.5);
642
+ text-align: center;
643
+ font-size: 16px;
644
+ font-style: normal;
645
+ font-weight: 500;
646
+ margin-left: auto;
647
+ text-decoration: none;
648
+ transition: color 0.2s ease-in-out;
649
+ cursor: pointer;
650
+ }
651
+
652
+ ${id} .get-wallet-link:hover {
653
+ color: rgba(255, 255, 255, 1);
654
+ }
655
+
656
+
657
+ ${id} .connect-item {
658
+ display: flex;
659
+ padding: 8px;
660
+ align-items: center;
661
+ gap: 12px;
662
+ align-self: stretch;
663
+ cursor: pointer;
664
+
665
+ transition: background 0.2s ease-in-out;
666
+ border-radius: 24px;
667
+ }
668
+
669
+ ${id} .connect-item img {
670
+ width: 48px;
671
+ height: 48px;
672
+ border-radius: 16px;
673
+ object-fit: cover;
674
+ flex-shrink: 0;
675
+ }
676
+
677
+ ${id} .connect-item-info {
678
+ display: flex;
679
+ flex-direction: column;
680
+ align-items: flex-start;
681
+ gap: 4px;
682
+ text-align: left;
683
+ flex: 1;
684
+ margin-top: -2px;
685
+ }
686
+
687
+ ${id} .connect-item-info .wallet-address {
688
+ color: rgba(255, 255, 255, 0.5);
689
+ font-size: 14px;
690
+ font-style: normal;
691
+ font-weight: 400;
692
+ line-height: normal;
693
+ }
694
+
695
+ ${id} .connect-item:hover {
696
+ background: rgba(255, 255, 255, 0.04);
697
+ }
698
+
699
+ ${id} .connect-item img {
700
+ width: 48px;
701
+ height: 48px;
702
+ border-radius: 16px;
703
+ object-fit: cover;
704
+ }
705
+
706
+ ${id} .connect-item p {
707
+ color: rgba(255, 255, 255, 0.9);
708
+ text-align: center;
709
+ font-size: 18px;
710
+ font-style: normal;
711
+ font-weight: 600;
712
+ line-height: normal;
713
+ letter-spacing: -0.36px;
714
+ margin: 0;
715
+ }
716
+ `
717
+ ), "css");
718
+ exports.css = css;
719
+ }
720
+ });
721
+
722
+ // ../../node_modules/@fastnear/near-connect/build/popups/Popup.js
723
+ var require_Popup = __commonJS({
724
+ "../../node_modules/@fastnear/near-connect/build/popups/Popup.js"(exports) {
725
+ "use strict";
726
+ Object.defineProperty(exports, "__esModule", { value: true });
727
+ exports.Popup = void 0;
728
+ var styles_1 = require_styles();
729
+ var html_1 = require_html();
730
+ var ID = `n${Math.random().toString(36).substring(2, 15)}`;
731
+ if (typeof document !== "undefined") {
732
+ const style = document.createElement("style");
733
+ style.textContent = (0, styles_1.css)(`.${ID}`);
734
+ document.head.append(style);
735
+ }
736
+ var Popup = class {
737
+ static {
738
+ __name(this, "Popup");
739
+ }
740
+ delegate;
741
+ isClosed = false;
742
+ root = document.createElement("div");
743
+ state = {};
744
+ constructor(delegate) {
745
+ this.delegate = delegate;
746
+ }
747
+ get dom() {
748
+ return (0, html_1.html)``;
749
+ }
750
+ disposables = [];
751
+ addListener(querySelector, event, callback) {
752
+ const element = typeof querySelector === "string" ? this.root.querySelector(querySelector) : querySelector;
753
+ if (!element)
754
+ return;
755
+ element.addEventListener(event, callback);
756
+ this.disposables.push(() => element.removeEventListener(event, callback));
757
+ }
758
+ handlers() {
759
+ this.disposables.forEach((dispose) => dispose());
760
+ this.disposables = [];
761
+ const modalContainer = this.root.querySelector(".modal-container");
762
+ const modalContent = this.root.querySelector(".modal-content");
763
+ modalContent.onclick = (e) => e.stopPropagation();
764
+ modalContainer.onclick = () => {
765
+ this.delegate.onReject();
766
+ this.destroy();
767
+ };
768
+ }
769
+ update(state) {
770
+ this.state = { ...this.state, ...state };
771
+ this.root.innerHTML = this.dom.html;
772
+ this.handlers();
773
+ }
774
+ create({ show = true }) {
775
+ this.root.className = `${ID} hot-connector-popup`;
776
+ this.root.innerHTML = this.dom.html;
777
+ document.body.append(this.root);
778
+ this.handlers();
779
+ const modalContainer = this.root.querySelector(".modal-container");
780
+ const modalContent = this.root.querySelector(".modal-content");
781
+ modalContent.style.transform = "translateY(50px)";
782
+ modalContainer.style.opacity = "0";
783
+ this.root.style.display = "none";
784
+ if (show) {
785
+ setTimeout(() => this.show(), 10);
786
+ }
787
+ }
788
+ show() {
789
+ const modalContainer = this.root.querySelector(".modal-container");
790
+ const modalContent = this.root.querySelector(".modal-content");
791
+ modalContent.style.transform = "translateY(50px)";
792
+ modalContainer.style.opacity = "0";
793
+ this.root.style.display = "block";
794
+ setTimeout(() => {
795
+ modalContent.style.transform = "translateY(0)";
796
+ modalContainer.style.opacity = "1";
797
+ }, 100);
798
+ }
799
+ hide() {
800
+ const modalContainer = this.root.querySelector(".modal-container");
801
+ const modalContent = this.root.querySelector(".modal-content");
802
+ modalContent.style.transform = "translateY(50px)";
803
+ modalContainer.style.opacity = "0";
804
+ setTimeout(() => {
805
+ this.root.style.display = "none";
806
+ }, 200);
807
+ }
808
+ destroy() {
809
+ if (this.isClosed)
810
+ return;
811
+ this.isClosed = true;
812
+ this.hide();
813
+ setTimeout(() => {
814
+ this.root.remove();
815
+ }, 200);
816
+ }
817
+ };
818
+ exports.Popup = Popup;
819
+ }
820
+ });
821
+
822
+ // ../../node_modules/@fastnear/near-connect/build/popups/IframeWalletPopup.js
823
+ var require_IframeWalletPopup = __commonJS({
824
+ "../../node_modules/@fastnear/near-connect/build/popups/IframeWalletPopup.js"(exports) {
825
+ "use strict";
826
+ Object.defineProperty(exports, "__esModule", { value: true });
827
+ exports.IframeWalletPopup = void 0;
828
+ var html_1 = require_html();
829
+ var Popup_1 = require_Popup();
830
+ var IframeWalletPopup = class extends Popup_1.Popup {
831
+ static {
832
+ __name(this, "IframeWalletPopup");
833
+ }
834
+ delegate;
835
+ constructor(delegate) {
836
+ super(delegate);
837
+ this.delegate = delegate;
838
+ }
839
+ handlers() {
840
+ super.handlers();
841
+ this.addListener("button", "click", () => this.delegate.onApprove());
842
+ }
843
+ create() {
844
+ super.create({ show: false });
845
+ const modalBody = this.root.querySelector(".modal-body");
846
+ modalBody.appendChild(this.delegate.iframe);
847
+ this.delegate.iframe.style.width = "100%";
848
+ this.delegate.iframe.style.height = "720px";
849
+ this.delegate.iframe.style.border = "none";
850
+ }
851
+ get footer() {
852
+ if (!this.delegate.footer)
853
+ return "";
854
+ const { icon, heading } = this.delegate.footer;
855
+ return (0, html_1.html)`
856
+ <div class="footer">
857
+ ${icon ? (0, html_1.html)`<img src="${icon}" alt="${heading}" />` : ""}
858
+ <p>${heading}</p>
859
+ </div>
860
+ `;
861
+ }
862
+ get dom() {
863
+ return (0, html_1.html)`<div class="modal-container">
864
+ <div class="modal-content">
865
+ <div class="modal-body" style="padding: 0; overflow: auto;"></div>
866
+ ${this.footer}
867
+ </div>
868
+ </div>`;
869
+ }
870
+ };
871
+ exports.IframeWalletPopup = IframeWalletPopup;
872
+ }
873
+ });
874
+
875
+ // ../../node_modules/@fastnear/near-connect/build/SandboxedWallet/code.js
876
+ var require_code = __commonJS({
877
+ "../../node_modules/@fastnear/near-connect/build/SandboxedWallet/code.js"(exports) {
878
+ "use strict";
879
+ Object.defineProperty(exports, "__esModule", { value: true });
880
+ async function getIframeCode(args) {
881
+ const storage = await args.executor.getAllStorage();
882
+ const providers = args.executor.connector.providers;
883
+ const manifest = args.executor.manifest;
884
+ const uuid = args.id;
885
+ const code = args.code.replaceAll(".localStorage", ".sandboxedLocalStorage").replaceAll(/(?<![.\w])localStorage(?=[\.\[\(])/g, "window.sandboxedLocalStorage").replaceAll("window.top", "window.selector").replaceAll("window.open", "window.selector.open");
886
+ return (
887
+ /* html */
888
+ `
889
+ <!DOCTYPE html>
890
+ <html>
891
+ <head>
892
+ <meta charset="UTF-8">
893
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
894
+ </head>
895
+ <body>
896
+ <div id="root"></div>
897
+
898
+ <style>
899
+ :root {
900
+ --background-color: rgb(40, 40, 40);
901
+ --text-color: rgb(255, 255, 255);
902
+ --border-color: rgb(209, 209, 209);
903
+ }
904
+
905
+ * {
906
+ font-family: system-ui, Avenir, Helvetica, Arial, sans-serif
907
+ }
908
+
909
+ body, html {
910
+ box-sizing: border-box;
911
+ margin: 0;
912
+ padding: 0;
913
+ background-color: var(--background-color);
914
+ color: var(--text-color);
915
+ }
916
+
917
+ #root {
918
+ display: none;
919
+ flex-direction: column;
920
+ align-items: center;
921
+ justify-content: center;
922
+ height: 100vh;
923
+ width: 100vw;
924
+ background: radial-gradient(circle at center, #2c2c2c 0%, #1a1a1a 100%);
925
+ text-align: center;
926
+ }
927
+
928
+ #root * {
929
+ box-sizing: border-box;
930
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
931
+ line-height: 1.5;
932
+ color-scheme: light dark;
933
+ color: rgb(255, 255, 255);
934
+ font-synthesis: none;
935
+ text-rendering: optimizeLegibility;
936
+ -webkit-font-smoothing: antialiased;
937
+ }
938
+
939
+ .prompt-container img {
940
+ width: 100px;
941
+ height: 100px;
942
+ object-fit: cover;
943
+ border-radius: 12px;
944
+ }
945
+
946
+ .prompt-container h1 {
947
+ margin: 0;
948
+ font-size: 24px;
949
+ font-weight: 600;
950
+ margin-top: 16px;
951
+ }
952
+
953
+ .prompt-container p {
954
+ margin: 0;
955
+ font-size: 16px;
956
+ font-weight: 500;
957
+ color: rgb(209, 209, 209);
958
+ }
959
+
960
+ .prompt-container button {
961
+ background-color: #131313;
962
+ border: none;
963
+ border-radius: 12px;
964
+ padding: 12px 24px;
965
+ cursor: pointer;
966
+ transition: border-color 0.25s;
967
+ color: #fff;
968
+ outline: none;
969
+ font-size: 14px;
970
+ font-weight: 500;
971
+ font-family: inherit;
972
+ margin-top: 16px;
973
+ }
974
+ </style>
975
+
976
+
977
+ <script>
978
+ window.sandboxedLocalStorage = (() => {
979
+ let storage = ${JSON.stringify(storage)}
980
+
981
+ return {
982
+ setItem: function(key, value) {
983
+ window.selector.storage.set(key, value)
984
+ storage[key] = value || '';
985
+ },
986
+ getItem: function(key) {
987
+ return key in storage ? storage[key] : null;
988
+ },
989
+ removeItem: function(key) {
990
+ window.selector.storage.remove(key)
991
+ delete storage[key];
992
+ },
993
+ get length() {
994
+ return Object.keys(storage).length;
995
+ },
996
+ key: function(i) {
997
+ const keys = Object.keys(storage);
998
+ return keys[i] || null;
999
+ },
1000
+ };
1001
+ })();
1002
+
1003
+ const showPrompt = async (args) => {
1004
+ const root = document.getElementById("root");
1005
+ root.style.display = "flex";
1006
+ root.innerHTML = \`
1007
+ <div class="prompt-container">
1008
+ <img src="${manifest.icon}" />
1009
+ <h1>${manifest.name}</h1>
1010
+ <p>\${args.title}</p>
1011
+ <button>\${args.button}</button>
1012
+ </div>
1013
+ \`;
1014
+
1015
+ return new Promise((resolve) => {
1016
+ root.querySelector("button")?.addEventListener("click", () => {
1017
+ root.innerHTML = "";
1018
+ resolve(true);
1019
+ });
1020
+ });
1021
+ }
1022
+
1023
+ class ProxyWindow {
1024
+ constructor(url, features) {
1025
+ this.closed = false;
1026
+ this.windowIdPromise = window.selector.call("open", { url, features });
1027
+
1028
+ window.addEventListener("message", async (event) => {
1029
+ if (event.data.origin !== "${uuid}") return;
1030
+ if (!event.data.method?.startsWith("proxy-window:")) return;
1031
+ const method = event.data.method.replace("proxy-window:", "");
1032
+ if (method === "closed" && event.data.windowId === await this.id()) this.closed = true;
1033
+ });
1034
+ }
1035
+
1036
+ async id() {
1037
+ return await this.windowIdPromise;
1038
+ }
1039
+
1040
+ async focus() {
1041
+ await window.selector.call("panel.focus", { windowId: await this.id() });
1042
+ }
1043
+
1044
+ async postMessage(data) {
1045
+ window.selector.call("panel.postMessage", { windowId: await this.id(), data });
1046
+ }
1047
+
1048
+ async close() {
1049
+ await window.selector.call("panel.close", { windowId: await this.id() });
1050
+ }
1051
+ }
1052
+
1053
+ window.selector = {
1054
+ wallet: null,
1055
+ location: "${window.location.href}",
1056
+
1057
+ outerHeight: ${window.outerHeight},
1058
+ screenY: ${window.screenY},
1059
+ outerWidth: ${window.outerWidth},
1060
+ screenX: ${window.screenX},
1061
+
1062
+ providers: {
1063
+ mainnet: ${JSON.stringify(providers.mainnet)},
1064
+ testnet: ${JSON.stringify(providers.testnet)},
1065
+ },
1066
+
1067
+ uuid() {
1068
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
1069
+ const r = (Math.random() * 16) | 0;
1070
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
1071
+ return v.toString(16);
1072
+ });
1073
+ },
1074
+
1075
+ walletConnect: {
1076
+ connect(params) {
1077
+ return window.selector.call("walletConnect.connect", params);
1078
+ },
1079
+ disconnect(params) {
1080
+ return window.selector.call("walletConnect.disconnect", params);
1081
+ },
1082
+ request(params) {
1083
+ return window.selector.call("walletConnect.request", params);
1084
+ },
1085
+ getProjectId() {
1086
+ return window.selector.call("walletConnect.getProjectId", {});
1087
+ },
1088
+ getSession() {
1089
+ return window.selector.call("walletConnect.getSession", {});
1090
+ },
1091
+ },
1092
+
1093
+ async ready(wallet) {
1094
+ window.parent.postMessage({ method: "wallet-ready", origin: "${uuid}" }, "*");
1095
+ window.selector.wallet = wallet;
1096
+ },
1097
+
1098
+ async call(method, params) {
1099
+ const id = window.selector.uuid();
1100
+ window.parent.postMessage({ method, params, id, origin: "${uuid}" }, "*");
1101
+
1102
+ return new Promise((resolve, reject) => {
1103
+ const handler = (event) => {
1104
+ if (event.data.id !== id || event.data.origin !== "${uuid}") return;
1105
+ window.removeEventListener("message", handler);
1106
+
1107
+ if (event.data.status === "failed") reject(event.data.result);
1108
+ else resolve(event.data.result);
1109
+ };
1110
+
1111
+ window.addEventListener("message", handler);
1112
+ });
1113
+ },
1114
+
1115
+ panelClosed(windowId) {
1116
+ window.parent.postMessage({
1117
+ method: "panel.closed",
1118
+ origin: "${uuid}",
1119
+ result: { windowId }
1120
+ }, "*");
1121
+ },
1122
+
1123
+ open(url, _, params) {
1124
+ return new ProxyWindow(url, params)
1125
+ },
1126
+
1127
+ external(entity, key, ...args) {
1128
+ return window.selector.call("external", { entity, key, args: args || [] });
1129
+ },
1130
+
1131
+ openNativeApp(url) {
1132
+ return window.selector.call("open.nativeApp", { url });
1133
+ },
1134
+
1135
+ ui: {
1136
+ async whenApprove(options) {
1137
+ window.selector.ui.showIframe();
1138
+ await showPrompt(options);
1139
+ window.selector.ui.hideIframe();
1140
+ },
1141
+
1142
+ async showIframe() {
1143
+ return await window.selector.call("ui.showIframe");
1144
+ },
1145
+
1146
+ async hideIframe() {
1147
+ return await window.selector.call("ui.hideIframe");
1148
+ },
1149
+ },
1150
+
1151
+ storage: {
1152
+ async set(key, value) {
1153
+ await window.selector.call("storage.set", { key, value });
1154
+ },
1155
+
1156
+ async get(key) {
1157
+ return await window.selector.call("storage.get", { key });
1158
+ },
1159
+
1160
+ async remove(key) {
1161
+ await window.selector.call("storage.remove", { key });
1162
+ },
1163
+
1164
+ async keys() {
1165
+ return await window.selector.call("storage.keys", {});
1166
+ },
1167
+ },
1168
+ };
1169
+
1170
+ window.addEventListener("message", async (event) => {
1171
+ if (event.data.origin !== "${uuid}") return;
1172
+ if (!event.data.method?.startsWith("wallet:")) return;
1173
+
1174
+ const wallet = window.selector.wallet;
1175
+ const method = event.data.method.replace("wallet:", "");
1176
+ const payload = { id: event.data.id, origin: "${uuid}", method };
1177
+
1178
+ if (wallet == null || typeof wallet[method] !== "function") {
1179
+ const data = { ...payload, status: "failed", result: "Method not found" };
1180
+ window.parent.postMessage(data, "*");
1181
+ return;
1182
+ }
1183
+
1184
+ try {
1185
+ // Ensure signerId is available in sandboxedLocalStorage for wallet code that reads it
1186
+ if (event.data.params?.signerId) {
1187
+ window.sandboxedLocalStorage.setItem("signedAccountId", event.data.params.signerId);
1188
+ }
1189
+
1190
+ const result = await wallet[method](event.data.params);
1191
+ window.parent.postMessage({ ...payload, status: "success", result }, "*");
1192
+ } catch (error) {
1193
+ const data = { ...payload, status: "failed", result: error };
1194
+ window.parent.postMessage(data, "*");
1195
+ }
1196
+ });
1197
+ </script>
1198
+
1199
+ <script type="module">${code}</script>
1200
+ </body>
1201
+ </html>
1202
+ `
1203
+ );
1204
+ }
1205
+ __name(getIframeCode, "getIframeCode");
1206
+ exports.default = getIframeCode;
1207
+ }
1208
+ });
1209
+
1210
+ // ../../node_modules/@fastnear/near-connect/build/SandboxedWallet/iframe.js
1211
+ var require_iframe = __commonJS({
1212
+ "../../node_modules/@fastnear/near-connect/build/SandboxedWallet/iframe.js"(exports) {
1213
+ "use strict";
1214
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1215
+ return mod && mod.__esModule ? mod : { "default": mod };
1216
+ };
1217
+ Object.defineProperty(exports, "__esModule", { value: true });
1218
+ var events_1 = require_events();
1219
+ var uuid_1 = require_uuid();
1220
+ var IframeWalletPopup_1 = require_IframeWalletPopup();
1221
+ var code_1 = __importDefault(require_code());
1222
+ var IframeExecutor = class {
1223
+ static {
1224
+ __name(this, "IframeExecutor");
1225
+ }
1226
+ executor;
1227
+ origin;
1228
+ iframe = document.createElement("iframe");
1229
+ events = new events_1.EventEmitter();
1230
+ popup;
1231
+ handler;
1232
+ readyPromiseResolve;
1233
+ readyPromise = new Promise((resolve) => {
1234
+ this.readyPromiseResolve = resolve;
1235
+ });
1236
+ constructor(executor, code, onMessage) {
1237
+ this.executor = executor;
1238
+ this.origin = (0, uuid_1.uuid4)();
1239
+ this.handler = (event) => {
1240
+ if (event.data.origin !== this.origin)
1241
+ return;
1242
+ if (event.data.method === "wallet-ready")
1243
+ this.readyPromiseResolve();
1244
+ onMessage(this, event);
1245
+ };
1246
+ window.addEventListener("message", this.handler);
1247
+ const iframeAllowedPersimissions = [];
1248
+ if (this.executor.checkPermissions("usb"))
1249
+ iframeAllowedPersimissions.push("usb *;");
1250
+ if (this.executor.checkPermissions("hid"))
1251
+ iframeAllowedPersimissions.push("hid *;");
1252
+ if (this.executor.checkPermissions("clipboardRead"))
1253
+ iframeAllowedPersimissions.push("clipboard-read;");
1254
+ if (this.executor.checkPermissions("clipboardWrite"))
1255
+ iframeAllowedPersimissions.push("clipboard-write;");
1256
+ this.iframe.allow = iframeAllowedPersimissions.join(" ");
1257
+ this.iframe.setAttribute("sandbox", "allow-scripts");
1258
+ (0, code_1.default)({ id: this.origin, executor: this.executor, code }).then((code2) => {
1259
+ this.executor.connector.logger?.log(`Iframe code injected`);
1260
+ this.iframe.srcdoc = code2;
1261
+ });
1262
+ this.popup = new IframeWalletPopup_1.IframeWalletPopup({
1263
+ footer: this.executor.connector.footerBranding,
1264
+ iframe: this.iframe,
1265
+ onApprove: /* @__PURE__ */ __name(() => {
1266
+ }, "onApprove"),
1267
+ onReject: /* @__PURE__ */ __name(() => {
1268
+ window.removeEventListener("message", this.handler);
1269
+ this.events.emit("close", {});
1270
+ this.popup.destroy();
1271
+ }, "onReject")
1272
+ });
1273
+ this.popup.create();
1274
+ }
1275
+ on(event, callback) {
1276
+ this.events.on(event, callback);
1277
+ }
1278
+ show() {
1279
+ this.popup.show();
1280
+ }
1281
+ hide() {
1282
+ this.popup.hide();
1283
+ }
1284
+ postMessage(data) {
1285
+ if (!this.iframe.contentWindow)
1286
+ throw new Error("Iframe not loaded");
1287
+ this.iframe.contentWindow.postMessage({ ...data, origin: this.origin }, "*");
1288
+ }
1289
+ dispose() {
1290
+ window.removeEventListener("message", this.handler);
1291
+ this.popup.destroy();
1292
+ }
1293
+ };
1294
+ exports.default = IframeExecutor;
1295
+ }
1296
+ });
1297
+
1298
+ // ../../node_modules/@fastnear/near-connect/build/SandboxedWallet/executor.js
1299
+ var require_executor = __commonJS({
1300
+ "../../node_modules/@fastnear/near-connect/build/SandboxedWallet/executor.js"(exports) {
1301
+ "use strict";
1302
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1303
+ return mod && mod.__esModule ? mod : { "default": mod };
1304
+ };
1305
+ Object.defineProperty(exports, "__esModule", { value: true });
1306
+ var url_1 = require_url();
1307
+ var uuid_1 = require_uuid();
1308
+ var iframe_1 = __importDefault(require_iframe());
1309
+ var cacheId = (0, uuid_1.uuid4)();
1310
+ var SandboxExecutor = class {
1311
+ static {
1312
+ __name(this, "SandboxExecutor");
1313
+ }
1314
+ connector;
1315
+ manifest;
1316
+ activePanels = {};
1317
+ storageSpace;
1318
+ constructor(connector2, manifest) {
1319
+ this.connector = connector2;
1320
+ this.manifest = manifest;
1321
+ this.storageSpace = manifest.id;
1322
+ }
1323
+ checkPermissions(action, params) {
1324
+ if (action === "walletConnect") {
1325
+ return !!this.manifest.permissions.walletConnect;
1326
+ }
1327
+ if (action === "external") {
1328
+ const external = this.manifest.permissions.external;
1329
+ if (!external || !params?.entity)
1330
+ return false;
1331
+ return external.includes(params.entity);
1332
+ }
1333
+ if (action === "allowsOpen") {
1334
+ const openUrl = (0, url_1.parseUrl)(params?.url || "");
1335
+ const allowsOpen = this.manifest.permissions.allowsOpen;
1336
+ if (!openUrl || !allowsOpen || !Array.isArray(allowsOpen) || allowsOpen.length === 0)
1337
+ return false;
1338
+ const isAllowed = allowsOpen.some((path) => {
1339
+ const url = (0, url_1.parseUrl)(path);
1340
+ if (!url)
1341
+ return false;
1342
+ if (openUrl.protocol !== url.protocol)
1343
+ return false;
1344
+ if (!!url.hostname && openUrl.hostname !== url.hostname)
1345
+ return false;
1346
+ if (!!url.pathname && url.pathname !== "/" && openUrl.pathname !== url.pathname)
1347
+ return false;
1348
+ return true;
1349
+ });
1350
+ return isAllowed;
1351
+ }
1352
+ return this.manifest.permissions[action];
1353
+ }
1354
+ assertPermissions(iframe, action, event) {
1355
+ if (!this.checkPermissions(action, event.data.params)) {
1356
+ iframe.postMessage({ ...event.data, status: "failed", result: "Permission denied" });
1357
+ throw new Error("Permission denied");
1358
+ }
1359
+ }
1360
+ _onMessage = /* @__PURE__ */ __name(async (iframe, event) => {
1361
+ const success = /* @__PURE__ */ __name((result) => {
1362
+ iframe.postMessage({ ...event.data, status: "success", result });
1363
+ }, "success");
1364
+ const failed = /* @__PURE__ */ __name((error) => {
1365
+ iframe.postMessage({ ...event.data, status: "failed", result: error });
1366
+ }, "failed");
1367
+ if (event.data.method === "ui.showIframe") {
1368
+ iframe.show();
1369
+ success(null);
1370
+ return;
1371
+ }
1372
+ if (event.data.method === "ui.hideIframe") {
1373
+ iframe.hide();
1374
+ success(null);
1375
+ return;
1376
+ }
1377
+ if (event.data.method === "storage.set") {
1378
+ this.assertPermissions(iframe, "storage", event);
1379
+ localStorage.setItem(`${this.storageSpace}:${event.data.params.key}`, event.data.params.value);
1380
+ success(null);
1381
+ return;
1382
+ }
1383
+ if (event.data.method === "storage.get") {
1384
+ this.assertPermissions(iframe, "storage", event);
1385
+ const value = localStorage.getItem(`${this.storageSpace}:${event.data.params.key}`);
1386
+ success(value);
1387
+ return;
1388
+ }
1389
+ if (event.data.method === "storage.keys") {
1390
+ this.assertPermissions(iframe, "storage", event);
1391
+ const keys = Object.keys(localStorage).filter((key) => key.startsWith(`${this.storageSpace}:`));
1392
+ success(keys);
1393
+ return;
1394
+ }
1395
+ if (event.data.method === "storage.remove") {
1396
+ this.assertPermissions(iframe, "storage", event);
1397
+ localStorage.removeItem(`${this.storageSpace}:${event.data.params.key}`);
1398
+ success(null);
1399
+ return;
1400
+ }
1401
+ if (event.data.method === "panel.focus") {
1402
+ const panel = this.activePanels[event.data.params.windowId];
1403
+ if (panel)
1404
+ panel.focus();
1405
+ success(null);
1406
+ return;
1407
+ }
1408
+ if (event.data.method === "panel.postMessage") {
1409
+ const panel = this.activePanels[event.data.params.windowId];
1410
+ if (panel)
1411
+ panel.postMessage(event.data.params.data, "*");
1412
+ success(null);
1413
+ return;
1414
+ }
1415
+ if (event.data.method === "panel.close") {
1416
+ const panel = this.activePanels[event.data.params.windowId];
1417
+ if (panel)
1418
+ panel.close();
1419
+ delete this.activePanels[event.data.params.windowId];
1420
+ success(null);
1421
+ return;
1422
+ }
1423
+ if (event.data.method === "walletConnect.connect") {
1424
+ this.assertPermissions(iframe, "walletConnect", event);
1425
+ try {
1426
+ if (!this.connector.walletConnect)
1427
+ throw new Error("WalletConnect is not configured");
1428
+ const client = await this.connector.walletConnect;
1429
+ const result = await client.connect(event.data.params);
1430
+ result.approval();
1431
+ success({ uri: result.uri });
1432
+ } catch (e) {
1433
+ failed(e);
1434
+ }
1435
+ return;
1436
+ }
1437
+ if (event.data.method === "walletConnect.getProjectId") {
1438
+ if (!this.connector.walletConnect)
1439
+ throw new Error("WalletConnect is not configured");
1440
+ this.assertPermissions(iframe, "walletConnect", event);
1441
+ const client = await this.connector.walletConnect;
1442
+ success(client.core.projectId);
1443
+ return;
1444
+ }
1445
+ if (event.data.method === "walletConnect.disconnect") {
1446
+ this.assertPermissions(iframe, "walletConnect", event);
1447
+ try {
1448
+ if (!this.connector.walletConnect)
1449
+ throw new Error("WalletConnect is not configured");
1450
+ const client = await this.connector.walletConnect;
1451
+ const result = await client.disconnect(event.data.params);
1452
+ success(result);
1453
+ } catch (e) {
1454
+ failed(e);
1455
+ }
1456
+ return;
1457
+ }
1458
+ if (event.data.method === "walletConnect.getSession") {
1459
+ this.assertPermissions(iframe, "walletConnect", event);
1460
+ try {
1461
+ if (!this.connector.walletConnect)
1462
+ throw new Error("WalletConnect is not configured");
1463
+ const client = await this.connector.walletConnect;
1464
+ const key = client.session.keys[client.session.keys.length - 1];
1465
+ const session = key ? client.session.get(key) : null;
1466
+ success(session ? { topic: session.topic, namespaces: session.namespaces } : null);
1467
+ } catch (e) {
1468
+ failed(e);
1469
+ }
1470
+ return;
1471
+ }
1472
+ if (event.data.method === "walletConnect.request") {
1473
+ this.assertPermissions(iframe, "walletConnect", event);
1474
+ try {
1475
+ if (!this.connector.walletConnect)
1476
+ throw new Error("WalletConnect is not configured");
1477
+ const client = await this.connector.walletConnect;
1478
+ const result = await client.request(event.data.params);
1479
+ success(result);
1480
+ } catch (e) {
1481
+ failed(e);
1482
+ }
1483
+ return;
1484
+ }
1485
+ if (event.data.method === "external") {
1486
+ this.assertPermissions(iframe, "external", event);
1487
+ try {
1488
+ const { entity, key, args } = event.data.params;
1489
+ const obj = entity.split(".").reduce((acc, key2) => acc[key2], window);
1490
+ if (entity === "nightly.near" && key === "signTransaction") {
1491
+ args[0].encode = () => args[0];
1492
+ }
1493
+ const result = typeof obj[key] === "function" ? await obj[key](...args || []) : obj[key];
1494
+ success(result);
1495
+ } catch (e) {
1496
+ failed(e);
1497
+ }
1498
+ return;
1499
+ }
1500
+ if (event.data.method === "open") {
1501
+ this.assertPermissions(iframe, "allowsOpen", event);
1502
+ const tgapp = typeof window !== "undefined" ? window?.Telegram?.WebApp : null;
1503
+ if (tgapp && event.data.params.url.startsWith("https://t.me")) {
1504
+ tgapp.openTelegramLink(event.data.params.url);
1505
+ return;
1506
+ }
1507
+ const panel = window.open(event.data.params.url, "_blank", event.data.params.features);
1508
+ const panelId = panel ? (0, uuid_1.uuid4)() : null;
1509
+ const handler = /* @__PURE__ */ __name((ev) => {
1510
+ const url = (0, url_1.parseUrl)(event.data.params.url);
1511
+ if (url && url.origin === ev.origin) {
1512
+ iframe.postMessage(ev.data);
1513
+ }
1514
+ }, "handler");
1515
+ success(panelId);
1516
+ window.addEventListener("message", handler);
1517
+ if (panel && panelId) {
1518
+ this.activePanels[panelId] = panel;
1519
+ const interval = setInterval(() => {
1520
+ if (!panel?.closed)
1521
+ return;
1522
+ window.removeEventListener("message", handler);
1523
+ const args = { method: "proxy-window:closed", windowId: panelId };
1524
+ delete this.activePanels[panelId];
1525
+ clearInterval(interval);
1526
+ try {
1527
+ iframe.postMessage(args);
1528
+ } catch {
1529
+ }
1530
+ }, 500);
1531
+ }
1532
+ return;
1533
+ }
1534
+ if (event.data.method === "open.nativeApp") {
1535
+ this.assertPermissions(iframe, "allowsOpen", event);
1536
+ const url = (0, url_1.parseUrl)(event.data.params.url);
1537
+ const invalid = ["https", "http", "javascript:", "file:", "data:", "blob:", "about:"];
1538
+ if (!url || invalid.includes(url.protocol)) {
1539
+ failed("Invalid URL");
1540
+ throw new Error("[open.nativeApp] Invalid URL");
1541
+ }
1542
+ const linkIframe = document.createElement("iframe");
1543
+ linkIframe.src = event.data.params.url;
1544
+ linkIframe.style.display = "none";
1545
+ document.body.appendChild(linkIframe);
1546
+ iframe.postMessage({ ...event.data, status: "success", result: null });
1547
+ return;
1548
+ }
1549
+ }, "_onMessage");
1550
+ actualCode = null;
1551
+ async checkNewVersion(executor, currentVersion) {
1552
+ if (this.actualCode) {
1553
+ this.connector.logger?.log(`New version of code already checked`);
1554
+ return this.actualCode;
1555
+ }
1556
+ let url = (0, url_1.parseUrl)(executor.manifest.executor);
1557
+ if (!url)
1558
+ url = (0, url_1.parseUrl)(location.origin + executor.manifest.executor);
1559
+ if (!url)
1560
+ throw new Error("Invalid executor URL");
1561
+ url.searchParams.set("nonce", cacheId);
1562
+ const newVersion = await fetch(url.toString()).then((res) => res.text());
1563
+ this.connector.logger?.log(`New version of code fetched`);
1564
+ this.actualCode = newVersion;
1565
+ if (newVersion === currentVersion) {
1566
+ this.connector.logger?.log(`New version of code is the same as the current version`);
1567
+ return this.actualCode;
1568
+ }
1569
+ await this.connector.db.setItem(`${this.manifest.id}:${this.manifest.version}`, newVersion);
1570
+ this.connector.logger?.log(`New version of code saved to cache`);
1571
+ return newVersion;
1572
+ }
1573
+ async loadCode() {
1574
+ const cachedCode = await this.connector.db.getItem(`${this.manifest.id}:${this.manifest.version}`).catch(() => null);
1575
+ this.connector.logger?.log(`Code loaded from cache`, cachedCode !== null);
1576
+ const task = this.checkNewVersion(this, cachedCode);
1577
+ if (cachedCode)
1578
+ return cachedCode;
1579
+ return await task;
1580
+ }
1581
+ async call(method, params) {
1582
+ if (params?.signerId) {
1583
+ localStorage.setItem(`${this.storageSpace}:signedAccountId`, params.signerId);
1584
+ }
1585
+ this.connector.logger?.log(`Add to queue`, method, params);
1586
+ this.connector.logger?.log(`Calling method`, method, params);
1587
+ const code = await this.loadCode();
1588
+ this.connector.logger?.log(`Code loaded, preparing`);
1589
+ const iframe = new iframe_1.default(this, code, this._onMessage);
1590
+ this.connector.logger?.log(`Code loaded, iframe initialized`);
1591
+ await iframe.readyPromise;
1592
+ this.connector.logger?.log(`Iframe ready`);
1593
+ const id = (0, uuid_1.uuid4)();
1594
+ return new Promise((resolve, reject) => {
1595
+ try {
1596
+ const handler = /* @__PURE__ */ __name((event) => {
1597
+ if (event.data.id !== id || event.data.origin !== iframe.origin)
1598
+ return;
1599
+ iframe.dispose();
1600
+ window.removeEventListener("message", handler);
1601
+ this.connector.logger?.log("postMessage", { result: event.data, request: { method, params } });
1602
+ if (event.data.status === "failed")
1603
+ reject(event.data.result);
1604
+ else
1605
+ resolve(event.data.result);
1606
+ }, "handler");
1607
+ window.addEventListener("message", handler);
1608
+ iframe.postMessage({ method, params, id });
1609
+ iframe.on("close", () => reject(new Error("Wallet closed")));
1610
+ } catch (e) {
1611
+ this.connector.logger?.log(`Iframe error`, e);
1612
+ reject(e);
1613
+ }
1614
+ });
1615
+ }
1616
+ async getAllStorage() {
1617
+ const keys = Object.keys(localStorage).filter((key) => key.startsWith(`${this.storageSpace}:`));
1618
+ const storage = {};
1619
+ for (const key of keys) {
1620
+ storage[key.replace(`${this.storageSpace}:`, "")] = localStorage.getItem(key);
1621
+ }
1622
+ return storage;
1623
+ }
1624
+ async clearStorage() {
1625
+ const keys = Object.keys(localStorage).filter((key) => key.startsWith(`${this.storageSpace}:`));
1626
+ for (const key of keys) {
1627
+ localStorage.removeItem(key);
1628
+ }
1629
+ }
1630
+ };
1631
+ exports.default = SandboxExecutor;
1632
+ }
1633
+ });
1634
+
1635
+ // ../../node_modules/@fastnear/near-connect/build/SandboxedWallet/index.js
1636
+ var require_SandboxedWallet = __commonJS({
1637
+ "../../node_modules/@fastnear/near-connect/build/SandboxedWallet/index.js"(exports) {
1638
+ "use strict";
1639
+ var __importDefault = exports && exports.__importDefault || function(mod) {
1640
+ return mod && mod.__esModule ? mod : { "default": mod };
1641
+ };
1642
+ Object.defineProperty(exports, "__esModule", { value: true });
1643
+ exports.SandboxWallet = void 0;
1644
+ var actions_1 = require_actions();
1645
+ var executor_1 = __importDefault(require_executor());
1646
+ var SandboxWallet = class {
1647
+ static {
1648
+ __name(this, "SandboxWallet");
1649
+ }
1650
+ connector;
1651
+ manifest;
1652
+ executor;
1653
+ constructor(connector2, manifest) {
1654
+ this.connector = connector2;
1655
+ this.manifest = manifest;
1656
+ this.executor = new executor_1.default(connector2, manifest);
1657
+ }
1658
+ async signIn(data) {
1659
+ return this.executor.call("wallet:signIn", {
1660
+ network: data?.network || this.connector.network,
1661
+ contractId: data?.contractId,
1662
+ methodNames: data?.methodNames
1663
+ });
1664
+ }
1665
+ async signInAndSignMessage(data) {
1666
+ return this.executor.call("wallet:signInAndSignMessage", {
1667
+ network: data?.network || this.connector.network,
1668
+ contractId: data?.contractId,
1669
+ methodNames: data?.methodNames,
1670
+ messageParams: data.messageParams
1671
+ });
1672
+ }
1673
+ async signOut(data) {
1674
+ const args = { ...data, network: data?.network || this.connector.network };
1675
+ await this.executor.call("wallet:signOut", args);
1676
+ await this.executor.clearStorage();
1677
+ }
1678
+ async getAccounts(data) {
1679
+ const args = { ...data, network: data?.network || this.connector.network };
1680
+ return this.executor.call("wallet:getAccounts", args);
1681
+ }
1682
+ async signAndSendTransaction(params) {
1683
+ const actions = (0, actions_1.nearActionsToConnectorActions)(params.actions);
1684
+ const args = { ...params, actions, network: params.network || this.connector.network };
1685
+ return this.executor.call("wallet:signAndSendTransaction", args);
1686
+ }
1687
+ async signAndSendTransactions(params) {
1688
+ const transactions = params.transactions.map((transaction) => ({
1689
+ actions: (0, actions_1.nearActionsToConnectorActions)(transaction.actions),
1690
+ receiverId: transaction.receiverId
1691
+ }));
1692
+ const args = { ...params, transactions, network: params.network || this.connector.network };
1693
+ return this.executor.call("wallet:signAndSendTransactions", args);
1694
+ }
1695
+ async signMessage(params) {
1696
+ const args = { ...params, network: params.network || this.connector.network };
1697
+ return this.executor.call("wallet:signMessage", args);
1698
+ }
1699
+ async signDelegateActions(params) {
1700
+ const args = {
1701
+ ...params,
1702
+ delegateActions: params.delegateActions.map((delegateAction) => ({
1703
+ ...delegateAction,
1704
+ actions: (0, actions_1.nearActionsToConnectorActions)(delegateAction.actions)
1705
+ })),
1706
+ network: params.network || this.connector.network
1707
+ };
1708
+ return this.executor.call("wallet:signDelegateActions", args);
1709
+ }
1710
+ };
1711
+ exports.SandboxWallet = SandboxWallet;
1712
+ exports.default = SandboxWallet;
1713
+ }
1714
+ });
1715
+
1716
+ // ../../node_modules/@fastnear/near-connect/build/InjectedWallet.js
1717
+ var require_InjectedWallet = __commonJS({
1718
+ "../../node_modules/@fastnear/near-connect/build/InjectedWallet.js"(exports) {
1719
+ "use strict";
1720
+ Object.defineProperty(exports, "__esModule", { value: true });
1721
+ exports.InjectedWallet = void 0;
1722
+ var actions_1 = require_actions();
1723
+ var InjectedWallet = class {
1724
+ static {
1725
+ __name(this, "InjectedWallet");
1726
+ }
1727
+ connector;
1728
+ wallet;
1729
+ constructor(connector2, wallet) {
1730
+ this.connector = connector2;
1731
+ this.wallet = wallet;
1732
+ }
1733
+ get manifest() {
1734
+ return this.wallet.manifest;
1735
+ }
1736
+ async signIn(data) {
1737
+ return this.wallet.signIn({
1738
+ network: data?.network || this.connector.network,
1739
+ contractId: data?.contractId,
1740
+ methodNames: data?.methodNames
1741
+ });
1742
+ }
1743
+ async signInAndSignMessage(data) {
1744
+ return this.wallet.signInAndSignMessage({
1745
+ network: data?.network || this.connector.network,
1746
+ contractId: data?.contractId,
1747
+ methodNames: data?.methodNames,
1748
+ messageParams: data.messageParams
1749
+ });
1750
+ }
1751
+ async signOut(data) {
1752
+ await this.wallet.signOut({ network: data?.network || this.connector.network });
1753
+ }
1754
+ async getAccounts(data) {
1755
+ return this.wallet.getAccounts({ network: data?.network || this.connector.network });
1756
+ }
1757
+ async signAndSendTransaction(params) {
1758
+ const actions = (0, actions_1.nearActionsToConnectorActions)(params.actions);
1759
+ const network = params.network || this.connector.network;
1760
+ const result = await this.wallet.signAndSendTransaction({ ...params, actions, network });
1761
+ if (!result)
1762
+ throw new Error("No result from wallet");
1763
+ if (Array.isArray(result.transactions))
1764
+ return result.transactions[0];
1765
+ return result;
1766
+ }
1767
+ async signAndSendTransactions(params) {
1768
+ const network = params.network || this.connector.network;
1769
+ const transactions = params.transactions.map((transaction) => ({
1770
+ actions: (0, actions_1.nearActionsToConnectorActions)(transaction.actions),
1771
+ receiverId: transaction.receiverId
1772
+ }));
1773
+ const result = await this.wallet.signAndSendTransactions({ ...params, transactions, network });
1774
+ if (!result)
1775
+ throw new Error("No result from wallet");
1776
+ if (Array.isArray(result.transactions))
1777
+ return result.transactions;
1778
+ return result;
1779
+ }
1780
+ async signMessage(params) {
1781
+ return this.wallet.signMessage({ ...params, network: params.network || this.connector.network });
1782
+ }
1783
+ async signDelegateActions(params) {
1784
+ return this.wallet.signDelegateActions({
1785
+ ...params,
1786
+ delegateActions: params.delegateActions.map((delegateAction) => ({
1787
+ ...delegateAction,
1788
+ actions: (0, actions_1.nearActionsToConnectorActions)(delegateAction.actions)
1789
+ })),
1790
+ network: params.network || this.connector.network
1791
+ });
1792
+ }
1793
+ };
1794
+ exports.InjectedWallet = InjectedWallet;
1795
+ }
1796
+ });
1797
+
1798
+ // ../../node_modules/@fastnear/near-connect/build/popups/NearWalletsPopup.js
1799
+ var require_NearWalletsPopup = __commonJS({
1800
+ "../../node_modules/@fastnear/near-connect/build/popups/NearWalletsPopup.js"(exports) {
1801
+ "use strict";
1802
+ Object.defineProperty(exports, "__esModule", { value: true });
1803
+ exports.NearWalletsPopup = void 0;
1804
+ var html_1 = require_html();
1805
+ var url_1 = require_url();
1806
+ var Popup_1 = require_Popup();
1807
+ var debugManifest = {
1808
+ id: "custom-wallet",
1809
+ name: "Custom Wallet",
1810
+ icon: "https://www.mynearwallet.com/images/webclip.png",
1811
+ description: "Custom wallet for NEAR.",
1812
+ website: "",
1813
+ version: "1.0.0",
1814
+ executor: "your-executor-url.js",
1815
+ type: "sandbox",
1816
+ platform: {},
1817
+ features: {
1818
+ signMessage: true,
1819
+ signInWithoutAddKey: true,
1820
+ signInAndSignMessage: true,
1821
+ signAndSendTransaction: true,
1822
+ signAndSendTransactions: true,
1823
+ signDelegateActions: true
1824
+ },
1825
+ permissions: {
1826
+ storage: true,
1827
+ allowsOpen: []
1828
+ }
1829
+ };
1830
+ var NearWalletsPopup = class extends Popup_1.Popup {
1831
+ static {
1832
+ __name(this, "NearWalletsPopup");
1833
+ }
1834
+ delegate;
1835
+ constructor(delegate) {
1836
+ super(delegate);
1837
+ this.delegate = delegate;
1838
+ this.update({ wallets: delegate.wallets, showSettings: false });
1839
+ }
1840
+ handlers() {
1841
+ super.handlers();
1842
+ this.addListener(".settings-button", "click", () => this.update({ showSettings: true }));
1843
+ this.addListener(".back-button", "click", () => this.update({ showSettings: false }));
1844
+ this.root.querySelectorAll(".connect-item").forEach((item) => {
1845
+ if (!(item instanceof HTMLDivElement))
1846
+ return;
1847
+ this.addListener(item, "click", () => this.delegate.onSelect(item.dataset.type));
1848
+ });
1849
+ this.root.querySelectorAll(".remove-wallet-button").forEach((item) => {
1850
+ if (!(item instanceof SVGSVGElement))
1851
+ return;
1852
+ this.addListener(item, "click", async (e) => {
1853
+ e.stopPropagation();
1854
+ await this.delegate.onRemoveDebugManifest(item.dataset.type);
1855
+ const wallets = this.state.wallets.filter((wallet) => wallet.id !== item.dataset.type);
1856
+ this.update({ wallets });
1857
+ });
1858
+ });
1859
+ this.addListener(".add-debug-manifest-button", "click", async () => {
1860
+ try {
1861
+ const wallet = this.root.querySelector("#debug-manifest-input")?.value ?? "";
1862
+ const manifest = await this.delegate.onAddDebugManifest(wallet);
1863
+ this.update({ showSettings: false, wallets: [manifest, ...this.state.wallets] });
1864
+ } catch (error) {
1865
+ alert(`Something went wrong: ${error}`);
1866
+ }
1867
+ });
1868
+ }
1869
+ create() {
1870
+ super.create({ show: true });
1871
+ }
1872
+ walletDom(wallet) {
1873
+ const removeButton = (0, html_1.html)`
1874
+ <svg
1875
+ class="remove-wallet-button"
1876
+ data-type="${wallet.id}"
1877
+ width="24"
1878
+ height="24"
1879
+ viewBox="0 0 24 24"
1880
+ fill="none"
1881
+ xmlns="http://www.w3.org/2000/svg"
1882
+ style="margin-right: 4px;"
1883
+ >
1884
+ <path d="M18 6L6 18" stroke="rgba(255,255,255,0.5)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
1885
+ <path d="M6 6L18 18" stroke="rgba(255,255,255,0.5)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
1886
+ </svg>
1887
+ `;
1888
+ return (0, html_1.html)`
1889
+ <div class="connect-item" data-type="${wallet.id}">
1890
+ <img style="background: #333" src="${wallet.icon}" alt="${wallet.name}" />
1891
+ <div class="connect-item-info">
1892
+ <span>${wallet.name}</span>
1893
+ <span class="wallet-address">${(0, url_1.parseUrl)(wallet.website)?.hostname}</span>
1894
+ </div>
1895
+ ${wallet.debug ? removeButton : ""}
1896
+ </div>
1897
+ `;
1898
+ }
1899
+ get footer() {
1900
+ if (!this.delegate.footer)
1901
+ return "";
1902
+ const { icon, heading, link, linkText } = this.delegate.footer;
1903
+ return (0, html_1.html)`
1904
+ <div class="footer">
1905
+ ${icon ? (0, html_1.html)`<img src="${icon}" alt="${heading}" />` : ""}
1906
+ <p>${heading}</p>
1907
+ <a class="get-wallet-link" href="${link}" target="_blank">${linkText}</a>
1908
+ </div>
1909
+ `;
1910
+ }
1911
+ get dom() {
1912
+ if (this.state.showSettings) {
1913
+ return (0, html_1.html)`
1914
+ <div class="modal-container">
1915
+ <div class="modal-content">
1916
+ <div class="modal-header">
1917
+ <button class="back-button" style="left: 16px; right: unset;">
1918
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
1919
+ <path d="M15 18L9 12L15 6" stroke="rgba(255,255,255,0.5)" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />
1920
+ </svg>
1921
+ </button>
1922
+ <p>Settings</p>
1923
+ </div>
1924
+
1925
+ <div class="modal-body">
1926
+ <p style="text-align: left;">
1927
+ You can add your wallet to dapp for debug,
1928
+ <a href="https://github.com/azbang/hot-connector" target="_blank">read the documentation.</a> Paste your manifest and click "Add".
1929
+ </p>
1930
+
1931
+ <textarea style="width: 100%;" id="debug-manifest-input" rows="10">${JSON.stringify(debugManifest, null, 2)}</textarea>
1932
+ <button class="add-debug-manifest-button">Add</button>
1933
+ </div>
1934
+
1935
+ ${this.footer}
1936
+ </div>
1937
+ </div>
1938
+ `;
1939
+ }
1940
+ return (0, html_1.html)`<div class="modal-container">
1941
+ <div class="modal-content">
1942
+ <div class="modal-header">
1943
+ <p>Select wallet</p>
1944
+ <button class="settings-button">
1945
+ <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
1946
+ <circle cx="12" cy="12" r="2" fill="rgba(255,255,255,0.5)" />
1947
+ <circle cx="19" cy="12" r="2" fill="rgba(255,255,255,0.5)" />
1948
+ <circle cx="5" cy="12" r="2" fill="rgba(255,255,255,0.5)" />
1949
+ </svg>
1950
+ </button>
1951
+ </div>
1952
+
1953
+ <div class="modal-body">${this.state.wallets.map((wallet) => this.walletDom(wallet))}</div>
1954
+
1955
+ ${this.footer}
1956
+ </div>
1957
+ </div>`;
1958
+ }
1959
+ };
1960
+ exports.NearWalletsPopup = NearWalletsPopup;
1961
+ }
1962
+ });
1963
+
1964
+ // ../../node_modules/@fastnear/near-connect/build/helpers/indexdb.js
1965
+ var require_indexdb = __commonJS({
1966
+ "../../node_modules/@fastnear/near-connect/build/helpers/indexdb.js"(exports) {
1967
+ "use strict";
1968
+ Object.defineProperty(exports, "__esModule", { value: true });
1969
+ var IndexedDB = class {
1970
+ static {
1971
+ __name(this, "IndexedDB");
1972
+ }
1973
+ dbName;
1974
+ storeName;
1975
+ version;
1976
+ constructor(dbName, storeName) {
1977
+ this.dbName = dbName;
1978
+ this.storeName = storeName;
1979
+ this.version = 1;
1980
+ }
1981
+ getDb() {
1982
+ return new Promise((resolve, reject) => {
1983
+ if (typeof window === "undefined" || typeof indexedDB === "undefined") {
1984
+ reject(new Error("IndexedDB is not available (SSR environment)"));
1985
+ return;
1986
+ }
1987
+ const request = indexedDB.open(this.dbName, this.version);
1988
+ request.onerror = (event) => {
1989
+ console.error("Error opening database:", event.target.error);
1990
+ reject(new Error("Error opening database"));
1991
+ };
1992
+ request.onsuccess = (event) => {
1993
+ resolve(request.result);
1994
+ };
1995
+ request.onupgradeneeded = (event) => {
1996
+ const db = request.result;
1997
+ const existingStores = db.objectStoreNames;
1998
+ if (!existingStores.contains(this.storeName)) {
1999
+ db.createObjectStore(this.storeName);
2000
+ }
2001
+ };
2002
+ });
2003
+ }
2004
+ async getItem(key) {
2005
+ const db = await this.getDb();
2006
+ if (typeof key === "number") {
2007
+ key = key.toString();
2008
+ }
2009
+ if (typeof key !== "string") {
2010
+ throw new Error("Key must be a string");
2011
+ }
2012
+ return new Promise((resolve, reject) => {
2013
+ if (!this.storeName) {
2014
+ reject(new Error("Store name not set"));
2015
+ return;
2016
+ }
2017
+ const transaction = db.transaction(this.storeName, "readonly");
2018
+ transaction.onerror = (event) => reject(transaction.error);
2019
+ const store = transaction.objectStore(this.storeName);
2020
+ const request = store.get(key);
2021
+ request.onerror = (event) => reject(request.error);
2022
+ request.onsuccess = () => {
2023
+ resolve(request.result);
2024
+ db.close();
2025
+ };
2026
+ });
2027
+ }
2028
+ async setItem(key, value) {
2029
+ const db = await this.getDb();
2030
+ if (typeof key === "number") {
2031
+ key = key.toString();
2032
+ }
2033
+ if (typeof key !== "string") {
2034
+ throw new Error("Key must be a string");
2035
+ }
2036
+ return new Promise((resolve, reject) => {
2037
+ if (!this.storeName) {
2038
+ reject(new Error("Store name not set"));
2039
+ return;
2040
+ }
2041
+ const transaction = db.transaction(this.storeName, "readwrite");
2042
+ transaction.onerror = (event) => reject(transaction.error);
2043
+ const store = transaction.objectStore(this.storeName);
2044
+ const request = store.put(value, key);
2045
+ request.onerror = (event) => reject(request.error);
2046
+ request.onsuccess = () => {
2047
+ db.close();
2048
+ resolve();
2049
+ };
2050
+ });
2051
+ }
2052
+ async removeItem(key) {
2053
+ const db = await this.getDb();
2054
+ if (typeof key === "number") {
2055
+ key = key.toString();
2056
+ }
2057
+ if (typeof key !== "string") {
2058
+ throw new Error("Key must be a string");
2059
+ }
2060
+ return new Promise((resolve, reject) => {
2061
+ if (!this.storeName) {
2062
+ reject(new Error("Store name not set"));
2063
+ return;
2064
+ }
2065
+ const transaction = db.transaction(this.storeName, "readwrite");
2066
+ transaction.onerror = (event) => reject(transaction.error);
2067
+ const store = transaction.objectStore(this.storeName);
2068
+ const request = store.delete(key);
2069
+ request.onerror = (event) => reject(request.error);
2070
+ request.onsuccess = () => {
2071
+ db.close();
2072
+ resolve();
2073
+ };
2074
+ });
2075
+ }
2076
+ async keys() {
2077
+ const db = await this.getDb();
2078
+ return new Promise((resolve, reject) => {
2079
+ if (!this.storeName) {
2080
+ reject(new Error("Store name not set"));
2081
+ return;
2082
+ }
2083
+ const transaction = db.transaction(this.storeName, "readonly");
2084
+ transaction.onerror = (event) => reject(transaction.error);
2085
+ const store = transaction.objectStore(this.storeName);
2086
+ const request = store.getAllKeys();
2087
+ request.onerror = (event) => reject(request.error);
2088
+ request.onsuccess = () => {
2089
+ resolve(request.result);
2090
+ db.close();
2091
+ };
2092
+ });
2093
+ }
2094
+ async count() {
2095
+ const db = await this.getDb();
2096
+ return new Promise((resolve, reject) => {
2097
+ if (!this.storeName) {
2098
+ reject(new Error("Store name not set"));
2099
+ return;
2100
+ }
2101
+ const transaction = db.transaction(this.storeName, "readonly");
2102
+ transaction.onerror = (event) => reject(transaction.error);
2103
+ const store = transaction.objectStore(this.storeName);
2104
+ const request = store.count();
2105
+ request.onerror = (event) => reject(request.error);
2106
+ request.onsuccess = () => {
2107
+ resolve(request.result);
2108
+ db.close();
2109
+ };
2110
+ });
2111
+ }
2112
+ async length() {
2113
+ return this.count();
2114
+ }
2115
+ async clear() {
2116
+ const db = await this.getDb();
2117
+ return new Promise((resolve, reject) => {
2118
+ if (!this.storeName) {
2119
+ reject(new Error("Store name not set"));
2120
+ return;
2121
+ }
2122
+ const transaction = db.transaction(this.storeName, "readwrite");
2123
+ transaction.onerror = (event) => reject(transaction.error);
2124
+ const store = transaction.objectStore(this.storeName);
2125
+ const request = store.clear();
2126
+ request.onerror = (event) => reject(request.error);
2127
+ request.onsuccess = () => {
2128
+ db.close();
2129
+ resolve();
2130
+ };
2131
+ });
2132
+ }
2133
+ };
2134
+ exports.default = IndexedDB;
2135
+ }
2136
+ });
2137
+
2138
+ // ../../node_modules/@fastnear/near-connect/build/NearConnector.js
2139
+ var require_NearConnector = __commonJS({
2140
+ "../../node_modules/@fastnear/near-connect/build/NearConnector.js"(exports) {
2141
+ "use strict";
2142
+ var __importDefault = exports && exports.__importDefault || function(mod) {
2143
+ return mod && mod.__esModule ? mod : { "default": mod };
2144
+ };
2145
+ Object.defineProperty(exports, "__esModule", { value: true });
2146
+ exports.NearConnector = void 0;
2147
+ var events_1 = require_events();
2148
+ var NearWalletsPopup_1 = require_NearWalletsPopup();
2149
+ var storage_1 = require_storage();
2150
+ var indexdb_1 = __importDefault(require_indexdb());
2151
+ var ParentFrameWallet_1 = require_ParentFrameWallet();
2152
+ var InjectedWallet_1 = require_InjectedWallet();
2153
+ var SandboxedWallet_1 = require_SandboxedWallet();
2154
+ var defaultManifests = [
2155
+ "https://raw.githubusercontent.com/fastnear/near-connect/refs/heads/main/repository/manifest.json",
2156
+ "https://cdn.jsdelivr.net/gh/fastnear/near-connect/repository/manifest.json"
2157
+ ];
2158
+ function createFilterForWalletFeatures(features) {
2159
+ return (wallet) => {
2160
+ return Object.entries(features).every(([key, value]) => {
2161
+ if (value && !wallet.manifest.features?.[key])
2162
+ return false;
2163
+ return true;
2164
+ });
2165
+ };
2166
+ }
2167
+ __name(createFilterForWalletFeatures, "createFilterForWalletFeatures");
2168
+ var NearConnector2 = class {
2169
+ static {
2170
+ __name(this, "NearConnector");
2171
+ }
2172
+ storage;
2173
+ events;
2174
+ db;
2175
+ logger;
2176
+ wallets = [];
2177
+ manifest = { wallets: [], version: "1.0.0" };
2178
+ features = {};
2179
+ network = "mainnet";
2180
+ providers = { mainnet: [], testnet: [] };
2181
+ signInData;
2182
+ walletConnect;
2183
+ footerBranding;
2184
+ excludedWallets = [];
2185
+ autoConnect;
2186
+ whenManifestLoaded;
2187
+ constructor(options) {
2188
+ this.db = new indexdb_1.default("hot-connector", "wallets");
2189
+ this.storage = options?.storage ?? new storage_1.LocalStorage();
2190
+ this.events = options?.events ?? new events_1.EventEmitter();
2191
+ this.logger = options?.logger;
2192
+ this.network = options?.network ?? "mainnet";
2193
+ this.walletConnect = options?.walletConnect;
2194
+ this.autoConnect = options?.autoConnect ?? true;
2195
+ this.providers = options?.providers ?? { mainnet: [], testnet: [] };
2196
+ this.excludedWallets = options?.excludedWallets ?? [];
2197
+ this.features = options?.features ?? {};
2198
+ this.signInData = options?.signIn;
2199
+ if (options?.footerBranding !== void 0) {
2200
+ this.footerBranding = options?.footerBranding;
2201
+ } else {
2202
+ this.footerBranding = {
2203
+ icon: "https://pages.near.org/wp-content/uploads/2023/11/NEAR_token.png",
2204
+ heading: "NEAR Connector",
2205
+ link: "https://wallet.near.org",
2206
+ linkText: "Don't have a wallet?"
2207
+ };
2208
+ }
2209
+ this.whenManifestLoaded = new Promise(async (resolve) => {
2210
+ if (options?.manifest == null || typeof options.manifest === "string") {
2211
+ this.manifest = await this._loadManifest(options?.manifest).catch(() => ({ wallets: [], version: "1.0.0" }));
2212
+ } else {
2213
+ this.manifest = options?.manifest ?? { wallets: [], version: "1.0.0" };
2214
+ }
2215
+ const set = new Set(this.excludedWallets);
2216
+ set.delete("hot-wallet");
2217
+ this.manifest.wallets = this.manifest.wallets.filter((wallet) => {
2218
+ if (wallet.permissions.walletConnect && !this.walletConnect)
2219
+ return false;
2220
+ if (set.has(wallet.id))
2221
+ return false;
2222
+ return true;
2223
+ });
2224
+ await new Promise((resolve2) => setTimeout(resolve2, 100));
2225
+ resolve();
2226
+ });
2227
+ if (typeof window !== "undefined") {
2228
+ window.addEventListener("near-wallet-injected", this._handleNearWalletInjected);
2229
+ window.dispatchEvent(new Event("near-selector-ready"));
2230
+ window.addEventListener("message", async (event) => {
2231
+ if (event.data.type === "near-wallet-injected") {
2232
+ await this.whenManifestLoaded.catch(() => {
2233
+ });
2234
+ this.wallets = this.wallets.filter((wallet) => wallet.manifest.id !== event.data.manifest.id);
2235
+ this.wallets.unshift(new ParentFrameWallet_1.ParentFrameWallet(this, event.data.manifest));
2236
+ this.events.emit("selector:walletsChanged", {});
2237
+ if (this.autoConnect) {
2238
+ this.connect({ walletId: event.data.manifest.id });
2239
+ }
2240
+ }
2241
+ });
2242
+ }
2243
+ this.whenManifestLoaded.then(() => {
2244
+ if (typeof window !== "undefined") {
2245
+ window.parent.postMessage({ type: "near-selector-ready" }, "*");
2246
+ }
2247
+ this.manifest.wallets.forEach((wallet) => this.registerWallet(wallet));
2248
+ this.storage.get("debug-wallets").then((json) => {
2249
+ const debugWallets = JSON.parse(json ?? "[]");
2250
+ debugWallets.forEach((wallet) => this.registerDebugWallet(wallet));
2251
+ });
2252
+ });
2253
+ }
2254
+ get availableWallets() {
2255
+ const wallets = this.wallets.filter((wallet) => {
2256
+ return Object.entries(this.features).every(([key, value]) => {
2257
+ if (value && !wallet.manifest.features?.[key])
2258
+ return false;
2259
+ return true;
2260
+ });
2261
+ });
2262
+ return wallets.filter((wallet) => {
2263
+ if (this.network === "testnet" && !wallet.manifest.features?.testnet)
2264
+ return false;
2265
+ return true;
2266
+ });
2267
+ }
2268
+ _handleNearWalletInjected = /* @__PURE__ */ __name((event) => {
2269
+ this.wallets = this.wallets.filter((wallet) => wallet.manifest.id !== event.detail.manifest.id);
2270
+ this.wallets.unshift(new InjectedWallet_1.InjectedWallet(this, event.detail));
2271
+ this.events.emit("selector:walletsChanged", {});
2272
+ }, "_handleNearWalletInjected");
2273
+ async _loadManifest(manifestUrl) {
2274
+ const manifestEndpoints = manifestUrl ? [manifestUrl] : defaultManifests;
2275
+ for (const endpoint of manifestEndpoints) {
2276
+ const res = await fetch(endpoint).catch(() => null);
2277
+ if (!res || !res.ok)
2278
+ continue;
2279
+ return await res.json();
2280
+ }
2281
+ throw new Error("Failed to load manifest");
2282
+ }
2283
+ async switchNetwork(network, signInData) {
2284
+ if (this.network === network)
2285
+ return;
2286
+ await this.disconnect().catch(() => {
2287
+ });
2288
+ if (signInData)
2289
+ this.signInData = signInData;
2290
+ this.network = network;
2291
+ await this.connect();
2292
+ }
2293
+ async registerWallet(manifest) {
2294
+ if (manifest.type !== "sandbox")
2295
+ throw new Error("Only sandbox wallets are supported");
2296
+ if (this.wallets.find((wallet) => wallet.manifest.id === manifest.id))
2297
+ return;
2298
+ this.wallets.push(new SandboxedWallet_1.SandboxWallet(this, manifest));
2299
+ this.events.emit("selector:walletsChanged", {});
2300
+ }
2301
+ async registerDebugWallet(json) {
2302
+ const manifest = typeof json === "string" ? JSON.parse(json) : json;
2303
+ if (manifest.type !== "sandbox")
2304
+ throw new Error("Only sandbox wallets type are supported");
2305
+ if (!manifest.id)
2306
+ throw new Error("Manifest must have an id");
2307
+ if (!manifest.name)
2308
+ throw new Error("Manifest must have a name");
2309
+ if (!manifest.icon)
2310
+ throw new Error("Manifest must have an icon");
2311
+ if (!manifest.website)
2312
+ throw new Error("Manifest must have a website");
2313
+ if (!manifest.version)
2314
+ throw new Error("Manifest must have a version");
2315
+ if (!manifest.executor)
2316
+ throw new Error("Manifest must have an executor");
2317
+ if (!manifest.features)
2318
+ throw new Error("Manifest must have features");
2319
+ if (!manifest.permissions)
2320
+ throw new Error("Manifest must have permissions");
2321
+ if (this.wallets.find((wallet) => wallet.manifest.id === manifest.id))
2322
+ throw new Error("Wallet already registered");
2323
+ manifest.debug = true;
2324
+ this.wallets.unshift(new SandboxedWallet_1.SandboxWallet(this, manifest));
2325
+ this.events.emit("selector:walletsChanged", {});
2326
+ const debugWallets = this.wallets.filter((wallet) => wallet.manifest.debug).map((wallet) => wallet.manifest);
2327
+ this.storage.set("debug-wallets", JSON.stringify(debugWallets));
2328
+ return manifest;
2329
+ }
2330
+ async removeDebugWallet(id) {
2331
+ this.wallets = this.wallets.filter((wallet) => wallet.manifest.id !== id);
2332
+ const debugWallets = this.wallets.filter((wallet) => wallet.manifest.debug).map((wallet) => wallet.manifest);
2333
+ this.storage.set("debug-wallets", JSON.stringify(debugWallets));
2334
+ this.events.emit("selector:walletsChanged", {});
2335
+ }
2336
+ async selectWallet({ features = {} } = {}) {
2337
+ await this.whenManifestLoaded.catch(() => {
2338
+ });
2339
+ return new Promise((resolve, reject) => {
2340
+ const popup = new NearWalletsPopup_1.NearWalletsPopup({
2341
+ footer: this.footerBranding,
2342
+ wallets: this.availableWallets.filter(createFilterForWalletFeatures(features)).map((wallet) => wallet.manifest),
2343
+ onRemoveDebugManifest: /* @__PURE__ */ __name(async (id) => this.removeDebugWallet(id), "onRemoveDebugManifest"),
2344
+ onAddDebugManifest: /* @__PURE__ */ __name(async (wallet) => this.registerDebugWallet(wallet), "onAddDebugManifest"),
2345
+ onReject: /* @__PURE__ */ __name(() => (reject(new Error("User rejected")), popup.destroy()), "onReject"),
2346
+ onSelect: /* @__PURE__ */ __name((id) => (resolve(id), popup.destroy()), "onSelect")
2347
+ });
2348
+ popup.create();
2349
+ });
2350
+ }
2351
+ async connect(input = {}) {
2352
+ let walletId = input.walletId;
2353
+ const signMessageParams = input.signMessageParams;
2354
+ await this.whenManifestLoaded.catch(() => {
2355
+ });
2356
+ if (!walletId)
2357
+ walletId = await this.selectWallet(input.signMessageParams != null ? { features: { signInAndSignMessage: true } } : void 0);
2358
+ try {
2359
+ const wallet = await this.wallet(walletId);
2360
+ this.logger?.log(`Wallet available to connect`, wallet);
2361
+ await this.storage.set("selected-wallet", walletId);
2362
+ this.logger?.log(`Set preferred wallet, try to signIn${signMessageParams != null ? " (with signed message)" : ""}`, walletId);
2363
+ if (signMessageParams != null) {
2364
+ const accounts = await wallet.signInAndSignMessage({
2365
+ contractId: this.signInData?.contractId,
2366
+ methodNames: this.signInData?.methodNames,
2367
+ messageParams: signMessageParams,
2368
+ network: this.network
2369
+ });
2370
+ if (!accounts?.length)
2371
+ throw new Error("Failed to sign in");
2372
+ this.logger?.log(`Signed in to wallet (with signed message)`, walletId, accounts);
2373
+ this.events.emit("wallet:signInAndSignMessage", { wallet, accounts, success: true });
2374
+ this.events.emit("wallet:signIn", {
2375
+ wallet,
2376
+ accounts: accounts.map((account) => ({
2377
+ accountId: account.accountId,
2378
+ publicKey: account.publicKey
2379
+ })),
2380
+ success: true,
2381
+ source: "signInAndSignMessage"
2382
+ });
2383
+ } else {
2384
+ const accounts = await wallet.signIn({
2385
+ contractId: this.signInData?.contractId,
2386
+ methodNames: this.signInData?.methodNames,
2387
+ network: this.network
2388
+ });
2389
+ if (!accounts?.length)
2390
+ throw new Error("Failed to sign in");
2391
+ this.logger?.log(`Signed in to wallet`, walletId, accounts);
2392
+ this.events.emit("wallet:signIn", { wallet, accounts, success: true, source: "signIn" });
2393
+ }
2394
+ return wallet;
2395
+ } catch (e) {
2396
+ this.logger?.log("Failed to connect to wallet", e);
2397
+ throw e;
2398
+ }
2399
+ }
2400
+ async disconnect(wallet) {
2401
+ if (!wallet)
2402
+ wallet = await this.wallet();
2403
+ await wallet.signOut({ network: this.network });
2404
+ await this.storage.remove("selected-wallet");
2405
+ this.events.emit("wallet:signOut", { success: true });
2406
+ }
2407
+ async getConnectedWallet() {
2408
+ await this.whenManifestLoaded.catch(() => {
2409
+ });
2410
+ const id = await this.storage.get("selected-wallet");
2411
+ const wallet = this.wallets.find((wallet2) => wallet2.manifest.id === id);
2412
+ if (!wallet)
2413
+ throw new Error("No wallet selected");
2414
+ const accounts = await wallet.getAccounts();
2415
+ if (!accounts?.length)
2416
+ throw new Error("No accounts found");
2417
+ return { wallet, accounts };
2418
+ }
2419
+ async wallet(id) {
2420
+ await this.whenManifestLoaded.catch(() => {
2421
+ });
2422
+ if (!id) {
2423
+ return this.getConnectedWallet().then(({ wallet: wallet2 }) => wallet2).catch(async () => {
2424
+ await this.storage.remove("selected-wallet");
2425
+ throw new Error("No accounts found");
2426
+ });
2427
+ }
2428
+ const wallet = this.wallets.find((wallet2) => wallet2.manifest.id === id);
2429
+ if (!wallet)
2430
+ throw new Error("Wallet not found");
2431
+ return wallet;
2432
+ }
2433
+ async use(plugin) {
2434
+ await this.whenManifestLoaded.catch(() => {
2435
+ });
2436
+ this.wallets = this.wallets.map((wallet) => {
2437
+ return new Proxy(wallet, {
2438
+ get(target, prop, receiver) {
2439
+ const originalValue = Reflect.get(target, prop, receiver);
2440
+ if (prop in plugin && typeof originalValue === "function") {
2441
+ const pluginMethod = plugin[prop];
2442
+ return function(...args) {
2443
+ const next = /* @__PURE__ */ __name(() => originalValue.apply(target, args), "next");
2444
+ return args.length > 0 ? pluginMethod.call(this, ...args, next) : pluginMethod.call(this, void 0, next);
2445
+ };
2446
+ }
2447
+ return originalValue;
2448
+ }
2449
+ });
2450
+ });
2451
+ }
2452
+ on(event, callback) {
2453
+ this.events.on(event, callback);
2454
+ }
2455
+ once(event, callback) {
2456
+ this.events.once(event, callback);
2457
+ }
2458
+ off(event, callback) {
2459
+ this.events.off(event, callback);
2460
+ }
2461
+ removeAllListeners(event) {
2462
+ this.events.removeAllListeners(event);
2463
+ }
2464
+ };
2465
+ exports.NearConnector = NearConnector2;
2466
+ }
2467
+ });
2468
+
2469
+ // ../../node_modules/@fastnear/near-connect/build/index.js
2470
+ var require_build = __commonJS({
2471
+ "../../node_modules/@fastnear/near-connect/build/index.js"(exports) {
2472
+ "use strict";
2473
+ Object.defineProperty(exports, "__esModule", { value: true });
2474
+ exports.nearActionsToConnectorActions = exports.NearConnector = exports.InjectedWallet = exports.SandboxWallet = exports.ParentFrameWallet = exports.LocalStorage = void 0;
2475
+ var storage_1 = require_storage();
2476
+ Object.defineProperty(exports, "LocalStorage", { enumerable: true, get: /* @__PURE__ */ __name(function() {
2477
+ return storage_1.LocalStorage;
2478
+ }, "get") });
2479
+ var ParentFrameWallet_1 = require_ParentFrameWallet();
2480
+ Object.defineProperty(exports, "ParentFrameWallet", { enumerable: true, get: /* @__PURE__ */ __name(function() {
2481
+ return ParentFrameWallet_1.ParentFrameWallet;
2482
+ }, "get") });
2483
+ var SandboxedWallet_1 = require_SandboxedWallet();
2484
+ Object.defineProperty(exports, "SandboxWallet", { enumerable: true, get: /* @__PURE__ */ __name(function() {
2485
+ return SandboxedWallet_1.SandboxWallet;
2486
+ }, "get") });
2487
+ var InjectedWallet_1 = require_InjectedWallet();
2488
+ Object.defineProperty(exports, "InjectedWallet", { enumerable: true, get: /* @__PURE__ */ __name(function() {
2489
+ return InjectedWallet_1.InjectedWallet;
2490
+ }, "get") });
2491
+ var NearConnector_1 = require_NearConnector();
2492
+ Object.defineProperty(exports, "NearConnector", { enumerable: true, get: /* @__PURE__ */ __name(function() {
2493
+ return NearConnector_1.NearConnector;
2494
+ }, "get") });
2495
+ var actions_1 = require_actions();
2496
+ Object.defineProperty(exports, "nearActionsToConnectorActions", { enumerable: true, get: /* @__PURE__ */ __name(function() {
2497
+ return actions_1.nearActionsToConnectorActions;
2498
+ }, "get") });
2499
+ }
2500
+ });
2501
+
2502
+ // src/index.ts
2503
+ var src_exports = {};
2504
+ __export(src_exports, {
2505
+ accountId: () => accountId,
2506
+ availableWallets: () => availableWallets,
2507
+ connect: () => connect,
2508
+ disconnect: () => disconnect,
2509
+ isConnected: () => isConnected,
2510
+ onConnect: () => onConnect,
2511
+ onDisconnect: () => onDisconnect,
2512
+ registerDebugWallet: () => registerDebugWallet,
2513
+ removeDebugWallet: () => removeDebugWallet,
2514
+ reset: () => reset,
2515
+ restore: () => restore,
2516
+ selectWallet: () => selectWallet,
2517
+ sendTransaction: () => sendTransaction,
2518
+ sendTransactions: () => sendTransactions,
2519
+ signMessage: () => signMessage,
2520
+ switchNetwork: () => switchNetwork,
2521
+ walletName: () => walletName
2522
+ });
2523
+
2524
+ // src/connector.ts
2525
+ var import_near_connect = __toESM(require_build(), 1);
2526
+ function toConnectorAction(action) {
2527
+ const { type, ...rest } = action;
2528
+ switch (type) {
2529
+ case "FunctionCall":
2530
+ return { type: "FunctionCall", params: { methodName: rest.methodName, args: rest.args ?? {}, gas: rest.gas ?? "30000000000000", deposit: rest.deposit ?? "0" } };
2531
+ case "Transfer":
2532
+ return { type: "Transfer", params: { deposit: rest.deposit } };
2533
+ case "Stake":
2534
+ return { type: "Stake", params: { stake: rest.stake, publicKey: rest.publicKey } };
2535
+ case "AddKey":
2536
+ return { type: "AddKey", params: { publicKey: rest.publicKey, accessKey: rest.accessKey } };
2537
+ case "DeleteKey":
2538
+ return { type: "DeleteKey", params: { publicKey: rest.publicKey } };
2539
+ case "DeleteAccount":
2540
+ return { type: "DeleteAccount", params: { beneficiaryId: rest.beneficiaryId } };
2541
+ case "CreateAccount":
2542
+ return { type: "CreateAccount" };
2543
+ case "DeployContract":
2544
+ return { type: "DeployContract", params: { code: rest.code ?? rest.codeBase64 } };
2545
+ default:
2546
+ return action;
2547
+ }
2548
+ }
2549
+ __name(toConnectorAction, "toConnectorAction");
2550
+ function toConnectorActions(actions) {
2551
+ return actions.map(toConnectorAction);
2552
+ }
2553
+ __name(toConnectorActions, "toConnectorActions");
2554
+ function isFastnearAction(action) {
2555
+ return action.type && !action.params && action.type !== "CreateAccount";
2556
+ }
2557
+ __name(isFastnearAction, "isFastnearAction");
2558
+ var connector = null;
2559
+ var connectedWallet = null;
2560
+ var currentAccountId = null;
2561
+ var currentNetwork = "mainnet";
2562
+ var connectListeners = [];
2563
+ var disconnectListeners = [];
2564
+ function getOrCreateConnector(options) {
2565
+ if (connector) return connector;
2566
+ const opts = {
2567
+ network: options?.network ?? currentNetwork,
2568
+ footerBranding: options?.footerBranding !== void 0 ? options.footerBranding : {
2569
+ heading: "Powered by FastNear",
2570
+ link: "https://fastnear.com",
2571
+ linkText: "fastnear.com"
2572
+ }
2573
+ };
2574
+ if (options?.contractId) {
2575
+ opts.signIn = {
2576
+ contractId: options.contractId,
2577
+ methodNames: options.methodNames ?? []
2578
+ };
2579
+ }
2580
+ if (options?.excludedWallets) {
2581
+ opts.excludedWallets = options.excludedWallets;
2582
+ }
2583
+ if (options?.features) {
2584
+ opts.features = options.features;
2585
+ }
2586
+ if (options?.manifest) {
2587
+ opts.manifest = options.manifest;
2588
+ }
2589
+ connector = new import_near_connect.NearConnector(opts);
2590
+ connector.on("wallet:signIn", (event) => {
2591
+ const acct = event?.accounts?.[0];
2592
+ if (acct) {
2593
+ currentAccountId = acct.accountId;
2594
+ const result = {
2595
+ accountId: acct.accountId,
2596
+ publicKey: acct.publicKey
2597
+ };
2598
+ for (const cb of connectListeners) {
2599
+ try {
2600
+ cb(result);
2601
+ } catch (_) {
2602
+ }
2603
+ }
2604
+ }
2605
+ });
2606
+ connector.on("wallet:signOut", () => {
2607
+ connectedWallet = null;
2608
+ currentAccountId = null;
2609
+ for (const cb of disconnectListeners) {
2610
+ try {
2611
+ cb();
2612
+ } catch (_) {
2613
+ }
2614
+ }
2615
+ });
2616
+ return connector;
2617
+ }
2618
+ __name(getOrCreateConnector, "getOrCreateConnector");
2619
+ async function restore(options) {
2620
+ const c = getOrCreateConnector(options);
2621
+ try {
2622
+ const result = await c.getConnectedWallet();
2623
+ if (result?.wallet && result?.accounts?.length) {
2624
+ connectedWallet = result.wallet;
2625
+ currentAccountId = result.accounts[0].accountId;
2626
+ const connectResult = {
2627
+ accountId: currentAccountId || "",
2628
+ publicKey: result.accounts[0].publicKey
2629
+ };
2630
+ for (const cb of connectListeners) {
2631
+ try {
2632
+ cb(connectResult);
2633
+ } catch (_) {
2634
+ }
2635
+ }
2636
+ return connectResult;
2637
+ }
2638
+ } catch (_) {
2639
+ }
2640
+ return null;
2641
+ }
2642
+ __name(restore, "restore");
2643
+ async function selectWallet(options) {
2644
+ const c = getOrCreateConnector(options);
2645
+ return c.selectWallet({ features: options?.features });
2646
+ }
2647
+ __name(selectWallet, "selectWallet");
2648
+ async function availableWallets(options) {
2649
+ const c = getOrCreateConnector(options);
2650
+ await c.whenManifestLoaded.catch(() => {
2651
+ });
2652
+ return c.availableWallets.map((w) => w.manifest);
2653
+ }
2654
+ __name(availableWallets, "availableWallets");
2655
+ async function registerDebugWallet(manifest, options) {
2656
+ const c = getOrCreateConnector(options);
2657
+ return c.registerDebugWallet(manifest);
2658
+ }
2659
+ __name(registerDebugWallet, "registerDebugWallet");
2660
+ async function removeDebugWallet(id, options) {
2661
+ const c = getOrCreateConnector(options);
2662
+ return c.removeDebugWallet(id);
2663
+ }
2664
+ __name(removeDebugWallet, "removeDebugWallet");
2665
+ async function switchNetwork(network, signInData) {
2666
+ if (!connector) throw new Error("No connector initialized. Call connect() or restore() first.");
2667
+ return connector.switchNetwork(network, signInData);
2668
+ }
2669
+ __name(switchNetwork, "switchNetwork");
2670
+ async function connect(options) {
2671
+ const c = getOrCreateConnector(options);
2672
+ let wallet;
2673
+ try {
2674
+ wallet = await c.connect({ walletId: options?.walletId });
2675
+ } catch (_) {
2676
+ return null;
2677
+ }
2678
+ connectedWallet = wallet;
2679
+ if (!currentAccountId) {
2680
+ try {
2681
+ const info = await c.getConnectedWallet();
2682
+ if (info?.accounts?.length) {
2683
+ currentAccountId = info.accounts[0].accountId;
2684
+ }
2685
+ } catch (_) {
2686
+ }
2687
+ }
2688
+ return {
2689
+ accountId: currentAccountId ?? "",
2690
+ publicKey: void 0
2691
+ };
2692
+ }
2693
+ __name(connect, "connect");
2694
+ async function disconnect() {
2695
+ if (connector) {
2696
+ await connector.disconnect(connectedWallet ?? void 0);
2697
+ }
2698
+ connectedWallet = null;
2699
+ currentAccountId = null;
2700
+ }
2701
+ __name(disconnect, "disconnect");
2702
+ async function sendTransaction(params) {
2703
+ if (!connectedWallet) {
2704
+ throw new Error("No wallet connected. Call connect() first.");
2705
+ }
2706
+ const actions = params.actions.some(isFastnearAction) ? toConnectorActions(params.actions) : params.actions;
2707
+ return connectedWallet.signAndSendTransaction({
2708
+ receiverId: params.receiverId,
2709
+ actions,
2710
+ signerId: params.signerId ?? currentAccountId ?? void 0
2711
+ });
2712
+ }
2713
+ __name(sendTransaction, "sendTransaction");
2714
+ async function sendTransactions(params) {
2715
+ if (!connectedWallet) {
2716
+ throw new Error("No wallet connected. Call connect() first.");
2717
+ }
2718
+ const transactions = params.transactions.map((tx) => ({
2719
+ receiverId: tx.receiverId,
2720
+ actions: tx.actions.some(isFastnearAction) ? toConnectorActions(tx.actions) : tx.actions
2721
+ }));
2722
+ return connectedWallet.signAndSendTransactions({
2723
+ transactions,
2724
+ signerId: params.signerId ?? currentAccountId ?? void 0
2725
+ });
2726
+ }
2727
+ __name(sendTransactions, "sendTransactions");
2728
+ async function signMessage(params) {
2729
+ if (!connectedWallet) {
2730
+ throw new Error("No wallet connected. Call connect() first.");
2731
+ }
2732
+ return connectedWallet.signMessage(params);
2733
+ }
2734
+ __name(signMessage, "signMessage");
2735
+ function accountId() {
2736
+ return currentAccountId;
2737
+ }
2738
+ __name(accountId, "accountId");
2739
+ function isConnected() {
2740
+ return currentAccountId !== null && connectedWallet !== null;
2741
+ }
2742
+ __name(isConnected, "isConnected");
2743
+ function walletName() {
2744
+ if (!connectedWallet) return null;
2745
+ return connectedWallet.metadata?.name ?? null;
2746
+ }
2747
+ __name(walletName, "walletName");
2748
+ function reset() {
2749
+ connector = null;
2750
+ connectedWallet = null;
2751
+ currentAccountId = null;
2752
+ }
2753
+ __name(reset, "reset");
2754
+ function onConnect(cb) {
2755
+ connectListeners.push(cb);
2756
+ }
2757
+ __name(onConnect, "onConnect");
2758
+ function onDisconnect(cb) {
2759
+ disconnectListeners.push(cb);
2760
+ }
2761
+ __name(onDisconnect, "onDisconnect");
2762
+ return __toCommonJS(src_exports);
2763
+ })();
2764
+
2765
+ Object.defineProperty(globalThis, 'nearWallet', {
2766
+ value: nearWallet,
2767
+ enumerable: true,
2768
+ configurable: false,
2769
+ });
2770
+
2771
+ // Auto-wire with @fastnear/api if it loaded first
2772
+ if (typeof globalThis.near !== 'undefined' && globalThis.near.useWallet) {
2773
+ globalThis.near.useWallet(nearWallet);
2774
+ }
2775
+
2776
+ //# sourceMappingURL=browser.global.js.map