@ocap/util 1.16.5 → 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 +20 -8
  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 multibase = require('multibase');
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,6 +31,18 @@ const DID_PREFIX = 'did:abt:';
31
31
  const zero = new BN(0);
32
32
  const negative1 = new BN(-1);
33
33
 
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') {
40
+ return false;
41
+ }
42
+
43
+ return data[0] === 'z';
44
+ };
45
+
34
46
  /**
35
47
  * Returns a BN object, converts a number value to a BN
36
48
  * @param {String|Number|Object} `arg` input a string number, hex string number, number, BigNumber or BN object
@@ -344,8 +356,8 @@ const toHex = (value, returnType) => {
344
356
  return returnType ? 'bytes' : bytesToHex(value);
345
357
  }
346
358
 
347
- if (multibase.isEncoded(value) === 'base58btc') {
348
- return returnType ? 'bytes' : bytesToHex(multibase.decode(value));
359
+ if (isBase58btc(value)) {
360
+ return returnType ? 'bytes' : bytesToHex(base58btc.decode(value));
349
361
  }
350
362
 
351
363
  if (isBoolean(value)) {
@@ -560,8 +572,8 @@ function toUint8Array(v) {
560
572
  vb = new Uint8Array(hexToBytes(v));
561
573
  } else if (isUint8Array(v)) {
562
574
  vb = new Uint8Array(v);
563
- } else if (multibase.isEncoded(v) === 'base58btc') {
564
- vb = new Uint8Array(multibase.decode(v));
575
+ } else if (isBase58btc(v)) {
576
+ vb = new Uint8Array(base58btc.decode(v));
565
577
  } else if (typeof v === 'string') {
566
578
  vb = new Uint8Array(hexToBytes(toHex(v)));
567
579
  } else {
@@ -596,7 +608,7 @@ function toBuffer(v) {
596
608
  * @throws {Error}
597
609
  */
598
610
  function toBase58(v) {
599
- const buf = multibase.encode('base58btc', toUint8Array(v));
611
+ const buf = base58btc.encode(toUint8Array(v));
600
612
  return Buffer.from(buf).toString('utf-8');
601
613
  }
602
614
 
@@ -609,11 +621,11 @@ function toBase58(v) {
609
621
  * @returns {buffer}
610
622
  */
611
623
  function fromBase58(v) {
612
- if (!multibase.isEncoded(v) === 'base58btc') {
624
+ if (isBase58btc(v) === false) {
613
625
  throw new Error('fromBase58 expect strict base58 encoded string as input');
614
626
  }
615
627
 
616
- return Buffer.from(multibase.decode(v));
628
+ return Buffer.from(base58btc.decode(v));
617
629
  }
618
630
 
619
631
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ocap/util",
3
- "version": "1.16.5",
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
- "multibase": "^3.1.1",
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": "689afc27e0aa3d712fa47449dddea0e2d1a81e1a"
59
+ "gitHead": "15e9623edafa6fcb628f67f0c9e26e64ab01bcd2"
60
60
  }