trac-msb 0.0.99 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Whitelist/pubkeys.csv +1 -1
- package/msb.mjs +2 -2
- package/package.json +2 -2
- package/src/index.js +7 -6
- package/src/network.js +16 -5
package/Whitelist/pubkeys.csv
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
dfb2944faf6db3ed72c2fb44a04f3e769577160357a664f036aa99220527d538
|
package/msb.mjs
CHANGED
|
@@ -4,9 +4,9 @@ const opts = {
|
|
|
4
4
|
stores_directory : 'stores/',
|
|
5
5
|
store_name : typeof process !== "undefined" ? process.argv[2] : Pear.config.args[0],
|
|
6
6
|
bootstrap: '4577ebf1e84c06d48b2caa33fe54ae58be3a79cb30810129d58b725fae412e37',
|
|
7
|
-
enable_updater : true,
|
|
8
7
|
channel: '00axtracnetworkmainsettlementbus',
|
|
9
|
-
tx : 'axtracnetworkmainsettlementbustx'
|
|
8
|
+
tx : 'axtracnetworkmainsettlementbustx',
|
|
9
|
+
enable_updater : true
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
const msb = new MainSettlementBus(opts);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trac-msb",
|
|
3
3
|
"main": "msb.mjs",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"pear": {
|
|
6
6
|
"name": "trac-msb",
|
|
7
7
|
"type": "terminal"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"bare-crypto": "^1.4.3",
|
|
22
22
|
"bare-events": "^2.5.4",
|
|
23
23
|
"bare-fetch": "^2.2.1",
|
|
24
|
-
"bare-fs": "4.
|
|
24
|
+
"bare-fs": "^4.1.2",
|
|
25
25
|
"bare-http1": "^4.0.2",
|
|
26
26
|
"bare-https": "^2.0.0",
|
|
27
27
|
"bare-inspector": "^4.0.1",
|
package/src/index.js
CHANGED
|
@@ -228,7 +228,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
228
228
|
const isWhitelisted = await this.#isWhitelisted2(op.key, batch);
|
|
229
229
|
if (!isWhitelisted || op.key !== op.value.pub) return;
|
|
230
230
|
// TODO: if the below is not a message signed by admin BUT this handler is supposed to be executed by the admin, then use admin signatures in apply!
|
|
231
|
-
const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.
|
|
231
|
+
const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.wk, op.value.nonce, op.type));
|
|
232
232
|
if (isMessageVerifed) {
|
|
233
233
|
await this.#addWriter(op, batch, base);
|
|
234
234
|
}
|
|
@@ -260,7 +260,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
260
260
|
const adminEntry = await batch.get(EntryType.ADMIN);
|
|
261
261
|
if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
|
|
262
262
|
// TODO: if the below is not a message signed by admin BUT this handler is supposed to be executed by the admin, then use admin signatures in apply!
|
|
263
|
-
const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key,
|
|
263
|
+
const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.wk, op.value.nonce, op.type));
|
|
264
264
|
if (isMessageVerifed) {
|
|
265
265
|
await this.#removeWriter(op, batch, base);
|
|
266
266
|
}
|
|
@@ -386,9 +386,9 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
386
386
|
this.#writerEventListener(); // only for writers
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
-
|
|
389
|
+
await this.#setUpRoleAutomatically(adminEntry);
|
|
390
390
|
|
|
391
|
-
if (this.#enable_updater
|
|
391
|
+
if (this.#enable_updater) {
|
|
392
392
|
this.updater();// TODO: NODE AFTER BECOMING A writer should start the updater
|
|
393
393
|
}
|
|
394
394
|
|
|
@@ -421,9 +421,10 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
421
421
|
async #setUpRoleAutomatically() {
|
|
422
422
|
if (!this.#base.writable) {
|
|
423
423
|
await this.#requestWriterRole(false)
|
|
424
|
+
console.log('Wait please...');
|
|
424
425
|
setTimeout(async () => {
|
|
425
426
|
await this.#requestWriterRole(true)
|
|
426
|
-
},
|
|
427
|
+
}, 5_000);
|
|
427
428
|
}
|
|
428
429
|
}
|
|
429
430
|
|
|
@@ -434,7 +435,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
434
435
|
const node = new DHT({bootstrap:this.#dht_bootstrap})
|
|
435
436
|
const stream = node.connect(b4a.from(adminEntry.tracPublicKey, 'hex'))
|
|
436
437
|
stream.on('connect', async function () {
|
|
437
|
-
await stream.send(b4a.from(JSON.stringify(
|
|
438
|
+
await stream.send(b4a.from(JSON.stringify(message)));
|
|
438
439
|
await stream.destroy();
|
|
439
440
|
});
|
|
440
441
|
stream.on('open', function () { });
|
package/src/network.js
CHANGED
|
@@ -80,19 +80,29 @@ class Network {
|
|
|
80
80
|
if(msg === 'get_writer_key'){
|
|
81
81
|
await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
|
|
82
82
|
await connection.destroy();
|
|
83
|
-
} else if(msg.
|
|
83
|
+
} else if(msg.type !== undefined && msg.key !== undefined && msg.value !== undefined && msg.type === 'addWriter'){
|
|
84
84
|
await connection.destroy();
|
|
85
|
-
msg = msg.message;
|
|
86
85
|
const adminEntry = await msb.get(EntryType.ADMIN);
|
|
87
86
|
if(null === adminEntry || (adminEntry.tracPublicKey !== wallet.publicKey)) return;
|
|
88
87
|
const nodeEntry = await msb.get(msg.value.pub);
|
|
89
88
|
const isAlreadyWriter = null !== nodeEntry && nodeEntry.isWriter;
|
|
90
|
-
const isAllowedToRequestRole = await msb._isAllowedToRequestRole(msg.
|
|
89
|
+
const isAllowedToRequestRole = await msb._isAllowedToRequestRole(msg.key, adminEntry);
|
|
91
90
|
const canAddWriter = base.writable && !isAlreadyWriter && isAllowedToRequestRole;
|
|
92
|
-
if(msg.
|
|
91
|
+
if(msg.key !== wallet.publicKey && canAddWriter){
|
|
93
92
|
await base.append(msg);
|
|
94
93
|
}
|
|
95
|
-
} else {
|
|
94
|
+
} else if (msg.type !== undefined && msg.key !== undefined && msg.value !== undefined && msg.type === 'removeWriter') {
|
|
95
|
+
await connection.destroy();
|
|
96
|
+
const adminEntry = await msb.get(EntryType.ADMIN);
|
|
97
|
+
if(null === adminEntry || (adminEntry.tracPublicKey !== wallet.publicKey)) return;
|
|
98
|
+
const nodeEntry = await msb.get(msg.value.pub);
|
|
99
|
+
const isAlreadyWriter = null !== nodeEntry && nodeEntry.isWriter;
|
|
100
|
+
const canRemoveWriter = base.writable && isAlreadyWriter
|
|
101
|
+
if (msg.key !== wallet.publicKey && canRemoveWriter) {
|
|
102
|
+
await base.append(msg);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
96
106
|
//await connection.destroy();
|
|
97
107
|
if (base.isIndexer || !base.writable) return;
|
|
98
108
|
|
|
@@ -133,6 +143,7 @@ class Network {
|
|
|
133
143
|
}
|
|
134
144
|
}catch(e){
|
|
135
145
|
console.log(e);
|
|
146
|
+
try{ await connection.destroy(); } catch (e){ }
|
|
136
147
|
}
|
|
137
148
|
});
|
|
138
149
|
connection.on('close', () => { });
|