@metamask-previews/keyring-utils 1.3.0-9c70d70 → 2.0.0-b0257dd
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 +16 -1
- package/dist/keyring.cjs +3 -0
- package/dist/keyring.cjs.map +1 -0
- package/dist/keyring.d.cts +235 -0
- package/dist/keyring.d.cts.map +1 -0
- package/dist/keyring.d.mts +235 -0
- package/dist/keyring.d.mts.map +1 -0
- package/dist/keyring.mjs +2 -0
- package/dist/keyring.mjs.map +1 -0
- package/dist/superstruct.cjs +0 -26
- package/dist/superstruct.cjs.map +1 -1
- package/dist/superstruct.d.cts +0 -23
- package/dist/superstruct.d.cts.map +1 -1
- package/dist/superstruct.d.mts +0 -23
- package/dist/superstruct.d.mts.map +1 -1
- package/dist/superstruct.mjs +1 -26
- package/dist/superstruct.mjs.map +1 -1
- package/dist/types.cjs +3 -3
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +1 -1
- package/dist/types.mjs.map +1 -1
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [2.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Remove `definePattern` ([#173](https://github.com/MetaMask/accounts/pull/173))
|
|
15
|
+
- Has been moved to `@metamask/utils@11.1.0`.
|
|
16
|
+
|
|
17
|
+
## [1.3.1]
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Bump `@metamask/utils` from `^11.0.1` to `^11.1.0` ([#167](https://github.com/MetaMask/accounts/pull/167))
|
|
22
|
+
|
|
10
23
|
## [1.3.0]
|
|
11
24
|
|
|
12
25
|
### Added
|
|
@@ -38,7 +51,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
38
51
|
- This new version fixes a bug with CJS re-exports.
|
|
39
52
|
- Initial release ([#24](https://github.com/MetaMask/accounts/pull/24))
|
|
40
53
|
|
|
41
|
-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@
|
|
54
|
+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@2.0.0...HEAD
|
|
55
|
+
[2.0.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@1.3.1...@metamask/keyring-utils@2.0.0
|
|
56
|
+
[1.3.1]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@1.3.0...@metamask/keyring-utils@1.3.1
|
|
42
57
|
[1.3.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@1.2.0...@metamask/keyring-utils@1.3.0
|
|
43
58
|
[1.2.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@1.1.0...@metamask/keyring-utils@1.2.0
|
|
44
59
|
[1.1.0]: https://github.com/MetaMask/accounts/compare/@metamask/keyring-utils@1.0.0...@metamask/keyring-utils@1.1.0
|
package/dist/keyring.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.cjs","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedTransaction, TxData } from '@ethereumjs/tx';\nimport type { Eip1024EncryptedData, Hex, Json } from '@metamask/utils';\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 = {\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;\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 = {\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<Json>;\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: Json): 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 an EIP-7702 authorization. This is a signing method for authorizing a\n * specific contract on a specific chain.\n *\n * @param address - The address of the account to use for signing.\n * @param authorization - An array containing the chain ID, contract address,\n * and nonce.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed authorization as a hex string.\n */\n signEip7702Authorization?(\n address: Hex,\n authorization: [chainId: number, contractAddress: Hex, nonce: number],\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC\n * method, which is exposed by MetaMask as the method `personal_sign`. See\n * the Ethereum JSON-RPC API documentation for more details.\n *\n * For more information about this method and why we call it `personal_sign`,\n * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signPersonalMessage?(\n address: Hex,\n message: Hex,\n options?: { version?: string } & Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum\n * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}\n * for more details.\n *\n * The \"version\" option dictates which version of `eth_signTypedData` is\n * used. The latest version reflects the specification most closely, whereas\n * earlier versions reflect earlier drafts of the specification that are\n * still supported for backwards-compatibility reasons. For more information\n * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept additional options as well. See the documentation for\n * the specific keyring for more information about what these options are.\n * For some keyrings, the options parameter can even change which key is used\n * for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param typedData - The data to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signTypedData?(\n address: Hex,\n typedData: Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get a public key to use for encryption. This is equivalent to the\n * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}\n * for more information.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used (e.g. encrypting with app keys).\n *\n * @param account - The address of the account you want the encryption key for.\n * @param options - Options; differs between keyrings.\n */\n getEncryptionPublicKey?(\n account: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`\n * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}\n * for more information.\n *\n * @param account - The address of the account you want to use to decrypt\n * the message.\n * @param encryptedData - The encrypted data that you want to decrypt.\n * @returns The decrypted data.\n */\n decryptMessage?(\n account: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string>;\n\n /**\n * Generates the properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @returns A promise resolving when the keyring has generated the properties.\n */\n generateRandomMnemonic?(): Promise<void>;\n\n /**\n * Destroy the keyring.\n */\n destroy?(): Promise<void>;\n};\n"]}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { TypedTransaction, TxData } from "@ethereumjs/tx";
|
|
2
|
+
import type { Eip1024EncryptedData, Hex, Json } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A Keyring class.
|
|
5
|
+
*
|
|
6
|
+
* This type is used to validate the constructor signature and the `type`
|
|
7
|
+
* static property on Keyring classes. See the {@link Keyring} type for more
|
|
8
|
+
* information.
|
|
9
|
+
*/
|
|
10
|
+
export type KeyringClass = {
|
|
11
|
+
/**
|
|
12
|
+
* The Keyring constructor. Takes a single parameter, an "options" object.
|
|
13
|
+
* See the documentation for the specific keyring for more information about
|
|
14
|
+
* what these options are.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The constructor options. Differs between keyring
|
|
17
|
+
* implementations.
|
|
18
|
+
*/
|
|
19
|
+
new (options?: Record<string, unknown>): Keyring;
|
|
20
|
+
/**
|
|
21
|
+
* The name of this type of keyring. This must uniquely identify the
|
|
22
|
+
* keyring type.
|
|
23
|
+
*/
|
|
24
|
+
type: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A keyring is something that can sign messages. Keyrings are used to add new
|
|
28
|
+
* signing strategies; each strategy is a new keyring.
|
|
29
|
+
*
|
|
30
|
+
* Each keyring manages a collection of key pairs, which we call "accounts".
|
|
31
|
+
* Each account is referred to by its "address", which is a unique identifier
|
|
32
|
+
* derived from the public key. The address is always a "0x"-prefixed
|
|
33
|
+
* hexidecimal string.
|
|
34
|
+
*
|
|
35
|
+
* The keyring might store the private key for each account as well, but it's
|
|
36
|
+
* not guaranteed. Some keyrings delegate signing, so they don't need the
|
|
37
|
+
* private key directly. The keyring (and in particular the keyring state)
|
|
38
|
+
* should be treated with care though, just in case it does contain sensitive
|
|
39
|
+
* material such as a private key.
|
|
40
|
+
*/
|
|
41
|
+
export type Keyring = {
|
|
42
|
+
/**
|
|
43
|
+
* The name of this type of keyring. This must match the `type` property of
|
|
44
|
+
* the keyring class.
|
|
45
|
+
*/
|
|
46
|
+
type: string;
|
|
47
|
+
/**
|
|
48
|
+
* Get the addresses for all accounts in this keyring.
|
|
49
|
+
*
|
|
50
|
+
* @returns A list of the account addresses for this keyring
|
|
51
|
+
*/
|
|
52
|
+
getAccounts(): Promise<Hex[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Add an account to the keyring.
|
|
55
|
+
*
|
|
56
|
+
* @param number - The number of accounts to add. Usually defaults to 1.
|
|
57
|
+
* @returns A list of the newly added account addresses.
|
|
58
|
+
*/
|
|
59
|
+
addAccounts(number: number): Promise<Hex[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Serialize the keyring state as a JSON-serializable object.
|
|
62
|
+
*
|
|
63
|
+
* @returns A JSON-serializable representation of the keyring state.
|
|
64
|
+
*/
|
|
65
|
+
serialize(): Promise<Json>;
|
|
66
|
+
/**
|
|
67
|
+
* Deserialize the given keyring state, overwriting any existing state with
|
|
68
|
+
* the serialized state provided.
|
|
69
|
+
*
|
|
70
|
+
* @param state - A JSON-serializable representation of the keyring state.
|
|
71
|
+
*/
|
|
72
|
+
deserialize(state: Json): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Method to include asynchronous configuration.
|
|
75
|
+
*/
|
|
76
|
+
init?(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Remove an account from the keyring.
|
|
79
|
+
*
|
|
80
|
+
* @param address - The address of the account to remove.
|
|
81
|
+
*/
|
|
82
|
+
removeAccount?(address: Hex): void;
|
|
83
|
+
/**
|
|
84
|
+
* Export the private key for one of the keyring accounts.
|
|
85
|
+
*
|
|
86
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
87
|
+
* for the specific keyring for more information about what these options
|
|
88
|
+
* are. For some keyrings, the options parameter is used to allow exporting a
|
|
89
|
+
* private key that is derived from the given account, rather than exporting
|
|
90
|
+
* that account's private key directly.
|
|
91
|
+
*
|
|
92
|
+
* @param address - The address of the account to export.
|
|
93
|
+
* @param options - Export options; differs between keyrings.
|
|
94
|
+
* @returns The non-prefixed, hex-encoded private key that was requested.
|
|
95
|
+
*/
|
|
96
|
+
exportAccount?(address: Hex, options?: Record<string, unknown>): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Get the "app key" address for the given account and origin. An app key is
|
|
99
|
+
* an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}
|
|
100
|
+
* for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}
|
|
101
|
+
* is used as the unique identifier for the application, and it's used as
|
|
102
|
+
* part of the key derivation process.
|
|
103
|
+
*
|
|
104
|
+
* @param address - The address of the account the app key is derived from.
|
|
105
|
+
* @param origin - The origin of the application.
|
|
106
|
+
* @returns The address of the app key for the given account and origin.
|
|
107
|
+
*/
|
|
108
|
+
getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;
|
|
109
|
+
/**
|
|
110
|
+
* Sign a transaction. This is equivalent to the `eth_signTransaction`
|
|
111
|
+
* Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for
|
|
112
|
+
* more details.
|
|
113
|
+
*
|
|
114
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
115
|
+
* for the specific keyring for more information about what these options
|
|
116
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
117
|
+
* used for signing (e.g. signing with app keys).
|
|
118
|
+
*
|
|
119
|
+
* @param address - The address of the account to use for signing.
|
|
120
|
+
* @param transaction - The transaction to sign.
|
|
121
|
+
* @param options - Signing options; differs between keyrings.
|
|
122
|
+
* @returns The signed transaction.
|
|
123
|
+
*/
|
|
124
|
+
signTransaction?(address: Hex, transaction: TypedTransaction, options?: Record<string, unknown>): Promise<TxData>;
|
|
125
|
+
/**
|
|
126
|
+
* Sign a message. This is equivalent to an older version of the the
|
|
127
|
+
* `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,
|
|
128
|
+
* using the curve secp256k1 the Keccak-256 hash function.
|
|
129
|
+
*
|
|
130
|
+
* For more information about this method and why we still support it, see
|
|
131
|
+
* the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
132
|
+
*
|
|
133
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
134
|
+
* for the specific keyring for more information about what these options
|
|
135
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
136
|
+
* used for signing (e.g. signing with app keys).
|
|
137
|
+
*
|
|
138
|
+
* @param address - The address of the account to use for signing.
|
|
139
|
+
* @param message - The message to sign.
|
|
140
|
+
* @param options - Signing options; differs between keyrings.
|
|
141
|
+
* @returns The signed message.
|
|
142
|
+
*/
|
|
143
|
+
signMessage?(address: Hex, message: string, options?: Record<string, unknown>): Promise<string>;
|
|
144
|
+
/**
|
|
145
|
+
* Sign an EIP-7702 authorization. This is a signing method for authorizing a
|
|
146
|
+
* specific contract on a specific chain.
|
|
147
|
+
*
|
|
148
|
+
* @param address - The address of the account to use for signing.
|
|
149
|
+
* @param authorization - An array containing the chain ID, contract address,
|
|
150
|
+
* and nonce.
|
|
151
|
+
* @param options - Signing options; differs between keyrings.
|
|
152
|
+
* @returns The signed authorization as a hex string.
|
|
153
|
+
*/
|
|
154
|
+
signEip7702Authorization?(address: Hex, authorization: [chainId: number, contractAddress: Hex, nonce: number], options?: Record<string, unknown>): Promise<string>;
|
|
155
|
+
/**
|
|
156
|
+
* Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC
|
|
157
|
+
* method, which is exposed by MetaMask as the method `personal_sign`. See
|
|
158
|
+
* the Ethereum JSON-RPC API documentation for more details.
|
|
159
|
+
*
|
|
160
|
+
* For more information about this method and why we call it `personal_sign`,
|
|
161
|
+
* see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
162
|
+
*
|
|
163
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
164
|
+
* for the specific keyring for more information about what these options
|
|
165
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
166
|
+
* used for signing (e.g. signing with app keys).
|
|
167
|
+
*
|
|
168
|
+
* @param address - The address of the account to use for signing.
|
|
169
|
+
* @param message - The message to sign.
|
|
170
|
+
* @param options - Signing options; differs between keyrings.
|
|
171
|
+
* @returns The signed message.
|
|
172
|
+
*/
|
|
173
|
+
signPersonalMessage?(address: Hex, message: Hex, options?: {
|
|
174
|
+
version?: string;
|
|
175
|
+
} & Record<string, unknown>): Promise<string>;
|
|
176
|
+
/**
|
|
177
|
+
* Sign a message. This is equivalent to the `eth_signTypedData` Ethereum
|
|
178
|
+
* JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}
|
|
179
|
+
* for more details.
|
|
180
|
+
*
|
|
181
|
+
* The "version" option dictates which version of `eth_signTypedData` is
|
|
182
|
+
* used. The latest version reflects the specification most closely, whereas
|
|
183
|
+
* earlier versions reflect earlier drafts of the specification that are
|
|
184
|
+
* still supported for backwards-compatibility reasons. For more information
|
|
185
|
+
* about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
186
|
+
*
|
|
187
|
+
* Some keyrings accept additional options as well. See the documentation for
|
|
188
|
+
* the specific keyring for more information about what these options are.
|
|
189
|
+
* For some keyrings, the options parameter can even change which key is used
|
|
190
|
+
* for signing (e.g. signing with app keys).
|
|
191
|
+
*
|
|
192
|
+
* @param address - The address of the account to use for signing.
|
|
193
|
+
* @param typedData - The data to sign.
|
|
194
|
+
* @param options - Signing options; differs between keyrings.
|
|
195
|
+
* @returns The signed message.
|
|
196
|
+
*/
|
|
197
|
+
signTypedData?(address: Hex, typedData: Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
|
|
198
|
+
/**
|
|
199
|
+
* Get a public key to use for encryption. This is equivalent to the
|
|
200
|
+
* ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}
|
|
201
|
+
* for more information.
|
|
202
|
+
*
|
|
203
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
204
|
+
* for the specific keyring for more information about what these options
|
|
205
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
206
|
+
* used (e.g. encrypting with app keys).
|
|
207
|
+
*
|
|
208
|
+
* @param account - The address of the account you want the encryption key for.
|
|
209
|
+
* @param options - Options; differs between keyrings.
|
|
210
|
+
*/
|
|
211
|
+
getEncryptionPublicKey?(account: Hex, options?: Record<string, unknown>): Promise<string>;
|
|
212
|
+
/**
|
|
213
|
+
* Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`
|
|
214
|
+
* JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}
|
|
215
|
+
* for more information.
|
|
216
|
+
*
|
|
217
|
+
* @param account - The address of the account you want to use to decrypt
|
|
218
|
+
* the message.
|
|
219
|
+
* @param encryptedData - The encrypted data that you want to decrypt.
|
|
220
|
+
* @returns The decrypted data.
|
|
221
|
+
*/
|
|
222
|
+
decryptMessage?(account: Hex, encryptedData: Eip1024EncryptedData): Promise<string>;
|
|
223
|
+
/**
|
|
224
|
+
* Generates the properties for the keyring based on the given
|
|
225
|
+
* BIP39-compliant mnemonic.
|
|
226
|
+
*
|
|
227
|
+
* @returns A promise resolving when the keyring has generated the properties.
|
|
228
|
+
*/
|
|
229
|
+
generateRandomMnemonic?(): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Destroy the keyring.
|
|
232
|
+
*/
|
|
233
|
+
destroy?(): Promise<void>;
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=keyring.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.d.cts","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,uBAAuB;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;;;OAOG;IACH,KAAK,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAEjD;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE9B;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE5C;;;;OAIG;IACH,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE3B;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,IAAI,GA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E;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvD,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa,CAAC,CACZ,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;;;;OAYG;IACH,sBAAsB,CAAC,CACrB,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;OASG;IACH,cAAc,CAAC,CACb,OAAO,EAAE,GAAG,EACZ,aAAa,EAAE,oBAAoB,GAClC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,sBAAsB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;OAEG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B,CAAC"}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type { TypedTransaction, TxData } from "@ethereumjs/tx";
|
|
2
|
+
import type { Eip1024EncryptedData, Hex, Json } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A Keyring class.
|
|
5
|
+
*
|
|
6
|
+
* This type is used to validate the constructor signature and the `type`
|
|
7
|
+
* static property on Keyring classes. See the {@link Keyring} type for more
|
|
8
|
+
* information.
|
|
9
|
+
*/
|
|
10
|
+
export type KeyringClass = {
|
|
11
|
+
/**
|
|
12
|
+
* The Keyring constructor. Takes a single parameter, an "options" object.
|
|
13
|
+
* See the documentation for the specific keyring for more information about
|
|
14
|
+
* what these options are.
|
|
15
|
+
*
|
|
16
|
+
* @param options - The constructor options. Differs between keyring
|
|
17
|
+
* implementations.
|
|
18
|
+
*/
|
|
19
|
+
new (options?: Record<string, unknown>): Keyring;
|
|
20
|
+
/**
|
|
21
|
+
* The name of this type of keyring. This must uniquely identify the
|
|
22
|
+
* keyring type.
|
|
23
|
+
*/
|
|
24
|
+
type: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* A keyring is something that can sign messages. Keyrings are used to add new
|
|
28
|
+
* signing strategies; each strategy is a new keyring.
|
|
29
|
+
*
|
|
30
|
+
* Each keyring manages a collection of key pairs, which we call "accounts".
|
|
31
|
+
* Each account is referred to by its "address", which is a unique identifier
|
|
32
|
+
* derived from the public key. The address is always a "0x"-prefixed
|
|
33
|
+
* hexidecimal string.
|
|
34
|
+
*
|
|
35
|
+
* The keyring might store the private key for each account as well, but it's
|
|
36
|
+
* not guaranteed. Some keyrings delegate signing, so they don't need the
|
|
37
|
+
* private key directly. The keyring (and in particular the keyring state)
|
|
38
|
+
* should be treated with care though, just in case it does contain sensitive
|
|
39
|
+
* material such as a private key.
|
|
40
|
+
*/
|
|
41
|
+
export type Keyring = {
|
|
42
|
+
/**
|
|
43
|
+
* The name of this type of keyring. This must match the `type` property of
|
|
44
|
+
* the keyring class.
|
|
45
|
+
*/
|
|
46
|
+
type: string;
|
|
47
|
+
/**
|
|
48
|
+
* Get the addresses for all accounts in this keyring.
|
|
49
|
+
*
|
|
50
|
+
* @returns A list of the account addresses for this keyring
|
|
51
|
+
*/
|
|
52
|
+
getAccounts(): Promise<Hex[]>;
|
|
53
|
+
/**
|
|
54
|
+
* Add an account to the keyring.
|
|
55
|
+
*
|
|
56
|
+
* @param number - The number of accounts to add. Usually defaults to 1.
|
|
57
|
+
* @returns A list of the newly added account addresses.
|
|
58
|
+
*/
|
|
59
|
+
addAccounts(number: number): Promise<Hex[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Serialize the keyring state as a JSON-serializable object.
|
|
62
|
+
*
|
|
63
|
+
* @returns A JSON-serializable representation of the keyring state.
|
|
64
|
+
*/
|
|
65
|
+
serialize(): Promise<Json>;
|
|
66
|
+
/**
|
|
67
|
+
* Deserialize the given keyring state, overwriting any existing state with
|
|
68
|
+
* the serialized state provided.
|
|
69
|
+
*
|
|
70
|
+
* @param state - A JSON-serializable representation of the keyring state.
|
|
71
|
+
*/
|
|
72
|
+
deserialize(state: Json): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Method to include asynchronous configuration.
|
|
75
|
+
*/
|
|
76
|
+
init?(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Remove an account from the keyring.
|
|
79
|
+
*
|
|
80
|
+
* @param address - The address of the account to remove.
|
|
81
|
+
*/
|
|
82
|
+
removeAccount?(address: Hex): void;
|
|
83
|
+
/**
|
|
84
|
+
* Export the private key for one of the keyring accounts.
|
|
85
|
+
*
|
|
86
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
87
|
+
* for the specific keyring for more information about what these options
|
|
88
|
+
* are. For some keyrings, the options parameter is used to allow exporting a
|
|
89
|
+
* private key that is derived from the given account, rather than exporting
|
|
90
|
+
* that account's private key directly.
|
|
91
|
+
*
|
|
92
|
+
* @param address - The address of the account to export.
|
|
93
|
+
* @param options - Export options; differs between keyrings.
|
|
94
|
+
* @returns The non-prefixed, hex-encoded private key that was requested.
|
|
95
|
+
*/
|
|
96
|
+
exportAccount?(address: Hex, options?: Record<string, unknown>): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Get the "app key" address for the given account and origin. An app key is
|
|
99
|
+
* an application-specific key pair. See {@link https://eips.ethereum.org/EIPS/eip-1775|EIP-1775}
|
|
100
|
+
* for more information. The {@link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin|origin}
|
|
101
|
+
* is used as the unique identifier for the application, and it's used as
|
|
102
|
+
* part of the key derivation process.
|
|
103
|
+
*
|
|
104
|
+
* @param address - The address of the account the app key is derived from.
|
|
105
|
+
* @param origin - The origin of the application.
|
|
106
|
+
* @returns The address of the app key for the given account and origin.
|
|
107
|
+
*/
|
|
108
|
+
getAppKeyAddress?(address: Hex, origin: string): Promise<Hex>;
|
|
109
|
+
/**
|
|
110
|
+
* Sign a transaction. This is equivalent to the `eth_signTransaction`
|
|
111
|
+
* Ethereum JSON-RPC method. See the Ethereum JSON-RPC API documentation for
|
|
112
|
+
* more details.
|
|
113
|
+
*
|
|
114
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
115
|
+
* for the specific keyring for more information about what these options
|
|
116
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
117
|
+
* used for signing (e.g. signing with app keys).
|
|
118
|
+
*
|
|
119
|
+
* @param address - The address of the account to use for signing.
|
|
120
|
+
* @param transaction - The transaction to sign.
|
|
121
|
+
* @param options - Signing options; differs between keyrings.
|
|
122
|
+
* @returns The signed transaction.
|
|
123
|
+
*/
|
|
124
|
+
signTransaction?(address: Hex, transaction: TypedTransaction, options?: Record<string, unknown>): Promise<TxData>;
|
|
125
|
+
/**
|
|
126
|
+
* Sign a message. This is equivalent to an older version of the the
|
|
127
|
+
* `eth_sign` Ethereum JSON-RPC method. The message is signed using ECDSA,
|
|
128
|
+
* using the curve secp256k1 the Keccak-256 hash function.
|
|
129
|
+
*
|
|
130
|
+
* For more information about this method and why we still support it, see
|
|
131
|
+
* the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
132
|
+
*
|
|
133
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
134
|
+
* for the specific keyring for more information about what these options
|
|
135
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
136
|
+
* used for signing (e.g. signing with app keys).
|
|
137
|
+
*
|
|
138
|
+
* @param address - The address of the account to use for signing.
|
|
139
|
+
* @param message - The message to sign.
|
|
140
|
+
* @param options - Signing options; differs between keyrings.
|
|
141
|
+
* @returns The signed message.
|
|
142
|
+
*/
|
|
143
|
+
signMessage?(address: Hex, message: string, options?: Record<string, unknown>): Promise<string>;
|
|
144
|
+
/**
|
|
145
|
+
* Sign an EIP-7702 authorization. This is a signing method for authorizing a
|
|
146
|
+
* specific contract on a specific chain.
|
|
147
|
+
*
|
|
148
|
+
* @param address - The address of the account to use for signing.
|
|
149
|
+
* @param authorization - An array containing the chain ID, contract address,
|
|
150
|
+
* and nonce.
|
|
151
|
+
* @param options - Signing options; differs between keyrings.
|
|
152
|
+
* @returns The signed authorization as a hex string.
|
|
153
|
+
*/
|
|
154
|
+
signEip7702Authorization?(address: Hex, authorization: [chainId: number, contractAddress: Hex, nonce: number], options?: Record<string, unknown>): Promise<string>;
|
|
155
|
+
/**
|
|
156
|
+
* Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC
|
|
157
|
+
* method, which is exposed by MetaMask as the method `personal_sign`. See
|
|
158
|
+
* the Ethereum JSON-RPC API documentation for more details.
|
|
159
|
+
*
|
|
160
|
+
* For more information about this method and why we call it `personal_sign`,
|
|
161
|
+
* see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
162
|
+
*
|
|
163
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
164
|
+
* for the specific keyring for more information about what these options
|
|
165
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
166
|
+
* used for signing (e.g. signing with app keys).
|
|
167
|
+
*
|
|
168
|
+
* @param address - The address of the account to use for signing.
|
|
169
|
+
* @param message - The message to sign.
|
|
170
|
+
* @param options - Signing options; differs between keyrings.
|
|
171
|
+
* @returns The signed message.
|
|
172
|
+
*/
|
|
173
|
+
signPersonalMessage?(address: Hex, message: Hex, options?: {
|
|
174
|
+
version?: string;
|
|
175
|
+
} & Record<string, unknown>): Promise<string>;
|
|
176
|
+
/**
|
|
177
|
+
* Sign a message. This is equivalent to the `eth_signTypedData` Ethereum
|
|
178
|
+
* JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}
|
|
179
|
+
* for more details.
|
|
180
|
+
*
|
|
181
|
+
* The "version" option dictates which version of `eth_signTypedData` is
|
|
182
|
+
* used. The latest version reflects the specification most closely, whereas
|
|
183
|
+
* earlier versions reflect earlier drafts of the specification that are
|
|
184
|
+
* still supported for backwards-compatibility reasons. For more information
|
|
185
|
+
* about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.
|
|
186
|
+
*
|
|
187
|
+
* Some keyrings accept additional options as well. See the documentation for
|
|
188
|
+
* the specific keyring for more information about what these options are.
|
|
189
|
+
* For some keyrings, the options parameter can even change which key is used
|
|
190
|
+
* for signing (e.g. signing with app keys).
|
|
191
|
+
*
|
|
192
|
+
* @param address - The address of the account to use for signing.
|
|
193
|
+
* @param typedData - The data to sign.
|
|
194
|
+
* @param options - Signing options; differs between keyrings.
|
|
195
|
+
* @returns The signed message.
|
|
196
|
+
*/
|
|
197
|
+
signTypedData?(address: Hex, typedData: Record<string, unknown>, options?: Record<string, unknown>): Promise<string>;
|
|
198
|
+
/**
|
|
199
|
+
* Get a public key to use for encryption. This is equivalent to the
|
|
200
|
+
* ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}
|
|
201
|
+
* for more information.
|
|
202
|
+
*
|
|
203
|
+
* Some keyrings accept an "options" parameter as well. See the documentation
|
|
204
|
+
* for the specific keyring for more information about what these options
|
|
205
|
+
* are. For some keyrings, the options parameter can even change which key is
|
|
206
|
+
* used (e.g. encrypting with app keys).
|
|
207
|
+
*
|
|
208
|
+
* @param account - The address of the account you want the encryption key for.
|
|
209
|
+
* @param options - Options; differs between keyrings.
|
|
210
|
+
*/
|
|
211
|
+
getEncryptionPublicKey?(account: Hex, options?: Record<string, unknown>): Promise<string>;
|
|
212
|
+
/**
|
|
213
|
+
* Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`
|
|
214
|
+
* JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}
|
|
215
|
+
* for more information.
|
|
216
|
+
*
|
|
217
|
+
* @param account - The address of the account you want to use to decrypt
|
|
218
|
+
* the message.
|
|
219
|
+
* @param encryptedData - The encrypted data that you want to decrypt.
|
|
220
|
+
* @returns The decrypted data.
|
|
221
|
+
*/
|
|
222
|
+
decryptMessage?(account: Hex, encryptedData: Eip1024EncryptedData): Promise<string>;
|
|
223
|
+
/**
|
|
224
|
+
* Generates the properties for the keyring based on the given
|
|
225
|
+
* BIP39-compliant mnemonic.
|
|
226
|
+
*
|
|
227
|
+
* @returns A promise resolving when the keyring has generated the properties.
|
|
228
|
+
*/
|
|
229
|
+
generateRandomMnemonic?(): Promise<void>;
|
|
230
|
+
/**
|
|
231
|
+
* Destroy the keyring.
|
|
232
|
+
*/
|
|
233
|
+
destroy?(): Promise<void>;
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=keyring.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.d.mts","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,EAAE,uBAAuB;AAC/D,OAAO,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAEvE;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;;;OAOG;IACH,KAAK,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;IAEjD;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;;;OAIG;IACH,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAE9B;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OA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OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;;;;OAiBG;IACH,mBAAmB,CAAC,CAClB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACvD,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa,CAAC,CACZ,OAAO,EAAE,GAAG,EACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;;;;OAYG;IACH,sBAAsB,CAAC,CACrB,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;;;;;OASG;IACH,cAAc,CAAC,CACb,OAAO,EAAE,GAAG,EACZ,aAAa,EAAE,oBAAoB,GAClC,OAAO,CAAC,MAAM,CAAC,CAAC;IAEnB;;;;;OAKG;IACH,sBAAsB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzC;;OAEG;IACH,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B,CAAC"}
|
package/dist/keyring.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyring.mjs","sourceRoot":"","sources":["../src/keyring.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedTransaction, TxData } from '@ethereumjs/tx';\nimport type { Eip1024EncryptedData, Hex, Json } from '@metamask/utils';\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 = {\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;\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 = {\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<Json>;\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: Json): 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 an EIP-7702 authorization. This is a signing method for authorizing a\n * specific contract on a specific chain.\n *\n * @param address - The address of the account to use for signing.\n * @param authorization - An array containing the chain ID, contract address,\n * and nonce.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed authorization as a hex string.\n */\n signEip7702Authorization?(\n address: Hex,\n authorization: [chainId: number, contractAddress: Hex, nonce: number],\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_sign` Ethereum JSON-RPC\n * method, which is exposed by MetaMask as the method `personal_sign`. See\n * the Ethereum JSON-RPC API documentation for more details.\n *\n * For more information about this method and why we call it `personal_sign`,\n * see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param message - The message to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signPersonalMessage?(\n address: Hex,\n message: Hex,\n options?: { version?: string } & Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Sign a message. This is equivalent to the `eth_signTypedData` Ethereum\n * JSON-RPC method. See {@link https://github.com/ethereum/EIPs/blob/master/EIPS/eip-712.md|EIP-712}\n * for more details.\n *\n * The \"version\" option dictates which version of `eth_signTypedData` is\n * used. The latest version reflects the specification most closely, whereas\n * earlier versions reflect earlier drafts of the specification that are\n * still supported for backwards-compatibility reasons. For more information\n * about why we support multiple versions, see the {@link https://docs.metamask.io/guide/signing-data.html|MetaMask Docs}.\n *\n * Some keyrings accept additional options as well. See the documentation for\n * the specific keyring for more information about what these options are.\n * For some keyrings, the options parameter can even change which key is used\n * for signing (e.g. signing with app keys).\n *\n * @param address - The address of the account to use for signing.\n * @param typedData - The data to sign.\n * @param options - Signing options; differs between keyrings.\n * @returns The signed message.\n */\n signTypedData?(\n address: Hex,\n typedData: Record<string, unknown>,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Get a public key to use for encryption. This is equivalent to the\n * ` eth_getEncryptionPublicKey` JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-getencryptionpublickey|MetaMask Docs}\n * for more information.\n *\n * Some keyrings accept an \"options\" parameter as well. See the documentation\n * for the specific keyring for more information about what these options\n * are. For some keyrings, the options parameter can even change which key is\n * used (e.g. encrypting with app keys).\n *\n * @param account - The address of the account you want the encryption key for.\n * @param options - Options; differs between keyrings.\n */\n getEncryptionPublicKey?(\n account: Hex,\n options?: Record<string, unknown>,\n ): Promise<string>;\n\n /**\n * Decrypt an encrypted message. This is equivalent to the ` eth_decrypt`\n * JSON-RPC method. See the {@link https://docs.metamask.io/guide/rpc-api.html#eth-decrypt|MetaMask Docs}\n * for more information.\n *\n * @param account - The address of the account you want to use to decrypt\n * the message.\n * @param encryptedData - The encrypted data that you want to decrypt.\n * @returns The decrypted data.\n */\n decryptMessage?(\n account: Hex,\n encryptedData: Eip1024EncryptedData,\n ): Promise<string>;\n\n /**\n * Generates the properties for the keyring based on the given\n * BIP39-compliant mnemonic.\n *\n * @returns A promise resolving when the keyring has generated the properties.\n */\n generateRandomMnemonic?(): Promise<void>;\n\n /**\n * Destroy the keyring.\n */\n destroy?(): Promise<void>;\n};\n"]}
|
package/dist/superstruct.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.object = object;
|
|
4
4
|
exports.exactOptional = exactOptional;
|
|
5
|
-
exports.definePattern = definePattern;
|
|
6
5
|
exports.strictMask = strictMask;
|
|
7
6
|
exports.selectiveUnion = selectiveUnion;
|
|
8
7
|
const superstruct_1 = require("@metamask/superstruct");
|
|
@@ -47,31 +46,6 @@ function exactOptional(struct) {
|
|
|
47
46
|
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
|
48
47
|
});
|
|
49
48
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Defines a new string-struct matching a regular expression.
|
|
52
|
-
*
|
|
53
|
-
* Example:
|
|
54
|
-
*
|
|
55
|
-
* ```ts
|
|
56
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
57
|
-
* type EthAddress = Infer<typeof EthAddressStruct>; // string
|
|
58
|
-
*
|
|
59
|
-
* const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
|
|
60
|
-
* 'CaipChainId',
|
|
61
|
-
* /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
|
|
62
|
-
* );
|
|
63
|
-
* type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
|
|
64
|
-
*
|
|
65
|
-
* ```
|
|
66
|
-
*
|
|
67
|
-
* @param name - Type name.
|
|
68
|
-
* @param pattern - Regular expression to match.
|
|
69
|
-
* @template Pattern - The pattern type, defaults to `string`.
|
|
70
|
-
* @returns A new string-struct that matches the given pattern.
|
|
71
|
-
*/
|
|
72
|
-
function definePattern(name, pattern) {
|
|
73
|
-
return (0, superstruct_1.define)(name, (value) => typeof value === 'string' && pattern.test(value));
|
|
74
|
-
}
|
|
75
49
|
/**
|
|
76
50
|
* Assert that a value is valid according to a struct.
|
|
77
51
|
*
|
package/dist/superstruct.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"superstruct.cjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":";;AA+DA,wBAIC;AA4BD,sCAYC;AAaD,gCAOC;AAwBD,wCAyBC;AAhLD,uDAA2E;AAwD3E;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,MAAc;IAEd,OAAO,IAAA,oBAAQ,EAAC,MAAM,CAAQ,CAAC;AACjC,CA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AAE,OAAO;YACrB,KAAK,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,OAAO,CAAC,KAAK,EAAE,OAAO;YACpB,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACjD,CAAC;QAED,SAAS,CAAC,KAAK,EAAE,OAAO;YACtB,uEAAuE;YACvE,YAAY;YACZ,OAAO,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Struct, assert, object as stObject } from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n AnyStruct,\n} from '@metamask/superstruct';\n\nimport type { Equals } from './types';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n\n/**\n * Extracts the type from a struct definition and asserts that it matches the\n * expected type. If the types do not match, the type `never` is returned.\n *\n * @param StructType - The struct type to infer.\n * @param ExpectedType - The expected type.\n */\nexport type InferEquals<\n StructType extends Struct<any, any>,\n ExpectedType,\n> = Equals<Infer<StructType>, ExpectedType> extends true\n ? Infer<StructType>\n : never;\n\n/**\n * Create a custom union struct that uses a `selector` function for choosing\n * the validation path.\n *\n * @param selector - The selector function choosing the struct to validate with.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function selectiveUnion<Selector extends (value: any) => AnyStruct>(\n selector: Selector,\n): Struct<Infer<ReturnType<Selector>>, null> {\n return new Struct({\n type: 'union',\n schema: null,\n\n *entries(value: any, context: any): ReturnType<Struct['entries']> {\n yield* selector(value).entries(value, context);\n },\n\n *refiner(value, context): ReturnType<Struct['refiner']> {\n yield* selector(value).refiner(value, context);\n },\n\n coercer(value, context): ReturnType<Struct['coercer']> {\n return selector(value).coercer(value, context);\n },\n\n validator(value, context): ReturnType<Struct['validator']> {\n // This only validates the root of the struct, entries does the rest of\n // the work.\n return selector(value).validator(value, context);\n },\n });\n}\n"]}
|
package/dist/superstruct.d.cts
CHANGED
|
@@ -55,29 +55,6 @@ export declare function object<Schema extends ObjectSchema>(schema: Schema): Str
|
|
|
55
55
|
* @returns The augmented struct.
|
|
56
56
|
*/
|
|
57
57
|
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
|
58
|
-
/**
|
|
59
|
-
* Defines a new string-struct matching a regular expression.
|
|
60
|
-
*
|
|
61
|
-
* Example:
|
|
62
|
-
*
|
|
63
|
-
* ```ts
|
|
64
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
65
|
-
* type EthAddress = Infer<typeof EthAddressStruct>; // string
|
|
66
|
-
*
|
|
67
|
-
* const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
|
|
68
|
-
* 'CaipChainId',
|
|
69
|
-
* /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
|
|
70
|
-
* );
|
|
71
|
-
* type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
|
|
72
|
-
*
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* @param name - Type name.
|
|
76
|
-
* @param pattern - Regular expression to match.
|
|
77
|
-
* @template Pattern - The pattern type, defaults to `string`.
|
|
78
|
-
* @returns A new string-struct that matches the given pattern.
|
|
79
|
-
*/
|
|
80
|
-
export declare function definePattern<Pattern extends string = string>(name: string, pattern: RegExp): Struct<Pattern, null>;
|
|
81
58
|
/**
|
|
82
59
|
* Assert that a value is valid according to a struct.
|
|
83
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"superstruct.d.cts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA8B,8BAA8B;AAC3E,OAAO,KAAK,EACV,KAAK,EAEL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,MAAM,EACN,QAAQ,EACR,SAAS,EACV,8BAA8B;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,oBAAgB;AAGtC,OAAO,CAAC,MAAM,mBAAmB,EAAE,OAAO,MAAM,CAAC;AAEjD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,OAAO,mBAAmB,CAAC;CAClC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,CAAC,GAAG,EAAE,IAAI,IAAI;KAClC,CAAC,IAAI,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;CACxC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,IAAI,MAAM,CAC1D,MAAM,EACN,gBAAgB,CACjB,GACC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAE3E;;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ema extends ObjectSchema>(schema: Schema): Str
|
|
|
55
55
|
* @returns The augmented struct.
|
|
56
56
|
*/
|
|
57
57
|
export declare function exactOptional<Type, Schema>(struct: Struct<Type, Schema>): Struct<Type | ExactOptionalTag, Schema>;
|
|
58
|
-
/**
|
|
59
|
-
* Defines a new string-struct matching a regular expression.
|
|
60
|
-
*
|
|
61
|
-
* Example:
|
|
62
|
-
*
|
|
63
|
-
* ```ts
|
|
64
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
65
|
-
* type EthAddress = Infer<typeof EthAddressStruct>; // string
|
|
66
|
-
*
|
|
67
|
-
* const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
|
|
68
|
-
* 'CaipChainId',
|
|
69
|
-
* /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
|
|
70
|
-
* );
|
|
71
|
-
* type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
|
|
72
|
-
*
|
|
73
|
-
* ```
|
|
74
|
-
*
|
|
75
|
-
* @param name - Type name.
|
|
76
|
-
* @param pattern - Regular expression to match.
|
|
77
|
-
* @template Pattern - The pattern type, defaults to `string`.
|
|
78
|
-
* @returns A new string-struct that matches the given pattern.
|
|
79
|
-
*/
|
|
80
|
-
export declare function definePattern<Pattern extends string = string>(name: string, pattern: RegExp): Struct<Pattern, null>;
|
|
81
58
|
/**
|
|
82
59
|
* Assert that a value is valid according to a struct.
|
|
83
60
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"superstruct.d.mts","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAA8B,8BAA8B;AAC3E,OAAO,KAAK,EACV,KAAK,EAEL,YAAY,EACZ,MAAM,EACN,WAAW,EACX,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AE,MAAM,EACrC,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CAGN;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,CACrB,UAAU,SAAS,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EACnC,YAAY,IACV,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,YAAY,CAAC,SAAS,IAAI,GACpD,KAAK,CAAC,UAAU,CAAC,GACjB,KAAK,CAAC;AAEV;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,QAAQ,SAAS,CAAC,KAAK,EAAE,GAAG,KAAK,SAAS,EACvE,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,IAAI,CAAC,CAuB3C"}
|
package/dist/superstruct.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Struct, assert,
|
|
1
|
+
import { Struct, assert, object as stObject } from "@metamask/superstruct";
|
|
2
2
|
/**
|
|
3
3
|
* Change the return type of a superstruct object struct to support exact
|
|
4
4
|
* optional properties.
|
|
@@ -40,31 +40,6 @@ export function exactOptional(struct) {
|
|
|
40
40
|
refiner: (value, ctx) => !hasOptional(ctx) || struct.refiner(value, ctx),
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Defines a new string-struct matching a regular expression.
|
|
45
|
-
*
|
|
46
|
-
* Example:
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* const EthAddressStruct = definePattern('EthAddress', /^0x[0-9a-f]{40}$/iu);
|
|
50
|
-
* type EthAddress = Infer<typeof EthAddressStruct>; // string
|
|
51
|
-
*
|
|
52
|
-
* const CaipChainIdStruct = defineTypedPattern<`${string}:${string}`>(
|
|
53
|
-
* 'CaipChainId',
|
|
54
|
-
* /^[-a-z0-9]{3,8}:[-_a-zA-Z0-9]{1,32}$/u;
|
|
55
|
-
* );
|
|
56
|
-
* type CaipChainId = Infer<typeof CaipChainIdStruct>; // `${string}:${string}`
|
|
57
|
-
*
|
|
58
|
-
* ```
|
|
59
|
-
*
|
|
60
|
-
* @param name - Type name.
|
|
61
|
-
* @param pattern - Regular expression to match.
|
|
62
|
-
* @template Pattern - The pattern type, defaults to `string`.
|
|
63
|
-
* @returns A new string-struct that matches the given pattern.
|
|
64
|
-
*/
|
|
65
|
-
export function definePattern(name, pattern) {
|
|
66
|
-
return define(name, (value) => typeof value === 'string' && pattern.test(value));
|
|
67
|
-
}
|
|
68
43
|
/**
|
|
69
44
|
* Assert that a value is valid according to a struct.
|
|
70
45
|
*
|
package/dist/superstruct.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"superstruct.mjs","sourceRoot":"","sources":["../src/superstruct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,QAAQ,EAAE,8BAA8B;AAwD3E;;;;;;GAMG;AACH,MAAM,UAAU,MAAM,CACpB,MAAc;IAEd,OAAO,QAAQ,CAAC,MAAM,CAAQ,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,GAAY;IAC/B,MAAM,QAAQ,GAAW,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACvD,MAAM,MAAM,GAA4B,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAE1E,OAAO,QAAQ,IAAI,MAAM,CAAC;AAC5B,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA4B;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AAC,KAAK,EAAE,OAAO,CAAC,CAAC;QACnD,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Struct, assert, object as stObject } from '@metamask/superstruct';\nimport type {\n Infer,\n Context,\n ObjectSchema,\n OmitBy,\n Optionalize,\n PickBy,\n Simplify,\n AnyStruct,\n} from '@metamask/superstruct';\n\nimport type { Equals } from './types';\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\ndeclare const ExactOptionalSymbol: unique symbol;\n\nexport type ExactOptionalTag = {\n type: typeof ExactOptionalSymbol;\n};\n\n/**\n * Exclude type `Type` from the properties of `Obj`.\n *\n * ```ts\n * type Foo = { a: string | null; b: number };\n * type Bar = ExcludeType<Foo, null>;\n * // Bar = { a: string, b: number }\n * ```\n */\nexport type ExcludeType<Obj, Type> = {\n [K in keyof Obj]: Exclude<Obj[K], Type>;\n};\n\n/**\n * Make optional all properties that have the `ExactOptionalTag` type.\n *\n * ```ts\n * type Foo = { a: string | ExactOptionalTag; b: number};\n * type Bar = ExactOptionalize<Foo>;\n * // Bar = { a?: string; b: number}\n * ```\n */\nexport type ExactOptionalize<Schema extends object> = OmitBy<\n Schema,\n ExactOptionalTag\n> &\n Partial<ExcludeType<PickBy<Schema, ExactOptionalTag>, ExactOptionalTag>>;\n\n/**\n * Infer a type from an superstruct object schema.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ExactOptionalize<Optionalize<{ [K in keyof Schema]: Infer<Schema[K]> }>>\n>;\n\n/**\n * Change the return type of a superstruct object struct to support exact\n * optional properties.\n *\n * @param schema - The object schema.\n * @returns A struct representing an object with a known set of properties.\n */\nexport function object<Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>, Schema> {\n return stObject(schema) as any;\n}\n\n/**\n * Check if the current property is present in its parent object.\n *\n * @param ctx - The context to check.\n * @returns `true` if the property is present, `false` otherwise.\n */\nfunction hasOptional(ctx: Context): boolean {\n const property: string = ctx.path[ctx.path.length - 1];\n const parent: Record<string, unknown> = ctx.branch[ctx.branch.length - 2];\n\n return property in parent;\n}\n\n/**\n * Augment a struct to allow exact-optional values. Exact-optional values can\n * be omitted but cannot be `undefined`.\n *\n * ```ts\n * const foo = object({ bar: exactOptional(string()) });\n * type Foo = Infer<typeof foo>;\n * // Foo = { bar?: string }\n * ```\n *\n * @param struct - The struct to augment.\n * @returns The augmented struct.\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type | ExactOptionalTag, Schema> {\n return new Struct({\n ...struct,\n\n validator: (value, ctx) =>\n !hasOptional(ctx) || struct.validator(value, ctx),\n\n refiner: (value, ctx) =>\n !hasOptional(ctx) || struct.refiner(value as Type, ctx),\n });\n}\n\n/**\n * Assert that a value is valid according to a struct.\n *\n * It is similar to superstruct's mask function, but it does not ignore extra\n * properties.\n *\n * @param value - Value to check.\n * @param struct - Struct to validate the value against.\n * @param message - Error message to throw if the value is not valid.\n * @returns The value if it is valid.\n */\nexport function strictMask<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n message?: string,\n): Type {\n assert(value, struct, message);\n return value;\n}\n\n/**\n * Extracts the type from a struct definition and asserts that it matches the\n * expected type. If the types do not match, the type `never` is returned.\n *\n * @param StructType - The struct type to infer.\n * @param ExpectedType - The expected type.\n */\nexport type InferEquals<\n StructType extends Struct<any, any>,\n ExpectedType,\n> = Equals<Infer<StructType>, ExpectedType> extends true\n ? Infer<StructType>\n : never;\n\n/**\n * Create a custom union struct that uses a `selector` function for choosing\n * the validation path.\n *\n * @param selector - The selector function choosing the struct to validate with.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function selectiveUnion<Selector extends (value: any) => AnyStruct>(\n selector: Selector,\n): Struct<Infer<ReturnType<Selector>>, null> {\n return new Struct({\n type: 'union',\n schema: null,\n\n *entries(value: any, context: any): ReturnType<Struct['entries']> {\n yield* selector(value).entries(value, context);\n },\n\n *refiner(value, context): ReturnType<Struct['refiner']> {\n yield* selector(value).refiner(value, context);\n },\n\n coercer(value, context): ReturnType<Struct['coercer']> {\n return selector(value).coercer(value, context);\n },\n\n validator(value, context): ReturnType<Struct['validator']> {\n // This only validates the root of the struct, entries does the rest of\n // the work.\n return selector(value).validator(value, context);\n },\n });\n}\n"]}
|
package/dist/types.cjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StringNumberStruct = exports.UrlStruct = exports.AccountIdStruct = exports.UuidStruct = void 0;
|
|
4
4
|
const superstruct_1 = require("@metamask/superstruct");
|
|
5
|
-
const
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
6
|
/**
|
|
7
7
|
* UUIDv4 struct.
|
|
8
8
|
*/
|
|
9
|
-
exports.UuidStruct = (0,
|
|
9
|
+
exports.UuidStruct = (0, utils_1.definePattern)('UuidV4', /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu);
|
|
10
10
|
/**
|
|
11
11
|
* Account ID (UUIDv4).
|
|
12
12
|
*/
|
|
@@ -29,5 +29,5 @@ exports.UrlStruct = (0, superstruct_1.define)('Url', (value) => {
|
|
|
29
29
|
/**
|
|
30
30
|
* A string which contains a positive float number.
|
|
31
31
|
*/
|
|
32
|
-
exports.StringNumberStruct = (0,
|
|
32
|
+
exports.StringNumberStruct = (0, utils_1.definePattern)('StringNumber', /^\d+(\.\d+)?$/u);
|
|
33
33
|
//# sourceMappingURL=types.cjs.map
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAAA,uDAA2D;AAC3D,2CAAgD;AAEhD;;GAEG;AACU,QAAA,UAAU,GAAG,IAAA,qBAAa,EACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AACF;;GAEG;AACU,QAAA,eAAe,GAAG,kBAAU,CAAC,CAAC,oCAAoC;AAE/E;;;;;GAKG;AACU,QAAA,SAAS,GAAG,IAAA,oBAAM,EAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACU,QAAA,kBAAkB,GAAG,IAAA,qBAAa,EAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\nimport { definePattern } from '@metamask/utils';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n/**\n * Account ID (UUIDv4).\n */\nexport const AccountIdStruct = UuidStruct; // Alias for better naming purposes.\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * This is a helper type used by the {@link Equals} type.\n */\ntype EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;\n\n/**\n * A utility type that checks whether two types are exactly the same.\n *\n * This type evaluates to `true` if `TypeA` and `TypeB` are identical,\n * otherwise it evaluates to `false`.\n *\n * @template TypeA - The first type to compare.\n * @template TypeB - The second type to compare.\n *\n * @example\n * ```ts\n * // Example usage:\n * type Test1 = Equals<number, number>; // true\n * type Test2 = Equals<number, string>; // false\n * type Test3 = Equals<{ a: string }, { a: string }>; // true\n * type Test4 = Equals<{ a: string }, { a: number }>; // false\n * ```\n */\nexport type Equals<TypeA, TypeB> =\n EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;\n"]}
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;AAG3D;;GAEG;AACH,eAAO,MAAM,UAAU,sDAGtB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,eAAe,sDAAa,CAAC;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sDAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D;;GAEG;AACH,KAAK,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,KAAK,IAC7B,YAAY,CAAC,KAAK,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,KAAK,EAAE,8BAA8B;AAG3D;;GAEG;AACH,eAAO,MAAM,UAAU,sDAGtB,CAAC;AACF;;GAEG;AACH,eAAO,MAAM,eAAe,sDAAa,CAAC;AAE1C;;;;;GAKG;AACH,eAAO,MAAM,SAAS,sDAOpB,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,sDAG9B,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE5D;;GAEG;AACH,KAAK,YAAY,CAAC,IAAI,IAAI,CAAC,KAAK,OAAO,KAAK,SAAS,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,MAAM,MAAM,CAAC,KAAK,EAAE,KAAK,IAC7B,YAAY,CAAC,KAAK,CAAC,SAAS,YAAY,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC"}
|
package/dist/types.mjs
CHANGED
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,8BAA8B;
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAc,8BAA8B;AAC3D,OAAO,EAAE,aAAa,EAAE,wBAAwB;AAEhD;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CACrC,QAAQ,EACR,yEAAyE,CAC1E,CAAC;AACF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC,CAAC,oCAAoC;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAS,KAAK,EAAE,CAAC,KAAc,EAAE,EAAE;IAChE,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAe,CAAC,CAAC;QACrC,OAAO,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,CAAC;IAC/D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,cAAc,EACd,gBAAgB,CACjB,CAAC","sourcesContent":["import { define, type Infer } from '@metamask/superstruct';\nimport { definePattern } from '@metamask/utils';\n\n/**\n * UUIDv4 struct.\n */\nexport const UuidStruct = definePattern(\n 'UuidV4',\n /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu,\n);\n/**\n * Account ID (UUIDv4).\n */\nexport const AccountIdStruct = UuidStruct; // Alias for better naming purposes.\n\n/**\n * Validates if a given value is a valid URL.\n *\n * @param value - The value to be validated.\n * @returns A boolean indicating if the value is a valid URL.\n */\nexport const UrlStruct = define<string>('Url', (value: unknown) => {\n try {\n const url = new URL(value as string);\n return url.protocol === 'http:' || url.protocol === 'https:';\n } catch {\n return false;\n }\n});\n\n/**\n * A string which contains a positive float number.\n */\nexport const StringNumberStruct = definePattern(\n 'StringNumber',\n /^\\d+(\\.\\d+)?$/u,\n);\nexport type StringNumber = Infer<typeof StringNumberStruct>;\n\n/**\n * This is a helper type used by the {@link Equals} type.\n */\ntype EqualsHelper<Type> = <Dummy>() => Dummy extends Type ? 1 : 2;\n\n/**\n * A utility type that checks whether two types are exactly the same.\n *\n * This type evaluates to `true` if `TypeA` and `TypeB` are identical,\n * otherwise it evaluates to `false`.\n *\n * @template TypeA - The first type to compare.\n * @template TypeB - The second type to compare.\n *\n * @example\n * ```ts\n * // Example usage:\n * type Test1 = Equals<number, number>; // true\n * type Test2 = Equals<number, string>; // false\n * type Test3 = Equals<{ a: string }, { a: string }>; // true\n * type Test4 = Equals<{ a: string }, { a: number }>; // false\n * ```\n */\nexport type Equals<TypeA, TypeB> =\n EqualsHelper<TypeA> extends EqualsHelper<TypeB> ? true : false;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/keyring-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-b0257dd",
|
|
4
4
|
"description": "MetaMask Keyring utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"metamask",
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
"test:watch": "jest --watch"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"@ethereumjs/tx": "^4.2.0",
|
|
48
49
|
"@metamask/superstruct": "^3.1.0",
|
|
49
|
-
"@metamask/utils": "^11.0
|
|
50
|
+
"@metamask/utils": "^11.1.0",
|
|
50
51
|
"bitcoin-address-validation": "^2.2.3"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|