@metamask-previews/eip-7702-internal-rpc-middleware 0.1.0-preview-cb4a07d5 → 0.1.0-preview-eb60826c

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/dist/utils.cjs CHANGED
@@ -57,7 +57,7 @@ exports.validateParams = validateParams;
57
57
  function formatValidationError(error, message) {
58
58
  return `${message}\n\n${error
59
59
  .failures()
60
- .map((f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`)
60
+ .map((failure) => `${failure.path.join(' > ')}${failure.path.length ? ' - ' : ''}${failure.message}`)
61
61
  .join('\n')}`;
62
62
  }
63
63
  //# sourceMappingURL=utils.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qDAAiE;AAEjE,uDAAiD;AAEjD,2CAA+C;AAE/C;;;;;;;;;GASG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAY,EACZ,MAAc,EACd,6BAAoE;IAEpE,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,IAAA,oBAAY,EAAC,OAAO,CAAC,EACtB,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,kDAAkD;SAC5D,CAAC,CAAC;IACL,CAAC;IAED,iEAAiE;IACjE,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,MAAM,6BAA6B,CAAC,MAAM,CAAC,CAAC;IAE7D,8DAA8D;IAC9D,MAAM,kBAAkB,GAAa,QAAQ,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CACnE,cAAc,CAAC,WAAW,EAAE,CAC7B,CAAC;IAEF,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACxD,MAAM,2BAAc,CAAC,YAAY,EAAE,CAAC;IACtC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA7BD,kEA6BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,KAA2B,EAC3B,MAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAExC,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,sBAAS,CAAC,aAAa,CAC3B,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CACnD,CAAC;IACJ,CAAC;AACH,CAAC;AAXD,wCAWC;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 { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { isHexAddress } from '@metamask/utils';\n\n/**\n * Validates address format, checks user eth_accounts permissions.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param origin - The origin string for permission checking.\n * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.\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 validateAndNormalizeAddress(\n address: Hex,\n origin: string,\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>,\n): Promise<Hex> {\n if (\n typeof address !== 'string' ||\n address.length === 0 ||\n !isHexAddress(address)\n ) {\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an EVM address.`,\n });\n }\n\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getPermittedAccountsForOrigin(origin);\n\n // Validate and convert each account address to normalized Hex\n const normalizedAccounts: string[] = accounts.map((accountAddress) =>\n accountAddress.toLowerCase(),\n );\n\n if (!normalizedAccounts.includes(address.toLowerCase())) {\n throw providerErrors.unauthorized();\n }\n\n return address;\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 parameters'),\n );\n }\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.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qDAAiE;AAEjE,uDAAiD;AAEjD,2CAA+C;AAE/C;;;;;;;;;GASG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAY,EACZ,MAAc,EACd,6BAAoE;IAEpE,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,IAAA,oBAAY,E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AClB,CAAC","sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { isHexAddress } from '@metamask/utils';\n\n/**\n * Validates address format, checks user eth_accounts permissions.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param origin - The origin string for permission checking.\n * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.\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 validateAndNormalizeAddress(\n address: Hex,\n origin: string,\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>,\n): Promise<Hex> {\n if (\n typeof address !== 'string' ||\n address.length === 0 ||\n !isHexAddress(address)\n ) {\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an EVM address.`,\n });\n }\n\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getPermittedAccountsForOrigin(origin);\n\n // Validate and convert each account address to normalized Hex\n const normalizedAccounts: string[] = accounts.map((accountAddress) =>\n accountAddress.toLowerCase(),\n );\n\n if (!normalizedAccounts.includes(address.toLowerCase())) {\n throw providerErrors.unauthorized();\n }\n\n return address;\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 parameters'),\n );\n }\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 (failure) =>\n `${failure.path.join(' > ')}${failure.path.length ? ' - ' : ''}${failure.message}`,\n )\n .join('\\n')}`;\n}\n"]}
package/dist/utils.mjs CHANGED
@@ -52,7 +52,7 @@ export function validateParams(value, struct) {
52
52
  function formatValidationError(error, message) {
53
53
  return `${message}\n\n${error
54
54
  .failures()
55
- .map((f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`)
55
+ .map((failure) => `${failure.path.join(' > ')}${failure.path.length ? ' - ' : ''}${failure.message}`)
56
56
  .join('\n')}`;
57
57
  }
58
58
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAEjE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAE/C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAY,EACZ,MAAc,EACd,6BAAoE;IAEpE,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,YAAY,CAAC,OAAO,CAAC,EACtB,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,kDAAkD;SAC5D,CAAC,CAAC;IACL,CAAC;IAED,iEAAiE;IACjE,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,MAAM,6BAA6B,CAAC,MAAM,CAAC,CAAC;IAE7D,8DAA8D;IAC9D,MAAM,kBAAkB,GAAa,QAAQ,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CACnE,cAAc,CAAC,WAAW,EAAE,CAC7B,CAAC;IAEF,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QACxD,MAAM,cAAc,CAAC,YAAY,EAAE,CAAC;IACtC,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,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,oBAAoB,CAAC,CACnD,CAAC;IACJ,CAAC;AACH,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 { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { isHexAddress } from '@metamask/utils';\n\n/**\n * Validates address format, checks user eth_accounts permissions.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param origin - The origin string for permission checking.\n * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.\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 validateAndNormalizeAddress(\n address: Hex,\n origin: string,\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>,\n): Promise<Hex> {\n if (\n typeof address !== 'string' ||\n address.length === 0 ||\n !isHexAddress(address)\n ) {\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an EVM address.`,\n });\n }\n\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getPermittedAccountsForOrigin(origin);\n\n // Validate and convert each account address to normalized Hex\n const normalizedAccounts: string[] = accounts.map((accountAddress) =>\n accountAddress.toLowerCase(),\n );\n\n if (!normalizedAccounts.includes(address.toLowerCase())) {\n throw providerErrors.unauthorized();\n }\n\n return address;\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 parameters'),\n );\n }\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":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAEjE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAE/C;;;;;;;;;GASG;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C,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CACrF;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { isHexAddress } from '@metamask/utils';\n\n/**\n * Validates address format, checks user eth_accounts permissions.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param origin - The origin string for permission checking.\n * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.\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 validateAndNormalizeAddress(\n address: Hex,\n origin: string,\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>,\n): Promise<Hex> {\n if (\n typeof address !== 'string' ||\n address.length === 0 ||\n !isHexAddress(address)\n ) {\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an EVM address.`,\n });\n }\n\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getPermittedAccountsForOrigin(origin);\n\n // Validate and convert each account address to normalized Hex\n const normalizedAccounts: string[] = accounts.map((accountAddress) =>\n accountAddress.toLowerCase(),\n );\n\n if (!normalizedAccounts.includes(address.toLowerCase())) {\n throw providerErrors.unauthorized();\n }\n\n return address;\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 parameters'),\n );\n }\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 (failure) =>\n `${failure.path.join(' > ')}${failure.path.length ? ' - ' : ''}${failure.message}`,\n )\n .join('\\n')}`;\n}\n"]}
@@ -38,10 +38,7 @@ async function walletGetAccountUpgradeStatus(req, res, hooks) {
38
38
  const normalizedAccount = await (0, utils_2.validateAndNormalizeAddress)(account, origin, hooks.getPermittedAccountsForOrigin);
39
39
  // Use current chain ID if not provided
40
40
  let targetChainId;
41
- if (chainId !== undefined) {
42
- targetChainId = chainId;
43
- }
44
- else {
41
+ if (chainId === undefined) {
45
42
  const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
46
43
  if (!currentChainIdForDomain) {
47
44
  throw rpc_errors_1.rpcErrors.invalidParams({
@@ -50,6 +47,9 @@ async function walletGetAccountUpgradeStatus(req, res, hooks) {
50
47
  }
51
48
  targetChainId = currentChainIdForDomain;
52
49
  }
50
+ else {
51
+ targetChainId = chainId;
52
+ }
53
53
  const { isSupported } = await hooks.isEip7702Supported({
54
54
  address: normalizedAccount,
55
55
  chainId: targetChainId,
@@ -1 +1 @@
1
- {"version":3,"file":"wallet_getAccountUpgradeStatus.cjs","sourceRoot":"","sources":["../src/wallet_getAccountUpgradeStatus.ts"],"names":[],"mappings":";;;AAAA,qDAA+D;AAC/D,2CAAkD;AAOlD,+CAA0D;AAE1D,uCAA8D;AAC9D,uCAAsE;AAatE,MAAM,iBAAiB,GAAG,KAAK,EAC7B,OAAe,EACf,eAAuB,EACvB,OAA6E,EACd,EAAE;IACjE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI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IAAI,KAAK,YAAY,yBAAY,EAAE,CAAC;YAClC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,sBAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,yCAAyC,IAAA,uBAAe,EAAC,KAAK,CAAC,EAAE;SAC3E,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AApFD,sEAoFC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { getErrorMessage } from '@metamask/utils';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport { DELEGATION_INDICATOR_PREFIX } from './constants';\nimport type { GetAccountUpgradeStatusParams } from './types';\nimport { GetAccountUpgradeStatusParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletGetAccountUpgradeStatusHooks = {\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n getCode: (address: string, networkClientId: string) => Promise<string | null>;\n getSelectedNetworkClientIdForChain: (chainId: string) => string | null;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n};\n\nconst isAccountUpgraded = async (\n address: string,\n networkClientId: string,\n getCode: (address: string, networkClientId: string) => Promise<string | null>,\n): Promise<{ isUpgraded: boolean; upgradedAddress: Hex | null }> => {\n const code = await getCode(address, networkClientId);\n if (!code || code === '0x' || code.length <= 2) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars\n if (code.length !== expectedLength) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n // Extract the 20-byte address (40 hex characters after the prefix)\n const upgradedAddress = `0x${code.slice(8, 48)}` as const;\n\n return { isUpgraded: true, upgradedAddress };\n};\n\n/**\n * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade status checking.\n */\nexport async function walletGetAccountUpgradeStatus(\n req: JsonRpcRequest<GetAccountUpgradeStatusParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletGetAccountUpgradeStatusHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, GetAccountUpgradeStatusParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current chain ID if not provided\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `Could not determine current chain ID for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n const { isSupported } = await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: targetChainId,\n });\n\n if (!isSupported) {\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded: false,\n upgradedAddress: null,\n chainId: targetChainId,\n };\n return;\n }\n\n try {\n // Get the network configuration for the target chain\n const hexChainId = targetChainId;\n const networkClientId =\n hooks.getSelectedNetworkClientIdForChain(hexChainId);\n\n if (!networkClientId) {\n throw rpcErrors.invalidParams({\n message: `Network client ID not found for chain ID ${targetChainId}`,\n });\n }\n\n // Check if the account is upgraded using the EIP7702 utils\n const { isUpgraded, upgradedAddress } = await isAccountUpgraded(\n normalizedAccount,\n networkClientId,\n hooks.getCode,\n );\n\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded,\n upgradedAddress,\n chainId: targetChainId,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"wallet_getAccountUpgradeStatus.cjs","sourceRoot":"","sources":["../src/wallet_getAccountUpgradeStatus.ts"],"names":[],"mappings":";;;AAAA,qDAA+D;AAC/D,2CAAkD;AAOlD,+CAA0D;AAE1D,uCAA8D;AAC9D,uCAAsE;AAatE,MAAM,iBAAiB,GAAG,KAAK,EAC7B,OAAe,EACf,eAAuB,EACvB,OAA6E,EACd,EAAE;IACjE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,uCAA2B,CAAC,EAAE,CAAC;QAClD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,MAAM,cAAc,GAAG,uCAA2B,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,0BAA0B;IAC1F,IAAI,IAAI,CAAC,MAAM,KAAK,cAAc,EAAE,CAAC;QACnC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,mEAAmE;IACnE,MAAM,eAAe,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAW,CAAC;IAE1D,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC;AAC/C,CAAC,CAAC;AAEF;;;;;;GAMG;AACI,KAAK,UAAU,6BAA6B,CACjD,GAAuE,EACv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AAI,CAAC,eAAe,EAAE,CAAC;YACrB,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,4CAA4C,aAAa,EAAE;aACrE,CAAC,CAAC;QACL,CAAC;QAED,2DAA2D;QAC3D,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,MAAM,iBAAiB,CAC7D,iBAAiB,EACjB,eAAe,EACf,KAAK,CAAC,OAAO,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,WAAW;YACX,OAAO,EAAE,iBAAiB;YAC1B,UAAU;YACV,eAAe;YACf,OAAO,EAAE,aAAa;SACvB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,4BAA4B;QAC5B,IAAI,KAAK,YAAY,yBAAY,EAAE,CAAC;YAClC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,sBAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,yCAAyC,IAAA,uBAAe,EAAC,KAAK,CAAC,EAAE;SAC3E,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AApFD,sEAoFC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { getErrorMessage } from '@metamask/utils';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport { DELEGATION_INDICATOR_PREFIX } from './constants';\nimport type { GetAccountUpgradeStatusParams } from './types';\nimport { GetAccountUpgradeStatusParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletGetAccountUpgradeStatusHooks = {\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n getCode: (address: string, networkClientId: string) => Promise<string | null>;\n getSelectedNetworkClientIdForChain: (chainId: string) => string | null;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n};\n\nconst isAccountUpgraded = async (\n address: string,\n networkClientId: string,\n getCode: (address: string, networkClientId: string) => Promise<string | null>,\n): Promise<{ isUpgraded: boolean; upgradedAddress: Hex | null }> => {\n const code = await getCode(address, networkClientId);\n if (!code || code === '0x' || code.length <= 2) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars\n if (code.length !== expectedLength) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n // Extract the 20-byte address (40 hex characters after the prefix)\n const upgradedAddress = `0x${code.slice(8, 48)}` as const;\n\n return { isUpgraded: true, upgradedAddress };\n};\n\n/**\n * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade status checking.\n */\nexport async function walletGetAccountUpgradeStatus(\n req: JsonRpcRequest<GetAccountUpgradeStatusParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletGetAccountUpgradeStatusHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, GetAccountUpgradeStatusParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current chain ID if not provided\n let targetChainId: Hex;\n if (chainId === undefined) {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `Could not determine current chain ID for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n } else {\n targetChainId = chainId;\n }\n\n const { isSupported } = await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: targetChainId,\n });\n\n if (!isSupported) {\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded: false,\n upgradedAddress: null,\n chainId: targetChainId,\n };\n return;\n }\n\n try {\n // Get the network configuration for the target chain\n const hexChainId = targetChainId;\n const networkClientId =\n hooks.getSelectedNetworkClientIdForChain(hexChainId);\n\n if (!networkClientId) {\n throw rpcErrors.invalidParams({\n message: `Network client ID not found for chain ID ${targetChainId}`,\n });\n }\n\n // Check if the account is upgraded using the EIP7702 utils\n const { isUpgraded, upgradedAddress } = await isAccountUpgraded(\n normalizedAccount,\n networkClientId,\n hooks.getCode,\n );\n\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded,\n upgradedAddress,\n chainId: targetChainId,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
@@ -35,10 +35,7 @@ export async function walletGetAccountUpgradeStatus(req, res, hooks) {
35
35
  const normalizedAccount = await validateAndNormalizeAddress(account, origin, hooks.getPermittedAccountsForOrigin);
36
36
  // Use current chain ID if not provided
37
37
  let targetChainId;
38
- if (chainId !== undefined) {
39
- targetChainId = chainId;
40
- }
41
- else {
38
+ if (chainId === undefined) {
42
39
  const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
43
40
  if (!currentChainIdForDomain) {
44
41
  throw rpcErrors.invalidParams({
@@ -47,6 +44,9 @@ export async function walletGetAccountUpgradeStatus(req, res, hooks) {
47
44
  }
48
45
  targetChainId = currentChainIdForDomain;
49
46
  }
47
+ else {
48
+ targetChainId = chainId;
49
+ }
50
50
  const { isSupported } = await hooks.isEip7702Supported({
51
51
  address: normalizedAccount,
52
52
  chainId: targetChainId,
@@ -1 +1 @@
1
- {"version":3,"file":"wallet_getAccountUpgradeStatus.mjs","sourceRoot":"","sources":["../src/wallet_getAccountUpgradeStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EA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4CAA4C,aAAa,EAAE;aACrE,CAAC,CAAC;QACL,CAAC;QAED,2DAA2D;QAC3D,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,MAAM,iBAAiB,CAC7D,iBAAiB,EACjB,eAAe,EACf,KAAK,CAAC,OAAO,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,WAAW;YACX,OAAO,EAAE,iBAAiB;YAC1B,UAAU;YACV,eAAe;YACf,OAAO,EAAE,aAAa;SACvB,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,4BAA4B;QAC5B,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,SAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,yCAAyC,eAAe,CAAC,KAAK,CAAC,EAAE;SAC3E,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport { getErrorMessage } from '@metamask/utils';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport { DELEGATION_INDICATOR_PREFIX } from './constants';\nimport type { GetAccountUpgradeStatusParams } from './types';\nimport { GetAccountUpgradeStatusParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletGetAccountUpgradeStatusHooks = {\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n getCode: (address: string, networkClientId: string) => Promise<string | null>;\n getSelectedNetworkClientIdForChain: (chainId: string) => string | null;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n};\n\nconst isAccountUpgraded = async (\n address: string,\n networkClientId: string,\n getCode: (address: string, networkClientId: string) => Promise<string | null>,\n): Promise<{ isUpgraded: boolean; upgradedAddress: Hex | null }> => {\n const code = await getCode(address, networkClientId);\n if (!code || code === '0x' || code.length <= 2) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars\n if (code.length !== expectedLength) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n // Extract the 20-byte address (40 hex characters after the prefix)\n const upgradedAddress = `0x${code.slice(8, 48)}` as const;\n\n return { isUpgraded: true, upgradedAddress };\n};\n\n/**\n * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade status checking.\n */\nexport async function walletGetAccountUpgradeStatus(\n req: JsonRpcRequest<GetAccountUpgradeStatusParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletGetAccountUpgradeStatusHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, GetAccountUpgradeStatusParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current chain ID if not provided\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `Could not determine current chain ID for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n const { isSupported } = await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: targetChainId,\n });\n\n if (!isSupported) {\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded: false,\n upgradedAddress: null,\n chainId: targetChainId,\n };\n return;\n }\n\n try {\n // Get the network configuration for the target chain\n const hexChainId = targetChainId;\n const networkClientId =\n hooks.getSelectedNetworkClientIdForChain(hexChainId);\n\n if (!networkClientId) {\n throw rpcErrors.invalidParams({\n message: `Network client ID not found for chain ID ${targetChainId}`,\n });\n }\n\n // Check if the account is upgraded using the EIP7702 utils\n const { isUpgraded, upgradedAddress } = await isAccountUpgraded(\n normalizedAccount,\n networkClientId,\n hooks.getCode,\n );\n\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded,\n upgradedAddress,\n chainId: targetChainId,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"wallet_getAccountUpgradeStatus.mjs","sourceRoot":"","sources":["../src/wallet_getAccountUpgradeStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAC/D,OAAO,EAAE,eAAe,EAAE,wBAAwB;AAOlD,OAAO,EAAE,2BAA2B,EAAE,wBAAoB;AAE1D,OAAO,EAAE,mCAAmC,EAAE,oBAAgB;AAC9D,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,oBAAgB;AAatE,MAAM,iBAAiB,GAAG,KAAK,EAC7B,OAAe,EACf,eAAuB,EACvB,OAA6E,EACd,EAAE;IACjE,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IACrD,IAAI,CAAC,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC;IACtD,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,2BAA2B,CAAC,EAAE,CAAC;QAClD,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,e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ask/utils';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport { DELEGATION_INDICATOR_PREFIX } from './constants';\nimport type { GetAccountUpgradeStatusParams } from './types';\nimport { GetAccountUpgradeStatusParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletGetAccountUpgradeStatusHooks = {\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n getCode: (address: string, networkClientId: string) => Promise<string | null>;\n getSelectedNetworkClientIdForChain: (chainId: string) => string | null;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n};\n\nconst isAccountUpgraded = async (\n address: string,\n networkClientId: string,\n getCode: (address: string, networkClientId: string) => Promise<string | null>,\n): Promise<{ isUpgraded: boolean; upgradedAddress: Hex | null }> => {\n const code = await getCode(address, networkClientId);\n if (!code || code === '0x' || code.length <= 2) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars\n if (code.length !== expectedLength) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n // Extract the 20-byte address (40 hex characters after the prefix)\n const upgradedAddress = `0x${code.slice(8, 48)}` as const;\n\n return { isUpgraded: true, upgradedAddress };\n};\n\n/**\n * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade status checking.\n */\nexport async function walletGetAccountUpgradeStatus(\n req: JsonRpcRequest<GetAccountUpgradeStatusParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletGetAccountUpgradeStatusHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, GetAccountUpgradeStatusParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current chain ID if not provided\n let targetChainId: Hex;\n if (chainId === undefined) {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `Could not determine current chain ID for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n } else {\n targetChainId = chainId;\n }\n\n const { isSupported } = await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: targetChainId,\n });\n\n if (!isSupported) {\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded: false,\n upgradedAddress: null,\n chainId: targetChainId,\n };\n return;\n }\n\n try {\n // Get the network configuration for the target chain\n const hexChainId = targetChainId;\n const networkClientId =\n hooks.getSelectedNetworkClientIdForChain(hexChainId);\n\n if (!networkClientId) {\n throw rpcErrors.invalidParams({\n message: `Network client ID not found for chain ID ${targetChainId}`,\n });\n }\n\n // Check if the account is upgraded using the EIP7702 utils\n const { isUpgraded, upgradedAddress } = await isAccountUpgraded(\n normalizedAccount,\n networkClientId,\n hooks.getCode,\n );\n\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded,\n upgradedAddress,\n chainId: targetChainId,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
@@ -20,10 +20,7 @@ async function walletUpgradeAccount(req, res, hooks) {
20
20
  const normalizedAccount = await (0, utils_1.validateAndNormalizeAddress)(account, origin, hooks.getPermittedAccountsForOrigin);
21
21
  // Use current app selected chain ID if not passed as a param
22
22
  let targetChainId;
23
- if (chainId !== undefined) {
24
- targetChainId = chainId;
25
- }
26
- else {
23
+ if (chainId === undefined) {
27
24
  const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
28
25
  if (!currentChainIdForDomain) {
29
26
  throw rpc_errors_1.rpcErrors.invalidParams({
@@ -32,6 +29,9 @@ async function walletUpgradeAccount(req, res, hooks) {
32
29
  }
33
30
  targetChainId = currentChainIdForDomain;
34
31
  }
32
+ else {
33
+ targetChainId = chainId;
34
+ }
35
35
  try {
36
36
  // Get the EIP7702 network configuration for the target chain
37
37
  const hexChainId = targetChainId;
@@ -1 +1 @@
1
- {"version":3,"file":"wallet_upgradeAccount.cjs","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":";;;AAAA,qDAA+D;AAQ/D,uCAAqD;AACrD,uCAAsE;AAgBtE;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAA8D,EAC9D,GAA2B,EAC3B,KAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,wCAAwC;IACxC,IAAA,sBAAc,EAAC,MAAM,EAAE,kCAA0B,CAAC,CAAC;IAEnD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEpC,sEAAsE;IACtE,MAAM,iBAAiB,GAAG,MAAM,IAAA,mCAA2B,EACzD,OAAO,EACP,MAAM,EACN,KAAK,CAAC,6BAA6B,CACpC,CAAC;IAEF,6DAA6D;IAC7D,IAAI,aAAkB,CAAC;IACvB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,aAAa,GAAG,OAAO,CAAC;IAC1B,CAAC;SAAM,CAAC;QACN,MAAM,uBAAuB,GAAG,KAAK,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC;QACzE,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,8CAA8C,MAAM,EAAE;aAChE,CAAC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\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport type { UpgradeAccountParams } from './types';\nimport { UpgradeAccountParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletUpgradeAccountHooks = {\n upgradeAccount: (\n address: string,\n upgradeContractAddress: string,\n chainId?: Hex,\n ) => Promise<{ transactionHash: string; delegatedTo: string }>;\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n};\n\n/**\n * The RPC method handler middleware for `wallet_upgradeAccount`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade functionality.\n */\nexport async function walletUpgradeAccount(\n req: JsonRpcRequest<UpgradeAccountParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletUpgradeAccountHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, UpgradeAccountParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current app selected chain ID if not passed as a param\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `No network configuration found for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n try {\n // Get the EIP7702 network configuration for the target chain\n const hexChainId = targetChainId;\n const { isSupported, upgradeContractAddress } =\n await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: hexChainId,\n });\n\n if (!isSupported) {\n throw rpcErrors.invalidParams({\n message: `Account upgrade not supported on chain ID ${targetChainId}`,\n });\n }\n\n if (!upgradeContractAddress) {\n throw rpcErrors.invalidParams({\n message: `No upgrade contract address available for chain ID ${targetChainId}`,\n });\n }\n\n // Perform the upgrade using existing EIP-7702 functionality\n const result = await hooks.upgradeAccount(\n normalizedAccount,\n upgradeContractAddress,\n targetChainId,\n );\n\n res.result = {\n transactionHash: result.transactionHash,\n upgradedAccount: normalizedAccount,\n delegatedTo: result.delegatedTo,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"wallet_upgradeAccount.cjs","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":";;;AAAA,qDAA+D;AAQ/D,uCAAqD;AACrD,uCAAsE;AAgBtE;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAA8D,EAC9D,GAA2B,EAC3B,KAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,wCAAwC;IACxC,IAAA,sBAAc,EAAC,MAAM,EAAE,kCAA0B,CAAC,CAAC;IAEnD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEpC,sEAAsE;IACtE,MAAM,iBAAiB,GAAG,MAAM,IAAA,mCAA2B,EACzD,OAAO,EACP,MAAM,EACN,KAAK,CAAC,6BAA6B,CACpC,CAAC;IAEF,6DAA6D;IAC7D,IAAI,aAAkB,CAAC;IACvB,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,uBAAuB,GAAG,KAAK,CAAC,0BAA0B,CAAC,MAAM,CAAC,CAAC;QACzE,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,8CAA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,CAAC;AACH,CAAC;AA3ED,oDA2EC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport type { UpgradeAccountParams } from './types';\nimport { UpgradeAccountParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletUpgradeAccountHooks = {\n upgradeAccount: (\n address: string,\n upgradeContractAddress: string,\n chainId?: Hex,\n ) => Promise<{ transactionHash: string; delegatedTo: string }>;\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n};\n\n/**\n * The RPC method handler middleware for `wallet_upgradeAccount`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade functionality.\n */\nexport async function walletUpgradeAccount(\n req: JsonRpcRequest<UpgradeAccountParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletUpgradeAccountHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, UpgradeAccountParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current app selected chain ID if not passed as a param\n let targetChainId: Hex;\n if (chainId === undefined) {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `No network configuration found for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n } else {\n targetChainId = chainId;\n }\n\n try {\n // Get the EIP7702 network configuration for the target chain\n const hexChainId = targetChainId;\n const { isSupported, upgradeContractAddress } =\n await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: hexChainId,\n });\n\n if (!isSupported) {\n throw rpcErrors.invalidParams({\n message: `Account upgrade not supported on chain ID ${targetChainId}`,\n });\n }\n\n if (!upgradeContractAddress) {\n throw rpcErrors.invalidParams({\n message: `No upgrade contract address available for chain ID ${targetChainId}`,\n });\n }\n\n // Perform the upgrade using existing EIP-7702 functionality\n const result = await hooks.upgradeAccount(\n normalizedAccount,\n upgradeContractAddress,\n targetChainId,\n );\n\n res.result = {\n transactionHash: result.transactionHash,\n upgradedAccount: normalizedAccount,\n delegatedTo: result.delegatedTo,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"]}
@@ -17,10 +17,7 @@ export async function walletUpgradeAccount(req, res, hooks) {
17
17
  const normalizedAccount = await validateAndNormalizeAddress(account, origin, hooks.getPermittedAccountsForOrigin);
18
18
  // Use current app selected chain ID if not passed as a param
19
19
  let targetChainId;
20
- if (chainId !== undefined) {
21
- targetChainId = chainId;
22
- }
23
- else {
20
+ if (chainId === undefined) {
24
21
  const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
25
22
  if (!currentChainIdForDomain) {
26
23
  throw rpcErrors.invalidParams({
@@ -29,6 +26,9 @@ export async function walletUpgradeAccount(req, res, hooks) {
29
26
  }
30
27
  targetChainId = currentChainIdForDomain;
31
28
  }
29
+ else {
30
+ targetChainId = chainId;
31
+ }
32
32
  try {
33
33
  // Get the EIP7702 network configuration for the target chain
34
34
  const hexChainId = targetChainId;
@@ -1 +1 @@
1
- {"version":3,"file":"wallet_upgradeAccount.mjs","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAQ/D,OAAO,EAAE,0BAA0B,EAAE,oBAAgB;AACrD,OAAO,EA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,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,sDAAsD,aAAa,EAAE;aAC/E,CAAC,CAAC;QACL,CAAC;QAED,4DAA4D;QAC5D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,cAAc,CACvC,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,eAAe,EAAE,iBAAiB;YAClC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,4BAA4B;QAC5B,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,SAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAChG,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport type { UpgradeAccountParams } from './types';\nimport { UpgradeAccountParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletUpgradeAccountHooks = {\n upgradeAccount: (\n address: string,\n upgradeContractAddress: string,\n chainId?: Hex,\n ) => Promise<{ transactionHash: string; delegatedTo: string }>;\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n};\n\n/**\n * The RPC method handler middleware for `wallet_upgradeAccount`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade functionality.\n */\nexport async function walletUpgradeAccount(\n req: JsonRpcRequest<UpgradeAccountParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletUpgradeAccountHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, UpgradeAccountParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current app selected chain ID if not passed as a param\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `No network configuration found for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n try {\n // Get the EIP7702 network configuration for the target chain\n const hexChainId = targetChainId;\n const { isSupported, upgradeContractAddress } =\n await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: hexChainId,\n });\n\n if (!isSupported) {\n throw rpcErrors.invalidParams({\n message: `Account upgrade not supported on chain ID ${targetChainId}`,\n });\n }\n\n if (!upgradeContractAddress) {\n throw rpcErrors.invalidParams({\n message: `No upgrade contract address available for chain ID ${targetChainId}`,\n });\n }\n\n // Perform the upgrade using existing EIP-7702 functionality\n const result = await hooks.upgradeAccount(\n normalizedAccount,\n upgradeContractAddress,\n targetChainId,\n );\n\n res.result = {\n transactionHash: result.transactionHash,\n upgradedAccount: normalizedAccount,\n delegatedTo: result.delegatedTo,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"wallet_upgradeAccount.mjs","source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I,CAAC,WAAW,EAAE,CAAC;YACjB,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,6CAA6C,aAAa,EAAE;aACtE,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,sDAAsD,aAAa,EAAE;aAC/E,CAAC,CAAC;QACL,CAAC;QAED,4DAA4D;QAC5D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,cAAc,CACvC,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,eAAe,EAAE,iBAAiB;YAClC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,4BAA4B;QAC5B,IAAI,KAAK,YAAY,YAAY,EAAE,CAAC;YAClC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,SAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAChG,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport type { UpgradeAccountParams } from './types';\nimport { UpgradeAccountParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletUpgradeAccountHooks = {\n upgradeAccount: (\n address: string,\n upgradeContractAddress: string,\n chainId?: Hex,\n ) => Promise<{ transactionHash: string; delegatedTo: string }>;\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n};\n\n/**\n * The RPC method handler middleware for `wallet_upgradeAccount`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade functionality.\n */\nexport async function walletUpgradeAccount(\n req: JsonRpcRequest<UpgradeAccountParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletUpgradeAccountHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, UpgradeAccountParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current app selected chain ID if not passed as a param\n let targetChainId: Hex;\n if (chainId === undefined) {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `No network configuration found for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n } else {\n targetChainId = chainId;\n }\n\n try {\n // Get the EIP7702 network configuration for the target chain\n const hexChainId = targetChainId;\n const { isSupported, upgradeContractAddress } =\n await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: hexChainId,\n });\n\n if (!isSupported) {\n throw rpcErrors.invalidParams({\n message: `Account upgrade not supported on chain ID ${targetChainId}`,\n });\n }\n\n if (!upgradeContractAddress) {\n throw rpcErrors.invalidParams({\n message: `No upgrade contract address available for chain ID ${targetChainId}`,\n });\n }\n\n // Perform the upgrade using existing EIP-7702 functionality\n const result = await hooks.upgradeAccount(\n normalizedAccount,\n upgradeContractAddress,\n targetChainId,\n );\n\n res.result = {\n transactionHash: result.transactionHash,\n upgradedAccount: normalizedAccount,\n delegatedTo: result.delegatedTo,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/eip-7702-internal-rpc-middleware",
3
- "version": "0.1.0-preview-cb4a07d5",
3
+ "version": "0.1.0-preview-eb60826c",
4
4
  "description": "Implements internal JSON-RPC methods for EIP-7702 account upgrade functionality",
5
5
  "keywords": [
6
6
  "MetaMask",