@ton-community/ton-ledger 7.1.0-pre.0 → 7.1.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 +9 -0
- package/dist/TonTransport.js +313 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
package/dist/TonTransport.d.ts
CHANGED
|
@@ -74,6 +74,11 @@ export type TonPayloadFormat = {
|
|
|
74
74
|
queryId: bigint | null;
|
|
75
75
|
swapId: Buffer;
|
|
76
76
|
};
|
|
77
|
+
export declare function parseMessage(cell: Cell, opts?: {
|
|
78
|
+
disallowUnsafe?: boolean;
|
|
79
|
+
disallowModification?: boolean;
|
|
80
|
+
encodeJettonBurnEthAddressAsHex?: boolean;
|
|
81
|
+
}): TonPayloadFormat | undefined;
|
|
77
82
|
export type SignDataRequest = {
|
|
78
83
|
type: 'plaintext';
|
|
79
84
|
text: string;
|
|
@@ -139,4 +144,8 @@ export declare class TonTransport {
|
|
|
139
144
|
includeWalletOp: boolean;
|
|
140
145
|
};
|
|
141
146
|
}) => Promise<Cell>;
|
|
147
|
+
getSettings(): Promise<{
|
|
148
|
+
blindSigningEnabled: boolean;
|
|
149
|
+
expertMode: boolean;
|
|
150
|
+
}>;
|
|
142
151
|
}
|
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 = 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,312 @@ 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
|
+
const dnsWalletKey = Buffer.from([0xe8, 0xd4, 0x40, 0x50, 0x87, 0x3d, 0xba, 0x86, 0x5a, 0xa7, 0xc1, 0x70, 0xab, 0x4c, 0xce, 0x64,
|
|
19
|
+
0xd9, 0x08, 0x39, 0xa3, 0x4d, 0xcf, 0xd6, 0xcf, 0x71, 0xd1, 0x4e, 0x02, 0x05, 0x44, 0x3b, 0x1b]);
|
|
20
|
+
function normalizeQueryId(qid) {
|
|
21
|
+
return qid === 0n ? null : qid;
|
|
22
|
+
}
|
|
23
|
+
function parseMessage(cell, opts) {
|
|
24
|
+
const params = {
|
|
25
|
+
disallowUnsafe: false,
|
|
26
|
+
disallowModification: false,
|
|
27
|
+
encodeJettonBurnEthAddressAsHex: true,
|
|
28
|
+
...opts,
|
|
29
|
+
};
|
|
30
|
+
if (cell.hash().equals(new core_1.Cell().hash())) {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
let s = cell.beginParse();
|
|
34
|
+
try {
|
|
35
|
+
const op = s.loadUint(32);
|
|
36
|
+
switch (op) {
|
|
37
|
+
case 0: {
|
|
38
|
+
const str = s.loadStringTail();
|
|
39
|
+
s.endParse();
|
|
40
|
+
if (str.length > 120) {
|
|
41
|
+
throw new Error('Comment must be at most 120 ASCII characters long');
|
|
42
|
+
}
|
|
43
|
+
for (const c of str) {
|
|
44
|
+
if (c.charCodeAt(0) < 0x20 || c.charCodeAt(0) >= 0x7f) {
|
|
45
|
+
throw new Error('Comment must only contain printable ASCII characters');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
type: 'comment',
|
|
50
|
+
text: str,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
case 0x0f8a7ea5: {
|
|
54
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
55
|
+
const amount = s.loadCoins();
|
|
56
|
+
const destination = s.loadAddress();
|
|
57
|
+
const responseDestination = s.loadAddress();
|
|
58
|
+
const customPayload = s.loadMaybeRef();
|
|
59
|
+
const forwardAmount = s.loadCoins();
|
|
60
|
+
let forwardPayload = null;
|
|
61
|
+
if (s.loadBit()) {
|
|
62
|
+
forwardPayload = s.loadRef();
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const p = s.asCell();
|
|
66
|
+
s = new core_1.Cell().beginParse(); // clear the slice
|
|
67
|
+
if (!p.hash().equals(new core_1.Cell().hash())) {
|
|
68
|
+
if (params.disallowModification) {
|
|
69
|
+
throw new Error('Jetton transfer message would be modified');
|
|
70
|
+
}
|
|
71
|
+
forwardPayload = p;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
s.endParse();
|
|
75
|
+
return {
|
|
76
|
+
type: 'jetton-transfer',
|
|
77
|
+
queryId,
|
|
78
|
+
amount,
|
|
79
|
+
destination,
|
|
80
|
+
responseDestination,
|
|
81
|
+
customPayload,
|
|
82
|
+
forwardAmount,
|
|
83
|
+
forwardPayload,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
case 0x5fcc3d14: {
|
|
87
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
88
|
+
const newOwner = s.loadAddress();
|
|
89
|
+
const responseDestination = s.loadAddress();
|
|
90
|
+
const customPayload = s.loadMaybeRef();
|
|
91
|
+
const forwardAmount = s.loadCoins();
|
|
92
|
+
let forwardPayload = null;
|
|
93
|
+
if (s.loadBit()) {
|
|
94
|
+
forwardPayload = s.loadRef();
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
const p = s.asCell();
|
|
98
|
+
s = new core_1.Cell().beginParse(); // clear the slice
|
|
99
|
+
if (!p.hash().equals(new core_1.Cell().hash())) {
|
|
100
|
+
if (params.disallowModification) {
|
|
101
|
+
throw new Error('Jetton transfer message would be modified');
|
|
102
|
+
}
|
|
103
|
+
forwardPayload = p;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
s.endParse();
|
|
107
|
+
return {
|
|
108
|
+
type: 'nft-transfer',
|
|
109
|
+
queryId,
|
|
110
|
+
newOwner,
|
|
111
|
+
responseDestination,
|
|
112
|
+
customPayload,
|
|
113
|
+
forwardAmount,
|
|
114
|
+
forwardPayload,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
case 0x595f07bc: {
|
|
118
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
119
|
+
const amount = s.loadCoins();
|
|
120
|
+
const responseDestination = s.loadAddress();
|
|
121
|
+
let customPayload = s.loadMaybeRef();
|
|
122
|
+
s.endParse();
|
|
123
|
+
if (params.encodeJettonBurnEthAddressAsHex && customPayload !== null && customPayload.bits.length === 160 && customPayload.refs.length === 0) {
|
|
124
|
+
const cs = customPayload.beginParse();
|
|
125
|
+
customPayload = cs.loadBuffer(20);
|
|
126
|
+
cs.endParse();
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
type: 'jetton-burn',
|
|
130
|
+
queryId,
|
|
131
|
+
amount,
|
|
132
|
+
responseDestination,
|
|
133
|
+
customPayload,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
case 0x7258a69b: {
|
|
137
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
138
|
+
const address = s.loadAddress();
|
|
139
|
+
s.endParse();
|
|
140
|
+
return {
|
|
141
|
+
type: 'add-whitelist',
|
|
142
|
+
queryId,
|
|
143
|
+
address,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
case 0x1000: {
|
|
147
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
148
|
+
const amount = s.loadCoins();
|
|
149
|
+
s.endParse();
|
|
150
|
+
return {
|
|
151
|
+
type: 'single-nominator-withdraw',
|
|
152
|
+
queryId,
|
|
153
|
+
amount,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
case 0x1001: {
|
|
157
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
158
|
+
const address = s.loadAddress();
|
|
159
|
+
s.endParse();
|
|
160
|
+
return {
|
|
161
|
+
type: 'single-nominator-change-validator',
|
|
162
|
+
queryId,
|
|
163
|
+
address,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
case 0x47d54391: {
|
|
167
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
168
|
+
let appId = null;
|
|
169
|
+
if (s.remainingBits > 0) {
|
|
170
|
+
appId = s.loadUintBig(64);
|
|
171
|
+
}
|
|
172
|
+
s.endParse();
|
|
173
|
+
return {
|
|
174
|
+
type: 'tonstakers-deposit',
|
|
175
|
+
queryId,
|
|
176
|
+
appId,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
case 0x69fb306c: {
|
|
180
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
181
|
+
const votingAddress = s.loadAddress();
|
|
182
|
+
const expirationDate = s.loadUint(48);
|
|
183
|
+
const vote = s.loadBit();
|
|
184
|
+
const needConfirmation = s.loadBit();
|
|
185
|
+
s.endParse();
|
|
186
|
+
return {
|
|
187
|
+
type: 'vote-for-proposal',
|
|
188
|
+
queryId,
|
|
189
|
+
votingAddress,
|
|
190
|
+
expirationDate,
|
|
191
|
+
vote,
|
|
192
|
+
needConfirmation,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
case 0x4eb1f0f9: {
|
|
196
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
197
|
+
const key = s.loadBuffer(32);
|
|
198
|
+
if (key.equals(dnsWalletKey)) {
|
|
199
|
+
if (s.remainingRefs > 0) {
|
|
200
|
+
const vs = s.loadRef().beginParse();
|
|
201
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
202
|
+
// tolerate the Maybe bit
|
|
203
|
+
if (!s.loadBit())
|
|
204
|
+
throw new Error('Incorrect change DNS record message');
|
|
205
|
+
}
|
|
206
|
+
s.endParse();
|
|
207
|
+
const type = vs.loadUint(16);
|
|
208
|
+
if (type !== 0x9fd3) {
|
|
209
|
+
throw new Error('Wrong DNS record type');
|
|
210
|
+
}
|
|
211
|
+
const address = vs.loadAddress();
|
|
212
|
+
const flags = vs.loadUint(8);
|
|
213
|
+
if (flags > 1) {
|
|
214
|
+
throw new Error('DNS wallet record must have flags 0 or 1');
|
|
215
|
+
}
|
|
216
|
+
let capabilities = (flags & 1) > 0 ? { isWallet: false } : null;
|
|
217
|
+
if (capabilities !== null) {
|
|
218
|
+
while (vs.loadBit()) {
|
|
219
|
+
const cap = vs.loadUint(16);
|
|
220
|
+
if (cap === 0x2177) {
|
|
221
|
+
if (capabilities.isWallet && params.disallowModification) {
|
|
222
|
+
throw new Error('DNS change record message would be modified');
|
|
223
|
+
}
|
|
224
|
+
capabilities.isWallet = true;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
throw new Error('Unknown DNS wallet record capability');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return {
|
|
232
|
+
type: 'change-dns-record',
|
|
233
|
+
queryId,
|
|
234
|
+
record: {
|
|
235
|
+
type: 'wallet',
|
|
236
|
+
value: {
|
|
237
|
+
address,
|
|
238
|
+
capabilities,
|
|
239
|
+
},
|
|
240
|
+
},
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
245
|
+
// tolerate the Maybe bit
|
|
246
|
+
if (s.loadBit())
|
|
247
|
+
throw new Error('Incorrect change DNS record message');
|
|
248
|
+
}
|
|
249
|
+
s.endParse();
|
|
250
|
+
return {
|
|
251
|
+
type: 'change-dns-record',
|
|
252
|
+
queryId,
|
|
253
|
+
record: {
|
|
254
|
+
type: 'wallet',
|
|
255
|
+
value: null,
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
if (s.remainingRefs > 0) {
|
|
262
|
+
const value = s.loadRef();
|
|
263
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
264
|
+
// tolerate the Maybe bit
|
|
265
|
+
if (!s.loadBit())
|
|
266
|
+
throw new Error('Incorrect change DNS record message');
|
|
267
|
+
}
|
|
268
|
+
s.endParse();
|
|
269
|
+
return {
|
|
270
|
+
type: 'change-dns-record',
|
|
271
|
+
queryId,
|
|
272
|
+
record: {
|
|
273
|
+
type: 'unknown',
|
|
274
|
+
key,
|
|
275
|
+
value,
|
|
276
|
+
},
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
if (s.remainingBits > 0 && !params.disallowModification) {
|
|
281
|
+
// tolerate the Maybe bit
|
|
282
|
+
if (s.loadBit())
|
|
283
|
+
throw new Error('Incorrect change DNS record message');
|
|
284
|
+
}
|
|
285
|
+
s.endParse();
|
|
286
|
+
return {
|
|
287
|
+
type: 'change-dns-record',
|
|
288
|
+
queryId,
|
|
289
|
+
record: {
|
|
290
|
+
type: 'unknown',
|
|
291
|
+
key,
|
|
292
|
+
value: null,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
case 0x8: {
|
|
299
|
+
const queryId = normalizeQueryId(s.loadUintBig(64));
|
|
300
|
+
const swapId = s.loadBuffer(32);
|
|
301
|
+
s.endParse();
|
|
302
|
+
return {
|
|
303
|
+
type: 'token-bridge-pay-swap',
|
|
304
|
+
queryId,
|
|
305
|
+
swapId,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
throw new Error('Unknown op: ' + op);
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
if (params.disallowUnsafe) {
|
|
313
|
+
throw e;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
type: 'unsafe',
|
|
318
|
+
message: cell,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
exports.parseMessage = parseMessage;
|
|
17
322
|
function chunks(buf, n) {
|
|
18
323
|
const nc = Math.ceil(buf.length / n);
|
|
19
324
|
const cs = [];
|
|
@@ -680,6 +985,13 @@ class TonTransport {
|
|
|
680
985
|
.storeSlice(transfer.beginParse())
|
|
681
986
|
.endCell();
|
|
682
987
|
};
|
|
988
|
+
async getSettings() {
|
|
989
|
+
let loaded = await this.#doRequest(INS_SETTINGS, 0x00, 0x00, Buffer.alloc(0));
|
|
990
|
+
return {
|
|
991
|
+
blindSigningEnabled: (loaded[0] & 0x01) > 0,
|
|
992
|
+
expertMode: (loaded[0] & 0x02) > 0,
|
|
993
|
+
};
|
|
994
|
+
}
|
|
683
995
|
#doRequest = async (ins, p1, p2, data) => {
|
|
684
996
|
return this.#lock.inLock(async () => {
|
|
685
997
|
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 } from './TonTransport';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TonTransport = void 0;
|
|
3
|
+
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; } });
|