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,543 +0,0 @@
1
- /**
2
- * JAELIS BLOCKCHAIN INTEGRATION
3
- *
4
- * Connects the Universal VM to the JAELIS blockchain:
5
- * - Transaction processing
6
- * - Block execution
7
- * - State synchronization
8
- * - Cross-chain bridge support
9
- *
10
- * @version 0.1.0
11
- * @author Mario Papaleo - JAELIS Foundation
12
- */
13
-
14
- const EventEmitter = require('events');
15
- const crypto = require('crypto');
16
-
17
- /**
18
- * VM Transaction Types
19
- */
20
- const TX_TYPES = {
21
- DEPLOY: 0x01, // Deploy contract
22
- CALL: 0x02, // Call contract function
23
- TRANSFER: 0x03, // Transfer native token
24
- CROSS_VM_CALL: 0x04, // Cross-VM call
25
- BRIDGE_LOCK: 0x05, // Lock for bridging
26
- BRIDGE_UNLOCK: 0x06, // Unlock from bridge
27
- CREATE_ACCOUNT: 0x07, // Create new account
28
- UPGRADE: 0x08 // Upgrade contract
29
- };
30
-
31
- /**
32
- * Cross-Chain Bridge Registry
33
- */
34
- class BridgeRegistry {
35
- constructor() {
36
- this.bridges = new Map();
37
- this.lockedAssets = new Map();
38
- this.mintedAssets = new Map();
39
- }
40
-
41
- registerBridge(sourceChain, targetChain, bridgeContract) {
42
- const key = `${sourceChain}:${targetChain}`;
43
- this.bridges.set(key, bridgeContract);
44
- }
45
-
46
- getBridge(sourceChain, targetChain) {
47
- return this.bridges.get(`${sourceChain}:${targetChain}`);
48
- }
49
-
50
- lockAsset(sourceChain, assetId, amount, owner) {
51
- const lockId = crypto.randomBytes(32).toString('hex');
52
- this.lockedAssets.set(lockId, {
53
- sourceChain,
54
- assetId,
55
- amount,
56
- owner,
57
- lockedAt: Date.now()
58
- });
59
- return lockId;
60
- }
61
-
62
- unlockAsset(lockId) {
63
- const asset = this.lockedAssets.get(lockId);
64
- if (!asset) throw new Error('Lock not found');
65
- this.lockedAssets.delete(lockId);
66
- return asset;
67
- }
68
-
69
- mintWrappedAsset(targetChain, originalAsset, amount, recipient) {
70
- const mintId = crypto.randomBytes(32).toString('hex');
71
- this.mintedAssets.set(mintId, {
72
- targetChain,
73
- originalAsset,
74
- amount,
75
- recipient,
76
- mintedAt: Date.now()
77
- });
78
- return mintId;
79
- }
80
- }
81
-
82
- /**
83
- * JAELIS Blockchain Integration
84
- */
85
- class JaelisIntegration extends EventEmitter {
86
- constructor(universalVM, config = {}) {
87
- super();
88
-
89
- this.vm = universalVM;
90
- this.config = {
91
- chainId: config.chainId || 4545,
92
- blockGasLimit: config.blockGasLimit || 30000000,
93
- ...config
94
- };
95
-
96
- // Bridge registry
97
- this.bridgeRegistry = new BridgeRegistry();
98
-
99
- // Transaction pool
100
- this.pendingTxs = [];
101
-
102
- // Block tracking
103
- this.currentBlock = {
104
- number: 0,
105
- timestamp: Math.floor(Date.now() / 1000),
106
- parentHash: '0x' + '0'.repeat(64),
107
- stateRoot: null,
108
- transactions: [],
109
- gasUsed: 0
110
- };
111
-
112
- // Cross-chain message queue
113
- this.crossChainMessages = [];
114
-
115
- console.log('[Integration] JAELIS blockchain integration initialized');
116
- }
117
-
118
- /**
119
- * Process a transaction
120
- */
121
- async processTransaction(tx) {
122
- console.log(`[Integration] Processing transaction: ${tx.hash?.substring(0, 16) || 'new'}...`);
123
-
124
- // Validate transaction
125
- const validation = await this.validateTransaction(tx);
126
- if (!validation.valid) {
127
- throw new Error(`Invalid transaction: ${validation.error}`);
128
- }
129
-
130
- // Get VM adapter based on transaction type
131
- const sourceVM = tx.sourceVM || this.detectSourceVM(tx);
132
-
133
- let result;
134
- switch (tx.type) {
135
- case TX_TYPES.DEPLOY:
136
- result = await this.processDeploy(tx, sourceVM);
137
- break;
138
-
139
- case TX_TYPES.CALL:
140
- result = await this.processCall(tx, sourceVM);
141
- break;
142
-
143
- case TX_TYPES.TRANSFER:
144
- result = await this.processTransfer(tx);
145
- break;
146
-
147
- case TX_TYPES.CROSS_VM_CALL:
148
- result = await this.processCrossVMCall(tx);
149
- break;
150
-
151
- case TX_TYPES.BRIDGE_LOCK:
152
- result = await this.processBridgeLock(tx);
153
- break;
154
-
155
- case TX_TYPES.BRIDGE_UNLOCK:
156
- result = await this.processBridgeUnlock(tx);
157
- break;
158
-
159
- default:
160
- throw new Error(`Unknown transaction type: ${tx.type}`);
161
- }
162
-
163
- // Update block stats
164
- this.currentBlock.transactions.push(tx.hash);
165
- this.currentBlock.gasUsed += result.gasUsed || 0;
166
-
167
- // Emit event
168
- this.emit('transactionProcessed', { tx, result });
169
-
170
- return result;
171
- }
172
-
173
- /**
174
- * Process deploy transaction
175
- */
176
- async processDeploy(tx, sourceVM) {
177
- console.log(`[Integration] Deploying ${sourceVM.toUpperCase()} contract...`);
178
-
179
- // Translate bytecode if needed
180
- const jir = await this.vm.translator.translateToJIR(tx.data, sourceVM);
181
-
182
- // Deploy to VM
183
- const result = await this.vm.deployBytecode(tx.data, sourceVM, {
184
- deployer: tx.from,
185
- value: tx.value,
186
- gasLimit: tx.gasLimit
187
- });
188
-
189
- // Record in state
190
- await this.vm.state.storeContract(result.address, {
191
- jir,
192
- sourceVM,
193
- bytecode: tx.data,
194
- deployer: tx.from
195
- });
196
-
197
- return {
198
- success: true,
199
- contractAddress: result.address,
200
- sourceVM,
201
- gasUsed: result.jirSize || 0
202
- };
203
- }
204
-
205
- /**
206
- * Process call transaction
207
- */
208
- async processCall(tx, sourceVM) {
209
- console.log(`[Integration] Calling contract ${tx.to?.substring(0, 16)}...`);
210
-
211
- // Get contract
212
- const contract = await this.vm.state.getContract(tx.to);
213
- if (!contract) {
214
- throw new Error(`Contract not found: ${tx.to}`);
215
- }
216
-
217
- // Execute
218
- const result = await this.vm.execute(tx.to, tx.function || 'fallback', tx.data, {
219
- from: tx.from,
220
- value: tx.value,
221
- gasLimit: tx.gasLimit,
222
- blockNumber: this.currentBlock.number,
223
- timestamp: this.currentBlock.timestamp,
224
- chainId: this.config.chainId
225
- });
226
-
227
- return {
228
- success: result.success,
229
- returnValue: result.returnValue,
230
- gasUsed: result.instructionsUsed,
231
- logs: result.logs,
232
- stateChanges: result.stateChanges
233
- };
234
- }
235
-
236
- /**
237
- * Process transfer transaction
238
- */
239
- async processTransfer(tx) {
240
- console.log(`[Integration] Transfer: ${tx.from?.substring(0, 10)}... → ${tx.to?.substring(0, 10)}...`);
241
-
242
- // Get balances
243
- const fromBalance = await this.vm.state.getBalance(tx.from);
244
- const toBalance = await this.vm.state.getBalance(tx.to);
245
-
246
- const amount = BigInt(tx.value);
247
- if (fromBalance < amount) {
248
- throw new Error('Insufficient balance');
249
- }
250
-
251
- // Update balances
252
- await this.vm.state.setBalance(tx.from, fromBalance - amount);
253
- await this.vm.state.setBalance(tx.to, toBalance + amount);
254
-
255
- return {
256
- success: true,
257
- gasUsed: 21000 // Base transfer gas
258
- };
259
- }
260
-
261
- /**
262
- * Process cross-VM call
263
- */
264
- async processCrossVMCall(tx) {
265
- console.log(`[Integration] Cross-VM call: ${tx.sourceVM} → ${tx.targetVM}`);
266
-
267
- const result = await this.vm.crossVMCall(
268
- tx.from,
269
- tx.to,
270
- tx.function,
271
- tx.args,
272
- {
273
- value: tx.value,
274
- gasLimit: tx.gasLimit
275
- }
276
- );
277
-
278
- return {
279
- success: result.success,
280
- returnValue: result.returnValue,
281
- gasUsed: result.instructionsUsed,
282
- crossVM: result.crossVM
283
- };
284
- }
285
-
286
- /**
287
- * Process bridge lock (for cross-chain transfers)
288
- */
289
- async processBridgeLock(tx) {
290
- console.log(`[Integration] Bridge lock: ${tx.targetChain}`);
291
-
292
- // Lock assets
293
- const lockId = this.bridgeRegistry.lockAsset(
294
- 'jaelis',
295
- tx.asset || 'native',
296
- tx.value,
297
- tx.from
298
- );
299
-
300
- // Deduct from sender
301
- if (!tx.asset || tx.asset === 'native') {
302
- const balance = await this.vm.state.getBalance(tx.from);
303
- await this.vm.state.setBalance(tx.from, balance - BigInt(tx.value));
304
- }
305
-
306
- // Queue cross-chain message
307
- this.crossChainMessages.push({
308
- type: 'mint',
309
- targetChain: tx.targetChain,
310
- lockId,
311
- recipient: tx.recipient || tx.from,
312
- asset: tx.asset || 'native',
313
- amount: tx.value
314
- });
315
-
316
- return {
317
- success: true,
318
- lockId,
319
- gasUsed: 50000
320
- };
321
- }
322
-
323
- /**
324
- * Process bridge unlock (receive from other chain)
325
- */
326
- async processBridgeUnlock(tx) {
327
- console.log(`[Integration] Bridge unlock: ${tx.lockId}`);
328
-
329
- // Verify lock proof from source chain
330
- if (!this.verifyLockProof(tx.sourceChain, tx.lockId, tx.proof)) {
331
- throw new Error('Invalid lock proof');
332
- }
333
-
334
- // Unlock or mint
335
- const asset = this.bridgeRegistry.unlockAsset(tx.lockId);
336
-
337
- // Credit recipient
338
- const balance = await this.vm.state.getBalance(tx.recipient);
339
- await this.vm.state.setBalance(tx.recipient, balance + BigInt(asset.amount));
340
-
341
- return {
342
- success: true,
343
- unlocked: asset,
344
- gasUsed: 50000
345
- };
346
- }
347
-
348
- /**
349
- * Execute a block
350
- */
351
- async executeBlock(block) {
352
- console.log(`[Integration] Executing block ${block.number}...`);
353
-
354
- // Create checkpoint for potential rollback
355
- const checkpoint = this.vm.state.checkpoint();
356
-
357
- try {
358
- const results = [];
359
-
360
- for (const tx of block.transactions) {
361
- const result = await this.processTransaction(tx);
362
- results.push(result);
363
- }
364
-
365
- // Commit checkpoint
366
- await this.vm.state.commit(checkpoint);
367
-
368
- // Update block state
369
- this.currentBlock = {
370
- number: block.number + 1,
371
- timestamp: Math.floor(Date.now() / 1000),
372
- parentHash: block.hash || this.hashBlock(block),
373
- stateRoot: this.vm.state.getStateRoot(),
374
- transactions: [],
375
- gasUsed: 0
376
- };
377
-
378
- return {
379
- success: true,
380
- blockHash: this.currentBlock.parentHash,
381
- stateRoot: this.currentBlock.stateRoot,
382
- results
383
- };
384
-
385
- } catch (error) {
386
- // Rollback on error
387
- await this.vm.state.revert(checkpoint);
388
- throw error;
389
- }
390
- }
391
-
392
- /**
393
- * Get pending cross-chain messages
394
- */
395
- getPendingCrossChainMessages() {
396
- return [...this.crossChainMessages];
397
- }
398
-
399
- /**
400
- * Clear processed cross-chain messages
401
- */
402
- clearCrossChainMessages(messageIds) {
403
- this.crossChainMessages = this.crossChainMessages.filter(
404
- m => !messageIds.includes(m.lockId)
405
- );
406
- }
407
-
408
- // ═══════════════════════════════════════════════════════════════
409
- // HELPERS
410
- // ═══════════════════════════════════════════════════════════════
411
-
412
- async validateTransaction(tx) {
413
- // Basic validation
414
- if (!tx.from) {
415
- return { valid: false, error: 'Missing sender' };
416
- }
417
-
418
- if (tx.type === TX_TYPES.CALL && !tx.to) {
419
- return { valid: false, error: 'Missing recipient for call' };
420
- }
421
-
422
- // Check nonce
423
- const expectedNonce = await this.vm.state.getNonce(tx.from);
424
- if (tx.nonce !== undefined && tx.nonce < expectedNonce) {
425
- return { valid: false, error: 'Nonce too low' };
426
- }
427
-
428
- // Check balance for value transfers
429
- if (tx.value > 0) {
430
- const balance = await this.vm.state.getBalance(tx.from);
431
- if (balance < BigInt(tx.value)) {
432
- return { valid: false, error: 'Insufficient balance' };
433
- }
434
- }
435
-
436
- return { valid: true };
437
- }
438
-
439
- detectSourceVM(tx) {
440
- // Try to detect VM from bytecode or calldata
441
- if (tx.data && tx.data.length > 0) {
442
- const firstByte = tx.data[0];
443
-
444
- // WASM magic number
445
- if (tx.data.length > 4 && tx.data[0] === 0x00 && tx.data[1] === 0x61) {
446
- return 'wasm';
447
- }
448
-
449
- // EVM-style (most common)
450
- if (firstByte === 0x60 || firstByte === 0x61) {
451
- return 'evm';
452
- }
453
-
454
- // ELF header (Solana)
455
- if (tx.data.length > 4 && tx.data[0] === 0x7F && tx.data[1] === 0x45) {
456
- return 'svm';
457
- }
458
- }
459
-
460
- // Default to EVM
461
- return 'evm';
462
- }
463
-
464
- verifyLockProof(sourceChain, lockId, proof) {
465
- // Simplified proof verification
466
- // Real implementation would verify Merkle proof against source chain
467
- return proof && proof.valid === true;
468
- }
469
-
470
- hashBlock(block) {
471
- const data = JSON.stringify({
472
- number: block.number,
473
- timestamp: block.timestamp,
474
- parentHash: block.parentHash,
475
- transactions: block.transactions.map(tx => tx.hash || crypto.createHash('sha256').update(JSON.stringify(tx)).digest('hex'))
476
- });
477
- return '0x' + crypto.createHash('sha256').update(data).digest('hex');
478
- }
479
-
480
- // ═══════════════════════════════════════════════════════════════
481
- // CHAIN OPERATOR INTERFACE
482
- // ═══════════════════════════════════════════════════════════════
483
-
484
- /**
485
- * Get VM statistics
486
- */
487
- getStats() {
488
- return {
489
- vm: this.vm.getStats(),
490
- state: this.vm.state.getStats(),
491
- currentBlock: this.currentBlock.number,
492
- pendingTxs: this.pendingTxs.length,
493
- crossChainMessages: this.crossChainMessages.length,
494
- bridges: this.bridgeRegistry.bridges.size
495
- };
496
- }
497
-
498
- /**
499
- * Register external chain for bridging
500
- */
501
- registerExternalChain(chainId, config) {
502
- console.log(`[Integration] Registered external chain: ${chainId}`);
503
- this.bridgeRegistry.registerBridge('jaelis', chainId, config);
504
- }
505
-
506
- /**
507
- * Submit pending transaction
508
- */
509
- submitTransaction(tx) {
510
- // Add hash if missing
511
- if (!tx.hash) {
512
- tx.hash = '0x' + crypto.createHash('sha256')
513
- .update(JSON.stringify(tx) + Date.now())
514
- .digest('hex');
515
- }
516
-
517
- this.pendingTxs.push(tx);
518
- return tx.hash;
519
- }
520
-
521
- /**
522
- * Create block from pending transactions
523
- */
524
- async createBlock() {
525
- const block = {
526
- number: this.currentBlock.number,
527
- timestamp: Math.floor(Date.now() / 1000),
528
- parentHash: this.currentBlock.parentHash,
529
- transactions: [...this.pendingTxs],
530
- gasLimit: this.config.blockGasLimit
531
- };
532
-
533
- this.pendingTxs = [];
534
-
535
- return this.executeBlock(block);
536
- }
537
- }
538
-
539
- module.exports = {
540
- JaelisIntegration,
541
- BridgeRegistry,
542
- TX_TYPES
543
- };