@paraspell/sdk-common 8.9.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ParaSpell
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/README.md ADDED
@@ -0,0 +1,52 @@
1
+ <br /><br />
2
+
3
+ <div align="center">
4
+ <h1 align="center">@paraspell/sdk-common</h1>
5
+ <h4 align="center"> Common code for @paraspell/sdk-core, @paraspell/assets and @paraspell/pallets. </h4>
6
+ <p align="center">
7
+ <a href="https://npmjs.com/package/@paraspell/sdk-common">
8
+ <img alt="version" src="https://img.shields.io/npm/v/@paraspell/sdk-common?style=flat-square" />
9
+ </a>
10
+ <a href="https://npmjs.com/package/@paraspell/sdk-common">
11
+ <img alt="downloads" src="https://img.shields.io/npm/dm/@paraspell/sdk-common?style=flat-square" />
12
+ </a>
13
+ <a href="https://github.com/paraspell/xcm-sdk/actions">
14
+ <img alt="build" src="https://github.com/paraspell/xcm-sdk/actions/workflows/release.yml/badge.svg" />
15
+ </a>
16
+ <a href="https://snyk.io/test/github/paraspell/sdk">
17
+ <img alt="snyk" src="https://snyk.io/test/github/paraspell/sdk/badge.svg" />
18
+ </a>
19
+ </p>
20
+ </div>
21
+
22
+ <br /><br />
23
+ <br /><br />
24
+
25
+ ## Information
26
+
27
+ This package serves as a `core` component for both `@paraspell/sdk-core`, `assets` and `pallets` and is `automatically` installed as a `dependency`. The package on its own `doesn't` offer any XCM functionality but can be used to get `common types` shared in mentioned packages.
28
+
29
+ ## 💻 Tests
30
+
31
+ - Run compilation using `pnpm compile`
32
+
33
+ - Run linter using `pnpm lint`
34
+
35
+ - Run unit tests using `pnpm test`
36
+
37
+ XCM SDK can be tested in [Playground](https://playground.paraspell.xyz/xcm-sdk/xcm-transfer).
38
+
39
+ ## License
40
+
41
+ Made with 💛 by [ParaSpell✨](https://paraspell.xyz/)
42
+
43
+ Published under [MIT License](https://github.com/paraspell/xcm-tools/blob/main/packages/sdk-common/LICENSE).
44
+
45
+ ## Support
46
+
47
+ <div align="center">
48
+ <p align="center">
49
+ <img width="200" alt="version" src="https://user-images.githubusercontent.com/55763425/211145923-f7ee2a57-3e63-4b7d-9674-2da9db46b2ee.png" />
50
+ <img width="200" alt="version" src="https://github.com/paraspell/xcm-sdk/assets/55763425/9ed74ebe-9b29-4efd-8e3e-7467ac4caed6" />
51
+ </p>
52
+ </div>
package/dist/index.cjs ADDED
@@ -0,0 +1,221 @@
1
+ 'use strict';
2
+
3
+ function _arrayLikeToArray(r, a) {
4
+ (null == a || a > r.length) && (a = r.length);
5
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
6
+ return n;
7
+ }
8
+ function _arrayWithoutHoles(r) {
9
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
10
+ }
11
+ function _createForOfIteratorHelper(r, e) {
12
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
13
+ if (!t) {
14
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
15
+ t && (r = t);
16
+ var n = 0,
17
+ F = function () {};
18
+ return {
19
+ s: F,
20
+ n: function () {
21
+ return n >= r.length ? {
22
+ done: true
23
+ } : {
24
+ done: false,
25
+ value: r[n++]
26
+ };
27
+ },
28
+ e: function (r) {
29
+ throw r;
30
+ },
31
+ f: F
32
+ };
33
+ }
34
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
35
+ }
36
+ var o,
37
+ a = true,
38
+ u = false;
39
+ return {
40
+ s: function () {
41
+ t = t.call(r);
42
+ },
43
+ n: function () {
44
+ var r = t.next();
45
+ return a = r.done, r;
46
+ },
47
+ e: function (r) {
48
+ u = true, o = r;
49
+ },
50
+ f: function () {
51
+ try {
52
+ a || null == t.return || t.return();
53
+ } finally {
54
+ if (u) throw o;
55
+ }
56
+ }
57
+ };
58
+ }
59
+ function _iterableToArray(r) {
60
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
61
+ }
62
+ function _nonIterableSpread() {
63
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
+ }
65
+ function _toConsumableArray(r) {
66
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
67
+ }
68
+ function _typeof(o) {
69
+ "@babel/helpers - typeof";
70
+
71
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
72
+ return typeof o;
73
+ } : function (o) {
74
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
75
+ }, _typeof(o);
76
+ }
77
+ function _unsupportedIterableToArray(r, a) {
78
+ if (r) {
79
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
80
+ var t = {}.toString.call(r).slice(8, -1);
81
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Supported nodes excluding relay chains and Ethereum.
87
+ */
88
+ var NODE_NAMES_DOT_KSM = ['AssetHubPolkadot', 'Acala', 'Astar', 'BifrostPolkadot', 'Bitgreen', 'BridgeHubPolkadot', 'BridgeHubKusama', 'Centrifuge', 'ComposableFinance', 'Darwinia', 'Hydration', 'Interlay', 'Heima', 'Moonbeam', 'Parallel', 'AssetHubKusama', 'CoretimeKusama', 'CoretimePolkadot', 'Encointer', 'Altair', 'Amplitude', 'Bajun', 'Basilisk', 'BifrostKusama', 'Calamari', 'CrustShadow', 'Crab', 'Imbue', 'InvArchTinker', 'Karura', 'Kintsugi', 'Moonriver', 'ParallelHeiko', 'Picasso', 'Quartz', 'RobonomicsKusama', 'RobonomicsPolkadot', 'PeoplePolkadot', 'PeopleKusama', 'Shiden', 'Turing', 'Unique', 'Crust', 'Manta', 'Nodle', 'NeuroWeb', 'Pendulum', 'Zeitgeist', 'Collectives', 'Phala', 'Subsocial', 'KiltSpiritnet', 'Curio', 'Mythos', 'Peaq', 'Polimec'];
89
+ /**
90
+ * Supported nodes including Ethereum.
91
+ */
92
+ var NODE_NAMES = [].concat(NODE_NAMES_DOT_KSM, ['Ethereum']);
93
+ /**
94
+ * Supported nodes including relay chains and Ethereum.
95
+ */
96
+ var NODES_WITH_RELAY_CHAINS = [].concat(_toConsumableArray(NODE_NAMES), ['Polkadot', 'Kusama']);
97
+ /**
98
+ * Supported nodes including relay chains and excluding Ethereum.
99
+ */
100
+ var NODES_WITH_RELAY_CHAINS_DOT_KSM = [].concat(NODE_NAMES_DOT_KSM, ['Polkadot', 'Kusama']);
101
+
102
+ var isTMultiLocation = function isTMultiLocation(value) {
103
+ return _typeof(value) === 'object' && value !== null && 'parents' in value && 'interior' in value;
104
+ };
105
+
106
+ exports.Parents = void 0;
107
+ (function (Parents) {
108
+ Parents[Parents["ZERO"] = 0] = "ZERO";
109
+ Parents[Parents["ONE"] = 1] = "ONE";
110
+ Parents[Parents["TWO"] = 2] = "TWO";
111
+ })(exports.Parents || (exports.Parents = {}));
112
+
113
+ var isPrimitive = function isPrimitive(obj) {
114
+ return obj !== Object(obj);
115
+ };
116
+ var _deepEqual = function deepEqual(obj1, obj2) {
117
+ if (obj1 === obj2) return true;
118
+ if (isPrimitive(obj1) && isPrimitive(obj2)) return obj1 === obj2;
119
+ if (_typeof(obj1) !== 'object' || obj1 === null || _typeof(obj2) !== 'object' || obj2 === null) {
120
+ return false;
121
+ }
122
+ if (Array.isArray(obj1) !== Array.isArray(obj2)) {
123
+ return false;
124
+ }
125
+ var obj1Keys = Object.keys(obj1).map(function (key) {
126
+ return key.toLowerCase();
127
+ });
128
+ var obj2Keys = Object.keys(obj2).map(function (key) {
129
+ return key.toLowerCase();
130
+ });
131
+ if (obj1Keys.length !== obj2Keys.length) return false;
132
+ var _iterator = _createForOfIteratorHelper(obj1Keys),
133
+ _step;
134
+ try {
135
+ var _loop = function _loop() {
136
+ var key = _step.value;
137
+ var keyInObj2 = obj2Keys.find(function (k) {
138
+ return k === key;
139
+ });
140
+ if (!keyInObj2) return {
141
+ v: false
142
+ };
143
+ var obj1Value = obj1[Object.keys(obj1).find(function (k) {
144
+ return k.toLowerCase() === key;
145
+ })];
146
+ var obj2Value = obj2[Object.keys(obj2).find(function (k) {
147
+ return k.toLowerCase() === key;
148
+ })];
149
+ if (!_deepEqual(obj1Value, obj2Value)) return {
150
+ v: false
151
+ };
152
+ },
153
+ _ret;
154
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
155
+ _ret = _loop();
156
+ if (_ret) return _ret.v;
157
+ }
158
+ } catch (err) {
159
+ _iterator.e(err);
160
+ } finally {
161
+ _iterator.f();
162
+ }
163
+ return true;
164
+ };
165
+
166
+ var flattenJunctions = function flattenJunctions(junctions) {
167
+ if (junctions.Here !== undefined) {
168
+ return [];
169
+ }
170
+ var result = [];
171
+ if (junctions.X1) {
172
+ if (Array.isArray(junctions.X1)) {
173
+ result.push.apply(result, _toConsumableArray(junctions.X1));
174
+ } else {
175
+ result.push(junctions.X1);
176
+ }
177
+ }
178
+ if (junctions.X2) result.push.apply(result, _toConsumableArray(junctions.X2));
179
+ if (junctions.X3) result.push.apply(result, _toConsumableArray(junctions.X3));
180
+ if (junctions.X4) result.push.apply(result, _toConsumableArray(junctions.X4));
181
+ if (junctions.X5) result.push.apply(result, _toConsumableArray(junctions.X5));
182
+ if (junctions.X6) result.push.apply(result, _toConsumableArray(junctions.X6));
183
+ if (junctions.X7) result.push.apply(result, _toConsumableArray(junctions.X7));
184
+ if (junctions.X8) result.push.apply(result, _toConsumableArray(junctions.X8));
185
+ return result;
186
+ };
187
+
188
+ var hasJunction = function hasJunction(multiLocation, junctionType, junctionValue) {
189
+ if (multiLocation.interior === 'Here') {
190
+ return false;
191
+ }
192
+ var allJunctions = flattenJunctions(multiLocation.interior);
193
+ return allJunctions.some(function (junction) {
194
+ var keys = Object.keys(junction);
195
+ if (keys.length !== 1) {
196
+ return false;
197
+ }
198
+ var key = keys[0];
199
+ if (key !== junctionType) {
200
+ return false;
201
+ }
202
+ if (junctionValue === undefined) {
203
+ return true;
204
+ }
205
+ var jv = junction[key];
206
+ try {
207
+ return JSON.stringify(jv) === JSON.stringify(junctionValue);
208
+ } catch (_unused) {
209
+ return jv === junctionValue;
210
+ }
211
+ });
212
+ };
213
+
214
+ exports.NODES_WITH_RELAY_CHAINS = NODES_WITH_RELAY_CHAINS;
215
+ exports.NODES_WITH_RELAY_CHAINS_DOT_KSM = NODES_WITH_RELAY_CHAINS_DOT_KSM;
216
+ exports.NODE_NAMES = NODE_NAMES;
217
+ exports.NODE_NAMES_DOT_KSM = NODE_NAMES_DOT_KSM;
218
+ exports.deepEqual = _deepEqual;
219
+ exports.hasJunction = hasJunction;
220
+ exports.isPrimitive = isPrimitive;
221
+ exports.isTMultiLocation = isTMultiLocation;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Supported nodes excluding relay chains and Ethereum.
3
+ */
4
+ declare const NODE_NAMES_DOT_KSM: readonly ["AssetHubPolkadot", "Acala", "Astar", "BifrostPolkadot", "Bitgreen", "BridgeHubPolkadot", "BridgeHubKusama", "Centrifuge", "ComposableFinance", "Darwinia", "Hydration", "Interlay", "Heima", "Moonbeam", "Parallel", "AssetHubKusama", "CoretimeKusama", "CoretimePolkadot", "Encointer", "Altair", "Amplitude", "Bajun", "Basilisk", "BifrostKusama", "Calamari", "CrustShadow", "Crab", "Imbue", "InvArchTinker", "Karura", "Kintsugi", "Moonriver", "ParallelHeiko", "Picasso", "Quartz", "RobonomicsKusama", "RobonomicsPolkadot", "PeoplePolkadot", "PeopleKusama", "Shiden", "Turing", "Unique", "Crust", "Manta", "Nodle", "NeuroWeb", "Pendulum", "Zeitgeist", "Collectives", "Phala", "Subsocial", "KiltSpiritnet", "Curio", "Mythos", "Peaq", "Polimec"];
5
+ /**
6
+ * Supported nodes including Ethereum.
7
+ */
8
+ declare const NODE_NAMES: readonly ["AssetHubPolkadot", "Acala", "Astar", "BifrostPolkadot", "Bitgreen", "BridgeHubPolkadot", "BridgeHubKusama", "Centrifuge", "ComposableFinance", "Darwinia", "Hydration", "Interlay", "Heima", "Moonbeam", "Parallel", "AssetHubKusama", "CoretimeKusama", "CoretimePolkadot", "Encointer", "Altair", "Amplitude", "Bajun", "Basilisk", "BifrostKusama", "Calamari", "CrustShadow", "Crab", "Imbue", "InvArchTinker", "Karura", "Kintsugi", "Moonriver", "ParallelHeiko", "Picasso", "Quartz", "RobonomicsKusama", "RobonomicsPolkadot", "PeoplePolkadot", "PeopleKusama", "Shiden", "Turing", "Unique", "Crust", "Manta", "Nodle", "NeuroWeb", "Pendulum", "Zeitgeist", "Collectives", "Phala", "Subsocial", "KiltSpiritnet", "Curio", "Mythos", "Peaq", "Polimec", "Ethereum"];
9
+ /**
10
+ * Supported nodes including relay chains and Ethereum.
11
+ */
12
+ declare const NODES_WITH_RELAY_CHAINS: readonly ["AssetHubPolkadot", "Acala", "Astar", "BifrostPolkadot", "Bitgreen", "BridgeHubPolkadot", "BridgeHubKusama", "Centrifuge", "ComposableFinance", "Darwinia", "Hydration", "Interlay", "Heima", "Moonbeam", "Parallel", "AssetHubKusama", "CoretimeKusama", "CoretimePolkadot", "Encointer", "Altair", "Amplitude", "Bajun", "Basilisk", "BifrostKusama", "Calamari", "CrustShadow", "Crab", "Imbue", "InvArchTinker", "Karura", "Kintsugi", "Moonriver", "ParallelHeiko", "Picasso", "Quartz", "RobonomicsKusama", "RobonomicsPolkadot", "PeoplePolkadot", "PeopleKusama", "Shiden", "Turing", "Unique", "Crust", "Manta", "Nodle", "NeuroWeb", "Pendulum", "Zeitgeist", "Collectives", "Phala", "Subsocial", "KiltSpiritnet", "Curio", "Mythos", "Peaq", "Polimec", "Ethereum", "Polkadot", "Kusama"];
13
+ /**
14
+ * Supported nodes including relay chains and excluding Ethereum.
15
+ */
16
+ declare const NODES_WITH_RELAY_CHAINS_DOT_KSM: readonly ["AssetHubPolkadot", "Acala", "Astar", "BifrostPolkadot", "Bitgreen", "BridgeHubPolkadot", "BridgeHubKusama", "Centrifuge", "ComposableFinance", "Darwinia", "Hydration", "Interlay", "Heima", "Moonbeam", "Parallel", "AssetHubKusama", "CoretimeKusama", "CoretimePolkadot", "Encointer", "Altair", "Amplitude", "Bajun", "Basilisk", "BifrostKusama", "Calamari", "CrustShadow", "Crab", "Imbue", "InvArchTinker", "Karura", "Kintsugi", "Moonriver", "ParallelHeiko", "Picasso", "Quartz", "RobonomicsKusama", "RobonomicsPolkadot", "PeoplePolkadot", "PeopleKusama", "Shiden", "Turing", "Unique", "Crust", "Manta", "Nodle", "NeuroWeb", "Pendulum", "Zeitgeist", "Collectives", "Phala", "Subsocial", "KiltSpiritnet", "Curio", "Mythos", "Peaq", "Polimec", "Polkadot", "Kusama"];
17
+
18
+ declare enum Parents {
19
+ ZERO = 0,
20
+ ONE = 1,
21
+ TWO = 2
22
+ }
23
+ type TJunctionType = 'Parachain' | 'AccountId32' | 'AccountIndex64' | 'AccountKey20' | 'PalletInstance' | 'GeneralIndex' | 'GeneralKey' | 'OnlyChild' | 'Plurality' | 'GlobalConsensus';
24
+ type TNetworkId = string | null;
25
+ type TBodyId = string | null;
26
+ type TBodyPart = string | null;
27
+ type TStringOrNumber = string | number;
28
+ type TStringOrNumberOrBigInt = TStringOrNumber | bigint;
29
+ type THexString = string;
30
+ type TJunctionParachain = {
31
+ Parachain: TStringOrNumberOrBigInt | undefined;
32
+ };
33
+ type TJunctionAccountId32 = {
34
+ AccountId32: {
35
+ network?: TNetworkId;
36
+ id: THexString;
37
+ };
38
+ };
39
+ type TJunctionAccountIndex64 = {
40
+ AccountIndex64: {
41
+ network: TNetworkId;
42
+ index: TStringOrNumberOrBigInt;
43
+ };
44
+ };
45
+ type TJunctionAccountKey20 = {
46
+ AccountKey20: {
47
+ network?: TNetworkId;
48
+ key: THexString;
49
+ };
50
+ };
51
+ type TJunctionPalletInstance = {
52
+ PalletInstance: TStringOrNumberOrBigInt;
53
+ };
54
+ type TJunctionGeneralIndex = {
55
+ GeneralIndex: TStringOrNumberOrBigInt;
56
+ };
57
+ type TJunctionGeneralKey = {
58
+ GeneralKey: {
59
+ length: TStringOrNumberOrBigInt;
60
+ data: THexString;
61
+ };
62
+ };
63
+ type TJunctionOnlyChild = {
64
+ OnlyChild: string;
65
+ };
66
+ type TJunctionPlurality = {
67
+ Plurality: {
68
+ id: TBodyId;
69
+ part: TBodyPart;
70
+ };
71
+ };
72
+ type TJunctionGlobalConsensus = {
73
+ GlobalConsensus: TNetworkId | object;
74
+ };
75
+ type TJunction = TJunctionParachain | TJunctionAccountId32 | TJunctionAccountIndex64 | TJunctionAccountKey20 | TJunctionPalletInstance | TJunctionGeneralIndex | TJunctionGeneralKey | TJunctionOnlyChild | TJunctionPlurality | TJunctionGlobalConsensus;
76
+ interface TJunctions {
77
+ Here?: null;
78
+ X1?: TJunction | TJunction[];
79
+ X2?: TJunction[];
80
+ X3?: TJunction[];
81
+ X4?: TJunction[];
82
+ X5?: TJunction[];
83
+ X6?: TJunction[];
84
+ X7?: TJunction[];
85
+ X8?: TJunction[];
86
+ }
87
+ interface TMultiLocation {
88
+ parents: TStringOrNumber;
89
+ interior: TJunctions | 'Here';
90
+ }
91
+
92
+ type TNode = (typeof NODE_NAMES)[number];
93
+ type TNodePolkadotKusama = Exclude<TNode, 'Ethereum'>;
94
+ type TNodeWithRelayChains = (typeof NODES_WITH_RELAY_CHAINS)[number];
95
+ type TNodeDotKsmWithRelayChains = Exclude<TNodeWithRelayChains, 'Ethereum'>;
96
+
97
+ type TEcosystemType = 'polkadot' | 'kusama' | 'ethereum';
98
+ type TRelayChainSymbol = 'DOT' | 'KSM';
99
+
100
+ declare const isTMultiLocation: (value: unknown) => value is TMultiLocation;
101
+
102
+ declare const isPrimitive: (obj: unknown) => boolean;
103
+ declare const deepEqual: (obj1: unknown, obj2: unknown) => boolean;
104
+
105
+ declare const hasJunction: (multiLocation: TMultiLocation, junctionType: TJunctionType, junctionValue?: unknown) => boolean;
106
+
107
+ export { NODES_WITH_RELAY_CHAINS, NODES_WITH_RELAY_CHAINS_DOT_KSM, NODE_NAMES, NODE_NAMES_DOT_KSM, Parents, type TEcosystemType, type TJunction, type TJunctionGeneralIndex, type TJunctionParachain, type TJunctionType, type TJunctions, type TMultiLocation, type TNode, type TNodeDotKsmWithRelayChains, type TNodePolkadotKusama, type TNodeWithRelayChains, type TRelayChainSymbol, deepEqual, hasJunction, isPrimitive, isTMultiLocation };
package/dist/index.mjs ADDED
@@ -0,0 +1,212 @@
1
+ function _arrayLikeToArray(r, a) {
2
+ (null == a || a > r.length) && (a = r.length);
3
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
4
+ return n;
5
+ }
6
+ function _arrayWithoutHoles(r) {
7
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
8
+ }
9
+ function _createForOfIteratorHelper(r, e) {
10
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
11
+ if (!t) {
12
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e) {
13
+ t && (r = t);
14
+ var n = 0,
15
+ F = function () {};
16
+ return {
17
+ s: F,
18
+ n: function () {
19
+ return n >= r.length ? {
20
+ done: true
21
+ } : {
22
+ done: false,
23
+ value: r[n++]
24
+ };
25
+ },
26
+ e: function (r) {
27
+ throw r;
28
+ },
29
+ f: F
30
+ };
31
+ }
32
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
33
+ }
34
+ var o,
35
+ a = true,
36
+ u = false;
37
+ return {
38
+ s: function () {
39
+ t = t.call(r);
40
+ },
41
+ n: function () {
42
+ var r = t.next();
43
+ return a = r.done, r;
44
+ },
45
+ e: function (r) {
46
+ u = true, o = r;
47
+ },
48
+ f: function () {
49
+ try {
50
+ a || null == t.return || t.return();
51
+ } finally {
52
+ if (u) throw o;
53
+ }
54
+ }
55
+ };
56
+ }
57
+ function _iterableToArray(r) {
58
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
59
+ }
60
+ function _nonIterableSpread() {
61
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
+ }
63
+ function _toConsumableArray(r) {
64
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
65
+ }
66
+ function _typeof(o) {
67
+ "@babel/helpers - typeof";
68
+
69
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
70
+ return typeof o;
71
+ } : function (o) {
72
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
73
+ }, _typeof(o);
74
+ }
75
+ function _unsupportedIterableToArray(r, a) {
76
+ if (r) {
77
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
78
+ var t = {}.toString.call(r).slice(8, -1);
79
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Supported nodes excluding relay chains and Ethereum.
85
+ */
86
+ var NODE_NAMES_DOT_KSM = ['AssetHubPolkadot', 'Acala', 'Astar', 'BifrostPolkadot', 'Bitgreen', 'BridgeHubPolkadot', 'BridgeHubKusama', 'Centrifuge', 'ComposableFinance', 'Darwinia', 'Hydration', 'Interlay', 'Heima', 'Moonbeam', 'Parallel', 'AssetHubKusama', 'CoretimeKusama', 'CoretimePolkadot', 'Encointer', 'Altair', 'Amplitude', 'Bajun', 'Basilisk', 'BifrostKusama', 'Calamari', 'CrustShadow', 'Crab', 'Imbue', 'InvArchTinker', 'Karura', 'Kintsugi', 'Moonriver', 'ParallelHeiko', 'Picasso', 'Quartz', 'RobonomicsKusama', 'RobonomicsPolkadot', 'PeoplePolkadot', 'PeopleKusama', 'Shiden', 'Turing', 'Unique', 'Crust', 'Manta', 'Nodle', 'NeuroWeb', 'Pendulum', 'Zeitgeist', 'Collectives', 'Phala', 'Subsocial', 'KiltSpiritnet', 'Curio', 'Mythos', 'Peaq', 'Polimec'];
87
+ /**
88
+ * Supported nodes including Ethereum.
89
+ */
90
+ var NODE_NAMES = [].concat(NODE_NAMES_DOT_KSM, ['Ethereum']);
91
+ /**
92
+ * Supported nodes including relay chains and Ethereum.
93
+ */
94
+ var NODES_WITH_RELAY_CHAINS = [].concat(_toConsumableArray(NODE_NAMES), ['Polkadot', 'Kusama']);
95
+ /**
96
+ * Supported nodes including relay chains and excluding Ethereum.
97
+ */
98
+ var NODES_WITH_RELAY_CHAINS_DOT_KSM = [].concat(NODE_NAMES_DOT_KSM, ['Polkadot', 'Kusama']);
99
+
100
+ var isTMultiLocation = function isTMultiLocation(value) {
101
+ return _typeof(value) === 'object' && value !== null && 'parents' in value && 'interior' in value;
102
+ };
103
+
104
+ var Parents;
105
+ (function (Parents) {
106
+ Parents[Parents["ZERO"] = 0] = "ZERO";
107
+ Parents[Parents["ONE"] = 1] = "ONE";
108
+ Parents[Parents["TWO"] = 2] = "TWO";
109
+ })(Parents || (Parents = {}));
110
+
111
+ var isPrimitive = function isPrimitive(obj) {
112
+ return obj !== Object(obj);
113
+ };
114
+ var _deepEqual = function deepEqual(obj1, obj2) {
115
+ if (obj1 === obj2) return true;
116
+ if (isPrimitive(obj1) && isPrimitive(obj2)) return obj1 === obj2;
117
+ if (_typeof(obj1) !== 'object' || obj1 === null || _typeof(obj2) !== 'object' || obj2 === null) {
118
+ return false;
119
+ }
120
+ if (Array.isArray(obj1) !== Array.isArray(obj2)) {
121
+ return false;
122
+ }
123
+ var obj1Keys = Object.keys(obj1).map(function (key) {
124
+ return key.toLowerCase();
125
+ });
126
+ var obj2Keys = Object.keys(obj2).map(function (key) {
127
+ return key.toLowerCase();
128
+ });
129
+ if (obj1Keys.length !== obj2Keys.length) return false;
130
+ var _iterator = _createForOfIteratorHelper(obj1Keys),
131
+ _step;
132
+ try {
133
+ var _loop = function _loop() {
134
+ var key = _step.value;
135
+ var keyInObj2 = obj2Keys.find(function (k) {
136
+ return k === key;
137
+ });
138
+ if (!keyInObj2) return {
139
+ v: false
140
+ };
141
+ var obj1Value = obj1[Object.keys(obj1).find(function (k) {
142
+ return k.toLowerCase() === key;
143
+ })];
144
+ var obj2Value = obj2[Object.keys(obj2).find(function (k) {
145
+ return k.toLowerCase() === key;
146
+ })];
147
+ if (!_deepEqual(obj1Value, obj2Value)) return {
148
+ v: false
149
+ };
150
+ },
151
+ _ret;
152
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
153
+ _ret = _loop();
154
+ if (_ret) return _ret.v;
155
+ }
156
+ } catch (err) {
157
+ _iterator.e(err);
158
+ } finally {
159
+ _iterator.f();
160
+ }
161
+ return true;
162
+ };
163
+
164
+ var flattenJunctions = function flattenJunctions(junctions) {
165
+ if (junctions.Here !== undefined) {
166
+ return [];
167
+ }
168
+ var result = [];
169
+ if (junctions.X1) {
170
+ if (Array.isArray(junctions.X1)) {
171
+ result.push.apply(result, _toConsumableArray(junctions.X1));
172
+ } else {
173
+ result.push(junctions.X1);
174
+ }
175
+ }
176
+ if (junctions.X2) result.push.apply(result, _toConsumableArray(junctions.X2));
177
+ if (junctions.X3) result.push.apply(result, _toConsumableArray(junctions.X3));
178
+ if (junctions.X4) result.push.apply(result, _toConsumableArray(junctions.X4));
179
+ if (junctions.X5) result.push.apply(result, _toConsumableArray(junctions.X5));
180
+ if (junctions.X6) result.push.apply(result, _toConsumableArray(junctions.X6));
181
+ if (junctions.X7) result.push.apply(result, _toConsumableArray(junctions.X7));
182
+ if (junctions.X8) result.push.apply(result, _toConsumableArray(junctions.X8));
183
+ return result;
184
+ };
185
+
186
+ var hasJunction = function hasJunction(multiLocation, junctionType, junctionValue) {
187
+ if (multiLocation.interior === 'Here') {
188
+ return false;
189
+ }
190
+ var allJunctions = flattenJunctions(multiLocation.interior);
191
+ return allJunctions.some(function (junction) {
192
+ var keys = Object.keys(junction);
193
+ if (keys.length !== 1) {
194
+ return false;
195
+ }
196
+ var key = keys[0];
197
+ if (key !== junctionType) {
198
+ return false;
199
+ }
200
+ if (junctionValue === undefined) {
201
+ return true;
202
+ }
203
+ var jv = junction[key];
204
+ try {
205
+ return JSON.stringify(jv) === JSON.stringify(junctionValue);
206
+ } catch (_unused) {
207
+ return jv === junctionValue;
208
+ }
209
+ });
210
+ };
211
+
212
+ export { NODES_WITH_RELAY_CHAINS, NODES_WITH_RELAY_CHAINS_DOT_KSM, NODE_NAMES, NODE_NAMES_DOT_KSM, Parents, _deepEqual as deepEqual, hasJunction, isPrimitive, isTMultiLocation };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@paraspell/sdk-common",
3
+ "version": "8.9.0",
4
+ "description": "SDK common code for ParaSpell XCM/XCMP tool for developers",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/paraspell/xcm-tools.git",
8
+ "directory": "packages/sdk-common"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
16
+ "require": "./dist/index.cjs"
17
+ }
18
+ },
19
+ "main": "dist/index.cjs",
20
+ "module": "dist/index.mjs",
21
+ "types": "dist/index.d.ts",
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "dependencies": {},
26
+ "devDependencies": {
27
+ "@babel/plugin-syntax-import-attributes": "^7.26.0",
28
+ "@babel/preset-env": "^7.26.9",
29
+ "@codecov/rollup-plugin": "^1.9.0",
30
+ "@polkadot/api": "^15.7.1",
31
+ "@polkadot/types": "^15.7.1",
32
+ "@rollup/plugin-babel": "^6.0.4",
33
+ "@rollup/plugin-json": "^6.1.0",
34
+ "@rollup/plugin-typescript": "^12.1.2",
35
+ "@vitest/coverage-v8": "^3.0.7",
36
+ "dotenv": "^16.4.7",
37
+ "prettier": "^3.5.2",
38
+ "rollup": "^4.34.8",
39
+ "rollup-plugin-dts": "^6.1.1"
40
+ },
41
+ "scripts": {
42
+ "compile": "tsc --noEmit",
43
+ "build": "rollup -c",
44
+ "lint:check": "eslint src",
45
+ "lint": "eslint --fix .",
46
+ "format:check": "prettier --check src",
47
+ "format:write": "prettier --write src",
48
+ "test": "vitest run",
49
+ "test:cov": "vitest run --coverage",
50
+ "test:watch": "vitest"
51
+ }
52
+ }