@metamask/utils 6.2.0 → 7.0.0
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 +11 -1
- package/dist/cjs/assert.js +116 -0
- package/dist/cjs/assert.js.map +1 -0
- package/dist/cjs/base64.js +32 -0
- package/dist/cjs/base64.js.map +1 -0
- package/dist/cjs/bytes.js +255 -0
- package/dist/cjs/bytes.js.map +1 -0
- package/dist/cjs/checksum.js +17 -0
- package/dist/cjs/checksum.js.map +1 -0
- package/dist/cjs/coercers.js +96 -0
- package/dist/cjs/coercers.js.map +1 -0
- package/dist/cjs/collections.js +157 -0
- package/dist/cjs/collections.js.map +1 -0
- package/dist/cjs/encryption-types.js +6 -0
- package/dist/cjs/encryption-types.js.map +1 -0
- package/dist/cjs/hex.js +107 -0
- package/dist/cjs/hex.js.map +1 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/json.js +263 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/cjs/keyring.js +6 -0
- package/dist/cjs/keyring.js.map +1 -0
- package/dist/cjs/logging.js +33 -0
- package/dist/cjs/logging.js.map +1 -0
- package/dist/cjs/misc.js +111 -0
- package/dist/cjs/misc.js.map +1 -0
- package/dist/cjs/number.js +52 -0
- package/dist/cjs/number.js.map +1 -0
- package/dist/cjs/opaque.js +8 -0
- package/dist/cjs/opaque.js.map +1 -0
- package/dist/cjs/time.js +63 -0
- package/dist/cjs/time.js.map +1 -0
- package/dist/cjs/transaction-types.js +6 -0
- package/dist/cjs/transaction-types.js.map +1 -0
- package/dist/cjs/versions.js +79 -0
- package/dist/cjs/versions.js.map +1 -0
- package/dist/{assert.js → esm/assert.js} +30 -35
- package/dist/esm/assert.js.map +1 -0
- package/dist/{base64.js → esm/base64.js} +10 -16
- package/dist/esm/base64.js.map +1 -0
- package/dist/{bytes.js → esm/bytes.js} +50 -93
- package/dist/esm/bytes.js.map +1 -0
- package/dist/esm/checksum.js +7 -0
- package/dist/esm/checksum.js.map +1 -0
- package/dist/{coercers.js → esm/coercers.js} +43 -52
- package/dist/esm/coercers.js.map +1 -0
- package/dist/esm/collections.js +140 -0
- package/dist/esm/collections.js.map +1 -0
- package/dist/esm/encryption-types.js +3 -0
- package/dist/esm/encryption-types.js.map +1 -0
- package/dist/esm/hex.js +108 -0
- package/dist/esm/hex.js.map +1 -0
- package/dist/{index.d.ts → esm/index.js} +2 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/json.js +301 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/esm/keyring.js +3 -0
- package/dist/esm/keyring.js.map +1 -0
- package/dist/{logging.js → esm/logging.js} +5 -14
- package/dist/esm/logging.js.map +1 -0
- package/dist/{misc.js → esm/misc.js} +37 -42
- package/dist/esm/misc.js.map +1 -0
- package/dist/{number.js → esm/number.js} +18 -28
- package/dist/esm/number.js.map +1 -0
- package/dist/esm/opaque.js +5 -0
- package/dist/esm/opaque.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/time.js +53 -0
- package/dist/esm/time.js.map +1 -0
- package/dist/esm/transaction-types.js +3 -0
- package/dist/esm/transaction-types.js.map +1 -0
- package/dist/esm/versions.js +78 -0
- package/dist/esm/versions.js.map +1 -0
- package/dist/{assert.d.ts → types/assert.d.ts} +3 -2
- package/dist/types/assert.d.ts.map +1 -0
- package/dist/{base64.d.ts → types/base64.d.ts} +3 -2
- package/dist/types/base64.d.ts.map +1 -0
- package/dist/{bytes.d.ts → types/bytes.d.ts} +2 -1
- package/dist/types/bytes.d.ts.map +1 -0
- package/dist/{checksum.d.ts → types/checksum.d.ts} +1 -0
- package/dist/types/checksum.d.ts.map +1 -0
- package/dist/{coercers.d.ts → types/coercers.d.ts} +3 -2
- package/dist/types/coercers.d.ts.map +1 -0
- package/dist/{collections.d.ts → types/collections.d.ts} +1 -0
- package/dist/types/collections.d.ts.map +1 -0
- package/dist/{encryption-types.d.ts → types/encryption-types.d.ts} +1 -0
- package/dist/types/encryption-types.d.ts.map +1 -0
- package/dist/{hex.d.ts → types/hex.d.ts} +2 -1
- package/dist/types/hex.d.ts.map +1 -0
- package/dist/types/hex.test-d.d.ts +2 -0
- package/dist/types/hex.test-d.d.ts.map +1 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/{json.d.ts → types/json.d.ts} +3 -2
- package/dist/types/json.d.ts.map +1 -0
- package/dist/types/json.test-d.d.ts +2 -0
- package/dist/types/json.test-d.d.ts.map +1 -0
- package/dist/{keyring.d.ts → types/keyring.d.ts} +3 -2
- package/dist/types/keyring.d.ts.map +1 -0
- package/dist/{logging.d.ts → types/logging.d.ts} +2 -1
- package/dist/types/logging.d.ts.map +1 -0
- package/dist/{misc.d.ts → types/misc.d.ts} +13 -0
- package/dist/types/misc.d.ts.map +1 -0
- package/dist/types/misc.test-d.d.ts +2 -0
- package/dist/types/misc.test-d.d.ts.map +1 -0
- package/dist/{number.d.ts → types/number.d.ts} +1 -0
- package/dist/types/number.d.ts.map +1 -0
- package/dist/{opaque.d.ts → types/opaque.d.ts} +1 -0
- package/dist/types/opaque.d.ts.map +1 -0
- package/dist/{time.d.ts → types/time.d.ts} +1 -0
- package/dist/types/time.d.ts.map +1 -0
- package/dist/{transaction-types.d.ts → types/transaction-types.d.ts} +3 -2
- package/dist/types/transaction-types.d.ts.map +1 -0
- package/dist/{versions.d.ts → types/versions.d.ts} +3 -2
- package/dist/types/versions.d.ts.map +1 -0
- package/package.json +40 -20
- package/dist/__fixtures__/bytes.d.ts +0 -25
- package/dist/__fixtures__/bytes.js +0 -234
- package/dist/__fixtures__/bytes.js.map +0 -1
- package/dist/__fixtures__/coercions.d.ts +0 -5
- package/dist/__fixtures__/coercions.js +0 -22
- package/dist/__fixtures__/coercions.js.map +0 -1
- package/dist/__fixtures__/index.d.ts +0 -4
- package/dist/__fixtures__/index.js +0 -21
- package/dist/__fixtures__/index.js.map +0 -1
- package/dist/__fixtures__/json.d.ts +0 -1226
- package/dist/__fixtures__/json.js +0 -1491
- package/dist/__fixtures__/json.js.map +0 -1
- package/dist/__fixtures__/numbers.d.ts +0 -5
- package/dist/__fixtures__/numbers.js +0 -56
- package/dist/__fixtures__/numbers.js.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/base64.js.map +0 -1
- package/dist/bytes.js.map +0 -1
- package/dist/checksum.js +0 -7
- package/dist/checksum.js.map +0 -1
- package/dist/coercers.js.map +0 -1
- package/dist/collections.js +0 -109
- package/dist/collections.js.map +0 -1
- package/dist/encryption-types.js +0 -3
- package/dist/encryption-types.js.map +0 -1
- package/dist/hex.js +0 -134
- package/dist/hex.js.map +0 -1
- package/dist/hex.test-d.d.ts +0 -1
- package/dist/hex.test-d.js +0 -16
- package/dist/hex.test-d.js.map +0 -1
- package/dist/index.js +0 -34
- package/dist/index.js.map +0 -1
- package/dist/json.js +0 -346
- package/dist/json.js.map +0 -1
- package/dist/json.test-d.d.ts +0 -1
- package/dist/json.test-d.js +0 -62
- package/dist/json.test-d.js.map +0 -1
- package/dist/keyring.js +0 -3
- package/dist/keyring.js.map +0 -1
- package/dist/logging.js.map +0 -1
- package/dist/misc.js.map +0 -1
- package/dist/misc.test-d.d.ts +0 -1
- package/dist/misc.test-d.js +0 -97
- package/dist/misc.test-d.js.map +0 -1
- package/dist/number.js.map +0 -1
- package/dist/opaque.js +0 -3
- package/dist/opaque.js.map +0 -1
- package/dist/time.js +0 -67
- package/dist/time.js.map +0 -1
- package/dist/transaction-types.js +0 -3
- package/dist/transaction-types.js.map +0 -1
- package/dist/versions.js +0 -95
- package/dist/versions.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/keyring.ts"],"sourcesContent":["import type { TypedTransaction, TxData } from '@ethereumjs/tx';\n\nimport type { Eip1024EncryptedData } from './encryption-types';\nimport type { Hex } from './hex';\nimport type { Json } from './json';\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 */\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 */\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<TxData>;\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 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 generateRandomMnemonic?(): void;\n\n /**\n * Destroy the keyring.\n */\n destroy?(): Promise<void>;\n};\n"],"names":[],"mappings":"AAAA,WAyQE"}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createModuleLogger = exports.createProjectLogger = void 0;
|
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
const globalLogger = (0, debug_1.default)('metamask');
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
const globalLogger = debug('metamask');
|
|
9
3
|
/**
|
|
10
4
|
* Creates a logger via the `debug` library whose log messages will be tagged
|
|
11
5
|
* using the name of your project. By default, such messages will be
|
|
@@ -17,11 +11,9 @@ const globalLogger = (0, debug_1.default)('metamask');
|
|
|
17
11
|
* @param projectName - The name of your project. This should be the name of
|
|
18
12
|
* your NPM package if you're developing one.
|
|
19
13
|
* @returns An instance of `debug`.
|
|
20
|
-
*/
|
|
21
|
-
function createProjectLogger(projectName) {
|
|
14
|
+
*/ export function createProjectLogger(projectName) {
|
|
22
15
|
return globalLogger.extend(projectName);
|
|
23
16
|
}
|
|
24
|
-
exports.createProjectLogger = createProjectLogger;
|
|
25
17
|
/**
|
|
26
18
|
* Creates a logger via the `debug` library which is derived from the logger for
|
|
27
19
|
* the whole project whose log messages will be tagged using the name of your
|
|
@@ -35,9 +27,8 @@ exports.createProjectLogger = createProjectLogger;
|
|
|
35
27
|
* @param moduleName - The name of your module. You could use the name of the
|
|
36
28
|
* file where you're using this logger or some other name.
|
|
37
29
|
* @returns An instance of `debug`.
|
|
38
|
-
*/
|
|
39
|
-
function createModuleLogger(projectLogger, moduleName) {
|
|
30
|
+
*/ export function createModuleLogger(projectLogger, moduleName) {
|
|
40
31
|
return projectLogger.extend(moduleName);
|
|
41
32
|
}
|
|
42
|
-
|
|
33
|
+
|
|
43
34
|
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/logging.ts"],"sourcesContent":["import type { Debugger } from 'debug';\nimport debug from 'debug';\n\nconst globalLogger = debug('metamask');\n\n/**\n * Creates a logger via the `debug` library whose log messages will be tagged\n * using the name of your project. By default, such messages will be\n * suppressed, but you can reveal them by setting the `DEBUG` environment\n * variable to `metamask:<projectName>`. You can also set this variable to\n * `metamask:*` if you want to see log messages from all MetaMask projects that\n * are also using this function to create their loggers.\n *\n * @param projectName - The name of your project. This should be the name of\n * your NPM package if you're developing one.\n * @returns An instance of `debug`.\n */\nexport function createProjectLogger(projectName: string): Debugger {\n return globalLogger.extend(projectName);\n}\n\n/**\n * Creates a logger via the `debug` library which is derived from the logger for\n * the whole project whose log messages will be tagged using the name of your\n * module. By default, such messages will be suppressed, but you can reveal them\n * by setting the `DEBUG` environment variable to\n * `metamask:<projectName>:<moduleName>`. You can also set this variable to\n * `metamask:<projectName>:*` if you want to see log messages from the project,\n * or `metamask:*` if you want to see log messages from all MetaMask projects.\n *\n * @param projectLogger - The logger created via {@link createProjectLogger}.\n * @param moduleName - The name of your module. You could use the name of the\n * file where you're using this logger or some other name.\n * @returns An instance of `debug`.\n */\nexport function createModuleLogger(\n projectLogger: Debugger,\n moduleName: string,\n): Debugger {\n return projectLogger.extend(moduleName);\n}\n"],"names":["debug","globalLogger","createProjectLogger","projectName","extend","createModuleLogger","projectLogger","moduleName"],"mappings":"AACA,OAAOA,WAAW,QAAQ;AAE1B,MAAMC,eAAeD,MAAM;AAE3B;;;;;;;;;;;CAWC,GACD,OAAO,SAASE,oBAAoBC,WAAmB;IACrD,OAAOF,aAAaG,MAAM,CAACD;AAC7B;AAEA;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASE,mBACdC,aAAuB,EACvBC,UAAkB;IAElB,OAAOD,cAAcF,MAAM,CAACG;AAC9B"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//
|
|
3
2
|
// Types
|
|
4
3
|
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Makes every specified property of the specified object type mutable.
|
|
6
|
+
*
|
|
7
|
+
* @template ObjectValue - The object whose readonly properties to make mutable.
|
|
8
|
+
* @template TargetKey - The property key(s) to make mutable.
|
|
9
|
+
*/ //
|
|
8
10
|
// Type Guards
|
|
9
11
|
//
|
|
10
12
|
/**
|
|
@@ -13,32 +15,26 @@ exports.calculateNumberSize = exports.calculateStringSize = exports.isASCII = ex
|
|
|
13
15
|
* @template Element - The non-empty array member type.
|
|
14
16
|
* @param value - The value to check.
|
|
15
17
|
* @returns Whether the value is a non-empty array.
|
|
16
|
-
*/
|
|
17
|
-
function isNonEmptyArray(value) {
|
|
18
|
+
*/ export function isNonEmptyArray(value) {
|
|
18
19
|
return Array.isArray(value) && value.length > 0;
|
|
19
20
|
}
|
|
20
|
-
exports.isNonEmptyArray = isNonEmptyArray;
|
|
21
21
|
/**
|
|
22
22
|
* Type guard for "nullishness".
|
|
23
23
|
*
|
|
24
24
|
* @param value - Any value.
|
|
25
25
|
* @returns `true` if the value is null or undefined, `false` otherwise.
|
|
26
|
-
*/
|
|
27
|
-
function isNullOrUndefined(value) {
|
|
26
|
+
*/ export function isNullOrUndefined(value) {
|
|
28
27
|
return value === null || value === undefined;
|
|
29
28
|
}
|
|
30
|
-
exports.isNullOrUndefined = isNullOrUndefined;
|
|
31
29
|
/**
|
|
32
30
|
* A type guard for {@link RuntimeObject}.
|
|
33
31
|
*
|
|
34
32
|
* @param value - The value to check.
|
|
35
33
|
* @returns Whether the specified value has a runtime type of `object` and is
|
|
36
34
|
* neither `null` nor an `Array`.
|
|
37
|
-
*/
|
|
38
|
-
function isObject(value) {
|
|
35
|
+
*/ export function isObject(value) {
|
|
39
36
|
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
40
37
|
}
|
|
41
|
-
exports.isObject = isObject;
|
|
42
38
|
//
|
|
43
39
|
// Other utility functions
|
|
44
40
|
//
|
|
@@ -49,14 +45,22 @@ exports.isObject = isObject;
|
|
|
49
45
|
* @param name - The property name to check for.
|
|
50
46
|
* @returns Whether the specified object has an own property with the specified
|
|
51
47
|
* name, regardless of whether it is enumerable or not.
|
|
52
|
-
*/
|
|
53
|
-
const hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
|
|
54
|
-
exports.hasProperty = hasProperty;
|
|
48
|
+
*/ export const hasProperty = (objectToCheck, name)=>Object.hasOwnProperty.call(objectToCheck, name);
|
|
55
49
|
/**
|
|
56
|
-
*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
50
|
+
* `Object.getOwnPropertyNames()` is intentionally generic: it returns the
|
|
51
|
+
* immediate property names of an object, but it cannot make guarantees about
|
|
52
|
+
* the contents of that object, so the type of the property names is merely
|
|
53
|
+
* `string[]`. While this is technically accurate, it is also unnecessary if we
|
|
54
|
+
* have an object with a type that we own (such as an enum).
|
|
55
|
+
*
|
|
56
|
+
* @param object - The plain object.
|
|
57
|
+
* @returns The own property names of the object which are assigned a type
|
|
58
|
+
* derived from the object itself.
|
|
59
|
+
*/ export function getKnownPropertyNames(object) {
|
|
60
|
+
return Object.getOwnPropertyNames(object);
|
|
61
|
+
}
|
|
62
|
+
export var JsonSize;
|
|
63
|
+
(function(JsonSize) {
|
|
60
64
|
JsonSize[JsonSize["Null"] = 4] = "Null";
|
|
61
65
|
JsonSize[JsonSize["Comma"] = 1] = "Comma";
|
|
62
66
|
JsonSize[JsonSize["Wrapper"] = 1] = "Wrapper";
|
|
@@ -64,71 +68,62 @@ var JsonSize;
|
|
|
64
68
|
JsonSize[JsonSize["False"] = 5] = "False";
|
|
65
69
|
JsonSize[JsonSize["Quote"] = 1] = "Quote";
|
|
66
70
|
JsonSize[JsonSize["Colon"] = 1] = "Colon";
|
|
67
|
-
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
68
|
-
|
|
69
|
-
})(JsonSize
|
|
71
|
+
JsonSize[JsonSize[// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
72
|
+
"Date"] = 24] = "Date";
|
|
73
|
+
})(JsonSize || (JsonSize = {}));
|
|
70
74
|
/**
|
|
71
75
|
* Regular expression with pattern matching for (special) escaped characters.
|
|
72
|
-
*/
|
|
73
|
-
exports.ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
|
|
76
|
+
*/ export const ESCAPE_CHARACTERS_REGEXP = /"|\\|\n|\r|\t/gu;
|
|
74
77
|
/**
|
|
75
78
|
* Check if the value is plain object.
|
|
76
79
|
*
|
|
77
80
|
* @param value - Value to be checked.
|
|
78
81
|
* @returns True if an object is the plain JavaScript object,
|
|
79
82
|
* false if the object is not plain (e.g. function).
|
|
80
|
-
*/
|
|
81
|
-
function isPlainObject(value) {
|
|
83
|
+
*/ export function isPlainObject(value) {
|
|
82
84
|
if (typeof value !== 'object' || value === null) {
|
|
83
85
|
return false;
|
|
84
86
|
}
|
|
85
87
|
try {
|
|
86
88
|
let proto = value;
|
|
87
|
-
while
|
|
89
|
+
while(Object.getPrototypeOf(proto) !== null){
|
|
88
90
|
proto = Object.getPrototypeOf(proto);
|
|
89
91
|
}
|
|
90
92
|
return Object.getPrototypeOf(value) === proto;
|
|
91
|
-
}
|
|
92
|
-
catch (_) {
|
|
93
|
+
} catch (_) {
|
|
93
94
|
return false;
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
exports.isPlainObject = isPlainObject;
|
|
97
97
|
/**
|
|
98
98
|
* Check if character is ASCII.
|
|
99
99
|
*
|
|
100
100
|
* @param character - Character.
|
|
101
101
|
* @returns True if a character code is ASCII, false if not.
|
|
102
|
-
*/
|
|
103
|
-
function isASCII(character) {
|
|
102
|
+
*/ export function isASCII(character) {
|
|
104
103
|
return character.charCodeAt(0) <= 127;
|
|
105
104
|
}
|
|
106
|
-
exports.isASCII = isASCII;
|
|
107
105
|
/**
|
|
108
106
|
* Calculate string size.
|
|
109
107
|
*
|
|
110
108
|
* @param value - String value to calculate size.
|
|
111
109
|
* @returns Number of bytes used to store whole string value.
|
|
112
|
-
*/
|
|
113
|
-
|
|
114
|
-
const size = value.split('').reduce((total, character) => {
|
|
110
|
+
*/ export function calculateStringSize(value) {
|
|
111
|
+
const size = value.split('').reduce((total, character)=>{
|
|
115
112
|
if (isASCII(character)) {
|
|
116
113
|
return total + 1;
|
|
117
114
|
}
|
|
118
115
|
return total + 2;
|
|
119
116
|
}, 0);
|
|
120
117
|
// Also detect characters that need backslash escape
|
|
121
|
-
return size + (value.match(
|
|
118
|
+
return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;
|
|
122
119
|
}
|
|
123
|
-
exports.calculateStringSize = calculateStringSize;
|
|
124
120
|
/**
|
|
125
121
|
* Calculate size of a number ofter JSON serialization.
|
|
126
122
|
*
|
|
127
123
|
* @param value - Number value to calculate size.
|
|
128
124
|
* @returns Number of bytes used to store whole number in JSON.
|
|
129
|
-
*/
|
|
130
|
-
function calculateNumberSize(value) {
|
|
125
|
+
*/ export function calculateNumberSize(value) {
|
|
131
126
|
return value.toString().length;
|
|
132
127
|
}
|
|
133
|
-
|
|
128
|
+
|
|
134
129
|
//# sourceMappingURL=misc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/misc.ts"],"sourcesContent":["//\n// Types\n//\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template ObjectValue - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n ObjectValue extends Record<string, unknown>,\n TargetKey extends keyof ObjectValue,\n> = {\n -readonly [Key in keyof Pick<ObjectValue, TargetKey>]: ObjectValue[Key];\n} & {\n [Key in keyof Omit<ObjectValue, TargetKey>]: ObjectValue[Key];\n};\n\n/**\n * Useful for representing some value that _might_ be present and / or complete.\n *\n * @template Value - The value that might be present or complete.\n */\nexport type PartialOrAbsent<Value> = Partial<Value> | null | undefined;\n\n/**\n * Like {@link Array}, but always non-empty.\n *\n * @template Element - The non-empty array member type.\n */\nexport type NonEmptyArray<Element> = [Element, ...Element[]];\n\n/**\n * A JavaScript object that is not `null`, a function, or an array.\n */\nexport type RuntimeObject = Record<PropertyKey, unknown>;\n\n//\n// Type Guards\n//\n\n/**\n * A {@link NonEmptyArray} type guard.\n *\n * @template Element - The non-empty array member type.\n * @param value - The value to check.\n * @returns Whether the value is a non-empty array.\n */\nexport function isNonEmptyArray<Element>(\n value: Element[],\n): value is NonEmptyArray<Element> {\n return Array.isArray(value) && value.length > 0;\n}\n\n/**\n * Type guard for \"nullishness\".\n *\n * @param value - Any value.\n * @returns `true` if the value is null or undefined, `false` otherwise.\n */\nexport function isNullOrUndefined(value: unknown): value is null | undefined {\n return value === null || value === undefined;\n}\n\n/**\n * A type guard for {@link RuntimeObject}.\n *\n * @param value - The value to check.\n * @returns Whether the specified value has a runtime type of `object` and is\n * neither `null` nor an `Array`.\n */\nexport function isObject(value: unknown): value is RuntimeObject {\n return Boolean(value) && typeof value === 'object' && !Array.isArray(value);\n}\n\n//\n// Other utility functions\n//\n\n/**\n * A type guard for ensuring an object has a property.\n *\n * @param objectToCheck - The object to check.\n * @param name - The property name to check for.\n * @returns Whether the specified object has an own property with the specified\n * name, regardless of whether it is enumerable or not.\n */\nexport const hasProperty = <\n // eslint-disable-next-line @typescript-eslint/ban-types\n ObjectToCheck extends Object,\n Property extends PropertyKey,\n>(\n objectToCheck: ObjectToCheck,\n name: Property,\n): objectToCheck is ObjectToCheck &\n Record<\n Property,\n Property extends keyof ObjectToCheck ? ObjectToCheck[Property] : unknown\n > => Object.hasOwnProperty.call(objectToCheck, name);\n\n/**\n * `Object.getOwnPropertyNames()` is intentionally generic: it returns the\n * immediate property names of an object, but it cannot make guarantees about\n * the contents of that object, so the type of the property names is merely\n * `string[]`. While this is technically accurate, it is also unnecessary if we\n * have an object with a type that we own (such as an enum).\n *\n * @param object - The plain object.\n * @returns The own property names of the object which are assigned a type\n * derived from the object itself.\n */\nexport function getKnownPropertyNames<Key extends PropertyKey>(\n object: Partial<Record<Key, any>>,\n): Key[] {\n return Object.getOwnPropertyNames(object) as Key[];\n}\n\nexport type PlainObject = Record<number | string | symbol, unknown>;\n\n/**\n * Predefined sizes (in Bytes) of specific parts of JSON structure.\n */\nexport enum JsonSize {\n Null = 4,\n Comma = 1,\n Wrapper = 1,\n True = 4,\n False = 5,\n Quote = 1,\n Colon = 1,\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Date = 24,\n}\n\n/**\n * Regular expression with pattern matching for (special) escaped characters.\n */\nexport const ESCAPE_CHARACTERS_REGEXP = /\"|\\\\|\\n|\\r|\\t/gu;\n\n/**\n * Check if the value is plain object.\n *\n * @param value - Value to be checked.\n * @returns True if an object is the plain JavaScript object,\n * false if the object is not plain (e.g. function).\n */\nexport function isPlainObject(value: unknown): value is PlainObject {\n if (typeof value !== 'object' || value === null) {\n return false;\n }\n\n try {\n let proto = value;\n while (Object.getPrototypeOf(proto) !== null) {\n proto = Object.getPrototypeOf(proto);\n }\n\n return Object.getPrototypeOf(value) === proto;\n } catch (_) {\n return false;\n }\n}\n\n/**\n * Check if character is ASCII.\n *\n * @param character - Character.\n * @returns True if a character code is ASCII, false if not.\n */\nexport function isASCII(character: string) {\n return character.charCodeAt(0) <= 127;\n}\n\n/**\n * Calculate string size.\n *\n * @param value - String value to calculate size.\n * @returns Number of bytes used to store whole string value.\n */\nexport function calculateStringSize(value: string): number {\n const size = value.split('').reduce((total, character) => {\n if (isASCII(character)) {\n return total + 1;\n }\n return total + 2;\n }, 0);\n\n // Also detect characters that need backslash escape\n return size + (value.match(ESCAPE_CHARACTERS_REGEXP) ?? []).length;\n}\n\n/**\n * Calculate size of a number ofter JSON serialization.\n *\n * @param value - Number value to calculate size.\n * @returns Number of bytes used to store whole number in JSON.\n */\nexport function calculateNumberSize(value: number): number {\n return value.toString().length;\n}\n"],"names":["isNonEmptyArray","value","Array","isArray","length","isNullOrUndefined","undefined","isObject","Boolean","hasProperty","objectToCheck","name","Object","hasOwnProperty","call","getKnownPropertyNames","object","getOwnPropertyNames","JsonSize","Null","Comma","Wrapper","True","False","Quote","Colon","Date","ESCAPE_CHARACTERS_REGEXP","isPlainObject","proto","getPrototypeOf","_","isASCII","character","charCodeAt","calculateStringSize","size","split","reduce","total","match","calculateNumberSize","toString"],"mappings":"AAAA,EAAE;AACF,QAAQ;AACR,EAAE;AAEF;;;;;CAKC,GA6BD,EAAE;AACF,cAAc;AACd,EAAE;AAEF;;;;;;CAMC,GACD,OAAO,SAASA,gBACdC,KAAgB;IAEhB,OAAOC,MAAMC,OAAO,CAACF,UAAUA,MAAMG,MAAM,GAAG;AAChD;AAEA;;;;;CAKC,GACD,OAAO,SAASC,kBAAkBJ,KAAc;IAC9C,OAAOA,UAAU,QAAQA,UAAUK;AACrC;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,SAASN,KAAc;IACrC,OAAOO,QAAQP,UAAU,OAAOA,UAAU,YAAY,CAACC,MAAMC,OAAO,CAACF;AACvE;AAEA,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF;;;;;;;CAOC,GACD,OAAO,MAAMQ,cAAc,CAKzBC,eACAC,OAKKC,OAAOC,cAAc,CAACC,IAAI,CAACJ,eAAeC,MAAM;AAEvD;;;;;;;;;;CAUC,GACD,OAAO,SAASI,sBACdC,MAAiC;IAEjC,OAAOJ,OAAOK,mBAAmB,CAACD;AACpC;WAOO;UAAKE,QAAQ;IAARA,SAAAA,SACVC,UAAO,KAAPA;IADUD,SAAAA,SAEVE,WAAQ,KAARA;IAFUF,SAAAA,SAGVG,aAAU,KAAVA;IAHUH,SAAAA,SAIVI,UAAO,KAAPA;IAJUJ,SAAAA,SAKVK,WAAQ,KAARA;IALUL,SAAAA,SAMVM,WAAQ,KAARA;IANUN,SAAAA,SAOVO,WAAQ,KAARA;IAPUP,SAAAA,SAQV,wDAAwD;IACxDQ,UAAO,MAAPA;GATUR,aAAAA;AAYZ;;CAEC,GACD,OAAO,MAAMS,2BAA2B,kBAAkB;AAE1D;;;;;;CAMC,GACD,OAAO,SAASC,cAAc3B,KAAc;IAC1C,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM;QAC/C,OAAO;IACT;IAEA,IAAI;QACF,IAAI4B,QAAQ5B;QACZ,MAAOW,OAAOkB,cAAc,CAACD,WAAW,KAAM;YAC5CA,QAAQjB,OAAOkB,cAAc,CAACD;QAChC;QAEA,OAAOjB,OAAOkB,cAAc,CAAC7B,WAAW4B;IAC1C,EAAE,OAAOE,GAAG;QACV,OAAO;IACT;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASC,QAAQC,SAAiB;IACvC,OAAOA,UAAUC,UAAU,CAAC,MAAM;AACpC;AAEA;;;;;CAKC,GACD,OAAO,SAASC,oBAAoBlC,KAAa;IAC/C,MAAMmC,OAAOnC,MAAMoC,KAAK,CAAC,IAAIC,MAAM,CAAC,CAACC,OAAON;QAC1C,IAAID,QAAQC,YAAY;YACtB,OAAOM,QAAQ;QACjB;QACA,OAAOA,QAAQ;IACjB,GAAG;IAEH,oDAAoD;IACpD,OAAOH,OAAO,AAACnC,CAAAA,MAAMuC,KAAK,CAACb,6BAA6B,EAAE,AAAD,EAAGvB,MAAM;AACpE;AAEA;;;;;CAKC,GACD,OAAO,SAASqC,oBAAoBxC,KAAa;IAC/C,OAAOA,MAAMyC,QAAQ,GAAGtC,MAAM;AAChC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.hexToBigInt = exports.hexToNumber = exports.bigIntToHex = exports.numberToHex = void 0;
|
|
4
|
-
const assert_1 = require("./assert");
|
|
5
|
-
const hex_1 = require("./hex");
|
|
1
|
+
import { assert } from './assert';
|
|
2
|
+
import { add0x, assertIsHexString } from './hex';
|
|
6
3
|
/**
|
|
7
4
|
* Convert a number to a hexadecimal string. This verifies that the number is a
|
|
8
5
|
* non-negative safe integer.
|
|
@@ -19,14 +16,12 @@ const hex_1 = require("./hex");
|
|
|
19
16
|
* @param value - The number to convert to a hexadecimal string.
|
|
20
17
|
* @returns The hexadecimal string, with the "0x"-prefix.
|
|
21
18
|
* @throws If the number is not a non-negative safe integer.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
(
|
|
26
|
-
|
|
27
|
-
return (0, hex_1.add0x)(value.toString(16));
|
|
19
|
+
*/ export const numberToHex = (value)=>{
|
|
20
|
+
assert(typeof value === 'number', 'Value must be a number.');
|
|
21
|
+
assert(value >= 0, 'Value must be a non-negative number.');
|
|
22
|
+
assert(Number.isSafeInteger(value), 'Value is not a safe integer. Use `bigIntToHex` instead.');
|
|
23
|
+
return add0x(value.toString(16));
|
|
28
24
|
};
|
|
29
|
-
exports.numberToHex = numberToHex;
|
|
30
25
|
/**
|
|
31
26
|
* Convert a `bigint` to a hexadecimal string. This verifies that the `bigint`
|
|
32
27
|
* is a non-negative integer.
|
|
@@ -42,13 +37,11 @@ exports.numberToHex = numberToHex;
|
|
|
42
37
|
* @param value - The `bigint` to convert to a hexadecimal string.
|
|
43
38
|
* @returns The hexadecimal string, with the "0x"-prefix.
|
|
44
39
|
* @throws If the `bigint` is not a non-negative integer.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return (0, hex_1.add0x)(value.toString(16));
|
|
40
|
+
*/ export const bigIntToHex = (value)=>{
|
|
41
|
+
assert(typeof value === 'bigint', 'Value must be a bigint.');
|
|
42
|
+
assert(value >= 0, 'Value must be a non-negative bigint.');
|
|
43
|
+
return add0x(value.toString(16));
|
|
50
44
|
};
|
|
51
|
-
exports.bigIntToHex = bigIntToHex;
|
|
52
45
|
/**
|
|
53
46
|
* Convert a hexadecimal string to a number. This verifies that the string is a
|
|
54
47
|
* valid hex string, and that the resulting number is a safe integer. Both
|
|
@@ -67,16 +60,14 @@ exports.bigIntToHex = bigIntToHex;
|
|
|
67
60
|
* @returns The number.
|
|
68
61
|
* @throws If the value is not a valid hexadecimal string, or if the resulting
|
|
69
62
|
* number is not a safe integer.
|
|
70
|
-
*/
|
|
71
|
-
|
|
72
|
-
(0, hex_1.assertIsHexString)(value);
|
|
63
|
+
*/ export const hexToNumber = (value)=>{
|
|
64
|
+
assertIsHexString(value);
|
|
73
65
|
// `parseInt` accepts values without the "0x"-prefix, whereas `Number` does
|
|
74
66
|
// not. Using this is slightly faster than `Number(add0x(value))`.
|
|
75
67
|
const numberValue = parseInt(value, 16);
|
|
76
|
-
|
|
68
|
+
assert(Number.isSafeInteger(numberValue), 'Value is not a safe integer. Use `hexToBigInt` instead.');
|
|
77
69
|
return numberValue;
|
|
78
70
|
};
|
|
79
|
-
exports.hexToNumber = hexToNumber;
|
|
80
71
|
/**
|
|
81
72
|
* Convert a hexadecimal string to a `bigint`. This verifies that the string is
|
|
82
73
|
* a valid hex string. Both "0x"-prefixed and unprefixed strings are supported.
|
|
@@ -92,11 +83,10 @@ exports.hexToNumber = hexToNumber;
|
|
|
92
83
|
* @param value - The hexadecimal string to convert to a `bigint`.
|
|
93
84
|
* @returns The `bigint`.
|
|
94
85
|
* @throws If the value is not a valid hexadecimal string.
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
(0, hex_1.assertIsHexString)(value);
|
|
86
|
+
*/ export const hexToBigInt = (value)=>{
|
|
87
|
+
assertIsHexString(value);
|
|
98
88
|
// The `BigInt` constructor requires the "0x"-prefix to parse a hex string.
|
|
99
|
-
return BigInt(
|
|
89
|
+
return BigInt(add0x(value));
|
|
100
90
|
};
|
|
101
|
-
|
|
91
|
+
|
|
102
92
|
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/number.ts"],"sourcesContent":["import { assert } from './assert';\nimport { add0x, assertIsHexString } from './hex';\n\n/**\n * Convert a number to a hexadecimal string. This verifies that the number is a\n * non-negative safe integer.\n *\n * To convert a `bigint` to a hexadecimal string instead, use\n * {@link bigIntToHex}.\n *\n * @example\n * ```typescript\n * numberToHex(0); // '0x0'\n * numberToHex(1); // '0x1'\n * numberToHex(16); // '0x10'\n * ```\n * @param value - The number to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the number is not a non-negative safe integer.\n */\nexport const numberToHex = (value: number): string => {\n assert(typeof value === 'number', 'Value must be a number.');\n assert(value >= 0, 'Value must be a non-negative number.');\n assert(\n Number.isSafeInteger(value),\n 'Value is not a safe integer. Use `bigIntToHex` instead.',\n );\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a `bigint` to a hexadecimal string. This verifies that the `bigint`\n * is a non-negative integer.\n *\n * To convert a number to a hexadecimal string instead, use {@link numberToHex}.\n *\n * @example\n * ```typescript\n * bigIntToHex(0n); // '0x0'\n * bigIntToHex(1n); // '0x1'\n * bigIntToHex(16n); // '0x10'\n * ```\n * @param value - The `bigint` to convert to a hexadecimal string.\n * @returns The hexadecimal string, with the \"0x\"-prefix.\n * @throws If the `bigint` is not a non-negative integer.\n */\nexport const bigIntToHex = (value: bigint): string => {\n assert(typeof value === 'bigint', 'Value must be a bigint.');\n assert(value >= 0, 'Value must be a non-negative bigint.');\n\n return add0x(value.toString(16));\n};\n\n/**\n * Convert a hexadecimal string to a number. This verifies that the string is a\n * valid hex string, and that the resulting number is a safe integer. Both\n * \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a `bigint` instead, use\n * {@link hexToBigInt}.\n *\n * @example\n * ```typescript\n * hexToNumber('0x0'); // 0\n * hexToNumber('0x1'); // 1\n * hexToNumber('0x10'); // 16\n * ```\n * @param value - The hexadecimal string to convert to a number.\n * @returns The number.\n * @throws If the value is not a valid hexadecimal string, or if the resulting\n * number is not a safe integer.\n */\nexport const hexToNumber = (value: string): number => {\n assertIsHexString(value);\n\n // `parseInt` accepts values without the \"0x\"-prefix, whereas `Number` does\n // not. Using this is slightly faster than `Number(add0x(value))`.\n const numberValue = parseInt(value, 16);\n\n assert(\n Number.isSafeInteger(numberValue),\n 'Value is not a safe integer. Use `hexToBigInt` instead.',\n );\n\n return numberValue;\n};\n\n/**\n * Convert a hexadecimal string to a `bigint`. This verifies that the string is\n * a valid hex string. Both \"0x\"-prefixed and unprefixed strings are supported.\n *\n * To convert a hexadecimal string to a number instead, use {@link hexToNumber}.\n *\n * @example\n * ```typescript\n * hexToBigInt('0x0'); // 0n\n * hexToBigInt('0x1'); // 1n\n * hexToBigInt('0x10'); // 16n\n * ```\n * @param value - The hexadecimal string to convert to a `bigint`.\n * @returns The `bigint`.\n * @throws If the value is not a valid hexadecimal string.\n */\nexport const hexToBigInt = (value: string): bigint => {\n assertIsHexString(value);\n\n // The `BigInt` constructor requires the \"0x\"-prefix to parse a hex string.\n return BigInt(add0x(value));\n};\n"],"names":["assert","add0x","assertIsHexString","numberToHex","value","Number","isSafeInteger","toString","bigIntToHex","hexToNumber","numberValue","parseInt","hexToBigInt","BigInt"],"mappings":"AAAA,SAASA,MAAM,QAAQ,WAAW;AAClC,SAASC,KAAK,EAAEC,iBAAiB,QAAQ,QAAQ;AAEjD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,cAAc,CAACC;IAC1BJ,OAAO,OAAOI,UAAU,UAAU;IAClCJ,OAAOI,SAAS,GAAG;IACnBJ,OACEK,OAAOC,aAAa,CAACF,QACrB;IAGF,OAAOH,MAAMG,MAAMG,QAAQ,CAAC;AAC9B,EAAE;AAEF;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAMC,cAAc,CAACJ;IAC1BJ,OAAO,OAAOI,UAAU,UAAU;IAClCJ,OAAOI,SAAS,GAAG;IAEnB,OAAOH,MAAMG,MAAMG,QAAQ,CAAC;AAC9B,EAAE;AAEF;;;;;;;;;;;;;;;;;;CAkBC,GACD,OAAO,MAAME,cAAc,CAACL;IAC1BF,kBAAkBE;IAElB,2EAA2E;IAC3E,kEAAkE;IAClE,MAAMM,cAAcC,SAASP,OAAO;IAEpCJ,OACEK,OAAOC,aAAa,CAACI,cACrB;IAGF,OAAOA;AACT,EAAE;AAEF;;;;;;;;;;;;;;;CAeC,GACD,OAAO,MAAME,cAAc,CAACR;IAC1BF,kBAAkBE;IAElB,2EAA2E;IAC3E,OAAOS,OAAOZ,MAAMG;AACtB,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/opaque.ts"],"sourcesContent":["// We use a symbol property name instead of { _type: Brand }, because that would show up in IDE suggestions,\n// while internal symbols do not.\ndeclare const brand: unique symbol;\nexport type Opaque<Base, Brand extends symbol> = Base & { [brand]: Brand };\n"],"names":[],"mappings":"AAAA,4GAA4G;AAC5G,iCAAiC;AACjC,WAC2E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
package/dist/esm/time.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common duration constants, in milliseconds.
|
|
3
|
+
*/ export var Duration;
|
|
4
|
+
(function(Duration) {
|
|
5
|
+
Duration[Duration[/**
|
|
6
|
+
* A millisecond.
|
|
7
|
+
*/ "Millisecond"] = 1] = "Millisecond";
|
|
8
|
+
Duration[Duration[/**
|
|
9
|
+
* A second, in milliseconds.
|
|
10
|
+
*/ "Second"] = 1000] = "Second";
|
|
11
|
+
Duration[Duration[/**
|
|
12
|
+
* A minute, in milliseconds.
|
|
13
|
+
*/ "Minute"] = 60000] = "Minute";
|
|
14
|
+
Duration[Duration[/**
|
|
15
|
+
* An hour, in milliseconds.
|
|
16
|
+
*/ "Hour"] = 3600000] = "Hour";
|
|
17
|
+
Duration[Duration[/**
|
|
18
|
+
* A day, in milliseconds.
|
|
19
|
+
*/ "Day"] = 86400000] = "Day";
|
|
20
|
+
Duration[Duration[/**
|
|
21
|
+
* A week, in milliseconds.
|
|
22
|
+
*/ "Week"] = 604800000] = "Week";
|
|
23
|
+
Duration[Duration[/**
|
|
24
|
+
* A year, in milliseconds.
|
|
25
|
+
*/ "Year"] = 31536000000] = "Year";
|
|
26
|
+
})(Duration || (Duration = {}));
|
|
27
|
+
const isNonNegativeInteger = (number)=>Number.isInteger(number) && number >= 0;
|
|
28
|
+
const assertIsNonNegativeInteger = (number, name)=>{
|
|
29
|
+
if (!isNonNegativeInteger(number)) {
|
|
30
|
+
throw new Error(`"${name}" must be a non-negative integer. Received: "${number}".`);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Calculates the millisecond value of the specified number of units of time.
|
|
35
|
+
*
|
|
36
|
+
* @param count - The number of units of time.
|
|
37
|
+
* @param duration - The unit of time to count.
|
|
38
|
+
* @returns The count multiplied by the specified duration.
|
|
39
|
+
*/ export function inMilliseconds(count, duration) {
|
|
40
|
+
assertIsNonNegativeInteger(count, 'count');
|
|
41
|
+
return count * duration;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the milliseconds since a particular Unix epoch timestamp.
|
|
45
|
+
*
|
|
46
|
+
* @param timestamp - A Unix millisecond timestamp.
|
|
47
|
+
* @returns The number of milliseconds elapsed since the specified timestamp.
|
|
48
|
+
*/ export function timeSince(timestamp) {
|
|
49
|
+
assertIsNonNegativeInteger(timestamp, 'timestamp');
|
|
50
|
+
return Date.now() - timestamp;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
//# sourceMappingURL=time.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/time.ts"],"sourcesContent":["/**\n * Common duration constants, in milliseconds.\n */\nexport enum Duration {\n /**\n * A millisecond.\n */\n Millisecond = 1,\n\n /**\n * A second, in milliseconds.\n */\n Second = 1000, // Millisecond * 1000\n\n /**\n * A minute, in milliseconds.\n */\n Minute = 60_000, // Second * 60\n\n /**\n * An hour, in milliseconds.\n */\n Hour = 3_600_000, // Minute * 60\n\n /**\n * A day, in milliseconds.\n */\n Day = 86_400_000, // Hour * 24\n\n /**\n * A week, in milliseconds.\n */\n Week = 604_800_000, // Day * 7\n\n /**\n * A year, in milliseconds.\n */\n Year = 31_536_000_000, // Day * 365\n}\n\nconst isNonNegativeInteger = (number: number) =>\n Number.isInteger(number) && number >= 0;\n\nconst assertIsNonNegativeInteger = (number: number, name: string) => {\n if (!isNonNegativeInteger(number)) {\n throw new Error(\n `\"${name}\" must be a non-negative integer. Received: \"${number}\".`,\n );\n }\n};\n\n/**\n * Calculates the millisecond value of the specified number of units of time.\n *\n * @param count - The number of units of time.\n * @param duration - The unit of time to count.\n * @returns The count multiplied by the specified duration.\n */\nexport function inMilliseconds(count: number, duration: Duration): number {\n assertIsNonNegativeInteger(count, 'count');\n return count * duration;\n}\n\n/**\n * Gets the milliseconds since a particular Unix epoch timestamp.\n *\n * @param timestamp - A Unix millisecond timestamp.\n * @returns The number of milliseconds elapsed since the specified timestamp.\n */\nexport function timeSince(timestamp: number): number {\n assertIsNonNegativeInteger(timestamp, 'timestamp');\n return Date.now() - timestamp;\n}\n"],"names":["Duration","Millisecond","Second","Minute","Hour","Day","Week","Year","isNonNegativeInteger","number","Number","isInteger","assertIsNonNegativeInteger","name","Error","inMilliseconds","count","duration","timeSince","timestamp","Date","now"],"mappings":"AAAA;;CAEC,cACM;UAAKA,QAAQ;IAARA,SAAAA,SACV;;GAEC,GACDC,iBAAc,KAAdA;IAJUD,SAAAA,SAMV;;GAEC,GACDE,YAAS,QAATA;IATUF,SAAAA,SAWV;;GAEC,GACDG,YAAS,SAATA;IAdUH,SAAAA,SAgBV;;GAEC,GACDI,UAAO,WAAPA;IAnBUJ,SAAAA,SAqBV;;GAEC,GACDK,SAAM,YAANA;IAxBUL,SAAAA,SA0BV;;GAEC,GACDM,UAAO,aAAPA;IA7BUN,SAAAA,SA+BV;;GAEC,GACDO,UAAO,eAAPA;GAlCUP,aAAAA;AAqCZ,MAAMQ,uBAAuB,CAACC,SAC5BC,OAAOC,SAAS,CAACF,WAAWA,UAAU;AAExC,MAAMG,6BAA6B,CAACH,QAAgBI;IAClD,IAAI,CAACL,qBAAqBC,SAAS;QACjC,MAAM,IAAIK,MACR,CAAC,CAAC,EAAED,KAAK,6CAA6C,EAAEJ,OAAO,EAAE,CAAC;IAEtE;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASM,eAAeC,KAAa,EAAEC,QAAkB;IAC9DL,2BAA2BI,OAAO;IAClC,OAAOA,QAAQC;AACjB;AAEA;;;;;CAKC,GACD,OAAO,SAASC,UAAUC,SAAiB;IACzCP,2BAA2BO,WAAW;IACtC,OAAOC,KAAKC,GAAG,KAAKF;AACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/transaction-types.ts"],"sourcesContent":["import type { Bytes } from './bytes';\nimport type { Hex } from './hex';\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"],"names":[],"mappings":"AAAA,WAqIE"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { gt as gtSemver, gtr as gtrSemver, satisfies as satisfiesSemver, valid as validSemVerVersion, validRange as validSemVerRange } from 'semver';
|
|
2
|
+
import { is, refine, string } from 'superstruct';
|
|
3
|
+
import { assertStruct } from './assert';
|
|
4
|
+
/**
|
|
5
|
+
* A struct for validating a version string.
|
|
6
|
+
*/ export const VersionStruct = refine(string(), 'Version', (value)=>{
|
|
7
|
+
if (validSemVerVersion(value) === null) {
|
|
8
|
+
return `Expected SemVer version, got "${value}"`;
|
|
9
|
+
}
|
|
10
|
+
return true;
|
|
11
|
+
});
|
|
12
|
+
export const VersionRangeStruct = refine(string(), 'Version range', (value)=>{
|
|
13
|
+
if (validSemVerRange(value) === null) {
|
|
14
|
+
return `Expected SemVer range, got "${value}"`;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
});
|
|
18
|
+
/**
|
|
19
|
+
* Checks whether a SemVer version is valid.
|
|
20
|
+
*
|
|
21
|
+
* @param version - A potential version.
|
|
22
|
+
* @returns `true` if the version is valid, and `false` otherwise.
|
|
23
|
+
*/ export function isValidSemVerVersion(version) {
|
|
24
|
+
return is(version, VersionStruct);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Checks whether a SemVer version range is valid.
|
|
28
|
+
*
|
|
29
|
+
* @param versionRange - A potential version range.
|
|
30
|
+
* @returns `true` if the version range is valid, and `false` otherwise.
|
|
31
|
+
*/ export function isValidSemVerRange(versionRange) {
|
|
32
|
+
return is(versionRange, VersionRangeStruct);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Asserts that a value is a valid concrete SemVer version.
|
|
36
|
+
*
|
|
37
|
+
* @param version - A potential SemVer concrete version.
|
|
38
|
+
*/ export function assertIsSemVerVersion(version) {
|
|
39
|
+
assertStruct(version, VersionStruct);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Asserts that a value is a valid SemVer range.
|
|
43
|
+
*
|
|
44
|
+
* @param range - A potential SemVer range.
|
|
45
|
+
*/ export function assertIsSemVerRange(range) {
|
|
46
|
+
assertStruct(range, VersionRangeStruct);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether a SemVer version is greater than another.
|
|
50
|
+
*
|
|
51
|
+
* @param version1 - The left-hand version.
|
|
52
|
+
* @param version2 - The right-hand version.
|
|
53
|
+
* @returns `version1 > version2`.
|
|
54
|
+
*/ export function gtVersion(version1, version2) {
|
|
55
|
+
return gtSemver(version1, version2);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Checks whether a SemVer version is greater than all possibilities in a range.
|
|
59
|
+
*
|
|
60
|
+
* @param version - A SemvVer version.
|
|
61
|
+
* @param range - The range to check against.
|
|
62
|
+
* @returns `version > range`.
|
|
63
|
+
*/ export function gtRange(version, range) {
|
|
64
|
+
return gtrSemver(version, range);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns whether a SemVer version satisfies a SemVer range.
|
|
68
|
+
*
|
|
69
|
+
* @param version - The SemVer version to check.
|
|
70
|
+
* @param versionRange - The SemVer version range to check against.
|
|
71
|
+
* @returns Whether the version satisfied the version range.
|
|
72
|
+
*/ export function satisfiesVersionRange(version, versionRange) {
|
|
73
|
+
return satisfiesSemver(version, versionRange, {
|
|
74
|
+
includePrerelease: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=versions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/versions.ts"],"sourcesContent":["import {\n gt as gtSemver,\n gtr as gtrSemver,\n satisfies as satisfiesSemver,\n valid as validSemVerVersion,\n validRange as validSemVerRange,\n} from 'semver';\nimport type { Struct } from 'superstruct';\nimport { is, refine, string } from 'superstruct';\n\nimport { assertStruct } from './assert';\nimport type { Opaque } from './opaque';\n\n/**\n * {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for SemVer ranges.\n *\n * @example Use {@link assertIsSemVerRange} and {@link isValidSemVerRange} to cast to proper type.\n * ```typescript\n * const unsafeRange: string = dataFromUser();\n * assertIsSemVerRange(unsafeRange);\n * unsafeRange\n * // ^? SemVerRange\n * ```\n * @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.\n * ```typescript\n * const unsafeRange: string = dataFromUser();\n * unsafeRange as SemVerRange;\n * // ^? SemVerRange\n * ```\n * @see {@link assertIsSemVerRange}\n * @see {@link isValidSemVerRange}\n */\nexport type SemVerRange = Opaque<string, typeof semVerRange>;\ndeclare const semVerRange: unique symbol;\n\n/**\n * {@link https://codemix.com/opaque-types-in-javascript/ Opaque} type for singular SemVer version.\n *\n * @example Use {@link assertIsSemVerVersion} and {@link isValidSemVerVersion} to cast to proper type.\n * ```typescript\n * const unsafeVersion: string = dataFromUser();\n * assertIsSemVerVersion(unsafeRange);\n * unsafeVersion\n * // ^? SemVerVersion\n * ```\n * @example If you know what you're doing and want to side-step type safety, casting from a string works correctly.\n * ```typescript\n * const unsafeVersion: string = dataFromUser();\n * unsafeRange as SemVerVersion;\n * // ^? SemVerVersion\n * ```\n * @see {@link assertIsSemVerVersion}\n * @see {@link isValidSemVerVersion}\n */\nexport type SemVerVersion = Opaque<string, typeof semVerVersion>;\ndeclare const semVerVersion: unique symbol;\n\n/**\n * A struct for validating a version string.\n */\nexport const VersionStruct = refine<SemVerVersion, null>(\n string() as unknown as Struct<SemVerVersion, null>,\n 'Version',\n (value) => {\n if (validSemVerVersion(value) === null) {\n return `Expected SemVer version, got \"${value}\"`;\n }\n return true;\n },\n);\n\nexport const VersionRangeStruct = refine<SemVerRange, null>(\n string() as unknown as Struct<SemVerRange, null>,\n 'Version range',\n (value) => {\n if (validSemVerRange(value) === null) {\n return `Expected SemVer range, got \"${value}\"`;\n }\n return true;\n },\n);\n\n/**\n * Checks whether a SemVer version is valid.\n *\n * @param version - A potential version.\n * @returns `true` if the version is valid, and `false` otherwise.\n */\nexport function isValidSemVerVersion(\n version: unknown,\n): version is SemVerVersion {\n return is(version, VersionStruct);\n}\n\n/**\n * Checks whether a SemVer version range is valid.\n *\n * @param versionRange - A potential version range.\n * @returns `true` if the version range is valid, and `false` otherwise.\n */\nexport function isValidSemVerRange(\n versionRange: unknown,\n): versionRange is SemVerRange {\n return is(versionRange, VersionRangeStruct);\n}\n\n/**\n * Asserts that a value is a valid concrete SemVer version.\n *\n * @param version - A potential SemVer concrete version.\n */\nexport function assertIsSemVerVersion(\n version: unknown,\n): asserts version is SemVerVersion {\n assertStruct(version, VersionStruct);\n}\n\n/**\n * Asserts that a value is a valid SemVer range.\n *\n * @param range - A potential SemVer range.\n */\nexport function assertIsSemVerRange(\n range: unknown,\n): asserts range is SemVerRange {\n assertStruct(range, VersionRangeStruct);\n}\n\n/**\n * Checks whether a SemVer version is greater than another.\n *\n * @param version1 - The left-hand version.\n * @param version2 - The right-hand version.\n * @returns `version1 > version2`.\n */\nexport function gtVersion(\n version1: SemVerVersion,\n version2: SemVerVersion,\n): boolean {\n return gtSemver(version1, version2);\n}\n\n/**\n * Checks whether a SemVer version is greater than all possibilities in a range.\n *\n * @param version - A SemvVer version.\n * @param range - The range to check against.\n * @returns `version > range`.\n */\nexport function gtRange(version: SemVerVersion, range: SemVerRange): boolean {\n return gtrSemver(version, range);\n}\n\n/**\n * Returns whether a SemVer version satisfies a SemVer range.\n *\n * @param version - The SemVer version to check.\n * @param versionRange - The SemVer version range to check against.\n * @returns Whether the version satisfied the version range.\n */\nexport function satisfiesVersionRange(\n version: SemVerVersion,\n versionRange: SemVerRange,\n): boolean {\n return satisfiesSemver(version, versionRange, {\n includePrerelease: true,\n });\n}\n"],"names":["gt","gtSemver","gtr","gtrSemver","satisfies","satisfiesSemver","valid","validSemVerVersion","validRange","validSemVerRange","is","refine","string","assertStruct","VersionStruct","value","VersionRangeStruct","isValidSemVerVersion","version","isValidSemVerRange","versionRange","assertIsSemVerVersion","assertIsSemVerRange","range","gtVersion","version1","version2","gtRange","satisfiesVersionRange","includePrerelease"],"mappings":"AAAA,SACEA,MAAMC,QAAQ,EACdC,OAAOC,SAAS,EAChBC,aAAaC,eAAe,EAC5BC,SAASC,kBAAkB,EAC3BC,cAAcC,gBAAgB,QACzB,SAAS;AAEhB,SAASC,EAAE,EAAEC,MAAM,EAAEC,MAAM,QAAQ,cAAc;AAEjD,SAASC,YAAY,QAAQ,WAAW;AA+CxC;;CAEC,GACD,OAAO,MAAMC,gBAAgBH,OAC3BC,UACA,WACA,CAACG;IACC,IAAIR,mBAAmBQ,WAAW,MAAM;QACtC,OAAO,CAAC,8BAA8B,EAAEA,MAAM,CAAC,CAAC;IAClD;IACA,OAAO;AACT,GACA;AAEF,OAAO,MAAMC,qBAAqBL,OAChCC,UACA,iBACA,CAACG;IACC,IAAIN,iBAAiBM,WAAW,MAAM;QACpC,OAAO,CAAC,4BAA4B,EAAEA,MAAM,CAAC,CAAC;IAChD;IACA,OAAO;AACT,GACA;AAEF;;;;;CAKC,GACD,OAAO,SAASE,qBACdC,OAAgB;IAEhB,OAAOR,GAAGQ,SAASJ;AACrB;AAEA;;;;;CAKC,GACD,OAAO,SAASK,mBACdC,YAAqB;IAErB,OAAOV,GAAGU,cAAcJ;AAC1B;AAEA;;;;CAIC,GACD,OAAO,SAASK,sBACdH,OAAgB;IAEhBL,aAAaK,SAASJ;AACxB;AAEA;;;;CAIC,GACD,OAAO,SAASQ,oBACdC,KAAc;IAEdV,aAAaU,OAAOP;AACtB;AAEA;;;;;;CAMC,GACD,OAAO,SAASQ,UACdC,QAAuB,EACvBC,QAAuB;IAEvB,OAAOzB,SAASwB,UAAUC;AAC5B;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,QAAQT,OAAsB,EAAEK,KAAkB;IAChE,OAAOpB,UAAUe,SAASK;AAC5B;AAEA;;;;;;CAMC,GACD,OAAO,SAASK,sBACdV,OAAsB,EACtBE,YAAyB;IAEzB,OAAOf,gBAAgBa,SAASE,cAAc;QAC5CS,mBAAmB;IACrB;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Struct } from 'superstruct';
|
|
1
|
+
import type { Struct } from 'superstruct';
|
|
2
2
|
export declare type AssertionErrorConstructor = (new (args: {
|
|
3
3
|
message: string;
|
|
4
4
|
}) => Error) | ((args: {
|
|
@@ -37,7 +37,7 @@ export declare function assert(value: any, message?: string | Error, ErrorWrappe
|
|
|
37
37
|
* Defaults to {@link AssertionError}.
|
|
38
38
|
* @throws If the value is not valid.
|
|
39
39
|
*/
|
|
40
|
-
export declare function assertStruct<
|
|
40
|
+
export declare function assertStruct<Type, Schema>(value: unknown, struct: Struct<Type, Schema>, errorPrefix?: string, ErrorWrapper?: AssertionErrorConstructor): asserts value is Type;
|
|
41
41
|
/**
|
|
42
42
|
* Use in the default case of a switch that you want to be fully exhaustive.
|
|
43
43
|
* Using this function forces the compiler to enforce exhaustivity during
|
|
@@ -58,3 +58,4 @@ export declare function assertStruct<T, S>(value: unknown, struct: Struct<T, S>,
|
|
|
58
58
|
* @param _object - The object on which the switch is being operated.
|
|
59
59
|
*/
|
|
60
60
|
export declare function assertExhaustive(_object: never): never;
|
|
61
|
+
//# sourceMappingURL=assert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../../src/assert.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,oBAAY,yBAAyB,GACjC,CAAC,KAAK,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,KAAK,KAAK,CAAC,GAC1C,CAAC,CAAC,IAAI,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,KAAK,KAAK,CAAC,CAAC;AAiE3C;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACvC,QAAQ,CAAC,IAAI,mBAAmB;gBAEpB,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;CAGzC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,MAAM,CACpB,KAAK,EAAE,GAAG,EACV,OAAO,GAAE,MAAM,GAAG,KAA2B,EAE7C,YAAY,GAAE,yBAA0C,GACvD,OAAO,CAAC,KAAK,CAQf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EACvC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAC5B,WAAW,SAAqB,EAEhC,YAAY,GAAE,yBAA0C,GACvD,OAAO,CAAC,KAAK,IAAI,IAAI,CAMvB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,KAAK,GAAG,KAAK,CAItD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Struct } from 'superstruct';
|
|
1
|
+
import type { Struct } from 'superstruct';
|
|
2
2
|
export declare type Base64Options = {
|
|
3
3
|
/**
|
|
4
4
|
* Is the `=` padding at the end required or not.
|
|
@@ -21,4 +21,5 @@ export declare type Base64Options = {
|
|
|
21
21
|
* @param options - Optional options to specialize base64 validation. See {@link Base64Options} documentation.
|
|
22
22
|
* @returns A superstruct validating base64.
|
|
23
23
|
*/
|
|
24
|
-
export declare const base64: <
|
|
24
|
+
export declare const base64: <Type extends string, Schema>(struct: Struct<Type, Schema>, options?: Base64Options) => Struct<Type, Schema>;
|
|
25
|
+
//# sourceMappingURL=base64.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C,oBAAY,aAAa,GAAG;IAC1B;;;;OAIG;IAEH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,QAAQ,GAAG,WAAW,CAAC;CACvC,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,wEAER,aAAa,yBA2BvB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Hex } from './hex';
|
|
1
|
+
import type { Hex } from './hex';
|
|
2
2
|
export declare type Bytes = bigint | number | string | Uint8Array;
|
|
3
3
|
/**
|
|
4
4
|
* Check if a value is a `Uint8Array`.
|
|
@@ -166,3 +166,4 @@ export declare function concatBytes(values: Bytes[]): Uint8Array;
|
|
|
166
166
|
* @returns The {@link DataView}.
|
|
167
167
|
*/
|
|
168
168
|
export declare function createDataView(bytes: Uint8Array): DataView;
|
|
169
|
+
//# sourceMappingURL=bytes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.d.ts","sourceRoot":"","sources":["../../src/bytes.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAUjC,oBAAY,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,UAAU,CAAC;AAwC1D;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,GAAG,CAgBjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAKvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAU7D;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAWvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAoCpD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAMvD;AAkBD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,UAAU,CAqBZ;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAUvD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAIvD;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAsBrD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,CAqBvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAe1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checksum.d.ts","sourceRoot":"","sources":["../../src/checksum.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,4CAI1B,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Infer } from 'superstruct';
|
|
2
|
-
import { Hex } from './hex';
|
|
1
|
+
import type { Infer } from 'superstruct';
|
|
2
|
+
import type { Hex } from './hex';
|
|
3
3
|
declare const NumberLikeStruct: import("superstruct").Struct<string | number | bigint, null>;
|
|
4
4
|
declare const BytesLikeStruct: import("superstruct").Struct<Uint8Array | `0x${string}`, null>;
|
|
5
5
|
export declare type NumberLike = Infer<typeof NumberLikeStruct>;
|
|
@@ -94,3 +94,4 @@ export declare function createBytes(value: BytesLike): Uint8Array;
|
|
|
94
94
|
*/
|
|
95
95
|
export declare function createHex(value: BytesLike): Hex;
|
|
96
96
|
export {};
|
|
97
|
+
//# sourceMappingURL=coercers.d.ts.map
|