@cartridge/controller 0.9.1 → 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { WalletAccount as me, constants as $, shortString as W, num as ye } from "starknet";
2
- import { R, t as be, K as we, B as _e, v as ke, N as p, p as Ae, A as Ie } from "./provider-iltRv2Q1.js";
3
- import { F as tr, h as rr, n as nr, a as sr, b as or } from "./provider-iltRv2Q1.js";
4
- import { connect as ve } from "starknetkit";
5
- import { InjectedConnector as Ee } from "starknetkit/injected";
6
- import { MetaMaskSDK as xe } from "@metamask/sdk";
7
- import { Transaction as Ce } from "@solana/web3.js";
8
- class H extends me {
1
+ import { WalletAccount as we, constants as z, shortString as H, num as _e } from "starknet";
2
+ import { R as S, t as ke, K as Ae, B as Ie, v as ve, N as p, p as Ee, A as xe } from "./provider-D7ialTEP.js";
3
+ import { F as ar, h as ir, n as cr, a as lr, b as dr } from "./provider-D7ialTEP.js";
4
+ import { connect as Ce } from "starknetkit";
5
+ import { InjectedConnector as Se } from "starknetkit/injected";
6
+ import { MetaMaskSDK as Re } from "@metamask/sdk";
7
+ import { Transaction as Pe } from "@solana/web3.js";
8
+ class K extends we {
9
9
  keychain;
10
10
  modal;
11
11
  options;
@@ -25,7 +25,7 @@ class H extends me {
25
25
  * @returns response from addTransaction
26
26
  */
27
27
  async execute(e) {
28
- return e = be(e), new Promise(async (t, n) => {
28
+ return e = ke(e), new Promise(async (t, n) => {
29
29
  const s = await this.keychain.execute(
30
30
  e,
31
31
  void 0,
@@ -33,11 +33,11 @@ class H extends me {
33
33
  !1,
34
34
  this.options?.feeSource
35
35
  );
36
- if (s.code === R.SUCCESS) {
36
+ if (s.code === S.SUCCESS) {
37
37
  t(s);
38
38
  return;
39
39
  }
40
- if (this.options?.propagateSessionErrors && s.code !== R.USER_INTERACTION_REQUIRED) {
40
+ if (this.options?.propagateSessionErrors && s.code !== S.USER_INTERACTION_REQUIRED) {
41
41
  n(s.error);
42
42
  return;
43
43
  }
@@ -49,7 +49,7 @@ class H extends me {
49
49
  !0,
50
50
  s.error
51
51
  );
52
- if (o.code === R.SUCCESS) {
52
+ if (o.code === S.SUCCESS) {
53
53
  t(o), this.modal.close();
54
54
  return;
55
55
  }
@@ -89,15 +89,15 @@ var N;
89
89
  (function(r) {
90
90
  r.ConnectionDestroyed = "ConnectionDestroyed", r.ConnectionTimeout = "ConnectionTimeout", r.NoIframeSrc = "NoIframeSrc";
91
91
  })(N || (N = {}));
92
- var z;
92
+ var O;
93
93
  (function(r) {
94
94
  r.DataCloneError = "DataCloneError";
95
- })(z || (z = {}));
95
+ })(O || (O = {}));
96
96
  var A;
97
97
  (function(r) {
98
98
  r.Message = "message";
99
99
  })(A || (A = {}));
100
- const Re = (r, e) => {
100
+ const De = (r, e) => {
101
101
  const t = [];
102
102
  let n = !1;
103
103
  return {
@@ -110,27 +110,27 @@ const Re = (r, e) => {
110
110
  n ? s() : t.push(s);
111
111
  }
112
112
  };
113
- }, Se = (r) => (...e) => {
113
+ }, Ne = (r) => (...e) => {
114
114
  r && console.log("[Penpal]", ...e);
115
- }, Pe = {
115
+ }, Me = {
116
116
  "http:": "80",
117
117
  "https:": "443"
118
- }, De = /^(https?:)?\/\/([^/:]+)?(:(\d+))?/, Ne = ["file:", "data:"], Me = (r) => {
119
- if (r && Ne.find((i) => r.startsWith(i)))
118
+ }, Be = /^(https?:)?\/\/([^/:]+)?(:(\d+))?/, Te = ["file:", "data:"], Qe = (r) => {
119
+ if (r && Te.find((i) => r.startsWith(i)))
120
120
  return "null";
121
- const e = document.location, t = De.exec(r);
121
+ const e = document.location, t = Be.exec(r);
122
122
  let n, s, o;
123
123
  t ? (n = t[1] ? t[1] : e.protocol, s = t[2], o = t[4]) : (n = e.protocol, s = e.hostname, o = e.port);
124
- const a = o && o !== Pe[n] ? `:${o}` : "";
124
+ const a = o && o !== Me[n] ? `:${o}` : "";
125
125
  return `${n}//${s}${a}`;
126
- }, K = ({ name: r, message: e, stack: t }) => ({
126
+ }, j = ({ name: r, message: e, stack: t }) => ({
127
127
  name: r,
128
128
  message: e,
129
129
  stack: t
130
- }), Be = (r) => {
130
+ }), Ue = (r) => {
131
131
  const e = new Error();
132
132
  return Object.keys(r).forEach((t) => e[t] = r[t]), e;
133
- }, Qe = (r, e, t) => {
133
+ }, $e = (r, e, t) => {
134
134
  const { localName: n, local: s, remote: o, originForSending: a, originForReceiving: i } = r;
135
135
  let c = !1;
136
136
  const l = (d) => {
@@ -140,11 +140,11 @@ const Re = (r, e) => {
140
140
  t(`${n} received message from origin ${d.origin} which did not match expected origin ${i}`);
141
141
  return;
142
142
  }
143
- const h = d.data, { methodName: m, args: u, id: _ } = h;
144
- t(`${n}: Received ${m}() call`);
143
+ const h = d.data, { methodName: g, args: u, id: _ } = h;
144
+ t(`${n}: Received ${g}() call`);
145
145
  const k = (y) => (I) => {
146
- if (t(`${n}: Sending ${m}() reply`), c) {
147
- t(`${n}: Unable to send ${m}() reply due to destroyed connection`);
146
+ if (t(`${n}: Sending ${g}() reply`), c) {
147
+ t(`${n}: Unable to send ${g}() reply due to destroyed connection`);
148
148
  return;
149
149
  }
150
150
  const w = {
@@ -153,16 +153,16 @@ const Re = (r, e) => {
153
153
  resolution: y,
154
154
  returnValue: I
155
155
  };
156
- y === v.Rejected && I instanceof Error && (w.returnValue = K(I), w.returnValueIsError = !0);
156
+ y === v.Rejected && I instanceof Error && (w.returnValue = j(I), w.returnValueIsError = !0);
157
157
  try {
158
158
  o.postMessage(w, a);
159
159
  } catch (f) {
160
- if (f.name === z.DataCloneError) {
160
+ if (f.name === O.DataCloneError) {
161
161
  const E = {
162
162
  penpal: b.Reply,
163
163
  id: _,
164
164
  resolution: v.Rejected,
165
- returnValue: K(f),
165
+ returnValue: j(f),
166
166
  returnValueIsError: !0
167
167
  };
168
168
  o.postMessage(E, a);
@@ -170,31 +170,31 @@ const Re = (r, e) => {
170
170
  throw f;
171
171
  }
172
172
  };
173
- new Promise((y) => y(e[m].call(e, d.origin).apply(e, u))).then(k(v.Fulfilled), k(v.Rejected));
173
+ new Promise((y) => y(e[g].call(e, d.origin).apply(e, u))).then(k(v.Fulfilled), k(v.Rejected));
174
174
  };
175
175
  return s.addEventListener(A.Message, l), () => {
176
176
  c = !0, s.removeEventListener(A.Message, l);
177
177
  };
178
178
  };
179
- let Ue = 0;
180
- const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r.join(re), ze = (r, e) => {
181
- const t = ne(e || "");
182
- return t.push(r), $e(t);
183
- }, Oe = (r, e, t) => {
184
- const n = ne(e);
179
+ let ze = 0;
180
+ const Oe = () => ++ze, se = ".", oe = (r) => r ? r.split(se) : [], Le = (r) => r.join(se), Ye = (r, e) => {
181
+ const t = oe(e || "");
182
+ return t.push(r), Le(t);
183
+ }, Fe = (r, e, t) => {
184
+ const n = oe(e);
185
185
  return n.reduce((s, o, a) => (typeof s[o] > "u" && (s[o] = {}), a === n.length - 1 && (s[o] = t), s[o]), r), r;
186
- }, se = (r, e) => {
186
+ }, ae = (r, e) => {
187
187
  const t = {};
188
188
  return Object.keys(r).forEach((n) => {
189
- const s = r[n], o = ze(n, e);
190
- typeof s == "object" && Object.assign(t, se(s, o)), typeof s == "function" && (t[o] = s);
189
+ const s = r[n], o = Ye(n, e);
190
+ typeof s == "object" && Object.assign(t, ae(s, o)), typeof s == "function" && (t[o] = s);
191
191
  }), t;
192
- }, Le = (r) => {
192
+ }, We = (r) => {
193
193
  const e = {};
194
194
  for (const t in r)
195
- Oe(e, t, r[t]);
195
+ Fe(e, t, r[t]);
196
196
  return e;
197
- }, Ye = (r, e, t, n, s) => {
197
+ }, He = (r, e, t, n, s) => {
198
198
  const { localName: o, local: a, remote: i, originForSending: c, originForReceiving: l } = e;
199
199
  let d = !1;
200
200
  s(`${o}: Connecting call sender`);
@@ -211,7 +211,7 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
211
211
  throw y.code = N.ConnectionDestroyed, y;
212
212
  }
213
213
  return new Promise((y, I) => {
214
- const w = Te(), f = (x) => {
214
+ const w = Oe(), f = (x) => {
215
215
  if (x.source !== i || x.data.penpal !== b.Reply || x.data.id !== w)
216
216
  return;
217
217
  if (l !== "*" && x.origin !== l) {
@@ -220,8 +220,8 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
220
220
  }
221
221
  const U = x.data;
222
222
  s(`${o}: Received ${u}() reply`), a.removeEventListener(A.Message, f);
223
- let T = U.returnValue;
224
- U.returnValueIsError && (T = Be(T)), (U.resolution === v.Fulfilled ? y : I)(T);
223
+ let $ = U.returnValue;
224
+ U.returnValueIsError && ($ = Ue($)), (U.resolution === v.Fulfilled ? y : I)($);
225
225
  };
226
226
  a.addEventListener(A.Message, f);
227
227
  const E = {
@@ -232,11 +232,11 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
232
232
  };
233
233
  i.postMessage(E, c);
234
234
  });
235
- }, m = t.reduce((u, _) => (u[_] = h(_), u), {});
236
- return Object.assign(r, Le(m)), () => {
235
+ }, g = t.reduce((u, _) => (u[_] = h(_), u), {});
236
+ return Object.assign(r, We(g)), () => {
237
237
  d = !0;
238
238
  };
239
- }, Fe = (r, e, t, n, s) => {
239
+ }, Ke = (r, e, t, n, s) => {
240
240
  const { destroy: o, onDestroy: a } = n;
241
241
  let i, c;
242
242
  const l = {};
@@ -253,13 +253,13 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
253
253
  originForSending: t,
254
254
  originForReceiving: e
255
255
  };
256
- i && i(), i = Qe(h, r, s), a(i), c && c.forEach((u) => {
256
+ i && i(), i = $e(h, r, s), a(i), c && c.forEach((u) => {
257
257
  delete l[u];
258
258
  }), c = d.data.methodNames;
259
- const m = Ye(l, h, c, o, s);
260
- return a(m), l;
259
+ const g = He(l, h, c, o, s);
260
+ return a(g), l;
261
261
  };
262
- }, We = (r, e, t, n) => (s) => {
262
+ }, je = (r, e, t, n) => (s) => {
263
263
  if (!s.source)
264
264
  return;
265
265
  if (t !== "*" && s.origin !== t) {
@@ -272,14 +272,14 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
272
272
  methodNames: Object.keys(e)
273
273
  };
274
274
  s.source.postMessage(o, n);
275
- }, He = 6e4, Ke = (r, e) => {
275
+ }, qe = 6e4, Xe = (r, e) => {
276
276
  const { destroy: t, onDestroy: n } = e, s = setInterval(() => {
277
277
  r.isConnected || (clearInterval(s), t());
278
- }, He);
278
+ }, qe);
279
279
  n(() => {
280
280
  clearInterval(s);
281
281
  });
282
- }, je = (r, e) => {
282
+ }, Ve = (r, e) => {
283
283
  let t;
284
284
  return r !== void 0 && (t = window.setTimeout(() => {
285
285
  const n = new Error(`Connection timed out after ${r}ms`);
@@ -287,22 +287,22 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
287
287
  }, r)), () => {
288
288
  clearTimeout(t);
289
289
  };
290
- }, qe = (r) => {
290
+ }, Ge = (r) => {
291
291
  if (!r.src && !r.srcdoc) {
292
292
  const e = new Error("Iframe must have src or srcdoc property defined.");
293
293
  throw e.code = N.NoIframeSrc, e;
294
294
  }
295
- }, Xe = (r) => {
295
+ }, Je = (r) => {
296
296
  let { iframe: e, methods: t = {}, childOrigin: n, timeout: s, debug: o = !1 } = r;
297
- const a = Se(o), i = Re("Parent", a), { onDestroy: c, destroy: l } = i;
298
- n || (qe(e), n = Me(e.src));
299
- const d = n === "null" ? "*" : n, h = se(t), m = We(a, h, n, d), u = Fe(h, n, d, i, a);
297
+ const a = Ne(o), i = De("Parent", a), { onDestroy: c, destroy: l } = i;
298
+ n || (Ge(e), n = Qe(e.src));
299
+ const d = n === "null" ? "*" : n, h = ae(t), g = je(a, h, n, d), u = Ke(h, n, d, i, a);
300
300
  return {
301
301
  promise: new Promise((k, y) => {
302
- const I = je(s, l), w = (f) => {
302
+ const I = Ve(s, l), w = (f) => {
303
303
  if (!(f.source !== e.contentWindow || !f.data)) {
304
304
  if (f.data.penpal === b.Syn) {
305
- m(f);
305
+ g(f);
306
306
  return;
307
307
  }
308
308
  if (f.data.penpal === b.Ack) {
@@ -312,7 +312,7 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
312
312
  }
313
313
  }
314
314
  };
315
- window.addEventListener(A.Message, w), a("Parent: Awaiting handshake"), Ke(e, i), c((f) => {
315
+ window.addEventListener(A.Message, w), a("Parent: Awaiting handshake"), Xe(e, i), c((f) => {
316
316
  window.removeEventListener(A.Message, w), f && y(f);
317
317
  });
318
318
  }),
@@ -321,12 +321,13 @@ const Te = () => ++Ue, re = ".", ne = (r) => r ? r.split(re) : [], $e = (r) => r
321
321
  }
322
322
  };
323
323
  };
324
- class Ge {
324
+ class Ze {
325
325
  url;
326
326
  iframe;
327
327
  container;
328
328
  onClose;
329
329
  child;
330
+ closeTimeout;
330
331
  constructor({
331
332
  id: e,
332
333
  url: t,
@@ -341,9 +342,9 @@ class Ge {
341
342
  const i = document.createElement("iframe");
342
343
  i.src = t.toString(), i.id = e, i.style.border = "none", i.sandbox.add("allow-forms"), i.sandbox.add("allow-popups"), i.sandbox.add("allow-popups-to-escape-sandbox"), i.sandbox.add("allow-scripts"), i.sandbox.add("allow-same-origin"), i.allow = "publickey-credentials-create *; publickey-credentials-get *; clipboard-write", document.hasStorageAccess && i.sandbox.add("allow-storage-access-by-user-activation");
343
344
  const c = document.createElement("div");
344
- c.id = "controller", c.style.position = "fixed", c.style.height = "100%", c.style.width = "100%", c.style.top = "0", c.style.left = "0", c.style.zIndex = "10000", c.style.backgroundColor = "rgba(0,0,0,0.6)", c.style.display = "flex", c.style.alignItems = "center", c.style.justifyContent = "center", c.style.visibility = "hidden", c.style.opacity = "0", c.style.transition = "opacity 0.2s ease", c.style.pointerEvents = "auto", c.appendChild(i), c.addEventListener("click", (h) => {
345
- h.target === c && (e === "controller-keychain" && this.child && this.child.reset?.().catch((m) => console.error("Error resetting context:", m)), this.close());
346
- }), this.iframe = i, this.container = c, Xe({
345
+ c.id = "controller", c.style.position = "fixed", c.style.height = "100%", c.style.width = "100%", c.style.top = "0", c.style.left = "0", c.style.zIndex = "10000", c.style.backgroundColor = "rgba(0,0,0,0.6)", c.style.display = "none", c.style.alignItems = "center", c.style.justifyContent = "center", c.style.transition = "opacity 0.2s ease", c.style.opacity = "0", c.style.pointerEvents = "auto", c.appendChild(i), c.addEventListener("click", (h) => {
346
+ h.target === c && (e === "controller-keychain" && this.child && this.child.reset?.().catch((g) => console.error("Error resetting context:", g)), this.close());
347
+ }), this.iframe = i, this.container = c, Je({
347
348
  iframe: this.iframe,
348
349
  methods: {
349
350
  close: (h) => () => this.close(),
@@ -366,10 +367,14 @@ class Ge {
366
367
  document.body && e === "controller-keychain" && !d && document.body.appendChild(c), this.onClose = s;
367
368
  }
368
369
  open() {
369
- !this.container || typeof document > "u" || !document.body || (document.body.style.overflow = "hidden", this.container.style.visibility = "visible", this.container.style.opacity = "1");
370
+ !this.container || typeof document > "u" || !document.body || (this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = void 0), document.body.style.overflow = "hidden", this.container.style.display = "flex", requestAnimationFrame(() => {
371
+ this.container && (this.container.style.opacity = "1");
372
+ }));
370
373
  }
371
374
  close() {
372
- !this.container || typeof document > "u" || !document.body || (this.onClose?.(), document.body.style.overflow = "auto", this.container.style.visibility = "hidden", this.container.style.opacity = "0");
375
+ !this.container || typeof document > "u" || !document.body || (this.onClose?.(), document.body.style.overflow = "auto", this.container.style.opacity = "0", this.closeTimeout = setTimeout(() => {
376
+ this.container && (this.container.style.display = "none"), this.closeTimeout = void 0;
377
+ }, 200));
373
378
  }
374
379
  sendBackward() {
375
380
  this.container && (this.container.style.zIndex = "9999");
@@ -387,11 +392,11 @@ class Ge {
387
392
  }
388
393
  }
389
394
  isOpen() {
390
- return this.iframe?.style.display !== "none";
395
+ return this.container?.style.display !== "none";
391
396
  }
392
397
  }
393
- const Ve = "6.13.7";
394
- function j(r, e, t) {
398
+ const et = "6.13.7";
399
+ function q(r, e, t) {
395
400
  for (let n in e) {
396
401
  let s = e[n];
397
402
  Object.defineProperty(r, n, { enumerable: !0, value: s, writable: !1 });
@@ -428,7 +433,7 @@ function C(r) {
428
433
  }
429
434
  return "[ COULD NOT SERIALIZE ]";
430
435
  }
431
- function Je(r, e, t) {
436
+ function tt(r, e, t) {
432
437
  let n = r;
433
438
  {
434
439
  const o = [];
@@ -442,7 +447,7 @@ function Je(r, e, t) {
442
447
  o.push(a + "=" + C(i));
443
448
  }
444
449
  }
445
- o.push(`code=${e}`), o.push(`version=${Ve}`), o.length && (r += " (" + o.join(", ") + ")");
450
+ o.push(`code=${e}`), o.push(`version=${et}`), o.length && (r += " (" + o.join(", ") + ")");
446
451
  }
447
452
  let s;
448
453
  switch (e) {
@@ -456,14 +461,14 @@ function Je(r, e, t) {
456
461
  default:
457
462
  s = new Error(r);
458
463
  }
459
- return j(s, { code: e }), t && Object.assign(s, t), s.shortMessage == null && j(s, { shortMessage: n }), s;
464
+ return q(s, { code: e }), t && Object.assign(s, t), s.shortMessage == null && q(s, { shortMessage: n }), s;
460
465
  }
461
- function Ze(r, e, t, n) {
466
+ function rt(r, e, t, n) {
462
467
  if (!r)
463
- throw Je(e, t, n);
468
+ throw tt(e, t, n);
464
469
  }
465
470
  function D(r, e, t, n) {
466
- Ze(r, e, "INVALID_ARGUMENT", { argument: t, value: n });
471
+ rt(r, e, "INVALID_ARGUMENT", { argument: t, value: n });
467
472
  }
468
473
  ["NFD", "NFC", "NFKD", "NFKC"].reduce((r, e) => {
469
474
  try {
@@ -476,7 +481,7 @@ function D(r, e, t, n) {
476
481
  }
477
482
  return r;
478
483
  }, []);
479
- function et(r, e, t) {
484
+ function nt(r, e, t) {
480
485
  if (r instanceof Uint8Array)
481
486
  return r;
482
487
  if (typeof r == "string" && r.match(/^0x(?:[0-9a-f][0-9a-f])*$/i)) {
@@ -488,28 +493,32 @@ function et(r, e, t) {
488
493
  }
489
494
  D(!1, "invalid BytesLike value", e || "value", r);
490
495
  }
491
- function O(r, e) {
492
- return et(r, e);
496
+ function L(r, e) {
497
+ return nt(r, e);
493
498
  }
494
- const q = "0123456789abcdef";
495
- function tt(r) {
496
- const e = O(r);
499
+ const X = "0123456789abcdef";
500
+ function st(r) {
501
+ const e = L(r);
497
502
  let t = "0x";
498
503
  for (let n = 0; n < e.length; n++) {
499
504
  const s = e[n];
500
- t += q[(s & 240) >> 4] + q[s & 15];
505
+ t += X[(s & 240) >> 4] + X[s & 15];
501
506
  }
502
507
  return t;
503
508
  }
504
- function X(r) {
509
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
510
+ function ot(r) {
511
+ return r instanceof Uint8Array || ArrayBuffer.isView(r) && r.constructor.name === "Uint8Array";
512
+ }
513
+ function V(r) {
505
514
  if (!Number.isSafeInteger(r) || r < 0)
506
- throw new Error(`Wrong positive integer: ${r}`);
515
+ throw new Error("positive integer expected, got " + r);
507
516
  }
508
- function oe(r, ...e) {
509
- if (!(r instanceof Uint8Array))
510
- throw new Error("Expected Uint8Array");
517
+ function T(r, ...e) {
518
+ if (!ot(r))
519
+ throw new Error("Uint8Array expected");
511
520
  if (e.length > 0 && !e.includes(r.length))
512
- throw new Error(`Expected Uint8Array of length ${e}, not of length=${r.length}`);
521
+ throw new Error("Uint8Array expected of length " + e + ", got length=" + r.length);
513
522
  }
514
523
  function G(r, e = !0) {
515
524
  if (r.destroyed)
@@ -517,70 +526,78 @@ function G(r, e = !0) {
517
526
  if (e && r.finished)
518
527
  throw new Error("Hash#digest() has already been called");
519
528
  }
520
- function rt(r, e) {
521
- oe(r);
529
+ function at(r, e) {
530
+ T(r);
522
531
  const t = e.outputLen;
523
532
  if (r.length < t)
524
- throw new Error(`digestInto() expects output buffer of length at least ${t}`);
533
+ throw new Error("digestInto() expects output buffer of length at least " + t);
525
534
  }
526
- /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
527
- const nt = (r) => r instanceof Uint8Array, st = (r) => new Uint32Array(r.buffer, r.byteOffset, Math.floor(r.byteLength / 4)), ot = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
528
- if (!ot)
529
- throw new Error("Non little-endian hardware is not supported");
530
- function at(r) {
535
+ function it(r) {
536
+ return new Uint32Array(r.buffer, r.byteOffset, Math.floor(r.byteLength / 4));
537
+ }
538
+ function ie(...r) {
539
+ for (let e = 0; e < r.length; e++)
540
+ r[e].fill(0);
541
+ }
542
+ const ct = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
543
+ function lt(r) {
544
+ return r << 24 & 4278190080 | r << 8 & 16711680 | r >>> 8 & 65280 | r >>> 24 & 255;
545
+ }
546
+ function dt(r) {
547
+ for (let e = 0; e < r.length; e++)
548
+ r[e] = lt(r[e]);
549
+ return r;
550
+ }
551
+ const J = ct ? (r) => r : dt;
552
+ function ht(r) {
531
553
  if (typeof r != "string")
532
- throw new Error(`utf8ToBytes expected string, got ${typeof r}`);
554
+ throw new Error("string expected");
533
555
  return new Uint8Array(new TextEncoder().encode(r));
534
556
  }
535
- function ae(r) {
536
- if (typeof r == "string" && (r = at(r)), !nt(r))
537
- throw new Error(`expected Uint8Array, got ${typeof r}`);
538
- return r;
557
+ function ce(r) {
558
+ return typeof r == "string" && (r = ht(r)), T(r), r;
539
559
  }
540
- class it {
541
- // Safe version that clones internal state
542
- clone() {
543
- return this._cloneInto();
544
- }
560
+ class ut {
545
561
  }
546
- function ct(r) {
547
- const e = (n) => r().update(ae(n)).digest(), t = r();
562
+ function ft(r) {
563
+ const e = (n) => r().update(ce(n)).digest(), t = r();
548
564
  return e.outputLen = t.outputLen, e.blockLen = t.blockLen, e.create = () => r(), e;
549
565
  }
550
- const B = /* @__PURE__ */ BigInt(2 ** 32 - 1), V = /* @__PURE__ */ BigInt(32);
551
- function lt(r, e = !1) {
552
- return e ? { h: Number(r & B), l: Number(r >> V & B) } : { h: Number(r >> V & B) | 0, l: Number(r & B) | 0 };
566
+ const B = /* @__PURE__ */ BigInt(2 ** 32 - 1), Z = /* @__PURE__ */ BigInt(32);
567
+ function pt(r, e = !1) {
568
+ return e ? { h: Number(r & B), l: Number(r >> Z & B) } : { h: Number(r >> Z & B) | 0, l: Number(r & B) | 0 };
553
569
  }
554
- function dt(r, e = !1) {
555
- let t = new Uint32Array(r.length), n = new Uint32Array(r.length);
556
- for (let s = 0; s < r.length; s++) {
557
- const { h: o, l: a } = lt(r[s], e);
558
- [t[s], n[s]] = [o, a];
559
- }
560
- return [t, n];
570
+ function mt(r, e = !1) {
571
+ const t = r.length;
572
+ let n = new Uint32Array(t), s = new Uint32Array(t);
573
+ for (let o = 0; o < t; o++) {
574
+ const { h: a, l: i } = pt(r[o], e);
575
+ [n[o], s[o]] = [a, i];
576
+ }
577
+ return [n, s];
561
578
  }
562
- const ht = (r, e, t) => r << t | e >>> 32 - t, ut = (r, e, t) => e << t | r >>> 32 - t, ft = (r, e, t) => e << t - 32 | r >>> 64 - t, pt = (r, e, t) => r << t - 32 | e >>> 64 - t, [ie, ce, le] = [[], [], []], gt = /* @__PURE__ */ BigInt(0), P = /* @__PURE__ */ BigInt(1), mt = /* @__PURE__ */ BigInt(2), yt = /* @__PURE__ */ BigInt(7), bt = /* @__PURE__ */ BigInt(256), wt = /* @__PURE__ */ BigInt(113);
579
+ const gt = (r, e, t) => r << t | e >>> 32 - t, yt = (r, e, t) => e << t | r >>> 32 - t, bt = (r, e, t) => e << t - 32 | r >>> 64 - t, wt = (r, e, t) => r << t - 32 | e >>> 64 - t, _t = BigInt(0), P = BigInt(1), kt = BigInt(2), At = BigInt(7), It = BigInt(256), vt = BigInt(113), le = [], de = [], he = [];
563
580
  for (let r = 0, e = P, t = 1, n = 0; r < 24; r++) {
564
- [t, n] = [n, (2 * t + 3 * n) % 5], ie.push(2 * (5 * n + t)), ce.push((r + 1) * (r + 2) / 2 % 64);
565
- let s = gt;
581
+ [t, n] = [n, (2 * t + 3 * n) % 5], le.push(2 * (5 * n + t)), de.push((r + 1) * (r + 2) / 2 % 64);
582
+ let s = _t;
566
583
  for (let o = 0; o < 7; o++)
567
- e = (e << P ^ (e >> yt) * wt) % bt, e & mt && (s ^= P << (P << /* @__PURE__ */ BigInt(o)) - P);
568
- le.push(s);
584
+ e = (e << P ^ (e >> At) * vt) % It, e & kt && (s ^= P << (P << /* @__PURE__ */ BigInt(o)) - P);
585
+ he.push(s);
569
586
  }
570
- const [_t, kt] = /* @__PURE__ */ dt(le, !0), J = (r, e, t) => t > 32 ? ft(r, e, t) : ht(r, e, t), Z = (r, e, t) => t > 32 ? pt(r, e, t) : ut(r, e, t);
571
- function At(r, e = 24) {
587
+ const ue = mt(he, !0), Et = ue[0], xt = ue[1], ee = (r, e, t) => t > 32 ? bt(r, e, t) : gt(r, e, t), te = (r, e, t) => t > 32 ? wt(r, e, t) : yt(r, e, t);
588
+ function Ct(r, e = 24) {
572
589
  const t = new Uint32Array(10);
573
590
  for (let n = 24 - e; n < 24; n++) {
574
591
  for (let a = 0; a < 10; a++)
575
592
  t[a] = r[a] ^ r[a + 10] ^ r[a + 20] ^ r[a + 30] ^ r[a + 40];
576
593
  for (let a = 0; a < 10; a += 2) {
577
- const i = (a + 8) % 10, c = (a + 2) % 10, l = t[c], d = t[c + 1], h = J(l, d, 1) ^ t[i], m = Z(l, d, 1) ^ t[i + 1];
594
+ const i = (a + 8) % 10, c = (a + 2) % 10, l = t[c], d = t[c + 1], h = ee(l, d, 1) ^ t[i], g = te(l, d, 1) ^ t[i + 1];
578
595
  for (let u = 0; u < 50; u += 10)
579
- r[a + u] ^= h, r[a + u + 1] ^= m;
596
+ r[a + u] ^= h, r[a + u + 1] ^= g;
580
597
  }
581
598
  let s = r[2], o = r[3];
582
599
  for (let a = 0; a < 24; a++) {
583
- const i = ce[a], c = J(s, o, i), l = Z(s, o, i), d = ie[a];
600
+ const i = de[a], c = ee(s, o, i), l = te(s, o, i), d = le[a];
584
601
  s = r[d], o = r[d + 1], r[d] = c, r[d + 1] = l;
585
602
  }
586
603
  for (let a = 0; a < 50; a += 10) {
@@ -589,25 +606,26 @@ function At(r, e = 24) {
589
606
  for (let i = 0; i < 10; i++)
590
607
  r[a + i] ^= ~t[(i + 2) % 10] & t[(i + 4) % 10];
591
608
  }
592
- r[0] ^= _t[n], r[1] ^= kt[n];
609
+ r[0] ^= Et[n], r[1] ^= xt[n];
593
610
  }
594
- t.fill(0);
611
+ ie(t);
595
612
  }
596
- class L extends it {
613
+ class Y extends ut {
597
614
  // NOTE: we accept arguments in bytes instead of bits here.
598
615
  constructor(e, t, n, s = !1, o = 24) {
599
- if (super(), this.blockLen = e, this.suffix = t, this.outputLen = n, this.enableXOF = s, this.rounds = o, this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, X(n), 0 >= this.blockLen || this.blockLen >= 200)
600
- throw new Error("Sha3 supports only keccak-f1600 function");
601
- this.state = new Uint8Array(200), this.state32 = st(this.state);
616
+ if (super(), this.pos = 0, this.posOut = 0, this.finished = !1, this.destroyed = !1, this.enableXOF = !1, this.blockLen = e, this.suffix = t, this.outputLen = n, this.enableXOF = s, this.rounds = o, V(n), !(0 < e && e < 200))
617
+ throw new Error("only keccak-f1600 function is supported");
618
+ this.state = new Uint8Array(200), this.state32 = it(this.state);
619
+ }
620
+ clone() {
621
+ return this._cloneInto();
602
622
  }
603
623
  keccak() {
604
- At(this.state32, this.rounds), this.posOut = 0, this.pos = 0;
624
+ J(this.state32), Ct(this.state32, this.rounds), J(this.state32), this.posOut = 0, this.pos = 0;
605
625
  }
606
626
  update(e) {
607
- G(this);
608
- const { blockLen: t, state: n } = this;
609
- e = ae(e);
610
- const s = e.length;
627
+ G(this), e = ce(e), T(e);
628
+ const { blockLen: t, state: n } = this, s = e.length;
611
629
  for (let o = 0; o < s; ) {
612
630
  const a = Math.min(t - this.pos, s - o);
613
631
  for (let i = 0; i < a; i++)
@@ -624,7 +642,7 @@ class L extends it {
624
642
  e[n] ^= t, (t & 128) !== 0 && n === s - 1 && this.keccak(), e[s - 1] ^= 128, this.keccak();
625
643
  }
626
644
  writeInto(e) {
627
- G(this, !1), oe(e), this.finish();
645
+ G(this, !1), T(e), this.finish();
628
646
  const t = this.state, { blockLen: n } = this;
629
647
  for (let s = 0, o = e.length; s < o; ) {
630
648
  this.posOut >= n && this.keccak();
@@ -639,10 +657,10 @@ class L extends it {
639
657
  return this.writeInto(e);
640
658
  }
641
659
  xof(e) {
642
- return X(e), this.xofInto(new Uint8Array(e));
660
+ return V(e), this.xofInto(new Uint8Array(e));
643
661
  }
644
662
  digestInto(e) {
645
- if (rt(e, this), this.finished)
663
+ if (at(e, this), this.finished)
646
664
  throw new Error("digest() was already called");
647
665
  return this.writeInto(e), this.destroy(), e;
648
666
  }
@@ -650,55 +668,55 @@ class L extends it {
650
668
  return this.digestInto(new Uint8Array(this.outputLen));
651
669
  }
652
670
  destroy() {
653
- this.destroyed = !0, this.state.fill(0);
671
+ this.destroyed = !0, ie(this.state);
654
672
  }
655
673
  _cloneInto(e) {
656
674
  const { blockLen: t, suffix: n, outputLen: s, rounds: o, enableXOF: a } = this;
657
- return e || (e = new L(t, n, s, a, o)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = o, e.suffix = n, e.outputLen = s, e.enableXOF = a, e.destroyed = this.destroyed, e;
675
+ return e || (e = new Y(t, n, s, a, o)), e.state32.set(this.state32), e.pos = this.pos, e.posOut = this.posOut, e.finished = this.finished, e.rounds = o, e.suffix = n, e.outputLen = s, e.enableXOF = a, e.destroyed = this.destroyed, e;
658
676
  }
659
677
  }
660
- const It = (r, e, t) => ct(() => new L(e, r, t)), vt = /* @__PURE__ */ It(1, 136, 256 / 8);
661
- let de = !1;
662
- const he = function(r) {
663
- return vt(r);
678
+ const St = (r, e, t) => ft(() => new Y(e, r, t)), Rt = St(1, 136, 256 / 8);
679
+ let fe = !1;
680
+ const pe = function(r) {
681
+ return Rt(r);
664
682
  };
665
- let ue = he;
683
+ let me = pe;
666
684
  function M(r) {
667
- const e = O(r, "data");
668
- return tt(ue(e));
685
+ const e = L(r, "data");
686
+ return st(me(e));
669
687
  }
670
- M._ = he;
688
+ M._ = pe;
671
689
  M.lock = function() {
672
- de = !0;
690
+ fe = !0;
673
691
  };
674
692
  M.register = function(r) {
675
- if (de)
693
+ if (fe)
676
694
  throw new TypeError("keccak256 is locked");
677
- ue = r;
695
+ me = r;
678
696
  };
679
697
  Object.freeze(M);
680
- const Et = BigInt(0), xt = BigInt(36);
681
- function ee(r) {
698
+ const Pt = BigInt(0), Dt = BigInt(36);
699
+ function re(r) {
682
700
  r = r.toLowerCase();
683
701
  const e = r.substring(2).split(""), t = new Uint8Array(40);
684
702
  for (let s = 0; s < 40; s++)
685
703
  t[s] = e[s].charCodeAt(0);
686
- const n = O(M(t));
704
+ const n = L(M(t));
687
705
  for (let s = 0; s < 40; s += 2)
688
706
  n[s >> 1] >> 4 >= 8 && (e[s] = e[s].toUpperCase()), (n[s >> 1] & 15) >= 8 && (e[s + 1] = e[s + 1].toUpperCase());
689
707
  return "0x" + e.join("");
690
708
  }
691
- const Y = {};
709
+ const F = {};
692
710
  for (let r = 0; r < 10; r++)
693
- Y[String(r)] = String(r);
711
+ F[String(r)] = String(r);
694
712
  for (let r = 0; r < 26; r++)
695
- Y[String.fromCharCode(65 + r)] = String(10 + r);
696
- const te = 15;
697
- function Ct(r) {
713
+ F[String.fromCharCode(65 + r)] = String(10 + r);
714
+ const ne = 15;
715
+ function Nt(r) {
698
716
  r = r.toUpperCase(), r = r.substring(4) + r.substring(0, 2) + "00";
699
- let e = r.split("").map((n) => Y[n]).join("");
700
- for (; e.length >= te; ) {
701
- let n = e.substring(0, te);
717
+ let e = r.split("").map((n) => F[n]).join("");
718
+ for (; e.length >= ne; ) {
719
+ let n = e.substring(0, ne);
702
720
  e = parseInt(n, 10) % 97 + e.substring(n.length);
703
721
  }
704
722
  let t = String(98 - parseInt(e, 10) % 97);
@@ -706,7 +724,7 @@ function Ct(r) {
706
724
  t = "0" + t;
707
725
  return t;
708
726
  }
709
- const Rt = function() {
727
+ const Mt = function() {
710
728
  const r = {};
711
729
  for (let e = 0; e < 36; e++) {
712
730
  const t = "0123456789abcdefghijklmnopqrstuvwxyz"[e];
@@ -714,29 +732,29 @@ const Rt = function() {
714
732
  }
715
733
  return r;
716
734
  }();
717
- function St(r) {
735
+ function Bt(r) {
718
736
  r = r.toLowerCase();
719
- let e = Et;
737
+ let e = Pt;
720
738
  for (let t = 0; t < r.length; t++)
721
- e = e * xt + Rt[r[t]];
739
+ e = e * Dt + Mt[r[t]];
722
740
  return e;
723
741
  }
724
- function g(r) {
742
+ function m(r) {
725
743
  if (D(typeof r == "string", "invalid address", "address", r), r.match(/^(0x)?[0-9a-fA-F]{40}$/)) {
726
744
  r.startsWith("0x") || (r = "0x" + r);
727
- const e = ee(r);
745
+ const e = re(r);
728
746
  return D(!r.match(/([A-F].*[a-f])|([a-f].*[A-F])/) || e === r, "bad address checksum", "address", r), e;
729
747
  }
730
748
  if (r.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)) {
731
- D(r.substring(2, 4) === Ct(r), "bad icap checksum", "address", r);
732
- let e = St(r.substring(4)).toString(16);
749
+ D(r.substring(2, 4) === Nt(r), "bad icap checksum", "address", r);
750
+ let e = Bt(r.substring(4)).toString(16);
733
751
  for (; e.length < 40; )
734
752
  e = "0" + e;
735
- return ee("0x" + e);
753
+ return re("0x" + e);
736
754
  }
737
755
  D(!1, "invalid address", "address", r);
738
756
  }
739
- class Pt {
757
+ class Tt {
740
758
  type = "argent";
741
759
  platform = "starknet";
742
760
  wallet = void 0;
@@ -762,8 +780,8 @@ class Pt {
762
780
  try {
763
781
  if (!this.isAvailable())
764
782
  throw new Error("Argent is not available");
765
- const { wallet: e, connectorData: t } = await ve({
766
- connectors: [new Ee({ options: { id: "argentX" } })]
783
+ const { wallet: e, connectorData: t } = await Ce({
784
+ connectors: [new Se({ options: { id: "argentX" } })]
767
785
  });
768
786
  if (!e)
769
787
  throw new Error("No wallet found");
@@ -826,16 +844,16 @@ class Pt {
826
844
  }
827
845
  }
828
846
  }
829
- function Dt(r) {
847
+ function Qt(r) {
830
848
  if (typeof window > "u")
831
849
  return;
832
850
  const e = (t) => r(t.detail);
833
851
  return window.addEventListener("eip6963:announceProvider", e), window.dispatchEvent(new CustomEvent("eip6963:requestProvider")), () => window.removeEventListener("eip6963:announceProvider", e);
834
852
  }
835
- function fe() {
853
+ function ge() {
836
854
  const r = /* @__PURE__ */ new Set();
837
855
  let e = [];
838
- const t = () => Dt((s) => {
856
+ const t = () => Qt((s) => {
839
857
  e.some(({ info: o }) => o.uuid === s.info.uuid) || (e = [...e, s], r.forEach((o) => o(e, { added: [s] })));
840
858
  });
841
859
  let n = t();
@@ -863,15 +881,15 @@ function fe() {
863
881
  }
864
882
  };
865
883
  }
866
- class Nt {
884
+ class Ut {
867
885
  type = "metamask";
868
886
  platform = "ethereum";
869
887
  MMSDK;
870
- store = fe();
888
+ store = ge();
871
889
  account = void 0;
872
890
  connectedAccounts = [];
873
891
  constructor() {
874
- this.MMSDK = new xe({
892
+ this.MMSDK = new Re({
875
893
  dappMetadata: {
876
894
  name: "Cartridge Controller",
877
895
  url: window.location.href
@@ -880,9 +898,9 @@ class Nt {
880
898
  this.MMSDK.getProvider()?.request({
881
899
  method: "eth_accounts"
882
900
  }).then((e) => {
883
- e && e.length > 0 && (this.account = g(e[0]), this.connectedAccounts = e.map(g));
901
+ e && e.length > 0 && (this.account = m(e[0]), this.connectedAccounts = e.map(m));
884
902
  }), this.MMSDK.getProvider()?.on("accountsChanged", (e) => {
885
- Array.isArray(e) && e.length > 0 && (this.account = g(e?.[0]), this.connectedAccounts = e.map(g));
903
+ Array.isArray(e) && e.length > 0 && (this.account = m(e?.[0]), this.connectedAccounts = e.map(m));
886
904
  });
887
905
  });
888
906
  }
@@ -909,8 +927,8 @@ class Nt {
909
927
  throw new Error("MetaMask is not available");
910
928
  const e = await this.MMSDK.connect();
911
929
  if (e && e.length > 0)
912
- return this.account = g(e[0]), this.connectedAccounts = e.map(
913
- (t) => g(t)
930
+ return this.account = m(e[0]), this.connectedAccounts = e.map(
931
+ (t) => m(t)
914
932
  ), { success: !0, wallet: this.type, account: this.account };
915
933
  throw new Error("No accounts found");
916
934
  } catch (e) {
@@ -1036,7 +1054,7 @@ class Nt {
1036
1054
  }
1037
1055
  }
1038
1056
  }
1039
- class Mt {
1057
+ class $t {
1040
1058
  type = "phantom";
1041
1059
  platform = "solana";
1042
1060
  account = void 0;
@@ -1104,7 +1122,7 @@ class Mt {
1104
1122
  if (!this.isAvailable() || !this.account)
1105
1123
  throw new Error("Phantom is not connected");
1106
1124
  try {
1107
- const t = Ce.from(e), s = await this.getProvider().signAndSendTransaction(t);
1125
+ const t = Pe.from(e), s = await this.getProvider().signAndSendTransaction(t);
1108
1126
  return {
1109
1127
  success: !0,
1110
1128
  wallet: this.type,
@@ -1139,21 +1157,21 @@ class Mt {
1139
1157
  }
1140
1158
  }
1141
1159
  }
1142
- const Bt = "io.rabby";
1143
- class Qt {
1160
+ const zt = "io.rabby";
1161
+ class Ot {
1144
1162
  type = "rabby";
1145
1163
  platform = "ethereum";
1146
1164
  account = void 0;
1147
- store = fe();
1165
+ store = ge();
1148
1166
  provider;
1149
1167
  connectedAccounts = [];
1150
1168
  constructor() {
1151
- this.provider = this.store.getProviders().find((e) => e.info.rdns === Bt), this.provider?.provider.request({
1169
+ this.provider = this.store.getProviders().find((e) => e.info.rdns === zt), this.provider?.provider.request({
1152
1170
  method: "eth_accounts"
1153
1171
  }).then((e) => {
1154
- this.connectedAccounts = e.map(g), e.length > 0 && (this.account = g(e?.[0]));
1172
+ this.connectedAccounts = e.map(m), e.length > 0 && (this.account = m(e?.[0]));
1155
1173
  }), this.provider?.provider?.on("accountsChanged", (e) => {
1156
- e && (this.connectedAccounts = e.map((t) => g(t)), this.account = g(e?.[0]));
1174
+ e && (this.connectedAccounts = e.map((t) => m(t)), this.account = m(e?.[0]));
1157
1175
  });
1158
1176
  }
1159
1177
  isAvailable() {
@@ -1172,7 +1190,7 @@ class Qt {
1172
1190
  };
1173
1191
  }
1174
1192
  async connect(e) {
1175
- if (e && this.connectedAccounts.includes(g(e)) && (this.account = g(e)), this.account)
1193
+ if (e && this.connectedAccounts.includes(m(e)) && (this.account = m(e)), this.account)
1176
1194
  return { success: !0, wallet: this.type, account: this.account };
1177
1195
  try {
1178
1196
  if (!this.isAvailable())
@@ -1181,7 +1199,7 @@ class Qt {
1181
1199
  method: "eth_requestAccounts"
1182
1200
  });
1183
1201
  if (t && t.length > 0)
1184
- return this.account = g(t[0]), this.connectedAccounts = t.map(g), { success: !0, wallet: this.type, account: this.account };
1202
+ return this.account = m(t[0]), this.connectedAccounts = t.map(m), { success: !0, wallet: this.type, account: this.account };
1185
1203
  throw new Error("No accounts found");
1186
1204
  } catch (t) {
1187
1205
  return console.error("Error connecting to Rabby:", t), {
@@ -1306,18 +1324,18 @@ class Qt {
1306
1324
  }
1307
1325
  }
1308
1326
  }
1309
- class Ut {
1327
+ class Lt {
1310
1328
  walletAdapters;
1311
1329
  constructor() {
1312
1330
  if (this.walletAdapters = /* @__PURE__ */ new Map(), typeof window > "u")
1313
1331
  return;
1314
- const e = new Nt();
1332
+ const e = new Ut();
1315
1333
  e.isAvailable() && this.walletAdapters.set("metamask", e);
1316
- const t = new Mt();
1334
+ const t = new $t();
1317
1335
  t.isAvailable() && this.walletAdapters.set("phantom", t);
1318
- const n = new Pt();
1336
+ const n = new Tt();
1319
1337
  n.isAvailable() && this.walletAdapters.set("argent", n);
1320
- const s = new Qt();
1338
+ const s = new Ot();
1321
1339
  s.isAvailable() && this.walletAdapters.set("rabby", s), window.wallet_bridge = this;
1322
1340
  }
1323
1341
  getIFrameMethods() {
@@ -1327,7 +1345,8 @@ class Ut {
1327
1345
  externalSignMessage: (e) => (t, n) => this.signMessage(t, n),
1328
1346
  externalSignTypedData: (e) => (t, n) => this.signTypedData(t, n),
1329
1347
  externalSendTransaction: (e) => (t, n) => this.sendTransaction(t, n),
1330
- externalGetBalance: (e) => (t, n) => this.getBalance(t, n)
1348
+ externalGetBalance: (e) => (t, n) => this.getBalance(t, n),
1349
+ externalSwitchChain: (e) => (t, n) => this.switchChain(t, n)
1331
1350
  };
1332
1351
  }
1333
1352
  async detectWallets() {
@@ -1376,16 +1395,16 @@ class Ut {
1376
1395
  }
1377
1396
  }
1378
1397
  getConnectedWalletAdapter(e) {
1379
- let t;
1380
- if (typeof e == "string") {
1381
- const n = g(e);
1382
- t = this.walletAdapters.values().find((s) => s.getConnectedAccounts().includes(n));
1383
- } else
1384
- t = this.walletAdapters.get(e);
1385
- if (!t)
1386
- throw new Error(
1387
- `Wallet with identifier ${e} is not connected or supported`
1388
- );
1398
+ let t, n;
1399
+ try {
1400
+ n = m(e);
1401
+ } catch {
1402
+ if (t = this.walletAdapters.get(e), !t)
1403
+ throw new Error(`Wallet ${e} is not connected or supported`);
1404
+ return t;
1405
+ }
1406
+ if (t = this.walletAdapters.values().find((s) => s.getConnectedAccounts().includes(n)), !t)
1407
+ throw new Error(`No wallet found with connected address ${e}`);
1389
1408
  return t;
1390
1409
  }
1391
1410
  async signMessage(e, t) {
@@ -1448,8 +1467,15 @@ class Ut {
1448
1467
  );
1449
1468
  }
1450
1469
  }
1470
+ async switchChain(e, t) {
1471
+ try {
1472
+ return await this.getConnectedWalletAdapter(e).switchChain(t);
1473
+ } catch (n) {
1474
+ return console.error(`Error switching chain for ${e} wallet:`, n), !1;
1475
+ }
1476
+ }
1451
1477
  }
1452
- class Tt extends Ge {
1478
+ class Yt extends Ze {
1453
1479
  walletBridge;
1454
1480
  constructor({
1455
1481
  url: e,
@@ -1460,7 +1486,7 @@ class Tt extends Ge {
1460
1486
  tokens: a,
1461
1487
  ...i
1462
1488
  }) {
1463
- const c = new URL(e ?? we), l = new Ut();
1489
+ const c = new URL(e ?? Ae), l = new Lt();
1464
1490
  t && c.searchParams.set(
1465
1491
  "policies",
1466
1492
  encodeURIComponent(JSON.stringify(t))
@@ -1478,7 +1504,7 @@ class Tt extends Ge {
1478
1504
  return this.walletBridge;
1479
1505
  }
1480
1506
  }
1481
- class Ht extends _e {
1507
+ class Vt extends Ie {
1482
1508
  keychain;
1483
1509
  options;
1484
1510
  iframes;
@@ -1492,15 +1518,15 @@ class Ht extends _e {
1492
1518
  const n = [...[
1493
1519
  { rpcUrl: "https://api.cartridge.gg/x/starknet/sepolia" },
1494
1520
  { rpcUrl: "https://api.cartridge.gg/x/starknet/mainnet" }
1495
- ], ...e.chains || []], s = e.defaultChainId || $.StarknetChainId.SN_MAIN;
1521
+ ], ...e.chains || []], s = e.defaultChainId || z.StarknetChainId.SN_MAIN;
1496
1522
  this.selectedChain = s, this.chains = /* @__PURE__ */ new Map(), this.iframes = {
1497
- keychain: new Tt({
1523
+ keychain: new Yt({
1498
1524
  ...e,
1499
1525
  onClose: this.keychain?.reset,
1500
1526
  onConnect: (o) => {
1501
1527
  this.keychain = o;
1502
1528
  },
1503
- version: ke
1529
+ version: ve
1504
1530
  })
1505
1531
  }, this.options = { ...e, chains: n, defaultChainId: s }, this.initializeChains(n), typeof window < "u" && (window.starknet_controller = this);
1506
1532
  }
@@ -1512,7 +1538,9 @@ class Ht extends _e {
1512
1538
  try {
1513
1539
  await this.disconnect(), document.querySelectorAll('iframe[id^="controller-"]').forEach((t) => {
1514
1540
  const n = t.parentElement;
1515
- n && (n.style.visibility = "hidden", n.style.opacity = "0");
1541
+ n && (n.style.opacity = "0", setTimeout(() => {
1542
+ n.style.display = "none";
1543
+ }, 200));
1516
1544
  }), document.body && (document.body.style.overflow = "auto"), window.location.reload();
1517
1545
  } catch (e) {
1518
1546
  throw console.error("Logout failed:", e), e;
@@ -1526,7 +1554,7 @@ class Ht extends _e {
1526
1554
  }
1527
1555
  const e = await this.keychain.probe(this.rpcUrl());
1528
1556
  let t = e?.rpcUrl || this.rpcUrl();
1529
- this.account = new H(
1557
+ this.account = new K(
1530
1558
  this,
1531
1559
  t,
1532
1560
  e.address,
@@ -1558,9 +1586,9 @@ class Ht extends _e {
1558
1586
  this.rpcUrl(),
1559
1587
  this.options.signupOptions
1560
1588
  );
1561
- if (e.code !== R.SUCCESS)
1589
+ if (e.code !== S.SUCCESS)
1562
1590
  throw new Error(e.message);
1563
- return e = e, this.account = new H(
1591
+ return e = e, this.account = new K(
1564
1592
  this,
1565
1593
  this.rpcUrl(),
1566
1594
  e.address,
@@ -1605,8 +1633,10 @@ class Ht extends _e {
1605
1633
  console.error("Account is not ready");
1606
1634
  return;
1607
1635
  }
1608
- const t = await this.keychain.username();
1609
- await this.keychain.navigate(`/account/${t}/${e}`), this.iframes.keychain.open();
1636
+ const t = await this.keychain.username(), n = [];
1637
+ this.options.slot && n.push(`ps=${this.options.slot}`), await this.keychain.navigate(
1638
+ `/account/${t}/${e}?${n.join("&")}`
1639
+ ), this.iframes.keychain.open();
1610
1640
  }
1611
1641
  async openProfileTo(e) {
1612
1642
  if (!this.keychain || !this.iframes.keychain) {
@@ -1617,8 +1647,10 @@ class Ht extends _e {
1617
1647
  console.error("Account is not ready");
1618
1648
  return;
1619
1649
  }
1620
- const t = await this.keychain.username();
1621
- await this.keychain.navigate(`/account/${t}/${e}`), this.iframes.keychain.open();
1650
+ const t = await this.keychain.username(), n = [];
1651
+ this.options.slot && n.push(`ps=${this.options.slot}`), await this.keychain.navigate(
1652
+ `/account/${t}/${e}?${n.join("&")}`
1653
+ ), this.iframes.keychain.open();
1622
1654
  }
1623
1655
  async openProfileAt(e) {
1624
1656
  if (!this.keychain || !this.iframes.keychain) {
@@ -1645,10 +1677,10 @@ class Ht extends _e {
1645
1677
  const e = this.chains.get(this.selectedChain);
1646
1678
  if (!e) {
1647
1679
  const t = Array.from(this.chains.keys()).map(
1648
- (n) => W.decodeShortString(n)
1680
+ (n) => H.decodeShortString(n)
1649
1681
  );
1650
1682
  throw new Error(
1651
- `Chain not found: ${W.decodeShortString(this.selectedChain)}. Available chains: ${t.join(", ")}`
1683
+ `Chain not found: ${H.decodeShortString(this.selectedChain)}. Available chains: ${t.join(", ")}`
1652
1684
  );
1653
1685
  }
1654
1686
  return e.rpcUrl;
@@ -1665,14 +1697,16 @@ class Ht extends _e {
1665
1697
  console.error(new p().message);
1666
1698
  return;
1667
1699
  }
1668
- this.iframes.keychain.open(), this.keychain.openPurchaseCredits();
1700
+ this.keychain.navigate("/purchase/credits").then(() => {
1701
+ this.iframes.keychain.open();
1702
+ });
1669
1703
  }
1670
1704
  openStarterPack(e) {
1671
1705
  if (!this.keychain || !this.iframes.keychain) {
1672
1706
  console.error(new p().message);
1673
1707
  return;
1674
1708
  }
1675
- this.keychain.navigate(`/starter-pack/${e}`).then(() => {
1709
+ this.keychain.navigate(`/purchase/starterpack/${e}`).then(() => {
1676
1710
  this.iframes.keychain.open();
1677
1711
  });
1678
1712
  }
@@ -1685,7 +1719,7 @@ class Ht extends _e {
1685
1719
  t && this.switchStarknetChain(t), this.iframes.keychain.open();
1686
1720
  const s = await this.keychain.execute(e, void 0, void 0, !0);
1687
1721
  return this.iframes.keychain.close(), t && this.switchStarknetChain(n), {
1688
- status: !(s && (s.code === R.NOT_CONNECTED || s.code === R.CANCELED)),
1722
+ status: !(s && (s.code === S.NOT_CONNECTED || s.code === S.CANCELED)),
1689
1723
  transactionHash: s?.transaction_hash
1690
1724
  };
1691
1725
  }
@@ -1695,7 +1729,7 @@ class Ht extends _e {
1695
1729
  initializeChains(e) {
1696
1730
  for (const t of e)
1697
1731
  try {
1698
- const n = new URL(t.rpcUrl), s = Ae(n), o = s === $.StarknetChainId.SN_MAIN, a = s === $.StarknetChainId.SN_SEPOLIA, i = n.hostname === "api.cartridge.gg", c = n.hostname === "localhost" || n.hostname === "127.0.0.1";
1732
+ const n = new URL(t.rpcUrl), s = Ee(n), o = s === z.StarknetChainId.SN_MAIN, a = s === z.StarknetChainId.SN_SEPOLIA, i = n.hostname === "api.cartridge.gg", c = n.hostname === "localhost" || n.hostname === "127.0.0.1";
1699
1733
  if ((o || a) && !(i || c))
1700
1734
  throw new Error(
1701
1735
  `Only Cartridge RPC providers are allowed for ${o ? "mainnet" : "sepolia"}. Please use: https://api.cartridge.gg/x/starknet/${o ? "mainnet" : "sepolia"}`
@@ -1723,11 +1757,11 @@ class Ht extends _e {
1723
1757
  });
1724
1758
  }
1725
1759
  }
1726
- const S = /* @__PURE__ */ new Map();
1727
- async function pe(r) {
1760
+ const R = /* @__PURE__ */ new Map();
1761
+ async function ye(r) {
1728
1762
  if (!r.addresses?.length && !r.usernames?.length)
1729
1763
  return { results: [] };
1730
- const e = await fetch(`${Ie}/lookup`, {
1764
+ const e = await fetch(`${xe}/lookup`, {
1731
1765
  method: "POST",
1732
1766
  headers: {
1733
1767
  "Content-Type": "application/json"
@@ -1738,26 +1772,26 @@ async function pe(r) {
1738
1772
  throw new Error(`HTTP error! status: ${e.status}`);
1739
1773
  return e.json();
1740
1774
  }
1741
- async function Kt(r) {
1742
- const e = r.filter((t) => !S.has(t));
1743
- return e.length > 0 && (await pe({ usernames: e })).results.forEach((n) => {
1744
- S.set(n.username, n.addresses[0]);
1775
+ async function Gt(r) {
1776
+ const e = r.filter((t) => !R.has(t));
1777
+ return e.length > 0 && (await ye({ usernames: e })).results.forEach((n) => {
1778
+ R.set(n.username, n.addresses[0]);
1745
1779
  }), new Map(
1746
- r.map((t) => [t, S.get(t)]).filter((t) => t[1] !== void 0)
1780
+ r.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1747
1781
  );
1748
1782
  }
1749
- async function jt(r) {
1750
- r = r.map(ye.toHex);
1751
- const e = r.filter((t) => !S.has(t));
1752
- return e.length > 0 && (await pe({
1783
+ async function Jt(r) {
1784
+ r = r.map(_e.toHex);
1785
+ const e = r.filter((t) => !R.has(t));
1786
+ return e.length > 0 && (await ye({
1753
1787
  addresses: e
1754
1788
  })).results.forEach((n) => {
1755
- S.set(n.addresses[0], n.username);
1789
+ R.set(n.addresses[0], n.username);
1756
1790
  }), new Map(
1757
- r.map((t) => [t, S.get(t)]).filter((t) => t[1] !== void 0)
1791
+ r.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1758
1792
  );
1759
1793
  }
1760
- var $t = [
1794
+ var Ft = [
1761
1795
  {
1762
1796
  name: "Wrapped BTC",
1763
1797
  symbol: "WBTC",
@@ -2321,13 +2355,13 @@ var $t = [
2321
2355
  total_supply: null,
2322
2356
  logo_url: "https://assets.underware.gg/pistols/fame.svg"
2323
2357
  }
2324
- ], ge = {
2358
+ ], be = {
2325
2359
  theme: {
2326
2360
  name: "Cartridge",
2327
2361
  icon: "icon.svg"
2328
2362
  }
2329
2363
  }, Q = "https://static.cartridge.gg/presets";
2330
- async function F() {
2364
+ async function W() {
2331
2365
  try {
2332
2366
  const r = await fetch(`${Q}/index.json`);
2333
2367
  if (!r.ok)
@@ -2337,12 +2371,12 @@ async function F() {
2337
2371
  return console.error("Error loading configs index:", r), { configs: [], baseUrl: Q };
2338
2372
  }
2339
2373
  }
2340
- async function qt() {
2341
- return (await F()).configs;
2374
+ async function Zt() {
2375
+ return (await W()).configs;
2342
2376
  }
2343
- async function Xt(r) {
2377
+ async function er(r) {
2344
2378
  try {
2345
- const n = `${(await F()).baseUrl || Q}/${r}`, s = await fetch(`${n}/config.json`);
2379
+ const n = `${(await W()).baseUrl || Q}/${r}`, s = await fetch(`${n}/config.json`);
2346
2380
  if (!s.ok)
2347
2381
  throw new Error(
2348
2382
  `Failed to load config ${r}: ${s.statusText}`
@@ -2372,8 +2406,8 @@ async function Xt(r) {
2372
2406
  return console.error(`Error loading config ${r}:`, e), null;
2373
2407
  }
2374
2408
  }
2375
- async function Gt() {
2376
- const r = await F(), e = r.configs, t = r.baseUrl || Q, n = {};
2409
+ async function tr() {
2410
+ const r = await W(), e = r.configs, t = r.baseUrl || Q, n = {};
2377
2411
  return await Promise.all(
2378
2412
  e.map(async (s) => {
2379
2413
  try {
@@ -2388,31 +2422,31 @@ async function Gt() {
2388
2422
  })
2389
2423
  ), n;
2390
2424
  }
2391
- ge.theme.icon = "https://static.cartridge.gg/presets/cartridge/icon.svg";
2392
- var Vt = $t, Jt = ge.theme;
2425
+ be.theme.icon = "https://static.cartridge.gg/presets/cartridge/icon.svg";
2426
+ var rr = Ft, nr = be.theme;
2393
2427
  export {
2394
- Pt as ArgentWallet,
2395
- tr as FeeSource,
2396
- Nt as MetaMaskWallet,
2428
+ Tt as ArgentWallet,
2429
+ ar as FeeSource,
2430
+ Ut as MetaMaskWallet,
2397
2431
  p as NotReadyToConnect,
2398
- Mt as PhantomWallet,
2399
- Qt as RabbyWallet,
2400
- R as ResponseCodes,
2401
- Ut as WalletBridge,
2402
- Ht as default,
2403
- Jt as defaultTheme,
2404
- Vt as erc20Metadata,
2405
- qt as getAvailableConfigs,
2406
- F as getConfigsIndex,
2407
- rr as humanizeString,
2408
- Gt as loadAllConfigs,
2409
- Xt as loadConfig,
2410
- jt as lookupAddresses,
2411
- Kt as lookupUsernames,
2412
- nr as normalizeCalls,
2413
- Ae as parseChainId,
2414
- be as toArray,
2415
- sr as toSessionPolicies,
2416
- or as toWasmPolicies
2432
+ $t as PhantomWallet,
2433
+ Ot as RabbyWallet,
2434
+ S as ResponseCodes,
2435
+ Lt as WalletBridge,
2436
+ Vt as default,
2437
+ nr as defaultTheme,
2438
+ rr as erc20Metadata,
2439
+ Zt as getAvailableConfigs,
2440
+ W as getConfigsIndex,
2441
+ ir as humanizeString,
2442
+ tr as loadAllConfigs,
2443
+ er as loadConfig,
2444
+ Jt as lookupAddresses,
2445
+ Gt as lookupUsernames,
2446
+ cr as normalizeCalls,
2447
+ Ee as parseChainId,
2448
+ ke as toArray,
2449
+ lr as toSessionPolicies,
2450
+ dr as toWasmPolicies
2417
2451
  };
2418
2452
  //# sourceMappingURL=index.js.map