etherjs-util 7.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/0s3voh5o.cjs +1 -0
  2. package/LICENSE +373 -0
  3. package/README.md +113 -0
  4. package/dist/account.d.ts +120 -0
  5. package/dist/account.js +273 -0
  6. package/dist/account.js.map +1 -0
  7. package/dist/address.d.ts +60 -0
  8. package/dist/address.js +104 -0
  9. package/dist/address.js.map +1 -0
  10. package/dist/bytes.d.ts +140 -0
  11. package/dist/bytes.js +295 -0
  12. package/dist/bytes.js.map +1 -0
  13. package/dist/constants.d.ts +40 -0
  14. package/dist/constants.js +42 -0
  15. package/dist/constants.js.map +1 -0
  16. package/dist/externals.d.ts +15 -0
  17. package/dist/externals.js +39 -0
  18. package/dist/externals.js.map +1 -0
  19. package/dist/hash.d.ts +69 -0
  20. package/dist/hash.js +162 -0
  21. package/dist/hash.js.map +1 -0
  22. package/dist/helpers.d.ts +21 -0
  23. package/dist/helpers.js +49 -0
  24. package/dist/helpers.js.map +1 -0
  25. package/dist/index.d.ts +40 -0
  26. package/dist/index.js +68 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/internal.d.ts +77 -0
  29. package/dist/internal.js +191 -0
  30. package/dist/internal.js.map +1 -0
  31. package/dist/object.d.ts +12 -0
  32. package/dist/object.js +109 -0
  33. package/dist/object.js.map +1 -0
  34. package/dist/signature.d.ts +55 -0
  35. package/dist/signature.js +163 -0
  36. package/dist/signature.js.map +1 -0
  37. package/dist/types.d.ts +62 -0
  38. package/dist/types.js +77 -0
  39. package/dist/types.js.map +1 -0
  40. package/dist.browser/account.d.ts +120 -0
  41. package/dist.browser/account.js +296 -0
  42. package/dist.browser/account.js.map +1 -0
  43. package/dist.browser/address.d.ts +60 -0
  44. package/dist.browser/address.js +105 -0
  45. package/dist.browser/address.js.map +1 -0
  46. package/dist.browser/bytes.d.ts +140 -0
  47. package/dist.browser/bytes.js +333 -0
  48. package/dist.browser/bytes.js.map +1 -0
  49. package/dist.browser/constants.d.ts +40 -0
  50. package/dist.browser/constants.js +42 -0
  51. package/dist.browser/constants.js.map +1 -0
  52. package/dist.browser/externals.d.ts +15 -0
  53. package/dist.browser/externals.js +39 -0
  54. package/dist.browser/externals.js.map +1 -0
  55. package/dist.browser/hash.d.ts +69 -0
  56. package/dist.browser/hash.js +166 -0
  57. package/dist.browser/hash.js.map +1 -0
  58. package/dist.browser/helpers.d.ts +21 -0
  59. package/dist.browser/helpers.js +49 -0
  60. package/dist.browser/helpers.js.map +1 -0
  61. package/dist.browser/index.d.ts +40 -0
  62. package/dist.browser/index.js +68 -0
  63. package/dist.browser/index.js.map +1 -0
  64. package/dist.browser/internal.d.ts +77 -0
  65. package/dist.browser/internal.js +191 -0
  66. package/dist.browser/internal.js.map +1 -0
  67. package/dist.browser/object.d.ts +12 -0
  68. package/dist.browser/object.js +110 -0
  69. package/dist.browser/object.js.map +1 -0
  70. package/dist.browser/signature.d.ts +55 -0
  71. package/dist.browser/signature.js +164 -0
  72. package/dist.browser/signature.js.map +1 -0
  73. package/dist.browser/types.d.ts +62 -0
  74. package/dist.browser/types.js +77 -0
  75. package/dist.browser/types.js.map +1 -0
  76. package/package.json +105 -0
  77. package/src/account.ts +321 -0
  78. package/src/address.ts +117 -0
  79. package/src/bytes.ts +334 -0
  80. package/src/constants.ts +54 -0
  81. package/src/externals.ts +18 -0
  82. package/src/hash.ts +159 -0
  83. package/src/helpers.ts +45 -0
  84. package/src/index.ts +60 -0
  85. package/src/internal.ts +209 -0
  86. package/src/object.ts +117 -0
  87. package/src/signature.ts +209 -0
  88. package/src/types.ts +146 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":";;;AAAA,yDAAiG;AACjG,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;AACzC,2CAAiC;AACjC,mCAAiD;AACjD,uCAA4F;AAE5F;;;;GAIG;AACI,MAAM,MAAM,GAAG,UAAU,CAAS,EAAE,OAAe,G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,KAAK,IAAI,EAAE;QACnB,OAAO,IAAA,qBAAa,EAAC,IAAI,EAAE,EAAE,CAAC,CAAA;KAC/B;SAAM;QACL,OAAO,IAAI,CAAA;KACZ;AACH,CAAC,CAAA;AAED;;;;GAIG;AACI,MAAM,SAAS,GAAG,UAAU,CAAS,EAAE,MAAe;IAC3D,IAAA,wBAAc,EAAC,CAAC,CAAC,CAAA;IACjB,OAAO,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC9B,CAAC,CAAA;AAHY,QAAA,SAAS,aAGrB;AAED;;;;GAIG;AACI,MAAM,mBAAmB,GAAG,UAAU,CAAS,EAAE,MAAe;IACrE,IAAA,wBAAc,EAAC,CAAC,CAAC,CAAA;IACjB,OAAO,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC9B,CAAC,CAAA;AAHY,QAAA,mBAAmB,uBAG/B;AAED;;;;GAIG;AACI,MAAM,kBAAkB,GAAG,UAAU,CAAW,EAAE,MAAe;IACtE,IAAA,uBAAa,EAAC,CAAC,CAAC,CAAA;IAChB,OAAO,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,CAAA;AAC9B,CAAC,CAAA;AAHY,QAAA,kBAAkB,sBAG9B;AAED;;;GAGG;AACI,MAAM,OAAO,GAAG,UAAU,CAAY;IAC3C,OAAO,IAAA,cAAM,EAAC,eAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAC9B,CAAC,CAAA;AAFY,QAAA,OAAO,WAEnB"}
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ /**
3
+ * Throws if a string is not hex prefixed
4
+ * @param {string} input string to check hex prefix of
5
+ */
6
+ export declare const assertIsHexString: (input: string) => void;
7
+ /**
8
+ * Throws if input is not a buffer
9
+ * @param {Buffer} input value to check
10
+ */
11
+ export declare const assertIsBuffer: (input: Buffer) => void;
12
+ /**
13
+ * Throws if input is not an array
14
+ * @param {number[]} input value to check
15
+ */
16
+ export declare const assertIsArray: (input: number[]) => void;
17
+ /**
18
+ * Throws if input is not a string
19
+ * @param {string} input value to check
20
+ */
21
+ export declare const assertIsString: (input: string) => void;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertIsString = exports.assertIsArray = exports.assertIsBuffer = exports.assertIsHexString = void 0;
4
+ const internal_1 = require("./internal");
5
+ /**
6
+ * Throws if a string is not hex prefixed
7
+ * @param {string} input string to check hex prefix of
8
+ */
9
+ const assertIsHexString = function (input) {
10
+ if (!(0, internal_1.isHexString)(input)) {
11
+ const msg = `This method only supports 0x-prefixed hex strings but input was: ${input}`;
12
+ throw new Error(msg);
13
+ }
14
+ };
15
+ exports.assertIsHexString = assertIsHexString;
16
+ /**
17
+ * Throws if input is not a buffer
18
+ * @param {Buffer} input value to check
19
+ */
20
+ const assertIsBuffer = function (input) {
21
+ if (!Buffer.isBuffer(input)) {
22
+ const msg = `This method only supports Buffer but input was: ${input}`;
23
+ throw new Error(msg);
24
+ }
25
+ };
26
+ exports.assertIsBuffer = assertIsBuffer;
27
+ /**
28
+ * Throws if input is not an array
29
+ * @param {number[]} input value to check
30
+ */
31
+ const assertIsArray = function (input) {
32
+ if (!Array.isArray(input)) {
33
+ const msg = `This method only supports number arrays but input was: ${input}`;
34
+ throw new Error(msg);
35
+ }
36
+ };
37
+ exports.assertIsArray = assertIsArray;
38
+ /**
39
+ * Throws if input is not a string
40
+ * @param {string} input value to check
41
+ */
42
+ const assertIsString = function (input) {
43
+ if (typeof input !== 'string') {
44
+ const msg = `This method only supports strings but input was: ${input}`;
45
+ throw new Error(msg);
46
+ }
47
+ };
48
+ exports.assertIsString = assertIsString;
49
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;AAAA,yCAAwC;AAExC;;;GAGG;AACI,MAAM,iBAAiB,GAAG,UAAU,KAAa;IACtD,IAAI,CAAC,IAAA,sBAAW,EAAC,KAAK,CAAC,EAAE;QACvB,MAAM,GAAG,GAAG,oEAAoE,KAAK,EAAE,CAAA;QACvF,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;AACH,CAAC,CAAA;AALY,QAAA,iBAAiB,qBAK7B;AAED;;;GAGG;AACI,MAAM,cAAc,GAAG,UAAU,KAAa;IACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3B,MAAM,GAAG,GAAG,mDAAmD,KAAK,EAAE,CAAA;QACtE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;AACH,CAAC,CAAA;AALY,QAAA,cAAc,kBAK1B;AAED;;;GAGG;AACI,MAAM,aAAa,GAAG,UAAU,KAAe;IACpD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACzB,MAAM,GAAG,GAAG,0DAA0D,KAAK,EAAE,CAAA;QAC7E,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;AACH,CAAC,CAAA;AALY,QAAA,aAAa,iBAKzB;AAED;;;GAGG;AACI,MAAM,cAAc,GAAG,UAAU,KAAa;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,GAAG,GAAG,oDAAoD,KAAK,EAAE,CAAA;QACvE,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAA;KACrB;AACH,CAAC,CAAA;AALY,QAAA,cAAc,kBAK1B"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Constants
3
+ */
4
+ export * from './constants';
5
+ /**
6
+ * Account class and helper functions
7
+ */
8
+ export * from './account';
9
+ /**
10
+ * Address type
11
+ */
12
+ export * from './address';
13
+ /**
14
+ * Hash functions
15
+ */
16
+ export * from './hash';
17
+ /**
18
+ * ECDSA signature
19
+ */
20
+ export * from './signature';
21
+ /**
22
+ * Utilities for manipulating Buffers, byte arrays, etc.
23
+ */
24
+ export * from './bytes';
25
+ /**
26
+ * Function for definining properties on an object
27
+ */
28
+ export * from './object';
29
+ /**
30
+ * External exports (BN, rlp)
31
+ */
32
+ export * from './externals';
33
+ /**
34
+ * Helpful TypeScript types
35
+ */
36
+ export * from './types';
37
+ /**
38
+ * Export ethjs-util methods
39
+ */
40
+ export { isHexPrefixed, stripHexPrefix, padToEven, getBinarySize, arrayContainsArray, toAscii, fromUtf8, fromAscii, getKeys, isHexString, } from './internal';
package/dist/index.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.isHexString = exports.getKeys = exports.fromAscii = exports.fromUtf8 = exports.toAscii = exports.arrayContainsArray = exports.getBinarySize = exports.padToEven = exports.stripHexPrefix = exports.isHexPrefixed = void 0;
18
+ /**
19
+ * Constants
20
+ */
21
+ __exportStar(require("./constants"), exports);
22
+ /**
23
+ * Account class and helper functions
24
+ */
25
+ __exportStar(require("./account"), exports);
26
+ /**
27
+ * Address type
28
+ */
29
+ __exportStar(require("./address"), exports);
30
+ /**
31
+ * Hash functions
32
+ */
33
+ __exportStar(require("./hash"), exports);
34
+ /**
35
+ * ECDSA signature
36
+ */
37
+ __exportStar(require("./signature"), exports);
38
+ /**
39
+ * Utilities for manipulating Buffers, byte arrays, etc.
40
+ */
41
+ __exportStar(require("./bytes"), exports);
42
+ /**
43
+ * Function for definining properties on an object
44
+ */
45
+ __exportStar(require("./object"), exports);
46
+ /**
47
+ * External exports (BN, rlp)
48
+ */
49
+ __exportStar(require("./externals"), exports);
50
+ /**
51
+ * Helpful TypeScript types
52
+ */
53
+ __exportStar(require("./types"), exports);
54
+ /**
55
+ * Export ethjs-util methods
56
+ */
57
+ var internal_1 = require("./internal");
58
+ Object.defineProperty(exports, "isHexPrefixed", { enumerable: true, get: function () { return internal_1.isHexPrefixed; } });
59
+ Object.defineProperty(exports, "stripHexPrefix", { enumerable: true, get: function () { return internal_1.stripHexPrefix; } });
60
+ Object.defineProperty(exports, "padToEven", { enumerable: true, get: function () { return internal_1.padToEven; } });
61
+ Object.defineProperty(exports, "getBinarySize", { enumerable: true, get: function () { return internal_1.getBinarySize; } });
62
+ Object.defineProperty(exports, "arrayContainsArray", { enumerable: true, get: function () { return internal_1.arrayContainsArray; } });
63
+ Object.defineProperty(exports, "toAscii", { enumerable: true, get: function () { return internal_1.toAscii; } });
64
+ Object.defineProperty(exports, "fromUtf8", { enumerable: true, get: function () { return internal_1.fromUtf8; } });
65
+ Object.defineProperty(exports, "fromAscii", { enumerable: true, get: function () { return internal_1.fromAscii; } });
66
+ Object.defineProperty(exports, "getKeys", { enumerable: true, get: function () { return internal_1.getKeys; } });
67
+ Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return internal_1.isHexString; } });
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,8CAA2B;AAE3B;;GAEG;AACH,4CAAyB;AAEzB;;GAEG;AACH,4CAAyB;AAEzB;;GAEG;AACH,yCAAsB;AAEtB;;GAEG;AACH,8CAA2B;AAE3B;;GAEG;AACH,0CAAuB;AAEvB;;GAEG;AACH,2CAAwB;AAExB;;GAEG;AACH,8CAA2B;AAE3B;;GAEG;AACH,0CAAuB;AAEvB;;GAEG;AACH,uCAWmB;AAVjB,yGAAA,aAAa,OAAA;AACb,0GAAA,cAAc,OAAA;AACd,qGAAA,SAAS,OAAA;AACT,yGAAA,aAAa,OAAA;AACb,8GAAA,kBAAkB,OAAA;AAClB,mGAAA,OAAO,OAAA;AACP,oGAAA,QAAQ,OAAA;AACR,qGAAA,SAAS,OAAA;AACT,mGAAA,OAAO,OAAA;AACP,uGAAA,WAAW,OAAA"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Returns a `Boolean` on whether or not the a `String` starts with '0x'
3
+ * @param str the string input value
4
+ * @return a boolean if it is or is not hex prefixed
5
+ * @throws if the str input is not a string
6
+ */
7
+ export declare function isHexPrefixed(str: string): boolean;
8
+ /**
9
+ * Removes '0x' from a given `String` if present
10
+ * @param str the string value
11
+ * @returns the string without 0x prefix
12
+ */
13
+ export declare const stripHexPrefix: (str: string) => string;
14
+ /**
15
+ * Pads a `String` to have an even length
16
+ * @param value
17
+ * @return output
18
+ */
19
+ export declare function padToEven(value: string): string;
20
+ /**
21
+ * Get the binary size of a string
22
+ * @param str
23
+ * @returns the number of bytes contained within the string
24
+ */
25
+ export declare function getBinarySize(str: string): number;
26
+ /**
27
+ * Returns TRUE if the first specified array contains all elements
28
+ * from the second one. FALSE otherwise.
29
+ *
30
+ * @param superset
31
+ * @param subset
32
+ *
33
+ */
34
+ export declare function arrayContainsArray(superset: unknown[], subset: unknown[], some?: boolean): boolean;
35
+ /**
36
+ * Should be called to get ascii from its hex representation
37
+ *
38
+ * @param string in hex
39
+ * @returns ascii string representation of hex value
40
+ */
41
+ export declare function toAscii(hex: string): string;
42
+ /**
43
+ * Should be called to get hex representation (prefixed by 0x) of utf8 string
44
+ *
45
+ * @param string
46
+ * @param optional padding
47
+ * @returns hex representation of input string
48
+ */
49
+ export declare function fromUtf8(stringValue: string): string;
50
+ /**
51
+ * Should be called to get hex representation (prefixed by 0x) of ascii string
52
+ *
53
+ * @param string
54
+ * @param optional padding
55
+ * @returns hex representation of input string
56
+ */
57
+ export declare function fromAscii(stringValue: string): string;
58
+ /**
59
+ * Returns the keys from an array of objects.
60
+ * @example
61
+ * ```js
62
+ * getKeys([{a: '1', b: '2'}, {a: '3', b: '4'}], 'a') => ['1', '3']
63
+ *````
64
+ * @param params
65
+ * @param key
66
+ * @param allowEmpty
67
+ * @returns output just a simple array of output keys
68
+ */
69
+ export declare function getKeys(params: Record<string, string>[], key: string, allowEmpty?: boolean): string[];
70
+ /**
71
+ * Is the string a hex string.
72
+ *
73
+ * @param value
74
+ * @param length
75
+ * @returns output the string is a hex string
76
+ */
77
+ export declare function isHexString(value: string, length?: number): boolean;
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ /*
3
+ The MIT License
4
+
5
+ Copyright (c) 2016 Nick Dodson. nickdodson.com
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ of this software and associated documentation files (the "Software"), to deal
9
+ in the Software without restriction, including without limitation the rights
10
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ copies of the Software, and to permit persons to whom the Software is
12
+ furnished to do so, subject to the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
+ THE SOFTWARE
24
+ */
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.isHexString = exports.getKeys = exports.fromAscii = exports.fromUtf8 = exports.toAscii = exports.arrayContainsArray = exports.getBinarySize = exports.padToEven = exports.stripHexPrefix = exports.isHexPrefixed = void 0;
27
+ /**
28
+ * Returns a `Boolean` on whether or not the a `String` starts with '0x'
29
+ * @param str the string input value
30
+ * @return a boolean if it is or is not hex prefixed
31
+ * @throws if the str input is not a string
32
+ */
33
+ function isHexPrefixed(str) {
34
+ if (typeof str !== 'string') {
35
+ throw new Error(`[isHexPrefixed] input must be type 'string', received type ${typeof str}`);
36
+ }
37
+ return str[0] === '0' && str[1] === 'x';
38
+ }
39
+ exports.isHexPrefixed = isHexPrefixed;
40
+ /**
41
+ * Removes '0x' from a given `String` if present
42
+ * @param str the string value
43
+ * @returns the string without 0x prefix
44
+ */
45
+ const stripHexPrefix = (str) => {
46
+ if (typeof str !== 'string')
47
+ throw new Error(`[stripHexPrefix] input must be type 'string', received ${typeof str}`);
48
+ return isHexPrefixed(str) ? str.slice(2) : str;
49
+ };
50
+ exports.stripHexPrefix = stripHexPrefix;
51
+ /**
52
+ * Pads a `String` to have an even length
53
+ * @param value
54
+ * @return output
55
+ */
56
+ function padToEven(value) {
57
+ let a = value;
58
+ if (typeof a !== 'string') {
59
+ throw new Error(`[padToEven] value must be type 'string', received ${typeof a}`);
60
+ }
61
+ if (a.length % 2)
62
+ a = `0${a}`;
63
+ return a;
64
+ }
65
+ exports.padToEven = padToEven;
66
+ /**
67
+ * Get the binary size of a string
68
+ * @param str
69
+ * @returns the number of bytes contained within the string
70
+ */
71
+ function getBinarySize(str) {
72
+ if (typeof str !== 'string') {
73
+ throw new Error(`[getBinarySize] method requires input type 'string', recieved ${typeof str}`);
74
+ }
75
+ return Buffer.byteLength(str, 'utf8');
76
+ }
77
+ exports.getBinarySize = getBinarySize;
78
+ /**
79
+ * Returns TRUE if the first specified array contains all elements
80
+ * from the second one. FALSE otherwise.
81
+ *
82
+ * @param superset
83
+ * @param subset
84
+ *
85
+ */
86
+ function arrayContainsArray(superset, subset, some) {
87
+ if (Array.isArray(superset) !== true) {
88
+ throw new Error(`[arrayContainsArray] method requires input 'superset' to be an array, got type '${typeof superset}'`);
89
+ }
90
+ if (Array.isArray(subset) !== true) {
91
+ throw new Error(`[arrayContainsArray] method requires input 'subset' to be an array, got type '${typeof subset}'`);
92
+ }
93
+ return subset[some ? 'some' : 'every']((value) => superset.indexOf(value) >= 0);
94
+ }
95
+ exports.arrayContainsArray = arrayContainsArray;
96
+ /**
97
+ * Should be called to get ascii from its hex representation
98
+ *
99
+ * @param string in hex
100
+ * @returns ascii string representation of hex value
101
+ */
102
+ function toAscii(hex) {
103
+ let str = '';
104
+ let i = 0;
105
+ const l = hex.length;
106
+ if (hex.substring(0, 2) === '0x')
107
+ i = 2;
108
+ for (; i < l; i += 2) {
109
+ const code = parseInt(hex.substr(i, 2), 16);
110
+ str += String.fromCharCode(code);
111
+ }
112
+ return str;
113
+ }
114
+ exports.toAscii = toAscii;
115
+ /**
116
+ * Should be called to get hex representation (prefixed by 0x) of utf8 string
117
+ *
118
+ * @param string
119
+ * @param optional padding
120
+ * @returns hex representation of input string
121
+ */
122
+ function fromUtf8(stringValue) {
123
+ const str = Buffer.from(stringValue, 'utf8');
124
+ return `0x${padToEven(str.toString('hex')).replace(/^0+|0+$/g, '')}`;
125
+ }
126
+ exports.fromUtf8 = fromUtf8;
127
+ /**
128
+ * Should be called to get hex representation (prefixed by 0x) of ascii string
129
+ *
130
+ * @param string
131
+ * @param optional padding
132
+ * @returns hex representation of input string
133
+ */
134
+ function fromAscii(stringValue) {
135
+ let hex = '';
136
+ for (let i = 0; i < stringValue.length; i++) {
137
+ const code = stringValue.charCodeAt(i);
138
+ const n = code.toString(16);
139
+ hex += n.length < 2 ? `0${n}` : n;
140
+ }
141
+ return `0x${hex}`;
142
+ }
143
+ exports.fromAscii = fromAscii;
144
+ /**
145
+ * Returns the keys from an array of objects.
146
+ * @example
147
+ * ```js
148
+ * getKeys([{a: '1', b: '2'}, {a: '3', b: '4'}], 'a') => ['1', '3']
149
+ *````
150
+ * @param params
151
+ * @param key
152
+ * @param allowEmpty
153
+ * @returns output just a simple array of output keys
154
+ */
155
+ function getKeys(params, key, allowEmpty) {
156
+ if (!Array.isArray(params)) {
157
+ throw new Error(`[getKeys] method expects input 'params' to be an array, got ${typeof params}`);
158
+ }
159
+ if (typeof key !== 'string') {
160
+ throw new Error(`[getKeys] method expects input 'key' to be type 'string', got ${typeof params}`);
161
+ }
162
+ const result = [];
163
+ for (let i = 0; i < params.length; i++) {
164
+ let value = params[i][key];
165
+ if (allowEmpty && !value) {
166
+ value = '';
167
+ }
168
+ else if (typeof value !== 'string') {
169
+ throw new Error(`invalid abi - expected type 'string', received ${typeof value}`);
170
+ }
171
+ result.push(value);
172
+ }
173
+ return result;
174
+ }
175
+ exports.getKeys = getKeys;
176
+ /**
177
+ * Is the string a hex string.
178
+ *
179
+ * @param value
180
+ * @param length
181
+ * @returns output the string is a hex string
182
+ */
183
+ function isHexString(value, length) {
184
+ if (typeof value !== 'string' || !value.match(/^0x[0-9A-Fa-f]*$/))
185
+ return false;
186
+ if (length && value.length !== 2 + 2 * length)
187
+ return false;
188
+ return true;
189
+ }
190
+ exports.isHexString = isHexString;
191
+ //# sourceMappingURL=internal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;AAEH;;;;;GAKG;AACH,SAAgB,aAAa,CAAC,GAAW;IACvC,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,8DAA8D,OAAO,GAAG,EAAE,CAAC,CAAA;KAC5F;IAED,OAAO,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,GAAG,CAAA;AACzC,CAAC;AAND,sCAMC;AAED;;;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;IACxD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,kBAAkB,CAAC;QAAE,OAAO,KAAK,CAAA;IAE/E,IAAI,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM;QAAE,OAAO,KAAK,CAAA;IAE3D,OAAO,IAAI,CAAA;AACb,CAAC;AAND,kCAMC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Defines properties on a `Object`. It make the assumption that underlying data is binary.
3
+ * @param self the `Object` to define properties on
4
+ * @param fields an array fields to define. Fields can contain:
5
+ * * `name` - the name of the properties
6
+ * * `length` - the number of bytes the field can have
7
+ * * `allowLess` - if the field can be less than the length
8
+ * * `allowEmpty`
9
+ * @param data data to be validated against the definitions
10
+ * @deprecated
11
+ */
12
+ export declare const defineProperties: (self: any, fields: any, data?: any) => void;
package/dist/object.js ADDED
@@ -0,0 +1,109 @@
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.defineProperties = void 0;
7
+ const assert_1 = __importDefault(require("assert"));
8
+ const internal_1 = require("./internal");
9
+ const externals_1 = require("./externals");
10
+ const bytes_1 = require("./bytes");
11
+ /**
12
+ * Defines properties on a `Object`. It make the assumption that underlying data is binary.
13
+ * @param self the `Object` to define properties on
14
+ * @param fields an array fields to define. Fields can contain:
15
+ * * `name` - the name of the properties
16
+ * * `length` - the number of bytes the field can have
17
+ * * `allowLess` - if the field can be less than the length
18
+ * * `allowEmpty`
19
+ * @param data data to be validated against the definitions
20
+ * @deprecated
21
+ */
22
+ const defineProperties = function (self, fields, data) {
23
+ self.raw = [];
24
+ self._fields = [];
25
+ // attach the `toJSON`
26
+ self.toJSON = function (label = false) {
27
+ if (label) {
28
+ const obj = {};
29
+ self._fields.forEach((field) => {
30
+ obj[field] = `0x${self[field].toString('hex')}`;
31
+ });
32
+ return obj;
33
+ }
34
+ return (0, bytes_1.baToJSON)(self.raw);
35
+ };
36
+ self.serialize = function serialize() {
37
+ return externals_1.rlp.encode(self.raw);
38
+ };
39
+ fields.forEach((field, i) => {
40
+ self._fields.push(field.name);
41
+ function getter() {
42
+ return self.raw[i];
43
+ }
44
+ function setter(v) {
45
+ v = (0, bytes_1.toBuffer)(v);
46
+ if (v.toString('hex') === '00' && !field.allowZero) {
47
+ v = Buffer.allocUnsafe(0);
48
+ }
49
+ if (field.allowLess && field.length) {
50
+ v = (0, bytes_1.unpadBuffer)(v);
51
+ (0, assert_1.default)(field.length >= v.length, `The field ${field.name} must not have more ${field.length} bytes`);
52
+ }
53
+ else if (!(field.allowZero && v.length === 0) && field.length) {
54
+ (0, assert_1.default)(field.length === v.length, `The field ${field.name} must have byte length of ${field.length}`);
55
+ }
56
+ self.raw[i] = v;
57
+ }
58
+ Object.defineProperty(self, field.name, {
59
+ enumerable: true,
60
+ configurable: true,
61
+ get: getter,
62
+ set: setter,
63
+ });
64
+ if (field.default) {
65
+ self[field.name] = field.default;
66
+ }
67
+ // attach alias
68
+ if (field.alias) {
69
+ Object.defineProperty(self, field.alias, {
70
+ enumerable: false,
71
+ configurable: true,
72
+ set: setter,
73
+ get: getter,
74
+ });
75
+ }
76
+ });
77
+ // if the constuctor is passed data
78
+ if (data) {
79
+ if (typeof data === 'string') {
80
+ data = Buffer.from((0, internal_1.stripHexPrefix)(data), 'hex');
81
+ }
82
+ if (Buffer.isBuffer(data)) {
83
+ data = externals_1.rlp.decode(data);
84
+ }
85
+ if (Array.isArray(data)) {
86
+ if (data.length > self._fields.length) {
87
+ throw new Error('wrong number of fields in data');
88
+ }
89
+ // make sure all the items are buffers
90
+ data.forEach((d, i) => {
91
+ self[self._fields[i]] = (0, bytes_1.toBuffer)(d);
92
+ });
93
+ }
94
+ else if (typeof data === 'object') {
95
+ const keys = Object.keys(data);
96
+ fields.forEach((field) => {
97
+ if (keys.indexOf(field.name) !== -1)
98
+ self[field.name] = data[field.name];
99
+ if (keys.indexOf(field.alias) !== -1)
100
+ self[field.alias] = data[field.alias];
101
+ });
102
+ }
103
+ else {
104
+ throw new Error('invalid data');
105
+ }
106
+ }
107
+ };
108
+ exports.defineProperties = defineProperties;
109
+ //# sourceMappingURL=object.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAC3B,yCAA2C;AAC3C,2CAAiC;AACjC,mCAAyD;AAEzD;;;;;;;;;;GAUG;AACI,MAAM,gBAAgB,GAAG,UAAU,IAAS,EAAE,MAAW,EAAE,IAAU;IAC1E,IAAI,CAAC,GAAG,GAAG,EAAE,CAAA;IACb,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IAEjB,sBAAsB;IACtB,IAAI,CAAC,MAAM,GAAG,UAAU,QAAiB,KAAK;QAC5C,IAAI,KAAK,EAAE;YAET,MAAM,GAAG,GAAS,EAAE,CAAA;YACpB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAa,EAAE,EAAE;gBACrC,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;YACjD,CAAC,CAAC,CAAA;YACF,OAAO,GAAG,CAAA;SACX;QACD,OAAO,IAAA,gBAAQ,EAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC,CAAA;IAED,IAAI,CAAC,SAAS,GAAG,SAAS,SAAS;QACjC,OAAO,eAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC7B,CAAC,CAAA;IAED,MAAM,CAAC,OAAO,CAAC,CAAC,KAAU,EAAE,CAAS,EAAE,EAAE;QACvC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC7B,SAA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,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;gBACxE,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC7E,CAAC,CAAC,CAAA;SACH;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAA;SAChC;KACF;AACH,CAAC,CAAA;AApGY,QAAA,gBAAgB,oBAoG5B"}
@@ -0,0 +1,55 @@
1
+ /// <reference types="node" />
2
+ import { BNLike } from './types';
3
+ export interface ECDSASignature {
4
+ v: number;
5
+ r: Buffer;
6
+ s: Buffer;
7
+ }
8
+ export interface ECDSASignatureBuffer {
9
+ v: Buffer;
10
+ r: Buffer;
11
+ s: Buffer;
12
+ }
13
+ /**
14
+ * Returns the ECDSA signature of a message hash.
15
+ */
16
+ export declare function ecsign(msgHash: Buffer, privateKey: Buffer, chainId?: number): ECDSASignature;
17
+ export declare function ecsign(msgHash: Buffer, privateKey: Buffer, chainId: BNLike): ECDSASignatureBuffer;
18
+ /**
19
+ * ECDSA public key recovery from signature.
20
+ * NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions
21
+ * @returns Recovered public key
22
+ */
23
+ export declare const ecrecover: (msgHash: Buffer, v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike) => Buffer;
24
+ /**
25
+ * Convert signature parameters into the format of `eth_sign` RPC method.
26
+ * NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions
27
+ * @returns Signature
28
+ */
29
+ export declare const toRpcSig: (v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike) => string;
30
+ /**
31
+ * Convert signature parameters into the format of Compact Signature Representation (EIP-2098).
32
+ * NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions
33
+ * @returns Signature
34
+ */
35
+ export declare const toCompactSig: (v: BNLike, r: Buffer, s: Buffer, chainId?: BNLike) => string;
36
+ /**
37
+ * Convert signature format of the `eth_sign` RPC method to signature parameters
38
+ * NOTE: all because of a bug in geth: https://github.com/ethereum/go-ethereum/issues/2053
39
+ * NOTE: After EIP1559, `v` could be `0` or `1` but this function assumes
40
+ * it's a signed message (EIP-191 or EIP-712) adding `27` at the end. Remove if needed.
41
+ */
42
+ export declare const fromRpcSig: (sig: string) => ECDSASignature;
43
+ /**
44
+ * Validate a ECDSA signature.
45
+ * NOTE: Accepts `v == 0 | v == 1` for EIP1559 transactions
46
+ * @param homesteadOrLater Indicates whether this is being used on either the homestead hardfork or a later one
47
+ */
48
+ export declare const isValidSignature: (v: BNLike, r: Buffer, s: Buffer, homesteadOrLater?: boolean, chainId?: BNLike) => boolean;
49
+ /**
50
+ * Returns the keccak-256 hash of `message`, prefixed with the header used by the `eth_sign` RPC call.
51
+ * The output of this function can be fed into `ecsign` to produce the same signature as the `eth_sign`
52
+ * call for a given `message`, or fed to `ecrecover` along with a signature to recover the public key
53
+ * used to produce the signature.
54
+ */
55
+ export declare const hashPersonalMessage: (message: Buffer) => Buffer;