@coinbase/cdp-sdk
Version:
SDK for interacting with the Coinbase Developer Platform Wallet API
98 lines • 5.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CDP_NETWORK_TO_CAIP2 = exports.solanaDevnetCaip2 = exports.solanaMainnetCaip2 = exports.worldSepoliaCaip2 = exports.worldCaip2 = exports.arbitrumCaip2 = exports.polygonCaip2 = exports.baseSepoliaCaip2 = exports.baseMainnetCaip2 = exports.CHAIN_ID_TO_CDP_NETWORK = void 0;
exports.getDefaultEvmRpcUrls = getDefaultEvmRpcUrls;
/* Network and RPC constants for x402 signing. */
const getBaseNodeRpcUrl_js_1 = require("../accounts/evm/getBaseNodeRpcUrl.js");
const coinbaseDeveloperPlatformAPIs_schemas_js_1 = require("../openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js");
const EIP155_CAIP2_PREFIX = "eip155:";
const baseMainnetChainId = 8453;
const baseSepoliaChainId = 84532;
const polygonChainId = 137;
const arbitrumChainId = 42161;
const worldChainId = 480;
const worldSepoliaChainId = 4801;
const optimismChainId = 10;
const zoraChainId = 7777777;
const bnbChainId = 56;
const avalancheChainId = 43114;
const ethereumSepoliaChainId = 11155111;
/**
* Maps EIP-155 chain IDs to CDP SDK network names for SCW typed-data signing.
*
* EVM CAIP-2 identifiers are derived from these chain IDs using `toEip155Caip2`.
*/
exports.CHAIN_ID_TO_CDP_NETWORK = {
[baseMainnetChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.base,
[baseSepoliaChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem["base-sepolia"],
[polygonChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.polygon,
[arbitrumChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.arbitrum,
[worldChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.world,
[worldSepoliaChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem["world-sepolia"],
[optimismChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.optimism,
[zoraChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.zora,
[bnbChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.bnb,
[avalancheChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem.avalanche,
[ethereumSepoliaChainId]: coinbaseDeveloperPlatformAPIs_schemas_js_1.EvmNetworkCriterionNetworksItem["ethereum-sepolia"],
};
/** CAIP-2 network identifiers for CDP-supported chains. */
exports.baseMainnetCaip2 = toEip155Caip2(baseMainnetChainId);
exports.baseSepoliaCaip2 = toEip155Caip2(baseSepoliaChainId);
exports.polygonCaip2 = toEip155Caip2(polygonChainId);
exports.arbitrumCaip2 = toEip155Caip2(arbitrumChainId);
exports.worldCaip2 = toEip155Caip2(worldChainId);
exports.worldSepoliaCaip2 = toEip155Caip2(worldSepoliaChainId);
exports.solanaMainnetCaip2 = coinbaseDeveloperPlatformAPIs_schemas_js_1.X402V2Network["solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"];
exports.solanaDevnetCaip2 = coinbaseDeveloperPlatformAPIs_schemas_js_1.X402V2Network["solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"];
/**
* Converts an EIP-155 chain ID into a typed CAIP-2 identifier.
*
* @param chainId - EIP-155 chain ID.
* @returns CAIP-2 network identifier in `eip155:<chainId>` format.
*/
function toEip155Caip2(chainId) {
return `${EIP155_CAIP2_PREFIX}${chainId}`;
}
/**
* Maps CDP SDK network names to their EIP-155 CAIP-2 identifiers.
*
* Derived by inverting CHAIN_ID_TO_CDP_NETWORK. Used by network-scoped account
* builders to validate that an accepted x402 requirement targets the scoped network.
* Networks not present here (e.g. raw RPC URLs) cause the scoped check to be skipped.
*/
exports.CDP_NETWORK_TO_CAIP2 = Object.fromEntries(Object.entries(exports.CHAIN_ID_TO_CDP_NETWORK).map(([chainId, networkName]) => [
networkName,
`eip155:${chainId}`,
]));
/**
* Resolves the default EVM RPC URLs used for x402 payment signing, keyed by
* CAIP-2 network identifier.
*
* Only Base and Base Sepolia get a default: both are backed by the CDP
* project's own authenticated node endpoint (via {@link getBaseNodeRpcUrl}),
* so no shared public infrastructure sits on the payment-signing path and no
* extra configuration is required to use them.
*
* All other networks (Polygon, Arbitrum, World, etc.) have no default RPC.
* RPC URLs are optional for core payload signing on those networks — they're
* only needed to backfill optional extension capabilities (for example,
* `eip2612` gas-sponsoring enrichment) — so callers that need one must supply
* it explicitly via the `rpcUrls` config option or `CDP_X402_RPC_URLS`
* environment variable.
*
* @returns CAIP-2 keyed RPC configuration map containing only the networks
* that resolved successfully.
*/
async function getDefaultEvmRpcUrls() {
const [mainnetRpcUrl, sepoliaRpcUrl] = await Promise.all([
(0, getBaseNodeRpcUrl_js_1.getBaseNodeRpcUrl)("base"),
(0, getBaseNodeRpcUrl_js_1.getBaseNodeRpcUrl)("base-sepolia"),
]);
const defaults = {};
if (mainnetRpcUrl)
defaults[exports.baseMainnetCaip2] = { rpcUrl: mainnetRpcUrl };
if (sepoliaRpcUrl)
defaults[exports.baseSepoliaCaip2] = { rpcUrl: sepoliaRpcUrl };
return defaults;
}
//# sourceMappingURL=constants.js.map