Skip to content

Refactor network ids#152

Merged
jolestar merged 4 commits intomainfrom
refactor_network_ids
Dec 26, 2025
Merged

Refactor network ids#152
jolestar merged 4 commits intomainfrom
refactor_network_ids

Conversation

@jolestar
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings December 26, 2025 02:03
@vercel
Copy link

vercel bot commented Dec 26, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
x402x-web Error Error Dec 26, 2025 2:15am

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 26, 2025

Deploying x402-exec with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3b326e8
Status: ✅  Deploy successful!
Preview URL: https://8de837cf.x402-exec.pages.dev
Branch Preview URL: https://refactor-network-ids.x402-exec.pages.dev

View logs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors network identifier handling by renaming functions and variables to better reflect their purpose as "aliases" for v1 compatibility rather than canonical "names". The changes improve code clarity by explicitly distinguishing between CAIP-2 identifiers (the canonical v2 format) and human-readable aliases (v1 legacy names).

Key Changes:

  • Renamed getNetworkNamegetNetworkAlias to clarify that these are v1 compatibility aliases, not canonical names
  • Renamed getSupportedNetworkNamesgetSupportedNetworkAliases for consistency
  • Renamed getSupportedNetworksV2getSupportedNetworkIds to better describe CAIP-2 identifiers
  • Updated network configuration keys from human-readable names to CAIP-2 format internally
  • Removed legacy-compat.ts file containing unused legacy compatibility shims

Reviewed changes

Copilot reviewed 19 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
typescript/packages/facilitator-sdk/test/settlement.test.ts Updated mock function name from getNetworkName to getNetworkAlias
typescript/packages/facilitator-sdk/test/integration.test.ts Updated mock function name from getNetworkName to getNetworkAlias
typescript/packages/facilitator-sdk/test/facilitator.test.ts Updated mock function name from getNetworkName to getNetworkAlias
typescript/packages/facilitator-sdk/src/types.d.ts Updated type declaration for renamed function
typescript/packages/facilitator-sdk/src/settlement.ts Updated function imports and variable names to use "alias" terminology
typescript/packages/extensions/src/utils.ts Updated function import and variable names for network alias handling
typescript/packages/extensions/src/networks.ts Refactored to use CAIP-2 as internal keys with normalization function; renamed exports to use "alias" terminology
typescript/packages/extensions/src/network-utils.ts Renamed constants and functions to use "alias" terminology; moved NETWORK_ALIASES_V1_TO_V2 definition earlier as primary mapping
typescript/packages/extensions/src/network-utils.test.ts Updated test to use toCanonicalNetworkKey instead of removed getNetworkId
typescript/packages/extensions/src/network-alignment.test.ts Updated function calls from getSupportedNetworksV2 to getSupportedNetworkIds
typescript/packages/extensions/src/legacy-compat.ts Removed entire file containing unused legacy compatibility shims
typescript/packages/extensions/src/index.ts Updated exports to reflect renamed functions and removed legacy compatibility exports
typescript/packages/extensions/src/hooks/transfer.ts Updated documentation and function signature to accept both CAIP-2 and human-readable names
typescript/packages/extensions/src/hooks/demo.ts Updated documentation and function signatures to accept both identifier formats
typescript/packages/extensions/src/chains.ts Refactored to normalize network identifiers internally using NETWORK_ALIASES_V1_TO_V2
facilitator/test/unit/token-validation.test.ts Updated error message expectation from "Unsupported network" to "Unknown network"
facilitator/src/types.d.ts Updated type declaration for renamed function
facilitator/src/network-utils.ts Updated function import and usage from getNetworkName to getNetworkAlias
examples/showcase/server/src/index.ts Updated function calls from getSupportedNetworksV2 to getSupportedNetworkIds
examples/showcase/client/src/wagmi.config.ts Updated function call from getSupportedNetworkNames to getSupportedNetworkAliases
examples/showcase/client/src/config.ts Updated function call from getSupportedNetworkNames to getSupportedNetworkAliases

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 43 to 57
function normalizeToCAIP2(network: string | Network): Network {
// Already CAIP-2 format
if (network.startsWith('eip155:')) {
return network as Network;
}
// Convert from human-readable name using alias mapping
const caip2 = NETWORK_ALIASES_V1_TO_V2[network];
if (!caip2) {
throw new Error(
`Unknown network: ${network}. ` +
`Supported networks: ${Object.keys(NETWORK_ALIASES_V1_TO_V2).join(", ")}`
);
}
return caip2;
}
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The normalizeToCAIP2 function accepts any string starting with 'eip155:' without validating whether it's actually a supported network. This could lead to undefined behavior when an unsupported CAIP-2 identifier is passed. Consider validating that the CAIP-2 identifier exists in NETWORK_ALIASES_V1_TO_V2 values or the networks configuration.

Copilot uses AI. Check for mistakes.
Comment on lines 86 to 102
export function getChain(network: string | Network): Chain {
let chainId: number;

// If already CAIP-2 format, extract chainId directly
if (network.startsWith('eip155:')) {
chainId = parseInt(network.split(":")[1]);
} else {
// Convert name to CAIP-2, then extract chainId
const caip2 = NETWORK_ALIASES_V1_TO_V2[network];
if (!caip2) {
throw new Error(
`Unknown network: ${network}. ` +
`Supported networks: ${Object.keys(NETWORK_ALIASES_V1_TO_V2).join(", ")}`
);
}
chainId = parseInt(caip2.split(":")[1]);
}
Copy link

Copilot AI Dec 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getChain function accepts any CAIP-2 identifier starting with 'eip155:' without validating whether it's a supported network in NETWORK_ALIASES_V1_TO_V2. This means unsupported chain IDs could pass through if they exist in viem's chain list but aren't configured in the application. Consider validating the CAIP-2 identifier against NETWORK_ALIASES before extracting the chain ID to ensure consistency with the supported networks configuration.

Copilot uses AI. Check for mistakes.
@jolestar jolestar merged commit 8a58a56 into main Dec 26, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant