@ocap/util 1.16.7 → 1.16.8

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 (2) hide show
  1. package/lib/index.js +10 -13
  2. package/package.json +3 -3
package/lib/index.js CHANGED
@@ -22,7 +22,7 @@ const camelCase = require('lodash/camelCase');
22
22
  const isNull = require('lodash/isNull');
23
23
  const rightPad = require('lodash/padEnd');
24
24
  const leftPad = require('lodash/padStart');
25
- const { base58btc } = require('multiformats/bases/base58');
25
+ const base58 = require('bs58');
26
26
  const utf8 = require('utf8');
27
27
  const base64 = require('base64-url');
28
28
  const BN = require('bn.js');
@@ -31,15 +31,12 @@ const DID_PREFIX = 'did:abt:';
31
31
  const zero = new BN(0);
32
32
  const negative1 = new BN(-1);
33
33
 
34
- const textDecoder = new TextDecoder();
35
- const decodeText = (bytes) => textDecoder.decode(bytes);
36
- const isBase58Encoded = (data) => {
37
- if (data instanceof Uint8Array) {
38
- data = decodeText(data);
39
- }
40
-
41
- // Ensure bufOrString is a string
42
- if (Object.prototype.toString.call(data) !== '[object String]') {
34
+ const base58btc = {
35
+ encode: (v) => `z${base58.encode(v)}`,
36
+ decode: (v) => base58.decode(v.slice(1)),
37
+ };
38
+ const isBase58btc = (data) => {
39
+ if (typeof data !== 'string') {
43
40
  return false;
44
41
  }
45
42
 
@@ -359,7 +356,7 @@ const toHex = (value, returnType) => {
359
356
  return returnType ? 'bytes' : bytesToHex(value);
360
357
  }
361
358
 
362
- if (isBase58Encoded(value)) {
359
+ if (isBase58btc(value)) {
363
360
  return returnType ? 'bytes' : bytesToHex(base58btc.decode(value));
364
361
  }
365
362
 
@@ -575,7 +572,7 @@ function toUint8Array(v) {
575
572
  vb = new Uint8Array(hexToBytes(v));
576
573
  } else if (isUint8Array(v)) {
577
574
  vb = new Uint8Array(v);
578
- } else if (isBase58Encoded(v)) {
575
+ } else if (isBase58btc(v)) {
579
576
  vb = new Uint8Array(base58btc.decode(v));
580
577
  } else if (typeof v === 'string') {
581
578
  vb = new Uint8Array(hexToBytes(toHex(v)));
@@ -624,7 +621,7 @@ function toBase58(v) {
624
621
  * @returns {buffer}
625
622
  */
626
623
  function fromBase58(v) {
627
- if (isBase58Encoded(v) === false) {
624
+ if (isBase58btc(v) === false) {
628
625
  throw new Error('fromBase58 expect strict base58 encoded string as input');
629
626
  }
630
627
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocap/util",
3
- "version": "1.16.7",
3
+ "version": "1.16.8",
4
4
  "description": "utils shared across multiple forge js libs, works in both node.js and browser",
5
5
  "keywords": [
6
6
  "forge",
@@ -15,8 +15,8 @@
15
15
  "dependencies": {
16
16
  "base64-url": "^2.3.3",
17
17
  "bn.js": "5.2.0",
18
+ "bs58": "^5.0.0",
18
19
  "lodash": "^4.17.21",
19
- "multiformats": "^9.6.5",
20
20
  "utf8": "^3.0.0"
21
21
  },
22
22
  "resolutions": {
@@ -56,5 +56,5 @@
56
56
  "bugs": {
57
57
  "url": "https://github.com/ArcBlock/asset-chain/issues"
58
58
  },
59
- "gitHead": "2d9b07c134cf57b6f73bf1ff2e76406fb682318e"
59
+ "gitHead": "15e9623edafa6fcb628f67f0c9e26e64ab01bcd2"
60
60
  }