@ton/ton 13.5.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/CHANGELOG.md +133 -0
- package/LICENSE +9 -0
- package/README.md +78 -0
- package/dist/client/TonClient.d.ts +231 -0
- package/dist/client/TonClient.js +392 -0
- package/dist/client/TonClient.spec.d.ts +1 -0
- package/dist/client/TonClient.spec.js +37 -0
- package/dist/client/TonClient4.d.ts +289 -0
- package/dist/client/TonClient4.js +514 -0
- package/dist/client/TonClient4.spec.d.ts +1 -0
- package/dist/client/TonClient4.spec.js +36 -0
- package/dist/client/api/HttpApi.d.ts +632 -0
- package/dist/client/api/HttpApi.js +297 -0
- package/dist/client/api/TonCache.d.ts +16 -0
- package/dist/client/api/TonCache.js +33 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +68 -0
- package/dist/jetton/JettonMaster.d.ts +21 -0
- package/dist/jetton/JettonMaster.js +39 -0
- package/dist/jetton/JettonMaster.spec.d.ts +8 -0
- package/dist/jetton/JettonMaster.spec.js +27 -0
- package/dist/jetton/JettonWallet.d.ts +14 -0
- package/dist/jetton/JettonWallet.js +27 -0
- package/dist/multisig/MultisigOrder.d.ts +17 -0
- package/dist/multisig/MultisigOrder.js +73 -0
- package/dist/multisig/MultisigOrder.spec.d.ts +1 -0
- package/dist/multisig/MultisigOrder.spec.js +139 -0
- package/dist/multisig/MultisigOrderBuilder.d.ts +13 -0
- package/dist/multisig/MultisigOrderBuilder.js +37 -0
- package/dist/multisig/MultisigWallet.d.ts +26 -0
- package/dist/multisig/MultisigWallet.js +120 -0
- package/dist/multisig/MultisigWallet.spec.d.ts +1 -0
- package/dist/multisig/MultisigWallet.spec.js +230 -0
- package/dist/utils/createTestClient.d.ts +9 -0
- package/dist/utils/createTestClient.js +18 -0
- package/dist/utils/createTestClient4.d.ts +9 -0
- package/dist/utils/createTestClient4.js +15 -0
- package/dist/utils/maybe.d.ts +8 -0
- package/dist/utils/maybe.js +9 -0
- package/dist/utils/randomTestKey.d.ts +8 -0
- package/dist/utils/randomTestKey.js +24 -0
- package/dist/utils/time.d.ts +15 -0
- package/dist/utils/time.js +63 -0
- package/dist/utils/toUrlSafe.d.ts +8 -0
- package/dist/utils/toUrlSafe.js +23 -0
- package/dist/wallets/WalletContractV1R1.d.ts +58 -0
- package/dist/wallets/WalletContractV1R1.js +100 -0
- package/dist/wallets/WalletContractV1R1.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV1R1.spec.js +44 -0
- package/dist/wallets/WalletContractV1R2.d.ts +58 -0
- package/dist/wallets/WalletContractV1R2.js +101 -0
- package/dist/wallets/WalletContractV1R2.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV1R2.spec.js +44 -0
- package/dist/wallets/WalletContractV1R3.d.ts +58 -0
- package/dist/wallets/WalletContractV1R3.js +101 -0
- package/dist/wallets/WalletContractV1R3.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV1R3.spec.js +44 -0
- package/dist/wallets/WalletContractV2R1.d.ts +60 -0
- package/dist/wallets/WalletContractV2R1.js +102 -0
- package/dist/wallets/WalletContractV2R1.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV2R1.spec.js +44 -0
- package/dist/wallets/WalletContractV2R2.d.ts +60 -0
- package/dist/wallets/WalletContractV2R2.js +102 -0
- package/dist/wallets/WalletContractV2R2.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV2R2.spec.js +44 -0
- package/dist/wallets/WalletContractV3R1.d.ts +62 -0
- package/dist/wallets/WalletContractV3R1.js +111 -0
- package/dist/wallets/WalletContractV3R1.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV3R1.spec.js +44 -0
- package/dist/wallets/WalletContractV3R2.d.ts +62 -0
- package/dist/wallets/WalletContractV3R2.js +111 -0
- package/dist/wallets/WalletContractV3R2.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV3R2.spec.js +44 -0
- package/dist/wallets/WalletContractV4.d.ts +62 -0
- package/dist/wallets/WalletContractV4.js +112 -0
- package/dist/wallets/WalletContractV4.spec.d.ts +8 -0
- package/dist/wallets/WalletContractV4.spec.js +48 -0
- package/dist/wallets/signing/createWalletTransfer.d.ts +39 -0
- package/dist/wallets/signing/createWalletTransfer.js +122 -0
- package/package.json +68 -0
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.HttpApi = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Copyright (c) Whales Corp.
|
|
9
|
+
* All Rights Reserved.
|
|
10
|
+
*
|
|
11
|
+
* This source code is licensed under the MIT license found in the
|
|
12
|
+
* LICENSE file in the root directory of this source tree.
|
|
13
|
+
*/
|
|
14
|
+
const TonCache_1 = require("./TonCache");
|
|
15
|
+
const dataloader_1 = __importDefault(require("dataloader"));
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const zod_1 = require("zod");
|
|
18
|
+
const version = require('../../../package.json').version;
|
|
19
|
+
const blockIdExt = zod_1.z.object({
|
|
20
|
+
'@type': zod_1.z.literal('ton.blockIdExt'),
|
|
21
|
+
workchain: zod_1.z.number(),
|
|
22
|
+
shard: zod_1.z.string(),
|
|
23
|
+
seqno: zod_1.z.number(),
|
|
24
|
+
root_hash: zod_1.z.string(),
|
|
25
|
+
file_hash: zod_1.z.string()
|
|
26
|
+
});
|
|
27
|
+
const addressInformation = zod_1.z.object({
|
|
28
|
+
balance: zod_1.z.union([zod_1.z.number(), zod_1.z.string()]),
|
|
29
|
+
state: zod_1.z.union([zod_1.z.literal('active'), zod_1.z.literal('uninitialized'), zod_1.z.literal('frozen')]),
|
|
30
|
+
data: zod_1.z.string(),
|
|
31
|
+
code: zod_1.z.string(),
|
|
32
|
+
last_transaction_id: zod_1.z.object({
|
|
33
|
+
'@type': zod_1.z.literal('internal.transactionId'),
|
|
34
|
+
lt: zod_1.z.string(),
|
|
35
|
+
hash: zod_1.z.string()
|
|
36
|
+
}),
|
|
37
|
+
block_id: blockIdExt,
|
|
38
|
+
sync_utime: zod_1.z.number()
|
|
39
|
+
});
|
|
40
|
+
const bocResponse = zod_1.z.object({
|
|
41
|
+
'@type': zod_1.z.literal('ok')
|
|
42
|
+
});
|
|
43
|
+
const feeResponse = zod_1.z.object({
|
|
44
|
+
'@type': zod_1.z.literal('query.fees'),
|
|
45
|
+
source_fees: zod_1.z.object({
|
|
46
|
+
'@type': zod_1.z.literal('fees'),
|
|
47
|
+
in_fwd_fee: zod_1.z.number(),
|
|
48
|
+
storage_fee: zod_1.z.number(),
|
|
49
|
+
gas_fee: zod_1.z.number(),
|
|
50
|
+
fwd_fee: zod_1.z.number()
|
|
51
|
+
})
|
|
52
|
+
});
|
|
53
|
+
const callGetMethod = zod_1.z.object({
|
|
54
|
+
gas_used: zod_1.z.number(),
|
|
55
|
+
exit_code: zod_1.z.number(),
|
|
56
|
+
stack: zod_1.z.array(zod_1.z.unknown())
|
|
57
|
+
});
|
|
58
|
+
const messageData = zod_1.z.union([
|
|
59
|
+
zod_1.z.object({
|
|
60
|
+
'@type': zod_1.z.literal('msg.dataRaw'),
|
|
61
|
+
'body': zod_1.z.string()
|
|
62
|
+
}),
|
|
63
|
+
zod_1.z.object({
|
|
64
|
+
'@type': zod_1.z.literal('msg.dataText'),
|
|
65
|
+
'text': zod_1.z.string()
|
|
66
|
+
}),
|
|
67
|
+
zod_1.z.object({
|
|
68
|
+
'@type': zod_1.z.literal('msg.dataDecryptedText'),
|
|
69
|
+
'text': zod_1.z.string()
|
|
70
|
+
}),
|
|
71
|
+
zod_1.z.object({
|
|
72
|
+
'@type': zod_1.z.literal('msg.dataEncryptedText'),
|
|
73
|
+
'text': zod_1.z.string()
|
|
74
|
+
})
|
|
75
|
+
]);
|
|
76
|
+
const message = zod_1.z.object({
|
|
77
|
+
source: zod_1.z.string(),
|
|
78
|
+
destination: zod_1.z.string(),
|
|
79
|
+
value: zod_1.z.string(),
|
|
80
|
+
fwd_fee: zod_1.z.string(),
|
|
81
|
+
ihr_fee: zod_1.z.string(),
|
|
82
|
+
created_lt: zod_1.z.string(),
|
|
83
|
+
body_hash: zod_1.z.string(),
|
|
84
|
+
msg_data: messageData
|
|
85
|
+
});
|
|
86
|
+
const transaction = zod_1.z.object({
|
|
87
|
+
data: zod_1.z.string(),
|
|
88
|
+
utime: zod_1.z.number(),
|
|
89
|
+
transaction_id: zod_1.z.object({
|
|
90
|
+
lt: zod_1.z.string(),
|
|
91
|
+
hash: zod_1.z.string()
|
|
92
|
+
}),
|
|
93
|
+
fee: zod_1.z.string(),
|
|
94
|
+
storage_fee: zod_1.z.string(),
|
|
95
|
+
other_fee: zod_1.z.string(),
|
|
96
|
+
in_msg: zod_1.z.union([zod_1.z.undefined(), message]),
|
|
97
|
+
out_msgs: zod_1.z.array(message)
|
|
98
|
+
});
|
|
99
|
+
const getTransactions = zod_1.z.array(transaction);
|
|
100
|
+
const getMasterchain = zod_1.z.object({
|
|
101
|
+
state_root_hash: zod_1.z.string(),
|
|
102
|
+
last: blockIdExt,
|
|
103
|
+
init: blockIdExt
|
|
104
|
+
});
|
|
105
|
+
const getShards = zod_1.z.object({
|
|
106
|
+
shards: zod_1.z.array(blockIdExt)
|
|
107
|
+
});
|
|
108
|
+
const blockShortTxt = zod_1.z.object({
|
|
109
|
+
'@type': zod_1.z.literal('blocks.shortTxId'),
|
|
110
|
+
mode: zod_1.z.number(),
|
|
111
|
+
account: zod_1.z.string(),
|
|
112
|
+
lt: zod_1.z.string(),
|
|
113
|
+
hash: zod_1.z.string()
|
|
114
|
+
});
|
|
115
|
+
const getBlockTransactions = zod_1.z.object({
|
|
116
|
+
id: blockIdExt,
|
|
117
|
+
req_count: zod_1.z.number(),
|
|
118
|
+
incomplete: zod_1.z.boolean(),
|
|
119
|
+
transactions: zod_1.z.array(blockShortTxt)
|
|
120
|
+
});
|
|
121
|
+
class TypedCache {
|
|
122
|
+
constructor(namespace, cache, codec, keyEncoder) {
|
|
123
|
+
this.namespace = namespace;
|
|
124
|
+
this.cache = cache;
|
|
125
|
+
this.codec = codec;
|
|
126
|
+
this.keyEncoder = keyEncoder;
|
|
127
|
+
}
|
|
128
|
+
async get(key) {
|
|
129
|
+
let ex = await this.cache.get(this.namespace, this.keyEncoder(key));
|
|
130
|
+
if (ex) {
|
|
131
|
+
let decoded = this.codec.safeParse(JSON.parse(ex));
|
|
132
|
+
if (decoded.success) {
|
|
133
|
+
return decoded.data;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
async set(key, value) {
|
|
139
|
+
if (value !== null) {
|
|
140
|
+
await this.cache.set(this.namespace, this.keyEncoder(key), JSON.stringify(value));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
await this.cache.set(this.namespace, this.keyEncoder(key), null);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
class HttpApi {
|
|
148
|
+
constructor(endpoint, parameters) {
|
|
149
|
+
this.endpoint = endpoint;
|
|
150
|
+
this.cache = new TonCache_1.InMemoryCache();
|
|
151
|
+
this.parameters = {
|
|
152
|
+
timeout: parameters?.timeout || 30000,
|
|
153
|
+
apiKey: parameters?.apiKey
|
|
154
|
+
};
|
|
155
|
+
// Shard
|
|
156
|
+
this.shardCache = new TypedCache('ton-shard', this.cache, zod_1.z.array(blockIdExt), (src) => src + '');
|
|
157
|
+
this.shardLoader = new dataloader_1.default(async (src) => {
|
|
158
|
+
return await Promise.all(src.map(async (v) => {
|
|
159
|
+
const cached = await this.shardCache.get(v);
|
|
160
|
+
if (cached) {
|
|
161
|
+
return cached;
|
|
162
|
+
}
|
|
163
|
+
let loaded = (await this.doCall('shards', { seqno: v }, getShards)).shards;
|
|
164
|
+
await this.shardCache.set(v, loaded);
|
|
165
|
+
return loaded;
|
|
166
|
+
}));
|
|
167
|
+
});
|
|
168
|
+
// Shard Transactions
|
|
169
|
+
this.shardTransactionsCache = new TypedCache('ton-shard-tx', this.cache, getBlockTransactions, (src) => src.workchain + ':' + src.shard + ':' + src.seqno);
|
|
170
|
+
this.shardTransactionsLoader = new dataloader_1.default(async (src) => {
|
|
171
|
+
return await Promise.all(src.map(async (v) => {
|
|
172
|
+
const cached = await this.shardTransactionsCache.get(v);
|
|
173
|
+
if (cached) {
|
|
174
|
+
return cached;
|
|
175
|
+
}
|
|
176
|
+
let loaded = await this.doCall('getBlockTransactions', { workchain: v.workchain, seqno: v.seqno, shard: v.shard }, getBlockTransactions);
|
|
177
|
+
await this.shardTransactionsCache.set(v, loaded);
|
|
178
|
+
return loaded;
|
|
179
|
+
}));
|
|
180
|
+
}, { cacheKeyFn: (src) => src.workchain + ':' + src.shard + ':' + src.seqno });
|
|
181
|
+
}
|
|
182
|
+
getAddressInformation(address) {
|
|
183
|
+
return this.doCall('getAddressInformation', { address: address.toString() }, addressInformation);
|
|
184
|
+
}
|
|
185
|
+
async getTransactions(address, opts) {
|
|
186
|
+
const inclusive = opts.inclusive;
|
|
187
|
+
delete opts.inclusive;
|
|
188
|
+
// Convert hash
|
|
189
|
+
let hash = undefined;
|
|
190
|
+
if (opts.hash) {
|
|
191
|
+
hash = Buffer.from(opts.hash, 'base64').toString('hex');
|
|
192
|
+
}
|
|
193
|
+
// Adjust limit
|
|
194
|
+
let limit = opts.limit;
|
|
195
|
+
if (opts.hash && opts.lt && inclusive !== true) {
|
|
196
|
+
limit++;
|
|
197
|
+
}
|
|
198
|
+
// Do request
|
|
199
|
+
let res = await this.doCall('getTransactions', { address: address.toString(), ...opts, limit, hash }, getTransactions);
|
|
200
|
+
if (res.length > limit) {
|
|
201
|
+
res = res.slice(0, limit);
|
|
202
|
+
}
|
|
203
|
+
// Adjust result
|
|
204
|
+
if (opts.hash && opts.lt && inclusive !== true) {
|
|
205
|
+
res.shift();
|
|
206
|
+
return res;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
return res;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async getMasterchainInfo() {
|
|
213
|
+
return await this.doCall('getMasterchainInfo', {}, getMasterchain);
|
|
214
|
+
}
|
|
215
|
+
async getShards(seqno) {
|
|
216
|
+
return await this.shardLoader.load(seqno);
|
|
217
|
+
}
|
|
218
|
+
async getBlockTransactions(workchain, seqno, shard) {
|
|
219
|
+
return await this.shardTransactionsLoader.load({ workchain, seqno, shard });
|
|
220
|
+
}
|
|
221
|
+
async getTransaction(address, lt, hash) {
|
|
222
|
+
let convHash = Buffer.from(hash, 'base64').toString('hex');
|
|
223
|
+
let res = await this.doCall('getTransactions', { address: address.toString(), lt, hash: convHash, limit: 1 }, getTransactions);
|
|
224
|
+
let ex = res.find((v) => v.transaction_id.lt === lt && v.transaction_id.hash === hash);
|
|
225
|
+
if (ex) {
|
|
226
|
+
return ex;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
async callGetMethod(address, method, stack) {
|
|
233
|
+
return await this.doCall('runGetMethod', { address: address.toString(), method, stack: serializeStack(stack) }, callGetMethod);
|
|
234
|
+
}
|
|
235
|
+
async sendBoc(body) {
|
|
236
|
+
await this.doCall('sendBoc', { boc: body.toString('base64') }, bocResponse);
|
|
237
|
+
}
|
|
238
|
+
async estimateFee(address, args) {
|
|
239
|
+
return await this.doCall('estimateFee', {
|
|
240
|
+
address: address.toString(),
|
|
241
|
+
body: args.body.toBoc().toString('base64'),
|
|
242
|
+
'init_data': args.initData ? args.initData.toBoc().toString('base64') : '',
|
|
243
|
+
'init_code': args.initCode ? args.initCode.toBoc().toString('base64') : '',
|
|
244
|
+
ignore_chksig: args.ignoreSignature
|
|
245
|
+
}, feeResponse);
|
|
246
|
+
}
|
|
247
|
+
async doCall(method, body, codec) {
|
|
248
|
+
let headers = {
|
|
249
|
+
'Content-Type': 'application/json',
|
|
250
|
+
'X-Ton-Client-Version': version,
|
|
251
|
+
};
|
|
252
|
+
if (this.parameters.apiKey) {
|
|
253
|
+
headers['X-API-Key'] = this.parameters.apiKey;
|
|
254
|
+
}
|
|
255
|
+
let res = await axios_1.default.post(this.endpoint, JSON.stringify({
|
|
256
|
+
id: '1',
|
|
257
|
+
jsonrpc: '2.0',
|
|
258
|
+
method: method,
|
|
259
|
+
params: body
|
|
260
|
+
}), {
|
|
261
|
+
headers,
|
|
262
|
+
timeout: this.parameters.timeout,
|
|
263
|
+
});
|
|
264
|
+
if (res.status !== 200 || !res.data.ok) {
|
|
265
|
+
throw Error('Received error: ' + JSON.stringify(res.data));
|
|
266
|
+
}
|
|
267
|
+
let decoded = codec.safeParse(res.data.result);
|
|
268
|
+
if (decoded.success) {
|
|
269
|
+
return decoded.data;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
throw Error('Malformed response: ' + decoded.error.format()._errors.join(', '));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.HttpApi = HttpApi;
|
|
277
|
+
function serializeStack(src) {
|
|
278
|
+
let stack = [];
|
|
279
|
+
for (let s of src) {
|
|
280
|
+
if (s.type === 'int') {
|
|
281
|
+
stack.push(['num', s.value.toString()]);
|
|
282
|
+
}
|
|
283
|
+
else if (s.type === 'cell') {
|
|
284
|
+
stack.push(['tvm.Cell', s.cell.toBoc().toString('base64')]);
|
|
285
|
+
}
|
|
286
|
+
else if (s.type === 'slice') {
|
|
287
|
+
stack.push(['tvm.Slice', s.cell.toBoc().toString('base64')]);
|
|
288
|
+
}
|
|
289
|
+
else if (s.type === 'builder') {
|
|
290
|
+
stack.push(['tvm.Builder', s.cell.toBoc().toString('base64')]);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
throw Error('Unsupported stack item type: ' + s.type);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return stack;
|
|
297
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Whales Corp.
|
|
3
|
+
* All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export interface TonCache {
|
|
9
|
+
set(namespace: string, key: string, value: string | null): Promise<void>;
|
|
10
|
+
get(namespace: string, key: string): Promise<string | null>;
|
|
11
|
+
}
|
|
12
|
+
export declare class InMemoryCache implements TonCache {
|
|
13
|
+
private cache;
|
|
14
|
+
set: (namespace: string, key: string, value: string | null) => Promise<void>;
|
|
15
|
+
get: (namespace: string, key: string) => Promise<string | null>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Whales Corp.
|
|
4
|
+
* All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.InMemoryCache = void 0;
|
|
11
|
+
class InMemoryCache {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.cache = new Map();
|
|
14
|
+
this.set = async (namespace, key, value) => {
|
|
15
|
+
if (value !== null) {
|
|
16
|
+
this.cache.set(namespace + '$$' + key, value);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.cache.delete(namespace + '$$' + key);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
this.get = async (namespace, key) => {
|
|
23
|
+
let res = this.cache.get(namespace + '$$' + key);
|
|
24
|
+
if (res !== undefined) {
|
|
25
|
+
return res;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.InMemoryCache = InMemoryCache;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Whales Corp.
|
|
3
|
+
* All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export * from '@ton/core';
|
|
9
|
+
export { HttpApi } from './client/api/HttpApi';
|
|
10
|
+
export { TonClient } from './client/TonClient';
|
|
11
|
+
export { TonClient4, TonClient4Parameters } from './client/TonClient4';
|
|
12
|
+
export { WalletContractV1R1 } from './wallets/WalletContractV1R1';
|
|
13
|
+
export { WalletContractV1R2 } from './wallets/WalletContractV1R2';
|
|
14
|
+
export { WalletContractV1R3 } from './wallets/WalletContractV1R3';
|
|
15
|
+
export { WalletContractV2R1 } from './wallets/WalletContractV2R1';
|
|
16
|
+
export { WalletContractV2R2 } from './wallets/WalletContractV2R2';
|
|
17
|
+
export { WalletContractV3R1 } from './wallets/WalletContractV3R1';
|
|
18
|
+
export { WalletContractV3R2 } from './wallets/WalletContractV3R2';
|
|
19
|
+
export { WalletContractV4 } from './wallets/WalletContractV4';
|
|
20
|
+
export { JettonMaster } from './jetton/JettonMaster';
|
|
21
|
+
export { JettonWallet } from './jetton/JettonWallet';
|
|
22
|
+
export { MultisigOrder } from './multisig/MultisigOrder';
|
|
23
|
+
export { MultisigOrderBuilder } from './multisig/MultisigOrderBuilder';
|
|
24
|
+
export { MultisigWallet } from './multisig/MultisigWallet';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Whales Corp.
|
|
4
|
+
* All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.MultisigWallet = exports.MultisigOrderBuilder = exports.MultisigOrder = exports.JettonWallet = exports.JettonMaster = exports.WalletContractV4 = exports.WalletContractV3R2 = exports.WalletContractV3R1 = exports.WalletContractV2R2 = exports.WalletContractV2R1 = exports.WalletContractV1R3 = exports.WalletContractV1R2 = exports.WalletContractV1R1 = exports.TonClient4 = exports.TonClient = exports.HttpApi = void 0;
|
|
21
|
+
__exportStar(require("@ton/core"), exports);
|
|
22
|
+
//
|
|
23
|
+
// toncenter Client
|
|
24
|
+
//
|
|
25
|
+
var HttpApi_1 = require("./client/api/HttpApi");
|
|
26
|
+
Object.defineProperty(exports, "HttpApi", { enumerable: true, get: function () { return HttpApi_1.HttpApi; } });
|
|
27
|
+
var TonClient_1 = require("./client/TonClient");
|
|
28
|
+
Object.defineProperty(exports, "TonClient", { enumerable: true, get: function () { return TonClient_1.TonClient; } });
|
|
29
|
+
//
|
|
30
|
+
// API V4 Client
|
|
31
|
+
//
|
|
32
|
+
var TonClient4_1 = require("./client/TonClient4");
|
|
33
|
+
Object.defineProperty(exports, "TonClient4", { enumerable: true, get: function () { return TonClient4_1.TonClient4; } });
|
|
34
|
+
//
|
|
35
|
+
// Wallets
|
|
36
|
+
//
|
|
37
|
+
var WalletContractV1R1_1 = require("./wallets/WalletContractV1R1");
|
|
38
|
+
Object.defineProperty(exports, "WalletContractV1R1", { enumerable: true, get: function () { return WalletContractV1R1_1.WalletContractV1R1; } });
|
|
39
|
+
var WalletContractV1R2_1 = require("./wallets/WalletContractV1R2");
|
|
40
|
+
Object.defineProperty(exports, "WalletContractV1R2", { enumerable: true, get: function () { return WalletContractV1R2_1.WalletContractV1R2; } });
|
|
41
|
+
var WalletContractV1R3_1 = require("./wallets/WalletContractV1R3");
|
|
42
|
+
Object.defineProperty(exports, "WalletContractV1R3", { enumerable: true, get: function () { return WalletContractV1R3_1.WalletContractV1R3; } });
|
|
43
|
+
var WalletContractV2R1_1 = require("./wallets/WalletContractV2R1");
|
|
44
|
+
Object.defineProperty(exports, "WalletContractV2R1", { enumerable: true, get: function () { return WalletContractV2R1_1.WalletContractV2R1; } });
|
|
45
|
+
var WalletContractV2R2_1 = require("./wallets/WalletContractV2R2");
|
|
46
|
+
Object.defineProperty(exports, "WalletContractV2R2", { enumerable: true, get: function () { return WalletContractV2R2_1.WalletContractV2R2; } });
|
|
47
|
+
var WalletContractV3R1_1 = require("./wallets/WalletContractV3R1");
|
|
48
|
+
Object.defineProperty(exports, "WalletContractV3R1", { enumerable: true, get: function () { return WalletContractV3R1_1.WalletContractV3R1; } });
|
|
49
|
+
var WalletContractV3R2_1 = require("./wallets/WalletContractV3R2");
|
|
50
|
+
Object.defineProperty(exports, "WalletContractV3R2", { enumerable: true, get: function () { return WalletContractV3R2_1.WalletContractV3R2; } });
|
|
51
|
+
var WalletContractV4_1 = require("./wallets/WalletContractV4");
|
|
52
|
+
Object.defineProperty(exports, "WalletContractV4", { enumerable: true, get: function () { return WalletContractV4_1.WalletContractV4; } });
|
|
53
|
+
//
|
|
54
|
+
// Jettons
|
|
55
|
+
//
|
|
56
|
+
var JettonMaster_1 = require("./jetton/JettonMaster");
|
|
57
|
+
Object.defineProperty(exports, "JettonMaster", { enumerable: true, get: function () { return JettonMaster_1.JettonMaster; } });
|
|
58
|
+
var JettonWallet_1 = require("./jetton/JettonWallet");
|
|
59
|
+
Object.defineProperty(exports, "JettonWallet", { enumerable: true, get: function () { return JettonWallet_1.JettonWallet; } });
|
|
60
|
+
//
|
|
61
|
+
// Multisig
|
|
62
|
+
//
|
|
63
|
+
var MultisigOrder_1 = require("./multisig/MultisigOrder");
|
|
64
|
+
Object.defineProperty(exports, "MultisigOrder", { enumerable: true, get: function () { return MultisigOrder_1.MultisigOrder; } });
|
|
65
|
+
var MultisigOrderBuilder_1 = require("./multisig/MultisigOrderBuilder");
|
|
66
|
+
Object.defineProperty(exports, "MultisigOrderBuilder", { enumerable: true, get: function () { return MultisigOrderBuilder_1.MultisigOrderBuilder; } });
|
|
67
|
+
var MultisigWallet_1 = require("./multisig/MultisigWallet");
|
|
68
|
+
Object.defineProperty(exports, "MultisigWallet", { enumerable: true, get: function () { return MultisigWallet_1.MultisigWallet; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Whales Corp.
|
|
3
|
+
* All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Address, Contract, ContractProvider } from "@ton/core";
|
|
9
|
+
export declare class JettonMaster implements Contract {
|
|
10
|
+
static create(address: Address): JettonMaster;
|
|
11
|
+
readonly address: Address;
|
|
12
|
+
constructor(address: Address);
|
|
13
|
+
getWalletAddress(provider: ContractProvider, owner: Address): Promise<Address>;
|
|
14
|
+
getJettonData(provider: ContractProvider): Promise<{
|
|
15
|
+
totalSupply: bigint;
|
|
16
|
+
mintable: boolean;
|
|
17
|
+
adminAddress: Address;
|
|
18
|
+
content: import("@ton/core").Cell;
|
|
19
|
+
walletCode: import("@ton/core").Cell;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Whales Corp.
|
|
4
|
+
* All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.JettonMaster = void 0;
|
|
11
|
+
const core_1 = require("@ton/core");
|
|
12
|
+
class JettonMaster {
|
|
13
|
+
constructor(address) {
|
|
14
|
+
this.address = address;
|
|
15
|
+
}
|
|
16
|
+
static create(address) {
|
|
17
|
+
return new JettonMaster(address);
|
|
18
|
+
}
|
|
19
|
+
async getWalletAddress(provider, owner) {
|
|
20
|
+
let res = await provider.get('get_wallet_address', [{ type: 'slice', cell: (0, core_1.beginCell)().storeAddress(owner).endCell() }]);
|
|
21
|
+
return res.stack.readAddress();
|
|
22
|
+
}
|
|
23
|
+
async getJettonData(provider) {
|
|
24
|
+
let res = await provider.get('get_jetton_data', []);
|
|
25
|
+
let totalSupply = res.stack.readBigNumber();
|
|
26
|
+
let mintable = res.stack.readBoolean();
|
|
27
|
+
let adminAddress = res.stack.readAddress();
|
|
28
|
+
let content = res.stack.readCell();
|
|
29
|
+
let walletCode = res.stack.readCell();
|
|
30
|
+
return {
|
|
31
|
+
totalSupply,
|
|
32
|
+
mintable,
|
|
33
|
+
adminAddress,
|
|
34
|
+
content,
|
|
35
|
+
walletCode
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.JettonMaster = JettonMaster;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Whales Corp.
|
|
4
|
+
* All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const core_1 = require("@ton/core");
|
|
11
|
+
const createTestClient_1 = require("../utils/createTestClient");
|
|
12
|
+
const JettonMaster_1 = require("./JettonMaster");
|
|
13
|
+
const JettonWallet_1 = require("./JettonWallet");
|
|
14
|
+
describe('JettonMaster', () => {
|
|
15
|
+
it('should resolve jetton wallet address', async () => {
|
|
16
|
+
let client = (0, createTestClient_1.createTestClient)('mainnet');
|
|
17
|
+
let master = client.open(JettonMaster_1.JettonMaster.create(core_1.Address.parse('EQDQoc5M3Bh8eWFephi9bClhevelbZZvWhkqdo80XuY_0qXv')));
|
|
18
|
+
let walletAddress = await master.getWalletAddress(core_1.Address.parse('EQCo6VT63H1vKJTiUo6W4M8RrTURCyk5MdbosuL5auEqpz-C'));
|
|
19
|
+
let jettonData = await master.getJettonData();
|
|
20
|
+
expect(walletAddress.equals(core_1.Address.parse('EQDslTlGmbLTFi0j4MPT7UVggWR7XRDI2bW6vmNG6Tc_FBDE'))).toBe(true);
|
|
21
|
+
expect(jettonData.mintable).toBe(true);
|
|
22
|
+
expect(jettonData.adminAddress.equals(core_1.Address.parse('EQCppzUtmGSMg3FIRlFLzhToqbaC0xjmjzOn0o7H4M8Aua1t'))).toBe(true);
|
|
23
|
+
let wallet = client.open(JettonWallet_1.JettonWallet.create(walletAddress));
|
|
24
|
+
let balance = await wallet.getBalance();
|
|
25
|
+
expect(balance).toBe(0n);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Whales Corp.
|
|
3
|
+
* All Rights Reserved.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Address, Contract, ContractProvider } from "@ton/core";
|
|
9
|
+
export declare class JettonWallet implements Contract {
|
|
10
|
+
static create(address: Address): JettonWallet;
|
|
11
|
+
readonly address: Address;
|
|
12
|
+
private constructor();
|
|
13
|
+
getBalance(provider: ContractProvider): Promise<bigint>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Whales Corp.
|
|
4
|
+
* All Rights Reserved.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.JettonWallet = void 0;
|
|
11
|
+
class JettonWallet {
|
|
12
|
+
constructor(address) {
|
|
13
|
+
this.address = address;
|
|
14
|
+
}
|
|
15
|
+
static create(address) {
|
|
16
|
+
return new JettonWallet(address);
|
|
17
|
+
}
|
|
18
|
+
async getBalance(provider) {
|
|
19
|
+
let state = await provider.getState();
|
|
20
|
+
if (state.state.type !== 'active') {
|
|
21
|
+
return 0n;
|
|
22
|
+
}
|
|
23
|
+
let res = await provider.get('get_wallet_data', []);
|
|
24
|
+
return res.stack.readBigNumber();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.JettonWallet = JettonWallet;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Cell } from '@ton/core';
|
|
3
|
+
import { MultisigWallet } from './MultisigWallet';
|
|
4
|
+
export declare class MultisigOrder {
|
|
5
|
+
readonly payload: Cell;
|
|
6
|
+
signatures: {
|
|
7
|
+
[key: number]: Buffer;
|
|
8
|
+
};
|
|
9
|
+
private constructor();
|
|
10
|
+
static fromCell(cell: Cell): MultisigOrder;
|
|
11
|
+
static fromPayload(payload: Cell): MultisigOrder;
|
|
12
|
+
addSignature(ownerId: number, signature: Buffer, multisig: MultisigWallet): void;
|
|
13
|
+
sign(ownerId: number, secretKey: Buffer): Buffer;
|
|
14
|
+
unionSignatures(other: MultisigOrder): void;
|
|
15
|
+
clearSignatures(): void;
|
|
16
|
+
toCell(ownerId: number): Cell;
|
|
17
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* Made by @Gusarich and @Miandic */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.MultisigOrder = void 0;
|
|
5
|
+
const crypto_1 = require("@ton/crypto");
|
|
6
|
+
const core_1 = require("@ton/core");
|
|
7
|
+
class MultisigOrder {
|
|
8
|
+
constructor(payload) {
|
|
9
|
+
this.signatures = {};
|
|
10
|
+
this.payload = payload;
|
|
11
|
+
}
|
|
12
|
+
static fromCell(cell) {
|
|
13
|
+
let s = cell.beginParse();
|
|
14
|
+
let signatures = s.loadMaybeRef()?.beginParse();
|
|
15
|
+
const messagesCell = s.asCell();
|
|
16
|
+
let order = new MultisigOrder(messagesCell);
|
|
17
|
+
if (signatures) {
|
|
18
|
+
while (signatures.remainingBits > 0) {
|
|
19
|
+
const signature = signatures.loadBuffer(64);
|
|
20
|
+
const ownerId = signatures.loadUint(8);
|
|
21
|
+
order.signatures[ownerId] = signature;
|
|
22
|
+
if (signatures.remainingRefs > 0) {
|
|
23
|
+
signatures = signatures.loadRef().asSlice();
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
signatures.skip(1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
signatures.endParse();
|
|
30
|
+
}
|
|
31
|
+
return order;
|
|
32
|
+
}
|
|
33
|
+
static fromPayload(payload) {
|
|
34
|
+
return new MultisigOrder(payload);
|
|
35
|
+
}
|
|
36
|
+
addSignature(ownerId, signature, multisig) {
|
|
37
|
+
const signingHash = this.payload.hash();
|
|
38
|
+
if (!(0, crypto_1.signVerify)(signingHash, signature, multisig.owners.get(ownerId).slice(0, -1))) {
|
|
39
|
+
throw Error('invalid signature');
|
|
40
|
+
}
|
|
41
|
+
this.signatures[ownerId] = signature;
|
|
42
|
+
}
|
|
43
|
+
sign(ownerId, secretKey) {
|
|
44
|
+
const signingHash = this.payload.hash();
|
|
45
|
+
this.signatures[ownerId] = (0, crypto_1.sign)(signingHash, secretKey);
|
|
46
|
+
return signingHash;
|
|
47
|
+
}
|
|
48
|
+
unionSignatures(other) {
|
|
49
|
+
this.signatures = Object.assign({}, this.signatures, other.signatures);
|
|
50
|
+
}
|
|
51
|
+
clearSignatures() {
|
|
52
|
+
this.signatures = {};
|
|
53
|
+
}
|
|
54
|
+
toCell(ownerId) {
|
|
55
|
+
let b = (0, core_1.beginCell)().storeBit(0);
|
|
56
|
+
for (const ownerId in this.signatures) {
|
|
57
|
+
const signature = this.signatures[ownerId];
|
|
58
|
+
b = (0, core_1.beginCell)()
|
|
59
|
+
.storeBit(1)
|
|
60
|
+
.storeRef((0, core_1.beginCell)()
|
|
61
|
+
.storeBuffer(signature)
|
|
62
|
+
.storeUint(parseInt(ownerId), 8)
|
|
63
|
+
.storeBuilder(b)
|
|
64
|
+
.endCell());
|
|
65
|
+
}
|
|
66
|
+
return (0, core_1.beginCell)()
|
|
67
|
+
.storeUint(ownerId, 8)
|
|
68
|
+
.storeBuilder(b)
|
|
69
|
+
.storeBuilder(this.payload.asBuilder())
|
|
70
|
+
.endCell();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.MultisigOrder = MultisigOrder;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|