trac-msb 0.0.13 → 0.0.14

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 +157 -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.14",
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
 
@@ -26,33 +20,32 @@ export class MainSettlementBus extends ReadyResource {
26
20
  super();
27
21
  this.STORES_DIRECTORY = options.stores_directory;
28
22
  this.KEY_PAIR_PATH = `${this.STORES_DIRECTORY}${options.store_name}/db/keypair.json`
23
+ this.signingKeyPair = null;
29
24
  this.store = new Corestore(this.STORES_DIRECTORY + options.store_name);
30
25
  this.swarm = null;
31
26
  this.tx = options.tx || null;
32
27
  this.tx_pool = [];
33
28
  this.enable_txchannel = typeof options.enable_txchannel !== "undefined" && options.enable_txchannel === false ? false : true;
34
29
  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
30
  this.base = null;
31
+ this.key = null;
37
32
  this.channel = options.channel || null;
38
33
  this.connectedNodes = 1;
39
34
  this.replicate = options.replicate !== false;
40
- this.writingKey = null;
35
+ this.writerLocalKey = null;
41
36
  this.isStreaming = false;
42
37
  this.bootstrap = options.bootstrap || null;
43
38
  this.opts = options;
39
+ this.connectedPeers = new Set();
44
40
  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 });
41
+ this.wallet = new PeerWallet(options);
48
42
 
49
43
  this.pool();
50
44
  this.msbListener();
51
45
  this._boot();
52
46
  this.ready().catch(noop);
53
-
54
47
  }
55
- //TODO: Move apply to the separate file
48
+
56
49
  _boot() {
57
50
  const _this = this;
58
51
  this.base = new Autobase(this.store, this.bootstrap, {
@@ -64,8 +57,6 @@ export class MainSettlementBus extends ReadyResource {
64
57
  keyEncoding: 'utf-8',
65
58
  valueEncoding: 'json'
66
59
  })
67
- _this.keysView = _this.bee.sub('pubKeys');
68
-
69
60
  return _this.bee;
70
61
  },
71
62
 
@@ -74,142 +65,25 @@ export class MainSettlementBus extends ReadyResource {
74
65
  for (const node of nodes) {
75
66
  const op = node.value;
76
67
  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
68
  if (op.type === 'tx') {
86
69
  if (null === await view.get(op.key) &&
87
- restoreHash(postTx) !== postTx.tx &&
88
70
  sanitizeTransaction(postTx) &&
89
71
  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
72
+ crypto.verify(Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.is, 'hex'), Buffer.from(postTx.ipk, 'hex')) &&// sender verification
73
+ crypto.verify(Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.wp, 'hex')) &&// writer verification
92
74
  Buffer.byteLength(JSON.stringify(postTx)) <= 4096
93
75
  ) {
94
76
  await view.put(op.key, op.value);
95
- console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
77
+ console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
96
78
  }
97
79
  } 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
- }
80
+ const writerKey = b4a.from(op.key, 'hex');
81
+ await base.addWriter(writerKey);
82
+ console.log(`Writer added: ${op.key}`);
83
+ } else if (op.type === 'addWriter2') {
84
+ const writerKey = b4a.from(op.key, 'hex');
85
+ await base.addWriter(writerKey, { isIndexer : false });
86
+ console.log(`Writer added: ${op.key} non-indexer`);
213
87
  }
214
88
  }
215
89
  }
@@ -219,23 +93,17 @@ export class MainSettlementBus extends ReadyResource {
219
93
 
220
94
  async _open() {
221
95
  await this.base.ready();
222
- if (this.enable_wallet && !this.isVerifyOnly) {
96
+ if(this.enable_wallet){
223
97
  await this.wallet.initKeyPair(this.KEY_PAIR_PATH);
224
98
  }
225
-
226
- this.writingKey = b4a.toString(this.base.local.key, 'hex');
227
-
99
+ console.log('View Length:', this.base.view.core.length);
100
+ console.log('View Signed Length:', this.base.view.core.signedLength);
101
+ console.log('MSB Key:', Buffer(this.base.view.core.key).toString('hex'));
102
+ this.writerLocalKey = b4a.toString(this.base.local.key, 'hex');
228
103
  if (this.replicate) await this._replicate();
229
104
  if (this.enable_txchannel) {
230
105
  await this.txChannel();
231
106
  }
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
107
  }
240
108
 
241
109
  async close() {
@@ -249,19 +117,23 @@ export class MainSettlementBus extends ReadyResource {
249
117
  this.tx_swarm = new Hyperswarm({ maxPeers: 1024, maxParallel: 512, maxServerConnections: 256 });
250
118
  this.tx_swarm.on('connection', async (connection, peerInfo) => {
251
119
  const _this = this;
120
+ const peerName = b4a.toString(connection.remotePublicKey, 'hex');
121
+ this.connectedPeers.add(peerName);
122
+ this.connectedNodes++;
252
123
 
253
124
  connection.on('close', () => {
125
+ this.connectedNodes--;
126
+ this.connectedPeers.delete(peerName);
254
127
  });
255
128
 
256
129
  connection.on('error', (error) => { });
257
130
 
258
131
  connection.on('data', async (msg) => {
259
132
 
260
- // indexers are NOT supposed to validate transactions!
261
- if (_this.base.isIndexer) return;
133
+ if(_this.base.isIndexer) return;
262
134
 
263
135
  // TODO: decide if a tx rejection should be responded with
264
- if (_this.tx_pool.length >= 1000) {
136
+ if(_this.tx_pool.length >= 1000) {
265
137
  console.log('pool full');
266
138
  return
267
139
  }
@@ -269,17 +141,16 @@ export class MainSettlementBus extends ReadyResource {
269
141
  if(Buffer.byteLength(msg) > 3072) return;
270
142
 
271
143
  try {
144
+
272
145
  const parsedPreTx = JSON.parse(msg);
273
146
 
274
147
  if (sanitizeTransaction(parsedPreTx) &&
275
148
  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 &&
149
+ crypto.verify(Buffer.from(parsedPreTx.tx, 'utf-8'), Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.ipk, 'hex')) &&
150
+ parsedPreTx.w === _this.writerLocalKey &&
279
151
  null === await _this.base.view.get(parsedPreTx.tx)
280
152
  ) {
281
- const signature = this.wallet.sign(Buffer.from(parsedPreTx.tx, 'utf-8'));
282
-
153
+ const signature = crypto.sign(Buffer.from(parsedPreTx.tx, 'utf-8'), this.signingKeyPair.secretKey);
283
154
  const append_tx = {
284
155
  op: 'post-tx',
285
156
  tx: parsedPreTx.tx,
@@ -289,10 +160,10 @@ export class MainSettlementBus extends ReadyResource {
289
160
  ipk: parsedPreTx.ipk,
290
161
  ch: parsedPreTx.ch,
291
162
  in: parsedPreTx.in,
292
- ws: JSON.parse(JSON.stringify(signature)),
293
- wp: JSON.parse(JSON.stringify(this.wallet.publicKey)),
163
+ ws: signature.toString('hex'),
164
+ wp: this.signingKeyPair.publicKey.toString('hex'),
294
165
  };
295
- _this.tx_pool.push({ tx: parsedPreTx.tx, append_tx: append_tx });
166
+ _this.tx_pool.push({ tx: parsedPreTx.tx, append_tx : append_tx });
296
167
  }
297
168
  } catch (e) {
298
169
  console.log(e)
@@ -306,40 +177,44 @@ export class MainSettlementBus extends ReadyResource {
306
177
  console.log('Joined MSB TX channel');
307
178
  }
308
179
 
309
- async pool() {
310
- while (true) {
311
- if (this.tx_pool.length > 0) {
180
+ async pool(){
181
+ while(true){
182
+ if(this.tx_pool.length > 0){
312
183
  const length = this.tx_pool.length;
313
- for (let i = 0; i < length; i++) {
184
+ for(let i = 0; i < length; i++){
314
185
  await this.base.append({ type: 'tx', key: this.tx_pool[i].tx, value: this.tx_pool[i].append_tx });
315
- await sleep(5);
186
+ await this.sleep(5);
316
187
  }
317
188
  this.tx_pool.splice(0, length);
318
189
  }
319
- await sleep(10);
190
+ await this.sleep(10);
320
191
  }
321
192
  }
322
193
 
194
+ async sleep(ms) {
195
+ return new Promise(resolve => setTimeout(resolve, ms));
196
+ }
197
+
323
198
  async _replicate() {
324
199
  if (!this.swarm) {
325
- const keyPair = this.base.local.keyPair //await this.store.createKeyPair('hyperswarm');
200
+ const keyPair = await this.store.createKeyPair('hyperswarm');
326
201
  this.swarm = new Hyperswarm({ keyPair, maxPeers: 1024, maxParallel: 512, maxServerConnections: 256 });
327
202
 
328
203
  console.log(`Channel: ${this.channel}`);
329
- console.log(`Writer key: ${this.writingKey}`)
330
-
204
+ console.log(`Writer key: ${this.writerLocalKey}`)
205
+ console.log(`isIndexer: ${this.base.isIndexer}`);
331
206
  this.swarm.on('connection', async (connection, peerInfo) => {
207
+ const peerName = b4a.toString(connection.remotePublicKey, 'hex');
208
+ this.connectedPeers.add(peerName);
332
209
  wakeup.addStream(connection);
333
210
  this.store.replicate(connection);
334
-
211
+ this.connectedNodes++;
335
212
 
336
213
  connection.on('close', () => {
214
+ this.connectedNodes--;
215
+ this.connectedPeers.delete(peerName);
337
216
  });
338
217
 
339
- connection.on('data', async data => {
340
- await WriterManager.handleIncomingWriterEvent(this, data);
341
- })
342
-
343
218
  connection.on('error', (error) => { });
344
219
 
345
220
  if (!this.isStreaming) {
@@ -362,6 +237,30 @@ export class MainSettlementBus extends ReadyResource {
362
237
  });
363
238
  }
364
239
 
240
+ async verifyDag() {
241
+ try {
242
+ console.log('--- DAG Monitoring ---');
243
+ const dagView = await this.base.view.core.treeHash();
244
+ const lengthdagView = this.base.view.core.length;
245
+ const dagSystem = await this.base.system.core.treeHash();
246
+ const lengthdagSystem = this.base.system.core.length;
247
+ console.log('this.base.view.core.signedLength:', this.base.view.core.signedLength);
248
+ console.log("this.base.signedLength", this.base.signedLength);
249
+ console.log("this.base.linearizer.indexers.length", this.base.linearizer.indexers.length);
250
+ console.log("this.base.indexedLength", this.base.indexedLength);
251
+ //console.log("this.base.system.core", this.base.system.core);
252
+ console.log(`writerLocalKey: ${this.writerLocalKey}`);
253
+ console.log(`base.key: ${this.base.key.toString('hex')}`);
254
+ console.log('discoveryKey:', b4a.toString(this.base.discoveryKey, 'hex'));
255
+
256
+ console.log(`VIEW Dag: ${dagView.toString('hex')} (length: ${lengthdagView})`);
257
+ console.log(`SYSTEM Dag: ${dagSystem.toString('hex')} (length: ${lengthdagSystem})`);
258
+
259
+ } catch (error) {
260
+ console.error('Error during DAG monitoring:', error.message);
261
+ }
262
+ }
263
+
365
264
  async interactiveMode() {
366
265
  const rl = readline.createInterface({
367
266
  input: process.stdin,
@@ -369,43 +268,102 @@ export class MainSettlementBus extends ReadyResource {
369
268
  });
370
269
 
371
270
  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');
271
+ console.log('- /add_writer: enter a peer writer key as argument to get included as writer.');
272
+ console.log('- /add_writer2: enter a peer writer key as argument to get included as non-indexing writer.');
376
273
  console.log('- /dag: check system properties such as writer key, DAG, etc.');
377
274
  console.log('- /exit: Exit the program');
378
275
 
379
276
  rl.on('line', async (input) => {
380
277
  switch (input) {
381
278
  case '/dag':
382
- await verifyDag(this.base);
279
+ await this.verifyDag();
383
280
  break;
384
281
  case '/exit':
385
282
  console.log('Exiting...');
386
283
  rl.close();
387
284
  await this.close();
388
285
  process.exit(0);
389
- case '/addMe':
390
- await this.writerManager.addMe();
391
- break;
392
- case '/removeMe':
393
- await this.writerManager.removeMe();
394
286
  break;
395
287
  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]);
288
+ if (input.startsWith('/add_writer')) {
289
+ await addWriter(input, this);
403
290
  }
404
291
  }
405
292
  rl.prompt();
406
293
  });
294
+
407
295
  rl.prompt();
408
296
  }
297
+
298
+ async #getMnemonicInteractiveMode() {
299
+ const rl = readline.createInterface({
300
+ input: process.stdin,
301
+ output: process.stdout
302
+ });
303
+
304
+ const question = (query) => {
305
+ return new Promise(resolve => {
306
+ rl.question(query, resolve);
307
+ });
308
+ }
309
+
310
+ let mnemonic;
311
+ let choice = '';
312
+ while (!choice.trim()) {
313
+ choice = await question("[1]. Generate new mnemonic phrase\n[2]. Restore keypair from backed up mnemonic phrase\nYour choice (1/2): ");
314
+ switch (choice) {
315
+ case '1':
316
+ mnemonic = undefined
317
+ break;
318
+ case '2':
319
+ const mnemonicInput = await question("Enter your mnemonic phrase: ");
320
+ mnemonic = this.wallet.sanitizeMnemonic(mnemonicInput);
321
+ break;
322
+ default:
323
+ console.log("Invalid choice. Please select again");
324
+ choice = '';
325
+ break;
326
+ }
327
+ }
328
+ rl.close();
329
+ return mnemonic;
330
+ }
331
+
332
+ async #initKeyPair() {
333
+ // TODO: User shouldn't be allowed to store it in unencrypted form. ASK for a password to encrypt it. ENCRYPT(HASH(PASSWORD,SALT),FILE)/DECRYPT(HASH(PASSWORD,SALT),ENCRYPTED_FILE)?
334
+ try {
335
+ // Check if the key file exists
336
+ if (fs.existsSync(this.KEY_PAIR_PATH)) {
337
+ const keyPair = JSON.parse(fs.readFileSync(this.KEY_PAIR_PATH));
338
+ this.signingKeyPair = {
339
+ publicKey: Buffer.from(keyPair.publicKey, 'hex'),
340
+ secretKey: Buffer.from(keyPair.secretKey, 'hex')
341
+ }
342
+ } else {
343
+ console.log("Key file was not found. How do you wish to proceed?");
344
+ const mnemonic = await this.#getMnemonicInteractiveMode();
345
+
346
+ const generatedSecrets = this.wallet.generateKeyPair(mnemonic);
347
+ const keyPair = {
348
+ publicKey: Buffer.from(generatedSecrets.publicKey).toString('hex'),
349
+ secretKey: Buffer.from(generatedSecrets.secretKey).toString('hex')
350
+ }
351
+
352
+ //TODO: ASK USER TO WRITE FIRST SECOND AND LAST WORD OR SOMETHING SIMILAR TO CONFIRM THEY HAVE WRITTEN IT DOWN
353
+ if (!mnemonic) console.log("This is your mnemonic:\n", generatedSecrets.mnemonic, "\nPlease back it up in a safe location")
354
+
355
+ fs.writeFileSync(this.KEY_PAIR_PATH, JSON.stringify(keyPair));
356
+ this.signingKeyPair = {
357
+ publicKey: generatedSecrets.publicKey,
358
+ secretKey: generatedSecrets.secretKey,
359
+ }
360
+
361
+ console.log("DEBUG: Key pair generated and stored in", this.KEY_PAIR_PATH);
362
+ }
363
+ } catch (err) {
364
+ console.error(err);
365
+ }
366
+ }
409
367
  }
410
368
 
411
369
  function noop() { }