trac-msb 0.0.18 → 0.0.20

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": "src/index.js",
4
- "version": "0.0.18",
4
+ "version": "0.0.20",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
package/src/functions.js CHANGED
@@ -11,7 +11,8 @@ export function sanitizeTransaction(parsedTx) {
11
11
  typeof parsedTx.w === 'string' &&
12
12
  typeof parsedTx.i === 'string' &&
13
13
  typeof parsedTx.ipk === 'string' &&
14
- typeof parsedTx.is === 'string'
14
+ typeof parsedTx.is === 'string' &&
15
+ typeof parsedTx.in === 'string'
15
16
  );
16
17
  }
17
18
 
package/src/index.js CHANGED
@@ -64,11 +64,12 @@ export class MainSettlementBus extends ReadyResource {
64
64
  const op = node.value;
65
65
  const postTx = op.value;
66
66
  if (op.type === 'tx') {
67
+ console.log('wn-verified', crypto.verify(Buffer.from(postTx.tx + postTx.wn, 'utf-8'), Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.wp, 'hex')));
67
68
  if (null === await view.get(op.key) &&
68
69
  sanitizeTransaction(postTx) &&
69
70
  postTx.op === 'post-tx' &&
70
- crypto.verify(Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.is, 'hex'), Buffer.from(postTx.ipk, 'hex')) &&// sender verification
71
- crypto.verify(Buffer.from(postTx.tx, 'utf-8'), Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.wp, 'hex')) &&// writer verification
71
+ crypto.verify(Buffer.from(postTx.tx + postTx.in, 'utf-8'), Buffer.from(postTx.is, 'hex'), Buffer.from(postTx.ipk, 'hex')) &&// sender verification
72
+ crypto.verify(Buffer.from(postTx.tx + postTx.wn, 'utf-8'), Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.wp, 'hex')) &&// writer verification
72
73
  Buffer.byteLength(JSON.stringify(postTx)) <= 4096
73
74
  ) {
74
75
  await view.put(op.key, op.value);
@@ -116,7 +117,9 @@ export class MainSettlementBus extends ReadyResource {
116
117
 
117
118
  async updater(){
118
119
  while(true){
119
- await this.base.append(null);
120
+ if(this.base.writable){
121
+ await this.base.append(null);
122
+ }
120
123
  await this.sleep(10_000);
121
124
  }
122
125
  }
@@ -152,13 +155,16 @@ export class MainSettlementBus extends ReadyResource {
152
155
 
153
156
  const parsedPreTx = JSON.parse(msg);
154
157
 
158
+ console.log('in-verified', crypto.verify(Buffer.from(parsedPreTx.tx + parsedPreTx.in, 'utf-8'), Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.ipk, 'hex')))
159
+
155
160
  if (sanitizeTransaction(parsedPreTx) &&
156
161
  parsedPreTx.op === 'pre-tx' &&
157
- crypto.verify(Buffer.from(parsedPreTx.tx, 'utf-8'), Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.ipk, 'hex')) &&
162
+ crypto.verify(Buffer.from(parsedPreTx.tx + parsedPreTx.in, 'utf-8'), Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.ipk, 'hex')) &&
158
163
  parsedPreTx.w === _this.writerLocalKey &&
159
164
  null === await _this.base.view.get(parsedPreTx.tx)
160
165
  ) {
161
- const signature = crypto.sign(Buffer.from(parsedPreTx.tx, 'utf-8'), Buffer.from(this.wallet.secretKey, 'hex'));
166
+ const nonce = Math.random() + '-' + Date.now();
167
+ const signature = crypto.sign(Buffer.from(parsedPreTx.tx + nonce, 'utf-8'), Buffer.from(this.wallet.secretKey, 'hex'));
162
168
  const append_tx = {
163
169
  op: 'post-tx',
164
170
  tx: parsedPreTx.tx,
@@ -169,6 +175,7 @@ export class MainSettlementBus extends ReadyResource {
169
175
  ch: parsedPreTx.ch,
170
176
  in: parsedPreTx.in,
171
177
  ws: signature.toString('hex'),
178
+ wn : nonce,
172
179
  wp: this.wallet.publicKey,
173
180
  };
174
181
  _this.tx_pool.push({ tx: parsedPreTx.tx, append_tx : append_tx });