@ocap/util 1.16.16 → 1.17.1

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.
@@ -0,0 +1 @@
1
+ export declare const DEFAULT_TOKEN_DECIMAL = 18;
package/lib/constant.js CHANGED
@@ -1,3 +1,4 @@
1
- module.exports = Object.freeze({
2
- DEFAULT_TOKEN_DECIMAL: 18,
3
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_TOKEN_DECIMAL = void 0;
4
+ exports.DEFAULT_TOKEN_DECIMAL = 18;
@@ -0,0 +1 @@
1
+ export declare const createSortedList: (list: $TSFixMe) => unknown[];
@@ -1,6 +1,10 @@
1
- const uniq = require('lodash/uniq');
2
- const flatten = require('lodash/flatten');
3
-
4
- const createSortedList = (list) => uniq(flatten(list)).filter(Boolean).sort();
5
-
6
- module.exports = createSortedList;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createSortedList = void 0;
7
+ const uniq_1 = __importDefault(require("lodash/uniq"));
8
+ const flatten_1 = __importDefault(require("lodash/flatten"));
9
+ const createSortedList = (list) => (0, uniq_1.default)((0, flatten_1.default)(list)).filter(Boolean).sort();
10
+ exports.createSortedList = createSortedList;
package/lib/error.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export declare class CustomError extends Error {
2
+ code: string;
3
+ props: {
4
+ persist: boolean;
5
+ [prop: string]: $TSFixMe;
6
+ };
7
+ constructor(code: string, message: string, props?: {});
8
+ }
package/lib/error.js CHANGED
@@ -1,14 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomError = void 0;
1
4
  class CustomError extends Error {
2
- constructor(code = 'GENERIC', message, props = {}) {
3
- super(message);
4
-
5
- if (Error.captureStackTrace) {
6
- Error.captureStackTrace(this, CustomError);
5
+ constructor(code, message, props = {}) {
6
+ super(message);
7
+ if (Error.captureStackTrace) {
8
+ Error.captureStackTrace(this, CustomError);
9
+ }
10
+ this.code = code;
11
+ this.props = Object.assign({ persist: false }, props);
7
12
  }
8
-
9
- this.code = code;
10
- this.props = { persist: false, ...props };
11
- }
12
13
  }
13
-
14
- module.exports = CustomError;
14
+ exports.CustomError = CustomError;
@@ -0,0 +1 @@
1
+ export declare const getListField: (obj: $TSFixMe, key: string) => any;
@@ -1,5 +1,9 @@
1
- const get = require('lodash/get');
2
-
3
- const getListField = (obj, key) => get(obj, `${key}List`) || get(obj, key) || [];
4
-
5
- module.exports = getListField;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getListField = void 0;
7
+ const get_1 = __importDefault(require("lodash/get"));
8
+ const getListField = (obj, key) => (0, get_1.default)(obj, `${key}List`) || (0, get_1.default)(obj, key) || [];
9
+ exports.getListField = getListField;
@@ -0,0 +1 @@
1
+ export declare const getRelatedAddresses: (state: $TSFixMe) => any[];
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRelatedAddresses = void 0;
1
4
  const getRelatedAddresses = (state) => [state.address].concat(state.migratedFrom || []).filter(Boolean);
2
-
3
- module.exports = getRelatedAddresses;
5
+ exports.getRelatedAddresses = getRelatedAddresses;
package/lib/index.d.ts CHANGED
@@ -1,6 +1,192 @@
1
- // Generate by [js2dts@0.3.3](https://github.com/whxaxes/js2dts#readme)
2
-
3
- import * as bnJs from 'bn.js';
1
+ /// <reference types="node" />
2
+ /// <reference types="jest" />
3
+ import rightPad from 'lodash/padEnd';
4
+ import leftPad from 'lodash/padStart';
5
+ import BN from 'bn.js';
6
+ export declare type BytesType = string | Buffer | Uint8Array;
7
+ export declare type EncodingType = 'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer';
8
+ export declare type KeyPairType = {
9
+ publicKey: BytesType;
10
+ secretKey: BytesType;
11
+ };
12
+ export { BN, leftPad, rightPad };
13
+ /**
14
+ * Returns a BN object, converts a number value to a BN
15
+ * @param {String|Number|Object} `arg` input a string number, hex string number, number, BigNumber or BN object
16
+ * @return {Object} `output` BN object of the number
17
+ * @throws if the argument is not an array, object that isn't a bignumber, not a string number or number
18
+ */
19
+ export declare const numberToBN: (arg: string | number | BN) => BN;
20
+ /**
21
+ * Returns a `boolean` on whether or not the `string` starts with '0x'
22
+ *
23
+ * @public
24
+ * @static
25
+ * @param {String} str the string input value
26
+ * @return {Boolean} a boolean if it is or is not hex prefixed
27
+ * @throws if the str input is not a string
28
+ */
29
+ export declare const isHexPrefixed: (str: string) => boolean;
30
+ /**
31
+ * Removes '0x' from a given `String` if present
32
+ *
33
+ * @public
34
+ * @static
35
+ * @param {String} str the string value
36
+ * @return {String|Optional} a string by pass if necessary
37
+ */
38
+ export declare const stripHexPrefix: (str: $TSFixMe) => any;
39
+ /**
40
+ * Returns true if object is BN, otherwise false
41
+ *
42
+ * @public
43
+ * @static
44
+ * @method isBN
45
+ * @param {Object} object
46
+ * @returns {Boolean}
47
+ */
48
+ export declare const isBN: (object: $TSFixMe) => boolean;
49
+ /**
50
+ * Returns true if object is BigNumber, otherwise false
51
+ *
52
+ * @public
53
+ * @static
54
+ * @method isBigNumber
55
+ * @param {Object} object
56
+ * @returns {Boolean}
57
+ */
58
+ export declare const isBigNumber: (object: $TSFixMe) => boolean;
59
+ /**
60
+ * Check if string is HEX, requires a 0x in front
61
+ *
62
+ * @public
63
+ * @static
64
+ * @method isHexStrict
65
+ * @param {String} hex to be checked
66
+ * @returns {Boolean}
67
+ */
68
+ export declare const isHexStrict: (hex: string) => boolean;
69
+ /**
70
+ * Check if string is HEX
71
+ *
72
+ * @public
73
+ * @static
74
+ * @method isHex
75
+ * @param {String} hex to be checked
76
+ * @returns {Boolean}
77
+ */
78
+ export declare const isHex: (hex: string) => boolean;
79
+ /**
80
+ * Takes an input and transforms it into an BN
81
+ *
82
+ * @public
83
+ * @static
84
+ * @method toBN
85
+ * @param {Number|String|BN} num, string, HEX string or BN
86
+ * @returns {BN} BN
87
+ */
88
+ export declare const toBN: (num: number | string | BN, base?: number | 'hex') => BN;
89
+ /**
90
+ * Should be called to get hex representation (prefixed by 0x) of utf8 string
91
+ *
92
+ * @public
93
+ * @static
94
+ * @method utf8ToHex
95
+ * @param {String} str
96
+ * @returns {String} hex representation of input string
97
+ */
98
+ export declare const utf8ToHex: (str: string) => string;
99
+ /**
100
+ * Should be called to get utf8 from it's hex representation
101
+ *
102
+ * @public
103
+ * @static
104
+ * @method hexToUtf8
105
+ * @param {String} hex
106
+ * @returns {String} ascii string representation of hex value
107
+ */
108
+ export declare const hexToUtf8: (hex: string) => string;
109
+ /**
110
+ * Converts value to number representation
111
+ *
112
+ * @public
113
+ * @static
114
+ * @method hexToNumber
115
+ * @param {String|Number|BN} value
116
+ * @returns {Number}
117
+ */
118
+ export declare const hexToNumber: (value: string | number | BN) => string | number | BN;
119
+ /**
120
+ * Converts value to hex representation
121
+ *
122
+ * @public
123
+ * @static
124
+ * @method numberToHex
125
+ * @param {String|Number|BN} value
126
+ * @returns {String}
127
+ */
128
+ export declare const numberToHex: (value: $TSFixMe) => string;
129
+ /**
130
+ * Convert a byte array to a hex string
131
+ * Note: Implementation from crypto-js
132
+ *
133
+ * @public
134
+ * @static
135
+ * @method bytesToHex
136
+ * @param {Array} bytes
137
+ * @returns {String} the hex string
138
+ */
139
+ export declare const bytesToHex: (bytes: $TSFixMe) => string;
140
+ /**
141
+ * Convert a hex string to a byte array
142
+ * Note: Implementation from crypto-js
143
+ *
144
+ * @public
145
+ * @static
146
+ * @method hexToBytes
147
+ * @param {String} hex
148
+ * @returns {Array} the byte array
149
+ */
150
+ export declare const hexToBytes: (hex: $TSFixMe) => number[];
151
+ /**
152
+ * Auto converts any given value into it's hex representation.
153
+ * And even stringify objects before.
154
+ *
155
+ * @public
156
+ * @static
157
+ * @method toHex
158
+ * @param {String|Number|BN|Object|TypedArray|Buffer} value
159
+ * @param {Boolean} returnType
160
+ * @returns {String}
161
+ */
162
+ export declare const toHex: (value: string | number | boolean | BN | Uint8Array | Buffer | (number | {
163
+ test: string;
164
+ })[] | {
165
+ test: string;
166
+ }, returnType?: boolean) => string;
167
+ export declare const numberToString: (arg: $TSFixMe) => any;
168
+ /**
169
+ * Format a big number to human readable number, such as 1_0000_0000_0000_000 => 1 Token
170
+ *
171
+ * @public
172
+ * @static
173
+ * @method fromUnitToToken
174
+ * @param {string|number} input
175
+ * @param {number} [decimal=18]
176
+ * @param {object} [optionsInput=undefined]
177
+ * @returns {string}
178
+ */
179
+ export declare const fromUnitToToken: (input: string | number | BN, decimal?: number, optionsInput?: $TSFixMe) => string;
180
+ /**
181
+ * Convert human readable token number to big number instance
182
+ *
183
+ * @public
184
+ * @static
185
+ * @param {string} input
186
+ * @param {number} [decimal=18]
187
+ * @returns {BN}
188
+ */
189
+ export declare const fromTokenToUnit: (input: string | number, decimal?: number) => BN;
4
190
  /**
5
191
  * Validates if a value is an Uint8Array.
6
192
  *
@@ -9,7 +195,24 @@ import * as bnJs from 'bn.js';
9
195
  * @param {*} value - value to validate
10
196
  * @returns {Boolean} boolean indicating if a value is an Uint8Array
11
197
  */
12
- declare function isUint8Array(value: any): boolean;
198
+ export declare function isUint8Array(value: $TSFixMe): boolean;
199
+ /**
200
+ * Generate a random UUID
201
+ *
202
+ * @public
203
+ * @static
204
+ * @returns {string} Generated uuid
205
+ */
206
+ export declare function UUID(): string;
207
+ /**
208
+ * Check if a string is valid UUID
209
+ *
210
+ * @public
211
+ * @static
212
+ * @param {string} str
213
+ * @returns {boolean}
214
+ */
215
+ export declare function isUUID(str: string): boolean;
13
216
  /**
14
217
  * Convert input to Uint8Array on best effort, base64 node supported
15
218
  *
@@ -19,7 +222,7 @@ declare function isUint8Array(value: any): boolean;
19
222
  * @returns {Uint8Array}
20
223
  * @throws {Error}
21
224
  */
22
- declare function toUint8Array(v: any): Uint8Array;
225
+ export declare function toUint8Array(v: $TSFixMe): Uint8Array;
23
226
  /**
24
227
  * Convert input to Buffer on best effort, base64 not supported
25
228
  *
@@ -29,7 +232,7 @@ declare function toUint8Array(v: any): Uint8Array;
29
232
  * @returns {buffer}
30
233
  * @throws {Error}
31
234
  */
32
- declare function toBuffer(v: any): any;
235
+ export declare function toBuffer(v: $TSFixMe): Buffer;
33
236
  /**
34
237
  * Convert input to base58btc format on best effort
35
238
  *
@@ -39,7 +242,7 @@ declare function toBuffer(v: any): any;
39
242
  * @returns {string}
40
243
  * @throws {Error}
41
244
  */
42
- declare function toBase58(v: any): string;
245
+ export declare function toBase58(v: $TSFixMe): string;
43
246
  /**
44
247
  * Decode base58 string
45
248
  *
@@ -48,7 +251,7 @@ declare function toBase58(v: any): string;
48
251
  * @param {string} v
49
252
  * @returns {buffer}
50
253
  */
51
- declare function fromBase58(v: string): any;
254
+ export declare function fromBase58(v: string): Buffer;
52
255
  /**
53
256
  * Convert input to base64 format
54
257
  *
@@ -59,7 +262,7 @@ declare function fromBase58(v: string): any;
59
262
  * @returns {string}
60
263
  * @throws {Error}
61
264
  */
62
- declare function toBase64(v: any, escape?: typeof escape): string;
265
+ export declare function toBase64(v: $TSFixMe, escape?: boolean): string;
63
266
  /**
64
267
  * Decode base64(base64_url) string to buffer
65
268
  *
@@ -68,77 +271,23 @@ declare function toBase64(v: any, escape?: typeof escape): string;
68
271
  * @param {string} v
69
272
  * @returns {buffer}
70
273
  */
71
- declare function fromBase64(v: string): any;
274
+ export declare function fromBase64(v: string): Buffer;
72
275
  /**
73
- * Generate a random UUID
74
- *
75
- * @public
76
- * @static
77
- * @returns {string} Generated uuid
78
- */
79
- declare function UUID(): string;
80
- /**
81
- * Check if a string is valid UUID
82
- *
83
- * @public
84
- * @static
85
- * @param {string} str
86
- * @returns {boolean}
87
- */
88
- declare function isUUID(str: string): boolean;
89
- /**
90
- * Convert address to did: prepend `did:abt:` prefix
276
+ * Convert did to address: remove `did:abt:` prefix
91
277
  *
92
278
  * @public
93
279
  * @static
94
280
  * @param {string} did - address string
95
281
  * @returns {string}
96
282
  */
97
- declare function toDid(address: any): string;
283
+ export declare function toAddress(did: string): string;
98
284
  /**
99
- * Convert did to address: remove `did:abt:` prefix
285
+ * Convert address to did: prepend `did:abt:` prefix
100
286
  *
101
287
  * @public
102
288
  * @static
103
289
  * @param {string} did - address string
104
290
  * @returns {string}
105
291
  */
106
- declare function toAddress(did: string): string;
107
- declare const _Lib: _Lib.T100;
108
- declare namespace _Lib {
109
- export interface T100 {
110
- BN: typeof bnJs;
111
- isBN: (object: any) => boolean;
112
- isBigNumber: (object: any) => boolean;
113
- isHexPrefixed: (str: string) => boolean;
114
- stripHexPrefix: (str: string) => any;
115
- utf8ToHex: (str: string) => string;
116
- hexToUtf8: (hex: string) => string;
117
- numberToHex: (value: string | number | bnJs) => string;
118
- hexToNumber: (value: string | number | bnJs) => number;
119
- isHex: (hex: string) => boolean;
120
- isHexStrict: (hex: string) => boolean;
121
- isUint8Array: typeof isUint8Array;
122
- hexToBytes: (hex: string) => any[];
123
- bytesToHex: (bytes: any[]) => string;
124
- toHex: (value: any, returnType: boolean) => string;
125
- numberToString: (arg: any) => any;
126
- fromUnitToToken: (input: string | number, decimal?: number, optionsInput?: any) => string;
127
- fromTokenToUnit: (input: string, decimal?: number) => bnJs;
128
- toBN: (number: string | number | bnJs) => bnJs;
129
- toUint8Array: typeof toUint8Array;
130
- toBuffer: typeof toBuffer;
131
- toBase58: typeof toBase58;
132
- fromBase58: typeof fromBase58;
133
- toBase64: typeof toBase64;
134
- fromBase64: typeof fromBase64;
135
- UUID: typeof UUID;
136
- isUUID: typeof isUUID;
137
- toDid: typeof toDid;
138
- toAddress: typeof toAddress;
139
- formatTxType: (type: any) => any;
140
- leftPad: any;
141
- rightPad: any;
142
- }
143
- }
144
- export = _Lib;
292
+ export declare function toDid(address: string): string;
293
+ export declare const formatTxType: (type: string) => string;