trac-msb 0.0.93 → 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,13 +1,12 @@
1
- 3e84de76f23d1f8f47aa5f133cb928ead44f91429df0b3f9761205049f2beeec
2
- bd3c9c5844187407baf418c3aa6329c364297b895f961a1f88a91bfe666f72c2
3
- 17e1856a71e2aef8be3dcb6776316cf90d339f8cab9bcbb3c356be2da86fd2e7
4
- ea866411e7d377efeae2eb1d243956e6a122330e697ff33d8312d1db48976658
5
- 30149ac3be7ab7c35c047f64cfa76c59ad7a3373fdc2ac568a05c3ed4169bb4f
6
- 49fd8429f26e61c7ae9382c763585c8085ac4d0c47649b3cb4b435f4b04f3a59
7
- 0e3831a32bd8b955be4050d7bcdacb38ec3b33cefd8e4f3c9921c98e1989f179
8
- eb3f93f89694374f5caabebb7499a218631e67e857197531e8422a70b038e992
9
- b675e900dce3d2d191a847230750ed98f86253888bc3ddd05c15de4f64c00881
10
- 714c6a9c4af41bfcf2c42a5f79ef85655ce398c4bbd070a03629d0a03d97dca5
11
- 35f12e13e447038d07e9ee2a1750084ca006368fced4e8e0c55d354e99b9571a
12
- 0fd54a89ea654011b800ed9f006deefdbdb68ddf1f0a392478cf7956f362adfe
13
- 1961a27b204d9bf8f1d0483103b3b510ed401d502e0b6b41dce399894f6924f1
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.93",
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;
@@ -379,7 +379,7 @@ export class MainSettlementBus extends ReadyResource {
379
379
  await Network.dhtServer(this, this.#dht_server, this.#base, this.#wallet, this.#writingKey, this.#network);
380
380
  }
381
381
 
382
- const adminEntry = await this.getSigned(EntryType.ADMIN);
382
+ const adminEntry = await this.get(EntryType.ADMIN);
383
383
 
384
384
  if (this.#isAdmin(adminEntry)) {
385
385
  this.#shouldListenToAdminEvents = true;
@@ -391,7 +391,7 @@ export class MainSettlementBus extends ReadyResource {
391
391
 
392
392
  //await this.#setUpRoleAutomatically(adminEntry);
393
393
 
394
- if (this.#enable_updater) {
394
+ if (this.#enable_updater && this.#base.writable) {
395
395
  this.updater();// TODO: NODE AFTER BECOMING A writer should start the updater
396
396
  }
397
397
 
@@ -501,7 +501,7 @@ export class MainSettlementBus extends ReadyResource {
501
501
  }
502
502
 
503
503
  async getWhitelistEntry(key) {
504
- const entry = await this.getSigned(WHITELIST_PREFIX + key);
504
+ const entry = await this.get(WHITELIST_PREFIX + key);
505
505
  return entry
506
506
  }
507
507
 
@@ -542,7 +542,7 @@ export class MainSettlementBus extends ReadyResource {
542
542
  });
543
543
 
544
544
  this.#base.on(EventType.WRITABLE, async () => {
545
- const updatedNodeEntry = await this.getSigned(this.#wallet.publicKey);
545
+ const updatedNodeEntry = await this.get(this.#wallet.publicKey);
546
546
  const canEnableWriterEvents = updatedNodeEntry &&
547
547
  updatedNodeEntry.wk === this.#writingKey &&
548
548
  !this.#shouldListenToWriterEvents;
@@ -559,7 +559,7 @@ export class MainSettlementBus extends ReadyResource {
559
559
  console.log('Current node is unwritable');
560
560
  return;
561
561
  }
562
- const updatedNodeEntry = await this.getSigned(this.#wallet.publicKey);
562
+ const updatedNodeEntry = await this.get(this.#wallet.publicKey);
563
563
  const canDisableWriterEvents = updatedNodeEntry &&
564
564
  !updatedNodeEntry.isWriter &&
565
565
  this.#shouldListenToWriterEvents;
@@ -586,7 +586,7 @@ export class MainSettlementBus extends ReadyResource {
586
586
  async #writerEventListener() {
587
587
  this.on(EventType.WRITER_EVENT, async (parsedRequest) => {
588
588
  if(this.#enable_wallet === false) return;
589
- const adminEntry = await this.getSigned(EntryType.ADMIN);
589
+ const adminEntry = await this.get(EntryType.ADMIN);
590
590
  const isEventMessageVerifed = await MsgUtils.verifyEventMessage(parsedRequest, this.#wallet)
591
591
  if (adminEntry && adminEntry.tracPublicKey === parsedRequest.key && isEventMessageVerifed) {
592
592
  await this.#base.append(parsedRequest);
@@ -604,7 +604,7 @@ export class MainSettlementBus extends ReadyResource {
604
604
 
605
605
  async #handleAdminOperations() {
606
606
  //TODO: ADJUST FOR WHITELIST STRUCTURE
607
- const adminEntry = await this.getSigned(EntryType.ADMIN);
607
+ const adminEntry = await this.get(EntryType.ADMIN);
608
608
  const addAdminMessage = await MsgUtils.assembleAdminMessage(adminEntry, this.#writingKey, this.#wallet, this.#bootstrap);
609
609
  if (!adminEntry && this.#wallet && this.#writingKey && this.#writingKey === this.#bootstrap) {
610
610
  await this.#base.append(addAdminMessage);
@@ -613,7 +613,7 @@ export class MainSettlementBus extends ReadyResource {
613
613
  for (const conn of this.#swarm.connections) {
614
614
 
615
615
  const remotePublicKeyHex = b4a.from(conn.remotePublicKey).toString('hex');
616
- const remotePublicKeyEntry = await this.getSigned(remotePublicKeyHex);
616
+ const remotePublicKeyEntry = await this.get(remotePublicKeyHex);
617
617
  const isWhitelisted = await this.#isWhitelisted(remotePublicKeyHex);
618
618
 
619
619
  if (conn.connected &&
@@ -632,7 +632,7 @@ export class MainSettlementBus extends ReadyResource {
632
632
  }
633
633
 
634
634
  setTimeout(async () => {
635
- const updatedAdminEntry = await this.getSigned(EntryType.ADMIN);
635
+ const updatedAdminEntry = await this.get(EntryType.ADMIN);
636
636
  if (this.#isAdmin(updatedAdminEntry) && !this.#shouldListenToAdminEvents) {
637
637
  this.#shouldListenToAdminEvents = true;
638
638
  this.#adminEventListener();
@@ -643,7 +643,7 @@ export class MainSettlementBus extends ReadyResource {
643
643
 
644
644
  async #handleWhitelistOperations() {
645
645
  if(this.#enable_wallet === false) return;
646
- const adminEntry = await this.getSigned(EntryType.ADMIN);
646
+ const adminEntry = await this.get(EntryType.ADMIN);
647
647
  if (!this.#isAdmin(adminEntry)) return;
648
648
 
649
649
  const assembledWhitelistMessages = await MsgUtils.assembleWhitelistMessages(adminEntry, this.#wallet);
@@ -675,8 +675,8 @@ export class MainSettlementBus extends ReadyResource {
675
675
 
676
676
  async #requestWriterRole(toAdd) {
677
677
  if(this.#enable_wallet === false) return;
678
- const adminEntry = await this.getSigned(EntryType.ADMIN);
679
- 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);
680
680
  const isAlreadyWriter = !!(nodeEntry && nodeEntry.isWriter)
681
681
  let assembledMessage = null;
682
682
  if (toAdd) {
@@ -699,16 +699,16 @@ export class MainSettlementBus extends ReadyResource {
699
699
 
700
700
  async #updateIndexerRole(tracPublicKey, toAdd) {
701
701
  if(this.#enable_wallet === false) return;
702
- const adminEntry = await this.getSigned(EntryType.ADMIN);
702
+ const adminEntry = await this.get(EntryType.ADMIN);
703
703
  if (!this.#isAdmin(adminEntry) && !this.#base.writable) return;
704
704
 
705
705
  const isWhitelisted = await this.#isWhitelisted(tracPublicKey);
706
706
  if (!isWhitelisted) return;
707
707
 
708
- const nodeEntry = await this.getSigned(tracPublicKey);
708
+ const nodeEntry = await this.get(tracPublicKey);
709
709
  if (!nodeEntry || !nodeEntry.isWriter) return;
710
710
 
711
- const indexersEntry = await this.getSigned(EntryType.INDEXERS);
711
+ const indexersEntry = await this.get(EntryType.INDEXERS);
712
712
 
713
713
  if (toAdd) {
714
714
  const canAddIndexer = !nodeEntry.isIndexer && indexersEntry.length <= MAX_INDEXERS;
@@ -791,9 +791,9 @@ export class MainSettlementBus extends ReadyResource {
791
791
  case '/show':
792
792
  // /get_node_info 9da99d98f02f24bdb13d46ba5d346c9a3eda03c18ab6e1441b7bac9743cf0bcc1
793
793
  // Only for DEBUG
794
- const admin = await this.getSigned(EntryType.ADMIN);
794
+ const admin = await this.get(EntryType.ADMIN);
795
795
  console.log('Admin:', admin);
796
- const indexers = await this.getSigned(EntryType.INDEXERS);
796
+ const indexers = await this.get(EntryType.INDEXERS);
797
797
  console.log('Indexers:', indexers);
798
798
  break;
799
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