trac-msb 0.0.92 → 0.0.94

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.
@@ -1,5 +1,12 @@
1
- 3e84de76f23d1f8f47aa5f133cb928ead44f91429df0b3f9761205049f2beeec
2
- bd3c9c5844187407baf418c3aa6329c364297b895f961a1f88a91bfe666f72c2
3
- 17e1856a71e2aef8be3dcb6776316cf90d339f8cab9bcbb3c356be2da86fd2e7
4
- ea866411e7d377efeae2eb1d243956e6a122330e697ff33d8312d1db48976658
5
- 30149ac3be7ab7c35c047f64cfa76c59ad7a3373fdc2ac568a05c3ed4169bb4f
1
+ 7be749936c803c08467c9ee6c4fa5ac512d3c461251a05a46df37e4b7c3352ae
2
+ d9b32f8954b265286a5003789df96dbd17246aa80327486677f5b5b37fc58472
3
+ 06a7d7bae9ae73a46ebcfa9041c64eea1c528c80eadeee74bbe1f15b8bb1985c
4
+ 1427ccaa352e379f63e183e9332aacf31d8e0fefae1f85ddf0dc79980c8c0a46
5
+ 47277c0a81d47ec173a86007e5b2afc0ce7212f341fccbc61336dda86814a4bf
6
+ 55abb6145c03eeb36019fc60a57db374695646e19d37fa97bbbe65a8b448708d
7
+ dbeda3d6d66784d1e8088d3bc2e91be5fb09ad808561e0b25a3eef23f3268e6d
8
+ 92d5dc88e86885a03309c9e1bd83d3da696de7326875222cc9a97c3e587c9976
9
+ 06facf44678703f96e27c0a0bf5ec1c2073bb0c5b54776bcdaa4d66c1d8cda27
10
+ dba246f800a5e29f561a2bde78c61d520079307fdbfae3a31f958c8ea31f90f9
11
+ dc4d146c11bee90870ade1a7ae5a6bdee84d521998c2b60a6628e064363acd3f
12
+ ccf0fea255e442ebe540213274b9d6e5484140d0db8b545978d404c369c680e9
package/msb.mjs CHANGED
@@ -4,6 +4,7 @@ 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,
7
8
  channel: '00axtracnetworkmainsettlementbus',
8
9
  tx : 'axtracnetworkmainsettlementbustx'
9
10
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.92",
4
+ "version": "0.0.94",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/index.js CHANGED
@@ -67,7 +67,7 @@ export class MainSettlementBus extends ReadyResource {
67
67
  this.#store = new Corestore(this.STORES_DIRECTORY + options.store_name);
68
68
  this.#bee = null;
69
69
  this.#swarm = null;
70
- this.#dht_bootstrap = ['116.202.214.143:10001','116.202.214.149:10001', 'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'];
70
+ this.#dht_bootstrap = [/*'116.202.214.143:10001','116.202.214.149:10001', */'node1.hyperdht.org:49737', 'node2.hyperdht.org:49737', 'node3.hyperdht.org:49737'];
71
71
  this.#dht_node = new DHT({ bootstrap: this.#dht_bootstrap });
72
72
  this.#dht_server = null;
73
73
  this.#base = null;
@@ -208,10 +208,13 @@ export class MainSettlementBus extends ReadyResource {
208
208
 
209
209
  async #handleApplyAppendWhitelistOperation(op, view, base, node, batch) {
210
210
  const adminEntry = await batch.get(EntryType.ADMIN);
211
- if (null === adminEntry || !this.check.sanitizeIndexerOrWhitelistOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
211
+ if (null === adminEntry || !this.check.sanitizeIndexerOrWhitelistOperations(op) /* TODO: This cannot work, needs to be signed, not checked against wallet!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
212
+ // TODO: is the below an admin signature?
212
213
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, adminEntry.value.tracPublicKey, MsgUtils.createMessage(op.key, op.value.nonce, op.type));
214
+ console.log('isMessageVerifed', isMessageVerifed);
213
215
  if (!isMessageVerifed) return;
214
- const isWhitelisted = await this.#isWhitelisted(op.key);
216
+ const isWhitelisted = await this.#isWhitelisted2(op.key, batch);
217
+ console.log('iswhitelisted', isWhitelisted);
215
218
  if (isWhitelisted) return;
216
219
  await this.#createWhitelistEntry(batch, op.key);
217
220
  }
@@ -223,10 +226,11 @@ export class MainSettlementBus extends ReadyResource {
223
226
 
224
227
  async #handleApplyAddWriterOperation(op, view, base, node, batch) {
225
228
  const adminEntry = await batch.get(EntryType.ADMIN);
226
- if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
229
+ if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) /*TODO: this cannot work, needs to be signed, not checked against wallet!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
227
230
 
228
- const isWhitelisted = await this.#isWhitelisted(op.key);
231
+ const isWhitelisted = await this.#isWhitelisted2(op.key, batch);
229
232
  if (!isWhitelisted || op.key !== op.value.pub) return;
233
+ // 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!
230
234
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.wk, op.value.nonce, op.type));
231
235
  if (isMessageVerifed) {
232
236
  await this.#addWriter(op, batch, base);
@@ -257,7 +261,8 @@ export class MainSettlementBus extends ReadyResource {
257
261
 
258
262
  async #handleApplyRemoveWriterOperation(op, view, base, node, batch) {
259
263
  const adminEntry = await batch.get(EntryType.ADMIN);
260
- if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) || !this.#isAdmin(adminEntry.value, node)) return;
264
+ if (null === adminEntry || !this.check.sanitizeAdminAndWritersOperations(op) /*TODO: this cannot work, needs to be signed, not checked against wallet!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
265
+ // 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!
261
266
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, op.key, MsgUtils.createMessage(op.key, op.value.wk, op.value.nonce, op.type));
262
267
  if (isMessageVerifed) {
263
268
  await this.#removeWriter(op, batch, base);
@@ -293,15 +298,16 @@ export class MainSettlementBus extends ReadyResource {
293
298
  }
294
299
 
295
300
  const adminEntry = await batch.get(EntryType.ADMIN);
296
- if (null === adminEntry || !this.#isAdmin(adminEntry.value, node)) return;
301
+ if (null === adminEntry /* TODO: this cannot work!!!! || !this.#isAdmin(adminEntry.value, node)*/) return;
297
302
 
298
- if (!this.#isWhitelisted(op.key)) return;
303
+ if (!this.#isWhitelisted2(op.key, batch)) return;
299
304
 
300
305
  const indexersEntry = await batch.get(EntryType.INDEXERS);
301
306
  if (null === indexersEntry || Array.from(indexersEntry.value).includes(op.key) ||
302
307
  Array.from(indexersEntry.value).length >= MAX_INDEXERS) {
303
308
  return;
304
309
  }
310
+ // TODO: is the below an admin signature?
305
311
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, adminEntry.value.tracPublicKey, MsgUtils.createMessage(op.key, op.value.nonce, op.type))
306
312
  if (isMessageVerifed) {
307
313
  await this.#addIndexer(indexersEntry.value, op, batch, base);
@@ -327,7 +333,8 @@ export class MainSettlementBus extends ReadyResource {
327
333
  if (!this.check.sanitizeIndexerOrWhitelistOperations(op)) return;
328
334
  const adminEntry = await batch.get(EntryType.ADMIN);
329
335
  let indexersEntry = await batch.get(EntryType.INDEXERS);
330
- if (null === adminEntry || !this.#isAdmin(adminEntry.value, node) || null === indexersEntry || !Array.from(indexersEntry.value).includes(op.key) || Array.from(indexersEntry.value).length <= 1) return;
336
+ if (null === adminEntry /* TODO: this cannot work!!! || !this.#isAdmin(adminEntry.value, node) */ || null === indexersEntry || !Array.from(indexersEntry.value).includes(op.key) || Array.from(indexersEntry.value).length <= 1) return;
337
+ // TODO: is the below an admin signature?
331
338
  const isMessageVerifed = await this.#verifyMessage(op.value.sig, adminEntry.value.tracPublicKey, MsgUtils.createMessage(op.key, op.value.nonce, op.type))
332
339
  if (isMessageVerifed) {
333
340
  let nodeEntry = await batch.get(op.key);
@@ -372,7 +379,7 @@ export class MainSettlementBus extends ReadyResource {
372
379
  await Network.dhtServer(this, this.#dht_server, this.#base, this.#wallet, this.#writingKey, this.#network);
373
380
  }
374
381
 
375
- const adminEntry = await this.getSigned(EntryType.ADMIN);
382
+ const adminEntry = await this.get(EntryType.ADMIN);
376
383
 
377
384
  if (this.#isAdmin(adminEntry)) {
378
385
  this.#shouldListenToAdminEvents = true;
@@ -384,7 +391,7 @@ export class MainSettlementBus extends ReadyResource {
384
391
 
385
392
  //await this.#setUpRoleAutomatically(adminEntry);
386
393
 
387
- if (this.#enable_updater) {
394
+ if (this.#enable_updater && this.#base.writable) {
388
395
  this.updater();// TODO: NODE AFTER BECOMING A writer should start the updater
389
396
  }
390
397
 
@@ -466,6 +473,11 @@ export class MainSettlementBus extends ReadyResource {
466
473
  return !!whitelistEntry;
467
474
  }
468
475
 
476
+ async #isWhitelisted2(key, batch) {
477
+ const whitelistEntry = await this.getWhitelistEntry2(key, batch)
478
+ return !!whitelistEntry;
479
+ }
480
+
469
481
  async updater() {
470
482
  while (true) {
471
483
  if (this.#base.writable) {
@@ -489,10 +501,15 @@ export class MainSettlementBus extends ReadyResource {
489
501
  }
490
502
 
491
503
  async getWhitelistEntry(key) {
492
- const entry = await this.getSigned(WHITELIST_PREFIX + key);
504
+ const entry = await this.get(WHITELIST_PREFIX + key);
493
505
  return entry
494
506
  }
495
507
 
508
+ async getWhitelistEntry2(key, batch) {
509
+ const entry = await batch.get(WHITELIST_PREFIX + key);
510
+ return entry !== null ? entry.value : null
511
+ }
512
+
496
513
  async #handleIncomingEvent(data) {
497
514
  try {
498
515
  const bufferData = data.toString();
@@ -525,7 +542,7 @@ export class MainSettlementBus extends ReadyResource {
525
542
  });
526
543
 
527
544
  this.#base.on(EventType.WRITABLE, async () => {
528
- const updatedNodeEntry = await this.getSigned(this.#wallet.publicKey);
545
+ const updatedNodeEntry = await this.get(this.#wallet.publicKey);
529
546
  const canEnableWriterEvents = updatedNodeEntry &&
530
547
  updatedNodeEntry.wk === this.#writingKey &&
531
548
  !this.#shouldListenToWriterEvents;
@@ -542,7 +559,7 @@ export class MainSettlementBus extends ReadyResource {
542
559
  console.log('Current node is unwritable');
543
560
  return;
544
561
  }
545
- const updatedNodeEntry = await this.getSigned(this.#wallet.publicKey);
562
+ const updatedNodeEntry = await this.get(this.#wallet.publicKey);
546
563
  const canDisableWriterEvents = updatedNodeEntry &&
547
564
  !updatedNodeEntry.isWriter &&
548
565
  this.#shouldListenToWriterEvents;
@@ -569,7 +586,7 @@ export class MainSettlementBus extends ReadyResource {
569
586
  async #writerEventListener() {
570
587
  this.on(EventType.WRITER_EVENT, async (parsedRequest) => {
571
588
  if(this.#enable_wallet === false) return;
572
- const adminEntry = await this.getSigned(EntryType.ADMIN);
589
+ const adminEntry = await this.get(EntryType.ADMIN);
573
590
  const isEventMessageVerifed = await MsgUtils.verifyEventMessage(parsedRequest, this.#wallet)
574
591
  if (adminEntry && adminEntry.tracPublicKey === parsedRequest.key && isEventMessageVerifed) {
575
592
  await this.#base.append(parsedRequest);
@@ -587,7 +604,7 @@ export class MainSettlementBus extends ReadyResource {
587
604
 
588
605
  async #handleAdminOperations() {
589
606
  //TODO: ADJUST FOR WHITELIST STRUCTURE
590
- const adminEntry = await this.getSigned(EntryType.ADMIN);
607
+ const adminEntry = await this.get(EntryType.ADMIN);
591
608
  const addAdminMessage = await MsgUtils.assembleAdminMessage(adminEntry, this.#writingKey, this.#wallet, this.#bootstrap);
592
609
  if (!adminEntry && this.#wallet && this.#writingKey && this.#writingKey === this.#bootstrap) {
593
610
  await this.#base.append(addAdminMessage);
@@ -596,7 +613,7 @@ export class MainSettlementBus extends ReadyResource {
596
613
  for (const conn of this.#swarm.connections) {
597
614
 
598
615
  const remotePublicKeyHex = b4a.from(conn.remotePublicKey).toString('hex');
599
- const remotePublicKeyEntry = await this.getSigned(remotePublicKeyHex);
616
+ const remotePublicKeyEntry = await this.get(remotePublicKeyHex);
600
617
  const isWhitelisted = await this.#isWhitelisted(remotePublicKeyHex);
601
618
 
602
619
  if (conn.connected &&
@@ -615,7 +632,7 @@ export class MainSettlementBus extends ReadyResource {
615
632
  }
616
633
 
617
634
  setTimeout(async () => {
618
- const updatedAdminEntry = await this.getSigned(EntryType.ADMIN);
635
+ const updatedAdminEntry = await this.get(EntryType.ADMIN);
619
636
  if (this.#isAdmin(updatedAdminEntry) && !this.#shouldListenToAdminEvents) {
620
637
  this.#shouldListenToAdminEvents = true;
621
638
  this.#adminEventListener();
@@ -626,7 +643,7 @@ export class MainSettlementBus extends ReadyResource {
626
643
 
627
644
  async #handleWhitelistOperations() {
628
645
  if(this.#enable_wallet === false) return;
629
- const adminEntry = await this.getSigned(EntryType.ADMIN);
646
+ const adminEntry = await this.get(EntryType.ADMIN);
630
647
  if (!this.#isAdmin(adminEntry)) return;
631
648
 
632
649
  const assembledWhitelistMessages = await MsgUtils.assembleWhitelistMessages(adminEntry, this.#wallet);
@@ -658,8 +675,8 @@ export class MainSettlementBus extends ReadyResource {
658
675
 
659
676
  async #requestWriterRole(toAdd) {
660
677
  if(this.#enable_wallet === false) return;
661
- const adminEntry = await this.getSigned(EntryType.ADMIN);
662
- const nodeEntry = await this.getSigned(this.#wallet.publicKey);
678
+ const adminEntry = await this.get(EntryType.ADMIN);
679
+ const nodeEntry = await this.get(this.#wallet.publicKey);
663
680
  const isAlreadyWriter = !!(nodeEntry && nodeEntry.isWriter)
664
681
  let assembledMessage = null;
665
682
  if (toAdd) {
@@ -682,16 +699,16 @@ export class MainSettlementBus extends ReadyResource {
682
699
 
683
700
  async #updateIndexerRole(tracPublicKey, toAdd) {
684
701
  if(this.#enable_wallet === false) return;
685
- const adminEntry = await this.getSigned(EntryType.ADMIN);
702
+ const adminEntry = await this.get(EntryType.ADMIN);
686
703
  if (!this.#isAdmin(adminEntry) && !this.#base.writable) return;
687
704
 
688
705
  const isWhitelisted = await this.#isWhitelisted(tracPublicKey);
689
706
  if (!isWhitelisted) return;
690
707
 
691
- const nodeEntry = await this.getSigned(tracPublicKey);
708
+ const nodeEntry = await this.get(tracPublicKey);
692
709
  if (!nodeEntry || !nodeEntry.isWriter) return;
693
710
 
694
- const indexersEntry = await this.getSigned(EntryType.INDEXERS);
711
+ const indexersEntry = await this.get(EntryType.INDEXERS);
695
712
 
696
713
  if (toAdd) {
697
714
  const canAddIndexer = !nodeEntry.isIndexer && indexersEntry.length <= MAX_INDEXERS;
@@ -774,9 +791,9 @@ export class MainSettlementBus extends ReadyResource {
774
791
  case '/show':
775
792
  // /get_node_info 9da99d98f02f24bdb13d46ba5d346c9a3eda03c18ab6e1441b7bac9743cf0bcc1
776
793
  // Only for DEBUG
777
- const admin = await this.getSigned(EntryType.ADMIN);
794
+ const admin = await this.get(EntryType.ADMIN);
778
795
  console.log('Admin:', admin);
779
- const indexers = await this.getSigned(EntryType.INDEXERS);
796
+ const indexers = await this.get(EntryType.INDEXERS);
780
797
  console.log('Indexers:', indexers);
781
798
  break;
782
799
  case '/dag':
package/src/network.js CHANGED
@@ -83,9 +83,9 @@ class Network {
83
83
  } else if(msg.op !== undefined && msg.message !== undefined && msg.op === 'add_writer'){
84
84
  await connection.destroy();
85
85
  msg = msg.message;
86
- const adminEntry = await msb.getSigned(EntryType.ADMIN);
86
+ const adminEntry = await msb.get(EntryType.ADMIN);
87
87
  if(null === adminEntry || (adminEntry.tracPublicKey !== wallet.publicKey)) return;
88
- const nodeEntry = await msb.getSigned(msg.value.pub);
88
+ const nodeEntry = await msb.get(msg.value.pub);
89
89
  const isAlreadyWriter = null !== nodeEntry && nodeEntry.isWriter;
90
90
  const isAllowedToRequestRole = await msb._isAllowedToRequestRole(msg.value.pub, adminEntry);
91
91
  const canAddWriter = base.writable && !isAlreadyWriter && isAllowedToRequestRole;
@@ -13,7 +13,7 @@ export class WriterManager extends ReadyResource {
13
13
 
14
14
  async addAdmin() {
15
15
  // case where admin entry doesn't exist yet and we have to autorize Admin public key only with bootstrap writing key
16
- const adminEntry = await this.msbInstance.getSigned('admin');
16
+ const adminEntry = await this.msbInstance.get('admin');
17
17
  if (!adminEntry && this.msbInstance.writingKey && this.msbInstance.writingKey === this.msbInstance.bootstrap) {
18
18
 
19
19
  const nonce = Math.random() + '-' + Date.now();
@@ -44,7 +44,7 @@ export class WriterManager extends ReadyResource {
44
44
  try {
45
45
  //TODO: IMPORTANT - IF WE GONNA STORE ~ 2K-10K PUBLIC KEYS IN THE LIST, WE NEED TO SPLIT IT INTO CHUNKS
46
46
  // ONE CHUNK WILL BE ~100 PUBLIC KEYS + NONCE + SIG AND ADDITIONAL BYTES < 4096 BYTES. ADMIN WILL NEED TO PERFORM MULTIPLE APPENDS. FOR NOW THIS IS NOT IMPLEMENTED.
47
- const adminEntry = await this.msbInstance.getSigned('admin');
47
+ const adminEntry = await this.msbInstance.get('admin');
48
48
 
49
49
  if (adminEntry && this.msbInstance.wallet.publicKey === Buffer.from(adminEntry.tpk.data).toString('hex')) {
50
50