trac-msb 0.0.73 → 0.0.74

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.74",
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
@@ -77,6 +75,13 @@ class Network {
77
75
 
78
76
  const parsedPreTx = JSON.parse(msg);
79
77
 
78
+ console.log(networkInstance.check.sanitizePreTx(parsedPreTx),
79
+ wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')),
80
+ parsedPreTx.w === writingKey,
81
+ parsedPreTx.wp === wallet.publicKey,
82
+ null === await base.view.get(parsedPreTx.tx)
83
+ );
84
+
80
85
  if (networkInstance.check.sanitizePreTx(parsedPreTx) &&
81
86
  wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')) &&
82
87
  parsedPreTx.w === writingKey &&
@@ -106,7 +111,7 @@ class Network {
106
111
  console.log(e)
107
112
  }
108
113
  }
109
- await connection.destroy();
114
+ //await connection.destroy();
110
115
  });
111
116
  connection.on('close', () => { });
112
117
  connection.on('error', (error) => { });
@@ -115,7 +120,7 @@ class Network {
115
120
  publicKey: b4a.from(wallet.publicKey, 'hex'),
116
121
  secretKey: b4a.from(wallet.secretKey, 'hex')
117
122
  };
118
- await server.listen(keyPair)
123
+ await dhtServer.listen(keyPair)
119
124
  console.log('DHT node is listening on public key', wallet.publicKey);
120
125
  } catch(e) { }
121
126
  }
@@ -108,6 +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
+ wp: { type: 'is_hex_string', length: 64, required: true },
111
112
  w: { type: 'is_hex_string', length: 64, required: true },
112
113
  i: { type: 'is_hex_string', length: 64, required: true },
113
114
  ipk: { type: 'is_hex_string', length: 64, required: true },