jaelis-node 1.9.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +147 -433
- package/bin/jaelis-node.js +79 -504
- package/lib/index.js +31 -2740
- package/lib/node.js +271 -0
- package/lib/rpc.js +315 -0
- package/lib/storage.js +198 -0
- package/lib/sync.js +366 -0
- package/package.json +19 -53
- package/config/default.json +0 -74
- package/config/mainnet.json +0 -30
- package/config/testnet.json +0 -26
- package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +0 -454
- package/lib/JAELIS-VM/lib/adapters/index.js +0 -411
- package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +0 -457
- package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +0 -1097
- package/lib/JAELIS-VM/lib/execution/engine.js +0 -1183
- package/lib/JAELIS-VM/lib/index.js +0 -440
- package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +0 -543
- package/lib/JAELIS-VM/lib/serialization/serializer.js +0 -819
- package/lib/JAELIS-VM/lib/state/state-manager.js +0 -1116
- package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +0 -1222
- package/lib/JAELIS-VM/lib/unified/cross-chain-deploy.js +0 -1678
- package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +0 -836
- package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +0 -1127
- package/lib/JAELIS-VM/lib/unified/index.js +0 -456
- package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +0 -1150
- package/lib/JAELIS-VM/lib/unified/unified-compiler.js +0 -1350
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +0 -12
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +0 -12
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +0 -12
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/.package-lock.json +0 -127
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +0 -1
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
- package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +0 -17
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +0 -1
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
- package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +0 -17
- package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +0 -21
- package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +0 -5
- package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +0 -11
- package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +0 -60
- package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +0 -50
- package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +0 -198
- package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +0 -21
- package/lib/JAELIS-VM/node_modules/cbor-x/README.md +0 -380
- package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +0 -11
- package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +0 -73
- package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +0 -11
- package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +0 -2
- package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +0 -1300
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +0 -1244
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +0 -2509
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +0 -2
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +0 -2508
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +0 -2
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +0 -2629
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +0 -3343
- package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +0 -1
- package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +0 -1231
- package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +0 -79
- package/lib/JAELIS-VM/node_modules/cbor-x/index.js +0 -3
- package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +0 -85
- package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +0 -24
- package/lib/JAELIS-VM/node_modules/cbor-x/package.json +0 -94
- package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +0 -88
- package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +0 -61
- package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +0 -19
- package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +0 -201
- package/lib/JAELIS-VM/node_modules/detect-libc/README.md +0 -163
- package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +0 -14
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +0 -313
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +0 -39
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +0 -51
- package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +0 -24
- package/lib/JAELIS-VM/node_modules/detect-libc/package.json +0 -44
- package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +0 -21
- package/lib/JAELIS-VM/node_modules/msgpackr/README.md +0 -372
- package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +0 -11
- package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +0 -67
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +0 -2407
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +0 -2
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +0 -2406
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +0 -2
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +0 -3320
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +0 -4540
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +0 -1250
- package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +0 -91
- package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +0 -91
- package/lib/JAELIS-VM/node_modules/msgpackr/index.js +0 -5
- package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +0 -87
- package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +0 -25
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +0 -1141
- package/lib/JAELIS-VM/node_modules/msgpackr/package.json +0 -104
- package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +0 -88
- package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +0 -57
- package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +0 -815
- package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +0 -3
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +0 -2
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +0 -2
- package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +0 -1221
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +0 -21
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +0 -5
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +0 -13
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +0 -63
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +0 -1
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +0 -12
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +0 -58
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +0 -82
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +0 -6
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +0 -236
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +0 -32
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +0 -50
- package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +0 -274
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +0 -58
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +0 -77
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +0 -224
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
- package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +0 -32
- package/lib/JAELIS-VM/package-lock.json +0 -284
- package/lib/JAELIS-VM/package.json +0 -38
- package/lib/JAELIS-VM/test/comprehensive.test.js +0 -267
- package/lib/JAELIS-VM/test/cross-chain-test.js +0 -470
- package/lib/JAELIS-VM/test/unified-vm-test.js +0 -459
- package/lib/JAELIS-VM/test/unified.test.js +0 -166
- package/lib/JAELIS-VM/test/vm.test.js +0 -599
- package/lib/settlement-server.js +0 -999
- package/lib/vm/index.js +0 -397
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* JAELIS VM ADAPTERS
|
|
3
|
-
*
|
|
4
|
-
* Provides chain-specific interfaces for the Universal VM
|
|
5
|
-
*
|
|
6
|
-
* @version 0.1.0
|
|
7
|
-
* @author Mario Papaleo - JAELIS Foundation
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const EVMAdapter = require('./evm-adapter');
|
|
11
|
-
const SVMAdapter = require('./svm-adapter');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Move VM Adapter (Aptos/Sui)
|
|
15
|
-
*/
|
|
16
|
-
class MoveAdapter {
|
|
17
|
-
constructor(vm) {
|
|
18
|
-
this.vm = vm;
|
|
19
|
-
this.modules = new Map();
|
|
20
|
-
this.resources = new Map();
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async publishModule(bytecode, options = {}) {
|
|
24
|
-
const moduleAddress = options.address || this.generateModuleAddress(bytecode);
|
|
25
|
-
|
|
26
|
-
this.modules.set(moduleAddress, {
|
|
27
|
-
bytecode,
|
|
28
|
-
metadata: options.metadata || {}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return this.vm.deployBytecode(bytecode, 'move', {
|
|
32
|
-
...options,
|
|
33
|
-
deployer: moduleAddress
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async executeFunction(moduleAddress, moduleName, functionName, typeArgs = [], args = [], options = {}) {
|
|
38
|
-
const callData = this.encodeEntryFunction(moduleName, functionName, typeArgs, args);
|
|
39
|
-
|
|
40
|
-
return this.vm.execute(moduleAddress, functionName, callData, options);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
encodeEntryFunction(moduleName, functionName, typeArgs, args) {
|
|
44
|
-
// BCS encoding for Move
|
|
45
|
-
const buffers = [];
|
|
46
|
-
|
|
47
|
-
// Module name
|
|
48
|
-
buffers.push(this.bcsEncodeString(moduleName));
|
|
49
|
-
|
|
50
|
-
// Function name
|
|
51
|
-
buffers.push(this.bcsEncodeString(functionName));
|
|
52
|
-
|
|
53
|
-
// Type arguments count
|
|
54
|
-
buffers.push(Buffer.from([typeArgs.length]));
|
|
55
|
-
|
|
56
|
-
// Arguments count
|
|
57
|
-
buffers.push(Buffer.from([args.length]));
|
|
58
|
-
|
|
59
|
-
// Encode each argument
|
|
60
|
-
for (const arg of args) {
|
|
61
|
-
buffers.push(this.bcsEncodeValue(arg));
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
return Buffer.concat(buffers);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
bcsEncodeString(str) {
|
|
68
|
-
const strBuf = Buffer.from(str, 'utf8');
|
|
69
|
-
const lenBuf = Buffer.alloc(4);
|
|
70
|
-
lenBuf.writeUInt32LE(strBuf.length);
|
|
71
|
-
return Buffer.concat([lenBuf, strBuf]);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
bcsEncodeValue(value) {
|
|
75
|
-
if (typeof value === 'number' || typeof value === 'bigint') {
|
|
76
|
-
const buf = Buffer.alloc(8);
|
|
77
|
-
buf.writeBigUInt64LE(BigInt(value));
|
|
78
|
-
return buf;
|
|
79
|
-
}
|
|
80
|
-
if (typeof value === 'string') {
|
|
81
|
-
return this.bcsEncodeString(value);
|
|
82
|
-
}
|
|
83
|
-
if (typeof value === 'boolean') {
|
|
84
|
-
return Buffer.from([value ? 1 : 0]);
|
|
85
|
-
}
|
|
86
|
-
return Buffer.alloc(0);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
generateModuleAddress(bytecode) {
|
|
90
|
-
const crypto = require('crypto');
|
|
91
|
-
return '0x' + crypto.createHash('sha256').update(bytecode).digest('hex').substring(0, 64);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
async getResource(address, resourceType) {
|
|
95
|
-
const key = `${address}:${resourceType}`;
|
|
96
|
-
return this.resources.get(key);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async setResource(address, resourceType, value) {
|
|
100
|
-
const key = `${address}:${resourceType}`;
|
|
101
|
-
this.resources.set(key, value);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* TON VM Adapter
|
|
107
|
-
*/
|
|
108
|
-
class TVMAdapter {
|
|
109
|
-
constructor(vm) {
|
|
110
|
-
this.vm = vm;
|
|
111
|
-
this.contracts = new Map();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async deployContract(code, data, options = {}) {
|
|
115
|
-
// TON uses code + data cells
|
|
116
|
-
const stateInit = this.createStateInit(code, data);
|
|
117
|
-
const address = this.calculateAddress(stateInit, options.workchain || 0);
|
|
118
|
-
|
|
119
|
-
return this.vm.deployBytecode(code, 'tvm', {
|
|
120
|
-
...options,
|
|
121
|
-
address,
|
|
122
|
-
stateInit
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async sendMessage(address, body, options = {}) {
|
|
127
|
-
return this.vm.execute(address, 'recv_internal', body, options);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async sendExternalMessage(address, body, options = {}) {
|
|
131
|
-
return this.vm.execute(address, 'recv_external', body, options);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
createStateInit(code, data) {
|
|
135
|
-
// Simplified state init
|
|
136
|
-
return {
|
|
137
|
-
code,
|
|
138
|
-
data,
|
|
139
|
-
libraries: null,
|
|
140
|
-
splitDepth: null,
|
|
141
|
-
tickTock: null
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
calculateAddress(stateInit, workchain) {
|
|
146
|
-
const crypto = require('crypto');
|
|
147
|
-
const hash = crypto.createHash('sha256')
|
|
148
|
-
.update(JSON.stringify(stateInit))
|
|
149
|
-
.digest('hex');
|
|
150
|
-
|
|
151
|
-
return `${workchain}:${hash}`;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
// Cell serialization (simplified)
|
|
155
|
-
createCell(data) {
|
|
156
|
-
return {
|
|
157
|
-
bits: data,
|
|
158
|
-
refs: []
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
parseCell(cell) {
|
|
163
|
-
return cell.bits;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* WASM Adapter (Cosmos, Polkadot, NEAR)
|
|
169
|
-
*/
|
|
170
|
-
class WASMAdapter {
|
|
171
|
-
constructor(vm) {
|
|
172
|
-
this.vm = vm;
|
|
173
|
-
this.contracts = new Map();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async instantiate(wasmCode, initMsg, options = {}) {
|
|
177
|
-
const codeId = this.storeCode(wasmCode);
|
|
178
|
-
const address = this.generateAddress(codeId, options.salt);
|
|
179
|
-
|
|
180
|
-
// Execute instantiate
|
|
181
|
-
const result = await this.vm.deployBytecode(wasmCode, 'wasm', {
|
|
182
|
-
...options,
|
|
183
|
-
address,
|
|
184
|
-
initMsg
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
this.contracts.set(address, { codeId, admin: options.admin });
|
|
188
|
-
|
|
189
|
-
return { ...result, address };
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
async execute(address, msg, options = {}) {
|
|
193
|
-
const msgBuffer = Buffer.from(JSON.stringify(msg));
|
|
194
|
-
return this.vm.execute(address, 'execute', msgBuffer, options);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async query(address, msg) {
|
|
198
|
-
const msgBuffer = Buffer.from(JSON.stringify(msg));
|
|
199
|
-
const result = await this.vm.execute(address, 'query', msgBuffer, {
|
|
200
|
-
readOnly: true
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
if (result.returnValue) {
|
|
204
|
-
try {
|
|
205
|
-
return JSON.parse(result.returnValue.toString());
|
|
206
|
-
} catch {
|
|
207
|
-
return result.returnValue;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
storeCode(wasmCode) {
|
|
214
|
-
const crypto = require('crypto');
|
|
215
|
-
return crypto.createHash('sha256').update(wasmCode).digest('hex');
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
generateAddress(codeId, salt) {
|
|
219
|
-
const crypto = require('crypto');
|
|
220
|
-
const input = salt ? `${codeId}${salt}` : `${codeId}${Date.now()}`;
|
|
221
|
-
return crypto.createHash('sha256').update(input).digest('hex').substring(0, 40);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Cairo Adapter (Starknet)
|
|
227
|
-
*/
|
|
228
|
-
class CairoAdapter {
|
|
229
|
-
constructor(vm) {
|
|
230
|
-
this.vm = vm;
|
|
231
|
-
this.classes = new Map();
|
|
232
|
-
this.contracts = new Map();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
async declareClass(sierraCode, casmCode) {
|
|
236
|
-
const crypto = require('crypto');
|
|
237
|
-
const classHash = crypto.createHash('sha256')
|
|
238
|
-
.update(sierraCode)
|
|
239
|
-
.digest('hex');
|
|
240
|
-
|
|
241
|
-
this.classes.set(classHash, { sierra: sierraCode, casm: casmCode });
|
|
242
|
-
|
|
243
|
-
return { classHash };
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
async deploy(classHash, constructorCalldata, options = {}) {
|
|
247
|
-
const classData = this.classes.get(classHash);
|
|
248
|
-
if (!classData) {
|
|
249
|
-
throw new Error(`Class not found: ${classHash}`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const address = this.calculateContractAddress(classHash, constructorCalldata, options.salt);
|
|
253
|
-
|
|
254
|
-
const result = await this.vm.deployBytecode(classData.casm, 'cairo', {
|
|
255
|
-
...options,
|
|
256
|
-
address,
|
|
257
|
-
constructorCalldata
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
this.contracts.set(address, { classHash });
|
|
261
|
-
|
|
262
|
-
return { ...result, address };
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
async invoke(address, selector, calldata, options = {}) {
|
|
266
|
-
return this.vm.execute(address, selector, calldata, options);
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
async call(address, selector, calldata) {
|
|
270
|
-
return this.vm.execute(address, selector, calldata, { readOnly: true });
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
calculateContractAddress(classHash, constructorCalldata, salt) {
|
|
274
|
-
const crypto = require('crypto');
|
|
275
|
-
const input = `${classHash}${JSON.stringify(constructorCalldata)}${salt || ''}`;
|
|
276
|
-
return '0x' + crypto.createHash('sha256').update(input).digest('hex').substring(0, 64);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// Felt252 operations
|
|
280
|
-
feltToString(felt) {
|
|
281
|
-
return BigInt(felt).toString(16);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
stringToFelt(str) {
|
|
285
|
-
let result = 0n;
|
|
286
|
-
for (let i = 0; i < str.length; i++) {
|
|
287
|
-
result = result * 256n + BigInt(str.charCodeAt(i));
|
|
288
|
-
}
|
|
289
|
-
return result;
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* Bitcoin Script Adapter
|
|
295
|
-
*/
|
|
296
|
-
class BitcoinAdapter {
|
|
297
|
-
constructor(vm) {
|
|
298
|
-
this.vm = vm;
|
|
299
|
-
this.utxos = new Map();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
async executeScript(script, stack = []) {
|
|
303
|
-
const result = await this.vm.execute('bitcoin', 'execute', script, {
|
|
304
|
-
stack
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
return {
|
|
308
|
-
success: result.returnValue !== 0,
|
|
309
|
-
stack: result.stateChanges?.stack || []
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
createP2PKH(pubkeyHash) {
|
|
314
|
-
// OP_DUP OP_HASH160 <pubkeyHash> OP_EQUALVERIFY OP_CHECKSIG
|
|
315
|
-
return Buffer.concat([
|
|
316
|
-
Buffer.from([0x76, 0xA9, 0x14]), // OP_DUP OP_HASH160 PUSH20
|
|
317
|
-
pubkeyHash,
|
|
318
|
-
Buffer.from([0x88, 0xAC]) // OP_EQUALVERIFY OP_CHECKSIG
|
|
319
|
-
]);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
createP2SH(scriptHash) {
|
|
323
|
-
// OP_HASH160 <scriptHash> OP_EQUAL
|
|
324
|
-
return Buffer.concat([
|
|
325
|
-
Buffer.from([0xA9, 0x14]), // OP_HASH160 PUSH20
|
|
326
|
-
scriptHash,
|
|
327
|
-
Buffer.from([0x87]) // OP_EQUAL
|
|
328
|
-
]);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
createP2WPKH(pubkeyHash) {
|
|
332
|
-
// OP_0 <pubkeyHash>
|
|
333
|
-
return Buffer.concat([
|
|
334
|
-
Buffer.from([0x00, 0x14]), // OP_0 PUSH20
|
|
335
|
-
pubkeyHash
|
|
336
|
-
]);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
createMultisig(m, pubkeys) {
|
|
340
|
-
// OP_M <pubkeys...> OP_N OP_CHECKMULTISIG
|
|
341
|
-
const n = pubkeys.length;
|
|
342
|
-
const parts = [Buffer.from([0x50 + m])]; // OP_M
|
|
343
|
-
|
|
344
|
-
for (const pubkey of pubkeys) {
|
|
345
|
-
parts.push(Buffer.from([pubkey.length]));
|
|
346
|
-
parts.push(pubkey);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
parts.push(Buffer.from([0x50 + n])); // OP_N
|
|
350
|
-
parts.push(Buffer.from([0xAE])); // OP_CHECKMULTISIG
|
|
351
|
-
|
|
352
|
-
return Buffer.concat(parts);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* Adapter Factory
|
|
358
|
-
*/
|
|
359
|
-
class AdapterFactory {
|
|
360
|
-
constructor(vm) {
|
|
361
|
-
this.vm = vm;
|
|
362
|
-
this.adapters = new Map();
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
getAdapter(vmType) {
|
|
366
|
-
if (this.adapters.has(vmType)) {
|
|
367
|
-
return this.adapters.get(vmType);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
let adapter;
|
|
371
|
-
switch (vmType) {
|
|
372
|
-
case 'evm':
|
|
373
|
-
adapter = new EVMAdapter(this.vm);
|
|
374
|
-
break;
|
|
375
|
-
case 'svm':
|
|
376
|
-
adapter = new SVMAdapter(this.vm);
|
|
377
|
-
break;
|
|
378
|
-
case 'move':
|
|
379
|
-
adapter = new MoveAdapter(this.vm);
|
|
380
|
-
break;
|
|
381
|
-
case 'tvm':
|
|
382
|
-
adapter = new TVMAdapter(this.vm);
|
|
383
|
-
break;
|
|
384
|
-
case 'wasm':
|
|
385
|
-
adapter = new WASMAdapter(this.vm);
|
|
386
|
-
break;
|
|
387
|
-
case 'cairo':
|
|
388
|
-
adapter = new CairoAdapter(this.vm);
|
|
389
|
-
break;
|
|
390
|
-
case 'bitcoin':
|
|
391
|
-
adapter = new BitcoinAdapter(this.vm);
|
|
392
|
-
break;
|
|
393
|
-
default:
|
|
394
|
-
throw new Error(`Unknown VM type: ${vmType}`);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
this.adapters.set(vmType, adapter);
|
|
398
|
-
return adapter;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
module.exports = {
|
|
403
|
-
EVMAdapter,
|
|
404
|
-
SVMAdapter,
|
|
405
|
-
MoveAdapter,
|
|
406
|
-
TVMAdapter,
|
|
407
|
-
WASMAdapter,
|
|
408
|
-
CairoAdapter,
|
|
409
|
-
BitcoinAdapter,
|
|
410
|
-
AdapterFactory
|
|
411
|
-
};
|