wan-ton-sdk 0.0.7 → 0.0.9
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/Bridge.compile.d.ts +2 -0
- package/dist/Bridge.compile.js +9 -0
- package/dist/Bridge.d.ts +208 -0
- package/dist/Bridge.js +468 -0
- package/dist/Fake.compile.d.ts +2 -0
- package/dist/Fake.compile.js +9 -0
- package/dist/GroupApprove.compile.d.ts +2 -0
- package/dist/GroupApprove.compile.js +7 -0
- package/dist/GroupApprove.d.ts +124 -0
- package/dist/GroupApprove.js +181 -0
- package/dist/JettonMinter.compile.d.ts +2 -0
- package/dist/JettonMinter.compile.js +6 -0
- package/dist/JettonMinter.d.ts +45 -0
- package/dist/JettonMinter.js +124 -0
- package/dist/JettonWallet.compile.d.ts +2 -0
- package/dist/JettonWallet.compile.js +6 -0
- package/dist/JettonWallet.d.ts +26 -0
- package/dist/JettonWallet.js +103 -0
- package/dist/Signature.compile.d.ts +2 -0
- package/dist/Signature.compile.js +7 -0
- package/dist/Signature.d.ts +44 -0
- package/dist/Signature.js +106 -0
- package/dist/address.compile.d.ts +2 -0
- package/dist/address.compile.js +9 -0
- package/dist/client/client-interface.d.ts +35 -0
- package/dist/client/client-interface.js +9 -0
- package/dist/client/client.d.ts +22 -0
- package/dist/client/client.js +86 -0
- package/dist/client/tonapi-client.d.ts +4630 -0
- package/dist/client/tonapi-client.js +5376 -0
- package/dist/code/encode-decode.d.ts +132 -0
- package/dist/code/encode-decode.js +645 -0
- package/dist/code/userLock.d.ts +39 -0
- package/dist/code/userLock.js +284 -0
- package/dist/common.d.ts +9 -0
- package/dist/common.js +45 -0
- package/dist/config/config-ex.d.ts +7 -0
- package/dist/config/config-ex.js +73 -0
- package/dist/const/const-value.d.ts +21 -0
- package/dist/const/const-value.js +26 -0
- package/dist/contractAccess/bridgeAccess.d.ts +10 -0
- package/dist/contractAccess/bridgeAccess.js +55 -0
- package/dist/contractAccess/groupApproveAccess.d.ts +10 -0
- package/dist/contractAccess/groupApproveAccess.js +54 -0
- package/dist/db/Db.d.ts +24 -0
- package/dist/db/Db.js +739 -0
- package/dist/db/DbAccess.d.ts +24 -0
- package/dist/db/DbAccess.js +211 -0
- package/dist/db/common.d.ts +5 -0
- package/dist/db/common.js +114 -0
- package/dist/event/getEvents.d.ts +17 -0
- package/dist/event/getEvents.js +387 -0
- package/dist/example/db/createDb-ex.d.ts +1 -0
- package/{example/createDb-ex.ts → dist/example/db/createDb-ex.js} +3 -4
- package/dist/example/db/dbFeedTrans-ex.d.ts +1 -0
- package/{example/dbFeedTrans-ex.ts → dist/example/db/dbFeedTrans-ex.js} +9 -11
- package/dist/example/event/getAllEvents-ex.d.ts +1 -0
- package/dist/example/event/getAllEvents-ex.js +70 -0
- package/dist/example/event/getEventByHash-ex.d.ts +1 -0
- package/{example/getEventByHash-ex.ts → dist/example/event/getEventByHash-ex.js} +21 -25
- package/dist/example/event/getEventsByRange-ex.d.ts +1 -0
- package/dist/example/event/getEventsByRange-ex.js +58 -0
- package/dist/example/getAllTrans.d.ts +1 -0
- package/dist/example/getAllTrans.js +30 -0
- package/dist/example/jetton/getJettonInfo-ex.d.ts +1 -0
- package/dist/example/jetton/getJettonInfo-ex.js +32 -0
- package/dist/example/lock-release/smgRelease-ex.d.ts +1 -0
- package/dist/example/lock-release/smgRelease-ex.js +134 -0
- package/dist/example/lock-release/userLock-ex.d.ts +1 -0
- package/dist/example/lock-release/userLock-ex.js +69 -0
- package/dist/example/manage/addSmg-ex.d.ts +1 -0
- package/dist/example/manage/addSmg-ex.js +59 -0
- package/dist/example/manage/compileContract-ex.d.ts +1 -0
- package/dist/example/manage/compileContract-ex.js +11 -0
- package/dist/example/manage/deploy-ex.d.ts +1 -0
- package/dist/example/manage/deploy-ex.js +58 -0
- package/dist/example/manage/setFee-ex.d.ts +1 -0
- package/dist/example/manage/setFee-ex.js +61 -0
- package/dist/example/manage/setFeeProxy.d.ts +1 -0
- package/dist/example/manage/setFeeProxy.js +47 -0
- package/dist/example/manage/upgradeBridgeSc-ex.d.ts +1 -0
- package/dist/example/manage/upgradeBridgeSc-ex.js +44 -0
- package/dist/example/token/AddToken-ex.d.ts +1 -0
- package/dist/example/token/AddToken-ex.js +113 -0
- package/dist/example/token/addTokenPair-ex.d.ts +1 -0
- package/dist/example/token/addTokenPair-ex.js +59 -0
- package/dist/example/token/delTokenPair-ex.d.ts +1 -0
- package/dist/example/token/delTokenPair-ex.js +49 -0
- package/dist/example/token/getTokenPair-ex.d.ts +1 -0
- package/dist/example/token/getTokenPair-ex.js +39 -0
- package/dist/example/token/mintToken-ex.d.ts +1 -0
- package/dist/example/token/mintToken-ex.js +56 -0
- package/dist/example/tran/converTranToTonTran.d.ts +1 -0
- package/dist/example/tran/converTranToTonTran.js +32 -0
- package/dist/example/tran/getTransByRange-ex.d.ts +1 -0
- package/{example/getTransByRange-ex.ts → dist/example/tran/getTransByRange-ex.js} +26 -40
- package/dist/example/tran/getTransaction-ex.d.ts +1 -0
- package/dist/example/tran/getTransaction-ex.js +47 -0
- package/dist/example/tran/isTranSuccess-ex.d.ts +1 -0
- package/dist/example/tran/isTranSuccess-ex.js +27 -0
- package/dist/fee/fee.d.ts +12 -0
- package/dist/fee/fee.js +21 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +95 -0
- package/dist/jest.config.d.ts +3 -0
- package/dist/jest.config.js +8 -0
- package/dist/opcodes.d.ts +55 -0
- package/dist/opcodes.js +59 -0
- package/dist/sign/buildHash.d.ts +6 -0
- package/dist/sign/buildHash.js +39 -0
- package/dist/sign/rawTrans.d.ts +36 -0
- package/dist/sign/rawTrans.js +89 -0
- package/dist/sign/tools-secp256k1.d.ts +21 -0
- package/{sign → dist/sign}/tools-secp256k1.js +18 -44
- package/dist/testData/JettonMinter.compile.func.d.ts +2 -0
- package/dist/testData/JettonMinter.compile.func.js +13 -0
- package/dist/testData/JettonWallet.compile.func.d.ts +2 -0
- package/dist/testData/JettonWallet.compile.func.js +13 -0
- package/dist/testData/bridge.compile.func.d.ts +2 -0
- package/dist/testData/bridge.compile.func.js +13 -0
- package/dist/transResult/transResult.d.ts +29 -0
- package/dist/transResult/transResult.js +528 -0
- package/dist/utils/compileContract.d.ts +13 -0
- package/dist/utils/compileContract.js +54 -0
- package/dist/utils/logger.d.ts +16 -0
- package/dist/utils/logger.js +94 -0
- package/dist/utils/utils.d.ts +26 -0
- package/dist/utils/utils.js +330 -0
- package/dist/wallet/balance.d.ts +5 -0
- package/dist/wallet/balance.js +29 -0
- package/dist/wallet/jetton.d.ts +16 -0
- package/dist/wallet/jetton.js +171 -0
- package/dist/wallet/walletContract.d.ts +31 -0
- package/dist/wallet/walletContract.js +106 -0
- package/package.json +8 -6
- package/Bridge.compile.ts +0 -8
- package/Bridge.ts +0 -645
- package/Bridge.ts.org +0 -647
- package/Fake.compile.ts +0 -8
- package/GroupApprove.compile.ts +0 -6
- package/GroupApprove.ts +0 -274
- package/JettonMinter.compile.ts +0 -5
- package/JettonMinter.ts +0 -135
- package/JettonWallet.compile.ts +0 -5
- package/JettonWallet.ts +0 -127
- package/Signature.compile.ts +0 -6
- package/Signature.ts +0 -105
- package/address.compile.ts +0 -8
- package/client/1.json +0 -1730
- package/client/client.ts +0 -73
- package/client/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/code/decode.spec.ts +0 -81
- package/code/encode-decode.ts +0 -622
- package/code/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
- package/code/log/wan-ton-sdk.out.2025-01-20 +0 -0
- package/code/userLock.ts +0 -291
- package/common.ts +0 -62
- package/config/config-ex.ts +0 -25
- package/config/config.ts +0 -1
- package/const/const-value.ts +0 -33
- package/contractAccess/bridgeAccess.ts +0 -60
- package/contractAccess/groupApproveAccess.ts +0 -59
- package/data/EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs.json +0 -7348
- package/db/Db.spec.ts +0 -193
- package/db/Db.ts +0 -736
- package/db/DbAccess.spec.ts +0 -23
- package/db/DbAccess.ts +0 -186
- package/db/common.ts +0 -94
- package/db/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/db/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/event/getEvents.ts +0 -441
- package/event/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/event/log/wan-ton-sdk.out.2024-12-19 +0 -0
- package/example/0:1.txt +0 -1
- package/example/AddToken-ex.ts +0 -148
- package/example/README.md +0 -21
- package/example/addSmg-ex.ts +0 -78
- package/example/addTokenPair-ex.ts +0 -73
- package/example/compileContract-ex.ts +0 -10
- package/example/converTranToTonTran.ts +0 -43
- package/example/delTokenPair-ex.ts +0 -63
- package/example/deploy-ex.ts +0 -68
- package/example/getAllEvents-ex.ts +0 -61
- package/example/getAllTrans.ts +0 -32
- package/example/getContractState-ex.ts +0 -33
- package/example/getEvents-ex.ts +0 -55
- package/example/getJettonInfo-ex.ts +0 -44
- package/example/getTokenPair-ex.ts +0 -47
- package/example/getTransaction-ex.ts +0 -62
- package/example/isTranSuccess-ex.ts +0 -33
- package/example/locateTx-ex.ts +0 -44
- package/example/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -55
- package/example/log/wan-ton-sdk.out.2025-04-21 +0 -447
- package/example/log/wan-ton-sdk.out.2025-04-22 +0 -1918
- package/example/log/wan-ton-sdk.out.2025-04-23 +0 -4216
- package/example/log/wan-ton-sdk.out.2025-04-24.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-25 +0 -46814
- package/example/log/wan-ton-sdk.out.2025-04-27.gz +0 -0
- package/example/log/wan-ton-sdk.out.2025-04-28 +0 -4966
- package/example/log/wan-ton-sdk.out.2025-04-29 +0 -1328
- package/example/log/wan-ton-sdk.out.2025-04-30 +0 -9
- package/example/mintToken-ex.ts +0 -82
- package/example/setFee-ex.ts +0 -82
- package/example/setFeeProxy.ts +0 -70
- package/example/smgRelease-ex.ts +0 -173
- package/example/upgradeBridgeSc-ex.ts +0 -49
- package/example/userLock-ex.ts +0 -78
- package/fee/fee.ts +0 -23
- package/index.ts +0 -76
- package/jest.config.ts +0 -9
- package/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -20
- package/log/wan-ton-sdk.out.2025-04-21 +0 -0
- package/log/wan-ton-sdk.out.2025-04-30 +0 -10
- package/opcodes.ts +0 -58
- package/publish.sh +0 -78
- package/sign/buildHash.ts +0 -47
- package/sign/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/sign/log/wan-ton-sdk.out.2025-04-14 +0 -3
- package/sign/rawTrans.spec.ts +0 -117
- package/sign/rawTrans.ts +0 -122
- package/testData/JettonMinter.compile.func.ts +0 -8
- package/testData/JettonWallet.compile.func.ts +0 -8
- package/testData/addressList.json +0 -6
- package/testData/bridge.compile.func.ts +0 -8
- package/testData/bridge.compiled.json +0 -1
- package/testData/contractAddress.json +0 -7
- package/testData/jettonTokenInfo.json +0 -14
- package/testData/prvlist.json +0 -6
- package/testData/smg.json +0 -5
- package/testData/tokenInfo.json +0 -23
- package/transResult/transResult.ts +0 -608
- package/tsconfig.json +0 -19
- package/utils/.compiled.json +0 -1
- package/utils/compileContract.ts +0 -60
- package/utils/log/.ba8901062aebb86bf525b42c65ff84f9485419e4-audit.json +0 -15
- package/utils/log/wan-ton-sdk.out.2025-01-08 +0 -0
- package/utils/logger.spec.ts +0 -14
- package/utils/logger.ts +0 -96
- package/utils/utils.spec.ts +0 -21
- package/utils/utils.ts +0 -295
- package/wallet/balance.ts +0 -29
- package/wallet/jetton.spec.ts +0 -27
- package/wallet/jetton.ts +0 -159
- package/wallet/walletContract.spec.ts +0 -111
- package/wallet/walletContract.ts +0 -105
- /package/{client/log/wan-ton-sdk.out.2024-12-19 → dist/config/config.d.ts} +0 -0
- /package/{code/log/wan-ton-sdk.out.2025-01-15 → dist/config/config.js} +0 -0
package/wallet/jetton.ts
DELETED
@@ -1,159 +0,0 @@
|
|
1
|
-
import {Address, beginCell, BitString, Builder, Cell, Dictionary} from "@ton/core";
|
2
|
-
import {TonClient} from "@ton/ton";
|
3
|
-
import {JettonMaster,JettonWallet} from "@ton/ton";
|
4
|
-
import {DictionaryKey, DictionaryKeyTypes, DictionaryValue} from "@ton/core"
|
5
|
-
import {sha256_sync} from "@ton/crypto";
|
6
|
-
|
7
|
-
export async function getJettonBalance(client:TonClient,jettonMasterAddr:Address, userAddress:Address): Promise<bigint> {
|
8
|
-
let jettonWalletAddress = await getJettonAddress(client,jettonMasterAddr,userAddress);
|
9
|
-
let jettonWalletContract = JettonWallet.create(jettonWalletAddress);
|
10
|
-
return await (client.open(jettonWalletContract)).getBalance();
|
11
|
-
}
|
12
|
-
|
13
|
-
export async function getJettonAddress(client:TonClient,jettonMasterAddr:Address,userAddress:Address){
|
14
|
-
let jettonMasterContract = JettonMaster.create(jettonMasterAddr);
|
15
|
-
return await (client.open(jettonMasterContract).getWalletAddress(userAddress));
|
16
|
-
}
|
17
|
-
|
18
|
-
export async function getJettonData(client:TonClient,jettonMasterAddr:Address){
|
19
|
-
let jettonMasterContract = JettonMaster.create(jettonMasterAddr);
|
20
|
-
return await (client.open(jettonMasterContract).getJettonData());
|
21
|
-
}
|
22
|
-
|
23
|
-
|
24
|
-
export async function getJettonDataContent(client:TonClient,jettonMasterAddr:Address){
|
25
|
-
let jettonMasterContract = JettonMaster.create(jettonMasterAddr);
|
26
|
-
return (await (client.open(jettonMasterContract).getJettonData())).content;
|
27
|
-
}
|
28
|
-
|
29
|
-
/*
|
30
|
-
opts= {
|
31
|
-
name:'dog', // string
|
32
|
-
symbol:'dog', // string
|
33
|
-
decimal:'5', // string
|
34
|
-
}
|
35
|
-
*/
|
36
|
-
|
37
|
-
function leftpad(str, len, ch=' ') {
|
38
|
-
str = String(str);
|
39
|
-
const pad = new Array(len - str.length + 1).join(ch);
|
40
|
-
return pad + str;
|
41
|
-
}
|
42
|
-
|
43
|
-
const SNAKE_PREFIX = 0x00;
|
44
|
-
const ONCHAIN_CONTENT_PREFIX = 0x00;
|
45
|
-
const KEYLEN = 256;
|
46
|
-
const jettonOnChainMetadataSpec = {
|
47
|
-
name: "utf8",
|
48
|
-
description: "utf8",
|
49
|
-
image: "ascii",
|
50
|
-
symbol: "utf8",
|
51
|
-
decimals: 'utf8'
|
52
|
-
};
|
53
|
-
|
54
|
-
async function getRidofProp(originalObj:any,propertiesToRemove:string[]):Promise<any> {
|
55
|
-
|
56
|
-
const newObj = Object.keys(originalObj)
|
57
|
-
.filter(key => !propertiesToRemove.includes(key))
|
58
|
-
.reduce((acc, key) => {
|
59
|
-
acc[key] = originalObj[key];
|
60
|
-
return acc;
|
61
|
-
}, {});
|
62
|
-
return newObj;
|
63
|
-
}
|
64
|
-
|
65
|
-
export async function buildWrappedJettonContent(opts:any):Promise<Cell>{
|
66
|
-
const dict = Dictionary.empty(Dictionary.Keys.BigUint(KEYLEN), Dictionary.Values.Cell());
|
67
|
-
|
68
|
-
let newOpts = await getRidofProp(opts,['tokenAddress']);
|
69
|
-
Object.entries(newOpts).forEach(([k, v]: [string, string | undefined]) => {
|
70
|
-
if (!jettonOnChainMetadataSpec[k])
|
71
|
-
throw new Error(`Unsupported token key: ${k}`);
|
72
|
-
if (v === undefined || v === "") return;
|
73
|
-
|
74
|
-
let bufferToStore = Buffer.from(v, jettonOnChainMetadataSpec[k]);
|
75
|
-
|
76
|
-
const rootCell = beginCell();
|
77
|
-
rootCell.storeUint(SNAKE_PREFIX, 8);
|
78
|
-
let currentCell = rootCell;
|
79
|
-
|
80
|
-
const CELL_MAX_SIZE_BYTES = Math.floor((1023 - 8) / 8);
|
81
|
-
while (bufferToStore.length > 0) {
|
82
|
-
currentCell.storeBuffer(bufferToStore.slice(0, CELL_MAX_SIZE_BYTES));
|
83
|
-
bufferToStore = bufferToStore.slice(CELL_MAX_SIZE_BYTES);
|
84
|
-
if (bufferToStore.length > 0) {
|
85
|
-
const newCell = beginCell();
|
86
|
-
currentCell.storeRef(newCell);
|
87
|
-
currentCell = newCell;
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
const keyHash = BigInt("0x" + sha256_sync(k).toString('hex'));
|
92
|
-
dict.set(keyHash, rootCell.endCell());
|
93
|
-
});
|
94
|
-
|
95
|
-
return beginCell()
|
96
|
-
.storeUint(ONCHAIN_CONTENT_PREFIX, 8)
|
97
|
-
.storeDict(dict)
|
98
|
-
.endCell();
|
99
|
-
}
|
100
|
-
|
101
|
-
export async function parseWrappedJettonContent(cell:Cell){
|
102
|
-
// const keys = Dictionary.Keys.BitString(256);
|
103
|
-
// const values = Dictionary.Values.Buffer(16);
|
104
|
-
|
105
|
-
// const keyName = new BitString(sha256_sync("name"),0,256);
|
106
|
-
// const keySymbol = new BitString(sha256_sync("symbol"),0,256);
|
107
|
-
// const keyDecimals = new BitString(sha256_sync("decimals"),0,256);
|
108
|
-
|
109
|
-
// let cs = cell.beginParse();
|
110
|
-
// cs.skip(8);
|
111
|
-
// let dictDs = Dictionary.loadDirect(keys, values, cs)
|
112
|
-
|
113
|
-
// return {
|
114
|
-
// name:dictDs.get(keyName).toString('utf-8').trim(),
|
115
|
-
// symbol:dictDs.get(keySymbol).toString('utf-8').trim(),
|
116
|
-
// decimals:dictDs.get(keyDecimals).toString('utf-8').trim(),
|
117
|
-
// }
|
118
|
-
|
119
|
-
const defaultJettonKeys = ["uri", "name", "description", "image", "image_data", "symbol", "decimals", "amount_style"]
|
120
|
-
const defaultNftKeys = ["uri", "name", "description", "image", "image_data"];
|
121
|
-
const contentValue = {
|
122
|
-
serialize: (src: any, builder: Builder) => {
|
123
|
-
builder.storeRef(beginCell().storeUint(0, 8).storeStringTail(src).endCell());
|
124
|
-
},
|
125
|
-
parse: (src: any) => {
|
126
|
-
const sc = src.loadRef().beginParse();
|
127
|
-
const prefix = sc.loadUint(8);
|
128
|
-
if(prefix == 0) {
|
129
|
-
return sc.loadStringTail();
|
130
|
-
}
|
131
|
-
else if(prefix == 1) {
|
132
|
-
// Not really tested, but feels like it should work
|
133
|
-
const chunkDict = Dictionary.loadDirect(Dictionary.Keys.Uint(32), Dictionary.Values.Cell(), sc);
|
134
|
-
return chunkDict.values().map(x => x.beginParse().loadStringTail()).join('');
|
135
|
-
}
|
136
|
-
else {
|
137
|
-
throw(Error(`Prefix ${prefix} is not supported yet`));
|
138
|
-
}
|
139
|
-
}
|
140
|
-
};
|
141
|
-
|
142
|
-
const content = cell.beginParse()
|
143
|
-
const type = content.loadUint(8)
|
144
|
-
console.log(`type is ${JSON.stringify(type)}`)
|
145
|
-
const contentDict = Dictionary.load(Dictionary.Keys.BigUint(256), contentValue, content);
|
146
|
-
const contentMap = {};
|
147
|
-
|
148
|
-
const contentKeys = defaultJettonKeys;
|
149
|
-
for (const name of contentKeys) {
|
150
|
-
// I know we should pre-compute hashed keys for known values... just not today.
|
151
|
-
const dictKey = BigInt("0x" + (sha256_sync(name)).toString('hex'))
|
152
|
-
const dictValue = contentDict.get(dictKey);
|
153
|
-
if(dictValue !== undefined) {
|
154
|
-
contentMap[name] = dictValue;
|
155
|
-
}
|
156
|
-
}
|
157
|
-
console.log(`jetton has content ${JSON.stringify(contentMap, null, 2)}`)
|
158
|
-
return contentMap
|
159
|
-
}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
import {TON_FEE} from "../fee/fee";
|
2
|
-
|
3
|
-
import {configTestnet,configMainnet} from "../config/config-ex";
|
4
|
-
import '@ton/test-utils';
|
5
|
-
import {sleep} from "../utils/utils";
|
6
|
-
|
7
|
-
const skSmg = new Buffer("097e961933fa62e3fef5cedef9a728a6a927a4b29f06a15c6e6c52c031a6cb2b", 'hex');
|
8
|
-
|
9
|
-
import {
|
10
|
-
getSenderByPrvKey,
|
11
|
-
getSender,
|
12
|
-
openWallet,
|
13
|
-
getWalletByPrvKey,
|
14
|
-
getWalletByMnemonic,
|
15
|
-
getTonAddrBySecPrvKey, getSenderBySecPrvKey, getWalletBySecPrvKey, getWalletAddrByPublicKey
|
16
|
-
} from "./walletContract";
|
17
|
-
|
18
|
-
import {KeyPair, mnemonicNew, mnemonicToWalletKey} from '@ton/crypto';
|
19
|
-
import {CommonMessageInfoRelaxedInternal, WalletContractV4} from "@ton/ton";
|
20
|
-
import {getClient, TonClientConfig} from "../client/client";
|
21
|
-
import {Address, beginCell, ContractProvider, MessageRelaxed, SendMode, toNano} from "@ton/core";
|
22
|
-
|
23
|
-
|
24
|
-
describe('walletContract', () => {
|
25
|
-
let mnemonics: string[][] = [[""],[""],[""],[""],[""]];
|
26
|
-
let accounts: WalletContractV4[] = [];
|
27
|
-
let keys: KeyPair[] = [];
|
28
|
-
|
29
|
-
beforeAll(async () => {
|
30
|
-
// create 5 account for example test
|
31
|
-
|
32
|
-
for(let i = 0 ;i<5;i++){
|
33
|
-
let mnemonic = await mnemonicNew(2);
|
34
|
-
mnemonics[i] = await mnemonicNew();
|
35
|
-
console.log(`mnemonics[${i}]=>`,mnemonics[i]);
|
36
|
-
}
|
37
|
-
});
|
38
|
-
|
39
|
-
beforeEach(async () => {
|
40
|
-
|
41
|
-
});
|
42
|
-
|
43
|
-
it('getWalletByMnemonic', async () => {
|
44
|
-
for(let i = 0; i < 5;i++){
|
45
|
-
let tempMnemonic = mnemonics[i].join(" ");
|
46
|
-
accounts.push(await getWalletByMnemonic(tempMnemonic));
|
47
|
-
console.log(`address[${i}]=>`,accounts[i].address);
|
48
|
-
}
|
49
|
-
});
|
50
|
-
|
51
|
-
it('getWalletAddrByPk', async () => {
|
52
|
-
console.log(await getWalletAddrByPublicKey(Buffer.from('497c3bc8bc7712f179d791e26a18544259909b11460fbf74027faf1a68ad515c','hex')));
|
53
|
-
});
|
54
|
-
|
55
|
-
it('address should equal (from mnemonic and from private key) success', async () => {
|
56
|
-
for(let i = 0; i < 5;i++){
|
57
|
-
let tempMnemonic = mnemonics[i];
|
58
|
-
keys.push(await mnemonicToWalletKey(tempMnemonic));
|
59
|
-
console.log(`pk[${i}]=>`,keys[i].publicKey.toString('hex'));
|
60
|
-
console.log(`prvKey[${i}]=>`,keys[i].secretKey.toString('hex'));
|
61
|
-
console.log(`mnemonics[${i}]=>`,tempMnemonic);
|
62
|
-
|
63
|
-
let wallet = await getWalletByPrvKey(keys[i].secretKey);
|
64
|
-
console.log(`address[${i}] from private key=>`,wallet.address);
|
65
|
-
console.log(`address[${i}] from mnenomic =>`,accounts[i].address);
|
66
|
-
|
67
|
-
expect((wallet.address.equals(accounts[i].address))).toBe(true);
|
68
|
-
}
|
69
|
-
});
|
70
|
-
|
71
|
-
it('only for test print', async () => {
|
72
|
-
for(let i = 0; i < 5;i++){
|
73
|
-
console.log(`pk[${i}]=>`,keys[i].publicKey.toString('hex'));
|
74
|
-
console.log(`prvKey[${i}]=>`,keys[i].secretKey.toString('hex'));
|
75
|
-
console.log(`mnemonics[${i}]=>`,mnemonics[i]);
|
76
|
-
console.log(`address[${i}] from private key=>`,accounts[i].address);
|
77
|
-
}
|
78
|
-
});
|
79
|
-
|
80
|
-
it('get address by sec prv key', async () => {
|
81
|
-
let rawAddr = "0:19dc7b6d850bd27b74b46017b8a23b014acd02f1fc324ad6f4a46159f024a8d1";
|
82
|
-
let addr = "EQAZ3HtthQvSe3S0YBe4ojsBSs0C8fwyStb0pGFZ8CSo0QSE";
|
83
|
-
let ret = await getTonAddrBySecPrvKey(skSmg);
|
84
|
-
expect(ret.rawAddr).toBe(rawAddr);
|
85
|
-
expect(ret.addr).toBe(addr);
|
86
|
-
});
|
87
|
-
|
88
|
-
it('active the wallet by sec prv key', async () => {
|
89
|
-
let rawAddr = "0:19dc7b6d850bd27b74b46017b8a23b014acd02f1fc324ad6f4a46159f024a8d1";
|
90
|
-
let addr = "EQAZ3HtthQvSe3S0YBe4ojsBSs0C8fwyStb0pGFZ8CSo0QSE";
|
91
|
-
|
92
|
-
let client = await getClient();
|
93
|
-
let wallet = await getWalletBySecPrvKey(skSmg)
|
94
|
-
let walletOpened = await client.open(wallet);
|
95
|
-
let seq = await walletOpened.getSeqno();
|
96
|
-
let via = await getSenderBySecPrvKey(client,skSmg);
|
97
|
-
|
98
|
-
let contractProvide = client.provider(Address.parse(addr));
|
99
|
-
let ret = await contractProvide.internal(via,{
|
100
|
-
value:TON_FEE.TRANS_FEE_NORMAL,
|
101
|
-
sendMode: SendMode.PAY_GAS_SEPARATELY,
|
102
|
-
body: beginCell().endCell(),
|
103
|
-
})
|
104
|
-
console.log("ret", ret);
|
105
|
-
let newSeq = seq;
|
106
|
-
while (newSeq == seq) {
|
107
|
-
await sleep(2000);
|
108
|
-
newSeq = await walletOpened.getSeqno();
|
109
|
-
}
|
110
|
-
},50000);
|
111
|
-
});
|
package/wallet/walletContract.ts
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
PayAttention:
|
3
|
-
This SDK only support v4 version wallet contract
|
4
|
-
for interface support all version of wallet contract, you can refer tonWeb sdk.
|
5
|
-
*/
|
6
|
-
|
7
|
-
//import {mnemonicToWalletKey, keyPairFromSecretKey} from "ton-crypto";
|
8
|
-
import {mnemonicToWalletKey, keyPairFromSecretKey} from "@ton/crypto";
|
9
|
-
import {address, TonClient, WalletContractV4} from "@ton/ton";
|
10
|
-
import {Address, ContractProvider, OpenedContract, Sender} from "@ton/core";
|
11
|
-
import {keyPairFromSeed} from "@ton/crypto";
|
12
|
-
import {Blockchain} from "@ton/sandbox";
|
13
|
-
|
14
|
-
export async function getWalletByMnemonic(mnemonic: String): Promise<WalletContractV4> {
|
15
|
-
const key = await mnemonicToWalletKey(mnemonic.split(" "));
|
16
|
-
return WalletContractV4.create({publicKey: key.publicKey, workchain: 0});
|
17
|
-
}
|
18
|
-
|
19
|
-
export function openWallet(client:TonClient,wallet:WalletContractV4):OpenedContract<WalletContractV4>{
|
20
|
-
return client.open(wallet);
|
21
|
-
}
|
22
|
-
|
23
|
-
export function getSender(provider: OpenedContract<WalletContractV4>,secretKey:Buffer):Sender{
|
24
|
-
return provider.sender(secretKey);
|
25
|
-
}
|
26
|
-
|
27
|
-
// for ed25519 private key
|
28
|
-
export async function getWalletByPrvKey(privateKey: Buffer): Promise<WalletContractV4> {
|
29
|
-
const key = keyPairFromSecretKey(privateKey);
|
30
|
-
return WalletContractV4.create({publicKey: key.publicKey, workchain: 0});
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
export async function getTonAddrByPrvKey(privateKey: Buffer){
|
35
|
-
return {
|
36
|
-
rawAddr: (await getWalletByPrvKey(privateKey)).address.toRawString(),
|
37
|
-
Addr:(await getWalletByPrvKey(privateKey)).address.toString(),
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
export async function getSenderByPrvKey(client:TonClient,privateKey: Buffer):Promise<Sender>{
|
42
|
-
let wallet = await getWalletByPrvKey(privateKey);
|
43
|
-
return getSender(openWallet(client,wallet),privateKey);
|
44
|
-
}
|
45
|
-
|
46
|
-
// example addr: EQDKbjIcfM6ezt8KjKJJLshZJJSqX7XOA4ff-W72r5gqPrHF
|
47
|
-
// example rawAddr: 0:ca6e321c7cce9ecedf0a8ca2492ec8592494aa5fb5ce0387dff96ef6af982a3e
|
48
|
-
export async function getWalletAddrByPrvKey(privateKey: Buffer){
|
49
|
-
return {
|
50
|
-
addr: (await getWalletByPrvKey(privateKey)).address.toString(),
|
51
|
-
rawAddr: (await getWalletByPrvKey(privateKey)).address.toRawString()
|
52
|
-
}
|
53
|
-
}
|
54
|
-
|
55
|
-
export async function openWalletByPrvKey(client:TonClient,privateKey: Buffer){
|
56
|
-
return await openWallet(client,await getWalletByPrvKey(privateKey));
|
57
|
-
}
|
58
|
-
|
59
|
-
// for evm private key
|
60
|
-
export async function getWalletBySecPrvKey(privateKey: Buffer):Promise<WalletContractV4>{
|
61
|
-
const key = keyPairFromSeed(privateKey);
|
62
|
-
return WalletContractV4.create({publicKey: key.publicKey, workchain: 0});
|
63
|
-
}
|
64
|
-
|
65
|
-
export async function getTonAddrBySecPrvKey(privateKey: Buffer){
|
66
|
-
return {
|
67
|
-
rawAddr: (await getWalletBySecPrvKey(privateKey)).address.toRawString(),
|
68
|
-
addr:(await getWalletBySecPrvKey(privateKey)).address.toString(),
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
export async function getSenderBySecPrvKey(client:TonClient,privateKey: Buffer):Promise<Sender>{
|
73
|
-
let wallet = await getWalletBySecPrvKey(privateKey);
|
74
|
-
const key = keyPairFromSeed(privateKey);
|
75
|
-
return getSender(openWallet(client,wallet),key.secretKey);
|
76
|
-
}
|
77
|
-
|
78
|
-
export async function openWalletBySecPrvKey(client:TonClient,privateKey: Buffer){
|
79
|
-
return await openWallet(client,await getWalletBySecPrvKey(privateKey));
|
80
|
-
}
|
81
|
-
|
82
|
-
export async function getWalletAddrBySecPrvKey(privateKey: Buffer){
|
83
|
-
return {
|
84
|
-
addr: (await getWalletBySecPrvKey(privateKey)).address.toString(),
|
85
|
-
rawAddr: (await getWalletBySecPrvKey(privateKey)).address.toRawString()
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
// others
|
90
|
-
export async function isAddrDepolyed(client:TonClient|Blockchain,addrStr:string){
|
91
|
-
if(client instanceof TonClient){
|
92
|
-
let addr = Address.parse(addrStr);
|
93
|
-
return await client.isContractDeployed(addr);
|
94
|
-
}else{
|
95
|
-
let addr = Address.parse(addrStr);
|
96
|
-
return (await client.getContract(addr)).accountState?.type === 'active'
|
97
|
-
}
|
98
|
-
}
|
99
|
-
|
100
|
-
export async function getWalletAddrByPublicKey(publicKey: Buffer){
|
101
|
-
let ret = WalletContractV4.create({publicKey: publicKey, workchain: 0});
|
102
|
-
return ret.address.toString();
|
103
|
-
}
|
104
|
-
|
105
|
-
|
File without changes
|
File without changes
|