@metamask/keyring-api 21.5.0 → 22.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/api/transaction.cjs +64 -1
  3. package/dist/api/transaction.cjs.map +1 -1
  4. package/dist/api/transaction.d.cts +135 -0
  5. package/dist/api/transaction.d.cts.map +1 -1
  6. package/dist/api/transaction.d.mts +135 -0
  7. package/dist/api/transaction.d.mts.map +1 -1
  8. package/dist/api/transaction.mjs +64 -1
  9. package/dist/api/transaction.mjs.map +1 -1
  10. package/dist/api/v2/index.cjs +0 -1
  11. package/dist/api/v2/index.cjs.map +1 -1
  12. package/dist/api/v2/index.d.cts +0 -1
  13. package/dist/api/v2/index.d.cts.map +1 -1
  14. package/dist/api/v2/index.d.mts +0 -1
  15. package/dist/api/v2/index.d.mts.map +1 -1
  16. package/dist/api/v2/index.mjs +0 -1
  17. package/dist/api/v2/index.mjs.map +1 -1
  18. package/dist/api/v2/keyring-type.cjs +4 -0
  19. package/dist/api/v2/keyring-type.cjs.map +1 -1
  20. package/dist/api/v2/keyring-type.d.cts +5 -1
  21. package/dist/api/v2/keyring-type.d.cts.map +1 -1
  22. package/dist/api/v2/keyring-type.d.mts +5 -1
  23. package/dist/api/v2/keyring-type.d.mts.map +1 -1
  24. package/dist/api/v2/keyring-type.mjs +4 -0
  25. package/dist/api/v2/keyring-type.mjs.map +1 -1
  26. package/dist/eth/index.cjs +0 -1
  27. package/dist/eth/index.cjs.map +1 -1
  28. package/dist/eth/index.d.cts +0 -1
  29. package/dist/eth/index.d.cts.map +1 -1
  30. package/dist/eth/index.d.mts +0 -1
  31. package/dist/eth/index.d.mts.map +1 -1
  32. package/dist/eth/index.mjs +0 -1
  33. package/dist/eth/index.mjs.map +1 -1
  34. package/dist/events.d.cts +12 -0
  35. package/dist/events.d.cts.map +1 -1
  36. package/dist/events.d.mts +12 -0
  37. package/dist/events.d.mts.map +1 -1
  38. package/dist/rpc.d.cts +23 -0
  39. package/dist/rpc.d.cts.map +1 -1
  40. package/dist/rpc.d.mts +23 -0
  41. package/dist/rpc.d.mts.map +1 -1
  42. package/package.json +2 -7
  43. package/dist/api/v2/wrapper/index.cjs +0 -19
  44. package/dist/api/v2/wrapper/index.cjs.map +0 -1
  45. package/dist/api/v2/wrapper/index.d.cts +0 -3
  46. package/dist/api/v2/wrapper/index.d.cts.map +0 -1
  47. package/dist/api/v2/wrapper/index.d.mts +0 -3
  48. package/dist/api/v2/wrapper/index.d.mts.map +0 -1
  49. package/dist/api/v2/wrapper/index.mjs +0 -3
  50. package/dist/api/v2/wrapper/index.mjs.map +0 -1
  51. package/dist/api/v2/wrapper/keyring-account-registry.cjs +0 -135
  52. package/dist/api/v2/wrapper/keyring-account-registry.cjs.map +0 -1
  53. package/dist/api/v2/wrapper/keyring-account-registry.d.cts +0 -88
  54. package/dist/api/v2/wrapper/keyring-account-registry.d.cts.map +0 -1
  55. package/dist/api/v2/wrapper/keyring-account-registry.d.mts +0 -88
  56. package/dist/api/v2/wrapper/keyring-account-registry.d.mts.map +0 -1
  57. package/dist/api/v2/wrapper/keyring-account-registry.mjs +0 -131
  58. package/dist/api/v2/wrapper/keyring-account-registry.mjs.map +0 -1
  59. package/dist/api/v2/wrapper/keyring-wrapper.cjs +0 -134
  60. package/dist/api/v2/wrapper/keyring-wrapper.cjs.map +0 -1
  61. package/dist/api/v2/wrapper/keyring-wrapper.d.cts +0 -154
  62. package/dist/api/v2/wrapper/keyring-wrapper.d.cts.map +0 -1
  63. package/dist/api/v2/wrapper/keyring-wrapper.d.mts +0 -154
  64. package/dist/api/v2/wrapper/keyring-wrapper.d.mts.map +0 -1
  65. package/dist/api/v2/wrapper/keyring-wrapper.mjs +0 -130
  66. package/dist/api/v2/wrapper/keyring-wrapper.mjs.map +0 -1
  67. package/dist/eth/v2/eth-keyring-wrapper.cjs +0 -165
  68. package/dist/eth/v2/eth-keyring-wrapper.cjs.map +0 -1
  69. package/dist/eth/v2/eth-keyring-wrapper.d.cts +0 -54
  70. package/dist/eth/v2/eth-keyring-wrapper.d.cts.map +0 -1
  71. package/dist/eth/v2/eth-keyring-wrapper.d.mts +0 -54
  72. package/dist/eth/v2/eth-keyring-wrapper.d.mts.map +0 -1
  73. package/dist/eth/v2/eth-keyring-wrapper.mjs +0 -161
  74. package/dist/eth/v2/eth-keyring-wrapper.mjs.map +0 -1
  75. package/dist/eth/v2/index.cjs +0 -18
  76. package/dist/eth/v2/index.cjs.map +0 -1
  77. package/dist/eth/v2/index.d.cts +0 -2
  78. package/dist/eth/v2/index.d.cts.map +0 -1
  79. package/dist/eth/v2/index.d.mts +0 -2
  80. package/dist/eth/v2/index.d.mts.map +0 -1
  81. package/dist/eth/v2/index.mjs +0 -2
  82. package/dist/eth/v2/index.mjs.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.cjs","sourceRoot":"","sources":["../../../src/eth/v2/eth-keyring-wrapper.ts"],"names":[],"mappings":";;;AAAA,uCAAsE;AAEtE,yDAA8D;AAE9D,uDAA+C;AAC/C,2CAA6D;AAI7D,8EAG8C;AAC9C,0CAUgB;AAChB,wCAAqC;AAErC;;;GAGG;AACH,IAAY,gBAKX;AALD,WAAY,gBAAgB;IAC1B,2CAAuB,CAAA;IACvB,yEAAqD,CAAA;IACrD,6DAAyC,CAAA;IACzC,6EAAyD,CAAA;AAC3D,CAAC,EALW,gBAAgB,gCAAhB,gBAAgB,QAK3B;AAQD;;;;;;;;;;;;GAYG;AACH,MAAsB,iBAGpB,SAAQ,gCAAgD;IACxD;;;;;;;OAOG;IACO,YAAY,CAAC,OAAe;QACpC,OAAO,IAAA,aAAK,EAAC,OAAO,CAAC,CAAC;IACxB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,aAAa,CAAC,OAAuB;QACzC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;QAE3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EAAE,2CAAqC,CAAC,CAAC;gBACtD,MAAM,CAAC,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC;gBAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;YAChE,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,gBAAgB,EAAE,CAAC,CAAC,CAAC;gBAC5C,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,gBAAgB,EAAE,CAAC;oBACjC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC/D,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,qCAA+B,CAAC,CAAC;gBAChD,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;gBACxB,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YACzD,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,IAAA,oBAAM,EAAC,MAAM,EAAE,6CAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF;AA5JD,8CA4JC","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from '../../api/account';\nimport type { KeyringRequest } from '../../api/request';\nimport {\n KeyringWrapper,\n type KeyringWrapperOptions,\n} from '../../api/v2/wrapper/keyring-wrapper';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n} from '../rpc';\nimport { EthMethod } from '../types';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an EthKeyringWrapper.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> =\n KeyringWrapperOptions<InnerKeyring>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
@@ -1,54 +0,0 @@
1
- import type { EthKeyring } from "@metamask/keyring-utils";
2
- import { type Hex, type Json } from "@metamask/utils";
3
- import type { KeyringAccount } from "../../api/account.cjs";
4
- import type { KeyringRequest } from "../../api/request.cjs";
5
- import { KeyringWrapper, type KeyringWrapperOptions } from "../../api/v2/wrapper/keyring-wrapper.cjs";
6
- /**
7
- * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
8
- * These are primarily encryption and utility methods.
9
- */
10
- export declare enum EthKeyringMethod {
11
- Decrypt = "eth_decrypt",
12
- GetEncryptionPublicKey = "eth_getEncryptionPublicKey",
13
- GetAppKeyAddress = "eth_getAppKeyAddress",
14
- SignEip7702Authorization = "eth_signEip7702Authorization"
15
- }
16
- /**
17
- * Options for constructing an EthKeyringWrapper.
18
- */
19
- export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = KeyringWrapperOptions<InnerKeyring>;
20
- /**
21
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
22
- *
23
- * This class provides common functionality for all Ethereum keyrings including:
24
- * - Request handling for standard Ethereum signing methods
25
- * - Helper methods for Hex address conversion
26
- *
27
- * Subclasses must implement:
28
- * - `getAccounts()`: Return all managed accounts
29
- * - `createAccounts()`: Create new accounts based on options
30
- * - `deleteAccount()`: Remove an account from the keyring
31
- * - `exportAccount()` (optional): Export private key in specified format
32
- */
33
- export declare abstract class EthKeyringWrapper<InnerKeyring extends EthKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {
34
- /**
35
- * Helper method to safely cast a KeyringAccount address to Hex type.
36
- * The KeyringAccount.address is typed as string, but for Ethereum accounts
37
- * it should always be a valid Hex address.
38
- *
39
- * @param address - The address from a KeyringAccount.
40
- * @returns The address as Hex type.
41
- */
42
- protected toHexAddress(address: string): Hex;
43
- /**
44
- * Handle an Ethereum signing request.
45
- *
46
- * Routes the request to the appropriate legacy keyring method based on
47
- * the RPC method name.
48
- *
49
- * @param request - The keyring request containing method and params.
50
- * @returns The result of the signing operation.
51
- */
52
- submitRequest(request: KeyringRequest): Promise<Json>;
53
- }
54
- //# sourceMappingURL=eth-keyring-wrapper.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.d.cts","sourceRoot":"","sources":["../../../src/eth/v2/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AACxD,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC3B,iDAA6C;AAc9C;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAClE,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;IACxD;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
@@ -1,54 +0,0 @@
1
- import type { EthKeyring } from "@metamask/keyring-utils";
2
- import { type Hex, type Json } from "@metamask/utils";
3
- import type { KeyringAccount } from "../../api/account.mjs";
4
- import type { KeyringRequest } from "../../api/request.mjs";
5
- import { KeyringWrapper, type KeyringWrapperOptions } from "../../api/v2/wrapper/keyring-wrapper.mjs";
6
- /**
7
- * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
8
- * These are primarily encryption and utility methods.
9
- */
10
- export declare enum EthKeyringMethod {
11
- Decrypt = "eth_decrypt",
12
- GetEncryptionPublicKey = "eth_getEncryptionPublicKey",
13
- GetAppKeyAddress = "eth_getAppKeyAddress",
14
- SignEip7702Authorization = "eth_signEip7702Authorization"
15
- }
16
- /**
17
- * Options for constructing an EthKeyringWrapper.
18
- */
19
- export type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> = KeyringWrapperOptions<InnerKeyring>;
20
- /**
21
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
22
- *
23
- * This class provides common functionality for all Ethereum keyrings including:
24
- * - Request handling for standard Ethereum signing methods
25
- * - Helper methods for Hex address conversion
26
- *
27
- * Subclasses must implement:
28
- * - `getAccounts()`: Return all managed accounts
29
- * - `createAccounts()`: Create new accounts based on options
30
- * - `deleteAccount()`: Remove an account from the keyring
31
- * - `exportAccount()` (optional): Export private key in specified format
32
- */
33
- export declare abstract class EthKeyringWrapper<InnerKeyring extends EthKeyring, KeyringAccountType extends KeyringAccount = KeyringAccount> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {
34
- /**
35
- * Helper method to safely cast a KeyringAccount address to Hex type.
36
- * The KeyringAccount.address is typed as string, but for Ethereum accounts
37
- * it should always be a valid Hex address.
38
- *
39
- * @param address - The address from a KeyringAccount.
40
- * @returns The address as Hex type.
41
- */
42
- protected toHexAddress(address: string): Hex;
43
- /**
44
- * Handle an Ethereum signing request.
45
- *
46
- * Routes the request to the appropriate legacy keyring method based on
47
- * the RPC method name.
48
- *
49
- * @param request - The keyring request containing method and params.
50
- * @returns The result of the signing operation.
51
- */
52
- submitRequest(request: KeyringRequest): Promise<Json>;
53
- }
54
- //# sourceMappingURL=eth-keyring-wrapper.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.d.mts","sourceRoot":"","sources":["../../../src/eth/v2/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAE1D,OAAO,EAAS,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,wBAAwB;AAE7D,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,8BAA0B;AACxD,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC3B,iDAA6C;AAc9C;;;GAGG;AACH,oBAAY,gBAAgB;IAC1B,OAAO,gBAAgB;IACvB,sBAAsB,+BAA+B;IACrD,gBAAgB,yBAAyB;IACzC,wBAAwB,iCAAiC;CAC1D;AAED;;GAEG;AACH,MAAM,MAAM,wBAAwB,CAAC,YAAY,SAAS,UAAU,IAClE,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAEtC;;;;;;;;;;;;GAYG;AACH,8BAAsB,iBAAiB,CACrC,YAAY,SAAS,UAAU,EAC/B,kBAAkB,SAAS,cAAc,GAAG,cAAc,CAC1D,SAAQ,cAAc,CAAC,YAAY,EAAE,kBAAkB,CAAC;IACxD;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAI5C;;;;;;;;OAQG;IACG,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAmI5D"}
@@ -1,161 +0,0 @@
1
- import { TransactionFactory } from "@ethereumjs/tx";
2
- import { SignTypedDataVersion } from "@metamask/eth-sig-util";
3
- import { assert } from "@metamask/superstruct";
4
- import { add0x } from "@metamask/utils";
5
- import { KeyringWrapper } from "../../api/v2/wrapper/keyring-wrapper.mjs";
6
- import { EthDecryptParamsStruct, EthGetAppKeyAddressParamsStruct, EthGetEncryptionPublicKeyParamsStruct, EthPersonalSignParamsStruct, EthSignEip7702AuthorizationParamsStruct, EthSignParamsStruct, EthSignTransactionParamsStruct, EthSignTypedDataParamsStruct, EthSignTypedDataV1ParamsStruct } from "../rpc/index.mjs";
7
- import { EthMethod } from "../types.mjs";
8
- /**
9
- * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.
10
- * These are primarily encryption and utility methods.
11
- */
12
- export var EthKeyringMethod;
13
- (function (EthKeyringMethod) {
14
- EthKeyringMethod["Decrypt"] = "eth_decrypt";
15
- EthKeyringMethod["GetEncryptionPublicKey"] = "eth_getEncryptionPublicKey";
16
- EthKeyringMethod["GetAppKeyAddress"] = "eth_getAppKeyAddress";
17
- EthKeyringMethod["SignEip7702Authorization"] = "eth_signEip7702Authorization";
18
- })(EthKeyringMethod || (EthKeyringMethod = {}));
19
- /**
20
- * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.
21
- *
22
- * This class provides common functionality for all Ethereum keyrings including:
23
- * - Request handling for standard Ethereum signing methods
24
- * - Helper methods for Hex address conversion
25
- *
26
- * Subclasses must implement:
27
- * - `getAccounts()`: Return all managed accounts
28
- * - `createAccounts()`: Create new accounts based on options
29
- * - `deleteAccount()`: Remove an account from the keyring
30
- * - `exportAccount()` (optional): Export private key in specified format
31
- */
32
- export class EthKeyringWrapper extends KeyringWrapper {
33
- /**
34
- * Helper method to safely cast a KeyringAccount address to Hex type.
35
- * The KeyringAccount.address is typed as string, but for Ethereum accounts
36
- * it should always be a valid Hex address.
37
- *
38
- * @param address - The address from a KeyringAccount.
39
- * @returns The address as Hex type.
40
- */
41
- toHexAddress(address) {
42
- return add0x(address);
43
- }
44
- /**
45
- * Handle an Ethereum signing request.
46
- *
47
- * Routes the request to the appropriate legacy keyring method based on
48
- * the RPC method name.
49
- *
50
- * @param request - The keyring request containing method and params.
51
- * @returns The result of the signing operation.
52
- */
53
- async submitRequest(request) {
54
- const { method, params } = request.request;
55
- const { address, methods } = await this.getAccount(request.account);
56
- const hexAddress = this.toHexAddress(address);
57
- // Validate account can handle the method
58
- if (!methods.includes(method)) {
59
- throw new Error(`Account ${request.account} cannot handle method: ${method}`);
60
- }
61
- switch (method) {
62
- case `${EthMethod.SignTransaction}`: {
63
- if (!this.inner.signTransaction) {
64
- throw new Error('Keyring does not support signTransaction');
65
- }
66
- assert(params, EthSignTransactionParamsStruct);
67
- const [txData] = params;
68
- // Convert validated transaction data to TypedTransaction
69
- // TODO: Improve typing to ensure txData matches TypedTxData
70
- const tx = TransactionFactory.fromTxData(txData);
71
- // Note: Bigints are not directly representable in JSON
72
- return (await this.inner.signTransaction(hexAddress, tx)); // FIXME: Should return type be unknown?
73
- }
74
- case `${EthMethod.Sign}`: {
75
- if (!this.inner.signMessage) {
76
- throw new Error('Keyring does not support signMessage');
77
- }
78
- assert(params, EthSignParamsStruct);
79
- const [, data] = params;
80
- return this.inner.signMessage(hexAddress, data);
81
- }
82
- case `${EthMethod.PersonalSign}`: {
83
- if (!this.inner.signPersonalMessage) {
84
- throw new Error('Keyring does not support signPersonalMessage');
85
- }
86
- assert(params, EthPersonalSignParamsStruct);
87
- const [data] = params;
88
- return this.inner.signPersonalMessage(hexAddress, data);
89
- }
90
- case `${EthMethod.SignTypedDataV1}`: {
91
- if (!this.inner.signTypedData) {
92
- throw new Error('Keyring does not support signTypedData');
93
- }
94
- assert(params, EthSignTypedDataV1ParamsStruct);
95
- const [, data] = params;
96
- return this.inner.signTypedData(hexAddress, data, {
97
- version: SignTypedDataVersion.V1,
98
- });
99
- }
100
- case `${EthMethod.SignTypedDataV3}`: {
101
- if (!this.inner.signTypedData) {
102
- throw new Error('Keyring does not support signTypedData');
103
- }
104
- assert(params, EthSignTypedDataParamsStruct);
105
- const [, data] = params;
106
- return this.inner.signTypedData(hexAddress,
107
- // TODO: Improve typing to ensure data matches MessageTypes
108
- data, {
109
- version: SignTypedDataVersion.V3,
110
- });
111
- }
112
- case `${EthMethod.SignTypedDataV4}`: {
113
- if (!this.inner.signTypedData) {
114
- throw new Error('Keyring does not support signTypedData');
115
- }
116
- assert(params, EthSignTypedDataParamsStruct);
117
- const [, data] = params;
118
- return this.inner.signTypedData(hexAddress,
119
- // TODO: Improve typing to ensure data matches MessageTypes
120
- data, {
121
- version: SignTypedDataVersion.V4,
122
- });
123
- }
124
- case `${EthKeyringMethod.Decrypt}`: {
125
- if (!this.inner.decryptMessage) {
126
- throw new Error('Keyring does not support decryptMessage');
127
- }
128
- assert(params, EthDecryptParamsStruct);
129
- const [encryptedData] = params;
130
- return this.inner.decryptMessage(hexAddress, encryptedData);
131
- }
132
- case `${EthKeyringMethod.GetEncryptionPublicKey}`: {
133
- if (!this.inner.getEncryptionPublicKey) {
134
- throw new Error('Keyring does not support getEncryptionPublicKey');
135
- }
136
- assert(params, EthGetEncryptionPublicKeyParamsStruct);
137
- const [, options] = params;
138
- return this.inner.getEncryptionPublicKey(hexAddress, options);
139
- }
140
- case `${EthKeyringMethod.GetAppKeyAddress}`: {
141
- if (!this.inner.getAppKeyAddress) {
142
- throw new Error('Keyring does not support getAppKeyAddress');
143
- }
144
- assert(params, EthGetAppKeyAddressParamsStruct);
145
- const [origin] = params;
146
- return this.inner.getAppKeyAddress(hexAddress, origin);
147
- }
148
- case `${EthKeyringMethod.SignEip7702Authorization}`: {
149
- if (!this.inner.signEip7702Authorization) {
150
- throw new Error('Keyring does not support signEip7702Authorization');
151
- }
152
- assert(params, EthSignEip7702AuthorizationParamsStruct);
153
- const [authorization] = params;
154
- return this.inner.signEip7702Authorization(hexAddress, authorization);
155
- }
156
- default:
157
- throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);
158
- }
159
- }
160
- }
161
- //# sourceMappingURL=eth-keyring-wrapper.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"eth-keyring-wrapper.mjs","sourceRoot":"","sources":["../../../src/eth/v2/eth-keyring-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAoB,uBAAuB;AAEtE,OAAO,EAAE,oBAAoB,EAAE,+BAA+B;AAE9D,OAAO,EAAE,MAAM,EAAE,8B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C,UAAU,EAAE,MAAM,CAAC,CAAC;YACzD,CAAC;YAED,KAAK,GAAG,gBAAgB,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;gBACpD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC;oBACzC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBACvE,CAAC;gBACD,MAAM,CAAC,MAAM,EAAE,uCAAuC,CAAC,CAAC;gBACxD,MAAM,CAAC,aAAa,CAAC,GAAG,MAAM,CAAC;gBAC/B,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,UAAU,EAAE,aAAa,CAAC,CAAC;YACxE,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QAC3E,CAAC;IACH,CAAC;CACF","sourcesContent":["import { TransactionFactory, type TypedTxData } from '@ethereumjs/tx';\nimport type { MessageTypes, TypedMessage } from '@metamask/eth-sig-util';\nimport { SignTypedDataVersion } from '@metamask/eth-sig-util';\nimport type { EthKeyring } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport { add0x, type Hex, type Json } from '@metamask/utils';\n\nimport type { KeyringAccount } from '../../api/account';\nimport type { KeyringRequest } from '../../api/request';\nimport {\n KeyringWrapper,\n type KeyringWrapperOptions,\n} from '../../api/v2/wrapper/keyring-wrapper';\nimport {\n EthDecryptParamsStruct,\n EthGetAppKeyAddressParamsStruct,\n EthGetEncryptionPublicKeyParamsStruct,\n EthPersonalSignParamsStruct,\n EthSignEip7702AuthorizationParamsStruct,\n EthSignParamsStruct,\n EthSignTransactionParamsStruct,\n EthSignTypedDataParamsStruct,\n EthSignTypedDataV1ParamsStruct,\n} from '../rpc';\nimport { EthMethod } from '../types';\n\n/**\n * Additional Ethereum methods supported by Eth keyrings that are not in the standard EthMethod enum.\n * These are primarily encryption and utility methods.\n */\nexport enum EthKeyringMethod {\n Decrypt = 'eth_decrypt',\n GetEncryptionPublicKey = 'eth_getEncryptionPublicKey',\n GetAppKeyAddress = 'eth_getAppKeyAddress',\n SignEip7702Authorization = 'eth_signEip7702Authorization',\n}\n\n/**\n * Options for constructing an EthKeyringWrapper.\n */\nexport type EthKeyringWrapperOptions<InnerKeyring extends EthKeyring> =\n KeyringWrapperOptions<InnerKeyring>;\n\n/**\n * Abstract wrapper for Ethereum-based keyrings that extends KeyringWrapper, that itself implements KeyringV2.\n *\n * This class provides common functionality for all Ethereum keyrings including:\n * - Request handling for standard Ethereum signing methods\n * - Helper methods for Hex address conversion\n *\n * Subclasses must implement:\n * - `getAccounts()`: Return all managed accounts\n * - `createAccounts()`: Create new accounts based on options\n * - `deleteAccount()`: Remove an account from the keyring\n * - `exportAccount()` (optional): Export private key in specified format\n */\nexport abstract class EthKeyringWrapper<\n InnerKeyring extends EthKeyring,\n KeyringAccountType extends KeyringAccount = KeyringAccount,\n> extends KeyringWrapper<InnerKeyring, KeyringAccountType> {\n /**\n * Helper method to safely cast a KeyringAccount address to Hex type.\n * The KeyringAccount.address is typed as string, but for Ethereum accounts\n * it should always be a valid Hex address.\n *\n * @param address - The address from a KeyringAccount.\n * @returns The address as Hex type.\n */\n protected toHexAddress(address: string): Hex {\n return add0x(address);\n }\n\n /**\n * Handle an Ethereum signing request.\n *\n * Routes the request to the appropriate legacy keyring method based on\n * the RPC method name.\n *\n * @param request - The keyring request containing method and params.\n * @returns The result of the signing operation.\n */\n async submitRequest(request: KeyringRequest): Promise<Json> {\n const { method, params } = request.request;\n\n const { address, methods } = await this.getAccount(request.account);\n const hexAddress = this.toHexAddress(address);\n\n // Validate account can handle the method\n if (!methods.includes(method)) {\n throw new Error(\n `Account ${request.account} cannot handle method: ${method}`,\n );\n }\n\n switch (method) {\n case `${EthMethod.SignTransaction}`: {\n if (!this.inner.signTransaction) {\n throw new Error('Keyring does not support signTransaction');\n }\n assert(params, EthSignTransactionParamsStruct);\n const [txData] = params;\n // Convert validated transaction data to TypedTransaction\n // TODO: Improve typing to ensure txData matches TypedTxData\n const tx = TransactionFactory.fromTxData(txData as TypedTxData);\n // Note: Bigints are not directly representable in JSON\n return (await this.inner.signTransaction(\n hexAddress,\n tx,\n )) as unknown as Json; // FIXME: Should return type be unknown?\n }\n\n case `${EthMethod.Sign}`: {\n if (!this.inner.signMessage) {\n throw new Error('Keyring does not support signMessage');\n }\n assert(params, EthSignParamsStruct);\n const [, data] = params;\n return this.inner.signMessage(hexAddress, data);\n }\n\n case `${EthMethod.PersonalSign}`: {\n if (!this.inner.signPersonalMessage) {\n throw new Error('Keyring does not support signPersonalMessage');\n }\n assert(params, EthPersonalSignParamsStruct);\n const [data] = params;\n return this.inner.signPersonalMessage(hexAddress, data as Hex);\n }\n\n case `${EthMethod.SignTypedDataV1}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataV1ParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(hexAddress, data, {\n version: SignTypedDataVersion.V1,\n });\n }\n\n case `${EthMethod.SignTypedDataV3}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V3,\n },\n );\n }\n\n case `${EthMethod.SignTypedDataV4}`: {\n if (!this.inner.signTypedData) {\n throw new Error('Keyring does not support signTypedData');\n }\n assert(params, EthSignTypedDataParamsStruct);\n const [, data] = params;\n return this.inner.signTypedData(\n hexAddress,\n // TODO: Improve typing to ensure data matches MessageTypes\n data as TypedMessage<MessageTypes>,\n {\n version: SignTypedDataVersion.V4,\n },\n );\n }\n\n case `${EthKeyringMethod.Decrypt}`: {\n if (!this.inner.decryptMessage) {\n throw new Error('Keyring does not support decryptMessage');\n }\n assert(params, EthDecryptParamsStruct);\n const [encryptedData] = params;\n return this.inner.decryptMessage(hexAddress, encryptedData);\n }\n\n case `${EthKeyringMethod.GetEncryptionPublicKey}`: {\n if (!this.inner.getEncryptionPublicKey) {\n throw new Error('Keyring does not support getEncryptionPublicKey');\n }\n assert(params, EthGetEncryptionPublicKeyParamsStruct);\n const [, options] = params;\n return this.inner.getEncryptionPublicKey(hexAddress, options);\n }\n\n case `${EthKeyringMethod.GetAppKeyAddress}`: {\n if (!this.inner.getAppKeyAddress) {\n throw new Error('Keyring does not support getAppKeyAddress');\n }\n assert(params, EthGetAppKeyAddressParamsStruct);\n const [origin] = params;\n return this.inner.getAppKeyAddress(hexAddress, origin);\n }\n\n case `${EthKeyringMethod.SignEip7702Authorization}`: {\n if (!this.inner.signEip7702Authorization) {\n throw new Error('Keyring does not support signEip7702Authorization');\n }\n assert(params, EthSignEip7702AuthorizationParamsStruct);\n const [authorization] = params;\n return this.inner.signEip7702Authorization(hexAddress, authorization);\n }\n\n default:\n throw new Error(`Unsupported method for EthKeyringWrapper: ${method}`);\n }\n }\n}\n"]}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./eth-keyring-wrapper.cjs"), exports);
18
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/eth/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAAsC","sourcesContent":["export * from './eth-keyring-wrapper';\n"]}
@@ -1,2 +0,0 @@
1
- export * from "./eth-keyring-wrapper.cjs";
2
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/eth/v2/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
@@ -1,2 +0,0 @@
1
- export * from "./eth-keyring-wrapper.mjs";
2
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/eth/v2/index.ts"],"names":[],"mappings":"AAAA,0CAAsC"}
@@ -1,2 +0,0 @@
1
- export * from "./eth-keyring-wrapper.mjs";
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/eth/v2/index.ts"],"names":[],"mappings":"AAAA,0CAAsC","sourcesContent":["export * from './eth-keyring-wrapper';\n"]}