@storm-trade/wallet-core 1.0.28 → 1.0.29
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/wallet-core.d.ts +3 -0
- package/dist/wallet-core.js +105 -80
- package/dist/wallet-core.js.map +1 -1
- package/dist/wallet-core.umd.cjs +1 -1
- package/dist/wallet-core.umd.cjs.map +1 -1
- package/package.json +1 -1
package/dist/wallet-core.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export declare class IframeAdapter {
|
|
|
60
60
|
private iframe?;
|
|
61
61
|
private state;
|
|
62
62
|
private readonly i18nInit?;
|
|
63
|
+
private iframeVersion?;
|
|
64
|
+
private iframeError?;
|
|
63
65
|
constructor(props: IframeAdapterProps);
|
|
64
66
|
private sendMessage;
|
|
65
67
|
private setupMessageListener;
|
|
@@ -78,6 +80,7 @@ export declare class IframeAdapter {
|
|
|
78
80
|
createTransfer(masterAddress: string, message: CreateTransferRequest): Promise<CreateTransferResponse>;
|
|
79
81
|
getActiveSessions(): Promise<ActiveSessionsResponse>;
|
|
80
82
|
disconnect(masterAddress: string): Promise<void>;
|
|
83
|
+
getIframeVersion(): string | undefined;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
export declare type IframeAdapterProps = {
|
package/dist/wallet-core.js
CHANGED
|
@@ -1,18 +1,35 @@
|
|
|
1
1
|
var M = Object.defineProperty;
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { beginCell as
|
|
5
|
-
const
|
|
6
|
-
class
|
|
2
|
+
var B = (n, e, t) => e in n ? M(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
|
+
var c = (n, e, t) => B(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { beginCell as b, Address as h, Dictionary as d, toNano as g, Cell as C, contractAddress as I } from "@ton/ton";
|
|
5
|
+
const y = "1.0.29", o = `[embedded-wallet v${y}]`;
|
|
6
|
+
class k {
|
|
7
7
|
constructor(e) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
c(this, "host");
|
|
9
|
+
c(this, "timeouts");
|
|
10
|
+
c(this, "waitingForResponse", /* @__PURE__ */ new Map());
|
|
11
|
+
c(this, "iframe");
|
|
12
|
+
c(this, "state", "not-ready");
|
|
13
|
+
c(this, "i18nInit");
|
|
14
|
+
c(this, "iframeVersion");
|
|
15
|
+
c(this, "iframeError");
|
|
16
|
+
c(this, "handleMessage", (e) => {
|
|
17
|
+
if (typeof e.data != "object" || e.data === null)
|
|
18
|
+
return;
|
|
19
|
+
if ("type" in e.data && e.data.type === "iframe-ready") {
|
|
20
|
+
const a = e.data;
|
|
21
|
+
if (this.iframeVersion = a.version, console.log(o, `iframe ready, version: ${a.version}`), a.version) {
|
|
22
|
+
const i = a.version.split(".")[0], f = y.split(".")[0];
|
|
23
|
+
i !== f && console.warn(o, `Version mismatch: wallet-core=${y}, iframe-host=${a.version}`);
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if ("type" in e.data && e.data.type === "iframe-error") {
|
|
28
|
+
const a = e.data;
|
|
29
|
+
console.error(o, "iframe error:", a.error, a.stack), this.iframeError = new Error(a.error || "Unknown iframe error");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!("id" in e.data) || !("status" in e.data) || typeof e.data.id != "string" || typeof e.data.status != "string")
|
|
16
33
|
return;
|
|
17
34
|
const t = this.waitingForResponse.get(e.data.id);
|
|
18
35
|
if (!t)
|
|
@@ -33,18 +50,18 @@ class F {
|
|
|
33
50
|
}, this.i18nInit = e.i18n;
|
|
34
51
|
}
|
|
35
52
|
async sendMessage(e, t) {
|
|
36
|
-
var
|
|
53
|
+
var a, i;
|
|
37
54
|
const s = Math.random().toString(), r = Promise.race([
|
|
38
|
-
new Promise((f,
|
|
39
|
-
this.waitingForResponse.set(s, [f,
|
|
55
|
+
new Promise((f, u) => {
|
|
56
|
+
this.waitingForResponse.set(s, [f, u]);
|
|
40
57
|
}),
|
|
41
|
-
new Promise((f,
|
|
58
|
+
new Promise((f, u) => {
|
|
42
59
|
setTimeout(() => {
|
|
43
|
-
|
|
60
|
+
u(new Error("Response timeout"));
|
|
44
61
|
}, t);
|
|
45
62
|
})
|
|
46
63
|
]);
|
|
47
|
-
return (
|
|
64
|
+
return (i = (a = this.iframe) == null ? void 0 : a.contentWindow) == null || i.postMessage({ id: s, payload: e }, this.host), r;
|
|
48
65
|
}
|
|
49
66
|
setupMessageListener() {
|
|
50
67
|
window.addEventListener("message", this.handleMessage);
|
|
@@ -52,10 +69,10 @@ class F {
|
|
|
52
69
|
async attachIframe(e) {
|
|
53
70
|
const t = document.createElement("iframe");
|
|
54
71
|
t.src = this.host, t.frameBorder = "0", t.width = "100%", t.height = "100%";
|
|
55
|
-
const s = new Promise((
|
|
56
|
-
t.addEventListener("load", () =>
|
|
57
|
-
}), r = new Promise((
|
|
58
|
-
setTimeout(() =>
|
|
72
|
+
const s = new Promise((a, i) => {
|
|
73
|
+
t.addEventListener("load", () => a(), { once: !0 }), t.addEventListener("error", (f) => i(f), { once: !0 });
|
|
74
|
+
}), r = new Promise((a, i) => {
|
|
75
|
+
setTimeout(() => i(new Error("Iframe load timeout")), this.timeouts.init);
|
|
59
76
|
});
|
|
60
77
|
return e.appendChild(t), this.iframe = t, Promise.race([s, r]);
|
|
61
78
|
}
|
|
@@ -63,18 +80,23 @@ class F {
|
|
|
63
80
|
if (this.state === "not-ready") {
|
|
64
81
|
this.state = "initializing";
|
|
65
82
|
try {
|
|
66
|
-
console.log(
|
|
83
|
+
this.setupMessageListener(), console.log(o, "attaching to root", e);
|
|
67
84
|
const t = performance.now();
|
|
68
|
-
await this.attachIframe(e), console.log(
|
|
85
|
+
if (await this.attachIframe(e), console.log(o, `iframe attached in ${Math.round(performance.now() - t)}ms`), this.iframeError)
|
|
86
|
+
throw this.iframeError;
|
|
87
|
+
console.log(o, "sending ping");
|
|
69
88
|
let s;
|
|
70
|
-
for (let r = 1; r <= 5; r++)
|
|
89
|
+
for (let r = 1; r <= 5; r++) {
|
|
90
|
+
if (this.iframeError)
|
|
91
|
+
throw this.iframeError;
|
|
71
92
|
try {
|
|
72
|
-
await this.sendMessage({ type: "ping", i18n: this.i18nInit }, this.timeouts.init), console.log(
|
|
93
|
+
await this.sendMessage({ type: "ping", i18n: this.i18nInit }, this.timeouts.init), console.log(o, "pong received"), this.state = "ready";
|
|
73
94
|
return;
|
|
74
|
-
} catch (
|
|
75
|
-
s =
|
|
95
|
+
} catch (a) {
|
|
96
|
+
s = a instanceof Error ? a : new Error(String(a)), console.warn(o, `ping attempt ${r}/5 failed:`, s.message), r < 5 && await new Promise((i) => setTimeout(i, 200));
|
|
76
97
|
}
|
|
77
|
-
|
|
98
|
+
}
|
|
99
|
+
throw new Error(`${o} ping retries exceeded: ${s == null ? void 0 : s.message}`);
|
|
78
100
|
} catch (t) {
|
|
79
101
|
throw this.destroy(), t;
|
|
80
102
|
}
|
|
@@ -117,51 +139,54 @@ class F {
|
|
|
117
139
|
async disconnect(e) {
|
|
118
140
|
return this.sendMessage({ type: "disconnect", address: e }, this.timeouts.disconnect);
|
|
119
141
|
}
|
|
142
|
+
getIframeVersion() {
|
|
143
|
+
return this.iframeVersion;
|
|
144
|
+
}
|
|
120
145
|
}
|
|
121
|
-
const P = (n) => n.loadBuffer(32), R = (n) =>
|
|
146
|
+
const P = (n) => n.loadBuffer(32), R = (n) => b().storeBuffer(n, 32).endCell(), T = {
|
|
122
147
|
serialize: (n, e) => {
|
|
123
148
|
e.storeBuilder(R(n).asBuilder());
|
|
124
149
|
},
|
|
125
150
|
parse: (n) => P(n)
|
|
126
|
-
},
|
|
127
|
-
function
|
|
128
|
-
const s =
|
|
129
|
-
return
|
|
151
|
+
}, U = "b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f", _ = 0;
|
|
152
|
+
function x(n, e, t) {
|
|
153
|
+
const s = C.fromHex(t), r = b().storeUint(_, 8).storeAddress(e).storeAddress(n).storeDict(null).endCell();
|
|
154
|
+
return I(0, { code: s, data: r });
|
|
130
155
|
}
|
|
131
|
-
class
|
|
132
|
-
constructor(e, t, s =
|
|
156
|
+
class F {
|
|
157
|
+
constructor(e, t, s = U) {
|
|
133
158
|
this.tonClient = e, this.config = t, this.ordinarySmartAccountCode = s;
|
|
134
159
|
}
|
|
135
160
|
calculateSmartAccountAddressFromStateInit(e) {
|
|
136
|
-
return
|
|
161
|
+
return x(e, h.parse(this.config.smartAccountMasterAddress), this.ordinarySmartAccountCode);
|
|
137
162
|
}
|
|
138
163
|
async getSmartAccountAddress(e) {
|
|
139
|
-
return (await this.tonClient.runMethod(
|
|
164
|
+
return (await this.tonClient.runMethod(h.parse(this.config.smartAccountMasterAddress), "get_nft_address_by_index", [
|
|
140
165
|
{
|
|
141
166
|
type: "int",
|
|
142
|
-
value: BigInt(`0x${
|
|
167
|
+
value: BigInt(`0x${h.parse(e).hash.toString("hex")}`)
|
|
143
168
|
}
|
|
144
169
|
])).stack.readAddress();
|
|
145
170
|
}
|
|
146
171
|
async getSmartAccountData(e) {
|
|
147
|
-
const t =
|
|
172
|
+
const t = h.parse(e);
|
|
148
173
|
try {
|
|
149
|
-
const r = (await this.tonClient.runMethod(t, "get_storage_data")).stack,
|
|
150
|
-
let
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
174
|
+
const r = (await this.tonClient.runMethod(t, "get_storage_data")).stack, a = r.readBigNumber(), i = r.readAddress(), f = r.readAddress(), u = r.readCellOpt();
|
|
175
|
+
let w = [];
|
|
176
|
+
u && (w = d.loadDirect(d.Keys.BigUint(256), d.Values.Cell(), u).keys());
|
|
177
|
+
const v = r.readAddress(), E = d.loadDirect(
|
|
178
|
+
d.Keys.Uint(8),
|
|
154
179
|
T,
|
|
155
180
|
r.readCell()
|
|
156
|
-
).values(),
|
|
181
|
+
).values(), S = r.readNumber();
|
|
157
182
|
return {
|
|
158
|
-
index:
|
|
159
|
-
collectionAddress:
|
|
183
|
+
index: a,
|
|
184
|
+
collectionAddress: i,
|
|
160
185
|
masterWalletAddress: f,
|
|
161
|
-
publicKeys:
|
|
162
|
-
adminAddress:
|
|
163
|
-
backendPublicKeys:
|
|
164
|
-
seqno:
|
|
186
|
+
publicKeys: w,
|
|
187
|
+
adminAddress: v,
|
|
188
|
+
backendPublicKeys: E,
|
|
189
|
+
seqno: S
|
|
165
190
|
};
|
|
166
191
|
} catch (s) {
|
|
167
192
|
if (s.message.endsWith("-13"))
|
|
@@ -170,9 +195,9 @@ class O {
|
|
|
170
195
|
}
|
|
171
196
|
}
|
|
172
197
|
createDeploySmartAccountTx(e, t) {
|
|
173
|
-
const s =
|
|
174
|
-
s.set(
|
|
175
|
-
const r =
|
|
198
|
+
const s = d.empty(d.Keys.BigUint(256), d.Values.Cell());
|
|
199
|
+
s.set(N(e), b().endCell());
|
|
200
|
+
const r = b().storeUint(1983912421, 32).storeUint(0, 64).storeDict(s).endCell();
|
|
176
201
|
return {
|
|
177
202
|
address: this.config.smartAccountMasterAddress,
|
|
178
203
|
payload: r.toBoc().toString("base64"),
|
|
@@ -180,7 +205,7 @@ class O {
|
|
|
180
205
|
};
|
|
181
206
|
}
|
|
182
207
|
createAddPublicKeyTx(e, t) {
|
|
183
|
-
const s =
|
|
208
|
+
const s = b().storeUint(571231257, 32).storeUint(0, 64).storeBuffer(t).endCell();
|
|
184
209
|
return {
|
|
185
210
|
address: e,
|
|
186
211
|
payload: s.toBoc().toString("base64"),
|
|
@@ -188,7 +213,7 @@ class O {
|
|
|
188
213
|
};
|
|
189
214
|
}
|
|
190
215
|
createRemovePublicKeyTx(e, t) {
|
|
191
|
-
const s =
|
|
216
|
+
const s = b().storeUint(1948765727, 32).storeUint(0, 64).storeBuffer(t).endCell();
|
|
192
217
|
return {
|
|
193
218
|
address: e,
|
|
194
219
|
payload: s.toBoc().toString("base64"),
|
|
@@ -196,7 +221,7 @@ class O {
|
|
|
196
221
|
};
|
|
197
222
|
}
|
|
198
223
|
createRemoveAllKeysExceptCurrentTx(e, t) {
|
|
199
|
-
const s =
|
|
224
|
+
const s = b().storeUint(1604127040, 32).storeUint(0, 64).storeBuffer(t).endCell();
|
|
200
225
|
return {
|
|
201
226
|
address: e,
|
|
202
227
|
payload: s.toBoc().toString("base64"),
|
|
@@ -205,36 +230,36 @@ class O {
|
|
|
205
230
|
};
|
|
206
231
|
}
|
|
207
232
|
}
|
|
208
|
-
function
|
|
233
|
+
function N(n) {
|
|
209
234
|
return BigInt("0x" + n.toString("hex"));
|
|
210
235
|
}
|
|
211
|
-
const
|
|
212
|
-
class
|
|
236
|
+
const A = 10n, l = 1022n, m = 8191n;
|
|
237
|
+
class p {
|
|
213
238
|
// [0 .. 1022]
|
|
214
239
|
constructor() {
|
|
215
|
-
|
|
240
|
+
c(this, "shift");
|
|
216
241
|
// [0 .. 8191]
|
|
217
|
-
|
|
242
|
+
c(this, "bitnumber");
|
|
218
243
|
this.shift = 0n, this.bitnumber = 0n;
|
|
219
244
|
}
|
|
220
245
|
static fromShiftAndBitNumber(e, t) {
|
|
221
|
-
const s = new
|
|
246
|
+
const s = new p();
|
|
222
247
|
if (s.shift = e, s.shift < 0) throw new Error("invalid shift");
|
|
223
248
|
if (s.shift > m) throw new Error("invalid shift");
|
|
224
249
|
if (s.bitnumber = t, s.bitnumber < 0) throw new Error("invalid bitnumber");
|
|
225
|
-
if (s.bitnumber >
|
|
250
|
+
if (s.bitnumber > l) throw new Error("invalid bitnumber");
|
|
226
251
|
return s;
|
|
227
252
|
}
|
|
228
253
|
getNext() {
|
|
229
254
|
let e = this.bitnumber + 1n, t = this.shift;
|
|
230
|
-
if (t === m && e >
|
|
255
|
+
if (t === m && e > l - 1n)
|
|
231
256
|
throw new Error("Overload");
|
|
232
|
-
if (e >
|
|
257
|
+
if (e > l && (e = 0n, t += 1n, t > m))
|
|
233
258
|
throw new Error("Overload");
|
|
234
|
-
return
|
|
259
|
+
return p.fromShiftAndBitNumber(t, e);
|
|
235
260
|
}
|
|
236
261
|
hasNext() {
|
|
237
|
-
return !(this.bitnumber >=
|
|
262
|
+
return !(this.bitnumber >= l - 1n && this.shift === m);
|
|
238
263
|
}
|
|
239
264
|
getShift() {
|
|
240
265
|
return this.shift;
|
|
@@ -243,10 +268,10 @@ class y {
|
|
|
243
268
|
return this.bitnumber;
|
|
244
269
|
}
|
|
245
270
|
getQueryId() {
|
|
246
|
-
return (this.shift <<
|
|
271
|
+
return (this.shift << A) + this.bitnumber;
|
|
247
272
|
}
|
|
248
273
|
static fromQueryId(e) {
|
|
249
|
-
const t = e >>
|
|
274
|
+
const t = e >> A, s = e & 1023n;
|
|
250
275
|
return this.fromShiftAndBitNumber(t, s);
|
|
251
276
|
}
|
|
252
277
|
static fromSeqno(e) {
|
|
@@ -260,17 +285,17 @@ class y {
|
|
|
260
285
|
return this.bitnumber + this.shift * 1023n;
|
|
261
286
|
}
|
|
262
287
|
}
|
|
263
|
-
function
|
|
288
|
+
function O() {
|
|
264
289
|
const n = Math.floor(Date.now() / 1e3) - 30;
|
|
265
290
|
return BigInt(n % (1 << 23));
|
|
266
291
|
}
|
|
267
|
-
const
|
|
292
|
+
const V = new Error("Session is expired or never provided");
|
|
268
293
|
export {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
294
|
+
p as HighloadQueryId,
|
|
295
|
+
k as IframeAdapter,
|
|
296
|
+
V as SessionExpiredOrNotProvided,
|
|
297
|
+
F as StormWallet,
|
|
298
|
+
x as calculateSmartAccountAddressFromStateInit,
|
|
299
|
+
O as queryId
|
|
275
300
|
};
|
|
276
301
|
//# sourceMappingURL=wallet-core.js.map
|
package/dist/wallet-core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-core.js","sources":["../src/version.ts","../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.ts","../src/utils/query-id.ts","../src/error.ts"],"sourcesContent":["declare const __VERSION__: string;\n\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'dev';\n","import {\n ActiveSessionsResponse,\n AdapterState,\n ConnectResponse,\n CreateTransferRequest,\n CreateTransferResponse,\n EmptyResponse,\n GetPublicKeyResponse,\n IframeAdapterProps,\n SignRequest,\n SignResponse,\n Timeouts,\n} from '../types';\nimport { VERSION } from '../version';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\n\nconst LOG_PREFIX = `[embedded-wallet v${VERSION}]`;\n\nexport class IframeAdapter {\n private readonly host: string;\n private readonly timeouts: Required<Timeouts>;\n private readonly waitingForResponse = new Map<string, Waiter>();\n private iframe?: HTMLIFrameElement;\n private state: AdapterState = 'not-ready';\n private readonly i18nInit?: IframeAdapterProps['i18n'];\n\n constructor(props: IframeAdapterProps) {\n this.host = props.host;\n this.timeouts = {\n init: 1000,\n connect: 60000,\n disconnect: 1000,\n sign: 1000,\n createTransfer: 1000,\n activeSessions: 1000,\n getPublicKey: 1000,\n resetDevice: 1000,\n ...props.timeouts,\n };\n this.i18nInit = props.i18n;\n }\n\n private async sendMessage<R>(payload: unknown, timeout: number): Promise<R> {\n const messageId = Math.random().toString();\n const response = Promise.race([\n new Promise<R>((resolve, reject) => {\n this.waitingForResponse.set(messageId, [resolve, reject]);\n }),\n new Promise<R>((_, reject) => {\n setTimeout(() => {\n reject(new Error('Response timeout'));\n }, timeout);\n }),\n ]);\n this.iframe?.contentWindow?.postMessage({ id: messageId, payload }, this.host);\n return response;\n }\n\n private setupMessageListener() {\n window.addEventListener('message', this.handleMessage);\n }\n\n private handleMessage = (e: MessageEvent<unknown>) => {\n if (typeof e.data !== 'object' || e.data === null) {\n return;\n }\n if (!('id' in e.data) || !('status' in e.data)) {\n return;\n }\n if (typeof e.data.id !== 'string' || typeof e.data.status !== 'string') {\n return;\n }\n const waiter = this.waitingForResponse.get(e.data.id);\n if (!waiter) {\n return;\n }\n const [resolve, reject] = waiter;\n this.waitingForResponse.delete(e.data.id);\n if (e.data.status === 'success') {\n if ('payload' in e.data) {\n resolve(e.data.payload);\n } else {\n resolve(undefined);\n }\n } else {\n if ('error' in e.data) {\n reject(new Error(e.data.error as string));\n } else {\n reject(new Error('Unknown error'));\n }\n }\n\n };\n\n private async attachIframe(root: HTMLElement): Promise<void> {\n const iframe = document.createElement('iframe');\n iframe.src = this.host;\n iframe.frameBorder = '0';\n iframe.width = '100%';\n iframe.height = '100%';\n\n const loadPromise = new Promise<void>((resolve, reject) => {\n iframe.addEventListener('load', () => resolve(), { once: true });\n iframe.addEventListener('error', (e) => reject(e), { once: true });\n });\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => reject(new Error('Iframe load timeout')), this.timeouts.init);\n });\n\n root.appendChild(iframe);\n this.iframe = iframe;\n return Promise.race([loadPromise, timeoutPromise]);\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state !== 'not-ready') {\n return;\n }\n\n this.state = 'initializing';\n\n try {\n console.log(LOG_PREFIX, 'attaching to root', root);\n const attachStart = performance.now();\n await this.attachIframe(root);\n console.log(LOG_PREFIX, `iframe attached in ${Math.round(performance.now() - attachStart)}ms`);\n this.setupMessageListener();\n console.log(LOG_PREFIX, 'sending ping');\n\n let lastError: Error | undefined;\n for (let attempt = 1; attempt <= 5; attempt++) {\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n console.log(LOG_PREFIX, 'pong received');\n this.state = 'ready';\n return;\n } catch (e) {\n lastError = e instanceof Error ? e : new Error(String(e));\n console.warn(LOG_PREFIX, `ping attempt ${attempt}/5 failed:`, lastError.message);\n if (attempt < 5) {\n await new Promise(resolve => setTimeout(resolve, 200));\n }\n }\n }\n\n throw new Error(`${LOG_PREFIX} ping retries exceeded: ${lastError?.message}`);\n } catch (e) {\n this.destroy();\n throw e;\n }\n }\n\n destroy(): void {\n if (this.state === 'not-ready') {\n return;\n }\n\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n\n for (const [, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n\n this.iframe?.remove();\n this.iframe = undefined;\n }\n\n async connect(masterAddress: string): Promise<ConnectResponse> {\n return this.sendMessage({ type: 'connect', address: masterAddress }, this.timeouts.connect);\n }\n\n\n\n async getPublicKey(address: string): Promise<GetPublicKeyResponse> {\n return this.sendMessage({ type: \"get-public-key\", address }, this.timeouts.getPublicKey);\n }\n\n async resetDevice(address: string): Promise<EmptyResponse> {\n return this.sendMessage({ type: \"reset-device\", address }, this.timeouts.resetDevice);\n }\n\n async signMessage(masterAddress: string, message: SignRequest): Promise<SignResponse> {\n return this.sendMessage({ type: 'sign', address: masterAddress, message }, this.timeouts.sign);\n }\n\n async signMessages(masterAddress: string, messages: SignRequest[]): Promise<{ hashes: Uint8Array[]; signatures: Uint8Array[]; }> {\n return this.sendMessage({ type: 'sign-many', address: masterAddress, messages }, this.timeouts.sign);\n }\n\n async createTransfer(masterAddress: string, message: CreateTransferRequest): Promise<CreateTransferResponse> {\n return this.sendMessage({\n type: 'create-transfer',\n address: masterAddress,\n data: message,\n }, this.timeouts.createTransfer);\n }\n\n async getActiveSessions(): Promise<ActiveSessionsResponse> {\n return this.sendMessage({ type: 'active-sessions' }, this.timeouts.activeSessions);\n }\n\n async disconnect(masterAddress: string): Promise<void> {\n return this.sendMessage({ type: 'disconnect', address: masterAddress }, this.timeouts.disconnect);\n }\n}\n","import { beginCell, Cell, DictionaryValue, Slice } from \"@ton/ton\";\n\nexport const unpackPublicKeys = (cs: Slice): Buffer => {\n return cs.loadBuffer(32);\n}\n\nexport const packPublicKeys = (publicKeys: Buffer): Cell => {\n return beginCell().storeBuffer(publicKeys, 32).endCell();\n}\n\nexport const PublicKeysValue: DictionaryValue<Buffer> = {\n serialize: (src: Buffer, builder) => {\n builder.storeBuilder(packPublicKeys(src).asBuilder());\n },\n parse: (src) => {\n return unpackPublicKeys(src);\n },\n};\n","import { Address, beginCell, Cell, contractAddress, Dictionary, toNano, TonClient } from \"@ton/ton\";\nimport { PublicKeysValue } from \"./utils/packers\";\n\ntype StormWalletConfig = {\n smartAccountMasterAddress: string;\n}\n\nexport enum SmartAccountInternalOp {\n deploy_account = 0x764019e5,\n add_new_user_public_key = 0x220c4c19,\n remove_user_public_key = 0x7427ce1f,\n execute_limit_order = 0x1c0af2cb,\n execute_orders_bundle = 0xf38e7e65,\n set_code = 0x9c0f3220,\n add_request_to_add_new_user_public_key = 0x03cc29e8,\n add_request_to_remove_user_public_key = 0x07d25def,\n remove_all_keys_except_current = 0x5f9d0940\n}\n\nexport const DEFAULT_ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f\"\nconst ORDINARY_SMART_ACCOUNT_HEADER = 0;\n\nexport function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address, ordinarySmartAccountCode: string): Address {\n const code = Cell.fromHex(ordinarySmartAccountCode);\n\n const data = beginCell()\n .storeUint(ORDINARY_SMART_ACCOUNT_HEADER, 8)\n .storeAddress(factory)\n .storeAddress(owner)\n .storeDict(null)\n .endCell()\n\n return contractAddress(0, {code, data});\n}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig, private readonly ordinarySmartAccountCode = DEFAULT_ORDINARY_SMART_ACCOUNT_CODE) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address): Address {\n return calculateSmartAccountAddressFromStateInit(owner, Address.parse(this.config.smartAccountMasterAddress), this.ordinarySmartAccountCode);\n }\n\n async getSmartAccountAddress(walletAddress: string): Promise<Address> {\n const result = await this.tonClient.runMethod(Address.parse(this.config.smartAccountMasterAddress), 'get_nft_address_by_index', [\n {\n type: 'int',\n value: BigInt(`0x${Address.parse(walletAddress).hash.toString('hex')}`)\n }\n ])\n return result.stack.readAddress()\n }\n\n async getSmartAccountData(smartAccountAddress: string) {\n const address = Address.parse(smartAccountAddress)\n try {\n const result = await this.tonClient.runMethod(address, 'get_storage_data')\n const stack = result.stack\n\n const index = stack.readBigNumber();\n const collectionAddress = stack.readAddress();\n const masterWalletAddress = stack.readAddress();\n\n\n const pksCell = stack.readCellOpt()\n let publicKeys: bigint[] = []\n\n if (pksCell) {\n publicKeys = Dictionary.loadDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell(), pksCell).keys();\n }\n\n const adminAddress = stack.readAddress();\n const backendPublicKeys = Dictionary.loadDirect(\n Dictionary.Keys.Uint(8),\n PublicKeysValue,\n stack.readCell()\n ).values();\n\n const seqno = stack.readNumber();\n\n return {\n index,\n collectionAddress,\n masterWalletAddress,\n publicKeys,\n adminAddress,\n backendPublicKeys,\n seqno,\n }\n } catch (e) {\n if ((e as Error).message.endsWith('-13')) {\n return null\n }\n throw e\n }\n }\n\n createDeploySmartAccountTx(publicKey: Buffer, transferAmount: bigint) {\n const publicKeys: Dictionary<bigint, Cell> = Dictionary.empty(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell());\n publicKeys.set(bufferToBigInt(publicKey), beginCell().endCell());\n\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.deploy_account, 32)\n .storeUint(0, 64)\n .storeDict(publicKeys)\n .endCell();\n\n return {\n address: this.config.smartAccountMasterAddress,\n payload: payload.toBoc().toString('base64'),\n amount: transferAmount,\n }\n }\n\n createAddPublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.add_new_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemovePublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemoveAllKeysExceptCurrentTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_all_keys_except_current, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05'), // при необходимости настрой сумму\n }\n }\n}\n\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n","const BIT_NUMBER_SIZE = 10n; // 10 bit\n// const SHIFT_SIZE = 13n; // 13 bit\nconst MAX_BIT_NUMBER = 1022n;\nconst MAX_SHIFT = 8191n; // 2^13 = 8192\n\nexport class HighloadQueryId {\n private shift: bigint; // [0 .. 8191]\n private bitnumber: bigint; // [0 .. 1022]\n\n constructor() {\n this.shift = 0n;\n this.bitnumber = 0n;\n }\n\n static fromShiftAndBitNumber(shift: bigint, bitnumber: bigint): HighloadQueryId {\n const q = new HighloadQueryId();\n q.shift = shift;\n if (q.shift < 0) throw new Error('invalid shift');\n if (q.shift > MAX_SHIFT) throw new Error('invalid shift');\n q.bitnumber = bitnumber;\n if (q.bitnumber < 0) throw new Error('invalid bitnumber');\n if (q.bitnumber > MAX_BIT_NUMBER) throw new Error('invalid bitnumber');\n return q;\n }\n\n\n getNext() {\n let newBitnumber = this.bitnumber + 1n;\n let newShift = this.shift;\n\n if (newShift === MAX_SHIFT && newBitnumber > (MAX_BIT_NUMBER - 1n)) {\n throw new Error('Overload'); // NOTE: we left one queryId for emergency withdraw\n }\n\n if (newBitnumber > MAX_BIT_NUMBER) {\n newBitnumber = 0n;\n newShift += 1n;\n if (newShift > MAX_SHIFT) {\n throw new Error('Overload')\n }\n }\n\n return HighloadQueryId.fromShiftAndBitNumber(newShift, newBitnumber);\n }\n\n hasNext() {\n const isEnd = this.bitnumber >= (MAX_BIT_NUMBER - 1n) && this.shift === MAX_SHIFT; // NOTE: we left one queryId for emergency withdraw;\n return !isEnd;\n }\n\n getShift(): bigint {\n return this.shift;\n }\n\n getBitNumber(): bigint {\n return this.bitnumber;\n }\n\n getQueryId(): bigint {\n return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;\n }\n\n static fromQueryId(queryId: bigint): HighloadQueryId {\n const shift = queryId >> BIT_NUMBER_SIZE;\n const bitnumber = queryId & 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n static fromSeqno(i: bigint): HighloadQueryId {\n const shift = i / 1023n;\n const bitnumber = i % 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n /**\n * @return {bigint} [0 .. 8380415]\n */\n toSeqno(): bigint {\n return this.bitnumber + this.shift * 1023n;\n }\n}\n\nexport function queryId(): bigint {\n const ts = Math.floor(Date.now() / 1000) - 30;\n\n return BigInt(ts % (1 << 23))\n}","export class NoActiveSessionError extends Error {\n public readonly address: string;\n\n constructor(address: string) {\n super(`No active session found for ${address}`);\n this.name = 'NoActiveSessionError';\n this.address = address;\n }\n}\n\n\nexport const SessionExpiredOrNotProvided = new Error('Session is expired or never provided')"],"names":["VERSION","LOG_PREFIX","IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","iframe","loadPromise","e","timeoutPromise","attachStart","lastError","attempt","masterAddress","address","message","messages","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","DEFAULT_ORDINARY_SMART_ACCOUNT_CODE","ORDINARY_SMART_ACCOUNT_HEADER","calculateSmartAccountAddressFromStateInit","owner","factory","ordinarySmartAccountCode","code","Cell","data","contractAddress","StormWallet","tonClient","config","Address","walletAddress","smartAccountAddress","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer","BIT_NUMBER_SIZE","MAX_BIT_NUMBER","MAX_SHIFT","HighloadQueryId","shift","bitnumber","q","newBitnumber","newShift","queryId","i","ts","SessionExpiredOrNotProvided"],"mappings":";;;;AAEa,MAAAA,IAA+C,UCetDC,IAAa,qBAAqBD,CAAO;AAExC,MAAME,EAAc;AAAA,EAQzB,YAAYC,GAA2B;AAPtB,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA,gDAAyB,IAAoB;AACtD,IAAAA,EAAA;AACA,IAAAA,EAAA,eAAsB;AACb,IAAAA,EAAA;AAsCT,IAAAA,EAAA,uBAAgB,CAAC,MAA6B;AAOhD,UANA,OAAO,EAAE,QAAS,YAAY,EAAE,SAAS,QAGzC,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,SAGrC,OAAO,EAAE,KAAK,MAAO,YAAY,OAAO,EAAE,KAAK,UAAW;AAC5D;AAEF,Y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AAA;AAAA,EAGd,aAAqB;AACX,YAAA,KAAK,SAASF,KAAmB,KAAK;AAAA,EAAA;AAAA,EAGhD,OAAO,YAAYS,GAAkC;AACnD,UAAML,IAAQK,KAAWT,GACnBK,IAAYI,IAAU;AACrB,WAAA,KAAK,sBAAsBL,GAAOC,CAAS;AAAA,EAAA;AAAA,EAGpD,OAAO,UAAUK,GAA4B;AAC3C,UAAMN,IAAQM,IAAI,OACZL,IAAYK,IAAI;AACf,WAAA,KAAK,sBAAsBN,GAAOC,CAAS;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMpD,UAAkB;AACT,WAAA,KAAK,YAAY,KAAK,QAAQ;AAAA,EAAA;AAEzC;AAEO,SAASI,IAAkB;AAChC,QAAME,IAAK,KAAK,MAAM,KAAK,IAAI,IAAI,GAAI,IAAI;AAEpC,SAAA,OAAOA,KAAM,KAAK,GAAG;AAC9B;AC3Ea,MAAAC,IAA8B,IAAI,MAAM,sCAAsC;"}
|
|
1
|
+
{"version":3,"file":"wallet-core.js","sources":["../src/version.ts","../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.ts","../src/utils/query-id.ts","../src/error.ts"],"sourcesContent":["declare const __VERSION__: string;\n\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'dev';\n","import {\n ActiveSessionsResponse,\n AdapterState,\n ConnectResponse,\n CreateTransferRequest,\n CreateTransferResponse,\n EmptyResponse,\n GetPublicKeyResponse,\n IframeAdapterProps,\n SignRequest,\n SignResponse,\n Timeouts,\n} from '../types';\nimport { VERSION } from '../version';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\n\nconst LOG_PREFIX = `[embedded-wallet v${VERSION}]`;\n\nexport class IframeAdapter {\n private readonly host: string;\n private readonly timeouts: Required<Timeouts>;\n private readonly waitingForResponse = new Map<string, Waiter>();\n private iframe?: HTMLIFrameElement;\n private state: AdapterState = 'not-ready';\n private readonly i18nInit?: IframeAdapterProps['i18n'];\n private iframeVersion?: string;\n private iframeError?: Error;\n\n constructor(props: IframeAdapterProps) {\n this.host = props.host;\n this.timeouts = {\n init: 1000,\n connect: 60000,\n disconnect: 1000,\n sign: 1000,\n createTransfer: 1000,\n activeSessions: 1000,\n getPublicKey: 1000,\n resetDevice: 1000,\n ...props.timeouts,\n };\n this.i18nInit = props.i18n;\n }\n\n private async sendMessage<R>(payload: unknown, timeout: number): Promise<R> {\n const messageId = Math.random().toString();\n const response = Promise.race([\n new Promise<R>((resolve, reject) => {\n this.waitingForResponse.set(messageId, [resolve, reject]);\n }),\n new Promise<R>((_, reject) => {\n setTimeout(() => {\n reject(new Error('Response timeout'));\n }, timeout);\n }),\n ]);\n this.iframe?.contentWindow?.postMessage({ id: messageId, payload }, this.host);\n return response;\n }\n\n private setupMessageListener() {\n window.addEventListener('message', this.handleMessage);\n }\n\n private handleMessage = (e: MessageEvent<unknown>) => {\n if (typeof e.data !== 'object' || e.data === null) {\n return;\n }\n\n // Handle iframe-ready message\n if ('type' in e.data && e.data.type === 'iframe-ready') {\n const data = e.data as { type: string; version?: string; timestamp?: number };\n this.iframeVersion = data.version;\n console.log(LOG_PREFIX, `iframe ready, version: ${data.version}`);\n\n // Check version compatibility\n if (data.version) {\n const iframeMajor = data.version.split('.')[0];\n const coreMajor = VERSION.split('.')[0];\n if (iframeMajor !== coreMajor) {\n console.warn(LOG_PREFIX, `Version mismatch: wallet-core=${VERSION}, iframe-host=${data.version}`);\n }\n }\n return;\n }\n\n // Handle iframe-error message\n if ('type' in e.data && e.data.type === 'iframe-error') {\n const data = e.data as { type: string; error?: string; stack?: string };\n console.error(LOG_PREFIX, 'iframe error:', data.error, data.stack);\n this.iframeError = new Error(data.error || 'Unknown iframe error');\n return;\n }\n\n if (!('id' in e.data) || !('status' in e.data)) {\n return;\n }\n if (typeof e.data.id !== 'string' || typeof e.data.status !== 'string') {\n return;\n }\n const waiter = this.waitingForResponse.get(e.data.id);\n if (!waiter) {\n return;\n }\n const [resolve, reject] = waiter;\n this.waitingForResponse.delete(e.data.id);\n if (e.data.status === 'success') {\n if ('payload' in e.data) {\n resolve(e.data.payload);\n } else {\n resolve(undefined);\n }\n } else {\n if ('error' in e.data) {\n reject(new Error(e.data.error as string));\n } else {\n reject(new Error('Unknown error'));\n }\n }\n };\n\n private async attachIframe(root: HTMLElement): Promise<void> {\n const iframe = document.createElement('iframe');\n iframe.src = this.host;\n iframe.frameBorder = '0';\n iframe.width = '100%';\n iframe.height = '100%';\n\n const loadPromise = new Promise<void>((resolve, reject) => {\n iframe.addEventListener('load', () => resolve(), { once: true });\n iframe.addEventListener('error', (e) => reject(e), { once: true });\n });\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => reject(new Error('Iframe load timeout')), this.timeouts.init);\n });\n\n root.appendChild(iframe);\n this.iframe = iframe;\n return Promise.race([loadPromise, timeoutPromise]);\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state !== 'not-ready') {\n return;\n }\n\n this.state = 'initializing';\n\n try {\n // Setup message listener before attaching iframe to catch early messages\n this.setupMessageListener();\n\n console.log(LOG_PREFIX, 'attaching to root', root);\n const attachStart = performance.now();\n await this.attachIframe(root);\n console.log(LOG_PREFIX, `iframe attached in ${Math.round(performance.now() - attachStart)}ms`);\n\n // Check if iframe reported an error during initialization\n if (this.iframeError) {\n throw this.iframeError;\n }\n\n console.log(LOG_PREFIX, 'sending ping');\n\n let lastError: Error | undefined;\n for (let attempt = 1; attempt <= 5; attempt++) {\n // Check for iframe errors between attempts\n if (this.iframeError) {\n throw this.iframeError;\n }\n\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n console.log(LOG_PREFIX, 'pong received');\n this.state = 'ready';\n return;\n } catch (e) {\n lastError = e instanceof Error ? e : new Error(String(e));\n console.warn(LOG_PREFIX, `ping attempt ${attempt}/5 failed:`, lastError.message);\n if (attempt < 5) {\n await new Promise(resolve => setTimeout(resolve, 200));\n }\n }\n }\n\n throw new Error(`${LOG_PREFIX} ping retries exceeded: ${lastError?.message}`);\n } catch (e) {\n this.destroy();\n throw e;\n }\n }\n\n destroy(): void {\n if (this.state === 'not-ready') {\n return;\n }\n\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n\n for (const [, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n\n this.iframe?.remove();\n this.iframe = undefined;\n }\n\n async connect(masterAddress: string): Promise<ConnectResponse> {\n return this.sendMessage({ type: 'connect', address: masterAddress }, this.timeouts.connect);\n }\n\n\n\n async getPublicKey(address: string): Promise<GetPublicKeyResponse> {\n return this.sendMessage({ type: \"get-public-key\", address }, this.timeouts.getPublicKey);\n }\n\n async resetDevice(address: string): Promise<EmptyResponse> {\n return this.sendMessage({ type: \"reset-device\", address }, this.timeouts.resetDevice);\n }\n\n async signMessage(masterAddress: string, message: SignRequest): Promise<SignResponse> {\n return this.sendMessage({ type: 'sign', address: masterAddress, message }, this.timeouts.sign);\n }\n\n async signMessages(masterAddress: string, messages: SignRequest[]): Promise<{ hashes: Uint8Array[]; signatures: Uint8Array[]; }> {\n return this.sendMessage({ type: 'sign-many', address: masterAddress, messages }, this.timeouts.sign);\n }\n\n async createTransfer(masterAddress: string, message: CreateTransferRequest): Promise<CreateTransferResponse> {\n return this.sendMessage({\n type: 'create-transfer',\n address: masterAddress,\n data: message,\n }, this.timeouts.createTransfer);\n }\n\n async getActiveSessions(): Promise<ActiveSessionsResponse> {\n return this.sendMessage({ type: 'active-sessions' }, this.timeouts.activeSessions);\n }\n\n async disconnect(masterAddress: string): Promise<void> {\n return this.sendMessage({ type: 'disconnect', address: masterAddress }, this.timeouts.disconnect);\n }\n\n getIframeVersion(): string | undefined {\n return this.iframeVersion;\n }\n}\n","import { beginCell, Cell, DictionaryValue, Slice } from \"@ton/ton\";\n\nexport const unpackPublicKeys = (cs: Slice): Buffer => {\n return cs.loadBuffer(32);\n}\n\nexport const packPublicKeys = (publicKeys: Buffer): Cell => {\n return beginCell().storeBuffer(publicKeys, 32).endCell();\n}\n\nexport const PublicKeysValue: DictionaryValue<Buffer> = {\n serialize: (src: Buffer, builder) => {\n builder.storeBuilder(packPublicKeys(src).asBuilder());\n },\n parse: (src) => {\n return unpackPublicKeys(src);\n },\n};\n","import { Address, beginCell, Cell, contractAddress, Dictionary, toNano, TonClient } from \"@ton/ton\";\nimport { PublicKeysValue } from \"./utils/packers\";\n\ntype StormWalletConfig = {\n smartAccountMasterAddress: string;\n}\n\nexport enum SmartAccountInternalOp {\n deploy_account = 0x764019e5,\n add_new_user_public_key = 0x220c4c19,\n remove_user_public_key = 0x7427ce1f,\n execute_limit_order = 0x1c0af2cb,\n execute_orders_bundle = 0xf38e7e65,\n set_code = 0x9c0f3220,\n add_request_to_add_new_user_public_key = 0x03cc29e8,\n add_request_to_remove_user_public_key = 0x07d25def,\n remove_all_keys_except_current = 0x5f9d0940\n}\n\nexport const DEFAULT_ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f\"\nconst ORDINARY_SMART_ACCOUNT_HEADER = 0;\n\nexport function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address, ordinarySmartAccountCode: string): Address {\n const code = Cell.fromHex(ordinarySmartAccountCode);\n\n const data = beginCell()\n .storeUint(ORDINARY_SMART_ACCOUNT_HEADER, 8)\n .storeAddress(factory)\n .storeAddress(owner)\n .storeDict(null)\n .endCell()\n\n return contractAddress(0, {code, data});\n}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig, private readonly ordinarySmartAccountCode = DEFAULT_ORDINARY_SMART_ACCOUNT_CODE) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address): Address {\n return calculateSmartAccountAddressFromStateInit(owner, Address.parse(this.config.smartAccountMasterAddress), this.ordinarySmartAccountCode);\n }\n\n async getSmartAccountAddress(walletAddress: string): Promise<Address> {\n const result = await this.tonClient.runMethod(Address.parse(this.config.smartAccountMasterAddress), 'get_nft_address_by_index', [\n {\n type: 'int',\n value: BigInt(`0x${Address.parse(walletAddress).hash.toString('hex')}`)\n }\n ])\n return result.stack.readAddress()\n }\n\n async getSmartAccountData(smartAccountAddress: string) {\n const address = Address.parse(smartAccountAddress)\n try {\n const result = await this.tonClient.runMethod(address, 'get_storage_data')\n const stack = result.stack\n\n const index = stack.readBigNumber();\n const collectionAddress = stack.readAddress();\n const masterWalletAddress = stack.readAddress();\n\n\n const pksCell = stack.readCellOpt()\n let publicKeys: bigint[] = []\n\n if (pksCell) {\n publicKeys = Dictionary.loadDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell(), pksCell).keys();\n }\n\n const adminAddress = stack.readAddress();\n const backendPublicKeys = Dictionary.loadDirect(\n Dictionary.Keys.Uint(8),\n PublicKeysValue,\n stack.readCell()\n ).values();\n\n const seqno = stack.readNumber();\n\n return {\n index,\n collectionAddress,\n masterWalletAddress,\n publicKeys,\n adminAddress,\n backendPublicKeys,\n seqno,\n }\n } catch (e) {\n if ((e as Error).message.endsWith('-13')) {\n return null\n }\n throw e\n }\n }\n\n createDeploySmartAccountTx(publicKey: Buffer, transferAmount: bigint) {\n const publicKeys: Dictionary<bigint, Cell> = Dictionary.empty(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell());\n publicKeys.set(bufferToBigInt(publicKey), beginCell().endCell());\n\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.deploy_account, 32)\n .storeUint(0, 64)\n .storeDict(publicKeys)\n .endCell();\n\n return {\n address: this.config.smartAccountMasterAddress,\n payload: payload.toBoc().toString('base64'),\n amount: transferAmount,\n }\n }\n\n createAddPublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.add_new_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemovePublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemoveAllKeysExceptCurrentTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_all_keys_except_current, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05'), // при необходимости настрой сумму\n }\n }\n}\n\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n","const BIT_NUMBER_SIZE = 10n; // 10 bit\n// const SHIFT_SIZE = 13n; // 13 bit\nconst MAX_BIT_NUMBER = 1022n;\nconst MAX_SHIFT = 8191n; // 2^13 = 8192\n\nexport class HighloadQueryId {\n private shift: bigint; // [0 .. 8191]\n private bitnumber: bigint; // [0 .. 1022]\n\n constructor() {\n this.shift = 0n;\n this.bitnumber = 0n;\n }\n\n static fromShiftAndBitNumber(shift: bigint, bitnumber: bigint): HighloadQueryId {\n const q = new HighloadQueryId();\n q.shift = shift;\n if (q.shift < 0) throw new Error('invalid shift');\n if (q.shift > MAX_SHIFT) throw new Error('invalid shift');\n q.bitnumber = bitnumber;\n if (q.bitnumber < 0) throw new Error('invalid bitnumber');\n if (q.bitnumber > MAX_BIT_NUMBER) throw new Error('invalid bitnumber');\n return q;\n }\n\n\n getNext() {\n let newBitnumber = this.bitnumber + 1n;\n let newShift = this.shift;\n\n if (newShift === MAX_SHIFT && newBitnumber > (MAX_BIT_NUMBER - 1n)) {\n throw new Error('Overload'); // NOTE: we left one queryId for emergency withdraw\n }\n\n if (newBitnumber > MAX_BIT_NUMBER) {\n newBitnumber = 0n;\n newShift += 1n;\n if (newShift > MAX_SHIFT) {\n throw new Error('Overload')\n }\n }\n\n return HighloadQueryId.fromShiftAndBitNumber(newShift, newBitnumber);\n }\n\n hasNext() {\n const isEnd = this.bitnumber >= (MAX_BIT_NUMBER - 1n) && this.shift === MAX_SHIFT; // NOTE: we left one queryId for emergency withdraw;\n return !isEnd;\n }\n\n getShift(): bigint {\n return this.shift;\n }\n\n getBitNumber(): bigint {\n return this.bitnumber;\n }\n\n getQueryId(): bigint {\n return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;\n }\n\n static fromQueryId(queryId: bigint): HighloadQueryId {\n const shift = queryId >> BIT_NUMBER_SIZE;\n const bitnumber = queryId & 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n static fromSeqno(i: bigint): HighloadQueryId {\n const shift = i / 1023n;\n const bitnumber = i % 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n /**\n * @return {bigint} [0 .. 8380415]\n */\n toSeqno(): bigint {\n return this.bitnumber + this.shift * 1023n;\n }\n}\n\nexport function queryId(): bigint {\n const ts = Math.floor(Date.now() / 1000) - 30;\n\n return BigInt(ts % (1 << 23))\n}","export class NoActiveSessionError extends Error {\n public readonly address: string;\n\n constructor(address: string) {\n super(`No active session found for ${address}`);\n this.name = 'NoActiveSessionError';\n this.address = address;\n }\n}\n\n\nexport const SessionExpiredOrNotProvided = new Error('Session is expired or never provided')"],"names":["VERSION","LOG_PREFIX","IframeAdapter","props","__publicField","data","iframeMajor","coreMajor","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","iframe","loadPromise","e","timeoutPromise","attachStart","lastError","attempt","masterAddress","address","message","messages","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","DEFAULT_ORDINARY_SMART_ACCOUNT_CODE","ORDINARY_SMART_ACCOUNT_HEADER","calculateSmartAccountAddressFromStateInit","owner","factory","ordinarySmartAccountCode","code","Cell","contractAddress","StormWallet","tonClient","config","Address","walletAddress","smartAccountAddress","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer","BIT_NUMBER_SIZE","MAX_BIT_NUMBER","MAX_SHIFT","HighloadQueryId","shift","bitnumber","q","newBitnumber","newShift","queryId","i","ts","SessionExpiredOrNotProvided"],"mappings":";;;;AAEa,MAAAA,IAA+C,UCetDC,IAAa,qBAAqBD,CAAO;AAExC,MAAME,EAAc;AAAA,EAUzB,YAAYC,GAA2B;AATtB,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA,gDAAyB,IAAoB;AACtD,IAAAA,EAAA;AACA,IAAAA,EAAA,eAAsB;AACb,IAAAA,EAAA;AACT,IAAAA,EAAA;AACA,IAAAA,EAAA;AAsCA,IAAAA,EAAA,uBAAgB,CAAC,MAA6B;AACpD,UAAI,OAAO,EAAE,QAAS,YAAY,EAAE,SAAS;AAC3C;AAIF,UAAI,UAAU,EAAE,QAAQ,EAAE,KAAK,SAAS,gBAAgB;AACtD,cAAMC,IAAO,EAAE;AAKf,YAJA,KAAK,gBAAgBA,EAAK,SAC1B,QAAQ,IAAIJ,GAAY,0BAA0BI,EAAK,OAAO,EAAE,GAG5DA,EAAK,SAAS;AAChB,gBAAMC,IAAcD,EAAK,QAAQ,MAAM,GAAG,EAAE,CAAC,GACvCE,IAAYP,EAAQ,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CAAsC;"}
|
package/dist/wallet-core.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(i,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@ton/ton")):typeof define=="function"&&define.amd?define(["exports","@ton/ton"],r):(i=typeof globalThis<"u"?globalThis:i||self,r(i.WalletCore={},i.ton))})(this,function(i,r){"use strict";var _=Object.defineProperty;var U=(i,r,l)=>r in i?_(i,r,{enumerable:!0,configurable:!0,writable:!0,value:l}):i[r]=l;var o=(i,r,l)=>U(i,typeof r!="symbol"?r+"":r,l);const f="[embedded-wallet v1.0.28]";class A{constructor(e){o(this,"host");o(this,"timeouts");o(this,"waitingForResponse",new Map);o(this,"iframe");o(this,"state","not-ready");o(this,"i18nInit");o(this,"handleMessage",e=>{if(typeof e.data!="object"||e.data===null||!("id"in e.data)||!("status"in e.data)||typeof e.data.id!="string"||typeof e.data.status!="string")return;const t=this.waitingForResponse.get(e.data.id);if(!t)return;const[s,n]=t;this.waitingForResponse.delete(e.data.id),e.data.status==="success"?"payload"in e.data?s(e.data.payload):s(void 0):"error"in e.data?n(new Error(e.data.error)):n(new Error("Unknown error"))});this.host=e.host,this.timeouts={init:1e3,connect:6e4,disconnect:1e3,sign:1e3,createTransfer:1e3,activeSessions:1e3,getPublicKey:1e3,resetDevice:1e3,...e.timeouts},this.i18nInit=e.i18n}async sendMessage(e,t){var a,d;const s=Math.random().toString(),n=Promise.race([new Promise((b,u)=>{this.waitingForResponse.set(s,[b,u])}),new Promise((b,u)=>{setTimeout(()=>{u(new Error("Response timeout"))},t)})]);return(d=(a=this.iframe)==null?void 0:a.contentWindow)==null||d.postMessage({id:s,payload:e},this.host),n}setupMessageListener(){window.addEventListener("message",this.handleMessage)}async attachIframe(e){const t=document.createElement("iframe");t.src=this.host,t.frameBorder="0",t.width="100%",t.height="100%";const s=new Promise((a,d)=>{t.addEventListener("load",()=>a(),{once:!0}),t.addEventListener("error",b=>d(b),{once:!0})}),n=new Promise((a,d)=>{setTimeout(()=>d(new Error("Iframe load timeout")),this.timeouts.init)});return e.appendChild(t),this.iframe=t,Promise.race([s,n])}async init(e){if(this.state==="not-ready"){this.state="initializing";try{console.log(f,"attaching to root",e);const t=performance.now();await this.attachIframe(e),console.log(f,`iframe attached in ${Math.round(performance.now()-t)}ms`),this.setupMessageListener(),console.log(f,"sending ping");let s;for(let n=1;n<=5;n++)try{await this.sendMessage({type:"ping",i18n:this.i18nInit},this.timeouts.init),console.log(f,"pong received"),this.state="ready";return}catch(a){s=a instanceof Error?a:new Error(String(a)),console.warn(f,`ping attempt ${n}/5 failed:`,s.message),n<5&&await new Promise(d=>setTimeout(d,200))}throw new Error(`${f} ping retries exceeded: ${s==null?void 0:s.message}`)}catch(t){throw this.destroy(),t}}}destroy(){var e;if(this.state!=="not-ready"){this.state="not-ready",window.removeEventListener("message",this.handleMessage);for(const[,t]of this.waitingForResponse.values())t(new Error("Iframe disconnected"));this.waitingForResponse.clear(),(e=this.iframe)==null||e.remove(),this.iframe=void 0}}async connect(e){return this.sendMessage({type:"connect",address:e},this.timeouts.connect)}async getPublicKey(e){return this.sendMessage({type:"get-public-key",address:e},this.timeouts.getPublicKey)}async resetDevice(e){return this.sendMessage({type:"reset-device",address:e},this.timeouts.resetDevice)}async signMessage(e,t){return this.sendMessage({type:"sign",address:e,message:t},this.timeouts.sign)}async signMessages(e,t){return this.sendMessage({type:"sign-many",address:e,messages:t},this.timeouts.sign)}async createTransfer(e,t){return this.sendMessage({type:"create-transfer",address:e,data:t},this.timeouts.createTransfer)}async getActiveSessions(){return this.sendMessage({type:"active-sessions"},this.timeouts.activeSessions)}async disconnect(e){return this.sendMessage({type:"disconnect",address:e},this.timeouts.disconnect)}}const S=c=>c.loadBuffer(32),v=c=>r.beginCell().storeBuffer(c,32).endCell(),E={serialize:(c,e)=>{e.storeBuilder(v(c).asBuilder())},parse:c=>S(c)},M="b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f",C=0;function y(c,e,t){const s=r.Cell.fromHex(t),n=r.beginCell().storeUint(C,8).storeAddress(e).storeAddress(c).storeDict(null).endCell();return r.contractAddress(0,{code:s,data:n})}class B{constructor(e,t,s=M){this.tonClient=e,this.config=t,this.ordinarySmartAccountCode=s}calculateSmartAccountAddressFromStateInit(e){return y(e,r.Address.parse(this.config.smartAccountMasterAddress),this.ordinarySmartAccountCode)}async getSmartAccountAddress(e){return(await this.tonClient.runMethod(r.Address.parse(this.config.smartAccountMasterAddress),"get_nft_address_by_index",[{type:"int",value:BigInt(`0x${r.Address.parse(e).hash.toString("hex")}`)}])).stack.readAddress()}async getSmartAccountData(e){const t=r.Address.parse(e);try{const n=(await this.tonClient.runMethod(t,"get_storage_data")).stack,a=n.readBigNumber(),d=n.readAddress(),b=n.readAddress(),u=n.readCellOpt();let w=[];u&&(w=r.Dictionary.loadDirect(r.Dictionary.Keys.BigUint(256),r.Dictionary.Values.Cell(),u).keys());const P=n.readAddress(),T=r.Dictionary.loadDirect(r.Dictionary.Keys.Uint(8),E,n.readCell()).values(),R=n.readNumber();return{index:a,collectionAddress:d,masterWalletAddress:b,publicKeys:w,adminAddress:P,backendPublicKeys:T,seqno:R}}catch(s){if(s.message.endsWith("-13"))return null;throw s}}createDeploySmartAccountTx(e,t){const s=r.Dictionary.empty(r.Dictionary.Keys.BigUint(256),r.Dictionary.Values.Cell());s.set(I(e),r.beginCell().endCell());const n=r.beginCell().storeUint(1983912421,32).storeUint(0,64).storeDict(s).endCell();return{address:this.config.smartAccountMasterAddress,payload:n.toBoc().toString("base64"),amount:t}}createAddPublicKeyTx(e,t){const s=r.beginCell().storeUint(571231257,32).storeUint(0,64).storeBuffer(t).endCell();return{address:e,payload:s.toBoc().toString("base64"),amount:r.toNano("0.05")}}createRemovePublicKeyTx(e,t){const s=r.beginCell().storeUint(1948765727,32).storeUint(0,64).storeBuffer(t).endCell();return{address:e,payload:s.toBoc().toString("base64"),amount:r.toNano("0.05")}}createRemoveAllKeysExceptCurrentTx(e,t){const s=r.beginCell().storeUint(1604127040,32).storeUint(0,64).storeBuffer(t).endCell();return{address:e,payload:s.toBoc().toString("base64"),amount:r.toNano("0.05")}}}function I(c){return BigInt("0x"+c.toString("hex"))}const p=10n,h=1022n,m=8191n;class g{constructor(){o(this,"shift");o(this,"bitnumber");this.shift=0n,this.bitnumber=0n}static fromShiftAndBitNumber(e,t){const s=new g;if(s.shift=e,s.shift<0)throw new Error("invalid shift");if(s.shift>m)throw new Error("invalid shift");if(s.bitnumber=t,s.bitnumber<0)throw new Error("invalid bitnumber");if(s.bitnumber>h)throw new Error("invalid bitnumber");return s}getNext(){let e=this.bitnumber+1n,t=this.shift;if(t===m&&e>h-1n)throw new Error("Overload");if(e>h&&(e=0n,t+=1n,t>m))throw new Error("Overload");return g.fromShiftAndBitNumber(t,e)}hasNext(){return!(this.bitnumber>=h-1n&&this.shift===m)}getShift(){return this.shift}getBitNumber(){return this.bitnumber}getQueryId(){return(this.shift<<p)+this.bitnumber}static fromQueryId(e){const t=e>>p,s=e&1023n;return this.fromShiftAndBitNumber(t,s)}static fromSeqno(e){const t=e/1023n,s=e%1023n;return this.fromShiftAndBitNumber(t,s)}toSeqno(){return this.bitnumber+this.shift*1023n}}function D(){const c=Math.floor(Date.now()/1e3)-30;return BigInt(c%(1<<23))}const N=new Error("Session is expired or never provided");i.HighloadQueryId=g,i.IframeAdapter=A,i.SessionExpiredOrNotProvided=N,i.StormWallet=B,i.calculateSmartAccountAddressFromStateInit=y,i.queryId=D,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(a,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("@ton/ton")):typeof define=="function"&&define.amd?define(["exports","@ton/ton"],r):(a=typeof globalThis<"u"?globalThis:a||self,r(a.WalletCore={},a.ton))})(this,function(a,r){"use strict";var U=Object.defineProperty;var _=(a,r,b)=>r in a?U(a,r,{enumerable:!0,configurable:!0,writable:!0,value:b}):a[r]=b;var d=(a,r,b)=>_(a,typeof r!="symbol"?r+"":r,b);const b="1.0.29",f=`[embedded-wallet v${b}]`;class A{constructor(e){d(this,"host");d(this,"timeouts");d(this,"waitingForResponse",new Map);d(this,"iframe");d(this,"state","not-ready");d(this,"i18nInit");d(this,"iframeVersion");d(this,"iframeError");d(this,"handleMessage",e=>{if(typeof e.data!="object"||e.data===null)return;if("type"in e.data&&e.data.type==="iframe-ready"){const n=e.data;if(this.iframeVersion=n.version,console.log(f,`iframe ready, version: ${n.version}`),n.version){const o=n.version.split(".")[0],u=b.split(".")[0];o!==u&&console.warn(f,`Version mismatch: wallet-core=${b}, iframe-host=${n.version}`)}return}if("type"in e.data&&e.data.type==="iframe-error"){const n=e.data;console.error(f,"iframe error:",n.error,n.stack),this.iframeError=new Error(n.error||"Unknown iframe error");return}if(!("id"in e.data)||!("status"in e.data)||typeof e.data.id!="string"||typeof e.data.status!="string")return;const t=this.waitingForResponse.get(e.data.id);if(!t)return;const[s,i]=t;this.waitingForResponse.delete(e.data.id),e.data.status==="success"?"payload"in e.data?s(e.data.payload):s(void 0):"error"in e.data?i(new Error(e.data.error)):i(new Error("Unknown error"))});this.host=e.host,this.timeouts={init:1e3,connect:6e4,disconnect:1e3,sign:1e3,createTransfer:1e3,activeSessions:1e3,getPublicKey:1e3,resetDevice:1e3,...e.timeouts},this.i18nInit=e.i18n}async sendMessage(e,t){var n,o;const s=Math.random().toString(),i=Promise.race([new Promise((u,l)=>{this.waitingForResponse.set(s,[u,l])}),new Promise((u,l)=>{setTimeout(()=>{l(new Error("Response timeout"))},t)})]);return(o=(n=this.iframe)==null?void 0:n.contentWindow)==null||o.postMessage({id:s,payload:e},this.host),i}setupMessageListener(){window.addEventListener("message",this.handleMessage)}async attachIframe(e){const t=document.createElement("iframe");t.src=this.host,t.frameBorder="0",t.width="100%",t.height="100%";const s=new Promise((n,o)=>{t.addEventListener("load",()=>n(),{once:!0}),t.addEventListener("error",u=>o(u),{once:!0})}),i=new Promise((n,o)=>{setTimeout(()=>o(new Error("Iframe load timeout")),this.timeouts.init)});return e.appendChild(t),this.iframe=t,Promise.race([s,i])}async init(e){if(this.state==="not-ready"){this.state="initializing";try{this.setupMessageListener(),console.log(f,"attaching to root",e);const t=performance.now();if(await this.attachIframe(e),console.log(f,`iframe attached in ${Math.round(performance.now()-t)}ms`),this.iframeError)throw this.iframeError;console.log(f,"sending ping");let s;for(let i=1;i<=5;i++){if(this.iframeError)throw this.iframeError;try{await this.sendMessage({type:"ping",i18n:this.i18nInit},this.timeouts.init),console.log(f,"pong received"),this.state="ready";return}catch(n){s=n instanceof Error?n:new Error(String(n)),console.warn(f,`ping attempt ${i}/5 failed:`,s.message),i<5&&await new Promise(o=>setTimeout(o,200))}}throw new Error(`${f} ping retries exceeded: ${s==null?void 0:s.message}`)}catch(t){throw this.destroy(),t}}}destroy(){var e;if(this.state!=="not-ready"){this.state="not-ready",window.removeEventListener("message",this.handleMessage);for(const[,t]of this.waitingForResponse.values())t(new Error("Iframe disconnected"));this.waitingForResponse.clear(),(e=this.iframe)==null||e.remove(),this.iframe=void 0}}async connect(e){return this.sendMessage({type:"connect",address:e},this.timeouts.connect)}async getPublicKey(e){return this.sendMessage({type:"get-public-key",address:e},this.timeouts.getPublicKey)}async resetDevice(e){return this.sendMessage({type:"reset-device",address:e},this.timeouts.resetDevice)}async signMessage(e,t){return this.sendMessage({type:"sign",address:e,message:t},this.timeouts.sign)}async signMessages(e,t){return this.sendMessage({type:"sign-many",address:e,messages:t},this.timeouts.sign)}async createTransfer(e,t){return this.sendMessage({type:"create-transfer",address:e,data:t},this.timeouts.createTransfer)}async getActiveSessions(){return this.sendMessage({type:"active-sessions"},this.timeouts.activeSessions)}async disconnect(e){return this.sendMessage({type:"disconnect",address:e},this.timeouts.disconnect)}getIframeVersion(){return this.iframeVersion}}const S=c=>c.loadBuffer(32),v=c=>r.beginCell().storeBuffer(c,32).endCell(),E={serialize:(c,e)=>{e.storeBuilder(v(c).asBuilder())},parse:c=>S(c)},M="b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f",C=0;function y(c,e,t){const s=r.Cell.fromHex(t),i=r.beginCell().storeUint(C,8).storeAddress(e).storeAddress(c).storeDict(null).endCell();return r.contractAddress(0,{code:s,data:i})}class B{constructor(e,t,s=M){this.tonClient=e,this.config=t,this.ordinarySmartAccountCode=s}calculateSmartAccountAddressFromStateInit(e){return y(e,r.Address.parse(this.config.smartAccountMasterAddress),this.ordinarySmartAccountCode)}async getSmartAccountAddress(e){return(await this.tonClient.runMethod(r.Address.parse(this.config.smartAccountMasterAddress),"get_nft_address_by_index",[{type:"int",value:BigInt(`0x${r.Address.parse(e).hash.toString("hex")}`)}])).stack.readAddress()}async getSmartAccountData(e){const t=r.Address.parse(e);try{const i=(await this.tonClient.runMethod(t,"get_storage_data")).stack,n=i.readBigNumber(),o=i.readAddress(),u=i.readAddress(),l=i.readCellOpt();let w=[];l&&(w=r.Dictionary.loadDirect(r.Dictionary.Keys.BigUint(256),r.Dictionary.Values.Cell(),l).keys());const T=i.readAddress(),N=r.Dictionary.loadDirect(r.Dictionary.Keys.Uint(8),E,i.readCell()).values(),R=i.readNumber();return{index:n,collectionAddress:o,masterWalletAddress:u,publicKeys:w,adminAddress:T,backendPublicKeys:N,seqno:R}}catch(s){if(s.message.endsWith("-13"))return null;throw s}}createDeploySmartAccountTx(e,t){const s=r.Dictionary.empty(r.Dictionary.Keys.BigUint(256),r.Dictionary.Values.Cell());s.set(I(e),r.beginCell().endCell());const i=r.beginCell().storeUint(1983912421,32).storeUint(0,64).storeDict(s).endCell();return{address:this.config.smartAccountMasterAddress,payload:i.toBoc().toString("base64"),amount:t}}createAddPublicKeyTx(e,t){const s=r.beginCell().storeUint(571231257,32).storeUint(0,64).storeBuffer(t).endCell();return{address:e,payload:s.toBoc().toString("base64"),amount:r.toNano("0.05")}}createRemovePublicKeyTx(e,t){const s=r.beginCell().storeUint(1948765727,32).storeUint(0,64).storeBuffer(t).endCell();return{address:e,payload:s.toBoc().toString("base64"),amount:r.toNano("0.05")}}createRemoveAllKeysExceptCurrentTx(e,t){const s=r.beginCell().storeUint(1604127040,32).storeUint(0,64).storeBuffer(t).endCell();return{address:e,payload:s.toBoc().toString("base64"),amount:r.toNano("0.05")}}}function I(c){return BigInt("0x"+c.toString("hex"))}const p=10n,h=1022n,m=8191n;class g{constructor(){d(this,"shift");d(this,"bitnumber");this.shift=0n,this.bitnumber=0n}static fromShiftAndBitNumber(e,t){const s=new g;if(s.shift=e,s.shift<0)throw new Error("invalid shift");if(s.shift>m)throw new Error("invalid shift");if(s.bitnumber=t,s.bitnumber<0)throw new Error("invalid bitnumber");if(s.bitnumber>h)throw new Error("invalid bitnumber");return s}getNext(){let e=this.bitnumber+1n,t=this.shift;if(t===m&&e>h-1n)throw new Error("Overload");if(e>h&&(e=0n,t+=1n,t>m))throw new Error("Overload");return g.fromShiftAndBitNumber(t,e)}hasNext(){return!(this.bitnumber>=h-1n&&this.shift===m)}getShift(){return this.shift}getBitNumber(){return this.bitnumber}getQueryId(){return(this.shift<<p)+this.bitnumber}static fromQueryId(e){const t=e>>p,s=e&1023n;return this.fromShiftAndBitNumber(t,s)}static fromSeqno(e){const t=e/1023n,s=e%1023n;return this.fromShiftAndBitNumber(t,s)}toSeqno(){return this.bitnumber+this.shift*1023n}}function D(){const c=Math.floor(Date.now()/1e3)-30;return BigInt(c%(1<<23))}const P=new Error("Session is expired or never provided");a.HighloadQueryId=g,a.IframeAdapter=A,a.SessionExpiredOrNotProvided=P,a.StormWallet=B,a.calculateSmartAccountAddressFromStateInit=y,a.queryId=D,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=wallet-core.umd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-core.umd.cjs","sources":["../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.ts","../src/utils/query-id.ts","../src/error.ts"],"sourcesContent":["import {\n ActiveSessionsResponse,\n AdapterState,\n ConnectResponse,\n CreateTransferRequest,\n CreateTransferResponse,\n EmptyResponse,\n GetPublicKeyResponse,\n IframeAdapterProps,\n SignRequest,\n SignResponse,\n Timeouts,\n} from '../types';\nimport { VERSION } from '../version';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\n\nconst LOG_PREFIX = `[embedded-wallet v${VERSION}]`;\n\nexport class IframeAdapter {\n private readonly host: string;\n private readonly timeouts: Required<Timeouts>;\n private readonly waitingForResponse = new Map<string, Waiter>();\n private iframe?: HTMLIFrameElement;\n private state: AdapterState = 'not-ready';\n private readonly i18nInit?: IframeAdapterProps['i18n'];\n\n constructor(props: IframeAdapterProps) {\n this.host = props.host;\n this.timeouts = {\n init: 1000,\n connect: 60000,\n disconnect: 1000,\n sign: 1000,\n createTransfer: 1000,\n activeSessions: 1000,\n getPublicKey: 1000,\n resetDevice: 1000,\n ...props.timeouts,\n };\n this.i18nInit = props.i18n;\n }\n\n private async sendMessage<R>(payload: unknown, timeout: number): Promise<R> {\n const messageId = Math.random().toString();\n const response = Promise.race([\n new Promise<R>((resolve, reject) => {\n this.waitingForResponse.set(messageId, [resolve, reject]);\n }),\n new Promise<R>((_, reject) => {\n setTimeout(() => {\n reject(new Error('Response timeout'));\n }, timeout);\n }),\n ]);\n this.iframe?.contentWindow?.postMessage({ id: messageId, payload }, this.host);\n return response;\n }\n\n private setupMessageListener() {\n window.addEventListener('message', this.handleMessage);\n }\n\n private handleMessage = (e: MessageEvent<unknown>) => {\n if (typeof e.data !== 'object' || e.data === null) {\n return;\n }\n if (!('id' in e.data) || !('status' in e.data)) {\n return;\n }\n if (typeof e.data.id !== 'string' || typeof e.data.status !== 'string') {\n return;\n }\n const waiter = this.waitingForResponse.get(e.data.id);\n if (!waiter) {\n return;\n }\n const [resolve, reject] = waiter;\n this.waitingForResponse.delete(e.data.id);\n if (e.data.status === 'success') {\n if ('payload' in e.data) {\n resolve(e.data.payload);\n } else {\n resolve(undefined);\n }\n } else {\n if ('error' in e.data) {\n reject(new Error(e.data.error as string));\n } else {\n reject(new Error('Unknown error'));\n }\n }\n\n };\n\n private async attachIframe(root: HTMLElement): Promise<void> {\n const iframe = document.createElement('iframe');\n iframe.src = this.host;\n iframe.frameBorder = '0';\n iframe.width = '100%';\n iframe.height = '100%';\n\n const loadPromise = new Promise<void>((resolve, reject) => {\n iframe.addEventListener('load', () => resolve(), { once: true });\n iframe.addEventListener('error', (e) => reject(e), { once: true });\n });\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => reject(new Error('Iframe load timeout')), this.timeouts.init);\n });\n\n root.appendChild(iframe);\n this.iframe = iframe;\n return Promise.race([loadPromise, timeoutPromise]);\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state !== 'not-ready') {\n return;\n }\n\n this.state = 'initializing';\n\n try {\n console.log(LOG_PREFIX, 'attaching to root', root);\n const attachStart = performance.now();\n await this.attachIframe(root);\n console.log(LOG_PREFIX, `iframe attached in ${Math.round(performance.now() - attachStart)}ms`);\n this.setupMessageListener();\n console.log(LOG_PREFIX, 'sending ping');\n\n let lastError: Error | undefined;\n for (let attempt = 1; attempt <= 5; attempt++) {\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n console.log(LOG_PREFIX, 'pong received');\n this.state = 'ready';\n return;\n } catch (e) {\n lastError = e instanceof Error ? e : new Error(String(e));\n console.warn(LOG_PREFIX, `ping attempt ${attempt}/5 failed:`, lastError.message);\n if (attempt < 5) {\n await new Promise(resolve => setTimeout(resolve, 200));\n }\n }\n }\n\n throw new Error(`${LOG_PREFIX} ping retries exceeded: ${lastError?.message}`);\n } catch (e) {\n this.destroy();\n throw e;\n }\n }\n\n destroy(): void {\n if (this.state === 'not-ready') {\n return;\n }\n\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n\n for (const [, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n\n this.iframe?.remove();\n this.iframe = undefined;\n }\n\n async connect(masterAddress: string): Promise<ConnectResponse> {\n return this.sendMessage({ type: 'connect', address: masterAddress }, this.timeouts.connect);\n }\n\n\n\n async getPublicKey(address: string): Promise<GetPublicKeyResponse> {\n return this.sendMessage({ type: \"get-public-key\", address }, this.timeouts.getPublicKey);\n }\n\n async resetDevice(address: string): Promise<EmptyResponse> {\n return this.sendMessage({ type: \"reset-device\", address }, this.timeouts.resetDevice);\n }\n\n async signMessage(masterAddress: string, message: SignRequest): Promise<SignResponse> {\n return this.sendMessage({ type: 'sign', address: masterAddress, message }, this.timeouts.sign);\n }\n\n async signMessages(masterAddress: string, messages: SignRequest[]): Promise<{ hashes: Uint8Array[]; signatures: Uint8Array[]; }> {\n return this.sendMessage({ type: 'sign-many', address: masterAddress, messages }, this.timeouts.sign);\n }\n\n async createTransfer(masterAddress: string, message: CreateTransferRequest): Promise<CreateTransferResponse> {\n return this.sendMessage({\n type: 'create-transfer',\n address: masterAddress,\n data: message,\n }, this.timeouts.createTransfer);\n }\n\n async getActiveSessions(): Promise<ActiveSessionsResponse> {\n return this.sendMessage({ type: 'active-sessions' }, this.timeouts.activeSessions);\n }\n\n async disconnect(masterAddress: string): Promise<void> {\n return this.sendMessage({ type: 'disconnect', address: masterAddress }, this.timeouts.disconnect);\n }\n}\n","import { beginCell, Cell, DictionaryValue, Slice } from \"@ton/ton\";\n\nexport const unpackPublicKeys = (cs: Slice): Buffer => {\n return cs.loadBuffer(32);\n}\n\nexport const packPublicKeys = (publicKeys: Buffer): Cell => {\n return beginCell().storeBuffer(publicKeys, 32).endCell();\n}\n\nexport const PublicKeysValue: DictionaryValue<Buffer> = {\n serialize: (src: Buffer, builder) => {\n builder.storeBuilder(packPublicKeys(src).asBuilder());\n },\n parse: (src) => {\n return unpackPublicKeys(src);\n },\n};\n","import { Address, beginCell, Cell, contractAddress, Dictionary, toNano, TonClient } from \"@ton/ton\";\nimport { PublicKeysValue } from \"./utils/packers\";\n\ntype StormWalletConfig = {\n smartAccountMasterAddress: string;\n}\n\nexport enum SmartAccountInternalOp {\n deploy_account = 0x764019e5,\n add_new_user_public_key = 0x220c4c19,\n remove_user_public_key = 0x7427ce1f,\n execute_limit_order = 0x1c0af2cb,\n execute_orders_bundle = 0xf38e7e65,\n set_code = 0x9c0f3220,\n add_request_to_add_new_user_public_key = 0x03cc29e8,\n add_request_to_remove_user_public_key = 0x07d25def,\n remove_all_keys_except_current = 0x5f9d0940\n}\n\nexport const DEFAULT_ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f\"\nconst ORDINARY_SMART_ACCOUNT_HEADER = 0;\n\nexport function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address, ordinarySmartAccountCode: string): Address {\n const code = Cell.fromHex(ordinarySmartAccountCode);\n\n const data = beginCell()\n .storeUint(ORDINARY_SMART_ACCOUNT_HEADER, 8)\n .storeAddress(factory)\n .storeAddress(owner)\n .storeDict(null)\n .endCell()\n\n return contractAddress(0, {code, data});\n}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig, private readonly ordinarySmartAccountCode = DEFAULT_ORDINARY_SMART_ACCOUNT_CODE) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address): Address {\n return calculateSmartAccountAddressFromStateInit(owner, Address.parse(this.config.smartAccountMasterAddress), this.ordinarySmartAccountCode);\n }\n\n async getSmartAccountAddress(walletAddress: string): Promise<Address> {\n const result = await this.tonClient.runMethod(Address.parse(this.config.smartAccountMasterAddress), 'get_nft_address_by_index', [\n {\n type: 'int',\n value: BigInt(`0x${Address.parse(walletAddress).hash.toString('hex')}`)\n }\n ])\n return result.stack.readAddress()\n }\n\n async getSmartAccountData(smartAccountAddress: string) {\n const address = Address.parse(smartAccountAddress)\n try {\n const result = await this.tonClient.runMethod(address, 'get_storage_data')\n const stack = result.stack\n\n const index = stack.readBigNumber();\n const collectionAddress = stack.readAddress();\n const masterWalletAddress = stack.readAddress();\n\n\n const pksCell = stack.readCellOpt()\n let publicKeys: bigint[] = []\n\n if (pksCell) {\n publicKeys = Dictionary.loadDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell(), pksCell).keys();\n }\n\n const adminAddress = stack.readAddress();\n const backendPublicKeys = Dictionary.loadDirect(\n Dictionary.Keys.Uint(8),\n PublicKeysValue,\n stack.readCell()\n ).values();\n\n const seqno = stack.readNumber();\n\n return {\n index,\n collectionAddress,\n masterWalletAddress,\n publicKeys,\n adminAddress,\n backendPublicKeys,\n seqno,\n }\n } catch (e) {\n if ((e as Error).message.endsWith('-13')) {\n return null\n }\n throw e\n }\n }\n\n createDeploySmartAccountTx(publicKey: Buffer, transferAmount: bigint) {\n const publicKeys: Dictionary<bigint, Cell> = Dictionary.empty(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell());\n publicKeys.set(bufferToBigInt(publicKey), beginCell().endCell());\n\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.deploy_account, 32)\n .storeUint(0, 64)\n .storeDict(publicKeys)\n .endCell();\n\n return {\n address: this.config.smartAccountMasterAddress,\n payload: payload.toBoc().toString('base64'),\n amount: transferAmount,\n }\n }\n\n createAddPublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.add_new_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemovePublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemoveAllKeysExceptCurrentTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_all_keys_except_current, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05'), // при необходимости настрой сумму\n }\n }\n}\n\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n","const BIT_NUMBER_SIZE = 10n; // 10 bit\n// const SHIFT_SIZE = 13n; // 13 bit\nconst MAX_BIT_NUMBER = 1022n;\nconst MAX_SHIFT = 8191n; // 2^13 = 8192\n\nexport class HighloadQueryId {\n private shift: bigint; // [0 .. 8191]\n private bitnumber: bigint; // [0 .. 1022]\n\n constructor() {\n this.shift = 0n;\n this.bitnumber = 0n;\n }\n\n static fromShiftAndBitNumber(shift: bigint, bitnumber: bigint): HighloadQueryId {\n const q = new HighloadQueryId();\n q.shift = shift;\n if (q.shift < 0) throw new Error('invalid shift');\n if (q.shift > MAX_SHIFT) throw new Error('invalid shift');\n q.bitnumber = bitnumber;\n if (q.bitnumber < 0) throw new Error('invalid bitnumber');\n if (q.bitnumber > MAX_BIT_NUMBER) throw new Error('invalid bitnumber');\n return q;\n }\n\n\n getNext() {\n let newBitnumber = this.bitnumber + 1n;\n let newShift = this.shift;\n\n if (newShift === MAX_SHIFT && newBitnumber > (MAX_BIT_NUMBER - 1n)) {\n throw new Error('Overload'); // NOTE: we left one queryId for emergency withdraw\n }\n\n if (newBitnumber > MAX_BIT_NUMBER) {\n newBitnumber = 0n;\n newShift += 1n;\n if (newShift > MAX_SHIFT) {\n throw new Error('Overload')\n }\n }\n\n return HighloadQueryId.fromShiftAndBitNumber(newShift, newBitnumber);\n }\n\n hasNext() {\n const isEnd = this.bitnumber >= (MAX_BIT_NUMBER - 1n) && this.shift === MAX_SHIFT; // NOTE: we left one queryId for emergency withdraw;\n return !isEnd;\n }\n\n getShift(): bigint {\n return this.shift;\n }\n\n getBitNumber(): bigint {\n return this.bitnumber;\n }\n\n getQueryId(): bigint {\n return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;\n }\n\n static fromQueryId(queryId: bigint): HighloadQueryId {\n const shift = queryId >> BIT_NUMBER_SIZE;\n const bitnumber = queryId & 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n static fromSeqno(i: bigint): HighloadQueryId {\n const shift = i / 1023n;\n const bitnumber = i % 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n /**\n * @return {bigint} [0 .. 8380415]\n */\n toSeqno(): bigint {\n return this.bitnumber + this.shift * 1023n;\n }\n}\n\nexport function queryId(): bigint {\n const ts = Math.floor(Date.now() / 1000) - 30;\n\n return BigInt(ts % (1 << 23))\n}","export class NoActiveSessionError extends Error {\n public readonly address: string;\n\n constructor(address: string) {\n super(`No active session found for ${address}`);\n this.name = 'NoActiveSessionError';\n this.address = address;\n }\n}\n\n\nexport const SessionExpiredOrNotProvided = new Error('Session is expired or never provided')"],"names":["LOG_PREFIX","IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","iframe","loadPromise","e","timeoutPromise","attachStart","lastError","attempt","masterAddress","address","message","messages","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","DEFAULT_ORDINARY_SMART_ACCOUNT_CODE","ORDINARY_SMART_ACCOUNT_HEADER","calculateSmartAccountAddressFromStateInit","owner","factory","ordinarySmartAccountCode","code","Cell","data","contractAddress","StormWallet","tonClient","config","Address","walletAddress","smartAccountAddress","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer","BIT_NUMBER_SIZE","MAX_BIT_NUMBER","MAX_SHIFT","HighloadQueryId","shift","bitnumber","q","newBitnumber","newShift","queryId","i","ts","SessionExpiredOrNotProvided"],"mappings":"6aAiBA,MAAMA,EAAa,4BAEZ,MAAMC,CAAc,CAQzB,YAAYC,EAA2B,CAPtBC,EAAA,aACAA,EAAA,iBACAA,EAAA,8BAAyB,KAClCA,EAAA,eACAA,EAAA,aAAsB,aACbA,EAAA,iBAsCTA,EAAA,qBAAiB,GAA6B,CAOhD,GANA,OAAO,EAAE,MAAS,UAAY,EAAE,OAAS,MAGzC,EAAE,OAAQ,EAAE,OAAS,EAAE,WAAY,E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,EAAE,UAAYD,EACVC,EAAE,UAAY,EAAS,MAAA,IAAI,MAAM,mBAAmB,EACxD,GAAIA,EAAE,UAAYL,EAAsB,MAAA,IAAI,MAAM,mBAAmB,EAC9D,OAAAK,CAAA,CAIT,SAAU,CACJ,IAAAC,EAAe,KAAK,UAAY,GAChCC,EAAW,KAAK,MAEpB,GAAIA,IAAaN,GAAaK,EAAgBN,EAAiB,GACvD,MAAA,IAAI,MAAM,UAAU,EAG5B,GAAIM,EAAeN,IACFM,EAAA,GACHC,GAAA,GACRA,EAAWN,GACP,MAAA,IAAI,MAAM,UAAU,EAIvB,OAAAC,EAAgB,sBAAsBK,EAAUD,CAAY,CAAA,CAGrE,SAAU,CAER,MAAO,EADO,KAAK,WAAcN,EAAiB,IAAO,KAAK,QAAUC,EAChE,CAGV,UAAmB,CACjB,OAAO,KAAK,KAAA,CAGd,cAAuB,CACrB,OAAO,KAAK,SAAA,CAGd,YAAqB,CACX,OAAA,KAAK,OAASF,GAAmB,KAAK,SAAA,CAGhD,OAAO,YAAYS,EAAkC,CACnD,MAAML,EAAQK,GAAWT,EACnBK,EAAYI,EAAU,MACrB,OAAA,KAAK,sBAAsBL,EAAOC,CAAS,CAAA,CAGpD,OAAO,UAAUK,EAA4B,CAC3C,MAAMN,EAAQM,EAAI,MACZL,EAAYK,EAAI,MACf,OAAA,KAAK,sBAAsBN,EAAOC,CAAS,CAAA,CAMpD,SAAkB,CACT,OAAA,KAAK,UAAY,KAAK,MAAQ,KAAA,CAEzC,CAEO,SAASI,GAAkB,CAChC,MAAME,EAAK,KAAK,MAAM,KAAK,IAAI,EAAI,GAAI,EAAI,GAEpC,OAAA,OAAOA,GAAM,GAAK,GAAG,CAC9B,CC3Ea,MAAAC,EAA8B,IAAI,MAAM,sCAAsC"}
|
|
1
|
+
{"version":3,"file":"wallet-core.umd.cjs","sources":["../src/version.ts","../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.ts","../src/utils/query-id.ts","../src/error.ts"],"sourcesContent":["declare const __VERSION__: string;\n\nexport const VERSION = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'dev';\n","import {\n ActiveSessionsResponse,\n AdapterState,\n ConnectResponse,\n CreateTransferRequest,\n CreateTransferResponse,\n EmptyResponse,\n GetPublicKeyResponse,\n IframeAdapterProps,\n SignRequest,\n SignResponse,\n Timeouts,\n} from '../types';\nimport { VERSION } from '../version';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\n\nconst LOG_PREFIX = `[embedded-wallet v${VERSION}]`;\n\nexport class IframeAdapter {\n private readonly host: string;\n private readonly timeouts: Required<Timeouts>;\n private readonly waitingForResponse = new Map<string, Waiter>();\n private iframe?: HTMLIFrameElement;\n private state: AdapterState = 'not-ready';\n private readonly i18nInit?: IframeAdapterProps['i18n'];\n private iframeVersion?: string;\n private iframeError?: Error;\n\n constructor(props: IframeAdapterProps) {\n this.host = props.host;\n this.timeouts = {\n init: 1000,\n connect: 60000,\n disconnect: 1000,\n sign: 1000,\n createTransfer: 1000,\n activeSessions: 1000,\n getPublicKey: 1000,\n resetDevice: 1000,\n ...props.timeouts,\n };\n this.i18nInit = props.i18n;\n }\n\n private async sendMessage<R>(payload: unknown, timeout: number): Promise<R> {\n const messageId = Math.random().toString();\n const response = Promise.race([\n new Promise<R>((resolve, reject) => {\n this.waitingForResponse.set(messageId, [resolve, reject]);\n }),\n new Promise<R>((_, reject) => {\n setTimeout(() => {\n reject(new Error('Response timeout'));\n }, timeout);\n }),\n ]);\n this.iframe?.contentWindow?.postMessage({ id: messageId, payload }, this.host);\n return response;\n }\n\n private setupMessageListener() {\n window.addEventListener('message', this.handleMessage);\n }\n\n private handleMessage = (e: MessageEvent<unknown>) => {\n if (typeof e.data !== 'object' || e.data === null) {\n return;\n }\n\n // Handle iframe-ready message\n if ('type' in e.data && e.data.type === 'iframe-ready') {\n const data = e.data as { type: string; version?: string; timestamp?: number };\n this.iframeVersion = data.version;\n console.log(LOG_PREFIX, `iframe ready, version: ${data.version}`);\n\n // Check version compatibility\n if (data.version) {\n const iframeMajor = data.version.split('.')[0];\n const coreMajor = VERSION.split('.')[0];\n if (iframeMajor !== coreMajor) {\n console.warn(LOG_PREFIX, `Version mismatch: wallet-core=${VERSION}, iframe-host=${data.version}`);\n }\n }\n return;\n }\n\n // Handle iframe-error message\n if ('type' in e.data && e.data.type === 'iframe-error') {\n const data = e.data as { type: string; error?: string; stack?: string };\n console.error(LOG_PREFIX, 'iframe error:', data.error, data.stack);\n this.iframeError = new Error(data.error || 'Unknown iframe error');\n return;\n }\n\n if (!('id' in e.data) || !('status' in e.data)) {\n return;\n }\n if (typeof e.data.id !== 'string' || typeof e.data.status !== 'string') {\n return;\n }\n const waiter = this.waitingForResponse.get(e.data.id);\n if (!waiter) {\n return;\n }\n const [resolve, reject] = waiter;\n this.waitingForResponse.delete(e.data.id);\n if (e.data.status === 'success') {\n if ('payload' in e.data) {\n resolve(e.data.payload);\n } else {\n resolve(undefined);\n }\n } else {\n if ('error' in e.data) {\n reject(new Error(e.data.error as string));\n } else {\n reject(new Error('Unknown error'));\n }\n }\n };\n\n private async attachIframe(root: HTMLElement): Promise<void> {\n const iframe = document.createElement('iframe');\n iframe.src = this.host;\n iframe.frameBorder = '0';\n iframe.width = '100%';\n iframe.height = '100%';\n\n const loadPromise = new Promise<void>((resolve, reject) => {\n iframe.addEventListener('load', () => resolve(), { once: true });\n iframe.addEventListener('error', (e) => reject(e), { once: true });\n });\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n setTimeout(() => reject(new Error('Iframe load timeout')), this.timeouts.init);\n });\n\n root.appendChild(iframe);\n this.iframe = iframe;\n return Promise.race([loadPromise, timeoutPromise]);\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state !== 'not-ready') {\n return;\n }\n\n this.state = 'initializing';\n\n try {\n // Setup message listener before attaching iframe to catch early messages\n this.setupMessageListener();\n\n console.log(LOG_PREFIX, 'attaching to root', root);\n const attachStart = performance.now();\n await this.attachIframe(root);\n console.log(LOG_PREFIX, `iframe attached in ${Math.round(performance.now() - attachStart)}ms`);\n\n // Check if iframe reported an error during initialization\n if (this.iframeError) {\n throw this.iframeError;\n }\n\n console.log(LOG_PREFIX, 'sending ping');\n\n let lastError: Error | undefined;\n for (let attempt = 1; attempt <= 5; attempt++) {\n // Check for iframe errors between attempts\n if (this.iframeError) {\n throw this.iframeError;\n }\n\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n console.log(LOG_PREFIX, 'pong received');\n this.state = 'ready';\n return;\n } catch (e) {\n lastError = e instanceof Error ? e : new Error(String(e));\n console.warn(LOG_PREFIX, `ping attempt ${attempt}/5 failed:`, lastError.message);\n if (attempt < 5) {\n await new Promise(resolve => setTimeout(resolve, 200));\n }\n }\n }\n\n throw new Error(`${LOG_PREFIX} ping retries exceeded: ${lastError?.message}`);\n } catch (e) {\n this.destroy();\n throw e;\n }\n }\n\n destroy(): void {\n if (this.state === 'not-ready') {\n return;\n }\n\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n\n for (const [, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n\n this.iframe?.remove();\n this.iframe = undefined;\n }\n\n async connect(masterAddress: string): Promise<ConnectResponse> {\n return this.sendMessage({ type: 'connect', address: masterAddress }, this.timeouts.connect);\n }\n\n\n\n async getPublicKey(address: string): Promise<GetPublicKeyResponse> {\n return this.sendMessage({ type: \"get-public-key\", address }, this.timeouts.getPublicKey);\n }\n\n async resetDevice(address: string): Promise<EmptyResponse> {\n return this.sendMessage({ type: \"reset-device\", address }, this.timeouts.resetDevice);\n }\n\n async signMessage(masterAddress: string, message: SignRequest): Promise<SignResponse> {\n return this.sendMessage({ type: 'sign', address: masterAddress, message }, this.timeouts.sign);\n }\n\n async signMessages(masterAddress: string, messages: SignRequest[]): Promise<{ hashes: Uint8Array[]; signatures: Uint8Array[]; }> {\n return this.sendMessage({ type: 'sign-many', address: masterAddress, messages }, this.timeouts.sign);\n }\n\n async createTransfer(masterAddress: string, message: CreateTransferRequest): Promise<CreateTransferResponse> {\n return this.sendMessage({\n type: 'create-transfer',\n address: masterAddress,\n data: message,\n }, this.timeouts.createTransfer);\n }\n\n async getActiveSessions(): Promise<ActiveSessionsResponse> {\n return this.sendMessage({ type: 'active-sessions' }, this.timeouts.activeSessions);\n }\n\n async disconnect(masterAddress: string): Promise<void> {\n return this.sendMessage({ type: 'disconnect', address: masterAddress }, this.timeouts.disconnect);\n }\n\n getIframeVersion(): string | undefined {\n return this.iframeVersion;\n }\n}\n","import { beginCell, Cell, DictionaryValue, Slice } from \"@ton/ton\";\n\nexport const unpackPublicKeys = (cs: Slice): Buffer => {\n return cs.loadBuffer(32);\n}\n\nexport const packPublicKeys = (publicKeys: Buffer): Cell => {\n return beginCell().storeBuffer(publicKeys, 32).endCell();\n}\n\nexport const PublicKeysValue: DictionaryValue<Buffer> = {\n serialize: (src: Buffer, builder) => {\n builder.storeBuilder(packPublicKeys(src).asBuilder());\n },\n parse: (src) => {\n return unpackPublicKeys(src);\n },\n};\n","import { Address, beginCell, Cell, contractAddress, Dictionary, toNano, TonClient } from \"@ton/ton\";\nimport { PublicKeysValue } from \"./utils/packers\";\n\ntype StormWalletConfig = {\n smartAccountMasterAddress: string;\n}\n\nexport enum SmartAccountInternalOp {\n deploy_account = 0x764019e5,\n add_new_user_public_key = 0x220c4c19,\n remove_user_public_key = 0x7427ce1f,\n execute_limit_order = 0x1c0af2cb,\n execute_orders_bundle = 0xf38e7e65,\n set_code = 0x9c0f3220,\n add_request_to_add_new_user_public_key = 0x03cc29e8,\n add_request_to_remove_user_public_key = 0x07d25def,\n remove_all_keys_except_current = 0x5f9d0940\n}\n\nexport const DEFAULT_ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000d3cb310c6345907411bee7fd03c8688ae26a620314eb93f4bba111e4cb869b4cc801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e58203dbea8209e1338070f83774fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f843410403d563745f\"\nconst ORDINARY_SMART_ACCOUNT_HEADER = 0;\n\nexport function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address, ordinarySmartAccountCode: string): Address {\n const code = Cell.fromHex(ordinarySmartAccountCode);\n\n const data = beginCell()\n .storeUint(ORDINARY_SMART_ACCOUNT_HEADER, 8)\n .storeAddress(factory)\n .storeAddress(owner)\n .storeDict(null)\n .endCell()\n\n return contractAddress(0, {code, data});\n}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig, private readonly ordinarySmartAccountCode = DEFAULT_ORDINARY_SMART_ACCOUNT_CODE) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address): Address {\n return calculateSmartAccountAddressFromStateInit(owner, Address.parse(this.config.smartAccountMasterAddress), this.ordinarySmartAccountCode);\n }\n\n async getSmartAccountAddress(walletAddress: string): Promise<Address> {\n const result = await this.tonClient.runMethod(Address.parse(this.config.smartAccountMasterAddress), 'get_nft_address_by_index', [\n {\n type: 'int',\n value: BigInt(`0x${Address.parse(walletAddress).hash.toString('hex')}`)\n }\n ])\n return result.stack.readAddress()\n }\n\n async getSmartAccountData(smartAccountAddress: string) {\n const address = Address.parse(smartAccountAddress)\n try {\n const result = await this.tonClient.runMethod(address, 'get_storage_data')\n const stack = result.stack\n\n const index = stack.readBigNumber();\n const collectionAddress = stack.readAddress();\n const masterWalletAddress = stack.readAddress();\n\n\n const pksCell = stack.readCellOpt()\n let publicKeys: bigint[] = []\n\n if (pksCell) {\n publicKeys = Dictionary.loadDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell(), pksCell).keys();\n }\n\n const adminAddress = stack.readAddress();\n const backendPublicKeys = Dictionary.loadDirect(\n Dictionary.Keys.Uint(8),\n PublicKeysValue,\n stack.readCell()\n ).values();\n\n const seqno = stack.readNumber();\n\n return {\n index,\n collectionAddress,\n masterWalletAddress,\n publicKeys,\n adminAddress,\n backendPublicKeys,\n seqno,\n }\n } catch (e) {\n if ((e as Error).message.endsWith('-13')) {\n return null\n }\n throw e\n }\n }\n\n createDeploySmartAccountTx(publicKey: Buffer, transferAmount: bigint) {\n const publicKeys: Dictionary<bigint, Cell> = Dictionary.empty(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell());\n publicKeys.set(bufferToBigInt(publicKey), beginCell().endCell());\n\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.deploy_account, 32)\n .storeUint(0, 64)\n .storeDict(publicKeys)\n .endCell();\n\n return {\n address: this.config.smartAccountMasterAddress,\n payload: payload.toBoc().toString('base64'),\n amount: transferAmount,\n }\n }\n\n createAddPublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.add_new_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemovePublicKeyTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_user_public_key, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05')\n }\n }\n\n createRemoveAllKeysExceptCurrentTx(smartAccountAddress: string, publicKey: Buffer) {\n const payload = beginCell()\n .storeUint(SmartAccountInternalOp.remove_all_keys_except_current, 32)\n .storeUint(0, 64)\n .storeBuffer(publicKey)\n .endCell();\n\n return {\n address: smartAccountAddress,\n payload: payload.toBoc().toString('base64'),\n amount: toNano('0.05'), // при необходимости настрой сумму\n }\n }\n}\n\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n","const BIT_NUMBER_SIZE = 10n; // 10 bit\n// const SHIFT_SIZE = 13n; // 13 bit\nconst MAX_BIT_NUMBER = 1022n;\nconst MAX_SHIFT = 8191n; // 2^13 = 8192\n\nexport class HighloadQueryId {\n private shift: bigint; // [0 .. 8191]\n private bitnumber: bigint; // [0 .. 1022]\n\n constructor() {\n this.shift = 0n;\n this.bitnumber = 0n;\n }\n\n static fromShiftAndBitNumber(shift: bigint, bitnumber: bigint): HighloadQueryId {\n const q = new HighloadQueryId();\n q.shift = shift;\n if (q.shift < 0) throw new Error('invalid shift');\n if (q.shift > MAX_SHIFT) throw new Error('invalid shift');\n q.bitnumber = bitnumber;\n if (q.bitnumber < 0) throw new Error('invalid bitnumber');\n if (q.bitnumber > MAX_BIT_NUMBER) throw new Error('invalid bitnumber');\n return q;\n }\n\n\n getNext() {\n let newBitnumber = this.bitnumber + 1n;\n let newShift = this.shift;\n\n if (newShift === MAX_SHIFT && newBitnumber > (MAX_BIT_NUMBER - 1n)) {\n throw new Error('Overload'); // NOTE: we left one queryId for emergency withdraw\n }\n\n if (newBitnumber > MAX_BIT_NUMBER) {\n newBitnumber = 0n;\n newShift += 1n;\n if (newShift > MAX_SHIFT) {\n throw new Error('Overload')\n }\n }\n\n return HighloadQueryId.fromShiftAndBitNumber(newShift, newBitnumber);\n }\n\n hasNext() {\n const isEnd = this.bitnumber >= (MAX_BIT_NUMBER - 1n) && this.shift === MAX_SHIFT; // NOTE: we left one queryId for emergency withdraw;\n return !isEnd;\n }\n\n getShift(): bigint {\n return this.shift;\n }\n\n getBitNumber(): bigint {\n return this.bitnumber;\n }\n\n getQueryId(): bigint {\n return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;\n }\n\n static fromQueryId(queryId: bigint): HighloadQueryId {\n const shift = queryId >> BIT_NUMBER_SIZE;\n const bitnumber = queryId & 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n static fromSeqno(i: bigint): HighloadQueryId {\n const shift = i / 1023n;\n const bitnumber = i % 1023n;\n return this.fromShiftAndBitNumber(shift, bitnumber);\n }\n\n /**\n * @return {bigint} [0 .. 8380415]\n */\n toSeqno(): bigint {\n return this.bitnumber + this.shift * 1023n;\n }\n}\n\nexport function queryId(): bigint {\n const ts = Math.floor(Date.now() / 1000) - 30;\n\n return BigInt(ts % (1 << 23))\n}","export class NoActiveSessionError extends Error {\n public readonly address: string;\n\n constructor(address: string) {\n super(`No active session found for ${address}`);\n this.name = 'NoActiveSessionError';\n this.address = address;\n }\n}\n\n\nexport const SessionExpiredOrNotProvided = new Error('Session is expired or never provided')"],"names":["VERSION","LOG_PREFIX","IframeAdapter","props","__publicField","data","iframeMajor","coreMajor","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","iframe","loadPromise","e","timeoutPromise","attachStart","lastError","attempt","masterAddress","address","message","messages","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","DEFAULT_ORDINARY_SMART_ACCOUNT_CODE","ORDINARY_SMART_ACCOUNT_HEADER","calculateSmartAccountAddressFromStateInit","owner","factory","ordinarySmartAccountCode","code","Cell","contractAddress","StormWallet","tonClient","config","Address","walletAddress","smartAccountAddress","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer","BIT_NUMBER_SIZE","MAX_BIT_NUMBER","MAX_SHIFT","HighloadQueryId","shift","bitnumber","q","newBitnumber","newShift","queryId","i","ts","SessionExpiredOrNotProvided"],"mappings":"6aAEa,MAAAA,EAA+C,SCetDC,EAAa,qBAAqBD,CAAO,IAExC,MAAME,CAAc,CAUzB,YAAYC,EAA2B,CATtBC,EAAA,aACAA,EAAA,iBACAA,EAAA,8BAAyB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