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.
- package/_stores/n1/db/000071.blob +0 -0
- package/_stores/n1/db/000073.blob +0 -0
- package/_stores/n1/db/000085.blob +0 -0
- package/_stores/n1/db/000088.blob +0 -0
- package/_stores/n1/db/000089.sst +0 -0
- package/_stores/n1/db/000090.sst +0 -0
- package/_stores/n1/db/000092.blob +0 -0
- package/_stores/n1/db/000093.sst +0 -0
- package/_stores/n1/db/000162.blob +0 -0
- package/_stores/n1/db/000165.blob +0 -0
- package/_stores/n1/db/000175.blob +0 -0
- package/_stores/n1/db/000186.blob +0 -0
- package/_stores/n1/db/000189.blob +0 -0
- package/_stores/n1/db/000195.blob +0 -0
- package/_stores/n1/db/000210.blob +0 -0
- package/_stores/n1/db/000222.blob +0 -0
- package/_stores/n1/db/000225.blob +0 -0
- package/_stores/n1/db/000229.sst +0 -0
- package/_stores/n1/db/000230.sst +0 -0
- package/_stores/n1/db/000231.blob +0 -0
- package/_stores/n1/db/000232.sst +0 -0
- package/_stores/n1/db/000245.blob +0 -0
- package/_stores/n1/db/000250.log +0 -0
- package/_stores/n1/db/000252.blob +0 -0
- package/_stores/n1/db/000253.sst +0 -0
- package/_stores/n1/db/000254.sst +0 -0
- package/_stores/n1/db/CURRENT +1 -0
- package/_stores/n1/db/IDENTITY +1 -0
- package/_stores/n1/db/LOCK +0 -0
- package/_stores/n1/db/LOG +115 -0
- package/_stores/n1/db/LOG.old.1742183021576909 +0 -0
- package/_stores/n1/db/LOG.old.1742186169260958 +0 -0
- package/_stores/n1/db/LOG.old.1742356429622171 +0 -0
- package/_stores/n1/db/LOG.old.1742356454896144 +0 -0
- package/_stores/n1/db/LOG.old.1742356784525414 +0 -0
- package/_stores/n1/db/LOG.old.1742356872553496 +0 -0
- package/_stores/n1/db/LOG.old.1742356889597303 +0 -0
- package/_stores/n1/db/LOG.old.1742357459830241 +0 -0
- package/_stores/n1/db/LOG.old.1742357505153356 +0 -0
- package/_stores/n1/db/LOG.old.1742404971790711 +0 -0
- package/_stores/n1/db/LOG.old.1742419942002515 +0 -0
- package/_stores/n1/db/LOG.old.1742420819468818 +0 -0
- package/_stores/n1/db/LOG.old.1742421141667874 +0 -0
- package/_stores/n1/db/LOG.old.1742577491693110 +0 -0
- package/_stores/n1/db/LOG.old.1742589273002581 +0 -0
- package/_stores/n1/db/LOG.old.1742641251570901 +466 -0
- package/_stores/n1/db/LOG.old.1742641819650240 +115 -0
- package/_stores/n1/db/MANIFEST-000247 +0 -0
- package/_stores/n1/db/OPTIONS-000243 +0 -0
- package/_stores/n1/db/OPTIONS-000249 +0 -0
- package/_stores/n1/db/keypair.json +1 -0
- package/_stores/n2/db/000067.blob +0 -0
- package/_stores/n2/db/000073.blob +0 -0
- package/_stores/n2/db/000081.blob +0 -0
- package/_stores/n2/db/000088.blob +0 -0
- package/_stores/n2/db/000093.sst +0 -0
- package/_stores/n2/db/000094.blob +0 -0
- package/_stores/n2/db/000095.sst +0 -0
- package/_stores/n2/db/000096.sst +0 -0
- package/_stores/n2/db/000114.blob +0 -0
- package/_stores/n2/db/000117.blob +0 -0
- package/_stores/n2/db/000127.blob +0 -0
- package/_stores/n2/db/000138.blob +0 -0
- package/_stores/n2/db/000141.blob +0 -0
- package/_stores/n2/db/000150.blob +0 -0
- package/_stores/n2/db/000166.blob +0 -0
- package/_stores/n2/db/000175.blob +0 -0
- package/_stores/n2/db/000180.sst +0 -0
- package/_stores/n2/db/000196.blob +0 -0
- package/_stores/n2/db/000201.sst +0 -0
- package/_stores/n2/db/000202.sst +0 -0
- package/_stores/n2/db/000204.sst +0 -0
- package/_stores/n2/db/000205.sst +0 -0
- package/_stores/n2/db/000206.sst +0 -0
- package/_stores/n2/db/000207.sst +0 -0
- package/_stores/n2/db/000208.log +0 -0
- package/_stores/n2/db/000209.sst +0 -0
- package/_stores/n2/db/000210.blob +0 -0
- package/_stores/n2/db/CURRENT +0 -0
- package/_stores/n2/db/IDENTITY +0 -0
- package/_stores/n2/db/LOCK +0 -0
- package/_stores/n2/db/LOG +0 -0
- package/_stores/n2/db/LOG.old.1742186170827801 +0 -0
- package/_stores/n2/db/LOG.old.1742419970256241 +0 -0
- package/_stores/n2/db/LOG.old.1742420821296937 +0 -0
- package/_stores/n2/db/LOG.old.1742421143874068 +0 -0
- package/_stores/n2/db/LOG.old.1742577493694397 +0 -0
- package/_stores/n2/db/LOG.old.1742589275454624 +0 -0
- package/_stores/n2/db/MANIFEST-000198 +0 -0
- package/_stores/n2/db/OPTIONS-000194 +0 -0
- package/_stores/n2/db/OPTIONS-000200 +0 -0
- package/_stores/n2/db/keypair.json +1 -0
- package/_stores/n3/db/000067.blob +0 -0
- package/_stores/n3/db/000073.blob +0 -0
- package/_stores/n3/db/000081.blob +0 -0
- package/_stores/n3/db/000088.blob +0 -0
- package/_stores/n3/db/000093.sst +0 -0
- package/_stores/n3/db/000094.blob +0 -0
- package/_stores/n3/db/000095.sst +0 -0
- package/_stores/n3/db/000096.sst +0 -0
- package/_stores/n3/db/000114.blob +0 -0
- package/_stores/n3/db/000117.blob +0 -0
- package/_stores/n3/db/000127.blob +0 -0
- package/_stores/n3/db/000138.blob +0 -0
- package/_stores/n3/db/000141.blob +0 -0
- package/_stores/n3/db/000150.blob +0 -0
- package/_stores/n3/db/000166.blob +0 -0
- package/_stores/n3/db/000175.blob +0 -0
- package/_stores/n3/db/000180.sst +0 -0
- package/_stores/n3/db/000196.blob +0 -0
- package/_stores/n3/db/000201.sst +0 -0
- package/_stores/n3/db/000202.sst +0 -0
- package/_stores/n3/db/000204.sst +0 -0
- package/_stores/n3/db/000205.sst +0 -0
- package/_stores/n3/db/000206.sst +0 -0
- package/_stores/n3/db/000207.sst +0 -0
- package/_stores/n3/db/000208.log +0 -0
- package/_stores/n3/db/000209.sst +0 -0
- package/_stores/n3/db/000210.blob +0 -0
- package/_stores/n3/db/CURRENT +0 -0
- package/_stores/n3/db/IDENTITY +0 -0
- package/_stores/n3/db/LOCK +0 -0
- package/_stores/n3/db/LOG +0 -0
- package/_stores/n3/db/LOG.old.1742186172888124 +0 -0
- package/_stores/n3/db/LOG.old.1742420094609648 +0 -0
- package/_stores/n3/db/LOG.old.1742420822815851 +0 -0
- package/_stores/n3/db/LOG.old.1742421145506410 +0 -0
- package/_stores/n3/db/LOG.old.1742577495315796 +0 -0
- package/_stores/n3/db/LOG.old.1742589277258083 +0 -0
- package/_stores/n3/db/MANIFEST-000198 +0 -0
- package/_stores/n3/db/OPTIONS-000194 +0 -0
- package/_stores/n3/db/OPTIONS-000200 +0 -0
- package/_stores/n3/db/keypair.json +1 -0
- package/_stores/n4/db/000067.blob +0 -0
- package/_stores/n4/db/000074.blob +0 -0
- package/_stores/n4/db/000081.blob +0 -0
- package/_stores/n4/db/000088.blob +0 -0
- package/_stores/n4/db/000093.sst +0 -0
- package/_stores/n4/db/000094.blob +0 -0
- package/_stores/n4/db/000095.sst +0 -0
- package/_stores/n4/db/000096.sst +0 -0
- package/_stores/n4/db/000114.blob +0 -0
- package/_stores/n4/db/000117.blob +0 -0
- package/_stores/n4/db/000127.blob +0 -0
- package/_stores/n4/db/000138.blob +0 -0
- package/_stores/n4/db/000141.blob +0 -0
- package/_stores/n4/db/000150.blob +0 -0
- package/_stores/n4/db/000159.blob +0 -0
- package/_stores/n4/db/000166.blob +0 -0
- package/_stores/n4/db/000175.blob +0 -0
- package/_stores/n4/db/000180.sst +0 -0
- package/_stores/n4/db/000196.blob +0 -0
- package/_stores/n4/db/000201.sst +0 -0
- package/_stores/n4/db/000202.sst +0 -0
- package/_stores/n4/db/000204.sst +0 -0
- package/_stores/n4/db/000205.sst +0 -0
- package/_stores/n4/db/000206.sst +0 -0
- package/_stores/n4/db/000207.sst +0 -0
- package/_stores/n4/db/000208.log +0 -0
- package/_stores/n4/db/000209.sst +0 -0
- package/_stores/n4/db/000210.blob +0 -0
- package/_stores/n4/db/CURRENT +0 -0
- package/_stores/n4/db/IDENTITY +0 -0
- package/_stores/n4/db/LOCK +0 -0
- package/_stores/n4/db/LOG +0 -0
- package/_stores/n4/db/LOG.old.1742186174617449 +0 -0
- package/_stores/n4/db/LOG.old.1742420096536170 +0 -0
- package/_stores/n4/db/LOG.old.1742420824264952 +0 -0
- package/_stores/n4/db/LOG.old.1742421147129074 +0 -0
- package/_stores/n4/db/LOG.old.1742577500353714 +0 -0
- package/_stores/n4/db/LOG.old.1742589279083454 +0 -0
- package/_stores/n4/db/MANIFEST-000198 +0 -0
- package/_stores/n4/db/OPTIONS-000194 +0 -0
- package/_stores/n4/db/OPTIONS-000200 +0 -0
- package/_stores/n4/db/keypair.json +0 -0
- package/_stores/n5/db/000067.blob +0 -0
- package/_stores/n5/db/000074.blob +0 -0
- package/_stores/n5/db/000081.blob +0 -0
- package/_stores/n5/db/000088.blob +0 -0
- package/_stores/n5/db/000093.sst +0 -0
- package/_stores/n5/db/000094.blob +0 -0
- package/_stores/n5/db/000095.sst +0 -0
- package/_stores/n5/db/000096.sst +0 -0
- package/_stores/n5/db/000114.blob +0 -0
- package/_stores/n5/db/000117.blob +0 -0
- package/_stores/n5/db/000127.blob +0 -0
- package/_stores/n5/db/000138.blob +0 -0
- package/_stores/n5/db/000141.blob +0 -0
- package/_stores/n5/db/000150.blob +0 -0
- package/_stores/n5/db/000166.blob +0 -0
- package/_stores/n5/db/000175.blob +0 -0
- package/_stores/n5/db/000180.sst +0 -0
- package/_stores/n5/db/000196.blob +0 -0
- package/_stores/n5/db/000201.sst +0 -0
- package/_stores/n5/db/000202.sst +0 -0
- package/_stores/n5/db/000204.sst +0 -0
- package/_stores/n5/db/000205.sst +0 -0
- package/_stores/n5/db/000206.sst +0 -0
- package/_stores/n5/db/000207.sst +0 -0
- package/_stores/n5/db/000208.log +0 -0
- package/_stores/n5/db/000209.sst +0 -0
- package/_stores/n5/db/000210.blob +0 -0
- package/_stores/n5/db/CURRENT +0 -0
- package/_stores/n5/db/IDENTITY +0 -0
- package/_stores/n5/db/LOCK +0 -0
- package/_stores/n5/db/LOG +0 -0
- package/_stores/n5/db/LOG.old.1742186176624713 +0 -0
- package/_stores/n5/db/LOG.old.1742420098319634 +0 -0
- package/_stores/n5/db/LOG.old.1742420825849458 +0 -0
- package/_stores/n5/db/LOG.old.1742421148865382 +0 -0
- package/_stores/n5/db/LOG.old.1742577501880031 +0 -0
- package/_stores/n5/db/LOG.old.1742589281491031 +0 -0
- package/_stores/n5/db/MANIFEST-000198 +0 -0
- package/_stores/n5/db/OPTIONS-000194 +0 -0
- package/_stores/n5/db/OPTIONS-000200 +0 -0
- package/_stores/n5/db/keypair.json +0 -0
- package/_stores/n6/db/000074.blob +0 -0
- package/_stores/n6/db/000081.blob +0 -0
- package/_stores/n6/db/000088.blob +0 -0
- package/_stores/n6/db/000093.sst +0 -0
- package/_stores/n6/db/000094.blob +0 -0
- package/_stores/n6/db/000095.sst +0 -0
- package/_stores/n6/db/000096.sst +0 -0
- package/_stores/n6/db/000114.blob +0 -0
- package/_stores/n6/db/000117.blob +0 -0
- package/_stores/n6/db/000127.blob +0 -0
- package/_stores/n6/db/000138.blob +0 -0
- package/_stores/n6/db/000150.blob +0 -0
- package/_stores/n6/db/000159.blob +0 -0
- package/_stores/n6/db/000166.blob +0 -0
- package/_stores/n6/db/000175.blob +0 -0
- package/_stores/n6/db/000180.sst +0 -0
- package/_stores/n6/db/000196.blob +0 -0
- package/_stores/n6/db/000201.sst +0 -0
- package/_stores/n6/db/000202.sst +0 -0
- package/_stores/n6/db/000204.sst +0 -0
- package/_stores/n6/db/000205.sst +0 -0
- package/_stores/n6/db/000206.sst +0 -0
- package/_stores/n6/db/000207.sst +0 -0
- package/_stores/n6/db/000208.log +0 -0
- package/_stores/n6/db/000209.sst +0 -0
- package/_stores/n6/db/000210.blob +0 -0
- package/_stores/n6/db/CURRENT +0 -0
- package/_stores/n6/db/IDENTITY +0 -0
- package/_stores/n6/db/LOCK +0 -0
- package/_stores/n6/db/LOG +0 -0
- package/_stores/n6/db/LOG.old.1742186178370518 +0 -0
- package/_stores/n6/db/LOG.old.1742420099918640 +0 -0
- package/_stores/n6/db/LOG.old.1742420827341589 +0 -0
- package/_stores/n6/db/LOG.old.1742421150560152 +0 -0
- package/_stores/n6/db/LOG.old.1742577503396008 +0 -0
- package/_stores/n6/db/LOG.old.1742589283821852 +0 -0
- package/_stores/n6/db/MANIFEST-000198 +0 -0
- package/_stores/n6/db/OPTIONS-000194 +0 -0
- package/_stores/n6/db/OPTIONS-000200 +0 -0
- package/_stores/n6/db/keypair.json +0 -0
- package/_stores/n7/db/000074.blob +0 -0
- package/_stores/n7/db/000081.blob +0 -0
- package/_stores/n7/db/000088.blob +0 -0
- package/_stores/n7/db/000093.sst +0 -0
- package/_stores/n7/db/000094.blob +0 -0
- package/_stores/n7/db/000095.sst +0 -0
- package/_stores/n7/db/000096.sst +0 -0
- package/_stores/n7/db/000114.blob +0 -0
- package/_stores/n7/db/000117.blob +0 -0
- package/_stores/n7/db/000127.blob +0 -0
- package/_stores/n7/db/000138.blob +0 -0
- package/_stores/n7/db/000150.blob +0 -0
- package/_stores/n7/db/000159.blob +0 -0
- package/_stores/n7/db/000166.blob +0 -0
- package/_stores/n7/db/000172.blob +0 -0
- package/_stores/n7/db/000175.blob +0 -0
- package/_stores/n7/db/000180.sst +0 -0
- package/_stores/n7/db/000193.blob +0 -0
- package/_stores/n7/db/000198.log +0 -0
- package/_stores/n7/db/000200.blob +0 -0
- package/_stores/n7/db/000201.sst +0 -0
- package/_stores/n7/db/000202.sst +0 -0
- package/_stores/n7/db/000204.sst +0 -0
- package/_stores/n7/db/000205.sst +0 -0
- package/_stores/n7/db/000206.sst +0 -0
- package/_stores/n7/db/000207.sst +0 -0
- package/_stores/n7/db/CURRENT +0 -0
- package/_stores/n7/db/IDENTITY +0 -0
- package/_stores/n7/db/LOCK +0 -0
- package/_stores/n7/db/LOG +0 -0
- package/_stores/n7/db/LOG.old.1742186180169762 +0 -0
- package/_stores/n7/db/LOG.old.1742420109317101 +0 -0
- package/_stores/n7/db/LOG.old.1742420828841380 +0 -0
- package/_stores/n7/db/LOG.old.1742421152251567 +0 -0
- package/_stores/n7/db/LOG.old.1742577512090130 +0 -0
- package/_stores/n7/db/LOG.old.1742589286130264 +0 -0
- package/_stores/n7/db/MANIFEST-000195 +0 -0
- package/_stores/n7/db/OPTIONS-000191 +0 -0
- package/_stores/n7/db/OPTIONS-000197 +0 -0
- package/_stores/n7/db/keypair.json +1 -0
- package/msb.mjs +1 -1
- package/package.json +1 -1
- package/src/functions.js +7 -64
- package/src/index.js +157 -199
- 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: '
|
|
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
package/src/functions.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
19
|
-
|
|
20
|
-
if
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
91
|
-
|
|
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: `,
|
|
77
|
+
console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
|
|
96
78
|
}
|
|
97
79
|
} else if (op.type === 'addWriter') {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
96
|
+
if(this.enable_wallet){
|
|
223
97
|
await this.wallet.initKeyPair(this.KEY_PAIR_PATH);
|
|
224
98
|
}
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
277
|
-
|
|
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 =
|
|
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:
|
|
293
|
-
wp:
|
|
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
|
|
311
|
-
if
|
|
180
|
+
async pool(){
|
|
181
|
+
while(true){
|
|
182
|
+
if(this.tx_pool.length > 0){
|
|
312
183
|
const length = this.tx_pool.length;
|
|
313
|
-
for
|
|
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 =
|
|
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.
|
|
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('- /
|
|
373
|
-
console.log('- /
|
|
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(
|
|
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('/
|
|
397
|
-
|
|
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() { }
|