@shapeshiftoss/caip 2.2.5 → 2.5.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/adapters/banxa/index.d.ts +7 -0
- package/dist/adapters/banxa/index.js +28 -1
- package/dist/caip19/caip19.js +2 -18
- package/dist/caip2/caip2.d.ts +3 -0
- package/dist/caip2/caip2.js +22 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +9 -6
- package/dist/utils.d.ts +14 -0
- package/dist/utils.js +28 -0
- package/package.json +1 -1
|
@@ -4,3 +4,10 @@ export declare const getSupportedBanxaAssets: () => {
|
|
|
4
4
|
CAIP19: string;
|
|
5
5
|
ticker: string;
|
|
6
6
|
}[];
|
|
7
|
+
/**
|
|
8
|
+
* Convert a banxa asset identifier to a Banxa chain identifier for use in Banxa HTTP URLs
|
|
9
|
+
*
|
|
10
|
+
* @param {string} banxaAssetId - a Banxa asset string referencing a specific asset; e.g., 'atom'
|
|
11
|
+
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
12
|
+
*/
|
|
13
|
+
export declare const getBanxaBlockchainFromBanxaAssetTicker: (banxaAssetId: string) => string;
|
|
@@ -3,9 +3,11 @@ 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.getSupportedBanxaAssets = exports.CAIP19ToBanxaTicker = exports.banxaTickerToCAIP19 = void 0;
|
|
6
|
+
exports.getBanxaBlockchainFromBanxaAssetTicker = exports.getSupportedBanxaAssets = exports.CAIP19ToBanxaTicker = exports.banxaTickerToCAIP19 = void 0;
|
|
7
7
|
const entries_1 = __importDefault(require("lodash/entries"));
|
|
8
8
|
const toLower_1 = __importDefault(require("lodash/toLower"));
|
|
9
|
+
const caip2_1 = require("../../caip2/caip2");
|
|
10
|
+
const caip19_1 = require("../../caip19/caip19");
|
|
9
11
|
const CAIP19ToBanxaTickerMap = {
|
|
10
12
|
'bip122:000000000019d6689c085ae165831e93/slip44:0': 'btc',
|
|
11
13
|
'cosmos:cosmoshub-4/slip44:118': 'atom',
|
|
@@ -47,3 +49,28 @@ const getSupportedBanxaAssets = () => (0, entries_1.default)(CAIP19ToBanxaTicker
|
|
|
47
49
|
ticker
|
|
48
50
|
}));
|
|
49
51
|
exports.getSupportedBanxaAssets = getSupportedBanxaAssets;
|
|
52
|
+
/**
|
|
53
|
+
* map ChainIds to Banxa blockchain codes (ETH, BTC, COSMOS),
|
|
54
|
+
* since some Banxa assets could be on multiple chains and their default
|
|
55
|
+
* chain won't be exactly the same as ours.
|
|
56
|
+
*/
|
|
57
|
+
const chainIdToBanxaBlockchainCodeMap = {
|
|
58
|
+
'eip155:1': 'ETH',
|
|
59
|
+
'bip122:000000000019d6689c085ae165831e93': 'BTC',
|
|
60
|
+
'cosmos:cosmoshub-4': 'COSMOS'
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Convert a banxa asset identifier to a Banxa chain identifier for use in Banxa HTTP URLs
|
|
64
|
+
*
|
|
65
|
+
* @param {string} banxaAssetId - a Banxa asset string referencing a specific asset; e.g., 'atom'
|
|
66
|
+
* @returns {string} - a Banxa chain identifier; e.g., 'cosmos'
|
|
67
|
+
*/
|
|
68
|
+
const getBanxaBlockchainFromBanxaAssetTicker = (banxaAssetId) => {
|
|
69
|
+
const assetCAIP19 = (0, exports.banxaTickerToCAIP19)(banxaAssetId.toLowerCase());
|
|
70
|
+
if (!assetCAIP19)
|
|
71
|
+
throw new Error(`getBanxaBlockchainFromBanxaAssetTicker: ${banxaAssetId} is not supported`);
|
|
72
|
+
const { chain, network } = (0, caip19_1.fromCAIP19)(assetCAIP19);
|
|
73
|
+
const chainId = (0, caip2_1.toCAIP2)({ network, chain });
|
|
74
|
+
return chainIdToBanxaBlockchainCodeMap[chainId];
|
|
75
|
+
};
|
|
76
|
+
exports.getBanxaBlockchainFromBanxaAssetTicker = getBanxaBlockchainFromBanxaAssetTicker;
|
package/dist/caip19/caip19.js
CHANGED
|
@@ -39,22 +39,6 @@ const validAssetNamespaces = Object.freeze({
|
|
|
39
39
|
AssetNamespace.Slip44
|
|
40
40
|
]
|
|
41
41
|
});
|
|
42
|
-
const chainReferenceToNetworkType = Object.freeze({
|
|
43
|
-
[caip2_1.ChainReference.BitcoinMainnet]: types_1.NetworkTypes.MAINNET,
|
|
44
|
-
[caip2_1.ChainReference.BitcoinTestnet]: types_1.NetworkTypes.TESTNET,
|
|
45
|
-
[caip2_1.ChainReference.EthereumMainnet]: types_1.NetworkTypes.MAINNET,
|
|
46
|
-
[caip2_1.ChainReference.EthereumRopsten]: types_1.NetworkTypes.ETH_ROPSTEN,
|
|
47
|
-
[caip2_1.ChainReference.EthereumRinkeby]: types_1.NetworkTypes.ETH_RINKEBY,
|
|
48
|
-
[caip2_1.ChainReference.CosmosHubMainnet]: types_1.NetworkTypes.COSMOSHUB_MAINNET,
|
|
49
|
-
[caip2_1.ChainReference.CosmosHubVega]: types_1.NetworkTypes.COSMOSHUB_VEGA,
|
|
50
|
-
[caip2_1.ChainReference.OsmosisMainnet]: types_1.NetworkTypes.OSMOSIS_MAINNET,
|
|
51
|
-
[caip2_1.ChainReference.OsmosisTestnet]: types_1.NetworkTypes.OSMOSIS_TESTNET
|
|
52
|
-
});
|
|
53
|
-
const chainNamespaceToChainType = Object.freeze({
|
|
54
|
-
[caip2_1.ChainNamespace.Bitcoin]: types_1.ChainTypes.Bitcoin,
|
|
55
|
-
[caip2_1.ChainNamespace.Ethereum]: types_1.ChainTypes.Ethereum,
|
|
56
|
-
[caip2_1.ChainNamespace.Cosmos]: types_1.ChainTypes.Cosmos
|
|
57
|
-
});
|
|
58
42
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
43
|
function stringToEnum(obj, item) {
|
|
60
44
|
var _a;
|
|
@@ -108,8 +92,8 @@ const fromCAIP19 = (caip19) => {
|
|
|
108
92
|
const matches = (_a = parseCaip19RegExp.exec(caip19)) !== null && _a !== void 0 ? _a : [];
|
|
109
93
|
// We're okay casting these strings to enums because we check to make sure
|
|
110
94
|
// they are valid enum values
|
|
111
|
-
let chain = chainNamespaceToChainType[matches[1]];
|
|
112
|
-
const network = chainReferenceToNetworkType[matches[2]];
|
|
95
|
+
let chain = caip2_1.chainNamespaceToChainType[matches[1]];
|
|
96
|
+
const network = caip2_1.chainReferenceToNetworkType[matches[2]];
|
|
113
97
|
const assetNamespace = stringToEnum(AssetNamespace, matches[3]);
|
|
114
98
|
let assetReference = matches[4];
|
|
115
99
|
if (chain && network && assetNamespace && assetReference) {
|
package/dist/caip2/caip2.d.ts
CHANGED
|
@@ -33,4 +33,7 @@ declare type FromCAIP2 = (caip2: string) => FromCAIP2Return;
|
|
|
33
33
|
export declare const fromCAIP2: FromCAIP2;
|
|
34
34
|
declare type IsCAIP2 = (caip2: string) => boolean;
|
|
35
35
|
export declare const isCAIP2: IsCAIP2;
|
|
36
|
+
export declare const chainReferenceToNetworkType: Record<ChainReference, NetworkTypes>;
|
|
37
|
+
export declare const networkTypeToChainReference: Record<NetworkTypes, ChainReference>;
|
|
38
|
+
export declare const chainNamespaceToChainType: Record<ChainNamespace, ChainTypes>;
|
|
36
39
|
export {};
|
package/dist/caip2/caip2.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.isCAIP2 = exports.fromCAIP2 = exports.toCAIP2 = exports.ChainReference = exports.ChainNamespace = void 0;
|
|
7
|
+
exports.chainNamespaceToChainType = exports.networkTypeToChainReference = exports.chainReferenceToNetworkType = exports.isCAIP2 = exports.fromCAIP2 = exports.toCAIP2 = exports.ChainReference = exports.ChainNamespace = void 0;
|
|
5
8
|
const types_1 = require("@shapeshiftoss/types");
|
|
9
|
+
const invert_1 = __importDefault(require("lodash/invert"));
|
|
6
10
|
var ChainNamespace;
|
|
7
11
|
(function (ChainNamespace) {
|
|
8
12
|
ChainNamespace["Ethereum"] = "eip155";
|
|
@@ -210,3 +214,20 @@ const isCAIP2 = (caip2) => {
|
|
|
210
214
|
throw new Error(`isCAIP2: invalid caip2 ${caip2}`);
|
|
211
215
|
};
|
|
212
216
|
exports.isCAIP2 = isCAIP2;
|
|
217
|
+
exports.chainReferenceToNetworkType = Object.freeze({
|
|
218
|
+
[ChainReference.BitcoinMainnet]: types_1.NetworkTypes.MAINNET,
|
|
219
|
+
[ChainReference.BitcoinTestnet]: types_1.NetworkTypes.TESTNET,
|
|
220
|
+
[ChainReference.EthereumMainnet]: types_1.NetworkTypes.MAINNET,
|
|
221
|
+
[ChainReference.EthereumRopsten]: types_1.NetworkTypes.ETH_ROPSTEN,
|
|
222
|
+
[ChainReference.EthereumRinkeby]: types_1.NetworkTypes.ETH_RINKEBY,
|
|
223
|
+
[ChainReference.CosmosHubMainnet]: types_1.NetworkTypes.COSMOSHUB_MAINNET,
|
|
224
|
+
[ChainReference.CosmosHubVega]: types_1.NetworkTypes.COSMOSHUB_VEGA,
|
|
225
|
+
[ChainReference.OsmosisMainnet]: types_1.NetworkTypes.OSMOSIS_MAINNET,
|
|
226
|
+
[ChainReference.OsmosisTestnet]: types_1.NetworkTypes.OSMOSIS_TESTNET
|
|
227
|
+
});
|
|
228
|
+
exports.networkTypeToChainReference = (0, invert_1.default)(exports.chainReferenceToNetworkType);
|
|
229
|
+
exports.chainNamespaceToChainType = Object.freeze({
|
|
230
|
+
[ChainNamespace.Bitcoin]: types_1.ChainTypes.Bitcoin,
|
|
231
|
+
[ChainNamespace.Ethereum]: types_1.ChainTypes.Ethereum,
|
|
232
|
+
[ChainNamespace.Cosmos]: types_1.ChainTypes.Cosmos
|
|
233
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ import * as caip2 from './caip2/caip2';
|
|
|
3
3
|
import * as caip10 from './caip10/caip10';
|
|
4
4
|
import * as caip19 from './caip19/caip19';
|
|
5
5
|
export { adapters, caip2, caip19, caip10 };
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
6
|
+
export * from './caip2/caip2';
|
|
7
|
+
export * from './caip10/caip10';
|
|
8
|
+
export * from './caip19/caip19';
|
package/dist/index.js
CHANGED
|
@@ -22,18 +22,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
|
+
};
|
|
25
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
29
|
+
exports.caip10 = exports.caip19 = exports.caip2 = exports.adapters = void 0;
|
|
27
30
|
const adapters = __importStar(require("./adapters"));
|
|
28
31
|
exports.adapters = adapters;
|
|
32
|
+
// TODO: These all go away on the caip breaking change PR
|
|
29
33
|
const caip2 = __importStar(require("./caip2/caip2"));
|
|
30
34
|
exports.caip2 = caip2;
|
|
31
35
|
const caip10 = __importStar(require("./caip10/caip10"));
|
|
32
36
|
exports.caip10 = caip10;
|
|
33
37
|
const caip19 = __importStar(require("./caip19/caip19"));
|
|
34
38
|
exports.caip19 = caip19;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Object.defineProperty(exports, "AssetReference", { enumerable: true, get: function () { return caip19_1.AssetReference; } });
|
|
39
|
+
// ENDTODO
|
|
40
|
+
__exportStar(require("./caip2/caip2"), exports);
|
|
41
|
+
__exportStar(require("./caip10/caip10"), exports);
|
|
42
|
+
__exportStar(require("./caip19/caip19"), exports);
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ChainId } from './caip2/caip2';
|
|
2
|
+
import { AccountId } from './caip10/caip10';
|
|
3
|
+
import { AssetId } from './caip19/caip19';
|
|
4
|
+
export declare const btcAssetId = "bip122:000000000019d6689c085ae165831e93/slip44:0";
|
|
5
|
+
export declare const ethAssetId = "eip155:1/slip44:60";
|
|
6
|
+
export declare const cosmosAssetId = "cosmos:cosmoshub-4/slip44:118";
|
|
7
|
+
export declare const ethChainId = "eip155:1";
|
|
8
|
+
export declare const btcChainId = "bip122:000000000019d6689c085ae165831e93";
|
|
9
|
+
export declare const cosmosChainId = "cosmos:cosmoshub-4";
|
|
10
|
+
export declare const chainIdToAssetId: Record<ChainId, AssetId>;
|
|
11
|
+
export declare const assetIdToChainId: (assetId: AssetId) => string;
|
|
12
|
+
export declare const accountIdToChainId: (accountId: AccountId) => ChainId;
|
|
13
|
+
export declare const accountIdToSpecifier: (accountId: AccountId) => string;
|
|
14
|
+
export declare const getChainReferenceFromChainId: (chainId: ChainId) => import("./caip2/caip2").ChainReference;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getChainReferenceFromChainId = exports.accountIdToSpecifier = exports.accountIdToChainId = exports.assetIdToChainId = exports.chainIdToAssetId = exports.cosmosChainId = exports.btcChainId = exports.ethChainId = exports.cosmosAssetId = exports.ethAssetId = exports.btcAssetId = void 0;
|
|
4
|
+
const caip2_1 = require("./caip2/caip2");
|
|
5
|
+
const caip10_1 = require("./caip10/caip10");
|
|
6
|
+
const caip19_1 = require("./caip19/caip19");
|
|
7
|
+
exports.btcAssetId = 'bip122:000000000019d6689c085ae165831e93/slip44:0';
|
|
8
|
+
exports.ethAssetId = 'eip155:1/slip44:60';
|
|
9
|
+
exports.cosmosAssetId = 'cosmos:cosmoshub-4/slip44:118';
|
|
10
|
+
exports.ethChainId = 'eip155:1';
|
|
11
|
+
exports.btcChainId = 'bip122:000000000019d6689c085ae165831e93';
|
|
12
|
+
exports.cosmosChainId = 'cosmos:cosmoshub-4';
|
|
13
|
+
exports.chainIdToAssetId = {
|
|
14
|
+
[exports.ethChainId]: 'eip155:1/slip44:60',
|
|
15
|
+
[exports.btcChainId]: 'bip122:000000000019d6689c085ae165831e93/slip44:0',
|
|
16
|
+
[exports.cosmosChainId]: 'cosmos:cosmoshub-4/slip44:118'
|
|
17
|
+
};
|
|
18
|
+
const assetIdToChainId = (assetId) => {
|
|
19
|
+
const { chain, network } = (0, caip19_1.fromCAIP19)(assetId);
|
|
20
|
+
return (0, caip2_1.toCAIP2)({ chain, network });
|
|
21
|
+
};
|
|
22
|
+
exports.assetIdToChainId = assetIdToChainId;
|
|
23
|
+
const accountIdToChainId = (accountId) => (0, caip10_1.fromCAIP10)(accountId).caip2;
|
|
24
|
+
exports.accountIdToChainId = accountIdToChainId;
|
|
25
|
+
const accountIdToSpecifier = (accountId) => (0, caip10_1.fromCAIP10)(accountId).account;
|
|
26
|
+
exports.accountIdToSpecifier = accountIdToSpecifier;
|
|
27
|
+
const getChainReferenceFromChainId = (chainId) => caip2_1.networkTypeToChainReference[(0, caip2_1.fromCAIP2)(chainId).network];
|
|
28
|
+
exports.getChainReferenceFromChainId = getChainReferenceFromChainId;
|