@rango-dev/internal-blockchains 0.1.1-next.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.
- package/dist/caip.d.ts +39 -0
- package/dist/caip.d.ts.map +1 -0
- package/dist/mod.d.ts +4 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +2 -0
- package/dist/mod.js.map +7 -0
- package/dist/networks.d.ts +47 -0
- package/dist/networks.d.ts.map +1 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +44 -0
- package/readme.md +34 -0
- package/src/caip.ts +196 -0
- package/src/mod.ts +3 -0
- package/src/networks.ts +49 -0
- package/src/utils.ts +84 -0
package/dist/caip.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { BlockchainMeta } from 'rango-types';
|
|
2
|
+
/**
|
|
3
|
+
* A CAIP-2 chain id, e.g. `eip155:1` or `bip122:000000000019d6689c085ae165831e93`.
|
|
4
|
+
*
|
|
5
|
+
* @see https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md
|
|
6
|
+
*/
|
|
7
|
+
export type CaipChainId = `${string}:${string}`;
|
|
8
|
+
/** Pair a namespace with a reference here, not at call sites — that's where ids get crossed. */
|
|
9
|
+
export declare const CAIP_CHAINS: {
|
|
10
|
+
readonly BITCOIN: "bip122:000000000019d6689c085ae165831e93";
|
|
11
|
+
readonly BITCOINCASH: "bip122:000000000000000000651ef99cb9fcbe";
|
|
12
|
+
readonly DOGECOIN: "bip122:1a91e3dace36e2be3bf030a65679fe82";
|
|
13
|
+
readonly ETHEREUM: "eip155:1";
|
|
14
|
+
readonly LITECOIN: "bip122:12a765e31ffd4059bada1e25190f6e98";
|
|
15
|
+
readonly SOLANA: "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
16
|
+
readonly STARKNET: "starknet:SN_MAIN";
|
|
17
|
+
readonly STELLAR: "stellar:mainnet";
|
|
18
|
+
readonly SUI: "sui:sui";
|
|
19
|
+
readonly TON: "tvm:-239";
|
|
20
|
+
readonly TRON: "tron:tron";
|
|
21
|
+
readonly XRPL: "xrpl:mainnet";
|
|
22
|
+
readonly ZCASH: "bip122:zcash";
|
|
23
|
+
};
|
|
24
|
+
type BlockchainMetaForCaip = Pick<BlockchainMeta, 'type' | 'chainId' | 'name'>;
|
|
25
|
+
/**
|
|
26
|
+
* Convert a meta entry to its CAIP-2 chain id, so providers are handed CAIP rather than
|
|
27
|
+
* Rango names. `null` means "not addressable by CAIP" — callers should skip the chain
|
|
28
|
+
* rather than fall back to a name.
|
|
29
|
+
*/
|
|
30
|
+
export declare function convertBlockchainMetaToCaip(blockchainMeta: BlockchainMetaForCaip): CaipChainId | null;
|
|
31
|
+
/**
|
|
32
|
+
* The name-level counterpart to {@link convertBlockchainMetaToCaip}: signers get
|
|
33
|
+
* `asset.blockchain` ('BTC'), not a chain id. Only `TRANSFER` names resolve.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isTransferBlockchainName(blockchainName: string, caipChainId: CaipChainId): boolean;
|
|
36
|
+
export declare function isBitcoinBlockchain(blockchainName: string): boolean;
|
|
37
|
+
export declare function isZcashBlockchain(blockchainName: string): boolean;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=caip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip.d.ts","sourceRoot":"","sources":["../src/caip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA8ClD;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAEhD,gGAAgG;AAChG,eAAO,MAAM,WAAW;;;;;;;;;;;;;;CAcwB,CAAC;AAEjD,KAAK,qBAAqB,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,CAAC;AA2F/E;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,cAAc,EAAE,qBAAqB,GACpC,WAAW,GAAG,IAAI,CAQpB;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,WAAW,GACvB,OAAO,CAET;AAED,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAEjE"}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var N=Object.defineProperty;var r=(C,n)=>N(C,"name",{value:n,configurable:!0});var p=(A=>(A.BTC="BTC",A.BSC="BSC",A.LTC="LTC",A.THORCHAIN="THOR",A.BCH="BCH",A.BINANCE="BNB",A.BLAST="BLAST",A.CELO="CELO",A.LINEA="LINEA",A.METIS="METIS",A.SONIC="SONIC",A.BERACHAIN="BERACHAIN",A.ZETA_CHAIN="ZETA_CHAIN",A.SCROLL="SCROLL",A.ZKSYNC="ZKSYNC",A.MONAD="MONAD",A.ETHEREUM="ETH",A.POLYGON="POLYGON",A.POLKADOT="",A.TRON="TRON",A.DOGE="DOGE",A.HARMONY="HARMONY",A.AVAX_CCHAIN="AVAX_CCHAIN",A.FANTOM="FANTOM",A.MOONBEAM="MOONBEAM",A.ARBITRUM="ARBITRUM",A.BOBA="BOBA",A.OPTIMISM="OPTIMISM",A.FUSE="FUSE",A.CRONOS="CRONOS",A.SOLANA="SOLANA",A.MOONRIVER="MOONRIVER",A.GNOSIS="GNOSIS",A.MAYA="MAYA",A.STARKNET="STARKNET",A.STELLAR="STELLAR",A.TON="TON",A.BASE="BASE",A.SUI="SUI",A.XRPL="XRPL",A.ZCASH="ZCASH",A.HYPERLIQUID="HYPERLIQUID",A.Unknown="Unkown",A))(p||{}),F="ARBITRUM";import{CAIP_ETHEREUM_CHAIN_ID as P,CAIP_NAMESPACE as t}from"@hub3js/evm";import{CAIP_SOLANA_CHAIN_ID as R,CAIP_NAMESPACE as m}from"@hub3js/solana";import{CAIP_STARKNET_CHAIN_ID as M,CAIP_NAMESPACE as l}from"@hub3js/starknet";import{CAIP_STELLAR_CHAIN_ID as f,CAIP_NAMESPACE as B}from"@hub3js/stellar";import{CAIP_SUI_CHAIN_ID as u,CAIP_NAMESPACE as L}from"@hub3js/sui";import{CAIP_TON_CHAIN_ID as H,CAIP_NAMESPACE as h}from"@hub3js/tvm";import{CAIP_XRPL_CHAIN_ID as s,CAIP_NAMESPACE as d}from"@hub3js/xrpl";import{CAIP_TRON_CHAIN_ID as $,CAIP_NAMESPACE as D}from"@rango-dev/wallets-core/namespaces/tron";import{CAIP_BITCOIN_CHAIN_ID as U,CAIP_BITCOINCASH_CHAIN_ID as v,CAIP_DOGECOIN_CHAIN_ID as x,CAIP_LITECOIN_CHAIN_ID as y,CAIP_NAMESPACE as e,CAIP_ZCASH_CHAIN_ID as g}from"@rango-dev/wallets-core/namespaces/utxo";import{TransactionType as a}from"rango-types";var I={BITCOIN:`${e}:${U}`,BITCOINCASH:`${e}:${v}`,DOGECOIN:`${e}:${x}`,ETHEREUM:`${t}:${P}`,LITECOIN:`${e}:${y}`,SOLANA:`${m}:${R}`,STARKNET:`${l}:${M}`,STELLAR:`${B}:${f}`,SUI:`${L}:${u}`,TON:`${h}:${H}`,TRON:`${D}:${$}`,XRPL:`${d}:${s}`,ZCASH:`${e}:${g}`},Y=16,X=10,O={BCH:I.BITCOINCASH,BTC:I.BITCOIN,DOGE:I.DOGECOIN,LTC:I.LITECOIN,ZCASH:I.ZCASH};function T(C,n){if(!n)return null;let i=/^0x[0-9a-f]+$/i.test(n),E=/^[0-9]+$/.test(n);if(!i&&!E)return null;let o=parseInt(n,i?Y:X);return Number.isSafeInteger(o)?`${C}:${o}`:null}r(T,"toNumericCaip");var K={[a.SOLANA]:I.SOLANA,[a.STARKNET]:I.STARKNET,[a.STELLAR]:I.STELLAR,[a.SUI]:I.SUI,[a.TON]:I.TON,[a.TRON]:I.TRON,[a.XRPL]:I.XRPL,[a.EVM]:C=>T(t,C.chainId),[a.HYPERLIQUID]:C=>T(t,C.chainId),[a.TRANSFER]:C=>O[C.name]??null,[a.COSMOS]:null};function S(C){let n=K[C.type];return n?typeof n=="function"?n(C):n:null}r(S,"convertBlockchainMetaToCaip");function c(C,n){return O[C]===n}r(c,"isTransferBlockchainName");function CA(C){return c(C,I.BITCOIN)}r(CA,"isBitcoinBlockchain");function nA(C){return c(C,I.ZCASH)}r(nA,"isZcashBlockchain");function rA(C,n){return n?.filter(i=>{let E=S(i);return E?C.isChainSupported(E):!1})??[]}r(rA,"getSupportedChainsFromNamespace");function EA(C,n){let i=C.info()?.metadata.properties?.find(E=>E.name==="namespaces");return n?.filter(E=>{let o=S(E);return o?i?.value.data.some(_=>_.isChainSupported(o))??!1:!1})??[]}r(EA,"getSupportedChainsFromProvider");function oA(C){return C.reduce((n,i)=>(n[i.name]={chainName:i.info.chainName,chainId:i.chainId,nativeCurrency:i.info.nativeCurrency,rpcUrls:i.info.rpcUrls,blockExplorerUrls:i.info.blockExplorerUrls},n),{})}r(oA,"convertEvmBlockchainMetaToEvmChainInfo");export{I as CAIP_CHAINS,F as HYPERLIQUID_SIGN_NETWORK,p as Networks,S as convertBlockchainMetaToCaip,oA as convertEvmBlockchainMetaToEvmChainInfo,rA as getSupportedChainsFromNamespace,EA as getSupportedChainsFromProvider,CA as isBitcoinBlockchain,c as isTransferBlockchainName,nA as isZcashBlockchain};
|
|
2
|
+
//# sourceMappingURL=mod.js.map
|
package/dist/mod.js.map
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/networks.ts", "../src/caip.ts", "../src/utils.ts"],
|
|
4
|
+
"sourcesContent": ["export enum Networks {\n BTC = 'BTC',\n BSC = 'BSC',\n LTC = 'LTC',\n THORCHAIN = 'THOR',\n BCH = 'BCH',\n BINANCE = 'BNB',\n BLAST = 'BLAST',\n CELO = 'CELO',\n LINEA = 'LINEA',\n METIS = 'METIS',\n SONIC = 'SONIC',\n BERACHAIN = 'BERACHAIN',\n ZETA_CHAIN = 'ZETA_CHAIN',\n SCROLL = 'SCROLL',\n ZKSYNC = 'ZKSYNC',\n MONAD = 'MONAD',\n ETHEREUM = 'ETH',\n POLYGON = 'POLYGON',\n POLKADOT = '',\n TRON = 'TRON',\n DOGE = 'DOGE',\n HARMONY = 'HARMONY',\n AVAX_CCHAIN = 'AVAX_CCHAIN',\n FANTOM = 'FANTOM',\n MOONBEAM = 'MOONBEAM',\n ARBITRUM = 'ARBITRUM',\n BOBA = 'BOBA',\n OPTIMISM = 'OPTIMISM',\n FUSE = 'FUSE',\n CRONOS = 'CRONOS',\n SOLANA = 'SOLANA',\n MOONRIVER = 'MOONRIVER',\n GNOSIS = 'GNOSIS',\n MAYA = 'MAYA',\n STARKNET = 'STARKNET',\n STELLAR = 'STELLAR',\n TON = 'TON',\n BASE = 'BASE',\n SUI = 'SUI',\n XRPL = 'XRPL',\n ZCASH = 'ZCASH',\n HYPERLIQUID = 'HYPERLIQUID',\n\n // Using instead of null\n Unknown = 'Unkown',\n}\n\nexport const HYPERLIQUID_SIGN_NETWORK = Networks.ARBITRUM;\n", "import type { BlockchainMeta } from 'rango-types';\n\nimport {\n CAIP_ETHEREUM_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_EVM_NAMESPACE,\n} from '@hub3js/evm';\nimport {\n CAIP_SOLANA_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_SOLANA_NAMESPACE,\n} from '@hub3js/solana';\nimport {\n CAIP_STARKNET_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_STARKNET_NAMESPACE,\n} from '@hub3js/starknet';\nimport {\n CAIP_STELLAR_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_STELLAR_NAMESPACE,\n} from '@hub3js/stellar';\nimport {\n CAIP_SUI_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_SUI_NAMESPACE,\n} from '@hub3js/sui';\nimport {\n CAIP_TON_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_TVM_NAMESPACE,\n} from '@hub3js/tvm';\nimport {\n CAIP_XRPL_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_XRPL_NAMESPACE,\n} from '@hub3js/xrpl';\nimport {\n CAIP_TRON_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_TRON_NAMESPACE,\n} from '@rango-dev/wallets-core/namespaces/tron';\nimport {\n CAIP_BITCOIN_CHAIN_ID,\n CAIP_BITCOINCASH_CHAIN_ID,\n CAIP_DOGECOIN_CHAIN_ID,\n CAIP_LITECOIN_CHAIN_ID,\n CAIP_NAMESPACE as CAIP_UTXO_NAMESPACE,\n CAIP_ZCASH_CHAIN_ID,\n} from '@rango-dev/wallets-core/namespaces/utxo';\nimport { TransactionType } from 'rango-types';\n\nimport { Networks } from './networks.js';\n\n/**\n * A CAIP-2 chain id, e.g. `eip155:1` or `bip122:000000000019d6689c085ae165831e93`.\n *\n * @see https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md\n */\nexport type CaipChainId = `${string}:${string}`;\n\n/** Pair a namespace with a reference here, not at call sites \u2014 that's where ids get crossed. */\nexport const CAIP_CHAINS = {\n BITCOIN: `${CAIP_UTXO_NAMESPACE}:${CAIP_BITCOIN_CHAIN_ID}`,\n BITCOINCASH: `${CAIP_UTXO_NAMESPACE}:${CAIP_BITCOINCASH_CHAIN_ID}`,\n DOGECOIN: `${CAIP_UTXO_NAMESPACE}:${CAIP_DOGECOIN_CHAIN_ID}`,\n ETHEREUM: `${CAIP_EVM_NAMESPACE}:${CAIP_ETHEREUM_CHAIN_ID}`,\n LITECOIN: `${CAIP_UTXO_NAMESPACE}:${CAIP_LITECOIN_CHAIN_ID}`,\n SOLANA: `${CAIP_SOLANA_NAMESPACE}:${CAIP_SOLANA_CHAIN_ID}`,\n STARKNET: `${CAIP_STARKNET_NAMESPACE}:${CAIP_STARKNET_CHAIN_ID}`,\n STELLAR: `${CAIP_STELLAR_NAMESPACE}:${CAIP_STELLAR_CHAIN_ID}`,\n SUI: `${CAIP_SUI_NAMESPACE}:${CAIP_SUI_CHAIN_ID}`,\n TON: `${CAIP_TVM_NAMESPACE}:${CAIP_TON_CHAIN_ID}`,\n TRON: `${CAIP_TRON_NAMESPACE}:${CAIP_TRON_CHAIN_ID}`,\n XRPL: `${CAIP_XRPL_NAMESPACE}:${CAIP_XRPL_CHAIN_ID}`,\n ZCASH: `${CAIP_UTXO_NAMESPACE}:${CAIP_ZCASH_CHAIN_ID}`,\n} as const satisfies Record<string, CaipChainId>;\n\ntype BlockchainMetaForCaip = Pick<BlockchainMeta, 'type' | 'chainId' | 'name'>;\n\nconst HEX_RADIX = 16;\nconst DECIMAL_RADIX = 10;\n\n/**\n * `TRANSFER` covers several UTXO chains and its meta `chainId` is always `null`, so\n * these can only be keyed by name. This table is the one place in the wallet packages\n * that has to know a Rango chain name \u2014 everywhere else works in CAIP-2 ids, which is\n * why `Networks` shouldn't spread beyond it.\n *\n * DASH is knowingly absent: no CAIP constant and no provider supports it, so it\n * converts to `null` and is dropped.\n */\nconst CAIP_BY_TRANSFER_BLOCKCHAIN_NAME: Record<string, CaipChainId> = {\n [Networks.BCH]: CAIP_CHAINS.BITCOINCASH,\n [Networks.BTC]: CAIP_CHAINS.BITCOIN,\n [Networks.DOGE]: CAIP_CHAINS.DOGECOIN,\n [Networks.LTC]: CAIP_CHAINS.LITECOIN,\n [Networks.ZCASH]: CAIP_CHAINS.ZCASH,\n};\n\n/**\n * `eip155` references are decimal but meta reports EVM chainIds as hex ('0xa86a'), and\n * Hyperliquid reports a bare decimal ('1337') \u2014 so the prefix picks the radix, not the\n * chain family.\n */\nfunction toNumericCaip(\n namespace: string,\n chainId: string | null | undefined\n): CaipChainId | null {\n if (!chainId) {\n return null;\n }\n\n const isHex = /^0x[0-9a-f]+$/i.test(chainId);\n const isDecimal = /^[0-9]+$/.test(chainId);\n\n // `parseInt` stops at the first bad character, so '12abc' would become chain id '12'.\n if (!isHex && !isDecimal) {\n return null;\n }\n\n const reference = parseInt(chainId, isHex ? HEX_RADIX : DECIMAL_RADIX);\n\n return Number.isSafeInteger(reference) ? `${namespace}:${reference}` : null;\n}\n\ntype CaipResolver =\n | CaipChainId\n | ((blockchainMeta: BlockchainMetaForCaip) => CaipChainId | null)\n | null;\n\n/**\n * A total `Record` on purpose: a new `TransactionType` in rango-types fails to compile\n * here instead of silently making that family invisible to every wallet.\n */\nconst CAIP_BY_TRANSACTION_TYPE: Record<TransactionType, CaipResolver> = {\n /*\n * Fixed ids, ignoring meta `chainId` \u2014 it is NOT the CAIP reference for several of\n * these (meta reports Solana as 'mainnet-beta', Sui as 'sui-mainnet'), so deriving\n * from it would produce ids that don't match the accounts providers report.\n */\n [TransactionType.SOLANA]: CAIP_CHAINS.SOLANA,\n [TransactionType.STARKNET]: CAIP_CHAINS.STARKNET,\n [TransactionType.STELLAR]: CAIP_CHAINS.STELLAR,\n [TransactionType.SUI]: CAIP_CHAINS.SUI,\n [TransactionType.TON]: CAIP_CHAINS.TON,\n [TransactionType.TRON]: CAIP_CHAINS.TRON,\n [TransactionType.XRPL]: CAIP_CHAINS.XRPL,\n\n [TransactionType.EVM]: (blockchainMeta) =>\n toNumericCaip(CAIP_EVM_NAMESPACE, blockchainMeta.chainId),\n\n /*\n * `eip155` so the wallets claiming the whole EVM family keep supporting Hyperliquid,\n * as they did when they listed it by name. The reference is meta's 1337, NOT\n * HyperEVM's real 999 \u2014 safe only because an `eip155` reference is never turned back\n * into a chain id. Give Hyperliquid its own namespace before deriving a network\n * switch or RPC target from this.\n */\n [TransactionType.HYPERLIQUID]: (blockchainMeta) =>\n toNumericCaip(CAIP_EVM_NAMESPACE, blockchainMeta.chainId),\n\n [TransactionType.TRANSFER]: (blockchainMeta) =>\n CAIP_BY_TRANSFER_BLOCKCHAIN_NAME[blockchainMeta.name] ?? null,\n\n // Not addressable \u2014 no namespace claims it, so no provider can match it.\n [TransactionType.COSMOS]: null,\n};\n\n/**\n * Convert a meta entry to its CAIP-2 chain id, so providers are handed CAIP rather than\n * Rango names. `null` means \"not addressable by CAIP\" \u2014 callers should skip the chain\n * rather than fall back to a name.\n */\nexport function convertBlockchainMetaToCaip(\n blockchainMeta: BlockchainMetaForCaip\n): CaipChainId | null {\n const resolver = CAIP_BY_TRANSACTION_TYPE[blockchainMeta.type];\n\n if (!resolver) {\n return null;\n }\n\n return typeof resolver === 'function' ? resolver(blockchainMeta) : resolver;\n}\n\n/**\n * The name-level counterpart to {@link convertBlockchainMetaToCaip}: signers get\n * `asset.blockchain` ('BTC'), not a chain id. Only `TRANSFER` names resolve.\n */\nexport function isTransferBlockchainName(\n blockchainName: string,\n caipChainId: CaipChainId\n): boolean {\n return CAIP_BY_TRANSFER_BLOCKCHAIN_NAME[blockchainName] === caipChainId;\n}\n\nexport function isBitcoinBlockchain(blockchainName: string): boolean {\n return isTransferBlockchainName(blockchainName, CAIP_CHAINS.BITCOIN);\n}\n\nexport function isZcashBlockchain(blockchainName: string): boolean {\n return isTransferBlockchainName(blockchainName, CAIP_CHAINS.ZCASH);\n}\n", "import type { Provider } from '@hub3js/core';\nimport type { Chain } from '@hub3js/evm';\nimport type { BlockchainMeta, EvmBlockchainMeta } from 'rango-types';\n\nimport { convertBlockchainMetaToCaip } from './caip.js';\n\ntype ChainSupport = {\n isChainSupported: (chainId: string) => boolean;\n};\n\nexport type EvmNetworksChainInfo = Record<string, Chain>;\n\n/**\n * The chains of `allBlockChains` a single namespace can address. Chains that don't\n * convert to CAIP are dropped rather than guessed at - see\n * {@link convertBlockchainMetaToCaip}.\n */\nexport function getSupportedChainsFromNamespace(\n namespace: ChainSupport,\n allBlockChains: BlockchainMeta[] | undefined\n): BlockchainMeta[] {\n return (\n allBlockChains?.filter((blockchain) => {\n const chainId = convertBlockchainMetaToCaip(blockchain);\n\n return chainId ? namespace.isChainSupported(chainId) : false;\n }) ?? []\n );\n}\n\n/**\n * The union of what every namespace of a provider supports, in `allBlockChains` order\n * and without duplicates when two namespaces claim the same chain.\n */\nexport function getSupportedChainsFromProvider(\n provider: Provider,\n allBlockChains: BlockchainMeta[] | undefined\n): BlockchainMeta[] {\n const namespacesProperty = provider\n .info()\n ?.metadata.properties?.find((property) => property.name === 'namespaces');\n\n return (\n allBlockChains?.filter((blockchain) => {\n const chainId = convertBlockchainMetaToCaip(blockchain);\n\n if (!chainId) {\n return false;\n }\n\n return (\n namespacesProperty?.value.data.some((namespace) =>\n namespace.isChainSupported(chainId)\n ) ?? false\n );\n }) ?? []\n );\n}\n\n/*\n * TODO: remove this. It exists only so a provider can look a chain up by Rango's\n * network name, which is knowledge a provider shouldn't carry \u2014 the caller already\n * resolves the chain and should hand the provider an EIP-3085 description instead.\n * Once every consumer does that, this table and the providers' dependency on\n * Rango's chain model go away together.\n */\nexport function convertEvmBlockchainMetaToEvmChainInfo(\n evmBlockchains: EvmBlockchainMeta[]\n): EvmNetworksChainInfo {\n return evmBlockchains.reduce<EvmNetworksChainInfo>(\n (evmNetworksChainInfo, blockchainMeta) => {\n evmNetworksChainInfo[blockchainMeta.name] = {\n chainName: blockchainMeta.info.chainName,\n chainId: blockchainMeta.chainId,\n nativeCurrency: blockchainMeta.info.nativeCurrency,\n rpcUrls: blockchainMeta.info.rpcUrls,\n blockExplorerUrls: blockchainMeta.info.blockExplorerUrls,\n };\n\n return evmNetworksChainInfo;\n },\n {}\n );\n}\n"],
|
|
5
|
+
"mappings": "+EAAO,IAAKA,OACVA,EAAA,IAAM,MACNA,EAAA,IAAM,MACNA,EAAA,IAAM,MACNA,EAAA,UAAY,OACZA,EAAA,IAAM,MACNA,EA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,GAAK,CAAC,CAEX,CAvBgBE,EAAAC,GAAA,kCAgCT,SAASI,GACdC,EACsB,CACtB,OAAOA,EAAe,OACpB,CAACC,EAAsBC,KACrBD,EAAqBC,EAAe,IAAI,EAAI,CAC1C,UAAWA,EAAe,KAAK,UAC/B,QAASA,EAAe,QACxB,eAAgBA,EAAe,KAAK,eACpC,QAASA,EAAe,KAAK,QAC7B,kBAAmBA,EAAe,KAAK,iBACzC,EAEOD,GAET,CAAC,CACH,CACF,CAjBgBP,EAAAK,GAAA",
|
|
6
|
+
"names": ["Networks", "HYPERLIQUID_SIGN_NETWORK", "CAIP_ETHEREUM_CHAIN_ID", "CAIP_EVM_NAMESPACE", "CAIP_SOLANA_CHAIN_ID", "CAIP_SOLANA_NAMESPACE", "CAIP_STARKNET_CHAIN_ID", "CAIP_STARKNET_NAMESPACE", "CAIP_STELLAR_CHAIN_ID", "CAIP_STELLAR_NAMESPACE", "CAIP_SUI_CHAIN_ID", "CAIP_SUI_NAMESPACE", "CAIP_TON_CHAIN_ID", "CAIP_TVM_NAMESPACE", "CAIP_XRPL_CHAIN_ID", "CAIP_XRPL_NAMESPACE", "CAIP_TRON_CHAIN_ID", "CAIP_TRON_NAMESPACE", "CAIP_BITCOIN_CHAIN_ID", "CAIP_BITCOINCASH_CHAIN_ID", "CAIP_DOGECOIN_CHAIN_ID", "CAIP_LITECOIN_CHAIN_ID", "CAIP_UTXO_NAMESPACE", "CAIP_ZCASH_CHAIN_ID", "TransactionType", "CAIP_CHAINS", "CAIP_UTXO_NAMESPACE", "CAIP_BITCOIN_CHAIN_ID", "CAIP_BITCOINCASH_CHAIN_ID", "CAIP_DOGECOIN_CHAIN_ID", "CAIP_EVM_NAMESPACE", "CAIP_ETHEREUM_CHAIN_ID", "CAIP_LITECOIN_CHAIN_ID", "CAIP_SOLANA_NAMESPACE", "CAIP_SOLANA_CHAIN_ID", "CAIP_STARKNET_NAMESPACE", "CAIP_STARKNET_CHAIN_ID", "CAIP_STELLAR_NAMESPACE", "CAIP_STELLAR_CHAIN_ID", "CAIP_SUI_NAMESPACE", "CAIP_SUI_CHAIN_ID", "CAIP_TVM_NAMESPACE", "CAIP_TON_CHAIN_ID", "CAIP_TRON_NAMESPACE", "CAIP_TRON_CHAIN_ID", "CAIP_XRPL_NAMESPACE", "CAIP_XRPL_CHAIN_ID", "CAIP_ZCASH_CHAIN_ID", "HEX_RADIX", "DECIMAL_RADIX", "CAIP_BY_TRANSFER_BLOCKCHAIN_NAME", "toNumericCaip", "namespace", "chainId", "isHex", "isDecimal", "reference", "__name", "CAIP_BY_TRANSACTION_TYPE", "TransactionType", "blockchainMeta", "convertBlockchainMetaToCaip", "resolver", "isTransferBlockchainName", "blockchainName", "caipChainId", "isBitcoinBlockchain", "isZcashBlockchain", "getSupportedChainsFromNamespace", "namespace", "allBlockChains", "blockchain", "chainId", "convertBlockchainMetaToCaip", "__name", "getSupportedChainsFromProvider", "provider", "namespacesProperty", "property", "convertEvmBlockchainMetaToEvmChainInfo", "evmBlockchains", "evmNetworksChainInfo", "blockchainMeta"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export declare enum Networks {
|
|
2
|
+
BTC = "BTC",
|
|
3
|
+
BSC = "BSC",
|
|
4
|
+
LTC = "LTC",
|
|
5
|
+
THORCHAIN = "THOR",
|
|
6
|
+
BCH = "BCH",
|
|
7
|
+
BINANCE = "BNB",
|
|
8
|
+
BLAST = "BLAST",
|
|
9
|
+
CELO = "CELO",
|
|
10
|
+
LINEA = "LINEA",
|
|
11
|
+
METIS = "METIS",
|
|
12
|
+
SONIC = "SONIC",
|
|
13
|
+
BERACHAIN = "BERACHAIN",
|
|
14
|
+
ZETA_CHAIN = "ZETA_CHAIN",
|
|
15
|
+
SCROLL = "SCROLL",
|
|
16
|
+
ZKSYNC = "ZKSYNC",
|
|
17
|
+
MONAD = "MONAD",
|
|
18
|
+
ETHEREUM = "ETH",
|
|
19
|
+
POLYGON = "POLYGON",
|
|
20
|
+
POLKADOT = "",
|
|
21
|
+
TRON = "TRON",
|
|
22
|
+
DOGE = "DOGE",
|
|
23
|
+
HARMONY = "HARMONY",
|
|
24
|
+
AVAX_CCHAIN = "AVAX_CCHAIN",
|
|
25
|
+
FANTOM = "FANTOM",
|
|
26
|
+
MOONBEAM = "MOONBEAM",
|
|
27
|
+
ARBITRUM = "ARBITRUM",
|
|
28
|
+
BOBA = "BOBA",
|
|
29
|
+
OPTIMISM = "OPTIMISM",
|
|
30
|
+
FUSE = "FUSE",
|
|
31
|
+
CRONOS = "CRONOS",
|
|
32
|
+
SOLANA = "SOLANA",
|
|
33
|
+
MOONRIVER = "MOONRIVER",
|
|
34
|
+
GNOSIS = "GNOSIS",
|
|
35
|
+
MAYA = "MAYA",
|
|
36
|
+
STARKNET = "STARKNET",
|
|
37
|
+
STELLAR = "STELLAR",
|
|
38
|
+
TON = "TON",
|
|
39
|
+
BASE = "BASE",
|
|
40
|
+
SUI = "SUI",
|
|
41
|
+
XRPL = "XRPL",
|
|
42
|
+
ZCASH = "ZCASH",
|
|
43
|
+
HYPERLIQUID = "HYPERLIQUID",
|
|
44
|
+
Unknown = "Unkown"
|
|
45
|
+
}
|
|
46
|
+
export declare const HYPERLIQUID_SIGN_NETWORK = Networks.ARBITRUM;
|
|
47
|
+
//# sourceMappingURL=networks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"networks.d.ts","sourceRoot":"","sources":["../src/networks.ts"],"names":[],"mappings":"AAAA,oBAAY,QAAQ;IAClB,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,SAAS,SAAS;IAClB,GAAG,QAAQ;IACX,OAAO,QAAQ;IACf,KAAK,UAAU;IACf,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,UAAU;IACf,SAAS,cAAc;IACvB,UAAU,eAAe;IACzB,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,QAAQ,QAAQ;IAChB,OAAO,YAAY;IACnB,QAAQ,KAAK;IACb,IAAI,SAAS;IACb,IAAI,SAAS;IACb,OAAO,YAAY;IACnB,WAAW,gBAAgB;IAC3B,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,SAAS,cAAc;IACvB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,QAAQ,aAAa;IACrB,OAAO,YAAY;IACnB,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,GAAG,QAAQ;IACX,IAAI,SAAS;IACb,KAAK,UAAU;IACf,WAAW,gBAAgB;IAG3B,OAAO,WAAW;CACnB;AAED,eAAO,MAAM,wBAAwB,oBAAoB,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Provider } from '@hub3js/core';
|
|
2
|
+
import type { Chain } from '@hub3js/evm';
|
|
3
|
+
import type { BlockchainMeta, EvmBlockchainMeta } from 'rango-types';
|
|
4
|
+
type ChainSupport = {
|
|
5
|
+
isChainSupported: (chainId: string) => boolean;
|
|
6
|
+
};
|
|
7
|
+
export type EvmNetworksChainInfo = Record<string, Chain>;
|
|
8
|
+
/**
|
|
9
|
+
* The chains of `allBlockChains` a single namespace can address. Chains that don't
|
|
10
|
+
* convert to CAIP are dropped rather than guessed at - see
|
|
11
|
+
* {@link convertBlockchainMetaToCaip}.
|
|
12
|
+
*/
|
|
13
|
+
export declare function getSupportedChainsFromNamespace(namespace: ChainSupport, allBlockChains: BlockchainMeta[] | undefined): BlockchainMeta[];
|
|
14
|
+
/**
|
|
15
|
+
* The union of what every namespace of a provider supports, in `allBlockChains` order
|
|
16
|
+
* and without duplicates when two namespaces claim the same chain.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSupportedChainsFromProvider(provider: Provider, allBlockChains: BlockchainMeta[] | undefined): BlockchainMeta[];
|
|
19
|
+
export declare function convertEvmBlockchainMetaToEvmChainInfo(evmBlockchains: EvmBlockchainMeta[]): EvmNetworksChainInfo;
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAIrE,KAAK,YAAY,GAAG;IAClB,gBAAgB,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,YAAY,EACvB,cAAc,EAAE,cAAc,EAAE,GAAG,SAAS,GAC3C,cAAc,EAAE,CAQlB;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC5C,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,cAAc,EAAE,GAAG,SAAS,GAC3C,cAAc,EAAE,CAoBlB;AASD,wBAAgB,sCAAsC,CACpD,cAAc,EAAE,iBAAiB,EAAE,GAClC,oBAAoB,CAetB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rango-dev/internal-blockchains",
|
|
3
|
+
"version": "0.1.1-next.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"source": "./src/mod.ts",
|
|
7
|
+
"main": "./dist/mod.js",
|
|
8
|
+
"typings": "dist/mod.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/mod.d.ts",
|
|
12
|
+
"default": "./dist/mod.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "yarn run rangutopia library build",
|
|
21
|
+
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
|
|
24
|
+
"lint": "eslint \"**/*.{ts,tsx}\"",
|
|
25
|
+
"test": "vitest",
|
|
26
|
+
"test:watch": "vitest --watch",
|
|
27
|
+
"test:coverage": "vitest run --coverage"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@hub3js/core": "^0.61.1",
|
|
31
|
+
"@hub3js/evm": "^0.4.0",
|
|
32
|
+
"@hub3js/solana": "^0.4.0",
|
|
33
|
+
"@hub3js/starknet": "^0.3.0",
|
|
34
|
+
"@hub3js/stellar": "^0.3.0",
|
|
35
|
+
"@hub3js/sui": "^0.3.0",
|
|
36
|
+
"@hub3js/tvm": "^0.3.0",
|
|
37
|
+
"@hub3js/xrpl": "^0.3.0",
|
|
38
|
+
"@rango-dev/wallets-core": "^0.61.1-next.0",
|
|
39
|
+
"rango-types": "^0.5.0"
|
|
40
|
+
},
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @rango-dev/internal-blockchains
|
|
2
|
+
|
|
3
|
+
Translation between Rango's chain vocabulary (`BlockchainMeta`, `TransactionType`,
|
|
4
|
+
`Networks`) and CAIP-2 chain ids.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import {
|
|
8
|
+
convertBlockchainMetaToCaip,
|
|
9
|
+
isBitcoinBlockchain,
|
|
10
|
+
} from '@rango-dev/internal-blockchains';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Why it is separate from `@hub3js/caip`
|
|
14
|
+
|
|
15
|
+
Providers are moving to hub3js, which holds no Rango domain logic. Splitting the two
|
|
16
|
+
puts that rule in the dependency graph rather than in review comments:
|
|
17
|
+
|
|
18
|
+
| Provider code | Speaks | Imports |
|
|
19
|
+
| --- | --- | --- |
|
|
20
|
+
| `constants.ts`, `namespaces/`, `actions/`, `builders/`, `ProviderMetadata`, `isChainSupported` | CAIP-2 only | `@hub3js/caip` |
|
|
21
|
+
| `signer.ts`, `signers/` | Rango names | this package |
|
|
22
|
+
|
|
23
|
+
The first row is what moves; after the CAIP-2 chain-support refactor none of it knows a
|
|
24
|
+
Rango chain name.
|
|
25
|
+
|
|
26
|
+
The second row is a conscious exception. A signer implements `GenericSigner<Transfer>`
|
|
27
|
+
from `rango-types`, so its input is a Rango transaction and `tx.asset.blockchain` is a
|
|
28
|
+
Rango name — every provider already depends on `rango-types` for exactly this, and no
|
|
29
|
+
signer moves to hub3js. The exception does not extend to resolving a name in provider
|
|
30
|
+
setup, keying an instance map by name, or deciding chain support by name; those have
|
|
31
|
+
CAIP equivalents.
|
|
32
|
+
|
|
33
|
+
Nothing here may move to hub3js. Anything expressible without `rango-types` belongs in
|
|
34
|
+
`@hub3js/caip` instead.
|
package/src/caip.ts
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { BlockchainMeta } from 'rango-types';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
CAIP_ETHEREUM_CHAIN_ID,
|
|
5
|
+
CAIP_NAMESPACE as CAIP_EVM_NAMESPACE,
|
|
6
|
+
} from '@hub3js/evm';
|
|
7
|
+
import {
|
|
8
|
+
CAIP_SOLANA_CHAIN_ID,
|
|
9
|
+
CAIP_NAMESPACE as CAIP_SOLANA_NAMESPACE,
|
|
10
|
+
} from '@hub3js/solana';
|
|
11
|
+
import {
|
|
12
|
+
CAIP_STARKNET_CHAIN_ID,
|
|
13
|
+
CAIP_NAMESPACE as CAIP_STARKNET_NAMESPACE,
|
|
14
|
+
} from '@hub3js/starknet';
|
|
15
|
+
import {
|
|
16
|
+
CAIP_STELLAR_CHAIN_ID,
|
|
17
|
+
CAIP_NAMESPACE as CAIP_STELLAR_NAMESPACE,
|
|
18
|
+
} from '@hub3js/stellar';
|
|
19
|
+
import {
|
|
20
|
+
CAIP_SUI_CHAIN_ID,
|
|
21
|
+
CAIP_NAMESPACE as CAIP_SUI_NAMESPACE,
|
|
22
|
+
} from '@hub3js/sui';
|
|
23
|
+
import {
|
|
24
|
+
CAIP_TON_CHAIN_ID,
|
|
25
|
+
CAIP_NAMESPACE as CAIP_TVM_NAMESPACE,
|
|
26
|
+
} from '@hub3js/tvm';
|
|
27
|
+
import {
|
|
28
|
+
CAIP_XRPL_CHAIN_ID,
|
|
29
|
+
CAIP_NAMESPACE as CAIP_XRPL_NAMESPACE,
|
|
30
|
+
} from '@hub3js/xrpl';
|
|
31
|
+
import {
|
|
32
|
+
CAIP_TRON_CHAIN_ID,
|
|
33
|
+
CAIP_NAMESPACE as CAIP_TRON_NAMESPACE,
|
|
34
|
+
} from '@rango-dev/wallets-core/namespaces/tron';
|
|
35
|
+
import {
|
|
36
|
+
CAIP_BITCOIN_CHAIN_ID,
|
|
37
|
+
CAIP_BITCOINCASH_CHAIN_ID,
|
|
38
|
+
CAIP_DOGECOIN_CHAIN_ID,
|
|
39
|
+
CAIP_LITECOIN_CHAIN_ID,
|
|
40
|
+
CAIP_NAMESPACE as CAIP_UTXO_NAMESPACE,
|
|
41
|
+
CAIP_ZCASH_CHAIN_ID,
|
|
42
|
+
} from '@rango-dev/wallets-core/namespaces/utxo';
|
|
43
|
+
import { TransactionType } from 'rango-types';
|
|
44
|
+
|
|
45
|
+
import { Networks } from './networks.js';
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A CAIP-2 chain id, e.g. `eip155:1` or `bip122:000000000019d6689c085ae165831e93`.
|
|
49
|
+
*
|
|
50
|
+
* @see https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-2.md
|
|
51
|
+
*/
|
|
52
|
+
export type CaipChainId = `${string}:${string}`;
|
|
53
|
+
|
|
54
|
+
/** Pair a namespace with a reference here, not at call sites — that's where ids get crossed. */
|
|
55
|
+
export const CAIP_CHAINS = {
|
|
56
|
+
BITCOIN: `${CAIP_UTXO_NAMESPACE}:${CAIP_BITCOIN_CHAIN_ID}`,
|
|
57
|
+
BITCOINCASH: `${CAIP_UTXO_NAMESPACE}:${CAIP_BITCOINCASH_CHAIN_ID}`,
|
|
58
|
+
DOGECOIN: `${CAIP_UTXO_NAMESPACE}:${CAIP_DOGECOIN_CHAIN_ID}`,
|
|
59
|
+
ETHEREUM: `${CAIP_EVM_NAMESPACE}:${CAIP_ETHEREUM_CHAIN_ID}`,
|
|
60
|
+
LITECOIN: `${CAIP_UTXO_NAMESPACE}:${CAIP_LITECOIN_CHAIN_ID}`,
|
|
61
|
+
SOLANA: `${CAIP_SOLANA_NAMESPACE}:${CAIP_SOLANA_CHAIN_ID}`,
|
|
62
|
+
STARKNET: `${CAIP_STARKNET_NAMESPACE}:${CAIP_STARKNET_CHAIN_ID}`,
|
|
63
|
+
STELLAR: `${CAIP_STELLAR_NAMESPACE}:${CAIP_STELLAR_CHAIN_ID}`,
|
|
64
|
+
SUI: `${CAIP_SUI_NAMESPACE}:${CAIP_SUI_CHAIN_ID}`,
|
|
65
|
+
TON: `${CAIP_TVM_NAMESPACE}:${CAIP_TON_CHAIN_ID}`,
|
|
66
|
+
TRON: `${CAIP_TRON_NAMESPACE}:${CAIP_TRON_CHAIN_ID}`,
|
|
67
|
+
XRPL: `${CAIP_XRPL_NAMESPACE}:${CAIP_XRPL_CHAIN_ID}`,
|
|
68
|
+
ZCASH: `${CAIP_UTXO_NAMESPACE}:${CAIP_ZCASH_CHAIN_ID}`,
|
|
69
|
+
} as const satisfies Record<string, CaipChainId>;
|
|
70
|
+
|
|
71
|
+
type BlockchainMetaForCaip = Pick<BlockchainMeta, 'type' | 'chainId' | 'name'>;
|
|
72
|
+
|
|
73
|
+
const HEX_RADIX = 16;
|
|
74
|
+
const DECIMAL_RADIX = 10;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* `TRANSFER` covers several UTXO chains and its meta `chainId` is always `null`, so
|
|
78
|
+
* these can only be keyed by name. This table is the one place in the wallet packages
|
|
79
|
+
* that has to know a Rango chain name — everywhere else works in CAIP-2 ids, which is
|
|
80
|
+
* why `Networks` shouldn't spread beyond it.
|
|
81
|
+
*
|
|
82
|
+
* DASH is knowingly absent: no CAIP constant and no provider supports it, so it
|
|
83
|
+
* converts to `null` and is dropped.
|
|
84
|
+
*/
|
|
85
|
+
const CAIP_BY_TRANSFER_BLOCKCHAIN_NAME: Record<string, CaipChainId> = {
|
|
86
|
+
[Networks.BCH]: CAIP_CHAINS.BITCOINCASH,
|
|
87
|
+
[Networks.BTC]: CAIP_CHAINS.BITCOIN,
|
|
88
|
+
[Networks.DOGE]: CAIP_CHAINS.DOGECOIN,
|
|
89
|
+
[Networks.LTC]: CAIP_CHAINS.LITECOIN,
|
|
90
|
+
[Networks.ZCASH]: CAIP_CHAINS.ZCASH,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* `eip155` references are decimal but meta reports EVM chainIds as hex ('0xa86a'), and
|
|
95
|
+
* Hyperliquid reports a bare decimal ('1337') — so the prefix picks the radix, not the
|
|
96
|
+
* chain family.
|
|
97
|
+
*/
|
|
98
|
+
function toNumericCaip(
|
|
99
|
+
namespace: string,
|
|
100
|
+
chainId: string | null | undefined
|
|
101
|
+
): CaipChainId | null {
|
|
102
|
+
if (!chainId) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const isHex = /^0x[0-9a-f]+$/i.test(chainId);
|
|
107
|
+
const isDecimal = /^[0-9]+$/.test(chainId);
|
|
108
|
+
|
|
109
|
+
// `parseInt` stops at the first bad character, so '12abc' would become chain id '12'.
|
|
110
|
+
if (!isHex && !isDecimal) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const reference = parseInt(chainId, isHex ? HEX_RADIX : DECIMAL_RADIX);
|
|
115
|
+
|
|
116
|
+
return Number.isSafeInteger(reference) ? `${namespace}:${reference}` : null;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type CaipResolver =
|
|
120
|
+
| CaipChainId
|
|
121
|
+
| ((blockchainMeta: BlockchainMetaForCaip) => CaipChainId | null)
|
|
122
|
+
| null;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* A total `Record` on purpose: a new `TransactionType` in rango-types fails to compile
|
|
126
|
+
* here instead of silently making that family invisible to every wallet.
|
|
127
|
+
*/
|
|
128
|
+
const CAIP_BY_TRANSACTION_TYPE: Record<TransactionType, CaipResolver> = {
|
|
129
|
+
/*
|
|
130
|
+
* Fixed ids, ignoring meta `chainId` — it is NOT the CAIP reference for several of
|
|
131
|
+
* these (meta reports Solana as 'mainnet-beta', Sui as 'sui-mainnet'), so deriving
|
|
132
|
+
* from it would produce ids that don't match the accounts providers report.
|
|
133
|
+
*/
|
|
134
|
+
[TransactionType.SOLANA]: CAIP_CHAINS.SOLANA,
|
|
135
|
+
[TransactionType.STARKNET]: CAIP_CHAINS.STARKNET,
|
|
136
|
+
[TransactionType.STELLAR]: CAIP_CHAINS.STELLAR,
|
|
137
|
+
[TransactionType.SUI]: CAIP_CHAINS.SUI,
|
|
138
|
+
[TransactionType.TON]: CAIP_CHAINS.TON,
|
|
139
|
+
[TransactionType.TRON]: CAIP_CHAINS.TRON,
|
|
140
|
+
[TransactionType.XRPL]: CAIP_CHAINS.XRPL,
|
|
141
|
+
|
|
142
|
+
[TransactionType.EVM]: (blockchainMeta) =>
|
|
143
|
+
toNumericCaip(CAIP_EVM_NAMESPACE, blockchainMeta.chainId),
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* `eip155` so the wallets claiming the whole EVM family keep supporting Hyperliquid,
|
|
147
|
+
* as they did when they listed it by name. The reference is meta's 1337, NOT
|
|
148
|
+
* HyperEVM's real 999 — safe only because an `eip155` reference is never turned back
|
|
149
|
+
* into a chain id. Give Hyperliquid its own namespace before deriving a network
|
|
150
|
+
* switch or RPC target from this.
|
|
151
|
+
*/
|
|
152
|
+
[TransactionType.HYPERLIQUID]: (blockchainMeta) =>
|
|
153
|
+
toNumericCaip(CAIP_EVM_NAMESPACE, blockchainMeta.chainId),
|
|
154
|
+
|
|
155
|
+
[TransactionType.TRANSFER]: (blockchainMeta) =>
|
|
156
|
+
CAIP_BY_TRANSFER_BLOCKCHAIN_NAME[blockchainMeta.name] ?? null,
|
|
157
|
+
|
|
158
|
+
// Not addressable — no namespace claims it, so no provider can match it.
|
|
159
|
+
[TransactionType.COSMOS]: null,
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Convert a meta entry to its CAIP-2 chain id, so providers are handed CAIP rather than
|
|
164
|
+
* Rango names. `null` means "not addressable by CAIP" — callers should skip the chain
|
|
165
|
+
* rather than fall back to a name.
|
|
166
|
+
*/
|
|
167
|
+
export function convertBlockchainMetaToCaip(
|
|
168
|
+
blockchainMeta: BlockchainMetaForCaip
|
|
169
|
+
): CaipChainId | null {
|
|
170
|
+
const resolver = CAIP_BY_TRANSACTION_TYPE[blockchainMeta.type];
|
|
171
|
+
|
|
172
|
+
if (!resolver) {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return typeof resolver === 'function' ? resolver(blockchainMeta) : resolver;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* The name-level counterpart to {@link convertBlockchainMetaToCaip}: signers get
|
|
181
|
+
* `asset.blockchain` ('BTC'), not a chain id. Only `TRANSFER` names resolve.
|
|
182
|
+
*/
|
|
183
|
+
export function isTransferBlockchainName(
|
|
184
|
+
blockchainName: string,
|
|
185
|
+
caipChainId: CaipChainId
|
|
186
|
+
): boolean {
|
|
187
|
+
return CAIP_BY_TRANSFER_BLOCKCHAIN_NAME[blockchainName] === caipChainId;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function isBitcoinBlockchain(blockchainName: string): boolean {
|
|
191
|
+
return isTransferBlockchainName(blockchainName, CAIP_CHAINS.BITCOIN);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function isZcashBlockchain(blockchainName: string): boolean {
|
|
195
|
+
return isTransferBlockchainName(blockchainName, CAIP_CHAINS.ZCASH);
|
|
196
|
+
}
|
package/src/mod.ts
ADDED
package/src/networks.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export enum Networks {
|
|
2
|
+
BTC = 'BTC',
|
|
3
|
+
BSC = 'BSC',
|
|
4
|
+
LTC = 'LTC',
|
|
5
|
+
THORCHAIN = 'THOR',
|
|
6
|
+
BCH = 'BCH',
|
|
7
|
+
BINANCE = 'BNB',
|
|
8
|
+
BLAST = 'BLAST',
|
|
9
|
+
CELO = 'CELO',
|
|
10
|
+
LINEA = 'LINEA',
|
|
11
|
+
METIS = 'METIS',
|
|
12
|
+
SONIC = 'SONIC',
|
|
13
|
+
BERACHAIN = 'BERACHAIN',
|
|
14
|
+
ZETA_CHAIN = 'ZETA_CHAIN',
|
|
15
|
+
SCROLL = 'SCROLL',
|
|
16
|
+
ZKSYNC = 'ZKSYNC',
|
|
17
|
+
MONAD = 'MONAD',
|
|
18
|
+
ETHEREUM = 'ETH',
|
|
19
|
+
POLYGON = 'POLYGON',
|
|
20
|
+
POLKADOT = '',
|
|
21
|
+
TRON = 'TRON',
|
|
22
|
+
DOGE = 'DOGE',
|
|
23
|
+
HARMONY = 'HARMONY',
|
|
24
|
+
AVAX_CCHAIN = 'AVAX_CCHAIN',
|
|
25
|
+
FANTOM = 'FANTOM',
|
|
26
|
+
MOONBEAM = 'MOONBEAM',
|
|
27
|
+
ARBITRUM = 'ARBITRUM',
|
|
28
|
+
BOBA = 'BOBA',
|
|
29
|
+
OPTIMISM = 'OPTIMISM',
|
|
30
|
+
FUSE = 'FUSE',
|
|
31
|
+
CRONOS = 'CRONOS',
|
|
32
|
+
SOLANA = 'SOLANA',
|
|
33
|
+
MOONRIVER = 'MOONRIVER',
|
|
34
|
+
GNOSIS = 'GNOSIS',
|
|
35
|
+
MAYA = 'MAYA',
|
|
36
|
+
STARKNET = 'STARKNET',
|
|
37
|
+
STELLAR = 'STELLAR',
|
|
38
|
+
TON = 'TON',
|
|
39
|
+
BASE = 'BASE',
|
|
40
|
+
SUI = 'SUI',
|
|
41
|
+
XRPL = 'XRPL',
|
|
42
|
+
ZCASH = 'ZCASH',
|
|
43
|
+
HYPERLIQUID = 'HYPERLIQUID',
|
|
44
|
+
|
|
45
|
+
// Using instead of null
|
|
46
|
+
Unknown = 'Unkown',
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const HYPERLIQUID_SIGN_NETWORK = Networks.ARBITRUM;
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { Provider } from '@hub3js/core';
|
|
2
|
+
import type { Chain } from '@hub3js/evm';
|
|
3
|
+
import type { BlockchainMeta, EvmBlockchainMeta } from 'rango-types';
|
|
4
|
+
|
|
5
|
+
import { convertBlockchainMetaToCaip } from './caip.js';
|
|
6
|
+
|
|
7
|
+
type ChainSupport = {
|
|
8
|
+
isChainSupported: (chainId: string) => boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type EvmNetworksChainInfo = Record<string, Chain>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The chains of `allBlockChains` a single namespace can address. Chains that don't
|
|
15
|
+
* convert to CAIP are dropped rather than guessed at - see
|
|
16
|
+
* {@link convertBlockchainMetaToCaip}.
|
|
17
|
+
*/
|
|
18
|
+
export function getSupportedChainsFromNamespace(
|
|
19
|
+
namespace: ChainSupport,
|
|
20
|
+
allBlockChains: BlockchainMeta[] | undefined
|
|
21
|
+
): BlockchainMeta[] {
|
|
22
|
+
return (
|
|
23
|
+
allBlockChains?.filter((blockchain) => {
|
|
24
|
+
const chainId = convertBlockchainMetaToCaip(blockchain);
|
|
25
|
+
|
|
26
|
+
return chainId ? namespace.isChainSupported(chainId) : false;
|
|
27
|
+
}) ?? []
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The union of what every namespace of a provider supports, in `allBlockChains` order
|
|
33
|
+
* and without duplicates when two namespaces claim the same chain.
|
|
34
|
+
*/
|
|
35
|
+
export function getSupportedChainsFromProvider(
|
|
36
|
+
provider: Provider,
|
|
37
|
+
allBlockChains: BlockchainMeta[] | undefined
|
|
38
|
+
): BlockchainMeta[] {
|
|
39
|
+
const namespacesProperty = provider
|
|
40
|
+
.info()
|
|
41
|
+
?.metadata.properties?.find((property) => property.name === 'namespaces');
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
allBlockChains?.filter((blockchain) => {
|
|
45
|
+
const chainId = convertBlockchainMetaToCaip(blockchain);
|
|
46
|
+
|
|
47
|
+
if (!chainId) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
namespacesProperty?.value.data.some((namespace) =>
|
|
53
|
+
namespace.isChainSupported(chainId)
|
|
54
|
+
) ?? false
|
|
55
|
+
);
|
|
56
|
+
}) ?? []
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/*
|
|
61
|
+
* TODO: remove this. It exists only so a provider can look a chain up by Rango's
|
|
62
|
+
* network name, which is knowledge a provider shouldn't carry — the caller already
|
|
63
|
+
* resolves the chain and should hand the provider an EIP-3085 description instead.
|
|
64
|
+
* Once every consumer does that, this table and the providers' dependency on
|
|
65
|
+
* Rango's chain model go away together.
|
|
66
|
+
*/
|
|
67
|
+
export function convertEvmBlockchainMetaToEvmChainInfo(
|
|
68
|
+
evmBlockchains: EvmBlockchainMeta[]
|
|
69
|
+
): EvmNetworksChainInfo {
|
|
70
|
+
return evmBlockchains.reduce<EvmNetworksChainInfo>(
|
|
71
|
+
(evmNetworksChainInfo, blockchainMeta) => {
|
|
72
|
+
evmNetworksChainInfo[blockchainMeta.name] = {
|
|
73
|
+
chainName: blockchainMeta.info.chainName,
|
|
74
|
+
chainId: blockchainMeta.chainId,
|
|
75
|
+
nativeCurrency: blockchainMeta.info.nativeCurrency,
|
|
76
|
+
rpcUrls: blockchainMeta.info.rpcUrls,
|
|
77
|
+
blockExplorerUrls: blockchainMeta.info.blockExplorerUrls,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
return evmNetworksChainInfo;
|
|
81
|
+
},
|
|
82
|
+
{}
|
|
83
|
+
);
|
|
84
|
+
}
|