@ton-community/ton-ledger 7.0.1 → 7.1.0-pre.0
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/README.md +3 -3
- package/dist/TonTransport.d.ts +56 -0
- package/dist/TonTransport.js +344 -78
- package/dist/utils/ledgerWriter.d.ts +2 -0
- package/dist/utils/ledgerWriter.js +15 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ This library allows you to connect to a ledger device and with with TON from bro
|
|
|
7
7
|
To add library to your project execute:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
yarn add ton-ledger
|
|
10
|
+
yarn add @ton-community/ton-ledger
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Connecting to a Device
|
|
@@ -29,7 +29,7 @@ React Native:
|
|
|
29
29
|
|
|
30
30
|
After connecting to a device create a TonTransport instance:
|
|
31
31
|
```typescript
|
|
32
|
-
import { TonTransport } from 'ton-ledger';
|
|
32
|
+
import { TonTransport } from '@ton-community/ton-ledger';
|
|
33
33
|
let transport = new TonTransport(device);
|
|
34
34
|
```
|
|
35
35
|
|
|
@@ -83,7 +83,7 @@ Ledger Nanoapp works with Wallet v4 for now, we recommend you to continue to use
|
|
|
83
83
|
|
|
84
84
|
```typescript
|
|
85
85
|
import { WalletV4Contract, WalletV4Source } from 'ton';
|
|
86
|
-
import { TonPayloadFormat } from 'ton-ledger';
|
|
86
|
+
import { TonPayloadFormat } from '@ton-community/ton-ledger';
|
|
87
87
|
import { TonClient, Address, SendMode, toNano } from 'ton-core';
|
|
88
88
|
|
|
89
89
|
let client = new TonClient({ endpoint: 'https://toncenter.com/api/v2/jsonRPC' });
|
package/dist/TonTransport.d.ts
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import Transport from "@ledgerhq/hw-transport";
|
|
3
3
|
import { Address, Cell, SendMode, StateInit } from "@ton/core";
|
|
4
4
|
export type TonPayloadFormat = {
|
|
5
|
+
type: 'unsafe';
|
|
6
|
+
message: Cell;
|
|
7
|
+
} | {
|
|
5
8
|
type: 'comment';
|
|
6
9
|
text: string;
|
|
7
10
|
} | {
|
|
@@ -21,6 +24,55 @@ export type TonPayloadFormat = {
|
|
|
21
24
|
customPayload: Cell | null;
|
|
22
25
|
forwardAmount: bigint;
|
|
23
26
|
forwardPayload: Cell | null;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'jetton-burn';
|
|
29
|
+
queryId: bigint | null;
|
|
30
|
+
amount: bigint;
|
|
31
|
+
responseDestination: Address;
|
|
32
|
+
customPayload: Cell | Buffer | null;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'add-whitelist';
|
|
35
|
+
queryId: bigint | null;
|
|
36
|
+
address: Address;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'single-nominator-withdraw';
|
|
39
|
+
queryId: bigint | null;
|
|
40
|
+
amount: bigint;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'single-nominator-change-validator';
|
|
43
|
+
queryId: bigint | null;
|
|
44
|
+
address: Address;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'tonstakers-deposit';
|
|
47
|
+
queryId: bigint | null;
|
|
48
|
+
appId: bigint | null;
|
|
49
|
+
} | {
|
|
50
|
+
type: 'vote-for-proposal';
|
|
51
|
+
queryId: bigint | null;
|
|
52
|
+
votingAddress: Address;
|
|
53
|
+
expirationDate: number;
|
|
54
|
+
vote: boolean;
|
|
55
|
+
needConfirmation: boolean;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'change-dns-record';
|
|
58
|
+
queryId: bigint | null;
|
|
59
|
+
record: {
|
|
60
|
+
type: 'wallet';
|
|
61
|
+
value: {
|
|
62
|
+
address: Address;
|
|
63
|
+
capabilities: {
|
|
64
|
+
isWallet: boolean;
|
|
65
|
+
} | null;
|
|
66
|
+
} | null;
|
|
67
|
+
} | {
|
|
68
|
+
type: 'unknown';
|
|
69
|
+
key: Buffer;
|
|
70
|
+
value: Cell | null;
|
|
71
|
+
};
|
|
72
|
+
} | {
|
|
73
|
+
type: 'token-bridge-pay-swap';
|
|
74
|
+
queryId: bigint | null;
|
|
75
|
+
swapId: Buffer;
|
|
24
76
|
};
|
|
25
77
|
export type SignDataRequest = {
|
|
26
78
|
type: 'plaintext';
|
|
@@ -82,5 +134,9 @@ export declare class TonTransport {
|
|
|
82
134
|
amount: bigint;
|
|
83
135
|
stateInit?: StateInit;
|
|
84
136
|
payload?: TonPayloadFormat;
|
|
137
|
+
walletSpecifiers?: {
|
|
138
|
+
subwalletId?: number;
|
|
139
|
+
includeWalletOp: boolean;
|
|
140
|
+
};
|
|
85
141
|
}) => Promise<Cell>;
|
|
86
142
|
}
|
package/dist/TonTransport.js
CHANGED
|
@@ -13,6 +13,7 @@ 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 DEFAULT_SUBWALLET_ID = 698983191;
|
|
16
17
|
function chunks(buf, n) {
|
|
17
18
|
const nc = Math.ceil(buf.length / n);
|
|
18
19
|
const cs = [];
|
|
@@ -34,6 +35,330 @@ function processAddressFlags(opts) {
|
|
|
34
35
|
}
|
|
35
36
|
return { bounceable, testOnly, chain, flags };
|
|
36
37
|
}
|
|
38
|
+
function convertPayload(input) {
|
|
39
|
+
let payload = null;
|
|
40
|
+
let hints = Buffer.concat([(0, ledgerWriter_1.writeUint8)(0)]);
|
|
41
|
+
if (input === undefined) {
|
|
42
|
+
return {
|
|
43
|
+
payload,
|
|
44
|
+
hints,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
switch (input.type) {
|
|
48
|
+
case 'unsafe': {
|
|
49
|
+
payload = input.message;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'comment': {
|
|
53
|
+
hints = Buffer.concat([
|
|
54
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
55
|
+
(0, ledgerWriter_1.writeUint32)(0x00),
|
|
56
|
+
(0, ledgerWriter_1.writeUint16)(Buffer.from(input.text).length),
|
|
57
|
+
Buffer.from(input.text)
|
|
58
|
+
]);
|
|
59
|
+
payload = (0, core_1.beginCell)()
|
|
60
|
+
.storeUint(0, 32)
|
|
61
|
+
.storeBuffer(Buffer.from(input.text))
|
|
62
|
+
.endCell();
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case 'jetton-transfer':
|
|
66
|
+
case 'nft-transfer': {
|
|
67
|
+
hints = Buffer.concat([
|
|
68
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
69
|
+
(0, ledgerWriter_1.writeUint32)(input.type === 'jetton-transfer' ? 0x01 : 0x02)
|
|
70
|
+
]);
|
|
71
|
+
let b = (0, core_1.beginCell)()
|
|
72
|
+
.storeUint(input.type === 'jetton-transfer' ? 0x0f8a7ea5 : 0x5fcc3d14, 32);
|
|
73
|
+
let d = Buffer.alloc(0);
|
|
74
|
+
if (input.queryId !== null) {
|
|
75
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
76
|
+
b = b.storeUint(input.queryId, 64);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
80
|
+
b = b.storeUint(0, 64);
|
|
81
|
+
}
|
|
82
|
+
if (input.type === 'jetton-transfer') {
|
|
83
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(input.amount)]);
|
|
84
|
+
b = b.storeCoins(input.amount);
|
|
85
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.destination)]);
|
|
86
|
+
b = b.storeAddress(input.destination);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.newOwner)]);
|
|
90
|
+
b = b.storeAddress(input.newOwner);
|
|
91
|
+
}
|
|
92
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.responseDestination)]);
|
|
93
|
+
b = b.storeAddress(input.responseDestination);
|
|
94
|
+
if (input.customPayload !== null) {
|
|
95
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeCellRef)(input.customPayload)]);
|
|
96
|
+
b = b.storeMaybeRef(input.customPayload);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
100
|
+
b = b.storeMaybeRef(input.customPayload);
|
|
101
|
+
}
|
|
102
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(input.forwardAmount)]);
|
|
103
|
+
b = b.storeCoins(input.forwardAmount);
|
|
104
|
+
if (input.forwardPayload !== null) {
|
|
105
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeCellRef)(input.forwardPayload)]);
|
|
106
|
+
b = b.storeMaybeRef(input.forwardPayload);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
110
|
+
b = b.storeMaybeRef(input.forwardPayload);
|
|
111
|
+
}
|
|
112
|
+
payload = b.endCell();
|
|
113
|
+
hints = Buffer.concat([
|
|
114
|
+
hints,
|
|
115
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
116
|
+
d
|
|
117
|
+
]);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
case 'jetton-burn': {
|
|
121
|
+
hints = Buffer.concat([
|
|
122
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
123
|
+
(0, ledgerWriter_1.writeUint32)(0x03)
|
|
124
|
+
]);
|
|
125
|
+
let b = (0, core_1.beginCell)()
|
|
126
|
+
.storeUint(0x595f07bc, 32);
|
|
127
|
+
let d = Buffer.alloc(0);
|
|
128
|
+
if (input.queryId !== null) {
|
|
129
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
130
|
+
b = b.storeUint(input.queryId, 64);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
134
|
+
b = b.storeUint(0, 64);
|
|
135
|
+
}
|
|
136
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(input.amount)]);
|
|
137
|
+
b = b.storeCoins(input.amount);
|
|
138
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.responseDestination)]);
|
|
139
|
+
b = b.storeAddress(input.responseDestination);
|
|
140
|
+
if (input.customPayload === null) {
|
|
141
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
142
|
+
b = b.storeMaybeRef(input.customPayload);
|
|
143
|
+
}
|
|
144
|
+
else if (input.customPayload instanceof core_1.Cell) {
|
|
145
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeCellRef)(input.customPayload)]);
|
|
146
|
+
b = b.storeMaybeRef(input.customPayload);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(2), (0, ledgerWriter_1.writeCellInline)(input.customPayload)]);
|
|
150
|
+
b = b.storeMaybeRef((0, core_1.beginCell)().storeBuffer(input.customPayload).endCell());
|
|
151
|
+
}
|
|
152
|
+
payload = b.endCell();
|
|
153
|
+
hints = Buffer.concat([
|
|
154
|
+
hints,
|
|
155
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
156
|
+
d
|
|
157
|
+
]);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 'add-whitelist':
|
|
161
|
+
case 'single-nominator-change-validator': {
|
|
162
|
+
hints = Buffer.concat([
|
|
163
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
164
|
+
(0, ledgerWriter_1.writeUint32)(input.type === 'add-whitelist' ? 0x04 : 0x06)
|
|
165
|
+
]);
|
|
166
|
+
let b = (0, core_1.beginCell)()
|
|
167
|
+
.storeUint(input.type === 'add-whitelist' ? 0x7258a69b : 0x1001, 32);
|
|
168
|
+
let d = Buffer.alloc(0);
|
|
169
|
+
if (input.queryId !== null) {
|
|
170
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
171
|
+
b = b.storeUint(input.queryId, 64);
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
175
|
+
b = b.storeUint(0, 64);
|
|
176
|
+
}
|
|
177
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.address)]);
|
|
178
|
+
b = b.storeAddress(input.address);
|
|
179
|
+
payload = b.endCell();
|
|
180
|
+
hints = Buffer.concat([
|
|
181
|
+
hints,
|
|
182
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
183
|
+
d
|
|
184
|
+
]);
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
case 'single-nominator-withdraw': {
|
|
188
|
+
hints = Buffer.concat([
|
|
189
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
190
|
+
(0, ledgerWriter_1.writeUint32)(0x05)
|
|
191
|
+
]);
|
|
192
|
+
let b = (0, core_1.beginCell)()
|
|
193
|
+
.storeUint(0x1000, 32);
|
|
194
|
+
let d = Buffer.alloc(0);
|
|
195
|
+
if (input.queryId !== null) {
|
|
196
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
197
|
+
b = b.storeUint(input.queryId, 64);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
201
|
+
b = b.storeUint(0, 64);
|
|
202
|
+
}
|
|
203
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(input.amount)]);
|
|
204
|
+
b = b.storeCoins(input.amount);
|
|
205
|
+
payload = b.endCell();
|
|
206
|
+
hints = Buffer.concat([
|
|
207
|
+
hints,
|
|
208
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
209
|
+
d
|
|
210
|
+
]);
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
case 'tonstakers-deposit': {
|
|
214
|
+
hints = Buffer.concat([
|
|
215
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
216
|
+
(0, ledgerWriter_1.writeUint32)(0x07)
|
|
217
|
+
]);
|
|
218
|
+
let b = (0, core_1.beginCell)()
|
|
219
|
+
.storeUint(0x47d54391, 32);
|
|
220
|
+
let d = Buffer.alloc(0);
|
|
221
|
+
if (input.queryId !== null) {
|
|
222
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
223
|
+
b = b.storeUint(input.queryId, 64);
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
227
|
+
b = b.storeUint(0, 64);
|
|
228
|
+
}
|
|
229
|
+
if (input.appId !== null) {
|
|
230
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.appId)]);
|
|
231
|
+
b = b.storeUint(input.appId, 64);
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
235
|
+
}
|
|
236
|
+
payload = b.endCell();
|
|
237
|
+
hints = Buffer.concat([
|
|
238
|
+
hints,
|
|
239
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
240
|
+
d
|
|
241
|
+
]);
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case 'vote-for-proposal': {
|
|
245
|
+
hints = Buffer.concat([
|
|
246
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
247
|
+
(0, ledgerWriter_1.writeUint32)(0x08)
|
|
248
|
+
]);
|
|
249
|
+
let b = (0, core_1.beginCell)()
|
|
250
|
+
.storeUint(0x69fb306c, 32);
|
|
251
|
+
let d = Buffer.alloc(0);
|
|
252
|
+
if (input.queryId !== null) {
|
|
253
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
254
|
+
b = b.storeUint(input.queryId, 64);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
258
|
+
b = b.storeUint(0, 64);
|
|
259
|
+
}
|
|
260
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.votingAddress)]);
|
|
261
|
+
b = b.storeAddress(input.votingAddress);
|
|
262
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint48)(input.expirationDate)]);
|
|
263
|
+
b = b.storeUint(input.expirationDate, 48);
|
|
264
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(input.vote ? 1 : 0), (0, ledgerWriter_1.writeUint8)(input.needConfirmation ? 1 : 0)]);
|
|
265
|
+
b = b.storeBit(input.vote).storeBit(input.needConfirmation);
|
|
266
|
+
payload = b.endCell();
|
|
267
|
+
hints = Buffer.concat([
|
|
268
|
+
hints,
|
|
269
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
270
|
+
d
|
|
271
|
+
]);
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case 'change-dns-record': {
|
|
275
|
+
hints = Buffer.concat([
|
|
276
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
277
|
+
(0, ledgerWriter_1.writeUint32)(0x09)
|
|
278
|
+
]);
|
|
279
|
+
let b = (0, core_1.beginCell)()
|
|
280
|
+
.storeUint(0x4eb1f0f9, 32);
|
|
281
|
+
let d = Buffer.alloc(0);
|
|
282
|
+
if (input.queryId !== null) {
|
|
283
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
284
|
+
b = b.storeUint(input.queryId, 64);
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
288
|
+
b = b.storeUint(0, 64);
|
|
289
|
+
}
|
|
290
|
+
if (input.record.type === 'unknown' && input.record.key.length !== 32) {
|
|
291
|
+
throw new Error('DNS record key length must be 32 bytes long');
|
|
292
|
+
}
|
|
293
|
+
b = b.storeBuffer(input.record.type === 'wallet' ? (0, crypto_1.sha256_sync)('wallet') : input.record.key);
|
|
294
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(input.record.value === null ? 0 : 1), (0, ledgerWriter_1.writeUint8)(input.record.type === 'wallet' ? 0 : 1)]);
|
|
295
|
+
if (input.record.type === 'wallet') {
|
|
296
|
+
if (input.record.value !== null) {
|
|
297
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(input.record.value.address), (0, ledgerWriter_1.writeUint8)(input.record.value.capabilities === null ? 0 : 1)]);
|
|
298
|
+
let rb = (0, core_1.beginCell)().storeUint(0x9fd3, 16).storeAddress(input.record.value.address).storeUint(input.record.value.capabilities === null ? 0 : 1, 8);
|
|
299
|
+
if (input.record.value.capabilities !== null) {
|
|
300
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(input.record.value.capabilities.isWallet ? 1 : 0)]);
|
|
301
|
+
if (input.record.value.capabilities.isWallet) {
|
|
302
|
+
rb = rb.storeBit(true).storeUint(0x2177, 16);
|
|
303
|
+
}
|
|
304
|
+
rb = rb.storeBit(false);
|
|
305
|
+
}
|
|
306
|
+
b = b.storeRef(rb);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
d = Buffer.concat([d, input.record.key]);
|
|
311
|
+
if (input.record.value !== null) {
|
|
312
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeCellRef)(input.record.value)]);
|
|
313
|
+
b = b.storeRef(input.record.value);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
payload = b.endCell();
|
|
317
|
+
hints = Buffer.concat([
|
|
318
|
+
hints,
|
|
319
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
320
|
+
d
|
|
321
|
+
]);
|
|
322
|
+
break;
|
|
323
|
+
}
|
|
324
|
+
case 'token-bridge-pay-swap': {
|
|
325
|
+
hints = Buffer.concat([
|
|
326
|
+
(0, ledgerWriter_1.writeUint8)(1),
|
|
327
|
+
(0, ledgerWriter_1.writeUint32)(0x0A)
|
|
328
|
+
]);
|
|
329
|
+
let b = (0, core_1.beginCell)()
|
|
330
|
+
.storeUint(8, 32);
|
|
331
|
+
let d = Buffer.alloc(0);
|
|
332
|
+
if (input.queryId !== null) {
|
|
333
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(input.queryId)]);
|
|
334
|
+
b = b.storeUint(input.queryId, 64);
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
338
|
+
b = b.storeUint(0, 64);
|
|
339
|
+
}
|
|
340
|
+
if (input.swapId.length !== 32) {
|
|
341
|
+
throw new Error('Token bridge swap ID must be 32 bytes long');
|
|
342
|
+
}
|
|
343
|
+
d = Buffer.concat([d, input.swapId]);
|
|
344
|
+
b = b.storeBuffer(input.swapId);
|
|
345
|
+
payload = b.endCell();
|
|
346
|
+
hints = Buffer.concat([
|
|
347
|
+
hints,
|
|
348
|
+
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
349
|
+
d
|
|
350
|
+
]);
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
default: {
|
|
354
|
+
throw new Error('Unknown payload type: ' + input.type);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
payload,
|
|
359
|
+
hints,
|
|
360
|
+
};
|
|
361
|
+
}
|
|
37
362
|
class TonTransport {
|
|
38
363
|
transport;
|
|
39
364
|
#lock = new teslabot_1.AsyncLock();
|
|
@@ -224,7 +549,17 @@ class TonTransport {
|
|
|
224
549
|
// Create package
|
|
225
550
|
//
|
|
226
551
|
let pkg = Buffer.concat([
|
|
227
|
-
(0, ledgerWriter_1.writeUint8)(0),
|
|
552
|
+
(0, ledgerWriter_1.writeUint8)(transaction.walletSpecifiers === undefined ? 0 : 1), // tag
|
|
553
|
+
]);
|
|
554
|
+
if (transaction.walletSpecifiers !== undefined) {
|
|
555
|
+
pkg = Buffer.concat([
|
|
556
|
+
pkg,
|
|
557
|
+
(0, ledgerWriter_1.writeUint32)(transaction.walletSpecifiers.subwalletId ?? DEFAULT_SUBWALLET_ID),
|
|
558
|
+
(0, ledgerWriter_1.writeUint8)(transaction.walletSpecifiers.includeWalletOp ? 1 : 0),
|
|
559
|
+
]);
|
|
560
|
+
}
|
|
561
|
+
pkg = Buffer.concat([
|
|
562
|
+
pkg,
|
|
228
563
|
(0, ledgerWriter_1.writeUint32)(transaction.seqno),
|
|
229
564
|
(0, ledgerWriter_1.writeUint32)(transaction.timeout),
|
|
230
565
|
(0, ledgerWriter_1.writeVarUInt)(transaction.amount),
|
|
@@ -256,78 +591,7 @@ class TonTransport {
|
|
|
256
591
|
//
|
|
257
592
|
// Payload
|
|
258
593
|
//
|
|
259
|
-
|
|
260
|
-
let hints = Buffer.concat([(0, ledgerWriter_1.writeUint8)(0)]);
|
|
261
|
-
if (transaction.payload) {
|
|
262
|
-
if (transaction.payload.type === 'comment') {
|
|
263
|
-
hints = Buffer.concat([
|
|
264
|
-
(0, ledgerWriter_1.writeUint8)(1),
|
|
265
|
-
(0, ledgerWriter_1.writeUint32)(0x00),
|
|
266
|
-
(0, ledgerWriter_1.writeUint16)(Buffer.from(transaction.payload.text).length),
|
|
267
|
-
Buffer.from(transaction.payload.text)
|
|
268
|
-
]);
|
|
269
|
-
payload = (0, core_1.beginCell)()
|
|
270
|
-
.storeUint(0, 32)
|
|
271
|
-
.storeBuffer(Buffer.from(transaction.payload.text))
|
|
272
|
-
.endCell();
|
|
273
|
-
}
|
|
274
|
-
else if (transaction.payload.type === 'jetton-transfer' || transaction.payload.type === 'nft-transfer') {
|
|
275
|
-
hints = Buffer.concat([
|
|
276
|
-
(0, ledgerWriter_1.writeUint8)(1),
|
|
277
|
-
(0, ledgerWriter_1.writeUint32)(transaction.payload.type === 'jetton-transfer' ? 0x01 : 0x02)
|
|
278
|
-
]);
|
|
279
|
-
let b = (0, core_1.beginCell)()
|
|
280
|
-
.storeUint(transaction.payload.type === 'jetton-transfer' ? 0x0f8a7ea5 : 0x5fcc3d14, 32);
|
|
281
|
-
let d = Buffer.alloc(0);
|
|
282
|
-
if (transaction.payload.queryId !== null) {
|
|
283
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeUint64)(transaction.payload.queryId)]);
|
|
284
|
-
b = b.storeUint(transaction.payload.queryId, 64);
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
288
|
-
b = b.storeUint(0, 64);
|
|
289
|
-
}
|
|
290
|
-
if (transaction.payload.type === 'jetton-transfer') {
|
|
291
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(transaction.payload.amount)]);
|
|
292
|
-
b = b.storeCoins(transaction.payload.amount);
|
|
293
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(transaction.payload.destination)]);
|
|
294
|
-
b = b.storeAddress(transaction.payload.destination);
|
|
295
|
-
}
|
|
296
|
-
else {
|
|
297
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(transaction.payload.newOwner)]);
|
|
298
|
-
b = b.storeAddress(transaction.payload.newOwner);
|
|
299
|
-
}
|
|
300
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeAddress)(transaction.payload.responseDestination)]);
|
|
301
|
-
b = b.storeAddress(transaction.payload.responseDestination);
|
|
302
|
-
if (transaction.payload.customPayload !== null) {
|
|
303
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeCellRef)(transaction.payload.customPayload)]);
|
|
304
|
-
b = b.storeMaybeRef(transaction.payload.customPayload);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
308
|
-
b = b.storeMaybeRef(transaction.payload.customPayload);
|
|
309
|
-
}
|
|
310
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeVarUInt)(transaction.payload.forwardAmount)]);
|
|
311
|
-
b = b.storeCoins(transaction.payload.forwardAmount);
|
|
312
|
-
if (transaction.payload.forwardPayload !== null) {
|
|
313
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(1), (0, ledgerWriter_1.writeCellRef)(transaction.payload.forwardPayload)]);
|
|
314
|
-
b = b.storeMaybeRef(transaction.payload.forwardPayload);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
d = Buffer.concat([d, (0, ledgerWriter_1.writeUint8)(0)]);
|
|
318
|
-
b = b.storeMaybeRef(transaction.payload.forwardPayload);
|
|
319
|
-
}
|
|
320
|
-
payload = b.endCell();
|
|
321
|
-
hints = Buffer.concat([
|
|
322
|
-
hints,
|
|
323
|
-
(0, ledgerWriter_1.writeUint16)(d.length),
|
|
324
|
-
d
|
|
325
|
-
]);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
//
|
|
329
|
-
// Serialize payload
|
|
330
|
-
//
|
|
594
|
+
const { payload, hints } = convertPayload(transaction.payload);
|
|
331
595
|
if (payload) {
|
|
332
596
|
pkg = Buffer.concat([
|
|
333
597
|
pkg,
|
|
@@ -391,12 +655,14 @@ class TonTransport {
|
|
|
391
655
|
.storeBit(false);
|
|
392
656
|
}
|
|
393
657
|
// Transfer message
|
|
394
|
-
let
|
|
395
|
-
.storeUint(
|
|
658
|
+
let transferB = (0, core_1.beginCell)()
|
|
659
|
+
.storeUint(transaction.walletSpecifiers?.subwalletId ?? DEFAULT_SUBWALLET_ID, 32)
|
|
396
660
|
.storeUint(transaction.timeout, 32)
|
|
397
|
-
.storeUint(transaction.seqno, 32)
|
|
398
|
-
|
|
399
|
-
.storeUint(
|
|
661
|
+
.storeUint(transaction.seqno, 32);
|
|
662
|
+
if (transaction.walletSpecifiers?.includeWalletOp ?? true) {
|
|
663
|
+
transferB = transferB.storeUint(0, 8);
|
|
664
|
+
}
|
|
665
|
+
let transfer = transferB.storeUint(transaction.sendMode, 8)
|
|
400
666
|
.storeRef(orderBuilder.endCell())
|
|
401
667
|
.endCell();
|
|
402
668
|
// Parse result
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { Address, Cell } from '@ton/core';
|
|
3
3
|
export declare function writeUint32(value: number): Buffer;
|
|
4
4
|
export declare function writeUint16(value: number): Buffer;
|
|
5
|
+
export declare function writeUint48(value: number): Buffer;
|
|
5
6
|
export declare function writeUint64(value: bigint): Buffer;
|
|
6
7
|
export declare function writeVarUInt(value: bigint): Buffer;
|
|
7
8
|
export declare function writeUint8(value: number): Buffer;
|
|
8
9
|
export declare function writeAddress(address: Address): Buffer;
|
|
9
10
|
export declare function writeCellRef(ref: Cell): Buffer;
|
|
11
|
+
export declare function writeCellInline(bytes: Buffer): Buffer;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeCellRef = exports.writeAddress = exports.writeUint8 = exports.writeVarUInt = exports.writeUint64 = exports.writeUint16 = exports.writeUint32 = void 0;
|
|
3
|
+
exports.writeCellInline = exports.writeCellRef = exports.writeAddress = exports.writeUint8 = exports.writeVarUInt = exports.writeUint64 = exports.writeUint48 = exports.writeUint16 = exports.writeUint32 = void 0;
|
|
4
4
|
const core_1 = require("@ton/core");
|
|
5
5
|
function writeUint32(value) {
|
|
6
6
|
let b = Buffer.alloc(4);
|
|
@@ -14,6 +14,13 @@ function writeUint16(value) {
|
|
|
14
14
|
return b;
|
|
15
15
|
}
|
|
16
16
|
exports.writeUint16 = writeUint16;
|
|
17
|
+
function writeUint48(value) {
|
|
18
|
+
let b = Buffer.alloc(6);
|
|
19
|
+
b.writeUint16BE(value >> 32, 0);
|
|
20
|
+
b.writeUint32BE(value & ((1 << 32) - 1), 2);
|
|
21
|
+
return b;
|
|
22
|
+
}
|
|
23
|
+
exports.writeUint48 = writeUint48;
|
|
17
24
|
function writeUint64(value) {
|
|
18
25
|
return (0, core_1.beginCell)().storeUint(value, 64).endCell().beginParse().loadBuffer(8);
|
|
19
26
|
}
|
|
@@ -43,3 +50,10 @@ function writeCellRef(ref) {
|
|
|
43
50
|
]);
|
|
44
51
|
}
|
|
45
52
|
exports.writeCellRef = writeCellRef;
|
|
53
|
+
function writeCellInline(bytes) {
|
|
54
|
+
return Buffer.concat([
|
|
55
|
+
writeUint8(bytes.length),
|
|
56
|
+
bytes,
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
exports.writeCellInline = writeCellInline;
|