@storm-trade/wallet-core 1.0.13 → 1.0.15

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.
@@ -12,6 +12,7 @@ export declare type ConnectResponse = {
12
12
  export declare type CreateTransferRequest = {
13
13
  validUntil: number;
14
14
  queryId?: number;
15
+ referenceQueryId?: number;
15
16
  payload: string;
16
17
  };
17
18
 
@@ -21,6 +22,12 @@ export declare type CreateTransferResponse = {
21
22
  signature: Uint8Array;
22
23
  };
23
24
 
25
+ declare type EmptyResponse = {};
26
+
27
+ declare type GetPublicKeyResponse = {
28
+ publicKey: Uint8Array | null;
29
+ };
30
+
24
31
  export declare class IframeAdapter {
25
32
  private readonly host;
26
33
  private readonly timeouts;
@@ -35,6 +42,9 @@ export declare class IframeAdapter {
35
42
  init(root: HTMLElement): Promise<void>;
36
43
  destroy(): void;
37
44
  connect(masterAddress: string): Promise<ConnectResponse>;
45
+ senEnterPinStep(step: string): Promise<ConnectResponse>;
46
+ getPublicKey(address: string): Promise<GetPublicKeyResponse>;
47
+ resetDevice(address: string): Promise<EmptyResponse>;
38
48
  signMessage(masterAddress: string, message: SignRequest): Promise<SignResponse>;
39
49
  createTransfer(masterAddress: string, message: CreateTransferRequest): Promise<CreateTransferResponse>;
40
50
  getActiveSessions(): Promise<ActiveSessionsResponse>;
@@ -46,7 +56,7 @@ export declare type IframeAdapterProps = {
46
56
  timeouts?: Timeouts;
47
57
  };
48
58
 
49
- export declare type PingResponse = {};
59
+ export declare type PingResponse = EmptyResponse;
50
60
 
51
61
  export declare type SignRequest = {
52
62
  body: Uint8Array;
@@ -99,6 +109,9 @@ declare type Timeouts = {
99
109
  activeSessions?: number;
100
110
  createTransfer?: number;
101
111
  disconnect?: number;
112
+ setEnterPinStep?: number;
113
+ getPublicKey?: number;
114
+ resetDevice?: number;
102
115
  };
103
116
 
104
117
  export { }
@@ -2,7 +2,7 @@ var w = Object.defineProperty;
2
2
  var b = (r, e, t) => e in r ? w(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
3
  var d = (r, e, t) => b(r, typeof e != "symbol" ? e + "" : e, t);
4
4
  import { beginCell as u, Address as h, Dictionary as a, toNano as m } from "@ton/ton";
5
- class x {
5
+ class S {
6
6
  constructor(e) {
7
7
  d(this, "host");
8
8
  d(this, "timeouts");
@@ -25,6 +25,9 @@ class x {
25
25
  sign: 1e3,
26
26
  createTransfer: 1e3,
27
27
  activeSessions: 1e3,
28
+ setEnterPinStep: 1e3,
29
+ getPublicKey: 1e3,
30
+ resetDevice: 1e3,
28
31
  ...e.timeouts
29
32
  };
30
33
  }
@@ -46,7 +49,7 @@ class x {
46
49
  window.addEventListener("message", this.handleMessage);
47
50
  }
48
51
  async attachIframe(e) {
49
- this.iframe = document.createElement("iframe"), this.iframe.src = this.host, this.iframe.frameBorder = "0";
52
+ this.iframe = document.createElement("iframe"), this.iframe.src = this.host, this.iframe.frameBorder = "0", this.iframe.width = "100%", this.iframe.height = "100%";
50
53
  const t = new Promise((s, n) => {
51
54
  var i, o;
52
55
  (i = this.iframe) == null || i.addEventListener("load", async () => {
@@ -83,6 +86,15 @@ class x {
83
86
  async connect(e) {
84
87
  return this.sendMessage({ type: "connect", address: e }, this.timeouts.connect);
85
88
  }
89
+ async senEnterPinStep(e) {
90
+ return this.sendMessage({ type: "set-create-pin-step", step: e }, this.timeouts.setEnterPinStep);
91
+ }
92
+ async getPublicKey(e) {
93
+ return this.sendMessage({ type: "get-public-key", address: e }, this.timeouts.getPublicKey);
94
+ }
95
+ async resetDevice(e) {
96
+ return this.sendMessage({ type: "reset-device", address: e }, this.timeouts.resetDevice);
97
+ }
86
98
  async signMessage(e, t) {
87
99
  return this.sendMessage({ type: "sign", address: e, message: t }, this.timeouts.sign);
88
100
  }
@@ -100,9 +112,9 @@ class x {
100
112
  return this.sendMessage({ type: "disconnect", address: e }, this.timeouts.disconnect);
101
113
  }
102
114
  }
103
- const M = (r) => r.loadBuffer(32), A = (r) => u().storeBuffer(r, 32).endCell(), v = {
115
+ const M = (r) => r.loadBuffer(32), v = (r) => u().storeBuffer(r, 32).endCell(), A = {
104
116
  serialize: (r, e) => {
105
- e.storeBuilder(A(r).asBuilder());
117
+ e.storeBuilder(v(r).asBuilder());
106
118
  },
107
119
  parse: (r) => M(r)
108
120
  };
@@ -124,19 +136,19 @@ class K {
124
136
  const n = (await this.tonClient.runMethod(t, "get_storage_data")).stack, i = n.readBigNumber(), o = n.readAddress(), c = n.readAddress(), l = n.readCellOpt();
125
137
  let g = [];
126
138
  l && (g = a.loadDirect(a.Keys.BigUint(256), a.Values.Cell(), l).keys());
127
- const f = n.readAddress(), y = a.loadDirect(
139
+ const y = n.readAddress(), p = a.loadDirect(
128
140
  a.Keys.Uint(8),
129
- v,
141
+ A,
130
142
  n.readCell()
131
- ).values(), p = n.readNumber();
143
+ ).values(), f = n.readNumber();
132
144
  return {
133
145
  index: i,
134
146
  collectionAddress: o,
135
147
  masterWalletAddress: c,
136
148
  publicKeys: g,
137
- adminAddress: f,
138
- backendPublicKeys: y,
139
- seqno: p
149
+ adminAddress: y,
150
+ backendPublicKeys: p,
151
+ seqno: f
140
152
  };
141
153
  } catch (s) {
142
154
  if (s.message.endsWith("-13"))
@@ -175,7 +187,7 @@ function B(r) {
175
187
  return BigInt("0x" + r.toString("hex"));
176
188
  }
177
189
  export {
178
- x as IframeAdapter,
190
+ S as IframeAdapter,
179
191
  K as StormWallet
180
192
  };
181
193
  //# sourceMappingURL=wallet-core.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-core.js","sources":["../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.ts"],"sourcesContent":["import {\n ActiveSessionsResponse,\n AdapterState,\n ConnectResponse,\n CreateTransferRequest,\n CreateTransferResponse,\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\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 ...props.timeouts,\n };\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 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 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' }, 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 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 add_new_user_public_key = 0x44ced4bc,\n remove_user_public_key = 0xd4b5ac6e,\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}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig) {\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(0x8bb43aa7, 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\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n"],"names":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","StormWallet","tonClient","config","walletAddress","Address","smartAccountAddress","address","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer"],"mappings":";;;;AAcO,MAAMA,EAAc;AAAA,EAOzB,YAAYC,GAA2B;AANtB,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA,gDAAyB,IAAoB;AACtD,IAA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UAAAtB,IAAuCiB,EAAW,MAAMA,EAAW,KAAK,QAAQ,GAAG,GAAGA,EAAW,OAAO,KAAA,CAAM;AACpH,IAAAjB,EAAW,IAAIuB,EAAeF,CAAS,GAAGpB,EAAU,EAAE,SAAS;AAE/D,UAAMjB,IAAUiB,EAAA,EACb,UAAU,YAAY,EAAE,EACxB,UAAU,GAAG,EAAE,EACf,UAAUD,CAAU,EACpB,QAAQ;AAEJ,WAAA;AAAA,MACL,SAAS,KAAK,OAAO;AAAA,MACrB,SAAShB,EAAQ,QAAQ,SAAS,QAAQ;AAAA,MAC1C,QAAQsC;AAAA,IACV;AAAA,EAAA;AAAA,EAGF,qBAAqBZ,GAA6BW,GAAmB;AACnE,UAAMrC,IAAUiB,EAAA,EACb,UAAU,YAAgD,EAAE,EAC5D,UAAU,GAAG,EAAE,EACf,YAAYoB,CAAS,EACrB,QAAQ;AAGJ,WAAA;AAAA,MACL,SAASX;AAAA,MACT,SAAS1B,EAAQ,QAAQ,SAAS,QAAQ;AAAA,MAC1C,QAAQwC,EAAO,MAAM;AAAA,IACvB;AAAA,EAAA;AAAA,EAGF,wBAAwBd,GAA6BW,GAAmB;AACtE,UAAMrC,IAAUiB,EAAA,EACb,UAAU,YAA+C,EAAE,EAC3D,UAAU,GAAG,EAAE,EACf,YAAYoB,CAAS,EACrB,QAAQ;AAGJ,WAAA;AAAA,MACL,SAASX;AAAA,MACT,SAAS1B,EAAQ,QAAQ,SAAS,QAAQ;AAAA,MAC1C,QAAQwC,EAAO,MAAM;AAAA,IACvB;AAAA,EAAA;AAEJ;AAEO,SAASD,EAAeE,GAAwB;AACrD,SAAO,OAAO,OAAOA,EAAO,SAAS,KAAK,CAAC;AAC7C;"}
1
+ {"version":3,"file":"wallet-core.js","sources":["../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.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\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 setEnterPinStep: 1000,\n getPublicKey: 1000,\n resetDevice: 1000,\n ...props.timeouts,\n };\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 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' }, 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 async senEnterPinStep(step: string): Promise<ConnectResponse> {\n return this.sendMessage({ type: 'set-create-pin-step', step }, this.timeouts.setEnterPinStep);\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 add_new_user_public_key = 0x44ced4bc,\n remove_user_public_key = 0xd4b5ac6e,\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}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig) {\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(0x8bb43aa7, 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\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n"],"names":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","step","address","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","StormWallet","tonClient","config","walletAddress","Address","smartAccountAddress","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer"],"mappings":";;;;AAgBO,MAAMA,EAAc;AAAA,EAOzB,YAAYC,GAA2B;AANtB,IAAAC,EAAA;AACA,IAAAA,EAAA;AACA,IAAAA,EAAA,gDAAyB,IAAoB;AACtD,IAAAA,EAAA;AACA,IAAAA,EAAA,eAAsB;AAsCtB,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;AACtB,MAAA,EAAE,KAAK,WAAW,YAChB,aAAa,EAAE,OACTC,EAAA,EAAE,KAAK,OAAO,IAEtBA,EAAQ,MAAS,IAGf,WAAW,EAAE,OACfC,EAAO,IAAI,MAAM,EAAE,KAAK,KAAe,CAAC,IAEjCA,EAAA,IAAI,MAAM,eAAe,CAAC;AAAA,IAIvC;AAhEE,SAAK,OAAOJ,EAAM,MAClB,KAAK,WAAW;AAAA,MACd,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,gBAAgB;AAAA,MAChB,gBAAgB;AAAA,MA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AAA;AAAA,MACL,SAAS,KAAK,OAAO;AAAA,MACrB,SAASlB,EAAQ,QAAQ,SAAS,QAAQ;AAAA,MAC1C,QAAQuC;AAAA,IACV;AAAA,EAAA;AAAA,EAGF,qBAAqBX,GAA6BU,GAAmB;AACnE,UAAMtC,IAAUmB,EAAA,EACb,UAAU,YAAgD,EAAE,EAC5D,UAAU,GAAG,EAAE,EACf,YAAYmB,CAAS,EACrB,QAAQ;AAGJ,WAAA;AAAA,MACL,SAASV;AAAA,MACT,SAAS5B,EAAQ,QAAQ,SAAS,QAAQ;AAAA,MAC1C,QAAQyC,EAAO,MAAM;AAAA,IACvB;AAAA,EAAA;AAAA,EAGF,wBAAwBb,GAA6BU,GAAmB;AACtE,UAAMtC,IAAUmB,EAAA,EACb,UAAU,YAA+C,EAAE,EAC3D,UAAU,GAAG,EAAE,EACf,YAAYmB,CAAS,EACrB,QAAQ;AAGJ,WAAA;AAAA,MACL,SAASV;AAAA,MACT,SAAS5B,EAAQ,QAAQ,SAAS,QAAQ;AAAA,MAC1C,QAAQyC,EAAO,MAAM;AAAA,IACvB;AAAA,EAAA;AAEJ;AAEO,SAASD,EAAeE,GAAwB;AACrD,SAAO,OAAO,OAAOA,EAAO,SAAS,KAAK,CAAC;AAC7C;"}
@@ -1,2 +1,2 @@
1
- (function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@ton/ton")):typeof define=="function"&&define.amd?define(["exports","@ton/ton"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a.WalletCore={},a.ton))})(this,function(a,t){"use strict";var M=Object.defineProperty;var v=(a,t,l)=>t in a?M(a,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):a[t]=l;var c=(a,t,l)=>v(a,typeof t!="symbol"?t+"":t,l);class l{constructor(e){c(this,"host");c(this,"timeouts");c(this,"waitingForResponse",new Map);c(this,"iframe");c(this,"state","not-ready");c(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 s=this.waitingForResponse.get(e.data.id);if(!s)return;const[r,n]=s;e.data.status==="success"?"payload"in e.data?r(e.data.payload):r(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,...e.timeouts}}async sendMessage(e,s){var o,d;const r=Math.random().toString(),n=Promise.race([new Promise((u,h)=>{this.waitingForResponse.set(r,[u,h])}),new Promise((u,h)=>{setTimeout(()=>{h(new Error("Response timeout"))},s)})]);return(d=(o=this.iframe)==null?void 0:o.contentWindow)==null||d.postMessage({id:r,payload:e},this.host),n}setupMessageListener(){window.addEventListener("message",this.handleMessage)}async attachIframe(e){this.iframe=document.createElement("iframe"),this.iframe.src=this.host,this.iframe.frameBorder="0";const s=new Promise((r,n)=>{var o,d;(o=this.iframe)==null||o.addEventListener("load",async()=>{r()},{once:!0}),(d=this.iframe)==null||d.addEventListener("error",u=>{n(u)},{once:!0})});return e.appendChild(this.iframe),s}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 s=5;for(;s>0;)try{await this.sendMessage({type:"ping"},this.timeouts.init);break}catch{if(s--,s===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[s,r]of this.waitingForResponse.values())r(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 signMessage(e,s){return this.sendMessage({type:"sign",address:e,message:s},this.timeouts.sign)}async createTransfer(e,s){return this.sendMessage({type:"create-transfer",address:e,data:s},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 f=i=>i.loadBuffer(32),m=i=>t.beginCell().storeBuffer(i,32).endCell(),y={serialize:(i,e)=>{e.storeBuilder(m(i).asBuilder())},parse:i=>f(i)};class p{constructor(e,s){this.tonClient=e,this.config=s}async getSmartAccountAddress(e){return(await this.tonClient.runMethod(t.Address.parse(this.config.smartAccountMasterAddress),"get_nft_address_by_index",[{type:"int",value:BigInt(`0x${t.Address.parse(e).hash.toString("hex")}`)}])).stack.readAddress()}async getSmartAccountData(e){const s=t.Address.parse(e);try{const n=(await this.tonClient.runMethod(s,"get_storage_data")).stack,o=n.readBigNumber(),d=n.readAddress(),u=n.readAddress(),h=n.readCellOpt();let g=[];h&&(g=t.Dictionary.loadDirect(t.Dictionary.Keys.BigUint(256),t.Dictionary.Values.Cell(),h).keys());const b=n.readAddress(),A=t.Dictionary.loadDirect(t.Dictionary.Keys.Uint(8),y,n.readCell()).values(),C=n.readNumber();return{index:o,collectionAddress:d,masterWalletAddress:u,publicKeys:g,adminAddress:b,backendPublicKeys:A,seqno:C}}catch(r){if(r.message.endsWith("-13"))return null;throw r}}createDeploySmartAccountTx(e,s){const r=t.Dictionary.empty(t.Dictionary.Keys.BigUint(256),t.Dictionary.Values.Cell());r.set(w(e),t.beginCell().endCell());const n=t.beginCell().storeUint(2343844519,32).storeUint(0,64).storeDict(r).endCell();return{address:this.config.smartAccountMasterAddress,payload:n.toBoc().toString("base64"),amount:s}}createAddPublicKeyTx(e,s){const r=t.beginCell().storeUint(1154405564,32).storeUint(0,64).storeBuffer(s).endCell();return{address:e,payload:r.toBoc().toString("base64"),amount:t.toNano("0.05")}}createRemovePublicKeyTx(e,s){const r=t.beginCell().storeUint(3568675950,32).storeUint(0,64).storeBuffer(s).endCell();return{address:e,payload:r.toBoc().toString("base64"),amount:t.toNano("0.05")}}}function w(i){return BigInt("0x"+i.toString("hex"))}a.IframeAdapter=l,a.StormWallet=p,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
1
+ (function(n,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("@ton/ton")):typeof define=="function"&&define.amd?define(["exports","@ton/ton"],t):(n=typeof globalThis<"u"?globalThis:n||self,t(n.WalletCore={},n.ton))})(this,function(n,t){"use strict";var A=Object.defineProperty;var C=(n,t,l)=>t in n?A(n,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):n[t]=l;var c=(n,t,l)=>C(n,typeof t!="symbol"?t+"":t,l);class l{constructor(e){c(this,"host");c(this,"timeouts");c(this,"waitingForResponse",new Map);c(this,"iframe");c(this,"state","not-ready");c(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 s=this.waitingForResponse.get(e.data.id);if(!s)return;const[i,r]=s;e.data.status==="success"?"payload"in e.data?i(e.data.payload):i(void 0):"error"in e.data?r(new Error(e.data.error)):r(new Error("Unknown error"))});this.host=e.host,this.timeouts={init:1e3,connect:6e4,disconnect:1e3,sign:1e3,createTransfer:1e3,activeSessions:1e3,setEnterPinStep:1e3,getPublicKey:1e3,resetDevice:1e3,...e.timeouts}}async sendMessage(e,s){var o,d;const i=Math.random().toString(),r=Promise.race([new Promise((u,h)=>{this.waitingForResponse.set(i,[u,h])}),new Promise((u,h)=>{setTimeout(()=>{h(new Error("Response timeout"))},s)})]);return(d=(o=this.iframe)==null?void 0:o.contentWindow)==null||d.postMessage({id:i,payload:e},this.host),r}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 s=new Promise((i,r)=>{var o,d;(o=this.iframe)==null||o.addEventListener("load",async()=>{i()},{once:!0}),(d=this.iframe)==null||d.addEventListener("error",u=>{r(u)},{once:!0})});return e.appendChild(this.iframe),s}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 s=5;for(;s>0;)try{await this.sendMessage({type:"ping"},this.timeouts.init);break}catch{if(s--,s===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[s,i]of this.waitingForResponse.values())i(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 senEnterPinStep(e){return this.sendMessage({type:"set-create-pin-step",step:e},this.timeouts.setEnterPinStep)}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,s){return this.sendMessage({type:"sign",address:e,message:s},this.timeouts.sign)}async createTransfer(e,s){return this.sendMessage({type:"create-transfer",address:e,data:s},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 y=a=>a.loadBuffer(32),m=a=>t.beginCell().storeBuffer(a,32).endCell(),f={serialize:(a,e)=>{e.storeBuilder(m(a).asBuilder())},parse:a=>y(a)};class p{constructor(e,s){this.tonClient=e,this.config=s}async getSmartAccountAddress(e){return(await this.tonClient.runMethod(t.Address.parse(this.config.smartAccountMasterAddress),"get_nft_address_by_index",[{type:"int",value:BigInt(`0x${t.Address.parse(e).hash.toString("hex")}`)}])).stack.readAddress()}async getSmartAccountData(e){const s=t.Address.parse(e);try{const r=(await this.tonClient.runMethod(s,"get_storage_data")).stack,o=r.readBigNumber(),d=r.readAddress(),u=r.readAddress(),h=r.readCellOpt();let g=[];h&&(g=t.Dictionary.loadDirect(t.Dictionary.Keys.BigUint(256),t.Dictionary.Values.Cell(),h).keys());const b=r.readAddress(),M=t.Dictionary.loadDirect(t.Dictionary.Keys.Uint(8),f,r.readCell()).values(),v=r.readNumber();return{index:o,collectionAddress:d,masterWalletAddress:u,publicKeys:g,adminAddress:b,backendPublicKeys:M,seqno:v}}catch(i){if(i.message.endsWith("-13"))return null;throw i}}createDeploySmartAccountTx(e,s){const i=t.Dictionary.empty(t.Dictionary.Keys.BigUint(256),t.Dictionary.Values.Cell());i.set(w(e),t.beginCell().endCell());const r=t.beginCell().storeUint(2343844519,32).storeUint(0,64).storeDict(i).endCell();return{address:this.config.smartAccountMasterAddress,payload:r.toBoc().toString("base64"),amount:s}}createAddPublicKeyTx(e,s){const i=t.beginCell().storeUint(1154405564,32).storeUint(0,64).storeBuffer(s).endCell();return{address:e,payload:i.toBoc().toString("base64"),amount:t.toNano("0.05")}}createRemovePublicKeyTx(e,s){const i=t.beginCell().storeUint(3568675950,32).storeUint(0,64).storeBuffer(s).endCell();return{address:e,payload:i.toBoc().toString("base64"),amount:t.toNano("0.05")}}}function w(a){return BigInt("0x"+a.toString("hex"))}n.IframeAdapter=l,n.StormWallet=p,Object.defineProperty(n,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"],"sourcesContent":["import {\n ActiveSessionsResponse,\n AdapterState,\n ConnectResponse,\n CreateTransferRequest,\n CreateTransferResponse,\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\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 ...props.timeouts,\n };\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 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 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' }, 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 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 add_new_user_public_key = 0x44ced4bc,\n remove_user_public_key = 0xd4b5ac6e,\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}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig) {\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(0x8bb43aa7, 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\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n"],"names":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","StormWallet","tonClient","config","walletAddress","Address","smartAccountAddress","address","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer"],"mappings":"6aAcO,MAAMA,CAAc,CAOzB,YAAYC,EAA2B,CANtBC,EAAA,aACAA,EAAA,iBACAA,EAAA,8BAAyB,KAClCA,EAAA,eACAA,EAAA,aAAsB,aAmCtBA,EAAA,qBAAiB,GAA6B,CAO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CACL,QAASX,EACT,QAAS1B,EAAQ,QAAQ,SAAS,QAAQ,EAC1C,OAAQwC,SAAO,MAAM,CACvB,CAAA,CAGF,wBAAwBd,EAA6BW,EAAmB,CACtE,MAAMrC,EAAUiB,EAAA,UAAA,EACb,UAAU,WAA+C,EAAE,EAC3D,UAAU,EAAG,EAAE,EACf,YAAYoB,CAAS,EACrB,QAAQ,EAGJ,MAAA,CACL,QAASX,EACT,QAAS1B,EAAQ,QAAQ,SAAS,QAAQ,EAC1C,OAAQwC,SAAO,MAAM,CACvB,CAAA,CAEJ,CAEO,SAASD,EAAeE,EAAwB,CACrD,OAAO,OAAO,KAAOA,EAAO,SAAS,KAAK,CAAC,CAC7C"}
1
+ {"version":3,"file":"wallet-core.umd.cjs","sources":["../src/adapters/iframe-adapter.ts","../src/utils/packers.ts","../src/wallet.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\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 setEnterPinStep: 1000,\n getPublicKey: 1000,\n resetDevice: 1000,\n ...props.timeouts,\n };\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 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' }, 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 async senEnterPinStep(step: string): Promise<ConnectResponse> {\n return this.sendMessage({ type: 'set-create-pin-step', step }, this.timeouts.setEnterPinStep);\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 add_new_user_public_key = 0x44ced4bc,\n remove_user_public_key = 0xd4b5ac6e,\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}\n\nexport class StormWallet {\n constructor(private readonly tonClient: TonClient, private readonly config: StormWalletConfig) {\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(0x8bb43aa7, 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\nexport function bufferToBigInt(buffer: Buffer): bigint {\n return BigInt('0x' + buffer.toString('hex'));\n}\n"],"names":["IframeAdapter","props","__publicField","waiter","resolve","reject","payload","timeout","messageId","response","_","_b","_a","root","p","e","retryCount","masterAddress","step","address","message","unpackPublicKeys","cs","packPublicKeys","publicKeys","beginCell","PublicKeysValue","src","builder","StormWallet","tonClient","config","walletAddress","Address","smartAccountAddress","stack","index","collectionAddress","masterWalletAddress","pksCell","Dictionary","adminAddress","backendPublicKeys","seqno","publicKey","transferAmount","bufferToBigInt","toNano","buffer"],"mappings":"6aAgBO,MAAMA,CAAc,CAOzB,YAAYC,EAA2B,CANtBC,EAAA,aACAA,EAAA,iBACAA,EAAA,8BAAyB,KAClCA,EAAA,eACAA,EAAA,aAAsB,aAsCtBA,EAAA,qBAAiB,GAA6B,CAOhD,GANA,OAAO,EAAE,MAAS,UAAY,EAAE,OAAS,MAGzC,EAAE,OAAQ,EAAE,OAAS,EAAE,WAAY,EAAE,OAGrC,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U,EAAG,EAAE,EACf,UAAUD,CAAU,EACpB,QAAQ,EAEJ,MAAA,CACL,QAAS,KAAK,OAAO,0BACrB,QAASlB,EAAQ,QAAQ,SAAS,QAAQ,EAC1C,OAAQuC,CACV,CAAA,CAGF,qBAAqBX,EAA6BU,EAAmB,CACnE,MAAMtC,EAAUmB,EAAA,UAAA,EACb,UAAU,WAAgD,EAAE,EAC5D,UAAU,EAAG,EAAE,EACf,YAAYmB,CAAS,EACrB,QAAQ,EAGJ,MAAA,CACL,QAASV,EACT,QAAS5B,EAAQ,QAAQ,SAAS,QAAQ,EAC1C,OAAQyC,SAAO,MAAM,CACvB,CAAA,CAGF,wBAAwBb,EAA6BU,EAAmB,CACtE,MAAMtC,EAAUmB,EAAA,UAAA,EACb,UAAU,WAA+C,EAAE,EAC3D,UAAU,EAAG,EAAE,EACf,YAAYmB,CAAS,EACrB,QAAQ,EAGJ,MAAA,CACL,QAASV,EACT,QAAS5B,EAAQ,QAAQ,SAAS,QAAQ,EAC1C,OAAQyC,SAAO,MAAM,CACvB,CAAA,CAEJ,CAEO,SAASD,EAAeE,EAAwB,CACrD,OAAO,OAAO,KAAOA,EAAO,SAAS,KAAK,CAAC,CAC7C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storm-trade/wallet-core",
3
- "version": "1.0.13",
3
+ "version": "1.0.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "files": [
@@ -10,6 +10,12 @@
10
10
  "module": "./dist/wallet-core",
11
11
  "types": "./dist/wallet-core",
12
12
  "description": "",
13
+ "scripts": {
14
+ "dev": "vite",
15
+ "build": "tsc && vite build",
16
+ "test": "vitest",
17
+ "prepublishOnly": "npm run build"
18
+ },
13
19
  "keywords": [],
14
20
  "author": "",
15
21
  "license": "ISC",
@@ -24,10 +30,5 @@
24
30
  "@ton/core": ">=0.60.0",
25
31
  "@ton/crypto": ">=3.3.0",
26
32
  "@ton/ton": ">=15.2.1"
27
- },
28
- "scripts": {
29
- "dev": "vite",
30
- "build": "tsc && vite build",
31
- "test": "vitest"
32
33
  }
33
- }
34
+ }