trac-peer 0.0.21 → 0.0.23

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-peer",
3
3
  "main": "src/index.js",
4
- "version": "0.0.21",
4
+ "version": "0.0.23",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "autobase": "7.0.45",
package/src/feature.js CHANGED
@@ -20,7 +20,7 @@ class Feature {
20
20
  key : key,
21
21
  hash : hash,
22
22
  value : value,
23
- nonce : Math.random()
23
+ nonce : Math.random() + '-' + Date.now()
24
24
  }
25
25
  }});
26
26
  }
package/src/functions.js CHANGED
@@ -90,7 +90,7 @@ export async function setAutoAddWriters(input, peer){
90
90
  const splitted = input.split(' ');
91
91
  const value = splitted[1];
92
92
  if(value !== 'on' && value !== 'off') throw new Error('setAutoAddWriters: use on and off values.');
93
- const msg = { type: 'setAutoAddWriters', key: value, nonce : Math.random() }
93
+ const msg = { type: 'setAutoAddWriters', key: value, nonce : Math.random() + '-' + Date.now() }
94
94
  const signature = {
95
95
  msg: msg
96
96
  };
@@ -108,7 +108,7 @@ export async function addAdmin(input, peer){
108
108
  export async function addWriter(input, peer){
109
109
  const splitted = input.split(' ');
110
110
  if(splitted[0] === '/add_indexer'){
111
- const msg = { type: 'addIndexer', key: splitted[splitted.length - 1], nonce : Math.random() }
111
+ const msg = { type: 'addIndexer', key: splitted[splitted.length - 1], nonce : Math.random() + '-' + Date.now() }
112
112
  const signature = {
113
113
  msg: msg
114
114
  };
@@ -116,7 +116,7 @@ export async function addWriter(input, peer){
116
116
  signature['hash'] = hash;
117
117
  peer.emit('announce', { op : 'append_writer', type: 'addIndexer', key: splitted[splitted.length - 1], value: signature });
118
118
  } else if(splitted[0] === '/add_writer') {
119
- const msg = { type: 'addWriter', key: splitted[splitted.length - 1], nonce : Math.random() }
119
+ const msg = { type: 'addWriter', key: splitted[splitted.length - 1], nonce : Math.random() + '-' + Date.now() }
120
120
  const signature = {
121
121
  msg: msg
122
122
  };
package/src/index.js CHANGED
@@ -92,7 +92,7 @@ export class Peer extends ReadyResource {
92
92
  typeof op.value.dispatch.value !== "undefined" &&
93
93
  null === await view.get('sh/'+op.value.dispatch.hash)){
94
94
  const verified = _this.wallet.verify(op.value.dispatch.hash, JSON.stringify(op.value.dispatch.value), admin.value);
95
- if(verified){
95
+ if(verified) {
96
96
  await _this.contract_instance.dispatch(op, node, view);
97
97
  }
98
98
  await view.put('sh/'+op.value.dispatch.hash, '');
@@ -103,41 +103,41 @@ export class Peer extends ReadyResource {
103
103
  if(null !== admin &&
104
104
  op.value.msg.key === op.key &&
105
105
  op.value.msg.type === 'addIndexer' &&
106
- null === await view.get('sh/'+op.op.value.hash)) {
106
+ null === await view.get('sh/'+op.value.hash)) {
107
107
  const verified = _this.wallet.verify(op.value.hash, JSON.stringify(op.value.msg), admin.value);
108
108
  if(verified){
109
109
  const writerKey = b4a.from(op.key, 'hex');
110
110
  await base.addWriter(writerKey);
111
111
  console.log(`Indexer added: ${op.key}`);
112
112
  }
113
- await view.put('sh/'+op.op.value.hash, '');
113
+ await view.put('sh/'+op.value.hash, '');
114
114
  }
115
115
  } else if (op.type === 'addWriter') {
116
116
  const admin = await view.get('admin');
117
117
  if(null !== admin &&
118
118
  op.value.msg.key === op.key &&
119
119
  op.value.msg.type === 'addWriter' &&
120
- null === await view.get('sh/'+op.op.value.hash)) {
120
+ null === await view.get('sh/'+op.value.hash)) {
121
121
  const verified = _this.wallet.verify(op.value.hash, JSON.stringify(op.value.msg), admin.value);
122
122
  if(verified){
123
123
  const writerKey = b4a.from(op.key, 'hex');
124
124
  await base.addWriter(writerKey, { isIndexer : false });
125
125
  console.log(`Writer added: ${op.key}`);
126
126
  }
127
- await view.put('sh/'+op.op.value.hash, '');
127
+ await view.put('sh/'+op.value.hash, '');
128
128
  }
129
129
  } else if (op.type === 'setAutoAddWriters') {
130
130
  const admin = await view.get('admin');
131
131
  if(null !== admin && op.value.msg.key === op.key &&
132
132
  op.value.msg.type === 'setAutoAddWriters' &&
133
133
  (op.key === 'on' || op.key === 'off') &&
134
- null === await view.get('sh/'+op.op.value.hash)) {
134
+ null === await view.get('sh/'+op.value.hash)) {
135
135
  const verified = _this.wallet.verify(op.value.hash, JSON.stringify(op.value.msg), admin.value);
136
136
  if(verified){
137
137
  await view.put('auto_add_writers', op.key);
138
138
  console.log(`Set auto_add_writers: ${op.key}`);
139
139
  }
140
- await view.put('sh/'+op.op.value.hash, '');
140
+ await view.put('sh/'+op.value.hash, '');
141
141
  }
142
142
  } else if (op.type === 'autoAddWriter') {
143
143
  const auto_add_writers = await view.get('auto_add_writers');
package/src/protocol.js CHANGED
@@ -30,7 +30,7 @@ class Protocol{
30
30
  this.base.localWriter !== null &&
31
31
  this.tokenized_input !== null)
32
32
  {
33
- this.nonce = Date.now();
33
+ this.nonce = Math.random() + '-' + Date.now();
34
34
  const MSBwriter = writer;
35
35
  const content_hash = createHash('sha256').update(JSON.stringify(obj)).digest('hex');
36
36
  let tx = createHash('sha256').update(