@metamask/utils 3.4.1 → 3.6.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.
@@ -0,0 +1,6 @@
1
+ export declare type Eip1024EncryptedData = {
2
+ version: string;
3
+ nonce: string;
4
+ ephemPublicKey: string;
5
+ ciphertext: string;
6
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=encryption-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encryption-types.js","sourceRoot":"","sources":["../src/encryption-types.ts"],"names":[],"mappings":"","sourcesContent":["export type Eip1024EncryptedData = {\n version: string;\n nonce: string;\n ephemPublicKey: string;\n ciphertext: string;\n};\n"]}
@@ -0,0 +1,210 @@
1
+ import type { Eip1024EncryptedData } from './encryption-types';
2
+ import { Hex } from './hex';
3
+ import { Json } from './json';
4
+ import type { Transaction, SignedTransaction } from './transaction-types';
5
+ /**
6
+ * A Keyring class.
7
+ *
8
+ * This type is used to validate the constructor signature and the `type`
9
+ * static property on Keyring classes. See the {@link Keyring} type for more
10
+ * information.
11
+ */
12
+ export declare type KeyringClass<State extends Json> = {
13
+ /**
14
+ * The Keyring constructor. Takes a single parameter, an "options" object.
15
+ * See the documentation for the specific keyring for more information about
16
+ * what these options are.
17
+ *
18
+ * @param options - The constructor options. Differs between keyring
19
+ * implementations.
20
+ */
21
+ new (options?: Record<string, unknown>): Keyring<State>;
22
+ /**
23
+ * The name of this type of keyring. This must uniquely identify the
24
+ * keyring type.
25
+ */
26
+ type: string;
27
+ };
28
+ /**
29
+ * A keyring is something that can sign messages. Keyrings are used to add new
30
+ * signing strategies; each strategy is a new keyring.
31
+ *
32
+ * Each keyring manages a collection of key pairs, which we call "accounts".
33
+ * Each account is referred to by its "address", which is a unique identifier
34
+ * derived from the public key. The address is always a "0x"-prefixed
35
+ * hexidecimal string.
36
+ *
37
+ * The keyring might store the private key for each account as well, but it's
38
+ * not guaranteed. Some keyrings delegate signing, so they don't need the
39
+ * private key directly. The keyring (and in particular the keyring state)
40
+ * should be treated with care though, just in case it does contain sensitive
41
+ * material such as a private key.
42
+ */
43
+ export declare type Keyring<State extends Json> = {
44
+ /**
45
+ * The name of this type of keyring. This must match the `type` property of
46
+ * the keyring class.
47
+ */
48
+ type: string;
49
+ /**
50
+ * Get the addresses for all accounts in this keyring.
51
+ *
52
+ * @returns A list of the account addresses for this keyring
53
+ */
54
+ getAccounts(): Promise<Hex[]>;
55
+ /**
56
+ * Add an account to the keyring.
57
+ *
58
+ * @param number - The number of accounts to add. Usually defaults to 1.
59
+ * @returns A list of the newly added account addresses.
60
+ */
61
+ addAccounts(number: number): Promise<Hex[]>;
62
+ /**
63
+ * Serialize the keyring state as a JSON-serializable object.
64
+ *
65
+ * @returns A JSON-serializable representation of the keyring state.
66
+ */
67
+ serialize(): Promise<State>;
68
+ /**
69
+ * Deserialize the given keyring state, overwriting any existing state with
70
+ * the serialized state provided.
71
+ *
72
+ * @param state - A JSON-serializable representation of the keyring state.
73
+ */
74
+ deserialize(state: State): Promise<void>;
75
+ /**
76
+ * Remove an account from the keyring.
77
+ *
78
+ * @param address - The address of the account to remove.
79
+ */
80
+ removeAccount?(address: Hex): void;
81
+ /**
82
+ * Export the private key for one of the keyring accounts.
83
+ *
84
+ * Some keyrings accept an "options" parameter as well. See the documentation
85
+ * for the specific keyring for more information about what these options
86
+ * are. For some keyrings, the options parameter is used to allow exporting a
87
+ * private key that is derived from the given account, rather than exporting
88
+ * that account's private key directly.
89
+ *
90
+ * @param address - The address of the account to export.
91
+ * @param options - Export options; differs between keyrings.
92
+ * @returns The non-prefixed, hex-encoded private key that was requested.
93
+ */
94
+ exportAccount?(address: Hex, options?: Record<string, unknown>): Promise<string>;
95
+ /**
96
+ * Get the "app key" address for the given account and origin. An app key is
97
+ * an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}
98
+ * for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}
99
+ * is used as the unique identifier for the application, and it's used as
100
+ * part of the key derivation process.
101
+ *
102
+ * @param address - The address of the account the app key is derived from.
103
+ * @param origin - The origin of the application.
104
+ * @returns The address of the app key for the given account and origin.
105
+ */
106
+ getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;
107
+ /**
108
+ * Sign a transaction. This is equivalent to the `eth_signTransaction`
109
+ * Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for
110
+ * more details.
111
+ *
112
+ * Some keyrings accept an "options" parameter as well. See the documentation
113
+ * for the specific keyring for more information about what these options
114
+ * are. For some keyrings, the options parameter can even change which key is
115
+ * used for signing (e.g. signing with app keys).
116
+ *
117
+ * @param address - The address of the account to use for signing.
118
+ * @param transaction - The transaction to sign.
119
+ * @param options - Signing options; differs between keyrings.
120
+ * @returns The signed transaction.
121
+ */
122
+ signTransaction?(address: Hex, transaction: Transaction, options?: Record<string, unknown>): Promise<SignedTransaction>;
123
+ /**
124
+ * Sign a message. This is equivalent to an older version of the the
125
+ * `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,
126
+ * using the curve secp256k1 the Keccak-256 hash function.
127
+ *
128
+ * For more information about this method and why we still support it, see
129
+ * the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
130
+ *
131
+ * Some keyrings accept an "options" parameter as well. See the documentation
132
+ * for the specific keyring for more information about what these options
133
+ * are. For some keyrings, the options parameter can even change which key is
134
+ * used for signing (e.g. signing with app keys).
135
+ *
136
+ * @param address - The address of the account to use for signing.
137
+ * @param message - The message to sign.
138
+ * @param options - Signing options; differs between keyrings.
139
+ * @returns The signed message.
140
+ */
141
+ signMessage?(address: Hex, message: string, options?: Record<string, unknown>): Promise<string>;
142
+ /**
143
+ * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC
144
+ * method, which is exposed by MetaMask as the method `personal_sign`. See
145
+ * the Ethereum JSON-RPC API documentation for more details.
146
+ *
147
+ * For more information about this method and why we call it `personal_sign`,
148
+ * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
149
+ *
150
+ * Some keyrings accept an "options" parameter as well. See the documentation
151
+ * for the specific keyring for more information about what these options
152
+ * are. For some keyrings, the options parameter can even change which key is
153
+ * used for signing (e.g. signing with app keys).
154
+ *
155
+ * @param address - The address of the account to use for signing.
156
+ * @param message - The message to sign.
157
+ * @param options - Signing options; differs between keyrings.
158
+ * @returns The signed message.
159
+ */
160
+ signPersonalMessage?(address: Hex, message: Hex, options?: {
161
+ version?: string;
162
+ } & Record<string, unknown>): Promise<string>;
163
+ /**
164
+ * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum
165
+ * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}
166
+ * for more details.
167
+ *
168
+ * The "version" option dictates which version of `eth_signTypedData` is
169
+ * used. The latest version reflects the specification most closely, whereas
170
+ * earlier versions reflect earlier drafts of the specification that are
171
+ * still supported for backwards-compatibility reasons. For more information
172
+ * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
173
+ *
174
+ * Some keyrings accept additional options as well. See the documentation for
175
+ * the specific keyring for more information about what these options are.
176
+ * For some keyrings, the options parameter can even change which key is used
177
+ * for signing (e.g. signing with app keys).
178
+ *
179
+ * @param address - The address of the account to use for signing.
180
+ * @param typedData - The data to sign.
181
+ * @param options - Signing options; differs between keyrings.
182
+ * @returns The signed message.
183
+ */
184
+ signTypedData?(address: Hex, typedData: Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
185
+ /**
186
+ * Get a public key to use for encryption. This is equivalent to the
187
+ * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}
188
+ * for more information.
189
+ *
190
+ * Some keyrings accept an "options" parameter as well. See the documentation
191
+ * for the specific keyring for more information about what these options
192
+ * are. For some keyrings, the options parameter can even change which key is
193
+ * used (e.g. encrypting with app keys).
194
+ *
195
+ * @param account - The address of the account you want the encryption key for.
196
+ * @param options - Options; differs between keyrings.
197
+ */
198
+ getEncryptionPublicKey?(account: Hex, options?: Record<string, unknown>): Promise<string>;
199
+ /**
200
+ * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`
201
+ * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}
202
+ * for more information.
203
+ *
204
+ * @param account - The address of the account you want to use to decrypt
205
+ * the message.
206
+ * @param encryptedData - The encrypted data that you want to decrypt.
207
+ * @returns The decrypted data.
208
+ */
209
+ decryptMessage?(account: Hex, encryptedData: Eip1024EncryptedData): Promise<string>;
210
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=keyring.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyring.js","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { Eip1024EncryptedData } from './encryption-types';\nimport { Hex } from './hex';\nimport { Json } from './json';\nimport type { Transaction, SignedTransaction } from './transaction-types';\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 * 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: Transaction,\n options?: Record<string, unknown>,\n ): Promise<SignedTransaction>;\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"]}
package/dist/misc.d.ts CHANGED
@@ -22,10 +22,9 @@ export declare type PartialOrAbsent<Value> = Partial<Value> | null | undefined;
22
22
  */
23
23
  export declare type NonEmptyArray<Element> = [Element, ...Element[]];
24
24
  /**
25
- * A JavaScript object that is not `null`, a function, or an array. The object
26
- * can still be an instance of a class.
25
+ * A JavaScript object that is not `null`, a function, or an array.
27
26
  */
28
- export declare type RuntimeObject = Record<number | string | symbol, unknown>;
27
+ export declare type RuntimeObject = Record<PropertyKey, unknown>;
29
28
  /**
30
29
  * A {@link NonEmptyArray} type guard.
31
30
  *
@@ -50,14 +49,14 @@ export declare function isNullOrUndefined(value: unknown): value is null | undef
50
49
  */
51
50
  export declare function isObject(value: unknown): value is RuntimeObject;
52
51
  /**
53
- * An alias for {@link Object.hasOwnProperty}.
52
+ * A type guard for ensuring an object has a property.
54
53
  *
55
- * @param object - The object to check.
54
+ * @param objectToCheck - The object to check.
56
55
  * @param name - The property name to check for.
57
56
  * @returns Whether the specified object has an own property with the specified
58
57
  * name, regardless of whether it is enumerable or not.
59
58
  */
60
- export declare const hasProperty: (object: RuntimeObject, name: string | number | symbol) => boolean;
59
+ export declare const hasProperty: <ObjectToCheck extends Object, Property extends PropertyKey>(objectToCheck: ObjectToCheck, name: Property) => objectToCheck is ObjectToCheck & Record<Property, unknown>;
61
60
  export declare type PlainObject = Record<number | string | symbol, unknown>;
62
61
  /**
63
62
  * Predefined sizes (in Bytes) of specific parts of JSON structure.
package/dist/misc.js CHANGED
@@ -43,14 +43,14 @@ exports.isObject = isObject;
43
43
  // Other utility functions
44
44
  //
45
45
  /**
46
- * An alias for {@link Object.hasOwnProperty}.
46
+ * A type guard for ensuring an object has a property.
47
47
  *
48
- * @param object - The object to check.
48
+ * @param objectToCheck - The object to check.
49
49
  * @param name - The property name to check for.
50
50
  * @returns Whether the specified object has an own property with the specified
51
51
  * name, regardless of whether it is enumerable or not.
52
52
  */
53
- const hasProperty = (object, name) => Object.hasOwnProperty.call(object, name);
53
+ const hasProperty = (objectToCheck, name) => Object.hasOwnProperty.call(objectToCheck, name);
54
54
  exports.hasProperty = hasProperty;
55
55
  /**
56
56
  * Predefined sizes (in Bytes) of specific parts of JSON structure.
package/dist/misc.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"misc.js","sourceRoot":"","sources":["../src/misc.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,QAAQ;AACR,EAAE;;;AAqCF,EAAE;AACF,cAAc;AACd,EAAE;AAEF;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,KAAgB;IAEhB,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;AAClD,CAAC;AAJD,0CAIC;AAED;;;;;GAKG;AACH,SAAgB,iBAAiB,CAAC,KAAc;IAC9C,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC;AAC/C,CAAC;AAFD,8CAEC;AAED;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAFD,4BAEC;AAED,EAAE;AACF,0BAA0B;AAC1B,EAAE;AAEF;;;;;;;GAOG;AACI,MAAM,WAAW,GAAG,CACzB,MAAqB,EACrB,IAA8B,EACrB,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAH1C,QAAA,WAAW,eAG+B;AAIvD;;GAEG;AACH,IAAY,QAUX;AAVD,WAAY,QAAQ;IAClB,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,6CAAW,CAAA;IACX,uCAAQ,CAAA;IACR,yCAAS,CAAA;IACT,yCAAS,CAAA;IACT,yCAAS,CAAA;IACT,wDAAwD;IACxD,wCAAS,CAAA;AACX,CAAC,EAVW,QAA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OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC;AACjC,CAAC;AAFD,kDAEC","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. The object\n * can still be an instance of a class.\n */\nexport type RuntimeObject = Record<number | string | symbol, 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 * An alias for {@link Object.hasOwnProperty}.\n *\n * @param object - 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 object: RuntimeObject,\n name: string | number | symbol,\n): boolean => Object.hasOwnProperty.call(object, name);\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"]}
1
+ {"version":3,"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AO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE;QAC/C,OAAO,KAAK,CAAC;KACd;IAED,IAAI;QACF,IAAI,KAAK,GAAG,KAAK,CAAC;QAClB,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE;YAC5C,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;SACtC;QAED,OAAO,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,KAAK,KAAK,CAAC;KAC/C;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAfD,sCAeC;AAED;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,SAAiB;IACvC,OAAO,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC;AACxC,CAAC;AAFD,0BAEC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa;;IAC/C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE;QACvD,IAAI,OAAO,CAAC,SAAS,CAAC,EAAE;YACtB,OAAO,KAAK,GAAG,CAAC,CAAC;SAClB;QACD,OAAO,KAAK,GAAG,CAAC,CAAC;IACnB,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,oDAAoD;IACpD,OAAO,IAAI,GAAG,CAAC,MAAA,KAAK,CAAC,KAAK,CAAC,gCAAwB,CAAC,mCAAI,EAAE,CAAC,CAAC,MAAM,CAAC;AACrE,CAAC;AAVD,kDAUC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,KAAa;IAC/C,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC;AACjC,CAAC;AAFD,kDAEC","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 & Record<Property, unknown> =>\n Object.hasOwnProperty.call(objectToCheck, name);\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"]}
@@ -0,0 +1,116 @@
1
+ import { Bytes } from './bytes';
2
+ import { Hex } from './hex';
3
+ export declare type Transaction = LegacyTransaction | EIP2930Transaction | EIP1559Transaction;
4
+ export declare type SignedTransaction = Transaction & Signature;
5
+ export declare type Signature = {
6
+ /**
7
+ * EC signature parameter
8
+ * 32 bytes long sequence.
9
+ */
10
+ r: Bytes;
11
+ /**
12
+ * EC signature parameter
13
+ * Signature proof.
14
+ * 32 bytes long sequence
15
+ */
16
+ s: Bytes;
17
+ /**
18
+ * Recovery identifier. It can be either 0x1b or 0x1c
19
+ * 1 byte long sequence
20
+ */
21
+ yParity: Bytes;
22
+ };
23
+ /**
24
+ * Base Ethereum Transaction
25
+ */
26
+ export declare type BaseTransaction = {
27
+ /**
28
+ * Sequentially incrementing counter which indicates the transaction
29
+ * number from the account
30
+ */
31
+ nonce: Bytes;
32
+ /**
33
+ * The address of the sender, that will be signing the transaction
34
+ */
35
+ from: Hex | Uint8Array;
36
+ /**
37
+ * The receiving address.
38
+ * If an externally-owned account, the transaction will transfer value.
39
+ * If a contract account, the transaction will execute the contract code.
40
+ */
41
+ to: Hex | Uint8Array;
42
+ /**
43
+ * The amount of Ether sent.
44
+ */
45
+ value: Bytes;
46
+ /**
47
+ * Maximum amount of gas units that this transaction can consume.
48
+ */
49
+ gasLimit: Bytes;
50
+ /**
51
+ * Arbitrary data.
52
+ */
53
+ data?: Bytes;
54
+ };
55
+ /**
56
+ * Typed Ethereum Transaction
57
+ */
58
+ export declare type TypedTransaction = BaseTransaction & {
59
+ /**
60
+ * Transaction type.
61
+ */
62
+ type: number;
63
+ };
64
+ /**
65
+ * Ethereum Legacy Transaction
66
+ * Reference: https://ethereum.org/en/developers/docs/transactions/
67
+ */
68
+ export declare type LegacyTransaction = BaseTransaction & {
69
+ /**
70
+ * Transaction's gas price.
71
+ */
72
+ gasPrice: Bytes | null;
73
+ };
74
+ /**
75
+ * EIP-2930 Transaction: Optional Access Lists
76
+ * Reference: https://eips.ethereum.org/EIPS/eip-2930
77
+ */
78
+ export declare type EIP2930Transaction = TypedTransaction & {
79
+ /**
80
+ * Transaction type.
81
+ */
82
+ type: 1;
83
+ /**
84
+ * Transaction chain ID
85
+ */
86
+ chainId: Bytes;
87
+ /**
88
+ * List of addresses and storage keys that the transaction plans to access
89
+ */
90
+ accessList: {
91
+ address: Hex;
92
+ storageKeys: Hex[];
93
+ }[] | {
94
+ address: Uint8Array;
95
+ storageKeys: Uint8Array[];
96
+ }[];
97
+ };
98
+ /**
99
+ * EIP-1559 Transaction: Fee market change for ETH 1.0 chain (Type-2)
100
+ *
101
+ * Reference: https://eips.ethereum.org/EIPS/eip-1559
102
+ */
103
+ export declare type EIP1559Transaction = TypedTransaction & {
104
+ /**
105
+ * Transaction type.
106
+ */
107
+ type: 2;
108
+ /**
109
+ * Maximum fee to give to the miner
110
+ */
111
+ maxPriorityFeePerGas: Bytes;
112
+ /**
113
+ * Maximum total fee
114
+ */
115
+ maxFeePerGas: Bytes;
116
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=transaction-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction-types.js","sourceRoot":"","sources":["../src/transaction-types.ts"],"names":[],"mappings":"","sourcesContent":["import { Bytes } from './bytes';\nimport { 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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/utils",
3
- "version": "3.4.1",
3
+ "version": "3.6.0",
4
4
  "description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- export {};
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tsd_1 = require("tsd");
4
- // Valid hex strings:
5
- (0, tsd_1.expectAssignable)('0x');
6
- (0, tsd_1.expectAssignable)('0x0');
7
- (0, tsd_1.expectAssignable)('0x😀');
8
- const embeddedString = 'test';
9
- (0, tsd_1.expectAssignable)(`0x${embeddedString}`);
10
- // Not valid hex strings:
11
- (0, tsd_1.expectNotAssignable)(`0X${embeddedString}`);
12
- (0, tsd_1.expectNotAssignable)(`1x${embeddedString}`);
13
- (0, tsd_1.expectNotAssignable)(0);
14
- (0, tsd_1.expectNotAssignable)('0');
15
- (0, tsd_1.expectNotAssignable)('🙃');
16
- //# sourceMappingURL=hex.test-d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hex.test-d.js","sourceRoot":"","sources":["../src/hex.test-d.ts"],"names":[],"mappings":";;AAAA,6BAA4D;AAI5D,qBAAqB;AAErB,IAAA,sBAAgB,EAAM,IAAI,CAAC,CAAC;AAE5B,IAAA,sBAAgB,EAAM,KAAK,CAAC,CAAC;AAE7B,IAAA,sBAAgB,EAAM,MAAM,CAAC,CAAC;AAE9B,MAAM,cAAc,GAAG,MAAM,CAAC;AAC9B,IAAA,sBAAgB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAE7C,yBAAyB;AAEzB,IAAA,yBAAmB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAEhD,IAAA,yBAAmB,EAAM,KAAK,cAAc,EAAE,CAAC,CAAC;AAEhD,IAAA,yBAAmB,EAAM,CAAC,CAAC,CAAC;AAE5B,IAAA,yBAAmB,EAAM,GAAG,CAAC,CAAC;AAE9B,IAAA,yBAAmB,EAAM,IAAI,CAAC,CAAC","sourcesContent":["import { expectAssignable, expectNotAssignable } from 'tsd';\n\nimport { Hex } from '.';\n\n// Valid hex strings:\n\nexpectAssignable<Hex>('0x');\n\nexpectAssignable<Hex>('0x0');\n\nexpectAssignable<Hex>('0x😀');\n\nconst embeddedString = 'test';\nexpectAssignable<Hex>(`0x${embeddedString}`);\n\n// Not valid hex strings:\n\nexpectNotAssignable<Hex>(`0X${embeddedString}`);\n\nexpectNotAssignable<Hex>(`1x${embeddedString}`);\n\nexpectNotAssignable<Hex>(0);\n\nexpectNotAssignable<Hex>('0');\n\nexpectNotAssignable<Hex>('🙃');\n"]}
@@ -1 +0,0 @@
1
- export {};
@@ -1,62 +0,0 @@
1
- "use strict";
2
- /* eslint-disable @typescript-eslint/consistent-type-definitions */
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const tsd_1 = require("tsd");
5
- // Valid Json:
6
- (0, tsd_1.expectAssignable)(null);
7
- (0, tsd_1.expectAssignable)(false);
8
- (0, tsd_1.expectAssignable)('');
9
- (0, tsd_1.expectAssignable)(0);
10
- (0, tsd_1.expectAssignable)([]);
11
- (0, tsd_1.expectAssignable)({});
12
- (0, tsd_1.expectAssignable)([0]);
13
- (0, tsd_1.expectAssignable)({ a: 0 });
14
- (0, tsd_1.expectAssignable)({ deeply: [{ nested: 1 }, 'mixed', 'types', 0] });
15
- (0, tsd_1.expectAssignable)(['array', { nested: { mixed: true, types: null } }, 0]);
16
- const jsonCompatibleType = { c: 0 };
17
- (0, tsd_1.expectAssignable)(jsonCompatibleType);
18
- // Invalid Json:
19
- (0, tsd_1.expectNotAssignable)(undefined);
20
- (0, tsd_1.expectNotAssignable)(new Date());
21
- (0, tsd_1.expectNotAssignable)(() => 0);
22
- (0, tsd_1.expectNotAssignable)(new Set());
23
- (0, tsd_1.expectNotAssignable)(new Map());
24
- (0, tsd_1.expectNotAssignable)(Symbol('test'));
25
- (0, tsd_1.expectNotAssignable)({ a: new Date() });
26
- (0, tsd_1.expectNotAssignable)(5);
27
- const interfaceWithOptionalProperty = { a: 0 };
28
- (0, tsd_1.expectNotAssignable)(interfaceWithOptionalProperty);
29
- const interfaceWithDate = { a: new Date() };
30
- (0, tsd_1.expectNotAssignable)(interfaceWithDate);
31
- const interfaceWithOptionalDate = { a: new Date() };
32
- (0, tsd_1.expectNotAssignable)(interfaceWithOptionalDate);
33
- const interfaceWithUndefinedTypeUnion = {
34
- a: 0,
35
- };
36
- (0, tsd_1.expectNotAssignable)(interfaceWithUndefinedTypeUnion);
37
- const interfaceWithFunction = { a: () => 0 };
38
- (0, tsd_1.expectNotAssignable)(interfaceWithFunction);
39
- const typeWithDate = { a: new Date() };
40
- (0, tsd_1.expectNotAssignable)(typeWithDate);
41
- const typeWithOptionalDate = { a: new Date() };
42
- (0, tsd_1.expectNotAssignable)(typeWithOptionalDate);
43
- const typeWithUndefinedTypeUnion = {
44
- a: 0,
45
- };
46
- (0, tsd_1.expectNotAssignable)(typeWithUndefinedTypeUnion);
47
- const typeWithFunction = { a: () => 0 };
48
- (0, tsd_1.expectNotAssignable)(typeWithFunction);
49
- const typeWithOptionalProperty = { a: undefined };
50
- (0, tsd_1.expectNotAssignable)(typeWithOptionalProperty);
51
- // Edge cases:
52
- // The Json type doesn't protect against the `any` type.
53
- (0, tsd_1.expectAssignable)(null);
54
- const a = { a: 0 };
55
- (0, tsd_1.expectNotAssignable)(a);
56
- // The Json type gets confused by classes. This class instance is valid Json,
57
- // but it's incompatible with the Json type.
58
- class Foo {
59
- }
60
- const foo = new Foo();
61
- (0, tsd_1.expectNotAssignable)(foo);
62
- //# sourceMappingURL=json.test-d.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"json.test-d.js","sourceRoot":"","sources":["../src/json.test-d.ts"],"names":[],"mappings":";AAAA,mEAAmE;;AAEnE,6BAA4D;AAI5D,cAAc;AAEd,IAAA,sBAAgB,EAAO,IAAI,CAAC,CAAC;AAE7B,IAAA,sBAAgB,EAAO,KAAK,CAAC,CAAC;AAE9B,IAAA,sBAAgB,EAAO,EAAE,CAAC,CAAC;AAE3B,IAAA,sBAAgB,EAAO,CAAC,CAAC,CAAC;AAE1B,IAAA,sBAAgB,EAAO,EAAE,CAAC,CAAC;AAE3B,IAAA,sBAAgB,EAAO,EAAE,CAAC,CAAC;AAE3B,IAAA,sBAAgB,EAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5B,IAA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AG,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/consistent-type-definitions */\n\nimport { expectAssignable, expectNotAssignable } from 'tsd';\n\nimport type { Json } from '.';\n\n// Valid Json:\n\nexpectAssignable<Json>(null);\n\nexpectAssignable<Json>(false);\n\nexpectAssignable<Json>('');\n\nexpectAssignable<Json>(0);\n\nexpectAssignable<Json>([]);\n\nexpectAssignable<Json>({});\n\nexpectAssignable<Json>([0]);\n\nexpectAssignable<Json>({ a: 0 });\n\nexpectAssignable<Json>({ deeply: [{ nested: 1 }, 'mixed', 'types', 0] });\n\nexpectAssignable<Json>(['array', { nested: { mixed: true, types: null } }, 0]);\n\ntype JsonCompatibleType = {\n c: number;\n};\nconst jsonCompatibleType: JsonCompatibleType = { c: 0 };\nexpectAssignable<Json>(jsonCompatibleType);\n\n// Invalid Json:\n\nexpectNotAssignable<Json>(undefined);\n\nexpectNotAssignable<Json>(new Date());\n\nexpectNotAssignable<Json>(() => 0);\n\nexpectNotAssignable<Json>(new Set());\n\nexpectNotAssignable<Json>(new Map());\n\nexpectNotAssignable<Json>(Symbol('test'));\n\nexpectNotAssignable<Json>({ a: new Date() });\n\nexpectNotAssignable<Json>(5 as number | undefined);\n\ninterface InterfaceWithOptionalProperty {\n a?: number;\n}\nconst interfaceWithOptionalProperty: InterfaceWithOptionalProperty = { a: 0 };\nexpectNotAssignable<Json>(interfaceWithOptionalProperty);\n\ninterface InterfaceWithDate {\n a: Date;\n}\nconst interfaceWithDate: InterfaceWithDate = { a: new Date() };\nexpectNotAssignable<Json>(interfaceWithDate);\n\ninterface InterfaceWithOptionalDate {\n a?: Date;\n}\nconst interfaceWithOptionalDate: InterfaceWithOptionalDate = { a: new Date() };\nexpectNotAssignable<Json>(interfaceWithOptionalDate);\n\ninterface InterfaceWithUndefinedTypeUnion {\n a: number | undefined;\n}\nconst interfaceWithUndefinedTypeUnion: InterfaceWithUndefinedTypeUnion = {\n a: 0,\n};\nexpectNotAssignable<Json>(interfaceWithUndefinedTypeUnion);\n\ninterface InterfaceWithFunction {\n a: () => number;\n}\nconst interfaceWithFunction: InterfaceWithFunction = { a: () => 0 };\nexpectNotAssignable<Json>(interfaceWithFunction);\n\ntype TypeWithDate = {\n a: Date;\n};\nconst typeWithDate: TypeWithDate = { a: new Date() };\nexpectNotAssignable<Json>(typeWithDate);\n\ntype TypeWithOptionalDate = {\n a?: Date;\n};\nconst typeWithOptionalDate: TypeWithOptionalDate = { a: new Date() };\nexpectNotAssignable<Json>(typeWithOptionalDate);\n\ntype TypeWithUndefinedTypeUnion = {\n a: number | undefined;\n};\nconst typeWithUndefinedTypeUnion: TypeWithUndefinedTypeUnion = {\n a: 0,\n};\nexpectNotAssignable<Json>(typeWithUndefinedTypeUnion);\n\ntype TypeWithFunction = {\n a: () => number;\n};\nconst typeWithFunction: TypeWithFunction = { a: () => 0 };\nexpectNotAssignable<Json>(typeWithFunction);\n\ntype TypeWithOptionalProperty = {\n a?: number | undefined;\n};\nconst typeWithOptionalProperty: TypeWithOptionalProperty = { a: undefined };\nexpectNotAssignable<Json>(typeWithOptionalProperty);\n\n// Edge cases:\n\n// The Json type doesn't protect against the `any` type.\nexpectAssignable<Json>(null as any);\n\n// The Json type gets confused by interfaces. This interface is valid Json,\n// but it's incompatible with the Json type.\ninterface A {\n a: number;\n}\nconst a: A = { a: 0 };\nexpectNotAssignable<Json>(a);\n\n// The Json type gets confused by classes. This class instance is valid Json,\n// but it's incompatible with the Json type.\nclass Foo {\n a!: number;\n}\nconst foo = new Foo();\nexpectNotAssignable<Json>(foo);\n"]}