@shapeshiftoss/caip 8.0.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/dist/assetId/assetId.d.ts +2 -2
- package/dist/assetId/assetId.js +14 -19
- package/dist/constants.d.ts +15 -5
- package/dist/constants.js +31 -23
- package/dist/typeGuards.d.ts +1 -1
- package/dist/typeGuards.js +9 -7
- package/dist/utils.js +2 -2
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ChainId, ChainNamespace, ChainReference } from '../chainId/chainId';
|
|
2
|
-
import {
|
|
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
|
|
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;
|
package/dist/assetId/assetId.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
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 =
|
|
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 {
|
|
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}`);
|
package/dist/constants.d.ts
CHANGED
|
@@ -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;
|
|
@@ -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
|
|
43
|
-
|
|
44
|
-
|
|
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.
|
|
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';
|
|
@@ -40,6 +42,25 @@ 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
65
|
[exports.CHAIN_NAMESPACE.Utxo]: [
|
|
45
66
|
exports.CHAIN_REFERENCE.BitcoinMainnet,
|
|
@@ -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.Utxo]: [
|
|
66
|
-
[exports.CHAIN_NAMESPACE.Evm]: [
|
|
67
|
-
[exports.CHAIN_NAMESPACE.CosmosSdk]: [
|
|
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
|
-
};
|
package/dist/typeGuards.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/dist/typeGuards.js
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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/
|
|
30
|
-
exports.parseAssetIdRegExp = /(
|
|
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;
|