@gfxlabs/oku-chains 1.12.3 → 1.12.5
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 +362 -3
- package/dist/index-mjs.js +348 -4
- package/dist/index.js +362 -3
- package/dist/types/index.d.ts +76 -0
- package/dist/types/non-evm/bitcoin.d.ts +83 -0
- package/dist/types/non-evm/index.d.ts +12 -0
- package/dist/types/spec/index.d.ts +31 -0
- package/dist/types/util/caip2.d.ts +12 -1
- package/dist/types/util/lookup.d.ts +68 -0
- package/package.json +2 -2
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { IChainInfo } from "../spec";
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when a network cannot be found by any lookup method.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NetworkNotFoundError extends Error {
|
|
6
|
+
constructor(input: unknown);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Pre-computed lookup index for fast chain resolution.
|
|
10
|
+
*/
|
|
11
|
+
export interface NetworkIndex {
|
|
12
|
+
byId: Map<number, IChainInfo>;
|
|
13
|
+
byName: Map<string, IChainInfo>;
|
|
14
|
+
byCAIP2: Map<string, IChainInfo>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a lookup index from a list of chains for fast repeated lookups.
|
|
18
|
+
* Pre-computes maps keyed by chain ID, internal name, and CAIP-2 identifier.
|
|
19
|
+
*
|
|
20
|
+
* Non-EVM chains use the {@link NON_EVM_CHAIN_ID} (`0`) placeholder id and are
|
|
21
|
+
* intentionally NOT registered in `byId` (they are not resolvable by numeric
|
|
22
|
+
* id, and would otherwise all collide on `0`). They remain resolvable by
|
|
23
|
+
* internal name and by their explicit CAIP-2 identifier.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildNetworkIndex(chains: readonly IChainInfo[]): NetworkIndex;
|
|
26
|
+
/**
|
|
27
|
+
* Look up a chain by its numeric chain ID. Non-EVM chains use the
|
|
28
|
+
* {@link NON_EVM_CHAIN_ID} placeholder and are not resolvable here.
|
|
29
|
+
*/
|
|
30
|
+
export declare function networkById(id: number, idx: NetworkIndex): IChainInfo;
|
|
31
|
+
/**
|
|
32
|
+
* Look up a chain by its internal name (e.g. "arbitrum", "mainnet",
|
|
33
|
+
* "bitcoin").
|
|
34
|
+
*/
|
|
35
|
+
export declare function networkByName(name: string, idx: NetworkIndex): IChainInfo;
|
|
36
|
+
/**
|
|
37
|
+
* Look up a chain by its CAIP-2 identifier string (e.g. "eip155:1" or
|
|
38
|
+
* "bip122:000000000019d6689c085ae165831e93"). This is the way to resolve
|
|
39
|
+
* non-EVM chains.
|
|
40
|
+
*/
|
|
41
|
+
export declare function networkByCAIP2(caip2: string, idx: NetworkIndex): IChainInfo;
|
|
42
|
+
/**
|
|
43
|
+
* Look up a chain from a string. Tries, in order:
|
|
44
|
+
* 1. CAIP-2 identifier (if the string contains ":")
|
|
45
|
+
* 2. Internal name
|
|
46
|
+
* 3. Numeric chain ID (parsed from string)
|
|
47
|
+
*
|
|
48
|
+
* Non-EVM chains are only reachable via the CAIP-2 or internal-name paths,
|
|
49
|
+
* never via the numeric-id fallback.
|
|
50
|
+
*
|
|
51
|
+
* Mirrors the Go `NetworkByString` function.
|
|
52
|
+
*/
|
|
53
|
+
export declare function networkByString(s: string, idx: NetworkIndex): IChainInfo;
|
|
54
|
+
/**
|
|
55
|
+
* Resolve a chain from an arbitrary input. Accepts:
|
|
56
|
+
* - `number`: treated as a numeric chain ID (EVM-only)
|
|
57
|
+
* - `string`: tried as CAIP-2 identifier (if it contains ":"), then as
|
|
58
|
+
* internal name, then as a numeric chain ID string
|
|
59
|
+
* - `IChainInfo`: returned directly (pass-through)
|
|
60
|
+
*
|
|
61
|
+
* Non-EVM chains have a placeholder numeric id, so they can only be resolved
|
|
62
|
+
* via their CAIP-2 identifier or internal name (or passed through directly).
|
|
63
|
+
*
|
|
64
|
+
* Mirrors the Go `NetworkByAny` function.
|
|
65
|
+
*
|
|
66
|
+
* @throws {NetworkNotFoundError} if no matching chain is found
|
|
67
|
+
*/
|
|
68
|
+
export declare function networkByAny(v: string | number | IChainInfo, idx: NetworkIndex): IChainInfo;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gfxlabs/oku-chains",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.5",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index-mjs.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"typescript": "^5.9.3",
|
|
54
54
|
"viem": "^2.47.11"
|
|
55
55
|
},
|
|
56
|
-
"packageManager": "yarn@4.
|
|
56
|
+
"packageManager": "yarn@4.15.0",
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"viem": "2.x"
|
|
59
59
|
}
|