@gfxlabs/oku-chains 1.12.5 → 1.12.6
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/browser.js +183 -9
- package/dist/index-mjs.js +182 -10
- package/dist/index.js +183 -9
- package/dist/types/index.d.ts +57 -0
- package/dist/types/spec/index.d.ts +63 -7
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -6855,17 +6855,102 @@
|
|
|
6855
6855
|
*/
|
|
6856
6856
|
const NON_EVM_CHAIN_ID = 0;
|
|
6857
6857
|
/**
|
|
6858
|
-
*
|
|
6859
|
-
*
|
|
6860
|
-
*
|
|
6861
|
-
* (
|
|
6858
|
+
* High-level chain family, derived from the chain's CAIP-2 namespace.
|
|
6859
|
+
*
|
|
6860
|
+
* The underlying string value of each member is the CAIP-2 namespace it maps
|
|
6861
|
+
* to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
|
|
6862
|
+
* resolve a chain's type directly from its `caip2Namespace` without relying on
|
|
6863
|
+
* sentinel values like {@link NON_EVM_CHAIN_ID}.
|
|
6864
|
+
*
|
|
6865
|
+
* @see https://chainagnostic.org/CAIPs/caip-2
|
|
6862
6866
|
*/
|
|
6863
|
-
|
|
6864
|
-
|
|
6867
|
+
exports.ChainType = void 0;
|
|
6868
|
+
(function (ChainType) {
|
|
6869
|
+
/** EVM chains (CAIP-2 namespace `eip155`). */
|
|
6870
|
+
ChainType["EVM"] = "eip155";
|
|
6871
|
+
/** Bitcoin (CAIP-2 namespace `bip122`). */
|
|
6872
|
+
ChainType["Bitcoin"] = "bip122";
|
|
6873
|
+
/** Solana (CAIP-2 namespace `solana`). */
|
|
6874
|
+
ChainType["Solana"] = "solana";
|
|
6875
|
+
/** Unknown / unrecognized CAIP-2 namespace. */
|
|
6876
|
+
ChainType["Unknown"] = "";
|
|
6877
|
+
})(exports.ChainType || (exports.ChainType = {}));
|
|
6878
|
+
/** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
|
|
6879
|
+
const CHAIN_TYPE_BY_NAMESPACE = {
|
|
6880
|
+
[exports.ChainType.EVM]: exports.ChainType.EVM,
|
|
6881
|
+
[exports.ChainType.Bitcoin]: exports.ChainType.Bitcoin,
|
|
6882
|
+
[exports.ChainType.Solana]: exports.ChainType.Solana,
|
|
6883
|
+
};
|
|
6884
|
+
/**
|
|
6885
|
+
* Resolve a CAIP-2 namespace from a chain-like value:
|
|
6886
|
+
* - an {@link IChainInfo} object: its `caip2Namespace`
|
|
6887
|
+
* - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
|
|
6888
|
+
* - a bare namespace string (e.g. `"eip155"`): used verbatim
|
|
6889
|
+
*
|
|
6890
|
+
* Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
|
|
6891
|
+
* namespace and resolves to {@link ChainType.Unknown} here. Use the
|
|
6892
|
+
* index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
|
|
6893
|
+
* those (they look the chain up first).
|
|
6894
|
+
*/
|
|
6895
|
+
function namespaceOf(c) {
|
|
6896
|
+
if (typeof c === "string") {
|
|
6897
|
+
const sep = c.indexOf(":");
|
|
6898
|
+
return sep === -1 ? c : c.slice(0, sep);
|
|
6899
|
+
}
|
|
6900
|
+
return c.caip2Namespace;
|
|
6865
6901
|
}
|
|
6866
|
-
/**
|
|
6867
|
-
|
|
6868
|
-
|
|
6902
|
+
/**
|
|
6903
|
+
* The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
|
|
6904
|
+
*
|
|
6905
|
+
* Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
|
|
6906
|
+
* like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
|
|
6907
|
+
* canonical way to determine a chain's family. Prefer it over inspecting the
|
|
6908
|
+
* numeric `id` (which is a placeholder for non-EVM chains).
|
|
6909
|
+
*
|
|
6910
|
+
* @example
|
|
6911
|
+
* ```ts
|
|
6912
|
+
* import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
|
|
6913
|
+
* chainType(mainnet) // => ChainType.EVM
|
|
6914
|
+
* chainType(bitcoin) // => ChainType.Bitcoin
|
|
6915
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
6916
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
6917
|
+
* ```
|
|
6918
|
+
*/
|
|
6919
|
+
function chainType$1(c) {
|
|
6920
|
+
return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? exports.ChainType.Unknown;
|
|
6921
|
+
}
|
|
6922
|
+
/**
|
|
6923
|
+
* True if the chain belongs to the given {@link ChainType} family.
|
|
6924
|
+
*
|
|
6925
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
6926
|
+
* checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
|
|
6927
|
+
*
|
|
6928
|
+
* @example
|
|
6929
|
+
* ```ts
|
|
6930
|
+
* import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
|
|
6931
|
+
* isNetworkType(ChainType.Bitcoin, bitcoin) // => true
|
|
6932
|
+
* isNetworkType(ChainType.EVM, bitcoin) // => false
|
|
6933
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
6934
|
+
* ```
|
|
6935
|
+
*/
|
|
6936
|
+
function isNetworkType$1(type, c) {
|
|
6937
|
+
return chainType$1(c) === type;
|
|
6938
|
+
}
|
|
6939
|
+
/**
|
|
6940
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
6941
|
+
* {@link IChainInfo} object or a CAIP-2 string.
|
|
6942
|
+
*/
|
|
6943
|
+
function isEvmChain$1(c) {
|
|
6944
|
+
return isNetworkType$1(exports.ChainType.EVM, c);
|
|
6945
|
+
}
|
|
6946
|
+
/**
|
|
6947
|
+
* True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
|
|
6948
|
+
* Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
|
|
6949
|
+
* EVM-only fields (contracts, uniswap metadata, etc.) will be present but
|
|
6950
|
+
* empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
|
|
6951
|
+
*/
|
|
6952
|
+
function isNonEvmChain$1(c) {
|
|
6953
|
+
return !isEvmChain$1(c);
|
|
6869
6954
|
}
|
|
6870
6955
|
|
|
6871
6956
|
/**
|
|
@@ -7309,6 +7394,93 @@
|
|
|
7309
7394
|
function networkByCAIP2(caip2) {
|
|
7310
7395
|
return networkByCAIP2$1(caip2, _idx);
|
|
7311
7396
|
}
|
|
7397
|
+
/**
|
|
7398
|
+
* Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
|
|
7399
|
+
* `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
|
|
7400
|
+
*/
|
|
7401
|
+
function namespaceOfChainLike(c) {
|
|
7402
|
+
if (typeof c === "object") {
|
|
7403
|
+
return c.caip2Namespace;
|
|
7404
|
+
}
|
|
7405
|
+
if (typeof c === "string") {
|
|
7406
|
+
// Full CAIP-2 identifier (namespace:reference) — classify by namespace.
|
|
7407
|
+
const sep = c.indexOf(":");
|
|
7408
|
+
if (sep !== -1) {
|
|
7409
|
+
return c.slice(0, sep);
|
|
7410
|
+
}
|
|
7411
|
+
// Bare CAIP-2 namespace (e.g. "eip155", "bip122").
|
|
7412
|
+
if (Object.values(exports.ChainType).includes(c) && c !== "") {
|
|
7413
|
+
return c;
|
|
7414
|
+
}
|
|
7415
|
+
// Otherwise treat as an internal name or numeric id string: resolve it.
|
|
7416
|
+
try {
|
|
7417
|
+
return networkByString$1(c, _idx).caip2Namespace;
|
|
7418
|
+
}
|
|
7419
|
+
catch {
|
|
7420
|
+
return "";
|
|
7421
|
+
}
|
|
7422
|
+
}
|
|
7423
|
+
// Numeric chain id.
|
|
7424
|
+
try {
|
|
7425
|
+
return networkById$1(Math.trunc(c), _idx).caip2Namespace;
|
|
7426
|
+
}
|
|
7427
|
+
catch {
|
|
7428
|
+
return "";
|
|
7429
|
+
}
|
|
7430
|
+
}
|
|
7431
|
+
/**
|
|
7432
|
+
* The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
|
|
7433
|
+
* CAIP-2 identifier or namespace string, an internal name, or a numeric chain
|
|
7434
|
+
* id. Internal names and numeric ids are resolved via the network index.
|
|
7435
|
+
*
|
|
7436
|
+
* @example
|
|
7437
|
+
* ```ts
|
|
7438
|
+
* import { chainType, ChainType } from "@gfxlabs/oku-chains";
|
|
7439
|
+
* chainType(1) // => ChainType.EVM
|
|
7440
|
+
* chainType("mainnet") // => ChainType.EVM
|
|
7441
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
7442
|
+
* chainType("bitcoin") // => ChainType.Bitcoin
|
|
7443
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
7444
|
+
* ```
|
|
7445
|
+
*/
|
|
7446
|
+
function chainType(c) {
|
|
7447
|
+
return chainType$1(namespaceOfChainLike(c));
|
|
7448
|
+
}
|
|
7449
|
+
/**
|
|
7450
|
+
* True if the chain belongs to the given {@link ChainType} family. Accepts an
|
|
7451
|
+
* {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
|
|
7452
|
+
* internal name, or a numeric chain id.
|
|
7453
|
+
*
|
|
7454
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
7455
|
+
* checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
|
|
7456
|
+
*
|
|
7457
|
+
* @example
|
|
7458
|
+
* ```ts
|
|
7459
|
+
* import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
|
|
7460
|
+
* isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
|
|
7461
|
+
* isNetworkType(ChainType.EVM, 1) // => true
|
|
7462
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
7463
|
+
* ```
|
|
7464
|
+
*/
|
|
7465
|
+
function isNetworkType(type, c) {
|
|
7466
|
+
return isNetworkType$1(type, namespaceOfChainLike(c));
|
|
7467
|
+
}
|
|
7468
|
+
/**
|
|
7469
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
7470
|
+
* {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
|
|
7471
|
+
* chain id.
|
|
7472
|
+
*/
|
|
7473
|
+
function isEvmChain(c) {
|
|
7474
|
+
return isEvmChain$1(namespaceOfChainLike(c));
|
|
7475
|
+
}
|
|
7476
|
+
/**
|
|
7477
|
+
* True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
|
|
7478
|
+
* an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
|
|
7479
|
+
* numeric chain id.
|
|
7480
|
+
*/
|
|
7481
|
+
function isNonEvmChain(c) {
|
|
7482
|
+
return isNonEvmChain$1(namespaceOfChainLike(c));
|
|
7483
|
+
}
|
|
7312
7484
|
|
|
7313
7485
|
exports.ALL_NETWORKS = ALL_NETWORKS;
|
|
7314
7486
|
exports.MAINNET_CHAINS = MAINNET_CHAINS;
|
|
@@ -7326,6 +7498,7 @@
|
|
|
7326
7498
|
exports.buildNetworkIndex = buildNetworkIndex;
|
|
7327
7499
|
exports.caip2Reference = caip2Reference;
|
|
7328
7500
|
exports.celo = celo;
|
|
7501
|
+
exports.chainType = chainType;
|
|
7329
7502
|
exports.corn = corn;
|
|
7330
7503
|
exports.etherlink = etherlink;
|
|
7331
7504
|
exports.filecoin = filecoin;
|
|
@@ -7337,6 +7510,7 @@
|
|
|
7337
7510
|
exports.hemi = hemi;
|
|
7338
7511
|
exports.hyperevm = hyperevm;
|
|
7339
7512
|
exports.isEvmChain = isEvmChain;
|
|
7513
|
+
exports.isNetworkType = isNetworkType;
|
|
7340
7514
|
exports.isNonEvmChain = isNonEvmChain;
|
|
7341
7515
|
exports.lens = lens;
|
|
7342
7516
|
exports.lightlink = lightlink;
|
package/dist/index-mjs.js
CHANGED
|
@@ -6852,17 +6852,102 @@ const zkSync = makeConfig({
|
|
|
6852
6852
|
*/
|
|
6853
6853
|
const NON_EVM_CHAIN_ID = 0;
|
|
6854
6854
|
/**
|
|
6855
|
-
*
|
|
6856
|
-
*
|
|
6857
|
-
*
|
|
6858
|
-
* (
|
|
6855
|
+
* High-level chain family, derived from the chain's CAIP-2 namespace.
|
|
6856
|
+
*
|
|
6857
|
+
* The underlying string value of each member is the CAIP-2 namespace it maps
|
|
6858
|
+
* to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
|
|
6859
|
+
* resolve a chain's type directly from its `caip2Namespace` without relying on
|
|
6860
|
+
* sentinel values like {@link NON_EVM_CHAIN_ID}.
|
|
6861
|
+
*
|
|
6862
|
+
* @see https://chainagnostic.org/CAIPs/caip-2
|
|
6859
6863
|
*/
|
|
6860
|
-
|
|
6861
|
-
|
|
6864
|
+
var ChainType;
|
|
6865
|
+
(function (ChainType) {
|
|
6866
|
+
/** EVM chains (CAIP-2 namespace `eip155`). */
|
|
6867
|
+
ChainType["EVM"] = "eip155";
|
|
6868
|
+
/** Bitcoin (CAIP-2 namespace `bip122`). */
|
|
6869
|
+
ChainType["Bitcoin"] = "bip122";
|
|
6870
|
+
/** Solana (CAIP-2 namespace `solana`). */
|
|
6871
|
+
ChainType["Solana"] = "solana";
|
|
6872
|
+
/** Unknown / unrecognized CAIP-2 namespace. */
|
|
6873
|
+
ChainType["Unknown"] = "";
|
|
6874
|
+
})(ChainType || (ChainType = {}));
|
|
6875
|
+
/** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
|
|
6876
|
+
const CHAIN_TYPE_BY_NAMESPACE = {
|
|
6877
|
+
[ChainType.EVM]: ChainType.EVM,
|
|
6878
|
+
[ChainType.Bitcoin]: ChainType.Bitcoin,
|
|
6879
|
+
[ChainType.Solana]: ChainType.Solana,
|
|
6880
|
+
};
|
|
6881
|
+
/**
|
|
6882
|
+
* Resolve a CAIP-2 namespace from a chain-like value:
|
|
6883
|
+
* - an {@link IChainInfo} object: its `caip2Namespace`
|
|
6884
|
+
* - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
|
|
6885
|
+
* - a bare namespace string (e.g. `"eip155"`): used verbatim
|
|
6886
|
+
*
|
|
6887
|
+
* Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
|
|
6888
|
+
* namespace and resolves to {@link ChainType.Unknown} here. Use the
|
|
6889
|
+
* index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
|
|
6890
|
+
* those (they look the chain up first).
|
|
6891
|
+
*/
|
|
6892
|
+
function namespaceOf(c) {
|
|
6893
|
+
if (typeof c === "string") {
|
|
6894
|
+
const sep = c.indexOf(":");
|
|
6895
|
+
return sep === -1 ? c : c.slice(0, sep);
|
|
6896
|
+
}
|
|
6897
|
+
return c.caip2Namespace;
|
|
6862
6898
|
}
|
|
6863
|
-
/**
|
|
6864
|
-
|
|
6865
|
-
|
|
6899
|
+
/**
|
|
6900
|
+
* The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
|
|
6901
|
+
*
|
|
6902
|
+
* Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
|
|
6903
|
+
* like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
|
|
6904
|
+
* canonical way to determine a chain's family. Prefer it over inspecting the
|
|
6905
|
+
* numeric `id` (which is a placeholder for non-EVM chains).
|
|
6906
|
+
*
|
|
6907
|
+
* @example
|
|
6908
|
+
* ```ts
|
|
6909
|
+
* import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
|
|
6910
|
+
* chainType(mainnet) // => ChainType.EVM
|
|
6911
|
+
* chainType(bitcoin) // => ChainType.Bitcoin
|
|
6912
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
6913
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
6914
|
+
* ```
|
|
6915
|
+
*/
|
|
6916
|
+
function chainType$1(c) {
|
|
6917
|
+
return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? ChainType.Unknown;
|
|
6918
|
+
}
|
|
6919
|
+
/**
|
|
6920
|
+
* True if the chain belongs to the given {@link ChainType} family.
|
|
6921
|
+
*
|
|
6922
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
6923
|
+
* checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
|
|
6924
|
+
*
|
|
6925
|
+
* @example
|
|
6926
|
+
* ```ts
|
|
6927
|
+
* import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
|
|
6928
|
+
* isNetworkType(ChainType.Bitcoin, bitcoin) // => true
|
|
6929
|
+
* isNetworkType(ChainType.EVM, bitcoin) // => false
|
|
6930
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
6931
|
+
* ```
|
|
6932
|
+
*/
|
|
6933
|
+
function isNetworkType$1(type, c) {
|
|
6934
|
+
return chainType$1(c) === type;
|
|
6935
|
+
}
|
|
6936
|
+
/**
|
|
6937
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
6938
|
+
* {@link IChainInfo} object or a CAIP-2 string.
|
|
6939
|
+
*/
|
|
6940
|
+
function isEvmChain$1(c) {
|
|
6941
|
+
return isNetworkType$1(ChainType.EVM, c);
|
|
6942
|
+
}
|
|
6943
|
+
/**
|
|
6944
|
+
* True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
|
|
6945
|
+
* Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
|
|
6946
|
+
* EVM-only fields (contracts, uniswap metadata, etc.) will be present but
|
|
6947
|
+
* empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
|
|
6948
|
+
*/
|
|
6949
|
+
function isNonEvmChain$1(c) {
|
|
6950
|
+
return !isEvmChain$1(c);
|
|
6866
6951
|
}
|
|
6867
6952
|
|
|
6868
6953
|
/**
|
|
@@ -7306,5 +7391,92 @@ function networkByString(s) {
|
|
|
7306
7391
|
function networkByCAIP2(caip2) {
|
|
7307
7392
|
return networkByCAIP2$1(caip2, _idx);
|
|
7308
7393
|
}
|
|
7394
|
+
/**
|
|
7395
|
+
* Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
|
|
7396
|
+
* `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
|
|
7397
|
+
*/
|
|
7398
|
+
function namespaceOfChainLike(c) {
|
|
7399
|
+
if (typeof c === "object") {
|
|
7400
|
+
return c.caip2Namespace;
|
|
7401
|
+
}
|
|
7402
|
+
if (typeof c === "string") {
|
|
7403
|
+
// Full CAIP-2 identifier (namespace:reference) — classify by namespace.
|
|
7404
|
+
const sep = c.indexOf(":");
|
|
7405
|
+
if (sep !== -1) {
|
|
7406
|
+
return c.slice(0, sep);
|
|
7407
|
+
}
|
|
7408
|
+
// Bare CAIP-2 namespace (e.g. "eip155", "bip122").
|
|
7409
|
+
if (Object.values(ChainType).includes(c) && c !== "") {
|
|
7410
|
+
return c;
|
|
7411
|
+
}
|
|
7412
|
+
// Otherwise treat as an internal name or numeric id string: resolve it.
|
|
7413
|
+
try {
|
|
7414
|
+
return networkByString$1(c, _idx).caip2Namespace;
|
|
7415
|
+
}
|
|
7416
|
+
catch {
|
|
7417
|
+
return "";
|
|
7418
|
+
}
|
|
7419
|
+
}
|
|
7420
|
+
// Numeric chain id.
|
|
7421
|
+
try {
|
|
7422
|
+
return networkById$1(Math.trunc(c), _idx).caip2Namespace;
|
|
7423
|
+
}
|
|
7424
|
+
catch {
|
|
7425
|
+
return "";
|
|
7426
|
+
}
|
|
7427
|
+
}
|
|
7428
|
+
/**
|
|
7429
|
+
* The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
|
|
7430
|
+
* CAIP-2 identifier or namespace string, an internal name, or a numeric chain
|
|
7431
|
+
* id. Internal names and numeric ids are resolved via the network index.
|
|
7432
|
+
*
|
|
7433
|
+
* @example
|
|
7434
|
+
* ```ts
|
|
7435
|
+
* import { chainType, ChainType } from "@gfxlabs/oku-chains";
|
|
7436
|
+
* chainType(1) // => ChainType.EVM
|
|
7437
|
+
* chainType("mainnet") // => ChainType.EVM
|
|
7438
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
7439
|
+
* chainType("bitcoin") // => ChainType.Bitcoin
|
|
7440
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
7441
|
+
* ```
|
|
7442
|
+
*/
|
|
7443
|
+
function chainType(c) {
|
|
7444
|
+
return chainType$1(namespaceOfChainLike(c));
|
|
7445
|
+
}
|
|
7446
|
+
/**
|
|
7447
|
+
* True if the chain belongs to the given {@link ChainType} family. Accepts an
|
|
7448
|
+
* {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
|
|
7449
|
+
* internal name, or a numeric chain id.
|
|
7450
|
+
*
|
|
7451
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
7452
|
+
* checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
|
|
7453
|
+
*
|
|
7454
|
+
* @example
|
|
7455
|
+
* ```ts
|
|
7456
|
+
* import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
|
|
7457
|
+
* isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
|
|
7458
|
+
* isNetworkType(ChainType.EVM, 1) // => true
|
|
7459
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
7460
|
+
* ```
|
|
7461
|
+
*/
|
|
7462
|
+
function isNetworkType(type, c) {
|
|
7463
|
+
return isNetworkType$1(type, namespaceOfChainLike(c));
|
|
7464
|
+
}
|
|
7465
|
+
/**
|
|
7466
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
7467
|
+
* {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
|
|
7468
|
+
* chain id.
|
|
7469
|
+
*/
|
|
7470
|
+
function isEvmChain(c) {
|
|
7471
|
+
return isEvmChain$1(namespaceOfChainLike(c));
|
|
7472
|
+
}
|
|
7473
|
+
/**
|
|
7474
|
+
* True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
|
|
7475
|
+
* an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
|
|
7476
|
+
* numeric chain id.
|
|
7477
|
+
*/
|
|
7478
|
+
function isNonEvmChain(c) {
|
|
7479
|
+
return isNonEvmChain$1(namespaceOfChainLike(c));
|
|
7480
|
+
}
|
|
7309
7481
|
|
|
7310
|
-
export { ALL_NETWORKS, MAINNET_CHAINS, NON_EVM_CHAINS, NON_EVM_CHAIN_ID, NetworkNotFoundError, arbitrum, avalanche, base, bitcoin, blast, bob, boba, bsc, buildNetworkIndex, caip2Reference, celo, corn, etherlink, filecoin, formatCAIP2, fromCAIP2, gensyn, gnosis, goat, hemi, hyperevm, isEvmChain, isNonEvmChain, lens, lightlink, linea, lisk, mainnet, makeConfig, manta, mantle, matchain, metal, monad, moonbeam, networkByAny, networkByCAIP2, networkById, networkByName, networkByString, nibiru, optimism, parseCAIP2, pharos, plasma, polygon, polygonZkEvm, redbelly, ronin, rootstock, saga, scroll, sei, sonic, taiko, telos, toCAIP2, tronShasta, unichain, worldchain, xdc, zerog, zkSync };
|
|
7482
|
+
export { ALL_NETWORKS, ChainType, MAINNET_CHAINS, NON_EVM_CHAINS, NON_EVM_CHAIN_ID, NetworkNotFoundError, arbitrum, avalanche, base, bitcoin, blast, bob, boba, bsc, buildNetworkIndex, caip2Reference, celo, chainType, corn, etherlink, filecoin, formatCAIP2, fromCAIP2, gensyn, gnosis, goat, hemi, hyperevm, isEvmChain, isNetworkType, isNonEvmChain, lens, lightlink, linea, lisk, mainnet, makeConfig, manta, mantle, matchain, metal, monad, moonbeam, networkByAny, networkByCAIP2, networkById, networkByName, networkByString, nibiru, optimism, parseCAIP2, pharos, plasma, polygon, polygonZkEvm, redbelly, ronin, rootstock, saga, scroll, sei, sonic, taiko, telos, toCAIP2, tronShasta, unichain, worldchain, xdc, zerog, zkSync };
|
package/dist/index.js
CHANGED
|
@@ -6854,17 +6854,102 @@ const zkSync = makeConfig({
|
|
|
6854
6854
|
*/
|
|
6855
6855
|
const NON_EVM_CHAIN_ID = 0;
|
|
6856
6856
|
/**
|
|
6857
|
-
*
|
|
6858
|
-
*
|
|
6859
|
-
*
|
|
6860
|
-
* (
|
|
6857
|
+
* High-level chain family, derived from the chain's CAIP-2 namespace.
|
|
6858
|
+
*
|
|
6859
|
+
* The underlying string value of each member is the CAIP-2 namespace it maps
|
|
6860
|
+
* to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
|
|
6861
|
+
* resolve a chain's type directly from its `caip2Namespace` without relying on
|
|
6862
|
+
* sentinel values like {@link NON_EVM_CHAIN_ID}.
|
|
6863
|
+
*
|
|
6864
|
+
* @see https://chainagnostic.org/CAIPs/caip-2
|
|
6861
6865
|
*/
|
|
6862
|
-
|
|
6863
|
-
|
|
6866
|
+
exports.ChainType = void 0;
|
|
6867
|
+
(function (ChainType) {
|
|
6868
|
+
/** EVM chains (CAIP-2 namespace `eip155`). */
|
|
6869
|
+
ChainType["EVM"] = "eip155";
|
|
6870
|
+
/** Bitcoin (CAIP-2 namespace `bip122`). */
|
|
6871
|
+
ChainType["Bitcoin"] = "bip122";
|
|
6872
|
+
/** Solana (CAIP-2 namespace `solana`). */
|
|
6873
|
+
ChainType["Solana"] = "solana";
|
|
6874
|
+
/** Unknown / unrecognized CAIP-2 namespace. */
|
|
6875
|
+
ChainType["Unknown"] = "";
|
|
6876
|
+
})(exports.ChainType || (exports.ChainType = {}));
|
|
6877
|
+
/** All recognized CAIP-2 namespaces, keyed by {@link ChainType}. */
|
|
6878
|
+
const CHAIN_TYPE_BY_NAMESPACE = {
|
|
6879
|
+
[exports.ChainType.EVM]: exports.ChainType.EVM,
|
|
6880
|
+
[exports.ChainType.Bitcoin]: exports.ChainType.Bitcoin,
|
|
6881
|
+
[exports.ChainType.Solana]: exports.ChainType.Solana,
|
|
6882
|
+
};
|
|
6883
|
+
/**
|
|
6884
|
+
* Resolve a CAIP-2 namespace from a chain-like value:
|
|
6885
|
+
* - an {@link IChainInfo} object: its `caip2Namespace`
|
|
6886
|
+
* - a CAIP-2 identifier string (e.g. `"eip155:1"`): the part before the `:`
|
|
6887
|
+
* - a bare namespace string (e.g. `"eip155"`): used verbatim
|
|
6888
|
+
*
|
|
6889
|
+
* Note: a bare internal name (e.g. `"bitcoin"`) or numeric id is NOT a CAIP-2
|
|
6890
|
+
* namespace and resolves to {@link ChainType.Unknown} here. Use the
|
|
6891
|
+
* index-bound `chainType`/`isNetworkType` in the package entrypoint to resolve
|
|
6892
|
+
* those (they look the chain up first).
|
|
6893
|
+
*/
|
|
6894
|
+
function namespaceOf(c) {
|
|
6895
|
+
if (typeof c === "string") {
|
|
6896
|
+
const sep = c.indexOf(":");
|
|
6897
|
+
return sep === -1 ? c : c.slice(0, sep);
|
|
6898
|
+
}
|
|
6899
|
+
return c.caip2Namespace;
|
|
6864
6900
|
}
|
|
6865
|
-
/**
|
|
6866
|
-
|
|
6867
|
-
|
|
6901
|
+
/**
|
|
6902
|
+
* The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
|
|
6903
|
+
*
|
|
6904
|
+
* Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
|
|
6905
|
+
* like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
|
|
6906
|
+
* canonical way to determine a chain's family. Prefer it over inspecting the
|
|
6907
|
+
* numeric `id` (which is a placeholder for non-EVM chains).
|
|
6908
|
+
*
|
|
6909
|
+
* @example
|
|
6910
|
+
* ```ts
|
|
6911
|
+
* import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
|
|
6912
|
+
* chainType(mainnet) // => ChainType.EVM
|
|
6913
|
+
* chainType(bitcoin) // => ChainType.Bitcoin
|
|
6914
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
6915
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
6916
|
+
* ```
|
|
6917
|
+
*/
|
|
6918
|
+
function chainType$1(c) {
|
|
6919
|
+
return CHAIN_TYPE_BY_NAMESPACE[namespaceOf(c)] ?? exports.ChainType.Unknown;
|
|
6920
|
+
}
|
|
6921
|
+
/**
|
|
6922
|
+
* True if the chain belongs to the given {@link ChainType} family.
|
|
6923
|
+
*
|
|
6924
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
6925
|
+
* checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
|
|
6926
|
+
*
|
|
6927
|
+
* @example
|
|
6928
|
+
* ```ts
|
|
6929
|
+
* import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
|
|
6930
|
+
* isNetworkType(ChainType.Bitcoin, bitcoin) // => true
|
|
6931
|
+
* isNetworkType(ChainType.EVM, bitcoin) // => false
|
|
6932
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
6933
|
+
* ```
|
|
6934
|
+
*/
|
|
6935
|
+
function isNetworkType$1(type, c) {
|
|
6936
|
+
return chainType$1(c) === type;
|
|
6937
|
+
}
|
|
6938
|
+
/**
|
|
6939
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
6940
|
+
* {@link IChainInfo} object or a CAIP-2 string.
|
|
6941
|
+
*/
|
|
6942
|
+
function isEvmChain$1(c) {
|
|
6943
|
+
return isNetworkType$1(exports.ChainType.EVM, c);
|
|
6944
|
+
}
|
|
6945
|
+
/**
|
|
6946
|
+
* True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
|
|
6947
|
+
* Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
|
|
6948
|
+
* EVM-only fields (contracts, uniswap metadata, etc.) will be present but
|
|
6949
|
+
* empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
|
|
6950
|
+
*/
|
|
6951
|
+
function isNonEvmChain$1(c) {
|
|
6952
|
+
return !isEvmChain$1(c);
|
|
6868
6953
|
}
|
|
6869
6954
|
|
|
6870
6955
|
/**
|
|
@@ -7308,6 +7393,93 @@ function networkByString(s) {
|
|
|
7308
7393
|
function networkByCAIP2(caip2) {
|
|
7309
7394
|
return networkByCAIP2$1(caip2, _idx);
|
|
7310
7395
|
}
|
|
7396
|
+
/**
|
|
7397
|
+
* Resolve a {@link ChainLike} input to the chain's `caip2Namespace`. Returns
|
|
7398
|
+
* `""` (→ {@link ChainType.Unknown}) when the input cannot be classified.
|
|
7399
|
+
*/
|
|
7400
|
+
function namespaceOfChainLike(c) {
|
|
7401
|
+
if (typeof c === "object") {
|
|
7402
|
+
return c.caip2Namespace;
|
|
7403
|
+
}
|
|
7404
|
+
if (typeof c === "string") {
|
|
7405
|
+
// Full CAIP-2 identifier (namespace:reference) — classify by namespace.
|
|
7406
|
+
const sep = c.indexOf(":");
|
|
7407
|
+
if (sep !== -1) {
|
|
7408
|
+
return c.slice(0, sep);
|
|
7409
|
+
}
|
|
7410
|
+
// Bare CAIP-2 namespace (e.g. "eip155", "bip122").
|
|
7411
|
+
if (Object.values(exports.ChainType).includes(c) && c !== "") {
|
|
7412
|
+
return c;
|
|
7413
|
+
}
|
|
7414
|
+
// Otherwise treat as an internal name or numeric id string: resolve it.
|
|
7415
|
+
try {
|
|
7416
|
+
return networkByString$1(c, _idx).caip2Namespace;
|
|
7417
|
+
}
|
|
7418
|
+
catch {
|
|
7419
|
+
return "";
|
|
7420
|
+
}
|
|
7421
|
+
}
|
|
7422
|
+
// Numeric chain id.
|
|
7423
|
+
try {
|
|
7424
|
+
return networkById$1(Math.trunc(c), _idx).caip2Namespace;
|
|
7425
|
+
}
|
|
7426
|
+
catch {
|
|
7427
|
+
return "";
|
|
7428
|
+
}
|
|
7429
|
+
}
|
|
7430
|
+
/**
|
|
7431
|
+
* The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
|
|
7432
|
+
* CAIP-2 identifier or namespace string, an internal name, or a numeric chain
|
|
7433
|
+
* id. Internal names and numeric ids are resolved via the network index.
|
|
7434
|
+
*
|
|
7435
|
+
* @example
|
|
7436
|
+
* ```ts
|
|
7437
|
+
* import { chainType, ChainType } from "@gfxlabs/oku-chains";
|
|
7438
|
+
* chainType(1) // => ChainType.EVM
|
|
7439
|
+
* chainType("mainnet") // => ChainType.EVM
|
|
7440
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
7441
|
+
* chainType("bitcoin") // => ChainType.Bitcoin
|
|
7442
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
7443
|
+
* ```
|
|
7444
|
+
*/
|
|
7445
|
+
function chainType(c) {
|
|
7446
|
+
return chainType$1(namespaceOfChainLike(c));
|
|
7447
|
+
}
|
|
7448
|
+
/**
|
|
7449
|
+
* True if the chain belongs to the given {@link ChainType} family. Accepts an
|
|
7450
|
+
* {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
|
|
7451
|
+
* internal name, or a numeric chain id.
|
|
7452
|
+
*
|
|
7453
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
7454
|
+
* checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
|
|
7455
|
+
*
|
|
7456
|
+
* @example
|
|
7457
|
+
* ```ts
|
|
7458
|
+
* import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
|
|
7459
|
+
* isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
|
|
7460
|
+
* isNetworkType(ChainType.EVM, 1) // => true
|
|
7461
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
7462
|
+
* ```
|
|
7463
|
+
*/
|
|
7464
|
+
function isNetworkType(type, c) {
|
|
7465
|
+
return isNetworkType$1(type, namespaceOfChainLike(c));
|
|
7466
|
+
}
|
|
7467
|
+
/**
|
|
7468
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
7469
|
+
* {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
|
|
7470
|
+
* chain id.
|
|
7471
|
+
*/
|
|
7472
|
+
function isEvmChain(c) {
|
|
7473
|
+
return isEvmChain$1(namespaceOfChainLike(c));
|
|
7474
|
+
}
|
|
7475
|
+
/**
|
|
7476
|
+
* True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
|
|
7477
|
+
* an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
|
|
7478
|
+
* numeric chain id.
|
|
7479
|
+
*/
|
|
7480
|
+
function isNonEvmChain(c) {
|
|
7481
|
+
return isNonEvmChain$1(namespaceOfChainLike(c));
|
|
7482
|
+
}
|
|
7311
7483
|
|
|
7312
7484
|
exports.ALL_NETWORKS = ALL_NETWORKS;
|
|
7313
7485
|
exports.MAINNET_CHAINS = MAINNET_CHAINS;
|
|
@@ -7325,6 +7497,7 @@ exports.bsc = bsc;
|
|
|
7325
7497
|
exports.buildNetworkIndex = buildNetworkIndex;
|
|
7326
7498
|
exports.caip2Reference = caip2Reference;
|
|
7327
7499
|
exports.celo = celo;
|
|
7500
|
+
exports.chainType = chainType;
|
|
7328
7501
|
exports.corn = corn;
|
|
7329
7502
|
exports.etherlink = etherlink;
|
|
7330
7503
|
exports.filecoin = filecoin;
|
|
@@ -7336,6 +7509,7 @@ exports.goat = goat;
|
|
|
7336
7509
|
exports.hemi = hemi;
|
|
7337
7510
|
exports.hyperevm = hyperevm;
|
|
7338
7511
|
exports.isEvmChain = isEvmChain;
|
|
7512
|
+
exports.isNetworkType = isNetworkType;
|
|
7339
7513
|
exports.isNonEvmChain = isNonEvmChain;
|
|
7340
7514
|
exports.lens = lens;
|
|
7341
7515
|
exports.lightlink = lightlink;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./util/caip2";
|
|
|
5
5
|
export { makeConfig } from "./util/index";
|
|
6
6
|
export { buildNetworkIndex, type NetworkIndex, NetworkNotFoundError, } from "./util/lookup";
|
|
7
7
|
import type { IChainInfo } from "./spec";
|
|
8
|
+
import { ChainType } from "./spec";
|
|
8
9
|
export declare const MAINNET_CHAINS: readonly [Readonly<{
|
|
9
10
|
name: "Arbitrum";
|
|
10
11
|
launchTime: 1688997600;
|
|
@@ -10836,3 +10837,59 @@ export declare function networkByString(s: string): IChainInfo;
|
|
|
10836
10837
|
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
10837
10838
|
*/
|
|
10838
10839
|
export declare function networkByCAIP2(caip2: string): IChainInfo;
|
|
10840
|
+
/**
|
|
10841
|
+
* Accepted input for the chain-family helpers ({@link chainType},
|
|
10842
|
+
* {@link isNetworkType}, etc.).
|
|
10843
|
+
*
|
|
10844
|
+
* - `IChainInfo`: classified by its `caip2Namespace`.
|
|
10845
|
+
* - CAIP-2 string (contains `:`, e.g. `"eip155:1"`) or bare namespace
|
|
10846
|
+
* (e.g. `"bip122"`): classified directly by the namespace, no lookup needed.
|
|
10847
|
+
* - internal name (e.g. `"bitcoin"`) or numeric id / id string: resolved to a
|
|
10848
|
+
* chain via the network index first, then classified.
|
|
10849
|
+
*/
|
|
10850
|
+
export type ChainLike = IChainInfo | string | number;
|
|
10851
|
+
/**
|
|
10852
|
+
* The {@link ChainType} of a chain. Accepts an {@link IChainInfo} object, a
|
|
10853
|
+
* CAIP-2 identifier or namespace string, an internal name, or a numeric chain
|
|
10854
|
+
* id. Internal names and numeric ids are resolved via the network index.
|
|
10855
|
+
*
|
|
10856
|
+
* @example
|
|
10857
|
+
* ```ts
|
|
10858
|
+
* import { chainType, ChainType } from "@gfxlabs/oku-chains";
|
|
10859
|
+
* chainType(1) // => ChainType.EVM
|
|
10860
|
+
* chainType("mainnet") // => ChainType.EVM
|
|
10861
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
10862
|
+
* chainType("bitcoin") // => ChainType.Bitcoin
|
|
10863
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
10864
|
+
* ```
|
|
10865
|
+
*/
|
|
10866
|
+
export declare function chainType(c: ChainLike): ChainType;
|
|
10867
|
+
/**
|
|
10868
|
+
* True if the chain belongs to the given {@link ChainType} family. Accepts an
|
|
10869
|
+
* {@link IChainInfo} object, a CAIP-2 identifier or namespace string, an
|
|
10870
|
+
* internal name, or a numeric chain id.
|
|
10871
|
+
*
|
|
10872
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
10873
|
+
* checks, e.g. `isNetworkType(ChainType.Bitcoin, "bitcoin")`.
|
|
10874
|
+
*
|
|
10875
|
+
* @example
|
|
10876
|
+
* ```ts
|
|
10877
|
+
* import { isNetworkType, ChainType } from "@gfxlabs/oku-chains";
|
|
10878
|
+
* isNetworkType(ChainType.Bitcoin, "bitcoin") // => true
|
|
10879
|
+
* isNetworkType(ChainType.EVM, 1) // => true
|
|
10880
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
10881
|
+
* ```
|
|
10882
|
+
*/
|
|
10883
|
+
export declare function isNetworkType(type: ChainType, c: ChainLike): boolean;
|
|
10884
|
+
/**
|
|
10885
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
10886
|
+
* {@link IChainInfo} object, a CAIP-2 string, an internal name, or a numeric
|
|
10887
|
+
* chain id.
|
|
10888
|
+
*/
|
|
10889
|
+
export declare function isEvmChain(c: ChainLike): boolean;
|
|
10890
|
+
/**
|
|
10891
|
+
* True if the chain is non-EVM (its CAIP-2 namespace is not `eip155`). Accepts
|
|
10892
|
+
* an {@link IChainInfo} object, a CAIP-2 string, an internal name, or a
|
|
10893
|
+
* numeric chain id.
|
|
10894
|
+
*/
|
|
10895
|
+
export declare function isNonEvmChain(c: ChainLike): boolean;
|
|
@@ -242,11 +242,67 @@ export interface IChainInfo<formatters extends ChainFormatters | undefined = Cha
|
|
|
242
242
|
*/
|
|
243
243
|
export declare const NON_EVM_CHAIN_ID = 0;
|
|
244
244
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* (
|
|
245
|
+
* High-level chain family, derived from the chain's CAIP-2 namespace.
|
|
246
|
+
*
|
|
247
|
+
* The underlying string value of each member is the CAIP-2 namespace it maps
|
|
248
|
+
* to (e.g. `eip155` for EVM, `bip122` for Bitcoin), so {@link chainType} can
|
|
249
|
+
* resolve a chain's type directly from its `caip2Namespace` without relying on
|
|
250
|
+
* sentinel values like {@link NON_EVM_CHAIN_ID}.
|
|
251
|
+
*
|
|
252
|
+
* @see https://chainagnostic.org/CAIPs/caip-2
|
|
253
|
+
*/
|
|
254
|
+
export declare enum ChainType {
|
|
255
|
+
/** EVM chains (CAIP-2 namespace `eip155`). */
|
|
256
|
+
EVM = "eip155",
|
|
257
|
+
/** Bitcoin (CAIP-2 namespace `bip122`). */
|
|
258
|
+
Bitcoin = "bip122",
|
|
259
|
+
/** Solana (CAIP-2 namespace `solana`). */
|
|
260
|
+
Solana = "solana",
|
|
261
|
+
/** Unknown / unrecognized CAIP-2 namespace. */
|
|
262
|
+
Unknown = ""
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* The {@link ChainType} of a chain, derived from its CAIP-2 namespace.
|
|
266
|
+
*
|
|
267
|
+
* Accepts an {@link IChainInfo} object or a CAIP-2 string (a full identifier
|
|
268
|
+
* like `"eip155:1"` or a bare namespace like `"bip122"`). This is the
|
|
269
|
+
* canonical way to determine a chain's family. Prefer it over inspecting the
|
|
270
|
+
* numeric `id` (which is a placeholder for non-EVM chains).
|
|
271
|
+
*
|
|
272
|
+
* @example
|
|
273
|
+
* ```ts
|
|
274
|
+
* import { mainnet, bitcoin } from "@gfxlabs/oku-chains";
|
|
275
|
+
* chainType(mainnet) // => ChainType.EVM
|
|
276
|
+
* chainType(bitcoin) // => ChainType.Bitcoin
|
|
277
|
+
* chainType("eip155:1") // => ChainType.EVM
|
|
278
|
+
* chainType("bip122") // => ChainType.Bitcoin
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
export declare function chainType(c: IChainInfo | string): ChainType;
|
|
282
|
+
/**
|
|
283
|
+
* True if the chain belongs to the given {@link ChainType} family.
|
|
284
|
+
*
|
|
285
|
+
* Reusable, namespace-driven replacement for one-off `isBitcoinChain` style
|
|
286
|
+
* checks. The chain may be an {@link IChainInfo} object or a CAIP-2 string.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```ts
|
|
290
|
+
* import { ChainType, isNetworkType, bitcoin } from "@gfxlabs/oku-chains";
|
|
291
|
+
* isNetworkType(ChainType.Bitcoin, bitcoin) // => true
|
|
292
|
+
* isNetworkType(ChainType.EVM, bitcoin) // => false
|
|
293
|
+
* isNetworkType(ChainType.EVM, "eip155:1") // => true
|
|
294
|
+
* ```
|
|
295
|
+
*/
|
|
296
|
+
export declare function isNetworkType(type: ChainType, c: IChainInfo | string): boolean;
|
|
297
|
+
/**
|
|
298
|
+
* True if the chain is an EVM chain (CAIP-2 namespace `eip155`). Accepts an
|
|
299
|
+
* {@link IChainInfo} object or a CAIP-2 string.
|
|
300
|
+
*/
|
|
301
|
+
export declare function isEvmChain(c: IChainInfo | string): boolean;
|
|
302
|
+
/**
|
|
303
|
+
* True if the chain is non-EVM (i.e. its CAIP-2 namespace is not `eip155`).
|
|
304
|
+
* Non-EVM chains live in the same {@link IChainInfo} shape as EVM chains, so
|
|
305
|
+
* EVM-only fields (contracts, uniswap metadata, etc.) will be present but
|
|
306
|
+
* empty. Accepts an {@link IChainInfo} object or a CAIP-2 string.
|
|
249
307
|
*/
|
|
250
|
-
export declare function isNonEvmChain(c: IChainInfo): boolean;
|
|
251
|
-
/** True if the chain is an EVM chain. Inverse of {@link isNonEvmChain}. */
|
|
252
|
-
export declare function isEvmChain(c: IChainInfo): boolean;
|
|
308
|
+
export declare function isNonEvmChain(c: IChainInfo | string): boolean;
|