@layerzerolabs/ton-sdk-tools 3.0.88 → 3.0.90-aptos-301.2
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 +0 -12
- package/dist/index.cjs +211 -169
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -23
- package/dist/index.d.ts +1 -23
- package/dist/index.mjs +213 -159
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,5 @@
|
|
|
1
1
|
# @layerzerolabs/ton-sdk-tools
|
|
2
2
|
|
|
3
|
-
## 3.0.88
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- d0cda5e: ton sdk-tools refactored, added rawDispatch action to funC++
|
|
8
|
-
|
|
9
|
-
## 3.0.87
|
|
10
|
-
|
|
11
|
-
### Patch Changes
|
|
12
|
-
|
|
13
|
-
- e92c65d: Update initia.js version
|
|
14
|
-
|
|
15
3
|
## 3.0.86
|
|
16
4
|
|
|
17
5
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,6 @@ var fs = require('fs');
|
|
|
4
4
|
var path = require('path');
|
|
5
5
|
var core = require('@ton/core');
|
|
6
6
|
var crc32 = require('crc-32');
|
|
7
|
-
var ethers = require('ethers');
|
|
8
7
|
var bigintBuffer = require('bigint-buffer');
|
|
9
8
|
var Event = require('@ton/sandbox/dist/event/Event');
|
|
10
9
|
var testUtils = require('@ton/test-utils');
|
|
@@ -35,85 +34,15 @@ var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
|
35
34
|
var crc32__namespace = /*#__PURE__*/_interopNamespace(crc32);
|
|
36
35
|
|
|
37
36
|
// src/sdk-tools.ts
|
|
38
|
-
function to32ByteBuffer(value, maxIntermediateBufferSize = 66) {
|
|
39
|
-
if (typeof value === "string") {
|
|
40
|
-
if (!isValidHex(value)) {
|
|
41
|
-
throw new Error("only hex string is supported");
|
|
42
|
-
}
|
|
43
|
-
let hex = trim0x(value);
|
|
44
|
-
if (hex.length % 2 !== 0) {
|
|
45
|
-
hex = "0" + hex;
|
|
46
|
-
}
|
|
47
|
-
value = bigintBuffer.toBigIntBE(Buffer.from(hex, "hex"));
|
|
48
|
-
}
|
|
49
|
-
if (value instanceof Uint8Array) {
|
|
50
|
-
value = bigintBuffer.toBigIntBE(Buffer.from(value));
|
|
51
|
-
}
|
|
52
|
-
const bf = bigintBuffer.toBufferBE(BigInt(value), maxIntermediateBufferSize);
|
|
53
|
-
return bf.subarray(-32);
|
|
54
|
-
}
|
|
55
|
-
function trim0x(str2) {
|
|
56
|
-
return str2.replace(/^0x/, "");
|
|
57
|
-
}
|
|
58
|
-
function isValidHex(str2) {
|
|
59
|
-
const hexRegex = /^(0x)?[0-9A-Fa-f]+$/;
|
|
60
|
-
return hexRegex.test(str2);
|
|
61
|
-
}
|
|
62
|
-
function bigintToAddress(value) {
|
|
63
|
-
const buf = to32ByteBuffer(value);
|
|
64
|
-
return core.Address.parse(`0:${buf.toString("hex")}`);
|
|
65
|
-
}
|
|
66
|
-
var parseTonAddress = (address) => {
|
|
67
|
-
if (address instanceof core.Address) {
|
|
68
|
-
return address;
|
|
69
|
-
}
|
|
70
|
-
if (typeof address === "bigint" || typeof address === "number") {
|
|
71
|
-
return bigintToAddress(BigInt(address));
|
|
72
|
-
}
|
|
73
|
-
if (address.startsWith("0x")) {
|
|
74
|
-
return bigintToAddress(BigInt(address));
|
|
75
|
-
}
|
|
76
|
-
try {
|
|
77
|
-
return core.Address.parse(address);
|
|
78
|
-
} catch (e) {
|
|
79
|
-
return bigintToAddress(BigInt(`0x${address}`));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var _addressToNotPaddedHex = (address) => {
|
|
83
|
-
return `0x${parseTonAddress(address).hash.toString("hex")}`;
|
|
84
|
-
};
|
|
85
|
-
var bigIntToHex = (bigInt) => {
|
|
86
|
-
return `0x${bigInt.toString(16)}`.toLowerCase();
|
|
87
|
-
};
|
|
88
|
-
var addressToHex = (address) => {
|
|
89
|
-
return `0x${to32ByteBuffer(_addressToNotPaddedHex(address)).toString("hex")}`.toLowerCase();
|
|
90
|
-
};
|
|
91
|
-
var addressToBigInt = (address) => {
|
|
92
|
-
return BigInt(_addressToNotPaddedHex(address));
|
|
93
|
-
};
|
|
94
|
-
var compareAddresses = (addressA, addressB) => {
|
|
95
|
-
return parseTonAddress(addressA).equals(parseTonAddress(addressB));
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/utils.ts
|
|
99
37
|
var MASTER_CHAIN_ID = -1;
|
|
100
38
|
var BASE_CHAIN_ID = 0;
|
|
101
39
|
var MASTER_CHAIN_SHARD = "8000000000000000";
|
|
102
40
|
var PUBLIC_KEY_BYTE_LENGTH = 64;
|
|
103
|
-
var SIGNATURE_BYTE_LENGTH = 65;
|
|
104
|
-
var SEED_SIZE = 32;
|
|
105
41
|
function publicKeyToHash(publicKey) {
|
|
106
42
|
const publicKeyCell = core.beginCell().storeBuffer(Buffer.from(publicKey), PUBLIC_KEY_BYTE_LENGTH).endCell();
|
|
107
43
|
const publicKeyHash = BigInt("0x" + publicKeyCell.hash().toString("hex"));
|
|
108
44
|
return publicKeyHash;
|
|
109
45
|
}
|
|
110
|
-
function preprocessPublicKey(publicKey) {
|
|
111
|
-
const publicKeyBuffer = Buffer.from(publicKey.slice(2), "hex");
|
|
112
|
-
return publicKeyBuffer.subarray(1);
|
|
113
|
-
}
|
|
114
|
-
function stringPublicKeyToHash(publicKey) {
|
|
115
|
-
return publicKeyToHash(preprocessPublicKey(publicKey));
|
|
116
|
-
}
|
|
117
46
|
function createVerifierDictSet(verifiers) {
|
|
118
47
|
const verifierDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
119
48
|
for (const verifier of verifiers) {
|
|
@@ -121,46 +50,6 @@ function createVerifierDictSet(verifiers) {
|
|
|
121
50
|
}
|
|
122
51
|
return core.beginCell().storeDictDirect(verifierDict, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
123
52
|
}
|
|
124
|
-
function createVerifierDictSetFromStrings(publicKeys) {
|
|
125
|
-
const publicKeyBuffers = publicKeys.map((key) => preprocessPublicKey(key));
|
|
126
|
-
return createVerifierDictSet(publicKeyBuffers);
|
|
127
|
-
}
|
|
128
|
-
function createVerifierDictSetFromEtherWallets(verifiers) {
|
|
129
|
-
const publicKeys = verifiers.map((key) => key.publicKey);
|
|
130
|
-
return createVerifierDictSetFromStrings(publicKeys);
|
|
131
|
-
}
|
|
132
|
-
function createAdminDictSet(admins) {
|
|
133
|
-
const verifierDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
134
|
-
for (const admin of admins) {
|
|
135
|
-
verifierDict.set(addressToBigInt(admin.address), core.beginCell().endCell());
|
|
136
|
-
}
|
|
137
|
-
return core.beginCell().storeDictDirect(verifierDict, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
138
|
-
}
|
|
139
|
-
function createSignatures(hash, verifiers) {
|
|
140
|
-
const signatures = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
141
|
-
for (const verifier of verifiers) {
|
|
142
|
-
const signature = verifier._signingKey().signDigest(hash);
|
|
143
|
-
const signatureBytes = ethers.ethers.utils.splitSignature(signature);
|
|
144
|
-
const signatureBytesArray = new Uint8Array([
|
|
145
|
-
...ethers.ethers.utils.arrayify(signatureBytes.r),
|
|
146
|
-
...ethers.ethers.utils.arrayify(signatureBytes.s),
|
|
147
|
-
signatureBytes.v
|
|
148
|
-
]);
|
|
149
|
-
signatures.set(
|
|
150
|
-
stringPublicKeyToHash(verifier.publicKey),
|
|
151
|
-
core.beginCell().storeBuffer(Buffer.from(signatureBytesArray), SIGNATURE_BYTE_LENGTH).endCell()
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
return core.beginCell().storeDictDirect(signatures, core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell()).endCell();
|
|
155
|
-
}
|
|
156
|
-
function generateRandomVerifierSet(count) {
|
|
157
|
-
const verifiers = [];
|
|
158
|
-
for (let i = 0; i < count; i++) {
|
|
159
|
-
const privateKey = ethers.ethers.utils.randomBytes(SEED_SIZE);
|
|
160
|
-
verifiers.push(new ethers.ethers.Wallet(privateKey));
|
|
161
|
-
}
|
|
162
|
-
return verifiers;
|
|
163
|
-
}
|
|
164
53
|
var getBocStringFromMessage = (message) => {
|
|
165
54
|
return core.beginCell().store(core.storeMessageRelaxed(message)).endCell().toBoc().toString("base64");
|
|
166
55
|
};
|
|
@@ -185,16 +74,6 @@ function findDeepestCell(cell) {
|
|
|
185
74
|
}
|
|
186
75
|
return { subTreeCells: size };
|
|
187
76
|
}
|
|
188
|
-
function addLibToBlockchain(blockchain, newLib) {
|
|
189
|
-
let libsDict;
|
|
190
|
-
if (blockchain.libs) {
|
|
191
|
-
libsDict = blockchain.libs.beginParse().loadDictDirect(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
192
|
-
} else {
|
|
193
|
-
libsDict = core.Dictionary.empty(core.Dictionary.Keys.BigUint(256), core.Dictionary.Values.Cell());
|
|
194
|
-
}
|
|
195
|
-
libsDict.set(BigInt(`0x${newLib.hash().toString("hex")}`), newLib);
|
|
196
|
-
blockchain.libs = core.beginCell().storeDictDirect(libsDict).endCell();
|
|
197
|
-
}
|
|
198
77
|
|
|
199
78
|
// src/sdk-tools.ts
|
|
200
79
|
var file_signature_header = `////// Generated by sdk/sdk-generator.ts`;
|
|
@@ -466,11 +345,11 @@ function saveBaseEventHandler(directory, opcodesImportPath = "../constants", all
|
|
|
466
345
|
import { Cell, Transaction, TransactionComputeVm, TransactionDescriptionGeneric, beginCell } from '@ton/core'
|
|
467
346
|
import { BlockchainTransaction, EventMessageSent, SendMessageResult } from '@ton/sandbox'
|
|
468
347
|
import { flattenTransaction } from '@ton/test-utils'
|
|
469
|
-
import { ExtendedContract
|
|
348
|
+
import { ExtendedContract } from '${baseWrapperImportPath}'
|
|
470
349
|
|
|
471
350
|
import { OPCODES } from '${opcodesImportPath}'
|
|
472
351
|
|
|
473
|
-
import {
|
|
352
|
+
import { getLzDict,
|
|
474
353
|
${allTypes.map((type) => " " + type + ",\n").join("")}} from '${allTypesImportPath}'
|
|
475
354
|
|
|
476
355
|
import { TonObjectUnwrapper } from '${tonObjectUnwrapperImportPath}'
|
|
@@ -667,7 +546,40 @@ import { Cell, OpenedContract, beginCell } from '@ton/core'
|
|
|
667
546
|
import { SandboxContract } from '@ton/sandbox'
|
|
668
547
|
|
|
669
548
|
import { TonContractWrapper } from '${tonContractWrapperImportPath}'
|
|
670
|
-
import { ExtendedContract
|
|
549
|
+
import { ExtendedContract } from '${baseWrapperImportPath}'
|
|
550
|
+
|
|
551
|
+
export class LzDict {
|
|
552
|
+
_cell: Cell
|
|
553
|
+
|
|
554
|
+
constructor(data: Cell) {
|
|
555
|
+
this._cell = data
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
static empty(): LzDict {
|
|
559
|
+
return new LzDict(beginCell().endCell())
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
async getCell(key: bigint, wrapper: ExtendedContract<TonContractWrapper>): Promise<Cell> {
|
|
563
|
+
return wrapper.getDictCellItem(this._cell, key)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
async getBigInt(key: bigint, wrapper: ExtendedContract<TonContractWrapper>): Promise<bigint> {
|
|
567
|
+
return wrapper.getDictUint256Item(this._cell, key)
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async set(key: bigint, value: Cell, wrapper: ExtendedContract<TonContractWrapper>): Promise<void> {
|
|
571
|
+
this._cell = await wrapper.getSetDictItem(this._cell, key, value)
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
asCell(): Cell {
|
|
575
|
+
return this._cell
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
export async function getLzDict(obj: Cell, fieldName: bigint, wrapper: ExtendedContract<TonContractWrapper>): Promise<LzDict> {
|
|
580
|
+
const dictCell = await wrapper.getClDict(obj, fieldName)
|
|
581
|
+
return new LzDict(dictCell)
|
|
582
|
+
}
|
|
671
583
|
|
|
672
584
|
export interface Md {}
|
|
673
585
|
|
|
@@ -810,6 +722,7 @@ export class LzGasTracker {
|
|
|
810
722
|
function saveTonObjectUnwrapper(tonObjects, directory, allTypesImportPath = "./allTypes", tonContractWrapperImportPath = "./TonContractWrapper", classlibWrapperImportPath = "@layerzerolabs/ton-sdk-tools", baseWrapperImportPath = "@layerzerolabs/ton-sdk-tools") {
|
|
811
723
|
const allTypes = [
|
|
812
724
|
...Object.values(tonObjects).map((obj) => obj.tsTypeName).filter((name) => name !== void 0),
|
|
725
|
+
"LzDict",
|
|
813
726
|
"Md",
|
|
814
727
|
"nameMap"
|
|
815
728
|
].sort();
|
|
@@ -821,11 +734,11 @@ import { Cell, Transaction, TransactionComputeVm, TransactionDescriptionGeneric,
|
|
|
821
734
|
import { BlockchainTransaction, EventMessageSent, SendMessageResult } from '@ton/sandbox'
|
|
822
735
|
import { flattenTransaction } from '@ton/test-utils'
|
|
823
736
|
|
|
824
|
-
import {
|
|
737
|
+
import { getLzDict,
|
|
825
738
|
${allTypes.map((type) => " " + type + ",\n").join("")}} from '${allTypesImportPath}'
|
|
826
739
|
import { TonContractWrapper } from '${tonContractWrapperImportPath}'
|
|
827
740
|
import { ClasslibWrapper } from '${classlibWrapperImportPath}'
|
|
828
|
-
import { ExtendedContract
|
|
741
|
+
import { ExtendedContract } from '${baseWrapperImportPath}'
|
|
829
742
|
|
|
830
743
|
export class TonObjectUnwrapper {
|
|
831
744
|
${Array.from(
|
|
@@ -1234,6 +1147,65 @@ function saveViewFunctions(viewFunctions, directory, filename) {
|
|
|
1234
1147
|
}
|
|
1235
1148
|
fs__namespace.writeFileSync(path__namespace.join(directory, filename), generated.join("\n"));
|
|
1236
1149
|
}
|
|
1150
|
+
function to32ByteBuffer(value, maxIntermediateBufferSize = 66) {
|
|
1151
|
+
if (typeof value === "string") {
|
|
1152
|
+
if (!isValidHex(value)) {
|
|
1153
|
+
throw new Error("only hex string is supported");
|
|
1154
|
+
}
|
|
1155
|
+
let hex = trim0x(value);
|
|
1156
|
+
if (hex.length % 2 !== 0) {
|
|
1157
|
+
hex = "0" + hex;
|
|
1158
|
+
}
|
|
1159
|
+
value = bigintBuffer.toBigIntBE(Buffer.from(hex, "hex"));
|
|
1160
|
+
}
|
|
1161
|
+
if (value instanceof Uint8Array) {
|
|
1162
|
+
value = bigintBuffer.toBigIntBE(Buffer.from(value));
|
|
1163
|
+
}
|
|
1164
|
+
const bf = bigintBuffer.toBufferBE(BigInt(value), maxIntermediateBufferSize);
|
|
1165
|
+
return bf.subarray(-32);
|
|
1166
|
+
}
|
|
1167
|
+
function trim0x(str2) {
|
|
1168
|
+
return str2.replace(/^0x/, "");
|
|
1169
|
+
}
|
|
1170
|
+
function isValidHex(str2) {
|
|
1171
|
+
const hexRegex = /^(0x)?[0-9A-Fa-f]+$/;
|
|
1172
|
+
return hexRegex.test(str2);
|
|
1173
|
+
}
|
|
1174
|
+
function bigintToAddress(value) {
|
|
1175
|
+
const buf = to32ByteBuffer(value);
|
|
1176
|
+
return core.Address.parse(`0:${buf.toString("hex")}`);
|
|
1177
|
+
}
|
|
1178
|
+
var parseTonAddress = (address) => {
|
|
1179
|
+
if (address instanceof core.Address) {
|
|
1180
|
+
return address;
|
|
1181
|
+
}
|
|
1182
|
+
if (typeof address === "bigint" || typeof address === "number") {
|
|
1183
|
+
return bigintToAddress(BigInt(address));
|
|
1184
|
+
}
|
|
1185
|
+
if (address.startsWith("0x")) {
|
|
1186
|
+
return bigintToAddress(BigInt(address));
|
|
1187
|
+
}
|
|
1188
|
+
try {
|
|
1189
|
+
return core.Address.parse(address);
|
|
1190
|
+
} catch (e) {
|
|
1191
|
+
return bigintToAddress(BigInt(`0x${address}`));
|
|
1192
|
+
}
|
|
1193
|
+
};
|
|
1194
|
+
var _addressToNotPaddedHex = (address) => {
|
|
1195
|
+
return `0x${parseTonAddress(address).hash.toString("hex")}`;
|
|
1196
|
+
};
|
|
1197
|
+
var bigIntToHex = (bigInt) => {
|
|
1198
|
+
return `0x${bigInt.toString(16)}`.toLowerCase();
|
|
1199
|
+
};
|
|
1200
|
+
var addressToHex = (address) => {
|
|
1201
|
+
return `0x${to32ByteBuffer(_addressToNotPaddedHex(address)).toString("hex")}`.toLowerCase();
|
|
1202
|
+
};
|
|
1203
|
+
var addressToBigInt = (address) => {
|
|
1204
|
+
return BigInt(_addressToNotPaddedHex(address));
|
|
1205
|
+
};
|
|
1206
|
+
var compareAddresses = (addressA, addressB) => {
|
|
1207
|
+
return parseTonAddress(addressA).equals(parseTonAddress(addressB));
|
|
1208
|
+
};
|
|
1237
1209
|
var BaseWrapper = class {
|
|
1238
1210
|
constructor(address, init) {
|
|
1239
1211
|
this.address = address;
|
|
@@ -1438,12 +1410,11 @@ import {
|
|
|
1438
1410
|
ExtendedContract,
|
|
1439
1411
|
sendMessageViaMultisigAndExpect,
|
|
1440
1412
|
sendInternalMessageAndExpect,
|
|
1441
|
-
|
|
1442
|
-
toHaveTransactions,
|
|
1443
|
-
addLibToBlockchain
|
|
1413
|
+
toHaveTransactions
|
|
1444
1414
|
} from '@layerzerolabs/ton-sdk-tools'
|
|
1445
1415
|
|
|
1446
1416
|
import {
|
|
1417
|
+
LzDict,
|
|
1447
1418
|
LzEventHandler,
|
|
1448
1419
|
MdPacketSent,
|
|
1449
1420
|
OPCODES,
|
|
@@ -1480,6 +1451,10 @@ export const newTonObjectsContainer: { items: { [key: string]: unknown } } = {
|
|
|
1480
1451
|
items: {},
|
|
1481
1452
|
}
|
|
1482
1453
|
|
|
1454
|
+
export const PUBLIC_KEY_BYTE_LENGTH = 64
|
|
1455
|
+
export const SIGNATURE_BYTE_LENGTH = 65
|
|
1456
|
+
const SEED_SIZE = 32
|
|
1457
|
+
|
|
1483
1458
|
// ==============================PROTOCOL SETUP GAS==============================
|
|
1484
1459
|
|
|
1485
1460
|
// todo update these to be accurate when ready. To fragile now during development
|
|
@@ -1513,6 +1488,40 @@ export const OAppFlowGas = {
|
|
|
1513
1488
|
|
|
1514
1489
|
export const emptyObject = beginCell().storeUint(0, 1).endCell()
|
|
1515
1490
|
|
|
1491
|
+
// ===============================INTERFACES===============================
|
|
1492
|
+
|
|
1493
|
+
export function publicKeyToHash(publicKey: string): bigint {
|
|
1494
|
+
// Remove '0x' prefix and convert to Buffer
|
|
1495
|
+
const publicKeyBuffer = Buffer.from(publicKey.slice(2), 'hex')
|
|
1496
|
+
// skip the first byte (h) as it's always 4
|
|
1497
|
+
const publicKeyWithoutH = publicKeyBuffer.subarray(1)
|
|
1498
|
+
const publicKeyCell = beginCell().storeBuffer(publicKeyWithoutH, PUBLIC_KEY_BYTE_LENGTH).endCell()
|
|
1499
|
+
const publicKeyHash = BigInt('0x' + publicKeyCell.hash().toString('hex'))
|
|
1500
|
+
return publicKeyHash
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
// ==============================VERIFIER SET==============================
|
|
1504
|
+
|
|
1505
|
+
export function generateRandomVerifierSet(count: number): ethers.Wallet[] {
|
|
1506
|
+
const verifiers: ethers.Wallet[] = []
|
|
1507
|
+
for (let i = 0; i < count; i++) {
|
|
1508
|
+
const privateKey = ethers.utils.randomBytes(SEED_SIZE)
|
|
1509
|
+
verifiers.push(new ethers.Wallet(privateKey))
|
|
1510
|
+
}
|
|
1511
|
+
return verifiers
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
export async function createVerifierDictSet(
|
|
1515
|
+
verifiers: ethers.Wallet[],
|
|
1516
|
+
wrapper: ExtendedContract<TonContractWrapper>
|
|
1517
|
+
): Promise<Cell> {
|
|
1518
|
+
const verifierDict = LzDict.empty()
|
|
1519
|
+
for (const verifier of verifiers) {
|
|
1520
|
+
await verifierDict.set(publicKeyToHash(verifier.publicKey), beginCell().endCell(), wrapper)
|
|
1521
|
+
}
|
|
1522
|
+
return verifierDict.asCell()
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1516
1525
|
export function serializeAddressList(admins: SandboxContract<TreasuryContract | TonContractWrapper>[]): Cell {
|
|
1517
1526
|
const addressList = admins.map((admin) => addressToBigInt(admin.address))
|
|
1518
1527
|
|
|
@@ -2004,6 +2013,17 @@ export async function getExecutionStatus(
|
|
|
2004
2013
|
return (await contract.getViewFunction('_viewExecutionStatus', args)).readBigNumber()
|
|
2005
2014
|
}
|
|
2006
2015
|
|
|
2016
|
+
export function addLibToBlockchain(blockchain: Blockchain, newLib: Cell): void {
|
|
2017
|
+
let libsDict: Dictionary<bigint, Cell>
|
|
2018
|
+
if (blockchain.libs) {
|
|
2019
|
+
libsDict = blockchain.libs.beginParse().loadDictDirect(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell())
|
|
2020
|
+
} else {
|
|
2021
|
+
libsDict = Dictionary.empty(Dictionary.Keys.BigUint(256), Dictionary.Values.Cell())
|
|
2022
|
+
}
|
|
2023
|
+
libsDict.set(BigInt(\`0x\${newLib.hash().toString('hex')}\`), newLib)
|
|
2024
|
+
blockchain.libs = beginCell().storeDictDirect(libsDict).endCell()
|
|
2025
|
+
}
|
|
2026
|
+
|
|
2007
2027
|
// ===============================DEPLOYING CONTRACTS===============================
|
|
2008
2028
|
|
|
2009
2029
|
export async function openAndDeployControllerViaMultiSig(
|
|
@@ -3140,7 +3160,7 @@ import ProxyArtifact from '@layerzerolabs/layerzero-v2-ton/build/Proxy.compiled.
|
|
|
3140
3160
|
import UlnArtifact from '@layerzerolabs/layerzero-v2-ton/build/Uln.compiled.json'
|
|
3141
3161
|
import UlnConnectionArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnConnection.compiled.json'
|
|
3142
3162
|
import UlnManagerArtifact from '@layerzerolabs/layerzero-v2-ton/build/UlnManager.compiled.json'
|
|
3143
|
-
import { BlueprintArtfiact, ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect,
|
|
3163
|
+
import { BlueprintArtfiact, ExtendedContract, Profile, addressToBigInt, cellFromArtifact, sendInternalMessageAndExpect, sendMessageViaMultisigAndExpect, } from '@layerzerolabs/ton-sdk-tools'
|
|
3144
3164
|
|
|
3145
3165
|
import {
|
|
3146
3166
|
OAppFixture,
|
|
@@ -3149,7 +3169,9 @@ import {
|
|
|
3149
3169
|
SIGNATURE_BYTE_LENGTH,
|
|
3150
3170
|
addMsgLibToController,
|
|
3151
3171
|
createLzPacketFromPacketEncoded,
|
|
3172
|
+
createVerifierDictSet,
|
|
3152
3173
|
emptyObject,
|
|
3174
|
+
generateRandomVerifierSet,
|
|
3153
3175
|
protocolSetupGas,
|
|
3154
3176
|
publicKeyToHash,
|
|
3155
3177
|
requireDefined,
|
|
@@ -3159,6 +3181,7 @@ import {
|
|
|
3159
3181
|
} from './auto-utils-common'
|
|
3160
3182
|
|
|
3161
3183
|
import {
|
|
3184
|
+
LzDict,
|
|
3162
3185
|
LzEventHandler,
|
|
3163
3186
|
MdPacketSent,
|
|
3164
3187
|
OPCODES,
|
|
@@ -3741,7 +3764,7 @@ export async function openAndDeployDvnAndProxy(
|
|
|
3741
3764
|
admins: serializeAddressList(adminSet),
|
|
3742
3765
|
version: version,
|
|
3743
3766
|
quorum: 1n,
|
|
3744
|
-
verifiers:
|
|
3767
|
+
verifiers: await createVerifierDictSet(verifierSet, allStorages),
|
|
3745
3768
|
})
|
|
3746
3769
|
)
|
|
3747
3770
|
)
|
|
@@ -4810,6 +4833,61 @@ export const dvnSetupGas = {
|
|
|
4810
4833
|
'Dvn.SEND_SIGNED_REQUEST': toNano('10'), // 0.235917
|
|
4811
4834
|
}
|
|
4812
4835
|
|
|
4836
|
+
export async function createAdminDictSet(
|
|
4837
|
+
admins: SandboxContract<TreasuryContract | TonContractWrapper>[],
|
|
4838
|
+
wrapper: ExtendedContract<TonContractWrapper>
|
|
4839
|
+
): Promise<Cell> {
|
|
4840
|
+
const adminDict = LzDict.empty()
|
|
4841
|
+
for (const admin of admins) {
|
|
4842
|
+
await adminDict.set(addressToBigInt(admin.address), beginCell().endCell(), wrapper)
|
|
4843
|
+
}
|
|
4844
|
+
return adminDict.asCell()
|
|
4845
|
+
}
|
|
4846
|
+
|
|
4847
|
+
export async function createSignatures(
|
|
4848
|
+
hash: Buffer,
|
|
4849
|
+
verifiers: ethers.Wallet[],
|
|
4850
|
+
wrapper: ExtendedContract<TonContractWrapper>
|
|
4851
|
+
): Promise<Cell> {
|
|
4852
|
+
const signatures = LzDict.empty()
|
|
4853
|
+
for (const verifier of verifiers) {
|
|
4854
|
+
// doing this one insted of .signMessage() to not sign with the "Ethereum" prefix
|
|
4855
|
+
const signature = verifier._signingKey().signDigest(hash)
|
|
4856
|
+
const signatureBytes = ethers.utils.splitSignature(signature)
|
|
4857
|
+
const signatureBytesArray = new Uint8Array([
|
|
4858
|
+
...ethers.utils.arrayify(signatureBytes.r),
|
|
4859
|
+
...ethers.utils.arrayify(signatureBytes.s),
|
|
4860
|
+
signatureBytes.v,
|
|
4861
|
+
])
|
|
4862
|
+
|
|
4863
|
+
await signatures.set(
|
|
4864
|
+
publicKeyToHash(verifier.publicKey),
|
|
4865
|
+
beginCell().storeBuffer(Buffer.from(signatureBytesArray), SIGNATURE_BYTE_LENGTH).endCell(),
|
|
4866
|
+
wrapper
|
|
4867
|
+
)
|
|
4868
|
+
|
|
4869
|
+
// Sanity Check: Attempt to recover the public key from the signature
|
|
4870
|
+
// const messageHash = ethers.utils.arrayify(hash)
|
|
4871
|
+
// try {
|
|
4872
|
+
// const recoveredPublicKey = ethers.utils.recoverPublicKey(messageHash, signatureBytes)
|
|
4873
|
+
// const originalPublicKey = verifier.publicKey
|
|
4874
|
+
|
|
4875
|
+
// console.log(\`Verifier:\`)
|
|
4876
|
+
// console.log(\`Original public key: \${originalPublicKey}\`)
|
|
4877
|
+
// console.log(\`Recovered public key: \${recoveredPublicKey}\`)
|
|
4878
|
+
|
|
4879
|
+
// if (recoveredPublicKey.toLowerCase() === originalPublicKey.toLowerCase()) {
|
|
4880
|
+
// console.log('Public key successfully recovered!')
|
|
4881
|
+
// } else {
|
|
4882
|
+
// console.log('Public key recovery failed.')
|
|
4883
|
+
// }
|
|
4884
|
+
// } catch (error) {
|
|
4885
|
+
// console.error(\`Error recovering public key for verifier:\`, error)
|
|
4886
|
+
// }
|
|
4887
|
+
}
|
|
4888
|
+
return signatures.asCell()
|
|
4889
|
+
}
|
|
4890
|
+
|
|
4813
4891
|
// ================================DVN: SEND REQUEST================================
|
|
4814
4892
|
|
|
4815
4893
|
interface SignAndSendRequestToDvnParams {
|
|
@@ -4833,7 +4911,7 @@ export async function signAndSendRequestToDvn({
|
|
|
4833
4911
|
}: SignAndSendRequestToDvnParams): Promise<SendMessageResult> {
|
|
4834
4912
|
const signedRequest = await allStorages.getNewMdSignedRequest({
|
|
4835
4913
|
request,
|
|
4836
|
-
signatures: createSignatures(request.hash(), verifierSet),
|
|
4914
|
+
signatures: await createSignatures(request.hash(), verifierSet, allStorages),
|
|
4837
4915
|
})
|
|
4838
4916
|
|
|
4839
4917
|
return sendInternalMessageAndExpect({
|
|
@@ -5100,7 +5178,7 @@ export async function ulnVerifyAndExpect(
|
|
|
5100
5178
|
opCode: OPCODES.Dvn_OP_VERIFY,
|
|
5101
5179
|
md: await allStorages.getNewMdSignedRequest({
|
|
5102
5180
|
request: requestMd,
|
|
5103
|
-
signatures: createSignatures(requestMd.hash(), verifiers),
|
|
5181
|
+
signatures: await createSignatures(requestMd.hash(), verifiers, allStorages),
|
|
5104
5182
|
}),
|
|
5105
5183
|
expectedTransactions: [
|
|
5106
5184
|
{
|
|
@@ -6937,30 +7015,6 @@ var printDeepDiff = (decodeClass, cellA, cellB) => {
|
|
|
6937
7015
|
)
|
|
6938
7016
|
);
|
|
6939
7017
|
};
|
|
6940
|
-
var LzDict = class _LzDict {
|
|
6941
|
-
constructor(data) {
|
|
6942
|
-
this._cell = data;
|
|
6943
|
-
}
|
|
6944
|
-
static empty() {
|
|
6945
|
-
return new _LzDict(core.beginCell().endCell());
|
|
6946
|
-
}
|
|
6947
|
-
async getCell(key, wrapper) {
|
|
6948
|
-
return wrapper.getDictCellItem(this._cell, key);
|
|
6949
|
-
}
|
|
6950
|
-
async getBigInt(key, wrapper) {
|
|
6951
|
-
return wrapper.getDictUint256Item(this._cell, key);
|
|
6952
|
-
}
|
|
6953
|
-
async set(key, value, wrapper) {
|
|
6954
|
-
this._cell = await wrapper.getSetDictItem(this._cell, key, value);
|
|
6955
|
-
}
|
|
6956
|
-
asCell() {
|
|
6957
|
-
return this._cell;
|
|
6958
|
-
}
|
|
6959
|
-
};
|
|
6960
|
-
async function getLzDict(obj, fieldName, wrapper) {
|
|
6961
|
-
const dictCell = await wrapper.getClDict(obj, fieldName);
|
|
6962
|
-
return new LzDict(dictCell);
|
|
6963
|
-
}
|
|
6964
7018
|
|
|
6965
7019
|
exports.BASE_CHAIN_ID = BASE_CHAIN_ID;
|
|
6966
7020
|
exports.BaseWrapper = BaseWrapper;
|
|
@@ -6968,7 +7022,6 @@ exports.ClasslibWrapper = ClasslibWrapper;
|
|
|
6968
7022
|
exports.Errors = Errors;
|
|
6969
7023
|
exports.JettonMinter = JettonMinter;
|
|
6970
7024
|
exports.JettonWallet = JettonWallet;
|
|
6971
|
-
exports.LzDict = LzDict;
|
|
6972
7025
|
exports.MASTER_CHAIN_ID = MASTER_CHAIN_ID;
|
|
6973
7026
|
exports.MASTER_CHAIN_SHARD = MASTER_CHAIN_SHARD;
|
|
6974
7027
|
exports.MAX_CELL_BITS = MAX_CELL_BITS;
|
|
@@ -6980,11 +7033,8 @@ exports.NAME_WIDTH = NAME_WIDTH;
|
|
|
6980
7033
|
exports.Op = Op;
|
|
6981
7034
|
exports.Order = Order;
|
|
6982
7035
|
exports.PUBLIC_KEY_BYTE_LENGTH = PUBLIC_KEY_BYTE_LENGTH;
|
|
6983
|
-
exports.SEED_SIZE = SEED_SIZE;
|
|
6984
|
-
exports.SIGNATURE_BYTE_LENGTH = SIGNATURE_BYTE_LENGTH;
|
|
6985
7036
|
exports.Txiterator = Txiterator;
|
|
6986
7037
|
exports._getTypeWidth = _getTypeWidth;
|
|
6987
|
-
exports.addLibToBlockchain = addLibToBlockchain;
|
|
6988
7038
|
exports.addressToBigInt = addressToBigInt;
|
|
6989
7039
|
exports.addressToHex = addressToHex;
|
|
6990
7040
|
exports.asciiStringToBigint = asciiStringToBigint2;
|
|
@@ -7004,11 +7054,7 @@ exports.clGetCellRef = clGetCellRef;
|
|
|
7004
7054
|
exports.clGetUint = clGetUint;
|
|
7005
7055
|
exports.compareAddresses = compareAddresses;
|
|
7006
7056
|
exports.computedGeneric = computedGeneric;
|
|
7007
|
-
exports.createAdminDictSet = createAdminDictSet;
|
|
7008
|
-
exports.createSignatures = createSignatures;
|
|
7009
7057
|
exports.createVerifierDictSet = createVerifierDictSet;
|
|
7010
|
-
exports.createVerifierDictSetFromEtherWallets = createVerifierDictSetFromEtherWallets;
|
|
7011
|
-
exports.createVerifierDictSetFromStrings = createVerifierDictSetFromStrings;
|
|
7012
7058
|
exports.deepDecode = deepDecode;
|
|
7013
7059
|
exports.deepDiff = deepDiff;
|
|
7014
7060
|
exports.deserializeAddressList = deserializeAddressList;
|
|
@@ -7035,7 +7081,6 @@ exports.generateConstructorCode = generateConstructorCode;
|
|
|
7035
7081
|
exports.generateDecodeClass = generateDecodeClass;
|
|
7036
7082
|
exports.generateDeconstructorCode = generateDeconstructorCode;
|
|
7037
7083
|
exports.generateEncodeClass = generateEncodeClass;
|
|
7038
|
-
exports.generateRandomVerifierSet = generateRandomVerifierSet;
|
|
7039
7084
|
exports.generateSmlTestUtils = generateSmlTestUtils;
|
|
7040
7085
|
exports.generateTonClassType = generateTonClassType;
|
|
7041
7086
|
exports.generateUlnTestUtils = generateUlnTestUtils;
|
|
@@ -7043,7 +7088,6 @@ exports.getBocStringFromMessage = getBocStringFromMessage;
|
|
|
7043
7088
|
exports.getCellName = getCellName;
|
|
7044
7089
|
exports.getCellNameNumber = getCellNameNumber;
|
|
7045
7090
|
exports.getClosestByteAlignedBits = getClosestByteAlignedBits;
|
|
7046
|
-
exports.getLzDict = getLzDict;
|
|
7047
7091
|
exports.getMessageFromBocString = getMessageFromBocString;
|
|
7048
7092
|
exports.getMsgPrices = getMsgPrices;
|
|
7049
7093
|
exports.getOpcodeCRC = getOpcodeCRC;
|
|
@@ -7068,7 +7112,6 @@ exports.openAndDeployAllStoragesTemplate = openAndDeployAllStoragesTemplate;
|
|
|
7068
7112
|
exports.orderConfigToCell = orderConfigToCell;
|
|
7069
7113
|
exports.parseDirectory = parseDirectory;
|
|
7070
7114
|
exports.parseTonAddress = parseTonAddress;
|
|
7071
|
-
exports.preprocessPublicKey = preprocessPublicKey;
|
|
7072
7115
|
exports.printDeepDecode = printDeepDecode;
|
|
7073
7116
|
exports.printDeepDiff = printDeepDiff;
|
|
7074
7117
|
exports.printTransactionTrace = printTransactionTrace;
|
|
@@ -7090,7 +7133,6 @@ exports.serializePayees = serializePayees;
|
|
|
7090
7133
|
exports.setLzTonSdkSaveToJson = setLzTonSdkSaveToJson;
|
|
7091
7134
|
exports.setLzTonSdkWriteToConsole = setLzTonSdkWriteToConsole;
|
|
7092
7135
|
exports.storageCollected = storageCollected;
|
|
7093
|
-
exports.stringPublicKeyToHash = stringPublicKeyToHash;
|
|
7094
7136
|
exports.to32ByteBuffer = to32ByteBuffer;
|
|
7095
7137
|
exports.toHaveTransactions = toHaveTransactions;
|
|
7096
7138
|
exports.toPathArray = toPathArray;
|