@storm-trade/wallet-core 1.0.19 → 1.0.20
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
CHANGED
|
@@ -5,6 +5,8 @@ export declare type ActiveSessionsResponse = {
|
|
|
5
5
|
addresses: string[];
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
+
export declare function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address): Address;
|
|
9
|
+
|
|
8
10
|
export declare type ConnectResponse = {
|
|
9
11
|
publicKey: Uint8Array;
|
|
10
12
|
};
|
|
@@ -99,7 +101,7 @@ export declare class StormWallet {
|
|
|
99
101
|
private readonly tonClient;
|
|
100
102
|
private readonly config;
|
|
101
103
|
constructor(tonClient: TonClient, config: StormWalletConfig);
|
|
102
|
-
calculateSmartAccountAddressFromStateInit(owner: Address
|
|
104
|
+
calculateSmartAccountAddressFromStateInit(owner: Address): Address;
|
|
103
105
|
getSmartAccountAddress(walletAddress: string): Promise<Address>;
|
|
104
106
|
getSmartAccountData(smartAccountAddress: string): Promise<{
|
|
105
107
|
index: bigint;
|
package/dist/wallet-core.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { beginCell as
|
|
5
|
-
class
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
|
+
var M = (r, e, t) => e in r ? v(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var n = (r, e, t) => M(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { beginCell as f, Address as l, Dictionary as a, toNano as m, Cell as B, contractAddress as E } from "@ton/ton";
|
|
5
|
+
class K {
|
|
6
6
|
constructor(e) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
n(this, "host");
|
|
8
|
+
n(this, "timeouts");
|
|
9
|
+
n(this, "waitingForResponse", /* @__PURE__ */ new Map());
|
|
10
|
+
n(this, "iframe");
|
|
11
|
+
n(this, "state", "not-ready");
|
|
12
|
+
n(this, "i18nInit");
|
|
13
|
+
n(this, "handleMessage", (e) => {
|
|
14
14
|
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")
|
|
15
15
|
return;
|
|
16
16
|
const t = this.waitingForResponse.get(e.data.id);
|
|
17
17
|
if (!t)
|
|
18
18
|
return;
|
|
19
|
-
const [s,
|
|
20
|
-
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 ?
|
|
19
|
+
const [s, c] = t;
|
|
20
|
+
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 ? c(new Error(e.data.error)) : c(new Error("Unknown error"));
|
|
21
21
|
});
|
|
22
22
|
this.host = e.host, this.timeouts = {
|
|
23
23
|
init: 1e3,
|
|
@@ -32,8 +32,8 @@ class N {
|
|
|
32
32
|
}, this.i18nInit = e.i18n;
|
|
33
33
|
}
|
|
34
34
|
async sendMessage(e, t) {
|
|
35
|
-
var
|
|
36
|
-
const s = Math.random().toString(),
|
|
35
|
+
var i, d;
|
|
36
|
+
const s = Math.random().toString(), c = Promise.race([
|
|
37
37
|
new Promise((o, b) => {
|
|
38
38
|
this.waitingForResponse.set(s, [o, b]);
|
|
39
39
|
}),
|
|
@@ -43,19 +43,19 @@ class N {
|
|
|
43
43
|
}, t);
|
|
44
44
|
})
|
|
45
45
|
]);
|
|
46
|
-
return (
|
|
46
|
+
return (d = (i = this.iframe) == null ? void 0 : i.contentWindow) == null || d.postMessage({ id: s, payload: e }, this.host), c;
|
|
47
47
|
}
|
|
48
48
|
setupMessageListener() {
|
|
49
49
|
window.addEventListener("message", this.handleMessage);
|
|
50
50
|
}
|
|
51
51
|
async attachIframe(e) {
|
|
52
52
|
this.iframe = document.createElement("iframe"), this.iframe.src = this.host, this.iframe.frameBorder = "0", this.iframe.width = "100%", this.iframe.height = "100%";
|
|
53
|
-
const t = new Promise((s,
|
|
54
|
-
var
|
|
55
|
-
(
|
|
53
|
+
const t = new Promise((s, c) => {
|
|
54
|
+
var i, d;
|
|
55
|
+
(i = this.iframe) == null || i.addEventListener("load", async () => {
|
|
56
56
|
s();
|
|
57
|
-
}, { once: !0 }), (
|
|
58
|
-
|
|
57
|
+
}, { once: !0 }), (d = this.iframe) == null || d.addEventListener("error", (o) => {
|
|
58
|
+
c(o);
|
|
59
59
|
}, { once: !0 });
|
|
60
60
|
});
|
|
61
61
|
return e.appendChild(this.iframe), t;
|
|
@@ -109,19 +109,22 @@ class N {
|
|
|
109
109
|
return this.sendMessage({ type: "disconnect", address: e }, this.timeouts.disconnect);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
const C = (r) => r.loadBuffer(32),
|
|
112
|
+
const C = (r) => r.loadBuffer(32), I = (r) => f().storeBuffer(r, 32).endCell(), x = {
|
|
113
113
|
serialize: (r, e) => {
|
|
114
|
-
e.storeBuilder(
|
|
114
|
+
e.storeBuilder(I(r).asBuilder());
|
|
115
115
|
},
|
|
116
116
|
parse: (r) => C(r)
|
|
117
|
-
},
|
|
117
|
+
}, R = "b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f84341040323803460", N = 0;
|
|
118
|
+
function U(r, e) {
|
|
119
|
+
const t = B.fromHex(R), s = f().storeUint(N, 8).storeAddress(e).storeAddress(r).storeDict(null).endCell();
|
|
120
|
+
return E(0, { code: t, data: s });
|
|
121
|
+
}
|
|
118
122
|
class P {
|
|
119
123
|
constructor(e, t) {
|
|
120
124
|
this.tonClient = e, this.config = t;
|
|
121
125
|
}
|
|
122
|
-
calculateSmartAccountAddressFromStateInit(e
|
|
123
|
-
|
|
124
|
-
return new l(0, c.hash());
|
|
126
|
+
calculateSmartAccountAddressFromStateInit(e) {
|
|
127
|
+
return U(e, l.parse(this.config.smartAccountMasterAddress));
|
|
125
128
|
}
|
|
126
129
|
async getSmartAccountAddress(e) {
|
|
127
130
|
return (await this.tonClient.runMethod(l.parse(this.config.smartAccountMasterAddress), "get_nft_address_by_index", [
|
|
@@ -134,22 +137,22 @@ class P {
|
|
|
134
137
|
async getSmartAccountData(e) {
|
|
135
138
|
const t = l.parse(e);
|
|
136
139
|
try {
|
|
137
|
-
const
|
|
140
|
+
const c = (await this.tonClient.runMethod(t, "get_storage_data")).stack, i = c.readBigNumber(), d = c.readAddress(), o = c.readAddress(), b = c.readCellOpt();
|
|
138
141
|
let y = [];
|
|
139
|
-
b && (y =
|
|
140
|
-
const w =
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
).values(),
|
|
142
|
+
b && (y = a.loadDirect(a.Keys.BigUint(256), a.Values.Cell(), b).keys());
|
|
143
|
+
const w = c.readAddress(), A = a.loadDirect(
|
|
144
|
+
a.Keys.Uint(8),
|
|
145
|
+
x,
|
|
146
|
+
c.readCell()
|
|
147
|
+
).values(), S = c.readNumber();
|
|
145
148
|
return {
|
|
146
|
-
index:
|
|
147
|
-
collectionAddress:
|
|
149
|
+
index: i,
|
|
150
|
+
collectionAddress: d,
|
|
148
151
|
masterWalletAddress: o,
|
|
149
152
|
publicKeys: y,
|
|
150
153
|
adminAddress: w,
|
|
151
154
|
backendPublicKeys: A,
|
|
152
|
-
seqno:
|
|
155
|
+
seqno: S
|
|
153
156
|
};
|
|
154
157
|
} catch (s) {
|
|
155
158
|
if (s.message.endsWith("-13"))
|
|
@@ -158,17 +161,17 @@ class P {
|
|
|
158
161
|
}
|
|
159
162
|
}
|
|
160
163
|
createDeploySmartAccountTx(e, t) {
|
|
161
|
-
const s =
|
|
162
|
-
s.set(
|
|
163
|
-
const
|
|
164
|
+
const s = a.empty(a.Keys.BigUint(256), a.Values.Cell());
|
|
165
|
+
s.set(_(e), f().endCell());
|
|
166
|
+
const c = f().storeUint(1983912421, 32).storeUint(0, 64).storeDict(s).endCell();
|
|
164
167
|
return {
|
|
165
168
|
address: this.config.smartAccountMasterAddress,
|
|
166
|
-
payload:
|
|
169
|
+
payload: c.toBoc().toString("base64"),
|
|
167
170
|
amount: t
|
|
168
171
|
};
|
|
169
172
|
}
|
|
170
173
|
createAddPublicKeyTx(e, t) {
|
|
171
|
-
const s =
|
|
174
|
+
const s = f().storeUint(571231257, 32).storeUint(0, 64).storeBuffer(t).endCell();
|
|
172
175
|
return {
|
|
173
176
|
address: e,
|
|
174
177
|
payload: s.toBoc().toString("base64"),
|
|
@@ -176,7 +179,7 @@ class P {
|
|
|
176
179
|
};
|
|
177
180
|
}
|
|
178
181
|
createRemovePublicKeyTx(e, t) {
|
|
179
|
-
const s =
|
|
182
|
+
const s = f().storeUint(1948765727, 32).storeUint(0, 64).storeBuffer(t).endCell();
|
|
180
183
|
return {
|
|
181
184
|
address: e,
|
|
182
185
|
payload: s.toBoc().toString("base64"),
|
|
@@ -184,7 +187,7 @@ class P {
|
|
|
184
187
|
};
|
|
185
188
|
}
|
|
186
189
|
createRemoveAllKeysExceptCurrentTx(e, t) {
|
|
187
|
-
const s =
|
|
190
|
+
const s = f().storeUint(1604127040, 32).storeUint(0, 64).storeBuffer(t).endCell();
|
|
188
191
|
return {
|
|
189
192
|
address: e,
|
|
190
193
|
payload: s.toBoc().toString("base64"),
|
|
@@ -193,16 +196,16 @@ class P {
|
|
|
193
196
|
};
|
|
194
197
|
}
|
|
195
198
|
}
|
|
196
|
-
function
|
|
199
|
+
function _(r) {
|
|
197
200
|
return BigInt("0x" + r.toString("hex"));
|
|
198
201
|
}
|
|
199
202
|
const p = 10n, u = 1022n, h = 8191n;
|
|
200
203
|
class g {
|
|
201
204
|
// [0 .. 1022]
|
|
202
205
|
constructor() {
|
|
203
|
-
|
|
206
|
+
n(this, "shift");
|
|
204
207
|
// [0 .. 8191]
|
|
205
|
-
|
|
208
|
+
n(this, "bitnumber");
|
|
206
209
|
this.shift = 0n, this.bitnumber = 0n;
|
|
207
210
|
}
|
|
208
211
|
static fromShiftAndBitNumber(e, t) {
|
|
@@ -248,16 +251,17 @@ class g {
|
|
|
248
251
|
return this.bitnumber + this.shift * 1023n;
|
|
249
252
|
}
|
|
250
253
|
}
|
|
251
|
-
function
|
|
254
|
+
function k() {
|
|
252
255
|
const r = Math.floor(Date.now() / 1e3) - 30;
|
|
253
256
|
return BigInt(r % (1 << 23));
|
|
254
257
|
}
|
|
255
|
-
const
|
|
258
|
+
const F = new Error("Session is expired or never provided");
|
|
256
259
|
export {
|
|
257
260
|
g as HighloadQueryId,
|
|
258
|
-
|
|
259
|
-
|
|
261
|
+
K as IframeAdapter,
|
|
262
|
+
F as SessionExpiredOrNotProvided,
|
|
260
263
|
P as StormWallet,
|
|
261
|
-
|
|
264
|
+
U as calculateSmartAccountAddressFromStateInit,
|
|
265
|
+
k as queryId
|
|
262
266
|
};
|
|
263
267
|
//# sourceMappingURL=wallet-core.js.map
|
package/dist/wallet-core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-core.js","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';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\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 this.iframe = document.createElement('iframe');\n this.iframe.src = this.host;\n this.iframe.frameBorder = '0';\n this.iframe.width='100%'\n this.iframe.height='100%'\n const p = new Promise<void>((resolve, reject) => {\n this.iframe?.addEventListener('load', async () => {\n resolve();\n }, { once: true });\n this.iframe?.addEventListener('error', (e) => {\n reject(e);\n }, { once: true });\n });\n root.appendChild(this.iframe);\n return p;\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state === 'not-ready') {\n this.state = 'initializing';\n console.log('[embedded-wallet] attaching to root', root);\n await this.attachIframe(root);\n console.log('[embedded-wallet] iframe attached');\n this.setupMessageListener();\n console.log('[embedded-wallet] sending ping');\n let retryCount = 5;\n while (retryCount > 0) {\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n break;\n } catch (e) {\n retryCount--;\n if (retryCount === 0) {\n this.destroy();\n throw new Error('[embedded-wallet] ping retries exceeded. Init failed');\n } else {\n console.warn('[embedded-wallet] failed to ping attached iframe retrying');\n }\n }\n }\n console.log('[embedded-wallet] pong received');\n this.state = 'ready';\n }\n }\n\n destroy(): void {\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n for (const [_, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n this.iframe?.remove();\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 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, 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\nconst ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f84341040323803460\"\n\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address): Address {\n const smartAccountCode = Cell.fromHex(ORDINARY_SMART_ACCOUNT_CODE);\n\n const data = beginCell()\n .storeUint(0, 8)\n .storeAddress(factory)\n .storeAddress(owner)\n .storeDict(null)\n .endCell()\n\n const stateInit = beginCell().storeUint(0, 2).storeMaybeRef(smartAccountCode).storeMaybeRef(data).storeUint(0, 1).endCell();\n\n return new Address(0, stateInit.hash());\n }\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":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","address","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","ORDINARY_SMART_ACCOUNT_CODE","StormWallet","tonClient","config","owner","factory","smartAccountCode","Cell","data","stateInit","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":";;;;AAgBO,MAAMA,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,YAAMC,IAAS,KAAK,mBAAmB,IAAI,EAAE,KAAK,EAAE;AACpD,UAAI,CAACA;AACH;AAEI,YAAA,CAACC,GAASC,CAAM,IAAIF;AAC1B,WAAK,mBAAmB,OAAO,EAAE,KAAK,EAAE,GACpC,EAAE,KAAK,WAAW,YAChB,aAAa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ACRA,IAAWN;AACP,YAAA,IAAI,MAAM,UAAU;AAIvB,WAAAC,EAAgB,sBAAsBK,GAAUD,CAAY;AAAA,EAAA;AAAA,EAGrE,UAAU;AAER,WAAO,EADO,KAAK,aAAcN,IAAiB,MAAO,KAAK,UAAUC;AAAA,EAChE;AAAA,EAGV,WAAmB;AACjB,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,eAAuB;AACrB,WAAO,KAAK;AAAA,EAAA;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/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';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\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 this.iframe = document.createElement('iframe');\n this.iframe.src = this.host;\n this.iframe.frameBorder = '0';\n this.iframe.width='100%'\n this.iframe.height='100%'\n const p = new Promise<void>((resolve, reject) => {\n this.iframe?.addEventListener('load', async () => {\n resolve();\n }, { once: true });\n this.iframe?.addEventListener('error', (e) => {\n reject(e);\n }, { once: true });\n });\n root.appendChild(this.iframe);\n return p;\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state === 'not-ready') {\n this.state = 'initializing';\n console.log('[embedded-wallet] attaching to root', root);\n await this.attachIframe(root);\n console.log('[embedded-wallet] iframe attached');\n this.setupMessageListener();\n console.log('[embedded-wallet] sending ping');\n let retryCount = 5;\n while (retryCount > 0) {\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n break;\n } catch (e) {\n retryCount--;\n if (retryCount === 0) {\n this.destroy();\n throw new Error('[embedded-wallet] ping retries exceeded. Init failed');\n } else {\n console.warn('[embedded-wallet] failed to ping attached iframe retrying');\n }\n }\n }\n console.log('[embedded-wallet] pong received');\n this.state = 'ready';\n }\n }\n\n destroy(): void {\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n for (const [_, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n this.iframe?.remove();\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 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\nconst ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f84341040323803460\"\nconst ORDINARY_SMART_ACCOUNT_HEADER = 0;\n\nexport function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address): Address {\n const code = Cell.fromHex(ORDINARY_SMART_ACCOUNT_CODE);\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) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address): Address {\n return calculateSmartAccountAddressFromStateInit(owner, Address.parse(this.config.smartAccountMasterAddress));\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":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","address","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","ORDINARY_SMART_ACCOUNT_CODE","ORDINARY_SMART_ACCOUNT_HEADER","calculateSmartAccountAddressFromStateInit","owner","factory","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":";;;;AAgBO,MAAMA,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,YAAMC,IAAS,KAAK,mBAAmB,IAAI,EAAE,KAAK,EAAE;AACpD,UAAI,CAACA;AACH;AAEI,YAAA,CAACC,GAASC,CAAM,IAAIF;AAC1B,WAAK,mBAAmB,OAAO,EAAE,KAAK,EAAE,GACpC,EAAE,KAAK,WAAW,YAChB,aAAa,E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HC,KAAA,IACRA,IAAWN;AACP,YAAA,IAAI,MAAM,UAAU;AAIvB,WAAAC,EAAgB,sBAAsBK,GAAUD,CAAY;AAAA,EAAA;AAAA,EAGrE,UAAU;AAER,WAAO,EADO,KAAK,aAAcN,IAAiB,MAAO,KAAK,UAAUC;AAAA,EAChE;AAAA,EAGV,WAAmB;AACjB,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,eAAuB;AACrB,WAAO,KAAK;AAAA,EAAA;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;"}
|
package/dist/wallet-core.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
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 R=Object.defineProperty;var U=(i,r,o)=>r in i?R(i,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):i[r]=o;var a=(i,r,o)=>U(i,typeof r!="symbol"?r+"":r,o);class o{constructor(e){a(this,"host");a(this,"timeouts");a(this,"waitingForResponse",new Map);a(this,"iframe");a(this,"state","not-ready");a(this,"i18nInit");a(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,c]=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?c(new Error(e.data.error)):c(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 d,f;const s=Math.random().toString(),c=Promise.race([new Promise((b,l)=>{this.waitingForResponse.set(s,[b,l])}),new Promise((b,l)=>{setTimeout(()=>{l(new Error("Response timeout"))},t)})]);return(f=(d=this.iframe)==null?void 0:d.contentWindow)==null||f.postMessage({id:s,payload:e},this.host),c}setupMessageListener(){window.addEventListener("message",this.handleMessage)}async attachIframe(e){this.iframe=document.createElement("iframe"),this.iframe.src=this.host,this.iframe.frameBorder="0",this.iframe.width="100%",this.iframe.height="100%";const t=new Promise((s,c)=>{var d,f;(d=this.iframe)==null||d.addEventListener("load",async()=>{s()},{once:!0}),(f=this.iframe)==null||f.addEventListener("error",b=>{c(b)},{once:!0})});return e.appendChild(this.iframe),t}async init(e){if(this.state==="not-ready"){this.state="initializing",console.log("[embedded-wallet] attaching to root",e),await this.attachIframe(e),console.log("[embedded-wallet] iframe attached"),this.setupMessageListener(),console.log("[embedded-wallet] sending ping");let t=5;for(;t>0;)try{await this.sendMessage({type:"ping",i18n:this.i18nInit},this.timeouts.init);break}catch{if(t--,t===0)throw this.destroy(),new Error("[embedded-wallet] ping retries exceeded. Init failed");console.warn("[embedded-wallet] failed to ping attached iframe retrying")}console.log("[embedded-wallet] pong received"),this.state="ready"}}destroy(){var e;this.state="not-ready",window.removeEventListener("message",this.handleMessage);for(const[t,s]of this.waitingForResponse.values())s(new Error("Iframe disconnected"));this.waitingForResponse.clear(),(e=this.iframe)==null||e.remove()}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 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 w=n=>n.loadBuffer(32),A=n=>r.beginCell().storeBuffer(n,32).endCell(),S={serialize:(n,e)=>{e.storeBuilder(A(n).asBuilder())},parse:n=>w(n)},v="b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f84341040323803460",C=0;function g(n,e){const t=r.Cell.fromHex(v),s=r.beginCell().storeUint(C,8).storeAddress(e).storeAddress(n).storeDict(null).endCell();return r.contractAddress(0,{code:t,data:s})}class M{constructor(e,t){this.tonClient=e,this.config=t}calculateSmartAccountAddressFromStateInit(e){return g(e,r.Address.parse(this.config.smartAccountMasterAddress))}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 c=(await this.tonClient.runMethod(t,"get_storage_data")).stack,d=c.readBigNumber(),f=c.readAddress(),b=c.readAddress(),l=c.readCellOpt();let p=[];l&&(p=r.Dictionary.loadDirect(r.Dictionary.Keys.BigUint(256),r.Dictionary.Values.Cell(),l).keys());const D=c.readAddress(),N=r.Dictionary.loadDirect(r.Dictionary.Keys.Uint(8),S,c.readCell()).values(),T=c.readNumber();return{index:d,collectionAddress:f,masterWalletAddress:b,publicKeys:p,adminAddress:D,backendPublicKeys:N,seqno:T}}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(B(e),r.beginCell().endCell());const c=r.beginCell().storeUint(1983912421,32).storeUint(0,64).storeDict(s).endCell();return{address:this.config.smartAccountMasterAddress,payload:c.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 B(n){return BigInt("0x"+n.toString("hex"))}const y=10n,u=1022n,h=8191n;class m{constructor(){a(this,"shift");a(this,"bitnumber");this.shift=0n,this.bitnumber=0n}static fromShiftAndBitNumber(e,t){const s=new m;if(s.shift=e,s.shift<0)throw new Error("invalid shift");if(s.shift>h)throw new Error("invalid shift");if(s.bitnumber=t,s.bitnumber<0)throw new Error("invalid bitnumber");if(s.bitnumber>u)throw new Error("invalid bitnumber");return s}getNext(){let e=this.bitnumber+1n,t=this.shift;if(t===h&&e>u-1n)throw new Error("Overload");if(e>u&&(e=0n,t+=1n,t>h))throw new Error("Overload");return m.fromShiftAndBitNumber(t,e)}hasNext(){return!(this.bitnumber>=u-1n&&this.shift===h)}getShift(){return this.shift}getBitNumber(){return this.bitnumber}getQueryId(){return(this.shift<<y)+this.bitnumber}static fromQueryId(e){const t=e>>y,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 E(){const n=Math.floor(Date.now()/1e3)-30;return BigInt(n%(1<<23))}const I=new Error("Session is expired or never provided");i.HighloadQueryId=m,i.IframeAdapter=o,i.SessionExpiredOrNotProvided=I,i.StormWallet=M,i.calculateSmartAccountAddressFromStateInit=g,i.queryId=E,Object.defineProperty(i,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';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\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 this.iframe = document.createElement('iframe');\n this.iframe.src = this.host;\n this.iframe.frameBorder = '0';\n this.iframe.width='100%'\n this.iframe.height='100%'\n const p = new Promise<void>((resolve, reject) => {\n this.iframe?.addEventListener('load', async () => {\n resolve();\n }, { once: true });\n this.iframe?.addEventListener('error', (e) => {\n reject(e);\n }, { once: true });\n });\n root.appendChild(this.iframe);\n return p;\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state === 'not-ready') {\n this.state = 'initializing';\n console.log('[embedded-wallet] attaching to root', root);\n await this.attachIframe(root);\n console.log('[embedded-wallet] iframe attached');\n this.setupMessageListener();\n console.log('[embedded-wallet] sending ping');\n let retryCount = 5;\n while (retryCount > 0) {\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n break;\n } catch (e) {\n retryCount--;\n if (retryCount === 0) {\n this.destroy();\n throw new Error('[embedded-wallet] ping retries exceeded. Init failed');\n } else {\n console.warn('[embedded-wallet] failed to ping attached iframe retrying');\n }\n }\n }\n console.log('[embedded-wallet] pong received');\n this.state = 'ready';\n }\n }\n\n destroy(): void {\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n for (const [_, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n this.iframe?.remove();\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 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, 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\nconst ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f84341040323803460\"\n\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address): Address {\n const smartAccountCode = Cell.fromHex(ORDINARY_SMART_ACCOUNT_CODE);\n\n const data = beginCell()\n .storeUint(0, 8)\n .storeAddress(factory)\n .storeAddress(owner)\n .storeDict(null)\n .endCell()\n\n const stateInit = beginCell().storeUint(0, 2).storeMaybeRef(smartAccountCode).storeMaybeRef(data).storeUint(0, 1).endCell();\n\n return new Address(0, stateInit.hash());\n }\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":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","address","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","ORDINARY_SMART_ACCOUNT_CODE","StormWallet","tonClient","config","owner","factory","smartAccountCode","Cell","data","stateInit","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":"6aAgBO,MAAMA,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,EAAE,OAGrC,OAAO,EAAE,KAAK,IAAO,UAAY,OAAO,EAAE,KAAK,QAAW,SAC5D,OAEF,MAAMC,EAAS,KAAK,mBAAmB,IAAI,EAAE,KAAK,EAAE,EACpD,GAAI,CAACA,EACH,OAEI,KAAA,CAACC,EAASC,CAAM,EAAIF,EAC1B,KAAK,mBAAmB,OAAO,EAAE,KAAK,EAAE,EACpC,EAAE,KAAK,SAAW,UAChB,YAAa,EAAE,KACTC,EAAA,EAAE,KAAK,OAAO,EAEtBA,EAAQ,MAAS,EAGf,UAAW,EAAE,KACfC,EAAO,IAAI,MAAM,EAAE,KAAK,KAAe,CAAC,EAEjCA,EAAA,IAAI,MAAM,eAAe,CAAC,CAIvC,GAjEE,KAAK,KAAOJ,EAAM,KAClB,KAAK,SAAW,CACd,KAAM,IACN,QAAS,IACT,WAAY,IACZ,KAAM,IACN,eAAgB,I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AAE,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/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';\n\ntype Waiter = [(value: any) => void, (e: Error) => void]\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 this.iframe = document.createElement('iframe');\n this.iframe.src = this.host;\n this.iframe.frameBorder = '0';\n this.iframe.width='100%'\n this.iframe.height='100%'\n const p = new Promise<void>((resolve, reject) => {\n this.iframe?.addEventListener('load', async () => {\n resolve();\n }, { once: true });\n this.iframe?.addEventListener('error', (e) => {\n reject(e);\n }, { once: true });\n });\n root.appendChild(this.iframe);\n return p;\n }\n\n async init(root: HTMLElement): Promise<void> {\n if (this.state === 'not-ready') {\n this.state = 'initializing';\n console.log('[embedded-wallet] attaching to root', root);\n await this.attachIframe(root);\n console.log('[embedded-wallet] iframe attached');\n this.setupMessageListener();\n console.log('[embedded-wallet] sending ping');\n let retryCount = 5;\n while (retryCount > 0) {\n try {\n await this.sendMessage({ type: 'ping', i18n: this.i18nInit }, this.timeouts.init);\n break;\n } catch (e) {\n retryCount--;\n if (retryCount === 0) {\n this.destroy();\n throw new Error('[embedded-wallet] ping retries exceeded. Init failed');\n } else {\n console.warn('[embedded-wallet] failed to ping attached iframe retrying');\n }\n }\n }\n console.log('[embedded-wallet] pong received');\n this.state = 'ready';\n }\n }\n\n destroy(): void {\n this.state = 'not-ready';\n window.removeEventListener('message', this.handleMessage);\n for (const [_, reject] of this.waitingForResponse.values()) {\n reject(new Error('Iframe disconnected'));\n }\n this.waitingForResponse.clear();\n this.iframe?.remove();\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 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\nconst ORDINARY_SMART_ACCOUNT_CODE = \"b5ee9c7241021401000460000114ff00f4a413f4bcf2c80b01020162021004bcd020c700915be001d0d3030171b0915be0fa4030ed44d0d30701f861fa4001f862fa4001f863f40430f86401d31f218210186b2edfba8e843101db3ce02182104fedc82bba8e843101db3ce02182105b0dd9f4bae30201821018a092f7ba03060b0c02f401d33ffa00fa40fa40d152408d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19182105b27f9c5c8cb1f13cb3f01fa02010704011acf16f843cf16c970598040db3c05002c718010c8cb055004cf165004fa0212cb6accc901fb0002da01d33ffa40fa00fa40d430d052528d086000beda81c3e461dc2beb1cc8c77929e81afd8ff8aa116c7b3b7040ad695c359094c801cf1601cf16c9880120f90022f90002d76503d76582020134c8cb17cb0f13cb0fcbffcbff71f90400c88b1801cf16cbffc9d001c705f2e19104070a0114ff00f4a413f4bcf2c80b080196d36c2220c700f24001d0d3030171b0f240fa403001d31f01821029c102d1ba8ea4ed44d0fa403012c705f2e29afa40d4d43001fb04ed54820898968070fb0270018306db3ce05b840ff2f0090028708010c8cb055003cf165003fa02cb6ac901fb0002b0f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f86422d70b01c0008e85328042db3c8e8c300181010bd719018042db3ce2f844f841c8cb07f842cf16f843cf16f400c9ed540f0f01d2310101d33ff8425230c705f2e1915801d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02f84301810082db3c0f01168e8301db3ce05b840ff2f00d017af8425210c705f2e19101d33ffa40fa00fa405023f844521081010bf40a6fa1c8019a01fa00305003a012fa02943158fa02e2f8441281010bf441f864030e01ae01d317d4d307d4d1fb046d6d58f823500503c8f40012f400cb3fcb17c970f843f844102655226d0107c8cb075006cf165004cf1612f400cb07ccf400ccc9ed548102e68203dbd98209e1338070f83770fb02810082db3c0f003e8210d53276db708010c8cb055005cf1624fa0214cb6a13cb1fcb3fc901fb0002012011120043bc82ff6a268698380fc30fd2000fc317d2000fc31fa02187c327c20fc217c21fc224014fbc7e7f6a268698380fc30fd2000fc317d2000fc31fa02187c327c147d2218e445997981d4678b10c1300f620c0008e1830c8709320c14097803058cb0701a4e801c9d001aa02d7198e4770800fc89322c1408e1a5331b020c20995a63701cb0795a63001cb07e203ab0302a44013e86c21c832c9d080409320c2009da520aa02522078d72413cf1602e85bc9d08308d719e2cf168b52e6a736f6e8cf16c970f842f84341040323803460\"\nconst ORDINARY_SMART_ACCOUNT_HEADER = 0;\n\nexport function calculateSmartAccountAddressFromStateInit(owner: Address, factory: Address): Address {\n const code = Cell.fromHex(ORDINARY_SMART_ACCOUNT_CODE);\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) {\n }\n\n calculateSmartAccountAddressFromStateInit(owner: Address): Address {\n return calculateSmartAccountAddressFromStateInit(owner, Address.parse(this.config.smartAccountMasterAddress));\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":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","address","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","ORDINARY_SMART_ACCOUNT_CODE","ORDINARY_SMART_ACCOUNT_HEADER","calculateSmartAccountAddressFromStateInit","owner","factory","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":"6aAgBO,MAAMA,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,EAAE,OAGrC,OAAO,EAAE,KAAK,IAAO,UAAY,OAAO,EAAE,KAAK,QAAW,SAC5D,OAEF,MAAMC,EAAS,KAAK,mBAAmB,IAAI,EAAE,KAAK,EAAE,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