@paraspell/sdk 12.1.2 → 12.2.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 +4 -1
- package/dist/index.mjs +87 -16
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -309,9 +309,12 @@ const builder = await Builder({
|
|
|
309
309
|
.from(TSubstrateChain)
|
|
310
310
|
.to(TChain)
|
|
311
311
|
.currency({id: currencyID, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: currencySymbol, amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Native('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: Foreign('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {symbol: ForeignAbstract('currencySymbol'), amount: amount /*Use "ALL" to transfer everything*/} | {location: AssetLocationString, amount: amount /*Use "ALL" to transfer everything*/ | AssetLocationJson, amount: amount /*Use "ALL" to transfer everything*/} | {location: Override('Custom Location'), amount: amount /*Use "ALL" to transfer everything*/} | [{currencySelection, isFeeAsset?: true /* for example symbol: symbol or id: id, or Location: Location*/, amount: amount /*Use "ALL" to transfer everything*/}])
|
|
312
|
-
.address(address)
|
|
312
|
+
.address(address) //You can also use prederived accounts - //Alice, //Bob... //Alith, //Balthathar...
|
|
313
|
+
.senderAddress(address) //You can also use prederived accounts //Alice, //Bob... //Alith, //Balthathar...
|
|
313
314
|
|
|
314
315
|
const tx = await builder.build()
|
|
316
|
+
//Or if you use prederived account as senderAddress:
|
|
317
|
+
//await builder.signAndSubmit()
|
|
315
318
|
|
|
316
319
|
//Disconnect API after TX
|
|
317
320
|
await builder.disconnect()
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { NumberFormatError, isConfig, InvalidAddressError, BatchMode, findNativeAssetInfoOrThrow, getChainProviders, MissingChainApiError, Parents, Version, findAssetInfoOrThrow, computeFeeFromDryRun, hasXcmPaymentApiSupport, replaceBigInt, getAssetsObject, RuntimeApiUnavailableError, wrapTxBypass, assertHasLocation, localizeLocation, isAssetXcEqual, RELAY_LOCATION, getRelayChainOf, padValueBy, isRelayChain, isAssetEqual, createChainClient as createChainClient$1, getBalance as getBalance$1, claimAssets as claimAssets$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, transferMoonbeamEvm, validateAddress, transferMoonbeamToEth, Builder as Builder$1, handleSwapExecuteTransfer as handleSwapExecuteTransfer$1, getParaEthTransferFees as getParaEthTransferFees$1, getBridgeStatus as getBridgeStatus$1, getXcmFee as getXcmFee$1, send as send$1, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1, getOriginXcmFee as getOriginXcmFee$1 } from '@paraspell/sdk-core';
|
|
1
|
+
import { getEvmPrivateKeyHex, NumberFormatError, isConfig, InvalidAddressError, BatchMode, findNativeAssetInfoOrThrow, getChainProviders, MissingChainApiError, Parents, Version, findAssetInfoOrThrow, computeFeeFromDryRun, hasXcmPaymentApiSupport, replaceBigInt, getAssetsObject, RuntimeApiUnavailableError, wrapTxBypass, assertHasLocation, localizeLocation, isAssetXcEqual, RELAY_LOCATION, getRelayChainOf, padValueBy, isRelayChain, isAssetEqual, createChainClient as createChainClient$1, getBalance as getBalance$1, claimAssets as claimAssets$1, Foreign, ForeignAbstract, Native, Override, findAssetInfo, getAllAssetsSymbols, getAssetDecimals, getAssetId, getAssets, getExistentialDeposit, getNativeAssetSymbol, getNativeAssets, getOtherAssets, getRelayChainSymbol, getSupportedAssets, getTChain, hasSupportForAsset, isChainEvm, convertSs58 as convertSs58$1, transferMoonbeamEvm, validateAddress, transferMoonbeamToEth, Builder as Builder$1, handleSwapExecuteTransfer as handleSwapExecuteTransfer$1, getParaEthTransferFees as getParaEthTransferFees$1, getBridgeStatus as getBridgeStatus$1, getXcmFee as getXcmFee$1, send as send$1, dryRun as dryRun$1, dryRunOrigin as dryRunOrigin$1, getOriginXcmFee as getOriginXcmFee$1 } from '@paraspell/sdk-core';
|
|
2
2
|
export * from '@paraspell/sdk-core';
|
|
3
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
4
|
+
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
5
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';
|
|
6
|
+
import { sr25519CreateDerive } from '@polkadot-labs/hdkd';
|
|
7
|
+
import { entropyToMiniSecret, mnemonicToEntropy, DEV_PHRASE } from '@polkadot-labs/hdkd-helpers';
|
|
8
|
+
import { AccountId, Binary, FixedSizeBinary, getSs58AddressInfo, createClient } from 'polkadot-api';
|
|
9
|
+
import { getPolkadotSigner } from 'polkadot-api/signer';
|
|
3
10
|
import { blake2b } from '@noble/hashes/blake2.js';
|
|
4
|
-
import { bytesToHex } from '@noble/hashes/utils.js';
|
|
5
11
|
import { withLegacy } from '@polkadot-api/legacy-provider';
|
|
6
|
-
import { Binary, FixedSizeBinary, getSs58AddressInfo, AccountId, createClient } from 'polkadot-api';
|
|
7
12
|
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat';
|
|
8
13
|
import { getWsProvider } from 'polkadot-api/ws-provider';
|
|
9
14
|
import { isAddress } from 'viem';
|
|
@@ -313,6 +318,51 @@ function _unsupportedIterableToArray(r, a) {
|
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
320
|
|
|
321
|
+
var signEcdsa = function signEcdsa(input, privateKey) {
|
|
322
|
+
var signature = secp256k1.sign(keccak_256(input), privateKey, {
|
|
323
|
+
prehash: false,
|
|
324
|
+
format: 'recovered'
|
|
325
|
+
});
|
|
326
|
+
return Uint8Array.from([].concat(_toConsumableArray(signature.slice(1)), [signature[0]]));
|
|
327
|
+
};
|
|
328
|
+
var createSr25519Keypair = function createSr25519Keypair(path) {
|
|
329
|
+
var miniSecret = entropyToMiniSecret(mnemonicToEntropy(DEV_PHRASE));
|
|
330
|
+
var derive = sr25519CreateDerive(miniSecret);
|
|
331
|
+
return derive(path);
|
|
332
|
+
};
|
|
333
|
+
var createSr25519Signer = function createSr25519Signer(path) {
|
|
334
|
+
var keyPair = createSr25519Keypair(path);
|
|
335
|
+
return getPolkadotSigner(keyPair.publicKey, 'Sr25519', keyPair.sign);
|
|
336
|
+
};
|
|
337
|
+
var resolveEcdsaAddress = function resolveEcdsaAddress(privateKey) {
|
|
338
|
+
return keccak_256(secp256k1.getPublicKey(privateKey, false).slice(1)).slice(-20);
|
|
339
|
+
};
|
|
340
|
+
var createEcdsaSigner = function createEcdsaSigner(privateKey) {
|
|
341
|
+
var publicAddress = resolveEcdsaAddress(privateKey);
|
|
342
|
+
return getPolkadotSigner(publicAddress, 'Ecdsa', function (input) {
|
|
343
|
+
return signEcdsa(input, privateKey);
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
var getEvmPrivateKey = function getEvmPrivateKey(path) {
|
|
347
|
+
var pkHex = getEvmPrivateKeyHex(path);
|
|
348
|
+
if (pkHex) return hexToBytes(pkHex.slice(2));
|
|
349
|
+
return undefined;
|
|
350
|
+
};
|
|
351
|
+
var createDevSigner = function createDevSigner(path) {
|
|
352
|
+
var evmPrivateKey = getEvmPrivateKey(path);
|
|
353
|
+
if (evmPrivateKey) return createEcdsaSigner(evmPrivateKey);
|
|
354
|
+
return createSr25519Signer(path);
|
|
355
|
+
};
|
|
356
|
+
var deriveAddress = function deriveAddress(path) {
|
|
357
|
+
var evmPrivateKey = getEvmPrivateKey(path);
|
|
358
|
+
if (evmPrivateKey) {
|
|
359
|
+
var address = resolveEcdsaAddress(evmPrivateKey);
|
|
360
|
+
return "0x".concat(bytesToHex(address));
|
|
361
|
+
}
|
|
362
|
+
var keyPair = createSr25519Keypair(path);
|
|
363
|
+
return AccountId().dec(keyPair.publicKey);
|
|
364
|
+
};
|
|
365
|
+
|
|
316
366
|
var LEGACY_CHAINS = ['Interlay', 'CrustShadow', 'Kintsugi', 'RobonomicsPolkadot', 'Pendulum'];
|
|
317
367
|
// Cache settings
|
|
318
368
|
var DEFAULT_TTL_MS = 60000; // 1 minute
|
|
@@ -1103,13 +1153,12 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1103
1153
|
key: "getFromRpc",
|
|
1104
1154
|
value: function () {
|
|
1105
1155
|
var _getFromRpc = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(module, method, key) {
|
|
1106
|
-
var
|
|
1156
|
+
var value;
|
|
1107
1157
|
return _regenerator().w(function (_context7) {
|
|
1108
1158
|
while (1) switch (_context7.n) {
|
|
1109
1159
|
case 0:
|
|
1110
|
-
toSS58 = AccountId().dec;
|
|
1111
1160
|
_context7.n = 1;
|
|
1112
|
-
return this.api._request("".concat(module, "_").concat(method), [module === 'system' && isHex(key) && !isAddress(key) ?
|
|
1161
|
+
return this.api._request("".concat(module, "_").concat(method), [module === 'system' && isHex(key) && !isAddress(key) ? AccountId().dec(key) : key]);
|
|
1113
1162
|
case 1:
|
|
1114
1163
|
value = _context7.v;
|
|
1115
1164
|
return _context7.a(2, isHex(value) ? value : '0x' + value.toString(16).padStart(8, '0'));
|
|
@@ -1722,9 +1771,9 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1722
1771
|
return event.type === 'Tokens' && event.value.type === 'Deposited';
|
|
1723
1772
|
}) : undefined;
|
|
1724
1773
|
processedAssetsAmount = chain === 'AssetHubPolkadot' && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== 'DOT' ? processAssetsDepositedEvents(emitted, amount, 'Assets', 'Deposited', true) : (_processAssetsDeposit = processAssetsDepositedEvents(emitted, amount, 'Balances', 'Minted', false)) !== null && _processAssetsDeposit !== void 0 ? _processAssetsDeposit : processAssetsDepositedEvents(emitted, amount, 'Balances', 'Issued', false);
|
|
1725
|
-
feeEvent = (_ref13 = (_ref14 = (_ref15 = (_ref16 = (_ref17 = feeAssetFeeEvent !== null && feeAssetFeeEvent !== void 0 ? feeAssetFeeEvent :
|
|
1726
|
-
|
|
1727
|
-
processedAssetsAmount !== undefined ? {
|
|
1774
|
+
feeEvent = (_ref13 = (_ref14 = (_ref15 = (_ref16 = (_ref17 = feeAssetFeeEvent !== null && feeAssetFeeEvent !== void 0 ? feeAssetFeeEvent : chain === 'Mythos' ? reversedEvents.find(function (event) {
|
|
1775
|
+
return event.type === 'Balances' && event.value.type === 'Issued';
|
|
1776
|
+
}) : undefined) !== null && _ref17 !== void 0 ? _ref17 : processedAssetsAmount !== undefined ? {
|
|
1728
1777
|
type: 'Assets',
|
|
1729
1778
|
value: {
|
|
1730
1779
|
type: 'Deposited',
|
|
@@ -1732,13 +1781,7 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1732
1781
|
amount: processedAssetsAmount
|
|
1733
1782
|
}
|
|
1734
1783
|
}
|
|
1735
|
-
} : undefined) !== null &&
|
|
1736
|
-
//
|
|
1737
|
-
chain === 'Mythos' ? reversedEvents.find(function (event) {
|
|
1738
|
-
return event.type === 'Balances' && event.value.type === 'Issued';
|
|
1739
|
-
}) : undefined) !== null && _ref16 !== void 0 ? _ref16 :
|
|
1740
|
-
//
|
|
1741
|
-
origin === 'Mythos' || chain === 'AssetHubPolkadot' && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== 'DOT' ? reversedEvents.find(function (event) {
|
|
1784
|
+
} : undefined) !== null && _ref16 !== void 0 ? _ref16 : origin === 'Mythos' || chain === 'AssetHubPolkadot' && (asset === null || asset === void 0 ? void 0 : asset.symbol) !== 'DOT' ? reversedEvents.find(function (event) {
|
|
1742
1785
|
return event.type === 'AssetConversion' && event.value.type === 'SwapCreditExecuted';
|
|
1743
1786
|
}) : undefined) !== null && _ref15 !== void 0 ? _ref15 :
|
|
1744
1787
|
// Prefer to Minted event
|
|
@@ -1836,6 +1879,34 @@ var PapiApi = /*#__PURE__*/function () {
|
|
|
1836
1879
|
}
|
|
1837
1880
|
return Promise.resolve();
|
|
1838
1881
|
}
|
|
1882
|
+
}, {
|
|
1883
|
+
key: "deriveAddress",
|
|
1884
|
+
value: function deriveAddress$1(path) {
|
|
1885
|
+
return deriveAddress(path);
|
|
1886
|
+
}
|
|
1887
|
+
}, {
|
|
1888
|
+
key: "signAndSubmit",
|
|
1889
|
+
value: function () {
|
|
1890
|
+
var _signAndSubmit = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee17(tx, path) {
|
|
1891
|
+
var signer, _yield$tx$signAndSubm, txHash;
|
|
1892
|
+
return _regenerator().w(function (_context17) {
|
|
1893
|
+
while (1) switch (_context17.n) {
|
|
1894
|
+
case 0:
|
|
1895
|
+
signer = createDevSigner(path);
|
|
1896
|
+
_context17.n = 1;
|
|
1897
|
+
return tx.signAndSubmit(signer);
|
|
1898
|
+
case 1:
|
|
1899
|
+
_yield$tx$signAndSubm = _context17.v;
|
|
1900
|
+
txHash = _yield$tx$signAndSubm.txHash;
|
|
1901
|
+
return _context17.a(2, txHash);
|
|
1902
|
+
}
|
|
1903
|
+
}, _callee17);
|
|
1904
|
+
}));
|
|
1905
|
+
function signAndSubmit(_x26, _x27) {
|
|
1906
|
+
return _signAndSubmit.apply(this, arguments);
|
|
1907
|
+
}
|
|
1908
|
+
return signAndSubmit;
|
|
1909
|
+
}()
|
|
1839
1910
|
}]);
|
|
1840
1911
|
}();
|
|
1841
1912
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paraspell/sdk",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.2.0",
|
|
4
4
|
"description": "SDK for ParaSpell XCM/XCMP tool for developers",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,8 +25,10 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@noble/hashes": "^2.0.1",
|
|
27
27
|
"@polkadot-api/legacy-provider": "^0.3.6",
|
|
28
|
+
"@polkadot-labs/hdkd": "^0.0.26",
|
|
29
|
+
"@polkadot-labs/hdkd-helpers": "^0.0.27",
|
|
28
30
|
"viem": "2.40.3",
|
|
29
|
-
"@paraspell/sdk-core": "12.
|
|
31
|
+
"@paraspell/sdk-core": "12.2.0"
|
|
30
32
|
},
|
|
31
33
|
"peerDependencies": {
|
|
32
34
|
"polkadot-api": ">= 1.23.1 < 2"
|
|
@@ -36,8 +38,6 @@
|
|
|
36
38
|
"@babel/preset-env": "^7.28.5",
|
|
37
39
|
"@codecov/rollup-plugin": "^1.9.1",
|
|
38
40
|
"@noble/curves": "^2.0.1",
|
|
39
|
-
"@polkadot-labs/hdkd": "^0.0.26",
|
|
40
|
-
"@polkadot-labs/hdkd-helpers": "^0.0.27",
|
|
41
41
|
"@rollup/plugin-babel": "^6.1.0",
|
|
42
42
|
"@rollup/plugin-json": "^6.1.0",
|
|
43
43
|
"@rollup/plugin-typescript": "^12.3.0",
|