@metamask-previews/utils 12.0.0-preview-21ae346cb → 12.0.0-preview-bd4de146a
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 +3 -0
- package/dist/coercers.d.ts +1 -1
- package/dist/coercers.d.ts.map +1 -1
- package/dist/coercers.js +1 -1
- package/dist/coercers.js.map +1 -1
- package/dist/hex.d.ts +1 -47
- package/dist/hex.d.ts.map +1 -1
- package/dist/hex.js +1 -71
- package/dist/hex.js.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/keyring.d.ts +1 -1
- package/dist/keyring.d.ts.map +1 -1
- package/dist/keyring.js.map +1 -1
- package/dist/transaction-types.d.ts +2 -2
- package/dist/transaction-types.d.ts.map +1 -1
- package/dist/transaction-types.js.map +1 -1
- package/package.json +2 -2
- package/dist/bytes.d.ts +0 -198
- package/dist/bytes.d.ts.map +0 -1
- package/dist/bytes.js +0 -419
- package/dist/bytes.js.map +0 -1
- package/dist/number.d.ts +0 -74
- package/dist/number.d.ts.map +0 -1
- package/dist/number.js +0 -95
- package/dist/number.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -27,6 +27,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
27
27
|
- Move `FileSandbox`, `createSandbox`, `directoryExists`, `ensureDirectoryStructureExists`, `fileExists`, `forceRemove`, `readFile`, `readJsonFile`, `writeFile`, and `writeJsonFile` to `@metamask/node-utils` ([#10926](https://github.com/MetaMask/core/pull/10926))
|
|
28
28
|
- These are still re-exported from `@metamask/utils/node`, so the public API is unchanged.
|
|
29
29
|
- It's recommended to import these types and functions from `@metamask/node-utils` instead of `@metamask/utils/node` going forward.
|
|
30
|
+
- Move `Bytes`, `Hex`, `HEX_REGEX`, `STRICT_HEX_REGEX`, `add0x`, `areUint8ArraysEqual`, `assertIsBytes`, `assertIsHexString`, `assertIsStrictHexString`, `base64ToBytes`, `bigIntToBytes`, `bigIntToHex`, `bytesToBase64`, `bytesToBigInt`, `bytesToHex`, `bytesToNumber`, `bytesToSignedBigInt`, `bytesToString`, `concatBytes`, `createDataView`, `hexToBigInt`, `hexToBytes`, `hexToNumber`, `isBytes`, `isHexString`, `isStrictHexString`, `numberToBytes`, `numberToHex`, `remove0x`, `signedBigIntToBytes`, `stringToBytes`, and `valueToBytes` to `@metamask/byte-utils` ([#11037](https://github.com/MetaMask/core/pull/11037))
|
|
31
|
+
- These are still re-exported from `@metamask/utils`, so the public API is unchanged.
|
|
32
|
+
- It's recommended to import these types and functions from `@metamask/byte-utils` instead of `@metamask/utils` going forward.
|
|
30
33
|
- Bump `uuid` from `^9.0.1` to `^11.1.1` ([#10243](https://github.com/MetaMask/core/pull/10243))
|
|
31
34
|
- Bump `semver` from `^7.6.3` to `^7.8.5` ([#10443](https://github.com/MetaMask/core/pull/10443))
|
|
32
35
|
- Bump `pony-cause` from `^2.1.10` to `^2.1.11` ([#10440](https://github.com/MetaMask/core/pull/10440))
|
package/dist/coercers.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { Hex } from '@metamask/byte-utils';
|
|
1
2
|
import type { Infer } from '@metamask/superstruct';
|
|
2
|
-
import type { Hex } from './hex.js';
|
|
3
3
|
declare const NumberLikeStruct: import("@metamask/superstruct").Struct<string | number | bigint, null>;
|
|
4
4
|
declare const BytesLikeStruct: import("@metamask/superstruct").Struct<Uint8Array<ArrayBuffer> | `0x${string}`, null>;
|
|
5
5
|
export type NumberLike = Infer<typeof NumberLikeStruct>;
|
package/dist/coercers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coercers.d.ts","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"coercers.d.ts","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAenD,QAAA,MAAM,gBAAgB,wEAAyD,CAAC;AAKhF,QAAA,MAAM,eAAe,uFAAiD,CAAC;AASvE,MAAM,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAEtD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAkBtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAgBtD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,UAAU,CAkBxD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,GAAG,GAAG,CAqB/C"}
|
package/dist/coercers.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { bytesToHex, hexToBytes } from '@metamask/byte-utils';
|
|
1
2
|
import { bigint, coerce, create, instance, number, string, StructError, union, } from '@metamask/superstruct';
|
|
2
3
|
import { assert } from '@metamask/type-utils';
|
|
3
|
-
import { bytesToHex, hexToBytes } from './bytes.js';
|
|
4
4
|
import { StrictHexStruct } from './hex.js';
|
|
5
5
|
const NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);
|
|
6
6
|
const NumberCoercer = coerce(number(), NumberLikeStruct, Number);
|
package/dist/coercers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coercers.js","sourceRoot":"","sources":["../src/coercers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":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AED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,SAAS,CAAC,KAAgB;IACxC,IACE,CAAC,KAAK,YAAY,UAAU,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC;QACnD,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,EAC3D,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,iHAAiH;QACjH,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CACb,qCAAqC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAC7D,CAAC;QACJ,CAAC;QAED,0BAA0B;QAC1B,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC","sourcesContent":["import { bytesToHex, hexToBytes } from '@metamask/byte-utils';\nimport type { Hex } from '@metamask/byte-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n bigint,\n coerce,\n create,\n instance,\n number,\n string,\n StructError,\n union,\n} from '@metamask/superstruct';\nimport { assert } from '@metamask/type-utils';\n\nimport { StrictHexStruct } from './hex.js';\n\nconst NumberLikeStruct = union([number(), bigint(), string(), StrictHexStruct]);\nconst NumberCoercer = coerce(number(), NumberLikeStruct, Number);\nconst BigIntCoercer = coerce(bigint(), NumberLikeStruct, BigInt);\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Only referenced via `Infer<typeof ...>` below, but the value is required for that.\nconst BytesLikeStruct = union([StrictHexStruct, instance(Uint8Array)]);\nconst BytesCoercer = coerce(\n instance(Uint8Array),\n union([StrictHexStruct]),\n hexToBytes,\n);\n\nconst HexCoercer = coerce(StrictHexStruct, instance(Uint8Array), bytesToHex);\n\nexport type NumberLike = Infer<typeof NumberLikeStruct>;\nexport type BytesLike = Infer<typeof BytesLikeStruct>;\n\n/**\n * Create a number from a number-like value.\n *\n * - If the value is a number, it is returned as-is.\n * - If the value is a `bigint`, it is converted to a number.\n * - If the value is a string, it is interpreted as a decimal number.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number.\n *\n * This validates that the value is a number-like value, and that the resulting\n * number is not `NaN` or `Infinity`.\n *\n * @example\n * ```typescript\n * const value = createNumber('0x010203');\n * console.log(value); // 66051\n *\n * const otherValue = createNumber(123n);\n * console.log(otherValue); // 123\n * ```\n * @param value - The value to create the number from.\n * @returns The created number.\n * @throws If the value is not a number-like value, or if the resulting number\n * is `NaN` or `Infinity`.\n */\nexport function createNumber(value: NumberLike): number {\n try {\n const result = create(value, NumberCoercer);\n\n assert(\n Number.isFinite(result),\n `Expected a number-like value, got \"${value}\".`,\n );\n\n return result;\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(`Expected a number-like value, got \"${value}\".`);\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a `bigint` from a number-like value.\n *\n * - If the value is a number, it is converted to a `bigint`.\n * - If the value is a `bigint`, it is returned as-is.\n * - If the value is a string, it is interpreted as a decimal number and\n * converted to a `bigint`.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is\n * interpreted as a hexadecimal number and converted to a `bigint`.\n *\n * @example\n * ```typescript\n * const value = createBigInt('0x010203');\n * console.log(value); // 16909060n\n *\n * const otherValue = createBigInt(123);\n * console.log(otherValue); // 123n\n * ```\n * @param value - The value to create the bigint from.\n * @returns The created bigint.\n * @throws If the value is not a number-like value.\n */\nexport function createBigInt(value: NumberLike): bigint {\n try {\n // The `BigInt` constructor throws if the value is not a number-like value.\n // There is no need to validate the value manually.\n return create(value, BigIntCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a number-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a byte array from a bytes-like value.\n *\n * - If the value is a byte array, it is returned as-is.\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is interpreted\n * as a hexadecimal number and converted to a byte array.\n *\n * @example\n * ```typescript\n * const value = createBytes('0x010203');\n * console.log(value); // Uint8Array [ 1, 2, 3 ]\n *\n * const otherValue = createBytes('0x010203');\n * console.log(otherValue); // Uint8Array [ 1, 2, 3 ]\n * ```\n * @param value - The value to create the byte array from.\n * @returns The created byte array.\n * @throws If the value is not a bytes-like value.\n */\nexport function createBytes(value: BytesLike): Uint8Array {\n if (typeof value === 'string' && value.toLowerCase() === '0x') {\n return new Uint8Array();\n }\n\n try {\n return create(value, BytesCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n\n/**\n * Create a hexadecimal string from a bytes-like value.\n *\n * - If the value is a hex string (i.e., it starts with \"0x\"), it is returned\n * as-is.\n * - If the value is a `Uint8Array`, it is converted to a hex string.\n *\n * @example\n * ```typescript\n * const value = createHex(new Uint8Array([1, 2, 3]));\n * console.log(value); // '0x010203'\n *\n * const otherValue = createHex('0x010203');\n * console.log(otherValue); // '0x010203'\n * ```\n * @param value - The value to create the hex string from.\n * @returns The created hex string.\n * @throws If the value is not a bytes-like value.\n */\nexport function createHex(value: BytesLike): Hex {\n if (\n (value instanceof Uint8Array && value.length === 0) ||\n (typeof value === 'string' && value.toLowerCase() === '0x')\n ) {\n return '0x';\n }\n\n try {\n return create(value, HexCoercer);\n } catch (error) {\n /* istanbul ignore else -- Coercion failures always surface as StructError; the rethrow below is a safety net. */\n if (error instanceof StructError) {\n throw new Error(\n `Expected a bytes-like value, got \"${String(error.value)}\".`,\n );\n }\n\n /* istanbul ignore next */\n throw error;\n }\n}\n"]}
|
package/dist/hex.d.ts
CHANGED
|
@@ -1,24 +1,9 @@
|
|
|
1
|
+
import { Hex } from '@metamask/byte-utils';
|
|
1
2
|
import type { Struct } from '@metamask/superstruct';
|
|
2
|
-
export type Hex = `0x${string}`;
|
|
3
3
|
export declare const HexStruct: Struct<string, null>;
|
|
4
4
|
export declare const StrictHexStruct: Struct<Hex, null>;
|
|
5
5
|
export declare const HexAddressStruct: Struct<Hex, null>;
|
|
6
6
|
export declare const HexChecksumAddressStruct: Struct<Hex, null>;
|
|
7
|
-
/**
|
|
8
|
-
* Check if a string is a valid hex string.
|
|
9
|
-
*
|
|
10
|
-
* @param value - The value to check.
|
|
11
|
-
* @returns Whether the value is a valid hex string.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isHexString(value: unknown): value is string;
|
|
14
|
-
/**
|
|
15
|
-
* Strictly check if a string is a valid hex string. A valid hex string must
|
|
16
|
-
* start with the "0x"-prefix.
|
|
17
|
-
*
|
|
18
|
-
* @param value - The value to check.
|
|
19
|
-
* @returns Whether the value is a valid hex string.
|
|
20
|
-
*/
|
|
21
|
-
export declare function isStrictHexString(value: unknown): value is Hex;
|
|
22
7
|
/**
|
|
23
8
|
* Check if a string is a valid hex address.
|
|
24
9
|
*
|
|
@@ -33,21 +18,6 @@ export declare function isHexAddress(value: unknown): value is Hex;
|
|
|
33
18
|
* @returns Whether the value is a valid hex checksum address.
|
|
34
19
|
*/
|
|
35
20
|
export declare function isHexChecksumAddress(value: unknown): value is Hex;
|
|
36
|
-
/**
|
|
37
|
-
* Assert that a value is a valid hex string.
|
|
38
|
-
*
|
|
39
|
-
* @param value - The value to check.
|
|
40
|
-
* @throws If the value is not a valid hex string.
|
|
41
|
-
*/
|
|
42
|
-
export declare function assertIsHexString(value: unknown): asserts value is string;
|
|
43
|
-
/**
|
|
44
|
-
* Assert that a value is a valid hex string. A valid hex string must start with
|
|
45
|
-
* the "0x"-prefix.
|
|
46
|
-
*
|
|
47
|
-
* @param value - The value to check.
|
|
48
|
-
* @throws If the value is not a valid hex string.
|
|
49
|
-
*/
|
|
50
|
-
export declare function assertIsStrictHexString(value: unknown): asserts value is Hex;
|
|
51
21
|
/**
|
|
52
22
|
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
53
23
|
* This is the unmemoized version, primarily used for testing.
|
|
@@ -98,20 +68,4 @@ export declare function isValidHexAddressUnmemoized(possibleAddress: Hex): boole
|
|
|
98
68
|
* @returns Whether or not the input is a valid hex address.
|
|
99
69
|
*/
|
|
100
70
|
export declare const isValidHexAddress: typeof isValidHexAddressUnmemoized & import("lodash").MemoizedFunction;
|
|
101
|
-
/**
|
|
102
|
-
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
103
|
-
* prefix, it is returned as-is.
|
|
104
|
-
*
|
|
105
|
-
* @param hexadecimal - The hexadecimal string to add the prefix to.
|
|
106
|
-
* @returns The prefixed hexadecimal string.
|
|
107
|
-
*/
|
|
108
|
-
export declare function add0x(hexadecimal: string): Hex;
|
|
109
|
-
/**
|
|
110
|
-
* Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have
|
|
111
|
-
* the prefix, it is returned as-is.
|
|
112
|
-
*
|
|
113
|
-
* @param hexadecimal - The hexadecimal string to remove the prefix from.
|
|
114
|
-
* @returns The un-prefixed hexadecimal string.
|
|
115
|
-
*/
|
|
116
|
-
export declare function remove0x(hexadecimal: string): string;
|
|
117
71
|
//# sourceMappingURL=hex.d.ts.map
|
package/dist/hex.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EAIJ,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAQpD,eAAO,MAAM,SAAS,sBAA+B,CAAC;AACtD,eAAO,MAAM,eAAe,EAA0C,MAAM,CAC1E,GAAG,EACH,IAAI,CACL,CAAC;AACF,eAAO,MAAM,gBAAgB,EAA2C,MAAM,CAC5E,GAAG,EACH,IAAI,CACL,CAAC;AACF,eAAO,MAAM,wBAAwB,EAGhC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AAIvB;;;;;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;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG,CAoBjE;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,yEAAwC,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAC9C,gBAAgB,EAAE,GAAG,GACpB,OAAO,CAMT;AAED;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,6EAA4C,CAAC;AAEhF;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,eAAe,EAAE,GAAG,GAAG,OAAO,CAIzE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,wEAAuC,CAAC"}
|
package/dist/hex.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
+
import { HEX_REGEX, remove0x, STRICT_HEX_REGEX, } from '@metamask/byte-utils';
|
|
1
2
|
import { pattern, string } from '@metamask/superstruct';
|
|
2
3
|
import { assert } from '@metamask/type-utils';
|
|
3
4
|
import { keccak_256 as keccak256 } from '@noble/hashes/sha3';
|
|
4
5
|
import memoize from 'lodash/memoize.js';
|
|
5
|
-
// Use native regexes instead of superstruct for maximum performance.
|
|
6
|
-
// Pre-compiled regex for maximum performance - avoids recompilation on each call
|
|
7
|
-
const HEX_REGEX = /^(?:0x)?[0-9a-f]+$/iu;
|
|
8
|
-
const STRICT_HEX_REGEX = /^0x[0-9a-f]+$/iu;
|
|
9
6
|
const HEX_ADDRESS_REGEX = /^0x[0-9a-f]{40}$/u;
|
|
10
7
|
const HEX_CHECKSUM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/u;
|
|
11
8
|
export const HexStruct = pattern(string(), HEX_REGEX);
|
|
@@ -13,25 +10,6 @@ export const StrictHexStruct = pattern(string(), STRICT_HEX_REGEX);
|
|
|
13
10
|
export const HexAddressStruct = pattern(string(), HEX_ADDRESS_REGEX);
|
|
14
11
|
export const HexChecksumAddressStruct = pattern(string(), HEX_CHECKSUM_ADDRESS_REGEX);
|
|
15
12
|
const isString = (value) => typeof value === 'string';
|
|
16
|
-
/**
|
|
17
|
-
* Check if a string is a valid hex string.
|
|
18
|
-
*
|
|
19
|
-
* @param value - The value to check.
|
|
20
|
-
* @returns Whether the value is a valid hex string.
|
|
21
|
-
*/
|
|
22
|
-
export function isHexString(value) {
|
|
23
|
-
return isString(value) && HEX_REGEX.test(value);
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Strictly check if a string is a valid hex string. A valid hex string must
|
|
27
|
-
* start with the "0x"-prefix.
|
|
28
|
-
*
|
|
29
|
-
* @param value - The value to check.
|
|
30
|
-
* @returns Whether the value is a valid hex string.
|
|
31
|
-
*/
|
|
32
|
-
export function isStrictHexString(value) {
|
|
33
|
-
return isString(value) && STRICT_HEX_REGEX.test(value);
|
|
34
|
-
}
|
|
35
13
|
/**
|
|
36
14
|
* Check if a string is a valid hex address.
|
|
37
15
|
*
|
|
@@ -50,25 +28,6 @@ export function isHexAddress(value) {
|
|
|
50
28
|
export function isHexChecksumAddress(value) {
|
|
51
29
|
return isString(value) && HEX_CHECKSUM_ADDRESS_REGEX.test(value);
|
|
52
30
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Assert that a value is a valid hex string.
|
|
55
|
-
*
|
|
56
|
-
* @param value - The value to check.
|
|
57
|
-
* @throws If the value is not a valid hex string.
|
|
58
|
-
*/
|
|
59
|
-
export function assertIsHexString(value) {
|
|
60
|
-
assert(isHexString(value), 'Value must be a hexadecimal string.');
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Assert that a value is a valid hex string. A valid hex string must start with
|
|
64
|
-
* the "0x"-prefix.
|
|
65
|
-
*
|
|
66
|
-
* @param value - The value to check.
|
|
67
|
-
* @throws If the value is not a valid hex string.
|
|
68
|
-
*/
|
|
69
|
-
export function assertIsStrictHexString(value) {
|
|
70
|
-
assert(isStrictHexString(value), 'Value must be a hexadecimal string, starting with "0x".');
|
|
71
|
-
}
|
|
72
31
|
/**
|
|
73
32
|
* Encode a passed hex string as an ERC-55 mixed-case checksum address.
|
|
74
33
|
* This is the unmemoized version, primarily used for testing.
|
|
@@ -142,33 +101,4 @@ export function isValidHexAddressUnmemoized(possibleAddress) {
|
|
|
142
101
|
* @returns Whether or not the input is a valid hex address.
|
|
143
102
|
*/
|
|
144
103
|
export const isValidHexAddress = memoize(isValidHexAddressUnmemoized);
|
|
145
|
-
/**
|
|
146
|
-
* Add the `0x`-prefix to a hexadecimal string. If the string already has the
|
|
147
|
-
* prefix, it is returned as-is.
|
|
148
|
-
*
|
|
149
|
-
* @param hexadecimal - The hexadecimal string to add the prefix to.
|
|
150
|
-
* @returns The prefixed hexadecimal string.
|
|
151
|
-
*/
|
|
152
|
-
export function add0x(hexadecimal) {
|
|
153
|
-
if (hexadecimal.startsWith('0x')) {
|
|
154
|
-
return hexadecimal;
|
|
155
|
-
}
|
|
156
|
-
if (hexadecimal.startsWith('0X')) {
|
|
157
|
-
return `0x${hexadecimal.substring(2)}`;
|
|
158
|
-
}
|
|
159
|
-
return `0x${hexadecimal}`;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Remove the `0x`-prefix from a hexadecimal string. If the string doesn't have
|
|
163
|
-
* the prefix, it is returned as-is.
|
|
164
|
-
*
|
|
165
|
-
* @param hexadecimal - The hexadecimal string to remove the prefix from.
|
|
166
|
-
* @returns The un-prefixed hexadecimal string.
|
|
167
|
-
*/
|
|
168
|
-
export function remove0x(hexadecimal) {
|
|
169
|
-
if (hexadecimal.startsWith('0x') || hexadecimal.startsWith('0X')) {
|
|
170
|
-
return hexadecimal.substring(2);
|
|
171
|
-
}
|
|
172
|
-
return hexadecimal;
|
|
173
|
-
}
|
|
174
104
|
//# sourceMappingURL=hex.js.map
|
package/dist/hex.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAIxC,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;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,CAAC;AACtD,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,gBAAgB,CAGhE,CAAC;AACF,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAGlE,CAAC;AACF,MAAM,CAAC,MAAM,wBAAwB,GAAG,OAAO,CAC7C,MAAM,EAAE,EACR,0BAA0B,CACN,CAAC;AAEvB,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAmB,EAAE,CAAC,OAAO,KAAK,KAAK,Q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AAsB,CAAC,eAAe,CAAC,CACzE,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,MAAM,UAAU,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;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 { assert } from '@metamask/type-utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport memoize from 'lodash/memoize.js';\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(\n possibleChecksum: Hex,\n): boolean {\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): boolean {\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"]}
|
|
1
|
+
{"version":3,"file":"hex.js","sourceRoot":"","sources":["../src/hex.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,SAAS,EACT,QAAQ,EACR,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,UAAU,IAAI,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,OAAO,MAAM,mBAAmB,CAAC;AAExC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AAC9C,MAAM,0BAA0B,GAAG,sBAAsB,CAAC;AAE1D,MAAM,CAAC,MAAM,SAAS,GAAG,OAA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EX,\n} from '@metamask/byte-utils';\nimport { pattern, string } from '@metamask/superstruct';\nimport type { Struct } from '@metamask/superstruct';\nimport { assert } from '@metamask/type-utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\nimport memoize from 'lodash/memoize.js';\n\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 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 * 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(\n possibleChecksum: Hex,\n): boolean {\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): boolean {\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"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
export * from './assert.js';
|
|
2
2
|
export * from './base64.js';
|
|
3
|
-
export * from './bytes.js';
|
|
4
3
|
export * from './caip-types.js';
|
|
5
4
|
export * from './checksum.js';
|
|
6
5
|
export * from './coercers.js';
|
|
7
6
|
export * from './collections.js';
|
|
8
7
|
export type * from './encryption-types.js';
|
|
9
8
|
export * from './hashing.js';
|
|
10
|
-
export
|
|
11
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexString, isStrictHexString, isHexAddress, isHexChecksumAddress, assertIsHexString, assertIsStrictHexString, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, add0x, remove0x, } from './hex.js';
|
|
9
|
+
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexAddress, isHexChecksumAddress, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, } from './hex.js';
|
|
12
10
|
export * from './json.js';
|
|
13
11
|
export type * from './keyring.js';
|
|
14
12
|
export * from './logging.js';
|
|
15
13
|
export * from './misc.js';
|
|
16
14
|
export * from './mnemonic.js';
|
|
17
|
-
export * from './number.js';
|
|
18
15
|
export type * from './opaque.js';
|
|
19
16
|
export * from './promise.js';
|
|
20
17
|
export * from './superstruct.js';
|
|
@@ -22,6 +19,8 @@ export * from './time.js';
|
|
|
22
19
|
export type * from './transaction-types.js';
|
|
23
20
|
export * from './versions.js';
|
|
24
21
|
export { toWei, fromWei, numberToString, getValueOfUnit, unitMap, } from './unitsConversion.js';
|
|
22
|
+
export type { Bytes, Hex } from '@metamask/byte-utils';
|
|
23
|
+
export { HEX_REGEX, STRICT_HEX_REGEX, add0x, assertIsHexString, assertIsStrictHexString, areUint8ArraysEqual, assertIsBytes, base64ToBytes, bigIntToBytes, bigIntToHex, bytesToBase64, bytesToBigInt, bytesToHex, bytesToNumber, bytesToSignedBigInt, bytesToString, concatBytes, createDataView, hexToBigInt, hexToNumber, hexToBytes, isBytes, isHexString, isStrictHexString, numberToBytes, numberToHex, remove0x, signedBigIntToBytes, stringToBytes, valueToBytes, } from '@metamask/byte-utils';
|
|
25
24
|
export { ensureError, getErrorMessage, isErrorWithCode, isErrorWithMessage, isErrorWithStack, wrapError, } from '@metamask/error-utils';
|
|
26
25
|
export type { AssertionErrorConstructor, Json, Mutable, NonEmptyArray, PartialOrAbsent, PublicInterface, RuntimeObject, RuntimeObject as PlainObject, } from '@metamask/type-utils';
|
|
27
26
|
export { AssertionError, assert, assertExhaustive, isNonEmptyArray, getKnownPropertyNames, hasProperty, isNullOrUndefined, isObject, isPlainObject, } from '@metamask/type-utils';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,mBAAmB,uBAAuB,CAAC;AAC3C,cAAc,cAAc,CAAC;AAC7B,OAAO,EACL,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,wBAAwB,EACxB,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,GACvB,MAAM,UAAU,CAAC;AAClB,cAAc,WAAW,CAAC;AAC1B,mBAAmB,cAAc,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,mBAAmB,aAAa,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,mBAAmB,wBAAwB,CAAC;AAC5C,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,KAAK,EACL,OAAO,EACP,cAAc,EACd,cAAc,EACd,OAAO,GACR,MAAM,sBAAsB,CAAC;AAG9B,YAAY,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,iBAAiB,EACjB,uBAAuB,EACvB,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,aAAa,EACb,aAAa,EACb,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,WAAW,EACX,cAAc,EACd,WAAW,EACX,WAAW,EACX,UAAU,EACV,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,WAAW,EACX,QAAQ,EACR,mBAAmB,EACnB,aAAa,EACb,YAAY,GACb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,WAAW,EACX,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,gBAAgB,EAChB,SAAS,GACV,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACV,yBAAyB,EACzB,IAAI,EACJ,OAAO,EACP,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,EACb,aAAa,IAAI,WAAW,GAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,cAAc,EACd,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,WAAW,EACX,iBAAiB,EACjB,QAAQ,EACR,aAAa,GACd,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
export * from './assert.js';
|
|
2
2
|
export * from './base64.js';
|
|
3
|
-
export * from './bytes.js';
|
|
4
3
|
export * from './caip-types.js';
|
|
5
4
|
export * from './checksum.js';
|
|
6
5
|
export * from './coercers.js';
|
|
7
6
|
export * from './collections.js';
|
|
8
7
|
export * from './hashing.js';
|
|
9
|
-
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct,
|
|
8
|
+
export { HexStruct, StrictHexStruct, HexAddressStruct, HexChecksumAddressStruct, isHexAddress, isHexChecksumAddress, isValidHexAddress, getChecksumAddress, isValidChecksumAddress, } from './hex.js';
|
|
10
9
|
export * from './json.js';
|
|
11
10
|
export * from './logging.js';
|
|
12
11
|
export * from './misc.js';
|
|
13
12
|
export * from './mnemonic.js';
|
|
14
|
-
export * from './number.js';
|
|
15
13
|
export * from './promise.js';
|
|
16
14
|
export * from './superstruct.js';
|
|
17
15
|
export * from './time.js';
|
|
18
16
|
export * from './versions.js';
|
|
19
17
|
export { toWei, fromWei, numberToString, getValueOfUnit, unitMap, } from './unitsConversion.js';
|
|
20
|
-
|
|
18
|
+
export { HEX_REGEX, STRICT_HEX_REGEX, add0x, assertIsHexString, assertIsStrictHexString, areUint8ArraysEqual, assertIsBytes, base64ToBytes, bigIntToBytes, bigIntToHex, bytesToBase64, bytesToBigInt, bytesToHex, bytesToNumber, bytesToSignedBigInt, bytesToString, concatBytes, createDataView, hexToBigInt, hexToNumber, hexToBytes, isBytes, isHexString, isStrictHexString, numberToBytes, numberToHex, remove0x, signedBigIntToBytes, stringToBytes, valueToBytes, } from '@metamask/byte-utils';
|
|
21
19
|
export { ensureError, getErrorMessage, isErrorWithCode, isErrorWithMessage, isErrorWithStack, wrapError, } from '@metamask/error-utils';
|
|
22
20
|
export { AssertionError, assert, assertExhaustive, isNonEmptyArray, getKnownPropertyNames, hasProperty, isNullOrUndefined, isObject, isPlainObject, } from '@metamask/type-utils';
|
|
23
21
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"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,iBAAiB,EACjB,QAAQ,EACR,aAAa,GACd,MAAM,sBAAsB,CAAC","sourcesContent":["export * from './assert.js';\nexport * from './base64.js';\nexport * from './caip-types.js';\nexport * from './checksum.js';\nexport * from './coercers.js';\nexport * from './collections.js';\nexport type * from './encryption-types.js';\nexport * from './hashing.js';\nexport {\n HexStruct,\n StrictHexStruct,\n HexAddressStruct,\n HexChecksumAddressStruct,\n isHexAddress,\n isHexChecksumAddress,\n isValidHexAddress,\n getChecksumAddress,\n isValidChecksumAddress,\n} from './hex.js';\nexport * from './json.js';\nexport type * from './keyring.js';\nexport * from './logging.js';\nexport * from './misc.js';\nexport * from './mnemonic.js';\nexport type * from './opaque.js';\nexport * from './promise.js';\nexport * from './superstruct.js';\nexport * from './time.js';\nexport type * from './transaction-types.js';\nexport * from './versions.js';\nexport {\n toWei,\n fromWei,\n numberToString,\n getValueOfUnit,\n unitMap,\n} from './unitsConversion.js';\n\n// Re-exports for backwards compatibility.\nexport type { Bytes, Hex } from '@metamask/byte-utils';\nexport {\n HEX_REGEX,\n STRICT_HEX_REGEX,\n add0x,\n assertIsHexString,\n assertIsStrictHexString,\n areUint8ArraysEqual,\n assertIsBytes,\n base64ToBytes,\n bigIntToBytes,\n bigIntToHex,\n bytesToBase64,\n bytesToBigInt,\n bytesToHex,\n bytesToNumber,\n bytesToSignedBigInt,\n bytesToString,\n concatBytes,\n createDataView,\n hexToBigInt,\n hexToNumber,\n hexToBytes,\n isBytes,\n isHexString,\n isStrictHexString,\n numberToBytes,\n numberToHex,\n remove0x,\n signedBigIntToBytes,\n stringToBytes,\n valueToBytes,\n} from '@metamask/byte-utils';\nexport {\n ensureError,\n getErrorMessage,\n isErrorWithCode,\n isErrorWithMessage,\n isErrorWithStack,\n wrapError,\n} from '@metamask/error-utils';\nexport type {\n AssertionErrorConstructor,\n Json,\n Mutable,\n NonEmptyArray,\n PartialOrAbsent,\n PublicInterface,\n RuntimeObject,\n RuntimeObject as PlainObject,\n} from '@metamask/type-utils';\nexport {\n AssertionError,\n assert,\n assertExhaustive,\n isNonEmptyArray,\n getKnownPropertyNames,\n hasProperty,\n isNullOrUndefined,\n isObject,\n isPlainObject,\n} from '@metamask/type-utils';\n"]}
|
package/dist/keyring.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TypedTransaction, LegacyTxData } from '@ethereumjs/tx';
|
|
2
|
+
import type { Hex } from '@metamask/byte-utils';
|
|
2
3
|
import type { Json } from '@metamask/type-utils';
|
|
3
4
|
import type { Eip1024EncryptedData } from './encryption-types.js';
|
|
4
|
-
import type { Hex } from './hex.js';
|
|
5
5
|
/**
|
|
6
6
|
* A Keyring class.
|
|
7
7
|
*
|
package/dist/keyring.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.d.ts","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"keyring.d.ts","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAElE;;;;;;;;;GASG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,SAAS,IAAI,IAAI;IAC7C;;;;;;;OAOG;IACH,KAAK,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;IAExD;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;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1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"keyring.js","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedTransaction, LegacyTxData } from '@ethereumjs/tx';\nimport type { Json } from '@metamask/type-utils';\n\nimport type { Eip1024EncryptedData } from './encryption-types.js';\nimport type { Hex } from './hex.js';\n\n/**\n * A Keyring class.\n *\n * This type is used to validate the constructor signature and the `type`\n * static property on Keyring classes. See the {@link Keyring} type for more\n * information.\n *\n * @deprecated This type has been moved to the `@metamask/keyring-utils` package.\n * See {@link https://github.com/MetaMask/accounts/tree/main/packages/keyring-utils Keyring Utils}.\n */\nexport type KeyringClass<State extends Json> = {\n /**\n * The Keyring constructor. Takes a single parameter, an \"options\" object.\n * See the documentation for the specific keyring for more information about\n * what these options are.\n *\n * @param options - The constructor options. Differs between keyring\n * implementations.\n */\n new (options?: Record<string, unknown>): Keyring<State>;\n\n /**\n * The name of this type of keyring. This must uniquely identify the\n * keyring type.\n */\n type: string;\n};\n\n/**\n * A keyring is something that can sign messages. Keyrings are used to add new\n * signing strategies; each strategy is a new keyring.\n *\n * Each keyring manages a collection of key pairs, which we call \"accounts\".\n * Each account is referred to by its \"address\", which is a unique identifier\n * derived from the public key. The address is always a \"0x\"-prefixed\n * hexidecimal string.\n *\n * The keyring might store the private key for each account as well, but it's\n * not guaranteed. Some keyrings delegate signing, so they don't need the\n * private key directly. The keyring (and in particular the keyring state)\n * should be treated with care though, just in case it does contain sensitive\n * material such as a private key.\n *\n * @deprecated This type has been moved to the `@metamask/keyring-utils` package.\n * See {@link https://github.com/MetaMask/accounts/tree/main/packages/keyring-utils Keyring Utils}.\n */\nexport type Keyring<State extends Json> = {\n /**\n * The name of this type of keyring. This must match the `type` property of\n * the keyring class.\n */\n type: string;\n\n /**\n * Get the addresses for all accounts in this keyring.\n *\n * @returns A list of the account addresses for this keyring\n */\n getAccounts(): Promise<Hex[]>;\n\n /**\n * Add an account to the keyring.\n *\n * @param number - The number of accounts to add. Usually defaults to 1.\n * @returns A list of the newly added account addresses.\n */\n addAccounts(number: number): Promise<Hex[]>;\n\n /**\n * Serialize the keyring state as a JSON-serializable object.\n *\n * @returns A JSON-serializable representation of the keyring state.\n */\n serialize(): Promise<State>;\n\n /**\n * Deserialize the given keyring state, overwriting any existing state with\n * the serialized state provided.\n *\n * @param state - A JSON-serializable representation of the keyring state.\n */\n deserialize(state: State): Promise<void>;\n\n /**\n * Method to include asynchronous configuration.\n */\n init?(): Promise<void>;\n\n /**\n * Remove an account from the keyring.\n *\n * @param address - The address of the account to remove.\n */\n removeAccount?(address: Hex): void;\n\n /**\n * Export the private key for one of the keyring accounts.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter is used to allow exporting a\n * private key that is derived from the given account, rather than exporting\n * that account's private key directly.\n *\n * @param address - The address of the account to export.\n * @param options - Export options; differs between keyrings.\n * @returns The non-prefixed, hex-encoded private key that was requested.\n */\n exportAccount?(\n address: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get the \"app key\" address for the given account and origin. An app key is\n * an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}\n * for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}\n * is used as the unique identifier for the application, and it's used as\n * part of the key derivation process.\n *\n * @param address - The address of the account the app key is derived from.\n * @param origin - The origin of the application.\n * @returns The address of the app key for the given account and origin.\n */\n getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;\n\n /**\n * Sign a transaction. This is equivalent to the `eth_signTransaction`\n * Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for\n * more details.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param transaction - The transaction to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed transaction.\n */\n signTransaction?(\n address: Hex,\n transaction: TypedTransaction,\n options?: Record<string, unknown>,\n ): Promise<LegacyTxData>;\n\n /**\n * Sign a message. This is equivalent to an older version of the the\n * `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,\n * using the curve secp256k1 the Keccak-256 hash function.\n *\n * For more information about this method and why we still support it, see\n * the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signMessage?(\n address: Hex,\n message: string,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign an EIP-7702 authorization. This is a signing method for authorizing a\n * specific contract on a specific chain.\n *\n * @param address - The address of the account to use for signing.\n * @param authorization - An array containing the chain ID, contract address,\n * and nonce.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed authorization as a hex string.\n */\n signEip7702Authorization?(\n address: Hex,\n authorization: [chainId: number, contractAddress: Hex, nonce: number],\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC\n * method, which is exposed by MetaMask as the method `personal_sign`. See\n * the Ethereum JSON-RPC API documentation for more details.\n *\n * For more information about this method and why we call it `personal_sign`,\n * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signPersonalMessage?(\n address: Hex,\n message: Hex,\n options?: { version?: string } & Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum\n * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}\n * for more details.\n *\n * The \"version\" option dictates which version of `eth_signTypedData` is\n * used. The latest version reflects the specification most closely, whereas\n * earlier versions reflect earlier drafts of the specification that are\n * still supported for backwards-compatibility reasons. For more information\n * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept additional options as well. See the documentation for\n * the specific keyring for more information about what these options are.\n * For some keyrings, the options parameter can even change which key is used\n * for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param typedData - The data to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signTypedData?(\n address: Hex,\n typedData: Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get a public key to use for encryption. This is equivalent to the\n * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}\n * for more information.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used (e.g. encrypting with app keys).\n *\n * @param account - The address of the account you want the encryption key for.\n * @param options - Options; differs between keyrings.\n */\n getEncryptionPublicKey?(\n account: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`\n * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}\n * for more information.\n *\n * @param account - The address of the account you want to use to decrypt\n * the message.\n * @param encryptedData - The encrypted data that you want to decrypt.\n * @returns The decrypted data.\n */\n decryptMessage?(\n account: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string>;\n\n /**\n * Generates the properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @returns A promise resolving when the keyring has generated the properties.\n */\n generateRandomMnemonic?(): Promise<void>;\n\n /**\n * Destroy the keyring.\n */\n destroy?(): Promise<void>;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"keyring.js","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedTransaction, LegacyTxData } from '@ethereumjs/tx';\nimport type { Hex } from '@metamask/byte-utils';\nimport type { Json } from '@metamask/type-utils';\n\nimport type { Eip1024EncryptedData } from './encryption-types.js';\n\n/**\n * A Keyring class.\n *\n * This type is used to validate the constructor signature and the `type`\n * static property on Keyring classes. See the {@link Keyring} type for more\n * information.\n *\n * @deprecated This type has been moved to the `@metamask/keyring-utils` package.\n * See {@link https://github.com/MetaMask/accounts/tree/main/packages/keyring-utils Keyring Utils}.\n */\nexport type KeyringClass<State extends Json> = {\n /**\n * The Keyring constructor. Takes a single parameter, an \"options\" object.\n * See the documentation for the specific keyring for more information about\n * what these options are.\n *\n * @param options - The constructor options. Differs between keyring\n * implementations.\n */\n new (options?: Record<string, unknown>): Keyring<State>;\n\n /**\n * The name of this type of keyring. This must uniquely identify the\n * keyring type.\n */\n type: string;\n};\n\n/**\n * A keyring is something that can sign messages. Keyrings are used to add new\n * signing strategies; each strategy is a new keyring.\n *\n * Each keyring manages a collection of key pairs, which we call \"accounts\".\n * Each account is referred to by its \"address\", which is a unique identifier\n * derived from the public key. The address is always a \"0x\"-prefixed\n * hexidecimal string.\n *\n * The keyring might store the private key for each account as well, but it's\n * not guaranteed. Some keyrings delegate signing, so they don't need the\n * private key directly. The keyring (and in particular the keyring state)\n * should be treated with care though, just in case it does contain sensitive\n * material such as a private key.\n *\n * @deprecated This type has been moved to the `@metamask/keyring-utils` package.\n * See {@link https://github.com/MetaMask/accounts/tree/main/packages/keyring-utils Keyring Utils}.\n */\nexport type Keyring<State extends Json> = {\n /**\n * The name of this type of keyring. This must match the `type` property of\n * the keyring class.\n */\n type: string;\n\n /**\n * Get the addresses for all accounts in this keyring.\n *\n * @returns A list of the account addresses for this keyring\n */\n getAccounts(): Promise<Hex[]>;\n\n /**\n * Add an account to the keyring.\n *\n * @param number - The number of accounts to add. Usually defaults to 1.\n * @returns A list of the newly added account addresses.\n */\n addAccounts(number: number): Promise<Hex[]>;\n\n /**\n * Serialize the keyring state as a JSON-serializable object.\n *\n * @returns A JSON-serializable representation of the keyring state.\n */\n serialize(): Promise<State>;\n\n /**\n * Deserialize the given keyring state, overwriting any existing state with\n * the serialized state provided.\n *\n * @param state - A JSON-serializable representation of the keyring state.\n */\n deserialize(state: State): Promise<void>;\n\n /**\n * Method to include asynchronous configuration.\n */\n init?(): Promise<void>;\n\n /**\n * Remove an account from the keyring.\n *\n * @param address - The address of the account to remove.\n */\n removeAccount?(address: Hex): void;\n\n /**\n * Export the private key for one of the keyring accounts.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter is used to allow exporting a\n * private key that is derived from the given account, rather than exporting\n * that account's private key directly.\n *\n * @param address - The address of the account to export.\n * @param options - Export options; differs between keyrings.\n * @returns The non-prefixed, hex-encoded private key that was requested.\n */\n exportAccount?(\n address: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get the \"app key\" address for the given account and origin. An app key is\n * an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}\n * for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}\n * is used as the unique identifier for the application, and it's used as\n * part of the key derivation process.\n *\n * @param address - The address of the account the app key is derived from.\n * @param origin - The origin of the application.\n * @returns The address of the app key for the given account and origin.\n */\n getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;\n\n /**\n * Sign a transaction. This is equivalent to the `eth_signTransaction`\n * Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for\n * more details.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param transaction - The transaction to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed transaction.\n */\n signTransaction?(\n address: Hex,\n transaction: TypedTransaction,\n options?: Record<string, unknown>,\n ): Promise<LegacyTxData>;\n\n /**\n * Sign a message. This is equivalent to an older version of the the\n * `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,\n * using the curve secp256k1 the Keccak-256 hash function.\n *\n * For more information about this method and why we still support it, see\n * the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signMessage?(\n address: Hex,\n message: string,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign an EIP-7702 authorization. This is a signing method for authorizing a\n * specific contract on a specific chain.\n *\n * @param address - The address of the account to use for signing.\n * @param authorization - An array containing the chain ID, contract address,\n * and nonce.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed authorization as a hex string.\n */\n signEip7702Authorization?(\n address: Hex,\n authorization: [chainId: number, contractAddress: Hex, nonce: number],\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC\n * method, which is exposed by MetaMask as the method `personal_sign`. See\n * the Ethereum JSON-RPC API documentation for more details.\n *\n * For more information about this method and why we call it `personal_sign`,\n * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signPersonalMessage?(\n address: Hex,\n message: Hex,\n options?: { version?: string } & Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum\n * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}\n * for more details.\n *\n * The \"version\" option dictates which version of `eth_signTypedData` is\n * used. The latest version reflects the specification most closely, whereas\n * earlier versions reflect earlier drafts of the specification that are\n * still supported for backwards-compatibility reasons. For more information\n * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept additional options as well. See the documentation for\n * the specific keyring for more information about what these options are.\n * For some keyrings, the options parameter can even change which key is used\n * for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param typedData - The data to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signTypedData?(\n address: Hex,\n typedData: Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get a public key to use for encryption. This is equivalent to the\n * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}\n * for more information.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used (e.g. encrypting with app keys).\n *\n * @param account - The address of the account you want the encryption key for.\n * @param options - Options; differs between keyrings.\n */\n getEncryptionPublicKey?(\n account: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`\n * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}\n * for more information.\n *\n * @param account - The address of the account you want to use to decrypt\n * the message.\n * @param encryptedData - The encrypted data that you want to decrypt.\n * @returns The decrypted data.\n */\n decryptMessage?(\n account: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string>;\n\n /**\n * Generates the properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @returns A promise resolving when the keyring has generated the properties.\n */\n generateRandomMnemonic?(): Promise<void>;\n\n /**\n * Destroy the keyring.\n */\n destroy?(): Promise<void>;\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Bytes } from '
|
|
2
|
-
import type { Hex } from '
|
|
1
|
+
import type { Bytes } from '@metamask/byte-utils';
|
|
2
|
+
import type { Hex } from '@metamask/byte-utils';
|
|
3
3
|
export type Transaction = LegacyTransaction | EIP2930Transaction | EIP1559Transaction;
|
|
4
4
|
export type SignedTransaction = Transaction & Signature;
|
|
5
5
|
export type Signature = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-types.d.ts","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"transaction-types.d.ts","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAEhD,MAAM,MAAM,WAAW,GACnB,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,CAAC;AAEvB,MAAM,MAAM,iBAAiB,GAAG,WAAW,GAAG,SAAS,CAAC;AAExD,MAAM,MAAM,SAAS,GAAG;IACtB;;;OAGG;IACH,CAAC,EAAE,KAAK,CAAC;IAET;;;;OAIG;IACH,CAAC,EAAE,KAAK,CAAC;IAET;;;OAGG;IACH,OAAO,EAAE,KAAK,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,IAAI,EAAE,GAAG,GAAG,UAAU,CAAC;IAEvB;;;;OAIG;IACH,EAAE,EAAE,GAAG,GAAG,UAAU,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,QAAQ,EAAE,KAAK,CAAC;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,eAAe,GAAG;IAC/C;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,eAAe,GAAG;IAChD;;OAEG;IACH,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAAG;IAClD;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,OAAO,EAAE,KAAK,CAAC;IAEf;;OAEG;IACH,UAAU,EACN;QAAE,OAAO,EAAE,GAAG,CAAC;QAAC,WAAW,EAAE,GAAG,EAAE,CAAA;KAAE,EAAE,GACtC;QAAE,OAAO,EAAE,UAAU,CAAC;QAAC,WAAW,EAAE,UAAU,EAAE,CAAA;KAAE,EAAE,CAAC;CAC1D,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAAG;IAClD;;OAEG;IACH,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,oBAAoB,EAAE,KAAK,CAAC;IAE5B;;OAEG;IACH,YAAY,EAAE,KAAK,CAAC;CACrB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction-types.js","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Bytes } from '
|
|
1
|
+
{"version":3,"file":"transaction-types.js","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Bytes } from '@metamask/byte-utils';\nimport type { Hex } from '@metamask/byte-utils';\n\nexport type Transaction =\n | LegacyTransaction\n | EIP2930Transaction\n | EIP1559Transaction;\n\nexport type SignedTransaction = Transaction & Signature;\n\nexport type Signature = {\n /**\n * EC signature parameter\n * 32 bytes long sequence.\n */\n r: Bytes;\n\n /**\n * EC signature parameter\n * Signature proof.\n * 32 bytes long sequence\n */\n s: Bytes;\n\n /**\n * Recovery identifier. It can be either 0x1b or 0x1c\n * 1 byte long sequence\n */\n yParity: Bytes;\n};\n\n/**\n * Base Ethereum Transaction\n */\nexport type BaseTransaction = {\n /**\n * Sequentially incrementing counter which indicates the transaction\n * number from the account\n */\n nonce: Bytes;\n\n /**\n * The address of the sender, that will be signing the transaction\n */\n from: Hex | Uint8Array;\n\n /**\n * The receiving address.\n * If an externally-owned account, the transaction will transfer value.\n * If a contract account, the transaction will execute the contract code.\n */\n to: Hex | Uint8Array;\n\n /**\n * The amount of Ether sent.\n */\n value: Bytes;\n\n /**\n * Maximum amount of gas units that this transaction can consume.\n */\n gasLimit: Bytes;\n\n /**\n * Arbitrary data.\n */\n data?: Bytes;\n};\n\n/**\n * Typed Ethereum Transaction\n */\nexport type TypedTransaction = BaseTransaction & {\n /**\n * Transaction type.\n */\n type: number;\n};\n\n/**\n * Ethereum Legacy Transaction\n * Reference: https://ethereum.org/en/developers/docs/transactions/\n */\nexport type LegacyTransaction = BaseTransaction & {\n /**\n * Transaction's gas price.\n */\n gasPrice: Bytes | null;\n};\n\n/**\n * EIP-2930 Transaction: Optional Access Lists\n * Reference: https://eips.ethereum.org/EIPS/eip-2930\n */\nexport type EIP2930Transaction = TypedTransaction & {\n /**\n * Transaction type.\n */\n type: 1;\n\n /**\n * Transaction chain ID\n */\n chainId: Bytes;\n\n /**\n * List of addresses and storage keys that the transaction plans to access\n */\n accessList:\n | { address: Hex; storageKeys: Hex[] }[]\n | { address: Uint8Array; storageKeys: Uint8Array[] }[];\n};\n\n/**\n * EIP-1559 Transaction: Fee market change for ETH 1.0 chain (Type-2)\n *\n * Reference: https://eips.ethereum.org/EIPS/eip-1559\n */\nexport type EIP1559Transaction = TypedTransaction & {\n /**\n * Transaction type.\n */\n type: 2;\n\n /**\n * Maximum fee to give to the miner\n */\n maxPriorityFeePerGas: Bytes;\n\n /**\n * Maximum total fee\n */\n maxFeePerGas: Bytes;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/utils",
|
|
3
|
-
"version": "12.0.0-preview-
|
|
3
|
+
"version": "12.0.0-preview-bd4de146a",
|
|
4
4
|
"description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -54,13 +54,13 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@ethereumjs/tx": "^5.4.0",
|
|
57
|
+
"@metamask/byte-utils": "^0.0.0",
|
|
57
58
|
"@metamask/error-utils": "^0.0.0",
|
|
58
59
|
"@metamask/node-utils": "^0.0.0",
|
|
59
60
|
"@metamask/scure-bip39": "^2.1.1",
|
|
60
61
|
"@metamask/superstruct": "^3.4.1",
|
|
61
62
|
"@metamask/type-utils": "^0.0.0",
|
|
62
63
|
"@noble/hashes": "^1.8.0",
|
|
63
|
-
"@scure/base": "^1.2.6",
|
|
64
64
|
"@types/debug": "^4.1.7",
|
|
65
65
|
"@types/lodash": "^4.17.26",
|
|
66
66
|
"debug": "^4.4.3",
|