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.
Files changed (173) hide show
  1. package/README.md +147 -433
  2. package/bin/jaelis-node.js +79 -504
  3. package/lib/index.js +31 -2740
  4. package/lib/node.js +271 -0
  5. package/lib/rpc.js +315 -0
  6. package/lib/storage.js +198 -0
  7. package/lib/sync.js +366 -0
  8. package/package.json +19 -53
  9. package/config/default.json +0 -74
  10. package/config/mainnet.json +0 -30
  11. package/config/testnet.json +0 -26
  12. package/lib/JAELIS-VM/lib/adapters/evm-adapter.js +0 -454
  13. package/lib/JAELIS-VM/lib/adapters/index.js +0 -411
  14. package/lib/JAELIS-VM/lib/adapters/svm-adapter.js +0 -457
  15. package/lib/JAELIS-VM/lib/compiler/jir-compiler.js +0 -1097
  16. package/lib/JAELIS-VM/lib/execution/engine.js +0 -1183
  17. package/lib/JAELIS-VM/lib/index.js +0 -440
  18. package/lib/JAELIS-VM/lib/integration/jaelis-integration.js +0 -543
  19. package/lib/JAELIS-VM/lib/serialization/serializer.js +0 -819
  20. package/lib/JAELIS-VM/lib/state/state-manager.js +0 -1116
  21. package/lib/JAELIS-VM/lib/translator/bytecode-translator.js +0 -1222
  22. package/lib/JAELIS-VM/lib/unified/cross-chain-deploy.js +0 -1678
  23. package/lib/JAELIS-VM/lib/unified/cross-chain-state.js +0 -836
  24. package/lib/JAELIS-VM/lib/unified/dynamic-contracts.js +0 -1127
  25. package/lib/JAELIS-VM/lib/unified/index.js +0 -456
  26. package/lib/JAELIS-VM/lib/unified/jaelis-abi.js +0 -1150
  27. package/lib/JAELIS-VM/lib/unified/unified-compiler.js +0 -1350
  28. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds +0 -12
  29. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.cmd +0 -17
  30. package/lib/JAELIS-VM/node_modules/.bin/download-cbor-prebuilds.ps1 +0 -28
  31. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds +0 -12
  32. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.cmd +0 -17
  33. package/lib/JAELIS-VM/node_modules/.bin/download-msgpackr-prebuilds.ps1 +0 -28
  34. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  35. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  36. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  37. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  38. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  39. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  40. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  41. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  42. package/lib/JAELIS-VM/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  43. package/lib/JAELIS-VM/node_modules/.package-lock.json +0 -127
  44. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/README.md +0 -1
  45. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/index.js +0 -0
  46. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.abi115.node +0 -0
  47. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/node.napi.node +0 -0
  48. package/lib/JAELIS-VM/node_modules/@cbor-extract/cbor-extract-win32-x64/package.json +0 -17
  49. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/README.md +0 -1
  50. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/index.js +0 -0
  51. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.abi115.node +0 -0
  52. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/node.napi.node +0 -0
  53. package/lib/JAELIS-VM/node_modules/@msgpackr-extract/msgpackr-extract-win32-x64/package.json +0 -17
  54. package/lib/JAELIS-VM/node_modules/cbor-extract/LICENSE +0 -21
  55. package/lib/JAELIS-VM/node_modules/cbor-extract/README.md +0 -5
  56. package/lib/JAELIS-VM/node_modules/cbor-extract/bin/download-prebuilds.js +0 -11
  57. package/lib/JAELIS-VM/node_modules/cbor-extract/binding.gyp +0 -60
  58. package/lib/JAELIS-VM/node_modules/cbor-extract/index.js +0 -1
  59. package/lib/JAELIS-VM/node_modules/cbor-extract/package.json +0 -50
  60. package/lib/JAELIS-VM/node_modules/cbor-extract/src/extract.cpp +0 -198
  61. package/lib/JAELIS-VM/node_modules/cbor-x/LICENSE +0 -21
  62. package/lib/JAELIS-VM/node_modules/cbor-x/README.md +0 -380
  63. package/lib/JAELIS-VM/node_modules/cbor-x/SECURITY.md +0 -11
  64. package/lib/JAELIS-VM/node_modules/cbor-x/benchmark.md +0 -73
  65. package/lib/JAELIS-VM/node_modules/cbor-x/browser.js +0 -11
  66. package/lib/JAELIS-VM/node_modules/cbor-x/decode.d.ts +0 -2
  67. package/lib/JAELIS-VM/node_modules/cbor-x/decode.js +0 -1300
  68. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs +0 -1244
  69. package/lib/JAELIS-VM/node_modules/cbor-x/dist/decode-no-eval.cjs.map +0 -1
  70. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs +0 -2509
  71. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.cjs.map +0 -1
  72. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js +0 -2
  73. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index-no-eval.min.js.map +0 -1
  74. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js +0 -2508
  75. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.js.map +0 -1
  76. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js +0 -2
  77. package/lib/JAELIS-VM/node_modules/cbor-x/dist/index.min.js.map +0 -1
  78. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs +0 -2629
  79. package/lib/JAELIS-VM/node_modules/cbor-x/dist/node.cjs.map +0 -1
  80. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js +0 -3343
  81. package/lib/JAELIS-VM/node_modules/cbor-x/dist/test.js.map +0 -1
  82. package/lib/JAELIS-VM/node_modules/cbor-x/encode.d.ts +0 -1
  83. package/lib/JAELIS-VM/node_modules/cbor-x/encode.js +0 -1231
  84. package/lib/JAELIS-VM/node_modules/cbor-x/index.d.ts +0 -79
  85. package/lib/JAELIS-VM/node_modules/cbor-x/index.js +0 -3
  86. package/lib/JAELIS-VM/node_modules/cbor-x/iterators.js +0 -85
  87. package/lib/JAELIS-VM/node_modules/cbor-x/node-index.js +0 -24
  88. package/lib/JAELIS-VM/node_modules/cbor-x/package.json +0 -94
  89. package/lib/JAELIS-VM/node_modules/cbor-x/rollup.config.js +0 -88
  90. package/lib/JAELIS-VM/node_modules/cbor-x/stream.js +0 -61
  91. package/lib/JAELIS-VM/node_modules/cbor-x/webpack.config.js +0 -19
  92. package/lib/JAELIS-VM/node_modules/detect-libc/LICENSE +0 -201
  93. package/lib/JAELIS-VM/node_modules/detect-libc/README.md +0 -163
  94. package/lib/JAELIS-VM/node_modules/detect-libc/index.d.ts +0 -14
  95. package/lib/JAELIS-VM/node_modules/detect-libc/lib/detect-libc.js +0 -313
  96. package/lib/JAELIS-VM/node_modules/detect-libc/lib/elf.js +0 -39
  97. package/lib/JAELIS-VM/node_modules/detect-libc/lib/filesystem.js +0 -51
  98. package/lib/JAELIS-VM/node_modules/detect-libc/lib/process.js +0 -24
  99. package/lib/JAELIS-VM/node_modules/detect-libc/package.json +0 -44
  100. package/lib/JAELIS-VM/node_modules/msgpackr/LICENSE +0 -21
  101. package/lib/JAELIS-VM/node_modules/msgpackr/README.md +0 -372
  102. package/lib/JAELIS-VM/node_modules/msgpackr/SECURITY.md +0 -11
  103. package/lib/JAELIS-VM/node_modules/msgpackr/benchmark.md +0 -67
  104. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs +0 -2407
  105. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.cjs.map +0 -1
  106. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js +0 -2
  107. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index-no-eval.min.js.map +0 -1
  108. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js +0 -2406
  109. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.js.map +0 -1
  110. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js +0 -2
  111. package/lib/JAELIS-VM/node_modules/msgpackr/dist/index.min.js.map +0 -1
  112. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs +0 -3320
  113. package/lib/JAELIS-VM/node_modules/msgpackr/dist/node.cjs.map +0 -1
  114. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js +0 -4540
  115. package/lib/JAELIS-VM/node_modules/msgpackr/dist/test.js.map +0 -1
  116. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs +0 -1250
  117. package/lib/JAELIS-VM/node_modules/msgpackr/dist/unpack-no-eval.cjs.map +0 -1
  118. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.cts +0 -91
  119. package/lib/JAELIS-VM/node_modules/msgpackr/index.d.ts +0 -91
  120. package/lib/JAELIS-VM/node_modules/msgpackr/index.js +0 -5
  121. package/lib/JAELIS-VM/node_modules/msgpackr/iterators.js +0 -87
  122. package/lib/JAELIS-VM/node_modules/msgpackr/node-index.js +0 -25
  123. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.cts +0 -1
  124. package/lib/JAELIS-VM/node_modules/msgpackr/pack.d.ts +0 -1
  125. package/lib/JAELIS-VM/node_modules/msgpackr/pack.js +0 -1141
  126. package/lib/JAELIS-VM/node_modules/msgpackr/package.json +0 -104
  127. package/lib/JAELIS-VM/node_modules/msgpackr/rollup.config.js +0 -88
  128. package/lib/JAELIS-VM/node_modules/msgpackr/stream.js +0 -57
  129. package/lib/JAELIS-VM/node_modules/msgpackr/struct.js +0 -815
  130. package/lib/JAELIS-VM/node_modules/msgpackr/test-worker.js +0 -3
  131. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.cts +0 -2
  132. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.d.ts +0 -2
  133. package/lib/JAELIS-VM/node_modules/msgpackr/unpack.js +0 -1221
  134. package/lib/JAELIS-VM/node_modules/msgpackr-extract/LICENSE +0 -21
  135. package/lib/JAELIS-VM/node_modules/msgpackr-extract/README.md +0 -5
  136. package/lib/JAELIS-VM/node_modules/msgpackr-extract/bin/download-prebuilds.js +0 -13
  137. package/lib/JAELIS-VM/node_modules/msgpackr-extract/binding.gyp +0 -63
  138. package/lib/JAELIS-VM/node_modules/msgpackr-extract/index.js +0 -1
  139. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages +0 -12
  140. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional +0 -12
  141. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.cmd +0 -17
  142. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-optional.ps1 +0 -28
  143. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test +0 -12
  144. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.cmd +0 -17
  145. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages-test.ps1 +0 -28
  146. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.cmd +0 -17
  147. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/.bin/node-gyp-build-optional-packages.ps1 +0 -28
  148. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  149. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  150. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/bin.js +0 -82
  151. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  152. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/index.js +0 -6
  153. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/node-gyp-build.js +0 -236
  154. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  155. package/lib/JAELIS-VM/node_modules/msgpackr-extract/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  156. package/lib/JAELIS-VM/node_modules/msgpackr-extract/package.json +0 -50
  157. package/lib/JAELIS-VM/node_modules/msgpackr-extract/src/extract.cpp +0 -274
  158. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/LICENSE +0 -21
  159. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/README.md +0 -58
  160. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/bin.js +0 -77
  161. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/build-test.js +0 -19
  162. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/index.js +0 -224
  163. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/optional.js +0 -7
  164. package/lib/JAELIS-VM/node_modules/node-gyp-build-optional-packages/package.json +0 -32
  165. package/lib/JAELIS-VM/package-lock.json +0 -284
  166. package/lib/JAELIS-VM/package.json +0 -38
  167. package/lib/JAELIS-VM/test/comprehensive.test.js +0 -267
  168. package/lib/JAELIS-VM/test/cross-chain-test.js +0 -470
  169. package/lib/JAELIS-VM/test/unified-vm-test.js +0 -459
  170. package/lib/JAELIS-VM/test/unified.test.js +0 -166
  171. package/lib/JAELIS-VM/test/vm.test.js +0 -599
  172. package/lib/settlement-server.js +0 -999
  173. package/lib/vm/index.js +0 -397
@@ -1,74 +0,0 @@
1
- {
2
- "node": {
3
- "name": "my-jaelis-node",
4
- "type": "full",
5
- "version": "1.0.0"
6
- },
7
- "network": {
8
- "name": "testnet",
9
- "chainId": 4545,
10
- "bootstrapNodes": [
11
- "/dns4/rpc.jaelis.io/tcp/30303"
12
- ]
13
- },
14
- "rpc": {
15
- "enabled": true,
16
- "host": "0.0.0.0",
17
- "port": 8545,
18
- "cors": "*",
19
- "methods": {
20
- "eth": true,
21
- "jaelis": true,
22
- "net": true,
23
- "web3": true
24
- }
25
- },
26
- "p2p": {
27
- "enabled": true,
28
- "port": 30303,
29
- "maxPeers": 50,
30
- "discovery": true
31
- },
32
- "storage": {
33
- "dataDir": "./jaelis-data",
34
- "engine": "leveldb",
35
- "cache": {
36
- "blocks": 512,
37
- "states": 256
38
- }
39
- },
40
- "sync": {
41
- "mode": "full",
42
- "fastSync": true,
43
- "pruning": false
44
- },
45
- "validator": {
46
- "enabled": false,
47
- "stake": "1000",
48
- "keyFile": null,
49
- "autoCompound": true
50
- },
51
- "metrics": {
52
- "enabled": true,
53
- "port": 9090,
54
- "path": "/metrics"
55
- },
56
- "logging": {
57
- "level": "info",
58
- "console": true,
59
- "file": {
60
- "enabled": true,
61
- "path": "./jaelis-data/logs/node.log",
62
- "maxSize": "100MB",
63
- "maxFiles": 10
64
- }
65
- },
66
- "security": {
67
- "maxRequestSize": "1MB",
68
- "rateLimit": {
69
- "enabled": true,
70
- "windowMs": 60000,
71
- "maxRequests": 1000
72
- }
73
- }
74
- }
@@ -1,30 +0,0 @@
1
- {
2
- "extends": "default",
3
- "network": {
4
- "name": "mainnet",
5
- "chainId": 4547,
6
- "symbol": "JAELIS",
7
- "rpcEndpoints": [
8
- "https://mainnet.jaelis.io"
9
- ],
10
- "bootstrapNodes": [],
11
- "genesis": {
12
- "timestamp": null,
13
- "difficulty": 1,
14
- "gasLimit": "0x0",
15
- "extraData": "0x4a41454c495320426c6f636b636861696e202d204d61696e6e6574"
16
- }
17
- },
18
- "storage": {
19
- "dataDir": "./jaelis-data/mainnet"
20
- },
21
- "logging": {
22
- "level": "info"
23
- },
24
- "validator": {
25
- "enabled": false,
26
- "stake": "10000",
27
- "autoCompound": true
28
- },
29
- "_status": "coming-soon"
30
- }
@@ -1,26 +0,0 @@
1
- {
2
- "extends": "default",
3
- "network": {
4
- "name": "testnet",
5
- "chainId": 4545,
6
- "symbol": "tJAELIS",
7
- "rpcEndpoints": [
8
- "https://rpc.jaelis.io"
9
- ],
10
- "bootstrapNodes": [
11
- "/dns4/rpc.jaelis.io/tcp/30303"
12
- ],
13
- "genesis": {
14
- "timestamp": 1731398400000,
15
- "difficulty": 1,
16
- "gasLimit": "0x0",
17
- "extraData": "0x4a41454c495320426c6f636b636861696e202d2054657374676e6573697320426c6f636b"
18
- }
19
- },
20
- "storage": {
21
- "dataDir": "./jaelis-data/testnet"
22
- },
23
- "logging": {
24
- "level": "debug"
25
- }
26
- }
@@ -1,454 +0,0 @@
1
- /**
2
- * EVM ADAPTER
3
- *
4
- * Provides EVM-compatible interface for JAELIS Universal VM
5
- * Supports: Ethereum, BSC, Polygon, Arbitrum, Optimism, Base, Avalanche
6
- *
7
- * Features:
8
- * - Solidity ABI encoding/decoding
9
- * - EIP-2718 transaction types
10
- * - EIP-1559 gas pricing
11
- * - Precompiled contracts
12
- *
13
- * @version 0.1.0
14
- * @author Mario Papaleo - JAELIS Foundation
15
- */
16
-
17
- const crypto = require('crypto');
18
-
19
- // Solidity ABI type encodings
20
- const ABI_TYPES = {
21
- uint256: { size: 32, dynamic: false },
22
- int256: { size: 32, dynamic: false },
23
- address: { size: 32, dynamic: false },
24
- bool: { size: 32, dynamic: false },
25
- bytes32: { size: 32, dynamic: false },
26
- bytes: { size: null, dynamic: true },
27
- string: { size: null, dynamic: true },
28
- 'uint256[]': { size: null, dynamic: true },
29
- 'address[]': { size: null, dynamic: true }
30
- };
31
-
32
- // EVM Precompiled contract addresses
33
- const PRECOMPILES = {
34
- '0x0000000000000000000000000000000000000001': 'ecrecover',
35
- '0x0000000000000000000000000000000000000002': 'sha256',
36
- '0x0000000000000000000000000000000000000003': 'ripemd160',
37
- '0x0000000000000000000000000000000000000004': 'identity',
38
- '0x0000000000000000000000000000000000000005': 'modexp',
39
- '0x0000000000000000000000000000000000000006': 'ecadd',
40
- '0x0000000000000000000000000000000000000007': 'ecmul',
41
- '0x0000000000000000000000000000000000000008': 'ecpairing',
42
- '0x0000000000000000000000000000000000000009': 'blake2f'
43
- };
44
-
45
- class EVMAdapter {
46
- constructor(vm) {
47
- this.vm = vm;
48
- this.chainId = 4545; // JAELIS testnet
49
-
50
- // Function signature cache
51
- this.signatureCache = new Map();
52
- }
53
-
54
- /**
55
- * Deploy EVM contract
56
- */
57
- async deploy(bytecode, constructorArgs = [], options = {}) {
58
- // Encode constructor arguments
59
- const encodedArgs = this.encodeParameters(
60
- options.constructorTypes || [],
61
- constructorArgs
62
- );
63
-
64
- const deployBytecode = Buffer.concat([
65
- Buffer.from(bytecode.replace('0x', ''), 'hex'),
66
- encodedArgs
67
- ]);
68
-
69
- return this.vm.deployBytecode(deployBytecode, 'evm', options);
70
- }
71
-
72
- /**
73
- * Call EVM contract function
74
- */
75
- async call(address, functionSignature, args = [], options = {}) {
76
- // Parse function signature
77
- const { name, types } = this.parseFunctionSignature(functionSignature);
78
-
79
- // Encode function call
80
- const selector = this.getFunctionSelector(functionSignature);
81
- const encodedArgs = this.encodeParameters(types, args);
82
-
83
- const callData = Buffer.concat([selector, encodedArgs]);
84
-
85
- // Execute
86
- const result = await this.vm.execute(address, name, callData, {
87
- ...options,
88
- callData
89
- });
90
-
91
- // Decode result if return types specified
92
- if (options.returnTypes) {
93
- result.decoded = this.decodeParameters(options.returnTypes, result.returnValue);
94
- }
95
-
96
- return result;
97
- }
98
-
99
- /**
100
- * Get function selector (4 bytes)
101
- */
102
- getFunctionSelector(signature) {
103
- // Check cache
104
- if (this.signatureCache.has(signature)) {
105
- return this.signatureCache.get(signature);
106
- }
107
-
108
- // Normalize signature
109
- const normalized = signature.replace(/\s/g, '');
110
-
111
- // Keccak256 hash and take first 4 bytes
112
- const hash = this.keccak256(Buffer.from(normalized));
113
- const selector = hash.slice(0, 4);
114
-
115
- this.signatureCache.set(signature, selector);
116
- return selector;
117
- }
118
-
119
- /**
120
- * Parse function signature
121
- */
122
- parseFunctionSignature(signature) {
123
- const match = signature.match(/^(\w+)\((.*)\)$/);
124
- if (!match) {
125
- throw new Error(`Invalid function signature: ${signature}`);
126
- }
127
-
128
- const name = match[1];
129
- const types = match[2] ? match[2].split(',').map(t => t.trim()) : [];
130
-
131
- return { name, types };
132
- }
133
-
134
- /**
135
- * Encode function parameters (ABI encoding)
136
- */
137
- encodeParameters(types, values) {
138
- if (types.length !== values.length) {
139
- throw new Error('Types and values length mismatch');
140
- }
141
-
142
- const heads = [];
143
- const tails = [];
144
- let tailOffset = types.length * 32; // Start of dynamic data
145
-
146
- for (let i = 0; i < types.length; i++) {
147
- const type = types[i];
148
- const value = values[i];
149
- const typeInfo = ABI_TYPES[type];
150
-
151
- if (!typeInfo || !typeInfo.dynamic) {
152
- // Static type - encode directly in head
153
- heads.push(this.encodeValue(type, value));
154
- } else {
155
- // Dynamic type - encode offset in head, data in tail
156
- heads.push(this.encodeUint256(tailOffset));
157
- const encoded = this.encodeValue(type, value);
158
- tails.push(encoded);
159
- tailOffset += encoded.length;
160
- }
161
- }
162
-
163
- return Buffer.concat([...heads, ...tails]);
164
- }
165
-
166
- /**
167
- * Decode function parameters
168
- */
169
- decodeParameters(types, data) {
170
- const results = [];
171
- let offset = 0;
172
-
173
- for (const type of types) {
174
- const typeInfo = ABI_TYPES[type];
175
-
176
- if (!typeInfo || !typeInfo.dynamic) {
177
- // Static type
178
- results.push(this.decodeValue(type, data, offset));
179
- offset += 32;
180
- } else {
181
- // Dynamic type - read offset first
182
- const dataOffset = Number(this.decodeUint256(data, offset));
183
- results.push(this.decodeValue(type, data, dataOffset));
184
- offset += 32;
185
- }
186
- }
187
-
188
- return results;
189
- }
190
-
191
- /**
192
- * Encode a single value
193
- */
194
- encodeValue(type, value) {
195
- switch (type) {
196
- case 'uint256':
197
- case 'int256':
198
- return this.encodeUint256(value);
199
-
200
- case 'address':
201
- return this.encodeAddress(value);
202
-
203
- case 'bool':
204
- return this.encodeUint256(value ? 1 : 0);
205
-
206
- case 'bytes32':
207
- return this.encodeBytes32(value);
208
-
209
- case 'bytes':
210
- return this.encodeBytes(value);
211
-
212
- case 'string':
213
- return this.encodeString(value);
214
-
215
- case 'uint256[]':
216
- case 'address[]':
217
- return this.encodeArray(type.replace('[]', ''), value);
218
-
219
- default:
220
- throw new Error(`Unsupported type: ${type}`);
221
- }
222
- }
223
-
224
- /**
225
- * Decode a single value
226
- */
227
- decodeValue(type, data, offset) {
228
- switch (type) {
229
- case 'uint256':
230
- return this.decodeUint256(data, offset);
231
-
232
- case 'int256':
233
- return this.decodeInt256(data, offset);
234
-
235
- case 'address':
236
- return this.decodeAddress(data, offset);
237
-
238
- case 'bool':
239
- return this.decodeUint256(data, offset) !== 0n;
240
-
241
- case 'bytes32':
242
- return '0x' + data.slice(offset, offset + 32).toString('hex');
243
-
244
- case 'bytes':
245
- return this.decodeBytes(data, offset);
246
-
247
- case 'string':
248
- return this.decodeString(data, offset);
249
-
250
- default:
251
- throw new Error(`Unsupported type: ${type}`);
252
- }
253
- }
254
-
255
- // ═══════════════════════════════════════════════════════════════
256
- // ENCODING HELPERS
257
- // ═══════════════════════════════════════════════════════════════
258
-
259
- encodeUint256(value) {
260
- const buf = Buffer.alloc(32);
261
- let v = BigInt(value);
262
- for (let i = 31; i >= 0 && v > 0n; i--) {
263
- buf[i] = Number(v & 0xffn);
264
- v >>= 8n;
265
- }
266
- return buf;
267
- }
268
-
269
- decodeUint256(data, offset = 0) {
270
- let result = 0n;
271
- for (let i = 0; i < 32; i++) {
272
- result = (result << 8n) | BigInt(data[offset + i] || 0);
273
- }
274
- return result;
275
- }
276
-
277
- decodeInt256(data, offset = 0) {
278
- const unsigned = this.decodeUint256(data, offset);
279
- // Check sign bit
280
- if (unsigned >= 2n ** 255n) {
281
- return unsigned - 2n ** 256n;
282
- }
283
- return unsigned;
284
- }
285
-
286
- encodeAddress(address) {
287
- const buf = Buffer.alloc(32);
288
- const hex = address.startsWith('0x') ? address.slice(2) : address;
289
- Buffer.from(hex.padStart(40, '0'), 'hex').copy(buf, 12);
290
- return buf;
291
- }
292
-
293
- decodeAddress(data, offset = 0) {
294
- return '0x' + data.slice(offset + 12, offset + 32).toString('hex');
295
- }
296
-
297
- encodeBytes32(value) {
298
- const buf = Buffer.alloc(32);
299
- const hex = value.startsWith('0x') ? value.slice(2) : value;
300
- Buffer.from(hex.padEnd(64, '0'), 'hex').copy(buf);
301
- return buf;
302
- }
303
-
304
- encodeBytes(value) {
305
- const data = Buffer.isBuffer(value) ? value : Buffer.from(value.replace('0x', ''), 'hex');
306
- const length = this.encodeUint256(data.length);
307
-
308
- // Pad to 32-byte boundary
309
- const padded = Buffer.alloc(Math.ceil(data.length / 32) * 32);
310
- data.copy(padded);
311
-
312
- return Buffer.concat([length, padded]);
313
- }
314
-
315
- decodeBytes(data, offset = 0) {
316
- const length = Number(this.decodeUint256(data, offset));
317
- return data.slice(offset + 32, offset + 32 + length);
318
- }
319
-
320
- encodeString(value) {
321
- return this.encodeBytes(Buffer.from(value, 'utf8'));
322
- }
323
-
324
- decodeString(data, offset = 0) {
325
- return this.decodeBytes(data, offset).toString('utf8');
326
- }
327
-
328
- encodeArray(elementType, values) {
329
- const length = this.encodeUint256(values.length);
330
- const elements = values.map(v => this.encodeValue(elementType, v));
331
- return Buffer.concat([length, ...elements]);
332
- }
333
-
334
- // ═══════════════════════════════════════════════════════════════
335
- // CRYPTO
336
- // ═══════════════════════════════════════════════════════════════
337
-
338
- keccak256(data) {
339
- // Using sha3-256 as approximation
340
- // Real implementation would use keccak
341
- return crypto.createHash('sha3-256').update(data).digest();
342
- }
343
-
344
- // ═══════════════════════════════════════════════════════════════
345
- // TRANSACTION ENCODING (EIP-2718, EIP-1559)
346
- // ═══════════════════════════════════════════════════════════════
347
-
348
- encodeTransaction(tx) {
349
- // EIP-1559 transaction
350
- const fields = [
351
- tx.chainId || this.chainId,
352
- tx.nonce || 0,
353
- tx.maxPriorityFeePerGas || 0,
354
- tx.maxFeePerGas || 0,
355
- tx.gasLimit || 21000,
356
- tx.to || '',
357
- tx.value || 0,
358
- tx.data || Buffer.alloc(0),
359
- tx.accessList || []
360
- ];
361
-
362
- // RLP encode (simplified)
363
- const encoded = this.rlpEncode(fields);
364
-
365
- // Prepend transaction type (0x02 for EIP-1559)
366
- return Buffer.concat([Buffer.from([0x02]), encoded]);
367
- }
368
-
369
- rlpEncode(input) {
370
- if (Array.isArray(input)) {
371
- const encoded = input.map(item => this.rlpEncode(item));
372
- const concat = Buffer.concat(encoded);
373
- return Buffer.concat([this.rlpEncodeLength(concat.length, 0xc0), concat]);
374
- }
375
-
376
- if (Buffer.isBuffer(input)) {
377
- if (input.length === 1 && input[0] < 0x80) {
378
- return input;
379
- }
380
- return Buffer.concat([this.rlpEncodeLength(input.length, 0x80), input]);
381
- }
382
-
383
- if (typeof input === 'number' || typeof input === 'bigint') {
384
- if (input === 0 || input === 0n) {
385
- return Buffer.from([0x80]);
386
- }
387
- const hex = input.toString(16);
388
- const buf = Buffer.from(hex.length % 2 ? '0' + hex : hex, 'hex');
389
- return this.rlpEncode(buf);
390
- }
391
-
392
- if (typeof input === 'string') {
393
- if (input.startsWith('0x')) {
394
- return this.rlpEncode(Buffer.from(input.slice(2), 'hex'));
395
- }
396
- return this.rlpEncode(Buffer.from(input));
397
- }
398
-
399
- return Buffer.from([0x80]);
400
- }
401
-
402
- rlpEncodeLength(length, offset) {
403
- if (length < 56) {
404
- return Buffer.from([offset + length]);
405
- }
406
- const hexLength = length.toString(16);
407
- const lenOfLen = Math.ceil(hexLength.length / 2);
408
- return Buffer.concat([
409
- Buffer.from([offset + 55 + lenOfLen]),
410
- Buffer.from(hexLength.padStart(lenOfLen * 2, '0'), 'hex')
411
- ]);
412
- }
413
-
414
- // ═══════════════════════════════════════════════════════════════
415
- // PRECOMPILES
416
- // ═══════════════════════════════════════════════════════════════
417
-
418
- async executePrecompile(address, input) {
419
- const name = PRECOMPILES[address.toLowerCase()];
420
- if (!name) {
421
- throw new Error(`Unknown precompile: ${address}`);
422
- }
423
-
424
- switch (name) {
425
- case 'ecrecover':
426
- return this._ecrecover(input);
427
- case 'sha256':
428
- return crypto.createHash('sha256').update(input).digest();
429
- case 'ripemd160':
430
- const ripemd = crypto.createHash('ripemd160').update(input).digest();
431
- return Buffer.concat([Buffer.alloc(12), ripemd]);
432
- case 'identity':
433
- return input;
434
- case 'modexp':
435
- return this._modexp(input);
436
- default:
437
- throw new Error(`Precompile not implemented: ${name}`);
438
- }
439
- }
440
-
441
- _ecrecover(input) {
442
- // Extract components from input
443
- // Would need actual EC recovery implementation
444
- return Buffer.alloc(32);
445
- }
446
-
447
- _modexp(input) {
448
- // Modular exponentiation
449
- // Would need big integer implementation
450
- return Buffer.alloc(32);
451
- }
452
- }
453
-
454
- module.exports = EVMAdapter;