@chain-registry/keplr 1.67.13 → 1.68.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/esm/index.js CHANGED
@@ -3,24 +3,53 @@ import semver from 'semver';
3
3
  const getRpc = (chain) => chain.apis?.rpc?.[0]?.address ?? '';
4
4
  const getRest = (chain) => chain.apis?.rest?.[0]?.address ?? '';
5
5
  const getExplr = (chain) => chain.explorers?.[0]?.url ?? '';
6
- const cleanVer = (ver) => {
7
- if (!semver.valid(ver)) {
8
- // try to split by @ for repo@version
9
- ver = ver.split('@').pop();
10
- if (semver.valid(ver))
11
- return ver;
12
- const spaces = ver.split('.').length;
13
- switch (spaces) {
14
- case 1:
15
- return ver + '.0.0';
16
- case 2:
17
- return ver + '.0';
18
- case 3:
19
- default:
20
- throw new Error('contact @chain-registry/keplr maintainers: bad version');
21
- }
22
- }
6
+ const versionPatterns = {
7
+ fullSemver: /v?(\d+\.\d+\.\d+)(?=-[\w.-]+|$)/, // Matches complete semver patterns like '0.47.20' or 'v0.47.20'
8
+ partialSemver: /v?(\d+\.\d+)(?=(?:\.\d+)?(?=-[\w.-]+|$))/, // Matches partial semver patterns like '0.47' or 'v0.47'
9
+ basicVersion: /v?(\d+)(?=(?:\.\d+)?(?:\.\d+)?(?=-[\w.-]+|$))/, // Matches basic versions like '0' or 'v0'
10
+ tagged: /@v(\d+\.\d+)(?:\.x)?(?=-[\w.-]+|$)/, // Specific for tagged formats
11
+ embedded: /\/v(\d+\.\d+\.\d+)(?=-[\w.-]+|$)/, // For versions embedded in paths
12
+ simple: /v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/, // General simple versions
13
+ complexEmbedded: /[\w-]+\/[\w-]+ v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-\d+[\w.-]*)/, // Complex formats with namespaces
14
+ taggedVersion: /[\w-]+\/[\w-]+ v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?=-[\w.-]+|$)/ // Versions with descriptive tags
23
15
  };
16
+ export function extractVersion(input) {
17
+ let version = null;
18
+ // Check each pattern in turn
19
+ if (versionPatterns.fullSemver.test(input)) {
20
+ version = input.match(versionPatterns.fullSemver)?.[1];
21
+ }
22
+ else if (versionPatterns.partialSemver.test(input)) {
23
+ version = input.match(versionPatterns.partialSemver)?.[1];
24
+ }
25
+ else if (versionPatterns.basicVersion.test(input)) {
26
+ version = input.match(versionPatterns.basicVersion)?.[1];
27
+ }
28
+ else if (versionPatterns.taggedVersion.test(input)) {
29
+ version = input.match(versionPatterns.taggedVersion)?.[1];
30
+ }
31
+ else if (versionPatterns.complexEmbedded.test(input)) {
32
+ version = input.match(versionPatterns.complexEmbedded)?.[1];
33
+ }
34
+ else if (versionPatterns.simple.test(input)) {
35
+ version = input.match(versionPatterns.simple)?.[1];
36
+ }
37
+ else if (versionPatterns.tagged.test(input)) {
38
+ version = input.match(versionPatterns.tagged)?.[1];
39
+ }
40
+ else if (versionPatterns.embedded.test(input)) {
41
+ version = input.match(versionPatterns.embedded)?.[1];
42
+ }
43
+ return version ? normalizeVersion(version) : null;
44
+ }
45
+ function normalizeVersion(version) {
46
+ // Ensures the version is normalized to the 'x.y.z' format, if applicable
47
+ const parts = version.split('.');
48
+ while (parts.length < 3) {
49
+ parts.push('0');
50
+ }
51
+ return parts.join('.');
52
+ }
24
53
  export const chainRegistryChainToKeplr = (chain, assets, options = {
25
54
  getRpcEndpoint: getRpc,
26
55
  getRestEndpoint: getRest,
@@ -35,7 +64,7 @@ export const chainRegistryChainToKeplr = (chain, assets, options = {
35
64
  const features = [];
36
65
  // if NOT specified, we assume stargate, sorry not sorry
37
66
  const sdkVer = chain.codebase?.cosmos_sdk_version
38
- ? cleanVer(chain.codebase?.cosmos_sdk_version)
67
+ ? extractVersion(chain.codebase?.cosmos_sdk_version)
39
68
  : '0.40';
40
69
  // stargate
41
70
  if (semver.satisfies(sdkVer, '>=0.40'))
@@ -50,7 +79,7 @@ export const chainRegistryChainToKeplr = (chain, assets, options = {
50
79
  features.push('ibc-go');
51
80
  if (chain.codebase?.cosmwasm_enabled) {
52
81
  features.push('cosmwasm');
53
- const wasmVer = cleanVer(chain.codebase.cosmwasm_version ?? '0.24');
82
+ const wasmVer = extractVersion(chain.codebase.cosmwasm_version ?? '0.24');
54
83
  if (semver.satisfies(wasmVer, '>=0.24'))
55
84
  features.push('wasmd_0.24+');
56
85
  }
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AssetList, Chain } from '@chain-registry/types';
2
2
  import { ChainInfo } from '@keplr-wallet/types';
3
+ export declare function extractVersion(input: string): string | null;
3
4
  export declare const chainRegistryChainToKeplr: (chain: Chain, assets: AssetList[], options?: {
4
5
  getRpcEndpoint?: (chain: Chain) => string;
5
6
  getRestEndpoint?: (chain: Chain) => string;
package/index.js CHANGED
@@ -3,30 +3,60 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.chainRegistryChainToKeplr = void 0;
6
+ exports.chainRegistryChainToKeplr = exports.extractVersion = void 0;
7
7
  const cosmos_1 = require("@keplr-wallet/cosmos");
8
8
  const semver_1 = __importDefault(require("semver"));
9
9
  const getRpc = (chain) => chain.apis?.rpc?.[0]?.address ?? '';
10
10
  const getRest = (chain) => chain.apis?.rest?.[0]?.address ?? '';
11
11
  const getExplr = (chain) => chain.explorers?.[0]?.url ?? '';
12
- const cleanVer = (ver) => {
13
- if (!semver_1.default.valid(ver)) {
14
- // try to split by @ for repo@version
15
- ver = ver.split('@').pop();
16
- if (semver_1.default.valid(ver))
17
- return ver;
18
- const spaces = ver.split('.').length;
19
- switch (spaces) {
20
- case 1:
21
- return ver + '.0.0';
22
- case 2:
23
- return ver + '.0';
24
- case 3:
25
- default:
26
- throw new Error('contact @chain-registry/keplr maintainers: bad version');
27
- }
28
- }
12
+ const versionPatterns = {
13
+ fullSemver: /v?(\d+\.\d+\.\d+)(?=-[\w.-]+|$)/, // Matches complete semver patterns like '0.47.20' or 'v0.47.20'
14
+ partialSemver: /v?(\d+\.\d+)(?=(?:\.\d+)?(?=-[\w.-]+|$))/, // Matches partial semver patterns like '0.47' or 'v0.47'
15
+ basicVersion: /v?(\d+)(?=(?:\.\d+)?(?:\.\d+)?(?=-[\w.-]+|$))/, // Matches basic versions like '0' or 'v0'
16
+ tagged: /@v(\d+\.\d+)(?:\.x)?(?=-[\w.-]+|$)/, // Specific for tagged formats
17
+ embedded: /\/v(\d+\.\d+\.\d+)(?=-[\w.-]+|$)/, // For versions embedded in paths
18
+ simple: /v?(\d+)(?:\.(\d+))?(?:\.(\d+))?$/, // General simple versions
19
+ complexEmbedded: /[\w-]+\/[\w-]+ v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-\d+[\w.-]*)/, // Complex formats with namespaces
20
+ taggedVersion: /[\w-]+\/[\w-]+ v(\d+)(?:\.(\d+))?(?:\.(\d+))?(?=-[\w.-]+|$)/ // Versions with descriptive tags
29
21
  };
22
+ function extractVersion(input) {
23
+ let version = null;
24
+ // Check each pattern in turn
25
+ if (versionPatterns.fullSemver.test(input)) {
26
+ version = input.match(versionPatterns.fullSemver)?.[1];
27
+ }
28
+ else if (versionPatterns.partialSemver.test(input)) {
29
+ version = input.match(versionPatterns.partialSemver)?.[1];
30
+ }
31
+ else if (versionPatterns.basicVersion.test(input)) {
32
+ version = input.match(versionPatterns.basicVersion)?.[1];
33
+ }
34
+ else if (versionPatterns.taggedVersion.test(input)) {
35
+ version = input.match(versionPatterns.taggedVersion)?.[1];
36
+ }
37
+ else if (versionPatterns.complexEmbedded.test(input)) {
38
+ version = input.match(versionPatterns.complexEmbedded)?.[1];
39
+ }
40
+ else if (versionPatterns.simple.test(input)) {
41
+ version = input.match(versionPatterns.simple)?.[1];
42
+ }
43
+ else if (versionPatterns.tagged.test(input)) {
44
+ version = input.match(versionPatterns.tagged)?.[1];
45
+ }
46
+ else if (versionPatterns.embedded.test(input)) {
47
+ version = input.match(versionPatterns.embedded)?.[1];
48
+ }
49
+ return version ? normalizeVersion(version) : null;
50
+ }
51
+ exports.extractVersion = extractVersion;
52
+ function normalizeVersion(version) {
53
+ // Ensures the version is normalized to the 'x.y.z' format, if applicable
54
+ const parts = version.split('.');
55
+ while (parts.length < 3) {
56
+ parts.push('0');
57
+ }
58
+ return parts.join('.');
59
+ }
30
60
  const chainRegistryChainToKeplr = (chain, assets, options = {
31
61
  getRpcEndpoint: getRpc,
32
62
  getRestEndpoint: getRest,
@@ -41,7 +71,7 @@ const chainRegistryChainToKeplr = (chain, assets, options = {
41
71
  const features = [];
42
72
  // if NOT specified, we assume stargate, sorry not sorry
43
73
  const sdkVer = chain.codebase?.cosmos_sdk_version
44
- ? cleanVer(chain.codebase?.cosmos_sdk_version)
74
+ ? extractVersion(chain.codebase?.cosmos_sdk_version)
45
75
  : '0.40';
46
76
  // stargate
47
77
  if (semver_1.default.satisfies(sdkVer, '>=0.40'))
@@ -56,7 +86,7 @@ const chainRegistryChainToKeplr = (chain, assets, options = {
56
86
  features.push('ibc-go');
57
87
  if (chain.codebase?.cosmwasm_enabled) {
58
88
  features.push('cosmwasm');
59
- const wasmVer = cleanVer(chain.codebase.cosmwasm_version ?? '0.24');
89
+ const wasmVer = extractVersion(chain.codebase.cosmwasm_version ?? '0.24');
60
90
  if (semver_1.default.satisfies(wasmVer, '>=0.24'))
61
91
  features.push('wasmd_0.24+');
62
92
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chain-registry/keplr",
3
- "version": "1.67.13",
3
+ "version": "1.68.0",
4
4
  "description": "Chain Registry to Keplr",
5
5
  "author": "Dan Lynch <pyramation@gmail.com>",
6
6
  "homepage": "https://github.com/cosmology-tech/chain-registry",
@@ -29,10 +29,10 @@
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/semver": "^7.5.8",
32
- "chain-registry": "^1.62.13"
32
+ "chain-registry": "^1.63.0"
33
33
  },
34
34
  "dependencies": {
35
- "@chain-registry/types": "^0.44.11",
35
+ "@chain-registry/types": "^0.45.0",
36
36
  "@keplr-wallet/cosmos": "0.12.28",
37
37
  "@keplr-wallet/crypto": "0.12.28",
38
38
  "semver": "^7.5.0"
@@ -44,5 +44,5 @@
44
44
  "interchain",
45
45
  "keplr"
46
46
  ],
47
- "gitHead": "7ec3056386ff38d794c79fb9b8ca8db35e691b1c"
47
+ "gitHead": "dc905987a07f8cd36cb05a57e6b8e2d49caee2ef"
48
48
  }