@talken/talkenkit 2.5.1 → 2.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -28
- package/dist/{AbcCredentialManager-5W3B7GI4.js → AbcCredentialManager-DDHLW2IH.js} +1 -1
- package/dist/AbcCredentialManager-JV4ZBMKF.js +7 -0
- package/dist/TalkenApiSingleton-TECFDCT4.js +9 -0
- package/dist/{abcWallet-O5IRLUXL.js → abcWallet-2BVT5XFX.js} +2 -2
- package/dist/abcWallet-BFCI4NEM.js +162 -0
- package/dist/{chunk-PN6K4CMZ.js → chunk-ALBABQ53.js} +1 -4
- package/dist/chunk-DNEDHHS4.js +379 -0
- package/dist/chunk-KOK5ZBR4.js +5447 -0
- package/dist/chunk-R6ZE7JAZ.js +15 -0
- package/dist/{chunk-UHZL3WSM.js → chunk-WPRIYR63.js} +194 -69
- package/dist/components/ConnectOptions/AbcWaasAuth/AbcWaasAuthFlow.d.ts +6 -32
- package/dist/components/ConnectOptions/AbcWaasAuth/AbcWaasAuthSections.d.ts +0 -9
- package/dist/components/ConnectOptions/AbcWaasAuth/hooks/useAbcWaasAuth.d.ts +3 -12
- package/dist/components/ConnectOptions/AbcWaasAuth/types.d.ts +1 -8
- package/dist/components/ConnectOptions/PinAuth/PinAuthFlow.d.ts +6 -4
- package/dist/components/ProfileDetails/ProfileDetails.d.ts +5 -5
- package/dist/hooks/useMultiChainBalances.d.ts +9 -0
- package/dist/index.js +1344 -1423
- package/dist/wallets/walletConnectors/abcWallet/AbcCredentialManager.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/AbcEvmAutoConnector.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcAccessKeyProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinConnector.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcBitcoinProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/abcProvider.js +4 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +7 -7
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +44 -44
- package/dist/wallets/walletConnectors/abcWallet/abcTronProvider.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +8 -8
- package/dist/wallets/walletConnectors/abcWallet/api/ConfigApi.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.d.ts +44 -0
- package/dist/wallets/walletConnectors/abcWallet/api/TalkenApiClient.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/api/TokenApi.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/api/WalletscanApi.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +6 -6
- package/dist/wallets/walletConnectors/abcWallet/constants.d.ts +3 -0
- package/dist/wallets/walletConnectors/abcWallet/constants.js +5 -3
- package/dist/wallets/walletConnectors/abcWallet/index.js +19 -19
- package/dist/wallets/walletConnectors/abcWallet/sessionUtils.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +4 -0
- package/dist/wallets/walletConnectors/abcWallet/utils.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/walletGeneration.js +3 -3
- 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-4JZPP3S7.js → chunk-2N244XPQ.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-QKK3OPQA.js → chunk-36BJXEBA.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-FKI5AZVH.js → chunk-3K3KYVRN.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-URS2KVYK.js → chunk-5DK36WJ2.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-5ERWBR7D.js +977 -0
- package/dist/wallets/walletConnectors/chunk-6KRX73ED.js +230 -0
- package/dist/wallets/walletConnectors/{chunk-H2AZTZMM.js → chunk-6L5G54IX.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-6WF4SXLB.js +156 -0
- package/dist/wallets/walletConnectors/{chunk-PF65YS3T.js → chunk-A66MTFML.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-LIGH2LEU.js → chunk-ACLPF2UW.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-KIYXONNH.js → chunk-BHEVY4QY.js} +2 -35
- package/dist/wallets/walletConnectors/{chunk-YKFI6ZGM.js → chunk-BXH3GDX5.js} +1 -1
- package/dist/wallets/walletConnectors/{chunk-RGYZNNB6.js → chunk-C4ADBB6M.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-CABLJOMU.js +194 -0
- package/dist/wallets/walletConnectors/{chunk-RX2VOIUB.js → chunk-DPTDOCWL.js} +1 -4
- package/dist/wallets/walletConnectors/{chunk-6TAU7OQK.js → chunk-DW36LXIV.js} +8 -7
- package/dist/wallets/walletConnectors/chunk-EBTKWCIS.js +224 -0
- package/dist/wallets/walletConnectors/{chunk-25ZDAJ3L.js → chunk-EZS3GXZN.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-FBJ5H6PM.js +300 -0
- package/dist/wallets/walletConnectors/chunk-IM7DEERX.js +585 -0
- package/dist/wallets/walletConnectors/chunk-J3YPHDHM.js +827 -0
- package/dist/wallets/walletConnectors/chunk-JADQLTFW.js +194 -0
- package/dist/wallets/walletConnectors/{chunk-L6FCF3FH.js → chunk-L3HWFGTN.js} +2 -2
- package/dist/wallets/walletConnectors/chunk-L6WDO3ZN.js +445 -0
- package/dist/wallets/walletConnectors/chunk-MO2AXXLI.js +30 -0
- package/dist/wallets/walletConnectors/chunk-NLA45GHJ.js +300 -0
- package/dist/wallets/walletConnectors/chunk-NU3ITJNK.js +1485 -0
- package/dist/wallets/walletConnectors/{chunk-HWRZGGGN.js → chunk-NULM3THX.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-OMOYFHBT.js +1485 -0
- package/dist/wallets/walletConnectors/{chunk-4YEALKXG.js → chunk-OOCL4OPQ.js} +29 -11
- package/dist/wallets/walletConnectors/chunk-PVPSVCVQ.js +96 -0
- package/dist/wallets/walletConnectors/chunk-VBNZ7HA3.js +241 -0
- package/dist/wallets/walletConnectors/chunk-VDWJ3NQ5.js +52 -0
- package/dist/wallets/walletConnectors/chunk-VLHDGDFH.js +273 -0
- package/dist/wallets/walletConnectors/chunk-VMCIDCO5.js +54 -0
- package/dist/wallets/walletConnectors/chunk-VNL7XEWF.js +54 -0
- package/dist/wallets/walletConnectors/chunk-YV6IZWGE.js +393 -0
- package/dist/wallets/walletConnectors/{chunk-645DT4TS.js → chunk-ZLH3W5PQ.js} +2 -2
- 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 +67 -67
- 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/klipWallet/klipWallet.js +2 -2
- package/dist/wallets/walletConnectors/klipWallet-TBZJ5GGT.js +7 -0
- 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 +12 -11
- package/LICENSE +0 -9
- package/dist/wallets/walletConnectors/klipWallet-PPTYYB5G.js +0 -7
|
@@ -165,15 +165,12 @@ var TALKEN_API_ENDPOINTS = {
|
|
|
165
165
|
SOLANA_TX_STATUS: "/wallet/solana/tx-status",
|
|
166
166
|
TX_BTC: "/wallet/tx/btc",
|
|
167
167
|
TX_TVM: "/wallet/tx/tvm",
|
|
168
|
-
TRON_UTIL: "/wallet/tron",
|
|
169
168
|
// ── Gas (WaaS proxy) ───────────────────────────────────────────────
|
|
170
169
|
GAS_PRICE: "/wallet/gas/price",
|
|
171
170
|
GAS_SUGGESTED: "/wallet/gas/suggested",
|
|
172
171
|
GAS_ESTIMATE: "/wallet/gas/estimate",
|
|
173
|
-
// ── Nonce
|
|
172
|
+
// ── Nonce (WaaS proxy) ─────────────────────────────────────────────
|
|
174
173
|
NONCE: "/wallet/nonce",
|
|
175
|
-
ADDRESS_BALANCE: "/wallet/address/balance",
|
|
176
|
-
ETH_CALL: "/wallet/contract/eth-call",
|
|
177
174
|
// ── Relayer ────────────────────────────────────────────────────────
|
|
178
175
|
RELAYER_FEE_ESTIMATE: "/relayer/estimate-fee",
|
|
179
176
|
// ── Config / Runtime ───────────────────────────────────────────────
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
abcConnector
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OOCL4OPQ.js";
|
|
5
|
+
import {
|
|
6
|
+
createTalkenApiClient
|
|
7
|
+
} from "./chunk-5ERWBR7D.js";
|
|
5
8
|
import {
|
|
6
9
|
resolveTalkenApiUrl
|
|
7
10
|
} from "./chunk-GFWUFYT2.js";
|
|
8
11
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ABC_WALLET_METADATA
|
|
13
|
-
} from "./chunk-RX2VOIUB.js";
|
|
12
|
+
ABC_WALLET_METADATA,
|
|
13
|
+
loadTgAccessKey
|
|
14
|
+
} from "./chunk-6KRX73ED.js";
|
|
14
15
|
|
|
15
16
|
// src/wallets/walletConnectors/abcWallet/abcWallet.ts
|
|
16
17
|
import { setTalkenApiClient } from "@talken/talkenkit";
|
|
@@ -21,7 +22,7 @@ var abcWallet = (specificOptions) => ({ projectId }) => {
|
|
|
21
22
|
debug: specificOptions?.environment === "development"
|
|
22
23
|
});
|
|
23
24
|
setTalkenApiClient(talkenApi);
|
|
24
|
-
const accessKey = specificOptions?.accessKey || (
|
|
25
|
+
const accessKey = specificOptions?.accessKey || loadTgAccessKey() || null;
|
|
25
26
|
const config = {
|
|
26
27
|
talkenApiUrl,
|
|
27
28
|
apiKey: specificOptions?.apiKey,
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
AbcError
|
|
4
|
+
} from "./chunk-4P3SPC44.js";
|
|
5
|
+
import {
|
|
6
|
+
PIN_CONFIG,
|
|
7
|
+
STORAGE_PREFIX,
|
|
8
|
+
TOKEN_EXPIRY
|
|
9
|
+
} from "./chunk-6KRX73ED.js";
|
|
10
|
+
|
|
11
|
+
// src/wallets/walletConnectors/abcWallet/utils.ts
|
|
12
|
+
async function hashPin(pin) {
|
|
13
|
+
if (typeof window === "undefined" || !window.crypto?.subtle) {
|
|
14
|
+
return btoa(pin);
|
|
15
|
+
}
|
|
16
|
+
const encoder = new TextEncoder();
|
|
17
|
+
const data = encoder.encode(pin);
|
|
18
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", data);
|
|
19
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
20
|
+
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
21
|
+
return hashHex;
|
|
22
|
+
}
|
|
23
|
+
function validatePin(pin) {
|
|
24
|
+
if (!pin || typeof pin !== "string") {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
const pinLength = pin.length;
|
|
28
|
+
if (pinLength < PIN_CONFIG.MIN_LENGTH || pinLength > PIN_CONFIG.MAX_LENGTH) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
return /^\d+$/.test(pin);
|
|
32
|
+
}
|
|
33
|
+
function validateEmail(email) {
|
|
34
|
+
if (!email || typeof email !== "string") {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
38
|
+
return emailRegex.test(email);
|
|
39
|
+
}
|
|
40
|
+
function getStorageKey(key) {
|
|
41
|
+
return `${STORAGE_PREFIX}${key}`;
|
|
42
|
+
}
|
|
43
|
+
function saveToStorage(key, value) {
|
|
44
|
+
if (typeof window === "undefined")
|
|
45
|
+
return;
|
|
46
|
+
try {
|
|
47
|
+
const storageKey = getStorageKey(key);
|
|
48
|
+
const serialized = JSON.stringify(value);
|
|
49
|
+
localStorage.setItem(storageKey, serialized);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Failed to save to storage:", error);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function loadFromStorage(key) {
|
|
55
|
+
if (typeof window === "undefined")
|
|
56
|
+
return null;
|
|
57
|
+
try {
|
|
58
|
+
const storageKey = getStorageKey(key);
|
|
59
|
+
const serialized = localStorage.getItem(storageKey);
|
|
60
|
+
if (!serialized)
|
|
61
|
+
return null;
|
|
62
|
+
try {
|
|
63
|
+
return JSON.parse(serialized);
|
|
64
|
+
} catch {
|
|
65
|
+
return serialized;
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error("Failed to load from storage:", error);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function removeFromStorage(key) {
|
|
73
|
+
if (typeof window === "undefined")
|
|
74
|
+
return;
|
|
75
|
+
try {
|
|
76
|
+
const storageKey = getStorageKey(key);
|
|
77
|
+
localStorage.removeItem(storageKey);
|
|
78
|
+
} catch (error) {
|
|
79
|
+
console.error("Failed to remove from storage:", error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function clearStorage() {
|
|
83
|
+
if (typeof window === "undefined")
|
|
84
|
+
return;
|
|
85
|
+
const keysToRemove = [];
|
|
86
|
+
for (let i = 0; i < localStorage.length; i++) {
|
|
87
|
+
const key = localStorage.key(i);
|
|
88
|
+
if (key?.startsWith(STORAGE_PREFIX)) {
|
|
89
|
+
keysToRemove.push(key);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
for (const key of keysToRemove) {
|
|
93
|
+
localStorage.removeItem(key);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
function isTokenExpired(expiresAt) {
|
|
97
|
+
if (!expiresAt)
|
|
98
|
+
return true;
|
|
99
|
+
return Date.now() >= expiresAt - TOKEN_EXPIRY.REFRESH_BUFFER;
|
|
100
|
+
}
|
|
101
|
+
function calculateExpiryTimestamp(expiresIn) {
|
|
102
|
+
return Date.now() + expiresIn * 1e3;
|
|
103
|
+
}
|
|
104
|
+
function saveAuthState(state) {
|
|
105
|
+
saveToStorage("auth_state" /* AUTH_STATE */, state);
|
|
106
|
+
if (state.user) {
|
|
107
|
+
saveToStorage("user" /* USER */, state.user);
|
|
108
|
+
}
|
|
109
|
+
if (state.wallet) {
|
|
110
|
+
saveToStorage("wallet" /* WALLET */, state.wallet);
|
|
111
|
+
}
|
|
112
|
+
if (state.solanaWallet) {
|
|
113
|
+
saveToStorage("solana_wallet" /* SOLANA_WALLET */, state.solanaWallet);
|
|
114
|
+
}
|
|
115
|
+
if (state.bitcoinWallet) {
|
|
116
|
+
saveToStorage("bitcoin_wallet" /* BITCOIN_WALLET */, state.bitcoinWallet);
|
|
117
|
+
}
|
|
118
|
+
if (state.tronWallet) {
|
|
119
|
+
saveToStorage("tron_wallet" /* TRON_WALLET */, state.tronWallet);
|
|
120
|
+
}
|
|
121
|
+
if (state.accessToken) {
|
|
122
|
+
saveToStorage("access_token" /* ACCESS_TOKEN */, state.accessToken);
|
|
123
|
+
}
|
|
124
|
+
if (state.refreshToken) {
|
|
125
|
+
saveToStorage("refresh_token" /* REFRESH_TOKEN */, state.refreshToken);
|
|
126
|
+
}
|
|
127
|
+
if (state.expiresAt) {
|
|
128
|
+
saveToStorage("expires_at" /* EXPIRES_AT */, state.expiresAt);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function hydrateAuthStateFromIndividualStorage(state) {
|
|
132
|
+
const user = loadFromStorage("user" /* USER */);
|
|
133
|
+
const wallet = loadFromStorage("wallet" /* WALLET */);
|
|
134
|
+
const solanaWallet = loadFromStorage(
|
|
135
|
+
"solana_wallet" /* SOLANA_WALLET */
|
|
136
|
+
);
|
|
137
|
+
const bitcoinWallet = loadFromStorage(
|
|
138
|
+
"bitcoin_wallet" /* BITCOIN_WALLET */
|
|
139
|
+
);
|
|
140
|
+
const tronWallet = loadFromStorage("tron_wallet" /* TRON_WALLET */);
|
|
141
|
+
const accessToken = loadFromStorage("access_token" /* ACCESS_TOKEN */);
|
|
142
|
+
const refreshToken = loadFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
143
|
+
const expiresAt = loadFromStorage("expires_at" /* EXPIRES_AT */);
|
|
144
|
+
const nextState = {
|
|
145
|
+
...state,
|
|
146
|
+
user: state.user || user || null,
|
|
147
|
+
wallet: state.wallet || wallet || null,
|
|
148
|
+
solanaWallet: state.solanaWallet || solanaWallet || null,
|
|
149
|
+
bitcoinWallet: state.bitcoinWallet || bitcoinWallet || null,
|
|
150
|
+
tronWallet: state.tronWallet || tronWallet || null,
|
|
151
|
+
accessToken: state.accessToken || accessToken || null,
|
|
152
|
+
refreshToken: state.refreshToken || refreshToken || null,
|
|
153
|
+
expiresAt: state.expiresAt || expiresAt || null
|
|
154
|
+
};
|
|
155
|
+
const wasHydrated = nextState.user !== state.user || nextState.wallet !== state.wallet || nextState.solanaWallet !== state.solanaWallet || nextState.bitcoinWallet !== state.bitcoinWallet || nextState.tronWallet !== state.tronWallet || nextState.accessToken !== state.accessToken || nextState.refreshToken !== state.refreshToken || nextState.expiresAt !== state.expiresAt;
|
|
156
|
+
if (wasHydrated) {
|
|
157
|
+
saveToStorage("auth_state" /* AUTH_STATE */, nextState);
|
|
158
|
+
}
|
|
159
|
+
return nextState;
|
|
160
|
+
}
|
|
161
|
+
function loadAuthState() {
|
|
162
|
+
const state = loadFromStorage("auth_state" /* AUTH_STATE */);
|
|
163
|
+
if (state) {
|
|
164
|
+
const isExpired = state.accessKeyMode ? state.accessKeyExpiresAt && Date.now() >= new Date(state.accessKeyExpiresAt).getTime() : state.accessToken && isTokenExpired(state.expiresAt);
|
|
165
|
+
if (isExpired) {
|
|
166
|
+
clearStorage();
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
return hydrateAuthStateFromIndividualStorage(state);
|
|
170
|
+
}
|
|
171
|
+
const user = loadFromStorage("user" /* USER */);
|
|
172
|
+
const wallet = loadFromStorage("wallet" /* WALLET */);
|
|
173
|
+
const solanaWallet = loadFromStorage("solana_wallet" /* SOLANA_WALLET */);
|
|
174
|
+
const accessToken = loadFromStorage("access_token" /* ACCESS_TOKEN */);
|
|
175
|
+
const refreshToken = loadFromStorage("refresh_token" /* REFRESH_TOKEN */);
|
|
176
|
+
const expiresAt = loadFromStorage("expires_at" /* EXPIRES_AT */);
|
|
177
|
+
if (!user || !accessToken) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
const bitcoinWallet = loadFromStorage("bitcoin_wallet" /* BITCOIN_WALLET */);
|
|
181
|
+
const tronWallet = loadFromStorage("tron_wallet" /* TRON_WALLET */);
|
|
182
|
+
return {
|
|
183
|
+
isAuthenticated: true,
|
|
184
|
+
user,
|
|
185
|
+
wallet,
|
|
186
|
+
solanaWallet,
|
|
187
|
+
bitcoinWallet,
|
|
188
|
+
tronWallet,
|
|
189
|
+
accessToken,
|
|
190
|
+
refreshToken,
|
|
191
|
+
expiresAt
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function clearAuthState() {
|
|
195
|
+
clearStorage();
|
|
196
|
+
}
|
|
197
|
+
function createAbcError(code, message, details, statusCode) {
|
|
198
|
+
return new AbcError(code, message, details, statusCode);
|
|
199
|
+
}
|
|
200
|
+
function hexToNumber(hex) {
|
|
201
|
+
return Number.parseInt(hex, 16);
|
|
202
|
+
}
|
|
203
|
+
function numberToHex(num) {
|
|
204
|
+
return `0x${num.toString(16)}`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export {
|
|
208
|
+
hashPin,
|
|
209
|
+
validatePin,
|
|
210
|
+
validateEmail,
|
|
211
|
+
getStorageKey,
|
|
212
|
+
saveToStorage,
|
|
213
|
+
loadFromStorage,
|
|
214
|
+
removeFromStorage,
|
|
215
|
+
clearStorage,
|
|
216
|
+
isTokenExpired,
|
|
217
|
+
calculateExpiryTimestamp,
|
|
218
|
+
saveAuthState,
|
|
219
|
+
loadAuthState,
|
|
220
|
+
clearAuthState,
|
|
221
|
+
createAbcError,
|
|
222
|
+
hexToNumber,
|
|
223
|
+
numberToHex
|
|
224
|
+
};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
setTalkenApiClient
|
|
4
|
+
} from "./chunk-R6ZE7JAZ.js";
|
|
5
|
+
import {
|
|
6
|
+
setGlobalDefaultBitcoinNetwork,
|
|
7
|
+
setGlobalDefaultChainId,
|
|
8
|
+
setGlobalDefaultSolanaNetwork
|
|
9
|
+
} from "./chunk-O4AU63LK.js";
|
|
10
|
+
import {
|
|
11
|
+
createAbcEvmProvider
|
|
12
|
+
} from "./chunk-OMOYFHBT.js";
|
|
13
|
+
import {
|
|
14
|
+
clearAuthState,
|
|
15
|
+
clearStorage,
|
|
16
|
+
loadAuthState,
|
|
17
|
+
loadFromStorage,
|
|
18
|
+
saveAuthState
|
|
19
|
+
} from "./chunk-A66MTFML.js";
|
|
20
|
+
import {
|
|
21
|
+
resolveTalkenApiUrl
|
|
22
|
+
} from "./chunk-GFWUFYT2.js";
|
|
23
|
+
import {
|
|
24
|
+
createTalkenApiClient
|
|
25
|
+
} from "./chunk-BHEVY4QY.js";
|
|
26
|
+
import {
|
|
27
|
+
getCredentialManager
|
|
28
|
+
} from "./chunk-6WF4SXLB.js";
|
|
29
|
+
|
|
30
|
+
// src/wallets/walletConnectors/abcWallet/abcConnector.ts
|
|
31
|
+
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
32
|
+
import { createConnector } from "wagmi";
|
|
33
|
+
function abcConnector(options) {
|
|
34
|
+
const { config } = options;
|
|
35
|
+
if (config.defaultChainId) {
|
|
36
|
+
setGlobalDefaultChainId(config.defaultChainId);
|
|
37
|
+
}
|
|
38
|
+
if (config.defaultSolanaNetwork) {
|
|
39
|
+
setGlobalDefaultSolanaNetwork(config.defaultSolanaNetwork);
|
|
40
|
+
}
|
|
41
|
+
if (config.defaultBitcoinNetwork) {
|
|
42
|
+
setGlobalDefaultBitcoinNetwork(config.defaultBitcoinNetwork);
|
|
43
|
+
}
|
|
44
|
+
return createConnector((wagmiConfig) => {
|
|
45
|
+
const talkenApi = getTalkenApiClient() || createTalkenApiClient({
|
|
46
|
+
baseUrl: resolveTalkenApiUrl(config.talkenApiUrl),
|
|
47
|
+
environment: config.environment,
|
|
48
|
+
debug: config.environment === "development",
|
|
49
|
+
defaultChainId: config.defaultChainId
|
|
50
|
+
});
|
|
51
|
+
setTalkenApiClient(talkenApi);
|
|
52
|
+
const provider = createAbcEvmProvider(talkenApi);
|
|
53
|
+
let accountsChangedHandler;
|
|
54
|
+
let chainChangedHandler;
|
|
55
|
+
let disconnectHandler;
|
|
56
|
+
return {
|
|
57
|
+
id: "abc",
|
|
58
|
+
name: "ABC Wallet",
|
|
59
|
+
type: "abc",
|
|
60
|
+
/**
|
|
61
|
+
* Connect wallet
|
|
62
|
+
*/
|
|
63
|
+
async connect() {
|
|
64
|
+
try {
|
|
65
|
+
const authState = loadAuthState();
|
|
66
|
+
if (!authState || !authState.isAuthenticated || !authState.wallet) {
|
|
67
|
+
throw new Error("ABC_LOGIN_REQUIRED");
|
|
68
|
+
}
|
|
69
|
+
provider.setWallet(authState.wallet);
|
|
70
|
+
if (authState.accessToken && authState.refreshToken && authState.expiresAt) {
|
|
71
|
+
talkenApi.setTokens(
|
|
72
|
+
authState.accessToken,
|
|
73
|
+
authState.refreshToken,
|
|
74
|
+
authState.expiresAt
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
const accounts = await provider.request({
|
|
78
|
+
method: "eth_requestAccounts"
|
|
79
|
+
});
|
|
80
|
+
let currentChainId = await provider.request({
|
|
81
|
+
method: "eth_chainId"
|
|
82
|
+
});
|
|
83
|
+
const currentChainIdNumber = Number(currentChainId);
|
|
84
|
+
const isChainSupported = wagmiConfig.chains.some(
|
|
85
|
+
(c) => c.id === currentChainIdNumber
|
|
86
|
+
);
|
|
87
|
+
if (!isChainSupported && wagmiConfig.chains.length > 0) {
|
|
88
|
+
const fallbackChainId = wagmiConfig.chains[0].id;
|
|
89
|
+
await provider.request({
|
|
90
|
+
method: "wallet_switchEthereumChain",
|
|
91
|
+
params: [{ chainId: `0x${fallbackChainId.toString(16)}` }]
|
|
92
|
+
});
|
|
93
|
+
currentChainId = `0x${fallbackChainId.toString(16)}`;
|
|
94
|
+
if (authState.wallet) {
|
|
95
|
+
authState.wallet.chainId = fallbackChainId;
|
|
96
|
+
saveAuthState(authState);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (accountsChangedHandler) {
|
|
100
|
+
provider.removeListener("accountsChanged", accountsChangedHandler);
|
|
101
|
+
}
|
|
102
|
+
accountsChangedHandler = (accounts2) => {
|
|
103
|
+
wagmiConfig.emitter.emit("change", {
|
|
104
|
+
accounts: accounts2
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
provider.on("accountsChanged", accountsChangedHandler);
|
|
108
|
+
if (chainChangedHandler) {
|
|
109
|
+
provider.removeListener("chainChanged", chainChangedHandler);
|
|
110
|
+
}
|
|
111
|
+
chainChangedHandler = (chainId) => {
|
|
112
|
+
wagmiConfig.emitter.emit("change", {
|
|
113
|
+
chainId: Number(chainId)
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
provider.on("chainChanged", chainChangedHandler);
|
|
117
|
+
if (disconnectHandler) {
|
|
118
|
+
provider.removeListener("disconnect", disconnectHandler);
|
|
119
|
+
}
|
|
120
|
+
disconnectHandler = () => {
|
|
121
|
+
wagmiConfig.emitter.emit("disconnect");
|
|
122
|
+
this.onDisconnect();
|
|
123
|
+
};
|
|
124
|
+
provider.on("disconnect", disconnectHandler);
|
|
125
|
+
wagmiConfig.emitter.emit("connect", {
|
|
126
|
+
accounts,
|
|
127
|
+
chainId: Number(currentChainId)
|
|
128
|
+
});
|
|
129
|
+
return {
|
|
130
|
+
accounts,
|
|
131
|
+
chainId: Number(currentChainId)
|
|
132
|
+
};
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error("\u274C ABC Connector connect() failed:", {
|
|
135
|
+
message: error.message,
|
|
136
|
+
code: error.code,
|
|
137
|
+
error
|
|
138
|
+
});
|
|
139
|
+
if (error.message === "ABC_LOGIN_REQUIRED") {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* Disconnect wallet
|
|
147
|
+
*/
|
|
148
|
+
async disconnect() {
|
|
149
|
+
if (accountsChangedHandler) {
|
|
150
|
+
provider.removeListener("accountsChanged", accountsChangedHandler);
|
|
151
|
+
accountsChangedHandler = void 0;
|
|
152
|
+
}
|
|
153
|
+
if (chainChangedHandler) {
|
|
154
|
+
provider.removeListener("chainChanged", chainChangedHandler);
|
|
155
|
+
chainChangedHandler = void 0;
|
|
156
|
+
}
|
|
157
|
+
if (disconnectHandler) {
|
|
158
|
+
provider.removeListener("disconnect", disconnectHandler);
|
|
159
|
+
disconnectHandler = void 0;
|
|
160
|
+
}
|
|
161
|
+
provider.clearWallet();
|
|
162
|
+
talkenApi.auth.logout();
|
|
163
|
+
clearAuthState();
|
|
164
|
+
getCredentialManager().clear();
|
|
165
|
+
},
|
|
166
|
+
/**
|
|
167
|
+
* Get accounts
|
|
168
|
+
*/
|
|
169
|
+
async getAccounts() {
|
|
170
|
+
const accounts = await provider.request({
|
|
171
|
+
method: "eth_accounts"
|
|
172
|
+
});
|
|
173
|
+
return accounts.map((account) => account);
|
|
174
|
+
},
|
|
175
|
+
/**
|
|
176
|
+
* Get chain ID
|
|
177
|
+
*/
|
|
178
|
+
async getChainId() {
|
|
179
|
+
const chainId = await provider.request({
|
|
180
|
+
method: "eth_chainId"
|
|
181
|
+
});
|
|
182
|
+
return Number(chainId);
|
|
183
|
+
},
|
|
184
|
+
/**
|
|
185
|
+
* Get provider
|
|
186
|
+
*/
|
|
187
|
+
async getProvider() {
|
|
188
|
+
return provider;
|
|
189
|
+
},
|
|
190
|
+
/**
|
|
191
|
+
* Check if authorized (has valid session)
|
|
192
|
+
* Auto-refreshes access token if expired but refresh token is valid
|
|
193
|
+
*/
|
|
194
|
+
async isAuthorized() {
|
|
195
|
+
try {
|
|
196
|
+
const authState = loadAuthState();
|
|
197
|
+
if (!authState || !authState.isAuthenticated) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (!authState.wallet) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (talkenApi.isAuthenticated()) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
const refreshToken = loadFromStorage(
|
|
207
|
+
"refresh_token" /* REFRESH_TOKEN */
|
|
208
|
+
);
|
|
209
|
+
if (!refreshToken) {
|
|
210
|
+
clearStorage();
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
const api = getTalkenApiClient();
|
|
215
|
+
if (!api) {
|
|
216
|
+
clearStorage();
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
const res = await api.auth.refresh();
|
|
220
|
+
talkenApi.setTokens(
|
|
221
|
+
res.accessToken,
|
|
222
|
+
res.refreshToken,
|
|
223
|
+
Date.now() + res.expiresIn * 1e3
|
|
224
|
+
);
|
|
225
|
+
const updatedState = loadAuthState();
|
|
226
|
+
return updatedState?.isAuthenticated ?? false;
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.error("[AbcConnector] Token refresh failed:", error);
|
|
229
|
+
clearStorage();
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
} catch (error) {
|
|
233
|
+
console.error(
|
|
234
|
+
"[AbcConnector] Unexpected error in isAuthorized:",
|
|
235
|
+
error
|
|
236
|
+
);
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
/**
|
|
241
|
+
* Switch chain
|
|
242
|
+
*/
|
|
243
|
+
async switchChain({ chainId }) {
|
|
244
|
+
await provider.request({
|
|
245
|
+
method: "wallet_switchEthereumChain",
|
|
246
|
+
params: [{ chainId: `0x${chainId.toString(16)}` }]
|
|
247
|
+
});
|
|
248
|
+
const newChainId = await this.getChainId();
|
|
249
|
+
const authState = loadAuthState();
|
|
250
|
+
if (authState?.wallet) {
|
|
251
|
+
authState.wallet.chainId = newChainId;
|
|
252
|
+
saveAuthState(authState);
|
|
253
|
+
}
|
|
254
|
+
return wagmiConfig.chains.find((x) => x.id === chainId) ?? {
|
|
255
|
+
id: chainId,
|
|
256
|
+
name: `Chain ${chainId}`,
|
|
257
|
+
nativeCurrency: {
|
|
258
|
+
name: "Ether",
|
|
259
|
+
decimals: 18,
|
|
260
|
+
symbol: "ETH"
|
|
261
|
+
},
|
|
262
|
+
rpcUrls: {
|
|
263
|
+
default: { http: [""] }
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
/**
|
|
268
|
+
* Handle accounts changed
|
|
269
|
+
*/
|
|
270
|
+
onAccountsChanged(accounts) {
|
|
271
|
+
if (accounts.length === 0) {
|
|
272
|
+
this.onDisconnect();
|
|
273
|
+
} else {
|
|
274
|
+
wagmiConfig.emitter.emit("change", {
|
|
275
|
+
accounts
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
/**
|
|
280
|
+
* Handle chain changed
|
|
281
|
+
*/
|
|
282
|
+
onChainChanged(chain) {
|
|
283
|
+
const chainId = Number(chain);
|
|
284
|
+
wagmiConfig.emitter.emit("change", { chainId });
|
|
285
|
+
},
|
|
286
|
+
/**
|
|
287
|
+
* Handle disconnect
|
|
288
|
+
*/
|
|
289
|
+
onDisconnect(_error) {
|
|
290
|
+
provider.clearWallet();
|
|
291
|
+
clearAuthState();
|
|
292
|
+
wagmiConfig.emitter.emit("disconnect");
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export {
|
|
299
|
+
abcConnector
|
|
300
|
+
};
|