@defuse-protocol/crosschain-assetid 1.0.0 → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 NEAR Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs CHANGED
@@ -1,102 +1,90 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
1
 
20
- // src/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- fromUniswapToken: () => fromUniswapToken,
24
- parse1cs: () => parse1cs,
25
- stringify1cs: () => stringify1cs
26
- });
27
- module.exports = __toCommonJS(index_exports);
28
-
29
- // src/parse.ts
2
+ //#region src/parse.ts
30
3
  function parse1cs(s) {
31
- const parts = s.split(":");
32
- if (parts.length < 4 || parts.length > 5 || parts[0] !== "1cs_v1") {
33
- throw new Error("Invalid 1cs_v1 string");
34
- }
35
- const [_, chain, namespace, refEnc, selEnc] = parts;
36
- const obj = {
37
- version: "v1",
38
- // biome-ignore lint/style/noNonNullAssertion: existence checked above
39
- chain,
40
- // biome-ignore lint/style/noNonNullAssertion: existence checked above
41
- namespace,
42
- // biome-ignore lint/style/noNonNullAssertion: existence checked above
43
- reference: decodeURIComponent(refEnc)
44
- };
45
- if (selEnc !== void 0) obj.selector = decodeURIComponent(selEnc);
46
- return obj;
4
+ const parts = s.split(":");
5
+ if (parts.length < 4 || parts.length > 5 || parts[0] !== "1cs_v1") throw new Error("Invalid 1cs_v1 string");
6
+ const [_, chain, namespace, refEnc, selEnc] = parts;
7
+ const obj = {
8
+ version: "v1",
9
+ chain,
10
+ namespace,
11
+ reference: decodeURIComponent(refEnc)
12
+ };
13
+ if (selEnc !== void 0) obj.selector = decodeURIComponent(selEnc);
14
+ return obj;
47
15
  }
48
16
 
49
- // src/stringify.ts
17
+ //#endregion
18
+ //#region src/stringify.ts
50
19
  function stringify1cs(o) {
51
- const ref = encodeURIComponent(o.reference);
52
- const sel = o.selector != null ? `:${encodeURIComponent(o.selector)}` : "";
53
- return `1cs_v1:${o.chain}:${o.namespace}:${ref}${sel}`;
20
+ const ref = encodeURIComponent(o.reference);
21
+ const sel = o.selector != null ? `:${encodeURIComponent(o.selector)}` : "";
22
+ return `1cs_v1:${o.chain}:${o.namespace}:${ref}${sel}`;
54
23
  }
55
24
 
56
- // src/caip2-slug-registry.json
25
+ //#endregion
26
+ //#region src/caip2-slug-registry.json
27
+ var eip155_1 = "eth";
28
+ var eip155_10 = "optimism";
29
+ var eip155_56 = "bsc";
30
+ var eip155_100 = "gnosis";
31
+ var eip155_137 = "polygon";
32
+ var eip155_8453 = "base";
33
+ var eip155_42161 = "arbitrum";
34
+ var eip155_43114 = "avalanche";
35
+ var eip155_80085 = "berachain";
36
+ var bip122_000000000019d6689c085ae165831e93 = "bitcoin";
37
+ var bip122_00040fe8ec8471911baa1db1266ea15d = "zcash";
38
+ var bip122_1a91e3dace36e2be3bf030a65679fe82 = "doge";
39
+ var near_mainnet = "near";
40
+ var solana_5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp = "sol";
41
+ var tron_27Lqcw = "tron";
42
+ var xrpl_0 = "xrpl";
43
+ var tvm__239 = "ton";
44
+ var sui_mainnet = "sui";
45
+ var aptos_mainnet = "aptos";
46
+ var stellar_pubnet = "stellar";
47
+ var cip34_1_764824073 = "cardano";
57
48
  var caip2_slug_registry_default = {
58
- "eip155:1": "eth",
59
- "eip155:10": "optimism",
60
- "eip155:56": "bsc",
61
- "eip155:100": "gnosis",
62
- "eip155:137": "polygon",
63
- "eip155:8453": "base",
64
- "eip155:42161": "arbitrum",
65
- "eip155:43114": "avalanche",
66
- "eip155:80085": "berachain",
67
- "bip122:000000000019d6689c085ae165831e93": "bitcoin",
68
- "bip122:00040fe8ec8471911baa1db1266ea15d": "zcash",
69
- "bip122:1a91e3dace36e2be3bf030a65679fe82": "doge",
70
- "near:mainnet": "near",
71
- "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": "sol",
72
- "tron:27Lqcw": "tron",
73
- "xrpl:0": "xrpl",
74
- "tvm:-239": "ton",
75
- "sui:mainnet": "sui",
76
- "aptos:mainnet": "aptos",
77
- "stellar:pubnet": "stellar",
78
- "cip34:1-764824073": "cardano"
49
+ "eip155:1": eip155_1,
50
+ "eip155:10": eip155_10,
51
+ "eip155:56": eip155_56,
52
+ "eip155:100": eip155_100,
53
+ "eip155:137": eip155_137,
54
+ "eip155:8453": eip155_8453,
55
+ "eip155:42161": eip155_42161,
56
+ "eip155:43114": eip155_43114,
57
+ "eip155:80085": eip155_80085,
58
+ "bip122:000000000019d6689c085ae165831e93": bip122_000000000019d6689c085ae165831e93,
59
+ "bip122:00040fe8ec8471911baa1db1266ea15d": bip122_00040fe8ec8471911baa1db1266ea15d,
60
+ "bip122:1a91e3dace36e2be3bf030a65679fe82": bip122_1a91e3dace36e2be3bf030a65679fe82,
61
+ "near:mainnet": near_mainnet,
62
+ "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": solana_5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp,
63
+ "tron:27Lqcw": tron_27Lqcw,
64
+ "xrpl:0": xrpl_0,
65
+ "tvm:-239": tvm__239,
66
+ "sui:mainnet": sui_mainnet,
67
+ "aptos:mainnet": aptos_mainnet,
68
+ "stellar:pubnet": stellar_pubnet,
69
+ "cip34:1-764824073": cip34_1_764824073
79
70
  };
80
71
 
81
- // src/uniswap.ts
82
- var evmSlugRegistry = caip2_slug_registry_default;
72
+ //#endregion
73
+ //#region src/uniswap.ts
74
+ const evmSlugRegistry = caip2_slug_registry_default;
83
75
  function fromUniswapToken(token, caip2slugMap) {
84
- const caip2 = `eip155:${token.chainId}`;
85
- const chain = caip2slugMap?.[caip2] ?? evmSlugRegistry[caip2];
86
- if (chain == null) {
87
- throw new Error(`Unsupported chainId = ${token.chainId}`);
88
- }
89
- const o = {
90
- version: "v1",
91
- chain,
92
- namespace: "erc20",
93
- reference: token.address
94
- };
95
- return stringify1cs(o);
76
+ const caip2 = `eip155:${token.chainId}`;
77
+ const chain = caip2slugMap?.[caip2] ?? evmSlugRegistry[caip2];
78
+ if (chain == null) throw new Error(`Unsupported chainId = ${token.chainId}`);
79
+ return stringify1cs({
80
+ version: "v1",
81
+ chain,
82
+ namespace: "erc20",
83
+ reference: token.address
84
+ });
96
85
  }
97
- // Annotate the CommonJS export names for ESM import in node:
98
- 0 && (module.exports = {
99
- fromUniswapToken,
100
- parse1cs,
101
- stringify1cs
102
- });
86
+
87
+ //#endregion
88
+ exports.fromUniswapToken = fromUniswapToken;
89
+ exports.parse1cs = parse1cs;
90
+ exports.stringify1cs = stringify1cs;
package/dist/index.d.cts CHANGED
@@ -1,19 +1,23 @@
1
+ //#region src/types.d.ts
1
2
  interface OneCsAsset {
2
- version: "v1";
3
- chain: string;
4
- namespace: string;
5
- reference: string;
6
- selector?: string;
3
+ version: "v1";
4
+ chain: string;
5
+ namespace: string;
6
+ reference: string;
7
+ selector?: string;
7
8
  }
8
-
9
+ //#endregion
10
+ //#region src/parse.d.ts
9
11
  declare function parse1cs(s: string): OneCsAsset;
10
-
12
+ //#endregion
13
+ //#region src/stringify.d.ts
11
14
  declare function stringify1cs(o: OneCsAsset): string;
12
-
15
+ //#endregion
16
+ //#region src/uniswap.d.ts
13
17
  interface UniToken {
14
- chainId: number;
15
- address: string;
18
+ chainId: number;
19
+ address: string;
16
20
  }
17
21
  declare function fromUniswapToken<T extends UniToken>(token: T, caip2slugMap?: Record<string, string>): string;
18
-
19
- export { type OneCsAsset, type UniToken, fromUniswapToken, parse1cs, stringify1cs };
22
+ //#endregion
23
+ export { type OneCsAsset, UniToken, fromUniswapToken, parse1cs, stringify1cs };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,23 @@
1
+ //#region src/types.d.ts
1
2
  interface OneCsAsset {
2
- version: "v1";
3
- chain: string;
4
- namespace: string;
5
- reference: string;
6
- selector?: string;
3
+ version: "v1";
4
+ chain: string;
5
+ namespace: string;
6
+ reference: string;
7
+ selector?: string;
7
8
  }
8
-
9
+ //#endregion
10
+ //#region src/parse.d.ts
9
11
  declare function parse1cs(s: string): OneCsAsset;
10
-
12
+ //#endregion
13
+ //#region src/stringify.d.ts
11
14
  declare function stringify1cs(o: OneCsAsset): string;
12
-
15
+ //#endregion
16
+ //#region src/uniswap.d.ts
13
17
  interface UniToken {
14
- chainId: number;
15
- address: string;
18
+ chainId: number;
19
+ address: string;
16
20
  }
17
21
  declare function fromUniswapToken<T extends UniToken>(token: T, caip2slugMap?: Record<string, string>): string;
18
-
19
- export { type OneCsAsset, type UniToken, fromUniswapToken, parse1cs, stringify1cs };
22
+ //#endregion
23
+ export { type OneCsAsset, UniToken, fromUniswapToken, parse1cs, stringify1cs };
package/dist/index.js CHANGED
@@ -1,73 +1,87 @@
1
- // src/parse.ts
1
+ //#region src/parse.ts
2
2
  function parse1cs(s) {
3
- const parts = s.split(":");
4
- if (parts.length < 4 || parts.length > 5 || parts[0] !== "1cs_v1") {
5
- throw new Error("Invalid 1cs_v1 string");
6
- }
7
- const [_, chain, namespace, refEnc, selEnc] = parts;
8
- const obj = {
9
- version: "v1",
10
- // biome-ignore lint/style/noNonNullAssertion: existence checked above
11
- chain,
12
- // biome-ignore lint/style/noNonNullAssertion: existence checked above
13
- namespace,
14
- // biome-ignore lint/style/noNonNullAssertion: existence checked above
15
- reference: decodeURIComponent(refEnc)
16
- };
17
- if (selEnc !== void 0) obj.selector = decodeURIComponent(selEnc);
18
- return obj;
3
+ const parts = s.split(":");
4
+ if (parts.length < 4 || parts.length > 5 || parts[0] !== "1cs_v1") throw new Error("Invalid 1cs_v1 string");
5
+ const [_, chain, namespace, refEnc, selEnc] = parts;
6
+ const obj = {
7
+ version: "v1",
8
+ chain,
9
+ namespace,
10
+ reference: decodeURIComponent(refEnc)
11
+ };
12
+ if (selEnc !== void 0) obj.selector = decodeURIComponent(selEnc);
13
+ return obj;
19
14
  }
20
15
 
21
- // src/stringify.ts
16
+ //#endregion
17
+ //#region src/stringify.ts
22
18
  function stringify1cs(o) {
23
- const ref = encodeURIComponent(o.reference);
24
- const sel = o.selector != null ? `:${encodeURIComponent(o.selector)}` : "";
25
- return `1cs_v1:${o.chain}:${o.namespace}:${ref}${sel}`;
19
+ const ref = encodeURIComponent(o.reference);
20
+ const sel = o.selector != null ? `:${encodeURIComponent(o.selector)}` : "";
21
+ return `1cs_v1:${o.chain}:${o.namespace}:${ref}${sel}`;
26
22
  }
27
23
 
28
- // src/caip2-slug-registry.json
24
+ //#endregion
25
+ //#region src/caip2-slug-registry.json
26
+ var eip155_1 = "eth";
27
+ var eip155_10 = "optimism";
28
+ var eip155_56 = "bsc";
29
+ var eip155_100 = "gnosis";
30
+ var eip155_137 = "polygon";
31
+ var eip155_8453 = "base";
32
+ var eip155_42161 = "arbitrum";
33
+ var eip155_43114 = "avalanche";
34
+ var eip155_80085 = "berachain";
35
+ var bip122_000000000019d6689c085ae165831e93 = "bitcoin";
36
+ var bip122_00040fe8ec8471911baa1db1266ea15d = "zcash";
37
+ var bip122_1a91e3dace36e2be3bf030a65679fe82 = "doge";
38
+ var near_mainnet = "near";
39
+ var solana_5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp = "sol";
40
+ var tron_27Lqcw = "tron";
41
+ var xrpl_0 = "xrpl";
42
+ var tvm__239 = "ton";
43
+ var sui_mainnet = "sui";
44
+ var aptos_mainnet = "aptos";
45
+ var stellar_pubnet = "stellar";
46
+ var cip34_1_764824073 = "cardano";
29
47
  var caip2_slug_registry_default = {
30
- "eip155:1": "eth",
31
- "eip155:10": "optimism",
32
- "eip155:56": "bsc",
33
- "eip155:100": "gnosis",
34
- "eip155:137": "polygon",
35
- "eip155:8453": "base",
36
- "eip155:42161": "arbitrum",
37
- "eip155:43114": "avalanche",
38
- "eip155:80085": "berachain",
39
- "bip122:000000000019d6689c085ae165831e93": "bitcoin",
40
- "bip122:00040fe8ec8471911baa1db1266ea15d": "zcash",
41
- "bip122:1a91e3dace36e2be3bf030a65679fe82": "doge",
42
- "near:mainnet": "near",
43
- "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": "sol",
44
- "tron:27Lqcw": "tron",
45
- "xrpl:0": "xrpl",
46
- "tvm:-239": "ton",
47
- "sui:mainnet": "sui",
48
- "aptos:mainnet": "aptos",
49
- "stellar:pubnet": "stellar",
50
- "cip34:1-764824073": "cardano"
48
+ "eip155:1": eip155_1,
49
+ "eip155:10": eip155_10,
50
+ "eip155:56": eip155_56,
51
+ "eip155:100": eip155_100,
52
+ "eip155:137": eip155_137,
53
+ "eip155:8453": eip155_8453,
54
+ "eip155:42161": eip155_42161,
55
+ "eip155:43114": eip155_43114,
56
+ "eip155:80085": eip155_80085,
57
+ "bip122:000000000019d6689c085ae165831e93": bip122_000000000019d6689c085ae165831e93,
58
+ "bip122:00040fe8ec8471911baa1db1266ea15d": bip122_00040fe8ec8471911baa1db1266ea15d,
59
+ "bip122:1a91e3dace36e2be3bf030a65679fe82": bip122_1a91e3dace36e2be3bf030a65679fe82,
60
+ "near:mainnet": near_mainnet,
61
+ "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp": solana_5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp,
62
+ "tron:27Lqcw": tron_27Lqcw,
63
+ "xrpl:0": xrpl_0,
64
+ "tvm:-239": tvm__239,
65
+ "sui:mainnet": sui_mainnet,
66
+ "aptos:mainnet": aptos_mainnet,
67
+ "stellar:pubnet": stellar_pubnet,
68
+ "cip34:1-764824073": cip34_1_764824073
51
69
  };
52
70
 
53
- // src/uniswap.ts
54
- var evmSlugRegistry = caip2_slug_registry_default;
71
+ //#endregion
72
+ //#region src/uniswap.ts
73
+ const evmSlugRegistry = caip2_slug_registry_default;
55
74
  function fromUniswapToken(token, caip2slugMap) {
56
- const caip2 = `eip155:${token.chainId}`;
57
- const chain = caip2slugMap?.[caip2] ?? evmSlugRegistry[caip2];
58
- if (chain == null) {
59
- throw new Error(`Unsupported chainId = ${token.chainId}`);
60
- }
61
- const o = {
62
- version: "v1",
63
- chain,
64
- namespace: "erc20",
65
- reference: token.address
66
- };
67
- return stringify1cs(o);
75
+ const caip2 = `eip155:${token.chainId}`;
76
+ const chain = caip2slugMap?.[caip2] ?? evmSlugRegistry[caip2];
77
+ if (chain == null) throw new Error(`Unsupported chainId = ${token.chainId}`);
78
+ return stringify1cs({
79
+ version: "v1",
80
+ chain,
81
+ namespace: "erc20",
82
+ reference: token.address
83
+ });
68
84
  }
69
- export {
70
- fromUniswapToken,
71
- parse1cs,
72
- stringify1cs
73
- };
85
+
86
+ //#endregion
87
+ export { fromUniswapToken, parse1cs, stringify1cs };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/crosschain-assetid",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -23,12 +23,12 @@
23
23
  ],
24
24
  "devDependencies": {
25
25
  "ajv": "^8.17.1",
26
- "tsup": "^8.0.2",
26
+ "tsdown": "0.15.5",
27
27
  "typescript": "^5.4.2"
28
28
  },
29
29
  "scripts": {
30
- "build": "tsup",
31
- "dev": "tsup --watch",
30
+ "build": "tsdown",
31
+ "dev": "tsdown --watch",
32
32
  "lint": "biome check .",
33
33
  "format": "biome format --write .",
34
34
  "typecheck": "tsc --noEmit"