@cartridge/controller 0.7.9-alpha.1 → 0.7.9-alpha.2

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,16 +1,17 @@
1
1
  import { WalletAccount as O, shortString as M, num as Y } from "starknet";
2
- import { R as A, t as $, K as W, P as H, B as j, N as g, p as K, A as q } from "./provider-qJi60GEX.js";
3
- import { h as Le, n as Oe, a as Ye, b as $e } from "./provider-qJi60GEX.js";
2
+ import { R as A, t as $, K as W, P as H, B as j, N as g, p as K, A as q } from "./provider-CGv2ANQX.js";
3
+ import { h as Ye, n as $e, a as We, b as He } from "./provider-CGv2ANQX.js";
4
4
  import { MetaMaskSDK as G } from "@metamask/sdk";
5
- import { connect as V } from "starknetkit";
6
- import { InjectedConnector as J } from "starknetkit/injected";
5
+ import { Transaction as V } from "@solana/web3.js";
6
+ import { connect as J } from "starknetkit";
7
+ import { InjectedConnector as X } from "starknetkit/injected";
7
8
  class N extends O {
8
9
  address;
9
10
  keychain;
10
11
  modal;
11
12
  options;
12
- constructor(e, t, a, n, o, c) {
13
- super({ nodeUrl: t }, e), this.address = a, this.keychain = n, this.options = o, this.modal = c;
13
+ constructor(e, t, r, n, o, c) {
14
+ super({ nodeUrl: t }, e), this.address = r, this.keychain = n, this.options = o, this.modal = c;
14
15
  }
15
16
  /**
16
17
  * Invoke execute function in account contract
@@ -25,7 +26,7 @@ class N extends O {
25
26
  * @returns response from addTransaction
26
27
  */
27
28
  async execute(e) {
28
- return e = $(e), new Promise(async (t, a) => {
29
+ return e = $(e), new Promise(async (t, r) => {
29
30
  const n = await this.keychain.execute(
30
31
  e,
31
32
  void 0,
@@ -37,7 +38,7 @@ class N extends O {
37
38
  return;
38
39
  }
39
40
  if (this.options?.propagateSessionErrors && n.code !== A.USER_INTERACTION_REQUIRED) {
40
- a(n.error);
41
+ r(n.error);
41
42
  return;
42
43
  }
43
44
  this.modal.open();
@@ -52,7 +53,7 @@ class N extends O {
52
53
  t(o), this.modal.close();
53
54
  return;
54
55
  }
55
- a(o.error);
56
+ r(o.error);
56
57
  });
57
58
  }
58
59
  /**
@@ -64,7 +65,7 @@ class N extends O {
64
65
  * @throws {Error} if the JSON object is not a valid JSON
65
66
  */
66
67
  async signMessage(e) {
67
- return new Promise(async (t, a) => {
68
+ return new Promise(async (t, r) => {
68
69
  const n = await this.keychain.signMessage(e, "", !0);
69
70
  if (!("code" in n)) {
70
71
  t(n);
@@ -72,78 +73,78 @@ class N extends O {
72
73
  }
73
74
  this.modal.open();
74
75
  const o = await this.keychain.signMessage(e, "", !1);
75
- "code" in o ? a(o.error) : t(o), this.modal.close();
76
+ "code" in o ? r(o.error) : t(o), this.modal.close();
76
77
  });
77
78
  }
78
79
  }
79
80
  var y;
80
- (function(r) {
81
- r.Call = "call", r.Reply = "reply", r.Syn = "syn", r.SynAck = "synAck", r.Ack = "ack";
81
+ (function(a) {
82
+ a.Call = "call", a.Reply = "reply", a.Syn = "syn", a.SynAck = "synAck", a.Ack = "ack";
82
83
  })(y || (y = {}));
83
84
  var x;
84
- (function(r) {
85
- r.Fulfilled = "fulfilled", r.Rejected = "rejected";
85
+ (function(a) {
86
+ a.Fulfilled = "fulfilled", a.Rejected = "rejected";
86
87
  })(x || (x = {}));
87
- var S;
88
- (function(r) {
89
- r.ConnectionDestroyed = "ConnectionDestroyed", r.ConnectionTimeout = "ConnectionTimeout", r.NoIframeSrc = "NoIframeSrc";
90
- })(S || (S = {}));
91
- var P;
92
- (function(r) {
93
- r.DataCloneError = "DataCloneError";
94
- })(P || (P = {}));
88
+ var E;
89
+ (function(a) {
90
+ a.ConnectionDestroyed = "ConnectionDestroyed", a.ConnectionTimeout = "ConnectionTimeout", a.NoIframeSrc = "NoIframeSrc";
91
+ })(E || (E = {}));
92
+ var D;
93
+ (function(a) {
94
+ a.DataCloneError = "DataCloneError";
95
+ })(D || (D = {}));
95
96
  var v;
96
- (function(r) {
97
- r.Message = "message";
97
+ (function(a) {
98
+ a.Message = "message";
98
99
  })(v || (v = {}));
99
- const X = (r, e) => {
100
+ const Z = (a, e) => {
100
101
  const t = [];
101
- let a = !1;
102
+ let r = !1;
102
103
  return {
103
104
  destroy(n) {
104
- a || (a = !0, e(`${r}: Destroying connection`), t.forEach((o) => {
105
+ r || (r = !0, e(`${a}: Destroying connection`), t.forEach((o) => {
105
106
  o(n);
106
107
  }));
107
108
  },
108
109
  onDestroy(n) {
109
- a ? n() : t.push(n);
110
+ r ? n() : t.push(n);
110
111
  }
111
112
  };
112
- }, Z = (r) => (...e) => {
113
- r && console.log("[Penpal]", ...e);
114
- }, ee = {
113
+ }, ee = (a) => (...e) => {
114
+ a && console.log("[Penpal]", ...e);
115
+ }, te = {
115
116
  "http:": "80",
116
117
  "https:": "443"
117
- }, te = /^(https?:)?\/\/([^/:]+)?(:(\d+))?/, ae = ["file:", "data:"], re = (r) => {
118
- if (r && ae.find((s) => r.startsWith(s)))
118
+ }, re = /^(https?:)?\/\/([^/:]+)?(:(\d+))?/, ae = ["file:", "data:"], ne = (a) => {
119
+ if (a && ae.find((s) => a.startsWith(s)))
119
120
  return "null";
120
- const e = document.location, t = te.exec(r);
121
- let a, n, o;
122
- t ? (a = t[1] ? t[1] : e.protocol, n = t[2], o = t[4]) : (a = e.protocol, n = e.hostname, o = e.port);
123
- const c = o && o !== ee[a] ? `:${o}` : "";
124
- return `${a}//${n}${c}`;
125
- }, B = ({ name: r, message: e, stack: t }) => ({
126
- name: r,
121
+ const e = document.location, t = re.exec(a);
122
+ let r, n, o;
123
+ t ? (r = t[1] ? t[1] : e.protocol, n = t[2], o = t[4]) : (r = e.protocol, n = e.hostname, o = e.port);
124
+ const c = o && o !== te[r] ? `:${o}` : "";
125
+ return `${r}//${n}${c}`;
126
+ }, B = ({ name: a, message: e, stack: t }) => ({
127
+ name: a,
127
128
  message: e,
128
129
  stack: t
129
- }), ne = (r) => {
130
+ }), oe = (a) => {
130
131
  const e = new Error();
131
- return Object.keys(r).forEach((t) => e[t] = r[t]), e;
132
- }, oe = (r, e, t) => {
133
- const { localName: a, local: n, remote: o, originForSending: c, originForReceiving: s } = r;
132
+ return Object.keys(a).forEach((t) => e[t] = a[t]), e;
133
+ }, se = (a, e, t) => {
134
+ const { localName: r, local: n, remote: o, originForSending: c, originForReceiving: s } = a;
134
135
  let i = !1;
135
136
  const p = (d) => {
136
137
  if (d.source !== o || d.data.penpal !== y.Call)
137
138
  return;
138
139
  if (s !== "*" && d.origin !== s) {
139
- t(`${a} received message from origin ${d.origin} which did not match expected origin ${s}`);
140
+ t(`${r} received message from origin ${d.origin} which did not match expected origin ${s}`);
140
141
  return;
141
142
  }
142
143
  const l = d.data, { methodName: f, args: h, id: _ } = l;
143
- t(`${a}: Received ${f}() call`);
144
+ t(`${r}: Received ${f}() call`);
144
145
  const w = (u) => (k) => {
145
- if (t(`${a}: Sending ${f}() reply`), i) {
146
- t(`${a}: Unable to send ${f}() reply due to destroyed connection`);
146
+ if (t(`${r}: Sending ${f}() reply`), i) {
147
+ t(`${r}: Unable to send ${f}() reply due to destroyed connection`);
147
148
  return;
148
149
  }
149
150
  const b = {
@@ -156,7 +157,7 @@ const X = (r, e) => {
156
157
  try {
157
158
  o.postMessage(b, c);
158
159
  } catch (m) {
159
- if (m.name === P.DataCloneError) {
160
+ if (m.name === D.DataCloneError) {
160
161
  const C = {
161
162
  penpal: y.Reply,
162
163
  id: _,
@@ -175,25 +176,25 @@ const X = (r, e) => {
175
176
  i = !0, n.removeEventListener(v.Message, p);
176
177
  };
177
178
  };
178
- let se = 0;
179
- const ie = () => ++se, Q = ".", T = (r) => r ? r.split(Q) : [], ce = (r) => r.join(Q), de = (r, e) => {
180
- const t = T(e || "");
181
- return t.push(r), ce(t);
182
- }, le = (r, e, t) => {
183
- const a = T(e);
184
- return a.reduce((n, o, c) => (typeof n[o] > "u" && (n[o] = {}), c === a.length - 1 && (n[o] = t), n[o]), r), r;
185
- }, z = (r, e) => {
179
+ let ie = 0;
180
+ const ce = () => ++ie, T = ".", Q = (a) => a ? a.split(T) : [], de = (a) => a.join(T), le = (a, e) => {
181
+ const t = Q(e || "");
182
+ return t.push(a), de(t);
183
+ }, pe = (a, e, t) => {
184
+ const r = Q(e);
185
+ return r.reduce((n, o, c) => (typeof n[o] > "u" && (n[o] = {}), c === r.length - 1 && (n[o] = t), n[o]), a), a;
186
+ }, z = (a, e) => {
186
187
  const t = {};
187
- return Object.keys(r).forEach((a) => {
188
- const n = r[a], o = de(a, e);
188
+ return Object.keys(a).forEach((r) => {
189
+ const n = a[r], o = le(r, e);
189
190
  typeof n == "object" && Object.assign(t, z(n, o)), typeof n == "function" && (t[o] = n);
190
191
  }), t;
191
- }, pe = (r) => {
192
+ }, me = (a) => {
192
193
  const e = {};
193
- for (const t in r)
194
- le(e, t, r[t]);
194
+ for (const t in a)
195
+ pe(e, t, a[t]);
195
196
  return e;
196
- }, me = (r, e, t, a, n) => {
197
+ }, he = (a, e, t, r, n) => {
197
198
  const { localName: o, local: c, remote: s, originForSending: i, originForReceiving: p } = e;
198
199
  let d = !1;
199
200
  n(`${o}: Connecting call sender`);
@@ -205,22 +206,22 @@ const ie = () => ++se, Q = ".", T = (r) => r ? r.split(Q) : [], ce = (r) => r.jo
205
206
  } catch {
206
207
  w = !0;
207
208
  }
208
- if (w && a(), d) {
209
+ if (w && r(), d) {
209
210
  const u = new Error(`Unable to send ${h}() call due to destroyed connection`);
210
- throw u.code = S.ConnectionDestroyed, u;
211
+ throw u.code = E.ConnectionDestroyed, u;
211
212
  }
212
213
  return new Promise((u, k) => {
213
- const b = ie(), m = (I) => {
214
+ const b = ce(), m = (I) => {
214
215
  if (I.source !== s || I.data.penpal !== y.Reply || I.data.id !== b)
215
216
  return;
216
217
  if (p !== "*" && I.origin !== p) {
217
218
  n(`${o} received message from origin ${I.origin} which did not match expected origin ${p}`);
218
219
  return;
219
220
  }
220
- const E = I.data;
221
+ const S = I.data;
221
222
  n(`${o}: Received ${h}() reply`), c.removeEventListener(v.Message, m);
222
- let D = E.returnValue;
223
- E.returnValueIsError && (D = ne(D)), (E.resolution === x.Fulfilled ? u : k)(D);
223
+ let P = S.returnValue;
224
+ S.returnValueIsError && (P = oe(P)), (S.resolution === x.Fulfilled ? u : k)(P);
224
225
  };
225
226
  c.addEventListener(v.Message, m);
226
227
  const C = {
@@ -232,11 +233,11 @@ const ie = () => ++se, Q = ".", T = (r) => r ? r.split(Q) : [], ce = (r) => r.jo
232
233
  s.postMessage(C, i);
233
234
  });
234
235
  }, f = t.reduce((h, _) => (h[_] = l(_), h), {});
235
- return Object.assign(r, pe(f)), () => {
236
+ return Object.assign(a, me(f)), () => {
236
237
  d = !0;
237
238
  };
238
- }, he = (r, e, t, a, n) => {
239
- const { destroy: o, onDestroy: c } = a;
239
+ }, fe = (a, e, t, r, n) => {
240
+ const { destroy: o, onDestroy: c } = r;
240
241
  let s, i;
241
242
  const p = {};
242
243
  return (d) => {
@@ -252,53 +253,53 @@ const ie = () => ++se, Q = ".", T = (r) => r ? r.split(Q) : [], ce = (r) => r.jo
252
253
  originForSending: t,
253
254
  originForReceiving: e
254
255
  };
255
- s && s(), s = oe(l, r, n), c(s), i && i.forEach((h) => {
256
+ s && s(), s = se(l, a, n), c(s), i && i.forEach((h) => {
256
257
  delete p[h];
257
258
  }), i = d.data.methodNames;
258
- const f = me(p, l, i, o, n);
259
+ const f = he(p, l, i, o, n);
259
260
  return c(f), p;
260
261
  };
261
- }, fe = (r, e, t, a) => (n) => {
262
+ }, ue = (a, e, t, r) => (n) => {
262
263
  if (!n.source)
263
264
  return;
264
265
  if (t !== "*" && n.origin !== t) {
265
- r(`Parent: Handshake - Received SYN message from origin ${n.origin} which did not match expected origin ${t}`);
266
+ a(`Parent: Handshake - Received SYN message from origin ${n.origin} which did not match expected origin ${t}`);
266
267
  return;
267
268
  }
268
- r("Parent: Handshake - Received SYN, responding with SYN-ACK");
269
+ a("Parent: Handshake - Received SYN, responding with SYN-ACK");
269
270
  const o = {
270
271
  penpal: y.SynAck,
271
272
  methodNames: Object.keys(e)
272
273
  };
273
- n.source.postMessage(o, a);
274
- }, ue = 6e4, ge = (r, e) => {
275
- const { destroy: t, onDestroy: a } = e, n = setInterval(() => {
276
- r.isConnected || (clearInterval(n), t());
277
- }, ue);
278
- a(() => {
274
+ n.source.postMessage(o, r);
275
+ }, ge = 6e4, ye = (a, e) => {
276
+ const { destroy: t, onDestroy: r } = e, n = setInterval(() => {
277
+ a.isConnected || (clearInterval(n), t());
278
+ }, ge);
279
+ r(() => {
279
280
  clearInterval(n);
280
281
  });
281
- }, ye = (r, e) => {
282
+ }, be = (a, e) => {
282
283
  let t;
283
- return r !== void 0 && (t = window.setTimeout(() => {
284
- const a = new Error(`Connection timed out after ${r}ms`);
285
- a.code = S.ConnectionTimeout, e(a);
286
- }, r)), () => {
284
+ return a !== void 0 && (t = window.setTimeout(() => {
285
+ const r = new Error(`Connection timed out after ${a}ms`);
286
+ r.code = E.ConnectionTimeout, e(r);
287
+ }, a)), () => {
287
288
  clearTimeout(t);
288
289
  };
289
- }, be = (r) => {
290
- if (!r.src && !r.srcdoc) {
290
+ }, _e = (a) => {
291
+ if (!a.src && !a.srcdoc) {
291
292
  const e = new Error("Iframe must have src or srcdoc property defined.");
292
- throw e.code = S.NoIframeSrc, e;
293
+ throw e.code = E.NoIframeSrc, e;
293
294
  }
294
- }, _e = (r) => {
295
- let { iframe: e, methods: t = {}, childOrigin: a, timeout: n, debug: o = !1 } = r;
296
- const c = Z(o), s = X("Parent", c), { onDestroy: i, destroy: p } = s;
297
- a || (be(e), a = re(e.src));
298
- const d = a === "null" ? "*" : a, l = z(t), f = fe(c, l, a, d), h = he(l, a, d, s, c);
295
+ }, we = (a) => {
296
+ let { iframe: e, methods: t = {}, childOrigin: r, timeout: n, debug: o = !1 } = a;
297
+ const c = ee(o), s = Z("Parent", c), { onDestroy: i, destroy: p } = s;
298
+ r || (_e(e), r = ne(e.src));
299
+ const d = r === "null" ? "*" : r, l = z(t), f = ue(c, l, r, d), h = fe(l, r, d, s, c);
299
300
  return {
300
301
  promise: new Promise((w, u) => {
301
- const k = ye(n, p), b = (m) => {
302
+ const k = be(n, p), b = (m) => {
302
303
  if (!(m.source !== e.contentWindow || !m.data)) {
303
304
  if (m.data.penpal === y.Syn) {
304
305
  f(m);
@@ -311,7 +312,7 @@ const ie = () => ++se, Q = ".", T = (r) => r ? r.split(Q) : [], ce = (r) => r.jo
311
312
  }
312
313
  }
313
314
  };
314
- window.addEventListener(v.Message, b), c("Parent: Awaiting handshake"), ge(e, s), i((m) => {
315
+ window.addEventListener(v.Message, b), c("Parent: Awaiting handshake"), ye(e, s), i((m) => {
315
316
  window.removeEventListener(v.Message, b), m && u(m);
316
317
  });
317
318
  }),
@@ -328,18 +329,18 @@ class F {
328
329
  constructor({
329
330
  id: e,
330
331
  url: t,
331
- preset: a,
332
+ preset: r,
332
333
  onClose: n,
333
334
  onConnect: o,
334
335
  methods: c = {}
335
336
  }) {
336
337
  if (typeof document > "u")
337
338
  return;
338
- a && t.searchParams.set("preset", a), this.url = t;
339
+ r && t.searchParams.set("preset", r), this.url = t;
339
340
  const s = document.createElement("iframe");
340
341
  s.src = t.toString(), s.id = e, s.style.border = "none", s.sandbox.add("allow-forms"), s.sandbox.add("allow-popups"), s.sandbox.add("allow-scripts"), s.sandbox.add("allow-same-origin"), s.allow = "publickey-credentials-create *; publickey-credentials-get *; clipboard-write", document.hasStorageAccess && s.sandbox.add("allow-storage-access-by-user-activation");
341
342
  const i = document.createElement("div");
342
- i.id = "controller", i.style.position = "fixed", i.style.height = "100%", i.style.width = "100%", i.style.top = "0", i.style.left = "0", i.style.zIndex = "10000", i.style.backgroundColor = "rgba(0,0,0,0.6)", i.style.display = "flex", i.style.alignItems = "center", i.style.justifyContent = "center", i.style.visibility = "hidden", i.style.opacity = "0", i.style.transition = "opacity 0.2s ease", i.appendChild(s), this.iframe = s, this.container = i, _e({
343
+ i.id = "controller", i.style.position = "fixed", i.style.height = "100%", i.style.width = "100%", i.style.top = "0", i.style.left = "0", i.style.zIndex = "10000", i.style.backgroundColor = "rgba(0,0,0,0.6)", i.style.display = "flex", i.style.alignItems = "center", i.style.justifyContent = "center", i.style.visibility = "hidden", i.style.opacity = "0", i.style.transition = "opacity 0.2s ease", i.appendChild(s), this.iframe = s, this.container = i, we({
343
344
  iframe: this.iframe,
344
345
  methods: { close: (l) => () => this.close(), ...c }
345
346
  }).promise.then(o), this.resize(), window.addEventListener("resize", () => this.resize());
@@ -376,7 +377,7 @@ class F {
376
377
  }
377
378
  }
378
379
  }
379
- class we {
380
+ class ve {
380
381
  type = "metamask";
381
382
  platform = "ethereum";
382
383
  MMSDK;
@@ -428,11 +429,11 @@ class we {
428
429
  const t = this.MMSDK.getProvider();
429
430
  if (!t)
430
431
  throw new Error("MetaMask is not connected");
431
- const a = await t.request({
432
+ const r = await t.request({
432
433
  method: "eth_sendTransaction",
433
434
  params: [e]
434
435
  });
435
- return { success: !0, wallet: this.type, result: a };
436
+ return { success: !0, wallet: this.type, result: r };
436
437
  } catch (t) {
437
438
  return console.error("Error signing transaction with MetaMask:", t), {
438
439
  success: !1,
@@ -464,11 +465,11 @@ class we {
464
465
  const t = this.MMSDK.getProvider();
465
466
  if (!t)
466
467
  throw new Error("MetaMask is not connected");
467
- const a = await t.request({
468
+ const r = await t.request({
468
469
  method: "eth_signTypedData_v4",
469
470
  params: [this.account, JSON.stringify(e)]
470
471
  });
471
- return { success: !0, wallet: this.type, result: a };
472
+ return { success: !0, wallet: this.type, result: r };
472
473
  } catch (t) {
473
474
  return console.error("Error signing typed data with MetaMask:", t), {
474
475
  success: !1,
@@ -477,6 +478,13 @@ class we {
477
478
  };
478
479
  }
479
480
  }
481
+ async sendTransaction(e) {
482
+ return {
483
+ success: !1,
484
+ wallet: this.type,
485
+ error: "Not implemented"
486
+ };
487
+ }
480
488
  async switchChain(e) {
481
489
  try {
482
490
  if (!this.isAvailable())
@@ -489,8 +497,8 @@ class we {
489
497
  method: "wallet_switchEthereumChain",
490
498
  params: [{ chainId: e }]
491
499
  }), !0;
492
- } catch (a) {
493
- throw a.code === 4902 && console.warn("Chain not added to MetaMask"), a;
500
+ } catch (r) {
501
+ throw r.code === 4902 && console.warn("Chain not added to MetaMask"), r;
494
502
  }
495
503
  } catch (t) {
496
504
  return console.error("Error switching chain for MetaMask:", t), !1;
@@ -510,11 +518,11 @@ class we {
510
518
  const t = this.MMSDK.getProvider();
511
519
  if (!t)
512
520
  throw new Error("MetaMask is not connected");
513
- const a = await t.request({
521
+ const r = await t.request({
514
522
  method: "eth_getBalance",
515
523
  params: [this.account, "latest"]
516
524
  });
517
- return { success: !0, wallet: this.type, result: a };
525
+ return { success: !0, wallet: this.type, result: r };
518
526
  }
519
527
  } catch (t) {
520
528
  return console.error("Error getting balance from MetaMask:", t), {
@@ -525,10 +533,18 @@ class we {
525
533
  }
526
534
  }
527
535
  }
528
- class ve {
536
+ class ke {
529
537
  type = "phantom";
530
538
  platform = "solana";
531
539
  account = void 0;
540
+ getProvider() {
541
+ if (typeof window > "u")
542
+ throw new Error("Not ready");
543
+ const e = window.solana;
544
+ if (!e?.isPhantom)
545
+ throw new Error("Phantom is not available");
546
+ return e;
547
+ }
532
548
  isAvailable() {
533
549
  return typeof window < "u" && !!window.solana?.isPhantom;
534
550
  }
@@ -548,7 +564,7 @@ class ve {
548
564
  try {
549
565
  if (!this.isAvailable())
550
566
  throw new Error("Phantom is not available");
551
- const e = await window.solana.connect();
567
+ const e = await this.getProvider().connect();
552
568
  if (e.publicKey)
553
569
  return this.account = e.publicKey.toString(), { success: !0, wallet: this.type, account: this.account };
554
570
  throw new Error("No accounts found");
@@ -560,28 +576,35 @@ class ve {
560
576
  };
561
577
  }
562
578
  }
563
- async signTransaction(e) {
579
+ async signMessage(e) {
564
580
  try {
565
581
  if (!this.isAvailable() || !this.account)
566
582
  throw new Error("Phantom is not connected");
567
- const t = await window.solana.signTransaction(e);
568
- return { success: !0, wallet: this.type, result: t };
583
+ const t = new TextEncoder().encode(e), r = await this.getProvider().signMessage(
584
+ t,
585
+ "utf8"
586
+ );
587
+ return { success: !0, wallet: this.type, result: r };
569
588
  } catch (t) {
570
- return console.error("Error signing transaction with Phantom:", t), {
589
+ return console.error("Error signing message with Phantom:", t), {
571
590
  success: !1,
572
591
  wallet: this.type,
573
592
  error: t.message || "Unknown error"
574
593
  };
575
594
  }
576
595
  }
577
- async signMessage(e) {
596
+ async sendTransaction(e) {
597
+ if (!this.isAvailable() || !this.account)
598
+ throw new Error("Phantom is not connected");
578
599
  try {
579
- if (!this.isAvailable() || !this.account)
580
- throw new Error("Phantom is not connected");
581
- const t = new TextEncoder().encode(e), a = await window.solana.signMessage(t, "utf8");
582
- return { success: !0, wallet: this.type, result: a };
600
+ const t = V.from(Buffer.from(e, "base64")), n = await this.getProvider().signAndSendTransaction(t);
601
+ return {
602
+ success: !0,
603
+ wallet: this.type,
604
+ result: n
605
+ };
583
606
  } catch (t) {
584
- return console.error("Error signing message with Phantom:", t), {
607
+ return console.error("Error sending transaction with Phantom:", t), {
585
608
  success: !1,
586
609
  wallet: this.type,
587
610
  error: t.message || "Unknown error"
@@ -609,7 +632,7 @@ class ve {
609
632
  }
610
633
  }
611
634
  }
612
- class ke {
635
+ class Ae {
613
636
  type = "argent";
614
637
  platform = "starknet";
615
638
  wallet = void 0;
@@ -634,8 +657,8 @@ class ke {
634
657
  try {
635
658
  if (!this.isAvailable())
636
659
  throw new Error("Argent is not available");
637
- const { wallet: e, connectorData: t } = await V({
638
- connectors: [new J({ options: { id: "argentX" } })]
660
+ const { wallet: e, connectorData: t } = await J({
661
+ connectors: [new X({ options: { id: "argentX" } })]
639
662
  });
640
663
  if (!e)
641
664
  throw new Error("No wallet found");
@@ -652,7 +675,6 @@ class ke {
652
675
  try {
653
676
  if (!this.isAvailable() || !this.wallet)
654
677
  throw new Error("Argent is not connected");
655
- console.log("signTypedData", e);
656
678
  const t = await this.wallet.request({
657
679
  type: "wallet_signTypedData",
658
680
  params: e
@@ -666,6 +688,13 @@ class ke {
666
688
  };
667
689
  }
668
690
  }
691
+ async sendTransaction(e) {
692
+ return {
693
+ success: !1,
694
+ wallet: this.type,
695
+ error: "Not implemented"
696
+ };
697
+ }
669
698
  async switchChain(e) {
670
699
  return console.warn(
671
700
  "Chain switching for Argent may require custom implementation"
@@ -689,19 +718,20 @@ class ke {
689
718
  }
690
719
  }
691
720
  }
692
- class Ae {
721
+ class xe {
693
722
  walletAdapters;
694
723
  connectedWallets = /* @__PURE__ */ new Map();
695
724
  constructor() {
696
- this.walletAdapters = /* @__PURE__ */ new Map(), this.walletAdapters.set("metamask", new we()), this.walletAdapters.set("phantom", new ve()), this.walletAdapters.set("argent", new ke()), typeof window < "u" && (window.wallet_bridge = this);
725
+ this.walletAdapters = /* @__PURE__ */ new Map(), this.walletAdapters.set("metamask", new ve()), this.walletAdapters.set("phantom", new ke()), this.walletAdapters.set("argent", new Ae()), typeof window < "u" && (window.wallet_bridge = this);
697
726
  }
698
727
  getIFrameMethods() {
699
728
  return {
700
729
  externalDetectWallets: (e) => () => this.detectWallets(),
701
730
  externalConnectWallet: (e) => (t) => this.connectWallet(t),
702
- externalSignMessage: (e) => (t, a) => this.signMessage(t, a),
703
- externalSignTypedData: (e) => (t, a) => this.signTypedData(t, a),
704
- externalGetBalance: (e) => (t, a) => this.getBalance(t, a)
731
+ externalSignMessage: (e) => (t, r) => this.signMessage(t, r),
732
+ externalSignTypedData: (e) => (t, r) => this.signTypedData(t, r),
733
+ externalSendTransaction: (e) => (t, r) => this.sendTransaction(t, r),
734
+ externalGetBalance: (e) => (t, r) => this.getBalance(t, r)
705
735
  };
706
736
  }
707
737
  async detectWallets() {
@@ -715,18 +745,14 @@ class Ae {
715
745
  throw new Error(`Unsupported wallet type: ${e}`);
716
746
  return t;
717
747
  }
718
- handleError(e, t, a) {
748
+ handleError(e, t, r) {
719
749
  const n = t instanceof Error ? t.message : "Unknown error";
720
- return console.error(`Error ${a} with ${e} wallet:`, t), { success: !1, wallet: e, error: n };
750
+ return console.error(`Error ${r} with ${e} wallet:`, t), { success: !1, wallet: e, error: n };
721
751
  }
722
752
  async connectWallet(e) {
723
753
  try {
724
- if (this.connectedWallets.has(e)) {
725
- const n = this.connectedWallets.get(e);
726
- return { success: !0, wallet: e, account: n.type };
727
- }
728
- const t = this.getWalletAdapter(e), a = await t.connect();
729
- return a.success && this.connectedWallets.set(e, t), a;
754
+ const t = this.getWalletAdapter(e), r = await t.connect();
755
+ return r.success && this.connectedWallets.set(e, t), r;
730
756
  } catch (t) {
731
757
  return this.handleError(e, t, "connecting to");
732
758
  }
@@ -735,24 +761,33 @@ class Ae {
735
761
  try {
736
762
  if (!this.connectedWallets.has(e))
737
763
  throw new Error(`Wallet ${e} is not connected`);
738
- const a = this.connectedWallets.get(e);
739
- if (!a.signMessage)
764
+ const r = this.connectedWallets.get(e);
765
+ if (!r.signMessage)
740
766
  throw new Error(`Wallet ${e} does not support signing messages`);
741
- return await a.signMessage(t);
742
- } catch (a) {
743
- return this.handleError(e, a, "signing message with");
767
+ return await r.signMessage(t);
768
+ } catch (r) {
769
+ return this.handleError(e, r, "signing message with");
744
770
  }
745
771
  }
746
772
  async signTypedData(e, t) {
747
773
  try {
748
774
  if (!this.connectedWallets.has(e))
749
775
  throw new Error(`Wallet ${e} is not connected`);
750
- const a = this.connectedWallets.get(e);
751
- if (!a.signTypedData)
776
+ const r = this.connectedWallets.get(e);
777
+ if (!r.signTypedData)
752
778
  throw new Error(`Wallet ${e} does not support signing typed data`);
753
- return await a.signTypedData(t);
754
- } catch (a) {
755
- return this.handleError(e, a, "signing typed data with");
779
+ return await r.signTypedData(t);
780
+ } catch (r) {
781
+ return this.handleError(e, r, "signing typed data with");
782
+ }
783
+ }
784
+ async sendTransaction(e, t) {
785
+ try {
786
+ if (!this.connectedWallets.has(e))
787
+ throw new Error(`Wallet ${e} is not connected`);
788
+ return await this.connectedWallets.get(e).sendTransaction(t);
789
+ } catch (r) {
790
+ return this.handleError(e, r, "sending transaction with");
756
791
  }
757
792
  }
758
793
  async getBalance(e, t) {
@@ -760,20 +795,20 @@ class Ae {
760
795
  if (!this.connectedWallets.has(e))
761
796
  throw new Error(`Wallet ${e} is not connected`);
762
797
  return await this.connectedWallets.get(e).getBalance(t);
763
- } catch (a) {
764
- return this.handleError(e, a, "getting balance from");
798
+ } catch (r) {
799
+ return this.handleError(e, r, "getting balance from");
765
800
  }
766
801
  }
767
802
  }
768
- class xe extends F {
803
+ class Ce extends F {
769
804
  walletBridge;
770
- constructor({ url: e, policies: t, ...a }) {
771
- const n = new URL(e ?? W), o = new Ae();
805
+ constructor({ url: e, policies: t, ...r }) {
806
+ const n = new URL(e ?? W), o = new xe();
772
807
  t && n.searchParams.set(
773
808
  "policies",
774
809
  encodeURIComponent(JSON.stringify(t))
775
810
  ), super({
776
- ...a,
811
+ ...r,
777
812
  id: "controller-keychain",
778
813
  url: n,
779
814
  methods: o.getIFrameMethods()
@@ -783,11 +818,11 @@ class xe extends F {
783
818
  return this.walletBridge;
784
819
  }
785
820
  }
786
- class Ce extends F {
821
+ class Ie extends F {
787
822
  constructor({
788
823
  profileUrl: e,
789
824
  rpcUrl: t,
790
- version: a,
825
+ version: r,
791
826
  username: n,
792
827
  slot: o,
793
828
  namespace: c,
@@ -799,7 +834,7 @@ class Ce extends F {
799
834
  let l = new URL(
800
835
  o ? `${d}/account/${n}/slot/${o}` : `${d}/account/${n}`
801
836
  );
802
- if (o && l.searchParams.set("ps", encodeURIComponent(o)), c && l.searchParams.set("ns", encodeURIComponent(c)), a && l.searchParams.set("v", encodeURIComponent(a)), l.searchParams.set("rpcUrl", encodeURIComponent(t)), s?.erc20 && l.searchParams.set(
837
+ if (o && l.searchParams.set("ps", encodeURIComponent(o)), c && l.searchParams.set("ns", encodeURIComponent(c)), r && l.searchParams.set("v", encodeURIComponent(r)), l.searchParams.set("rpcUrl", encodeURIComponent(t)), s?.erc20 && l.searchParams.set(
803
838
  "erc20",
804
839
  encodeURIComponent(s.erc20.toString())
805
840
  ), i?.contracts) {
@@ -818,7 +853,7 @@ class Ce extends F {
818
853
  });
819
854
  }
820
855
  }
821
- class Me extends j {
856
+ class Be extends j {
822
857
  keychain;
823
858
  profile;
824
859
  options;
@@ -827,7 +862,7 @@ class Me extends j {
827
862
  chains;
828
863
  constructor(e) {
829
864
  super(), this.selectedChain = e.defaultChainId, this.chains = /* @__PURE__ */ new Map(), this.iframes = {
830
- keychain: new xe({
865
+ keychain: new Ce({
831
866
  ...e,
832
867
  onClose: this.keychain?.reset,
833
868
  onConnect: (t) => {
@@ -858,7 +893,7 @@ class Me extends j {
858
893
  }
859
894
  if (!this.iframes.profile) {
860
895
  const e = await this.keychain.username();
861
- this.iframes.profile = new Ce({
896
+ this.iframes.profile = new Ie({
862
897
  ...this.options,
863
898
  onConnect: (t) => {
864
899
  this.profile = t;
@@ -973,7 +1008,7 @@ class Me extends j {
973
1008
  const e = this.chains.get(this.selectedChain);
974
1009
  if (!e) {
975
1010
  const t = Array.from(this.chains.keys()).map(
976
- (a) => M.decodeShortString(a)
1011
+ (r) => M.decodeShortString(r)
977
1012
  );
978
1013
  throw new Error(
979
1014
  `Chain not found: ${M.decodeShortString(this.selectedChain)}. Available chains: ${t.join(", ")}`
@@ -1008,10 +1043,10 @@ class Me extends j {
1008
1043
  console.error("Profile is not ready");
1009
1044
  return;
1010
1045
  }
1011
- let a = this.selectedChain;
1046
+ let r = this.selectedChain;
1012
1047
  t && this.switchStarknetChain(t), this.iframes.profile?.sendBackward(), this.iframes.keychain.open(), this.iframes.profile?.close();
1013
1048
  const n = await this.keychain.execute(e, void 0, void 0, !0);
1014
- return this.iframes.profile?.open(), this.iframes.keychain.close(), this.iframes.profile?.sendForward(), t && this.switchStarknetChain(a), !(n && (n.code === A.NOT_CONNECTED || n.code === A.CANCELED));
1049
+ return this.iframes.profile?.open(), this.iframes.keychain.close(), this.iframes.profile?.sendForward(), t && this.switchStarknetChain(r), !(n && (n.code === A.NOT_CONNECTED || n.code === A.CANCELED));
1015
1050
  }
1016
1051
  async delegateAccount() {
1017
1052
  return this.keychain ? await this.keychain.delegateAccount() : (console.error(new g().message), null);
@@ -1019,10 +1054,10 @@ class Me extends j {
1019
1054
  async validateChains(e) {
1020
1055
  for (const t of e)
1021
1056
  try {
1022
- const a = new URL(t.rpcUrl), n = await K(a);
1057
+ const r = new URL(t.rpcUrl), n = await K(r);
1023
1058
  this.chains.set(n, t);
1024
- } catch (a) {
1025
- console.error(`Failed to parse chainId for ${t.rpcUrl}:`, a);
1059
+ } catch (r) {
1060
+ console.error(`Failed to parse chainId for ${t.rpcUrl}:`, r);
1026
1061
  }
1027
1062
  this.chains.has(this.selectedChain) || console.warn(
1028
1063
  `Selected chain ${this.selectedChain} not found in configured chains. Available chains: ${Array.from(this.chains.keys()).join(", ")}`
@@ -1032,49 +1067,49 @@ class Me extends j {
1032
1067
  timeout: e = 5e4,
1033
1068
  interval: t = 100
1034
1069
  } = {}) {
1035
- return new Promise((a, n) => {
1070
+ return new Promise((r, n) => {
1036
1071
  const o = Date.now(), c = setInterval(() => {
1037
1072
  if (Date.now() - o > e) {
1038
1073
  clearInterval(c), n(new Error("Timeout waiting for keychain"));
1039
1074
  return;
1040
1075
  }
1041
- this.keychain && (clearInterval(c), a());
1076
+ this.keychain && (clearInterval(c), r());
1042
1077
  }, t);
1043
1078
  });
1044
1079
  }
1045
1080
  }
1046
1081
  const R = /* @__PURE__ */ new Map();
1047
- async function U(r) {
1048
- if (!r.addresses?.length && !r.usernames?.length)
1082
+ async function U(a) {
1083
+ if (!a.addresses?.length && !a.usernames?.length)
1049
1084
  return { results: [] };
1050
1085
  const e = await fetch(`${q}/lookup`, {
1051
1086
  method: "POST",
1052
1087
  headers: {
1053
1088
  "Content-Type": "application/json"
1054
1089
  },
1055
- body: JSON.stringify(r)
1090
+ body: JSON.stringify(a)
1056
1091
  });
1057
1092
  if (!e.ok)
1058
1093
  throw new Error(`HTTP error! status: ${e.status}`);
1059
1094
  return e.json();
1060
1095
  }
1061
- async function Ne(r) {
1062
- const e = r.filter((t) => !R.has(t));
1063
- return e.length > 0 && (await U({ usernames: e })).results.forEach((a) => {
1064
- R.set(a.username, a.addresses[0]);
1096
+ async function Te(a) {
1097
+ const e = a.filter((t) => !R.has(t));
1098
+ return e.length > 0 && (await U({ usernames: e })).results.forEach((r) => {
1099
+ R.set(r.username, r.addresses[0]);
1065
1100
  }), new Map(
1066
- r.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1101
+ a.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1067
1102
  );
1068
1103
  }
1069
- async function Be(r) {
1070
- r = r.map(Y.toHex);
1071
- const e = r.filter((t) => !R.has(t));
1104
+ async function Qe(a) {
1105
+ a = a.map(Y.toHex);
1106
+ const e = a.filter((t) => !R.has(t));
1072
1107
  return e.length > 0 && (await U({
1073
1108
  addresses: e
1074
- })).results.forEach((a) => {
1075
- R.set(a.addresses[0], a.username);
1109
+ })).results.forEach((r) => {
1110
+ R.set(r.addresses[0], r.username);
1076
1111
  }), new Map(
1077
- r.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1112
+ a.map((t) => [t, R.get(t)]).filter((t) => t[1] !== void 0)
1078
1113
  );
1079
1114
  }
1080
1115
  var L = {
@@ -2823,7 +2858,7 @@ var L = {
2823
2858
  name: "zKube"
2824
2859
  }
2825
2860
  }
2826
- }, Ie = [
2861
+ }, Re = [
2827
2862
  {
2828
2863
  name: "Wrapped BTC",
2829
2864
  symbol: "WBTC",
@@ -3369,25 +3404,25 @@ var L = {
3369
3404
  hidden: !0,
3370
3405
  logo_url: "https://imagedelivery.net/0xPAQaDtnQhBs8IzYRIlNg/6deef27f-df40-4248-4e1b-ed1d79a3f000/logo"
3371
3406
  }
3372
- ], Qe = L, Te = Ie, ze = L.cartridge.theme;
3407
+ ], ze = L, Fe = Re, Ue = L.cartridge.theme;
3373
3408
  export {
3374
- ke as ArgentWallet,
3375
- we as MetaMaskWallet,
3409
+ Ae as ArgentWallet,
3410
+ ve as MetaMaskWallet,
3376
3411
  g as NotReadyToConnect,
3377
- ve as PhantomWallet,
3412
+ ke as PhantomWallet,
3378
3413
  A as ResponseCodes,
3379
- Ae as WalletBridge,
3380
- Qe as controllerConfigs,
3381
- Me as default,
3382
- ze as defaultTheme,
3383
- Te as erc20Metadata,
3384
- Le as humanizeString,
3385
- Be as lookupAddresses,
3386
- Ne as lookupUsernames,
3387
- Oe as normalizeCalls,
3414
+ xe as WalletBridge,
3415
+ ze as controllerConfigs,
3416
+ Be as default,
3417
+ Ue as defaultTheme,
3418
+ Fe as erc20Metadata,
3419
+ Ye as humanizeString,
3420
+ Qe as lookupAddresses,
3421
+ Te as lookupUsernames,
3422
+ $e as normalizeCalls,
3388
3423
  K as parseChainId,
3389
3424
  $ as toArray,
3390
- Ye as toSessionPolicies,
3391
- $e as toWasmPolicies
3425
+ We as toSessionPolicies,
3426
+ He as toWasmPolicies
3392
3427
  };
3393
3428
  //# sourceMappingURL=index.js.map