@chain-registry/client 1.53.151 → 2.0.2

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/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  <img height="20" src="https://github.com/hyperweb-io/chain-registry/actions/workflows/run-tests.yml/badge.svg" />
10
10
  </a>
11
11
  <a href="https://github.com/hyperweb-io/chain-registry/blob/main/LICENSE"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
12
- <a href="https://www.npmjs.com/package/@chain-registry/client"><img height="20" src="https://img.shields.io/github/package-json/v/hyperweb-io/chain-registry?filename=v1%2Fpackages%2Fclient%2Fpackage.json"></a>
12
+ <a href="https://www.npmjs.com/package/@chain-registry/client"><img height="20" src="https://img.shields.io/github/package-json/v/hyperweb-io/chain-registry?filename=v2%2Fpackages%2Fclient%2Fpackage.json"></a>
13
13
  </p>
14
14
 
15
15
  The `@chain-registry/client` package provides a client for dynamically fetching and managing chain and asset data from the Cosmos chain registry. This tool is essential for developers who need to access up-to-date blockchain information, including asset lists and IBC data.
@@ -72,7 +72,7 @@ The `ChainRegistryClient` constructor accepts an `options` object you can specif
72
72
 
73
73
  - `ibcNamePairs` (optional): An array of string arrays, where each nested array contains two elements representing a pair of chain names. This setting specifies the Inter-Blockchain Communication (IBC) connections between the chains for which data should be considered. It is particularly useful for limiting the scope of IBC-related data processing.
74
74
 
75
- - `baseUrl` (optional): A string representing the base URL for fetching the chain registry data. If not specified, the client defaults to the official Cosmos chain registry on GitHub (`https://raw.githubusercontent.com/cosmos/chain-registry/master`).
75
+ - `baseUrl` (optional): A string representing the base URL for fetching the chain registry data. If not specified, the client defaults to the [chain registry on GitHub](`https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel`). The client will support both [`camel`](https://github.com/chain-registry/chain-registry/tree/main/registries/camel) or [`minimal`](https://github.com/chain-registry/chain-registry/tree/main/registries/minimal)
76
76
 
77
77
  #### Initialization Examples
78
78
 
@@ -173,12 +173,12 @@ import { ChainRegistryFetcher, ChainRegistryFetcherOptions } from '@chain-regist
173
173
 
174
174
  const options: ChainRegistryFetcherOptions = {
175
175
  urls: [
176
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/chain.json',
177
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/osmosis/assetlist.json',
178
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/assetlist.json',
179
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/secretnetwork/assetlist.json',
180
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/juno-osmosis.json',
181
- 'https://raw.githubusercontent.com/cosmos/chain-registry/master/_IBC/osmosis-secretnetwork.json'
176
+ 'https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel/osmosis/chain.json',
177
+ 'https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel/osmosis/assetlist.json',
178
+ 'https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel/juno/assetlist.json',
179
+ 'https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel/secretnetwork/assetlist.json',
180
+ 'https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel/_IBC/juno-osmosis.json',
181
+ 'https://raw.githubusercontent.com/chain-registry/chain-registry/refs/heads/main/registries/camel/_IBC/osmosis-secretnetwork.json'
182
182
  ]
183
183
  };
184
184
  const registry = new ChainRegistryFetcher(options);
@@ -187,7 +187,7 @@ await registry.fetchUrls();
187
187
 
188
188
  #### Fetching Schemata
189
189
 
190
- We currently only support fetching JSON schemas as defined in https://github.com/cosmos/chain-registry. Supported are `assetlist.schema.json`, `chain.schema.json` and `ibc_data.schema.json`.
190
+ We currently only support fetching JSON schemas as defined in [chain-registry/chain-registry](https://github.com/chain-registry/chain-registry) — the v2 client will support both [`camel`](https://github.com/chain-registry/chain-registry/tree/main/registries/camel) or [`minimal`](https://github.com/chain-registry/chain-registry/tree/main/registries/minimal). Supported are `assetlist.schema.json`, `chain.schema.json` and `ibc_data.schema.json`.
191
191
 
192
192
  #### fetchUrls
193
193
 
package/chain-info.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AssetList, Chain, IBCInfo } from '@chain-registry/types';
1
+ import { AssetList, Chain, IBCData } from '@chain-registry/types';
2
2
  import { ChainRegistryFetcher } from './fetcher';
3
3
  export interface ChainInfoOptions {
4
4
  chainName: string;
@@ -10,10 +10,10 @@ export declare class ChainInfo {
10
10
  protected _chain: Chain;
11
11
  protected _assetList: AssetList;
12
12
  protected _assetLists: AssetList[];
13
- protected _ibcData: IBCInfo[];
13
+ protected _ibcData: IBCData[];
14
14
  constructor(options: ChainInfoOptions);
15
15
  refresh(): void;
16
16
  get chain(): Chain;
17
17
  get nativeAssetList(): AssetList;
18
- get assetLists(): any[];
18
+ get assetLists(): AssetList[];
19
19
  }
package/chain-info.js CHANGED
@@ -19,13 +19,13 @@ class ChainInfo {
19
19
  this._ibcData = this.fetcher.getChainIbcData(this.chainName);
20
20
  this._chain = this.fetcher.getChain(this.chainName);
21
21
  const supportedChains = this._ibcData.reduce((m, v) => {
22
- if (!m.includes(v.chain_1.chain_name))
23
- m.push(v.chain_1.chain_name);
24
- if (!m.includes(v.chain_2.chain_name))
25
- m.push(v.chain_2.chain_name);
22
+ if (!m.includes(v.chain1.chainName))
23
+ m.push(v.chain1.chainName);
24
+ if (!m.includes(v.chain1.chainName))
25
+ m.push(v.chain1.chainName);
26
26
  return m;
27
27
  }, []);
28
- this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.chain_name));
28
+ this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.chainName));
29
29
  }
30
30
  get chain() {
31
31
  return this._chain;
package/chain-util.js CHANGED
@@ -14,7 +14,7 @@ class ChainRegistryChainUtil {
14
14
  ...chainInfo.nativeAssetList.assets,
15
15
  ...chainInfo.assetLists.flatMap(({ assets }) => assets)
16
16
  ],
17
- chain_name: chainName
17
+ chainName: chainName
18
18
  }
19
19
  ];
20
20
  }
package/esm/chain-info.js CHANGED
@@ -16,13 +16,13 @@ export class ChainInfo {
16
16
  this._ibcData = this.fetcher.getChainIbcData(this.chainName);
17
17
  this._chain = this.fetcher.getChain(this.chainName);
18
18
  const supportedChains = this._ibcData.reduce((m, v) => {
19
- if (!m.includes(v.chain_1.chain_name))
20
- m.push(v.chain_1.chain_name);
21
- if (!m.includes(v.chain_2.chain_name))
22
- m.push(v.chain_2.chain_name);
19
+ if (!m.includes(v.chain1.chainName))
20
+ m.push(v.chain1.chainName);
21
+ if (!m.includes(v.chain1.chainName))
22
+ m.push(v.chain1.chainName);
23
23
  return m;
24
24
  }, []);
25
- this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.chain_name));
25
+ this._assetLists = this.fetcher.assetLists.filter((list) => supportedChains.includes(list.chainName));
26
26
  }
27
27
  get chain() {
28
28
  return this._chain;
package/esm/chain-util.js CHANGED
@@ -11,7 +11,7 @@ export class ChainRegistryChainUtil {
11
11
  ...chainInfo.nativeAssetList.assets,
12
12
  ...chainInfo.assetLists.flatMap(({ assets }) => assets)
13
13
  ],
14
- chain_name: chainName
14
+ chainName: chainName
15
15
  }
16
16
  ];
17
17
  }
package/esm/fetcher.js CHANGED
@@ -2,6 +2,19 @@ import { getAssetLists } from '@chain-registry/utils';
2
2
  import { basename } from 'bfs-path';
3
3
  import fetch from 'cross-fetch';
4
4
  import { ChainInfo } from './chain-info';
5
+ const keysToCamel = (o) => {
6
+ if (o === Object(o) && !Array.isArray(o) && typeof o !== 'function') {
7
+ const n = {};
8
+ Object.keys(o).forEach((k) => {
9
+ n[k.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : '')] = keysToCamel(o[k]);
10
+ });
11
+ return n;
12
+ }
13
+ else if (Array.isArray(o)) {
14
+ return o.map((i) => keysToCamel(i));
15
+ }
16
+ return o;
17
+ };
5
18
  const fetchUrl = (url) => {
6
19
  return fetch(url).then((res) => {
7
20
  if (res.status >= 400) {
@@ -42,17 +55,17 @@ export class ChainRegistryFetcher {
42
55
  return this._ibcData;
43
56
  }
44
57
  getChain(chainName) {
45
- return this._chains.find((chain) => chain.chain_name === chainName);
58
+ return this._chains.find((chain) => chain.chainName === chainName);
46
59
  }
47
60
  getChainAssetList(chainName) {
48
- return this._assetLists.find((list) => list.chain_name === chainName);
61
+ return this._assetLists.find((list) => list.chainName === chainName);
49
62
  }
50
63
  getGeneratedAssetLists(chainName) {
51
64
  return getAssetLists(chainName, this._ibcData, this._assetLists);
52
65
  }
53
66
  getChainIbcData(chainName) {
54
- return this._ibcData.filter((info) => info.chain_1.chain_name === chainName ||
55
- info.chain_2.chain_name === chainName);
67
+ return this._ibcData.filter((info) => info.chain1.chainName === chainName ||
68
+ info.chain2.chainName === chainName);
56
69
  }
57
70
  getChainInfo(chainName) {
58
71
  let chainInfo = this.chainInfoList.find((it) => it.chainName === chainName);
@@ -67,17 +80,18 @@ export class ChainRegistryFetcher {
67
80
  }
68
81
  upsertChain(data) {
69
82
  const found = this._chains.find((chain) => {
70
- return (chain.chain_name === data.chain_name &&
71
- chain.network_type === data.network_type);
83
+ return (chain.chainName === data.chainName &&
84
+ chain.networkType === data.networkType);
72
85
  });
86
+ const convertedData = keysToCamel(data);
73
87
  if (!found) {
74
- this._chains.push(data);
88
+ this._chains.push(convertedData);
75
89
  return;
76
90
  }
77
91
  this._chains = this._chains.map((chain) => {
78
- if (chain.chain_name === data.chain_name &&
79
- chain.network_type === data.network_type) {
80
- return data;
92
+ if (chain.chainName === data.chainName &&
93
+ chain.networkType === data.networkType) {
94
+ return convertedData;
81
95
  }
82
96
  else {
83
97
  return chain;
@@ -86,15 +100,16 @@ export class ChainRegistryFetcher {
86
100
  }
87
101
  updateAssetList(data) {
88
102
  const found = this._assetLists.find((list) => {
89
- return list.chain_name === data.chain_name;
103
+ return list.chainName === data.chainName;
90
104
  });
105
+ const convertedData = keysToCamel(data);
91
106
  if (!found) {
92
- this._assetLists.push(data);
107
+ this._assetLists.push(convertedData);
93
108
  return;
94
109
  }
95
110
  this._assetLists = this._assetLists.map((list) => {
96
- if (list.chain_name === data.chain_name) {
97
- return data;
111
+ if (list.chainName === data.chainName) {
112
+ return convertedData;
98
113
  }
99
114
  else {
100
115
  return list;
@@ -103,17 +118,18 @@ export class ChainRegistryFetcher {
103
118
  }
104
119
  upsertIbcData(data) {
105
120
  const found = this._ibcData.find((info) => {
106
- return (info.chain_1.chain_name === data.chain_1.chain_name &&
107
- info.chain_2.chain_name === data.chain_2.chain_name);
121
+ return (info.chain1.chainName === data.chain1.chainName &&
122
+ info.chain2.chainName === data.chain2.chainName);
108
123
  });
124
+ const convertedData = keysToCamel(data);
109
125
  if (!found) {
110
- this._ibcData.push(data);
126
+ this._ibcData.push(convertedData);
111
127
  return;
112
128
  }
113
129
  this._ibcData = this._ibcData.map((info) => {
114
- if (info.chain_1.chain_name === data.chain_1.chain_name &&
115
- info.chain_2.chain_name === data.chain_2.chain_name) {
116
- return data;
130
+ if (info.chain1.chainName === data.chain1.chainName &&
131
+ info.chain2.chainName === data.chain2.chainName) {
132
+ return convertedData;
117
133
  }
118
134
  else {
119
135
  return info;
package/esm/registry.js CHANGED
@@ -3,7 +3,7 @@ import { ChainRegistryFetcher } from './fetcher';
3
3
  export class ChainRegistryClient extends ChainRegistryFetcher {
4
4
  _options = {
5
5
  chainNames: [],
6
- baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/original'
6
+ baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/camel'
7
7
  };
8
8
  constructor(options) {
9
9
  const { chainNames, assetListNames, ibcNamePairs, baseUrl, ...restOptions } = options;
package/fetcher.d.ts CHANGED
@@ -1,30 +1,30 @@
1
- import { AssetList, Chain, ChainRegistry, IBCInfo } from '@chain-registry/types';
1
+ import { AssetList, Chain, IBCData } from '@chain-registry/types';
2
2
  import { ChainInfo } from './chain-info';
3
3
  export interface ChainRegistryFetcherOptions {
4
4
  assetLists?: AssetList[];
5
5
  chains?: Chain[];
6
- ibcData?: IBCInfo[];
6
+ ibcData?: IBCData[];
7
7
  urls?: string[];
8
8
  }
9
- export declare class ChainRegistryFetcher implements ChainRegistry {
9
+ export declare class ChainRegistryFetcher {
10
10
  urls: string[];
11
11
  protected _assetLists: AssetList[];
12
12
  protected _chains: Chain[];
13
- protected _ibcData: IBCInfo[];
13
+ protected _ibcData: IBCData[];
14
14
  private chainInfoList;
15
15
  constructor(options?: ChainRegistryFetcherOptions);
16
16
  get chains(): Chain[];
17
17
  get assetLists(): AssetList[];
18
- get ibcData(): IBCInfo[];
18
+ get ibcData(): IBCData[];
19
19
  getChain(chainName: string): Chain;
20
20
  getChainAssetList(chainName: string): AssetList;
21
21
  getGeneratedAssetLists(chainName: string): AssetList[];
22
- getChainIbcData(chainName: string): IBCInfo[];
22
+ getChainIbcData(chainName: string): IBCData[];
23
23
  getChainInfo(chainName: string): ChainInfo;
24
24
  upsertChain(data: Chain): void;
25
25
  updateAssetList(data: AssetList): void;
26
- upsertIbcData(data: IBCInfo): void;
27
- update(data: Chain | AssetList | IBCInfo): void;
26
+ upsertIbcData(data: IBCData): void;
27
+ update(data: Chain | AssetList | IBCData): void;
28
28
  fetch(url: string): Promise<void>;
29
29
  fetchUrls(): Promise<void[]>;
30
30
  }
package/fetcher.js CHANGED
@@ -8,6 +8,19 @@ const utils_1 = require("@chain-registry/utils");
8
8
  const bfs_path_1 = require("bfs-path");
9
9
  const cross_fetch_1 = __importDefault(require("cross-fetch"));
10
10
  const chain_info_1 = require("./chain-info");
11
+ const keysToCamel = (o) => {
12
+ if (o === Object(o) && !Array.isArray(o) && typeof o !== 'function') {
13
+ const n = {};
14
+ Object.keys(o).forEach((k) => {
15
+ n[k.replace(/[-_\s]+(.)?/g, (_, c) => c ? c.toUpperCase() : '')] = keysToCamel(o[k]);
16
+ });
17
+ return n;
18
+ }
19
+ else if (Array.isArray(o)) {
20
+ return o.map((i) => keysToCamel(i));
21
+ }
22
+ return o;
23
+ };
11
24
  const fetchUrl = (url) => {
12
25
  return (0, cross_fetch_1.default)(url).then((res) => {
13
26
  if (res.status >= 400) {
@@ -48,17 +61,17 @@ class ChainRegistryFetcher {
48
61
  return this._ibcData;
49
62
  }
50
63
  getChain(chainName) {
51
- return this._chains.find((chain) => chain.chain_name === chainName);
64
+ return this._chains.find((chain) => chain.chainName === chainName);
52
65
  }
53
66
  getChainAssetList(chainName) {
54
- return this._assetLists.find((list) => list.chain_name === chainName);
67
+ return this._assetLists.find((list) => list.chainName === chainName);
55
68
  }
56
69
  getGeneratedAssetLists(chainName) {
57
70
  return (0, utils_1.getAssetLists)(chainName, this._ibcData, this._assetLists);
58
71
  }
59
72
  getChainIbcData(chainName) {
60
- return this._ibcData.filter((info) => info.chain_1.chain_name === chainName ||
61
- info.chain_2.chain_name === chainName);
73
+ return this._ibcData.filter((info) => info.chain1.chainName === chainName ||
74
+ info.chain2.chainName === chainName);
62
75
  }
63
76
  getChainInfo(chainName) {
64
77
  let chainInfo = this.chainInfoList.find((it) => it.chainName === chainName);
@@ -73,17 +86,18 @@ class ChainRegistryFetcher {
73
86
  }
74
87
  upsertChain(data) {
75
88
  const found = this._chains.find((chain) => {
76
- return (chain.chain_name === data.chain_name &&
77
- chain.network_type === data.network_type);
89
+ return (chain.chainName === data.chainName &&
90
+ chain.networkType === data.networkType);
78
91
  });
92
+ const convertedData = keysToCamel(data);
79
93
  if (!found) {
80
- this._chains.push(data);
94
+ this._chains.push(convertedData);
81
95
  return;
82
96
  }
83
97
  this._chains = this._chains.map((chain) => {
84
- if (chain.chain_name === data.chain_name &&
85
- chain.network_type === data.network_type) {
86
- return data;
98
+ if (chain.chainName === data.chainName &&
99
+ chain.networkType === data.networkType) {
100
+ return convertedData;
87
101
  }
88
102
  else {
89
103
  return chain;
@@ -92,15 +106,16 @@ class ChainRegistryFetcher {
92
106
  }
93
107
  updateAssetList(data) {
94
108
  const found = this._assetLists.find((list) => {
95
- return list.chain_name === data.chain_name;
109
+ return list.chainName === data.chainName;
96
110
  });
111
+ const convertedData = keysToCamel(data);
97
112
  if (!found) {
98
- this._assetLists.push(data);
113
+ this._assetLists.push(convertedData);
99
114
  return;
100
115
  }
101
116
  this._assetLists = this._assetLists.map((list) => {
102
- if (list.chain_name === data.chain_name) {
103
- return data;
117
+ if (list.chainName === data.chainName) {
118
+ return convertedData;
104
119
  }
105
120
  else {
106
121
  return list;
@@ -109,17 +124,18 @@ class ChainRegistryFetcher {
109
124
  }
110
125
  upsertIbcData(data) {
111
126
  const found = this._ibcData.find((info) => {
112
- return (info.chain_1.chain_name === data.chain_1.chain_name &&
113
- info.chain_2.chain_name === data.chain_2.chain_name);
127
+ return (info.chain1.chainName === data.chain1.chainName &&
128
+ info.chain2.chainName === data.chain2.chainName);
114
129
  });
130
+ const convertedData = keysToCamel(data);
115
131
  if (!found) {
116
- this._ibcData.push(data);
132
+ this._ibcData.push(convertedData);
117
133
  return;
118
134
  }
119
135
  this._ibcData = this._ibcData.map((info) => {
120
- if (info.chain_1.chain_name === data.chain_1.chain_name &&
121
- info.chain_2.chain_name === data.chain_2.chain_name) {
122
- return data;
136
+ if (info.chain1.chainName === data.chain1.chainName &&
137
+ info.chain2.chainName === data.chain2.chainName) {
138
+ return convertedData;
123
139
  }
124
140
  else {
125
141
  return info;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/client",
3
- "version": "1.53.151",
3
+ "version": "2.0.2",
4
4
  "description": "Chain Registry Client",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/hyperweb-io/chain-registry",
@@ -35,8 +35,8 @@
35
35
  "supertest": "6.3.3"
36
36
  },
37
37
  "dependencies": {
38
- "@chain-registry/types": "^0.50.151",
39
- "@chain-registry/utils": "^1.51.151",
38
+ "@chain-registry/types": "^2.0.2",
39
+ "@chain-registry/utils": "^2.0.2",
40
40
  "bfs-path": "^1.0.2",
41
41
  "cross-fetch": "^3.1.5"
42
42
  },
@@ -47,5 +47,5 @@
47
47
  "interchain",
48
48
  "tokens"
49
49
  ],
50
- "gitHead": "1f1d8c99437916d1762e9af9835f7984fc36c8a7"
50
+ "gitHead": "06d713a3dcbfd99af7b11a3e8bc542d681d48d71"
51
51
  }
package/registry.js CHANGED
@@ -6,7 +6,7 @@ const fetcher_1 = require("./fetcher");
6
6
  class ChainRegistryClient extends fetcher_1.ChainRegistryFetcher {
7
7
  _options = {
8
8
  chainNames: [],
9
- baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/original'
9
+ baseUrl: 'https://raw.githubusercontent.com/chain-registry/chain-registry/main/registries/camel'
10
10
  };
11
11
  constructor(options) {
12
12
  const { chainNames, assetListNames, ibcNamePairs, baseUrl, ...restOptions } = options;