@shapeshiftoss/caip 1.12.0 → 1.12.1

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.
@@ -21,6 +21,16 @@ var AssetReference;
21
21
  AssetReference[AssetReference["Cosmos"] = 118] = "Cosmos";
22
22
  AssetReference[AssetReference["Osmosis"] = 118] = "Osmosis";
23
23
  })(AssetReference = exports.AssetReference || (exports.AssetReference = {}));
24
+ /**
25
+ * validate that a value is a string slip44 value
26
+ * @see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
27
+ * @param {string} value - possible slip44 value
28
+ */
29
+ const isValidSlip44 = (value) => {
30
+ const n = Number(value);
31
+ // slip44 has a max value of an unsigned 32-bit integer
32
+ return !isNaN(n) && n >= 0 && n < 4294967296;
33
+ };
24
34
  const toCAIP19 = ({ chain, network, contractType, tokenId, assetNamespace, assetReference }) => {
25
35
  const caip2 = (0, caip2_1.toCAIP2)({ chain, network });
26
36
  switch (chain) {
@@ -37,10 +47,11 @@ const toCAIP19 = ({ chain, network, contractType, tokenId, assetNamespace, asset
37
47
  case AssetNamespace.IBC:
38
48
  case AssetNamespace.NATIVE:
39
49
  return `${caip2}/${assetNamespace}:${assetReference}`;
40
- default: {
41
- throw new Error(`Could not construct CAIP19 chain: ${chain}, network: ${network}, assetNamespace: ${assetNamespace}, assetReference: ${assetReference}`);
42
- }
50
+ case AssetNamespace.Slip44:
51
+ if (isValidSlip44(assetReference))
52
+ return `${caip2}/${assetNamespace}:${assetReference}`;
43
53
  }
54
+ throw new Error(`Could not construct CAIP19 chain: ${chain}, network: ${network}, assetNamespace: ${assetNamespace}, assetReference: ${assetReference}`);
44
55
  }
45
56
  case types_1.ChainTypes.Ethereum: {
46
57
  tokenId = tokenId === null || tokenId === void 0 ? void 0 : tokenId.toLowerCase();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shapeshiftoss/caip",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "CAIP Implementation",
5
5
  "homepage": "",
6
6
  "license": "MIT",