@talken/talkenkit 2.8.3 → 2.8.5
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/dist/{AbcCredentialManager-6FBGTSSM.js → AbcCredentialManager-WZBF3GHF.js} +1 -1
- package/dist/{abcWallet-7ZZXHG7O.js → abcWallet-EOHU5AIB.js} +2 -2
- package/dist/{chunk-SUYKWM5G.js → chunk-CUPPBGFC.js} +23 -14
- package/dist/{chunk-HX6JUKSS.js → chunk-WGSS57V6.js} +985 -212
- package/dist/config/networks.d.ts +12 -0
- package/dist/gasless/utils/revokeDelegation.d.ts +4 -3
- package/dist/index.css +13 -13
- package/dist/index.js +26 -20
- package/dist/utils/amount.d.ts +17 -0
- package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/ProviderError.d.ts +7 -0
- package/dist/wallets/walletConnectors/abcWallet/StorageService.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +13 -4
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +21 -17
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +3 -4
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +11 -7
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +22 -18
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +13 -4
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +22 -18
- package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.d.ts +18 -1
- package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.js +17 -6
- package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +17 -14
- package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +22 -19
- package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.d.ts +17 -3
- package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.js +14 -5
- package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.d.ts +27 -8
- package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.js +13 -4
- package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.d.ts +79 -0
- package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.js +32 -0
- package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.d.ts +37 -0
- package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.js +29 -0
- package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.d.ts +21 -0
- package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.js +18 -0
- package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.d.ts +10 -4
- package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.js +10 -2
- package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.d.ts +10 -4
- package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.js +13 -2
- package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/modules/walletscan.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.d.ts +13 -3
- package/dist/wallets/walletConnectors/abcWallet/api/modules/xrp.js +13 -2
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +23 -11
- package/dist/wallets/walletConnectors/abcWallet/constants.js +3 -1
- package/dist/wallets/walletConnectors/abcWallet/evmTxType.d.ts +20 -0
- package/dist/wallets/walletConnectors/abcWallet/evmTxType.js +8 -0
- package/dist/wallets/walletConnectors/abcWallet/index.js +45 -40
- package/dist/wallets/walletConnectors/abcWallet/sendFailure.d.ts +10 -0
- package/dist/wallets/walletConnectors/abcWallet/sendFailure.js +7 -0
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/types/api.types.d.ts +147 -2
- package/dist/wallets/walletConnectors/abcWallet/types/config.types.d.ts +4 -0
- package/dist/wallets/walletConnectors/abcWallet/types/error.types.d.ts +14 -1
- package/dist/wallets/walletConnectors/abcWallet/types/error.types.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/types.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/utils.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +6 -6
- package/dist/wallets/walletConnectors/{chunk-CXWASK7L.js → chunk-2M6E3YXU.js} +31 -19
- package/dist/wallets/walletConnectors/{chunk-URTS7ZIZ.js → chunk-365TL36N.js} +36 -31
- package/dist/wallets/walletConnectors/{chunk-7DLZKN46.js → chunk-4CKIGJZD.js} +8 -8
- package/dist/wallets/walletConnectors/{chunk-6FPKKAFI.js → chunk-5SRSGEZR.js} +2 -2
- package/dist/wallets/walletConnectors/{chunk-ZOBSRU6L.js → chunk-6MZWQBNQ.js} +28 -7
- package/dist/wallets/walletConnectors/chunk-6X2XITQP.js +71 -0
- package/dist/wallets/walletConnectors/{chunk-ZXG3X6PV.js → chunk-743DKBGG.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-DFG3BSSC.js +341 -0
- package/dist/wallets/walletConnectors/chunk-DKMR2ML5.js +163 -0
- package/dist/wallets/walletConnectors/{chunk-4BG6V5TZ.js → chunk-DRL2CDHT.js} +24 -22
- package/dist/wallets/walletConnectors/{chunk-S6XEM7RM.js → chunk-EGLT3GPM.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-VVXSRRXI.js → chunk-F4JUKZBB.js} +3 -3
- package/dist/wallets/walletConnectors/chunk-GAJ4FJTW.js +382 -0
- package/dist/wallets/walletConnectors/{chunk-4Y7YP4IR.js → chunk-GO6HUJTP.js} +51 -12
- package/dist/wallets/walletConnectors/{chunk-3NWM24MH.js → chunk-HMIFFMGK.js} +22 -8
- package/dist/wallets/walletConnectors/chunk-M4SNNQU2.js +56 -0
- package/dist/wallets/walletConnectors/{chunk-ANBOP6A6.js → chunk-MNGSJBPX.js} +31 -14
- package/dist/wallets/walletConnectors/chunk-OESFVVLA.js +38 -0
- package/dist/wallets/walletConnectors/{chunk-2LOET2LX.js → chunk-OMZSFUVN.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-L3EPZ4NZ.js → chunk-OTLPTGHO.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-XDNFWX2X.js → chunk-P64PMEPU.js} +2 -2
- package/dist/wallets/walletConnectors/{chunk-2LH53QET.js → chunk-PL56SINL.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-RSR35XOZ.js +206 -0
- package/dist/wallets/walletConnectors/{chunk-YNE2UX2Z.js → chunk-SORKIBWX.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-HM73RD2O.js → chunk-SUPFF4EQ.js} +44 -812
- package/dist/wallets/walletConnectors/{chunk-BUAWEYGV.js → chunk-TP4BDK7W.js} +5 -1
- package/dist/wallets/walletConnectors/{chunk-4DGLNUHL.js → chunk-TRFREYPH.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-FWX2HD26.js → chunk-UHVJ6AF6.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-NEMEHJ72.js → chunk-V6R6WDOQ.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-XGQUYXTL.js +1215 -0
- package/dist/wallets/walletConnectors/{chunk-3Z5DO42M.js → chunk-XPZCOEQL.js} +23 -14
- package/dist/wallets/walletConnectors/{chunk-YFNVHCMA.js → chunk-YPMD3ZHF.js} +33 -18
- package/dist/wallets/walletConnectors/chunk-Z66ETAKN.js +20 -0
- package/dist/wallets/walletConnectors/{chunk-M4YGDOD5.js → chunk-ZBI7MSWF.js} +5 -5
- package/dist/wallets/walletConnectors/chunk-ZWIAZOVB.js +58 -0
- package/dist/wallets/walletConnectors/index.js +73 -69
- package/package.json +1 -1
- package/dist/wallets/walletConnectors/chunk-2KHTFKPP.js +0 -186
- package/dist/wallets/walletConnectors/chunk-3QC567QK.js +0 -94
- package/dist/wallets/walletConnectors/chunk-4K2V7RCL.js +0 -96
- package/dist/wallets/walletConnectors/chunk-4V3HRM2R.js +0 -95
- package/dist/wallets/walletConnectors/chunk-5QYCHHVB.js +0 -98
- package/dist/wallets/walletConnectors/chunk-76M232IF.js +0 -101
- package/dist/wallets/walletConnectors/chunk-7IBMHOYD.js +0 -102
- package/dist/wallets/walletConnectors/chunk-A2DZALFI.js +0 -108
- package/dist/wallets/walletConnectors/chunk-BZPKBSWY.js +0 -66
- package/dist/wallets/walletConnectors/chunk-CEOJSQAI.js +0 -66
- package/dist/wallets/walletConnectors/chunk-CTAFZ5RQ.js +0 -71
- package/dist/wallets/walletConnectors/chunk-DHWJ3552.js +0 -93
- package/dist/wallets/walletConnectors/chunk-EJALZNAR.js +0 -101
- package/dist/wallets/walletConnectors/chunk-FE2BFYJB.js +0 -73
- package/dist/wallets/walletConnectors/chunk-FGYJTUYV.js +0 -94
- package/dist/wallets/walletConnectors/chunk-FVA6H2VF.js +0 -95
- package/dist/wallets/walletConnectors/chunk-GNF5CHDQ.js +0 -102
- package/dist/wallets/walletConnectors/chunk-GZPGNUNF.js +0 -94
- package/dist/wallets/walletConnectors/chunk-HALTGRQW.js +0 -87
- package/dist/wallets/walletConnectors/chunk-ICGK5DGY.js +0 -146
- package/dist/wallets/walletConnectors/chunk-IONL6LMJ.js +0 -71
- package/dist/wallets/walletConnectors/chunk-KNNHGFKJ.js +0 -98
- package/dist/wallets/walletConnectors/chunk-KQDFRZT4.js +0 -65
- package/dist/wallets/walletConnectors/chunk-KQROIRBW.js +0 -27
- package/dist/wallets/walletConnectors/chunk-LKNK2KKU.js +0 -76
- package/dist/wallets/walletConnectors/chunk-NM7YUGLV.js +0 -186
- package/dist/wallets/walletConnectors/chunk-PXL5G2PM.js +0 -96
- package/dist/wallets/walletConnectors/chunk-QB3QLNSL.js +0 -76
- package/dist/wallets/walletConnectors/chunk-QRU6XFHH.js +0 -110
- package/dist/wallets/walletConnectors/chunk-T6RB3SM7.js +0 -73
- package/dist/wallets/walletConnectors/chunk-TA4DDCKN.js +0 -96
- package/dist/wallets/walletConnectors/chunk-TWVKSPTP.js +0 -91
- package/dist/wallets/walletConnectors/chunk-TYJR3KGY.js +0 -46
- package/dist/wallets/walletConnectors/chunk-U5UPCM5V.js +0 -66
- package/dist/wallets/walletConnectors/chunk-V5LGED4F.js +0 -103
- package/dist/wallets/walletConnectors/chunk-WZMFQQ6R.js +0 -108
- package/dist/wallets/walletConnectors/chunk-XS6GJRRA.js +0 -98
- package/dist/wallets/walletConnectors/chunk-XSJUQHR7.js +0 -95
- package/dist/wallets/walletConnectors/chunk-XSX5EECZ.js +0 -96
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
ABC_WALLET_METADATA,
|
|
8
8
|
DEFAULT_TALKEN_API_CONFIG,
|
|
9
9
|
PIN_CONFIG,
|
|
10
|
+
SEND_REQUEST_TIMEOUT,
|
|
10
11
|
STORAGE_NS,
|
|
11
12
|
TALKEN_API_ENDPOINTS,
|
|
12
13
|
TOKEN_EXPIRY,
|
|
@@ -18,7 +19,7 @@ import {
|
|
|
18
19
|
remove,
|
|
19
20
|
set,
|
|
20
21
|
setJSON
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-CUPPBGFC.js";
|
|
22
23
|
|
|
23
24
|
// src/wallets/walletConnectors/abcWallet/abcWallet.ts
|
|
24
25
|
import { setTalkenApiClient as setTalkenApiClient2 } from "@talken/talkenkit";
|
|
@@ -943,6 +944,25 @@ function networkNameToChainKey(network) {
|
|
|
943
944
|
return network;
|
|
944
945
|
return CHAIN_ID_TO_KEY[chainId] ?? network;
|
|
945
946
|
}
|
|
947
|
+
function getNetworkType(network) {
|
|
948
|
+
const byParam = NETWORK_BY_PARAM[network];
|
|
949
|
+
if (byParam)
|
|
950
|
+
return byParam.type;
|
|
951
|
+
const nonEvmParam = Object.keys(NON_EVM_CHAIN_KEY).find(
|
|
952
|
+
(param) => NON_EVM_CHAIN_KEY[param] === network
|
|
953
|
+
);
|
|
954
|
+
if (nonEvmParam)
|
|
955
|
+
return NETWORK_BY_PARAM[nonEvmParam]?.type ?? "Non-EVM" /* NON_EVM */;
|
|
956
|
+
if (Object.values(CHAIN_ID_TO_KEY).includes(network))
|
|
957
|
+
return "EVM" /* EVM */;
|
|
958
|
+
return void 0;
|
|
959
|
+
}
|
|
960
|
+
function getEvmChainKey(network) {
|
|
961
|
+
const chainId = NETWORK_BY_PARAM[network]?.chainId;
|
|
962
|
+
if (chainId != null)
|
|
963
|
+
return CHAIN_ID_TO_KEY[chainId];
|
|
964
|
+
return Object.values(CHAIN_ID_TO_KEY).includes(network) ? network : void 0;
|
|
965
|
+
}
|
|
946
966
|
function networkToChainId(network) {
|
|
947
967
|
return NETWORK_BY_PARAM[network]?.chainId;
|
|
948
968
|
}
|
|
@@ -1504,6 +1524,591 @@ import {
|
|
|
1504
1524
|
toHex,
|
|
1505
1525
|
toRlp
|
|
1506
1526
|
} from "viem";
|
|
1527
|
+
|
|
1528
|
+
// src/utils/amount.ts
|
|
1529
|
+
var MAX_DECIMALS = 255;
|
|
1530
|
+
var U64_MAX = BigInt("18446744073709551615");
|
|
1531
|
+
var ZERO = BigInt(0);
|
|
1532
|
+
var TEN = BigInt(10);
|
|
1533
|
+
var CANONICAL_DECIMAL = /^(0|[1-9]\d*)(\.\d+)?$/;
|
|
1534
|
+
var BASE_UNIT_INTEGER = /^(0|[1-9]\d*)$/;
|
|
1535
|
+
function validateAmount(amount) {
|
|
1536
|
+
if (typeof amount === "string") {
|
|
1537
|
+
if (!CANONICAL_DECIMAL.test(amount))
|
|
1538
|
+
throw new Error(
|
|
1539
|
+
"Token amount must be a plain decimal string (no sign, exponent or separators)"
|
|
1540
|
+
);
|
|
1541
|
+
if (!/[1-9]/.test(amount))
|
|
1542
|
+
throw new Error("Token amount must be finite and positive");
|
|
1543
|
+
return;
|
|
1544
|
+
}
|
|
1545
|
+
if (typeof amount !== "number" || !Number.isFinite(amount) || amount <= 0)
|
|
1546
|
+
throw new Error("Token amount must be finite and positive");
|
|
1547
|
+
}
|
|
1548
|
+
function isValidDecimals(decimals) {
|
|
1549
|
+
return decimals !== void 0 && Number.isInteger(decimals) && decimals >= 0 && decimals <= MAX_DECIMALS;
|
|
1550
|
+
}
|
|
1551
|
+
function assertDecimals(decimals) {
|
|
1552
|
+
if (!isValidDecimals(decimals))
|
|
1553
|
+
throw new Error("Token decimals are missing or invalid");
|
|
1554
|
+
}
|
|
1555
|
+
function splitAmount(amount) {
|
|
1556
|
+
const [coefficient, exponent = "0"] = String(amount).toLowerCase().split("e");
|
|
1557
|
+
const [whole, fraction = ""] = coefficient.split(".");
|
|
1558
|
+
return {
|
|
1559
|
+
digits: BigInt(`${whole}${fraction}`),
|
|
1560
|
+
fractionLength: fraction.length,
|
|
1561
|
+
exponent: Number(exponent)
|
|
1562
|
+
};
|
|
1563
|
+
}
|
|
1564
|
+
function toBaseUnits(amount, decimals) {
|
|
1565
|
+
validateAmount(amount);
|
|
1566
|
+
assertDecimals(decimals);
|
|
1567
|
+
const { digits, fractionLength, exponent } = splitAmount(amount);
|
|
1568
|
+
if (typeof amount === "string" && fractionLength > decimals)
|
|
1569
|
+
throw new Error(
|
|
1570
|
+
`Token amount exceeds decimal precision (${decimals} decimals)`
|
|
1571
|
+
);
|
|
1572
|
+
const scale = decimals + exponent - fractionLength;
|
|
1573
|
+
if (scale >= 0)
|
|
1574
|
+
return digits * TEN ** BigInt(scale);
|
|
1575
|
+
const divisor = TEN ** BigInt(-scale);
|
|
1576
|
+
if (digits % divisor !== ZERO)
|
|
1577
|
+
throw new Error(
|
|
1578
|
+
`Token amount exceeds decimal precision (${decimals} decimals)`
|
|
1579
|
+
);
|
|
1580
|
+
return digits / divisor;
|
|
1581
|
+
}
|
|
1582
|
+
function toDecimalAmount(baseUnits, decimals) {
|
|
1583
|
+
assertDecimals(decimals);
|
|
1584
|
+
if (typeof baseUnits === "string" && !BASE_UNIT_INTEGER.test(baseUnits))
|
|
1585
|
+
throw new Error("Base-unit amount must be a non-negative integer string");
|
|
1586
|
+
const value = BigInt(baseUnits);
|
|
1587
|
+
if (value <= ZERO)
|
|
1588
|
+
throw new Error("Token amount must be finite and positive");
|
|
1589
|
+
const unit = TEN ** BigInt(decimals);
|
|
1590
|
+
const whole = value / unit;
|
|
1591
|
+
const fraction = (value % unit).toString().padStart(decimals, "0").replace(/0+$/, "");
|
|
1592
|
+
return fraction ? `${whole}.${fraction}` : whole.toString();
|
|
1593
|
+
}
|
|
1594
|
+
function toSplRawAmount(amount, decimals) {
|
|
1595
|
+
validateAmount(amount);
|
|
1596
|
+
if (!isValidDecimals(decimals))
|
|
1597
|
+
throw new Error("SPL token decimals are missing or invalid");
|
|
1598
|
+
const raw = toBaseUnits(amount, decimals);
|
|
1599
|
+
if (raw > U64_MAX)
|
|
1600
|
+
throw new Error("Token amount is outside the SPL u64 range");
|
|
1601
|
+
return raw;
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
// src/wallets/walletConnectors/abcWallet/types/error.types.ts
|
|
1605
|
+
var AbcErrorCode = /* @__PURE__ */ ((AbcErrorCode3) => {
|
|
1606
|
+
AbcErrorCode3["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
|
|
1607
|
+
AbcErrorCode3["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
|
|
1608
|
+
AbcErrorCode3["WALLET_NOT_FOUND"] = "WALLET_NOT_FOUND";
|
|
1609
|
+
AbcErrorCode3["INVALID_PIN"] = "INVALID_PIN";
|
|
1610
|
+
AbcErrorCode3["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
1611
|
+
AbcErrorCode3["SIGNATURE_FAILED"] = "SIGNATURE_FAILED";
|
|
1612
|
+
AbcErrorCode3["USER_CANCELLED"] = "USER_CANCELLED";
|
|
1613
|
+
AbcErrorCode3["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
1614
|
+
return AbcErrorCode3;
|
|
1615
|
+
})(AbcErrorCode || {});
|
|
1616
|
+
var AbcError = class extends Error {
|
|
1617
|
+
constructor(code, message, details, statusCode) {
|
|
1618
|
+
super(message);
|
|
1619
|
+
this.name = "AbcError";
|
|
1620
|
+
this.code = code;
|
|
1621
|
+
this.details = details;
|
|
1622
|
+
this.statusCode = statusCode;
|
|
1623
|
+
}
|
|
1624
|
+
};
|
|
1625
|
+
var TalkenApiError = class extends Error {
|
|
1626
|
+
constructor(code, message, statusCode, details, outcome) {
|
|
1627
|
+
super(message);
|
|
1628
|
+
this.name = "TalkenApiError";
|
|
1629
|
+
this.code = code;
|
|
1630
|
+
this.statusCode = statusCode;
|
|
1631
|
+
this.details = details;
|
|
1632
|
+
if (outcome?.retryable !== void 0)
|
|
1633
|
+
this.retryable = outcome.retryable;
|
|
1634
|
+
if (outcome?.possibleTxHash !== void 0)
|
|
1635
|
+
this.possibleTxHash = outcome.possibleTxHash;
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
|
|
1639
|
+
// src/wallets/walletConnectors/abcWallet/types/config.types.ts
|
|
1640
|
+
var AbcStorageKey = /* @__PURE__ */ ((AbcStorageKey2) => {
|
|
1641
|
+
AbcStorageKey2["USER"] = "user";
|
|
1642
|
+
AbcStorageKey2["WALLET"] = "wallet";
|
|
1643
|
+
AbcStorageKey2["SOLANA_WALLET"] = "solana_wallet";
|
|
1644
|
+
AbcStorageKey2["BITCOIN_WALLET"] = "bitcoin_wallet";
|
|
1645
|
+
AbcStorageKey2["TRON_WALLET"] = "tron_wallet";
|
|
1646
|
+
AbcStorageKey2["XRPL_WALLET"] = "xrpl_wallet";
|
|
1647
|
+
AbcStorageKey2["ACCESS_TOKEN"] = "access_token";
|
|
1648
|
+
AbcStorageKey2["REFRESH_TOKEN"] = "refresh_token";
|
|
1649
|
+
AbcStorageKey2["EXPIRES_AT"] = "expires_at";
|
|
1650
|
+
AbcStorageKey2["AUTH_STATE"] = "auth_state";
|
|
1651
|
+
return AbcStorageKey2;
|
|
1652
|
+
})(AbcStorageKey || {});
|
|
1653
|
+
|
|
1654
|
+
// src/wallets/walletConnectors/abcWallet/api/modules/signBodies.ts
|
|
1655
|
+
function badRequest(message) {
|
|
1656
|
+
return new TalkenApiError("BAD_REQUEST", message, 400);
|
|
1657
|
+
}
|
|
1658
|
+
function compact(body) {
|
|
1659
|
+
return Object.fromEntries(
|
|
1660
|
+
Object.entries(body).filter(([, value]) => value != null)
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
function isRecord(value) {
|
|
1664
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1665
|
+
}
|
|
1666
|
+
function toDecimalString(value, field) {
|
|
1667
|
+
const text = typeof value === "string" ? value.trim() : String(value);
|
|
1668
|
+
if (!/^(0x[0-9a-fA-F]+|\d+)$/.test(text)) {
|
|
1669
|
+
throw badRequest(`${field} must be a decimal or 0x-hex integer`);
|
|
1670
|
+
}
|
|
1671
|
+
return BigInt(text).toString(10);
|
|
1672
|
+
}
|
|
1673
|
+
function toSignTxBody(params) {
|
|
1674
|
+
if (!params.network || !params.to) {
|
|
1675
|
+
throw badRequest("network and to are required");
|
|
1676
|
+
}
|
|
1677
|
+
return compact({
|
|
1678
|
+
chainKey: params.network,
|
|
1679
|
+
to: params.to,
|
|
1680
|
+
amountWei: toDecimalString(params.value || "0", "value"),
|
|
1681
|
+
data: params.data,
|
|
1682
|
+
nonce: params.nonce,
|
|
1683
|
+
gasLimit: params.gasLimit,
|
|
1684
|
+
gasPrice: params.gasPrice,
|
|
1685
|
+
maxFeePerGas: params.maxFeePerGas,
|
|
1686
|
+
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
1687
|
+
type: params.type,
|
|
1688
|
+
pin: params.pin,
|
|
1689
|
+
email: params.email
|
|
1690
|
+
});
|
|
1691
|
+
}
|
|
1692
|
+
function referencedTypeNames(types) {
|
|
1693
|
+
const names = /* @__PURE__ */ new Set();
|
|
1694
|
+
for (const fields of Object.values(types)) {
|
|
1695
|
+
if (!Array.isArray(fields))
|
|
1696
|
+
continue;
|
|
1697
|
+
for (const field of fields) {
|
|
1698
|
+
const type = isRecord(field) ? field.type : void 0;
|
|
1699
|
+
if (typeof type === "string")
|
|
1700
|
+
names.add(type.replace(/(\[\d*\])+$/, ""));
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
return names;
|
|
1704
|
+
}
|
|
1705
|
+
function inferPrimaryType(types) {
|
|
1706
|
+
const referenced = referencedTypeNames(types);
|
|
1707
|
+
const roots = Object.keys(types).filter(
|
|
1708
|
+
(name) => name !== "EIP712Domain" && !referenced.has(name)
|
|
1709
|
+
);
|
|
1710
|
+
if (roots.length !== 1) {
|
|
1711
|
+
throw badRequest(
|
|
1712
|
+
"typedData.primaryType is required when types has no single root struct"
|
|
1713
|
+
);
|
|
1714
|
+
}
|
|
1715
|
+
return roots[0];
|
|
1716
|
+
}
|
|
1717
|
+
function toSignTypedDataBody(params) {
|
|
1718
|
+
if (!params.network || !params.typedData) {
|
|
1719
|
+
throw badRequest("network and typedData are required");
|
|
1720
|
+
}
|
|
1721
|
+
let parsed = params.typedData;
|
|
1722
|
+
if (typeof parsed === "string") {
|
|
1723
|
+
try {
|
|
1724
|
+
parsed = JSON.parse(parsed);
|
|
1725
|
+
} catch {
|
|
1726
|
+
throw badRequest("typedData must be valid JSON");
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
if (!isRecord(parsed))
|
|
1730
|
+
throw badRequest("typedData must be a JSON object");
|
|
1731
|
+
const { domain, types, primaryType, message } = parsed;
|
|
1732
|
+
if (!isRecord(domain))
|
|
1733
|
+
throw badRequest("typedData.domain must be an object");
|
|
1734
|
+
if (!isRecord(types))
|
|
1735
|
+
throw badRequest("typedData.types must be an object");
|
|
1736
|
+
if (!isRecord(message)) {
|
|
1737
|
+
throw badRequest("typedData.message must be an object");
|
|
1738
|
+
}
|
|
1739
|
+
if (primaryType != null && (typeof primaryType !== "string" || primaryType.trim() === "")) {
|
|
1740
|
+
throw badRequest("typedData.primaryType must be a non-empty string");
|
|
1741
|
+
}
|
|
1742
|
+
return compact({
|
|
1743
|
+
chainKey: params.network,
|
|
1744
|
+
domain,
|
|
1745
|
+
types,
|
|
1746
|
+
primaryType: primaryType ?? inferPrimaryType(types),
|
|
1747
|
+
message,
|
|
1748
|
+
pin: params.pin,
|
|
1749
|
+
email: params.email
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
function toSignMessageBody(params) {
|
|
1753
|
+
return compact({
|
|
1754
|
+
chainKey: params.network,
|
|
1755
|
+
message: params.message,
|
|
1756
|
+
address: params.address,
|
|
1757
|
+
signaturePrefix: params.signaturePrefix,
|
|
1758
|
+
pin: params.pin,
|
|
1759
|
+
email: params.email
|
|
1760
|
+
});
|
|
1761
|
+
}
|
|
1762
|
+
function toSignAuthorizationBody(params) {
|
|
1763
|
+
const { authorization } = params;
|
|
1764
|
+
if (!authorization?.address || authorization.chainId == null || authorization.nonce == null) {
|
|
1765
|
+
throw badRequest(
|
|
1766
|
+
"authorization.chainId, authorization.address, authorization.nonce are required"
|
|
1767
|
+
);
|
|
1768
|
+
}
|
|
1769
|
+
return compact({
|
|
1770
|
+
chainKey: params.network,
|
|
1771
|
+
authorization: {
|
|
1772
|
+
chainId: Number(
|
|
1773
|
+
toDecimalString(authorization.chainId, "authorization.chainId")
|
|
1774
|
+
),
|
|
1775
|
+
address: authorization.address,
|
|
1776
|
+
nonce: toDecimalString(authorization.nonce, "authorization.nonce")
|
|
1777
|
+
},
|
|
1778
|
+
pin: params.pin,
|
|
1779
|
+
email: params.email
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
function toSignSolanaBody(params) {
|
|
1783
|
+
return compact({
|
|
1784
|
+
message: params.message,
|
|
1785
|
+
network: params.network,
|
|
1786
|
+
pin: params.pin,
|
|
1787
|
+
keyId: params.keyId,
|
|
1788
|
+
encryptedShare: params.encryptedShare,
|
|
1789
|
+
secretStore: params.secretStore
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
function toSignHashBody(params) {
|
|
1793
|
+
return compact({
|
|
1794
|
+
hash: params.hash,
|
|
1795
|
+
chainKey: params.network || void 0,
|
|
1796
|
+
pin: params.pin,
|
|
1797
|
+
email: params.email
|
|
1798
|
+
});
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
// src/wallets/walletConnectors/abcWallet/api/modules/executeBodies.ts
|
|
1802
|
+
var NATIVE_DECIMALS = {
|
|
1803
|
+
solana: 9,
|
|
1804
|
+
tron: 6,
|
|
1805
|
+
xrpl: 6,
|
|
1806
|
+
bitcoin: 8
|
|
1807
|
+
};
|
|
1808
|
+
var MAX_IDEMPOTENCY_KEY_LENGTH = 200;
|
|
1809
|
+
var IDEMPOTENCY_KEY_BYTES = 16;
|
|
1810
|
+
var BTC_FEE_RATE_PATTERN = /^[1-9][0-9]{0,3}$/;
|
|
1811
|
+
var BTC_FEE_RATE_MAX = 1e3;
|
|
1812
|
+
var XRP_FEE_PATTERN = /^[1-9][0-9]{0,6}$/;
|
|
1813
|
+
var XRP_FEE_MAX_DROPS = 1e6;
|
|
1814
|
+
var TRC20_FEE_LIMIT_MAX_SUN = 1e9;
|
|
1815
|
+
var XRP_DESTINATION_TAG_MAX = 4294967295;
|
|
1816
|
+
var SOLANA_CHAIN_KEYS = { solana: "solana", solana_devnet: "solanaDevnet" };
|
|
1817
|
+
var TRON_CHAIN_KEYS = { tron: "tron", tron_nile: "tronNile" };
|
|
1818
|
+
var XRPL_CHAIN_KEYS = { xrpl: "xrpl", xrpl_testnet: "xrplTestnet" };
|
|
1819
|
+
var BITCOIN_CHAIN_KEYS = {
|
|
1820
|
+
bitcoin: "bitcoin",
|
|
1821
|
+
bitcoin_testnet: "bitcoinTestnet"
|
|
1822
|
+
};
|
|
1823
|
+
function newIdempotencyKey() {
|
|
1824
|
+
const bytes = crypto.getRandomValues(new Uint8Array(IDEMPOTENCY_KEY_BYTES));
|
|
1825
|
+
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join(
|
|
1826
|
+
""
|
|
1827
|
+
);
|
|
1828
|
+
}
|
|
1829
|
+
function acceptIdempotencyKey(key) {
|
|
1830
|
+
if (key === void 0)
|
|
1831
|
+
return newIdempotencyKey();
|
|
1832
|
+
if (typeof key !== "string" || key === "" || key.length > MAX_IDEMPOTENCY_KEY_LENGTH) {
|
|
1833
|
+
throw badRequest(
|
|
1834
|
+
`idempotencyKey must be a string of 1 to ${MAX_IDEMPOTENCY_KEY_LENGTH} characters`
|
|
1835
|
+
);
|
|
1836
|
+
}
|
|
1837
|
+
return key;
|
|
1838
|
+
}
|
|
1839
|
+
function chainKeyFor(label, table, network) {
|
|
1840
|
+
if (typeof network === "string" && Object.prototype.hasOwnProperty.call(table, network)) {
|
|
1841
|
+
return table[network];
|
|
1842
|
+
}
|
|
1843
|
+
throw badRequest(
|
|
1844
|
+
`${label} network must be one of: ${Object.keys(table).join(", ")}`
|
|
1845
|
+
);
|
|
1846
|
+
}
|
|
1847
|
+
function required(value, field) {
|
|
1848
|
+
if (typeof value !== "string" || value === "") {
|
|
1849
|
+
throw badRequest(`${field} is required`);
|
|
1850
|
+
}
|
|
1851
|
+
return value;
|
|
1852
|
+
}
|
|
1853
|
+
function refuseDefined(params, fields, context) {
|
|
1854
|
+
for (const field of fields) {
|
|
1855
|
+
if (params[field] != null) {
|
|
1856
|
+
throw badRequest(`${field} is not supported ${context}`);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
function humanAmount(baseUnits, decimals, field) {
|
|
1861
|
+
try {
|
|
1862
|
+
return toDecimalAmount(required(baseUnits, field), decimals);
|
|
1863
|
+
} catch (error) {
|
|
1864
|
+
if (error instanceof TalkenApiError)
|
|
1865
|
+
throw error;
|
|
1866
|
+
throw badRequest(
|
|
1867
|
+
`${field}: ${error instanceof Error ? error.message : String(error)}`
|
|
1868
|
+
);
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
function toExecuteTxBody(params) {
|
|
1872
|
+
return compact({
|
|
1873
|
+
chainKey: params.chainKey,
|
|
1874
|
+
to: params.to,
|
|
1875
|
+
amountWei: params.amountWei,
|
|
1876
|
+
data: params.data,
|
|
1877
|
+
gasLimit: params.gasLimit,
|
|
1878
|
+
gasPrice: params.gasPrice,
|
|
1879
|
+
maxFeePerGas: params.maxFeePerGas,
|
|
1880
|
+
maxPriorityFeePerGas: params.maxPriorityFeePerGas,
|
|
1881
|
+
pin: params.pin,
|
|
1882
|
+
email: params.email,
|
|
1883
|
+
waitForReceipt: params.waitForReceipt,
|
|
1884
|
+
idempotencyKey: acceptIdempotencyKey(params.idempotencyKey)
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
function toSolanaSendBody(params) {
|
|
1888
|
+
const chainKey = chainKeyFor("Solana", SOLANA_CHAIN_KEYS, params.network);
|
|
1889
|
+
const to = required(params.toAddress, "toAddress");
|
|
1890
|
+
const kind = params.kind ?? (params.mintAddress ? "spl" : "native");
|
|
1891
|
+
if (kind !== "native" && kind !== "spl") {
|
|
1892
|
+
throw badRequest("kind must be native or spl");
|
|
1893
|
+
}
|
|
1894
|
+
const common = {
|
|
1895
|
+
pin: params.pin,
|
|
1896
|
+
email: params.email,
|
|
1897
|
+
waitForReceipt: params.waitForConfirmation,
|
|
1898
|
+
idempotencyKey: acceptIdempotencyKey(params.idempotencyKey)
|
|
1899
|
+
};
|
|
1900
|
+
if (kind === "native") {
|
|
1901
|
+
refuseDefined(
|
|
1902
|
+
params,
|
|
1903
|
+
["mintAddress", "amount", "decimals"],
|
|
1904
|
+
"for a native SOL transfer"
|
|
1905
|
+
);
|
|
1906
|
+
return compact({
|
|
1907
|
+
to,
|
|
1908
|
+
chainKey,
|
|
1909
|
+
amount: humanAmount(
|
|
1910
|
+
params.amountLamports,
|
|
1911
|
+
NATIVE_DECIMALS.solana,
|
|
1912
|
+
"amountLamports"
|
|
1913
|
+
),
|
|
1914
|
+
...common
|
|
1915
|
+
});
|
|
1916
|
+
}
|
|
1917
|
+
refuseDefined(params, ["amountLamports"], "for an SPL transfer");
|
|
1918
|
+
return compact({
|
|
1919
|
+
to,
|
|
1920
|
+
chainKey,
|
|
1921
|
+
amount: humanAmount(params.amount, params.decimals, "amount"),
|
|
1922
|
+
token: required(params.mintAddress, "mintAddress"),
|
|
1923
|
+
decimals: params.decimals,
|
|
1924
|
+
...common
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
1927
|
+
function toTronSendBody(params) {
|
|
1928
|
+
const chainKey = chainKeyFor("TRON", TRON_CHAIN_KEYS, params.network);
|
|
1929
|
+
const to = required(params.toAddress, "toAddress");
|
|
1930
|
+
const kind = params.kind ?? "native";
|
|
1931
|
+
refuseDefined(
|
|
1932
|
+
params,
|
|
1933
|
+
["data", "callValue", "confirmPollMs", "confirmMaxAttempts"],
|
|
1934
|
+
"by /execute/send"
|
|
1935
|
+
);
|
|
1936
|
+
const common = {
|
|
1937
|
+
pin: params.pin,
|
|
1938
|
+
email: params.email,
|
|
1939
|
+
waitForReceipt: params.waitForConfirmation,
|
|
1940
|
+
idempotencyKey: acceptIdempotencyKey(params.idempotencyKey)
|
|
1941
|
+
};
|
|
1942
|
+
if (kind === "native") {
|
|
1943
|
+
refuseDefined(
|
|
1944
|
+
params,
|
|
1945
|
+
["contractAddress", "amount", "decimals", "feeLimit"],
|
|
1946
|
+
"for a native TRX transfer"
|
|
1947
|
+
);
|
|
1948
|
+
return compact({
|
|
1949
|
+
to,
|
|
1950
|
+
chainKey,
|
|
1951
|
+
amount: humanAmount(params.amountSun, NATIVE_DECIMALS.tron, "amountSun"),
|
|
1952
|
+
...common
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
if (kind !== "trc20") {
|
|
1956
|
+
throw badRequest("kind must be native or trc20");
|
|
1957
|
+
}
|
|
1958
|
+
refuseDefined(params, ["amountSun"], "for a TRC-20 transfer");
|
|
1959
|
+
if (params.feeLimit != null && !(Number.isSafeInteger(params.feeLimit) && params.feeLimit >= 1 && params.feeLimit <= TRC20_FEE_LIMIT_MAX_SUN)) {
|
|
1960
|
+
throw badRequest(
|
|
1961
|
+
`feeLimit must be an integer number of sun from 1 to ${TRC20_FEE_LIMIT_MAX_SUN}`
|
|
1962
|
+
);
|
|
1963
|
+
}
|
|
1964
|
+
return compact({
|
|
1965
|
+
to,
|
|
1966
|
+
chainKey,
|
|
1967
|
+
amount: humanAmount(params.amount, params.decimals, "amount"),
|
|
1968
|
+
token: required(params.contractAddress, "contractAddress"),
|
|
1969
|
+
decimals: params.decimals,
|
|
1970
|
+
feeLimit: params.feeLimit,
|
|
1971
|
+
...common
|
|
1972
|
+
});
|
|
1973
|
+
}
|
|
1974
|
+
function toXrpSendBody(params) {
|
|
1975
|
+
const chainKey = chainKeyFor("XRPL", XRPL_CHAIN_KEYS, params.network);
|
|
1976
|
+
const to = required(params.destination, "destination");
|
|
1977
|
+
if (params.destinationTag != null && !(Number.isInteger(params.destinationTag) && params.destinationTag >= 0 && params.destinationTag <= XRP_DESTINATION_TAG_MAX)) {
|
|
1978
|
+
throw badRequest(
|
|
1979
|
+
`destinationTag must be an integer from 0 to ${XRP_DESTINATION_TAG_MAX}`
|
|
1980
|
+
);
|
|
1981
|
+
}
|
|
1982
|
+
if (params.fee != null && !(typeof params.fee === "string" && XRP_FEE_PATTERN.test(params.fee) && Number(params.fee) <= XRP_FEE_MAX_DROPS)) {
|
|
1983
|
+
throw badRequest(
|
|
1984
|
+
`fee must be a decimal string of whole drops from 1 to ${XRP_FEE_MAX_DROPS}`
|
|
1985
|
+
);
|
|
1986
|
+
}
|
|
1987
|
+
const common = {
|
|
1988
|
+
destinationTag: params.destinationTag,
|
|
1989
|
+
fee: params.fee,
|
|
1990
|
+
pin: params.pin,
|
|
1991
|
+
email: params.email,
|
|
1992
|
+
waitForReceipt: params.waitForConfirmation,
|
|
1993
|
+
idempotencyKey: acceptIdempotencyKey(params.idempotencyKey)
|
|
1994
|
+
};
|
|
1995
|
+
if (params.kind === "native") {
|
|
1996
|
+
refuseDefined(params, ["currency", "issuer"], "for a native XRP transfer");
|
|
1997
|
+
return compact({
|
|
1998
|
+
to,
|
|
1999
|
+
chainKey,
|
|
2000
|
+
amount: humanAmount(params.amount, NATIVE_DECIMALS.xrpl, "amount"),
|
|
2001
|
+
...common
|
|
2002
|
+
});
|
|
2003
|
+
}
|
|
2004
|
+
if (params.kind !== "fungible") {
|
|
2005
|
+
throw badRequest("kind must be native or fungible");
|
|
2006
|
+
}
|
|
2007
|
+
try {
|
|
2008
|
+
validateAmount(required(params.amount, "amount"));
|
|
2009
|
+
} catch (error) {
|
|
2010
|
+
if (error instanceof TalkenApiError)
|
|
2011
|
+
throw error;
|
|
2012
|
+
throw badRequest(
|
|
2013
|
+
`amount: ${error instanceof Error ? error.message : String(error)}`
|
|
2014
|
+
);
|
|
2015
|
+
}
|
|
2016
|
+
return compact({
|
|
2017
|
+
to,
|
|
2018
|
+
chainKey,
|
|
2019
|
+
amount: params.amount,
|
|
2020
|
+
token: required(params.currency, "currency"),
|
|
2021
|
+
issuer: required(params.issuer, "issuer"),
|
|
2022
|
+
...common
|
|
2023
|
+
});
|
|
2024
|
+
}
|
|
2025
|
+
function toBitcoinSendBody(params) {
|
|
2026
|
+
if (params.action !== void 0 && params.action !== "transfer") {
|
|
2027
|
+
throw badRequest("only action=transfer is sent through /execute/send");
|
|
2028
|
+
}
|
|
2029
|
+
refuseDefined(
|
|
2030
|
+
params,
|
|
2031
|
+
[
|
|
2032
|
+
"blocks",
|
|
2033
|
+
"hash",
|
|
2034
|
+
"signatureHex",
|
|
2035
|
+
"confirmPollMs",
|
|
2036
|
+
"confirmMaxAttempts",
|
|
2037
|
+
"minConfirmations"
|
|
2038
|
+
],
|
|
2039
|
+
"by /execute/send"
|
|
2040
|
+
);
|
|
2041
|
+
const chainKey = chainKeyFor("Bitcoin", BITCOIN_CHAIN_KEYS, params.network);
|
|
2042
|
+
let feeRate;
|
|
2043
|
+
if (params.feeRate != null) {
|
|
2044
|
+
feeRate = String(params.feeRate);
|
|
2045
|
+
if (!BTC_FEE_RATE_PATTERN.test(feeRate) || Number(feeRate) > BTC_FEE_RATE_MAX) {
|
|
2046
|
+
throw badRequest(
|
|
2047
|
+
`feeRate must be a whole sat/vB from 1 to ${BTC_FEE_RATE_MAX}`
|
|
2048
|
+
);
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
return compact({
|
|
2052
|
+
to: required(params.toAddress, "toAddress"),
|
|
2053
|
+
chainKey,
|
|
2054
|
+
amount: humanAmount(
|
|
2055
|
+
params.amountSats,
|
|
2056
|
+
NATIVE_DECIMALS.bitcoin,
|
|
2057
|
+
"amountSats"
|
|
2058
|
+
),
|
|
2059
|
+
feeRate,
|
|
2060
|
+
pin: params.pin,
|
|
2061
|
+
email: params.email,
|
|
2062
|
+
idempotencyKey: acceptIdempotencyKey(params.idempotencyKey)
|
|
2063
|
+
});
|
|
2064
|
+
}
|
|
2065
|
+
function toBroadcastBody(chainKey, transaction) {
|
|
2066
|
+
return {
|
|
2067
|
+
chainKey: required(chainKey, "chainKey"),
|
|
2068
|
+
transaction: required(transaction, "transaction")
|
|
2069
|
+
};
|
|
2070
|
+
}
|
|
2071
|
+
function routeRawTransaction(params) {
|
|
2072
|
+
const { chain } = params;
|
|
2073
|
+
if (chain === "tvm" && params.network == null)
|
|
2074
|
+
return "legacy";
|
|
2075
|
+
const network = required(params.network, "network");
|
|
2076
|
+
const family = getNetworkType(network);
|
|
2077
|
+
const contradiction = () => badRequest(`chain=${chain} contradicts network=${network}`);
|
|
2078
|
+
if (chain === "tvm" || family === "TRX" /* TRON */) {
|
|
2079
|
+
if (chain !== void 0 && chain !== "tvm" || family !== "TRX" /* TRON */) {
|
|
2080
|
+
throw family === void 0 && chain === "tvm" ? badRequest(`network ${network} is not a TRON network`) : contradiction();
|
|
2081
|
+
}
|
|
2082
|
+
return "legacy";
|
|
2083
|
+
}
|
|
2084
|
+
if (chain === "svm") {
|
|
2085
|
+
throw badRequest(
|
|
2086
|
+
"sendRawTransaction broadcasts signed EVM transactions only; send a Solana transfer with solana.transfer, or sign a Solana message or transaction with solana.sign"
|
|
2087
|
+
);
|
|
2088
|
+
}
|
|
2089
|
+
if (family !== "EVM" /* EVM */) {
|
|
2090
|
+
throw badRequest(
|
|
2091
|
+
`network ${network} is not an EVM network; /execute/broadcast takes signed EVM transactions only`
|
|
2092
|
+
);
|
|
2093
|
+
}
|
|
2094
|
+
if (chain !== void 0 && chain !== "evm")
|
|
2095
|
+
throw contradiction();
|
|
2096
|
+
return getEvmChainKey(network) === void 0 ? "legacy" : "broadcast";
|
|
2097
|
+
}
|
|
2098
|
+
function toExecuteBroadcastBody(params) {
|
|
2099
|
+
const chainKey = routeRawTransaction(params) === "broadcast" ? getEvmChainKey(required(params.network, "network")) : void 0;
|
|
2100
|
+
if (chainKey === void 0) {
|
|
2101
|
+
throw badRequest(
|
|
2102
|
+
"Only a signed EVM transaction on a network with a chain key is broadcast through /execute/broadcast"
|
|
2103
|
+
);
|
|
2104
|
+
}
|
|
2105
|
+
return toBroadcastBody(
|
|
2106
|
+
chainKey,
|
|
2107
|
+
required(params.signedSerializeTx, "signedSerializeTx")
|
|
2108
|
+
);
|
|
2109
|
+
}
|
|
2110
|
+
|
|
2111
|
+
// src/gasless/utils/revokeDelegation.ts
|
|
1507
2112
|
var ZERO_ADDRESS2 = "0x0000000000000000000000000000000000000000";
|
|
1508
2113
|
var DEFAULT_GAS_LIMIT = BigInt(1e5);
|
|
1509
2114
|
var DEFAULT_MAX_FEE = BigInt(3e10);
|
|
@@ -1531,7 +2136,7 @@ async function recoverYParity(hash, r, s, expectedAddress) {
|
|
|
1531
2136
|
}
|
|
1532
2137
|
throw new Error("Failed to recover yParity from tx signature");
|
|
1533
2138
|
}
|
|
1534
|
-
async function sendRevokeTx(userAddress,
|
|
2139
|
+
async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
1535
2140
|
const api = getTalkenApiClient();
|
|
1536
2141
|
if (!api)
|
|
1537
2142
|
throw new Error("TalkenApiClient not initialized");
|
|
@@ -1604,7 +2209,7 @@ async function sendRevokeTx(userAddress, _chainKey, chainId) {
|
|
|
1604
2209
|
];
|
|
1605
2210
|
const signingPayload = `0x04${toRlp(unsignedFields).slice(2)}`;
|
|
1606
2211
|
const signingHash = keccak256(signingPayload);
|
|
1607
|
-
const signResult = await api.
|
|
2212
|
+
const signResult = await api.bitcoin.signHash({
|
|
1608
2213
|
hash: signingHash,
|
|
1609
2214
|
pin: pinHash,
|
|
1610
2215
|
...network && { network },
|
|
@@ -1639,17 +2244,12 @@ async function sendRevokeTx(userAddress, _chainKey, chainId) {
|
|
|
1639
2244
|
);
|
|
1640
2245
|
const signedFields = [...unsignedFields, txYParity ? "0x01" : "0x", txR, txS];
|
|
1641
2246
|
const signedTx = `0x04${toRlp(signedFields).slice(2)}`;
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
network,
|
|
1647
|
-
signedSerializeTx: signedTx,
|
|
1648
|
-
waitForConfirmation: true
|
|
1649
|
-
}
|
|
2247
|
+
const { txHash } = await api.post(
|
|
2248
|
+
TALKEN_API_ENDPOINTS.EXECUTE_BROADCAST,
|
|
2249
|
+
toBroadcastBody(chainKey, signedTx),
|
|
2250
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
1650
2251
|
);
|
|
1651
|
-
|
|
1652
|
-
console.log(`[RevokeDelegation] Revoke tx confirmed: ${txHash}`);
|
|
2252
|
+
console.log(`[RevokeDelegation] Revoke tx broadcast: ${txHash}`);
|
|
1653
2253
|
return { txHash };
|
|
1654
2254
|
}
|
|
1655
2255
|
async function sendRevokeViaWalletClient(walletClient, chainId, userAddress) {
|
|
@@ -2625,51 +3225,75 @@ var AbstractChainProvider = class extends EventEmitter {
|
|
|
2625
3225
|
}
|
|
2626
3226
|
};
|
|
2627
3227
|
|
|
2628
|
-
// src/wallets/walletConnectors/abcWallet/
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
AbcErrorCode3["WALLET_NOT_FOUND"] = "WALLET_NOT_FOUND";
|
|
2633
|
-
AbcErrorCode3["INVALID_PIN"] = "INVALID_PIN";
|
|
2634
|
-
AbcErrorCode3["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
2635
|
-
AbcErrorCode3["SIGNATURE_FAILED"] = "SIGNATURE_FAILED";
|
|
2636
|
-
AbcErrorCode3["USER_CANCELLED"] = "USER_CANCELLED";
|
|
2637
|
-
AbcErrorCode3["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
2638
|
-
return AbcErrorCode3;
|
|
2639
|
-
})(AbcErrorCode || {});
|
|
2640
|
-
var AbcError = class extends Error {
|
|
2641
|
-
constructor(code, message, details, statusCode) {
|
|
2642
|
-
super(message);
|
|
2643
|
-
this.name = "AbcError";
|
|
2644
|
-
this.code = code;
|
|
2645
|
-
this.details = details;
|
|
2646
|
-
this.statusCode = statusCode;
|
|
3228
|
+
// src/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.ts
|
|
3229
|
+
function isSigningCredentialError(error) {
|
|
3230
|
+
if (!(error instanceof TalkenApiError) || error.statusCode !== 502 || !error.message.includes("Missing required wallet fields")) {
|
|
3231
|
+
return false;
|
|
2647
3232
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
3233
|
+
const broadcast = broadcastMarker(error.details);
|
|
3234
|
+
if (broadcast === false)
|
|
3235
|
+
return true;
|
|
3236
|
+
return !(error.retryable === false || broadcast === "unknown" || isUnconfirmedBroadcastCode(error.code) || error.possibleTxHash !== void 0);
|
|
3237
|
+
}
|
|
3238
|
+
function isUnconfirmedBroadcastCode(code) {
|
|
3239
|
+
return code === "BROADCAST_UNCONFIRMED" || code.endsWith("_BROADCAST_UNCONFIRMED");
|
|
3240
|
+
}
|
|
3241
|
+
function broadcastMarker(details) {
|
|
3242
|
+
return typeof details === "object" && details !== null ? details.broadcast : void 0;
|
|
3243
|
+
}
|
|
3244
|
+
async function withSigningCredentialRefresh(client, call, options) {
|
|
3245
|
+
try {
|
|
3246
|
+
return await call();
|
|
3247
|
+
} catch (error) {
|
|
3248
|
+
if (!isSigningCredentialError(error))
|
|
3249
|
+
throw error;
|
|
3250
|
+
let pin = null;
|
|
3251
|
+
let email = null;
|
|
3252
|
+
try {
|
|
3253
|
+
const credentials = getCredentialManager();
|
|
3254
|
+
pin = credentials.getPinHash();
|
|
3255
|
+
email = options?.email || credentials.getEmail();
|
|
3256
|
+
} catch {
|
|
3257
|
+
}
|
|
3258
|
+
if (!pin || !email)
|
|
3259
|
+
throw error;
|
|
3260
|
+
await client.post(TALKEN_API_ENDPOINTS.WALLET_MPC, {
|
|
3261
|
+
action: "create",
|
|
3262
|
+
email,
|
|
3263
|
+
pin
|
|
3264
|
+
});
|
|
3265
|
+
return call();
|
|
2656
3266
|
}
|
|
2657
|
-
}
|
|
3267
|
+
}
|
|
2658
3268
|
|
|
2659
|
-
// src/wallets/walletConnectors/abcWallet/
|
|
2660
|
-
var
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
3269
|
+
// src/wallets/walletConnectors/abcWallet/evmTxType.ts
|
|
3270
|
+
var QUANTITY = /^(?:0x[0-9a-fA-F]+|[0-9]+)$/;
|
|
3271
|
+
function resolveEvmSignType(tx) {
|
|
3272
|
+
const request = tx ?? {};
|
|
3273
|
+
if (Array.isArray(request.authorizationList) && request.authorizationList.length > 0) {
|
|
3274
|
+
throw unsupported7702();
|
|
3275
|
+
}
|
|
3276
|
+
const raw = request.type;
|
|
3277
|
+
if (raw === void 0 || raw === null || raw === "")
|
|
3278
|
+
return void 0;
|
|
3279
|
+
const value = typeof raw === "number" ? raw : typeof raw === "string" && QUANTITY.test(raw) ? Number(raw) : Number.NaN;
|
|
3280
|
+
if (value === 0)
|
|
3281
|
+
return "LEGACY";
|
|
3282
|
+
if (value === 2)
|
|
3283
|
+
return "EIP1559";
|
|
3284
|
+
if (value === 4)
|
|
3285
|
+
throw unsupported7702();
|
|
3286
|
+
throw new ProviderRpcError(
|
|
3287
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
3288
|
+
`Transaction type ${JSON.stringify(raw)} is not supported: use legacy (0x0) or EIP-1559 (0x2)`
|
|
3289
|
+
);
|
|
3290
|
+
}
|
|
3291
|
+
function unsupported7702() {
|
|
3292
|
+
return new ProviderRpcError(
|
|
3293
|
+
ProviderErrorCode.INVALID_PARAMS,
|
|
3294
|
+
"EIP-7702 (type 0x4) transactions are not supported by this wallet: sign the authorization with eth_signAuthorization instead"
|
|
3295
|
+
);
|
|
3296
|
+
}
|
|
2673
3297
|
|
|
2674
3298
|
// src/wallets/walletConnectors/abcWallet/utils.ts
|
|
2675
3299
|
function validatePin(pin) {
|
|
@@ -2873,7 +3497,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2873
3497
|
* a wallet.generate() call (idempotent create/recover) to repopulate.
|
|
2874
3498
|
*/
|
|
2875
3499
|
isSigningCredentialError(error) {
|
|
2876
|
-
return error
|
|
3500
|
+
return isSigningCredentialError(error);
|
|
2877
3501
|
}
|
|
2878
3502
|
/**
|
|
2879
3503
|
* Refresh server-side signing credentials.
|
|
@@ -2882,9 +3506,8 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2882
3506
|
* 1. PIN hash in memory → wallet.generate() to repopulate server cache
|
|
2883
3507
|
* 2. Neither available → throw UNAUTHORIZED
|
|
2884
3508
|
*
|
|
2885
|
-
* Note:
|
|
2886
|
-
*
|
|
2887
|
-
* can use them as fallback without a separate refresh call.
|
|
3509
|
+
* Note: the /sign/* and /execute/* routes do not accept cached `evmCreds`,
|
|
3510
|
+
* so this refresh is the only recovery from a cold server credential cache.
|
|
2888
3511
|
*/
|
|
2889
3512
|
async refreshSigningCredentials() {
|
|
2890
3513
|
const credMgr = getCredentialManager();
|
|
@@ -3045,6 +3668,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
3045
3668
|
"Invalid transaction params"
|
|
3046
3669
|
);
|
|
3047
3670
|
}
|
|
3671
|
+
resolveEvmSignType(params[0]);
|
|
3048
3672
|
const resolved = await this.callInterceptor("eth_sendTransaction", params);
|
|
3049
3673
|
const tx = params[0];
|
|
3050
3674
|
logger2.debug("eth_sendTransaction incoming gas params:", {
|
|
@@ -3145,23 +3769,21 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
3145
3769
|
const amountWei = BigInt(hexValue).toString();
|
|
3146
3770
|
try {
|
|
3147
3771
|
const gasLimit = tx.gas || tx.gasLimit;
|
|
3148
|
-
const result = await
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
})
|
|
3164
|
-
);
|
|
3772
|
+
const result = await api.evm.sendTransaction({
|
|
3773
|
+
chainKey,
|
|
3774
|
+
to: tx.to,
|
|
3775
|
+
amountWei,
|
|
3776
|
+
pin: pinHash,
|
|
3777
|
+
data: tx.data || "0x",
|
|
3778
|
+
waitForReceipt: true,
|
|
3779
|
+
...gasLimit && { gasLimit },
|
|
3780
|
+
...tx.gasPrice && { gasPrice: tx.gasPrice },
|
|
3781
|
+
...tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas },
|
|
3782
|
+
...tx.maxPriorityFeePerGas && {
|
|
3783
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
3784
|
+
},
|
|
3785
|
+
...email && { email }
|
|
3786
|
+
});
|
|
3165
3787
|
this.updateTxResult({
|
|
3166
3788
|
txHash: result.txHash,
|
|
3167
3789
|
network: chainKey,
|
|
@@ -3266,6 +3888,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
3266
3888
|
"Invalid transaction params"
|
|
3267
3889
|
);
|
|
3268
3890
|
}
|
|
3891
|
+
const signType = resolveEvmSignType(params[0]);
|
|
3269
3892
|
const resolved = await this.callInterceptor("eth_signTransaction", params);
|
|
3270
3893
|
const tx = params[0];
|
|
3271
3894
|
if (resolved) {
|
|
@@ -3304,6 +3927,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
3304
3927
|
maxFeePerGas: tx.maxFeePerGas,
|
|
3305
3928
|
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
3306
3929
|
nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0,
|
|
3930
|
+
...signType && { type: signType },
|
|
3307
3931
|
...pinHash && { pin: pinHash },
|
|
3308
3932
|
...email && { email }
|
|
3309
3933
|
})
|
|
@@ -3848,33 +4472,44 @@ var TalkenEvmModule = class {
|
|
|
3848
4472
|
}
|
|
3849
4473
|
/**
|
|
3850
4474
|
* Sign EVM transaction (sign only, no broadcast)
|
|
3851
|
-
* POST /
|
|
3852
|
-
*
|
|
4475
|
+
* POST /sign/tx { chainKey, to, amountWei, data?, ... }
|
|
4476
|
+
* `network` is sent as `chainKey`, `value` as decimal `amountWei`; `from` is
|
|
4477
|
+
* not sent. Server handles SecureChannel internally.
|
|
3853
4478
|
*/
|
|
3854
4479
|
async signTransaction(params) {
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
4480
|
+
const body = toSignTxBody(params);
|
|
4481
|
+
return withSigningCredentialRefresh(
|
|
4482
|
+
this.client,
|
|
4483
|
+
() => this.client.post(
|
|
4484
|
+
TALKEN_API_ENDPOINTS.SIGN_EVM,
|
|
4485
|
+
body
|
|
4486
|
+
)
|
|
3858
4487
|
);
|
|
3859
4488
|
}
|
|
3860
4489
|
/**
|
|
3861
4490
|
* Sign EIP-712 typed data
|
|
3862
|
-
* POST /
|
|
4491
|
+
* POST /sign/typed-data { chainKey, domain, types, primaryType, message }
|
|
4492
|
+
* `typedData` (JSON string or object) is split into those four fields.
|
|
3863
4493
|
*/
|
|
3864
4494
|
async signTypedData(params) {
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
4495
|
+
const body = toSignTypedDataBody(params);
|
|
4496
|
+
return withSigningCredentialRefresh(
|
|
4497
|
+
this.client,
|
|
4498
|
+
() => this.client.post(
|
|
4499
|
+
TALKEN_API_ENDPOINTS.SIGN_TYPED,
|
|
4500
|
+
body
|
|
4501
|
+
)
|
|
3868
4502
|
);
|
|
3869
4503
|
}
|
|
3870
4504
|
/**
|
|
3871
4505
|
* Sign personal message (EIP-191)
|
|
3872
|
-
* POST /
|
|
4506
|
+
* POST /sign/message { chainKey, message, address? }
|
|
3873
4507
|
*/
|
|
3874
4508
|
async signPersonal(params) {
|
|
3875
|
-
const
|
|
3876
|
-
|
|
3877
|
-
|
|
4509
|
+
const body = toSignMessageBody(params);
|
|
4510
|
+
const res = await withSigningCredentialRefresh(
|
|
4511
|
+
this.client,
|
|
4512
|
+
() => this.client.post(TALKEN_API_ENDPOINTS.SIGN_PERSONAL, body)
|
|
3878
4513
|
);
|
|
3879
4514
|
return {
|
|
3880
4515
|
signature: res?.signature ?? res?.serializedTx ?? "",
|
|
@@ -3883,32 +4518,66 @@ var TalkenEvmModule = class {
|
|
|
3883
4518
|
}
|
|
3884
4519
|
/**
|
|
3885
4520
|
* Sign EIP-7702 authorization payload
|
|
3886
|
-
* POST /
|
|
4521
|
+
* POST /sign/authorization { chainKey, authorization, pin? }
|
|
4522
|
+
* `authorization.nonce` is sent as a decimal string.
|
|
3887
4523
|
*/
|
|
3888
4524
|
async signAuthorization(params) {
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
4525
|
+
const body = toSignAuthorizationBody(params);
|
|
4526
|
+
return withSigningCredentialRefresh(
|
|
4527
|
+
this.client,
|
|
4528
|
+
() => this.client.post(
|
|
4529
|
+
TALKEN_API_ENDPOINTS.SIGN_AUTHORIZATION,
|
|
4530
|
+
body
|
|
4531
|
+
)
|
|
3892
4532
|
);
|
|
3893
4533
|
}
|
|
3894
4534
|
/**
|
|
3895
|
-
* Broadcast signed transaction
|
|
3896
|
-
* POST /
|
|
4535
|
+
* Broadcast a signed EVM transaction
|
|
4536
|
+
* POST /execute/broadcast { chainKey, transaction }
|
|
4537
|
+
* `network` (a WaaS network name or a chain key) is sent as the chain key the
|
|
4538
|
+
* kit's network tables map it to, never as the WaaS name, and
|
|
4539
|
+
* `signedSerializeTx` as `transaction`. The answer is the submission
|
|
4540
|
+
* acknowledgement (`txHash`); the route does not wait for a receipt.
|
|
4541
|
+
*
|
|
4542
|
+
* Deprecated for raw TRON (`chain: 'tvm'` or a TRON network) and for an EVM
|
|
4543
|
+
* network the kit has no chain key for (`optimism`, `moonbeam`, ...): they have
|
|
4544
|
+
* no /execute/* successor and stay on POST /wallet/tx/raw until its 2027-03-10
|
|
4545
|
+
* sunset. A Solana or Bitcoin network, an unknown network, and a `chain` that
|
|
4546
|
+
* contradicts the network are refused.
|
|
3897
4547
|
*/
|
|
3898
4548
|
async sendRawTransaction(params) {
|
|
4549
|
+
if (routeRawTransaction(params) === "legacy") {
|
|
4550
|
+
return this.client.post(
|
|
4551
|
+
TALKEN_API_ENDPOINTS.TX_RAW,
|
|
4552
|
+
params
|
|
4553
|
+
);
|
|
4554
|
+
}
|
|
3899
4555
|
return this.client.post(
|
|
3900
|
-
TALKEN_API_ENDPOINTS.
|
|
3901
|
-
params
|
|
4556
|
+
TALKEN_API_ENDPOINTS.EXECUTE_BROADCAST,
|
|
4557
|
+
toExecuteBroadcastBody(params),
|
|
4558
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
3902
4559
|
);
|
|
3903
4560
|
}
|
|
3904
4561
|
/**
|
|
3905
4562
|
* Integrated EVM transfer (sign + broadcast)
|
|
3906
|
-
* POST /
|
|
4563
|
+
* POST /execute/tx { chainKey, to, amountWei, pin, idempotencyKey, ... }
|
|
4564
|
+
* Cached `evmCreds` are not attached: the route does not accept them. Pass one
|
|
4565
|
+
* `idempotencyKey` per user action to share it across a re-send of that
|
|
4566
|
+
* action; without one the call generates its own.
|
|
4567
|
+
* A cold server credential cache (502 "Missing required wallet fields", which
|
|
4568
|
+
* the server answers before anything is signed) is refreshed once and the same
|
|
4569
|
+
* request re-sent under the same key, as for the /sign/* methods.
|
|
3907
4570
|
*/
|
|
3908
4571
|
async sendTransaction(params) {
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
4572
|
+
const body = toExecuteTxBody(params);
|
|
4573
|
+
return withSigningCredentialRefresh(
|
|
4574
|
+
this.client,
|
|
4575
|
+
() => this.client.post(
|
|
4576
|
+
TALKEN_API_ENDPOINTS.EXECUTE_TX,
|
|
4577
|
+
body,
|
|
4578
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
4579
|
+
),
|
|
4580
|
+
{ email: params.email }
|
|
3912
4581
|
);
|
|
3913
4582
|
}
|
|
3914
4583
|
/**
|
|
@@ -4027,20 +4696,41 @@ var TalkenBitcoinModule = class {
|
|
|
4027
4696
|
}
|
|
4028
4697
|
/**
|
|
4029
4698
|
* Send BTC (integrated sign + broadcast, action=transfer)
|
|
4030
|
-
* POST /
|
|
4699
|
+
* POST /execute/send { to, chainKey, amount, feeRate?, pin, email, idempotencyKey }
|
|
4700
|
+
* `amountSats` is sent as a BTC `amount` and `network` (required) as the chain
|
|
4701
|
+
* key. `waitForConfirmation` is not forwarded: the server's confirmation poll
|
|
4702
|
+
* outlasts the client timeout, so the answer is the broadcast `txHash`.
|
|
4703
|
+
* A cold server credential cache (502 "Missing required wallet fields",
|
|
4704
|
+
* answered before anything is signed, `details.broadcast: false`) is refreshed
|
|
4705
|
+
* once and the same request re-sent under the same key. The cached `evmCreds`
|
|
4706
|
+
* the legacy route took as its fallback are not accepted by /execute/send.
|
|
4031
4707
|
*/
|
|
4032
4708
|
async sendTransaction(params) {
|
|
4033
|
-
const
|
|
4034
|
-
return
|
|
4035
|
-
|
|
4036
|
-
|
|
4709
|
+
const body = toBitcoinSendBody(params);
|
|
4710
|
+
return withSigningCredentialRefresh(
|
|
4711
|
+
this.client,
|
|
4712
|
+
() => this.client.post(
|
|
4713
|
+
TALKEN_API_ENDPOINTS.EXECUTE_SEND,
|
|
4714
|
+
body,
|
|
4715
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
4716
|
+
),
|
|
4717
|
+
{ email: params.email }
|
|
4037
4718
|
);
|
|
4038
4719
|
}
|
|
4039
4720
|
/**
|
|
4040
|
-
* Execute BTC action endpoint (
|
|
4721
|
+
* Execute a BTC action endpoint (generate|finalize)
|
|
4041
4722
|
* POST /wallet/tx/btc
|
|
4723
|
+
*
|
|
4724
|
+
* @deprecated No /execute/* successor for the generate and finalize steps; stays
|
|
4725
|
+
* on /wallet/tx/btc until its 2027-03-10 sunset. Use `sendTransaction` to send
|
|
4726
|
+
* and `signHash` to sign.
|
|
4042
4727
|
*/
|
|
4043
4728
|
async execute(params) {
|
|
4729
|
+
if (params.action !== "generate" && params.action !== "finalize") {
|
|
4730
|
+
throw badRequest(
|
|
4731
|
+
"execute supports only action=generate or finalize; use sendTransaction to send and signHash to sign"
|
|
4732
|
+
);
|
|
4733
|
+
}
|
|
4044
4734
|
return this.client.post(
|
|
4045
4735
|
TALKEN_API_ENDPOINTS.TX_BTC,
|
|
4046
4736
|
withCachedEvmCreds(params)
|
|
@@ -4048,17 +4738,24 @@ var TalkenBitcoinModule = class {
|
|
|
4048
4738
|
}
|
|
4049
4739
|
/**
|
|
4050
4740
|
* Sign raw hash via secp256k1 MPC (universal: EVM/BTC/TVM)
|
|
4051
|
-
* POST /
|
|
4741
|
+
* POST /sign/hash { hash, pin, chainKey? } — `network` is sent as `chainKey`
|
|
4052
4742
|
*/
|
|
4053
4743
|
async signHash(params) {
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4744
|
+
const body = toSignHashBody(params);
|
|
4745
|
+
return withSigningCredentialRefresh(
|
|
4746
|
+
this.client,
|
|
4747
|
+
() => this.client.post(
|
|
4748
|
+
TALKEN_API_ENDPOINTS.SIGN_HASH,
|
|
4749
|
+
body
|
|
4750
|
+
)
|
|
4057
4751
|
);
|
|
4058
4752
|
}
|
|
4059
4753
|
/**
|
|
4060
4754
|
* Broadcast raw BTC transaction
|
|
4061
4755
|
* POST /wallet/tx/raw { network, signedSerializeTx }
|
|
4756
|
+
*
|
|
4757
|
+
* @deprecated No /execute/* successor (/execute/broadcast answers 501 for
|
|
4758
|
+
* Bitcoin); stays on /wallet/tx/raw until its 2027-03-10 sunset.
|
|
4062
4759
|
*/
|
|
4063
4760
|
async broadcastRawTransaction(params) {
|
|
4064
4761
|
return this.client.post(TALKEN_API_ENDPOINTS.TX_RAW, {
|
|
@@ -4093,19 +4790,26 @@ var TalkenSolanaModule = class {
|
|
|
4093
4790
|
}
|
|
4094
4791
|
/**
|
|
4095
4792
|
* Transfer SOL or SPL token (integrated sign + broadcast)
|
|
4096
|
-
* POST /
|
|
4097
|
-
* - kind='native':
|
|
4098
|
-
* - kind='spl':
|
|
4793
|
+
* POST /execute/send { to, chainKey, amount, token?, decimals?, pin, ... }
|
|
4794
|
+
* - kind='native': `amountLamports` (base units) is sent as a SOL `amount`
|
|
4795
|
+
* - kind='spl': `amount` (raw units) and `decimals` are sent as the human
|
|
4796
|
+
* `amount` with `token` (the mint) and `decimals`
|
|
4797
|
+
* `network` is required and becomes the chain key; `waitForConfirmation` is
|
|
4798
|
+
* sent as `waitForReceipt`.
|
|
4799
|
+
* Not wrapped in `withSigningCredentialRefresh`: Solana signs with the
|
|
4800
|
+
* wallet's encrypted share, not the EVM signing credentials, so the server
|
|
4801
|
+
* never answers this send with the cold-credential 502.
|
|
4099
4802
|
*/
|
|
4100
4803
|
async transfer(params) {
|
|
4101
4804
|
return this.client.post(
|
|
4102
|
-
TALKEN_API_ENDPOINTS.
|
|
4103
|
-
params
|
|
4805
|
+
TALKEN_API_ENDPOINTS.EXECUTE_SEND,
|
|
4806
|
+
toSolanaSendBody(params),
|
|
4807
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
4104
4808
|
);
|
|
4105
4809
|
}
|
|
4106
4810
|
/**
|
|
4107
4811
|
* Sign Solana transaction or message (sign-only, no broadcast)
|
|
4108
|
-
* POST /wallet/sign/sol
|
|
4812
|
+
* POST /sign/solana (same body as the retired /wallet/sign/sol)
|
|
4109
4813
|
*
|
|
4110
4814
|
* Two modes:
|
|
4111
4815
|
* - PIN mode: { message, pin } — server resolves signing material
|
|
@@ -4116,7 +4820,7 @@ var TalkenSolanaModule = class {
|
|
|
4116
4820
|
async sign(params) {
|
|
4117
4821
|
return this.client.post(
|
|
4118
4822
|
TALKEN_API_ENDPOINTS.SIGN_SVM,
|
|
4119
|
-
params
|
|
4823
|
+
toSignSolanaBody(params)
|
|
4120
4824
|
);
|
|
4121
4825
|
}
|
|
4122
4826
|
};
|
|
@@ -4128,15 +4832,33 @@ var TalkenTronModule = class {
|
|
|
4128
4832
|
}
|
|
4129
4833
|
/**
|
|
4130
4834
|
* Execute TVM(TRON) transfer/call (integrated sign + broadcast)
|
|
4131
|
-
* POST /
|
|
4132
|
-
* - kind=native: TRX transfer
|
|
4133
|
-
* - kind=trc20: TRC-20 transfer (
|
|
4134
|
-
*
|
|
4835
|
+
* POST /execute/send { to, chainKey, amount, token?, decimals?, feeLimit?, pin, ... }
|
|
4836
|
+
* - kind=native: TRX transfer; `amountSun` is sent as a TRX `amount`
|
|
4837
|
+
* - kind=trc20: TRC-20 transfer; `amount` (raw units) and `decimals` are sent as
|
|
4838
|
+
* the human `amount` with `token` (the contract) and `decimals`. `decimals`
|
|
4839
|
+
* is required, and `feeLimit` (sun, an integer) is sent for TRC-20 only.
|
|
4840
|
+
* A cold server credential cache (502 "Missing required wallet fields",
|
|
4841
|
+
* answered before anything is signed, `details.broadcast: false`) is refreshed
|
|
4842
|
+
* once and the same request re-sent under the same key.
|
|
4843
|
+
* - kind=contract: arbitrary contract call. Deprecated: it has no /execute/*
|
|
4844
|
+
* successor and stays on POST /wallet/tx/tvm until its 2027-03-10 sunset.
|
|
4135
4845
|
*/
|
|
4136
4846
|
async transferTrx(params) {
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4847
|
+
if (params.kind === "contract") {
|
|
4848
|
+
return this.client.post(
|
|
4849
|
+
TALKEN_API_ENDPOINTS.TX_TVM,
|
|
4850
|
+
params
|
|
4851
|
+
);
|
|
4852
|
+
}
|
|
4853
|
+
const body = toTronSendBody(params);
|
|
4854
|
+
return withSigningCredentialRefresh(
|
|
4855
|
+
this.client,
|
|
4856
|
+
() => this.client.post(
|
|
4857
|
+
TALKEN_API_ENDPOINTS.EXECUTE_SEND,
|
|
4858
|
+
body,
|
|
4859
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
4860
|
+
),
|
|
4861
|
+
{ email: params.email }
|
|
4140
4862
|
);
|
|
4141
4863
|
}
|
|
4142
4864
|
/**
|
|
@@ -4285,14 +5007,28 @@ var TalkenXrpModule = class {
|
|
|
4285
5007
|
}
|
|
4286
5008
|
/**
|
|
4287
5009
|
* Execute XRP transfer (integrated sign + broadcast)
|
|
4288
|
-
* POST /
|
|
4289
|
-
* - kind=native: XRP transfer
|
|
4290
|
-
* - kind=fungible: IOU token transfer
|
|
5010
|
+
* POST /execute/send { to, chainKey, amount, token?, issuer?, fee?, destinationTag?, pin, ... }
|
|
5011
|
+
* - kind=native: XRP transfer; `amount` (drops) is sent as an XRP `amount`
|
|
5012
|
+
* - kind=fungible: IOU token transfer; `amount` is already in human units and
|
|
5013
|
+
* is sent unscaled, with `currency` as `token` and `issuer`. `decimals` is
|
|
5014
|
+
* never sent: the route refuses it on XRPL.
|
|
5015
|
+
* A cold server credential cache (502 "Missing required wallet fields",
|
|
5016
|
+
* answered before anything is signed, `details.broadcast: false`) is refreshed
|
|
5017
|
+
* once and the same request re-sent under the same key.
|
|
5018
|
+
* The route answers once the transaction is submitted (`engineResult`
|
|
5019
|
+
* `tesSUCCESS`) or queued (`terQUEUED`, `submissionStatus: 'queued'`);
|
|
5020
|
+
* `validated` is always false.
|
|
4291
5021
|
*/
|
|
4292
5022
|
async transferXrp(params) {
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
5023
|
+
const body = toXrpSendBody(params);
|
|
5024
|
+
return withSigningCredentialRefresh(
|
|
5025
|
+
this.client,
|
|
5026
|
+
() => this.client.post(
|
|
5027
|
+
TALKEN_API_ENDPOINTS.EXECUTE_SEND,
|
|
5028
|
+
body,
|
|
5029
|
+
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
5030
|
+
),
|
|
5031
|
+
{ email: params.email }
|
|
4296
5032
|
);
|
|
4297
5033
|
}
|
|
4298
5034
|
/**
|
|
@@ -4418,6 +5154,16 @@ function saveToken(key, value) {
|
|
|
4418
5154
|
function removeToken(key) {
|
|
4419
5155
|
remove(STORAGE_NS.API, key);
|
|
4420
5156
|
}
|
|
5157
|
+
function errorOutcome(error, details) {
|
|
5158
|
+
const fromDetails = typeof details === "object" && details !== null ? details.possibleTxHash : void 0;
|
|
5159
|
+
const hash = error?.possibleTxHash ?? fromDetails;
|
|
5160
|
+
return {
|
|
5161
|
+
...typeof error?.retryable === "boolean" && {
|
|
5162
|
+
retryable: error.retryable
|
|
5163
|
+
},
|
|
5164
|
+
...typeof hash === "string" && hash !== "" && { possibleTxHash: hash }
|
|
5165
|
+
};
|
|
5166
|
+
}
|
|
4421
5167
|
var TalkenApiClient = class _TalkenApiClient {
|
|
4422
5168
|
constructor(config2) {
|
|
4423
5169
|
this.accessToken = null;
|
|
@@ -4677,11 +5423,13 @@ var TalkenApiClient = class _TalkenApiClient {
|
|
|
4677
5423
|
if (this.config.debug) {
|
|
4678
5424
|
logger3.error(`Error: ${errCode} - ${errMsg}`);
|
|
4679
5425
|
}
|
|
5426
|
+
const details = data.error?.details || data.details;
|
|
4680
5427
|
throw new TalkenApiError(
|
|
4681
5428
|
errCode,
|
|
4682
5429
|
errMsg,
|
|
4683
5430
|
response.status,
|
|
4684
|
-
|
|
5431
|
+
details,
|
|
5432
|
+
errorOutcome(data.error, details)
|
|
4685
5433
|
);
|
|
4686
5434
|
}
|
|
4687
5435
|
return data.data ?? data;
|
|
@@ -5728,6 +6476,21 @@ function setupVisibilityRefresh() {
|
|
|
5728
6476
|
return () => document.removeEventListener("visibilitychange", handler);
|
|
5729
6477
|
}
|
|
5730
6478
|
|
|
6479
|
+
// src/wallets/walletConnectors/abcWallet/sendFailure.ts
|
|
6480
|
+
function sendFailure(create, message, cause) {
|
|
6481
|
+
const { retryable, possibleTxHash } = cause ?? {};
|
|
6482
|
+
const hash = typeof possibleTxHash === "string" && possibleTxHash !== "" ? possibleTxHash : void 0;
|
|
6483
|
+
const error = create(
|
|
6484
|
+
hash ? `${message} (possible transaction hash: ${hash})` : message,
|
|
6485
|
+
cause
|
|
6486
|
+
);
|
|
6487
|
+
if (typeof retryable === "boolean")
|
|
6488
|
+
error.retryable = retryable;
|
|
6489
|
+
if (hash !== void 0)
|
|
6490
|
+
error.possibleTxHash = hash;
|
|
6491
|
+
return error;
|
|
6492
|
+
}
|
|
6493
|
+
|
|
5731
6494
|
// src/wallets/walletConnectors/abcWallet/abcBitcoinProvider.ts
|
|
5732
6495
|
var logger8 = createLogger("BitcoinProvider");
|
|
5733
6496
|
function isTalkenApiClient(client) {
|
|
@@ -5990,32 +6753,14 @@ var AbcBitcoinProvider = class extends AbstractChainProvider {
|
|
|
5990
6753
|
}
|
|
5991
6754
|
const pinHash = getCredentialManager().getPinHash() || "";
|
|
5992
6755
|
const email = this.getRecoveryEmail();
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
const result = await api.bitcoin.execute({
|
|
5996
|
-
action: "signHash",
|
|
6756
|
+
const signstr = this.extractHashSignature(
|
|
6757
|
+
await api.bitcoin.signHash({
|
|
5997
6758
|
hash: hashHex,
|
|
5998
6759
|
pin: pinHash || void 0,
|
|
5999
6760
|
network: this.network.type,
|
|
6000
6761
|
...email && { email }
|
|
6001
|
-
})
|
|
6002
|
-
|
|
6003
|
-
} catch (error) {
|
|
6004
|
-
logger8.warn(
|
|
6005
|
-
"BTC signHash endpoint failed, falling back to generic sign/hash:",
|
|
6006
|
-
error
|
|
6007
|
-
);
|
|
6008
|
-
}
|
|
6009
|
-
if (!signstr) {
|
|
6010
|
-
signstr = this.extractHashSignature(
|
|
6011
|
-
await api.bitcoin.signHash({
|
|
6012
|
-
hash: hashHex,
|
|
6013
|
-
pin: pinHash || void 0,
|
|
6014
|
-
network: this.network.type,
|
|
6015
|
-
...email && { email }
|
|
6016
|
-
})
|
|
6017
|
-
);
|
|
6018
|
-
}
|
|
6762
|
+
})
|
|
6763
|
+
);
|
|
6019
6764
|
if (!signstr) {
|
|
6020
6765
|
throw new BitcoinProviderError(
|
|
6021
6766
|
ProviderErrorCode.INTERNAL_ERROR,
|
|
@@ -6060,6 +6805,10 @@ var AbcBitcoinProvider = class extends AbstractChainProvider {
|
|
|
6060
6805
|
"Wallet not connected"
|
|
6061
6806
|
);
|
|
6062
6807
|
}
|
|
6808
|
+
const amountSats = toBaseUnits(
|
|
6809
|
+
params.amount,
|
|
6810
|
+
NATIVE_DECIMALS.bitcoin
|
|
6811
|
+
).toString();
|
|
6063
6812
|
try {
|
|
6064
6813
|
const INPUT_PER_BYTE = 141;
|
|
6065
6814
|
const BUFFER = 500;
|
|
@@ -6092,10 +6841,10 @@ var AbcBitcoinProvider = class extends AbstractChainProvider {
|
|
|
6092
6841
|
);
|
|
6093
6842
|
}
|
|
6094
6843
|
const email = this.getRecoveryEmail();
|
|
6095
|
-
const satoshis = Math.floor(params.amount * 1e8);
|
|
6096
6844
|
const result = await api.bitcoin.sendTransaction({
|
|
6097
6845
|
toAddress: params.toAddress,
|
|
6098
|
-
amountSats
|
|
6846
|
+
amountSats,
|
|
6847
|
+
network: this.network.type,
|
|
6099
6848
|
pin: pinHash || void 0,
|
|
6100
6849
|
...email && { email }
|
|
6101
6850
|
});
|
|
@@ -6120,15 +6869,23 @@ var AbcBitcoinProvider = class extends AbstractChainProvider {
|
|
|
6120
6869
|
}
|
|
6121
6870
|
logger8.error("Transaction failed:", error.message);
|
|
6122
6871
|
if (error.message?.includes("insufficient")) {
|
|
6123
|
-
throw
|
|
6124
|
-
|
|
6872
|
+
throw sendFailure(
|
|
6873
|
+
(message, cause) => new BitcoinProviderError(
|
|
6874
|
+
ProviderErrorCode.INSUFFICIENT_FUNDS,
|
|
6875
|
+
message,
|
|
6876
|
+
cause
|
|
6877
|
+
),
|
|
6125
6878
|
"Insufficient BTC balance",
|
|
6126
6879
|
error
|
|
6127
6880
|
);
|
|
6128
6881
|
}
|
|
6129
6882
|
this.emit("error", error);
|
|
6130
|
-
throw
|
|
6131
|
-
|
|
6883
|
+
throw sendFailure(
|
|
6884
|
+
(message, cause) => new BitcoinProviderError(
|
|
6885
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
6886
|
+
message,
|
|
6887
|
+
cause
|
|
6888
|
+
),
|
|
6132
6889
|
"Failed to send transaction",
|
|
6133
6890
|
error
|
|
6134
6891
|
);
|
|
@@ -6170,8 +6927,12 @@ var AbcBitcoinProvider = class extends AbstractChainProvider {
|
|
|
6170
6927
|
} catch (error) {
|
|
6171
6928
|
logger8.error("Transaction broadcast failed:", error.message);
|
|
6172
6929
|
this.emit("error", error);
|
|
6173
|
-
throw
|
|
6174
|
-
|
|
6930
|
+
throw sendFailure(
|
|
6931
|
+
(message, cause) => new BitcoinProviderError(
|
|
6932
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
6933
|
+
message,
|
|
6934
|
+
cause
|
|
6935
|
+
),
|
|
6175
6936
|
"Failed to broadcast transaction",
|
|
6176
6937
|
error
|
|
6177
6938
|
);
|
|
@@ -6659,6 +7420,20 @@ var AbcSolanaProvider = class extends AbstractChainProvider {
|
|
|
6659
7420
|
"Wallet not connected"
|
|
6660
7421
|
);
|
|
6661
7422
|
}
|
|
7423
|
+
validateAmount(params.amount);
|
|
7424
|
+
const apiNetwork = this.getSigningNetwork();
|
|
7425
|
+
let decimals = NATIVE_DECIMALS.solana;
|
|
7426
|
+
if (params.mintAddress) {
|
|
7427
|
+
const walletscanApi = createWalletscanApi();
|
|
7428
|
+
const tokenMeta = await walletscanApi.getContractTokenWithTimeout({
|
|
7429
|
+
contractAddress: params.mintAddress,
|
|
7430
|
+
networks: apiNetwork
|
|
7431
|
+
});
|
|
7432
|
+
if (tokenMeta?.decimals == null)
|
|
7433
|
+
throw new Error("SPL token decimals are missing or invalid");
|
|
7434
|
+
decimals = tokenMeta.decimals;
|
|
7435
|
+
}
|
|
7436
|
+
const rawAmount = toSplRawAmount(params.amount, decimals);
|
|
6662
7437
|
try {
|
|
6663
7438
|
const symbol = params.mintAddress ? "SPL" : "SOL";
|
|
6664
7439
|
await this.callInterceptor({
|
|
@@ -6690,16 +7465,8 @@ var AbcSolanaProvider = class extends AbstractChainProvider {
|
|
|
6690
7465
|
network: this.wallet.network,
|
|
6691
7466
|
hasPinHash: !!pinHash
|
|
6692
7467
|
});
|
|
6693
|
-
const apiNetwork = this.wallet.network === "solana" ? "solana" : "solana_devnet";
|
|
6694
7468
|
this.showPendingTx({ network: apiNetwork, chain: "solana" });
|
|
6695
7469
|
if (params.mintAddress) {
|
|
6696
|
-
const walletscanApi = createWalletscanApi();
|
|
6697
|
-
const tokenMeta = await walletscanApi.getContractTokenWithTimeout({
|
|
6698
|
-
contractAddress: params.mintAddress,
|
|
6699
|
-
networks: apiNetwork
|
|
6700
|
-
});
|
|
6701
|
-
const decimals = tokenMeta?.decimals ?? 9;
|
|
6702
|
-
const rawAmount = Math.floor(params.amount * 10 ** decimals);
|
|
6703
7470
|
const result2 = await api.solana.transfer({
|
|
6704
7471
|
kind: "spl",
|
|
6705
7472
|
toAddress: params.toAddress,
|
|
@@ -6714,8 +7481,7 @@ var AbcSolanaProvider = class extends AbstractChainProvider {
|
|
|
6714
7481
|
this.updateSolanaTransactionResult(result2, apiNetwork);
|
|
6715
7482
|
return { signature: result2.txHash };
|
|
6716
7483
|
}
|
|
6717
|
-
const
|
|
6718
|
-
const amountLamports = params.amount * LAMPORTS_PER_SOL;
|
|
7484
|
+
const amountLamports = rawAmount.toString();
|
|
6719
7485
|
logger10.info("native transfer request:", {
|
|
6720
7486
|
toAddress: params.toAddress,
|
|
6721
7487
|
amountLamports: String(amountLamports),
|
|
@@ -6748,8 +7514,12 @@ var AbcSolanaProvider = class extends AbstractChainProvider {
|
|
|
6748
7514
|
throw error;
|
|
6749
7515
|
}
|
|
6750
7516
|
this.emit("error", error);
|
|
6751
|
-
throw
|
|
6752
|
-
|
|
7517
|
+
throw sendFailure(
|
|
7518
|
+
(message, cause) => new SolanaProviderError(
|
|
7519
|
+
ProviderErrorCode.INTERNAL_ERROR,
|
|
7520
|
+
message,
|
|
7521
|
+
cause
|
|
7522
|
+
),
|
|
6753
7523
|
"Failed to transfer",
|
|
6754
7524
|
error
|
|
6755
7525
|
);
|
|
@@ -7006,6 +7776,11 @@ ${msgBytes.length}`
|
|
|
7006
7776
|
"Wallet not connected"
|
|
7007
7777
|
);
|
|
7008
7778
|
}
|
|
7779
|
+
const txType = params.contractAddress ? "TRC20" : "NATIVE";
|
|
7780
|
+
const amountRaw = toBaseUnits(
|
|
7781
|
+
params.amount,
|
|
7782
|
+
txType === "NATIVE" ? NATIVE_DECIMALS.tron : params.decimals
|
|
7783
|
+
).toString();
|
|
7009
7784
|
try {
|
|
7010
7785
|
const tokenMetadata = await this.fetchTokenMetadata(
|
|
7011
7786
|
params.contractAddress
|
|
@@ -7032,22 +7807,7 @@ ${msgBytes.length}`
|
|
|
7032
7807
|
"PIN hash not found. Please login again."
|
|
7033
7808
|
);
|
|
7034
7809
|
}
|
|
7035
|
-
|
|
7036
|
-
let amountRaw;
|
|
7037
|
-
if (txType === "NATIVE") {
|
|
7038
|
-
amountRaw = Math.floor(
|
|
7039
|
-
Number.parseFloat(params.amount) * 1e6
|
|
7040
|
-
).toString();
|
|
7041
|
-
logger11.debug(`Converting ${params.amount} TRX -> ${amountRaw} SUN`);
|
|
7042
|
-
} else {
|
|
7043
|
-
const decimals = params.decimals ?? 6;
|
|
7044
|
-
amountRaw = Math.floor(
|
|
7045
|
-
Number.parseFloat(params.amount) * 10 ** decimals
|
|
7046
|
-
).toString();
|
|
7047
|
-
logger11.debug(
|
|
7048
|
-
`Converting ${params.amount} -> ${amountRaw} (decimals: ${decimals})`
|
|
7049
|
-
);
|
|
7050
|
-
}
|
|
7810
|
+
logger11.debug(`Converted ${params.amount} -> ${amountRaw} base units`);
|
|
7051
7811
|
const email = getCredentialManager().getEmail() || void 0;
|
|
7052
7812
|
const request = txType === "NATIVE" ? {
|
|
7053
7813
|
kind: "native",
|
|
@@ -7063,6 +7823,7 @@ ${msgBytes.length}`
|
|
|
7063
7823
|
toAddress: params.toAddress,
|
|
7064
7824
|
contractAddress: params.contractAddress,
|
|
7065
7825
|
amount: amountRaw,
|
|
7826
|
+
decimals: params.decimals,
|
|
7066
7827
|
feeLimit: params.feeLimit,
|
|
7067
7828
|
pin: pinHash || void 0,
|
|
7068
7829
|
waitForConfirmation: true,
|
|
@@ -7097,15 +7858,19 @@ ${msgBytes.length}`
|
|
|
7097
7858
|
errorMessage: error.message
|
|
7098
7859
|
});
|
|
7099
7860
|
if (error.message?.includes("insufficient")) {
|
|
7100
|
-
throw
|
|
7101
|
-
|
|
7861
|
+
throw sendFailure(
|
|
7862
|
+
(message, cause) => new TronProviderError(
|
|
7863
|
+
ProviderErrorCode.INSUFFICIENT_FUNDS,
|
|
7864
|
+
message,
|
|
7865
|
+
cause
|
|
7866
|
+
),
|
|
7102
7867
|
"Insufficient TRX balance",
|
|
7103
7868
|
error
|
|
7104
7869
|
);
|
|
7105
7870
|
}
|
|
7106
7871
|
this.emit("error", error);
|
|
7107
|
-
throw
|
|
7108
|
-
ProviderErrorCode.INTERNAL_ERROR,
|
|
7872
|
+
throw sendFailure(
|
|
7873
|
+
(message, cause) => new TronProviderError(ProviderErrorCode.INTERNAL_ERROR, message, cause),
|
|
7109
7874
|
error.message || "Failed to send TRON transaction",
|
|
7110
7875
|
error
|
|
7111
7876
|
);
|
|
@@ -7132,7 +7897,7 @@ ${msgBytes.length}`
|
|
|
7132
7897
|
const blockNumber = info?.blockNumber ?? info?.result?.blockNumber ?? null;
|
|
7133
7898
|
const rcpt = info?.receipt ?? info?.result?.receipt;
|
|
7134
7899
|
const ret = tx?.ret ?? tx?.result?.ret;
|
|
7135
|
-
const contractRet = Array.isArray(ret) ? ret[0]?.contractRet : void 0;
|
|
7900
|
+
const contractRet = (Array.isArray(ret) ? ret[0]?.contractRet : void 0) ?? rcpt?.result;
|
|
7136
7901
|
receipt = {
|
|
7137
7902
|
status: contractRet === "SUCCESS" ? 1 : contractRet ? 0 : null,
|
|
7138
7903
|
blockNumber,
|
|
@@ -7154,8 +7919,15 @@ var logger12 = createLogger("XrplProvider");
|
|
|
7154
7919
|
function isTalkenApiClient3(client) {
|
|
7155
7920
|
return typeof client?.xrp?.transferXrp === "function";
|
|
7156
7921
|
}
|
|
7157
|
-
var XRP_DECIMALS =
|
|
7158
|
-
|
|
7922
|
+
var XRP_DECIMALS = NATIVE_DECIMALS.xrpl;
|
|
7923
|
+
function classifyXrplSubmission(result) {
|
|
7924
|
+
const { engineResult } = result;
|
|
7925
|
+
if (engineResult === "terQUEUED" || result.submissionStatus === "queued")
|
|
7926
|
+
return "pending";
|
|
7927
|
+
if (!engineResult || engineResult === "tesSUCCESS")
|
|
7928
|
+
return "applied";
|
|
7929
|
+
return "rejected";
|
|
7930
|
+
}
|
|
7159
7931
|
var XRPL_NETWORKS = {
|
|
7160
7932
|
mainnet: {
|
|
7161
7933
|
name: "XRP",
|
|
@@ -7226,8 +7998,15 @@ var AbcXrplProvider = class extends AbstractChainProvider {
|
|
|
7226
7998
|
"Wallet not connected"
|
|
7227
7999
|
);
|
|
7228
8000
|
}
|
|
8001
|
+
const isNative = !params.currency;
|
|
8002
|
+
let amountRaw;
|
|
8003
|
+
if (isNative) {
|
|
8004
|
+
amountRaw = toBaseUnits(params.amount, XRP_DECIMALS).toString();
|
|
8005
|
+
} else {
|
|
8006
|
+
validateAmount(params.amount);
|
|
8007
|
+
amountRaw = params.amount;
|
|
8008
|
+
}
|
|
7229
8009
|
try {
|
|
7230
|
-
const isNative = !params.currency;
|
|
7231
8010
|
const symbol = isNative ? "XRP" : params.currency;
|
|
7232
8011
|
await this.callInterceptor({
|
|
7233
8012
|
chain: "xrpl",
|
|
@@ -7250,15 +8029,7 @@ var AbcXrplProvider = class extends AbstractChainProvider {
|
|
|
7250
8029
|
);
|
|
7251
8030
|
}
|
|
7252
8031
|
const email = getCredentialManager().getEmail() || void 0;
|
|
7253
|
-
|
|
7254
|
-
if (isNative) {
|
|
7255
|
-
amountRaw = Math.floor(
|
|
7256
|
-
Number.parseFloat(params.amount) * XRP_DROPS_PER_UNIT
|
|
7257
|
-
).toString();
|
|
7258
|
-
logger12.debug(`Converting ${params.amount} XRP -> ${amountRaw} drops`);
|
|
7259
|
-
} else {
|
|
7260
|
-
amountRaw = params.amount;
|
|
7261
|
-
}
|
|
8032
|
+
logger12.debug(`Converted ${params.amount} -> ${amountRaw}`);
|
|
7262
8033
|
const request = {
|
|
7263
8034
|
kind: isNative ? "native" : "fungible",
|
|
7264
8035
|
network: this.network.type,
|
|
@@ -7276,19 +8047,19 @@ var AbcXrplProvider = class extends AbstractChainProvider {
|
|
|
7276
8047
|
const result = await api.xrp.transferXrp(request);
|
|
7277
8048
|
const txHash = result.txHash;
|
|
7278
8049
|
const engineResult = result.engineResult;
|
|
7279
|
-
const
|
|
8050
|
+
const outcome = classifyXrplSubmission(result);
|
|
7280
8051
|
this.updateTxResult({
|
|
7281
8052
|
txHash,
|
|
7282
8053
|
network: this.network.type,
|
|
7283
8054
|
chain: "xrpl",
|
|
7284
8055
|
receipt: {
|
|
7285
|
-
status:
|
|
8056
|
+
status: { applied: 1, pending: null, rejected: 0 }[outcome],
|
|
7286
8057
|
blockNumber: null,
|
|
7287
8058
|
gasUsed: null
|
|
7288
8059
|
},
|
|
7289
8060
|
explorerUrl: `${this.network.explorer}/tx/${txHash}`
|
|
7290
8061
|
});
|
|
7291
|
-
if (
|
|
8062
|
+
if (outcome === "rejected") {
|
|
7292
8063
|
logger12.error(`XRPL transaction failed on-ledger: ${engineResult}`);
|
|
7293
8064
|
throw new XrplProviderError(
|
|
7294
8065
|
ProviderErrorCode.INTERNAL_ERROR,
|
|
@@ -7320,8 +8091,8 @@ var AbcXrplProvider = class extends AbstractChainProvider {
|
|
|
7320
8091
|
errorMessage: error.message
|
|
7321
8092
|
});
|
|
7322
8093
|
this.emit("error", error);
|
|
7323
|
-
throw
|
|
7324
|
-
ProviderErrorCode.INTERNAL_ERROR,
|
|
8094
|
+
throw sendFailure(
|
|
8095
|
+
(message, cause) => new XrplProviderError(ProviderErrorCode.INTERNAL_ERROR, message, cause),
|
|
7325
8096
|
error.message || "Failed to send XRPL transaction",
|
|
7326
8097
|
error
|
|
7327
8098
|
);
|
|
@@ -7797,6 +8568,8 @@ export {
|
|
|
7797
8568
|
getGaslessConfig,
|
|
7798
8569
|
resolveFeeTokensFromConfig,
|
|
7799
8570
|
getSharedGaslessFeeService,
|
|
8571
|
+
validateAmount,
|
|
8572
|
+
toSplRawAmount,
|
|
7800
8573
|
checkDelegation,
|
|
7801
8574
|
ensureDelegationCleared,
|
|
7802
8575
|
GaslessTransferService,
|