trac-msb 0.0.73 → 0.0.75

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.73",
4
+ "version": "0.0.75",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/network.js CHANGED
@@ -54,15 +54,13 @@ class Network {
54
54
 
55
55
  static async dhtServer(dhtServer, base, wallet, writingKey, networkInstance){
56
56
  try{
57
- server.on('connection', function (connection) {
57
+ dhtServer.on('connection', function (connection) {
58
58
  connection.on('message', async (msg) => {
59
- const cmd = b4a.toString(msg, 'utf-8');
60
- if(cmd === 'get_writer_key'){
59
+ msg = b4a.toString(msg, 'utf-8');
60
+ if(msg === 'get_writer_key'){
61
61
  await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
62
62
  } else {
63
63
 
64
- console.log(msg);
65
-
66
64
  if (base.isIndexer || !base.writable) return;
67
65
 
68
66
  // TODO: decide if a tx rejection should be responded with
@@ -74,12 +72,10 @@ class Network {
74
72
  if (b4a.byteLength(msg) > 3072) return;
75
73
 
76
74
  try {
77
-
78
75
  const parsedPreTx = JSON.parse(msg);
79
76
 
80
77
  if (networkInstance.check.sanitizePreTx(parsedPreTx) &&
81
78
  wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')) &&
82
- parsedPreTx.w === writingKey &&
83
79
  parsedPreTx.wp === wallet.publicKey &&
84
80
  null === await base.view.get(parsedPreTx.tx)
85
81
  ) {
@@ -89,7 +85,7 @@ class Network {
89
85
  op: OperationType.POST_TX,
90
86
  tx: parsedPreTx.tx,
91
87
  is: parsedPreTx.is,
92
- w: parsedPreTx.w,
88
+ w: writingKey,
93
89
  i: parsedPreTx.i,
94
90
  ipk: parsedPreTx.ipk,
95
91
  ch: parsedPreTx.ch,
@@ -106,7 +102,7 @@ class Network {
106
102
  console.log(e)
107
103
  }
108
104
  }
109
- await connection.destroy();
105
+ //await connection.destroy();
110
106
  });
111
107
  connection.on('close', () => { });
112
108
  connection.on('error', (error) => { });
@@ -115,7 +111,7 @@ class Network {
115
111
  publicKey: b4a.from(wallet.publicKey, 'hex'),
116
112
  secretKey: b4a.from(wallet.secretKey, 'hex')
117
113
  };
118
- await server.listen(keyPair)
114
+ await dhtServer.listen(keyPair)
119
115
  console.log('DHT node is listening on public key', wallet.publicKey);
120
116
  } catch(e) { }
121
117
  }
@@ -108,7 +108,7 @@ class Check {
108
108
  op: { type: 'string', enum: ['pre-tx'], required: true },
109
109
  tx: { type: 'is_hex_string', required: true }, // TODO: if we will use only 256 bit hash then change to length: 64
110
110
  is: { type: 'is_hex_string', length: 128, required: true },
111
- w: { type: 'is_hex_string', length: 64, required: true },
111
+ wp: { type: 'is_hex_string', length: 64, required: true },
112
112
  i: { type: 'is_hex_string', length: 64, required: true },
113
113
  ipk: { type: 'is_hex_string', length: 64, required: true },
114
114
  ch: { type: 'is_hex_string', required: true }, // TODO: if we will use only 256 bit hash then change to length: 64