@talken/talkenkit 2.4.21 → 2.4.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/dist/abcWallet-4RS3B4ZG.js +188 -0
- package/dist/abcWallet-EBOW2RJB.js +188 -0
- package/dist/abcWallet-RS4EOJ4I.js +188 -0
- package/dist/abcWallet-SNEZVK7V.js +188 -0
- package/dist/abcWallet-TC7M2JYX.js +188 -0
- package/dist/abcWallet-VZMW2DR3.js +188 -0
- package/dist/abcWallet-XJ3WSUVI.js +188 -0
- package/dist/abcWallet-XNCBZAIQ.js +188 -0
- package/dist/chunk-6FLQAAC4.js +7213 -0
- package/dist/chunk-7GIIMIPN.js +7213 -0
- package/dist/chunk-IBFA37SC.js +7228 -0
- package/dist/chunk-O5ZOC4NJ.js +7215 -0
- package/dist/chunk-OPOAKGEX.js +7216 -0
- package/dist/chunk-OTIHVCVR.js +7213 -0
- package/dist/chunk-P77BVZZF.js +7369 -0
- package/dist/chunk-RFLXXSQH.js +7139 -0
- package/dist/components/ConfirmationModal/NonEvmConfirmationModal.css.d.ts +11 -0
- package/dist/components/ConfirmationModal/NonEvmSignConfirmationModal.d.ts +9 -0
- package/dist/components/ConfirmationModal/NonEvmTransferConfirmationModal.d.ts +9 -0
- package/dist/components/ConfirmationModal/SignConfirmationModal.css.d.ts +1 -19
- package/dist/components/ConfirmationModal/TransactionConfirmationModal.css.d.ts +1 -20
- package/dist/components/ConfirmationModal/commonStyles.css.d.ts +19 -0
- package/dist/components/ConfirmationModal/index.d.ts +2 -0
- package/dist/components/ConfirmationModal/utils.d.ts +2 -1
- package/dist/hooks/useWalletCapabilities.d.ts +2 -0
- package/dist/index.css +227 -307
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2004 -1064
- package/dist/providers/SignConfirmationProvider/NonEvmConfirmationContext.d.ts +6 -0
- package/dist/providers/SignConfirmationProvider/index.d.ts +2 -1
- package/dist/providers/SignConfirmationProvider/requestParsers.d.ts +6 -1
- package/dist/providers/SignConfirmationProvider/types.d.ts +35 -1
- package/dist/wallets/capabilities/detectCapabilities.d.ts +7 -0
- package/dist/wallets/capabilities/requestWalletAction.d.ts +8 -0
- package/dist/wallets/capabilities/types.d.ts +50 -0
- package/dist/wallets/walletConnectors/abcWallet/abcApi.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.d.ts +10 -0
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +5 -5
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.d.ts +9 -0
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +10 -0
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.d.ts +16 -0
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +115 -33
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.d.ts +16 -0
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/api/AuthApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/BaseApiClient.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/api/BitcoinApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/GasApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +9 -4
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/TransactionApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/TronApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/WalletApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +13 -13
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +5 -4
- package/dist/wallets/walletConnectors/abcWallet/constants.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/index.js +21 -21
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +31 -1
- package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
- package/dist/wallets/walletConnectors/berasigWallet/berasigWallet.js +2 -2
- package/dist/wallets/walletConnectors/bifrostWallet/bifrostWallet.js +2 -2
- package/dist/wallets/walletConnectors/binanceWallet/binanceWallet.js +2 -2
- package/dist/wallets/walletConnectors/bitgetWallet/bitgetWallet.js +2 -2
- package/dist/wallets/walletConnectors/bybitWallet/bybitWallet.js +2 -2
- package/dist/wallets/walletConnectors/chunk-2IZBLAHI.js +52 -0
- package/dist/wallets/walletConnectors/chunk-32IJ3ILH.js +71 -0
- package/dist/wallets/walletConnectors/chunk-3AX66UHT.js +479 -0
- package/dist/wallets/walletConnectors/chunk-3BVPV64G.js +36 -0
- package/dist/wallets/walletConnectors/chunk-3DGFHWI3.js +302 -0
- package/dist/wallets/walletConnectors/chunk-4FKUVQCM.js +655 -0
- package/dist/wallets/walletConnectors/chunk-56SF4VRC.js +640 -0
- package/dist/wallets/walletConnectors/chunk-5KOE7NJW.js +52 -0
- package/dist/wallets/walletConnectors/chunk-6CVXZ3ZW.js +771 -0
- package/dist/wallets/walletConnectors/chunk-6GCWEPU7.js +643 -0
- package/dist/wallets/walletConnectors/chunk-6YFP3Q2I.js +118 -0
- package/dist/wallets/walletConnectors/chunk-7EEPPULA.js +118 -0
- package/dist/wallets/walletConnectors/chunk-7QL42XTB.js +302 -0
- package/dist/wallets/walletConnectors/chunk-A7ZSPSFX.js +577 -0
- package/dist/wallets/walletConnectors/chunk-AI3CT254.js +302 -0
- package/dist/wallets/walletConnectors/chunk-AMNVH7CZ.js +151 -0
- package/dist/wallets/walletConnectors/chunk-AOREXGRM.js +350 -0
- package/dist/wallets/walletConnectors/chunk-BLO7E54F.js +302 -0
- package/dist/wallets/walletConnectors/chunk-BNRH5PYS.js +52 -0
- package/dist/wallets/walletConnectors/chunk-BOV5FXU6.js +151 -0
- package/dist/wallets/walletConnectors/chunk-BR25RFNF.js +260 -0
- package/dist/wallets/walletConnectors/chunk-BXQ2UWJ3.js +91 -0
- package/dist/wallets/walletConnectors/chunk-CAMPW7O2.js +874 -0
- package/dist/wallets/walletConnectors/chunk-CLMFCNP7.js +52 -0
- package/dist/wallets/walletConnectors/chunk-DSZOE65L.js +107 -0
- package/dist/wallets/walletConnectors/chunk-DU6RCLWT.js +272 -0
- package/dist/wallets/walletConnectors/chunk-ENN6UGGA.js +421 -0
- package/dist/wallets/walletConnectors/chunk-EXWDLN5V.js +204 -0
- package/dist/wallets/walletConnectors/chunk-FFU26Y5Y.js +272 -0
- package/dist/wallets/walletConnectors/chunk-FGS2WHVA.js +118 -0
- package/dist/wallets/walletConnectors/chunk-FJJ3QI4R.js +91 -0
- package/dist/wallets/walletConnectors/chunk-FS2OOQYF.js +204 -0
- package/dist/wallets/walletConnectors/chunk-G5X3COSW.js +205 -0
- package/dist/wallets/walletConnectors/chunk-H53R4SFZ.js +204 -0
- package/dist/wallets/walletConnectors/chunk-J4QGDATF.js +71 -0
- package/dist/wallets/walletConnectors/chunk-JIJNCMJR.js +874 -0
- package/dist/wallets/walletConnectors/chunk-JSGZYU4A.js +52 -0
- package/dist/wallets/walletConnectors/chunk-JVT7R2GZ.js +771 -0
- package/dist/wallets/walletConnectors/chunk-K3JNN5UK.js +71 -0
- package/dist/wallets/walletConnectors/chunk-KBHPY3NA.js +302 -0
- package/dist/wallets/walletConnectors/chunk-KEX6WS23.js +640 -0
- package/dist/wallets/walletConnectors/chunk-KHYKVVR7.js +52 -0
- package/dist/wallets/walletConnectors/chunk-LOL7ZZ3S.js +302 -0
- package/dist/wallets/walletConnectors/chunk-LOSXI36Y.js +479 -0
- package/dist/wallets/walletConnectors/chunk-M2U5QGM7.js +260 -0
- package/dist/wallets/walletConnectors/chunk-M73AWLIV.js +107 -0
- package/dist/wallets/walletConnectors/chunk-MAUC46AE.js +302 -0
- package/dist/wallets/walletConnectors/chunk-MBRXYEQC.js +272 -0
- package/dist/wallets/walletConnectors/chunk-MDDD4LG2.js +874 -0
- package/dist/wallets/walletConnectors/chunk-MMR2QAEU.js +642 -0
- package/dist/wallets/walletConnectors/chunk-MNZZRFUC.js +302 -0
- package/dist/wallets/walletConnectors/chunk-OIRY24PH.js +302 -0
- package/dist/wallets/walletConnectors/chunk-ORBX4JE2.js +52 -0
- package/dist/wallets/walletConnectors/chunk-OXJFFDW7.js +761 -0
- package/dist/wallets/walletConnectors/chunk-QD3PPWTN.js +272 -0
- package/dist/wallets/walletConnectors/chunk-RCIABMG5.js +259 -0
- package/dist/wallets/walletConnectors/chunk-RHC4SVLB.js +71 -0
- package/dist/wallets/walletConnectors/chunk-S2CB4KFC.js +71 -0
- package/dist/wallets/walletConnectors/chunk-S6HZD4XZ.js +302 -0
- package/dist/wallets/walletConnectors/chunk-S72LCNVX.js +272 -0
- package/dist/wallets/walletConnectors/chunk-SCWE5EEX.js +91 -0
- package/dist/wallets/walletConnectors/chunk-TKEL4D4E.js +151 -0
- package/dist/wallets/walletConnectors/chunk-TKJEMEBZ.js +71 -0
- package/dist/wallets/walletConnectors/chunk-TZ44ZREA.js +302 -0
- package/dist/wallets/walletConnectors/chunk-UGQSI3US.js +547 -0
- package/dist/wallets/walletConnectors/chunk-UU4JYY3C.js +205 -0
- package/dist/wallets/walletConnectors/chunk-V5P5BL6Z.js +302 -0
- package/dist/wallets/walletConnectors/chunk-VH6DIRPF.js +71 -0
- package/dist/wallets/walletConnectors/chunk-VPNZAMW5.js +205 -0
- package/dist/wallets/walletConnectors/chunk-W6QN6QXO.js +52 -0
- package/dist/wallets/walletConnectors/chunk-WDULICVN.js +302 -0
- package/dist/wallets/walletConnectors/chunk-WGGHGODM.js +272 -0
- package/dist/wallets/walletConnectors/chunk-XUCMTLM3.js +52 -0
- package/dist/wallets/walletConnectors/chunk-Y5WAX6WO.js +52 -0
- package/dist/wallets/walletConnectors/chunk-Y62PFBWE.js +640 -0
- package/dist/wallets/walletConnectors/chunk-Z6ABK6G6.js +107 -0
- package/dist/wallets/walletConnectors/chunk-ZCA5QSIM.js +71 -0
- package/dist/wallets/walletConnectors/chunk-ZJDZJW55.js +479 -0
- package/dist/wallets/walletConnectors/chunk-ZOF7ZDGU.js +52 -0
- package/dist/wallets/walletConnectors/chunk-ZUU57RHO.js +36 -0
- package/dist/wallets/walletConnectors/chunk-ZWFGRREM.js +36 -0
- package/dist/wallets/walletConnectors/chunk-ZY5BCHP2.js +302 -0
- package/dist/wallets/walletConnectors/clvWallet/clvWallet.js +2 -2
- package/dist/wallets/walletConnectors/coin98Wallet/coin98Wallet.js +2 -2
- package/dist/wallets/walletConnectors/coreWallet/coreWallet.js +2 -2
- package/dist/wallets/walletConnectors/foxWallet/foxWallet.js +2 -2
- package/dist/wallets/walletConnectors/frontierWallet/frontierWallet.js +2 -2
- package/dist/wallets/walletConnectors/gateWallet/gateWallet.js +2 -2
- package/dist/wallets/walletConnectors/index.js +91 -91
- package/dist/wallets/walletConnectors/iopayWallet/iopayWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaiaWallet/kaiaWallet.js +2 -2
- package/dist/wallets/walletConnectors/kaikasWallet/kaikasWallet.js +2 -2
- package/dist/wallets/walletConnectors/metaMaskWallet/metaMaskWallet.js +2 -2
- package/dist/wallets/walletConnectors/okxWallet/okxWallet.js +2 -2
- package/dist/wallets/walletConnectors/rainbowWallet/rainbowWallet.js +2 -2
- package/dist/wallets/walletConnectors/roninWallet/roninWallet.js +2 -2
- package/dist/wallets/walletConnectors/safepalWallet/safepalWallet.js +2 -2
- package/dist/wallets/walletConnectors/subWallet/subWallet.js +2 -2
- package/dist/wallets/walletConnectors/tokenPocketWallet/tokenPocketWallet.js +2 -2
- package/dist/wallets/walletConnectors/trustWallet/trustWallet.js +2 -2
- package/dist/wallets/walletConnectors/zealWallet/zealWallet.js +2 -2
- package/dist/wallets/walletConnectors/zerionWallet/zerionWallet.js +2 -2
- package/package.json +11 -12
|
@@ -0,0 +1,643 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
getChainKey,
|
|
4
|
+
getNetworkName
|
|
5
|
+
} from "./chunk-7QHCSJDN.js";
|
|
6
|
+
import {
|
|
7
|
+
hexToNumber,
|
|
8
|
+
numberToHex
|
|
9
|
+
} from "./chunk-LOSXI36Y.js";
|
|
10
|
+
|
|
11
|
+
// src/wallets/walletConnectors/abcWallet/abcProvider.ts
|
|
12
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
13
|
+
import { parseGwei } from "viem";
|
|
14
|
+
var EventEmitter = class {
|
|
15
|
+
constructor() {
|
|
16
|
+
this.events = /* @__PURE__ */ new Map();
|
|
17
|
+
}
|
|
18
|
+
on(event, listener) {
|
|
19
|
+
if (!this.events.has(event)) {
|
|
20
|
+
this.events.set(event, []);
|
|
21
|
+
}
|
|
22
|
+
this.events.get(event).push(listener);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
off(event, listener) {
|
|
26
|
+
const listeners = this.events.get(event);
|
|
27
|
+
if (listeners) {
|
|
28
|
+
const index = listeners.indexOf(listener);
|
|
29
|
+
if (index !== -1) {
|
|
30
|
+
listeners.splice(index, 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
removeListener(event, listener) {
|
|
36
|
+
return this.off(event, listener);
|
|
37
|
+
}
|
|
38
|
+
emit(event, ...args) {
|
|
39
|
+
const listeners = this.events.get(event);
|
|
40
|
+
if (listeners) {
|
|
41
|
+
for (const listener of listeners) {
|
|
42
|
+
listener(...args);
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
removeAllListeners(event) {
|
|
49
|
+
if (event) {
|
|
50
|
+
this.events.delete(event);
|
|
51
|
+
} else {
|
|
52
|
+
this.events.clear();
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var ProviderRpcError = class extends Error {
|
|
58
|
+
constructor(code, message, data) {
|
|
59
|
+
super(message);
|
|
60
|
+
this.code = code;
|
|
61
|
+
this.data = data;
|
|
62
|
+
this.name = "ProviderRpcError";
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var ErrorCode = {
|
|
66
|
+
USER_REJECTED: 4001,
|
|
67
|
+
UNAUTHORIZED: 4100,
|
|
68
|
+
UNSUPPORTED_METHOD: 4200,
|
|
69
|
+
DISCONNECTED: 4900,
|
|
70
|
+
CHAIN_DISCONNECTED: 4901,
|
|
71
|
+
INVALID_PARAMS: -32602,
|
|
72
|
+
INTERNAL_ERROR: -32603
|
|
73
|
+
};
|
|
74
|
+
var AbcEvmProvider = class extends EventEmitter {
|
|
75
|
+
constructor(client) {
|
|
76
|
+
super();
|
|
77
|
+
this.wallet = null;
|
|
78
|
+
this.chainId = 1;
|
|
79
|
+
// Default to Ethereum mainnet
|
|
80
|
+
this.connected = false;
|
|
81
|
+
this.client = client;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Set wallet information
|
|
85
|
+
*/
|
|
86
|
+
setWallet(wallet) {
|
|
87
|
+
const previousAddress = this.wallet?.address;
|
|
88
|
+
const previousChainId = this.chainId;
|
|
89
|
+
this.wallet = wallet;
|
|
90
|
+
this.chainId = wallet.chainId;
|
|
91
|
+
this.connected = true;
|
|
92
|
+
if (previousAddress !== wallet.address) {
|
|
93
|
+
this.emit("accountsChanged", [wallet.address]);
|
|
94
|
+
}
|
|
95
|
+
if (previousChainId !== wallet.chainId) {
|
|
96
|
+
this.emit("chainChanged", numberToHex(wallet.chainId));
|
|
97
|
+
}
|
|
98
|
+
this.emit("connect", { chainId: numberToHex(wallet.chainId) });
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Clear wallet (disconnect)
|
|
102
|
+
*/
|
|
103
|
+
clearWallet() {
|
|
104
|
+
this.wallet = null;
|
|
105
|
+
this.connected = false;
|
|
106
|
+
this.emit("disconnect", {
|
|
107
|
+
code: ErrorCode.DISCONNECTED,
|
|
108
|
+
message: "User disconnected"
|
|
109
|
+
});
|
|
110
|
+
this.emit("accountsChanged", []);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Set request interceptor for sign confirmation
|
|
114
|
+
* The interceptor is called before signing operations to show confirmation UI
|
|
115
|
+
*/
|
|
116
|
+
setRequestInterceptor(interceptor) {
|
|
117
|
+
this.requestInterceptor = interceptor;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Set TalkenApiClient for backend-proxied transaction flow
|
|
121
|
+
* When set, transaction methods will use a single API call instead of multi-step WaaS
|
|
122
|
+
*/
|
|
123
|
+
setTalkenApi(talkenApi) {
|
|
124
|
+
this.talkenApi = talkenApi;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Call request interceptor if configured
|
|
128
|
+
* Called by specific signing/transaction methods that need user confirmation
|
|
129
|
+
* @returns Resolved transaction with user modifications if changed in confirmation modal
|
|
130
|
+
*/
|
|
131
|
+
async callInterceptor(method, params) {
|
|
132
|
+
if (!this.requestInterceptor) {
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
const request = {
|
|
136
|
+
method,
|
|
137
|
+
params,
|
|
138
|
+
chainId: this.chainId,
|
|
139
|
+
address: this.wallet?.address || ""
|
|
140
|
+
};
|
|
141
|
+
return this.requestInterceptor(request);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* EIP-1193 request method
|
|
145
|
+
*/
|
|
146
|
+
async request(args) {
|
|
147
|
+
const { method, params } = args;
|
|
148
|
+
switch (method) {
|
|
149
|
+
case "eth_requestAccounts":
|
|
150
|
+
return this.eth_requestAccounts();
|
|
151
|
+
case "eth_accounts":
|
|
152
|
+
return this.eth_accounts();
|
|
153
|
+
case "eth_chainId":
|
|
154
|
+
return this.eth_chainId();
|
|
155
|
+
case "eth_sendTransaction":
|
|
156
|
+
case "wallet_sendTransaction":
|
|
157
|
+
return this.eth_sendTransaction(params);
|
|
158
|
+
case "eth_signTransaction":
|
|
159
|
+
return this.eth_signTransaction(params);
|
|
160
|
+
case "personal_sign":
|
|
161
|
+
return this.personal_sign(params);
|
|
162
|
+
case "eth_sign":
|
|
163
|
+
return this.eth_sign(params);
|
|
164
|
+
case "eth_signTypedData":
|
|
165
|
+
case "eth_signTypedData_v3":
|
|
166
|
+
case "eth_signTypedData_v4":
|
|
167
|
+
return this.eth_signTypedData(params);
|
|
168
|
+
case "wallet_getCapabilities":
|
|
169
|
+
return this.wallet_getCapabilities();
|
|
170
|
+
case "eth_signAuthorization":
|
|
171
|
+
return this.eth_signAuthorization(params);
|
|
172
|
+
case "wallet_switchEthereumChain":
|
|
173
|
+
return this.wallet_switchEthereumChain(params);
|
|
174
|
+
case "wallet_addEthereumChain":
|
|
175
|
+
return this.wallet_addEthereumChain(params);
|
|
176
|
+
case "eth_estimateGas":
|
|
177
|
+
return this.eth_estimateGas(params);
|
|
178
|
+
case "eth_getTransactionCount":
|
|
179
|
+
return this.eth_getTransactionCount(
|
|
180
|
+
Array.isArray(params) ? params : []
|
|
181
|
+
);
|
|
182
|
+
case "eth_blockNumber":
|
|
183
|
+
case "eth_call":
|
|
184
|
+
case "eth_gasPrice":
|
|
185
|
+
case "eth_getBalance":
|
|
186
|
+
case "eth_getBlockByHash":
|
|
187
|
+
case "eth_getBlockByNumber":
|
|
188
|
+
case "eth_getCode":
|
|
189
|
+
case "eth_getStorageAt":
|
|
190
|
+
case "eth_getTransactionByHash":
|
|
191
|
+
case "eth_getTransactionReceipt":
|
|
192
|
+
throw new ProviderRpcError(
|
|
193
|
+
ErrorCode.UNSUPPORTED_METHOD,
|
|
194
|
+
`Method ${method} should be handled by RPC provider`
|
|
195
|
+
);
|
|
196
|
+
default:
|
|
197
|
+
throw new ProviderRpcError(
|
|
198
|
+
ErrorCode.UNSUPPORTED_METHOD,
|
|
199
|
+
`Method ${method} not supported`
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Request accounts (EIP-1193)
|
|
205
|
+
*/
|
|
206
|
+
async eth_requestAccounts() {
|
|
207
|
+
if (!this.wallet) {
|
|
208
|
+
throw new ProviderRpcError(
|
|
209
|
+
ErrorCode.UNAUTHORIZED,
|
|
210
|
+
"Wallet not connected"
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
return [this.wallet.address];
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Get accounts
|
|
217
|
+
*/
|
|
218
|
+
async eth_accounts() {
|
|
219
|
+
if (!this.wallet) {
|
|
220
|
+
return [];
|
|
221
|
+
}
|
|
222
|
+
return [this.wallet.address];
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get chain ID
|
|
226
|
+
*/
|
|
227
|
+
async eth_chainId() {
|
|
228
|
+
return numberToHex(this.chainId);
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Send transaction
|
|
232
|
+
*/
|
|
233
|
+
async eth_sendTransaction(params) {
|
|
234
|
+
if (!this.wallet) {
|
|
235
|
+
throw new ProviderRpcError(
|
|
236
|
+
ErrorCode.UNAUTHORIZED,
|
|
237
|
+
"Wallet not connected"
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
241
|
+
throw new ProviderRpcError(
|
|
242
|
+
ErrorCode.INVALID_PARAMS,
|
|
243
|
+
"Invalid transaction params"
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const resolved = await this.callInterceptor("eth_sendTransaction", params);
|
|
247
|
+
const tx = params[0];
|
|
248
|
+
if (resolved) {
|
|
249
|
+
if (resolved.data) {
|
|
250
|
+
tx.data = resolved.data;
|
|
251
|
+
}
|
|
252
|
+
if (resolved.gasFee?.maxFeePerGas) {
|
|
253
|
+
try {
|
|
254
|
+
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
255
|
+
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.error(
|
|
258
|
+
"[AbcProvider] \u274C Failed to parse maxFeePerGas:",
|
|
259
|
+
error
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
if (resolved.gasFee?.maxPriorityFeePerGas) {
|
|
264
|
+
try {
|
|
265
|
+
const priorityFeeWei = parseGwei(
|
|
266
|
+
resolved.gasFee.maxPriorityFeePerGas
|
|
267
|
+
);
|
|
268
|
+
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
269
|
+
} catch (error) {
|
|
270
|
+
console.error(
|
|
271
|
+
"[AbcProvider] \u274C Failed to parse maxPriorityFeePerGas:",
|
|
272
|
+
error
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
const isContractDeployment = !tx.to || tx.to === "0x" || tx.to === "0x0" || tx.to === "0x0000000000000000000000000000000000000000";
|
|
278
|
+
if (isContractDeployment) {
|
|
279
|
+
tx.to = "0x";
|
|
280
|
+
} else if (!tx.to) {
|
|
281
|
+
throw new ProviderRpcError(
|
|
282
|
+
ErrorCode.INVALID_PARAMS,
|
|
283
|
+
'Transaction must have "to" field'
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
287
|
+
if (!pinHash) {
|
|
288
|
+
throw new ProviderRpcError(
|
|
289
|
+
ErrorCode.INTERNAL_ERROR,
|
|
290
|
+
"PIN hash not found. Please login again."
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
const hexValue = tx.value || "0x0";
|
|
294
|
+
const amountWei = BigInt(hexValue).toString();
|
|
295
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
296
|
+
const result = await api.evm.sendTransaction({
|
|
297
|
+
chainKey: getChainKey(this.chainId),
|
|
298
|
+
to: tx.to,
|
|
299
|
+
amountWei,
|
|
300
|
+
pin: pinHash,
|
|
301
|
+
data: tx.data || "0x",
|
|
302
|
+
gasLimit: tx.gas || tx.gasLimit,
|
|
303
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
304
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas
|
|
305
|
+
});
|
|
306
|
+
return result.txHash;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Sign transaction (without sending)
|
|
310
|
+
*/
|
|
311
|
+
async eth_signTransaction(params) {
|
|
312
|
+
if (!this.wallet) {
|
|
313
|
+
throw new ProviderRpcError(
|
|
314
|
+
ErrorCode.UNAUTHORIZED,
|
|
315
|
+
"Wallet not connected"
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
319
|
+
throw new ProviderRpcError(
|
|
320
|
+
ErrorCode.INVALID_PARAMS,
|
|
321
|
+
"Invalid transaction params"
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
const resolved = await this.callInterceptor("eth_signTransaction", params);
|
|
325
|
+
const tx = params[0];
|
|
326
|
+
if (resolved) {
|
|
327
|
+
if (resolved.data) {
|
|
328
|
+
tx.data = resolved.data;
|
|
329
|
+
}
|
|
330
|
+
if (resolved.gasFee?.maxFeePerGas) {
|
|
331
|
+
try {
|
|
332
|
+
const maxFeeWei = parseGwei(resolved.gasFee.maxFeePerGas);
|
|
333
|
+
tx.maxFeePerGas = `0x${maxFeeWei.toString(16)}`;
|
|
334
|
+
} catch (error) {
|
|
335
|
+
console.error(
|
|
336
|
+
"[AbcProvider] \u274C Failed to parse maxFeePerGas:",
|
|
337
|
+
error
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
if (resolved.gasFee?.maxPriorityFeePerGas) {
|
|
342
|
+
try {
|
|
343
|
+
const priorityFeeWei = parseGwei(
|
|
344
|
+
resolved.gasFee.maxPriorityFeePerGas
|
|
345
|
+
);
|
|
346
|
+
tx.maxPriorityFeePerGas = `0x${priorityFeeWei.toString(16)}`;
|
|
347
|
+
} catch (error) {
|
|
348
|
+
console.error(
|
|
349
|
+
"[AbcProvider] \u274C Failed to parse maxPriorityFeePerGas:",
|
|
350
|
+
error
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
356
|
+
const result = await api.evm.signTransaction({
|
|
357
|
+
network: getNetworkName(this.chainId),
|
|
358
|
+
to: tx.to,
|
|
359
|
+
value: tx.value || "0x0",
|
|
360
|
+
data: tx.data || "0x",
|
|
361
|
+
gasLimit: tx.gas || tx.gasLimit,
|
|
362
|
+
maxFeePerGas: tx.maxFeePerGas,
|
|
363
|
+
maxPriorityFeePerGas: tx.maxPriorityFeePerGas,
|
|
364
|
+
nonce: tx.nonce ? String(Number.parseInt(tx.nonce, 16)) : void 0
|
|
365
|
+
});
|
|
366
|
+
return result.signature;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Personal sign (EIP-191)
|
|
370
|
+
*/
|
|
371
|
+
async personal_sign(params) {
|
|
372
|
+
if (!this.wallet) {
|
|
373
|
+
console.error("[AbcProvider] \u274C Wallet not connected");
|
|
374
|
+
throw new ProviderRpcError(
|
|
375
|
+
ErrorCode.UNAUTHORIZED,
|
|
376
|
+
"Wallet not connected"
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
380
|
+
console.error("[AbcProvider] \u274C Invalid params:", params);
|
|
381
|
+
throw new ProviderRpcError(
|
|
382
|
+
ErrorCode.INVALID_PARAMS,
|
|
383
|
+
"Invalid personal_sign params"
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
await this.callInterceptor("personal_sign", params);
|
|
387
|
+
const [message, address] = params;
|
|
388
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
389
|
+
console.error("[AbcProvider] \u274C Address mismatch");
|
|
390
|
+
throw new ProviderRpcError(
|
|
391
|
+
ErrorCode.INVALID_PARAMS,
|
|
392
|
+
"Address does not match connected wallet"
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
396
|
+
const network = getNetworkName(this.chainId);
|
|
397
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash") || void 0;
|
|
398
|
+
const result = await api.evm.signPersonal({
|
|
399
|
+
network,
|
|
400
|
+
message,
|
|
401
|
+
address,
|
|
402
|
+
pin: pinHash
|
|
403
|
+
});
|
|
404
|
+
return result.signature;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Eth sign
|
|
408
|
+
*/
|
|
409
|
+
async eth_sign(params) {
|
|
410
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
411
|
+
throw new ProviderRpcError(
|
|
412
|
+
ErrorCode.INVALID_PARAMS,
|
|
413
|
+
"Invalid eth_sign params"
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
const [address, message] = params;
|
|
417
|
+
return this.personal_sign([message, address]);
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Sign typed data (EIP-712)
|
|
421
|
+
*/
|
|
422
|
+
async eth_signTypedData(params) {
|
|
423
|
+
if (!this.wallet) {
|
|
424
|
+
throw new ProviderRpcError(
|
|
425
|
+
ErrorCode.UNAUTHORIZED,
|
|
426
|
+
"Wallet not connected"
|
|
427
|
+
);
|
|
428
|
+
}
|
|
429
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
430
|
+
throw new ProviderRpcError(
|
|
431
|
+
ErrorCode.INVALID_PARAMS,
|
|
432
|
+
"Invalid signTypedData params"
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
await this.callInterceptor("eth_signTypedData_v4", params);
|
|
436
|
+
const [address, typedData] = params;
|
|
437
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
438
|
+
throw new ProviderRpcError(
|
|
439
|
+
ErrorCode.INVALID_PARAMS,
|
|
440
|
+
"Address does not match connected wallet"
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
444
|
+
const network = getNetworkName(this.chainId);
|
|
445
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash") || void 0;
|
|
446
|
+
const result = await api.evm.signTypedData({
|
|
447
|
+
network,
|
|
448
|
+
typedData: typeof typedData === "string" ? typedData : JSON.stringify(typedData),
|
|
449
|
+
pin: pinHash,
|
|
450
|
+
email: this.wallet.email
|
|
451
|
+
});
|
|
452
|
+
return result.signature;
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Return normalized wallet capabilities for ABC embedded wallets.
|
|
456
|
+
* ABC supports EIP-7702 authorization signing via talken-api.
|
|
457
|
+
*/
|
|
458
|
+
async wallet_getCapabilities() {
|
|
459
|
+
return {
|
|
460
|
+
supportsTypedDataV4: true,
|
|
461
|
+
supports7702Authorization: true,
|
|
462
|
+
supports5792Batch: false,
|
|
463
|
+
supportsPaymasterService: false,
|
|
464
|
+
supportsPermit2RelayHints: true,
|
|
465
|
+
walletType: "abc-embedded"
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Sign EIP-7702 authorization via Talken API.
|
|
470
|
+
*/
|
|
471
|
+
async eth_signAuthorization(params) {
|
|
472
|
+
if (!this.wallet) {
|
|
473
|
+
throw new ProviderRpcError(
|
|
474
|
+
ErrorCode.UNAUTHORIZED,
|
|
475
|
+
"Wallet not connected"
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
if (!Array.isArray(params) || params.length < 2) {
|
|
479
|
+
throw new ProviderRpcError(
|
|
480
|
+
ErrorCode.INVALID_PARAMS,
|
|
481
|
+
"Invalid signAuthorization params"
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
const [address, authorization] = params;
|
|
485
|
+
if (address.toLowerCase() !== this.wallet.address.toLowerCase()) {
|
|
486
|
+
throw new ProviderRpcError(
|
|
487
|
+
ErrorCode.INVALID_PARAMS,
|
|
488
|
+
"Address does not match connected wallet"
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
if (!authorization?.address || authorization.chainId == null || authorization.nonce == null) {
|
|
492
|
+
throw new ProviderRpcError(
|
|
493
|
+
ErrorCode.INVALID_PARAMS,
|
|
494
|
+
"Authorization payload is incomplete"
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
await this.callInterceptor("eth_signAuthorization", params);
|
|
498
|
+
const api = this.talkenApi || getTalkenApiClient();
|
|
499
|
+
const network = getNetworkName(this.chainId);
|
|
500
|
+
const pinHash = localStorage.getItem("talkenkit_abc_pin_hash") || void 0;
|
|
501
|
+
const chainIdValue = typeof authorization.chainId === "string" ? Number(BigInt(authorization.chainId)) : Number(authorization.chainId);
|
|
502
|
+
const nonceValue = typeof authorization.nonce === "string" ? BigInt(authorization.nonce).toString() : String(authorization.nonce);
|
|
503
|
+
const result = await api.evm.signAuthorization({
|
|
504
|
+
network,
|
|
505
|
+
authorization: {
|
|
506
|
+
chainId: chainIdValue,
|
|
507
|
+
address: authorization.address,
|
|
508
|
+
nonce: nonceValue
|
|
509
|
+
},
|
|
510
|
+
pin: pinHash,
|
|
511
|
+
email: this.wallet.email
|
|
512
|
+
});
|
|
513
|
+
return result.authorization;
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Switch Ethereum chain
|
|
517
|
+
*/
|
|
518
|
+
async wallet_switchEthereumChain(params) {
|
|
519
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
520
|
+
throw new ProviderRpcError(
|
|
521
|
+
ErrorCode.INVALID_PARAMS,
|
|
522
|
+
"Invalid switchEthereumChain params"
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
const { chainId } = params[0];
|
|
526
|
+
const newChainId = hexToNumber(chainId);
|
|
527
|
+
if (this.chainId === newChainId) {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
const _previousChainId = this.chainId;
|
|
531
|
+
this.chainId = newChainId;
|
|
532
|
+
if (this.wallet) {
|
|
533
|
+
this.wallet.chainId = newChainId;
|
|
534
|
+
}
|
|
535
|
+
this.emit("chainChanged", numberToHex(newChainId));
|
|
536
|
+
return null;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Add Ethereum chain
|
|
540
|
+
*/
|
|
541
|
+
async wallet_addEthereumChain(params) {
|
|
542
|
+
return this.wallet_switchEthereumChain(params);
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Get transaction count (nonce) using ABC WaaS API
|
|
546
|
+
*/
|
|
547
|
+
async eth_getTransactionCount(params) {
|
|
548
|
+
const address = params[0]?.toLowerCase();
|
|
549
|
+
if (!address) {
|
|
550
|
+
throw new ProviderRpcError(
|
|
551
|
+
ErrorCode.INVALID_PARAMS,
|
|
552
|
+
"Missing address parameter"
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
const currentChainId = this.chainId;
|
|
556
|
+
try {
|
|
557
|
+
const nonce = await this.client.getTransactionCount({
|
|
558
|
+
chainId: currentChainId,
|
|
559
|
+
address
|
|
560
|
+
});
|
|
561
|
+
return nonce;
|
|
562
|
+
} catch (error) {
|
|
563
|
+
console.error(
|
|
564
|
+
"[AbcEvmProvider] \u274C Failed to get transaction count from ABC WaaS:",
|
|
565
|
+
error
|
|
566
|
+
);
|
|
567
|
+
throw new ProviderRpcError(
|
|
568
|
+
ErrorCode.INTERNAL_ERROR,
|
|
569
|
+
`Failed to get transaction count: ${error instanceof Error ? error.message : String(error)}`
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
/**
|
|
574
|
+
* Estimate gas for transaction
|
|
575
|
+
* Uses ABC WaaS gas estimation API with fallback
|
|
576
|
+
*/
|
|
577
|
+
async eth_estimateGas(params) {
|
|
578
|
+
if (!Array.isArray(params) || params.length === 0) {
|
|
579
|
+
throw new ProviderRpcError(
|
|
580
|
+
ErrorCode.INVALID_PARAMS,
|
|
581
|
+
"Invalid estimateGas params"
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
const tx = params[0];
|
|
585
|
+
if (!tx.to) {
|
|
586
|
+
throw new ProviderRpcError(
|
|
587
|
+
ErrorCode.INVALID_PARAMS,
|
|
588
|
+
'Transaction must have "to" field'
|
|
589
|
+
);
|
|
590
|
+
}
|
|
591
|
+
try {
|
|
592
|
+
const gasLimit = await this.client.estimateGas({
|
|
593
|
+
chainId: this.chainId,
|
|
594
|
+
from: tx.from || this.wallet?.address,
|
|
595
|
+
to: tx.to,
|
|
596
|
+
value: tx.value,
|
|
597
|
+
data: tx.data
|
|
598
|
+
});
|
|
599
|
+
return gasLimit;
|
|
600
|
+
} catch (error) {
|
|
601
|
+
console.warn(
|
|
602
|
+
"[AbcEvmProvider] Gas estimation failed, using fallback:",
|
|
603
|
+
error
|
|
604
|
+
);
|
|
605
|
+
if (tx.data && tx.data !== "0x") {
|
|
606
|
+
return "0x493e0";
|
|
607
|
+
}
|
|
608
|
+
return "0x5208";
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Check if connected
|
|
613
|
+
*/
|
|
614
|
+
isConnected() {
|
|
615
|
+
return this.connected;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Get current wallet
|
|
619
|
+
*/
|
|
620
|
+
getWallet() {
|
|
621
|
+
return this.wallet;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* Get current chain ID
|
|
625
|
+
*/
|
|
626
|
+
getChainId() {
|
|
627
|
+
return this.chainId;
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
function createAbcEvmProvider(client, talkenApi) {
|
|
631
|
+
const provider = new AbcEvmProvider(client);
|
|
632
|
+
if (talkenApi) {
|
|
633
|
+
provider.setTalkenApi(talkenApi);
|
|
634
|
+
}
|
|
635
|
+
return provider;
|
|
636
|
+
}
|
|
637
|
+
var createAbcProvider = createAbcEvmProvider;
|
|
638
|
+
|
|
639
|
+
export {
|
|
640
|
+
AbcEvmProvider,
|
|
641
|
+
createAbcEvmProvider,
|
|
642
|
+
createAbcProvider
|
|
643
|
+
};
|