@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
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
createAbcEvmProvider
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import {
|
|
6
|
-
resolveTalkenApiUrl
|
|
7
|
-
} from "./chunk-GFWUFYT2.js";
|
|
4
|
+
} from "./chunk-5ZTGAJ4K.js";
|
|
8
5
|
import {
|
|
9
6
|
createTalkenApiClient
|
|
10
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-SN2BNZTO.js";
|
|
11
8
|
import {
|
|
12
|
-
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import {
|
|
15
|
-
setTalkenApiClient
|
|
16
|
-
} from "./chunk-R6ZE7JAZ.js";
|
|
9
|
+
resolveTalkenApiUrl
|
|
10
|
+
} from "./chunk-GFWUFYT2.js";
|
|
17
11
|
import {
|
|
18
12
|
setGlobalDefaultBitcoinNetwork,
|
|
19
13
|
setGlobalDefaultChainId,
|
|
@@ -28,18 +22,25 @@ import {
|
|
|
28
22
|
loadAuthState,
|
|
29
23
|
loadFromStorage,
|
|
30
24
|
saveAuthState
|
|
31
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-RU6FIXMD.js";
|
|
26
|
+
import {
|
|
27
|
+
getTalkenApiClient,
|
|
28
|
+
ownsTalkenApiStorage,
|
|
29
|
+
setTalkenApiClient
|
|
30
|
+
} from "./chunk-2YCHXOLC.js";
|
|
31
|
+
import {
|
|
32
|
+
getCredentialManager
|
|
33
|
+
} from "./chunk-WUNGUZIQ.js";
|
|
32
34
|
import {
|
|
33
35
|
STORAGE_NS,
|
|
34
36
|
get,
|
|
35
37
|
remove
|
|
36
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-MRUBFVXX.js";
|
|
37
39
|
import {
|
|
38
40
|
loadTgAccessKey
|
|
39
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-TPLIG5I7.js";
|
|
40
42
|
|
|
41
43
|
// src/wallets/walletConnectors/abcWallet/abcConnector.ts
|
|
42
|
-
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
43
44
|
import { createConnector } from "wagmi";
|
|
44
45
|
var logger = createLogger("AbcConnector");
|
|
45
46
|
function abcConnector(options) {
|
|
@@ -71,6 +72,8 @@ function abcConnector(options) {
|
|
|
71
72
|
let accountsChangedHandler;
|
|
72
73
|
let chainChangedHandler;
|
|
73
74
|
let disconnectHandler;
|
|
75
|
+
let connectedRevision = talkenApi.getSessionRevision();
|
|
76
|
+
const ownsConnectedSession = () => getTalkenApiClient() === talkenApi && talkenApi.getSessionRevision() === connectedRevision && ownsTalkenApiStorage(talkenApi);
|
|
74
77
|
return {
|
|
75
78
|
id: "abc",
|
|
76
79
|
name: "ABC Wallet",
|
|
@@ -79,12 +82,22 @@ function abcConnector(options) {
|
|
|
79
82
|
* Connect wallet
|
|
80
83
|
*/
|
|
81
84
|
async connect() {
|
|
85
|
+
let revision = talkenApi.getSessionRevision();
|
|
86
|
+
const assertCurrent = () => {
|
|
87
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
88
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
89
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
90
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
91
|
+
if (talkenApi.isAccessKeyMode() && !talkenApi.getAuthenticatedWalletSession())
|
|
92
|
+
throw new Error("ABC_LOGIN_REQUIRED");
|
|
93
|
+
};
|
|
94
|
+
assertCurrent();
|
|
82
95
|
try {
|
|
83
96
|
const authState = loadAuthState();
|
|
84
97
|
if (!authState || !authState.isAuthenticated || !authState.wallet) {
|
|
85
98
|
throw new Error("ABC_LOGIN_REQUIRED");
|
|
86
99
|
}
|
|
87
|
-
if (isAccessKeyMode) {
|
|
100
|
+
if (talkenApi.isAccessKeyMode()) {
|
|
88
101
|
const w = authState.wallet;
|
|
89
102
|
provider.setWallet({
|
|
90
103
|
address: w.address,
|
|
@@ -98,21 +111,26 @@ function abcConnector(options) {
|
|
|
98
111
|
email: w.email || authState.user?.email || ""
|
|
99
112
|
});
|
|
100
113
|
} else {
|
|
101
|
-
provider.setWallet(authState.wallet);
|
|
102
114
|
if (authState.accessToken && authState.refreshToken && authState.expiresAt) {
|
|
115
|
+
if (talkenApi.getAccessToken() !== authState.accessToken || talkenApi.getRefreshToken() !== authState.refreshToken)
|
|
116
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
103
117
|
talkenApi.setTokens(
|
|
104
118
|
authState.accessToken,
|
|
105
119
|
authState.refreshToken,
|
|
106
120
|
authState.expiresAt
|
|
107
121
|
);
|
|
108
122
|
}
|
|
123
|
+
provider.setWallet(authState.wallet);
|
|
109
124
|
}
|
|
125
|
+
revision = talkenApi.getSessionRevision();
|
|
110
126
|
const accounts = await provider.request({
|
|
111
127
|
method: "eth_requestAccounts"
|
|
112
128
|
});
|
|
129
|
+
assertCurrent();
|
|
113
130
|
let currentChainId = await provider.request({
|
|
114
131
|
method: "eth_chainId"
|
|
115
132
|
});
|
|
133
|
+
assertCurrent();
|
|
116
134
|
const currentChainIdNumber = Number(currentChainId);
|
|
117
135
|
const isChainSupported = wagmiConfig.chains.some(
|
|
118
136
|
(c) => c.id === currentChainIdNumber
|
|
@@ -123,6 +141,7 @@ function abcConnector(options) {
|
|
|
123
141
|
method: "wallet_switchEthereumChain",
|
|
124
142
|
params: [{ chainId: `0x${fallbackChainId.toString(16)}` }]
|
|
125
143
|
});
|
|
144
|
+
assertCurrent();
|
|
126
145
|
currentChainId = `0x${fallbackChainId.toString(16)}`;
|
|
127
146
|
if (authState.wallet) {
|
|
128
147
|
authState.wallet.chainId = fallbackChainId;
|
|
@@ -133,6 +152,8 @@ function abcConnector(options) {
|
|
|
133
152
|
provider.removeListener("accountsChanged", accountsChangedHandler);
|
|
134
153
|
}
|
|
135
154
|
accountsChangedHandler = (accounts2) => {
|
|
155
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
156
|
+
return;
|
|
136
157
|
wagmiConfig.emitter.emit("change", {
|
|
137
158
|
accounts: accounts2
|
|
138
159
|
});
|
|
@@ -142,6 +163,8 @@ function abcConnector(options) {
|
|
|
142
163
|
provider.removeListener("chainChanged", chainChangedHandler);
|
|
143
164
|
}
|
|
144
165
|
chainChangedHandler = (chainId) => {
|
|
166
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
167
|
+
return;
|
|
145
168
|
wagmiConfig.emitter.emit("change", {
|
|
146
169
|
chainId: Number(chainId)
|
|
147
170
|
});
|
|
@@ -151,10 +174,13 @@ function abcConnector(options) {
|
|
|
151
174
|
provider.removeListener("disconnect", disconnectHandler);
|
|
152
175
|
}
|
|
153
176
|
disconnectHandler = () => {
|
|
177
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
178
|
+
return;
|
|
154
179
|
wagmiConfig.emitter.emit("disconnect");
|
|
155
180
|
this.onDisconnect();
|
|
156
181
|
};
|
|
157
182
|
provider.on("disconnect", disconnectHandler);
|
|
183
|
+
connectedRevision = revision;
|
|
158
184
|
wagmiConfig.emitter.emit("connect", {
|
|
159
185
|
accounts,
|
|
160
186
|
chainId: Number(currentChainId)
|
|
@@ -179,6 +205,10 @@ function abcConnector(options) {
|
|
|
179
205
|
* Disconnect wallet
|
|
180
206
|
*/
|
|
181
207
|
async disconnect() {
|
|
208
|
+
if (!ownsConnectedSession())
|
|
209
|
+
return;
|
|
210
|
+
talkenApi.clearSession();
|
|
211
|
+
const revision = talkenApi.getSessionRevision();
|
|
182
212
|
if (accountsChangedHandler) {
|
|
183
213
|
provider.removeListener("accountsChanged", accountsChangedHandler);
|
|
184
214
|
accountsChangedHandler = void 0;
|
|
@@ -192,7 +222,10 @@ function abcConnector(options) {
|
|
|
192
222
|
disconnectHandler = void 0;
|
|
193
223
|
}
|
|
194
224
|
provider.clearWallet();
|
|
195
|
-
talkenApi
|
|
225
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
226
|
+
return;
|
|
227
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
228
|
+
return;
|
|
196
229
|
remove(STORAGE_NS.API, "access_key_raw");
|
|
197
230
|
clearAuthState();
|
|
198
231
|
getCredentialManager().clear();
|
|
@@ -226,8 +259,14 @@ function abcConnector(options) {
|
|
|
226
259
|
* Auto-refreshes access token if expired but refresh token is valid
|
|
227
260
|
*/
|
|
228
261
|
async isAuthorized() {
|
|
262
|
+
const revision = talkenApi.getSessionRevision();
|
|
263
|
+
const isCurrentSession = () => ownsTalkenApiStorage(talkenApi) && getTalkenApiClient() === talkenApi && talkenApi.getSessionRevision() === revision;
|
|
264
|
+
if (!isCurrentSession())
|
|
265
|
+
return false;
|
|
229
266
|
try {
|
|
230
|
-
if (isAccessKeyMode) {
|
|
267
|
+
if (talkenApi.isAccessKeyMode()) {
|
|
268
|
+
if (!talkenApi.getAuthenticatedWalletSession())
|
|
269
|
+
return false;
|
|
231
270
|
if (provider.isConnected())
|
|
232
271
|
return true;
|
|
233
272
|
const hasKey = !!effectiveAccessKey || !!get(STORAGE_NS.API, "access_key_raw") || !!loadTgAccessKey();
|
|
@@ -245,30 +284,22 @@ function abcConnector(options) {
|
|
|
245
284
|
return true;
|
|
246
285
|
}
|
|
247
286
|
if (talkenApi.isAccessKeyMode()) {
|
|
248
|
-
return
|
|
287
|
+
return !!talkenApi.getAuthenticatedWalletSession();
|
|
249
288
|
}
|
|
250
|
-
const refreshToken = loadFromStorage(
|
|
251
|
-
"refresh_token" /* REFRESH_TOKEN */
|
|
252
|
-
);
|
|
289
|
+
const refreshToken = talkenApi.getRefreshToken() || loadFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
253
290
|
if (!refreshToken) {
|
|
254
291
|
clearStorage();
|
|
255
292
|
return false;
|
|
256
293
|
}
|
|
257
294
|
try {
|
|
258
|
-
|
|
259
|
-
if (!
|
|
260
|
-
clearStorage();
|
|
295
|
+
await talkenApi.auth.refresh();
|
|
296
|
+
if (!isCurrentSession())
|
|
261
297
|
return false;
|
|
262
|
-
}
|
|
263
|
-
const res = await api.auth.refresh();
|
|
264
|
-
talkenApi.setTokens(
|
|
265
|
-
res.accessToken,
|
|
266
|
-
res.refreshToken,
|
|
267
|
-
Date.now() + res.expiresIn * 1e3
|
|
268
|
-
);
|
|
269
298
|
const updatedState = loadAuthState();
|
|
270
299
|
return updatedState?.isAuthenticated ?? false;
|
|
271
300
|
} catch (error) {
|
|
301
|
+
if (!isCurrentSession())
|
|
302
|
+
return false;
|
|
272
303
|
logger.error("Token refresh failed:", error);
|
|
273
304
|
clearStorage();
|
|
274
305
|
return false;
|
|
@@ -282,11 +313,21 @@ function abcConnector(options) {
|
|
|
282
313
|
* Switch chain
|
|
283
314
|
*/
|
|
284
315
|
async switchChain({ chainId }) {
|
|
316
|
+
const revision = talkenApi.getSessionRevision();
|
|
317
|
+
const assertCurrent = () => {
|
|
318
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
319
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
320
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
321
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
322
|
+
};
|
|
323
|
+
assertCurrent();
|
|
285
324
|
await provider.request({
|
|
286
325
|
method: "wallet_switchEthereumChain",
|
|
287
326
|
params: [{ chainId: `0x${chainId.toString(16)}` }]
|
|
288
327
|
});
|
|
328
|
+
assertCurrent();
|
|
289
329
|
const newChainId = await this.getChainId();
|
|
330
|
+
assertCurrent();
|
|
290
331
|
const authState = loadAuthState();
|
|
291
332
|
if (authState?.wallet) {
|
|
292
333
|
authState.wallet.chainId = newChainId;
|
|
@@ -328,7 +369,15 @@ function abcConnector(options) {
|
|
|
328
369
|
* Handle disconnect
|
|
329
370
|
*/
|
|
330
371
|
onDisconnect(_error) {
|
|
372
|
+
if (!ownsConnectedSession())
|
|
373
|
+
return;
|
|
374
|
+
talkenApi.clearSession();
|
|
375
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
376
|
+
return;
|
|
377
|
+
const revision = talkenApi.getSessionRevision();
|
|
331
378
|
provider.clearWallet();
|
|
379
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
380
|
+
return;
|
|
332
381
|
clearAuthState();
|
|
333
382
|
wagmiConfig.emitter.emit("disconnect");
|
|
334
383
|
}
|
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
createAbcEvmProvider
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PWJLUT4Z.js";
|
|
5
5
|
import {
|
|
6
6
|
createTalkenApiClient
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-5GTFKQGQ.js";
|
|
8
8
|
import {
|
|
9
9
|
resolveTalkenApiUrl
|
|
10
10
|
} from "./chunk-GFWUFYT2.js";
|
|
11
|
-
import {
|
|
12
|
-
getCredentialManager
|
|
13
|
-
} from "./chunk-SORKIBWX.js";
|
|
14
|
-
import {
|
|
15
|
-
setTalkenApiClient
|
|
16
|
-
} from "./chunk-R6ZE7JAZ.js";
|
|
17
11
|
import {
|
|
18
12
|
setGlobalDefaultBitcoinNetwork,
|
|
19
13
|
setGlobalDefaultChainId,
|
|
@@ -22,24 +16,31 @@ import {
|
|
|
22
16
|
import {
|
|
23
17
|
createLogger
|
|
24
18
|
} from "./chunk-2DFJ6LEN.js";
|
|
19
|
+
import {
|
|
20
|
+
getTalkenApiClient,
|
|
21
|
+
ownsTalkenApiStorage,
|
|
22
|
+
setTalkenApiClient
|
|
23
|
+
} from "./chunk-2YCHXOLC.js";
|
|
24
|
+
import {
|
|
25
|
+
getCredentialManager
|
|
26
|
+
} from "./chunk-WUNGUZIQ.js";
|
|
25
27
|
import {
|
|
26
28
|
clearAuthState,
|
|
27
29
|
clearStorage,
|
|
28
30
|
loadAuthState,
|
|
29
31
|
loadFromStorage,
|
|
30
32
|
saveAuthState
|
|
31
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-RU6FIXMD.js";
|
|
32
34
|
import {
|
|
33
35
|
STORAGE_NS,
|
|
34
36
|
get,
|
|
35
37
|
remove
|
|
36
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-MRUBFVXX.js";
|
|
37
39
|
import {
|
|
38
40
|
loadTgAccessKey
|
|
39
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-TPLIG5I7.js";
|
|
40
42
|
|
|
41
43
|
// src/wallets/walletConnectors/abcWallet/abcConnector.ts
|
|
42
|
-
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
43
44
|
import { createConnector } from "wagmi";
|
|
44
45
|
var logger = createLogger("AbcConnector");
|
|
45
46
|
function abcConnector(options) {
|
|
@@ -71,6 +72,8 @@ function abcConnector(options) {
|
|
|
71
72
|
let accountsChangedHandler;
|
|
72
73
|
let chainChangedHandler;
|
|
73
74
|
let disconnectHandler;
|
|
75
|
+
let connectedRevision = talkenApi.getSessionRevision();
|
|
76
|
+
const ownsConnectedSession = () => getTalkenApiClient() === talkenApi && talkenApi.getSessionRevision() === connectedRevision && ownsTalkenApiStorage(talkenApi);
|
|
74
77
|
return {
|
|
75
78
|
id: "abc",
|
|
76
79
|
name: "ABC Wallet",
|
|
@@ -79,12 +82,22 @@ function abcConnector(options) {
|
|
|
79
82
|
* Connect wallet
|
|
80
83
|
*/
|
|
81
84
|
async connect() {
|
|
85
|
+
let revision = talkenApi.getSessionRevision();
|
|
86
|
+
const assertCurrent = () => {
|
|
87
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
88
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
89
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
90
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
91
|
+
if (talkenApi.isAccessKeyMode() && !talkenApi.getAuthenticatedWalletSession())
|
|
92
|
+
throw new Error("ABC_LOGIN_REQUIRED");
|
|
93
|
+
};
|
|
94
|
+
assertCurrent();
|
|
82
95
|
try {
|
|
83
96
|
const authState = loadAuthState();
|
|
84
97
|
if (!authState || !authState.isAuthenticated || !authState.wallet) {
|
|
85
98
|
throw new Error("ABC_LOGIN_REQUIRED");
|
|
86
99
|
}
|
|
87
|
-
if (isAccessKeyMode) {
|
|
100
|
+
if (talkenApi.isAccessKeyMode()) {
|
|
88
101
|
const w = authState.wallet;
|
|
89
102
|
provider.setWallet({
|
|
90
103
|
address: w.address,
|
|
@@ -98,21 +111,26 @@ function abcConnector(options) {
|
|
|
98
111
|
email: w.email || authState.user?.email || ""
|
|
99
112
|
});
|
|
100
113
|
} else {
|
|
101
|
-
provider.setWallet(authState.wallet);
|
|
102
114
|
if (authState.accessToken && authState.refreshToken && authState.expiresAt) {
|
|
115
|
+
if (talkenApi.getAccessToken() !== authState.accessToken || talkenApi.getRefreshToken() !== authState.refreshToken)
|
|
116
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
103
117
|
talkenApi.setTokens(
|
|
104
118
|
authState.accessToken,
|
|
105
119
|
authState.refreshToken,
|
|
106
120
|
authState.expiresAt
|
|
107
121
|
);
|
|
108
122
|
}
|
|
123
|
+
provider.setWallet(authState.wallet);
|
|
109
124
|
}
|
|
125
|
+
revision = talkenApi.getSessionRevision();
|
|
110
126
|
const accounts = await provider.request({
|
|
111
127
|
method: "eth_requestAccounts"
|
|
112
128
|
});
|
|
129
|
+
assertCurrent();
|
|
113
130
|
let currentChainId = await provider.request({
|
|
114
131
|
method: "eth_chainId"
|
|
115
132
|
});
|
|
133
|
+
assertCurrent();
|
|
116
134
|
const currentChainIdNumber = Number(currentChainId);
|
|
117
135
|
const isChainSupported = wagmiConfig.chains.some(
|
|
118
136
|
(c) => c.id === currentChainIdNumber
|
|
@@ -123,6 +141,7 @@ function abcConnector(options) {
|
|
|
123
141
|
method: "wallet_switchEthereumChain",
|
|
124
142
|
params: [{ chainId: `0x${fallbackChainId.toString(16)}` }]
|
|
125
143
|
});
|
|
144
|
+
assertCurrent();
|
|
126
145
|
currentChainId = `0x${fallbackChainId.toString(16)}`;
|
|
127
146
|
if (authState.wallet) {
|
|
128
147
|
authState.wallet.chainId = fallbackChainId;
|
|
@@ -133,6 +152,8 @@ function abcConnector(options) {
|
|
|
133
152
|
provider.removeListener("accountsChanged", accountsChangedHandler);
|
|
134
153
|
}
|
|
135
154
|
accountsChangedHandler = (accounts2) => {
|
|
155
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
156
|
+
return;
|
|
136
157
|
wagmiConfig.emitter.emit("change", {
|
|
137
158
|
accounts: accounts2
|
|
138
159
|
});
|
|
@@ -142,6 +163,8 @@ function abcConnector(options) {
|
|
|
142
163
|
provider.removeListener("chainChanged", chainChangedHandler);
|
|
143
164
|
}
|
|
144
165
|
chainChangedHandler = (chainId) => {
|
|
166
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
167
|
+
return;
|
|
145
168
|
wagmiConfig.emitter.emit("change", {
|
|
146
169
|
chainId: Number(chainId)
|
|
147
170
|
});
|
|
@@ -151,10 +174,13 @@ function abcConnector(options) {
|
|
|
151
174
|
provider.removeListener("disconnect", disconnectHandler);
|
|
152
175
|
}
|
|
153
176
|
disconnectHandler = () => {
|
|
177
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
178
|
+
return;
|
|
154
179
|
wagmiConfig.emitter.emit("disconnect");
|
|
155
180
|
this.onDisconnect();
|
|
156
181
|
};
|
|
157
182
|
provider.on("disconnect", disconnectHandler);
|
|
183
|
+
connectedRevision = revision;
|
|
158
184
|
wagmiConfig.emitter.emit("connect", {
|
|
159
185
|
accounts,
|
|
160
186
|
chainId: Number(currentChainId)
|
|
@@ -179,6 +205,10 @@ function abcConnector(options) {
|
|
|
179
205
|
* Disconnect wallet
|
|
180
206
|
*/
|
|
181
207
|
async disconnect() {
|
|
208
|
+
if (!ownsConnectedSession())
|
|
209
|
+
return;
|
|
210
|
+
talkenApi.clearSession();
|
|
211
|
+
const revision = talkenApi.getSessionRevision();
|
|
182
212
|
if (accountsChangedHandler) {
|
|
183
213
|
provider.removeListener("accountsChanged", accountsChangedHandler);
|
|
184
214
|
accountsChangedHandler = void 0;
|
|
@@ -192,7 +222,10 @@ function abcConnector(options) {
|
|
|
192
222
|
disconnectHandler = void 0;
|
|
193
223
|
}
|
|
194
224
|
provider.clearWallet();
|
|
195
|
-
talkenApi
|
|
225
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
226
|
+
return;
|
|
227
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
228
|
+
return;
|
|
196
229
|
remove(STORAGE_NS.API, "access_key_raw");
|
|
197
230
|
clearAuthState();
|
|
198
231
|
getCredentialManager().clear();
|
|
@@ -226,8 +259,14 @@ function abcConnector(options) {
|
|
|
226
259
|
* Auto-refreshes access token if expired but refresh token is valid
|
|
227
260
|
*/
|
|
228
261
|
async isAuthorized() {
|
|
262
|
+
const revision = talkenApi.getSessionRevision();
|
|
263
|
+
const isCurrentSession = () => ownsTalkenApiStorage(talkenApi) && getTalkenApiClient() === talkenApi && talkenApi.getSessionRevision() === revision;
|
|
264
|
+
if (!isCurrentSession())
|
|
265
|
+
return false;
|
|
229
266
|
try {
|
|
230
|
-
if (isAccessKeyMode) {
|
|
267
|
+
if (talkenApi.isAccessKeyMode()) {
|
|
268
|
+
if (!talkenApi.getAuthenticatedWalletSession())
|
|
269
|
+
return false;
|
|
231
270
|
if (provider.isConnected())
|
|
232
271
|
return true;
|
|
233
272
|
const hasKey = !!effectiveAccessKey || !!get(STORAGE_NS.API, "access_key_raw") || !!loadTgAccessKey();
|
|
@@ -245,30 +284,22 @@ function abcConnector(options) {
|
|
|
245
284
|
return true;
|
|
246
285
|
}
|
|
247
286
|
if (talkenApi.isAccessKeyMode()) {
|
|
248
|
-
return
|
|
287
|
+
return !!talkenApi.getAuthenticatedWalletSession();
|
|
249
288
|
}
|
|
250
|
-
const refreshToken = loadFromStorage(
|
|
251
|
-
"refresh_token" /* REFRESH_TOKEN */
|
|
252
|
-
);
|
|
289
|
+
const refreshToken = talkenApi.getRefreshToken() || loadFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
253
290
|
if (!refreshToken) {
|
|
254
291
|
clearStorage();
|
|
255
292
|
return false;
|
|
256
293
|
}
|
|
257
294
|
try {
|
|
258
|
-
|
|
259
|
-
if (!
|
|
260
|
-
clearStorage();
|
|
295
|
+
await talkenApi.auth.refresh();
|
|
296
|
+
if (!isCurrentSession())
|
|
261
297
|
return false;
|
|
262
|
-
}
|
|
263
|
-
const res = await api.auth.refresh();
|
|
264
|
-
talkenApi.setTokens(
|
|
265
|
-
res.accessToken,
|
|
266
|
-
res.refreshToken,
|
|
267
|
-
Date.now() + res.expiresIn * 1e3
|
|
268
|
-
);
|
|
269
298
|
const updatedState = loadAuthState();
|
|
270
299
|
return updatedState?.isAuthenticated ?? false;
|
|
271
300
|
} catch (error) {
|
|
301
|
+
if (!isCurrentSession())
|
|
302
|
+
return false;
|
|
272
303
|
logger.error("Token refresh failed:", error);
|
|
273
304
|
clearStorage();
|
|
274
305
|
return false;
|
|
@@ -282,11 +313,21 @@ function abcConnector(options) {
|
|
|
282
313
|
* Switch chain
|
|
283
314
|
*/
|
|
284
315
|
async switchChain({ chainId }) {
|
|
316
|
+
const revision = talkenApi.getSessionRevision();
|
|
317
|
+
const assertCurrent = () => {
|
|
318
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
319
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
320
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
321
|
+
throw new Error("AUTH_SESSION_CHANGED");
|
|
322
|
+
};
|
|
323
|
+
assertCurrent();
|
|
285
324
|
await provider.request({
|
|
286
325
|
method: "wallet_switchEthereumChain",
|
|
287
326
|
params: [{ chainId: `0x${chainId.toString(16)}` }]
|
|
288
327
|
});
|
|
328
|
+
assertCurrent();
|
|
289
329
|
const newChainId = await this.getChainId();
|
|
330
|
+
assertCurrent();
|
|
290
331
|
const authState = loadAuthState();
|
|
291
332
|
if (authState?.wallet) {
|
|
292
333
|
authState.wallet.chainId = newChainId;
|
|
@@ -328,7 +369,15 @@ function abcConnector(options) {
|
|
|
328
369
|
* Handle disconnect
|
|
329
370
|
*/
|
|
330
371
|
onDisconnect(_error) {
|
|
372
|
+
if (!ownsConnectedSession())
|
|
373
|
+
return;
|
|
374
|
+
talkenApi.clearSession();
|
|
375
|
+
if (!ownsTalkenApiStorage(talkenApi))
|
|
376
|
+
return;
|
|
377
|
+
const revision = talkenApi.getSessionRevision();
|
|
331
378
|
provider.clearWallet();
|
|
379
|
+
if (getTalkenApiClient() !== talkenApi || talkenApi.getSessionRevision() !== revision)
|
|
380
|
+
return;
|
|
332
381
|
clearAuthState();
|
|
333
382
|
wagmiConfig.emitter.emit("disconnect");
|
|
334
383
|
}
|