@shapeshiftoss/caip 6.16.0 → 8.1.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/README.md CHANGED
@@ -12,7 +12,7 @@ Usage
12
12
  ### `toChainId` | `toCAIP2`
13
13
 
14
14
  ```ts
15
- const chainNamespace = CHAIN_NAMESPACE.Ethereum
15
+ const chainNamespace = CHAIN_NAMESPACE.Evm
16
16
  const chainReference = CHAIN_REFERENCE.EthereumMainnet
17
17
  const result = toChainId({ chainNamespace, chainReference })
18
18
  expect(result).toEqual('eip155:1')
@@ -23,7 +23,7 @@ expect(result).toEqual('eip155:1')
23
23
  ```ts
24
24
  const ethereumChainId = 'eip155:1'
25
25
  const { chainNamespace, chainReference } = fromChainId(ethereumChainId)
26
- expect(chainNamespace).toEqual(CHAIN_NAMESPACE.Ethereum)
26
+ expect(chainNamespace).toEqual(CHAIN_NAMESPACE.Evm)
27
27
  expect(chainReference).toEqual(CHAIN_REFERENCE.EthereumMainnet)
28
28
  ```
29
29
 
@@ -36,7 +36,7 @@ Usage
36
36
  ### `toAccountId` | `toCAIP10`
37
37
 
38
38
  ```ts
39
- const chainNamespace = CHAIN_NAMESPACE.Ethereum
39
+ const chainNamespace = CHAIN_NAMESPACE.Evm
40
40
  const chainReference = CHAIN_REFERENCE.EthereumMainnet
41
41
  const chainId = toChainId({ chainNamespace, chainReference })
42
42
  const account = '0xa44c286ba83bb771cd0107b2c1df678435bd1535'
@@ -67,7 +67,7 @@ Usage
67
67
  Ether
68
68
 
69
69
  ```ts
70
- const chainNamespace = CHAIN_NAMESPACE.Ethereum
70
+ const chainNamespace = CHAIN_NAMESPACE.Evm
71
71
  const chainReference = CHAIN_REFERENCE.EthereumMainnet
72
72
  const chainId = toChainId({ chainNamespace, chainReference })
73
73
  const assetNamespace = 'slip44'
@@ -79,7 +79,7 @@ expect(toAssetId({ chainId, assetNamespace, assetReference })).toEqual('eip155:1
79
79
  ERC20 token
80
80
 
81
81
  ```ts
82
- const chainNamespace = CHAIN_NAMESPACE.Ethereum
82
+ const chainNamespace = CHAIN_NAMESPACE.Evm
83
83
  const chainReference = CHAIN_REFERENCE.EthereumMainnet
84
84
  const chainId = toChainId({ chainNamespace, chainReference })
85
85
  const assetNamespace = 'erc20'
@@ -13,7 +13,7 @@ const toAccountId = ({ chainId: maybeChainId, chainNamespace: maybeChainNamespac
13
13
  // we lowercase eth accounts as per the draft spec
14
14
  // it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
15
15
  // we don't lowercase bitcoin addresses as they'll fail checksum
16
- const outputAccount = chainNamespace === constants_1.CHAIN_NAMESPACE.Ethereum ? account.toLowerCase() : account;
16
+ const outputAccount = chainNamespace === constants_1.CHAIN_NAMESPACE.Evm ? account.toLowerCase() : account;
17
17
  return `${chainId}:${outputAccount}`;
18
18
  };
19
19
  exports.toAccountId = toAccountId;
@@ -35,7 +35,7 @@ const fromAccountId = (accountId) => {
35
35
  // we lowercase eth accounts as per the draft spec
36
36
  // it's not explicit, but cHecKsUM can be recovered from lowercase eth accounts
37
37
  // we don't lowercase bitcoin addresses as they'll fail checksum
38
- const outputAccount = chainNamespace === constants_1.CHAIN_NAMESPACE.Ethereum ? account.toLowerCase() : account;
38
+ const outputAccount = chainNamespace === constants_1.CHAIN_NAMESPACE.Evm ? account.toLowerCase() : account;
39
39
  return { chainId, account: outputAccount, chainNamespace, chainReference };
40
40
  };
41
41
  exports.fromAccountId = fromAccountId;
@@ -22,7 +22,7 @@ exports.fetchData = fetchData;
22
22
  const parseEthData = (data) => {
23
23
  const ethCoins = data.filter(({ id, explorer }) => (explorer && explorer.startsWith('https://etherscan.io/token/0x')) || id === 'ethereum');
24
24
  return ethCoins.reduce((acc, { id, explorer }) => {
25
- const chainNamespace = constants_1.CHAIN_NAMESPACE.Ethereum;
25
+ const chainNamespace = constants_1.CHAIN_NAMESPACE.Evm;
26
26
  const chainReference = constants_1.CHAIN_REFERENCE.EthereumMainnet;
27
27
  let assetReference = constants_1.ASSET_REFERENCE.Ethereum;
28
28
  const assetNamespace = id === 'ethereum' ? 'slip44' : 'erc20';
@@ -58,7 +58,7 @@ exports.assetIdToCoingecko = assetIdToCoingecko;
58
58
  const chainIdToCoingeckoAssetPlatform = (chainId) => {
59
59
  const { chainNamespace, chainReference } = (0, chainId_1.fromChainId)(chainId);
60
60
  switch (chainNamespace) {
61
- case constants_1.CHAIN_NAMESPACE.Ethereum:
61
+ case constants_1.CHAIN_NAMESPACE.Evm:
62
62
  switch (chainReference) {
63
63
  case constants_1.CHAIN_REFERENCE.EthereumMainnet:
64
64
  return CoingeckoAssetPlatform.Ethereum;
@@ -67,7 +67,7 @@ const chainIdToCoingeckoAssetPlatform = (chainId) => {
67
67
  default:
68
68
  throw new Error(`chainNamespace ${chainNamespace}, chainReference ${chainReference} not supported.`);
69
69
  }
70
- case constants_1.CHAIN_NAMESPACE.Cosmos:
70
+ case constants_1.CHAIN_NAMESPACE.CosmosSdk:
71
71
  switch (chainReference) {
72
72
  case constants_1.CHAIN_REFERENCE.CosmosHubMainnet:
73
73
  return CoingeckoAssetPlatform.Cosmos;
@@ -77,7 +77,7 @@ const chainIdToCoingeckoAssetPlatform = (chainId) => {
77
77
  throw new Error(`chainNamespace ${chainNamespace}, chainReference ${chainReference} not supported.`);
78
78
  }
79
79
  // No valid asset platform: https://api.coingecko.com/api/v3/asset_platforms
80
- case constants_1.CHAIN_NAMESPACE.Bitcoin:
80
+ case constants_1.CHAIN_NAMESPACE.Utxo:
81
81
  default:
82
82
  throw new Error(`chainNamespace ${chainNamespace} not supported.`);
83
83
  }
@@ -16,7 +16,7 @@ const parseData = (coins) => {
16
16
  if (Object.keys(platforms).includes('ethereum')) {
17
17
  try {
18
18
  const assetId = (0, assetId_1.toAssetId)({
19
- chainNamespace: constants_1.CHAIN_NAMESPACE.Ethereum,
19
+ chainNamespace: constants_1.CHAIN_NAMESPACE.Evm,
20
20
  chainReference: constants_1.CHAIN_REFERENCE.EthereumMainnet,
21
21
  assetNamespace: 'erc20',
22
22
  assetReference: platforms.ethereum,
@@ -30,7 +30,7 @@ const parseData = (coins) => {
30
30
  if (Object.keys(platforms).includes('avalanche')) {
31
31
  try {
32
32
  const assetId = (0, assetId_1.toAssetId)({
33
- chainNamespace: constants_1.CHAIN_NAMESPACE.Ethereum,
33
+ chainNamespace: constants_1.CHAIN_NAMESPACE.Evm,
34
34
  chainReference: constants_1.CHAIN_REFERENCE.AvalancheCChain,
35
35
  assetNamespace: 'erc20',
36
36
  assetReference: platforms.avalanche,
@@ -34,7 +34,7 @@ const parseOsmosisData = (data) => {
34
34
  assetReference = denom.split('/')[1];
35
35
  assetNamespace = 'ibc';
36
36
  }
37
- const chainNamespace = constants_1.CHAIN_NAMESPACE.Cosmos;
37
+ const chainNamespace = constants_1.CHAIN_NAMESPACE.CosmosSdk;
38
38
  const chainReference = constants_1.CHAIN_REFERENCE.OsmosisMainnet;
39
39
  const assetId = (0, assetId_1.toAssetId)({ chainNamespace, chainReference, assetNamespace, assetReference });
40
40
  acc[assetId] = symbol;
@@ -45,7 +45,7 @@ const parseOsmosisData = (data) => {
45
45
  exports.parseOsmosisData = parseOsmosisData;
46
46
  const parseData = (d) => {
47
47
  const osmosisMainnet = (0, chainId_1.toChainId)({
48
- chainNamespace: constants_1.CHAIN_NAMESPACE.Cosmos,
48
+ chainNamespace: constants_1.CHAIN_NAMESPACE.CosmosSdk,
49
49
  chainReference: constants_1.CHAIN_REFERENCE.OsmosisMainnet,
50
50
  });
51
51
  return {
@@ -36,7 +36,7 @@ const fetchData = async () => {
36
36
  exports.fetchData = fetchData;
37
37
  const parseEthData = (data) => {
38
38
  const assetNamespace = 'erc20';
39
- const chainNamespace = constants_1.CHAIN_NAMESPACE.Ethereum;
39
+ const chainNamespace = constants_1.CHAIN_NAMESPACE.Evm;
40
40
  const chainReference = constants_1.CHAIN_REFERENCE.EthereumMainnet;
41
41
  return data.reduce((acc, datum) => {
42
42
  const { address } = datum;
@@ -55,7 +55,7 @@ const parseEthData = (data) => {
55
55
  exports.parseEthData = parseEthData;
56
56
  const parseData = (d) => {
57
57
  const ethMainnet = (0, chainId_1.toChainId)({
58
- chainNamespace: constants_1.CHAIN_NAMESPACE.Ethereum,
58
+ chainNamespace: constants_1.CHAIN_NAMESPACE.Evm,
59
59
  chainReference: constants_1.CHAIN_REFERENCE.EthereumMainnet,
60
60
  });
61
61
  return { [ethMainnet]: (0, exports.parseEthData)(d) };
@@ -1,8 +1,8 @@
1
1
  import { ChainId, ChainNamespace, ChainReference } from '../chainId/chainId';
2
- import { ASSET_NAMESPACE_STRINGS, ASSET_REFERENCE } from '../constants';
2
+ import { ASSET_NAMESPACE, ASSET_REFERENCE } from '../constants';
3
3
  import { Nominal } from '../utils';
4
4
  export declare type AssetId = Nominal<string, 'AssetId'>;
5
- export declare type AssetNamespace = typeof ASSET_NAMESPACE_STRINGS[number];
5
+ export declare type AssetNamespace = typeof ASSET_NAMESPACE[keyof typeof ASSET_NAMESPACE];
6
6
  export declare type AssetReference = typeof ASSET_REFERENCE[keyof typeof ASSET_REFERENCE];
7
7
  declare type ToAssetIdWithChainId = {
8
8
  chainNamespace?: never;
@@ -1,11 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ // https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
5
3
  Object.defineProperty(exports, "__esModule", { value: true });
6
4
  exports.fromCAIP19 = exports.toCAIP19 = exports.fromAssetId = exports.toAssetId = void 0;
7
- // https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
8
- const toLower_1 = __importDefault(require("lodash/toLower"));
9
5
  const chainId_1 = require("../chainId/chainId");
10
6
  const constants_1 = require("../constants");
11
7
  const typeGuards_1 = require("../typeGuards");
@@ -69,28 +65,27 @@ const toAssetId = (args) => {
69
65
  };
70
66
  exports.toAssetId = toAssetId;
71
67
  const fromAssetId = (assetId) => {
72
- var _a;
73
68
  if (!(0, typeGuards_1.isAssetId)(assetId))
74
69
  throw new Error(`fromAssetId: invalid AssetId: ${assetId}`);
75
- const matches = (_a = utils_1.parseAssetIdRegExp.exec(assetId)) === null || _a === void 0 ? void 0 : _a.groups;
70
+ const matches = utils_1.parseAssetIdRegExp.exec(assetId);
76
71
  if (!matches)
77
72
  throw new Error(`fromAssetId: could not parse AssetId: ${assetId}`);
73
+ const { 1: chainNamespace, 2: chainReference, 3: assetNamespace, 4: assetReference } = matches;
78
74
  // These should never throw because isAssetId() would have already caught it, but they help with type inference
79
- (0, typeGuards_1.assertIsChainNamespace)(matches.chainNamespace);
80
- (0, typeGuards_1.assertIsChainReference)(matches.chainReference);
81
- (0, typeGuards_1.assertIsAssetNamespace)(matches.assetNamespace);
82
- const chainNamespace = matches.chainNamespace;
83
- const chainReference = matches.chainReference;
84
- const assetNamespace = matches.assetNamespace;
85
- const shouldLowercaseAssetReference = assetNamespace && ['erc20', 'erc721'].includes(assetNamespace);
86
- const assetReference = shouldLowercaseAssetReference
87
- ? (0, toLower_1.default)(matches.assetReference)
88
- : matches.assetReference;
89
- (0, typeGuards_1.assertIsChainReference)(chainReference);
90
75
  (0, typeGuards_1.assertIsChainNamespace)(chainNamespace);
76
+ (0, typeGuards_1.assertIsChainReference)(chainReference);
77
+ (0, typeGuards_1.assertIsAssetNamespace)(assetNamespace);
91
78
  const chainId = (0, chainId_1.toChainId)({ chainNamespace, chainReference });
92
79
  if (assetNamespace && assetReference && chainId) {
93
- return { chainId, chainReference, chainNamespace, assetNamespace, assetReference };
80
+ return {
81
+ chainId,
82
+ chainReference,
83
+ chainNamespace,
84
+ assetNamespace,
85
+ assetReference: ['erc20', 'erc721'].includes(assetNamespace)
86
+ ? assetReference.toLowerCase()
87
+ : assetReference,
88
+ };
94
89
  }
95
90
  else {
96
91
  throw new Error(`fromAssetId: invalid AssetId: ${assetId}`);
@@ -6,6 +6,8 @@ export declare const dogeAssetId: AssetId;
6
6
  export declare const ltcAssetId: AssetId;
7
7
  export declare const ethAssetId: AssetId;
8
8
  export declare const avalancheAssetId: AssetId;
9
+ export declare const foxAssetId: AssetId;
10
+ export declare const foxyAssetId: AssetId;
9
11
  export declare const cosmosAssetId: AssetId;
10
12
  export declare const osmosisAssetId: AssetId;
11
13
  export declare const btcChainId: ChainId;
@@ -17,9 +19,9 @@ export declare const avalancheChainId: ChainId;
17
19
  export declare const cosmosChainId: ChainId;
18
20
  export declare const osmosisChainId: ChainId;
19
21
  export declare const CHAIN_NAMESPACE: {
20
- readonly Ethereum: "eip155";
21
- readonly Bitcoin: "bip122";
22
- readonly Cosmos: "cosmos";
22
+ readonly Evm: "eip155";
23
+ readonly Utxo: "bip122";
24
+ readonly CosmosSdk: "cosmos";
23
25
  };
24
26
  declare type ValidChainMap = {
25
27
  [k in ChainNamespace]: ChainReference[];
@@ -39,12 +41,15 @@ export declare const CHAIN_REFERENCE: {
39
41
  readonly OsmosisTestnet: "osmo-testnet-1";
40
42
  readonly AvalancheCChain: "43114";
41
43
  };
42
- export declare const VALID_CHAIN_IDS: ValidChainMap;
43
- declare type ValidAssetNamespace = {
44
- [k in ChainNamespace]: AssetNamespace[];
44
+ export declare const ASSET_NAMESPACE: {
45
+ readonly cw20: "cw20";
46
+ readonly cw721: "cw721";
47
+ readonly erc20: "erc20";
48
+ readonly erc721: "erc721";
49
+ readonly slip44: "slip44";
50
+ readonly native: "native";
51
+ readonly ibc: "ibc";
45
52
  };
46
- export declare const VALID_ASSET_NAMESPACE: ValidAssetNamespace;
47
- export declare const ASSET_NAMESPACE_STRINGS: readonly ["cw20", "cw721", "erc20", "erc721", "slip44", "native", "ibc"];
48
53
  export declare const ASSET_REFERENCE: {
49
54
  readonly Bitcoin: "0";
50
55
  readonly Litecoin: "2";
@@ -55,4 +60,9 @@ export declare const ASSET_REFERENCE: {
55
60
  readonly BitcoinCash: "145";
56
61
  readonly AvalancheC: "9000";
57
62
  };
63
+ export declare const VALID_CHAIN_IDS: ValidChainMap;
64
+ declare type ValidAssetNamespace = {
65
+ [k in ChainNamespace]: AssetNamespace[];
66
+ };
67
+ export declare const VALID_ASSET_NAMESPACE: ValidAssetNamespace;
58
68
  export {};
package/dist/constants.js CHANGED
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ASSET_REFERENCE = exports.ASSET_NAMESPACE_STRINGS = exports.VALID_ASSET_NAMESPACE = exports.VALID_CHAIN_IDS = exports.CHAIN_REFERENCE = exports.CHAIN_NAMESPACE = exports.osmosisChainId = exports.cosmosChainId = exports.avalancheChainId = exports.ethChainId = exports.ltcChainId = exports.dogeChainId = exports.bchChainId = exports.btcChainId = exports.osmosisAssetId = exports.cosmosAssetId = exports.avalancheAssetId = exports.ethAssetId = exports.ltcAssetId = exports.dogeAssetId = exports.bchAssetId = exports.btcAssetId = void 0;
3
+ exports.VALID_ASSET_NAMESPACE = exports.VALID_CHAIN_IDS = exports.ASSET_REFERENCE = exports.ASSET_NAMESPACE = exports.CHAIN_REFERENCE = exports.CHAIN_NAMESPACE = exports.osmosisChainId = exports.cosmosChainId = exports.avalancheChainId = exports.ethChainId = exports.ltcChainId = exports.dogeChainId = exports.bchChainId = exports.btcChainId = exports.osmosisAssetId = exports.cosmosAssetId = exports.foxyAssetId = exports.foxAssetId = exports.avalancheAssetId = exports.ethAssetId = exports.ltcAssetId = exports.dogeAssetId = exports.bchAssetId = exports.btcAssetId = void 0;
4
4
  exports.btcAssetId = 'bip122:000000000019d6689c085ae165831e93/slip44:0';
5
5
  exports.bchAssetId = 'bip122:000000000000000000651ef99cb9fcbe/slip44:145';
6
6
  exports.dogeAssetId = 'bip122:00000000001a91e3dace36e2be3bf030/slip44:3';
7
7
  exports.ltcAssetId = 'bip122:12a765e31ffd4059bada1e25190f6e98/slip44:2';
8
8
  exports.ethAssetId = 'eip155:1/slip44:60';
9
9
  exports.avalancheAssetId = 'eip155:43114/slip44:9000';
10
+ exports.foxAssetId = 'eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d';
11
+ exports.foxyAssetId = 'eip155:1/erc20:0xdc49108ce5c57bc3408c3a5e95f3d864ec386ed3';
10
12
  exports.cosmosAssetId = 'cosmos:cosmoshub-4/slip44:118';
11
13
  exports.osmosisAssetId = 'cosmos:osmosis-1/slip44:118';
12
14
  exports.btcChainId = 'bip122:000000000019d6689c085ae165831e93';
@@ -18,9 +20,9 @@ exports.avalancheChainId = 'eip155:43114';
18
20
  exports.cosmosChainId = 'cosmos:cosmoshub-4';
19
21
  exports.osmosisChainId = 'cosmos:osmosis-1';
20
22
  exports.CHAIN_NAMESPACE = {
21
- Ethereum: 'eip155',
22
- Bitcoin: 'bip122',
23
- Cosmos: 'cosmos',
23
+ Evm: 'eip155',
24
+ Utxo: 'bip122',
25
+ CosmosSdk: 'cosmos',
24
26
  };
25
27
  exports.CHAIN_REFERENCE = {
26
28
  EthereumMainnet: '1',
@@ -40,21 +42,40 @@ exports.CHAIN_REFERENCE = {
40
42
  OsmosisTestnet: 'osmo-testnet-1',
41
43
  AvalancheCChain: '43114', // https://docs.avax.network/apis/avalanchego/apis/c-chain
42
44
  };
45
+ exports.ASSET_NAMESPACE = {
46
+ cw20: 'cw20',
47
+ cw721: 'cw721',
48
+ erc20: 'erc20',
49
+ erc721: 'erc721',
50
+ slip44: 'slip44',
51
+ native: 'native',
52
+ ibc: 'ibc',
53
+ };
54
+ exports.ASSET_REFERENCE = {
55
+ Bitcoin: '0',
56
+ Litecoin: '2',
57
+ Dogecoin: '3',
58
+ Ethereum: '60',
59
+ Cosmos: '118',
60
+ Osmosis: '118',
61
+ BitcoinCash: '145',
62
+ AvalancheC: '9000',
63
+ };
43
64
  exports.VALID_CHAIN_IDS = Object.freeze({
44
- [exports.CHAIN_NAMESPACE.Bitcoin]: [
65
+ [exports.CHAIN_NAMESPACE.Utxo]: [
45
66
  exports.CHAIN_REFERENCE.BitcoinMainnet,
46
67
  exports.CHAIN_REFERENCE.BitcoinTestnet,
47
68
  exports.CHAIN_REFERENCE.BitcoinCashMainnet,
48
69
  exports.CHAIN_REFERENCE.DogecoinMainnet,
49
70
  exports.CHAIN_REFERENCE.LitecoinMainnet,
50
71
  ],
51
- [exports.CHAIN_NAMESPACE.Ethereum]: [
72
+ [exports.CHAIN_NAMESPACE.Evm]: [
52
73
  exports.CHAIN_REFERENCE.EthereumMainnet,
53
74
  exports.CHAIN_REFERENCE.EthereumRopsten,
54
75
  exports.CHAIN_REFERENCE.EthereumRinkeby,
55
76
  exports.CHAIN_REFERENCE.AvalancheCChain,
56
77
  ],
57
- [exports.CHAIN_NAMESPACE.Cosmos]: [
78
+ [exports.CHAIN_NAMESPACE.CosmosSdk]: [
58
79
  exports.CHAIN_REFERENCE.CosmosHubMainnet,
59
80
  exports.CHAIN_REFERENCE.CosmosHubVega,
60
81
  exports.CHAIN_REFERENCE.OsmosisMainnet,
@@ -62,26 +83,13 @@ exports.VALID_CHAIN_IDS = Object.freeze({
62
83
  ],
63
84
  });
64
85
  exports.VALID_ASSET_NAMESPACE = Object.freeze({
65
- [exports.CHAIN_NAMESPACE.Bitcoin]: ['slip44'],
66
- [exports.CHAIN_NAMESPACE.Ethereum]: ['slip44', 'erc20', 'erc721'],
67
- [exports.CHAIN_NAMESPACE.Cosmos]: ['cw20', 'cw721', 'ibc', 'native', 'slip44'],
86
+ [exports.CHAIN_NAMESPACE.Utxo]: [exports.ASSET_NAMESPACE.slip44],
87
+ [exports.CHAIN_NAMESPACE.Evm]: [exports.ASSET_NAMESPACE.slip44, exports.ASSET_NAMESPACE.erc20, exports.ASSET_NAMESPACE.erc721],
88
+ [exports.CHAIN_NAMESPACE.CosmosSdk]: [
89
+ exports.ASSET_NAMESPACE.cw20,
90
+ exports.ASSET_NAMESPACE.cw721,
91
+ exports.ASSET_NAMESPACE.ibc,
92
+ exports.ASSET_NAMESPACE.native,
93
+ exports.ASSET_NAMESPACE.slip44,
94
+ ],
68
95
  });
69
- exports.ASSET_NAMESPACE_STRINGS = [
70
- 'cw20',
71
- 'cw721',
72
- 'erc20',
73
- 'erc721',
74
- 'slip44',
75
- 'native',
76
- 'ibc',
77
- ];
78
- exports.ASSET_REFERENCE = {
79
- Bitcoin: '0',
80
- Litecoin: '2',
81
- Dogecoin: '3',
82
- Ethereum: '60',
83
- Cosmos: '118',
84
- Osmosis: '118',
85
- BitcoinCash: '145',
86
- AvalancheC: '9000',
87
- };
@@ -2,7 +2,7 @@ import { AssetId, AssetNamespace, AssetReference } from './assetId/assetId';
2
2
  import { ChainId, ChainNamespace, ChainReference } from './chainId/chainId';
3
3
  export declare const isChainNamespace: (maybeChainNamespace: ChainNamespace | string) => maybeChainNamespace is ChainNamespace;
4
4
  export declare const isChainReference: (maybeChainReference: ChainReference | string) => maybeChainReference is ChainReference;
5
- export declare const isAssetNamespace: (maybeAssetNamespace: AssetNamespace | string) => maybeAssetNamespace is "cw20" | "cw721" | "erc20" | "erc721" | "slip44" | "native" | "ibc";
5
+ export declare const isAssetNamespace: (maybeAssetNamespace: AssetNamespace | string) => maybeAssetNamespace is AssetNamespace;
6
6
  export declare const isAssetReference: (maybeAssetReference: AssetReference | string) => maybeAssetReference is AssetReference;
7
7
  export declare const isAssetId: (maybeAssetId: AssetId | string) => maybeAssetId is AssetReference;
8
8
  export declare const isChainId: (maybeChainId: ChainId | string) => maybeChainId is ChainId;
@@ -7,17 +7,19 @@ const isChainNamespace = (maybeChainNamespace) => Object.values(constants_1.CHAI
7
7
  exports.isChainNamespace = isChainNamespace;
8
8
  const isChainReference = (maybeChainReference) => Object.values(constants_1.CHAIN_REFERENCE).some((s) => s === maybeChainReference);
9
9
  exports.isChainReference = isChainReference;
10
- const isAssetNamespace = (maybeAssetNamespace) => constants_1.ASSET_NAMESPACE_STRINGS.some((s) => s === maybeAssetNamespace);
10
+ const isAssetNamespace = (maybeAssetNamespace) => Object.values(constants_1.ASSET_NAMESPACE).some((s) => s === maybeAssetNamespace);
11
11
  exports.isAssetNamespace = isAssetNamespace;
12
12
  const isAssetReference = (maybeAssetReference) => Object.values(constants_1.ASSET_REFERENCE).some((s) => s === maybeAssetReference);
13
13
  exports.isAssetReference = isAssetReference;
14
14
  const isAssetId = (maybeAssetId) => {
15
- var _a;
16
- const matches = (_a = utils_1.parseAssetIdRegExp.exec(maybeAssetId)) === null || _a === void 0 ? void 0 : _a.groups;
17
- return (!!matches &&
18
- (0, exports.isChainNamespace)(matches.chainNamespace) &&
19
- (0, exports.isChainReference)(matches.chainReference) &&
20
- (0, exports.isAssetNamespace)(matches.assetNamespace));
15
+ const matches = utils_1.parseAssetIdRegExp.exec(maybeAssetId);
16
+ if (!matches) {
17
+ return false;
18
+ }
19
+ const { 1: chainNamespace, 2: chainReference, 3: assetNamespace } = matches;
20
+ return ((0, exports.isChainNamespace)(chainNamespace) &&
21
+ (0, exports.isChainReference)(chainReference) &&
22
+ (0, exports.isAssetNamespace)(assetNamespace));
21
23
  };
22
24
  exports.isAssetId = isAssetId;
23
25
  const isChainId = (maybeChainId) => {
package/dist/utils.js CHANGED
@@ -26,8 +26,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.osmosisAssetMap = exports.cosmosAssetMap = exports.litecoinAssetMap = exports.dogecoinAssetMap = exports.bitcoinCashAssetMap = exports.bitcoinAssetMap = exports.isValidChainPartsPair = exports.accountIdToSpecifier = exports.accountIdToChainId = exports.parseAssetIdRegExp = void 0;
27
27
  const accountId_1 = require("./accountId/accountId");
28
28
  const constants = __importStar(require("./constants"));
29
- // https://regex101.com/r/f0xGqP/2
30
- exports.parseAssetIdRegExp = /(?<chainNamespace>[-a-z\d]{3,8}):(?<chainReference>[-a-zA-Z\d]{1,32})\/(?<assetNamespace>[-a-z\d]{3,8}):(?<assetReference>[-a-zA-Z\d]+)/;
29
+ // https://regex101.com/r/URAeoi/1
30
+ exports.parseAssetIdRegExp = /([-a-z\d]{3,8}):([-a-zA-Z\d]{1,32})\/([-a-z\d]{3,8}):([-a-zA-Z\d]+)/;
31
31
  const accountIdToChainId = (accountId) => (0, accountId_1.fromAccountId)(accountId).chainId;
32
32
  exports.accountIdToChainId = accountIdToChainId;
33
33
  const accountIdToSpecifier = (accountId) => (0, accountId_1.fromAccountId)(accountId).account;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/caip",
3
- "version": "6.16.0",
3
+ "version": "8.1.0",
4
4
  "description": "CAIP Implementation",
5
5
  "homepage": "",
6
6
  "license": "MIT",