trac-msb 0.0.78 → 0.0.79

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": "msb.mjs",
4
- "version": "0.0.78",
4
+ "version": "0.0.79",
5
5
  "pear": {
6
6
  "name": "trac-msb",
7
7
  "type": "terminal"
@@ -35,10 +35,9 @@ export async function sleep(ms) {
35
35
  export async function createHash(type, message) {
36
36
  if (type === 'sha256') {
37
37
  const out = b4a.alloc(sodium.crypto_hash_sha256_BYTES);
38
- sodium.crypto_hash_sha256(out, b4a.from(message));
38
+ sodium.crypto_hash_sha256(out,!b4a.isBuffer(message) ? b4a.from(message) : message);
39
39
  return b4a.toString(out, 'hex');
40
40
  }
41
- let createHash = null;
42
41
  if (global.Pear !== undefined) {
43
42
  let _type = '';
44
43
  switch (type.toLowerCase()) {
@@ -48,13 +47,15 @@ export async function createHash(type, message) {
48
47
  default: throw new Error('Unsupported algorithm.');
49
48
  }
50
49
  const encoder = new TextEncoder();
51
- const data = encoder.encode(message);
50
+ const data = encoder.encode(b4a.isBuffer(message) ? b4a.toString(message, 'utf-8') : message);
52
51
  const hash = await crypto.subtle.digest(_type, data);
53
52
  const hashArray = Array.from(new Uint8Array(hash));
54
53
  return hashArray
55
54
  .map((b) => b.toString(16).padStart(2, "0"))
56
55
  .join("");
57
56
  } else {
58
- return nodeCreateHash(type).update(message).digest('hex');
57
+ // this is only available here for completeness and in fact will never be used in the MSB.
58
+ // just keep it as it is.
59
+ return crypto.createHash(type).update(!b4a.isBuffer(message) ? b4a.from(message) : message).digest('hex')
59
60
  }
60
61
  }
@@ -1,5 +1,5 @@
1
1
  import ReadyResource from 'ready-resource';
2
- import { createHash } from 'crypto';
2
+ import { createHash } from 'utils/functions.js';
3
3
  import fs from 'fs';
4
4
  //TODO: GENERATE NONCE WITH CRYPTO LIBRARY WHICH ALLOW US TO GENERATE IT WITH UNIFORM DISTRIBUTION.
5
5
 
@@ -25,7 +25,7 @@ export class WriterManager extends ReadyResource {
25
25
  ]
26
26
  )
27
27
 
28
- const hash = createHash('sha256').update(msg).digest('hex');
28
+ const hash = await createHash('sha256', msg);
29
29
  await this.msbInstance.base.append({
30
30
  type: 'addAdmin',
31
31
  key: 'admin',
@@ -57,7 +57,7 @@ export class WriterManager extends ReadyResource {
57
57
  Buffer.from(nonce),
58
58
  ]
59
59
  )
60
- const hash = createHash('sha256').update(msg).digest('hex');
60
+ const hash = await createHash('sha256', msg);
61
61
  await this.msbInstance.base.append({
62
62
  type: 'whitelist',
63
63
  key: 'list',