@metamask-previews/utils 11.12.1-preview-c44fd50 → 11.12.1-preview-2caaa71
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/CHANGELOG.md +6 -0
- package/dist/{assert.d.mts → assert.d.ts} +2 -2
- package/dist/assert.d.ts.map +1 -0
- package/dist/{assert.mjs → assert.js} +4 -4
- package/dist/assert.js.map +1 -0
- package/dist/{base64.d.cts → base64.d.ts} +2 -2
- package/dist/base64.d.ts.map +1 -0
- package/dist/{base64.mjs → base64.js} +3 -3
- package/dist/base64.js.map +1 -0
- package/dist/{bytes.d.cts → bytes.d.ts} +2 -2
- package/dist/bytes.d.ts.map +1 -0
- package/dist/{bytes.mjs → bytes.js} +4 -4
- package/dist/bytes.js.map +1 -0
- package/dist/{caip-types.d.cts → caip-types.d.ts} +2 -2
- package/dist/caip-types.d.ts.map +1 -0
- package/dist/{caip-types.mjs → caip-types.js} +2 -2
- package/dist/caip-types.js.map +1 -0
- package/dist/{checksum.d.cts → checksum.d.ts} +1 -1
- package/dist/checksum.d.ts.map +1 -0
- package/dist/checksum.js +4 -0
- package/dist/checksum.js.map +1 -0
- package/dist/{coercers.d.cts → coercers.d.ts} +4 -4
- package/dist/coercers.d.ts.map +1 -0
- package/dist/{coercers.mjs → coercers.js} +5 -5
- package/dist/coercers.js.map +1 -0
- package/dist/{collections.d.cts → collections.d.ts} +9 -9
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +93 -0
- package/dist/collections.js.map +1 -0
- package/dist/{encryption-types.d.cts → encryption-types.d.ts} +1 -1
- package/dist/encryption-types.d.ts.map +1 -0
- package/dist/encryption-types.js +2 -0
- package/dist/encryption-types.js.map +1 -0
- package/dist/{errors.d.mts → errors.d.ts} +1 -1
- package/dist/errors.d.ts.map +1 -0
- package/dist/{errors.mjs → errors.js} +4 -10
- package/dist/errors.js.map +1 -0
- package/dist/{fs.d.cts → fs.d.ts} +2 -2
- package/dist/fs.d.ts.map +1 -0
- package/dist/{fs.mjs → fs.js} +7 -7
- package/dist/fs.js.map +1 -0
- package/dist/{hashing.d.cts → hashing.d.ts} +1 -1
- package/dist/hashing.d.ts.map +1 -0
- package/dist/{hashing.mjs → hashing.js} +8 -3
- package/dist/hashing.js.map +1 -0
- package/dist/{hex.d.cts → hex.d.ts} +5 -6
- package/dist/hex.d.ts.map +1 -0
- package/dist/{hex.mjs → hex.js} +5 -6
- package/dist/hex.js.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/{json.d.cts → json.d.ts} +19 -29
- package/dist/json.d.ts.map +1 -0
- package/dist/{json.mjs → json.js} +5 -4
- package/dist/json.js.map +1 -0
- package/dist/{keyring.d.mts → keyring.d.ts} +5 -5
- package/dist/keyring.d.ts.map +1 -0
- package/dist/keyring.js +2 -0
- package/dist/keyring.js.map +1 -0
- package/dist/{logging.d.cts → logging.d.ts} +2 -2
- package/dist/logging.d.ts.map +1 -0
- package/dist/{logging.mjs → logging.js} +2 -9
- package/dist/logging.js.map +1 -0
- package/dist/{misc.d.mts → misc.d.ts} +1 -1
- package/dist/misc.d.ts.map +1 -0
- package/dist/{misc.mjs → misc.js} +1 -1
- package/dist/misc.js.map +1 -0
- package/dist/{mnemonic.d.cts → mnemonic.d.ts} +1 -1
- package/dist/mnemonic.d.ts.map +1 -0
- package/dist/{mnemonic.mjs → mnemonic.js} +2 -2
- package/dist/mnemonic.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +3 -0
- package/dist/node.js.map +1 -0
- package/dist/{number.d.mts → number.d.ts} +2 -2
- package/dist/number.d.ts.map +1 -0
- package/dist/{number.mjs → number.js} +3 -3
- package/dist/number.js.map +1 -0
- package/dist/{opaque.d.cts → opaque.d.ts} +1 -1
- package/dist/opaque.d.ts.map +1 -0
- package/dist/opaque.js +2 -0
- package/dist/opaque.js.map +1 -0
- package/dist/{promise.d.cts → promise.d.ts} +1 -1
- package/dist/promise.d.ts.map +1 -0
- package/dist/{promise.mjs → promise.js} +1 -1
- package/dist/promise.js.map +1 -0
- package/dist/{superstruct.d.mts → superstruct.d.ts} +2 -2
- package/dist/superstruct.d.ts.map +1 -0
- package/dist/{superstruct.mjs → superstruct.js} +2 -2
- package/dist/superstruct.js.map +1 -0
- package/dist/{time.d.mts → time.d.ts} +1 -1
- package/dist/time.d.ts.map +1 -0
- package/dist/{time.mjs → time.js} +1 -1
- package/dist/time.js.map +1 -0
- package/dist/{transaction-types.d.cts → transaction-types.d.ts} +3 -3
- package/dist/transaction-types.d.ts.map +1 -0
- package/dist/transaction-types.js +2 -0
- package/dist/transaction-types.js.map +1 -0
- package/dist/{unitsConversion.d.cts → unitsConversion.d.ts} +28 -28
- package/dist/unitsConversion.d.ts.map +1 -0
- package/dist/{unitsConversion.mjs → unitsConversion.js} +1 -1
- package/dist/unitsConversion.js.map +1 -0
- package/dist/{versions.d.mts → versions.d.ts} +3 -3
- package/dist/versions.d.ts.map +1 -0
- package/dist/{versions.mjs → versions.js} +4 -4
- package/dist/versions.js.map +1 -0
- package/package.json +21 -30
- package/dist/assert.cjs +0 -122
- package/dist/assert.cjs.map +0 -1
- package/dist/assert.d.cts +0 -61
- package/dist/assert.d.cts.map +0 -1
- package/dist/assert.d.mts.map +0 -1
- package/dist/assert.mjs.map +0 -1
- package/dist/base64.cjs +0 -34
- package/dist/base64.cjs.map +0 -1
- package/dist/base64.d.cts.map +0 -1
- package/dist/base64.d.mts +0 -25
- package/dist/base64.d.mts.map +0 -1
- package/dist/base64.mjs.map +0 -1
- package/dist/bytes.cjs +0 -427
- package/dist/bytes.cjs.map +0 -1
- package/dist/bytes.d.cts.map +0 -1
- package/dist/bytes.d.mts +0 -198
- package/dist/bytes.d.mts.map +0 -1
- package/dist/bytes.mjs.map +0 -1
- package/dist/caip-types.cjs +0 -390
- package/dist/caip-types.cjs.map +0 -1
- package/dist/caip-types.d.cts.map +0 -1
- package/dist/caip-types.d.mts +0 -294
- package/dist/caip-types.d.mts.map +0 -1
- package/dist/caip-types.mjs.map +0 -1
- package/dist/checksum.cjs +0 -7
- package/dist/checksum.cjs.map +0 -1
- package/dist/checksum.d.cts.map +0 -1
- package/dist/checksum.d.mts +0 -2
- package/dist/checksum.d.mts.map +0 -1
- package/dist/checksum.mjs +0 -4
- package/dist/checksum.mjs.map +0 -1
- package/dist/coercers.cjs +0 -166
- package/dist/coercers.cjs.map +0 -1
- package/dist/coercers.d.cts.map +0 -1
- package/dist/coercers.d.mts +0 -97
- package/dist/coercers.d.mts.map +0 -1
- package/dist/coercers.mjs.map +0 -1
- package/dist/collections.cjs +0 -109
- package/dist/collections.cjs.map +0 -1
- package/dist/collections.d.cts.map +0 -1
- package/dist/collections.d.mts +0 -39
- package/dist/collections.d.mts.map +0 -1
- package/dist/collections.mjs +0 -105
- package/dist/collections.mjs.map +0 -1
- package/dist/encryption-types.cjs +0 -3
- package/dist/encryption-types.cjs.map +0 -1
- package/dist/encryption-types.d.cts.map +0 -1
- package/dist/encryption-types.d.mts +0 -7
- package/dist/encryption-types.d.mts.map +0 -1
- package/dist/encryption-types.mjs +0 -2
- package/dist/encryption-types.mjs.map +0 -1
- package/dist/errors.cjs +0 -129
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -68
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/fs.cjs +0 -248
- package/dist/fs.cjs.map +0 -1
- package/dist/fs.d.cts.map +0 -1
- package/dist/fs.d.mts +0 -133
- package/dist/fs.d.mts.map +0 -1
- package/dist/fs.mjs.map +0 -1
- package/dist/hashing.cjs +0 -60
- package/dist/hashing.cjs.map +0 -1
- package/dist/hashing.d.cts.map +0 -1
- package/dist/hashing.d.mts +0 -28
- package/dist/hashing.d.mts.map +0 -1
- package/dist/hashing.mjs.map +0 -1
- package/dist/hex.cjs +0 -188
- package/dist/hex.cjs.map +0 -1
- package/dist/hex.d.cts.map +0 -1
- package/dist/hex.d.mts +0 -118
- package/dist/hex.d.mts.map +0 -1
- package/dist/hex.mjs.map +0 -1
- package/dist/index.cjs +0 -58
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -26
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -26
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -21
- package/dist/index.mjs.map +0 -1
- package/dist/json.cjs +0 -425
- package/dist/json.cjs.map +0 -1
- package/dist/json.d.cts.map +0 -1
- package/dist/json.d.mts +0 -398
- package/dist/json.d.mts.map +0 -1
- package/dist/json.mjs.map +0 -1
- package/dist/keyring.cjs +0 -3
- package/dist/keyring.cjs.map +0 -1
- package/dist/keyring.d.cts +0 -243
- package/dist/keyring.d.cts.map +0 -1
- package/dist/keyring.d.mts.map +0 -1
- package/dist/keyring.mjs +0 -2
- package/dist/keyring.mjs.map +0 -1
- package/dist/logging.cjs +0 -43
- package/dist/logging.cjs.map +0 -1
- package/dist/logging.d.cts.map +0 -1
- package/dist/logging.d.mts +0 -30
- package/dist/logging.d.mts.map +0 -1
- package/dist/logging.mjs.map +0 -1
- package/dist/misc.cjs +0 -154
- package/dist/misc.cjs.map +0 -1
- package/dist/misc.d.cts +0 -127
- package/dist/misc.d.cts.map +0 -1
- package/dist/misc.d.mts.map +0 -1
- package/dist/misc.mjs.map +0 -1
- package/dist/mnemonic.cjs +0 -53
- package/dist/mnemonic.cjs.map +0 -1
- package/dist/mnemonic.d.cts.map +0 -1
- package/dist/mnemonic.d.mts +0 -14
- package/dist/mnemonic.d.mts.map +0 -1
- package/dist/mnemonic.mjs.map +0 -1
- package/dist/node.cjs +0 -19
- package/dist/node.cjs.map +0 -1
- package/dist/node.d.cts +0 -3
- package/dist/node.d.cts.map +0 -1
- package/dist/node.d.mts +0 -3
- package/dist/node.d.mts.map +0 -1
- package/dist/node.mjs +0 -3
- package/dist/node.mjs.map +0 -1
- package/dist/number.cjs +0 -102
- package/dist/number.cjs.map +0 -1
- package/dist/number.d.cts +0 -74
- package/dist/number.d.cts.map +0 -1
- package/dist/number.d.mts.map +0 -1
- package/dist/number.mjs.map +0 -1
- package/dist/opaque.cjs +0 -3
- package/dist/opaque.cjs.map +0 -1
- package/dist/opaque.d.cts.map +0 -1
- package/dist/opaque.d.mts +0 -6
- package/dist/opaque.d.mts.map +0 -1
- package/dist/opaque.mjs +0 -2
- package/dist/opaque.mjs.map +0 -1
- package/dist/promise.cjs +0 -44
- package/dist/promise.cjs.map +0 -1
- package/dist/promise.d.cts.map +0 -1
- package/dist/promise.d.mts +0 -45
- package/dist/promise.d.mts.map +0 -1
- package/dist/promise.mjs.map +0 -1
- package/dist/superstruct.cjs +0 -28
- package/dist/superstruct.cjs.map +0 -1
- package/dist/superstruct.d.cts +0 -20
- package/dist/superstruct.d.cts.map +0 -1
- package/dist/superstruct.d.mts.map +0 -1
- package/dist/superstruct.mjs.map +0 -1
- package/dist/time.cjs +0 -67
- package/dist/time.cjs.map +0 -1
- package/dist/time.d.cts +0 -49
- package/dist/time.d.cts.map +0 -1
- package/dist/time.d.mts.map +0 -1
- package/dist/time.mjs.map +0 -1
- package/dist/transaction-types.cjs +0 -3
- package/dist/transaction-types.cjs.map +0 -1
- package/dist/transaction-types.d.cts.map +0 -1
- package/dist/transaction-types.d.mts +0 -117
- package/dist/transaction-types.d.mts.map +0 -1
- package/dist/transaction-types.mjs +0 -2
- package/dist/transaction-types.mjs.map +0 -1
- package/dist/unitsConversion.cjs +0 -217
- package/dist/unitsConversion.cjs.map +0 -1
- package/dist/unitsConversion.d.cts.map +0 -1
- package/dist/unitsConversion.d.mts +0 -80
- package/dist/unitsConversion.d.mts.map +0 -1
- package/dist/unitsConversion.mjs.map +0 -1
- package/dist/versions.cjs +0 -95
- package/dist/versions.cjs.map +0 -1
- package/dist/versions.d.cts +0 -101
- package/dist/versions.d.cts.map +0 -1
- package/dist/versions.d.mts.map +0 -1
- package/dist/versions.mjs.map +0 -1
package/dist/hashing.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hashing.mjs","sourceRoot":"","sources":["../src/hashing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,6BAA6B;AAC7D,OAAO,EACL,MAAM,IAAI,WAAW,EACrB,MAAM,IAAI,WAAW,EACtB,6BAA6B;AAE9B;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAiB;IAC5C,8DAA8D;IAC9D,IACE,QAAQ,IAAI,UAAU;QACtB,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ;QACrC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAChC,CAAC;QACD,OAAO,IAAI,UAAU,CACnB,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CACxD,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAiB;IAC5C,8DAA8D;IAC9D,IACE,QAAQ,IAAI,UAAU;QACtB,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ;QACrC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAChC,CAAC;QACD,OAAO,IAAI,UAAU,CACnB,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CACxD,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAiB;IAC5C,8DAA8D;IAC9D,IACE,QAAQ,IAAI,UAAU;QACtB,OAAO,UAAU,CAAC,MAAM,KAAK,QAAQ;QACrC,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAChC,CAAC;QACD,OAAO,IAAI,UAAU,CACnB,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,KAAK,CAAC,CACxD,CAAC;IACJ,CAAC;IACD,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC","sourcesContent":["import { sha256 as nobleSha256 } from '@noble/hashes/sha256';\nimport {\n sha512 as nobleSha512,\n sha384 as nobleSha384,\n} from '@noble/hashes/sha512';\n\n/**\n * Compute a SHA-256 digest for a given byte array.\n *\n * Uses the native crypto implementation and falls back to noble.\n *\n * @param bytes - A byte array.\n * @returns The SHA-256 hash as a byte array.\n */\nexport async function sha256(bytes: Uint8Array): Promise<Uint8Array> {\n // Use crypto.subtle.digest whenever possible as it is faster.\n if (\n 'crypto' in globalThis &&\n typeof globalThis.crypto === 'object' &&\n globalThis.crypto.subtle?.digest\n ) {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-256', bytes),\n );\n }\n return nobleSha256(bytes);\n}\n\n/**\n * Compute a SHA-512 digest for a given byte array.\n *\n * Uses the native crypto implementation and falls back to noble.\n *\n * @param bytes - A byte array.\n * @returns The SHA-512 hash as a byte array.\n */\nexport async function sha512(bytes: Uint8Array): Promise<Uint8Array> {\n // Use crypto.subtle.digest whenever possible as it is faster.\n if (\n 'crypto' in globalThis &&\n typeof globalThis.crypto === 'object' &&\n globalThis.crypto.subtle?.digest\n ) {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-512', bytes),\n );\n }\n return nobleSha512(bytes);\n}\n\n/**\n * Compute a SHA-384 digest for a given byte array.\n *\n * Uses the native crypto implementation and falls back to noble.\n *\n * @param bytes - A byte array.\n * @returns The SHA-384 hash as a byte array.\n */\nexport async function sha384(bytes: Uint8Array): Promise<Uint8Array> {\n // Use crypto.subtle.digest whenever possible as it is faster.\n if (\n 'crypto' in globalThis &&\n typeof globalThis.crypto === 'object' &&\n globalThis.crypto.subtle?.digest\n ) {\n return new Uint8Array(\n await globalThis.crypto.subtle.digest('SHA-384', bytes),\n );\n }\n return nobleSha384(bytes);\n}\n"]}
|
package/dist/hex.cjs
DELETED
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.remove0x = exports.add0x = exports.isValidHexAddress = exports.isValidHexAddressUnmemoized = exports.isValidChecksumAddress = exports.isValidChecksumAddressUnmemoized = exports.getChecksumAddress = exports.getChecksumAddressUnmemoized = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isHexChecksumAddress = exports.isHexAddress = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0;
|
|
4
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
-
const sha3_1 = require("@noble/hashes/sha3");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
|
-
const assert_1 = require("./assert.cjs");
|
|
8
|
-
// Use native regexes instead of superstruct for maximum performance.
|
|
9
|
-
// Pre-compiled regex for maximum performance - avoids recompilation on each call
|
|
10
|
-
const HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;
|
|
11
|
-
const STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;
|
|
12
|
-
const HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;
|
|
13
|
-
const HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;
|
|
14
|
-
exports.HexStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), HEX_REGEX);
|
|
15
|
-
exports.StrictHexStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), STRICT_HEX_REGEX);
|
|
16
|
-
exports.HexAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), HEX_ADDRESS_REGEX);
|
|
17
|
-
exports.HexChecksumAddressStruct = (0, superstruct_1.pattern)((0, superstruct_1.string)(), HEX_CHECKSUM_ADDRESS_REGEX);
|
|
18
|
-
const isString = (value) => typeof value === 'string';
|
|
19
|
-
/**
|
|
20
|
-
* Check if a string is a valid hex string.
|
|
21
|
-
*
|
|
22
|
-
* @param value - The value to check.
|
|
23
|
-
* @returns Whether the value is a valid hex string.
|
|
24
|
-
*/
|
|
25
|
-
function isHexString(value) {
|
|
26
|
-
return isString(value) && HEX_REGEX.test(value);
|
|
27
|
-
}
|
|
28
|
-
exports.isHexString = isHexString;
|
|
29
|
-
/**
|
|
30
|
-
* Strictly check if a string is a valid hex string. A valid hex string must
|
|
31
|
-
* start with the "0x"-prefix.
|
|
32
|
-
*
|
|
33
|
-
* @param value - The value to check.
|
|
34
|
-
* @returns Whether the value is a valid hex string.
|
|
35
|
-
*/
|
|
36
|
-
function isStrictHexString(value) {
|
|
37
|
-
return isString(value) && STRICT_HEX_REGEX.test(value);
|
|
38
|
-
}
|
|
39
|
-
exports.isStrictHexString = isStrictHexString;
|
|
40
|
-
/**
|
|
41
|
-
* Check if a string is a valid hex address.
|
|
42
|
-
*
|
|
43
|
-
* @param value - The value to check.
|
|
44
|
-
* @returns Whether the value is a valid hex address.
|
|
45
|
-
*/
|
|
46
|
-
function isHexAddress(value) {
|
|
47
|
-
return isString(value) && HEX_ADDRESS_REGEX.test(value);
|
|
48
|
-
}
|
|
49
|
-
exports.isHexAddress = isHexAddress;
|
|
50
|
-
/**
|
|
51
|
-
* Check if a string is a valid hex checksum address.
|
|
52
|
-
*
|
|
53
|
-
* @param value - The value to check.
|
|
54
|
-
* @returns Whether the value is a valid hex checksum address.
|
|
55
|
-
*/
|
|
56
|
-
function isHexChecksumAddress(value) {
|
|
57
|
-
return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);
|
|
58
|
-
}
|
|
59
|
-
exports.isHexChecksumAddress = isHexChecksumAddress;
|
|
60
|
-
/**
|
|
61
|
-
* Assert that a value is a valid hex string.
|
|
62
|
-
*
|
|
63
|
-
* @param value - The value to check.
|
|
64
|
-
* @throws If the value is not a valid hex string.
|
|
65
|
-
*/
|
|
66
|
-
function assertIsHexString(value) {
|
|
67
|
-
(0, assert_1.assert)(isHexString(value), 'Value must be a hexadecimal string.');
|
|
68
|
-
}
|
|
69
|
-
exports.assertIsHexString = assertIsHexString;
|
|
70
|
-
/**
|
|
71
|
-
* Assert that a value is a valid hex string. A valid hex string must start with
|
|
72
|
-
* the "0x"-prefix.
|
|
73
|
-
*
|
|
74
|
-
* @param value - The value to check.
|
|
75
|
-
* @throws If the value is not a valid hex string.
|
|
76
|
-
*/
|
|
77
|
-
function assertIsStrictHexString(value) {
|
|
78
|
-
(0, assert_1.assert)(isStrictHexString(value), 'Value must be a hexadecimal string, starting with "0x".');
|
|
79
|
-
}
|
|
80
|
-
exports.assertIsStrictHexString = assertIsStrictHexString;
|
|
81
|
-
/**
|
|
82
|
-
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
83
|
-
* This is the unmemoized version, primarily used for testing.
|
|
84
|
-
*
|
|
85
|
-
* @param hexAddress - The hex address to encode.
|
|
86
|
-
* @returns The address encoded according to ERC-55.
|
|
87
|
-
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
88
|
-
*/
|
|
89
|
-
function getChecksumAddressUnmemoized(hexAddress) {
|
|
90
|
-
(0, assert_1.assert)(isHexChecksumAddress(hexAddress), 'Invalid hex address.');
|
|
91
|
-
const address = remove0x(hexAddress).toLowerCase();
|
|
92
|
-
const hashBytes = (0, sha3_1.keccak_256)(address);
|
|
93
|
-
const { length } = address;
|
|
94
|
-
const result = new Array(length); // Pre-allocate array
|
|
95
|
-
for (let i = 0; i < length; i++) {
|
|
96
|
-
/* eslint-disable no-bitwise */
|
|
97
|
-
const byteIndex = i >> 1; // Faster than Math.floor(i / 2)
|
|
98
|
-
const nibbleIndex = i & 1; // Faster than i % 2
|
|
99
|
-
const byte = hashBytes[byteIndex];
|
|
100
|
-
const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;
|
|
101
|
-
/* eslint-enable no-bitwise */
|
|
102
|
-
result[i] = nibble >= 8 ? address[i].toUpperCase() : address[i];
|
|
103
|
-
}
|
|
104
|
-
return `0x${result.join('')}`;
|
|
105
|
-
}
|
|
106
|
-
exports.getChecksumAddressUnmemoized = getChecksumAddressUnmemoized;
|
|
107
|
-
/**
|
|
108
|
-
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
109
|
-
* This function is memoized for performance.
|
|
110
|
-
*
|
|
111
|
-
* @param hexAddress - The hex address to encode.
|
|
112
|
-
* @returns The address encoded according to ERC-55.
|
|
113
|
-
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
114
|
-
*/
|
|
115
|
-
exports.getChecksumAddress = (0, lodash_1.memoize)(getChecksumAddressUnmemoized);
|
|
116
|
-
/**
|
|
117
|
-
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
118
|
-
* checksum address.
|
|
119
|
-
*
|
|
120
|
-
* @param possibleChecksum - The hex address to check.
|
|
121
|
-
* @returns True if the address is a checksum address.
|
|
122
|
-
*/
|
|
123
|
-
function isValidChecksumAddressUnmemoized(possibleChecksum) {
|
|
124
|
-
if (!isHexChecksumAddress(possibleChecksum)) {
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
return (0, exports.getChecksumAddress)(possibleChecksum) === possibleChecksum;
|
|
128
|
-
}
|
|
129
|
-
exports.isValidChecksumAddressUnmemoized = isValidChecksumAddressUnmemoized;
|
|
130
|
-
/**
|
|
131
|
-
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
132
|
-
* checksum address.
|
|
133
|
-
*
|
|
134
|
-
* @param possibleChecksum - The hex address to check.
|
|
135
|
-
* @returns True if the address is a checksum address.
|
|
136
|
-
*/
|
|
137
|
-
exports.isValidChecksumAddress = (0, lodash_1.memoize)(isValidChecksumAddressUnmemoized);
|
|
138
|
-
/**
|
|
139
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
140
|
-
* hex address, or a valid mixed-case checksum address.
|
|
141
|
-
*
|
|
142
|
-
* @param possibleAddress - Input parameter to check against.
|
|
143
|
-
* @returns Whether or not the input is a valid hex address.
|
|
144
|
-
*/
|
|
145
|
-
function isValidHexAddressUnmemoized(possibleAddress) {
|
|
146
|
-
return (isHexAddress(possibleAddress) || (0, exports.isValidChecksumAddress)(possibleAddress));
|
|
147
|
-
}
|
|
148
|
-
exports.isValidHexAddressUnmemoized = isValidHexAddressUnmemoized;
|
|
149
|
-
/**
|
|
150
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
151
|
-
* hex address, or a valid mixed-case checksum address.
|
|
152
|
-
*
|
|
153
|
-
* @param possibleAddress - Input parameter to check against.
|
|
154
|
-
* @returns Whether or not the input is a valid hex address.
|
|
155
|
-
*/
|
|
156
|
-
exports.isValidHexAddress = (0, lodash_1.memoize)(isValidHexAddressUnmemoized);
|
|
157
|
-
/**
|
|
158
|
-
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
159
|
-
* prefix, it is returned as-is.
|
|
160
|
-
*
|
|
161
|
-
* @param hexadecimal - The hexadecimal string to add the prefix to.
|
|
162
|
-
* @returns The prefixed hexadecimal string.
|
|
163
|
-
*/
|
|
164
|
-
function add0x(hexadecimal) {
|
|
165
|
-
if (hexadecimal.startsWith('0x')) {
|
|
166
|
-
return hexadecimal;
|
|
167
|
-
}
|
|
168
|
-
if (hexadecimal.startsWith('0X')) {
|
|
169
|
-
return `0x${hexadecimal.substring(2)}`;
|
|
170
|
-
}
|
|
171
|
-
return `0x${hexadecimal}`;
|
|
172
|
-
}
|
|
173
|
-
exports.add0x = add0x;
|
|
174
|
-
/**
|
|
175
|
-
* Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have
|
|
176
|
-
* the prefix, it is returned as-is.
|
|
177
|
-
*
|
|
178
|
-
* @param hexadecimal - The hexadecimal string to remove the prefix from.
|
|
179
|
-
* @returns The un-prefixed hexadecimal string.
|
|
180
|
-
*/
|
|
181
|
-
function remove0x(hexadecimal) {
|
|
182
|
-
if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {
|
|
183
|
-
return hexadecimal.substring(2);
|
|
184
|
-
}
|
|
185
|
-
return hexadecimal;
|
|
186
|
-
}
|
|
187
|
-
exports.remove0x = remove0x;
|
|
188
|
-
//# sourceMappingURL=hex.cjs.map
|
package/dist/hex.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.cjs","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";;;AAAA,uDAAwD;AAExD,6CAA6D;AAC7D,mCAAiC;AAEjC,yCAAkC;AAIlC,qEAAqE;AACrE,iFAAiF;AACjF,MAAM,SAAS,GAAG,sBAAsB,CAAC;AACzC,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AAC3C,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAE7C,QAAA,SAAS,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,SAAS,CAAC,CAAC;AACzC,QAAA,eAAe,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,gBAAgB,CAGhE,CAAC;AACW,QAAA,gBAAgB,GAAG,IAAA,qBAAO,EAAC,IAAA,oBAAM,GAAE,EAAE,iBAAiB,CAGlE,CAAC;AACW,QAAA,wBAAwB,GAAG,IAAA,qBAAO,EAC7C,IAAA,oBAAM,GAAE,EACR,0BAA0B,CACN,CAAC;AAEvB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC;AAEhF;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;A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;GAMG;AACU,QAAA,iBAAiB,GAAG,IAAA,gBAAO,EAAC,2BAA2B,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,SAAgB,KAAK,CAAC,WAAmB;IACvC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO,WAAkB,CAAC;IAC5B,CAAC;IAED,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACjC,OAAO,KAAK,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;IACzC,CAAC;IAED,OAAO,KAAK,WAAW,EAAE,CAAC;AAC5B,CAAC;AAVD,sBAUC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,WAAmB;IAC1C,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACjE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAND,4BAMC","sourcesContent":["import { pattern, string } from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport { memoize } from 'lodash';\n\nimport { assert } from './assert';\n\nexport type Hex = `0x${string}`;\n\n// Use native regexes instead of superstruct for maximum performance.\n// Pre-compiled regex for maximum performance - avoids recompilation on each call\nconst HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;\nconst STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;\nconst HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;\nconst HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;\n\nexport const HexStruct = pattern(string(), HEX_REGEX);\nexport const StrictHexStruct = pattern(string(), STRICT_HEX_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(string(), HEX_ADDRESS_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n HEX_CHECKSUM_ADDRESS_REGEX,\n) as Struct<Hex, null>;\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return isString(value) && HEX_REGEX.test(value);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return isString(value) && STRICT_HEX_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex address.\n */\nexport function isHexAddress(value: unknown): value is Hex {\n return isString(value) && HEX_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex checksum address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex checksum address.\n */\nexport function isHexChecksumAddress(value: unknown): value is Hex {\n return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This is the unmemoized version, primarily used for testing.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddressUnmemoized(hexAddress: Hex): Hex {\n assert(isHexChecksumAddress(hexAddress), 'Invalid hex address.');\n const address = remove0x(hexAddress).toLowerCase();\n\n const hashBytes = keccak256(address);\n const { length } = address;\n const result = new Array(length); // Pre-allocate array\n\n for (let i = 0; i < length; i++) {\n /* eslint-disable no-bitwise */\n const byteIndex = i >> 1; // Faster than Math.floor(i / 2)\n const nibbleIndex = i & 1; // Faster than i % 2\n const byte = hashBytes[byteIndex] as number;\n const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;\n /* eslint-enable no-bitwise */\n\n result[i] = nibble >= 8 ? (address[i] as string).toUpperCase() : address[i];\n }\n\n return `0x${result.join('')}`;\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This function is memoized for performance.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport const getChecksumAddress = memoize(getChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddressUnmemoized(possibleChecksum: Hex) {\n if (!isHexChecksumAddress(possibleChecksum)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport const isValidChecksumAddress = memoize(isValidChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddressUnmemoized(possibleAddress: Hex) {\n return (\n isHexAddress(possibleAddress) || isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport const isValidHexAddress = memoize(isValidHexAddressUnmemoized);\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"]}
|
package/dist/hex.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.cts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAMpD,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAShC,eAAO,MAAM,SAAS,sBAA+B,CAAC;AACtD,eAAO,MAAM,eAAe,6BAG3B,CAAC;AACF,eAAO,MAAM,gBAAgB,6BAG5B,CAAC;AACF,eAAO,MAAM,wBAAwB,6BAGf,CAAC;AAIvB;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAEzD;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,GAAG,CAEjE;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,MAAM,CAEzE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,GAAG,CAK5E;AAED;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,CAoBjE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,yEAAwC,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,gBAAgB,EAAE,GAAG,WAMrE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,6EAA4C,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,GAAG,WAI/D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,wEAAuC,CAAC;AAEtE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG,CAU9C;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAMpD"}
|
package/dist/hex.d.mts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/// <reference types="lodash" />
|
|
2
|
-
import type { Struct } from "@metamask/superstruct";
|
|
3
|
-
export type Hex = `0x${string}`;
|
|
4
|
-
export declare const HexStruct: Struct<string, null>;
|
|
5
|
-
export declare const StrictHexStruct: Struct<`0x${string}`, null>;
|
|
6
|
-
export declare const HexAddressStruct: Struct<`0x${string}`, null>;
|
|
7
|
-
export declare const HexChecksumAddressStruct: Struct<`0x${string}`, null>;
|
|
8
|
-
/**
|
|
9
|
-
* Check if a string is a valid hex string.
|
|
10
|
-
*
|
|
11
|
-
* @param value - The value to check.
|
|
12
|
-
* @returns Whether the value is a valid hex string.
|
|
13
|
-
*/
|
|
14
|
-
export declare function isHexString(value: unknown): value is string;
|
|
15
|
-
/**
|
|
16
|
-
* Strictly check if a string is a valid hex string. A valid hex string must
|
|
17
|
-
* start with the "0x"-prefix.
|
|
18
|
-
*
|
|
19
|
-
* @param value - The value to check.
|
|
20
|
-
* @returns Whether the value is a valid hex string.
|
|
21
|
-
*/
|
|
22
|
-
export declare function isStrictHexString(value: unknown): value is Hex;
|
|
23
|
-
/**
|
|
24
|
-
* Check if a string is a valid hex address.
|
|
25
|
-
*
|
|
26
|
-
* @param value - The value to check.
|
|
27
|
-
* @returns Whether the value is a valid hex address.
|
|
28
|
-
*/
|
|
29
|
-
export declare function isHexAddress(value: unknown): value is Hex;
|
|
30
|
-
/**
|
|
31
|
-
* Check if a string is a valid hex checksum address.
|
|
32
|
-
*
|
|
33
|
-
* @param value - The value to check.
|
|
34
|
-
* @returns Whether the value is a valid hex checksum address.
|
|
35
|
-
*/
|
|
36
|
-
export declare function isHexChecksumAddress(value: unknown): value is Hex;
|
|
37
|
-
/**
|
|
38
|
-
* Assert that a value is a valid hex string.
|
|
39
|
-
*
|
|
40
|
-
* @param value - The value to check.
|
|
41
|
-
* @throws If the value is not a valid hex string.
|
|
42
|
-
*/
|
|
43
|
-
export declare function assertIsHexString(value: unknown): asserts value is string;
|
|
44
|
-
/**
|
|
45
|
-
* Assert that a value is a valid hex string. A valid hex string must start with
|
|
46
|
-
* the "0x"-prefix.
|
|
47
|
-
*
|
|
48
|
-
* @param value - The value to check.
|
|
49
|
-
* @throws If the value is not a valid hex string.
|
|
50
|
-
*/
|
|
51
|
-
export declare function assertIsStrictHexString(value: unknown): asserts value is Hex;
|
|
52
|
-
/**
|
|
53
|
-
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
54
|
-
* This is the unmemoized version, primarily used for testing.
|
|
55
|
-
*
|
|
56
|
-
* @param hexAddress - The hex address to encode.
|
|
57
|
-
* @returns The address encoded according to ERC-55.
|
|
58
|
-
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
59
|
-
*/
|
|
60
|
-
export declare function getChecksumAddressUnmemoized(hexAddress: Hex): Hex;
|
|
61
|
-
/**
|
|
62
|
-
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
63
|
-
* This function is memoized for performance.
|
|
64
|
-
*
|
|
65
|
-
* @param hexAddress - The hex address to encode.
|
|
66
|
-
* @returns The address encoded according to ERC-55.
|
|
67
|
-
* @see https://eips.ethereum.org/EIPS/eip-55
|
|
68
|
-
*/
|
|
69
|
-
export declare const getChecksumAddress: typeof getChecksumAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
70
|
-
/**
|
|
71
|
-
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
72
|
-
* checksum address.
|
|
73
|
-
*
|
|
74
|
-
* @param possibleChecksum - The hex address to check.
|
|
75
|
-
* @returns True if the address is a checksum address.
|
|
76
|
-
*/
|
|
77
|
-
export declare function isValidChecksumAddressUnmemoized(possibleChecksum: Hex): boolean;
|
|
78
|
-
/**
|
|
79
|
-
* Validate that the passed hex string is a valid ERC-55 mixed-case
|
|
80
|
-
* checksum address.
|
|
81
|
-
*
|
|
82
|
-
* @param possibleChecksum - The hex address to check.
|
|
83
|
-
* @returns True if the address is a checksum address.
|
|
84
|
-
*/
|
|
85
|
-
export declare const isValidChecksumAddress: typeof isValidChecksumAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
86
|
-
/**
|
|
87
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
88
|
-
* hex address, or a valid mixed-case checksum address.
|
|
89
|
-
*
|
|
90
|
-
* @param possibleAddress - Input parameter to check against.
|
|
91
|
-
* @returns Whether or not the input is a valid hex address.
|
|
92
|
-
*/
|
|
93
|
-
export declare function isValidHexAddressUnmemoized(possibleAddress: Hex): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Validate that the passed prefixed hex string is an all-lowercase
|
|
96
|
-
* hex address, or a valid mixed-case checksum address.
|
|
97
|
-
*
|
|
98
|
-
* @param possibleAddress - Input parameter to check against.
|
|
99
|
-
* @returns Whether or not the input is a valid hex address.
|
|
100
|
-
*/
|
|
101
|
-
export declare const isValidHexAddress: typeof isValidHexAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
102
|
-
/**
|
|
103
|
-
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
104
|
-
* prefix, it is returned as-is.
|
|
105
|
-
*
|
|
106
|
-
* @param hexadecimal - The hexadecimal string to add the prefix to.
|
|
107
|
-
* @returns The prefixed hexadecimal string.
|
|
108
|
-
*/
|
|
109
|
-
export declare function add0x(hexadecimal: string): Hex;
|
|
110
|
-
/**
|
|
111
|
-
* Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have
|
|
112
|
-
* the prefix, it is returned as-is.
|
|
113
|
-
*
|
|
114
|
-
* @param hexadecimal - The hexadecimal string to remove the prefix from.
|
|
115
|
-
* @returns The un-prefixed hexadecimal string.
|
|
116
|
-
*/
|
|
117
|
-
export declare function remove0x(hexadecimal: string): string;
|
|
118
|
-
//# sourceMappingURL=hex.d.mts.map
|
package/dist/hex.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.mts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,MAAM,EAAE,8BAA8B;AAMpD,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAShC,eAAO,MAAM,SAAS,sBAA+B,CAAC;AACtD,eAAO,MAAM,eAAe,6BAG3B,CAAC;AACF,eAAO,MAAM,gBAAgB,6BAG5B,CAAC;AACF,eAAO,MAAM,wBAAwB,6BAGf,CAAC;AAIvB;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AAW,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CAAC,WAAmB;IAC1C,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACjE,OAAO,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["import { pattern, string } from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport { memoize } from 'lodash';\n\nimport { assert } from './assert';\n\nexport type Hex = `0x${string}`;\n\n// Use native regexes instead of superstruct for maximum performance.\n// Pre-compiled regex for maximum performance - avoids recompilation on each call\nconst HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;\nconst STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;\nconst HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;\nconst HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;\n\nexport const HexStruct = pattern(string(), HEX_REGEX);\nexport const StrictHexStruct = pattern(string(), STRICT_HEX_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexAddressStruct = pattern(string(), HEX_ADDRESS_REGEX) as Struct<\n Hex,\n null\n>;\nexport const HexChecksumAddressStruct = pattern(\n string(),\n HEX_CHECKSUM_ADDRESS_REGEX,\n) as Struct<Hex, null>;\n\nconst isString = (value: unknown): value is string => typeof value === 'string';\n\n/**\n * Check if a string is a valid hex string.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isHexString(value: unknown): value is string {\n return isString(value) && HEX_REGEX.test(value);\n}\n\n/**\n * Strictly check if a string is a valid hex string. A valid hex string must\n * start with the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex string.\n */\nexport function isStrictHexString(value: unknown): value is Hex {\n return isString(value) && STRICT_HEX_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex address.\n */\nexport function isHexAddress(value: unknown): value is Hex {\n return isString(value) && HEX_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Check if a string is a valid hex checksum address.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid hex checksum address.\n */\nexport function isHexChecksumAddress(value: unknown): value is Hex {\n return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);\n}\n\n/**\n * Assert that a value is a valid hex string.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsHexString(value: unknown): asserts value is string {\n assert(isHexString(value), 'Value must be a hexadecimal string.');\n}\n\n/**\n * Assert that a value is a valid hex string. A valid hex string must start with\n * the \"0x\"-prefix.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid hex string.\n */\nexport function assertIsStrictHexString(value: unknown): asserts value is Hex {\n assert(\n isStrictHexString(value),\n 'Value must be a hexadecimal string, starting with \"0x\".',\n );\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This is the unmemoized version, primarily used for testing.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport function getChecksumAddressUnmemoized(hexAddress: Hex): Hex {\n assert(isHexChecksumAddress(hexAddress), 'Invalid hex address.');\n const address = remove0x(hexAddress).toLowerCase();\n\n const hashBytes = keccak256(address);\n const { length } = address;\n const result = new Array(length); // Pre-allocate array\n\n for (let i = 0; i < length; i++) {\n /* eslint-disable no-bitwise */\n const byteIndex = i >> 1; // Faster than Math.floor(i / 2)\n const nibbleIndex = i & 1; // Faster than i % 2\n const byte = hashBytes[byteIndex] as number;\n const nibble = nibbleIndex === 0 ? byte >> 4 : byte & 0x0f;\n /* eslint-enable no-bitwise */\n\n result[i] = nibble >= 8 ? (address[i] as string).toUpperCase() : address[i];\n }\n\n return `0x${result.join('')}`;\n}\n\n/**\n * Encode a passed hex string as an ERC-55 mixed-case checksum address.\n * This function is memoized for performance.\n *\n * @param hexAddress - The hex address to encode.\n * @returns The address encoded according to ERC-55.\n * @see https://eips.ethereum.org/EIPS/eip-55\n */\nexport const getChecksumAddress = memoize(getChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport function isValidChecksumAddressUnmemoized(possibleChecksum: Hex) {\n if (!isHexChecksumAddress(possibleChecksum)) {\n return false;\n }\n\n return getChecksumAddress(possibleChecksum) === possibleChecksum;\n}\n\n/**\n * Validate that the passed hex string is a valid ERC-55 mixed-case\n * checksum address.\n *\n * @param possibleChecksum - The hex address to check.\n * @returns True if the address is a checksum address.\n */\nexport const isValidChecksumAddress = memoize(isValidChecksumAddressUnmemoized);\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport function isValidHexAddressUnmemoized(possibleAddress: Hex) {\n return (\n isHexAddress(possibleAddress) || isValidChecksumAddress(possibleAddress)\n );\n}\n\n/**\n * Validate that the passed prefixed hex string is an all-lowercase\n * hex address, or a valid mixed-case checksum address.\n *\n * @param possibleAddress - Input parameter to check against.\n * @returns Whether or not the input is a valid hex address.\n */\nexport const isValidHexAddress = memoize(isValidHexAddressUnmemoized);\n\n/**\n * Add the `0x`-prefix to a hexadecimal string. If the string already has the\n * prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to add the prefix to.\n * @returns The prefixed hexadecimal string.\n */\nexport function add0x(hexadecimal: string): Hex {\n if (hexadecimal.startsWith('0x')) {\n return hexadecimal as Hex;\n }\n\n if (hexadecimal.startsWith('0X')) {\n return `0x${hexadecimal.substring(2)}`;\n }\n\n return `0x${hexadecimal}`;\n}\n\n/**\n * Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have\n * the prefix, it is returned as-is.\n *\n * @param hexadecimal - The hexadecimal string to remove the prefix from.\n * @returns The un-prefixed hexadecimal string.\n */\nexport function remove0x(hexadecimal: string): string {\n if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {\n return hexadecimal.substring(2);\n }\n\n return hexadecimal;\n}\n"]}
|
package/dist/index.cjs
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
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.unitMap = exports.getValueOfUnit = exports.numberToString = exports.fromWei = exports.toWei = exports.remove0x = exports.add0x = exports.isValidChecksumAddress = exports.getChecksumAddress = exports.isValidHexAddress = exports.assertIsStrictHexString = exports.assertIsHexString = exports.isHexChecksumAddress = exports.isHexAddress = exports.isStrictHexString = exports.isHexString = exports.HexChecksumAddressStruct = exports.HexAddressStruct = exports.StrictHexStruct = exports.HexStruct = void 0;
|
|
18
|
-
__exportStar(require("./assert.cjs"), exports);
|
|
19
|
-
__exportStar(require("./base64.cjs"), exports);
|
|
20
|
-
__exportStar(require("./bytes.cjs"), exports);
|
|
21
|
-
__exportStar(require("./caip-types.cjs"), exports);
|
|
22
|
-
__exportStar(require("./checksum.cjs"), exports);
|
|
23
|
-
__exportStar(require("./coercers.cjs"), exports);
|
|
24
|
-
__exportStar(require("./collections.cjs"), exports);
|
|
25
|
-
__exportStar(require("./errors.cjs"), exports);
|
|
26
|
-
__exportStar(require("./hashing.cjs"), exports);
|
|
27
|
-
var hex_1 = require("./hex.cjs");
|
|
28
|
-
Object.defineProperty(exports, "HexStruct", { enumerable: true, get: function () { return hex_1.HexStruct; } });
|
|
29
|
-
Object.defineProperty(exports, "StrictHexStruct", { enumerable: true, get: function () { return hex_1.StrictHexStruct; } });
|
|
30
|
-
Object.defineProperty(exports, "HexAddressStruct", { enumerable: true, get: function () { return hex_1.HexAddressStruct; } });
|
|
31
|
-
Object.defineProperty(exports, "HexChecksumAddressStruct", { enumerable: true, get: function () { return hex_1.HexChecksumAddressStruct; } });
|
|
32
|
-
Object.defineProperty(exports, "isHexString", { enumerable: true, get: function () { return hex_1.isHexString; } });
|
|
33
|
-
Object.defineProperty(exports, "isStrictHexString", { enumerable: true, get: function () { return hex_1.isStrictHexString; } });
|
|
34
|
-
Object.defineProperty(exports, "isHexAddress", { enumerable: true, get: function () { return hex_1.isHexAddress; } });
|
|
35
|
-
Object.defineProperty(exports, "isHexChecksumAddress", { enumerable: true, get: function () { return hex_1.isHexChecksumAddress; } });
|
|
36
|
-
Object.defineProperty(exports, "assertIsHexString", { enumerable: true, get: function () { return hex_1.assertIsHexString; } });
|
|
37
|
-
Object.defineProperty(exports, "assertIsStrictHexString", { enumerable: true, get: function () { return hex_1.assertIsStrictHexString; } });
|
|
38
|
-
Object.defineProperty(exports, "isValidHexAddress", { enumerable: true, get: function () { return hex_1.isValidHexAddress; } });
|
|
39
|
-
Object.defineProperty(exports, "getChecksumAddress", { enumerable: true, get: function () { return hex_1.getChecksumAddress; } });
|
|
40
|
-
Object.defineProperty(exports, "isValidChecksumAddress", { enumerable: true, get: function () { return hex_1.isValidChecksumAddress; } });
|
|
41
|
-
Object.defineProperty(exports, "add0x", { enumerable: true, get: function () { return hex_1.add0x; } });
|
|
42
|
-
Object.defineProperty(exports, "remove0x", { enumerable: true, get: function () { return hex_1.remove0x; } });
|
|
43
|
-
__exportStar(require("./json.cjs"), exports);
|
|
44
|
-
__exportStar(require("./logging.cjs"), exports);
|
|
45
|
-
__exportStar(require("./misc.cjs"), exports);
|
|
46
|
-
__exportStar(require("./mnemonic.cjs"), exports);
|
|
47
|
-
__exportStar(require("./number.cjs"), exports);
|
|
48
|
-
__exportStar(require("./promise.cjs"), exports);
|
|
49
|
-
__exportStar(require("./superstruct.cjs"), exports);
|
|
50
|
-
__exportStar(require("./time.cjs"), exports);
|
|
51
|
-
__exportStar(require("./versions.cjs"), exports);
|
|
52
|
-
var unitsConversion_1 = require("./unitsConversion.cjs");
|
|
53
|
-
Object.defineProperty(exports, "toWei", { enumerable: true, get: function () { return unitsConversion_1.toWei; } });
|
|
54
|
-
Object.defineProperty(exports, "fromWei", { enumerable: true, get: function () { return unitsConversion_1.fromWei; } });
|
|
55
|
-
Object.defineProperty(exports, "numberToString", { enumerable: true, get: function () { return unitsConversion_1.numberToString; } });
|
|
56
|
-
Object.defineProperty(exports, "getValueOfUnit", { enumerable: true, get: function () { return unitsConversion_1.getValueOfUnit; } });
|
|
57
|
-
Object.defineProperty(exports, "unitMap", { enumerable: true, get: function () { return unitsConversion_1.unitMap; } });
|
|
58
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAyB;AACzB,+CAAyB;AACzB,8CAAwB;AACxB,mDAA6B;AAC7B,iDAA2B;AAC3B,iDAA2B;AAC3B,oDAA8B;AAE9B,+CAAyB;AACzB,gDAA0B;AAE1B,iCAgBe;AAfb,gGAAA,SAAS,OAAA;AACT,sGAAA,eAAe,OAAA;AACf,uGAAA,gBAAgB,OAAA;AAChB,+GAAA,wBAAwB,OAAA;AACxB,kGAAA,WAAW,OAAA;AACX,wGAAA,iBAAiB,OAAA;AACjB,mGAAA,YAAY,OAAA;AACZ,2GAAA,oBAAoB,OAAA;AACpB,wGAAA,iBAAiB,OAAA;AACjB,8GAAA,uBAAuB,OAAA;AACvB,wGAAA,iBAAiB,OAAA;AACjB,yGAAA,kBAAkB,OAAA;AAClB,6GAAA,sBAAsB,OAAA;AACtB,4FAAA,KAAK,OAAA;AACL,+FAAA,QAAQ,OAAA;AAEV,6CAAuB;AAEvB,gDAA0B;AAC1B,6CAAuB;AACvB,iDAA2B;AAC3B,+CAAyB;AAEzB,gDAA0B;AAC1B,oDAA8B;AAC9B,6CAAuB;AAEvB,iDAA2B;AAC3B,yDAM2B;AALzB,wGAAA,KAAK,OAAA;AACL,0GAAA,OAAO,OAAA;AACP,iHAAA,cAAc,OAAA;AACd,iHAAA,cAAc,OAAA;AACd,0GAAA,OAAO,OAAA","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caip-types';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport type * from './encryption-types';\nexport * from './errors';\nexport * from './hashing';\nexport type { Hex } from './hex';\nexport {\n HexStruct,\n StrictHexStruct,\n HexAddressStruct,\n HexChecksumAddressStruct,\n isHexString,\n isStrictHexString,\n isHexAddress,\n isHexChecksumAddress,\n assertIsHexString,\n assertIsStrictHexString,\n isValidHexAddress,\n getChecksumAddress,\n isValidChecksumAddress,\n add0x,\n remove0x,\n} from './hex';\nexport * from './json';\nexport type * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './mnemonic';\nexport * from './number';\nexport type * from './opaque';\nexport * from './promise';\nexport * from './superstruct';\nexport * from './time';\nexport type * from './transaction-types';\nexport * from './versions';\nexport {\n toWei,\n fromWei,\n numberToString,\n getValueOfUnit,\n unitMap,\n} from './unitsConversion';\n"]}
|
package/dist/index.d.cts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export * from "./assert.cjs";
|
|
2
|
-
export * from "./base64.cjs";
|
|
3
|
-
export * from "./bytes.cjs";
|
|
4
|
-
export * from "./caip-types.cjs";
|
|
5
|
-
export * from "./checksum.cjs";
|
|
6
|
-
export * from "./coercers.cjs";
|
|
7
|
-
export * from "./collections.cjs";
|
|
8
|
-
export type * from "./encryption-types.cjs";
|
|
9
|
-
export * from "./errors.cjs";
|
|
10
|
-
export * from "./hashing.cjs";
|
|
11
|
-
export type { Hex } from "./hex.cjs";
|
|
12
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from "./hex.cjs";
|
|
13
|
-
export * from "./json.cjs";
|
|
14
|
-
export type * from "./keyring.cjs";
|
|
15
|
-
export * from "./logging.cjs";
|
|
16
|
-
export * from "./misc.cjs";
|
|
17
|
-
export * from "./mnemonic.cjs";
|
|
18
|
-
export * from "./number.cjs";
|
|
19
|
-
export type * from "./opaque.cjs";
|
|
20
|
-
export * from "./promise.cjs";
|
|
21
|
-
export * from "./superstruct.cjs";
|
|
22
|
-
export * from "./time.cjs";
|
|
23
|
-
export type * from "./transaction-types.cjs";
|
|
24
|
-
export * from "./versions.cjs";
|
|
25
|
-
export { toWei, fromWei, numberToString, getValueOfUnit, unitMap, } from "./unitsConversion.cjs";
|
|
26
|
-
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,4CAAwC;AACxC,6BAAyB;AACzB,8BAA0B;AAC1B,YAAY,EAAE,GAAG,EAAE,kBAAc;AACjC,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,GACT,kBAAc;AACf,2BAAuB;AACvB,mCAA+B;AAC/B,8BAA0B;AAC1B,2BAAuB;AACvB,+BAA2B;AAC3B,6BAAyB;AACzB,kCAA8B;AAC9B,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,6CAAyC;AACzC,+BAA2B;AAC3B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,GACR,8BAA0B"}
|
package/dist/index.d.mts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export * from "./assert.mjs";
|
|
2
|
-
export * from "./base64.mjs";
|
|
3
|
-
export * from "./bytes.mjs";
|
|
4
|
-
export * from "./caip-types.mjs";
|
|
5
|
-
export * from "./checksum.mjs";
|
|
6
|
-
export * from "./coercers.mjs";
|
|
7
|
-
export * from "./collections.mjs";
|
|
8
|
-
export type * from "./encryption-types.mjs";
|
|
9
|
-
export * from "./errors.mjs";
|
|
10
|
-
export * from "./hashing.mjs";
|
|
11
|
-
export type { Hex } from "./hex.mjs";
|
|
12
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from "./hex.mjs";
|
|
13
|
-
export * from "./json.mjs";
|
|
14
|
-
export type * from "./keyring.mjs";
|
|
15
|
-
export * from "./logging.mjs";
|
|
16
|
-
export * from "./misc.mjs";
|
|
17
|
-
export * from "./mnemonic.mjs";
|
|
18
|
-
export * from "./number.mjs";
|
|
19
|
-
export type * from "./opaque.mjs";
|
|
20
|
-
export * from "./promise.mjs";
|
|
21
|
-
export * from "./superstruct.mjs";
|
|
22
|
-
export * from "./time.mjs";
|
|
23
|
-
export type * from "./transaction-types.mjs";
|
|
24
|
-
export * from "./versions.mjs";
|
|
25
|
-
export { toWei, fromWei, numberToString, getValueOfUnit, unitMap, } from "./unitsConversion.mjs";
|
|
26
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAC9B,4CAAwC;AACxC,6BAAyB;AACzB,8BAA0B;AAC1B,YAAY,EAAE,GAAG,EAAE,kBAAc;AACjC,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,GACT,kBAAc;AACf,2BAAuB;AACvB,mCAA+B;AAC/B,8BAA0B;AAC1B,2BAAuB;AACvB,+BAA2B;AAC3B,6BAAyB;AACzB,kCAA8B;AAC9B,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AACvB,6CAAyC;AACzC,+BAA2B;AAC3B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,GACR,8BAA0B"}
|
package/dist/index.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export * from "./assert.mjs";
|
|
2
|
-
export * from "./base64.mjs";
|
|
3
|
-
export * from "./bytes.mjs";
|
|
4
|
-
export * from "./caip-types.mjs";
|
|
5
|
-
export * from "./checksum.mjs";
|
|
6
|
-
export * from "./coercers.mjs";
|
|
7
|
-
export * from "./collections.mjs";
|
|
8
|
-
export * from "./errors.mjs";
|
|
9
|
-
export * from "./hashing.mjs";
|
|
10
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x } from "./hex.mjs";
|
|
11
|
-
export * from "./json.mjs";
|
|
12
|
-
export * from "./logging.mjs";
|
|
13
|
-
export * from "./misc.mjs";
|
|
14
|
-
export * from "./mnemonic.mjs";
|
|
15
|
-
export * from "./number.mjs";
|
|
16
|
-
export * from "./promise.mjs";
|
|
17
|
-
export * from "./superstruct.mjs";
|
|
18
|
-
export * from "./time.mjs";
|
|
19
|
-
export * from "./versions.mjs";
|
|
20
|
-
export { toWei, fromWei, numberToString, getValueOfUnit, unitMap } from "./unitsConversion.mjs";
|
|
21
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6BAAyB;AACzB,6BAAyB;AACzB,4BAAwB;AACxB,iCAA6B;AAC7B,+BAA2B;AAC3B,+BAA2B;AAC3B,kCAA8B;AAE9B,6BAAyB;AACzB,8BAA0B;AAE1B,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,iBAAiB,EACjB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,KAAK,EACL,QAAQ,EACT,kBAAc;AACf,2BAAuB;AAEvB,8BAA0B;AAC1B,2BAAuB;AACvB,+BAA2B;AAC3B,6BAAyB;AAEzB,8BAA0B;AAC1B,kCAA8B;AAC9B,2BAAuB;AAEvB,+BAA2B;AAC3B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,EACR,8BAA0B","sourcesContent":["export * from './assert';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caip-types';\nexport * from './checksum';\nexport * from './coercers';\nexport * from './collections';\nexport type * from './encryption-types';\nexport * from './errors';\nexport * from './hashing';\nexport type { Hex } from './hex';\nexport {\n HexStruct,\n StrictHexStruct,\n HexAddressStruct,\n HexChecksumAddressStruct,\n isHexString,\n isStrictHexString,\n isHexAddress,\n isHexChecksumAddress,\n assertIsHexString,\n assertIsStrictHexString,\n isValidHexAddress,\n getChecksumAddress,\n isValidChecksumAddress,\n add0x,\n remove0x,\n} from './hex';\nexport * from './json';\nexport type * from './keyring';\nexport * from './logging';\nexport * from './misc';\nexport * from './mnemonic';\nexport * from './number';\nexport type * from './opaque';\nexport * from './promise';\nexport * from './superstruct';\nexport * from './time';\nexport type * from './transaction-types';\nexport * from './versions';\nexport {\n toWei,\n fromWei,\n numberToString,\n getValueOfUnit,\n unitMap,\n} from './unitsConversion';\n"]}
|