trac-msb 0.0.65 → 0.0.67

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 +1 @@
1
- f46776c2cbdc14938b72d19a257d24c680040158d7b0a0bfc2437b8c6a1bf59c
1
+ e247a9ceefb8a83e28d3c5845055910bc61e0b418c7578d297354708f276af04
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.65",
4
+ "version": "0.0.67",
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.#enable_txchannel = options.enable_txchannel !== false;
68
68
  this.#enable_updater = options.enable_updater !== false;
69
69
  this.#enable_wallet = options.enable_wallet !== false;
70
- this.#wallet = this.#enable_wallet ? new PeerWallet(options) : null;
70
+ this.#wallet = new PeerWallet(options);
71
71
  this.#replicate = options.replicate !== false;
72
72
  this.#opts = options;
73
73
  }
@@ -152,7 +152,7 @@ export class MainSettlementBus extends ReadyResource {
152
152
  b4a.byteLength(JSON.stringify(postTx)) <= 4096
153
153
  ) {
154
154
  await batch.put(op.key, op.value);
155
- //console.log(`TX: ${op.key} appended. Signed length: `, this.#base.view.core.signedLength);
155
+ console.log(`TX: ${op.key} appended. Signed length: `, this.#base.view.core.signedLength);
156
156
  }
157
157
  }
158
158
 
@@ -414,10 +414,10 @@ export class MainSettlementBus extends ReadyResource {
414
414
  }
415
415
 
416
416
  #isAdmin(adminEntry, node = null) {
417
+ if(this.#enable_wallet === false) return false;
417
418
  if (!adminEntry) return false;
418
419
  if (node) return adminEntry.wk === b4a.from(node.from.key).toString('hex');
419
420
  return !!(this.#wallet.publicKey === adminEntry.tracPublicKey && adminEntry.wk === this.#writingKey);
420
-
421
421
  }
422
422
 
423
423
  async #isAllowedToRequestRole(key, adminEntry) {
@@ -463,7 +463,7 @@ export class MainSettlementBus extends ReadyResource {
463
463
  const parsedRequest = JSON.parse(bufferData);
464
464
  if (parsedRequest && parsedRequest.type && parsedRequest.key && parsedRequest.value) {
465
465
  if (parsedRequest.type === OperationType.ADD_WRITER || parsedRequest.type === OperationType.REMOVE_WRITER) {
466
- //This request must be hanlded by ADMIN
466
+ //This request must be hanlded by ADMIN
467
467
  this.emit(EventType.ADMIN_EVENT, parsedRequest);
468
468
  } else if (parsedRequest.type === OperationType.ADD_ADMIN) {
469
469
  //This request must be handled by WRITER
@@ -502,6 +502,10 @@ export class MainSettlementBus extends ReadyResource {
502
502
  });
503
503
 
504
504
  this.#base.on(EventType.UNWRITABLE, async () => {
505
+ if(this.#enable_wallet === false) {
506
+ console.log('Current node is unwritable');
507
+ return;
508
+ }
505
509
  const updatedNodeEntry = await this.getSigned(this.#wallet.publicKey);
506
510
  const canDisableWriterEvents = updatedNodeEntry &&
507
511
  !updatedNodeEntry.isWriter &&
@@ -517,6 +521,7 @@ export class MainSettlementBus extends ReadyResource {
517
521
 
518
522
  async #adminEventListener() {
519
523
  this.on(EventType.ADMIN_EVENT, async (parsedRequest) => {
524
+ if(this.#enable_wallet === false) return;
520
525
  const isWhitelisted = await this.#isWhitelisted(parsedRequest.key);
521
526
  const isEventMessageVerifed = await MsgUtils.verifyEventMessage(parsedRequest, this.#wallet)
522
527
  if (isWhitelisted && isEventMessageVerifed) {
@@ -527,6 +532,7 @@ export class MainSettlementBus extends ReadyResource {
527
532
 
528
533
  async #writerEventListener() {
529
534
  this.on(EventType.WRITER_EVENT, async (parsedRequest) => {
535
+ if(this.#enable_wallet === false) return;
530
536
  const adminEntry = await this.getSigned(EntryType.ADMIN);
531
537
  const isEventMessageVerifed = await MsgUtils.verifyEventMessage(parsedRequest, this.#wallet)
532
538
  if (adminEntry && adminEntry.tracPublicKey === parsedRequest.key && isEventMessageVerifed) {
@@ -549,7 +555,7 @@ export class MainSettlementBus extends ReadyResource {
549
555
  const addAdminMessage = await MsgUtils.assembleAdminMessage(adminEntry, this.#writingKey, this.#wallet, this.#bootstrap);
550
556
  if (!adminEntry && this.#wallet && this.#writingKey && this.#writingKey === this.#bootstrap) {
551
557
  await this.#base.append(addAdminMessage);
552
- } else if (adminEntry && adminEntry.tracPublicKey === this.#wallet.publicKey && this.#writingKey && this.#writingKey !== adminEntry.wk) {
558
+ } else if (adminEntry && this.#wallet && adminEntry.tracPublicKey === this.#wallet.publicKey && this.#writingKey && this.#writingKey !== adminEntry.wk) {
553
559
  let connections = [];
554
560
  for (const conn of this.#swarm.connections) {
555
561
 
@@ -569,7 +575,7 @@ export class MainSettlementBus extends ReadyResource {
569
575
  if (connections.length > 0) {
570
576
  connections[Math.floor(Math.random() * connections.length)].write(JSON.stringify(addAdminMessage));
571
577
  }
572
- //TODO: Implement an algorithm to search a new writer and connect/send the request for it.
578
+ //TODO: Implement an algorithm to search a new writer and connect/send the request for it.
573
579
  }
574
580
 
575
581
  setTimeout(async () => {
@@ -583,6 +589,7 @@ export class MainSettlementBus extends ReadyResource {
583
589
  }
584
590
 
585
591
  async #handleWhitelistOperations() {
592
+ if(this.#enable_wallet === false) return;
586
593
  const adminEntry = await this.getSigned(EntryType.ADMIN);
587
594
  if (!this.#isAdmin(adminEntry)) return;
588
595
 
@@ -614,6 +621,7 @@ export class MainSettlementBus extends ReadyResource {
614
621
  }
615
622
 
616
623
  async #requestWriterRole(toAdd) {
624
+ if(this.#enable_wallet === false) return;
617
625
  const adminEntry = await this.getSigned(EntryType.ADMIN);
618
626
  const nodeEntry = await this.getSigned(this.#wallet.publicKey);
619
627
  const isAlreadyWriter = !!(nodeEntry && nodeEntry.isWriter)
@@ -638,6 +646,7 @@ export class MainSettlementBus extends ReadyResource {
638
646
  }
639
647
 
640
648
  async #updateIndexerRole(tracPublicKey, toAdd) {
649
+ if(this.#enable_wallet === false) return;
641
650
  const adminEntry = await this.getSigned(EntryType.ADMIN);
642
651
  if (!this.#isAdmin(adminEntry) && !this.#base.writable) return;
643
652
 
@@ -737,7 +746,6 @@ export class MainSettlementBus extends ReadyResource {
737
746
  default:
738
747
  if (input.startsWith('/get_node_info')) {
739
748
  const splitted = input.split(' ');
740
- console.log("address:", await this.getSigned(splitted[1]))
741
749
  console.log("whitelist entry:", await this.#isWhitelisted(splitted[1]))
742
750
  } else if (input.startsWith('/add_indexer')) {
743
751
  const splitted = input.split(' ');
package/src/network.js CHANGED
@@ -20,18 +20,17 @@ class Network {
20
20
  let keyPair;
21
21
  if (!walletEnabled) {
22
22
  keyPair = await store.createKeyPair(TRAC_NAMESPACE);
23
+ } else {
24
+ keyPair = {
25
+ publicKey: b4a.from(wallet.publicKey, 'hex'),
26
+ secretKey: b4a.from(wallet.secretKey, 'hex')
27
+ };
23
28
  }
24
29
 
25
- keyPair = {
26
- publicKey: b4a.from(wallet.publicKey, 'hex'),
27
- secretKey: b4a.from(wallet.secretKey, 'hex')
28
- };
29
-
30
30
  swarm = new Hyperswarm({ keyPair, maxPeers: MAX_PEERS, maxParallel: MAX_PARALLEL, maxServerConnections: MAX_SERVER_CONNECTIONS });
31
31
 
32
32
  console.log(`Channel: ${b4a.toString(channel)}`);
33
33
  swarm.on('connection', async (connection) => {
34
-
35
34
  wakeup.addStream(connection);
36
35
  store.replicate(connection);
37
36
  connection.on('close', () => { });
@@ -75,7 +74,7 @@ class Network {
75
74
  try {
76
75
 
77
76
  const parsedPreTx = JSON.parse(msg);
78
-
77
+
79
78
  if (networkInstance.check.sanitizePreTx(parsedPreTx) &&
80
79
  wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')) &&
81
80
  parsedPreTx.w === writingKey &&