@talken/talkenkit 2.8.5 → 2.8.7
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/{abcWallet-EOHU5AIB.js → abcWallet-WTHSP3A6.js} +22 -25
- package/dist/{chunk-WGSS57V6.js → chunk-S3KOGN7P.js} +2540 -715
- package/dist/gasless/api/ChainConfigApi.d.ts +2 -2
- package/dist/gasless/index.d.ts +1 -1
- package/dist/gasless/services/GaslessTransferService.d.ts +4 -3
- package/dist/gasless/signer/AbcWaasSigner.d.ts +9 -0
- package/dist/gasless/signer/GaslessSigner.d.ts +10 -0
- package/dist/gasless/signer/WagmiSigner.d.ts +40 -0
- package/dist/gasless/signer/index.d.ts +1 -1
- package/dist/gasless/utils/delegationGuard.d.ts +11 -11
- package/dist/gasless/utils/revokeDelegation.d.ts +22 -23
- package/dist/hooks/useMultiChainBalances.d.ts +2 -0
- package/dist/index.css +5 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1279 -584
- package/dist/services/AbcAuthService.d.ts +12 -1
- package/dist/solana/clusterIdentity.d.ts +5 -0
- package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.d.ts +0 -1
- package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/AbstractChainProvider.d.ts +11 -0
- package/dist/wallets/walletConnectors/abcWallet/AbstractChainProvider.js +5 -2
- package/dist/wallets/walletConnectors/abcWallet/StorageService.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.d.ts +2 -0
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +7 -5
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +10 -9
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +23 -21
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +12 -11
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +26 -24
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +3 -0
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +183 -62
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +10 -9
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +24 -22
- package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/abcXrplProvider.js +10 -9
- package/dist/wallets/walletConnectors/abcWallet/api/AccessKeySessionBinding.d.ts +10 -0
- package/dist/wallets/walletConnectors/abcWallet/api/AccessKeySessionBinding.js +13 -0
- package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +5 -2
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +5 -1
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +5 -1
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +34 -12
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +19 -16
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.d.ts +6 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiSingleton.js +10 -1
- package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +5 -2
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +13 -3
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +26 -23
- package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.d.ts +20 -10
- package/dist/wallets/walletConnectors/abcWallet/api/modules/auth.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/api/modules/bitcoin.js +11 -9
- package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/modules/evm.js +10 -8
- package/dist/wallets/walletConnectors/abcWallet/api/modules/executeBodies.js +4 -3
- package/dist/wallets/walletConnectors/abcWallet/api/modules/signBodies.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/modules/signingRefresh.js +6 -5
- package/dist/wallets/walletConnectors/abcWallet/api/modules/solana.js +6 -5
- package/dist/wallets/walletConnectors/abcWallet/api/modules/tron.js +10 -8
- package/dist/wallets/walletConnectors/abcWallet/api/modules/wallet.d.ts +2 -1
- 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.js +10 -8
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +18 -6
- package/dist/wallets/walletConnectors/abcWallet/constants.js +13 -3
- package/dist/wallets/walletConnectors/abcWallet/index.d.ts +1 -0
- package/dist/wallets/walletConnectors/abcWallet/index.js +40 -38
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +11 -3
- package/dist/wallets/walletConnectors/abcWallet/types/auth.types.d.ts +75 -0
- package/dist/wallets/walletConnectors/abcWallet/types/error.types.d.ts +2 -0
- package/dist/wallets/walletConnectors/abcWallet/types/error.types.js +5 -3
- package/dist/wallets/walletConnectors/abcWallet/types.js +5 -3
- package/dist/wallets/walletConnectors/abcWallet/utils.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +6 -5
- package/dist/wallets/walletConnectors/chunk-2YCHXOLC.js +53 -0
- package/dist/wallets/walletConnectors/{chunk-6MZWQBNQ.js → chunk-3RUQ4ARU.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-MNGSJBPX.js → chunk-3XZJNLAA.js} +128 -77
- package/dist/wallets/walletConnectors/chunk-4UMY2AY7.js +414 -0
- package/dist/wallets/walletConnectors/chunk-5GTFKQGQ.js +739 -0
- package/dist/wallets/walletConnectors/{chunk-XGQUYXTL.js → chunk-5KPLYJOO.js} +12 -407
- package/dist/wallets/walletConnectors/{chunk-EGLT3GPM.js → chunk-5V5TLGH6.js} +58 -7
- package/dist/wallets/walletConnectors/{chunk-SUPFF4EQ.js → chunk-5ZTGAJ4K.js} +538 -191
- package/dist/wallets/walletConnectors/{chunk-PL56SINL.js → chunk-6GE2YBW5.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-M4SNNQU2.js → chunk-AROBVCG2.js} +29 -6
- package/dist/wallets/walletConnectors/{chunk-OTLZVWY7.js → chunk-BAKRM7LQ.js} +3 -1
- package/dist/wallets/walletConnectors/{chunk-6X2XITQP.js → chunk-BGDDDPVU.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-365TL36N.js → chunk-C3MTWYLE.js} +106 -53
- package/dist/wallets/walletConnectors/{chunk-UHVJ6AF6.js → chunk-CBXCYWLB.js} +6 -5
- package/dist/wallets/walletConnectors/{chunk-5SRSGEZR.js → chunk-DT2L5ADS.js} +35 -10
- package/dist/wallets/walletConnectors/{chunk-DKMR2ML5.js → chunk-DUEQONAP.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-ZBI7MSWF.js → chunk-EJB7HH6N.js} +7 -5
- package/dist/wallets/walletConnectors/{chunk-OTLPTGHO.js → chunk-EMFKD777.js} +4 -2
- package/dist/wallets/walletConnectors/{chunk-743DKBGG.js → chunk-F2TFFXON.js} +72 -20
- package/dist/wallets/walletConnectors/chunk-GM6AIRNT.js +71 -0
- package/dist/wallets/walletConnectors/chunk-H63QJV3U.js +84 -0
- package/dist/wallets/walletConnectors/chunk-HEZOSHLH.js +446 -0
- package/dist/wallets/walletConnectors/{chunk-GO6HUJTP.js → chunk-HJAUM3KX.js} +6 -6
- package/dist/wallets/walletConnectors/chunk-ICSPFTBY.js +246 -0
- package/dist/wallets/walletConnectors/{chunk-OMZSFUVN.js → chunk-LGFHSL7G.js} +7 -3
- package/dist/wallets/walletConnectors/{chunk-V6R6WDOQ.js → chunk-MRUBFVXX.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-MZFLUT3E.js +243 -0
- package/dist/wallets/walletConnectors/chunk-N7ACKYTK.js +291 -0
- package/dist/wallets/walletConnectors/{chunk-RSR35XOZ.js → chunk-NNLRIZSK.js} +11 -7
- package/dist/wallets/walletConnectors/chunk-NWHJRPZL.js +158 -0
- package/dist/wallets/walletConnectors/{chunk-P64PMEPU.js → chunk-O77UF634.js} +66 -12
- package/dist/wallets/walletConnectors/{chunk-4CKIGJZD.js → chunk-PK5XVWRF.js} +81 -32
- package/dist/wallets/walletConnectors/{chunk-DFG3BSSC.js → chunk-PS66FDPT.js} +79 -30
- package/dist/wallets/walletConnectors/chunk-PWJLUT4Z.js +2629 -0
- package/dist/wallets/walletConnectors/chunk-QCVDHC6P.js +210 -0
- package/dist/wallets/walletConnectors/{chunk-HMIFFMGK.js → chunk-QNZQZ7IH.js} +26 -16
- package/dist/wallets/walletConnectors/chunk-RTECHRPH.js +154 -0
- package/dist/wallets/walletConnectors/{chunk-F4JUKZBB.js → chunk-RU6FIXMD.js} +3 -3
- package/dist/wallets/walletConnectors/{chunk-ZWIAZOVB.js → chunk-RUYSIXR3.js} +6 -4
- package/dist/wallets/walletConnectors/{chunk-TRFREYPH.js → chunk-S75DVWSP.js} +39 -9
- package/dist/wallets/walletConnectors/chunk-SN2BNZTO.js +739 -0
- package/dist/wallets/walletConnectors/{chunk-YPMD3ZHF.js → chunk-SRXI2XF5.js} +80 -44
- package/dist/wallets/walletConnectors/chunk-TOX35ET4.js +307 -0
- package/dist/wallets/walletConnectors/{chunk-XPZCOEQL.js → chunk-TPLIG5I7.js} +35 -7
- package/dist/wallets/walletConnectors/{chunk-TP4BDK7W.js → chunk-UVPRZEPJ.js} +5 -1
- package/dist/wallets/walletConnectors/{chunk-SORKIBWX.js → chunk-WUNGUZIQ.js} +4 -5
- package/dist/wallets/walletConnectors/{chunk-2OHHFQQ7.js → chunk-WZMAZENY.js} +3 -1
- package/dist/wallets/walletConnectors/chunk-XPOLIWQQ.js +200 -0
- package/dist/wallets/walletConnectors/{chunk-DRL2CDHT.js → chunk-YFYJ2CFB.js} +80 -44
- package/dist/wallets/walletConnectors/chunk-ZPICFPYN.js +79 -0
- package/dist/wallets/walletConnectors/index.js +67 -65
- package/package.json +1 -1
- package/dist/AbcCredentialManager-WZBF3GHF.js +0 -7
- package/dist/TalkenApiSingleton-TECFDCT4.js +0 -9
- package/dist/chunk-CUPPBGFC.js +0 -460
- package/dist/chunk-R6ZE7JAZ.js +0 -15
- package/dist/wallets/walletConnectors/chunk-2M6E3YXU.js +0 -382
- package/dist/wallets/walletConnectors/chunk-3DHUDD4U.js +0 -132
- package/dist/wallets/walletConnectors/chunk-GAJ4FJTW.js +0 -382
- package/dist/wallets/walletConnectors/chunk-R6ZE7JAZ.js +0 -15
|
@@ -4,22 +4,18 @@ import {
|
|
|
4
4
|
} from "./chunk-OESFVVLA.js";
|
|
5
5
|
import {
|
|
6
6
|
isSigningCredentialError
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ZPICFPYN.js";
|
|
8
8
|
import {
|
|
9
|
-
getChainKey,
|
|
10
|
-
getExplorerTxUrl,
|
|
11
|
-
getNetworkName,
|
|
12
9
|
toBroadcastBody
|
|
13
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4UMY2AY7.js";
|
|
14
11
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
getChainKey,
|
|
13
|
+
getExplorerTxUrl,
|
|
14
|
+
getNetworkName
|
|
15
|
+
} from "./chunk-5KPLYJOO.js";
|
|
17
16
|
import {
|
|
18
17
|
AbstractChainProvider
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import {
|
|
21
|
-
getTalkenApiClient
|
|
22
|
-
} from "./chunk-R6ZE7JAZ.js";
|
|
18
|
+
} from "./chunk-ICSPFTBY.js";
|
|
23
19
|
import {
|
|
24
20
|
ProviderErrorCode,
|
|
25
21
|
ProviderRpcError
|
|
@@ -30,11 +26,22 @@ import {
|
|
|
30
26
|
import {
|
|
31
27
|
hexToNumber,
|
|
32
28
|
numberToHex
|
|
33
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-RU6FIXMD.js";
|
|
30
|
+
import {
|
|
31
|
+
TalkenApiError
|
|
32
|
+
} from "./chunk-UVPRZEPJ.js";
|
|
33
|
+
import {
|
|
34
|
+
getTalkenApiClient,
|
|
35
|
+
ownsTalkenApiStorage
|
|
36
|
+
} from "./chunk-2YCHXOLC.js";
|
|
37
|
+
import {
|
|
38
|
+
getCredentialManager
|
|
39
|
+
} from "./chunk-WUNGUZIQ.js";
|
|
34
40
|
import {
|
|
35
41
|
SEND_REQUEST_TIMEOUT,
|
|
36
|
-
TALKEN_API_ENDPOINTS
|
|
37
|
-
|
|
42
|
+
TALKEN_API_ENDPOINTS,
|
|
43
|
+
chainTokenBalancesPath
|
|
44
|
+
} from "./chunk-TPLIG5I7.js";
|
|
38
45
|
|
|
39
46
|
// src/wallets/walletConnectors/abcWallet/abcProvider.ts
|
|
40
47
|
import { parseGwei } from "viem";
|
|
@@ -114,7 +121,7 @@ var ChainConfigApi = class {
|
|
|
114
121
|
}
|
|
115
122
|
/**
|
|
116
123
|
* Get runtime chain config (eip7702Delegate, token addresses, etc.).
|
|
117
|
-
* GET /
|
|
124
|
+
* GET /chains/{chainKey}
|
|
118
125
|
*
|
|
119
126
|
* Cached for 60 minutes.
|
|
120
127
|
*/
|
|
@@ -137,7 +144,7 @@ var ChainConfigApi = class {
|
|
|
137
144
|
}
|
|
138
145
|
/**
|
|
139
146
|
* Get token balances for an address on a chain.
|
|
140
|
-
* GET /
|
|
147
|
+
* GET /chains/{chainKey}/accounts/{address}/token-balances
|
|
141
148
|
*
|
|
142
149
|
* Cached for 30 seconds.
|
|
143
150
|
*/
|
|
@@ -151,7 +158,7 @@ var ChainConfigApi = class {
|
|
|
151
158
|
if (!api)
|
|
152
159
|
throw new Error("TalkenApiClient not initialized");
|
|
153
160
|
const response = await api.get(
|
|
154
|
-
|
|
161
|
+
chainTokenBalancesPath(chainKey, address)
|
|
155
162
|
);
|
|
156
163
|
const balances = Array.isArray(response) ? response : [];
|
|
157
164
|
this.balanceCache.set(cacheKey, {
|
|
@@ -590,15 +597,26 @@ async function recoverYParity(hash, r, s, expectedAddress) {
|
|
|
590
597
|
}
|
|
591
598
|
throw new Error("Failed to recover yParity from tx signature");
|
|
592
599
|
}
|
|
593
|
-
async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
600
|
+
async function sendRevokeTx(userAddress, chainKey, chainId, assertOrigin) {
|
|
601
|
+
assertOrigin?.();
|
|
594
602
|
const api = getTalkenApiClient();
|
|
595
603
|
if (!api)
|
|
596
604
|
throw new Error("TalkenApiClient not initialized");
|
|
605
|
+
const revision = api.getSessionRevision();
|
|
606
|
+
const assertCurrent = () => {
|
|
607
|
+
assertOrigin?.();
|
|
608
|
+
if (getTalkenApiClient() !== api || api.getSessionRevision() !== revision || !ownsTalkenApiStorage(api))
|
|
609
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
610
|
+
if (api.isAccessKeyMode() && api.getAuthenticatedWalletSession()?.wallets.evm !== userAddress.toLowerCase())
|
|
611
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
612
|
+
};
|
|
613
|
+
assertCurrent();
|
|
597
614
|
const credentialManager = getCredentialManager();
|
|
598
615
|
const pinHash = credentialManager.getPinHash() || "";
|
|
599
|
-
const email = credentialManager.getEmail() ?? void 0;
|
|
616
|
+
const email = api.isAccessKeyMode() ? api.getAuthenticatedWalletSession()?.user.email ?? void 0 : credentialManager.getEmail() ?? void 0;
|
|
600
617
|
const network = getNetworkName(chainId);
|
|
601
618
|
const nonceResult = await api.evm.getNonce(network, userAddress);
|
|
619
|
+
assertCurrent();
|
|
602
620
|
const nonceRaw = nonceResult?.data?.result ?? nonceResult?.nonce ?? nonceResult?.result ?? nonceResult;
|
|
603
621
|
const currentNonce = Number(nonceRaw);
|
|
604
622
|
if (!Number.isFinite(currentNonce)) {
|
|
@@ -615,6 +633,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
|
615
633
|
pin: pinHash,
|
|
616
634
|
...email && { email }
|
|
617
635
|
});
|
|
636
|
+
assertCurrent();
|
|
618
637
|
const auth = authResult?.authorization ?? authResult;
|
|
619
638
|
if (!auth?.r || !auth?.s) {
|
|
620
639
|
throw new Error("signAuthorization returned empty r/s for revoke");
|
|
@@ -627,6 +646,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
|
627
646
|
let maxPriorityFeePerGas = DEFAULT_MAX_PRIORITY_FEE;
|
|
628
647
|
try {
|
|
629
648
|
const suggested = await api.evm.getGasSuggested(network);
|
|
649
|
+
assertCurrent();
|
|
630
650
|
if (suggested?.high) {
|
|
631
651
|
maxPriorityFeePerGas = BigInt(
|
|
632
652
|
Math.round(Number(suggested.high.suggestedMaxPriorityFeePerGas) * 1e9)
|
|
@@ -636,6 +656,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
|
636
656
|
);
|
|
637
657
|
}
|
|
638
658
|
} catch {
|
|
659
|
+
assertCurrent();
|
|
639
660
|
}
|
|
640
661
|
const authEntry = [
|
|
641
662
|
rlpUint(chainId),
|
|
@@ -669,6 +690,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
|
669
690
|
...network && { network },
|
|
670
691
|
...email && { email }
|
|
671
692
|
});
|
|
693
|
+
assertCurrent();
|
|
672
694
|
const signStr = signResult?.signstr ?? signResult?.signature ?? "";
|
|
673
695
|
if (!signStr)
|
|
674
696
|
throw new Error("signHash returned empty signature");
|
|
@@ -696,6 +718,7 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
|
696
718
|
txSRaw,
|
|
697
719
|
userAddress
|
|
698
720
|
);
|
|
721
|
+
assertCurrent();
|
|
699
722
|
const signedFields = [...unsignedFields, txYParity ? "0x01" : "0x", txR, txS];
|
|
700
723
|
const signedTx = `0x04${toRlp(signedFields).slice(2)}`;
|
|
701
724
|
const { txHash } = await api.post(
|
|
@@ -703,31 +726,137 @@ async function sendRevokeTx(userAddress, chainKey, chainId) {
|
|
|
703
726
|
toBroadcastBody(chainKey, signedTx),
|
|
704
727
|
{ timeout: SEND_REQUEST_TIMEOUT }
|
|
705
728
|
);
|
|
729
|
+
assertCurrent();
|
|
706
730
|
console.log(`[RevokeDelegation] Revoke tx broadcast: ${txHash}`);
|
|
707
731
|
return { txHash };
|
|
708
732
|
}
|
|
733
|
+
function unsupportedRevoke(message) {
|
|
734
|
+
return new TalkenApiError("EXTERNAL_REVOKE_UNSUPPORTED", message, 400);
|
|
735
|
+
}
|
|
736
|
+
function unsupportedAuthorization(error) {
|
|
737
|
+
let current = error;
|
|
738
|
+
for (let depth = 0; current && typeof current === "object" && depth < 5; depth++) {
|
|
739
|
+
const value = current;
|
|
740
|
+
if (value.name === "AccountTypeNotSupportedError" || value.name === "MethodNotSupportedRpcError" || value.name === "MethodNotFoundRpcError" || value.code === -32601 || value.code === 4200)
|
|
741
|
+
return true;
|
|
742
|
+
current = value.cause;
|
|
743
|
+
}
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
function normalizeRevokeRejection(error) {
|
|
747
|
+
const topCode = error?.code;
|
|
748
|
+
if (topCode === 4001 || topCode === "AUTH_SESSION_CHANGED" || topCode === "AUTH_SESSION_UNBOUND")
|
|
749
|
+
return error;
|
|
750
|
+
let current = error;
|
|
751
|
+
let rejected = false;
|
|
752
|
+
for (let depth = 0; current && typeof current === "object" && depth < 5; depth++) {
|
|
753
|
+
const value = current;
|
|
754
|
+
if (value.possibleTxHash || value.txHash || value.transactionHash || value.details?.broadcast === true || value.details?.broadcast === "unknown")
|
|
755
|
+
return error;
|
|
756
|
+
if (value.code === 4001)
|
|
757
|
+
rejected = true;
|
|
758
|
+
current = value.cause;
|
|
759
|
+
}
|
|
760
|
+
return rejected ? Object.assign(new Error("User rejected the external revoke request."), {
|
|
761
|
+
code: 4001,
|
|
762
|
+
cause: error
|
|
763
|
+
}) : error;
|
|
764
|
+
}
|
|
709
765
|
async function sendRevokeViaWalletClient(walletClient, chainId, userAddress) {
|
|
710
|
-
if (!
|
|
766
|
+
if (!walletClient || typeof walletClient.assertSessionCurrent !== "function")
|
|
767
|
+
throw unsupportedRevoke(
|
|
768
|
+
"External revoke requires an originating account and network guard."
|
|
769
|
+
);
|
|
770
|
+
const assertCurrent = () => walletClient.assertSessionCurrent();
|
|
771
|
+
assertCurrent();
|
|
772
|
+
if (typeof walletClient.getTransactionCount !== "function" || typeof walletClient.signAuthorization !== "function" || typeof walletClient.sendTransaction !== "function" || walletClient.waitForTransactionReceipt !== void 0 && typeof walletClient.waitForTransactionReceipt !== "function")
|
|
773
|
+
throw unsupportedRevoke(
|
|
774
|
+
"External revoke requires pending nonce, authorization signing and transaction capabilities."
|
|
775
|
+
);
|
|
776
|
+
if (!isAddress(userAddress))
|
|
711
777
|
throw new Error(`Invalid address for revoke: ${userAddress}`);
|
|
778
|
+
if (!Number.isSafeInteger(chainId) || chainId <= 0)
|
|
779
|
+
throw unsupportedRevoke(
|
|
780
|
+
"External revoke requires an explicit valid chain."
|
|
781
|
+
);
|
|
782
|
+
const guarded = async (operation) => {
|
|
783
|
+
assertCurrent();
|
|
784
|
+
try {
|
|
785
|
+
const result = await operation();
|
|
786
|
+
assertCurrent();
|
|
787
|
+
return result;
|
|
788
|
+
} catch (error) {
|
|
789
|
+
assertCurrent();
|
|
790
|
+
throw error;
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
const nonce = await guarded(
|
|
794
|
+
() => walletClient.getTransactionCount({
|
|
795
|
+
address: userAddress,
|
|
796
|
+
blockTag: "pending"
|
|
797
|
+
})
|
|
798
|
+
);
|
|
799
|
+
if (!Number.isSafeInteger(nonce) || nonce < 0 || nonce >= Number.MAX_SAFE_INTEGER)
|
|
800
|
+
throw unsupportedRevoke(
|
|
801
|
+
"External revoke could not prepare a safe pending nonce."
|
|
802
|
+
);
|
|
803
|
+
let raw;
|
|
804
|
+
try {
|
|
805
|
+
raw = await guarded(
|
|
806
|
+
() => walletClient.signAuthorization({
|
|
807
|
+
contractAddress: ZERO_ADDRESS2,
|
|
808
|
+
chainId,
|
|
809
|
+
nonce: nonce + 1,
|
|
810
|
+
executor: "self"
|
|
811
|
+
})
|
|
812
|
+
);
|
|
813
|
+
} catch (error) {
|
|
814
|
+
const refusal = normalizeRevokeRejection(error);
|
|
815
|
+
if (refusal !== error)
|
|
816
|
+
throw refusal;
|
|
817
|
+
if (["AUTH_SESSION_CHANGED", "AUTH_SESSION_UNBOUND", 4001].includes(
|
|
818
|
+
error?.code ?? ""
|
|
819
|
+
))
|
|
820
|
+
throw error;
|
|
821
|
+
if (unsupportedAuthorization(error))
|
|
822
|
+
throw unsupportedRevoke(
|
|
823
|
+
"This wallet cannot sign an EIP-7702 revoke authorization."
|
|
824
|
+
);
|
|
825
|
+
throw error;
|
|
826
|
+
}
|
|
827
|
+
const signed = raw;
|
|
828
|
+
const parity = signed?.yParity ?? (signed?.v === BigInt(0) || signed?.v === 0 || signed?.v === BigInt(27) || signed?.v === 27 ? 0 : signed?.v === BigInt(1) || signed?.v === 1 || signed?.v === BigInt(28) || signed?.v === 28 ? 1 : signed?.v);
|
|
829
|
+
if (!signed || signed.address !== ZERO_ADDRESS2 || signed.chainId !== chainId || signed.nonce !== nonce + 1 || typeof signed.r !== "string" || !/^0x[0-9a-fA-F]{1,64}$/.test(signed.r) || typeof signed.s !== "string" || !/^0x[0-9a-fA-F]{1,64}$/.test(signed.s) || parity !== 0 && parity !== 1)
|
|
830
|
+
throw unsupportedRevoke(
|
|
831
|
+
"The wallet returned an invalid EIP-7702 revoke authorization."
|
|
832
|
+
);
|
|
833
|
+
const authorization = {
|
|
834
|
+
address: ZERO_ADDRESS2,
|
|
835
|
+
chainId,
|
|
836
|
+
nonce: nonce + 1,
|
|
837
|
+
r: signed.r,
|
|
838
|
+
s: signed.s,
|
|
839
|
+
yParity: parity
|
|
840
|
+
};
|
|
841
|
+
let txHash;
|
|
842
|
+
try {
|
|
843
|
+
txHash = await guarded(
|
|
844
|
+
() => walletClient.sendTransaction({
|
|
845
|
+
authorizationList: [authorization],
|
|
846
|
+
nonce,
|
|
847
|
+
to: userAddress,
|
|
848
|
+
value: BigInt(0)
|
|
849
|
+
})
|
|
850
|
+
);
|
|
851
|
+
} catch (error) {
|
|
852
|
+
throw normalizeRevokeRejection(error);
|
|
712
853
|
}
|
|
713
|
-
const txHash = await walletClient.sendTransaction({
|
|
714
|
-
authorizationList: [
|
|
715
|
-
{ contractAddress: ZERO_ADDRESS2, chainId }
|
|
716
|
-
],
|
|
717
|
-
to: userAddress,
|
|
718
|
-
value: BigInt(0)
|
|
719
|
-
});
|
|
720
|
-
console.log(`[RevokeDelegation] External wallet revoke tx sent: ${txHash}`);
|
|
721
854
|
if (walletClient.waitForTransactionReceipt) {
|
|
722
|
-
const receipt = await
|
|
723
|
-
hash: txHash
|
|
724
|
-
});
|
|
725
|
-
if (receipt.status === "reverted") {
|
|
726
|
-
throw new Error(`Revoke transaction reverted: ${txHash}`);
|
|
727
|
-
}
|
|
728
|
-
console.log(
|
|
729
|
-
`[RevokeDelegation] External wallet revoke tx confirmed: ${txHash}`
|
|
855
|
+
const receipt = await guarded(
|
|
856
|
+
() => walletClient.waitForTransactionReceipt({ hash: txHash })
|
|
730
857
|
);
|
|
858
|
+
if (receipt.status === "reverted")
|
|
859
|
+
throw new Error(`Revoke transaction reverted: ${txHash}`);
|
|
731
860
|
}
|
|
732
861
|
return { txHash };
|
|
733
862
|
}
|
|
@@ -741,38 +870,56 @@ var _locks = /* @__PURE__ */ new Map();
|
|
|
741
870
|
function lockKey(chainKey, address) {
|
|
742
871
|
return `${chainKey}:${address.toLowerCase()}`;
|
|
743
872
|
}
|
|
744
|
-
async function checkDelegation(chainKey, address) {
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
const response = await api.get(
|
|
751
|
-
`${TALKEN_API_ENDPOINTS.WALLET_CODE}/${encodeURIComponent(chainKey)}/${encodeURIComponent(address)}`
|
|
873
|
+
async function checkDelegation(chainKey, address, delegationClient, assertCurrent) {
|
|
874
|
+
if (!delegationClient || typeof delegationClient.readCode !== "function")
|
|
875
|
+
throw new TalkenApiError(
|
|
876
|
+
"DELEGATION_CONTEXT_REQUIRED",
|
|
877
|
+
"An originating wallet delegation client is required.",
|
|
878
|
+
401
|
|
752
879
|
);
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
880
|
+
assertCurrent?.();
|
|
881
|
+
let rawCode;
|
|
882
|
+
try {
|
|
883
|
+
rawCode = await delegationClient.readCode(chainKey, address);
|
|
884
|
+
} catch (error) {
|
|
885
|
+
assertCurrent?.();
|
|
886
|
+
throw error;
|
|
887
|
+
}
|
|
888
|
+
assertCurrent?.();
|
|
889
|
+
const code = String(rawCode).toLowerCase();
|
|
890
|
+
const hasDelegation = code.startsWith(EIP7702_CODE_PREFIX) && code.length >= EIP7702_CODE_PREFIX.length + 40;
|
|
891
|
+
return {
|
|
892
|
+
hasDelegation,
|
|
893
|
+
code,
|
|
894
|
+
delegateAddress: hasDelegation ? `0x${code.slice(EIP7702_CODE_PREFIX.length, EIP7702_CODE_PREFIX.length + 40)}` : ""
|
|
895
|
+
};
|
|
763
896
|
}
|
|
764
897
|
async function ensureDelegationCleared(chainKey, chainId, address, options) {
|
|
898
|
+
const delegationClient = options?.delegationClient;
|
|
899
|
+
if (!delegationClient)
|
|
900
|
+
throw new TalkenApiError(
|
|
901
|
+
"DELEGATION_CONTEXT_REQUIRED",
|
|
902
|
+
"An originating wallet delegation client is required.",
|
|
903
|
+
401
|
|
904
|
+
);
|
|
905
|
+
const assertCurrent = () => options?.assertSessionCurrent?.();
|
|
906
|
+
const readDelegation = () => checkDelegation(chainKey, address, delegationClient, assertCurrent);
|
|
907
|
+
assertCurrent();
|
|
765
908
|
const key = lockKey(chainKey, address);
|
|
766
909
|
const existing = _locks.get(key);
|
|
767
910
|
if (existing) {
|
|
768
911
|
try {
|
|
769
912
|
await existing;
|
|
913
|
+
assertCurrent();
|
|
770
914
|
return;
|
|
771
915
|
} catch {
|
|
916
|
+
assertCurrent();
|
|
772
917
|
}
|
|
773
918
|
}
|
|
774
919
|
const check = async () => {
|
|
775
|
-
|
|
920
|
+
assertCurrent();
|
|
921
|
+
const initial = await readDelegation();
|
|
922
|
+
assertCurrent();
|
|
776
923
|
if (!initial.hasDelegation)
|
|
777
924
|
return;
|
|
778
925
|
logger.warn(
|
|
@@ -783,9 +930,21 @@ async function ensureDelegationCleared(chainKey, chainId, address, options) {
|
|
|
783
930
|
options.walletClient,
|
|
784
931
|
chainId,
|
|
785
932
|
address
|
|
786
|
-
) : await
|
|
933
|
+
) : delegationClient.revoke ? await delegationClient.revoke(chainKey, chainId, address) : (() => {
|
|
934
|
+
throw new TalkenApiError(
|
|
935
|
+
"EXTERNAL_REVOKE_UNSUPPORTED",
|
|
936
|
+
"This wallet has no delegation revoke capability.",
|
|
937
|
+
400
|
|
938
|
+
);
|
|
939
|
+
})();
|
|
940
|
+
assertCurrent();
|
|
787
941
|
logger.info(`Revoke tx sent: ${txHash}. Polling for clearance...`);
|
|
788
942
|
} catch (revokeErr) {
|
|
943
|
+
assertCurrent();
|
|
944
|
+
if (["AUTH_SESSION_CHANGED", "EXTERNAL_REVOKE_UNSUPPORTED"].includes(
|
|
945
|
+
revokeErr?.code ?? ""
|
|
946
|
+
))
|
|
947
|
+
throw revokeErr;
|
|
789
948
|
if (revokeErr && typeof revokeErr === "object" && "code" in revokeErr && revokeErr.code === 4001) {
|
|
790
949
|
throw revokeErr;
|
|
791
950
|
}
|
|
@@ -794,13 +953,16 @@ async function ensureDelegationCleared(chainKey, chainId, address, options) {
|
|
|
794
953
|
const deadline = Date.now() + POLL_TIMEOUT_MS;
|
|
795
954
|
while (Date.now() < deadline) {
|
|
796
955
|
await new Promise((r) => setTimeout(r, POLL_INTERVAL_MS));
|
|
797
|
-
|
|
956
|
+
assertCurrent();
|
|
957
|
+
const current = await readDelegation();
|
|
958
|
+
assertCurrent();
|
|
798
959
|
if (!current.hasDelegation) {
|
|
799
960
|
logger.info("Delegation cleared");
|
|
800
961
|
return;
|
|
801
962
|
}
|
|
802
963
|
}
|
|
803
964
|
const message = "Previous transaction delegation is still active. Please wait a moment and try again.";
|
|
965
|
+
assertCurrent();
|
|
804
966
|
if (options?.onDelegationError) {
|
|
805
967
|
options.onDelegationError({
|
|
806
968
|
chainId,
|
|
@@ -812,7 +974,8 @@ async function ensureDelegationCleared(chainKey, chainId, address, options) {
|
|
|
812
974
|
throw new Error(message);
|
|
813
975
|
};
|
|
814
976
|
const promise = check().finally(() => {
|
|
815
|
-
_locks.
|
|
977
|
+
if (_locks.get(key) === promise)
|
|
978
|
+
_locks.delete(key);
|
|
816
979
|
});
|
|
817
980
|
_locks.set(key, promise);
|
|
818
981
|
return promise;
|
|
@@ -833,7 +996,14 @@ var Eip7702Service = class {
|
|
|
833
996
|
*/
|
|
834
997
|
async preflight(chainKey, chainId, address, options) {
|
|
835
998
|
try {
|
|
836
|
-
await ensureDelegationCleared(chainKey, chainId, address,
|
|
999
|
+
await ensureDelegationCleared(chainKey, chainId, address, {
|
|
1000
|
+
...options,
|
|
1001
|
+
delegationClient: options?.delegationClient ?? this.signer.getDelegationClient?.(),
|
|
1002
|
+
assertSessionCurrent: () => {
|
|
1003
|
+
this.signer.assertSessionCurrent?.();
|
|
1004
|
+
options?.assertSessionCurrent?.();
|
|
1005
|
+
}
|
|
1006
|
+
});
|
|
837
1007
|
} catch (error) {
|
|
838
1008
|
console.warn(
|
|
839
1009
|
"[Eip7702Service] Pre-flight delegation check failed:",
|
|
@@ -1084,6 +1254,7 @@ var RelayPhase2Error = class extends Error {
|
|
|
1084
1254
|
};
|
|
1085
1255
|
var GaslessTransferService = class {
|
|
1086
1256
|
constructor(deps) {
|
|
1257
|
+
this.assertSessionCurrent = () => this.signer.assertSessionCurrent?.();
|
|
1087
1258
|
this.relayerApi = deps.relayerApi ?? new RelayerApi();
|
|
1088
1259
|
this.signer = deps.signer;
|
|
1089
1260
|
this.walletClient = deps.walletClient;
|
|
@@ -1094,22 +1265,28 @@ var GaslessTransferService = class {
|
|
|
1094
1265
|
});
|
|
1095
1266
|
}
|
|
1096
1267
|
async execute(params, gaslessConfig) {
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1268
|
+
this.assertSessionCurrent();
|
|
1269
|
+
try {
|
|
1270
|
+
switch (params.gaslessMode) {
|
|
1271
|
+
case "generic":
|
|
1272
|
+
return await this.executeGenericRelay(params);
|
|
1273
|
+
case "eip7702-fee":
|
|
1274
|
+
case "eip7702-points":
|
|
1275
|
+
return await this.executeEip7702Relay(params, gaslessConfig);
|
|
1276
|
+
default:
|
|
1277
|
+
throw new Error(`Unknown gasless mode: ${params.gaslessMode}`);
|
|
1278
|
+
}
|
|
1279
|
+
} catch (error) {
|
|
1280
|
+
this.assertSessionCurrent();
|
|
1281
|
+
throw error;
|
|
1105
1282
|
}
|
|
1106
1283
|
}
|
|
1107
1284
|
/**
|
|
1108
1285
|
* Generic 2-phase relay execution.
|
|
1109
1286
|
*
|
|
1110
|
-
* Phase 1: POST /
|
|
1287
|
+
* Phase 1: POST /relay/execute { auth: { method: 'auto' } }
|
|
1111
1288
|
* → Server responds with signatureRequests
|
|
1112
|
-
* Phase 2: Sign all requests → POST /
|
|
1289
|
+
* Phase 2: Sign all requests → POST /relay/execute { requestId, signatures }
|
|
1113
1290
|
* → Server responds with txHash
|
|
1114
1291
|
*/
|
|
1115
1292
|
async executeGenericRelay(params) {
|
|
@@ -1118,14 +1295,24 @@ var GaslessTransferService = class {
|
|
|
1118
1295
|
params.chainKey,
|
|
1119
1296
|
params.chainId,
|
|
1120
1297
|
params.fromAddress,
|
|
1121
|
-
{
|
|
1298
|
+
{
|
|
1299
|
+
walletClient: this.walletClient,
|
|
1300
|
+
assertSessionCurrent: this.assertSessionCurrent,
|
|
1301
|
+
delegationClient: this.signer.getDelegationClient?.()
|
|
1302
|
+
}
|
|
1122
1303
|
);
|
|
1123
1304
|
} catch (err) {
|
|
1305
|
+
this.assertSessionCurrent();
|
|
1306
|
+
if (["AUTH_SESSION_CHANGED", "EXTERNAL_REVOKE_UNSUPPORTED", 4001].includes(
|
|
1307
|
+
err?.code ?? ""
|
|
1308
|
+
))
|
|
1309
|
+
throw err;
|
|
1124
1310
|
console.warn(
|
|
1125
1311
|
"[GaslessTransferService] Preflight check failed (non-blocking):",
|
|
1126
1312
|
err
|
|
1127
1313
|
);
|
|
1128
1314
|
}
|
|
1315
|
+
this.assertSessionCurrent();
|
|
1129
1316
|
const deadline = Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
1130
1317
|
const feeMaxAmount = (BigInt(params.feeAmountRaw) * BigInt(3) / BigInt(2)).toString();
|
|
1131
1318
|
const baseRequest = {
|
|
@@ -1147,12 +1334,14 @@ var GaslessTransferService = class {
|
|
|
1147
1334
|
auth: { method: "auto" }
|
|
1148
1335
|
};
|
|
1149
1336
|
const phase1 = await this.relayerApi.execute(baseRequest);
|
|
1337
|
+
this.assertSessionCurrent();
|
|
1150
1338
|
if (phase1.phase !== "sign") {
|
|
1151
1339
|
return this.extractResult(phase1, params);
|
|
1152
1340
|
}
|
|
1153
1341
|
const signatures = await this.permitService.signAll(
|
|
1154
1342
|
phase1.signatureRequests
|
|
1155
1343
|
);
|
|
1344
|
+
this.assertSessionCurrent();
|
|
1156
1345
|
let phase2;
|
|
1157
1346
|
try {
|
|
1158
1347
|
phase2 = await this.relayerApi.execute({
|
|
@@ -1161,8 +1350,12 @@ var GaslessTransferService = class {
|
|
|
1161
1350
|
signatures
|
|
1162
1351
|
});
|
|
1163
1352
|
} catch (err) {
|
|
1353
|
+
this.assertSessionCurrent();
|
|
1354
|
+
if (err?.code === "AUTH_SESSION_CHANGED")
|
|
1355
|
+
throw err;
|
|
1164
1356
|
throw new RelayPhase2Error(phase1.requestId, err);
|
|
1165
1357
|
}
|
|
1358
|
+
this.assertSessionCurrent();
|
|
1166
1359
|
return this.extractResult(phase2, params);
|
|
1167
1360
|
}
|
|
1168
1361
|
/**
|
|
@@ -1182,19 +1375,24 @@ var GaslessTransferService = class {
|
|
|
1182
1375
|
params.fromAddress,
|
|
1183
1376
|
{
|
|
1184
1377
|
walletClient: this.walletClient,
|
|
1185
|
-
onDelegationError: gaslessConfig.onDelegationError
|
|
1378
|
+
onDelegationError: gaslessConfig.onDelegationError,
|
|
1379
|
+
assertSessionCurrent: this.assertSessionCurrent,
|
|
1380
|
+
delegationClient: this.signer.getDelegationClient?.()
|
|
1186
1381
|
}
|
|
1187
1382
|
);
|
|
1383
|
+
this.assertSessionCurrent();
|
|
1188
1384
|
try {
|
|
1189
1385
|
const { delegateAuth } = await this.eip7702Service.signDelegate(
|
|
1190
1386
|
params.chainKey,
|
|
1191
1387
|
params.chainId,
|
|
1192
1388
|
params.fromAddress
|
|
1193
1389
|
);
|
|
1390
|
+
this.assertSessionCurrent();
|
|
1194
1391
|
const { relayerAddress, executionNonce } = await this.eip7702Service.getRelayerInfo(
|
|
1195
1392
|
params.chainKey,
|
|
1196
1393
|
params.fromAddress
|
|
1197
1394
|
);
|
|
1395
|
+
this.assertSessionCurrent();
|
|
1198
1396
|
const deadline = Math.floor(Date.now() / 1e3) + 20 * 60;
|
|
1199
1397
|
const isPointsMode = params.gaslessMode === "eip7702-points";
|
|
1200
1398
|
const transferCalldata = this.encodeErc20Transfer(
|
|
@@ -1221,6 +1419,7 @@ var GaslessTransferService = class {
|
|
|
1221
1419
|
feeAmount: params.feeAmountRaw
|
|
1222
1420
|
});
|
|
1223
1421
|
const executionAuth = await this.eip7702Service.signExecutionTypedData(executionTypedData);
|
|
1422
|
+
this.assertSessionCurrent();
|
|
1224
1423
|
const feeAmount = isPointsMode ? "0" : params.feeAmountRaw;
|
|
1225
1424
|
const feeMaxAmount = isPointsMode ? "0" : (BigInt(params.feeAmountRaw) * BigInt(3) / BigInt(2)).toString();
|
|
1226
1425
|
const result = await this.relayerApi.execute({
|
|
@@ -1246,8 +1445,12 @@ var GaslessTransferService = class {
|
|
|
1246
1445
|
executionAuth
|
|
1247
1446
|
}
|
|
1248
1447
|
});
|
|
1448
|
+
this.assertSessionCurrent();
|
|
1249
1449
|
return this.extractResult(result, params);
|
|
1250
1450
|
} catch (error) {
|
|
1451
|
+
this.assertSessionCurrent();
|
|
1452
|
+
if (error?.code === "AUTH_SESSION_CHANGED")
|
|
1453
|
+
throw error;
|
|
1251
1454
|
try {
|
|
1252
1455
|
await ensureDelegationCleared(
|
|
1253
1456
|
params.chainKey,
|
|
@@ -1255,10 +1458,15 @@ var GaslessTransferService = class {
|
|
|
1255
1458
|
params.fromAddress,
|
|
1256
1459
|
{
|
|
1257
1460
|
walletClient: this.walletClient,
|
|
1258
|
-
onDelegationError: gaslessConfig.onDelegationError
|
|
1461
|
+
onDelegationError: gaslessConfig.onDelegationError,
|
|
1462
|
+
assertSessionCurrent: this.assertSessionCurrent,
|
|
1463
|
+
delegationClient: this.signer.getDelegationClient?.()
|
|
1259
1464
|
}
|
|
1260
1465
|
);
|
|
1261
1466
|
} catch (cleanupError) {
|
|
1467
|
+
this.assertSessionCurrent();
|
|
1468
|
+
if (cleanupError?.code === "AUTH_SESSION_CHANGED")
|
|
1469
|
+
throw cleanupError;
|
|
1262
1470
|
console.error(
|
|
1263
1471
|
"[GaslessTransferService] Post-failure delegation cleanup failed:",
|
|
1264
1472
|
cleanupError
|
|
@@ -1311,10 +1519,33 @@ function sleep(ms) {
|
|
|
1311
1519
|
}
|
|
1312
1520
|
var AbcWaasSigner = class {
|
|
1313
1521
|
constructor(params) {
|
|
1522
|
+
this.api = getTalkenApiClient();
|
|
1523
|
+
this.revision = this.api?.getSessionRevision();
|
|
1314
1524
|
this.pinHash = params.pinHash;
|
|
1315
1525
|
this.network = params.network;
|
|
1316
1526
|
this.email = params.email;
|
|
1317
1527
|
}
|
|
1528
|
+
getDelegationClient() {
|
|
1529
|
+
return {
|
|
1530
|
+
readCode: async (chainKey, address) => {
|
|
1531
|
+
const api = this.getApiOrThrow();
|
|
1532
|
+
const result = await api.get(
|
|
1533
|
+
`/wallet/code/${encodeURIComponent(chainKey)}/${encodeURIComponent(address)}`
|
|
1534
|
+
);
|
|
1535
|
+
this.getApiOrThrow();
|
|
1536
|
+
return result.code ?? "0x";
|
|
1537
|
+
},
|
|
1538
|
+
revoke: (chainKey, chainId, address) => sendRevokeTx(
|
|
1539
|
+
address,
|
|
1540
|
+
chainKey,
|
|
1541
|
+
chainId,
|
|
1542
|
+
() => this.assertSessionCurrent()
|
|
1543
|
+
)
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
assertSessionCurrent() {
|
|
1547
|
+
this.getApiOrThrow();
|
|
1548
|
+
}
|
|
1318
1549
|
supportsAuthorization() {
|
|
1319
1550
|
return true;
|
|
1320
1551
|
}
|
|
@@ -1323,20 +1554,24 @@ var AbcWaasSigner = class {
|
|
|
1323
1554
|
let lastError = null;
|
|
1324
1555
|
for (let attempt = 0; attempt < MAX_SIGN_ATTEMPTS; attempt++) {
|
|
1325
1556
|
try {
|
|
1557
|
+
this.getApiOrThrow();
|
|
1326
1558
|
const result = await api.evm.signTypedData({
|
|
1327
1559
|
network: this.network,
|
|
1328
1560
|
typedData: JSON.stringify(typedData),
|
|
1329
1561
|
...this.pinHash && { pin: this.pinHash },
|
|
1330
1562
|
...this.email && { email: this.email }
|
|
1331
1563
|
});
|
|
1564
|
+
this.getApiOrThrow();
|
|
1332
1565
|
const sig = typeof result === "string" ? result : result?.signature ?? result?.result;
|
|
1333
1566
|
if (sig)
|
|
1334
1567
|
return sig;
|
|
1335
1568
|
throw new Error("signTypedData returned empty signature");
|
|
1336
1569
|
} catch (error) {
|
|
1570
|
+
this.getApiOrThrow();
|
|
1337
1571
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1338
1572
|
if (attempt < MAX_SIGN_ATTEMPTS - 1) {
|
|
1339
1573
|
await sleep(RETRY_BASE_MS * 2 ** attempt);
|
|
1574
|
+
this.getApiOrThrow();
|
|
1340
1575
|
}
|
|
1341
1576
|
}
|
|
1342
1577
|
}
|
|
@@ -1347,6 +1582,7 @@ var AbcWaasSigner = class {
|
|
|
1347
1582
|
let lastError = null;
|
|
1348
1583
|
for (let attempt = 0; attempt < MAX_SIGN_ATTEMPTS; attempt++) {
|
|
1349
1584
|
try {
|
|
1585
|
+
this.getApiOrThrow();
|
|
1350
1586
|
const result = await api.evm.signAuthorization({
|
|
1351
1587
|
network: this.network,
|
|
1352
1588
|
authorization: {
|
|
@@ -1357,6 +1593,7 @@ var AbcWaasSigner = class {
|
|
|
1357
1593
|
...this.pinHash && { pin: this.pinHash },
|
|
1358
1594
|
...this.email && { email: this.email }
|
|
1359
1595
|
});
|
|
1596
|
+
this.getApiOrThrow();
|
|
1360
1597
|
const auth = result?.authorization ?? result;
|
|
1361
1598
|
if (!auth?.r || !auth?.s) {
|
|
1362
1599
|
throw new Error("signAuthorization returned empty r/s");
|
|
@@ -1370,9 +1607,11 @@ var AbcWaasSigner = class {
|
|
|
1370
1607
|
s: auth.s
|
|
1371
1608
|
};
|
|
1372
1609
|
} catch (error) {
|
|
1610
|
+
this.getApiOrThrow();
|
|
1373
1611
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1374
1612
|
if (attempt < MAX_SIGN_ATTEMPTS - 1) {
|
|
1375
1613
|
await sleep(RETRY_BASE_MS * 2 ** attempt);
|
|
1614
|
+
this.getApiOrThrow();
|
|
1376
1615
|
}
|
|
1377
1616
|
}
|
|
1378
1617
|
}
|
|
@@ -1381,6 +1620,7 @@ var AbcWaasSigner = class {
|
|
|
1381
1620
|
async getNonce(address) {
|
|
1382
1621
|
const api = this.getApiOrThrow();
|
|
1383
1622
|
const nonceResult = await api.evm.getNonce(this.network, address);
|
|
1623
|
+
this.getApiOrThrow();
|
|
1384
1624
|
const raw = nonceResult?.data?.result ?? nonceResult?.nonce ?? nonceResult?.result ?? nonceResult;
|
|
1385
1625
|
const nonce = Number(raw);
|
|
1386
1626
|
if (!Number.isFinite(nonce)) {
|
|
@@ -1392,6 +1632,19 @@ var AbcWaasSigner = class {
|
|
|
1392
1632
|
const api = getTalkenApiClient();
|
|
1393
1633
|
if (!api)
|
|
1394
1634
|
throw new Error("TalkenApiClient not initialized");
|
|
1635
|
+
if (api !== this.api || api.getSessionRevision() !== this.revision || !ownsTalkenApiStorage(api))
|
|
1636
|
+
throw new TalkenApiError(
|
|
1637
|
+
"AUTH_SESSION_CHANGED",
|
|
1638
|
+
"The signer wallet session changed.",
|
|
1639
|
+
401
|
|
1640
|
+
);
|
|
1641
|
+
const session = api.isAccessKeyMode() ? api.getAuthenticatedWalletSession() : null;
|
|
1642
|
+
if (api.isAccessKeyMode() && (!session || this.email && session.user.email !== this.email.trim().toLowerCase()))
|
|
1643
|
+
throw new TalkenApiError(
|
|
1644
|
+
"AUTH_SESSION_CHANGED",
|
|
1645
|
+
"The signer account does not match this login.",
|
|
1646
|
+
401
|
|
1647
|
+
);
|
|
1395
1648
|
return api;
|
|
1396
1649
|
}
|
|
1397
1650
|
};
|
|
@@ -1470,17 +1723,21 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1470
1723
|
this.gaslessFeeService = getSharedGaslessFeeService();
|
|
1471
1724
|
this.gaslessLock = Promise.resolve();
|
|
1472
1725
|
}
|
|
1726
|
+
getWalletOperationNetwork() {
|
|
1727
|
+
return this.chainId;
|
|
1728
|
+
}
|
|
1473
1729
|
getRecoveryEmail() {
|
|
1474
1730
|
const walletEmail = this.wallet?.email?.trim();
|
|
1475
1731
|
if (walletEmail) {
|
|
1476
1732
|
return walletEmail;
|
|
1477
1733
|
}
|
|
1478
|
-
return
|
|
1734
|
+
return this.getSharedCredentials()?.getEmail() || void 0;
|
|
1479
1735
|
}
|
|
1480
1736
|
/**
|
|
1481
1737
|
* Set wallet — EVM override for chainId tracking + chainChanged event
|
|
1482
1738
|
*/
|
|
1483
1739
|
setWallet(wallet) {
|
|
1740
|
+
this.assertWalletSession(wallet);
|
|
1484
1741
|
const previousChainId = this.chainId;
|
|
1485
1742
|
this.chainId = wallet.chainId;
|
|
1486
1743
|
super.setWallet(wallet);
|
|
@@ -1518,13 +1775,17 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1518
1775
|
* so this refresh is the only recovery from a cold server credential cache.
|
|
1519
1776
|
*/
|
|
1520
1777
|
async refreshSigningCredentials() {
|
|
1521
|
-
const credMgr =
|
|
1522
|
-
const pinHash = credMgr
|
|
1778
|
+
const credMgr = this.getSharedCredentials();
|
|
1779
|
+
const pinHash = credMgr?.getPinHash();
|
|
1523
1780
|
const email = this.getRecoveryEmail();
|
|
1781
|
+
const assertOperation = this.captureWalletOperation();
|
|
1524
1782
|
if (pinHash && email) {
|
|
1525
1783
|
const api = this.getTalkenApiClientOrThrow();
|
|
1526
1784
|
logger2.info("Refreshing signing credentials via wallet.generate...");
|
|
1527
|
-
await
|
|
1785
|
+
await this.awaitWalletOperation(
|
|
1786
|
+
assertOperation,
|
|
1787
|
+
async () => api.wallet.generate(pinHash, email)
|
|
1788
|
+
);
|
|
1528
1789
|
logger2.info("Signing credentials refreshed via PIN");
|
|
1529
1790
|
return;
|
|
1530
1791
|
}
|
|
@@ -1541,15 +1802,26 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1541
1802
|
* On first failure, refreshes the server's signing credential cache and retries once.
|
|
1542
1803
|
*/
|
|
1543
1804
|
async withSigningCredentialRetry(operation) {
|
|
1805
|
+
const assertOperation = this.captureWalletOperation();
|
|
1544
1806
|
try {
|
|
1545
|
-
return await
|
|
1807
|
+
return await this.awaitWalletOperation(
|
|
1808
|
+
assertOperation,
|
|
1809
|
+
async () => operation()
|
|
1810
|
+
);
|
|
1546
1811
|
} catch (error) {
|
|
1812
|
+
assertOperation();
|
|
1547
1813
|
if (this.isSigningCredentialError(error)) {
|
|
1548
1814
|
logger2.info(
|
|
1549
1815
|
"Signing credentials missing on server \u2014 attempting refresh and retry"
|
|
1550
1816
|
);
|
|
1551
|
-
await this.
|
|
1552
|
-
|
|
1817
|
+
await this.awaitWalletOperation(
|
|
1818
|
+
assertOperation,
|
|
1819
|
+
async () => this.refreshSigningCredentials()
|
|
1820
|
+
);
|
|
1821
|
+
return await this.awaitWalletOperation(
|
|
1822
|
+
assertOperation,
|
|
1823
|
+
async () => operation()
|
|
1824
|
+
);
|
|
1553
1825
|
}
|
|
1554
1826
|
throw error;
|
|
1555
1827
|
}
|
|
@@ -1575,6 +1847,8 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1575
1847
|
* EIP-1193 request method
|
|
1576
1848
|
*/
|
|
1577
1849
|
async request(args) {
|
|
1850
|
+
if (this.wallet)
|
|
1851
|
+
this.assertWalletSession();
|
|
1578
1852
|
const { method, params } = args;
|
|
1579
1853
|
switch (method) {
|
|
1580
1854
|
case "eth_requestAccounts":
|
|
@@ -1677,7 +1951,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1677
1951
|
);
|
|
1678
1952
|
}
|
|
1679
1953
|
resolveEvmSignType(params[0]);
|
|
1680
|
-
const
|
|
1954
|
+
const assertOperation = this.captureWalletOperation();
|
|
1955
|
+
const resolved = await this.awaitWalletOperation(
|
|
1956
|
+
assertOperation,
|
|
1957
|
+
async () => this.callInterceptor("eth_sendTransaction", params)
|
|
1958
|
+
);
|
|
1681
1959
|
const tx = params[0];
|
|
1682
1960
|
logger2.debug("eth_sendTransaction incoming gas params:", {
|
|
1683
1961
|
gas: tx.gas ?? tx.gasLimit,
|
|
@@ -1694,6 +1972,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1694
1972
|
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
1695
1973
|
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
1696
1974
|
} catch (error) {
|
|
1975
|
+
assertOperation();
|
|
1697
1976
|
logger2.error("Failed to parse maxFeePerGas:", error);
|
|
1698
1977
|
}
|
|
1699
1978
|
}
|
|
@@ -1704,6 +1983,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1704
1983
|
);
|
|
1705
1984
|
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
1706
1985
|
} catch (error) {
|
|
1986
|
+
assertOperation();
|
|
1707
1987
|
logger2.error("Failed to parse maxPriorityFeePerGas:", error);
|
|
1708
1988
|
}
|
|
1709
1989
|
}
|
|
@@ -1724,7 +2004,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1724
2004
|
);
|
|
1725
2005
|
}
|
|
1726
2006
|
const api = this.getTalkenApiClientOrThrow();
|
|
1727
|
-
const pinHash = api.isAccessKeyMode() ? void 0 :
|
|
2007
|
+
const pinHash = api.isAccessKeyMode() ? void 0 : this.getSharedCredentials()?.getPinHash() || void 0;
|
|
1728
2008
|
if (!pinHash && !api.isAccessKeyMode()) {
|
|
1729
2009
|
throw new ProviderRpcError(
|
|
1730
2010
|
ProviderErrorCode.INTERNAL_ERROR,
|
|
@@ -1740,22 +2020,27 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1740
2020
|
if (shouldTryGasless) {
|
|
1741
2021
|
const effectiveConfig = gaslessConfig ?? { enabled: true };
|
|
1742
2022
|
const attempt = this.gaslessLock.catch(() => {
|
|
1743
|
-
}).then(
|
|
1744
|
-
()
|
|
2023
|
+
}).then(() => {
|
|
2024
|
+
assertOperation();
|
|
2025
|
+
return this.tryGaslessTransfer(
|
|
1745
2026
|
tx,
|
|
1746
2027
|
chainKey,
|
|
1747
2028
|
pinHash,
|
|
1748
2029
|
email,
|
|
1749
2030
|
effectiveConfig,
|
|
1750
2031
|
preEstimatedFee
|
|
1751
|
-
)
|
|
1752
|
-
);
|
|
2032
|
+
);
|
|
2033
|
+
});
|
|
1753
2034
|
this.gaslessLock = attempt;
|
|
1754
2035
|
try {
|
|
1755
|
-
const gaslessResult = await
|
|
2036
|
+
const gaslessResult = await this.awaitWalletOperation(
|
|
2037
|
+
assertOperation,
|
|
2038
|
+
async () => attempt
|
|
2039
|
+
);
|
|
1756
2040
|
if (gaslessResult)
|
|
1757
2041
|
return gaslessResult;
|
|
1758
2042
|
} catch (gaslessError) {
|
|
2043
|
+
assertOperation();
|
|
1759
2044
|
const failedTxHash = gaslessError?.txHash || "";
|
|
1760
2045
|
this.updateTxResult({
|
|
1761
2046
|
txHash: failedTxHash,
|
|
@@ -1777,21 +2062,24 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1777
2062
|
const amountWei = BigInt(hexValue).toString();
|
|
1778
2063
|
try {
|
|
1779
2064
|
const gasLimit = tx.gas || tx.gasLimit;
|
|
1780
|
-
const result = await
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
2065
|
+
const result = await this.awaitWalletOperation(
|
|
2066
|
+
assertOperation,
|
|
2067
|
+
async () => api.evm.sendTransaction({
|
|
2068
|
+
chainKey,
|
|
2069
|
+
to: tx.to,
|
|
2070
|
+
amountWei,
|
|
2071
|
+
pin: pinHash,
|
|
2072
|
+
data: tx.data || "0x",
|
|
2073
|
+
waitForReceipt: true,
|
|
2074
|
+
...gasLimit && { gasLimit },
|
|
2075
|
+
...tx.gasPrice && { gasPrice: tx.gasPrice },
|
|
2076
|
+
...tx.maxFeePerGas && { maxFeePerGas: tx.maxFeePerGas },
|
|
2077
|
+
...tx.maxPriorityFeePerGas && {
|
|
2078
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
2079
|
+
},
|
|
2080
|
+
...email && { email }
|
|
2081
|
+
})
|
|
2082
|
+
);
|
|
1795
2083
|
this.updateTxResult({
|
|
1796
2084
|
txHash: result.txHash,
|
|
1797
2085
|
network: chainKey,
|
|
@@ -1801,6 +2089,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1801
2089
|
});
|
|
1802
2090
|
return result.txHash;
|
|
1803
2091
|
} catch (error) {
|
|
2092
|
+
assertOperation();
|
|
1804
2093
|
this.failTxResult({
|
|
1805
2094
|
network: chainKey,
|
|
1806
2095
|
chain: "evm",
|
|
@@ -1822,18 +2111,23 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1822
2111
|
if (!detected)
|
|
1823
2112
|
return null;
|
|
1824
2113
|
let feeEstimate = preEstimatedFee ?? null;
|
|
2114
|
+
const assertOperation = this.captureWalletOperation();
|
|
1825
2115
|
if (!feeEstimate) {
|
|
1826
2116
|
try {
|
|
1827
|
-
feeEstimate = await this.
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
2117
|
+
feeEstimate = await this.awaitWalletOperation(
|
|
2118
|
+
assertOperation,
|
|
2119
|
+
async () => this.gaslessFeeService.estimateFee({
|
|
2120
|
+
chainKey,
|
|
2121
|
+
chainId: this.chainId,
|
|
2122
|
+
tokenAddress: tx.to,
|
|
2123
|
+
fromAddress: this.wallet.address,
|
|
2124
|
+
toAddress: detected.to,
|
|
2125
|
+
amount: detected.amount,
|
|
2126
|
+
gaslessConfig
|
|
2127
|
+
})
|
|
2128
|
+
);
|
|
1836
2129
|
} catch (err) {
|
|
2130
|
+
assertOperation();
|
|
1837
2131
|
console.warn("[AbcProvider] Gasless fee estimation failed:", err);
|
|
1838
2132
|
return null;
|
|
1839
2133
|
}
|
|
@@ -1849,19 +2143,22 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1849
2143
|
relayerApi: this._sharedRelayerApi,
|
|
1850
2144
|
signer
|
|
1851
2145
|
});
|
|
1852
|
-
const gaslessResult = await
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
2146
|
+
const gaslessResult = await this.awaitWalletOperation(
|
|
2147
|
+
assertOperation,
|
|
2148
|
+
async () => transferService.execute(
|
|
2149
|
+
{
|
|
2150
|
+
chainId: this.chainId,
|
|
2151
|
+
chainKey,
|
|
2152
|
+
fromAddress: this.wallet.address,
|
|
2153
|
+
toAddress: detected.to,
|
|
2154
|
+
tokenAddress: tx.to,
|
|
2155
|
+
amount: detected.amount,
|
|
2156
|
+
feeToken: feeEstimate.feeToken,
|
|
2157
|
+
gaslessMode: feeEstimate.gaslessMode,
|
|
2158
|
+
feeAmountRaw: feeEstimate.feeAmountRaw
|
|
2159
|
+
},
|
|
2160
|
+
gaslessConfig
|
|
2161
|
+
)
|
|
1865
2162
|
);
|
|
1866
2163
|
this.updateTxResult({
|
|
1867
2164
|
txHash: gaslessResult.txHash,
|
|
@@ -1897,7 +2194,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1897
2194
|
);
|
|
1898
2195
|
}
|
|
1899
2196
|
const signType = resolveEvmSignType(params[0]);
|
|
1900
|
-
const
|
|
2197
|
+
const assertOperation = this.captureWalletOperation();
|
|
2198
|
+
const resolved = await this.awaitWalletOperation(
|
|
2199
|
+
assertOperation,
|
|
2200
|
+
async () => this.callInterceptor("eth_signTransaction", params)
|
|
2201
|
+
);
|
|
1901
2202
|
const tx = params[0];
|
|
1902
2203
|
if (resolved) {
|
|
1903
2204
|
if (resolved.data) {
|
|
@@ -1908,6 +2209,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1908
2209
|
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
1909
2210
|
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
1910
2211
|
} catch (error) {
|
|
2212
|
+
assertOperation();
|
|
1911
2213
|
logger2.error("Failed to parse maxFeePerGas:", error);
|
|
1912
2214
|
}
|
|
1913
2215
|
}
|
|
@@ -1918,27 +2220,31 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1918
2220
|
);
|
|
1919
2221
|
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
1920
2222
|
} catch (error) {
|
|
2223
|
+
assertOperation();
|
|
1921
2224
|
logger2.error("Failed to parse maxPriorityFeePerGas:", error);
|
|
1922
2225
|
}
|
|
1923
2226
|
}
|
|
1924
2227
|
}
|
|
1925
2228
|
const api = this.getTalkenApiClientOrThrow();
|
|
1926
|
-
const pinHash =
|
|
2229
|
+
const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
|
|
1927
2230
|
const email = this.getRecoveryEmail();
|
|
1928
|
-
const result = await this.
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2231
|
+
const result = await this.awaitWalletOperation(
|
|
2232
|
+
assertOperation,
|
|
2233
|
+
async () => this.withSigningCredentialRetry(
|
|
2234
|
+
() => api.evm.signTransaction({
|
|
2235
|
+
network: getNetworkName(this.chainId),
|
|
2236
|
+
to: tx.to,
|
|
2237
|
+
value: tx.value || "0x0",
|
|
2238
|
+
data: tx.data || "0x",
|
|
2239
|
+
gasLimit: tx.gas || tx.gasLimit,
|
|
2240
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
2241
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
2242
|
+
nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0,
|
|
2243
|
+
...signType && { type: signType },
|
|
2244
|
+
...pinHash && { pin: pinHash },
|
|
2245
|
+
...email && { email }
|
|
2246
|
+
})
|
|
2247
|
+
)
|
|
1942
2248
|
);
|
|
1943
2249
|
return result.signature;
|
|
1944
2250
|
}
|
|
@@ -1960,7 +2266,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1960
2266
|
"Invalid personal_sign params"
|
|
1961
2267
|
);
|
|
1962
2268
|
}
|
|
1963
|
-
|
|
2269
|
+
const assertOperation = this.captureWalletOperation();
|
|
2270
|
+
await this.awaitWalletOperation(
|
|
2271
|
+
assertOperation,
|
|
2272
|
+
async () => this.callInterceptor("personal_sign", params)
|
|
2273
|
+
);
|
|
1964
2274
|
const [message, address] = params;
|
|
1965
2275
|
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
1966
2276
|
logger2.error("Address mismatch");
|
|
@@ -1971,20 +2281,23 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
1971
2281
|
}
|
|
1972
2282
|
const api = this.getTalkenApiClientOrThrow();
|
|
1973
2283
|
const network = getNetworkName(this.chainId);
|
|
1974
|
-
const pinHash =
|
|
2284
|
+
const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
|
|
1975
2285
|
const email = this.getRecoveryEmail();
|
|
1976
2286
|
const rawOpts = Array.isArray(params) && params.length > 2 ? params[2] : null;
|
|
1977
2287
|
const validPrefixes = ["eip191", "native"];
|
|
1978
2288
|
const signaturePrefix = rawOpts != null && typeof rawOpts === "object" && "signaturePrefix" in rawOpts && validPrefixes.includes(rawOpts.signaturePrefix) ? rawOpts.signaturePrefix : void 0;
|
|
1979
|
-
const result = await this.
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2289
|
+
const result = await this.awaitWalletOperation(
|
|
2290
|
+
assertOperation,
|
|
2291
|
+
async () => this.withSigningCredentialRetry(
|
|
2292
|
+
() => api.evm.signPersonal({
|
|
2293
|
+
network,
|
|
2294
|
+
message,
|
|
2295
|
+
address,
|
|
2296
|
+
pin: pinHash,
|
|
2297
|
+
...email && { email },
|
|
2298
|
+
...signaturePrefix && { signaturePrefix }
|
|
2299
|
+
})
|
|
2300
|
+
)
|
|
1988
2301
|
);
|
|
1989
2302
|
return result.signature;
|
|
1990
2303
|
}
|
|
@@ -2017,7 +2330,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2017
2330
|
"Invalid signTypedData params"
|
|
2018
2331
|
);
|
|
2019
2332
|
}
|
|
2020
|
-
|
|
2333
|
+
const assertOperation = this.captureWalletOperation();
|
|
2334
|
+
await this.awaitWalletOperation(
|
|
2335
|
+
assertOperation,
|
|
2336
|
+
async () => this.callInterceptor("eth_signTypedData_v4", params)
|
|
2337
|
+
);
|
|
2021
2338
|
const [address, typedData] = params;
|
|
2022
2339
|
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
2023
2340
|
throw new ProviderRpcError(
|
|
@@ -2027,15 +2344,18 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2027
2344
|
}
|
|
2028
2345
|
const api = this.getTalkenApiClientOrThrow();
|
|
2029
2346
|
const network = getNetworkName(this.chainId);
|
|
2030
|
-
const pinHash =
|
|
2347
|
+
const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
|
|
2031
2348
|
const email = this.getRecoveryEmail();
|
|
2032
|
-
const result = await this.
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2349
|
+
const result = await this.awaitWalletOperation(
|
|
2350
|
+
assertOperation,
|
|
2351
|
+
async () => this.withSigningCredentialRetry(
|
|
2352
|
+
() => api.evm.signTypedData({
|
|
2353
|
+
network,
|
|
2354
|
+
typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData),
|
|
2355
|
+
pin: pinHash,
|
|
2356
|
+
...email && { email }
|
|
2357
|
+
})
|
|
2358
|
+
)
|
|
2039
2359
|
);
|
|
2040
2360
|
return result.signature;
|
|
2041
2361
|
}
|
|
@@ -2082,25 +2402,32 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2082
2402
|
"Authorization payload is incomplete"
|
|
2083
2403
|
);
|
|
2084
2404
|
}
|
|
2085
|
-
|
|
2405
|
+
const assertOperation = this.captureWalletOperation();
|
|
2406
|
+
await this.awaitWalletOperation(
|
|
2407
|
+
assertOperation,
|
|
2408
|
+
async () => this.callInterceptor("eth_signAuthorization", params)
|
|
2409
|
+
);
|
|
2086
2410
|
const api = this.getTalkenApiClientOrThrow();
|
|
2087
2411
|
const network = getNetworkName(this.chainId);
|
|
2088
|
-
const pinHash =
|
|
2412
|
+
const pinHash = this.getSharedCredentials()?.getPinHash() || void 0;
|
|
2089
2413
|
const email = this.getRecoveryEmail();
|
|
2090
2414
|
const chainIdValue = typeof authorization.chainId === "string" ? Number(BigInt(authorization.chainId)) : Number(authorization.chainId);
|
|
2091
2415
|
const nonceValue = typeof authorization.nonce === "string" ? BigInt(authorization.nonce).toString() : String(authorization.nonce);
|
|
2092
2416
|
const authAddress = authorization.address;
|
|
2093
|
-
const result = await this.
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2417
|
+
const result = await this.awaitWalletOperation(
|
|
2418
|
+
assertOperation,
|
|
2419
|
+
async () => this.withSigningCredentialRetry(
|
|
2420
|
+
() => api.evm.signAuthorization({
|
|
2421
|
+
network,
|
|
2422
|
+
authorization: {
|
|
2423
|
+
chainId: chainIdValue,
|
|
2424
|
+
address: authAddress,
|
|
2425
|
+
nonce: nonceValue
|
|
2426
|
+
},
|
|
2427
|
+
pin: pinHash,
|
|
2428
|
+
...email && { email }
|
|
2429
|
+
})
|
|
2430
|
+
)
|
|
2104
2431
|
);
|
|
2105
2432
|
return result.authorization;
|
|
2106
2433
|
}
|
|
@@ -2120,6 +2447,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2120
2447
|
return null;
|
|
2121
2448
|
}
|
|
2122
2449
|
const _previousChainId = this.chainId;
|
|
2450
|
+
this.invalidateWalletOperations();
|
|
2123
2451
|
this.chainId = newChainId;
|
|
2124
2452
|
if (this.wallet) {
|
|
2125
2453
|
this.wallet.chainId = newChainId;
|
|
@@ -2146,11 +2474,12 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2146
2474
|
);
|
|
2147
2475
|
}
|
|
2148
2476
|
const currentChainId = this.chainId;
|
|
2477
|
+
const assertOperation = this.captureWalletOperation();
|
|
2149
2478
|
try {
|
|
2150
2479
|
const api = this.getTalkenApiClientOrThrow();
|
|
2151
|
-
const response = await
|
|
2152
|
-
|
|
2153
|
-
address
|
|
2480
|
+
const response = await this.awaitWalletOperation(
|
|
2481
|
+
assertOperation,
|
|
2482
|
+
async () => api.evm.getNonce(getNetworkName(currentChainId), address)
|
|
2154
2483
|
);
|
|
2155
2484
|
const nonce = response.result !== void 0 ? typeof response.result === "number" ? `0x${response.result.toString(16)}` : response.result : void 0;
|
|
2156
2485
|
if (!nonce) {
|
|
@@ -2158,6 +2487,7 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2158
2487
|
}
|
|
2159
2488
|
return nonce;
|
|
2160
2489
|
} catch (error) {
|
|
2490
|
+
assertOperation();
|
|
2161
2491
|
logger2.error("Failed to get transaction count from ABC WaaS:", error);
|
|
2162
2492
|
throw new ProviderRpcError(
|
|
2163
2493
|
ProviderErrorCode.INTERNAL_ERROR,
|
|
@@ -2183,19 +2513,24 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2183
2513
|
'Transaction must have "to" field'
|
|
2184
2514
|
);
|
|
2185
2515
|
}
|
|
2516
|
+
const assertOperation = this.captureWalletOperation();
|
|
2186
2517
|
try {
|
|
2187
|
-
const response = await this.
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2518
|
+
const response = await this.awaitWalletOperation(
|
|
2519
|
+
assertOperation,
|
|
2520
|
+
async () => this.getTalkenApiClientOrThrow().evm.estimateGas({
|
|
2521
|
+
network: getNetworkName(this.chainId),
|
|
2522
|
+
from: tx.from || this.wallet?.address || "",
|
|
2523
|
+
to: tx.to,
|
|
2524
|
+
value: tx.value,
|
|
2525
|
+
data: tx.data
|
|
2526
|
+
})
|
|
2527
|
+
);
|
|
2194
2528
|
if (!response.result) {
|
|
2195
2529
|
throw new Error("No result in gas estimate response");
|
|
2196
2530
|
}
|
|
2197
2531
|
return response.result;
|
|
2198
2532
|
} catch (error) {
|
|
2533
|
+
assertOperation();
|
|
2199
2534
|
logger2.warn("Gas estimation failed, using fallback:", error);
|
|
2200
2535
|
if (tx.data && tx.data !== "0x") {
|
|
2201
2536
|
return "0x493e0";
|
|
@@ -2215,16 +2550,21 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2215
2550
|
"eth_call requires to and data"
|
|
2216
2551
|
);
|
|
2217
2552
|
}
|
|
2553
|
+
const assertOperation = this.captureWalletOperation();
|
|
2218
2554
|
try {
|
|
2219
2555
|
const api = this.getTalkenApiClientOrThrow();
|
|
2220
|
-
const response = await
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2556
|
+
const response = await this.awaitWalletOperation(
|
|
2557
|
+
assertOperation,
|
|
2558
|
+
async () => api.evm.ethCall({
|
|
2559
|
+
network: getNetworkName(this.chainId),
|
|
2560
|
+
to: tx.to,
|
|
2561
|
+
data: tx.data,
|
|
2562
|
+
from: tx.from || this.wallet?.address
|
|
2563
|
+
})
|
|
2564
|
+
);
|
|
2226
2565
|
return response?.result ?? response?.data ?? "0x";
|
|
2227
2566
|
} catch (error) {
|
|
2567
|
+
assertOperation();
|
|
2228
2568
|
throw new ProviderRpcError(
|
|
2229
2569
|
ProviderErrorCode.INTERNAL_ERROR,
|
|
2230
2570
|
`eth_call failed: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -2243,14 +2583,16 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2243
2583
|
"Missing address parameter"
|
|
2244
2584
|
);
|
|
2245
2585
|
}
|
|
2586
|
+
const assertOperation = this.captureWalletOperation();
|
|
2246
2587
|
try {
|
|
2247
2588
|
const api = this.getTalkenApiClientOrThrow();
|
|
2248
|
-
const response = await
|
|
2249
|
-
|
|
2250
|
-
address
|
|
2589
|
+
const response = await this.awaitWalletOperation(
|
|
2590
|
+
assertOperation,
|
|
2591
|
+
async () => api.evm.getBalance(getNetworkName(this.chainId), address)
|
|
2251
2592
|
);
|
|
2252
2593
|
return response?.balance ?? "0x0";
|
|
2253
2594
|
} catch (error) {
|
|
2595
|
+
assertOperation();
|
|
2254
2596
|
throw new ProviderRpcError(
|
|
2255
2597
|
ProviderErrorCode.INTERNAL_ERROR,
|
|
2256
2598
|
`eth_getBalance failed: ${error instanceof Error ? error.message : String(error)}`
|
|
@@ -2261,6 +2603,11 @@ var AbcEvmProvider = class extends AbstractChainProvider {
|
|
|
2261
2603
|
* Get current wallet
|
|
2262
2604
|
*/
|
|
2263
2605
|
getWallet() {
|
|
2606
|
+
try {
|
|
2607
|
+
this.assertWalletSession();
|
|
2608
|
+
} catch {
|
|
2609
|
+
return null;
|
|
2610
|
+
}
|
|
2264
2611
|
return this.wallet;
|
|
2265
2612
|
}
|
|
2266
2613
|
/**
|