@shapeshiftoss/caip 2.5.2 → 3.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
@@ -3,13 +3,13 @@
3
3
  This package is ShapeShift's partial implementation of [CAIPs](https://github.com/ChainAgnostic/CAIPs) - Chain Agnostic Improvement Protocols.
4
4
  It is not exhaustive and is currently only used internally.
5
5
 
6
- ## ChainId - Blockchain ID Specification
6
+ ## ChainId (CAIP2) - Blockchain ID Specification
7
7
 
8
8
  https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md
9
9
 
10
10
  Usage
11
11
 
12
- ### `toChainId`
12
+ ### `toChainId` | `toCAIP2`
13
13
 
14
14
  ```ts
15
15
  const chain = ChainTypes.Ethereum
@@ -18,7 +18,7 @@ const result = toChainId({ chain, network })
18
18
  expect(result).toEqual('eip155:1')
19
19
  ```
20
20
 
21
- ### `fromChainId`
21
+ ### `fromChainId` | `fromCAIP2`
22
22
 
23
23
  ```ts
24
24
  const ethChainId = 'eip155:1'
@@ -27,13 +27,37 @@ expect(chain).toEqual(ChainTypes.Ethereum)
27
27
  expect(network).toEqual(NetworkTypes.MAINNET)
28
28
  ```
29
29
 
30
- ## AssetId - Asset Type and Asset ID Specification
30
+ ## AccountId (CAIP10) - Blockchain ID Specification
31
+
32
+ https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md
33
+
34
+ Usage
35
+
36
+ ### `toAccountId` | `toCAIP10`
37
+
38
+ ```ts
39
+ const chainId = 'eip155:1'
40
+ const account = '0xA44C286BA83Bb771cd0107B2c1Df678435Bd1535'
41
+ const result = (toAccountId({ chainId, account }))
42
+ expect(result).toEqual('eip155:1:0xa44c286ba83bb771cd0107b2c1df678435bd1535')
43
+ ```
44
+
45
+ ### `fromAccountId` | `fromCAIP10`
46
+
47
+ ```ts
48
+ const accountId = 'eip155:1:0xa44c286ba83bb771cd0107b2c1df678435bd1535'
49
+ const { chainId, account } = fromAccountId(accountId)
50
+ expect(chainId).toEqual('eip155:1')
51
+ expect(account).toEqual('0xa44c286ba83bb771cd0107b2c1df678435bd1535')
52
+ ```
53
+
54
+ ## AssetId (CAIP19) - Asset Type and Asset ID Specification
31
55
 
32
56
  https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
33
57
 
34
58
  Usage
35
59
 
36
- ### `toAssetId`
60
+ ### `toAssetId` | `toCAIP19`
37
61
 
38
62
  Ether
39
63
 
@@ -57,7 +81,7 @@ const result = toAssetId({ chain, network, contractType, tokenId })
57
81
  expect(result).toEqual('eip155:1/erc20:0xc770eefad204b5180df6a14ee197d99d808ee52d')
58
82
  ```
59
83
 
60
- ### `fromAssetId`
84
+ ### `fromAssetId` | `fromCAIP19`
61
85
 
62
86
  Ether
63
87
 
@@ -12,4 +12,6 @@ declare type FromAccountIdReturn = {
12
12
  };
13
13
  declare type FromAccountId = (accountId: string) => FromAccountIdReturn;
14
14
  export declare const fromAccountId: FromAccountId;
15
+ export declare const toCAIP10: ToAccountId;
16
+ export declare const fromCAIP10: FromAccountId;
15
17
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromAccountId = exports.toAccountId = void 0;
3
+ exports.fromCAIP10 = exports.toCAIP10 = exports.fromAccountId = exports.toAccountId = void 0;
4
4
  const chainId_1 = require("../chainId/chainId");
5
5
  const toAccountId = ({ chainId, account }) => {
6
6
  if (!(0, chainId_1.isChainId)(chainId)) {
@@ -38,3 +38,5 @@ const fromAccountId = (accountId) => {
38
38
  return { chainId, account: outputAccount };
39
39
  };
40
40
  exports.fromAccountId = fromAccountId;
41
+ exports.toCAIP10 = exports.toAccountId;
42
+ exports.fromCAIP10 = exports.fromAccountId;
@@ -30,5 +30,8 @@ declare type FromAssetIdReturn = {
30
30
  assetNamespace: AssetNamespace;
31
31
  assetReference: AssetReference | string;
32
32
  };
33
- export declare const fromAssetId: (assetId: string) => FromAssetIdReturn;
33
+ export declare type FromAssetId = (assetId: AssetId) => FromAssetIdReturn;
34
+ export declare const fromAssetId: FromAssetId;
35
+ export declare const toCAIP19: ToAssetId;
36
+ export declare const fromCAIP19: FromAssetId;
34
37
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fromAssetId = exports.toAssetId = exports.AssetReference = exports.AssetNamespace = void 0;
3
+ exports.fromCAIP19 = exports.toCAIP19 = exports.fromAssetId = exports.toAssetId = exports.AssetReference = exports.AssetNamespace = void 0;
4
4
  // https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md
5
5
  const types_1 = require("@shapeshiftoss/types");
6
6
  const chainId_1 = require("../chainId/chainId");
@@ -113,3 +113,5 @@ const fromAssetId = (assetId) => {
113
113
  throw new Error(`fromAssetId: invalid AssetId: ${assetId}`);
114
114
  };
115
115
  exports.fromAssetId = fromAssetId;
116
+ exports.toCAIP19 = exports.toAssetId;
117
+ exports.fromCAIP19 = exports.fromAssetId;
@@ -32,4 +32,6 @@ export declare const isChainId: IsChainId;
32
32
  export declare const chainReferenceToNetworkType: Record<ChainReference, NetworkTypes>;
33
33
  export declare const networkTypeToChainReference: Record<NetworkTypes, ChainReference>;
34
34
  export declare const chainNamespaceToChainType: Record<ChainNamespace, ChainTypes>;
35
+ export declare const toCAIP2: (args: ToChainIdArgs) => string;
36
+ export declare const fromCAIP2: FromChainId;
35
37
  export {};
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.chainNamespaceToChainType = exports.networkTypeToChainReference = exports.chainReferenceToNetworkType = exports.isChainId = exports.fromChainId = exports.toChainId = exports.ChainReference = exports.ChainNamespace = void 0;
7
+ exports.fromCAIP2 = exports.toCAIP2 = exports.chainNamespaceToChainType = exports.networkTypeToChainReference = exports.chainReferenceToNetworkType = exports.isChainId = exports.fromChainId = exports.toChainId = exports.ChainReference = exports.ChainNamespace = void 0;
8
8
  const types_1 = require("@shapeshiftoss/types");
9
9
  const invert_1 = __importDefault(require("lodash/invert"));
10
10
  var ChainNamespace;
@@ -231,3 +231,5 @@ exports.chainNamespaceToChainType = Object.freeze({
231
231
  [ChainNamespace.Ethereum]: types_1.ChainTypes.Ethereum,
232
232
  [ChainNamespace.Cosmos]: types_1.ChainTypes.Cosmos
233
233
  });
234
+ exports.toCAIP2 = exports.toChainId;
235
+ exports.fromCAIP2 = exports.fromChainId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/caip",
3
- "version": "2.5.2",
3
+ "version": "3.1.0",
4
4
  "description": "CAIP Implementation",
5
5
  "homepage": "",
6
6
  "license": "MIT",