@ton-community/ton-ledger 7.1.0-pre.0 → 7.2.0-pre.1
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/TonTransport.d.ts +24 -0
- package/dist/TonTransport.js +378 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/utils/getInit.d.ts +1 -1
- package/dist/utils/getInit.js +7 -7
- package/package.json +1 -1
package/dist/TonTransport.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import Transport from "@ledgerhq/hw-transport";
|
|
3
3
|
import { Address, Cell, SendMode, StateInit } from "@ton/core";
|
|
4
|
+
export type KnownJetton = {
|
|
5
|
+
symbol: string;
|
|
6
|
+
masterAddress: Address;
|
|
7
|
+
};
|
|
8
|
+
export declare const KNOWN_JETTONS: KnownJetton[];
|
|
4
9
|
export type TonPayloadFormat = {
|
|
5
10
|
type: 'unsafe';
|
|
6
11
|
message: Cell;
|
|
@@ -16,6 +21,10 @@ export type TonPayloadFormat = {
|
|
|
16
21
|
customPayload: Cell | null;
|
|
17
22
|
forwardAmount: bigint;
|
|
18
23
|
forwardPayload: Cell | null;
|
|
24
|
+
knownJetton: {
|
|
25
|
+
jettonId: number;
|
|
26
|
+
workchain: number;
|
|
27
|
+
} | null;
|
|
19
28
|
} | {
|
|
20
29
|
type: 'nft-transfer';
|
|
21
30
|
queryId: bigint | null;
|
|
@@ -74,6 +83,11 @@ export type TonPayloadFormat = {
|
|
|
74
83
|
queryId: bigint | null;
|
|
75
84
|
swapId: Buffer;
|
|
76
85
|
};
|
|
86
|
+
export declare function parseMessage(cell: Cell, opts?: {
|
|
87
|
+
disallowUnsafe?: boolean;
|
|
88
|
+
disallowModification?: boolean;
|
|
89
|
+
encodeJettonBurnEthAddressAsHex?: boolean;
|
|
90
|
+
}): TonPayloadFormat | undefined;
|
|
77
91
|
export type SignDataRequest = {
|
|
78
92
|
type: 'plaintext';
|
|
79
93
|
text: string;
|
|
@@ -94,6 +108,8 @@ export declare class TonTransport {
|
|
|
94
108
|
testOnly?: boolean;
|
|
95
109
|
bounceable?: boolean;
|
|
96
110
|
chain?: number;
|
|
111
|
+
subwalletId?: number;
|
|
112
|
+
walletVersion?: 'v3r2' | 'v4';
|
|
97
113
|
}): Promise<{
|
|
98
114
|
address: string;
|
|
99
115
|
publicKey: Buffer;
|
|
@@ -102,6 +118,8 @@ export declare class TonTransport {
|
|
|
102
118
|
testOnly?: boolean;
|
|
103
119
|
bounceable?: boolean;
|
|
104
120
|
chain?: number;
|
|
121
|
+
subwalletId?: number;
|
|
122
|
+
walletVersion?: 'v3r2' | 'v4';
|
|
105
123
|
}): Promise<{
|
|
106
124
|
address: string;
|
|
107
125
|
publicKey: Buffer;
|
|
@@ -114,6 +132,8 @@ export declare class TonTransport {
|
|
|
114
132
|
testOnly?: boolean;
|
|
115
133
|
bounceable?: boolean;
|
|
116
134
|
chain?: number;
|
|
135
|
+
subwalletId?: number;
|
|
136
|
+
walletVersion?: 'v3r2' | 'v4';
|
|
117
137
|
}): Promise<{
|
|
118
138
|
signature: Buffer;
|
|
119
139
|
hash: Buffer;
|
|
@@ -139,4 +159,8 @@ export declare class TonTransport {
|
|
|
139
159
|
includeWalletOp: boolean;
|
|
140
160
|
};
|
|
141
161
|
}) => Promise<Cell>;
|
|
162
|
+
getSettings(): Promise<{
|
|
163
|
+
blindSigningEnabled: boolean;
|
|
164
|
+
expertMode: boolean;
|
|
165
|
+
}>;
|
|
142
166
|
}
|
package/dist/TonTransport.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TonTransport = void 0;
|
|
3
|
+
exports.TonTransport = exports.parseMessage = exports.KNOWN_JETTONS = void 0;
|
|
4
4
|
const core_1 = require("@ton/core");
|
|
5
5
|
const crypto_1 = require("@ton/crypto");
|
|
6
6
|
const teslabot_1 = require("teslabot");
|
|
@@ -13,7 +13,339 @@ const INS_ADDRESS = 0x05;
|
|
|
13
13
|
const INS_SIGN_TX = 0x06;
|
|
14
14
|
const INS_PROOF = 0x08;
|
|
15
15
|
const INS_SIGN_DATA = 0x09;
|
|
16
|
+
const INS_SETTINGS = 0x0A;
|
|
16
17
|
const DEFAULT_SUBWALLET_ID = 698983191;
|
|
18
|
+
exports.KNOWN_JETTONS = [
|
|
19
|
+
{
|
|
20
|
+
symbol: 'USDT',
|
|
21
|
+
masterAddress: core_1.Address.parse('EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs'),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
symbol: 'NOT',
|
|
25
|
+
masterAddress: core_1.Address.parse('EQAvlWFDxGF2lXm67y4yzC17wYKD9A0guwPkMs1gOsM__NOT'),
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
symbol: 'tsTON',
|
|
29
|
+
masterAddress: core_1.Address.parse('EQC98_qAmNEptUtPc7W6xdHh_ZHrBUFpw5Ft_IzNU20QAJav'),
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
symbol: 'wsTON',
|
|
33
|
+
masterAddress: core_1.Address.parse('EQB0SoxuGDx5qjVt0P_bPICFeWdFLBmVopHhjgfs0q-wsTON'),
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
symbol: 'hTON',
|
|
37
|
+
masterAddress: core_1.Address.parse('EQDPdq8xjAhytYqfGSX8KcFWIReCufsB9Wdg0pLlYSO_h76w'),
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
symbol: 'stTON',
|
|
41
|
+
masterAddress: core_1.Address.parse('EQDNhy-nxYFgUqzfUzImBEP67JqsyMIcyk2S5_RwNNEYku0k'),
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
const dnsWalletKey = Buffer.from([0xe8, 0xd4, 0x40, 0x50, 0x87, 0x3d, 0xba, 0x86, 0x5a, 0xa7, 0xc1, 0x70, 0xab, 0x4c, 0xce, 0x64,
|
|
45
|
+
0xd9, 0x08, 0x39, 0xa3, 0x4d, 0xcf, 0xd6, 0xcf, 0x71, 0xd1, 0x4e, 0x02, 0x05, 0x44, 0x3b, 0x1b]);
|
|
46
|
+
function normalizeQueryId(qid) {
|
|
47
|
+
return qid === 0n ? null : qid;
|
|
48
|
+
}
|
|
49
|
+
function parseMessage(cell, opts) {
|
|
50
|
+
const params = {
|
|
51
|
+
disallowUnsafe: false,
|
|
52
|
+
disallowModification: false,
|
|
53
|
+
encodeJettonBurnEthAddressAsHex: true,
|
|
54
|
+
...opts,
|
|
55
|
+
};
|
|
56
|
+
if (cell.hash().equals(new core_1.Cell().hash())) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
let s = cell.beginParse();
|
|
60
|
+
try {
|
|
61
|
+
const op = s.loadUint(32);
|
|
62
|
+
switch (op) {
|
|
63
|
+
case 0: {
|
|
64
|
+
const str = s.loadStringTail();
|
|
65
|
+
s.endParse();
|
|
66
|
+
if (str.length > 120) {
|
|
67
|
+
throw new Error('Comment must be at most 120 ASCII characters long');
|
|
68
|
+
}
|
|
69
|
+
for (const c of str) {
|
|
70
|
+
if (c.charCodeAt(0) < 0x20 || c.charCodeAt(0) >= 0x7f) {
|
|
71
|
+
throw new Error('Comment must only contain printable ASCII characters');
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
type: 'comment',
|
|
76
|
+
text: str,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
case 0x0f8a7ea5: {
|
|
80
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
81
|
+
const amount = s.loadCoins();
|
|
82
|
+
const destination = s.loadAddress();
|
|
83
|
+
const responseDestination = s.loadAddress();
|
|
84
|
+
const customPayload = s.loadMaybeRef();
|
|
85
|
+
const forwardAmount = s.loadCoins();
|
|
86
|
+
let forwardPayload = null;
|
|
87
|
+
if (s.loadBit()) {
|
|
88
|
+
forwardPayload = s.loadRef();
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const p = s.asCell();
|
|
92
|
+
s = new core_1.Cell().beginParse(); // clear the slice
|
|
93
|
+
if (!p.hash().equals(new core_1.Cell().hash())) {
|
|
94
|
+
if (params.disallowModification) {
|
|
95
|
+
throw new Error('Jetton transfer message would be modified');
|
|
96
|
+
}
|
|
97
|
+
forwardPayload = p;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
s.endParse();
|
|
101
|
+
return {
|
|
102
|
+
type: 'jetton-transfer',
|
|
103
|
+
queryId,
|
|
104
|
+
amount,
|
|
105
|
+
destination,
|
|
106
|
+
responseDestination,
|
|
107
|
+
customPayload,
|
|
108
|
+
forwardAmount,
|
|
109
|
+
forwardPayload,
|
|
110
|
+
knownJetton: null,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
case 0x5fcc3d14: {
|
|
114
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
115
|
+
const newOwner = s.loadAddress();
|
|
116
|
+
const responseDestination = s.loadAddress();
|
|
117
|
+
const customPayload = s.loadMaybeRef();
|
|
118
|
+
const forwardAmount = s.loadCoins();
|
|
119
|
+
let forwardPayload = null;
|
|
120
|
+
if (s.loadBit()) {
|
|
121
|
+
forwardPayload = s.loadRef();
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
const p = s.asCell();
|
|
125
|
+
s = new core_1.Cell().beginParse(); // clear the slice
|
|
126
|
+
if (!p.hash().equals(new core_1.Cell().hash())) {
|
|
127
|
+
if (params.disallowModification) {
|
|
128
|
+
throw new Error('Jetton transfer message would be modified');
|
|
129
|
+
}
|
|
130
|
+
forwardPayload = p;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
s.endParse();
|
|
134
|
+
return {
|
|
135
|
+
type: 'nft-transfer',
|
|
136
|
+
queryId,
|
|
137
|
+
newOwner,
|
|
138
|
+
responseDestination,
|
|
139
|
+
customPayload,
|
|
140
|
+
forwardAmount,
|
|
141
|
+
forwardPayload,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
case 0x595f07bc: {
|
|
145
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
146
|
+
const amount = s.loadCoins();
|
|
147
|
+
const responseDestination = s.loadAddress();
|
|
148
|
+
let customPayload = s.loadMaybeRef();
|
|
149
|
+
s.endParse();
|
|
150
|
+
if (params.encodeJettonBurnEthAddressAsHex && customPayload !== null && customPayload.bits.length === 160 && customPayload.refs.length === 0) {
|
|
151
|
+
const cs = customPayload.beginParse();
|
|
152
|
+
customPayload = cs.loadBuffer(20);
|
|
153
|
+
cs.endParse();
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
type: 'jetton-burn',
|
|
157
|
+
queryId,
|
|
158
|
+
amount,
|
|
159
|
+
responseDestination,
|
|
160
|
+
customPayload,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
case 0x7258a69b: {
|
|
164
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
165
|
+
const address = s.loadAddress();
|
|
166
|
+
s.endParse();
|
|
167
|
+
return {
|
|
168
|
+
type: 'add-whitelist',
|
|
169
|
+
queryId,
|
|
170
|
+
address,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
case 0x1000: {
|
|
174
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
175
|
+
const amount = s.loadCoins();
|
|
176
|
+
s.endParse();
|
|
177
|
+
return {
|
|
178
|
+
type: 'single-nominator-withdraw',
|
|
179
|
+
queryId,
|
|
180
|
+
amount,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
case 0x1001: {
|
|
184
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
185
|
+
const address = s.loadAddress();
|
|
186
|
+
s.endParse();
|
|
187
|
+
return {
|
|
188
|
+
type: 'single-nominator-change-validator',
|
|
189
|
+
queryId,
|
|
190
|
+
address,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
case 0x47d54391: {
|
|
194
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
195
|
+
let appId = null;
|
|
196
|
+
if (s.remainingBits > 0) {
|
|
197
|
+
appId = s.loadUintBig(64);
|
|
198
|
+
}
|
|
199
|
+
s.endParse();
|
|
200
|
+
return {
|
|
201
|
+
type: 'tonstakers-deposit',
|
|
202
|
+
queryId,
|
|
203
|
+
appId,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
case 0x69fb306c: {
|
|
207
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
208
|
+
const votingAddress = s.loadAddress();
|
|
209
|
+
const expirationDate = s.loadUint(48);
|
|
210
|
+
const vote = s.loadBit();
|
|
211
|
+
const needConfirmation = s.loadBit();
|
|
212
|
+
s.endParse();
|
|
213
|
+
return {
|
|
214
|
+
type: 'vote-for-proposal',
|
|
215
|
+
queryId,
|
|
216
|
+
votingAddress,
|
|
217
|
+
expirationDate,
|
|
218
|
+
vote,
|
|
219
|
+
needConfirmation,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
case 0x4eb1f0f9: {
|
|
223
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
224
|
+
const key = s.loadBuffer(32);
|
|
225
|
+
if (key.equals(dnsWalletKey)) {
|
|
226
|
+
if (s.remainingRefs > 0) {
|
|
227
|
+
const vs = s.loadRef().beginParse();
|
|
228
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
229
|
+
// tolerate the Maybe bit
|
|
230
|
+
if (!s.loadBit())
|
|
231
|
+
throw new Error('Incorrect change DNS record message');
|
|
232
|
+
}
|
|
233
|
+
s.endParse();
|
|
234
|
+
const type = vs.loadUint(16);
|
|
235
|
+
if (type !== 0x9fd3) {
|
|
236
|
+
throw new Error('Wrong DNS record type');
|
|
237
|
+
}
|
|
238
|
+
const address = vs.loadAddress();
|
|
239
|
+
const flags = vs.loadUint(8);
|
|
240
|
+
if (flags > 1) {
|
|
241
|
+
throw new Error('DNS wallet record must have flags 0 or 1');
|
|
242
|
+
}
|
|
243
|
+
let capabilities = (flags & 1) > 0 ? { isWallet: false } : null;
|
|
244
|
+
if (capabilities !== null) {
|
|
245
|
+
while (vs.loadBit()) {
|
|
246
|
+
const cap = vs.loadUint(16);
|
|
247
|
+
if (cap === 0x2177) {
|
|
248
|
+
if (capabilities.isWallet && params.disallowModification) {
|
|
249
|
+
throw new Error('DNS change record message would be modified');
|
|
250
|
+
}
|
|
251
|
+
capabilities.isWallet = true;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
throw new Error('Unknown DNS wallet record capability');
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return {
|
|
259
|
+
type: 'change-dns-record',
|
|
260
|
+
queryId,
|
|
261
|
+
record: {
|
|
262
|
+
type: 'wallet',
|
|
263
|
+
value: {
|
|
264
|
+
address,
|
|
265
|
+
capabilities,
|
|
266
|
+
},
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
272
|
+
// tolerate the Maybe bit
|
|
273
|
+
if (s.loadBit())
|
|
274
|
+
throw new Error('Incorrect change DNS record message');
|
|
275
|
+
}
|
|
276
|
+
s.endParse();
|
|
277
|
+
return {
|
|
278
|
+
type: 'change-dns-record',
|
|
279
|
+
queryId,
|
|
280
|
+
record: {
|
|
281
|
+
type: 'wallet',
|
|
282
|
+
value: null,
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
else {
|
|
288
|
+
if (s.remainingRefs > 0) {
|
|
289
|
+
const value = s.loadRef();
|
|
290
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
291
|
+
// tolerate the Maybe bit
|
|
292
|
+
if (!s.loadBit())
|
|
293
|
+
throw new Error('Incorrect change DNS record message');
|
|
294
|
+
}
|
|
295
|
+
s.endParse();
|
|
296
|
+
return {
|
|
297
|
+
type: 'change-dns-record',
|
|
298
|
+
queryId,
|
|
299
|
+
record: {
|
|
300
|
+
type: 'unknown',
|
|
301
|
+
key,
|
|
302
|
+
value,
|
|
303
|
+
},
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
308
|
+
// tolerate the Maybe bit
|
|
309
|
+
if (s.loadBit())
|
|
310
|
+
throw new Error('Incorrect change DNS record message');
|
|
311
|
+
}
|
|
312
|
+
s.endParse();
|
|
313
|
+
return {
|
|
314
|
+
type: 'change-dns-record',
|
|
315
|
+
queryId,
|
|
316
|
+
record: {
|
|
317
|
+
type: 'unknown',
|
|
318
|
+
key,
|
|
319
|
+
value: null,
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
case 0x8: {
|
|
326
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
327
|
+
const swapId = s.loadBuffer(32);
|
|
328
|
+
s.endParse();
|
|
329
|
+
return {
|
|
330
|
+
type: 'token-bridge-pay-swap',
|
|
331
|
+
queryId,
|
|
332
|
+
swapId,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
throw new Error('Unknown op: ' + op);
|
|
337
|
+
}
|
|
338
|
+
catch (e) {
|
|
339
|
+
if (params.disallowUnsafe) {
|
|
340
|
+
throw e;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
type: 'unsafe',
|
|
345
|
+
message: cell,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
exports.parseMessage = parseMessage;
|
|
17
349
|
function chunks(buf, n) {
|
|
18
350
|
const nc = Math.ceil(buf.length / n);
|
|
19
351
|
const cs = [];
|
|
@@ -26,6 +358,9 @@ function processAddressFlags(opts) {
|
|
|
26
358
|
const bounceable = opts?.bounceable ?? true;
|
|
27
359
|
const testOnly = opts?.testOnly ?? false;
|
|
28
360
|
const chain = opts?.chain ?? 0;
|
|
361
|
+
const subwalletId = opts?.subwalletId ?? 698983191;
|
|
362
|
+
const walletVersion = opts?.walletVersion ?? 'v3r2';
|
|
363
|
+
let specifiers = undefined;
|
|
29
364
|
let flags = 0x00;
|
|
30
365
|
if (testOnly) {
|
|
31
366
|
flags |= 0x01;
|
|
@@ -33,7 +368,14 @@ function processAddressFlags(opts) {
|
|
|
33
368
|
if (chain === -1) {
|
|
34
369
|
flags |= 0x02;
|
|
35
370
|
}
|
|
36
|
-
|
|
371
|
+
if (subwalletId !== 698983191 || walletVersion !== 'v4') {
|
|
372
|
+
flags |= 0x04;
|
|
373
|
+
specifiers = {
|
|
374
|
+
subwalletId,
|
|
375
|
+
isV3R2: walletVersion === 'v3r2',
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
return { bounceable, testOnly, chain, flags, specifiers };
|
|
37
379
|
}
|
|
38
380
|
function convertPayload(input) {
|
|
39
381
|
let payload = null;
|
|
@@ -71,15 +413,25 @@ function convertPayload(input) {
|
|
|
71
413
|
let b = (0, core_1.beginCell)()
|
|
72
414
|
.storeUint(input.type === 'jetton-transfer' ? 0x0f8a7ea5 : 0x5fcc3d14, 32);
|
|
73
415
|
let d = Buffer.alloc(0);
|
|
416
|
+
let flags = 0;
|
|
74
417
|
if (input.queryId !== null) {
|
|
75
|
-
|
|
418
|
+
flags |= 1;
|
|
419
|
+
}
|
|
420
|
+
if (input.type === 'jetton-transfer' && input.knownJetton !== null) {
|
|
421
|
+
flags |= 2;
|
|
422
|
+
}
|
|
423
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(flags)]);
|
|
424
|
+
if (input.queryId !== null) {
|
|
425
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
76
426
|
b = b.storeUint(input.queryId, 64);
|
|
77
427
|
}
|
|
78
428
|
else {
|
|
79
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
80
429
|
b = b.storeUint(0, 64);
|
|
81
430
|
}
|
|
82
431
|
if (input.type === 'jetton-transfer') {
|
|
432
|
+
if (input.knownJetton !== null) {
|
|
433
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint16)(input.knownJetton.jettonId), (0, ledgerWriter_1.writeUint8)(input.knownJetton.workchain)]);
|
|
434
|
+
}
|
|
83
435
|
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(input.amount)]);
|
|
84
436
|
b = b.storeCoins(input.amount);
|
|
85
437
|
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.destination)]);
|
|
@@ -397,14 +749,14 @@ class TonTransport {
|
|
|
397
749
|
// Check path
|
|
398
750
|
validatePath(path);
|
|
399
751
|
// Resolve flags
|
|
400
|
-
const { bounceable, testOnly, chain } = processAddressFlags(opts);
|
|
752
|
+
const { bounceable, testOnly, chain, specifiers } = processAddressFlags(opts);
|
|
401
753
|
// Get public key
|
|
402
754
|
let response = await this.#doRequest(INS_ADDRESS, 0x00, 0x00, pathElementsToBuffer(path.map((v) => v + 0x80000000)));
|
|
403
755
|
if (response.length !== 32) {
|
|
404
756
|
throw Error('Invalid response');
|
|
405
757
|
}
|
|
406
758
|
// Contract
|
|
407
|
-
const contract = (0, getInit_1.getInit)(
|
|
759
|
+
const contract = (0, getInit_1.getInit)(response, specifiers?.subwalletId ?? 698983191, specifiers?.isV3R2 ?? false);
|
|
408
760
|
const address = (0, core_1.contractAddress)(chain, contract);
|
|
409
761
|
return { address: address.toString({ bounceable, testOnly }), publicKey: response };
|
|
410
762
|
}
|
|
@@ -412,14 +764,18 @@ class TonTransport {
|
|
|
412
764
|
// Check path
|
|
413
765
|
validatePath(path);
|
|
414
766
|
// Resolve flags
|
|
415
|
-
const { bounceable, testOnly, chain, flags } = processAddressFlags(opts);
|
|
767
|
+
const { bounceable, testOnly, chain, flags, specifiers } = processAddressFlags(opts);
|
|
768
|
+
let r = pathElementsToBuffer(path.map((v) => v + 0x80000000));
|
|
769
|
+
if (specifiers !== undefined) {
|
|
770
|
+
r = Buffer.concat([r, (0, ledgerWriter_1.writeUint8)(specifiers.isV3R2 ? 1 : 0), (0, ledgerWriter_1.writeUint32)(specifiers.subwalletId)]);
|
|
771
|
+
}
|
|
416
772
|
// Get public key
|
|
417
|
-
let response = await this.#doRequest(INS_ADDRESS, 0x01, flags,
|
|
773
|
+
let response = await this.#doRequest(INS_ADDRESS, 0x01, flags, r);
|
|
418
774
|
if (response.length !== 32) {
|
|
419
775
|
throw Error('Invalid response');
|
|
420
776
|
}
|
|
421
777
|
// Contract
|
|
422
|
-
const contract = (0, getInit_1.getInit)(
|
|
778
|
+
const contract = (0, getInit_1.getInit)(response, specifiers?.subwalletId ?? 698983191, specifiers?.isV3R2 ?? false);
|
|
423
779
|
const address = (0, core_1.contractAddress)(chain, contract);
|
|
424
780
|
return { address: address.toString({ bounceable, testOnly }), publicKey: response };
|
|
425
781
|
}
|
|
@@ -428,10 +784,15 @@ class TonTransport {
|
|
|
428
784
|
validatePath(path);
|
|
429
785
|
let publicKey = (await this.getAddress(path)).publicKey;
|
|
430
786
|
// Resolve flags
|
|
431
|
-
const { flags } = processAddressFlags(opts);
|
|
787
|
+
const { flags, specifiers } = processAddressFlags(opts);
|
|
788
|
+
let specifiersBuf = Buffer.alloc(0);
|
|
789
|
+
if (specifiers !== undefined) {
|
|
790
|
+
specifiersBuf = Buffer.concat([(0, ledgerWriter_1.writeUint8)(specifiers.isV3R2 ? 1 : 0), (0, ledgerWriter_1.writeUint32)(specifiers.subwalletId)]);
|
|
791
|
+
}
|
|
432
792
|
const domainBuf = Buffer.from(params.domain, 'utf-8');
|
|
433
793
|
const reqBuf = Buffer.concat([
|
|
434
794
|
pathElementsToBuffer(path.map((v) => v + 0x80000000)),
|
|
795
|
+
specifiersBuf,
|
|
435
796
|
(0, ledgerWriter_1.writeUint8)(domainBuf.length),
|
|
436
797
|
domainBuf,
|
|
437
798
|
(0, ledgerWriter_1.writeUint64)(BigInt(params.timestamp)),
|
|
@@ -680,6 +1041,13 @@ class TonTransport {
|
|
|
680
1041
|
.storeSlice(transfer.beginParse())
|
|
681
1042
|
.endCell();
|
|
682
1043
|
};
|
|
1044
|
+
async getSettings() {
|
|
1045
|
+
let loaded = await this.#doRequest(INS_SETTINGS, 0x00, 0x00, Buffer.alloc(0));
|
|
1046
|
+
return {
|
|
1047
|
+
blindSigningEnabled: (loaded[0] & 0x01) > 0,
|
|
1048
|
+
expertMode: (loaded[0] & 0x02) > 0,
|
|
1049
|
+
};
|
|
1050
|
+
}
|
|
683
1051
|
#doRequest = async (ins, p1, p2, data) => {
|
|
684
1052
|
return this.#lock.inLock(async () => {
|
|
685
1053
|
let r = await this.transport.send(LEDGER_CLA, ins, p1, p2, data);
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { TonPayloadFormat, TonTransport, SignDataRequest } from './TonTransport';
|
|
1
|
+
export { TonPayloadFormat, TonTransport, SignDataRequest, parseMessage, KNOWN_JETTONS } from './TonTransport';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TonTransport = void 0;
|
|
3
|
+
exports.KNOWN_JETTONS = exports.parseMessage = exports.TonTransport = void 0;
|
|
4
4
|
var TonTransport_1 = require("./TonTransport");
|
|
5
5
|
Object.defineProperty(exports, "TonTransport", { enumerable: true, get: function () { return TonTransport_1.TonTransport; } });
|
|
6
|
+
Object.defineProperty(exports, "parseMessage", { enumerable: true, get: function () { return TonTransport_1.parseMessage; } });
|
|
7
|
+
Object.defineProperty(exports, "KNOWN_JETTONS", { enumerable: true, get: function () { return TonTransport_1.KNOWN_JETTONS; } });
|
package/dist/utils/getInit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { Cell } from '@ton/core';
|
|
3
|
-
export declare function getInit(
|
|
3
|
+
export declare function getInit(publicKey: Buffer, subwalletId: number, isV3R2: boolean): {
|
|
4
4
|
code: Cell;
|
|
5
5
|
data: Cell;
|
|
6
6
|
};
|
package/dist/utils/getInit.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getInit = void 0;
|
|
4
4
|
const core_1 = require("@ton/core");
|
|
5
|
-
function getInit(
|
|
6
|
-
let code = core_1.Cell.fromBoc(Buffer.from('te6ccgECFAEAAtQAART/APSkE/S88sgLAQIBIAIDAgFIBAUE+PKDCNcYINMf0x/THwL4I7vyZO1E0NMf0x/T//QE0VFDuvKhUVG68qIF+QFUEGT5EPKj+AAkpMjLH1JAyx9SMMv/UhD0AMntVPgPAdMHIcAAn2xRkyDXSpbTB9QC+wDoMOAhwAHjACHAAuMAAcADkTDjDQOkyMsfEssfy/8QERITAubQAdDTAyFxsJJfBOAi10nBIJJfBOAC0x8hghBwbHVnvSKCEGRzdHK9sJJfBeAD+kAwIPpEAcjKB8v/ydDtRNCBAUDXIfQEMFyBAQj0Cm+hMbOSXwfgBdM/yCWCEHBsdWe6kjgw4w0DghBkc3RyupJfBuMNBgcCASAICQB4AfoA9AQw+CdvIjBQCqEhvvLgUIIQcGx1Z4MesXCAGFAEywUmzxZY+gIZ9ADLaRfLH1Jgyz8gyYBA+wAGAIpQBIEBCPRZMO1E0IEBQNcgyAHPFvQAye1UAXKwjiOCEGRzdHKDHrFwgBhQBcsFUAPPFiP6AhPLassfyz/JgED7AJJfA+ICASAKCwBZvSQrb2omhAgKBrkPoCGEcNQICEekk30pkQzmkD6f+YN4EoAbeBAUiYcVnzGEAgFYDA0AEbjJftRNDXCx+AA9sp37UTQgQFA1yH0BDACyMoHy//J0AGBAQj0Cm+hMYAIBIA4PABmtznaiaEAga5Drhf/AABmvHfaiaEAQa5DrhY/AAG7SB/oA1NQi+QAFyMoHFcv/ydB3dIAYyMsFywIizxZQBfoCFMtrEszMyXP7AMhAFIEBCPRR8qcCAHCBAQjXGPoA0z/IVCBHgQEI9FHyp4IQbm90ZXB0gBjIywXLAlAGzxZQBPoCFMtqEssfyz/Jc/sAAgBsgQEI1xj6ANM/MFIkgQEI9Fnyp4IQZHN0cnB0gBjIywXLAlAFzxZQA/oCE8tqyx8Syz/Jc/sAAAr0AMntVA==', 'base64'))[0];
|
|
5
|
+
function getInit(publicKey, subwalletId, isV3R2) {
|
|
7
6
|
let data = (0, core_1.beginCell)()
|
|
8
7
|
.storeUint(0, 32) // Seqno
|
|
9
|
-
.storeUint(
|
|
10
|
-
.storeBuffer(publicKey)
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
|
|
8
|
+
.storeUint(subwalletId, 32)
|
|
9
|
+
.storeBuffer(publicKey);
|
|
10
|
+
return {
|
|
11
|
+
code: isV3R2 ? core_1.Cell.fromBase64('te6cckEBAQEAcQAA3v8AIN0gggFMl7ohggEznLqxn3Gw7UTQ0x/THzHXC//jBOCk8mCDCNcYINMf0x/TH/gjE7vyY+1E0NMf0x/T/9FRMrryoVFEuvKiBPkBVBBV+RDyo/gAkyDXSpbTB9QC+wDo0QGkyMsfyx/L/8ntVBC9ba0=') : core_1.Cell.fromBase64('te6ccgECFAEAAtQAART/APSkE/S88sgLAQIBIAIDAgFIBAUE+PKDCNcYINMf0x/THwL4I7vyZO1E0NMf0x/T//QE0VFDuvKhUVG68qIF+QFUEGT5EPKj+AAkpMjLH1JAyx9SMMv/UhD0AMntVPgPAdMHIcAAn2xRkyDXSpbTB9QC+wDoMOAhwAHjACHAAuMAAcADkTDjDQOkyMsfEssfy/8QERITAubQAdDTAyFxsJJfBOAi10nBIJJfBOAC0x8hghBwbHVnvSKCEGRzdHK9sJJfBeAD+kAwIPpEAcjKB8v/ydDtRNCBAUDXIfQEMFyBAQj0Cm+hMbOSXwfgBdM/yCWCEHBsdWe6kjgw4w0DghBkc3RyupJfBuMNBgcCASAICQB4AfoA9AQw+CdvIjBQCqEhvvLgUIIQcGx1Z4MesXCAGFAEywUmzxZY+gIZ9ADLaRfLH1Jgyz8gyYBA+wAGAIpQBIEBCPRZMO1E0IEBQNcgyAHPFvQAye1UAXKwjiOCEGRzdHKDHrFwgBhQBcsFUAPPFiP6AhPLassfyz/JgED7AJJfA+ICASAKCwBZvSQrb2omhAgKBrkPoCGEcNQICEekk30pkQzmkD6f+YN4EoAbeBAUiYcVnzGEAgFYDA0AEbjJftRNDXCx+AA9sp37UTQgQFA1yH0BDACyMoHy//J0AGBAQj0Cm+hMYAIBIA4PABmtznaiaEAga5Drhf/AABmvHfaiaEAQa5DrhY/AAG7SB/oA1NQi+QAFyMoHFcv/ydB3dIAYyMsFywIizxZQBfoCFMtrEszMyXP7AMhAFIEBCPRR8qcCAHCBAQjXGPoA0z/IVCBHgQEI9FHyp4IQbm90ZXB0gBjIywXLAlAGzxZQBPoCFMtqEssfyz/Jc/sAAgBsgQEI1xj6ANM/MFIkgQEI9Fnyp4IQZHN0cnB0gBjIywXLAlAFzxZQA/oCE8tqyx8Syz/Jc/sAAAr0AMntVA=='),
|
|
12
|
+
data: isV3R2 ? data.endCell() : data.storeBit(0).endCell(),
|
|
13
|
+
};
|
|
14
14
|
}
|
|
15
15
|
exports.getInit = getInit;
|