@ocap/util 1.16.14 → 1.16.17

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