trac-msb 0.0.44 → 0.0.45

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.
Files changed (3) hide show
  1. package/msb.mjs +2 -2
  2. package/package.json +7 -7
  3. package/src/index.js +18 -13
package/msb.mjs CHANGED
@@ -4,8 +4,8 @@ const opts = {
4
4
  stores_directory : 'stores/',
5
5
  store_name : typeof process !== "undefined" ? process.argv[2] : Pear.config.args[0],
6
6
  bootstrap: 'e442c6aadc8419c2439552ebecc79ffdc993dd816f9d2d6f562eef56e71ab9ba',
7
- channel: Buffer.alloc(32).fill('00bptracnetworkmainsettlementbus'),
8
- tx : Buffer.alloc(32).fill('bptracnetworkmainsettlementbustx')
7
+ channel: '00bptracnetworkmainsettlementbus',
8
+ tx : 'bptracnetworkmainsettlementbustx'
9
9
  };
10
10
 
11
11
  const msb = new MainSettlementBus(opts);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "trac-msb",
3
3
  "main": "msb.mjs",
4
- "version": "0.0.44",
4
+ "version": "0.0.45",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
@@ -12,6 +12,7 @@
12
12
  "test": "brittle test/*.test.js"
13
13
  },
14
14
  "dependencies": {
15
+ "trac-wallet": "^0.0.33",
15
16
  "autobase": "7.0.45",
16
17
  "b4a": "1.6.7",
17
18
  "bare": "^1.17.1",
@@ -28,12 +29,11 @@
28
29
  "protomux-wakeup": "^2.2.1",
29
30
  "ready-resource": "^1.0.0",
30
31
  "safety-catch": "1.0.2",
31
- "trac-wallet": "^0.0.32",
32
32
  "xache": "1.2.0",
33
33
  "bare-assert": "^1.0.2",
34
34
  "bare-buffer": "^3.1.2",
35
35
  "bare-console": "^6.0.1",
36
- "bare-crypto": "^1.4.1",
36
+ "bare-crypto": "^1.4.2",
37
37
  "bare-events": "^2.5.4",
38
38
  "bare-fs": "^4.0.2",
39
39
  "bare-http1": "^4.0.2",
@@ -49,22 +49,23 @@
49
49
  "bare-subprocess": "^5.0.3",
50
50
  "bare-timers": "^3.0.1",
51
51
  "bare-tls": "^2.0.2",
52
- "bare-tty": "^5.0.2",
52
+ "bare-tty": "^3.2.0",
53
53
  "bare-url": "^2.1.4",
54
54
  "bare-utils": "^1.2.0",
55
55
  "bare-worker": "^3.0.0",
56
56
  "bare-zlib": "^1.2.5",
57
+ "worker_threads": "npm:bare-node-worker-threads",
58
+ "crypto": "npm:bare-node-crypto",
57
59
  "assert": "npm:bare-node-assert",
58
60
  "buffer": "npm:bare-node-buffer",
59
61
  "child_process": "npm:bare-node-child-process",
60
62
  "console": "npm:bare-node-console",
61
- "crypto": "npm:bare-node-crypto",
62
63
  "events": "npm:bare-node-events",
63
64
  "fs": "npm:bare-node-fs",
64
65
  "http": "npm:bare-node-http",
65
66
  "https": "npm:bare-node-https",
66
- "inspector": "npm:bare-node-inspector",
67
67
  "module": "npm:bare-node-module",
68
+ "inspector": "npm:bare-node-inspector",
68
69
  "os": "npm:bare-node-os",
69
70
  "path": "npm:bare-node-path",
70
71
  "process": "npm:bare-node-process",
@@ -76,7 +77,6 @@
76
77
  "tty": "npm:bare-node-tty",
77
78
  "url": "npm:bare-node-url",
78
79
  "util": "npm:bare-node-util",
79
- "worker_threads": "npm:bare-node-worker-threads",
80
80
  "zlib": "npm:bare-node-zlib"
81
81
  },
82
82
  "publishConfig": {
package/src/index.js CHANGED
@@ -11,6 +11,8 @@ import w from 'protomux-wakeup';
11
11
  import PeerWallet from "trac-wallet"
12
12
  import Corestore from 'corestore';
13
13
  import tty from 'tty'
14
+ // removed until PEAR desktop bare-crypto package is fixed
15
+ //import crypto from 'crypto'
14
16
 
15
17
  const wakeup = new w();
16
18
 
@@ -22,14 +24,14 @@ export class MainSettlementBus extends ReadyResource {
22
24
  this.KEY_PAIR_PATH = `${this.STORES_DIRECTORY}${options.store_name}/db/keypair.json`
23
25
  this.store = new Corestore(this.STORES_DIRECTORY + options.store_name);
24
26
  this.swarm = null;
25
- this.tx = options.tx || null;
27
+ this.tx = b4a.alloc(32).fill(options.tx) || null;
26
28
  this.tx_pool = [];
27
29
  this.enable_txchannel = typeof options.enable_txchannel !== "undefined" && options.enable_txchannel === false ? false : true;
28
30
  this.enable_wallet = typeof options.enable_wallet !== "undefined" && options.enable_wallet === false ? false : true;
29
31
  this.enable_updater = typeof options.enable_updater !== "undefined" && options.enable_updater === false ? false : true;
30
32
  this.base = null;
31
33
  this.key = null;
32
- this.channel = options.channel || null;
34
+ this.channel = b4a.alloc(32).fill(options.channel) || null;
33
35
  this.connectedNodes = 1;
34
36
  this.replicate = options.replicate !== false;
35
37
  this.writerLocalKey = null;
@@ -67,9 +69,9 @@ export class MainSettlementBus extends ReadyResource {
67
69
  if (null === await view.get(op.key) &&
68
70
  sanitizeTransaction(postTx) &&
69
71
  postTx.op === 'post-tx' &&
70
- hccrypto.verify(Buffer.from(postTx.tx + postTx.in, 'utf-8'), Buffer.from(postTx.is, 'hex'), Buffer.from(postTx.ipk, 'hex')) &&// sender verification
71
- hccrypto.verify(Buffer.from(postTx.tx + postTx.wn, 'utf-8'), Buffer.from(postTx.ws, 'hex'), Buffer.from(postTx.wp, 'hex')) &&// writer verification
72
- Buffer.byteLength(JSON.stringify(postTx)) <= 4096
72
+ hccrypto.verify(b4a.from(postTx.tx + postTx.in, 'utf-8'), b4a.from(postTx.is, 'hex'), b4a.from(postTx.ipk, 'hex')) &&// sender verification
73
+ hccrypto.verify(b4a.from(postTx.tx + postTx.wn, 'utf-8'), b4a.from(postTx.ws, 'hex'), b4a.from(postTx.wp, 'hex')) &&// writer verification
74
+ b4a.byteLength(JSON.stringify(postTx)) <= 4096
73
75
  ) {
74
76
  await view.put(op.key, op.value);
75
77
  console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
@@ -96,7 +98,7 @@ export class MainSettlementBus extends ReadyResource {
96
98
  }
97
99
  console.log('View Length:', this.base.view.core.length);
98
100
  console.log('View Signed Length:', this.base.view.core.signedLength);
99
- console.log('MSB Key:', new Buffer(this.base.view.core.key).toString('hex'));
101
+ console.log('MSB Key:', b4a.toString(this.base.view.core.key, 'hex'));
100
102
  this.writerLocalKey = b4a.toString(this.base.local.key, 'hex');
101
103
  if (this.replicate) await this._replicate();
102
104
  if (this.enable_txchannel) {
@@ -148,7 +150,7 @@ export class MainSettlementBus extends ReadyResource {
148
150
  return
149
151
  }
150
152
 
151
- if(Buffer.byteLength(msg) > 3072) return;
153
+ if(b4a.byteLength(msg) > 3072) return;
152
154
 
153
155
  try {
154
156
 
@@ -156,12 +158,12 @@ export class MainSettlementBus extends ReadyResource {
156
158
 
157
159
  if (sanitizeTransaction(parsedPreTx) &&
158
160
  parsedPreTx.op === 'pre-tx' &&
159
- hccrypto.verify(Buffer.from(parsedPreTx.tx + parsedPreTx.in, 'utf-8'), Buffer.from(parsedPreTx.is, 'hex'), Buffer.from(parsedPreTx.ipk, 'hex')) &&
161
+ hccrypto.verify(b4a.from(parsedPreTx.tx + parsedPreTx.in, 'utf-8'), b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.ipk, 'hex')) &&
160
162
  parsedPreTx.w === _this.writerLocalKey &&
161
163
  null === await _this.base.view.get(parsedPreTx.tx)
162
164
  ) {
163
165
  const nonce = Math.random() + '-' + Date.now();
164
- const signature = hccrypto.sign(Buffer.from(parsedPreTx.tx + nonce, 'utf-8'), Buffer.from(this.wallet.secretKey, 'hex'));
166
+ const signature = hccrypto.sign(b4a.from(parsedPreTx.tx + nonce, 'utf-8'), b4a.from(this.wallet.secretKey, 'hex'));
165
167
  const append_tx = {
166
168
  op: 'post-tx',
167
169
  tx: parsedPreTx.tx,
@@ -250,13 +252,16 @@ export class MainSettlementBus extends ReadyResource {
250
252
  }
251
253
 
252
254
  async createHash(type, message){
255
+ if(type === 'sha256'){
256
+ const out = b4a.alloc(sodium.crypto_hash_sha256_BYTES);
257
+ sodium.crypto_hash_sha256(out, b4a.from(message));
258
+ return b4a.toString(out, 'hex');
259
+ }
253
260
  let createHash = null;
254
- console.log(message.toLowerCase());
255
- if(typeof crypto.subtle !== 'undefined'){
261
+ if(global.Pear !== undefined){
256
262
  let _type = '';
257
263
  switch(type.toLowerCase()){
258
264
  case 'sha1': _type = 'SHA-1'; break;
259
- case 'sha256': _type = 'SHA-256'; break;
260
265
  case 'sha384': _type = 'SHA-384'; break;
261
266
  case 'sha512': _type = 'SHA-512'; break;
262
267
  default: throw new Error('Unsupported algorithm.');
@@ -269,7 +274,7 @@ export class MainSettlementBus extends ReadyResource {
269
274
  .map((b) => b.toString(16).padStart(2, "0"))
270
275
  .join("");
271
276
  } else {
272
- return createHash(type).update(message).digest('hex')
277
+ return crypto.createHash(type).update(message).digest('hex')
273
278
  }
274
279
  }
275
280