trac-msb 0.0.13 → 0.0.15

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 (301) hide show
  1. package/_stores/n1/db/000071.blob +0 -0
  2. package/_stores/n1/db/000073.blob +0 -0
  3. package/_stores/n1/db/000085.blob +0 -0
  4. package/_stores/n1/db/000088.blob +0 -0
  5. package/_stores/n1/db/000089.sst +0 -0
  6. package/_stores/n1/db/000090.sst +0 -0
  7. package/_stores/n1/db/000092.blob +0 -0
  8. package/_stores/n1/db/000093.sst +0 -0
  9. package/_stores/n1/db/000162.blob +0 -0
  10. package/_stores/n1/db/000165.blob +0 -0
  11. package/_stores/n1/db/000175.blob +0 -0
  12. package/_stores/n1/db/000186.blob +0 -0
  13. package/_stores/n1/db/000189.blob +0 -0
  14. package/_stores/n1/db/000195.blob +0 -0
  15. package/_stores/n1/db/000210.blob +0 -0
  16. package/_stores/n1/db/000222.blob +0 -0
  17. package/_stores/n1/db/000225.blob +0 -0
  18. package/_stores/n1/db/000229.sst +0 -0
  19. package/_stores/n1/db/000230.sst +0 -0
  20. package/_stores/n1/db/000231.blob +0 -0
  21. package/_stores/n1/db/000232.sst +0 -0
  22. package/_stores/n1/db/000245.blob +0 -0
  23. package/_stores/n1/db/000250.log +0 -0
  24. package/_stores/n1/db/000252.blob +0 -0
  25. package/_stores/n1/db/000253.sst +0 -0
  26. package/_stores/n1/db/000254.sst +0 -0
  27. package/_stores/n1/db/CURRENT +1 -0
  28. package/_stores/n1/db/IDENTITY +1 -0
  29. package/_stores/n1/db/LOCK +0 -0
  30. package/_stores/n1/db/LOG +115 -0
  31. package/_stores/n1/db/LOG.old.1742183021576909 +0 -0
  32. package/_stores/n1/db/LOG.old.1742186169260958 +0 -0
  33. package/_stores/n1/db/LOG.old.1742356429622171 +0 -0
  34. package/_stores/n1/db/LOG.old.1742356454896144 +0 -0
  35. package/_stores/n1/db/LOG.old.1742356784525414 +0 -0
  36. package/_stores/n1/db/LOG.old.1742356872553496 +0 -0
  37. package/_stores/n1/db/LOG.old.1742356889597303 +0 -0
  38. package/_stores/n1/db/LOG.old.1742357459830241 +0 -0
  39. package/_stores/n1/db/LOG.old.1742357505153356 +0 -0
  40. package/_stores/n1/db/LOG.old.1742404971790711 +0 -0
  41. package/_stores/n1/db/LOG.old.1742419942002515 +0 -0
  42. package/_stores/n1/db/LOG.old.1742420819468818 +0 -0
  43. package/_stores/n1/db/LOG.old.1742421141667874 +0 -0
  44. package/_stores/n1/db/LOG.old.1742577491693110 +0 -0
  45. package/_stores/n1/db/LOG.old.1742589273002581 +0 -0
  46. package/_stores/n1/db/LOG.old.1742641251570901 +466 -0
  47. package/_stores/n1/db/LOG.old.1742641819650240 +115 -0
  48. package/_stores/n1/db/MANIFEST-000247 +0 -0
  49. package/_stores/n1/db/OPTIONS-000243 +0 -0
  50. package/_stores/n1/db/OPTIONS-000249 +0 -0
  51. package/_stores/n1/db/keypair.json +1 -0
  52. package/_stores/n2/db/000067.blob +0 -0
  53. package/_stores/n2/db/000073.blob +0 -0
  54. package/_stores/n2/db/000081.blob +0 -0
  55. package/_stores/n2/db/000088.blob +0 -0
  56. package/_stores/n2/db/000093.sst +0 -0
  57. package/_stores/n2/db/000094.blob +0 -0
  58. package/_stores/n2/db/000095.sst +0 -0
  59. package/_stores/n2/db/000096.sst +0 -0
  60. package/_stores/n2/db/000114.blob +0 -0
  61. package/_stores/n2/db/000117.blob +0 -0
  62. package/_stores/n2/db/000127.blob +0 -0
  63. package/_stores/n2/db/000138.blob +0 -0
  64. package/_stores/n2/db/000141.blob +0 -0
  65. package/_stores/n2/db/000150.blob +0 -0
  66. package/_stores/n2/db/000166.blob +0 -0
  67. package/_stores/n2/db/000175.blob +0 -0
  68. package/_stores/n2/db/000180.sst +0 -0
  69. package/_stores/n2/db/000196.blob +0 -0
  70. package/_stores/n2/db/000201.sst +0 -0
  71. package/_stores/n2/db/000202.sst +0 -0
  72. package/_stores/n2/db/000204.sst +0 -0
  73. package/_stores/n2/db/000205.sst +0 -0
  74. package/_stores/n2/db/000206.sst +0 -0
  75. package/_stores/n2/db/000207.sst +0 -0
  76. package/_stores/n2/db/000208.log +0 -0
  77. package/_stores/n2/db/000209.sst +0 -0
  78. package/_stores/n2/db/000210.blob +0 -0
  79. package/_stores/n2/db/CURRENT +0 -0
  80. package/_stores/n2/db/IDENTITY +0 -0
  81. package/_stores/n2/db/LOCK +0 -0
  82. package/_stores/n2/db/LOG +0 -0
  83. package/_stores/n2/db/LOG.old.1742186170827801 +0 -0
  84. package/_stores/n2/db/LOG.old.1742419970256241 +0 -0
  85. package/_stores/n2/db/LOG.old.1742420821296937 +0 -0
  86. package/_stores/n2/db/LOG.old.1742421143874068 +0 -0
  87. package/_stores/n2/db/LOG.old.1742577493694397 +0 -0
  88. package/_stores/n2/db/LOG.old.1742589275454624 +0 -0
  89. package/_stores/n2/db/MANIFEST-000198 +0 -0
  90. package/_stores/n2/db/OPTIONS-000194 +0 -0
  91. package/_stores/n2/db/OPTIONS-000200 +0 -0
  92. package/_stores/n2/db/keypair.json +1 -0
  93. package/_stores/n3/db/000067.blob +0 -0
  94. package/_stores/n3/db/000073.blob +0 -0
  95. package/_stores/n3/db/000081.blob +0 -0
  96. package/_stores/n3/db/000088.blob +0 -0
  97. package/_stores/n3/db/000093.sst +0 -0
  98. package/_stores/n3/db/000094.blob +0 -0
  99. package/_stores/n3/db/000095.sst +0 -0
  100. package/_stores/n3/db/000096.sst +0 -0
  101. package/_stores/n3/db/000114.blob +0 -0
  102. package/_stores/n3/db/000117.blob +0 -0
  103. package/_stores/n3/db/000127.blob +0 -0
  104. package/_stores/n3/db/000138.blob +0 -0
  105. package/_stores/n3/db/000141.blob +0 -0
  106. package/_stores/n3/db/000150.blob +0 -0
  107. package/_stores/n3/db/000166.blob +0 -0
  108. package/_stores/n3/db/000175.blob +0 -0
  109. package/_stores/n3/db/000180.sst +0 -0
  110. package/_stores/n3/db/000196.blob +0 -0
  111. package/_stores/n3/db/000201.sst +0 -0
  112. package/_stores/n3/db/000202.sst +0 -0
  113. package/_stores/n3/db/000204.sst +0 -0
  114. package/_stores/n3/db/000205.sst +0 -0
  115. package/_stores/n3/db/000206.sst +0 -0
  116. package/_stores/n3/db/000207.sst +0 -0
  117. package/_stores/n3/db/000208.log +0 -0
  118. package/_stores/n3/db/000209.sst +0 -0
  119. package/_stores/n3/db/000210.blob +0 -0
  120. package/_stores/n3/db/CURRENT +0 -0
  121. package/_stores/n3/db/IDENTITY +0 -0
  122. package/_stores/n3/db/LOCK +0 -0
  123. package/_stores/n3/db/LOG +0 -0
  124. package/_stores/n3/db/LOG.old.1742186172888124 +0 -0
  125. package/_stores/n3/db/LOG.old.1742420094609648 +0 -0
  126. package/_stores/n3/db/LOG.old.1742420822815851 +0 -0
  127. package/_stores/n3/db/LOG.old.1742421145506410 +0 -0
  128. package/_stores/n3/db/LOG.old.1742577495315796 +0 -0
  129. package/_stores/n3/db/LOG.old.1742589277258083 +0 -0
  130. package/_stores/n3/db/MANIFEST-000198 +0 -0
  131. package/_stores/n3/db/OPTIONS-000194 +0 -0
  132. package/_stores/n3/db/OPTIONS-000200 +0 -0
  133. package/_stores/n3/db/keypair.json +1 -0
  134. package/_stores/n4/db/000067.blob +0 -0
  135. package/_stores/n4/db/000074.blob +0 -0
  136. package/_stores/n4/db/000081.blob +0 -0
  137. package/_stores/n4/db/000088.blob +0 -0
  138. package/_stores/n4/db/000093.sst +0 -0
  139. package/_stores/n4/db/000094.blob +0 -0
  140. package/_stores/n4/db/000095.sst +0 -0
  141. package/_stores/n4/db/000096.sst +0 -0
  142. package/_stores/n4/db/000114.blob +0 -0
  143. package/_stores/n4/db/000117.blob +0 -0
  144. package/_stores/n4/db/000127.blob +0 -0
  145. package/_stores/n4/db/000138.blob +0 -0
  146. package/_stores/n4/db/000141.blob +0 -0
  147. package/_stores/n4/db/000150.blob +0 -0
  148. package/_stores/n4/db/000159.blob +0 -0
  149. package/_stores/n4/db/000166.blob +0 -0
  150. package/_stores/n4/db/000175.blob +0 -0
  151. package/_stores/n4/db/000180.sst +0 -0
  152. package/_stores/n4/db/000196.blob +0 -0
  153. package/_stores/n4/db/000201.sst +0 -0
  154. package/_stores/n4/db/000202.sst +0 -0
  155. package/_stores/n4/db/000204.sst +0 -0
  156. package/_stores/n4/db/000205.sst +0 -0
  157. package/_stores/n4/db/000206.sst +0 -0
  158. package/_stores/n4/db/000207.sst +0 -0
  159. package/_stores/n4/db/000208.log +0 -0
  160. package/_stores/n4/db/000209.sst +0 -0
  161. package/_stores/n4/db/000210.blob +0 -0
  162. package/_stores/n4/db/CURRENT +0 -0
  163. package/_stores/n4/db/IDENTITY +0 -0
  164. package/_stores/n4/db/LOCK +0 -0
  165. package/_stores/n4/db/LOG +0 -0
  166. package/_stores/n4/db/LOG.old.1742186174617449 +0 -0
  167. package/_stores/n4/db/LOG.old.1742420096536170 +0 -0
  168. package/_stores/n4/db/LOG.old.1742420824264952 +0 -0
  169. package/_stores/n4/db/LOG.old.1742421147129074 +0 -0
  170. package/_stores/n4/db/LOG.old.1742577500353714 +0 -0
  171. package/_stores/n4/db/LOG.old.1742589279083454 +0 -0
  172. package/_stores/n4/db/MANIFEST-000198 +0 -0
  173. package/_stores/n4/db/OPTIONS-000194 +0 -0
  174. package/_stores/n4/db/OPTIONS-000200 +0 -0
  175. package/_stores/n4/db/keypair.json +0 -0
  176. package/_stores/n5/db/000067.blob +0 -0
  177. package/_stores/n5/db/000074.blob +0 -0
  178. package/_stores/n5/db/000081.blob +0 -0
  179. package/_stores/n5/db/000088.blob +0 -0
  180. package/_stores/n5/db/000093.sst +0 -0
  181. package/_stores/n5/db/000094.blob +0 -0
  182. package/_stores/n5/db/000095.sst +0 -0
  183. package/_stores/n5/db/000096.sst +0 -0
  184. package/_stores/n5/db/000114.blob +0 -0
  185. package/_stores/n5/db/000117.blob +0 -0
  186. package/_stores/n5/db/000127.blob +0 -0
  187. package/_stores/n5/db/000138.blob +0 -0
  188. package/_stores/n5/db/000141.blob +0 -0
  189. package/_stores/n5/db/000150.blob +0 -0
  190. package/_stores/n5/db/000166.blob +0 -0
  191. package/_stores/n5/db/000175.blob +0 -0
  192. package/_stores/n5/db/000180.sst +0 -0
  193. package/_stores/n5/db/000196.blob +0 -0
  194. package/_stores/n5/db/000201.sst +0 -0
  195. package/_stores/n5/db/000202.sst +0 -0
  196. package/_stores/n5/db/000204.sst +0 -0
  197. package/_stores/n5/db/000205.sst +0 -0
  198. package/_stores/n5/db/000206.sst +0 -0
  199. package/_stores/n5/db/000207.sst +0 -0
  200. package/_stores/n5/db/000208.log +0 -0
  201. package/_stores/n5/db/000209.sst +0 -0
  202. package/_stores/n5/db/000210.blob +0 -0
  203. package/_stores/n5/db/CURRENT +0 -0
  204. package/_stores/n5/db/IDENTITY +0 -0
  205. package/_stores/n5/db/LOCK +0 -0
  206. package/_stores/n5/db/LOG +0 -0
  207. package/_stores/n5/db/LOG.old.1742186176624713 +0 -0
  208. package/_stores/n5/db/LOG.old.1742420098319634 +0 -0
  209. package/_stores/n5/db/LOG.old.1742420825849458 +0 -0
  210. package/_stores/n5/db/LOG.old.1742421148865382 +0 -0
  211. package/_stores/n5/db/LOG.old.1742577501880031 +0 -0
  212. package/_stores/n5/db/LOG.old.1742589281491031 +0 -0
  213. package/_stores/n5/db/MANIFEST-000198 +0 -0
  214. package/_stores/n5/db/OPTIONS-000194 +0 -0
  215. package/_stores/n5/db/OPTIONS-000200 +0 -0
  216. package/_stores/n5/db/keypair.json +0 -0
  217. package/_stores/n6/db/000074.blob +0 -0
  218. package/_stores/n6/db/000081.blob +0 -0
  219. package/_stores/n6/db/000088.blob +0 -0
  220. package/_stores/n6/db/000093.sst +0 -0
  221. package/_stores/n6/db/000094.blob +0 -0
  222. package/_stores/n6/db/000095.sst +0 -0
  223. package/_stores/n6/db/000096.sst +0 -0
  224. package/_stores/n6/db/000114.blob +0 -0
  225. package/_stores/n6/db/000117.blob +0 -0
  226. package/_stores/n6/db/000127.blob +0 -0
  227. package/_stores/n6/db/000138.blob +0 -0
  228. package/_stores/n6/db/000150.blob +0 -0
  229. package/_stores/n6/db/000159.blob +0 -0
  230. package/_stores/n6/db/000166.blob +0 -0
  231. package/_stores/n6/db/000175.blob +0 -0
  232. package/_stores/n6/db/000180.sst +0 -0
  233. package/_stores/n6/db/000196.blob +0 -0
  234. package/_stores/n6/db/000201.sst +0 -0
  235. package/_stores/n6/db/000202.sst +0 -0
  236. package/_stores/n6/db/000204.sst +0 -0
  237. package/_stores/n6/db/000205.sst +0 -0
  238. package/_stores/n6/db/000206.sst +0 -0
  239. package/_stores/n6/db/000207.sst +0 -0
  240. package/_stores/n6/db/000208.log +0 -0
  241. package/_stores/n6/db/000209.sst +0 -0
  242. package/_stores/n6/db/000210.blob +0 -0
  243. package/_stores/n6/db/CURRENT +0 -0
  244. package/_stores/n6/db/IDENTITY +0 -0
  245. package/_stores/n6/db/LOCK +0 -0
  246. package/_stores/n6/db/LOG +0 -0
  247. package/_stores/n6/db/LOG.old.1742186178370518 +0 -0
  248. package/_stores/n6/db/LOG.old.1742420099918640 +0 -0
  249. package/_stores/n6/db/LOG.old.1742420827341589 +0 -0
  250. package/_stores/n6/db/LOG.old.1742421150560152 +0 -0
  251. package/_stores/n6/db/LOG.old.1742577503396008 +0 -0
  252. package/_stores/n6/db/LOG.old.1742589283821852 +0 -0
  253. package/_stores/n6/db/MANIFEST-000198 +0 -0
  254. package/_stores/n6/db/OPTIONS-000194 +0 -0
  255. package/_stores/n6/db/OPTIONS-000200 +0 -0
  256. package/_stores/n6/db/keypair.json +0 -0
  257. package/_stores/n7/db/000074.blob +0 -0
  258. package/_stores/n7/db/000081.blob +0 -0
  259. package/_stores/n7/db/000088.blob +0 -0
  260. package/_stores/n7/db/000093.sst +0 -0
  261. package/_stores/n7/db/000094.blob +0 -0
  262. package/_stores/n7/db/000095.sst +0 -0
  263. package/_stores/n7/db/000096.sst +0 -0
  264. package/_stores/n7/db/000114.blob +0 -0
  265. package/_stores/n7/db/000117.blob +0 -0
  266. package/_stores/n7/db/000127.blob +0 -0
  267. package/_stores/n7/db/000138.blob +0 -0
  268. package/_stores/n7/db/000150.blob +0 -0
  269. package/_stores/n7/db/000159.blob +0 -0
  270. package/_stores/n7/db/000166.blob +0 -0
  271. package/_stores/n7/db/000172.blob +0 -0
  272. package/_stores/n7/db/000175.blob +0 -0
  273. package/_stores/n7/db/000180.sst +0 -0
  274. package/_stores/n7/db/000193.blob +0 -0
  275. package/_stores/n7/db/000198.log +0 -0
  276. package/_stores/n7/db/000200.blob +0 -0
  277. package/_stores/n7/db/000201.sst +0 -0
  278. package/_stores/n7/db/000202.sst +0 -0
  279. package/_stores/n7/db/000204.sst +0 -0
  280. package/_stores/n7/db/000205.sst +0 -0
  281. package/_stores/n7/db/000206.sst +0 -0
  282. package/_stores/n7/db/000207.sst +0 -0
  283. package/_stores/n7/db/CURRENT +0 -0
  284. package/_stores/n7/db/IDENTITY +0 -0
  285. package/_stores/n7/db/LOCK +0 -0
  286. package/_stores/n7/db/LOG +0 -0
  287. package/_stores/n7/db/LOG.old.1742186180169762 +0 -0
  288. package/_stores/n7/db/LOG.old.1742420109317101 +0 -0
  289. package/_stores/n7/db/LOG.old.1742420828841380 +0 -0
  290. package/_stores/n7/db/LOG.old.1742421152251567 +0 -0
  291. package/_stores/n7/db/LOG.old.1742577512090130 +0 -0
  292. package/_stores/n7/db/LOG.old.1742589286130264 +0 -0
  293. package/_stores/n7/db/MANIFEST-000195 +0 -0
  294. package/_stores/n7/db/OPTIONS-000191 +0 -0
  295. package/_stores/n7/db/OPTIONS-000197 +0 -0
  296. package/_stores/n7/db/keypair.json +1 -0
  297. package/msb.mjs +1 -1
  298. package/package.json +1 -1
  299. package/src/functions.js +7 -64
  300. package/src/index.js +120 -199
  301. package/src/writerManager.js +0 -316
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ {"publicKey":"e76e8affcd49bd1ebb7f1c0048243efcc272fd9f9d144f41e84d59587d368578","secretKey":"e2e6823887157d3dfa60e344325bce082694ae8b6c91b910efa5839cfee49f5ce76e8affcd49bd1ebb7f1c0048243efcc272fd9f9d144f41e84d59587d368578"}
package/msb.mjs CHANGED
@@ -2,7 +2,7 @@ import MainSettlementBus from './src/index.js';
2
2
  const opts = {
3
3
  stores_directory : 'stores/',
4
4
  store_name : process.argv[2],
5
- bootstrap: '3ad0f48d685fdf10c551e596c48596a99ff373c65845d8827da8b7862a476979',
5
+ bootstrap: '8e192d111aee4a29497f2967a4126fdabc2071dc7885a62a82bdfc97b4e4a2e3',
6
6
  channel: Buffer.alloc(32).fill('00botracnetworkmainsettlementbus'),
7
7
  tx : Buffer.alloc(32).fill('botracnetworkmainsettlementbustx')
8
8
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "src/index.js",
4
- "version": "0.0.13",
4
+ "version": "0.0.15",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/functions.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createHash } from "node:crypto";
1
+
2
2
  //TODO: if something is missing, add additonal sanitization
3
3
  // parsed.op === 'pre-tx' -> moved out of the scope this check because we can re-use this function in the apply
4
4
  // TODO: Split sanitization on pre and post TX
@@ -15,68 +15,11 @@ export function sanitizeTransaction(parsedTx) {
15
15
  );
16
16
  }
17
17
 
18
- export function restoreManifest(parsedManifest) {
19
-
20
- if (Array.isArray(parsedManifest.signers)) {
21
- parsedManifest.signers = parsedManifest.signers.map(signer => {
22
- if(signer.namespace && signer.namespace.data &&signer.publicKey && signer.publicKey.data){
23
- return {
24
- ...signer,
25
- namespace: Buffer.from(signer.namespace.data),
26
- publicKey: Buffer.from(signer.publicKey.data),
27
- }
28
- } else {
29
- return signer;
30
- }
31
- });
32
- }
33
-
34
- return parsedManifest;
35
- }
36
-
37
- // To improve - could be done in better approach (simplify)
38
- export function restoreHash(parsedPreTx) {
39
- const reconstructedContentHash = createHash('sha256')
40
- .update(JSON.stringify(parsedPreTx.ch))
41
- .digest('hex');
42
-
43
- const reconstructedTxHash = createHash('sha256')
44
- .update(
45
- parsedPreTx.w + '-' +
46
- parsedPreTx.i + '-' +
47
- parsedPreTx.ipk + '-' +
48
- reconstructedContentHash + '-' +
49
- parsedPreTx.in
50
- )
51
- .digest('hex');
52
-
53
- const finalReconstructedTxHash = createHash('sha256')
54
- .update(reconstructedTxHash)
55
- .digest('hex');
56
- return finalReconstructedTxHash;
57
- }
58
-
59
- export async function verifyDag(autoBaseInsance) {
60
- try {
61
- console.log('--- DAG Monitoring ---');
62
- const dagView = await autoBaseInsance.view.core.treeHash();
63
- const lengthdagView = autoBaseInsance.view.core.length;
64
- const dagSystem = await autoBaseInsance.system.core.treeHash();
65
- const lengthdagSystem = autoBaseInsance.system.core.length;
66
- console.log('this.base.view.core.signedLength:', autoBaseInsance.view.core.signedLength);
67
- console.log("this.base.signedLength", autoBaseInsance.signedLength);
68
- console.log("this.base.linearizer.indexers.length", autoBaseInsance.linearizer.indexers.length);
69
- console.log("this.base.indexedLength", autoBaseInsance.indexedLength);
70
- console.log(`base.key/writingKey: ${autoBaseInsance.key.toString('hex')}`);
71
-
72
- console.log(`VIEW Dag: ${dagView.toString('hex')} (length: ${lengthdagView})`);
73
- console.log(`SYSTEM Dag: ${dagSystem.toString('hex')} (length: ${lengthdagSystem})`);
74
-
75
- } catch (error) {
76
- console.error('Error during DAG monitoring:', error.message);
18
+ export async function addWriter(input, peer){
19
+ const splitted = input.split(' ');
20
+ if(splitted[0] === '/add_writer'){
21
+ await peer.base.append({ type: 'addWriter', key: splitted[splitted.length - 1] });
22
+ } else if(splitted[0] === '/add_writer2') {
23
+ await peer.base.append({ type: 'addWriter2', key: splitted[splitted.length - 1] });
77
24
  }
78
- }
79
-
80
- export async function sleep(ms) {
81
- return new Promise(resolve => setTimeout(resolve, ms));
82
25
  }
package/src/index.js CHANGED
@@ -5,20 +5,14 @@ import ReadyResource from 'ready-resource';
5
5
  import b4a from 'b4a';
6
6
  import Hyperbee from 'hyperbee';
7
7
  import readline from 'readline';
8
- import { sanitizeTransaction, restoreManifest, sleep, restoreHash ,verifyDag } from './functions.js';
8
+ import crypto from 'hypercore-crypto';
9
+ import { sanitizeTransaction, addWriter } from './functions.js';
9
10
  import w from 'protomux-wakeup';
11
+ import PeerWallet from "trac-wallet"
12
+ import fs from 'node:fs';
10
13
  import Corestore from 'corestore';
11
- import verifier from 'hypercore/lib/verifier.js';
12
- import WriterManager from './writerManager.js';
13
- import PeerWallet from "trac-wallet"; // TODO: Decide if this should be used here directly or inputed as an option
14
-
15
-
16
- const { manifestHash, createManifest } = verifier;
17
14
 
18
15
  const wakeup = new w();
19
- //TODO: change isValid to isIndexer
20
- //TODO: How about nonce if edDSA is deterministic?
21
- //TODO: CHECK IF TX HASH IS ALREDY IN BASE BEFORE VALIDATING IT TO DON'T OVERWRITE tx/writerPubKey. Also we need to validate this case where the 2 nodes send the same hash.
22
16
 
23
17
  export class MainSettlementBus extends ReadyResource {
24
18
 
@@ -32,27 +26,25 @@ export class MainSettlementBus extends ReadyResource {
32
26
  this.tx_pool = [];
33
27
  this.enable_txchannel = typeof options.enable_txchannel !== "undefined" && options.enable_txchannel === false ? false : true;
34
28
  this.enable_wallet = typeof options.enable_wallet !== "undefined" && options.enable_wallet === false ? false : true;
35
- this.isVerifyOnly = typeof options.isVerifyOnly !== "undefined" && options.isVerifyOnly === true ? true : false;
36
29
  this.base = null;
30
+ this.key = null;
37
31
  this.channel = options.channel || null;
38
32
  this.connectedNodes = 1;
39
33
  this.replicate = options.replicate !== false;
40
- this.writingKey = null;
34
+ this.writerLocalKey = null;
41
35
  this.isStreaming = false;
42
36
  this.bootstrap = options.bootstrap || null;
43
37
  this.opts = options;
38
+ this.connectedPeers = new Set();
44
39
  this.bee = null;
45
-
46
- // TODO: Decide if this is better placed in the _open method instead of here
47
- this.wallet = new PeerWallet({ isVerifyOnly: this.isVerifyOnly });
40
+ this.wallet = new PeerWallet(options);
48
41
 
49
42
  this.pool();
50
43
  this.msbListener();
51
44
  this._boot();
52
45
  this.ready().catch(noop);
53
-
54
46
  }
55
- //TODO: Move apply to the separate file
47
+
56
48
  _boot() {
57
49
  const _this = this;
58
50
  this.base = new Autobase(this.store, this.bootstrap, {
@@ -64,8 +56,6 @@ export class MainSettlementBus extends ReadyResource {
64
56
  keyEncoding: 'utf-8',
65
57
  valueEncoding: 'json'
66
58
  })
67
- _this.keysView = _this.bee.sub('pubKeys');
68
-
69
59
  return _this.bee;
70
60
  },
71
61
 
@@ -74,142 +64,25 @@ export class MainSettlementBus extends ReadyResource {
74
64
  for (const node of nodes) {
75
65
  const op = node.value;
76
66
  const postTx = op.value;
77
-
78
- // UNDER NO CIRCUMSTANCE DO THINGS LIKE THIS IN APPLY!
79
-
80
- if (!op || !op.type || !op.key || !op.value) {
81
- continue;
82
- }
83
-
84
- // WRITING & INDEXING
85
67
  if (op.type === 'tx') {
86
68
  if (null === await view.get(op.key) &&
87
- restoreHash(postTx) !== postTx.tx &&
88
69
  sanitizeTransaction(postTx) &&
89
70
  postTx.op === 'post-tx' &&
90
- this.wallet.verify(Buffer.from(postTx.is, 'hex'), Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.ipk, 'hex')) &&// sender verification
91
- this.wallet.verify(Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.wp, 'hex')) &&// writer verification
71
+ crypto.verify(Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.is, 'hex'), Buffer.from(postTx.ipk, 'hex')) &&// sender verification
72
+ crypto.verify(Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.wp, 'hex')) &&// writer verification
92
73
  Buffer.byteLength(JSON.stringify(postTx)) <= 4096
93
74
  ) {
94
75
  await view.put(op.key, op.value);
95
- console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
76
+ console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
96
77
  }
97
78
  } else if (op.type === 'addWriter') {
98
- //TODO: it can be optimalized by adding variables to don't call Buffer.from multiple times.
99
- //TODO: SANITIZE INCOMPING PROPOSAL
100
- if (node.from.key.toString('hex') === this.bootstrap) {
101
- const message = Buffer.concat([
102
- Buffer.from(JSON.stringify(op.value.hpm)),
103
- Buffer.from(op.value.wk, 'hex'),
104
- Buffer.from(op.key, 'hex')
105
- //TODO: ADD THE NONCE?
106
- ]);
107
-
108
- const pop1Valid = this.wallet.verify(op.value.pop1, message, Buffer.from(op.value.hpm.signers[0].publicKey));
109
- const pop2Valid = this.wallet.verify(op.value.pop2, message, op.key);
110
-
111
-
112
- const restoredManifest = restoreManifest(op.value.hpm); //temporary workaround
113
- if (pop1Valid && pop2Valid && manifestHash(createManifest(restoredManifest)).toString('hex') === op.value.wk) {
114
-
115
- const writerEntry = this.base.view.get(op.key);
116
- if (writerEntry === null || !writerEntry.isValid) {
117
- await base.addWriter(b4a.from(op.value.wk, 'hex'), { isIndexer: false })
118
-
119
- await view.put(op.key, {
120
- wk: op.value.wk,
121
- hpm: op.value.hpm,
122
- pop1: op.value.pop1, // TODO: observation this is really necessary to store pops? IF NOT DELETE IT!
123
- pop2: op.value.pop2,
124
- isValid: true,
125
- isIndexer: false
126
- //TODO: ADD NONCE?
127
- });
128
- console.log(`Writer added: ${op.value.wk}`);
129
- }
130
- }
131
- }
132
- } else if (op.type === 'removeWriter') {
133
- //TODO: it can be optimalized by adding variables to don't call Buffer.from multiple times. And other operations
134
- //TODO: SANITIZE INCOMPING PROPOSAL
135
- if (node.from.key.toString('hex') === this.bootstrap) {
136
- const publicKey = Buffer.from(op.key, 'hex');
137
- const message = Buffer.concat([
138
- publicKey
139
- //TODO: ADD NONCE ?
140
- ]);
141
-
142
- const popIsValid = this.wallet.verify(op.value.pop, message, publicKey);
143
- if (popIsValid) {
144
- const writerEntry = await _this.base.view.get(op.key)
145
- if (writerEntry !== null && writerEntry.value.isValid ) {
146
- await base.removeWriter(Buffer.from(writerEntry.value.wk, 'hex'));
147
- writerEntry.value.isValid = false;
148
- if (writerEntry.value.isIndexer === true) {
149
- writerEntry.value.isIndexer = false;
150
- }
151
- await view.put(op.key, writerEntry.value);
152
- console.log(`Writer removed: ${writerEntry.value.wk}`);
153
- }
154
-
155
- }
156
- }
157
- } else if (op.type === 'initBootstrap') {
158
- // this operation initializes the bootstrap skp to grant this public key the owner status.
159
- //TODO: ADD MORE SANITIZATION. THIS IS STILL JS.
160
- //TODO: HANDLE ERRORS?
161
- //TODO: it can be optimalized by adding variables to don't call Buffer.from multiple times.
162
- if (node.from.key.toString('hex') === this.bootstrap) {
163
- const message = Buffer.concat([
164
- Buffer.from(JSON.stringify(op.value.hpm)),
165
- Buffer.from(op.value.wk, 'hex'),
166
- Buffer.from(op.value.skp, 'hex')
167
- //here should be nonce anyway in the future - generated randomly from the huge space.
168
- ]);
169
-
170
- const pop1Valid = this.wallet.verify(op.value.pop1, message, Buffer.from(op.value.hpm.signers[0].publicKey));
171
- const pop2Valid = this.wallet.verify(op.value.pop2, message, Buffer.from(op.value.skp, 'hex'));
172
- const restoredManifest = restoreManifest(op.value.hpm); //temporary workaround
173
-
174
- if (pop1Valid && pop2Valid && manifestHash(createManifest(restoredManifest)).toString('hex') === this.bootstrap) {
175
- await view.put(op.key, op.value);
176
- }
177
- }
178
- } else if (op.type === 'addIndexer') {
179
- if (node.from.key.toString('hex') === _this.bootstrap) {
180
- //Simplify signature
181
- const message = Buffer.concat([
182
- Buffer.from(op.value.ptpk, 'hex'),
183
- Buffer.from(op.value.pwk, 'hex')]
184
- )
185
- const popValid = _this.wallet.verify(op.value.pop, message, op.key);
186
- const writerEntry = await _this.base.view.get(op.value.ptpk);
187
- if (popValid && writerEntry !== null && writerEntry.value.isValid === true && writerEntry.value.wk === op.value.pwk && writerEntry.value.isIndexer === false) {
188
- await base.removeWriter(Buffer.from(writerEntry.value.wk, 'hex'));
189
- await base.addWriter(b4a.from(writerEntry.value.wk, 'hex'), { indexer: true })
190
- writerEntry.value.isIndexer = true;
191
- await view.put(op.value.ptpk, writerEntry.value);
192
- console.log(`${op.value.ptpk}:${op.value.pwk} writer became indexer`);
193
- }
194
- }
195
- } else if (op.type === 'removeIndexer') {
196
- if (node.from.key.toString('hex') === _this.bootstrap) {
197
- //Simplify signature
198
- const message = Buffer.concat([
199
- Buffer.from(op.value.ptpk, 'hex'),
200
- Buffer.from(op.value.pwk, 'hex')]
201
- )
202
- const popValid = _this.wallet.verify(op.value.pop, message, op.key);
203
- const writerEntry = await _this.base.view.get(op.value.ptpk);
204
-
205
- if (popValid && writerEntry !== null && writerEntry.value.isValid === true && writerEntry.value.wk === op.value.pwk && writerEntry.value.isIndexer === true) {
206
- await base.removeWriter(Buffer.from(writerEntry.value.wk, 'hex'));
207
- await base.addWriter(b4a.from(writerEntry.value.wk, 'hex'), { indexer: false })
208
- writerEntry.value.isIndexer = false;
209
- await view.put(op.value.ptpk, writerEntry.value);
210
- console.log(`Writer ${op.value.ptpk}:${op.value.pwk} is not longer indexer`);
211
- }
212
- }
79
+ const writerKey = b4a.from(op.key, 'hex');
80
+ await base.addWriter(writerKey);
81
+ console.log(`Writer added: ${op.key}`);
82
+ } else if (op.type === 'addWriter2') {
83
+ const writerKey = b4a.from(op.key, 'hex');
84
+ await base.addWriter(writerKey, { isIndexer : false });
85
+ console.log(`Writer added: ${op.key} non-indexer`);
213
86
  }
214
87
  }
215
88
  }
@@ -219,23 +92,17 @@ export class MainSettlementBus extends ReadyResource {
219
92
 
220
93
  async _open() {
221
94
  await this.base.ready();
222
- if (this.enable_wallet && !this.isVerifyOnly) {
95
+ if(this.enable_wallet){
223
96
  await this.wallet.initKeyPair(this.KEY_PAIR_PATH);
224
97
  }
225
-
226
- this.writingKey = b4a.toString(this.base.local.key, 'hex');
227
-
98
+ console.log('View Length:', this.base.view.core.length);
99
+ console.log('View Signed Length:', this.base.view.core.signedLength);
100
+ console.log('MSB Key:', Buffer(this.base.view.core.key).toString('hex'));
101
+ this.writerLocalKey = b4a.toString(this.base.local.key, 'hex');
228
102
  if (this.replicate) await this._replicate();
229
103
  if (this.enable_txchannel) {
230
104
  await this.txChannel();
231
105
  }
232
- this.writerManager = new WriterManager(this);
233
-
234
- console.log('View Length:', this.base.view.core.length);
235
- console.log('View Signed Length:', this.base.view.core.signedLength);
236
- console.log('MSB Key:', Buffer(this.base.view.core.key).toString('hex'));
237
- console.log(`isWritable? ${this.base.writable}`);
238
- console.log(`isIndexer: ${this.base.isIndexer}`);
239
106
  }
240
107
 
241
108
  async close() {
@@ -249,19 +116,23 @@ export class MainSettlementBus extends ReadyResource {
249
116
  this.tx_swarm = new Hyperswarm({ maxPeers: 1024, maxParallel: 512, maxServerConnections: 256 });
250
117
  this.tx_swarm.on('connection', async (connection, peerInfo) => {
251
118
  const _this = this;
119
+ const peerName = b4a.toString(connection.remotePublicKey, 'hex');
120
+ this.connectedPeers.add(peerName);
121
+ this.connectedNodes++;
252
122
 
253
123
  connection.on('close', () => {
124
+ this.connectedNodes--;
125
+ this.connectedPeers.delete(peerName);
254
126
  });
255
127
 
256
128
  connection.on('error', (error) => { });
257
129
 
258
130
  connection.on('data', async (msg) => {
259
131
 
260
- // indexers are NOT supposed to validate transactions!
261
- if (_this.base.isIndexer) return;
132
+ if(_this.base.isIndexer) return;
262
133
 
263
134
  // TODO: decide if a tx rejection should be responded with
264
- if (_this.tx_pool.length >= 1000) {
135
+ if(_this.tx_pool.length >= 1000) {
265
136
  console.log('pool full');
266
137
  return
267
138
  }
@@ -269,17 +140,16 @@ export class MainSettlementBus extends ReadyResource {
269
140
  if(Buffer.byteLength(msg) > 3072) return;
270
141
 
271
142
  try {
143
+
272
144
  const parsedPreTx = JSON.parse(msg);
273
145
 
274
146
  if (sanitizeTransaction(parsedPreTx) &&
275
147
  parsedPreTx.op === 'pre-tx' &&
276
- restoreHash(parsedPreTx) !== parsedPreTx.tx &&
277
- this.wallet.verify(Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.tx, 'utf-8'), Buffer.from(parsedPreTx.ipk, 'hex')) &&
278
- parsedPreTx.w === _this.writingKey &&
148
+ crypto.verify(Buffer.from(parsedPreTx.tx, 'utf-8'), Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.ipk, 'hex')) &&
149
+ parsedPreTx.w === _this.writerLocalKey &&
279
150
  null === await _this.base.view.get(parsedPreTx.tx)
280
151
  ) {
281
- const signature = this.wallet.sign(Buffer.from(parsedPreTx.tx, 'utf-8'));
282
-
152
+ const signature = crypto.sign(Buffer.from(parsedPreTx.tx, 'utf-8'), this.wallet.secretKey);
283
153
  const append_tx = {
284
154
  op: 'post-tx',
285
155
  tx: parsedPreTx.tx,
@@ -289,10 +159,10 @@ export class MainSettlementBus extends ReadyResource {
289
159
  ipk: parsedPreTx.ipk,
290
160
  ch: parsedPreTx.ch,
291
161
  in: parsedPreTx.in,
292
- ws: JSON.parse(JSON.stringify(signature)),
293
- wp: JSON.parse(JSON.stringify(this.wallet.publicKey)),
162
+ ws: signature.toString('hex'),
163
+ wp: this.wallet.publicKey,
294
164
  };
295
- _this.tx_pool.push({ tx: parsedPreTx.tx, append_tx: append_tx });
165
+ _this.tx_pool.push({ tx: parsedPreTx.tx, append_tx : append_tx });
296
166
  }
297
167
  } catch (e) {
298
168
  console.log(e)
@@ -306,40 +176,44 @@ export class MainSettlementBus extends ReadyResource {
306
176
  console.log('Joined MSB TX channel');
307
177
  }
308
178
 
309
- async pool() {
310
- while (true) {
311
- if (this.tx_pool.length > 0) {
179
+ async pool(){
180
+ while(true){
181
+ if(this.tx_pool.length > 0){
312
182
  const length = this.tx_pool.length;
313
- for (let i = 0; i < length; i++) {
183
+ for(let i = 0; i < length; i++){
314
184
  await this.base.append({ type: 'tx', key: this.tx_pool[i].tx, value: this.tx_pool[i].append_tx });
315
- await sleep(5);
185
+ await this.sleep(5);
316
186
  }
317
187
  this.tx_pool.splice(0, length);
318
188
  }
319
- await sleep(10);
189
+ await this.sleep(10);
320
190
  }
321
191
  }
322
192
 
193
+ async sleep(ms) {
194
+ return new Promise(resolve => setTimeout(resolve, ms));
195
+ }
196
+
323
197
  async _replicate() {
324
198
  if (!this.swarm) {
325
- const keyPair = this.base.local.keyPair //await this.store.createKeyPair('hyperswarm');
199
+ const keyPair = await this.store.createKeyPair('hyperswarm');
326
200
  this.swarm = new Hyperswarm({ keyPair, maxPeers: 1024, maxParallel: 512, maxServerConnections: 256 });
327
201
 
328
202
  console.log(`Channel: ${this.channel}`);
329
- console.log(`Writer key: ${this.writingKey}`)
330
-
203
+ console.log(`Writer key: ${this.writerLocalKey}`)
204
+ console.log(`isIndexer: ${this.base.isIndexer}`);
331
205
  this.swarm.on('connection', async (connection, peerInfo) => {
206
+ const peerName = b4a.toString(connection.remotePublicKey, 'hex');
207
+ this.connectedPeers.add(peerName);
332
208
  wakeup.addStream(connection);
333
209
  this.store.replicate(connection);
334
-
210
+ this.connectedNodes++;
335
211
 
336
212
  connection.on('close', () => {
213
+ this.connectedNodes--;
214
+ this.connectedPeers.delete(peerName);
337
215
  });
338
216
 
339
- connection.on('data', async data => {
340
- await WriterManager.handleIncomingWriterEvent(this, data);
341
- })
342
-
343
217
  connection.on('error', (error) => { });
344
218
 
345
219
  if (!this.isStreaming) {
@@ -362,6 +236,30 @@ export class MainSettlementBus extends ReadyResource {
362
236
  });
363
237
  }
364
238
 
239
+ async verifyDag() {
240
+ try {
241
+ console.log('--- DAG Monitoring ---');
242
+ const dagView = await this.base.view.core.treeHash();
243
+ const lengthdagView = this.base.view.core.length;
244
+ const dagSystem = await this.base.system.core.treeHash();
245
+ const lengthdagSystem = this.base.system.core.length;
246
+ console.log('this.base.view.core.signedLength:', this.base.view.core.signedLength);
247
+ console.log("this.base.signedLength", this.base.signedLength);
248
+ console.log("this.base.linearizer.indexers.length", this.base.linearizer.indexers.length);
249
+ console.log("this.base.indexedLength", this.base.indexedLength);
250
+ //console.log("this.base.system.core", this.base.system.core);
251
+ console.log(`writerLocalKey: ${this.writerLocalKey}`);
252
+ console.log(`base.key: ${this.base.key.toString('hex')}`);
253
+ console.log('discoveryKey:', b4a.toString(this.base.discoveryKey, 'hex'));
254
+
255
+ console.log(`VIEW Dag: ${dagView.toString('hex')} (length: ${lengthdagView})`);
256
+ console.log(`SYSTEM Dag: ${dagSystem.toString('hex')} (length: ${lengthdagSystem})`);
257
+
258
+ } catch (error) {
259
+ console.error('Error during DAG monitoring:', error.message);
260
+ }
261
+ }
262
+
365
263
  async interactiveMode() {
366
264
  const rl = readline.createInterface({
367
265
  input: process.stdin,
@@ -369,43 +267,66 @@ export class MainSettlementBus extends ReadyResource {
369
267
  });
370
268
 
371
269
  console.log('MSB started. Available commands:');
372
- console.log('- /addMe: send request to admin to become a writer node in the TRAC Network');
373
- console.log('- /removeMe: send request to admin to remove writer node from the TRAC Network');
374
- console.log('- /addIndexer <TracPublicKey> <WritingKey> (Admin only): enter a public key and writing key to make node as Indexer. Node have to be a writer already. ');
375
- console.log('- /removeIndexer <TracPublicKey> <WritingKey> (Admin only): enter a public key and writing key to take off Indexer role. Node have to be a writer already');
270
+ console.log('- /add_writer: enter a peer writer key as argument to get included as writer.');
271
+ console.log('- /add_writer2: enter a peer writer key as argument to get included as non-indexing writer.');
376
272
  console.log('- /dag: check system properties such as writer key, DAG, etc.');
377
273
  console.log('- /exit: Exit the program');
378
274
 
379
275
  rl.on('line', async (input) => {
380
276
  switch (input) {
381
277
  case '/dag':
382
- await verifyDag(this.base);
278
+ await this.verifyDag();
383
279
  break;
384
280
  case '/exit':
385
281
  console.log('Exiting...');
386
282
  rl.close();
387
283
  await this.close();
388
284
  process.exit(0);
389
- case '/addMe':
390
- await this.writerManager.addMe();
391
- break;
392
- case '/removeMe':
393
- await this.writerManager.removeMe();
394
285
  break;
395
286
  default:
396
- if (input.startsWith('/addIndexer')) {
397
- const splitted = input.split(' ');
398
- this.writerManager.addIndexer(splitted[1], splitted[2]);
399
-
400
- } else if (input.startsWith('/removeIndexer')) {
401
- const splitted = input.split(' ');
402
- this.writerManager.removeIndexer(splitted[1], splitted[2]);
287
+ if (input.startsWith('/add_writer')) {
288
+ await addWriter(input, this);
403
289
  }
404
290
  }
405
291
  rl.prompt();
406
292
  });
293
+
407
294
  rl.prompt();
408
295
  }
296
+
297
+ async #getMnemonicInteractiveMode() {
298
+ const rl = readline.createInterface({
299
+ input: process.stdin,
300
+ output: process.stdout
301
+ });
302
+
303
+ const question = (query) => {
304
+ return new Promise(resolve => {
305
+ rl.question(query, resolve);
306
+ });
307
+ }
308
+
309
+ let mnemonic;
310
+ let choice = '';
311
+ while (!choice.trim()) {
312
+ choice = await question("[1]. Generate new mnemonic phrase\n[2]. Restore keypair from backed up mnemonic phrase\nYour choice (1/2): ");
313
+ switch (choice) {
314
+ case '1':
315
+ mnemonic = undefined
316
+ break;
317
+ case '2':
318
+ const mnemonicInput = await question("Enter your mnemonic phrase: ");
319
+ mnemonic = this.wallet.sanitizeMnemonic(mnemonicInput);
320
+ break;
321
+ default:
322
+ console.log("Invalid choice. Please select again");
323
+ choice = '';
324
+ break;
325
+ }
326
+ }
327
+ rl.close();
328
+ return mnemonic;
329
+ }
409
330
  }
410
331
 
411
332
  function noop() { }