@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 +21 -0
- package/dist/index.cjs +78 -90
- package/dist/index.d.cts +16 -12
- package/dist/index.d.ts +16 -12
- package/dist/index.js +76 -62
- package/package.json +4 -4
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/stringify.ts
|
|
50
19
|
function stringify1cs(o) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/uniswap.ts
|
|
74
|
+
const evmSlugRegistry = caip2_slug_registry_default;
|
|
83
75
|
function fromUniswapToken(token, caip2slugMap) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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,
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
15
|
-
|
|
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,
|
|
22
|
+
//#endregion
|
|
23
|
+
export { type OneCsAsset, UniToken, fromUniswapToken, parse1cs, stringify1cs };
|
package/dist/index.js
CHANGED
|
@@ -1,73 +1,87 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/parse.ts
|
|
2
2
|
function parse1cs(s) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/stringify.ts
|
|
22
18
|
function stringify1cs(o) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
54
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/uniswap.ts
|
|
73
|
+
const evmSlugRegistry = caip2_slug_registry_default;
|
|
55
74
|
function fromUniswapToken(token, caip2slugMap) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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.
|
|
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
|
-
"
|
|
26
|
+
"tsdown": "0.15.5",
|
|
27
27
|
"typescript": "^5.4.2"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "
|
|
31
|
-
"dev": "
|
|
30
|
+
"build": "tsdown",
|
|
31
|
+
"dev": "tsdown --watch",
|
|
32
32
|
"lint": "biome check .",
|
|
33
33
|
"format": "biome format --write .",
|
|
34
34
|
"typecheck": "tsc --noEmit"
|