@ocap/util 1.16.6 → 1.16.9

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/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  // Generate by [js2dts@0.3.3](https://github.com/whxaxes/js2dts#readme)
2
2
 
3
+ import * as bnJs from 'bn.js';
3
4
  /**
4
5
  * Validates if a value is an Uint8Array.
5
6
  *
@@ -106,15 +107,15 @@ declare function toAddress(did: string): string;
106
107
  declare const _Lib: _Lib.T100;
107
108
  declare namespace _Lib {
108
109
  export interface T100 {
109
- BN: any;
110
+ BN: typeof bnJs;
110
111
  isBN: (object: any) => boolean;
111
112
  isBigNumber: (object: any) => boolean;
112
113
  isHexPrefixed: (str: string) => boolean;
113
114
  stripHexPrefix: (str: string) => any;
114
115
  utf8ToHex: (str: string) => string;
115
116
  hexToUtf8: (hex: string) => string;
116
- numberToHex: (value: any) => string;
117
- hexToNumber: (value: any) => number;
117
+ numberToHex: (value: string | number | bnJs) => string;
118
+ hexToNumber: (value: string | number | bnJs) => number;
118
119
  isHex: (hex: string) => boolean;
119
120
  isHexStrict: (hex: string) => boolean;
120
121
  isUint8Array: typeof isUint8Array;
@@ -123,8 +124,8 @@ declare namespace _Lib {
123
124
  toHex: (value: any, returnType: boolean) => string;
124
125
  numberToString: (arg: any) => any;
125
126
  fromUnitToToken: (input: string | number, decimal?: number, optionsInput?: any) => string;
126
- fromTokenToUnit: (input: string, decimal?: number) => any;
127
- toBN: (number: any) => any;
127
+ fromTokenToUnit: (input: string, decimal?: number) => bnJs;
128
+ toBN: (number: string | number | bnJs) => bnJs;
128
129
  toUint8Array: typeof toUint8Array;
129
130
  toBuffer: typeof toBuffer;
130
131
  toBase58: typeof toBase58;
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,9 +1,8 @@
1
1
  {
2
2
  "name": "@ocap/util",
3
- "version": "1.16.6",
3
+ "version": "1.16.9",
4
4
  "description": "utils shared across multiple forge js libs, works in both node.js and browser",
5
5
  "keywords": [
6
- "forge",
7
6
  "arcblock",
8
7
  "node.js",
9
8
  "browser",
@@ -15,8 +14,8 @@
15
14
  "dependencies": {
16
15
  "base64-url": "^2.3.3",
17
16
  "bn.js": "5.2.0",
17
+ "bs58": "^5.0.0",
18
18
  "lodash": "^4.17.21",
19
- "multibase": "^3.1.1",
20
19
  "utf8": "^3.0.0"
21
20
  },
22
21
  "resolutions": {
@@ -25,13 +24,16 @@
25
24
  },
26
25
  "devDependencies": {
27
26
  "jest": "^27.3.1",
28
- "jsdoc-to-markdown": "^5.0.0"
27
+ "jsdoc-to-markdown": "^7.1.1"
29
28
  },
30
29
  "author": {
31
30
  "name": "wangshijun",
32
31
  "email": "shijun@arcblock.io",
33
32
  "url": "https://github.com/wangshijun"
34
33
  },
34
+ "contributors": [
35
+ "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
36
+ ],
35
37
  "homepage": "https://github.com/ArcBlock/asset-chain/tree/master/core/forge-util",
36
38
  "license": "Apache-2.0",
37
39
  "main": "lib/index.js",
@@ -56,5 +58,5 @@
56
58
  "bugs": {
57
59
  "url": "https://github.com/ArcBlock/asset-chain/issues"
58
60
  },
59
- "gitHead": "c37106e25f4ac2b4e64230e5ab559bdafb5a6a7e"
61
+ "gitHead": "16fb7ce43033d07f83794914f2d5dda731f80814"
60
62
  }