trac-msb 0.0.44 → 0.0.46

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 +3 -3
  2. package/package.json +7 -7
  3. package/src/index.js +16 -13
package/msb.mjs CHANGED
@@ -3,9 +3,9 @@ import MainSettlementBus from './src/index.js';
3
3
  const opts = {
4
4
  stores_directory : 'stores/',
5
5
  store_name : typeof process !== "undefined" ? process.argv[2] : Pear.config.args[0],
6
- bootstrap: 'e442c6aadc8419c2439552ebecc79ffdc993dd816f9d2d6f562eef56e71ab9ba',
7
- channel: Buffer.alloc(32).fill('00bptracnetworkmainsettlementbus'),
8
- tx : Buffer.alloc(32).fill('bptracnetworkmainsettlementbustx')
6
+ bootstrap: '2cad3a1aeffd0db5eabc8169da8873800f4c2187299b06fffb4059caeddcdd21',
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.46",
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.34",
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.3",
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
@@ -22,14 +22,14 @@ export class MainSettlementBus extends ReadyResource {
22
22
  this.KEY_PAIR_PATH = `${this.STORES_DIRECTORY}${options.store_name}/db/keypair.json`
23
23
  this.store = new Corestore(this.STORES_DIRECTORY + options.store_name);
24
24
  this.swarm = null;
25
- this.tx = options.tx || null;
25
+ this.tx = b4a.alloc(32).fill(options.tx) || null;
26
26
  this.tx_pool = [];
27
27
  this.enable_txchannel = typeof options.enable_txchannel !== "undefined" && options.enable_txchannel === false ? false : true;
28
28
  this.enable_wallet = typeof options.enable_wallet !== "undefined" && options.enable_wallet === false ? false : true;
29
29
  this.enable_updater = typeof options.enable_updater !== "undefined" && options.enable_updater === false ? false : true;
30
30
  this.base = null;
31
31
  this.key = null;
32
- this.channel = options.channel || null;
32
+ this.channel = b4a.alloc(32).fill(options.channel) || null;
33
33
  this.connectedNodes = 1;
34
34
  this.replicate = options.replicate !== false;
35
35
  this.writerLocalKey = null;
@@ -67,9 +67,9 @@ export class MainSettlementBus extends ReadyResource {
67
67
  if (null === await view.get(op.key) &&
68
68
  sanitizeTransaction(postTx) &&
69
69
  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
70
+ hccrypto.verify(b4a.from(postTx.tx + postTx.in, 'utf-8'), b4a.from(postTx.is, 'hex'), b4a.from(postTx.ipk, 'hex')) &&// sender verification
71
+ hccrypto.verify(b4a.from(postTx.tx + postTx.wn, 'utf-8'), b4a.from(postTx.ws, 'hex'), b4a.from(postTx.wp, 'hex')) &&// writer verification
72
+ b4a.byteLength(JSON.stringify(postTx)) <= 4096
73
73
  ) {
74
74
  await view.put(op.key, op.value);
75
75
  console.log(`TX: ${op.key} appended. Signed length: `, _this.base.view.core.signedLength);
@@ -96,7 +96,7 @@ export class MainSettlementBus extends ReadyResource {
96
96
  }
97
97
  console.log('View Length:', this.base.view.core.length);
98
98
  console.log('View Signed Length:', this.base.view.core.signedLength);
99
- console.log('MSB Key:', new Buffer(this.base.view.core.key).toString('hex'));
99
+ console.log('MSB Key:', b4a.toString(this.base.view.core.key, 'hex'));
100
100
  this.writerLocalKey = b4a.toString(this.base.local.key, 'hex');
101
101
  if (this.replicate) await this._replicate();
102
102
  if (this.enable_txchannel) {
@@ -148,7 +148,7 @@ export class MainSettlementBus extends ReadyResource {
148
148
  return
149
149
  }
150
150
 
151
- if(Buffer.byteLength(msg) > 3072) return;
151
+ if(b4a.byteLength(msg) > 3072) return;
152
152
 
153
153
  try {
154
154
 
@@ -156,12 +156,12 @@ export class MainSettlementBus extends ReadyResource {
156
156
 
157
157
  if (sanitizeTransaction(parsedPreTx) &&
158
158
  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')) &&
159
+ hccrypto.verify(b4a.from(parsedPreTx.tx + parsedPreTx.in, 'utf-8'), b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.ipk, 'hex')) &&
160
160
  parsedPreTx.w === _this.writerLocalKey &&
161
161
  null === await _this.base.view.get(parsedPreTx.tx)
162
162
  ) {
163
163
  const nonce = Math.random() + '-' + Date.now();
164
- const signature = hccrypto.sign(Buffer.from(parsedPreTx.tx + nonce, 'utf-8'), Buffer.from(this.wallet.secretKey, 'hex'));
164
+ const signature = hccrypto.sign(b4a.from(parsedPreTx.tx + nonce, 'utf-8'), b4a.from(this.wallet.secretKey, 'hex'));
165
165
  const append_tx = {
166
166
  op: 'post-tx',
167
167
  tx: parsedPreTx.tx,
@@ -250,13 +250,16 @@ export class MainSettlementBus extends ReadyResource {
250
250
  }
251
251
 
252
252
  async createHash(type, message){
253
+ if(type === 'sha256'){
254
+ const out = b4a.alloc(sodium.crypto_hash_sha256_BYTES);
255
+ sodium.crypto_hash_sha256(out, b4a.from(message));
256
+ return b4a.toString(out, 'hex');
257
+ }
253
258
  let createHash = null;
254
- console.log(message.toLowerCase());
255
- if(typeof crypto.subtle !== 'undefined'){
259
+ if(global.Pear !== undefined){
256
260
  let _type = '';
257
261
  switch(type.toLowerCase()){
258
262
  case 'sha1': _type = 'SHA-1'; break;
259
- case 'sha256': _type = 'SHA-256'; break;
260
263
  case 'sha384': _type = 'SHA-384'; break;
261
264
  case 'sha512': _type = 'SHA-512'; break;
262
265
  default: throw new Error('Unsupported algorithm.');
@@ -269,7 +272,7 @@ export class MainSettlementBus extends ReadyResource {
269
272
  .map((b) => b.toString(16).padStart(2, "0"))
270
273
  .join("");
271
274
  } else {
272
- return createHash(type).update(message).digest('hex')
275
+ return crypto.createHash(type).update(message).digest('hex')
273
276
  }
274
277
  }
275
278