astra-modal-test 1.0.5 → 1.0.7

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.
Files changed (154) hide show
  1. package/.github/workflows/code-quality.yml +43 -0
  2. package/.github/workflows/publish.yml +64 -0
  3. package/README.md +204 -0
  4. package/dist/SwapController-CsNqEWIM.js +447 -0
  5. package/dist/add-Dm_oSEbv.js +19 -0
  6. package/dist/all-wallets-DfLlzQJ3.js +10 -0
  7. package/dist/app-store-BMdJkp6P.js +21 -0
  8. package/dist/apple-BetlVMKw.js +22 -0
  9. package/dist/arrow-bottom-BddPptxy.js +12 -0
  10. package/dist/arrow-bottom-circle-CvdJJniv.js +15 -0
  11. package/dist/arrow-left-Bbq-z1nQ.js +12 -0
  12. package/dist/arrow-right-Bu4_SVLC.js +12 -0
  13. package/dist/arrow-top-CynlXB-M.js +12 -0
  14. package/dist/astra-sdk.es.js +4 -4
  15. package/dist/bank-B9QscNnS.js +18 -0
  16. package/dist/bin-v-tshf8_.js +8 -0
  17. package/dist/bitcoin-C01gkYyN.js +17 -0
  18. package/dist/browser-9uNaCY31.js +18 -0
  19. package/dist/card-hKR9lRzU.js +18 -0
  20. package/dist/{ccip-oZOrZYR9.js → ccip-CUCziAPw.js} +52 -49
  21. package/dist/checkmark-D1M40aM5.js +15 -0
  22. package/dist/checkmark-bold-1_UGl24m.js +12 -0
  23. package/dist/chevron-bottom-BleoRNRL.js +12 -0
  24. package/dist/chevron-left-C9JMU-3B.js +12 -0
  25. package/dist/chevron-right-Daue4WBx.js +12 -0
  26. package/dist/chevron-top-yuXekbUC.js +12 -0
  27. package/dist/chrome-store-BsUFRR7F.js +65 -0
  28. package/dist/circle-BCxdhM5X.js +8 -0
  29. package/dist/clock-7a-DWZQa.js +12 -0
  30. package/dist/close-DMQYuJ0z.js +12 -0
  31. package/dist/clsx.m-DCYaa4RU.js +20 -0
  32. package/dist/coinPlaceholder-DjQ-HnSH.js +12 -0
  33. package/dist/compass-AMecXNVm.js +12 -0
  34. package/dist/copy-CgIPGYbU.js +19 -0
  35. package/dist/cursor-DpYbTNcO.js +7 -0
  36. package/dist/cursor-transparent-C8iPJkn8.js +16 -0
  37. package/dist/desktop-BWVQVGng.js +13 -0
  38. package/dist/disconnect-C6IQRrtF.js +12 -0
  39. package/dist/discord-gH3i-QsC.js +21 -0
  40. package/dist/email-BxYwJC5T.js +10 -0
  41. package/dist/embedded-wallet-DCcVNgkc.js +464 -0
  42. package/dist/ethereum-CGWsmZaC.js +14 -0
  43. package/dist/etherscan-D4EFsAJ4.js +10 -0
  44. package/dist/exclamation-triangle-DNwQ1Xq6.js +8 -0
  45. package/dist/extension-DxQPsN2z.js +12 -0
  46. package/dist/external-link-BeEzrdgR.js +12 -0
  47. package/dist/facebook-B2Ix8_d3.js +30 -0
  48. package/dist/farcaster-BB83p8dC.js +16 -0
  49. package/dist/filters-PzdIomB1.js +12 -0
  50. package/dist/github-gcp1rxX0.js +22 -0
  51. package/dist/google-Qv9lTZcz.js +22 -0
  52. package/dist/help-circle-BLXTMjzX.js +16 -0
  53. package/dist/id-BHg2CRhj.js +16 -0
  54. package/dist/image-DWi1V30x.js +8 -0
  55. package/dist/index-4lbsZ6RQ.js +33 -0
  56. package/dist/index-64U3D9_n.js +21034 -0
  57. package/dist/index-CRU49I0g.js +15911 -0
  58. package/dist/index-ChxXyuZj.js +572 -0
  59. package/dist/index-ClS956E1.js +74511 -0
  60. package/dist/index-Cs4fWw01.js +386 -0
  61. package/dist/index-DfWqgW4h.js +709 -0
  62. package/dist/index-VYNI76FM.js +315 -0
  63. package/dist/index-qfkTLN90.js +10785 -0
  64. package/dist/index-r2ztgVN2.js +1060 -0
  65. package/dist/index-wvh7Yd5J.js +70 -0
  66. package/dist/info-Bl5tmiBJ.js +7 -0
  67. package/dist/info-circle-D2uYywg-.js +16 -0
  68. package/dist/lightbulb-HvXH2AVF.js +7 -0
  69. package/dist/mail-DXOPfnog.js +12 -0
  70. package/dist/mobile-Dd0Gj4vZ.js +13 -0
  71. package/dist/more-DYcnClbB.js +15 -0
  72. package/dist/network-placeholder-CfRZGQfi.js +18 -0
  73. package/dist/nftPlaceholder-DHmFkY55.js +12 -0
  74. package/dist/off-CG2Y30qN.js +8 -0
  75. package/dist/onramp-DoAMTeNm.js +917 -0
  76. package/dist/play-store-B5EYBQto.js +36 -0
  77. package/dist/plus-DPo25_zL.js +17 -0
  78. package/dist/qr-code-BRTO19PL.js +10 -0
  79. package/dist/receive-BvclNdV_.js +179 -0
  80. package/dist/recycle-horizontal-ng_b2eJV.js +13 -0
  81. package/dist/refresh-3kiwRV0w.js +12 -0
  82. package/dist/reown-logo-_9cuIfJD.js +16 -0
  83. package/dist/search-CoJvIxpi.js +12 -0
  84. package/dist/secp256k1-wZyK2iIX.js +1257 -0
  85. package/dist/send-BVKGSR-Z.js +19 -0
  86. package/dist/send-Bkj5YtHe.js +1039 -0
  87. package/dist/socials-DL42HlL5.js +589 -0
  88. package/dist/solana-BjP-_Ioa.js +17 -0
  89. package/dist/swapHorizontal-Do3uBbum.js +12 -0
  90. package/dist/swapHorizontalBold-D7N75BE-.js +12 -0
  91. package/dist/swapHorizontalMedium-BahEVO2x.js +20 -0
  92. package/dist/swapHorizontalRoundedBold-D6Hoi132.js +12 -0
  93. package/dist/swapVertical-P-fnrADh.js +12 -0
  94. package/dist/swaps-DZgbVJZ2.js +1713 -0
  95. package/dist/telegram-DmaL2iB8.js +20 -0
  96. package/dist/three-dots-oXyAsUA6.js +9 -0
  97. package/dist/transactions-BjB5yZN7.js +35 -0
  98. package/dist/twitch-0UGrMr2K.js +22 -0
  99. package/dist/twitterIcon-B97KAbaJ.js +10 -0
  100. package/dist/ui-r6nnVhBA.js +812 -0
  101. package/dist/user-BG1yp56Q.js +7 -0
  102. package/dist/verify-CgzkMSuV.js +12 -0
  103. package/dist/verify-filled-D-TRpWtN.js +12 -0
  104. package/dist/w3m-modal-Drsibcs0.js +1041 -0
  105. package/dist/wallet-CAHsZdfj.js +12 -0
  106. package/dist/wallet-placeholder-agbbreqw.js +18 -0
  107. package/dist/walletconnect-Yd8iXqY9.js +36 -0
  108. package/dist/warning-circle-C0hqC6h_.js +16 -0
  109. package/dist/x-mark-D9_ai2sI.js +7 -0
  110. package/dist/x-z6v1Jegg.js +16 -0
  111. package/eslint.config.mjs +1 -1
  112. package/package.json +14 -13
  113. package/src/apis/lspApi.js +47 -24
  114. package/src/assets/ln.png +0 -0
  115. package/src/assets/network/Arbitrum.png +0 -0
  116. package/src/assets/network/Polygon.png +0 -0
  117. package/src/assets/network/Solana.png +0 -0
  118. package/src/assets/network/botanix.png +0 -0
  119. package/src/assets/network/bsc.svg +13 -0
  120. package/src/assets/pay.png +0 -0
  121. package/src/assets/tokens/usdc.png +0 -0
  122. package/src/assets/tokens/usdt.png +0 -0
  123. package/src/comps/AstraImage.jsx +17 -3
  124. package/src/comps/AstraModal.jsx +22 -16
  125. package/src/comps/AstraModalLogo.jsx +9 -9
  126. package/src/comps/AstraNetwork.jsx +174 -45
  127. package/src/comps/CheckErc20Button.jsx +1 -1
  128. package/src/comps/CommonStyle.jsx +4 -0
  129. package/src/comps/ConnectButton.jsx +16 -33
  130. package/src/comps/ResultModal.jsx +45 -39
  131. package/src/comps/ToLightning.jsx +207 -80
  132. package/src/comps/ToToken.jsx +278 -217
  133. package/src/constants/index.js +20 -4
  134. package/src/hooks/useContract.js +164 -125
  135. package/src/hooks/useGetMinAndMax.js +48 -0
  136. package/src/hooks/useLspApi.js +56 -39
  137. package/src/hooks/useParseInvoice.js +82 -72
  138. package/src/index.jsx +43 -10
  139. package/src/main.jsx +36 -5
  140. package/src/utils/index.js +136 -24
  141. package/vite.config.js +7 -1
  142. package/dist/astra-sdk.umd.js +0 -12578
  143. package/dist/hooks.module-BBZfodGH.js +0 -506
  144. package/dist/index-BKKAfRrw.js +0 -87520
  145. package/dist/index-C2MAIRET.js +0 -2929
  146. package/dist/index-CsRxokSv.js +0 -445
  147. package/dist/index-DQ6iiHxJ.js +0 -13720
  148. package/dist/index-SJhlkSif.js +0 -133
  149. package/dist/w3m-modal-CYJpmgnf.js +0 -267
  150. package/src/constants/contracts/abi/bridge.js +0 -1281
  151. package/src/constants/contracts/abi/index.js +0 -3
  152. package/src/constants/contracts/abi/usdt.js +0 -130
  153. package/src/constants/contracts/abi/watcher.js +0 -437
  154. package/src/constants/contracts/index.js +0 -37
@@ -1,2929 +0,0 @@
1
- import { aZ as N, a_ as Et, a$ as It, b0 as St, b1 as _t } from "./index-BKKAfRrw.js";
2
- import { D as we, g as R, c as te, h as Le, y as Ct } from "./hooks.module-BBZfodGH.js";
3
- class H {
4
- constructor(e, n) {
5
- this.scope = e, this.module = n;
6
- }
7
- storeObject(e, n) {
8
- this.setItem(e, JSON.stringify(n));
9
- }
10
- loadObject(e) {
11
- const n = this.getItem(e);
12
- return n ? JSON.parse(n) : void 0;
13
- }
14
- setItem(e, n) {
15
- localStorage.setItem(this.scopedKey(e), n);
16
- }
17
- getItem(e) {
18
- return localStorage.getItem(this.scopedKey(e));
19
- }
20
- removeItem(e) {
21
- localStorage.removeItem(this.scopedKey(e));
22
- }
23
- clear() {
24
- const e = this.scopedKey(""), n = [];
25
- for (let s = 0; s < localStorage.length; s++) {
26
- const r = localStorage.key(s);
27
- typeof r == "string" && r.startsWith(e) && n.push(r);
28
- }
29
- n.forEach((s) => localStorage.removeItem(s));
30
- }
31
- scopedKey(e) {
32
- return `-${this.scope}${this.module ? `:${this.module}` : ""}:${e}`;
33
- }
34
- static clearAll() {
35
- new H("CBWSDK").clear(), new H("walletlink").clear();
36
- }
37
- }
38
- const j = {
39
- rpc: {
40
- invalidInput: -32e3,
41
- resourceNotFound: -32001,
42
- resourceUnavailable: -32002,
43
- transactionRejected: -32003,
44
- methodNotSupported: -32004,
45
- limitExceeded: -32005,
46
- parse: -32700,
47
- invalidRequest: -32600,
48
- methodNotFound: -32601,
49
- invalidParams: -32602,
50
- internal: -32603
51
- },
52
- provider: {
53
- userRejectedRequest: 4001,
54
- unauthorized: 4100,
55
- unsupportedMethod: 4200,
56
- disconnected: 4900,
57
- chainDisconnected: 4901,
58
- unsupportedChain: 4902
59
- }
60
- }, ye = {
61
- "-32700": {
62
- standard: "JSON RPC 2.0",
63
- message: "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text."
64
- },
65
- "-32600": {
66
- standard: "JSON RPC 2.0",
67
- message: "The JSON sent is not a valid Request object."
68
- },
69
- "-32601": {
70
- standard: "JSON RPC 2.0",
71
- message: "The method does not exist / is not available."
72
- },
73
- "-32602": {
74
- standard: "JSON RPC 2.0",
75
- message: "Invalid method parameter(s)."
76
- },
77
- "-32603": {
78
- standard: "JSON RPC 2.0",
79
- message: "Internal JSON-RPC error."
80
- },
81
- "-32000": {
82
- standard: "EIP-1474",
83
- message: "Invalid input."
84
- },
85
- "-32001": {
86
- standard: "EIP-1474",
87
- message: "Resource not found."
88
- },
89
- "-32002": {
90
- standard: "EIP-1474",
91
- message: "Resource unavailable."
92
- },
93
- "-32003": {
94
- standard: "EIP-1474",
95
- message: "Transaction rejected."
96
- },
97
- "-32004": {
98
- standard: "EIP-1474",
99
- message: "Method not supported."
100
- },
101
- "-32005": {
102
- standard: "EIP-1474",
103
- message: "Request limit exceeded."
104
- },
105
- 4001: {
106
- standard: "EIP-1193",
107
- message: "User rejected the request."
108
- },
109
- 4100: {
110
- standard: "EIP-1193",
111
- message: "The requested account and/or method has not been authorized by the user."
112
- },
113
- 4200: {
114
- standard: "EIP-1193",
115
- message: "The requested method is not supported by this Ethereum provider."
116
- },
117
- 4900: {
118
- standard: "EIP-1193",
119
- message: "The provider is disconnected from all chains."
120
- },
121
- 4901: {
122
- standard: "EIP-1193",
123
- message: "The provider is disconnected from the specified chain."
124
- },
125
- 4902: {
126
- standard: "EIP-3085",
127
- message: "Unrecognized chain ID."
128
- }
129
- }, Xe = "Unspecified error message.", At = "Unspecified server error.";
130
- function Ee(t, e = Xe) {
131
- if (t && Number.isInteger(t)) {
132
- const n = t.toString();
133
- if (me(ye, n))
134
- return ye[n].message;
135
- if (et(t))
136
- return At;
137
- }
138
- return e;
139
- }
140
- function Lt(t) {
141
- if (!Number.isInteger(t))
142
- return !1;
143
- const e = t.toString();
144
- return !!(ye[e] || et(t));
145
- }
146
- function Mt(t, { shouldIncludeStack: e = !1 } = {}) {
147
- const n = {};
148
- if (t && typeof t == "object" && !Array.isArray(t) && me(t, "code") && Lt(t.code)) {
149
- const s = t;
150
- n.code = s.code, s.message && typeof s.message == "string" ? (n.message = s.message, me(s, "data") && (n.data = s.data)) : (n.message = Ee(n.code), n.data = { originalError: Me(t) });
151
- } else
152
- n.code = j.rpc.internal, n.message = xe(t, "message") ? t.message : Xe, n.data = { originalError: Me(t) };
153
- return e && (n.stack = xe(t, "stack") ? t.stack : void 0), n;
154
- }
155
- function et(t) {
156
- return t >= -32099 && t <= -32e3;
157
- }
158
- function Me(t) {
159
- return t && typeof t == "object" && !Array.isArray(t) ? Object.assign({}, t) : t;
160
- }
161
- function me(t, e) {
162
- return Object.prototype.hasOwnProperty.call(t, e);
163
- }
164
- function xe(t, e) {
165
- return typeof t == "object" && t !== null && e in t && typeof t[e] == "string";
166
- }
167
- const A = {
168
- rpc: {
169
- parse: (t) => W(j.rpc.parse, t),
170
- invalidRequest: (t) => W(j.rpc.invalidRequest, t),
171
- invalidParams: (t) => W(j.rpc.invalidParams, t),
172
- methodNotFound: (t) => W(j.rpc.methodNotFound, t),
173
- internal: (t) => W(j.rpc.internal, t),
174
- server: (t) => {
175
- if (!t || typeof t != "object" || Array.isArray(t))
176
- throw new Error("Ethereum RPC Server errors must provide single object argument.");
177
- const { code: e } = t;
178
- if (!Number.isInteger(e) || e > -32005 || e < -32099)
179
- throw new Error('"code" must be an integer such that: -32099 <= code <= -32005');
180
- return W(e, t);
181
- },
182
- invalidInput: (t) => W(j.rpc.invalidInput, t),
183
- resourceNotFound: (t) => W(j.rpc.resourceNotFound, t),
184
- resourceUnavailable: (t) => W(j.rpc.resourceUnavailable, t),
185
- transactionRejected: (t) => W(j.rpc.transactionRejected, t),
186
- methodNotSupported: (t) => W(j.rpc.methodNotSupported, t),
187
- limitExceeded: (t) => W(j.rpc.limitExceeded, t)
188
- },
189
- provider: {
190
- userRejectedRequest: (t) => Q(j.provider.userRejectedRequest, t),
191
- unauthorized: (t) => Q(j.provider.unauthorized, t),
192
- unsupportedMethod: (t) => Q(j.provider.unsupportedMethod, t),
193
- disconnected: (t) => Q(j.provider.disconnected, t),
194
- chainDisconnected: (t) => Q(j.provider.chainDisconnected, t),
195
- unsupportedChain: (t) => Q(j.provider.unsupportedChain, t),
196
- custom: (t) => {
197
- if (!t || typeof t != "object" || Array.isArray(t))
198
- throw new Error("Ethereum Provider custom errors must provide single object argument.");
199
- const { code: e, message: n, data: s } = t;
200
- if (!n || typeof n != "string")
201
- throw new Error('"message" must be a nonempty string');
202
- return new st(e, n, s);
203
- }
204
- }
205
- };
206
- function W(t, e) {
207
- const [n, s] = tt(e);
208
- return new nt(t, n || Ee(t), s);
209
- }
210
- function Q(t, e) {
211
- const [n, s] = tt(e);
212
- return new st(t, n || Ee(t), s);
213
- }
214
- function tt(t) {
215
- if (t) {
216
- if (typeof t == "string")
217
- return [t];
218
- if (typeof t == "object" && !Array.isArray(t)) {
219
- const { message: e, data: n } = t;
220
- if (e && typeof e != "string")
221
- throw new Error("Must specify string message.");
222
- return [e || void 0, n];
223
- }
224
- }
225
- return [];
226
- }
227
- class nt extends Error {
228
- constructor(e, n, s) {
229
- if (!Number.isInteger(e))
230
- throw new Error('"code" must be an integer.');
231
- if (!n || typeof n != "string")
232
- throw new Error('"message" must be a nonempty string.');
233
- super(n), this.code = e, s !== void 0 && (this.data = s);
234
- }
235
- }
236
- class st extends nt {
237
- /**
238
- * Create an Ethereum Provider JSON-RPC error.
239
- * `code` must be an integer in the 1000 <= 4999 range.
240
- */
241
- constructor(e, n, s) {
242
- if (!xt(e))
243
- throw new Error('"code" must be an integer such that: 1000 <= code <= 4999');
244
- super(e, n, s);
245
- }
246
- }
247
- function xt(t) {
248
- return Number.isInteger(t) && t >= 1e3 && t <= 4999;
249
- }
250
- function Ie() {
251
- return (t) => t;
252
- }
253
- const ie = Ie(), Rt = Ie(), Pt = Ie();
254
- function z(t) {
255
- return Math.floor(t);
256
- }
257
- const it = /^[0-9]*$/, rt = /^[a-f0-9]*$/;
258
- function J(t) {
259
- return Se(crypto.getRandomValues(new Uint8Array(t)));
260
- }
261
- function Se(t) {
262
- return [...t].map((e) => e.toString(16).padStart(2, "0")).join("");
263
- }
264
- function oe(t) {
265
- return new Uint8Array(t.match(/.{1,2}/g).map((e) => Number.parseInt(e, 16)));
266
- }
267
- function ne(t, e = !1) {
268
- const n = t.toString("hex");
269
- return ie(e ? `0x${n}` : n);
270
- }
271
- function de(t) {
272
- return ne(ke(t), !0);
273
- }
274
- function K(t) {
275
- return Pt(t.toString(10));
276
- }
277
- function $(t) {
278
- return ie(`0x${BigInt(t).toString(16)}`);
279
- }
280
- function at(t) {
281
- return t.startsWith("0x") || t.startsWith("0X");
282
- }
283
- function _e(t) {
284
- return at(t) ? t.slice(2) : t;
285
- }
286
- function ot(t) {
287
- return at(t) ? `0x${t.slice(2)}` : `0x${t}`;
288
- }
289
- function ce(t) {
290
- if (typeof t != "string")
291
- return !1;
292
- const e = _e(t).toLowerCase();
293
- return rt.test(e);
294
- }
295
- function Tt(t, e = !1) {
296
- if (typeof t == "string") {
297
- const n = _e(t).toLowerCase();
298
- if (rt.test(n))
299
- return ie(e ? `0x${n}` : n);
300
- }
301
- throw A.rpc.invalidParams(`"${String(t)}" is not a hexadecimal string`);
302
- }
303
- function Ce(t, e = !1) {
304
- let n = Tt(t, !1);
305
- return n.length % 2 === 1 && (n = ie(`0${n}`)), e ? ie(`0x${n}`) : n;
306
- }
307
- function Y(t) {
308
- if (typeof t == "string") {
309
- const e = _e(t).toLowerCase();
310
- if (ce(e) && e.length === 40)
311
- return Rt(ot(e));
312
- }
313
- throw A.rpc.invalidParams(`Invalid Ethereum address: ${String(t)}`);
314
- }
315
- function ke(t) {
316
- if (N.isBuffer(t))
317
- return t;
318
- if (typeof t == "string") {
319
- if (ce(t)) {
320
- const e = Ce(t, !1);
321
- return N.from(e, "hex");
322
- }
323
- return N.from(t, "utf8");
324
- }
325
- throw A.rpc.invalidParams(`Not binary data: ${String(t)}`);
326
- }
327
- function se(t) {
328
- if (typeof t == "number" && Number.isInteger(t))
329
- return z(t);
330
- if (typeof t == "string") {
331
- if (it.test(t))
332
- return z(Number(t));
333
- if (ce(t))
334
- return z(Number(BigInt(Ce(t, !0))));
335
- }
336
- throw A.rpc.invalidParams(`Not an integer: ${String(t)}`);
337
- }
338
- function X(t) {
339
- if (t !== null && (typeof t == "bigint" || Nt(t)))
340
- return BigInt(t.toString(10));
341
- if (typeof t == "number")
342
- return BigInt(se(t));
343
- if (typeof t == "string") {
344
- if (it.test(t))
345
- return BigInt(t);
346
- if (ce(t))
347
- return BigInt(Ce(t, !0));
348
- }
349
- throw A.rpc.invalidParams(`Not an integer: ${String(t)}`);
350
- }
351
- function Ot(t) {
352
- if (typeof t == "string")
353
- return JSON.parse(t);
354
- if (typeof t == "object")
355
- return t;
356
- throw A.rpc.invalidParams(`Not a JSON string or an object: ${String(t)}`);
357
- }
358
- function Nt(t) {
359
- if (t == null || typeof t.constructor != "function")
360
- return !1;
361
- const { constructor: e } = t;
362
- return typeof e.config == "function" && typeof e.EUCLID == "number";
363
- }
364
- async function Dt() {
365
- return crypto.subtle.generateKey({
366
- name: "ECDH",
367
- namedCurve: "P-256"
368
- }, !0, ["deriveKey"]);
369
- }
370
- async function jt(t, e) {
371
- return crypto.subtle.deriveKey({
372
- name: "ECDH",
373
- public: e
374
- }, t, {
375
- name: "AES-GCM",
376
- length: 256
377
- }, !1, ["encrypt", "decrypt"]);
378
- }
379
- async function Ut(t, e) {
380
- const n = crypto.getRandomValues(new Uint8Array(12)), s = await crypto.subtle.encrypt({
381
- name: "AES-GCM",
382
- iv: n
383
- }, t, new TextEncoder().encode(e));
384
- return { iv: n, cipherText: s };
385
- }
386
- async function Bt(t, { iv: e, cipherText: n }) {
387
- const s = await crypto.subtle.decrypt({
388
- name: "AES-GCM",
389
- iv: e
390
- }, t, n);
391
- return new TextDecoder().decode(s);
392
- }
393
- function ct(t) {
394
- switch (t) {
395
- case "public":
396
- return "spki";
397
- case "private":
398
- return "pkcs8";
399
- }
400
- }
401
- async function dt(t, e) {
402
- const n = ct(t), s = await crypto.subtle.exportKey(n, e);
403
- return Se(new Uint8Array(s));
404
- }
405
- async function lt(t, e) {
406
- const n = ct(t), s = oe(e).buffer;
407
- return await crypto.subtle.importKey(n, new Uint8Array(s), {
408
- name: "ECDH",
409
- namedCurve: "P-256"
410
- }, !0, t === "private" ? ["deriveKey"] : []);
411
- }
412
- async function Wt(t, e) {
413
- const n = JSON.stringify(t, (s, r) => {
414
- if (!(r instanceof Error))
415
- return r;
416
- const i = r;
417
- return Object.assign(Object.assign({}, i.code ? { code: i.code } : {}), { message: i.message });
418
- });
419
- return Ut(e, n);
420
- }
421
- async function qt(t, e) {
422
- return JSON.parse(await Bt(e, t));
423
- }
424
- const le = {
425
- storageKey: "ownPrivateKey",
426
- keyType: "private"
427
- }, ue = {
428
- storageKey: "ownPublicKey",
429
- keyType: "public"
430
- }, he = {
431
- storageKey: "peerPublicKey",
432
- keyType: "public"
433
- };
434
- class Kt {
435
- constructor() {
436
- this.storage = new H("CBWSDK", "SCWKeyManager"), this.ownPrivateKey = null, this.ownPublicKey = null, this.peerPublicKey = null, this.sharedSecret = null;
437
- }
438
- async getOwnPublicKey() {
439
- return await this.loadKeysIfNeeded(), this.ownPublicKey;
440
- }
441
- // returns null if the shared secret is not yet derived
442
- async getSharedSecret() {
443
- return await this.loadKeysIfNeeded(), this.sharedSecret;
444
- }
445
- async setPeerPublicKey(e) {
446
- this.sharedSecret = null, this.peerPublicKey = e, await this.storeKey(he, e), await this.loadKeysIfNeeded();
447
- }
448
- async clear() {
449
- this.ownPrivateKey = null, this.ownPublicKey = null, this.peerPublicKey = null, this.sharedSecret = null, this.storage.removeItem(ue.storageKey), this.storage.removeItem(le.storageKey), this.storage.removeItem(he.storageKey);
450
- }
451
- async generateKeyPair() {
452
- const e = await Dt();
453
- this.ownPrivateKey = e.privateKey, this.ownPublicKey = e.publicKey, await this.storeKey(le, e.privateKey), await this.storeKey(ue, e.publicKey);
454
- }
455
- async loadKeysIfNeeded() {
456
- if (this.ownPrivateKey === null && (this.ownPrivateKey = await this.loadKey(le)), this.ownPublicKey === null && (this.ownPublicKey = await this.loadKey(ue)), (this.ownPrivateKey === null || this.ownPublicKey === null) && await this.generateKeyPair(), this.peerPublicKey === null && (this.peerPublicKey = await this.loadKey(he)), this.sharedSecret === null) {
457
- if (this.ownPrivateKey === null || this.peerPublicKey === null)
458
- return;
459
- this.sharedSecret = await jt(this.ownPrivateKey, this.peerPublicKey);
460
- }
461
- }
462
- // storage methods
463
- async loadKey(e) {
464
- const n = this.storage.getItem(e.storageKey);
465
- return n ? lt(e.keyType, n) : null;
466
- }
467
- async storeKey(e, n) {
468
- const s = await dt(e.keyType, n);
469
- this.storage.setItem(e.storageKey, s);
470
- }
471
- }
472
- const re = "4.2.3", ut = "@coinbase/wallet-sdk";
473
- async function ht(t, e) {
474
- const n = Object.assign(Object.assign({}, t), { jsonrpc: "2.0", id: crypto.randomUUID() }), s = await window.fetch(e, {
475
- method: "POST",
476
- body: JSON.stringify(n),
477
- mode: "cors",
478
- headers: {
479
- "Content-Type": "application/json",
480
- "X-Cbw-Sdk-Version": re,
481
- "X-Cbw-Sdk-Platform": ut
482
- }
483
- }), { result: r, error: i } = await s.json();
484
- if (i)
485
- throw i;
486
- return r;
487
- }
488
- function Ht() {
489
- return globalThis.coinbaseWalletExtension;
490
- }
491
- function zt() {
492
- var t, e;
493
- try {
494
- const n = globalThis;
495
- return (t = n.ethereum) !== null && t !== void 0 ? t : (e = n.top) === null || e === void 0 ? void 0 : e.ethereum;
496
- } catch {
497
- return;
498
- }
499
- }
500
- function Ft({ metadata: t, preference: e }) {
501
- var n, s;
502
- const { appName: r, appLogoUrl: i, appChainIds: a } = t;
503
- if (e.options !== "smartWalletOnly") {
504
- const l = Ht();
505
- if (l)
506
- return (n = l.setAppInfo) === null || n === void 0 || n.call(l, r, i, a, e), l;
507
- }
508
- const c = zt();
509
- if (c != null && c.isCoinbaseBrowser)
510
- return (s = c.setAppInfo) === null || s === void 0 || s.call(c, r, i, a, e), c;
511
- }
512
- function Gt(t) {
513
- if (!t || typeof t != "object" || Array.isArray(t))
514
- throw A.rpc.invalidParams({
515
- message: "Expected a single, non-array, object argument.",
516
- data: t
517
- });
518
- const { method: e, params: n } = t;
519
- if (typeof e != "string" || e.length === 0)
520
- throw A.rpc.invalidParams({
521
- message: "'args.method' must be a non-empty string.",
522
- data: t
523
- });
524
- if (n !== void 0 && !Array.isArray(n) && (typeof n != "object" || n === null))
525
- throw A.rpc.invalidParams({
526
- message: "'args.params' must be an object or array if provided.",
527
- data: t
528
- });
529
- switch (e) {
530
- case "eth_sign":
531
- case "eth_signTypedData_v2":
532
- case "eth_subscribe":
533
- case "eth_unsubscribe":
534
- throw A.provider.unsupportedMethod();
535
- }
536
- }
537
- const Re = "accounts", Pe = "activeChain", Te = "availableChains", Oe = "walletCapabilities";
538
- class Yt {
539
- constructor(e) {
540
- var n, s, r;
541
- this.metadata = e.metadata, this.communicator = e.communicator, this.callback = e.callback, this.keyManager = new Kt(), this.storage = new H("CBWSDK", "SCWStateManager"), this.accounts = (n = this.storage.loadObject(Re)) !== null && n !== void 0 ? n : [], this.chain = this.storage.loadObject(Pe) || {
542
- id: (r = (s = e.metadata.appChainIds) === null || s === void 0 ? void 0 : s[0]) !== null && r !== void 0 ? r : 1
543
- }, this.handshake = this.handshake.bind(this), this.request = this.request.bind(this), this.createRequestMessage = this.createRequestMessage.bind(this), this.decryptResponseMessage = this.decryptResponseMessage.bind(this);
544
- }
545
- async handshake(e) {
546
- var n, s;
547
- const r = await this.createRequestMessage({
548
- handshake: {
549
- method: e.method,
550
- params: Object.assign({}, this.metadata, (n = e.params) !== null && n !== void 0 ? n : {})
551
- }
552
- }), i = await this.communicator.postRequestAndWaitForResponse(r);
553
- if ("failure" in i.content)
554
- throw i.content.failure;
555
- const a = await lt("public", i.sender);
556
- await this.keyManager.setPeerPublicKey(a);
557
- const l = (await this.decryptResponseMessage(i)).result;
558
- if ("error" in l)
559
- throw l.error;
560
- const f = l.value;
561
- this.accounts = f, this.storage.storeObject(Re, f), (s = this.callback) === null || s === void 0 || s.call(this, "accountsChanged", f);
562
- }
563
- async request(e) {
564
- var n;
565
- if (this.accounts.length === 0)
566
- throw A.provider.unauthorized();
567
- switch (e.method) {
568
- case "eth_requestAccounts":
569
- return (n = this.callback) === null || n === void 0 || n.call(this, "connect", { chainId: $(this.chain.id) }), this.accounts;
570
- case "eth_accounts":
571
- return this.accounts;
572
- case "eth_coinbase":
573
- return this.accounts[0];
574
- case "net_version":
575
- return this.chain.id;
576
- case "eth_chainId":
577
- return $(this.chain.id);
578
- case "wallet_getCapabilities":
579
- return this.storage.loadObject(Oe);
580
- case "wallet_switchEthereumChain":
581
- return this.handleSwitchChainRequest(e);
582
- case "eth_ecRecover":
583
- case "personal_sign":
584
- case "personal_ecRecover":
585
- case "eth_signTransaction":
586
- case "eth_sendTransaction":
587
- case "eth_signTypedData_v1":
588
- case "eth_signTypedData_v3":
589
- case "eth_signTypedData_v4":
590
- case "eth_signTypedData":
591
- case "wallet_addEthereumChain":
592
- case "wallet_watchAsset":
593
- case "wallet_sendCalls":
594
- case "wallet_showCallsStatus":
595
- case "wallet_grantPermissions":
596
- return this.sendRequestToPopup(e);
597
- default:
598
- if (!this.chain.rpcUrl)
599
- throw A.rpc.internal("No RPC URL set for chain");
600
- return ht(e, this.chain.rpcUrl);
601
- }
602
- }
603
- async sendRequestToPopup(e) {
604
- var n, s;
605
- await ((s = (n = this.communicator).waitForPopupLoaded) === null || s === void 0 ? void 0 : s.call(n));
606
- const r = await this.sendEncryptedRequest(e), a = (await this.decryptResponseMessage(r)).result;
607
- if ("error" in a)
608
- throw a.error;
609
- return a.value;
610
- }
611
- async cleanup() {
612
- var e, n;
613
- this.storage.clear(), await this.keyManager.clear(), this.accounts = [], this.chain = {
614
- id: (n = (e = this.metadata.appChainIds) === null || e === void 0 ? void 0 : e[0]) !== null && n !== void 0 ? n : 1
615
- };
616
- }
617
- /**
618
- * @returns `null` if the request was successful.
619
- * https://eips.ethereum.org/EIPS/eip-3326#wallet_switchethereumchain
620
- */
621
- async handleSwitchChainRequest(e) {
622
- var n;
623
- const s = e.params;
624
- if (!s || !(!((n = s[0]) === null || n === void 0) && n.chainId))
625
- throw A.rpc.invalidParams();
626
- const r = se(s[0].chainId);
627
- if (this.updateChain(r))
628
- return null;
629
- const a = await this.sendRequestToPopup(e);
630
- return a === null && this.updateChain(r), a;
631
- }
632
- async sendEncryptedRequest(e) {
633
- const n = await this.keyManager.getSharedSecret();
634
- if (!n)
635
- throw A.provider.unauthorized("No valid session found, try requestAccounts before other methods");
636
- const s = await Wt({
637
- action: e,
638
- chainId: this.chain.id
639
- }, n), r = await this.createRequestMessage({ encrypted: s });
640
- return this.communicator.postRequestAndWaitForResponse(r);
641
- }
642
- async createRequestMessage(e) {
643
- const n = await dt("public", await this.keyManager.getOwnPublicKey());
644
- return {
645
- id: crypto.randomUUID(),
646
- sender: n,
647
- content: e,
648
- timestamp: /* @__PURE__ */ new Date()
649
- };
650
- }
651
- async decryptResponseMessage(e) {
652
- var n, s;
653
- const r = e.content;
654
- if ("failure" in r)
655
- throw r.failure;
656
- const i = await this.keyManager.getSharedSecret();
657
- if (!i)
658
- throw A.provider.unauthorized("Invalid session");
659
- const a = await qt(r.encrypted, i), c = (n = a.data) === null || n === void 0 ? void 0 : n.chains;
660
- if (c) {
661
- const f = Object.entries(c).map(([m, E]) => ({
662
- id: Number(m),
663
- rpcUrl: E
664
- }));
665
- this.storage.storeObject(Te, f), this.updateChain(this.chain.id, f);
666
- }
667
- const l = (s = a.data) === null || s === void 0 ? void 0 : s.capabilities;
668
- return l && this.storage.storeObject(Oe, l), a;
669
- }
670
- updateChain(e, n) {
671
- var s;
672
- const r = n ?? this.storage.loadObject(Te), i = r == null ? void 0 : r.find((a) => a.id === e);
673
- return i ? (i !== this.chain && (this.chain = i, this.storage.storeObject(Pe, i), (s = this.callback) === null || s === void 0 || s.call(this, "chainChanged", $(i.id))), !0) : !1;
674
- }
675
- }
676
- var O = {}, q = {}, Ne;
677
- function ft() {
678
- if (Ne) return q;
679
- Ne = 1, Object.defineProperty(q, "__esModule", { value: !0 }), q.anumber = t, q.number = t, q.abytes = n, q.bytes = n, q.ahash = s, q.aexists = r, q.aoutput = i;
680
- function t(c) {
681
- if (!Number.isSafeInteger(c) || c < 0)
682
- throw new Error("positive integer expected, got " + c);
683
- }
684
- function e(c) {
685
- return c instanceof Uint8Array || ArrayBuffer.isView(c) && c.constructor.name === "Uint8Array";
686
- }
687
- function n(c, ...l) {
688
- if (!e(c))
689
- throw new Error("Uint8Array expected");
690
- if (l.length > 0 && !l.includes(c.length))
691
- throw new Error("Uint8Array expected of length " + l + ", got length=" + c.length);
692
- }
693
- function s(c) {
694
- if (typeof c != "function" || typeof c.create != "function")
695
- throw new Error("Hash should be wrapped by utils.wrapConstructor");
696
- t(c.outputLen), t(c.blockLen);
697
- }
698
- function r(c, l = !0) {
699
- if (c.destroyed)
700
- throw new Error("Hash instance has been destroyed");
701
- if (l && c.finished)
702
- throw new Error("Hash#digest() has already been called");
703
- }
704
- function i(c, l) {
705
- n(c);
706
- const f = l.outputLen;
707
- if (c.length < f)
708
- throw new Error("digestInto() expects output buffer of length at least " + f);
709
- }
710
- const a = {
711
- number: t,
712
- bytes: n,
713
- hash: s,
714
- exists: r,
715
- output: i
716
- };
717
- return q.default = a, q;
718
- }
719
- var v = {}, De;
720
- function $t() {
721
- if (De) return v;
722
- De = 1, Object.defineProperty(v, "__esModule", { value: !0 }), v.add5L = v.add5H = v.add4H = v.add4L = v.add3H = v.add3L = v.rotlBL = v.rotlBH = v.rotlSL = v.rotlSH = v.rotr32L = v.rotr32H = v.rotrBL = v.rotrBH = v.rotrSL = v.rotrSH = v.shrSL = v.shrSH = v.toBig = void 0, v.fromBig = n, v.split = s, v.add = L;
723
- const t = /* @__PURE__ */ BigInt(2 ** 32 - 1), e = /* @__PURE__ */ BigInt(32);
724
- function n(g, p = !1) {
725
- return p ? { h: Number(g & t), l: Number(g >> e & t) } : { h: Number(g >> e & t) | 0, l: Number(g & t) | 0 };
726
- }
727
- function s(g, p = !1) {
728
- let o = new Uint32Array(g.length), b = new Uint32Array(g.length);
729
- for (let S = 0; S < g.length; S++) {
730
- const { h: C, l: D } = n(g[S], p);
731
- [o[S], b[S]] = [C, D];
732
- }
733
- return [o, b];
734
- }
735
- const r = (g, p) => BigInt(g >>> 0) << e | BigInt(p >>> 0);
736
- v.toBig = r;
737
- const i = (g, p, o) => g >>> o;
738
- v.shrSH = i;
739
- const a = (g, p, o) => g << 32 - o | p >>> o;
740
- v.shrSL = a;
741
- const c = (g, p, o) => g >>> o | p << 32 - o;
742
- v.rotrSH = c;
743
- const l = (g, p, o) => g << 32 - o | p >>> o;
744
- v.rotrSL = l;
745
- const f = (g, p, o) => g << 64 - o | p >>> o - 32;
746
- v.rotrBH = f;
747
- const m = (g, p, o) => g >>> o - 32 | p << 64 - o;
748
- v.rotrBL = m;
749
- const E = (g, p) => p;
750
- v.rotr32H = E;
751
- const u = (g, p) => g;
752
- v.rotr32L = u;
753
- const d = (g, p, o) => g << o | p >>> 32 - o;
754
- v.rotlSH = d;
755
- const h = (g, p, o) => p << o | g >>> 32 - o;
756
- v.rotlSL = h;
757
- const _ = (g, p, o) => p << o - 32 | g >>> 64 - o;
758
- v.rotlBH = _;
759
- const k = (g, p, o) => g << o - 32 | p >>> 64 - o;
760
- v.rotlBL = k;
761
- function L(g, p, o, b) {
762
- const S = (p >>> 0) + (b >>> 0);
763
- return { h: g + o + (S / 2 ** 32 | 0) | 0, l: S | 0 };
764
- }
765
- const M = (g, p, o) => (g >>> 0) + (p >>> 0) + (o >>> 0);
766
- v.add3L = M;
767
- const P = (g, p, o, b) => p + o + b + (g / 2 ** 32 | 0) | 0;
768
- v.add3H = P;
769
- const y = (g, p, o, b) => (g >>> 0) + (p >>> 0) + (o >>> 0) + (b >>> 0);
770
- v.add4L = y;
771
- const w = (g, p, o, b, S) => p + o + b + S + (g / 2 ** 32 | 0) | 0;
772
- v.add4H = w;
773
- const I = (g, p, o, b, S) => (g >>> 0) + (p >>> 0) + (o >>> 0) + (b >>> 0) + (S >>> 0);
774
- v.add5L = I;
775
- const x = (g, p, o, b, S, C) => p + o + b + S + C + (g / 2 ** 32 | 0) | 0;
776
- v.add5H = x;
777
- const T = {
778
- fromBig: n,
779
- split: s,
780
- toBig: r,
781
- shrSH: i,
782
- shrSL: a,
783
- rotrSH: c,
784
- rotrSL: l,
785
- rotrBH: f,
786
- rotrBL: m,
787
- rotr32H: E,
788
- rotr32L: u,
789
- rotlSH: d,
790
- rotlSL: h,
791
- rotlBH: _,
792
- rotlBL: k,
793
- add: L,
794
- add3L: M,
795
- add3H: P,
796
- add4L: y,
797
- add4H: w,
798
- add5H: x,
799
- add5L: I
800
- };
801
- return v.default = T, v;
802
- }
803
- var fe = {}, ee = {}, je;
804
- function Vt() {
805
- return je || (je = 1, Object.defineProperty(ee, "__esModule", { value: !0 }), ee.crypto = void 0, ee.crypto = typeof globalThis == "object" && "crypto" in globalThis ? globalThis.crypto : void 0), ee;
806
- }
807
- var Ue;
808
- function Jt() {
809
- return Ue || (Ue = 1, function(t) {
810
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
811
- Object.defineProperty(t, "__esModule", { value: !0 }), t.Hash = t.nextTick = t.byteSwapIfBE = t.byteSwap = t.isLE = t.rotl = t.rotr = t.createView = t.u32 = t.u8 = void 0, t.isBytes = s, t.byteSwap32 = m, t.bytesToHex = u, t.hexToBytes = _, t.asyncLoop = L, t.utf8ToBytes = M, t.toBytes = P, t.concatBytes = y, t.checkOpts = I, t.wrapConstructor = x, t.wrapConstructorWithOpts = T, t.wrapXOFConstructorWithOpts = g, t.randomBytes = p;
812
- const e = /* @__PURE__ */ Vt(), n = /* @__PURE__ */ ft();
813
- function s(o) {
814
- return o instanceof Uint8Array || ArrayBuffer.isView(o) && o.constructor.name === "Uint8Array";
815
- }
816
- const r = (o) => new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
817
- t.u8 = r;
818
- const i = (o) => new Uint32Array(o.buffer, o.byteOffset, Math.floor(o.byteLength / 4));
819
- t.u32 = i;
820
- const a = (o) => new DataView(o.buffer, o.byteOffset, o.byteLength);
821
- t.createView = a;
822
- const c = (o, b) => o << 32 - b | o >>> b;
823
- t.rotr = c;
824
- const l = (o, b) => o << b | o >>> 32 - b >>> 0;
825
- t.rotl = l, t.isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
826
- const f = (o) => o << 24 & 4278190080 | o << 8 & 16711680 | o >>> 8 & 65280 | o >>> 24 & 255;
827
- t.byteSwap = f, t.byteSwapIfBE = t.isLE ? (o) => o : (o) => (0, t.byteSwap)(o);
828
- function m(o) {
829
- for (let b = 0; b < o.length; b++)
830
- o[b] = (0, t.byteSwap)(o[b]);
831
- }
832
- const E = /* @__PURE__ */ Array.from({ length: 256 }, (o, b) => b.toString(16).padStart(2, "0"));
833
- function u(o) {
834
- (0, n.abytes)(o);
835
- let b = "";
836
- for (let S = 0; S < o.length; S++)
837
- b += E[o[S]];
838
- return b;
839
- }
840
- const d = { _0: 48, _9: 57, A: 65, F: 70, a: 97, f: 102 };
841
- function h(o) {
842
- if (o >= d._0 && o <= d._9)
843
- return o - d._0;
844
- if (o >= d.A && o <= d.F)
845
- return o - (d.A - 10);
846
- if (o >= d.a && o <= d.f)
847
- return o - (d.a - 10);
848
- }
849
- function _(o) {
850
- if (typeof o != "string")
851
- throw new Error("hex string expected, got " + typeof o);
852
- const b = o.length, S = b / 2;
853
- if (b % 2)
854
- throw new Error("hex string expected, got unpadded hex of length " + b);
855
- const C = new Uint8Array(S);
856
- for (let D = 0, B = 0; D < S; D++, B += 2) {
857
- const V = h(o.charCodeAt(B)), Ae = h(o.charCodeAt(B + 1));
858
- if (V === void 0 || Ae === void 0) {
859
- const vt = o[B] + o[B + 1];
860
- throw new Error('hex string expected, got non-hex character "' + vt + '" at index ' + B);
861
- }
862
- C[D] = V * 16 + Ae;
863
- }
864
- return C;
865
- }
866
- const k = async () => {
867
- };
868
- t.nextTick = k;
869
- async function L(o, b, S) {
870
- let C = Date.now();
871
- for (let D = 0; D < o; D++) {
872
- S(D);
873
- const B = Date.now() - C;
874
- B >= 0 && B < b || (await (0, t.nextTick)(), C += B);
875
- }
876
- }
877
- function M(o) {
878
- if (typeof o != "string")
879
- throw new Error("utf8ToBytes expected string, got " + typeof o);
880
- return new Uint8Array(new TextEncoder().encode(o));
881
- }
882
- function P(o) {
883
- return typeof o == "string" && (o = M(o)), (0, n.abytes)(o), o;
884
- }
885
- function y(...o) {
886
- let b = 0;
887
- for (let C = 0; C < o.length; C++) {
888
- const D = o[C];
889
- (0, n.abytes)(D), b += D.length;
890
- }
891
- const S = new Uint8Array(b);
892
- for (let C = 0, D = 0; C < o.length; C++) {
893
- const B = o[C];
894
- S.set(B, D), D += B.length;
895
- }
896
- return S;
897
- }
898
- class w {
899
- // Safe version that clones internal state
900
- clone() {
901
- return this._cloneInto();
902
- }
903
- }
904
- t.Hash = w;
905
- function I(o, b) {
906
- if (b !== void 0 && {}.toString.call(b) !== "[object Object]")
907
- throw new Error("Options should be object or undefined");
908
- return Object.assign(o, b);
909
- }
910
- function x(o) {
911
- const b = (C) => o().update(P(C)).digest(), S = o();
912
- return b.outputLen = S.outputLen, b.blockLen = S.blockLen, b.create = () => o(), b;
913
- }
914
- function T(o) {
915
- const b = (C, D) => o(D).update(P(C)).digest(), S = o({});
916
- return b.outputLen = S.outputLen, b.blockLen = S.blockLen, b.create = (C) => o(C), b;
917
- }
918
- function g(o) {
919
- const b = (C, D) => o(D).update(P(C)).digest(), S = o({});
920
- return b.outputLen = S.outputLen, b.blockLen = S.blockLen, b.create = (C) => o(C), b;
921
- }
922
- function p(o = 32) {
923
- if (e.crypto && typeof e.crypto.getRandomValues == "function")
924
- return e.crypto.getRandomValues(new Uint8Array(o));
925
- if (e.crypto && typeof e.crypto.randomBytes == "function")
926
- return e.crypto.randomBytes(o);
927
- throw new Error("crypto.getRandomValues must be defined");
928
- }
929
- }(fe)), fe;
930
- }
931
- var Be;
932
- function Qt() {
933
- if (Be) return O;
934
- Be = 1, Object.defineProperty(O, "__esModule", { value: !0 }), O.shake256 = O.shake128 = O.keccak_512 = O.keccak_384 = O.keccak_256 = O.keccak_224 = O.sha3_512 = O.sha3_384 = O.sha3_256 = O.sha3_224 = O.Keccak = void 0, O.keccakP = k;
935
- const t = /* @__PURE__ */ ft(), e = /* @__PURE__ */ $t(), n = /* @__PURE__ */ Jt(), s = [], r = [], i = [], a = /* @__PURE__ */ BigInt(0), c = /* @__PURE__ */ BigInt(1), l = /* @__PURE__ */ BigInt(2), f = /* @__PURE__ */ BigInt(7), m = /* @__PURE__ */ BigInt(256), E = /* @__PURE__ */ BigInt(113);
936
- for (let y = 0, w = c, I = 1, x = 0; y < 24; y++) {
937
- [I, x] = [x, (2 * I + 3 * x) % 5], s.push(2 * (5 * x + I)), r.push((y + 1) * (y + 2) / 2 % 64);
938
- let T = a;
939
- for (let g = 0; g < 7; g++)
940
- w = (w << c ^ (w >> f) * E) % m, w & l && (T ^= c << (c << /* @__PURE__ */ BigInt(g)) - c);
941
- i.push(T);
942
- }
943
- const [u, d] = /* @__PURE__ */ (0, e.split)(i, !0), h = (y, w, I) => I > 32 ? (0, e.rotlBH)(y, w, I) : (0, e.rotlSH)(y, w, I), _ = (y, w, I) => I > 32 ? (0, e.rotlBL)(y, w, I) : (0, e.rotlSL)(y, w, I);
944
- function k(y, w = 24) {
945
- const I = new Uint32Array(10);
946
- for (let x = 24 - w; x < 24; x++) {
947
- for (let p = 0; p < 10; p++)
948
- I[p] = y[p] ^ y[p + 10] ^ y[p + 20] ^ y[p + 30] ^ y[p + 40];
949
- for (let p = 0; p < 10; p += 2) {
950
- const o = (p + 8) % 10, b = (p + 2) % 10, S = I[b], C = I[b + 1], D = h(S, C, 1) ^ I[o], B = _(S, C, 1) ^ I[o + 1];
951
- for (let V = 0; V < 50; V += 10)
952
- y[p + V] ^= D, y[p + V + 1] ^= B;
953
- }
954
- let T = y[2], g = y[3];
955
- for (let p = 0; p < 24; p++) {
956
- const o = r[p], b = h(T, g, o), S = _(T, g, o), C = s[p];
957
- T = y[C], g = y[C + 1], y[C] = b, y[C + 1] = S;
958
- }
959
- for (let p = 0; p < 50; p += 10) {
960
- for (let o = 0; o < 10; o++)
961
- I[o] = y[p + o];
962
- for (let o = 0; o < 10; o++)
963
- y[p + o] ^= ~I[(o + 2) % 10] & I[(o + 4) % 10];
964
- }
965
- y[0] ^= u[x], y[1] ^= d[x];
966
- }
967
- I.fill(0);
968
- }
969
- class L extends n.Hash {
970
- // NOTE: we accept arguments in bytes instead of bits here.
971
- constructor(w, I, x, T = !1, g = 24) {
972
- if (super(), this.blockLen = w, this.suffix = I, this.outputLen = x, this.enableXOF = T, this.rounds = g, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, (0, t.anumber)(x), 0 >= this.blockLen || this.blockLen >= 200)
973
- throw new Error("Sha3 supports only keccak-f1600 function");
974
- this.state = new Uint8Array(200), this.state32 = (0, n.u32)(this.state);
975
- }
976
- keccak() {
977
- n.isLE || (0, n.byteSwap32)(this.state32), k(this.state32, this.rounds), n.isLE || (0, n.byteSwap32)(this.state32), this.posOut = 0, this.pos = 0;
978
- }
979
- update(w) {
980
- (0, t.aexists)(this);
981
- const { blockLen: I, state: x } = this;
982
- w = (0, n.toBytes)(w);
983
- const T = w.length;
984
- for (let g = 0; g < T; ) {
985
- const p = Math.min(I - this.pos, T - g);
986
- for (let o = 0; o < p; o++)
987
- x[this.pos++] ^= w[g++];
988
- this.pos === I && this.keccak();
989
- }
990
- return this;
991
- }
992
- finish() {
993
- if (this.finished)
994
- return;
995
- this.finished = !0;
996
- const { state: w, suffix: I, pos: x, blockLen: T } = this;
997
- w[x] ^= I, I & 128 && x === T - 1 && this.keccak(), w[T - 1] ^= 128, this.keccak();
998
- }
999
- writeInto(w) {
1000
- (0, t.aexists)(this, !1), (0, t.abytes)(w), this.finish();
1001
- const I = this.state, { blockLen: x } = this;
1002
- for (let T = 0, g = w.length; T < g; ) {
1003
- this.posOut >= x && this.keccak();
1004
- const p = Math.min(x - this.posOut, g - T);
1005
- w.set(I.subarray(this.posOut, this.posOut + p), T), this.posOut += p, T += p;
1006
- }
1007
- return w;
1008
- }
1009
- xofInto(w) {
1010
- if (!this.enableXOF)
1011
- throw new Error("XOF is not possible for this instance");
1012
- return this.writeInto(w);
1013
- }
1014
- xof(w) {
1015
- return (0, t.anumber)(w), this.xofInto(new Uint8Array(w));
1016
- }
1017
- digestInto(w) {
1018
- if ((0, t.aoutput)(w, this), this.finished)
1019
- throw new Error("digest() was already called");
1020
- return this.writeInto(w), this.destroy(), w;
1021
- }
1022
- digest() {
1023
- return this.digestInto(new Uint8Array(this.outputLen));
1024
- }
1025
- destroy() {
1026
- this.destroyed = !0, this.state.fill(0);
1027
- }
1028
- _cloneInto(w) {
1029
- const { blockLen: I, suffix: x, outputLen: T, rounds: g, enableXOF: p } = this;
1030
- return w || (w = new L(I, x, T, p, g)), w.state32.set(this.state32), w.pos = this.pos, w.posOut = this.posOut, w.finished = this.finished, w.rounds = g, w.suffix = x, w.outputLen = T, w.enableXOF = p, w.destroyed = this.destroyed, w;
1031
- }
1032
- }
1033
- O.Keccak = L;
1034
- const M = (y, w, I) => (0, n.wrapConstructor)(() => new L(w, y, I));
1035
- O.sha3_224 = M(6, 144, 224 / 8), O.sha3_256 = M(6, 136, 256 / 8), O.sha3_384 = M(6, 104, 384 / 8), O.sha3_512 = M(6, 72, 512 / 8), O.keccak_224 = M(1, 144, 224 / 8), O.keccak_256 = M(1, 136, 256 / 8), O.keccak_384 = M(1, 104, 384 / 8), O.keccak_512 = M(1, 72, 512 / 8);
1036
- const P = (y, w, I) => (0, n.wrapXOFConstructorWithOpts)((x = {}) => new L(w, y, x.dkLen === void 0 ? I : x.dkLen, !0));
1037
- return O.shake128 = P(31, 168, 128 / 8), O.shake256 = P(31, 136, 256 / 8), O;
1038
- }
1039
- var pe, We;
1040
- function pt() {
1041
- if (We) return pe;
1042
- We = 1;
1043
- const { keccak_256: t } = /* @__PURE__ */ Qt();
1044
- function e(d) {
1045
- return N.allocUnsafe(d).fill(0);
1046
- }
1047
- function n(d) {
1048
- return d.toString(2).length;
1049
- }
1050
- function s(d, h) {
1051
- let _ = d.toString(16);
1052
- _.length % 2 !== 0 && (_ = "0" + _);
1053
- const k = _.match(/.{1,2}/g).map((L) => parseInt(L, 16));
1054
- for (; k.length < h; )
1055
- k.unshift(0);
1056
- return N.from(k);
1057
- }
1058
- function r(d, h) {
1059
- const _ = d < 0n;
1060
- let k;
1061
- if (_) {
1062
- const L = (1n << BigInt(h)) - 1n;
1063
- k = (~d & L) + 1n;
1064
- } else
1065
- k = d;
1066
- return k &= (1n << BigInt(h)) - 1n, k;
1067
- }
1068
- function i(d, h, _) {
1069
- const k = e(h);
1070
- return d = c(d), _ ? d.length < h ? (d.copy(k), k) : d.slice(0, h) : d.length < h ? (d.copy(k, h - d.length), k) : d.slice(-h);
1071
- }
1072
- function a(d, h) {
1073
- return i(d, h, !0);
1074
- }
1075
- function c(d) {
1076
- if (!N.isBuffer(d))
1077
- if (Array.isArray(d))
1078
- d = N.from(d);
1079
- else if (typeof d == "string")
1080
- E(d) ? d = N.from(m(u(d)), "hex") : d = N.from(d);
1081
- else if (typeof d == "number")
1082
- d = intToBuffer(d);
1083
- else if (d == null)
1084
- d = N.allocUnsafe(0);
1085
- else if (typeof d == "bigint")
1086
- d = s(d);
1087
- else if (d.toArray)
1088
- d = N.from(d.toArray());
1089
- else
1090
- throw new Error("invalid type");
1091
- return d;
1092
- }
1093
- function l(d) {
1094
- return d = c(d), "0x" + d.toString("hex");
1095
- }
1096
- function f(d, h) {
1097
- if (d = c(d), h || (h = 256), h !== 256)
1098
- throw new Error("unsupported");
1099
- return N.from(t(new Uint8Array(d)));
1100
- }
1101
- function m(d) {
1102
- return d.length % 2 ? "0" + d : d;
1103
- }
1104
- function E(d) {
1105
- return typeof d == "string" && d.match(/^0x[0-9A-Fa-f]*$/);
1106
- }
1107
- function u(d) {
1108
- return typeof d == "string" && d.startsWith("0x") ? d.slice(2) : d;
1109
- }
1110
- return pe = {
1111
- zeros: e,
1112
- setLength: i,
1113
- setLengthRight: a,
1114
- isHexString: E,
1115
- stripHexPrefix: u,
1116
- toBuffer: c,
1117
- bufferToHex: l,
1118
- keccak: f,
1119
- bitLengthFromBigInt: n,
1120
- bufferBEFromBigInt: s,
1121
- twosFromBigInt: r
1122
- }, pe;
1123
- }
1124
- var ge, qe;
1125
- function Zt() {
1126
- if (qe) return ge;
1127
- qe = 1;
1128
- const t = /* @__PURE__ */ pt();
1129
- function e(u) {
1130
- return u.startsWith("int[") ? "int256" + u.slice(3) : u === "int" ? "int256" : u.startsWith("uint[") ? "uint256" + u.slice(4) : u === "uint" ? "uint256" : u.startsWith("fixed[") ? "fixed128x128" + u.slice(5) : u === "fixed" ? "fixed128x128" : u.startsWith("ufixed[") ? "ufixed128x128" + u.slice(6) : u === "ufixed" ? "ufixed128x128" : u;
1131
- }
1132
- function n(u) {
1133
- return Number.parseInt(/^\D+(\d+)$/.exec(u)[1], 10);
1134
- }
1135
- function s(u) {
1136
- var d = /^\D+(\d+)x(\d+)$/.exec(u);
1137
- return [Number.parseInt(d[1], 10), Number.parseInt(d[2], 10)];
1138
- }
1139
- function r(u) {
1140
- var d = u.match(/(.*)\[(.*?)\]$/);
1141
- return d ? d[2] === "" ? "dynamic" : Number.parseInt(d[2], 10) : null;
1142
- }
1143
- function i(u) {
1144
- var d = typeof u;
1145
- if (d === "string" || d === "number")
1146
- return BigInt(u);
1147
- if (d === "bigint")
1148
- return u;
1149
- throw new Error("Argument is not a number");
1150
- }
1151
- function a(u, d) {
1152
- var h, _, k, L;
1153
- if (u === "address")
1154
- return a("uint160", i(d));
1155
- if (u === "bool")
1156
- return a("uint8", d ? 1 : 0);
1157
- if (u === "string")
1158
- return a("bytes", new N(d, "utf8"));
1159
- if (l(u)) {
1160
- if (typeof d.length > "u")
1161
- throw new Error("Not an array?");
1162
- if (h = r(u), h !== "dynamic" && h !== 0 && d.length > h)
1163
- throw new Error("Elements exceed array size: " + h);
1164
- k = [], u = u.slice(0, u.lastIndexOf("[")), typeof d == "string" && (d = JSON.parse(d));
1165
- for (L in d)
1166
- k.push(a(u, d[L]));
1167
- if (h === "dynamic") {
1168
- var M = a("uint256", d.length);
1169
- k.unshift(M);
1170
- }
1171
- return N.concat(k);
1172
- } else {
1173
- if (u === "bytes")
1174
- return d = new N(d), k = N.concat([a("uint256", d.length), d]), d.length % 32 !== 0 && (k = N.concat([k, t.zeros(32 - d.length % 32)])), k;
1175
- if (u.startsWith("bytes")) {
1176
- if (h = n(u), h < 1 || h > 32)
1177
- throw new Error("Invalid bytes<N> width: " + h);
1178
- return t.setLengthRight(d, 32);
1179
- } else if (u.startsWith("uint")) {
1180
- if (h = n(u), h % 8 || h < 8 || h > 256)
1181
- throw new Error("Invalid uint<N> width: " + h);
1182
- _ = i(d);
1183
- const P = t.bitLengthFromBigInt(_);
1184
- if (P > h)
1185
- throw new Error("Supplied uint exceeds width: " + h + " vs " + P);
1186
- if (_ < 0)
1187
- throw new Error("Supplied uint is negative");
1188
- return t.bufferBEFromBigInt(_, 32);
1189
- } else if (u.startsWith("int")) {
1190
- if (h = n(u), h % 8 || h < 8 || h > 256)
1191
- throw new Error("Invalid int<N> width: " + h);
1192
- _ = i(d);
1193
- const P = t.bitLengthFromBigInt(_);
1194
- if (P > h)
1195
- throw new Error("Supplied int exceeds width: " + h + " vs " + P);
1196
- const y = t.twosFromBigInt(_, 256);
1197
- return t.bufferBEFromBigInt(y, 32);
1198
- } else if (u.startsWith("ufixed")) {
1199
- if (h = s(u), _ = i(d), _ < 0)
1200
- throw new Error("Supplied ufixed is negative");
1201
- return a("uint256", _ * BigInt(2) ** BigInt(h[1]));
1202
- } else if (u.startsWith("fixed"))
1203
- return h = s(u), a("int256", i(d) * BigInt(2) ** BigInt(h[1]));
1204
- }
1205
- throw new Error("Unsupported or invalid type: " + u);
1206
- }
1207
- function c(u) {
1208
- return u === "string" || u === "bytes" || r(u) === "dynamic";
1209
- }
1210
- function l(u) {
1211
- return u.lastIndexOf("]") === u.length - 1;
1212
- }
1213
- function f(u, d) {
1214
- var h = [], _ = [], k = 32 * u.length;
1215
- for (var L in u) {
1216
- var M = e(u[L]), P = d[L], y = a(M, P);
1217
- c(M) ? (h.push(a("uint256", k)), _.push(y), k += y.length) : h.push(y);
1218
- }
1219
- return N.concat(h.concat(_));
1220
- }
1221
- function m(u, d) {
1222
- if (u.length !== d.length)
1223
- throw new Error("Number of types are not matching the values");
1224
- for (var h, _, k = [], L = 0; L < u.length; L++) {
1225
- var M = e(u[L]), P = d[L];
1226
- if (M === "bytes")
1227
- k.push(P);
1228
- else if (M === "string")
1229
- k.push(new N(P, "utf8"));
1230
- else if (M === "bool")
1231
- k.push(new N(P ? "01" : "00", "hex"));
1232
- else if (M === "address")
1233
- k.push(t.setLength(P, 20));
1234
- else if (M.startsWith("bytes")) {
1235
- if (h = n(M), h < 1 || h > 32)
1236
- throw new Error("Invalid bytes<N> width: " + h);
1237
- k.push(t.setLengthRight(P, h));
1238
- } else if (M.startsWith("uint")) {
1239
- if (h = n(M), h % 8 || h < 8 || h > 256)
1240
- throw new Error("Invalid uint<N> width: " + h);
1241
- _ = i(P);
1242
- const y = t.bitLengthFromBigInt(_);
1243
- if (y > h)
1244
- throw new Error("Supplied uint exceeds width: " + h + " vs " + y);
1245
- k.push(t.bufferBEFromBigInt(_, h / 8));
1246
- } else if (M.startsWith("int")) {
1247
- if (h = n(M), h % 8 || h < 8 || h > 256)
1248
- throw new Error("Invalid int<N> width: " + h);
1249
- _ = i(P);
1250
- const y = t.bitLengthFromBigInt(_);
1251
- if (y > h)
1252
- throw new Error("Supplied int exceeds width: " + h + " vs " + y);
1253
- const w = t.twosFromBigInt(_, h);
1254
- k.push(t.bufferBEFromBigInt(w, h / 8));
1255
- } else
1256
- throw new Error("Unsupported or invalid type: " + M);
1257
- }
1258
- return N.concat(k);
1259
- }
1260
- function E(u, d) {
1261
- return t.keccak(m(u, d));
1262
- }
1263
- return ge = {
1264
- rawEncode: f,
1265
- solidityPack: m,
1266
- soliditySHA3: E
1267
- }, ge;
1268
- }
1269
- var be, Ke;
1270
- function Xt() {
1271
- if (Ke) return be;
1272
- Ke = 1;
1273
- const t = /* @__PURE__ */ pt(), e = /* @__PURE__ */ Zt(), n = {
1274
- type: "object",
1275
- properties: {
1276
- types: {
1277
- type: "object",
1278
- additionalProperties: {
1279
- type: "array",
1280
- items: {
1281
- type: "object",
1282
- properties: {
1283
- name: { type: "string" },
1284
- type: { type: "string" }
1285
- },
1286
- required: ["name", "type"]
1287
- }
1288
- }
1289
- },
1290
- primaryType: { type: "string" },
1291
- domain: { type: "object" },
1292
- message: { type: "object" }
1293
- },
1294
- required: ["types", "primaryType", "domain", "message"]
1295
- }, s = {
1296
- /**
1297
- * Encodes an object by encoding and concatenating each of its members
1298
- *
1299
- * @param {string} primaryType - Root type
1300
- * @param {Object} data - Object to encode
1301
- * @param {Object} types - Type definitions
1302
- * @returns {string} - Encoded representation of an object
1303
- */
1304
- encodeData(i, a, c, l = !0) {
1305
- const f = ["bytes32"], m = [this.hashType(i, c)];
1306
- if (l) {
1307
- const E = (u, d, h) => {
1308
- if (c[d] !== void 0)
1309
- return ["bytes32", h == null ? "0x0000000000000000000000000000000000000000000000000000000000000000" : t.keccak(this.encodeData(d, h, c, l))];
1310
- if (h === void 0)
1311
- throw new Error(`missing value for field ${u} of type ${d}`);
1312
- if (d === "bytes")
1313
- return ["bytes32", t.keccak(h)];
1314
- if (d === "string")
1315
- return typeof h == "string" && (h = N.from(h, "utf8")), ["bytes32", t.keccak(h)];
1316
- if (d.lastIndexOf("]") === d.length - 1) {
1317
- const _ = d.slice(0, d.lastIndexOf("[")), k = h.map((L) => E(u, _, L));
1318
- return ["bytes32", t.keccak(e.rawEncode(
1319
- k.map(([L]) => L),
1320
- k.map(([, L]) => L)
1321
- ))];
1322
- }
1323
- return [d, h];
1324
- };
1325
- for (const u of c[i]) {
1326
- const [d, h] = E(u.name, u.type, a[u.name]);
1327
- f.push(d), m.push(h);
1328
- }
1329
- } else
1330
- for (const E of c[i]) {
1331
- let u = a[E.name];
1332
- if (u !== void 0)
1333
- if (E.type === "bytes")
1334
- f.push("bytes32"), u = t.keccak(u), m.push(u);
1335
- else if (E.type === "string")
1336
- f.push("bytes32"), typeof u == "string" && (u = N.from(u, "utf8")), u = t.keccak(u), m.push(u);
1337
- else if (c[E.type] !== void 0)
1338
- f.push("bytes32"), u = t.keccak(this.encodeData(E.type, u, c, l)), m.push(u);
1339
- else {
1340
- if (E.type.lastIndexOf("]") === E.type.length - 1)
1341
- throw new Error("Arrays currently unimplemented in encodeData");
1342
- f.push(E.type), m.push(u);
1343
- }
1344
- }
1345
- return e.rawEncode(f, m);
1346
- },
1347
- /**
1348
- * Encodes the type of an object by encoding a comma delimited list of its members
1349
- *
1350
- * @param {string} primaryType - Root type to encode
1351
- * @param {Object} types - Type definitions
1352
- * @returns {string} - Encoded representation of the type of an object
1353
- */
1354
- encodeType(i, a) {
1355
- let c = "", l = this.findTypeDependencies(i, a).filter((f) => f !== i);
1356
- l = [i].concat(l.sort());
1357
- for (const f of l) {
1358
- if (!a[f])
1359
- throw new Error("No type definition specified: " + f);
1360
- c += f + "(" + a[f].map(({ name: E, type: u }) => u + " " + E).join(",") + ")";
1361
- }
1362
- return c;
1363
- },
1364
- /**
1365
- * Finds all types within a type definition object
1366
- *
1367
- * @param {string} primaryType - Root type
1368
- * @param {Object} types - Type definitions
1369
- * @param {Array} results - current set of accumulated types
1370
- * @returns {Array} - Set of all types found in the type definition
1371
- */
1372
- findTypeDependencies(i, a, c = []) {
1373
- if (i = i.match(/^\w*/)[0], c.includes(i) || a[i] === void 0)
1374
- return c;
1375
- c.push(i);
1376
- for (const l of a[i])
1377
- for (const f of this.findTypeDependencies(l.type, a, c))
1378
- !c.includes(f) && c.push(f);
1379
- return c;
1380
- },
1381
- /**
1382
- * Hashes an object
1383
- *
1384
- * @param {string} primaryType - Root type
1385
- * @param {Object} data - Object to hash
1386
- * @param {Object} types - Type definitions
1387
- * @returns {Buffer} - Hash of an object
1388
- */
1389
- hashStruct(i, a, c, l = !0) {
1390
- return t.keccak(this.encodeData(i, a, c, l));
1391
- },
1392
- /**
1393
- * Hashes the type of an object
1394
- *
1395
- * @param {string} primaryType - Root type to hash
1396
- * @param {Object} types - Type definitions
1397
- * @returns {string} - Hash of an object
1398
- */
1399
- hashType(i, a) {
1400
- return t.keccak(this.encodeType(i, a));
1401
- },
1402
- /**
1403
- * Removes properties from a message object that are not defined per EIP-712
1404
- *
1405
- * @param {Object} data - typed message object
1406
- * @returns {Object} - typed message object with only allowed fields
1407
- */
1408
- sanitizeData(i) {
1409
- const a = {};
1410
- for (const c in n.properties)
1411
- i[c] && (a[c] = i[c]);
1412
- return a.types && (a.types = Object.assign({ EIP712Domain: [] }, a.types)), a;
1413
- },
1414
- /**
1415
- * Returns the hash of a typed message as per EIP-712 for signing
1416
- *
1417
- * @param {Object} typedData - Types message data to sign
1418
- * @returns {string} - sha3 hash for signing
1419
- */
1420
- hash(i, a = !0) {
1421
- const c = this.sanitizeData(i), l = [N.from("1901", "hex")];
1422
- return l.push(this.hashStruct("EIP712Domain", c.domain, c.types, a)), c.primaryType !== "EIP712Domain" && l.push(this.hashStruct(c.primaryType, c.message, c.types, a)), t.keccak(N.concat(l));
1423
- }
1424
- };
1425
- be = {
1426
- TYPED_MESSAGE_SCHEMA: n,
1427
- TypedDataUtils: s,
1428
- hashForSignTypedDataLegacy: function(i) {
1429
- return r(i.data);
1430
- },
1431
- hashForSignTypedData_v3: function(i) {
1432
- return s.hash(i.data, !1);
1433
- },
1434
- hashForSignTypedData_v4: function(i) {
1435
- return s.hash(i.data);
1436
- }
1437
- };
1438
- function r(i) {
1439
- const a = new Error("Expect argument to be non-empty array");
1440
- if (typeof i != "object" || !i.length) throw a;
1441
- const c = i.map(function(m) {
1442
- return m.type === "bytes" ? t.toBuffer(m.value) : m.value;
1443
- }), l = i.map(function(m) {
1444
- return m.type;
1445
- }), f = i.map(function(m) {
1446
- if (!m.name) throw a;
1447
- return m.type + " " + m.name;
1448
- });
1449
- return e.soliditySHA3(
1450
- ["bytes32", "bytes32"],
1451
- [
1452
- e.soliditySHA3(new Array(i.length).fill("string"), f),
1453
- e.soliditySHA3(l, c)
1454
- ]
1455
- );
1456
- }
1457
- return be;
1458
- }
1459
- var en = /* @__PURE__ */ Xt();
1460
- const ae = /* @__PURE__ */ Et(en), tn = "walletUsername", ve = "Addresses", nn = "AppVersion";
1461
- function U(t) {
1462
- return t.errorMessage !== void 0;
1463
- }
1464
- class sn {
1465
- // @param secret hex representation of 32-byte secret
1466
- constructor(e) {
1467
- this.secret = e;
1468
- }
1469
- /**
1470
- *
1471
- * @param plainText string to be encrypted
1472
- * returns hex string representation of bytes in the order: initialization vector (iv),
1473
- * auth tag, encrypted plaintext. IV is 12 bytes. Auth tag is 16 bytes. Remaining bytes are the
1474
- * encrypted plainText.
1475
- */
1476
- async encrypt(e) {
1477
- const n = this.secret;
1478
- if (n.length !== 64)
1479
- throw Error("secret must be 256 bits");
1480
- const s = crypto.getRandomValues(new Uint8Array(12)), r = await crypto.subtle.importKey("raw", oe(n), { name: "aes-gcm" }, !1, ["encrypt", "decrypt"]), i = new TextEncoder(), a = await window.crypto.subtle.encrypt({
1481
- name: "AES-GCM",
1482
- iv: s
1483
- }, r, i.encode(e)), c = 16, l = a.slice(a.byteLength - c), f = a.slice(0, a.byteLength - c), m = new Uint8Array(l), E = new Uint8Array(f), u = new Uint8Array([...s, ...m, ...E]);
1484
- return Se(u);
1485
- }
1486
- /**
1487
- *
1488
- * @param cipherText hex string representation of bytes in the order: initialization vector (iv),
1489
- * auth tag, encrypted plaintext. IV is 12 bytes. Auth tag is 16 bytes.
1490
- */
1491
- async decrypt(e) {
1492
- const n = this.secret;
1493
- if (n.length !== 64)
1494
- throw Error("secret must be 256 bits");
1495
- return new Promise((s, r) => {
1496
- (async function() {
1497
- const i = await crypto.subtle.importKey("raw", oe(n), { name: "aes-gcm" }, !1, ["encrypt", "decrypt"]), a = oe(e), c = a.slice(0, 12), l = a.slice(12, 28), f = a.slice(28), m = new Uint8Array([...f, ...l]), E = {
1498
- name: "AES-GCM",
1499
- iv: new Uint8Array(c)
1500
- };
1501
- try {
1502
- const u = await window.crypto.subtle.decrypt(E, i, m), d = new TextDecoder();
1503
- s(d.decode(u));
1504
- } catch (u) {
1505
- r(u);
1506
- }
1507
- })();
1508
- });
1509
- }
1510
- }
1511
- class rn {
1512
- constructor(e, n, s) {
1513
- this.linkAPIUrl = e, this.sessionId = n;
1514
- const r = `${n}:${s}`;
1515
- this.auth = `Basic ${btoa(r)}`;
1516
- }
1517
- // mark unseen events as seen
1518
- async markUnseenEventsAsSeen(e) {
1519
- return Promise.all(e.map((n) => fetch(`${this.linkAPIUrl}/events/${n.eventId}/seen`, {
1520
- method: "POST",
1521
- headers: {
1522
- Authorization: this.auth
1523
- }
1524
- }))).catch((n) => console.error("Unabled to mark event as failed:", n));
1525
- }
1526
- async fetchUnseenEvents() {
1527
- var e;
1528
- const n = await fetch(`${this.linkAPIUrl}/events?unseen=true`, {
1529
- headers: {
1530
- Authorization: this.auth
1531
- }
1532
- });
1533
- if (n.ok) {
1534
- const { events: s, error: r } = await n.json();
1535
- if (r)
1536
- throw new Error(`Check unseen events failed: ${r}`);
1537
- const i = (e = s == null ? void 0 : s.filter((a) => a.event === "Web3Response").map((a) => ({
1538
- type: "Event",
1539
- sessionId: this.sessionId,
1540
- eventId: a.id,
1541
- event: a.event,
1542
- data: a.data
1543
- }))) !== null && e !== void 0 ? e : [];
1544
- return this.markUnseenEventsAsSeen(i), i;
1545
- }
1546
- throw new Error(`Check unseen events failed: ${n.status}`);
1547
- }
1548
- }
1549
- var G;
1550
- (function(t) {
1551
- t[t.DISCONNECTED = 0] = "DISCONNECTED", t[t.CONNECTING = 1] = "CONNECTING", t[t.CONNECTED = 2] = "CONNECTED";
1552
- })(G || (G = {}));
1553
- class an {
1554
- setConnectionStateListener(e) {
1555
- this.connectionStateListener = e;
1556
- }
1557
- setIncomingDataListener(e) {
1558
- this.incomingDataListener = e;
1559
- }
1560
- /**
1561
- * Constructor
1562
- * @param url WebSocket server URL
1563
- * @param [WebSocketClass] Custom WebSocket implementation
1564
- */
1565
- constructor(e, n = WebSocket) {
1566
- this.WebSocketClass = n, this.webSocket = null, this.pendingData = [], this.url = e.replace(/^http/, "ws");
1567
- }
1568
- /**
1569
- * Make a websocket connection
1570
- * @returns a Promise that resolves when connected
1571
- */
1572
- async connect() {
1573
- if (this.webSocket)
1574
- throw new Error("webSocket object is not null");
1575
- return new Promise((e, n) => {
1576
- var s;
1577
- let r;
1578
- try {
1579
- this.webSocket = r = new this.WebSocketClass(this.url);
1580
- } catch (i) {
1581
- n(i);
1582
- return;
1583
- }
1584
- (s = this.connectionStateListener) === null || s === void 0 || s.call(this, G.CONNECTING), r.onclose = (i) => {
1585
- var a;
1586
- this.clearWebSocket(), n(new Error(`websocket error ${i.code}: ${i.reason}`)), (a = this.connectionStateListener) === null || a === void 0 || a.call(this, G.DISCONNECTED);
1587
- }, r.onopen = (i) => {
1588
- var a;
1589
- e(), (a = this.connectionStateListener) === null || a === void 0 || a.call(this, G.CONNECTED), this.pendingData.length > 0 && ([...this.pendingData].forEach((l) => this.sendData(l)), this.pendingData = []);
1590
- }, r.onmessage = (i) => {
1591
- var a, c;
1592
- if (i.data === "h")
1593
- (a = this.incomingDataListener) === null || a === void 0 || a.call(this, {
1594
- type: "Heartbeat"
1595
- });
1596
- else
1597
- try {
1598
- const l = JSON.parse(i.data);
1599
- (c = this.incomingDataListener) === null || c === void 0 || c.call(this, l);
1600
- } catch {
1601
- }
1602
- };
1603
- });
1604
- }
1605
- /**
1606
- * Disconnect from server
1607
- */
1608
- disconnect() {
1609
- var e;
1610
- const { webSocket: n } = this;
1611
- if (n) {
1612
- this.clearWebSocket(), (e = this.connectionStateListener) === null || e === void 0 || e.call(this, G.DISCONNECTED), this.connectionStateListener = void 0, this.incomingDataListener = void 0;
1613
- try {
1614
- n.close();
1615
- } catch {
1616
- }
1617
- }
1618
- }
1619
- /**
1620
- * Send data to server
1621
- * @param data text to send
1622
- */
1623
- sendData(e) {
1624
- const { webSocket: n } = this;
1625
- if (!n) {
1626
- this.pendingData.push(e), this.connect();
1627
- return;
1628
- }
1629
- n.send(e);
1630
- }
1631
- clearWebSocket() {
1632
- const { webSocket: e } = this;
1633
- e && (this.webSocket = null, e.onclose = null, e.onerror = null, e.onmessage = null, e.onopen = null);
1634
- }
1635
- }
1636
- const He = 1e4, on = 6e4;
1637
- class cn {
1638
- /**
1639
- * Constructor
1640
- * @param session Session
1641
- * @param linkAPIUrl Coinbase Wallet link server URL
1642
- * @param listener WalletLinkConnectionUpdateListener
1643
- * @param [WebSocketClass] Custom WebSocket implementation
1644
- */
1645
- constructor({ session: e, linkAPIUrl: n, listener: s }) {
1646
- this.destroyed = !1, this.lastHeartbeatResponse = 0, this.nextReqId = z(1), this._connected = !1, this._linked = !1, this.shouldFetchUnseenEventsOnConnect = !1, this.requestResolutions = /* @__PURE__ */ new Map(), this.handleSessionMetadataUpdated = (i) => {
1647
- if (!i)
1648
- return;
1649
- (/* @__PURE__ */ new Map([
1650
- ["__destroyed", this.handleDestroyed],
1651
- ["EthereumAddress", this.handleAccountUpdated],
1652
- ["WalletUsername", this.handleWalletUsernameUpdated],
1653
- ["AppVersion", this.handleAppVersionUpdated],
1654
- [
1655
- "ChainId",
1656
- // ChainId and JsonRpcUrl are always updated together
1657
- (c) => i.JsonRpcUrl && this.handleChainUpdated(c, i.JsonRpcUrl)
1658
- ]
1659
- ])).forEach((c, l) => {
1660
- const f = i[l];
1661
- f !== void 0 && c(f);
1662
- });
1663
- }, this.handleDestroyed = (i) => {
1664
- var a;
1665
- i === "1" && ((a = this.listener) === null || a === void 0 || a.resetAndReload());
1666
- }, this.handleAccountUpdated = async (i) => {
1667
- var a;
1668
- const c = await this.cipher.decrypt(i);
1669
- (a = this.listener) === null || a === void 0 || a.accountUpdated(c);
1670
- }, this.handleMetadataUpdated = async (i, a) => {
1671
- var c;
1672
- const l = await this.cipher.decrypt(a);
1673
- (c = this.listener) === null || c === void 0 || c.metadataUpdated(i, l);
1674
- }, this.handleWalletUsernameUpdated = async (i) => {
1675
- this.handleMetadataUpdated(tn, i);
1676
- }, this.handleAppVersionUpdated = async (i) => {
1677
- this.handleMetadataUpdated(nn, i);
1678
- }, this.handleChainUpdated = async (i, a) => {
1679
- var c;
1680
- const l = await this.cipher.decrypt(i), f = await this.cipher.decrypt(a);
1681
- (c = this.listener) === null || c === void 0 || c.chainUpdated(l, f);
1682
- }, this.session = e, this.cipher = new sn(e.secret), this.listener = s;
1683
- const r = new an(`${n}/rpc`, WebSocket);
1684
- r.setConnectionStateListener(async (i) => {
1685
- let a = !1;
1686
- switch (i) {
1687
- case G.DISCONNECTED:
1688
- if (!this.destroyed) {
1689
- const c = async () => {
1690
- await new Promise((l) => setTimeout(l, 5e3)), this.destroyed || r.connect().catch(() => {
1691
- c();
1692
- });
1693
- };
1694
- c();
1695
- }
1696
- break;
1697
- case G.CONNECTED:
1698
- a = await this.handleConnected(), this.updateLastHeartbeat(), setInterval(() => {
1699
- this.heartbeat();
1700
- }, He), this.shouldFetchUnseenEventsOnConnect && this.fetchUnseenEventsAPI();
1701
- break;
1702
- case G.CONNECTING:
1703
- break;
1704
- }
1705
- this.connected !== a && (this.connected = a);
1706
- }), r.setIncomingDataListener((i) => {
1707
- var a;
1708
- switch (i.type) {
1709
- // handle server's heartbeat responses
1710
- case "Heartbeat":
1711
- this.updateLastHeartbeat();
1712
- return;
1713
- // handle link status updates
1714
- case "IsLinkedOK":
1715
- case "Linked": {
1716
- const c = i.type === "IsLinkedOK" ? i.linked : void 0;
1717
- this.linked = c || i.onlineGuests > 0;
1718
- break;
1719
- }
1720
- // handle session config updates
1721
- case "GetSessionConfigOK":
1722
- case "SessionConfigUpdated": {
1723
- this.handleSessionMetadataUpdated(i.metadata);
1724
- break;
1725
- }
1726
- case "Event": {
1727
- this.handleIncomingEvent(i);
1728
- break;
1729
- }
1730
- }
1731
- i.id !== void 0 && ((a = this.requestResolutions.get(i.id)) === null || a === void 0 || a(i));
1732
- }), this.ws = r, this.http = new rn(n, e.id, e.key);
1733
- }
1734
- /**
1735
- * Make a connection to the server
1736
- */
1737
- connect() {
1738
- if (this.destroyed)
1739
- throw new Error("instance is destroyed");
1740
- this.ws.connect();
1741
- }
1742
- /**
1743
- * Terminate connection, and mark as destroyed. To reconnect, create a new
1744
- * instance of WalletSDKConnection
1745
- */
1746
- async destroy() {
1747
- this.destroyed || (await this.makeRequest({
1748
- type: "SetSessionConfig",
1749
- id: z(this.nextReqId++),
1750
- sessionId: this.session.id,
1751
- metadata: { __destroyed: "1" }
1752
- }, { timeout: 1e3 }), this.destroyed = !0, this.ws.disconnect(), this.listener = void 0);
1753
- }
1754
- get connected() {
1755
- return this._connected;
1756
- }
1757
- set connected(e) {
1758
- this._connected = e;
1759
- }
1760
- get linked() {
1761
- return this._linked;
1762
- }
1763
- set linked(e) {
1764
- var n, s;
1765
- this._linked = e, e && ((n = this.onceLinked) === null || n === void 0 || n.call(this)), (s = this.listener) === null || s === void 0 || s.linkedUpdated(e);
1766
- }
1767
- setOnceLinked(e) {
1768
- return new Promise((n) => {
1769
- this.linked ? e().then(n) : this.onceLinked = () => {
1770
- e().then(n), this.onceLinked = void 0;
1771
- };
1772
- });
1773
- }
1774
- async handleIncomingEvent(e) {
1775
- var n;
1776
- if (e.type !== "Event" || e.event !== "Web3Response")
1777
- return;
1778
- const s = await this.cipher.decrypt(e.data), r = JSON.parse(s);
1779
- if (r.type !== "WEB3_RESPONSE")
1780
- return;
1781
- const { id: i, response: a } = r;
1782
- (n = this.listener) === null || n === void 0 || n.handleWeb3ResponseMessage(i, a);
1783
- }
1784
- async checkUnseenEvents() {
1785
- if (!this.connected) {
1786
- this.shouldFetchUnseenEventsOnConnect = !0;
1787
- return;
1788
- }
1789
- await new Promise((e) => setTimeout(e, 250));
1790
- try {
1791
- await this.fetchUnseenEventsAPI();
1792
- } catch (e) {
1793
- console.error("Unable to check for unseen events", e);
1794
- }
1795
- }
1796
- async fetchUnseenEventsAPI() {
1797
- this.shouldFetchUnseenEventsOnConnect = !1, (await this.http.fetchUnseenEvents()).forEach((n) => this.handleIncomingEvent(n));
1798
- }
1799
- /**
1800
- * Publish an event and emit event ID when successful
1801
- * @param event event name
1802
- * @param unencryptedData unencrypted event data
1803
- * @param callWebhook whether the webhook should be invoked
1804
- * @returns a Promise that emits event ID when successful
1805
- */
1806
- async publishEvent(e, n, s = !1) {
1807
- const r = await this.cipher.encrypt(JSON.stringify(Object.assign(Object.assign({}, n), { origin: location.origin, relaySource: "coinbaseWalletExtension" in window && window.coinbaseWalletExtension ? "injected_sdk" : "sdk" }))), i = {
1808
- type: "PublishEvent",
1809
- id: z(this.nextReqId++),
1810
- sessionId: this.session.id,
1811
- event: e,
1812
- data: r,
1813
- callWebhook: s
1814
- };
1815
- return this.setOnceLinked(async () => {
1816
- const a = await this.makeRequest(i);
1817
- if (a.type === "Fail")
1818
- throw new Error(a.error || "failed to publish event");
1819
- return a.eventId;
1820
- });
1821
- }
1822
- sendData(e) {
1823
- this.ws.sendData(JSON.stringify(e));
1824
- }
1825
- updateLastHeartbeat() {
1826
- this.lastHeartbeatResponse = Date.now();
1827
- }
1828
- heartbeat() {
1829
- if (Date.now() - this.lastHeartbeatResponse > He * 2) {
1830
- this.ws.disconnect();
1831
- return;
1832
- }
1833
- try {
1834
- this.ws.sendData("h");
1835
- } catch {
1836
- }
1837
- }
1838
- async makeRequest(e, n = { timeout: on }) {
1839
- const s = e.id;
1840
- this.sendData(e);
1841
- let r;
1842
- return Promise.race([
1843
- new Promise((i, a) => {
1844
- r = window.setTimeout(() => {
1845
- a(new Error(`request ${s} timed out`));
1846
- }, n.timeout);
1847
- }),
1848
- new Promise((i) => {
1849
- this.requestResolutions.set(s, (a) => {
1850
- clearTimeout(r), i(a), this.requestResolutions.delete(s);
1851
- });
1852
- })
1853
- ]);
1854
- }
1855
- async handleConnected() {
1856
- return (await this.makeRequest({
1857
- type: "HostSession",
1858
- id: z(this.nextReqId++),
1859
- sessionId: this.session.id,
1860
- sessionKey: this.session.key
1861
- })).type === "Fail" ? !1 : (this.sendData({
1862
- type: "IsLinked",
1863
- id: z(this.nextReqId++),
1864
- sessionId: this.session.id
1865
- }), this.sendData({
1866
- type: "GetSessionConfig",
1867
- id: z(this.nextReqId++),
1868
- sessionId: this.session.id
1869
- }), !0);
1870
- }
1871
- }
1872
- class dn {
1873
- constructor() {
1874
- this._nextRequestId = 0, this.callbacks = /* @__PURE__ */ new Map();
1875
- }
1876
- makeRequestId() {
1877
- this._nextRequestId = (this._nextRequestId + 1) % 2147483647;
1878
- const e = this._nextRequestId, n = ot(e.toString(16));
1879
- return this.callbacks.get(n) && this.callbacks.delete(n), e;
1880
- }
1881
- }
1882
- const ze = "session:id", Fe = "session:secret", Ge = "session:linked";
1883
- class Z {
1884
- constructor(e, n, s, r = !1) {
1885
- this.storage = e, this.id = n, this.secret = s, this.key = It(St(`${n}, ${s} WalletLink`)), this._linked = !!r;
1886
- }
1887
- static create(e) {
1888
- const n = J(16), s = J(32);
1889
- return new Z(e, n, s).save();
1890
- }
1891
- static load(e) {
1892
- const n = e.getItem(ze), s = e.getItem(Ge), r = e.getItem(Fe);
1893
- return n && r ? new Z(e, n, r, s === "1") : null;
1894
- }
1895
- get linked() {
1896
- return this._linked;
1897
- }
1898
- set linked(e) {
1899
- this._linked = e, this.persistLinked();
1900
- }
1901
- save() {
1902
- return this.storage.setItem(ze, this.id), this.storage.setItem(Fe, this.secret), this.persistLinked(), this;
1903
- }
1904
- persistLinked() {
1905
- this.storage.setItem(Ge, this._linked ? "1" : "0");
1906
- }
1907
- }
1908
- function ln() {
1909
- try {
1910
- return window.frameElement !== null;
1911
- } catch {
1912
- return !1;
1913
- }
1914
- }
1915
- function un() {
1916
- try {
1917
- return ln() && window.top ? window.top.location : window.location;
1918
- } catch {
1919
- return window.location;
1920
- }
1921
- }
1922
- function hn() {
1923
- var t;
1924
- return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test((t = window == null ? void 0 : window.navigator) === null || t === void 0 ? void 0 : t.userAgent);
1925
- }
1926
- function gt() {
1927
- var t, e;
1928
- return (e = (t = window == null ? void 0 : window.matchMedia) === null || t === void 0 ? void 0 : t.call(window, "(prefers-color-scheme: dark)").matches) !== null && e !== void 0 ? e : !1;
1929
- }
1930
- const fn = '@namespace svg "http://www.w3.org/2000/svg";.-cbwsdk-css-reset,.-cbwsdk-css-reset *{animation:none;animation-delay:0;animation-direction:normal;animation-duration:0;animation-fill-mode:none;animation-iteration-count:1;animation-name:none;animation-play-state:running;animation-timing-function:ease;backface-visibility:visible;background:0;background-attachment:scroll;background-clip:border-box;background-color:rgba(0,0,0,0);background-image:none;background-origin:padding-box;background-position:0 0;background-position-x:0;background-position-y:0;background-repeat:repeat;background-size:auto auto;border:0;border-style:none;border-width:medium;border-color:inherit;border-bottom:0;border-bottom-color:inherit;border-bottom-left-radius:0;border-bottom-right-radius:0;border-bottom-style:none;border-bottom-width:medium;border-collapse:separate;border-image:none;border-left:0;border-left-color:inherit;border-left-style:none;border-left-width:medium;border-radius:0;border-right:0;border-right-color:inherit;border-right-style:none;border-right-width:medium;border-spacing:0;border-top:0;border-top-color:inherit;border-top-left-radius:0;border-top-right-radius:0;border-top-style:none;border-top-width:medium;box-shadow:none;box-sizing:border-box;caption-side:top;clear:none;clip:auto;color:inherit;columns:auto;column-count:auto;column-fill:balance;column-gap:normal;column-rule:medium none currentColor;column-rule-color:currentColor;column-rule-style:none;column-rule-width:none;column-span:1;column-width:auto;counter-increment:none;counter-reset:none;direction:ltr;empty-cells:show;float:none;font:normal;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;height:auto;hyphens:none;letter-spacing:normal;line-height:normal;list-style:none;list-style-image:none;list-style-position:outside;list-style-type:disc;margin:0;margin-bottom:0;margin-left:0;margin-right:0;margin-top:0;opacity:1;orphans:0;outline:0;outline-color:invert;outline-style:none;outline-width:medium;overflow:visible;overflow-x:visible;overflow-y:visible;padding:0;padding-bottom:0;padding-left:0;padding-right:0;padding-top:0;page-break-after:auto;page-break-before:auto;page-break-inside:auto;perspective:none;perspective-origin:50% 50%;pointer-events:auto;position:static;quotes:"\\201C" "\\201D" "\\2018" "\\2019";tab-size:8;table-layout:auto;text-align:inherit;text-align-last:auto;text-decoration:none;text-decoration-color:inherit;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-shadow:none;text-transform:none;transform:none;transform-style:flat;transition:none;transition-delay:0s;transition-duration:0s;transition-property:none;transition-timing-function:ease;unicode-bidi:normal;vertical-align:baseline;visibility:visible;white-space:normal;widows:0;word-spacing:normal;z-index:auto}.-cbwsdk-css-reset strong{font-weight:bold}.-cbwsdk-css-reset *{box-sizing:border-box;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI","Helvetica Neue",Arial,sans-serif;line-height:1}.-cbwsdk-css-reset [class*=container]{margin:0;padding:0}.-cbwsdk-css-reset style{display:none}';
1931
- function bt() {
1932
- const t = document.createElement("style");
1933
- t.type = "text/css", t.appendChild(document.createTextNode(fn)), document.documentElement.appendChild(t);
1934
- }
1935
- const pn = ".-cbwsdk-css-reset .-gear-container{margin-left:16px !important;margin-right:9px !important;display:flex;align-items:center;justify-content:center;width:24px;height:24px;transition:opacity .25s}.-cbwsdk-css-reset .-gear-container *{user-select:none}.-cbwsdk-css-reset .-gear-container svg{opacity:0;position:absolute}.-cbwsdk-css-reset .-gear-icon{height:12px;width:12px;z-index:10000}.-cbwsdk-css-reset .-cbwsdk-snackbar{align-items:flex-end;display:flex;flex-direction:column;position:fixed;right:0;top:0;z-index:2147483647}.-cbwsdk-css-reset .-cbwsdk-snackbar *{user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance{display:flex;flex-direction:column;margin:8px 16px 0 16px;overflow:visible;text-align:left;transform:translateX(0);transition:opacity .25s,transform .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header:hover .-gear-container svg{opacity:1}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header{display:flex;align-items:center;background:#fff;overflow:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-cblogo{margin:8px 8px 8px 8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-header-message{color:#000;font-size:13px;line-height:1.5;user-select:none}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu{background:#fff;transition:opacity .25s ease-in-out,transform .25s linear,visibility 0s;visibility:hidden;border:1px solid #e7ebee;box-sizing:border-box;border-radius:8px;opacity:0;flex-direction:column;padding-left:8px;padding-right:8px}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:last-child{margin-bottom:8px !important}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover{background:#f5f7f8;border-radius:6px;transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover span{color:#050f19;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item:hover svg path{fill:#000;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item{visibility:inherit;height:35px;margin-top:8px;margin-bottom:0;display:flex;flex-direction:row;align-items:center;padding:8px;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item *{visibility:inherit;cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover{background:rgba(223,95,103,.2);transition:background .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover *{cursor:pointer}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover svg path{fill:#df5f67;transition:fill .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-is-red:hover span{color:#df5f67;transition:color .25s}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-menu-item-info{color:#aaa;font-size:13px;margin:0 8px 0 32px;position:absolute}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-hidden{opacity:0;text-align:left;transform:translateX(25%);transition:opacity .5s linear}.-cbwsdk-css-reset .-cbwsdk-snackbar-instance-expanded .-cbwsdk-snackbar-instance-menu{opacity:1;display:flex;transform:translateY(8px);visibility:visible}", gn = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEuNDkyIDEwLjQxOWE4LjkzIDguOTMgMCAwMTguOTMtOC45M2gxMS4xNjNhOC45MyA4LjkzIDAgMDE4LjkzIDguOTN2MTEuMTYzYTguOTMgOC45MyAwIDAxLTguOTMgOC45M0gxMC40MjJhOC45MyA4LjkzIDAgMDEtOC45My04LjkzVjEwLjQxOXoiIGZpbGw9IiMxNjUyRjAiLz48cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTEwLjQxOSAwSDIxLjU4QzI3LjMzNSAwIDMyIDQuNjY1IDMyIDEwLjQxOVYyMS41OEMzMiAyNy4zMzUgMjcuMzM1IDMyIDIxLjU4MSAzMkgxMC40MkM0LjY2NSAzMiAwIDI3LjMzNSAwIDIxLjU4MVYxMC40MkMwIDQuNjY1IDQuNjY1IDAgMTAuNDE5IDB6bTAgMS40ODhhOC45MyA4LjkzIDAgMDAtOC45MyA4LjkzdjExLjE2M2E4LjkzIDguOTMgMCAwMDguOTMgOC45M0gyMS41OGE4LjkzIDguOTMgMCAwMDguOTMtOC45M1YxMC40MmE4LjkzIDguOTMgMCAwMC04LjkzLTguOTNIMTAuNDJ6IiBmaWxsPSIjZmZmIi8+PHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0xNS45OTggMjYuMDQ5Yy01LjU0OSAwLTEwLjA0Ny00LjQ5OC0xMC4wNDctMTAuMDQ3IDAtNS41NDggNC40OTgtMTAuMDQ2IDEwLjA0Ny0xMC4wNDYgNS41NDggMCAxMC4wNDYgNC40OTggMTAuMDQ2IDEwLjA0NiAwIDUuNTQ5LTQuNDk4IDEwLjA0Ny0xMC4wNDYgMTAuMDQ3eiIgZmlsbD0iI2ZmZiIvPjxwYXRoIGQ9Ik0xMi43NjIgMTQuMjU0YzAtLjgyMi42NjctMS40ODkgMS40ODktMS40ODloMy40OTdjLjgyMiAwIDEuNDg4LjY2NiAxLjQ4OCAxLjQ4OXYzLjQ5N2MwIC44MjItLjY2NiAxLjQ4OC0xLjQ4OCAxLjQ4OGgtMy40OTdhMS40ODggMS40ODggMCAwMS0xLjQ4OS0xLjQ4OHYtMy40OTh6IiBmaWxsPSIjMTY1MkYwIi8+PC9zdmc+", bn = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTIiIGhlaWdodD0iMTIiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDYuNzV2LTEuNWwtMS43Mi0uNTdjLS4wOC0uMjctLjE5LS41Mi0uMzItLjc3bC44MS0xLjYyLTEuMDYtMS4wNi0xLjYyLjgxYy0uMjQtLjEzLS41LS4yNC0uNzctLjMyTDYuNzUgMGgtMS41bC0uNTcgMS43MmMtLjI3LjA4LS41My4xOS0uNzcuMzJsLTEuNjItLjgxLTEuMDYgMS4wNi44MSAxLjYyYy0uMTMuMjQtLjI0LjUtLjMyLjc3TDAgNS4yNXYxLjVsMS43Mi41N2MuMDguMjcuMTkuNTMuMzIuNzdsLS44MSAxLjYyIDEuMDYgMS4wNiAxLjYyLS44MWMuMjQuMTMuNS4yMy43Ny4zMkw1LjI1IDEyaDEuNWwuNTctMS43MmMuMjctLjA4LjUyLS4xOS43Ny0uMzJsMS42Mi44MSAxLjA2LTEuMDYtLjgxLTEuNjJjLjEzLS4yNC4yMy0uNS4zMi0uNzdMMTIgNi43NXpNNiA4LjVhMi41IDIuNSAwIDAxMC01IDIuNSAyLjUgMCAwMTAgNXoiIGZpbGw9IiMwNTBGMTkiLz48L3N2Zz4=";
1936
- class wn {
1937
- constructor() {
1938
- this.items = /* @__PURE__ */ new Map(), this.nextItemKey = 0, this.root = null, this.darkMode = gt();
1939
- }
1940
- attach(e) {
1941
- this.root = document.createElement("div"), this.root.className = "-cbwsdk-snackbar-root", e.appendChild(this.root), this.render();
1942
- }
1943
- presentItem(e) {
1944
- const n = this.nextItemKey++;
1945
- return this.items.set(n, e), this.render(), () => {
1946
- this.items.delete(n), this.render();
1947
- };
1948
- }
1949
- clear() {
1950
- this.items.clear(), this.render();
1951
- }
1952
- render() {
1953
- this.root && we(R(
1954
- "div",
1955
- null,
1956
- R(wt, { darkMode: this.darkMode }, Array.from(this.items.entries()).map(([e, n]) => R(yn, Object.assign({}, n, { key: e }))))
1957
- ), this.root);
1958
- }
1959
- }
1960
- const wt = (t) => R(
1961
- "div",
1962
- { class: te("-cbwsdk-snackbar-container") },
1963
- R("style", null, pn),
1964
- R("div", { class: "-cbwsdk-snackbar" }, t.children)
1965
- ), yn = ({ autoExpand: t, message: e, menuItems: n }) => {
1966
- const [s, r] = Le(!0), [i, a] = Le(t ?? !1);
1967
- Ct(() => {
1968
- const l = [
1969
- window.setTimeout(() => {
1970
- r(!1);
1971
- }, 1),
1972
- window.setTimeout(() => {
1973
- a(!0);
1974
- }, 1e4)
1975
- ];
1976
- return () => {
1977
- l.forEach(window.clearTimeout);
1978
- };
1979
- });
1980
- const c = () => {
1981
- a(!i);
1982
- };
1983
- return R(
1984
- "div",
1985
- { class: te("-cbwsdk-snackbar-instance", s && "-cbwsdk-snackbar-instance-hidden", i && "-cbwsdk-snackbar-instance-expanded") },
1986
- R(
1987
- "div",
1988
- { class: "-cbwsdk-snackbar-instance-header", onClick: c },
1989
- R("img", { src: gn, class: "-cbwsdk-snackbar-instance-header-cblogo" }),
1990
- " ",
1991
- R("div", { class: "-cbwsdk-snackbar-instance-header-message" }, e),
1992
- R(
1993
- "div",
1994
- { class: "-gear-container" },
1995
- !i && R(
1996
- "svg",
1997
- { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
1998
- R("circle", { cx: "12", cy: "12", r: "12", fill: "#F5F7F8" })
1999
- ),
2000
- R("img", { src: bn, class: "-gear-icon", title: "Expand" })
2001
- )
2002
- ),
2003
- n && n.length > 0 && R("div", { class: "-cbwsdk-snackbar-instance-menu" }, n.map((l, f) => R(
2004
- "div",
2005
- { class: te("-cbwsdk-snackbar-instance-menu-item", l.isRed && "-cbwsdk-snackbar-instance-menu-item-is-red"), onClick: l.onClick, key: f },
2006
- R(
2007
- "svg",
2008
- { width: l.svgWidth, height: l.svgHeight, viewBox: "0 0 10 11", fill: "none", xmlns: "http://www.w3.org/2000/svg" },
2009
- R("path", { "fill-rule": l.defaultFillRule, "clip-rule": l.defaultClipRule, d: l.path, fill: "#AAAAAA" })
2010
- ),
2011
- R("span", { class: te("-cbwsdk-snackbar-instance-menu-item-info", l.isRed && "-cbwsdk-snackbar-instance-menu-item-info-is-red") }, l.info)
2012
- )))
2013
- );
2014
- };
2015
- class mn {
2016
- constructor() {
2017
- this.attached = !1, this.snackbar = new wn();
2018
- }
2019
- attach() {
2020
- if (this.attached)
2021
- throw new Error("Coinbase Wallet SDK UI is already attached");
2022
- const e = document.documentElement, n = document.createElement("div");
2023
- n.className = "-cbwsdk-css-reset", e.appendChild(n), this.snackbar.attach(n), this.attached = !0, bt();
2024
- }
2025
- showConnecting(e) {
2026
- let n;
2027
- return e.isUnlinkedErrorState ? n = {
2028
- autoExpand: !0,
2029
- message: "Connection lost",
2030
- menuItems: [
2031
- {
2032
- isRed: !1,
2033
- info: "Reset connection",
2034
- svgWidth: "10",
2035
- svgHeight: "11",
2036
- path: "M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",
2037
- defaultFillRule: "evenodd",
2038
- defaultClipRule: "evenodd",
2039
- onClick: e.onResetConnection
2040
- }
2041
- ]
2042
- } : n = {
2043
- message: "Confirm on phone",
2044
- menuItems: [
2045
- {
2046
- isRed: !0,
2047
- info: "Cancel transaction",
2048
- svgWidth: "11",
2049
- svgHeight: "11",
2050
- path: "M10.3711 1.52346L9.21775 0.370117L5.37109 4.21022L1.52444 0.370117L0.371094 1.52346L4.2112 5.37012L0.371094 9.21677L1.52444 10.3701L5.37109 6.53001L9.21775 10.3701L10.3711 9.21677L6.53099 5.37012L10.3711 1.52346Z",
2051
- defaultFillRule: "inherit",
2052
- defaultClipRule: "inherit",
2053
- onClick: e.onCancel
2054
- },
2055
- {
2056
- isRed: !1,
2057
- info: "Reset connection",
2058
- svgWidth: "10",
2059
- svgHeight: "11",
2060
- path: "M5.00008 0.96875C6.73133 0.96875 8.23758 1.94375 9.00008 3.375L10.0001 2.375V5.5H9.53133H7.96883H6.87508L7.80633 4.56875C7.41258 3.3875 6.31258 2.53125 5.00008 2.53125C3.76258 2.53125 2.70633 3.2875 2.25633 4.36875L0.812576 3.76875C1.50008 2.125 3.11258 0.96875 5.00008 0.96875ZM2.19375 6.43125C2.5875 7.6125 3.6875 8.46875 5 8.46875C6.2375 8.46875 7.29375 7.7125 7.74375 6.63125L9.1875 7.23125C8.5 8.875 6.8875 10.0312 5 10.0312C3.26875 10.0312 1.7625 9.05625 1 7.625L0 8.625V5.5H0.46875H2.03125H3.125L2.19375 6.43125Z",
2061
- defaultFillRule: "evenodd",
2062
- defaultClipRule: "evenodd",
2063
- onClick: e.onResetConnection
2064
- }
2065
- ]
2066
- }, this.snackbar.presentItem(n);
2067
- }
2068
- }
2069
- const kn = ".-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop{position:fixed;top:0;left:0;right:0;bottom:0;transition:opacity .25s;background-color:rgba(10,11,13,.5)}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-backdrop-hidden{opacity:0}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box{display:block;position:fixed;top:50%;left:50%;transform:translate(-50%, -50%);padding:20px;border-radius:8px;background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box p{display:block;font-weight:400;font-size:14px;line-height:20px;padding-bottom:12px;color:#5b636e}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box button{appearance:none;border:none;background:none;color:#0052ff;padding:0;text-decoration:none;display:block;font-weight:600;font-size:16px;line-height:24px}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark{background-color:#0a0b0d;color:#fff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.dark button{color:#0052ff}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light{background-color:#fff;color:#0a0b0d}.-cbwsdk-css-reset .-cbwsdk-redirect-dialog-box.light button{color:#0052ff}";
2070
- class vn {
2071
- constructor() {
2072
- this.root = null, this.darkMode = gt();
2073
- }
2074
- attach() {
2075
- const e = document.documentElement;
2076
- this.root = document.createElement("div"), this.root.className = "-cbwsdk-css-reset", e.appendChild(this.root), bt();
2077
- }
2078
- present(e) {
2079
- this.render(e);
2080
- }
2081
- clear() {
2082
- this.render(null);
2083
- }
2084
- render(e) {
2085
- this.root && (we(null, this.root), e && we(R(En, Object.assign({}, e, { onDismiss: () => {
2086
- this.clear();
2087
- }, darkMode: this.darkMode })), this.root));
2088
- }
2089
- }
2090
- const En = ({ title: t, buttonText: e, darkMode: n, onButtonClick: s, onDismiss: r }) => {
2091
- const i = n ? "dark" : "light";
2092
- return R(
2093
- wt,
2094
- { darkMode: n },
2095
- R(
2096
- "div",
2097
- { class: "-cbwsdk-redirect-dialog" },
2098
- R("style", null, kn),
2099
- R("div", { class: "-cbwsdk-redirect-dialog-backdrop", onClick: r }),
2100
- R(
2101
- "div",
2102
- { class: te("-cbwsdk-redirect-dialog-box", i) },
2103
- R("p", null, t),
2104
- R("button", { onClick: s }, e)
2105
- )
2106
- )
2107
- );
2108
- }, In = "https://keys.coinbase.com/connect", Ye = "https://www.walletlink.org", Sn = "https://go.cb-w.com/walletlink";
2109
- class $e {
2110
- constructor() {
2111
- this.attached = !1, this.redirectDialog = new vn();
2112
- }
2113
- attach() {
2114
- if (this.attached)
2115
- throw new Error("Coinbase Wallet SDK UI is already attached");
2116
- this.redirectDialog.attach(), this.attached = !0;
2117
- }
2118
- redirectToCoinbaseWallet(e) {
2119
- const n = new URL(Sn);
2120
- n.searchParams.append("redirect_url", un().href), e && n.searchParams.append("wl_url", e);
2121
- const s = document.createElement("a");
2122
- s.target = "cbw-opener", s.href = n.href, s.rel = "noreferrer noopener", s.click();
2123
- }
2124
- openCoinbaseWalletDeeplink(e) {
2125
- this.redirectDialog.present({
2126
- title: "Redirecting to Coinbase Wallet...",
2127
- buttonText: "Open",
2128
- onButtonClick: () => {
2129
- this.redirectToCoinbaseWallet(e);
2130
- }
2131
- }), setTimeout(() => {
2132
- this.redirectToCoinbaseWallet(e);
2133
- }, 99);
2134
- }
2135
- showConnecting(e) {
2136
- return () => {
2137
- this.redirectDialog.clear();
2138
- };
2139
- }
2140
- }
2141
- class F {
2142
- constructor(e) {
2143
- this.chainCallbackParams = { chainId: "", jsonRpcUrl: "" }, this.isMobileWeb = hn(), this.linkedUpdated = (i) => {
2144
- this.isLinked = i;
2145
- const a = this.storage.getItem(ve);
2146
- if (i && (this._session.linked = i), this.isUnlinkedErrorState = !1, a) {
2147
- const c = a.split(" "), l = this.storage.getItem("IsStandaloneSigning") === "true";
2148
- c[0] !== "" && !i && this._session.linked && !l && (this.isUnlinkedErrorState = !0);
2149
- }
2150
- }, this.metadataUpdated = (i, a) => {
2151
- this.storage.setItem(i, a);
2152
- }, this.chainUpdated = (i, a) => {
2153
- this.chainCallbackParams.chainId === i && this.chainCallbackParams.jsonRpcUrl === a || (this.chainCallbackParams = {
2154
- chainId: i,
2155
- jsonRpcUrl: a
2156
- }, this.chainCallback && this.chainCallback(a, Number.parseInt(i, 10)));
2157
- }, this.accountUpdated = (i) => {
2158
- this.accountsCallback && this.accountsCallback([i]), F.accountRequestCallbackIds.size > 0 && (Array.from(F.accountRequestCallbackIds.values()).forEach((a) => {
2159
- this.invokeCallback(a, {
2160
- method: "requestEthereumAccounts",
2161
- result: [i]
2162
- });
2163
- }), F.accountRequestCallbackIds.clear());
2164
- }, this.resetAndReload = this.resetAndReload.bind(this), this.linkAPIUrl = e.linkAPIUrl, this.storage = e.storage, this.metadata = e.metadata, this.accountsCallback = e.accountsCallback, this.chainCallback = e.chainCallback;
2165
- const { session: n, ui: s, connection: r } = this.subscribe();
2166
- this._session = n, this.connection = r, this.relayEventManager = new dn(), this.ui = s, this.ui.attach();
2167
- }
2168
- subscribe() {
2169
- const e = Z.load(this.storage) || Z.create(this.storage), { linkAPIUrl: n } = this, s = new cn({
2170
- session: e,
2171
- linkAPIUrl: n,
2172
- listener: this
2173
- }), r = this.isMobileWeb ? new $e() : new mn();
2174
- return s.connect(), { session: e, ui: r, connection: s };
2175
- }
2176
- resetAndReload() {
2177
- this.connection.destroy().then(() => {
2178
- const e = Z.load(this.storage);
2179
- (e == null ? void 0 : e.id) === this._session.id && H.clearAll(), document.location.reload();
2180
- }).catch((e) => {
2181
- });
2182
- }
2183
- signEthereumTransaction(e) {
2184
- return this.sendRequest({
2185
- method: "signEthereumTransaction",
2186
- params: {
2187
- fromAddress: e.fromAddress,
2188
- toAddress: e.toAddress,
2189
- weiValue: K(e.weiValue),
2190
- data: ne(e.data, !0),
2191
- nonce: e.nonce,
2192
- gasPriceInWei: e.gasPriceInWei ? K(e.gasPriceInWei) : null,
2193
- maxFeePerGas: e.gasPriceInWei ? K(e.gasPriceInWei) : null,
2194
- maxPriorityFeePerGas: e.gasPriceInWei ? K(e.gasPriceInWei) : null,
2195
- gasLimit: e.gasLimit ? K(e.gasLimit) : null,
2196
- chainId: e.chainId,
2197
- shouldSubmit: !1
2198
- }
2199
- });
2200
- }
2201
- signAndSubmitEthereumTransaction(e) {
2202
- return this.sendRequest({
2203
- method: "signEthereumTransaction",
2204
- params: {
2205
- fromAddress: e.fromAddress,
2206
- toAddress: e.toAddress,
2207
- weiValue: K(e.weiValue),
2208
- data: ne(e.data, !0),
2209
- nonce: e.nonce,
2210
- gasPriceInWei: e.gasPriceInWei ? K(e.gasPriceInWei) : null,
2211
- maxFeePerGas: e.maxFeePerGas ? K(e.maxFeePerGas) : null,
2212
- maxPriorityFeePerGas: e.maxPriorityFeePerGas ? K(e.maxPriorityFeePerGas) : null,
2213
- gasLimit: e.gasLimit ? K(e.gasLimit) : null,
2214
- chainId: e.chainId,
2215
- shouldSubmit: !0
2216
- }
2217
- });
2218
- }
2219
- submitEthereumTransaction(e, n) {
2220
- return this.sendRequest({
2221
- method: "submitEthereumTransaction",
2222
- params: {
2223
- signedTransaction: ne(e, !0),
2224
- chainId: n
2225
- }
2226
- });
2227
- }
2228
- getWalletLinkSession() {
2229
- return this._session;
2230
- }
2231
- sendRequest(e) {
2232
- let n = null;
2233
- const s = J(8), r = (i) => {
2234
- this.publishWeb3RequestCanceledEvent(s), this.handleErrorResponse(s, e.method, i), n == null || n();
2235
- };
2236
- return new Promise((i, a) => {
2237
- n = this.ui.showConnecting({
2238
- isUnlinkedErrorState: this.isUnlinkedErrorState,
2239
- onCancel: r,
2240
- onResetConnection: this.resetAndReload
2241
- // eslint-disable-line @typescript-eslint/unbound-method
2242
- }), this.relayEventManager.callbacks.set(s, (c) => {
2243
- if (n == null || n(), U(c))
2244
- return a(new Error(c.errorMessage));
2245
- i(c);
2246
- }), this.publishWeb3RequestEvent(s, e);
2247
- });
2248
- }
2249
- publishWeb3RequestEvent(e, n) {
2250
- const s = { type: "WEB3_REQUEST", id: e, request: n };
2251
- this.publishEvent("Web3Request", s, !0).then((r) => {
2252
- }).catch((r) => {
2253
- this.handleWeb3ResponseMessage(s.id, {
2254
- method: n.method,
2255
- errorMessage: r.message
2256
- });
2257
- }), this.isMobileWeb && this.openCoinbaseWalletDeeplink(n.method);
2258
- }
2259
- // copied from MobileRelay
2260
- openCoinbaseWalletDeeplink(e) {
2261
- if (this.ui instanceof $e)
2262
- switch (e) {
2263
- case "requestEthereumAccounts":
2264
- // requestEthereumAccounts is handled via popup
2265
- case "switchEthereumChain":
2266
- return;
2267
- default:
2268
- window.addEventListener("blur", () => {
2269
- window.addEventListener("focus", () => {
2270
- this.connection.checkUnseenEvents();
2271
- }, { once: !0 });
2272
- }, { once: !0 }), this.ui.openCoinbaseWalletDeeplink();
2273
- break;
2274
- }
2275
- }
2276
- publishWeb3RequestCanceledEvent(e) {
2277
- const n = {
2278
- type: "WEB3_REQUEST_CANCELED",
2279
- id: e
2280
- };
2281
- this.publishEvent("Web3RequestCanceled", n, !1).then();
2282
- }
2283
- publishEvent(e, n, s) {
2284
- return this.connection.publishEvent(e, n, s);
2285
- }
2286
- handleWeb3ResponseMessage(e, n) {
2287
- if (n.method === "requestEthereumAccounts") {
2288
- F.accountRequestCallbackIds.forEach((s) => this.invokeCallback(s, n)), F.accountRequestCallbackIds.clear();
2289
- return;
2290
- }
2291
- this.invokeCallback(e, n);
2292
- }
2293
- handleErrorResponse(e, n, s) {
2294
- var r;
2295
- const i = (r = s == null ? void 0 : s.message) !== null && r !== void 0 ? r : "Unspecified error message.";
2296
- this.handleWeb3ResponseMessage(e, {
2297
- method: n,
2298
- errorMessage: i
2299
- });
2300
- }
2301
- invokeCallback(e, n) {
2302
- const s = this.relayEventManager.callbacks.get(e);
2303
- s && (s(n), this.relayEventManager.callbacks.delete(e));
2304
- }
2305
- requestEthereumAccounts() {
2306
- const { appName: e, appLogoUrl: n } = this.metadata, s = {
2307
- method: "requestEthereumAccounts",
2308
- params: {
2309
- appName: e,
2310
- appLogoUrl: n
2311
- }
2312
- }, r = J(8);
2313
- return new Promise((i, a) => {
2314
- this.relayEventManager.callbacks.set(r, (c) => {
2315
- if (U(c))
2316
- return a(new Error(c.errorMessage));
2317
- i(c);
2318
- }), F.accountRequestCallbackIds.add(r), this.publishWeb3RequestEvent(r, s);
2319
- });
2320
- }
2321
- watchAsset(e, n, s, r, i, a) {
2322
- const c = {
2323
- method: "watchAsset",
2324
- params: {
2325
- type: e,
2326
- options: {
2327
- address: n,
2328
- symbol: s,
2329
- decimals: r,
2330
- image: i
2331
- },
2332
- chainId: a
2333
- }
2334
- };
2335
- let l = null;
2336
- const f = J(8), m = (E) => {
2337
- this.publishWeb3RequestCanceledEvent(f), this.handleErrorResponse(f, c.method, E), l == null || l();
2338
- };
2339
- return l = this.ui.showConnecting({
2340
- isUnlinkedErrorState: this.isUnlinkedErrorState,
2341
- onCancel: m,
2342
- onResetConnection: this.resetAndReload
2343
- // eslint-disable-line @typescript-eslint/unbound-method
2344
- }), new Promise((E, u) => {
2345
- this.relayEventManager.callbacks.set(f, (d) => {
2346
- if (l == null || l(), U(d))
2347
- return u(new Error(d.errorMessage));
2348
- E(d);
2349
- }), this.publishWeb3RequestEvent(f, c);
2350
- });
2351
- }
2352
- addEthereumChain(e, n, s, r, i, a) {
2353
- const c = {
2354
- method: "addEthereumChain",
2355
- params: {
2356
- chainId: e,
2357
- rpcUrls: n,
2358
- blockExplorerUrls: r,
2359
- chainName: i,
2360
- iconUrls: s,
2361
- nativeCurrency: a
2362
- }
2363
- };
2364
- let l = null;
2365
- const f = J(8), m = (E) => {
2366
- this.publishWeb3RequestCanceledEvent(f), this.handleErrorResponse(f, c.method, E), l == null || l();
2367
- };
2368
- return l = this.ui.showConnecting({
2369
- isUnlinkedErrorState: this.isUnlinkedErrorState,
2370
- onCancel: m,
2371
- onResetConnection: this.resetAndReload
2372
- // eslint-disable-line @typescript-eslint/unbound-method
2373
- }), new Promise((E, u) => {
2374
- this.relayEventManager.callbacks.set(f, (d) => {
2375
- if (l == null || l(), U(d))
2376
- return u(new Error(d.errorMessage));
2377
- E(d);
2378
- }), this.publishWeb3RequestEvent(f, c);
2379
- });
2380
- }
2381
- switchEthereumChain(e, n) {
2382
- const s = {
2383
- method: "switchEthereumChain",
2384
- params: Object.assign({ chainId: e }, { address: n })
2385
- };
2386
- let r = null;
2387
- const i = J(8), a = (c) => {
2388
- this.publishWeb3RequestCanceledEvent(i), this.handleErrorResponse(i, s.method, c), r == null || r();
2389
- };
2390
- return r = this.ui.showConnecting({
2391
- isUnlinkedErrorState: this.isUnlinkedErrorState,
2392
- onCancel: a,
2393
- onResetConnection: this.resetAndReload
2394
- // eslint-disable-line @typescript-eslint/unbound-method
2395
- }), new Promise((c, l) => {
2396
- this.relayEventManager.callbacks.set(i, (f) => {
2397
- if (r == null || r(), U(f) && f.errorCode)
2398
- return l(A.provider.custom({
2399
- code: f.errorCode,
2400
- message: "Unrecognized chain ID. Try adding the chain using addEthereumChain first."
2401
- }));
2402
- if (U(f))
2403
- return l(new Error(f.errorMessage));
2404
- c(f);
2405
- }), this.publishWeb3RequestEvent(i, s);
2406
- });
2407
- }
2408
- }
2409
- F.accountRequestCallbackIds = /* @__PURE__ */ new Set();
2410
- const Ve = "DefaultChainId", Je = "DefaultJsonRpcUrl";
2411
- class yt {
2412
- constructor(e) {
2413
- this._relay = null, this._addresses = [], this.metadata = e.metadata, this._storage = new H("walletlink", Ye), this.callback = e.callback || null;
2414
- const n = this._storage.getItem(ve);
2415
- if (n) {
2416
- const s = n.split(" ");
2417
- s[0] !== "" && (this._addresses = s.map((r) => Y(r)));
2418
- }
2419
- this.initializeRelay();
2420
- }
2421
- getSession() {
2422
- const e = this.initializeRelay(), { id: n, secret: s } = e.getWalletLinkSession();
2423
- return { id: n, secret: s };
2424
- }
2425
- async handshake() {
2426
- await this._eth_requestAccounts();
2427
- }
2428
- get selectedAddress() {
2429
- return this._addresses[0] || void 0;
2430
- }
2431
- get jsonRpcUrl() {
2432
- var e;
2433
- return (e = this._storage.getItem(Je)) !== null && e !== void 0 ? e : void 0;
2434
- }
2435
- set jsonRpcUrl(e) {
2436
- this._storage.setItem(Je, e);
2437
- }
2438
- updateProviderInfo(e, n) {
2439
- var s;
2440
- this.jsonRpcUrl = e;
2441
- const r = this.getChainId();
2442
- this._storage.setItem(Ve, n.toString(10)), se(n) !== r && ((s = this.callback) === null || s === void 0 || s.call(this, "chainChanged", $(n)));
2443
- }
2444
- async watchAsset(e) {
2445
- const n = Array.isArray(e) ? e[0] : e;
2446
- if (!n.type)
2447
- throw A.rpc.invalidParams("Type is required");
2448
- if ((n == null ? void 0 : n.type) !== "ERC20")
2449
- throw A.rpc.invalidParams(`Asset of type '${n.type}' is not supported`);
2450
- if (!(n != null && n.options))
2451
- throw A.rpc.invalidParams("Options are required");
2452
- if (!(n != null && n.options.address))
2453
- throw A.rpc.invalidParams("Address is required");
2454
- const s = this.getChainId(), { address: r, symbol: i, image: a, decimals: c } = n.options, f = await this.initializeRelay().watchAsset(n.type, r, i, c, a, s == null ? void 0 : s.toString());
2455
- return U(f) ? !1 : !!f.result;
2456
- }
2457
- async addEthereumChain(e) {
2458
- var n, s;
2459
- const r = e[0];
2460
- if (((n = r.rpcUrls) === null || n === void 0 ? void 0 : n.length) === 0)
2461
- throw A.rpc.invalidParams("please pass in at least 1 rpcUrl");
2462
- if (!r.chainName || r.chainName.trim() === "")
2463
- throw A.rpc.invalidParams("chainName is a required field");
2464
- if (!r.nativeCurrency)
2465
- throw A.rpc.invalidParams("nativeCurrency is a required field");
2466
- const i = Number.parseInt(r.chainId, 16);
2467
- if (i === this.getChainId())
2468
- return !1;
2469
- const a = this.initializeRelay(), { rpcUrls: c = [], blockExplorerUrls: l = [], chainName: f, iconUrls: m = [], nativeCurrency: E } = r, u = await a.addEthereumChain(i.toString(), c, m, l, f, E);
2470
- if (U(u))
2471
- return !1;
2472
- if (((s = u.result) === null || s === void 0 ? void 0 : s.isApproved) === !0)
2473
- return this.updateProviderInfo(c[0], i), null;
2474
- throw A.rpc.internal("unable to add ethereum chain");
2475
- }
2476
- async switchEthereumChain(e) {
2477
- const n = e[0], s = Number.parseInt(n.chainId, 16), i = await this.initializeRelay().switchEthereumChain(s.toString(10), this.selectedAddress || void 0);
2478
- if (U(i))
2479
- throw i;
2480
- const a = i.result;
2481
- return a.isApproved && a.rpcUrl.length > 0 && this.updateProviderInfo(a.rpcUrl, s), null;
2482
- }
2483
- async cleanup() {
2484
- this.callback = null, this._relay && this._relay.resetAndReload(), this._storage.clear();
2485
- }
2486
- _setAddresses(e, n) {
2487
- var s;
2488
- if (!Array.isArray(e))
2489
- throw new Error("addresses is not an array");
2490
- const r = e.map((i) => Y(i));
2491
- JSON.stringify(r) !== JSON.stringify(this._addresses) && (this._addresses = r, (s = this.callback) === null || s === void 0 || s.call(this, "accountsChanged", r), this._storage.setItem(ve, r.join(" ")));
2492
- }
2493
- async request(e) {
2494
- const n = e.params || [];
2495
- switch (e.method) {
2496
- case "eth_accounts":
2497
- return [...this._addresses];
2498
- case "eth_coinbase":
2499
- return this.selectedAddress || null;
2500
- case "net_version":
2501
- return this.getChainId().toString(10);
2502
- case "eth_chainId":
2503
- return $(this.getChainId());
2504
- case "eth_requestAccounts":
2505
- return this._eth_requestAccounts();
2506
- case "eth_ecRecover":
2507
- case "personal_ecRecover":
2508
- return this.ecRecover(e);
2509
- case "personal_sign":
2510
- return this.personalSign(e);
2511
- case "eth_signTransaction":
2512
- return this._eth_signTransaction(n);
2513
- case "eth_sendRawTransaction":
2514
- return this._eth_sendRawTransaction(n);
2515
- case "eth_sendTransaction":
2516
- return this._eth_sendTransaction(n);
2517
- case "eth_signTypedData_v1":
2518
- case "eth_signTypedData_v3":
2519
- case "eth_signTypedData_v4":
2520
- case "eth_signTypedData":
2521
- return this.signTypedData(e);
2522
- case "wallet_addEthereumChain":
2523
- return this.addEthereumChain(n);
2524
- case "wallet_switchEthereumChain":
2525
- return this.switchEthereumChain(n);
2526
- case "wallet_watchAsset":
2527
- return this.watchAsset(n);
2528
- default:
2529
- if (!this.jsonRpcUrl)
2530
- throw A.rpc.internal("No RPC URL set for chain");
2531
- return ht(e, this.jsonRpcUrl);
2532
- }
2533
- }
2534
- _ensureKnownAddress(e) {
2535
- const n = Y(e);
2536
- if (!this._addresses.map((r) => Y(r)).includes(n))
2537
- throw new Error("Unknown Ethereum address");
2538
- }
2539
- _prepareTransactionParams(e) {
2540
- const n = e.from ? Y(e.from) : this.selectedAddress;
2541
- if (!n)
2542
- throw new Error("Ethereum address is unavailable");
2543
- this._ensureKnownAddress(n);
2544
- const s = e.to ? Y(e.to) : null, r = e.value != null ? X(e.value) : BigInt(0), i = e.data ? ke(e.data) : N.alloc(0), a = e.nonce != null ? se(e.nonce) : null, c = e.gasPrice != null ? X(e.gasPrice) : null, l = e.maxFeePerGas != null ? X(e.maxFeePerGas) : null, f = e.maxPriorityFeePerGas != null ? X(e.maxPriorityFeePerGas) : null, m = e.gas != null ? X(e.gas) : null, E = e.chainId ? se(e.chainId) : this.getChainId();
2545
- return {
2546
- fromAddress: n,
2547
- toAddress: s,
2548
- weiValue: r,
2549
- data: i,
2550
- nonce: a,
2551
- gasPriceInWei: c,
2552
- maxFeePerGas: l,
2553
- maxPriorityFeePerGas: f,
2554
- gasLimit: m,
2555
- chainId: E
2556
- };
2557
- }
2558
- async ecRecover(e) {
2559
- const { method: n, params: s } = e;
2560
- if (!Array.isArray(s))
2561
- throw A.rpc.invalidParams();
2562
- const i = await this.initializeRelay().sendRequest({
2563
- method: "ethereumAddressFromSignedMessage",
2564
- params: {
2565
- message: de(s[0]),
2566
- signature: de(s[1]),
2567
- addPrefix: n === "personal_ecRecover"
2568
- }
2569
- });
2570
- if (U(i))
2571
- throw i;
2572
- return i.result;
2573
- }
2574
- getChainId() {
2575
- var e;
2576
- return Number.parseInt((e = this._storage.getItem(Ve)) !== null && e !== void 0 ? e : "1", 10);
2577
- }
2578
- async _eth_requestAccounts() {
2579
- var e, n;
2580
- if (this._addresses.length > 0)
2581
- return (e = this.callback) === null || e === void 0 || e.call(this, "connect", { chainId: $(this.getChainId()) }), this._addresses;
2582
- const r = await this.initializeRelay().requestEthereumAccounts();
2583
- if (U(r))
2584
- throw r;
2585
- if (!r.result)
2586
- throw new Error("accounts received is empty");
2587
- return this._setAddresses(r.result), (n = this.callback) === null || n === void 0 || n.call(this, "connect", { chainId: $(this.getChainId()) }), this._addresses;
2588
- }
2589
- async personalSign({ params: e }) {
2590
- if (!Array.isArray(e))
2591
- throw A.rpc.invalidParams();
2592
- const n = e[1], s = e[0];
2593
- this._ensureKnownAddress(n);
2594
- const i = await this.initializeRelay().sendRequest({
2595
- method: "signEthereumMessage",
2596
- params: {
2597
- address: Y(n),
2598
- message: de(s),
2599
- addPrefix: !0,
2600
- typedDataJson: null
2601
- }
2602
- });
2603
- if (U(i))
2604
- throw i;
2605
- return i.result;
2606
- }
2607
- async _eth_signTransaction(e) {
2608
- const n = this._prepareTransactionParams(e[0] || {}), r = await this.initializeRelay().signEthereumTransaction(n);
2609
- if (U(r))
2610
- throw r;
2611
- return r.result;
2612
- }
2613
- async _eth_sendRawTransaction(e) {
2614
- const n = ke(e[0]), r = await this.initializeRelay().submitEthereumTransaction(n, this.getChainId());
2615
- if (U(r))
2616
- throw r;
2617
- return r.result;
2618
- }
2619
- async _eth_sendTransaction(e) {
2620
- const n = this._prepareTransactionParams(e[0] || {}), r = await this.initializeRelay().signAndSubmitEthereumTransaction(n);
2621
- if (U(r))
2622
- throw r;
2623
- return r.result;
2624
- }
2625
- async signTypedData(e) {
2626
- const { method: n, params: s } = e;
2627
- if (!Array.isArray(s))
2628
- throw A.rpc.invalidParams();
2629
- const r = (f) => {
2630
- const m = {
2631
- eth_signTypedData_v1: ae.hashForSignTypedDataLegacy,
2632
- eth_signTypedData_v3: ae.hashForSignTypedData_v3,
2633
- eth_signTypedData_v4: ae.hashForSignTypedData_v4,
2634
- eth_signTypedData: ae.hashForSignTypedData_v4
2635
- };
2636
- return ne(m[n]({
2637
- data: Ot(f)
2638
- }), !0);
2639
- }, i = s[n === "eth_signTypedData_v1" ? 1 : 0], a = s[n === "eth_signTypedData_v1" ? 0 : 1];
2640
- this._ensureKnownAddress(i);
2641
- const l = await this.initializeRelay().sendRequest({
2642
- method: "signEthereumMessage",
2643
- params: {
2644
- address: Y(i),
2645
- message: r(a),
2646
- typedDataJson: JSON.stringify(a, null, 2),
2647
- addPrefix: !1
2648
- }
2649
- });
2650
- if (U(l))
2651
- throw l;
2652
- return l.result;
2653
- }
2654
- initializeRelay() {
2655
- return this._relay || (this._relay = new F({
2656
- linkAPIUrl: Ye,
2657
- storage: this._storage,
2658
- metadata: this.metadata,
2659
- accountsCallback: this._setAddresses.bind(this),
2660
- chainCallback: this.updateProviderInfo.bind(this)
2661
- })), this._relay;
2662
- }
2663
- }
2664
- const mt = "SignerType", kt = new H("CBWSDK", "SignerConfigurator");
2665
- function _n() {
2666
- return kt.getItem(mt);
2667
- }
2668
- function Cn(t) {
2669
- kt.setItem(mt, t);
2670
- }
2671
- async function An(t) {
2672
- const { communicator: e, metadata: n, handshakeRequest: s, callback: r } = t;
2673
- Mn(e, n, r).catch(() => {
2674
- });
2675
- const i = {
2676
- id: crypto.randomUUID(),
2677
- event: "selectSignerType",
2678
- data: Object.assign(Object.assign({}, t.preference), { handshakeRequest: s })
2679
- }, { data: a } = await e.postRequestAndWaitForResponse(i);
2680
- return a;
2681
- }
2682
- function Ln(t) {
2683
- const { signerType: e, metadata: n, communicator: s, callback: r } = t;
2684
- switch (e) {
2685
- case "scw":
2686
- return new Yt({
2687
- metadata: n,
2688
- callback: r,
2689
- communicator: s
2690
- });
2691
- case "walletlink":
2692
- return new yt({
2693
- metadata: n,
2694
- callback: r
2695
- });
2696
- }
2697
- }
2698
- async function Mn(t, e, n) {
2699
- await t.onMessage(({ event: r }) => r === "WalletLinkSessionRequest");
2700
- const s = new yt({
2701
- metadata: e,
2702
- callback: n
2703
- });
2704
- t.postMessage({
2705
- event: "WalletLinkUpdate",
2706
- data: { session: s.getSession() }
2707
- }), await s.handshake(), t.postMessage({
2708
- event: "WalletLinkUpdate",
2709
- data: { connected: !0 }
2710
- });
2711
- }
2712
- const xn = `Coinbase Wallet SDK requires the Cross-Origin-Opener-Policy header to not be set to 'same-origin'. This is to ensure that the SDK can communicate with the Coinbase Smart Wallet app.
2713
-
2714
- Please see https://www.smartwallet.dev/guides/tips/popup-tips#cross-origin-opener-policy for more information.`, Rn = () => {
2715
- let t;
2716
- return {
2717
- getCrossOriginOpenerPolicy: () => t === void 0 ? "undefined" : t,
2718
- checkCrossOriginOpenerPolicy: async () => {
2719
- if (typeof window > "u") {
2720
- t = "non-browser-env";
2721
- return;
2722
- }
2723
- try {
2724
- const e = `${window.location.origin}${window.location.pathname}`, n = await fetch(e, {
2725
- method: "HEAD"
2726
- });
2727
- if (!n.ok)
2728
- throw new Error(`HTTP error! status: ${n.status}`);
2729
- const s = n.headers.get("Cross-Origin-Opener-Policy");
2730
- t = s ?? "null", t === "same-origin" && console.error(xn);
2731
- } catch (e) {
2732
- console.error("Error checking Cross-Origin-Opener-Policy:", e.message), t = "error";
2733
- }
2734
- }
2735
- };
2736
- }, { checkCrossOriginOpenerPolicy: Pn, getCrossOriginOpenerPolicy: Tn } = Rn(), Qe = 420, Ze = 540;
2737
- function On(t) {
2738
- const e = (window.innerWidth - Qe) / 2 + window.screenX, n = (window.innerHeight - Ze) / 2 + window.screenY;
2739
- Dn(t);
2740
- const s = window.open(t, "Smart Wallet", `width=${Qe}, height=${Ze}, left=${e}, top=${n}`);
2741
- if (s == null || s.focus(), !s)
2742
- throw A.rpc.internal("Pop up window failed to open");
2743
- return s;
2744
- }
2745
- function Nn(t) {
2746
- t && !t.closed && t.close();
2747
- }
2748
- function Dn(t) {
2749
- const e = {
2750
- sdkName: ut,
2751
- sdkVersion: re,
2752
- origin: window.location.origin,
2753
- coop: Tn()
2754
- };
2755
- for (const [n, s] of Object.entries(e))
2756
- t.searchParams.append(n, s.toString());
2757
- }
2758
- class jn {
2759
- constructor({ url: e = In, metadata: n, preference: s }) {
2760
- this.popup = null, this.listeners = /* @__PURE__ */ new Map(), this.postMessage = async (r) => {
2761
- (await this.waitForPopupLoaded()).postMessage(r, this.url.origin);
2762
- }, this.postRequestAndWaitForResponse = async (r) => {
2763
- const i = this.onMessage(({ requestId: a }) => a === r.id);
2764
- return this.postMessage(r), await i;
2765
- }, this.onMessage = async (r) => new Promise((i, a) => {
2766
- const c = (l) => {
2767
- if (l.origin !== this.url.origin)
2768
- return;
2769
- const f = l.data;
2770
- r(f) && (i(f), window.removeEventListener("message", c), this.listeners.delete(c));
2771
- };
2772
- window.addEventListener("message", c), this.listeners.set(c, { reject: a });
2773
- }), this.disconnect = () => {
2774
- Nn(this.popup), this.popup = null, this.listeners.forEach(({ reject: r }, i) => {
2775
- r(A.provider.userRejectedRequest("Request rejected")), window.removeEventListener("message", i);
2776
- }), this.listeners.clear();
2777
- }, this.waitForPopupLoaded = async () => this.popup && !this.popup.closed ? (this.popup.focus(), this.popup) : (this.popup = On(this.url), this.onMessage(({ event: r }) => r === "PopupUnload").then(this.disconnect).catch(() => {
2778
- }), this.onMessage(({ event: r }) => r === "PopupLoaded").then((r) => {
2779
- this.postMessage({
2780
- requestId: r.id,
2781
- data: {
2782
- version: re,
2783
- metadata: this.metadata,
2784
- preference: this.preference,
2785
- location: window.location.toString()
2786
- }
2787
- });
2788
- }).then(() => {
2789
- if (!this.popup)
2790
- throw A.rpc.internal();
2791
- return this.popup;
2792
- })), this.url = new URL(e), this.metadata = n, this.preference = s;
2793
- }
2794
- }
2795
- function Un(t) {
2796
- const e = Mt(Bn(t), {
2797
- shouldIncludeStack: !0
2798
- }), n = new URL("https://docs.cloud.coinbase.com/wallet-sdk/docs/errors");
2799
- return n.searchParams.set("version", re), n.searchParams.set("code", e.code.toString()), n.searchParams.set("message", e.message), Object.assign(Object.assign({}, e), { docUrl: n.href });
2800
- }
2801
- function Bn(t) {
2802
- var e;
2803
- if (typeof t == "string")
2804
- return {
2805
- message: t,
2806
- code: j.rpc.internal
2807
- };
2808
- if (U(t)) {
2809
- const n = t.errorMessage, s = (e = t.errorCode) !== null && e !== void 0 ? e : n.match(/(denied|rejected)/i) ? j.provider.userRejectedRequest : void 0;
2810
- return Object.assign(Object.assign({}, t), {
2811
- message: n,
2812
- code: s,
2813
- data: { method: t.method }
2814
- });
2815
- }
2816
- return t;
2817
- }
2818
- class Wn extends _t {
2819
- }
2820
- var qn = function(t, e) {
2821
- var n = {};
2822
- for (var s in t) Object.prototype.hasOwnProperty.call(t, s) && e.indexOf(s) < 0 && (n[s] = t[s]);
2823
- if (t != null && typeof Object.getOwnPropertySymbols == "function")
2824
- for (var r = 0, s = Object.getOwnPropertySymbols(t); r < s.length; r++)
2825
- e.indexOf(s[r]) < 0 && Object.prototype.propertyIsEnumerable.call(t, s[r]) && (n[s[r]] = t[s[r]]);
2826
- return n;
2827
- };
2828
- class Kn extends Wn {
2829
- constructor(e) {
2830
- var { metadata: n } = e, s = e.preference, { keysUrl: r } = s, i = qn(s, ["keysUrl"]);
2831
- super(), this.signer = null, this.isCoinbaseWallet = !0, this.metadata = n, this.preference = i, this.communicator = new jn({
2832
- url: r,
2833
- metadata: n,
2834
- preference: i
2835
- });
2836
- const a = _n();
2837
- a && (this.signer = this.initSigner(a));
2838
- }
2839
- async request(e) {
2840
- try {
2841
- if (Gt(e), !this.signer)
2842
- switch (e.method) {
2843
- case "eth_requestAccounts": {
2844
- const n = await this.requestSignerSelection(e), s = this.initSigner(n);
2845
- await s.handshake(e), this.signer = s, Cn(n);
2846
- break;
2847
- }
2848
- case "net_version":
2849
- return 1;
2850
- // default value
2851
- case "eth_chainId":
2852
- return $(1);
2853
- // default value
2854
- default:
2855
- throw A.provider.unauthorized("Must call 'eth_requestAccounts' before other methods");
2856
- }
2857
- return this.signer.request(e);
2858
- } catch (n) {
2859
- const { code: s } = n;
2860
- return s === j.provider.unauthorized && this.disconnect(), Promise.reject(Un(n));
2861
- }
2862
- }
2863
- /** @deprecated Use `.request({ method: 'eth_requestAccounts' })` instead. */
2864
- async enable() {
2865
- return console.warn('.enable() has been deprecated. Please use .request({ method: "eth_requestAccounts" }) instead.'), await this.request({
2866
- method: "eth_requestAccounts"
2867
- });
2868
- }
2869
- async disconnect() {
2870
- var e;
2871
- await ((e = this.signer) === null || e === void 0 ? void 0 : e.cleanup()), this.signer = null, H.clearAll(), this.emit("disconnect", A.provider.disconnected("User initiated disconnection"));
2872
- }
2873
- requestSignerSelection(e) {
2874
- return An({
2875
- communicator: this.communicator,
2876
- preference: this.preference,
2877
- metadata: this.metadata,
2878
- handshakeRequest: e,
2879
- callback: this.emit.bind(this)
2880
- });
2881
- }
2882
- initSigner(e) {
2883
- return Ln({
2884
- signerType: e,
2885
- metadata: this.metadata,
2886
- communicator: this.communicator,
2887
- callback: this.emit.bind(this)
2888
- });
2889
- }
2890
- }
2891
- function Hn(t) {
2892
- if (t) {
2893
- if (!["all", "smartWalletOnly", "eoaOnly"].includes(t.options))
2894
- throw new Error(`Invalid options: ${t.options}`);
2895
- if (t.attribution && t.attribution.auto !== void 0 && t.attribution.dataSuffix !== void 0)
2896
- throw new Error("Attribution cannot contain both auto and dataSuffix properties");
2897
- }
2898
- }
2899
- function zn(t) {
2900
- var e;
2901
- const n = {
2902
- metadata: t.metadata,
2903
- preference: t.preference
2904
- };
2905
- return (e = Ft(n)) !== null && e !== void 0 ? e : new Kn(n);
2906
- }
2907
- const Fn = {
2908
- options: "all"
2909
- };
2910
- function $n(t) {
2911
- var e;
2912
- new H("CBWSDK").setItem("VERSION", re), Pn();
2913
- const s = {
2914
- metadata: {
2915
- appName: t.appName || "Dapp",
2916
- appLogoUrl: t.appLogoUrl || "",
2917
- appChainIds: t.appChainIds || []
2918
- },
2919
- preference: Object.assign(Fn, (e = t.preference) !== null && e !== void 0 ? e : {})
2920
- };
2921
- Hn(s.preference);
2922
- let r = null;
2923
- return {
2924
- getProvider: () => (r || (r = zn(s)), r)
2925
- };
2926
- }
2927
- export {
2928
- $n as createCoinbaseWalletSDK
2929
- };