trac-msb 0.0.82 → 0.0.83

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.
@@ -2,4 +2,5 @@ e247a9ceefb8a83e28d3c5845055910bc61e0b418c7578d297354708f276af04
2
2
  580c44d7827fbeeb7778e4d2dce660b30f3ca3baa4de254ecd556dfb5b60fc35
3
3
  a3590854889d059927fed4dfdf329b75447bc9f5885b6a843b317d1c2d38258a
4
4
  dd2f83c9cb1d146c8be6c1d98822cbbb3f631a0659b765c9e4564960acf6e228
5
- 726b2885e551a98c20b37675b113476390f57321768a303e1b6c029ffca509a9
5
+ 726b2885e551a98c20b37675b113476390f57321768a303e1b6c029ffca509a9
6
+ 7da7f48e1c805b551fd69a2b6e59b99c00740dea699c66e10b88bd1efb932815
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.82",
4
+ "version": "0.0.83",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/network.js CHANGED
@@ -64,32 +64,33 @@ class Network {
64
64
  try{
65
65
  dhtServer.on('connection', function (connection) {
66
66
  connection.on('message', async (msg) => {
67
- msg = b4a.toString(msg, 'utf-8');
68
- msg = JSON.parse(msg);
69
- if(msg === 'get_writer_key'){
70
- await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
71
- } else if(msg.op !== undefined && msg.message !== undefined && msg.op === 'add_writer'){
72
- const adminEntry = await msb.getSigned(EntryType.ADMIN);
73
- const nodeEntry = await msb.getSigned(msg.message.pk);
74
- const isAlreadyWriter = !!(nodeEntry && nodeEntry.isWriter);
75
- const isAllowedToRequestRole = await msb.isAllowedToRequestRole(msg.message.pk, adminEntry);
76
- const canAddWriter = !!(!base.writable && !isAlreadyWriter && isAllowedToRequestRole);
77
- if(null !== adminEntry && adminEntry.tracPublicKey === wallet.publicKey
78
- && msg.message.pk !== wallet.publicKey && canAddWriter){
79
- await base.append(msg.message);
80
- }
81
- } else {
82
- if (base.isIndexer || !base.writable) return;
67
+ try{
68
+ msg = b4a.toString(msg, 'utf-8');
69
+ msg = JSON.parse(msg);
70
+ if(msg === 'get_writer_key'){
71
+ await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
72
+ } else if(msg.op !== undefined && msg.message !== undefined && msg.op === 'add_writer'){
73
+ msg = msg.value;
74
+ const adminEntry = await msb.getSigned(EntryType.ADMIN);
75
+ const nodeEntry = await msb.getSigned(msg.message.pub);
76
+ const isAlreadyWriter = !!(nodeEntry && nodeEntry.isWriter);
77
+ const isAllowedToRequestRole = await msb.isAllowedToRequestRole(msg.message.pub, adminEntry);
78
+ const canAddWriter = !!(!base.writable && !isAlreadyWriter && isAllowedToRequestRole);
79
+ if(null !== adminEntry && adminEntry.tracPublicKey === wallet.publicKey
80
+ && msg.message.pub !== wallet.publicKey && canAddWriter){
81
+ await base.append(msg.message);
82
+ }
83
+ } else {
84
+ if (base.isIndexer || !base.writable) return;
83
85
 
84
- // TODO: decide if a tx rejection should be responded with
85
- if (networkInstance.tx_pool.length >= 1000) {
86
- console.log('pool full');
87
- return
88
- }
86
+ // TODO: decide if a tx rejection should be responded with
87
+ if (networkInstance.tx_pool.length >= 1000) {
88
+ console.log('pool full');
89
+ return
90
+ }
89
91
 
90
- if (b4a.byteLength(msg) > 3072) return;
92
+ if (b4a.byteLength(msg) > 3072) return;
91
93
 
92
- try {
93
94
  const parsedPreTx = msg;
94
95
 
95
96
  if (networkInstance.check.sanitizePreTx(parsedPreTx) &&
@@ -116,11 +117,11 @@ class Network {
116
117
  };
117
118
  networkInstance.tx_pool.push({ tx: parsedPreTx.tx, append_tx: append_tx });
118
119
  }
119
- } catch (e) {
120
- console.log(e)
121
120
  }
121
+ //await connection.destroy();
122
+ }catch(e){
123
+ console.log(e);
122
124
  }
123
- //await connection.destroy();
124
125
  });
125
126
  connection.on('close', () => { });
126
127
  connection.on('error', (error) => { });
@@ -69,7 +69,7 @@ class Check {
69
69
  value: {
70
70
  $$strict: true,
71
71
  $$type: "object",
72
- pk: { type: 'is_hex_string', length: 64, required: true },
72
+ pub: { type: 'is_hex_string', length: 64, required: true },
73
73
  wk: { type: 'is_hex_string', length: 64, required: true },
74
74
  nonce: { type: 'string', min: 1, max: 256, required: true },
75
75
  sig: { type: 'is_hex_string', length: 128, required: true },
@@ -39,7 +39,7 @@ class MsgUtils {
39
39
  msg = this.createMessage(wallet.publicKey, keyParam, nonce, operationType);
40
40
  hash = await createHash('sha256', msg);
41
41
  value = {
42
- pk : wallet.publicKey,
42
+ pub : wallet.publicKey,
43
43
  wk: keyParam,
44
44
  nonce: nonce,
45
45
  sig: wallet.sign(hash)