@metamask/eip-5792-middleware 1.2.4 → 2.1.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 (40) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/hooks/getCallsStatus.cjs +1 -1
  3. package/dist/hooks/getCallsStatus.cjs.map +1 -1
  4. package/dist/hooks/getCallsStatus.mjs +1 -1
  5. package/dist/hooks/getCallsStatus.mjs.map +1 -1
  6. package/dist/hooks/getCapabilities.cjs.map +1 -1
  7. package/dist/hooks/getCapabilities.mjs.map +1 -1
  8. package/dist/hooks/processSendCalls.cjs +9 -2
  9. package/dist/hooks/processSendCalls.cjs.map +1 -1
  10. package/dist/hooks/processSendCalls.d.cts.map +1 -1
  11. package/dist/hooks/processSendCalls.d.mts.map +1 -1
  12. package/dist/hooks/processSendCalls.mjs +9 -2
  13. package/dist/hooks/processSendCalls.mjs.map +1 -1
  14. package/dist/methods/wallet_getCallsStatus.cjs.map +1 -1
  15. package/dist/methods/wallet_getCallsStatus.d.cts +1 -1
  16. package/dist/methods/wallet_getCallsStatus.d.cts.map +1 -1
  17. package/dist/methods/wallet_getCallsStatus.d.mts +1 -1
  18. package/dist/methods/wallet_getCallsStatus.d.mts.map +1 -1
  19. package/dist/methods/wallet_getCallsStatus.mjs.map +1 -1
  20. package/dist/methods/wallet_getCapabilities.cjs.map +1 -1
  21. package/dist/methods/wallet_getCapabilities.d.cts +1 -1
  22. package/dist/methods/wallet_getCapabilities.d.cts.map +1 -1
  23. package/dist/methods/wallet_getCapabilities.d.mts +1 -1
  24. package/dist/methods/wallet_getCapabilities.d.mts.map +1 -1
  25. package/dist/methods/wallet_getCapabilities.mjs.map +1 -1
  26. package/dist/methods/wallet_sendCalls.cjs.map +1 -1
  27. package/dist/methods/wallet_sendCalls.d.cts +1 -1
  28. package/dist/methods/wallet_sendCalls.d.cts.map +1 -1
  29. package/dist/methods/wallet_sendCalls.d.mts +1 -1
  30. package/dist/methods/wallet_sendCalls.d.mts.map +1 -1
  31. package/dist/methods/wallet_sendCalls.mjs.map +1 -1
  32. package/dist/types.cjs.map +1 -1
  33. package/dist/types.d.cts +8 -8
  34. package/dist/types.d.cts.map +1 -1
  35. package/dist/types.d.mts +8 -8
  36. package/dist/types.d.mts.map +1 -1
  37. package/dist/types.mjs.map +1 -1
  38. package/dist/utils.cjs.map +1 -1
  39. package/dist/utils.mjs.map +1 -1
  40. package/package.json +7 -4
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAE/E,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAG/C;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAAmB,EACnB,SAA2B;IAE3B,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,IAAI,CACjC,6BAA6B,CAC9B,CAAC,gBAAgB,CAAC;IAEnB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC1C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,cAAc,CAAC,WAAW,EAAE,CACpE,CAAC;IAEF,MAAM,WAAW,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;IAErD,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,YAAY,CACpB,gBAAgB,CAAC,eAAe,EAChC,2DAA2D,CAC5D,CAAC;KACH;IAED,OAAO,WAA2B,CAAC;AACrC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,6BAA6B,CACjD,OAAY,EACZ,GAAmB,EACnB,EAAE,WAAW,EAA+D;IAE5E,IACE,OAAO,OAAO,K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K,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\n\nimport { EIP5792ErrorCode } from './constants';\nimport type { EIP5792Messenger } from './types';\n\n/**\n * Retrieves the keyring type for a given account address.\n *\n * @param accountAddress - The account address to look up.\n * @param messenger - Messenger instance for controller communication.\n * @returns The keyring type associated with the account.\n * @throws JsonRpcError if the account type is unknown or not found.\n */\nexport function getAccountKeyringType(\n accountAddress: Hex,\n messenger: EIP5792Messenger,\n): KeyringTypes {\n const { accounts } = messenger.call(\n 'AccountsController:getState',\n ).internalAccounts;\n\n const account = Object.values(accounts).find(\n (acc) => acc.address.toLowerCase() === accountAddress.toLowerCase(),\n );\n\n const keyringType = account?.metadata?.keyring?.type;\n\n if (!keyringType) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported as account type is unknown',\n );\n }\n\n return keyringType as KeyringTypes;\n}\n\n/**\n * Validates and normalizes a keyholder address for EIP-5792 operations.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param req - The JSON-RPC request object for permission checking.\n * @param options - Configuration object containing the getAccounts function.\n * @param options.getAccounts - Function to retrieve accounts for the requester.\n * @returns A normalized (lowercase) hex address if valid and authorized.\n * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.\n * @throws JsonRpcError with invalid params if the address format is invalid.\n */\nexport async function validateAndNormalizeKeyholder(\n address: Hex,\n req: JsonRpcRequest,\n { getAccounts }: { getAccounts: (req: JsonRpcRequest) => Promise<string[]> },\n): Promise<Hex> {\n if (\n typeof address === 'string' &&\n address.length > 0 &&\n resemblesAddress(address)\n ) {\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getAccounts(req);\n\n const normalizedAccounts: string[] = accounts.map((_address) =>\n _address.toLowerCase(),\n );\n\n const normalizedAddress = address.toLowerCase() as Hex;\n\n if (normalizedAccounts.includes(normalizedAddress)) {\n return normalizedAddress;\n }\n\n throw providerErrors.unauthorized();\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an Ethereum address.`,\n });\n}\n\n/**\n * Validates parameters against a Superstruct schema and throws an error if validation fails.\n *\n * @param value - The value to validate against the struct schema.\n * @param struct - The Superstruct schema to validate against.\n * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.\n */\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, `Invalid params`),\n );\n }\n}\n\n/**\n * Checks if a string resembles an Ethereum address format.\n *\n * @param str - The string to check for address-like format.\n * @returns True if the string has the correct length for an Ethereum address.\n */\nexport function resemblesAddress(str: string): boolean {\n // hex prefix 2 + 20 bytes\n return str.length === 2 + 20 * 2;\n}\n\n/**\n * Formats a Superstruct validation error into a human-readable string.\n *\n * @param error - The Superstruct validation error to format.\n * @param message - The base error message to prepend to the formatted details.\n * @returns A formatted error message string with validation failure details.\n */\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAE/E,OA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C;YACnD,OAAO,iBAAiB,CAAC;QAC3B,CAAC;QAED,MAAM,cAAc,CAAC,YAAY,EAAE,CAAC;IACtC,CAAC;IAED,MAAM,SAAS,CAAC,aAAa,CAAC;QAC5B,OAAO,EAAE,uDAAuD;KACjE,CAAC,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,KAA2B,EAC3B,MAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAExC,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,SAAS,CAAC,aAAa,CAC3B,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAC/C,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW;IAC1C,0BAA0B;IAC1B,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,KAAkB,EAAE,OAAe;IAChE,OAAO,GAAG,OAAO,OAAO,KAAK;SAC1B,QAAQ,EAAE;SACV,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\n\nimport { EIP5792ErrorCode } from './constants';\nimport type { EIP5792Messenger } from './types';\n\n/**\n * Retrieves the keyring type for a given account address.\n *\n * @param accountAddress - The account address to look up.\n * @param messenger - Messenger instance for controller communication.\n * @returns The keyring type associated with the account.\n * @throws JsonRpcError if the account type is unknown or not found.\n */\nexport function getAccountKeyringType(\n accountAddress: Hex,\n messenger: EIP5792Messenger,\n): KeyringTypes {\n const { accounts } = messenger.call(\n 'AccountsController:getState',\n ).internalAccounts;\n\n const account = Object.values(accounts).find(\n (acc) => acc.address.toLowerCase() === accountAddress.toLowerCase(),\n );\n\n const keyringType = account?.metadata?.keyring?.type;\n\n if (!keyringType) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported as account type is unknown',\n );\n }\n\n return keyringType as KeyringTypes;\n}\n\n/**\n * Validates and normalizes a keyholder address for EIP-5792 operations.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param req - The JSON-RPC request object for permission checking.\n * @param options - Configuration object containing the getAccounts function.\n * @param options.getAccounts - Function to retrieve accounts for the requester.\n * @returns A normalized (lowercase) hex address if valid and authorized.\n * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.\n * @throws JsonRpcError with invalid params if the address format is invalid.\n */\nexport async function validateAndNormalizeKeyholder(\n address: Hex,\n req: JsonRpcRequest,\n { getAccounts }: { getAccounts: (req: JsonRpcRequest) => Promise<string[]> },\n): Promise<Hex> {\n if (\n typeof address === 'string' &&\n address.length > 0 &&\n resemblesAddress(address)\n ) {\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getAccounts(req);\n\n const normalizedAccounts: string[] = accounts.map((_address) =>\n _address.toLowerCase(),\n );\n\n const normalizedAddress = address.toLowerCase() as Hex;\n\n if (normalizedAccounts.includes(normalizedAddress)) {\n return normalizedAddress;\n }\n\n throw providerErrors.unauthorized();\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an Ethereum address.`,\n });\n}\n\n/**\n * Validates parameters against a Superstruct schema and throws an error if validation fails.\n *\n * @param value - The value to validate against the struct schema.\n * @param struct - The Superstruct schema to validate against.\n * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.\n */\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, `Invalid params`),\n );\n }\n}\n\n/**\n * Checks if a string resembles an Ethereum address format.\n *\n * @param str - The string to check for address-like format.\n * @returns True if the string has the correct length for an Ethereum address.\n */\nexport function resemblesAddress(str: string): boolean {\n // hex prefix 2 + 20 bytes\n return str.length === 2 + 20 * 2;\n}\n\n/**\n * Formats a Superstruct validation error into a human-readable string.\n *\n * @param error - The Superstruct validation error to format.\n * @param message - The base error message to prepend to the formatted details.\n * @returns A formatted error message string with validation failure details.\n */\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/eip-5792-middleware",
3
- "version": "1.2.4",
3
+ "version": "2.1.0",
4
4
  "description": "Implements the JSON-RPC methods for sending multiple calls from the user's wallet, and checking their status, as referenced in EIP-5792",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -36,6 +36,7 @@
36
36
  ],
37
37
  "scripts": {
38
38
  "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
39
+ "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
39
40
  "build:docs": "typedoc",
40
41
  "changelog:update": "../../scripts/update-changelog.sh @metamask/eip-5792-middleware",
41
42
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/eip-5792-middleware",
@@ -47,16 +48,18 @@
47
48
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48
49
  },
49
50
  "dependencies": {
51
+ "@metamask/messenger": "^0.3.0",
50
52
  "@metamask/superstruct": "^3.1.0",
51
- "@metamask/transaction-controller": "^60.10.0",
53
+ "@metamask/transaction-controller": "^62.7.0",
52
54
  "@metamask/utils": "^11.8.1",
53
55
  "lodash": "^4.17.21",
54
56
  "uuid": "^8.3.2"
55
57
  },
56
58
  "devDependencies": {
57
59
  "@metamask/auto-changelog": "^3.4.4",
58
- "@metamask/keyring-controller": "^23.2.0",
60
+ "@metamask/keyring-controller": "^25.0.0",
59
61
  "@metamask/rpc-errors": "^7.0.2",
62
+ "@ts-bridge/cli": "^0.6.4",
60
63
  "@types/jest": "^27.4.1",
61
64
  "deepmerge": "^4.2.2",
62
65
  "jest": "^27.5.1",
@@ -64,7 +67,7 @@
64
67
  "ts-jest": "^27.1.4",
65
68
  "typedoc": "^0.24.8",
66
69
  "typedoc-plugin-missing-exports": "^2.0.0",
67
- "typescript": "~5.2.2"
70
+ "typescript": "~5.3.3"
68
71
  },
69
72
  "engines": {
70
73
  "node": "^18.18 || >=20"