@talken/talkenkit 2.5.3 → 2.5.4
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/README.md +28 -8
- package/dist/{abcWallet-BFCI4NEM.js → abcWallet-QJ5BKEXW.js} +1 -1
- package/dist/{chunk-WPRIYR63.js → chunk-YORGXWYS.js} +26 -0
- package/dist/index.js +137 -104
- package/dist/klipWallet-TBZJ5GGT.js +7 -0
- package/dist/wallets/walletConnectors/abcWallet/abcAccessKeyProvider.d.ts +4 -0
- package/dist/wallets/walletConnectors/abcWallet/abcAccessKeyProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcConnector.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +3 -4
- package/dist/wallets/walletConnectors/abcWallet/abcWallet.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/index.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-2N244XPQ.js → chunk-E6ZG77AF.js} +26 -0
- package/dist/wallets/walletConnectors/{chunk-DW36LXIV.js → chunk-G6SV7RAS.js} +1 -1
- package/dist/wallets/walletConnectors/chunk-HKMJ67FD.js +37 -0
- package/dist/wallets/walletConnectors/{chunk-OOCL4OPQ.js → chunk-SDRE2D5I.js} +1 -1
- 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.d.ts +2 -1
- package/dist/wallets/walletConnectors/index.js +65 -61
- 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 +3 -63
- 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
- package/dist/AbcCredentialManager-DDHLW2IH.js +0 -7
- package/dist/abcWallet-2BVT5XFX.js +0 -161
- package/dist/chunk-ALBABQ53.js +0 -354
- package/dist/chunk-KOK5ZBR4.js +0 -5447
- package/dist/wallets/walletConnectors/chunk-6WF4SXLB.js +0 -156
- package/dist/wallets/walletConnectors/chunk-A66MTFML.js +0 -223
- package/dist/wallets/walletConnectors/chunk-ACLPF2UW.js +0 -96
- package/dist/wallets/walletConnectors/chunk-BHEVY4QY.js +0 -827
- package/dist/wallets/walletConnectors/chunk-BXH3GDX5.js +0 -273
- package/dist/wallets/walletConnectors/chunk-CABLJOMU.js +0 -194
- package/dist/wallets/walletConnectors/chunk-DPTDOCWL.js +0 -205
- package/dist/wallets/walletConnectors/chunk-FBJ5H6PM.js +0 -300
- package/dist/wallets/walletConnectors/chunk-IM7DEERX.js +0 -585
- package/dist/wallets/walletConnectors/chunk-J3YPHDHM.js +0 -827
- package/dist/wallets/walletConnectors/chunk-JADQLTFW.js +0 -194
- package/dist/wallets/walletConnectors/chunk-L6WDO3ZN.js +0 -445
- package/dist/wallets/walletConnectors/chunk-MO2AXXLI.js +0 -30
- package/dist/wallets/walletConnectors/chunk-NLA45GHJ.js +0 -300
- package/dist/wallets/walletConnectors/chunk-NU3ITJNK.js +0 -1485
- package/dist/wallets/walletConnectors/chunk-NULM3THX.js +0 -241
- package/dist/wallets/walletConnectors/chunk-OMOYFHBT.js +0 -1485
- package/dist/wallets/walletConnectors/chunk-VDWJ3NQ5.js +0 -52
- package/dist/wallets/walletConnectors/chunk-VMCIDCO5.js +0 -54
- package/dist/wallets/walletConnectors/chunk-VNL7XEWF.js +0 -54
- package/dist/wallets/walletConnectors/chunk-YV6IZWGE.js +0 -393
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
getBitcoinNetwork,
|
|
4
|
-
getEvmNetwork,
|
|
5
|
-
getSolanaNetwork,
|
|
6
|
-
getTronNetwork
|
|
7
|
-
} from "./chunk-O4AU63LK.js";
|
|
8
|
-
import {
|
|
9
|
-
AbcError
|
|
10
|
-
} from "./chunk-4P3SPC44.js";
|
|
11
|
-
import {
|
|
12
|
-
getCredentialManager
|
|
13
|
-
} from "./chunk-6WF4SXLB.js";
|
|
14
|
-
|
|
15
|
-
// src/wallets/walletConnectors/abcWallet/walletGeneration.ts
|
|
16
|
-
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
17
|
-
async function mapApiResponseToWallets(genResponse, infoResponse, email) {
|
|
18
|
-
const accounts = infoResponse?.accounts || [];
|
|
19
|
-
const evmAccount = accounts[0] || infoResponse || {};
|
|
20
|
-
const uid = String(genResponse.uid || evmAccount.uid || "");
|
|
21
|
-
const wid = String(genResponse.wid || evmAccount.wid || "");
|
|
22
|
-
const sid = String(
|
|
23
|
-
evmAccount.sid || evmAccount.ethAddress || genResponse.evmAddress || ""
|
|
24
|
-
);
|
|
25
|
-
const pubkey = String(evmAccount.pubkey || genResponse.pubkey || "");
|
|
26
|
-
const solMaterial = genResponse.solana || {};
|
|
27
|
-
let btcAddress = genResponse.btcAddress || "";
|
|
28
|
-
let trxAddress = genResponse.trxAddress || "";
|
|
29
|
-
if ((!btcAddress || !trxAddress) && pubkey) {
|
|
30
|
-
try {
|
|
31
|
-
const api = getTalkenApiClient();
|
|
32
|
-
if (api) {
|
|
33
|
-
const addrResponse = await api.wallet.getAddressForChain("all");
|
|
34
|
-
if (!btcAddress)
|
|
35
|
-
btcAddress = addrResponse?.btc || addrResponse?.btcAddress || "";
|
|
36
|
-
if (!trxAddress)
|
|
37
|
-
trxAddress = addrResponse?.trx || addrResponse?.trxAddress || "";
|
|
38
|
-
}
|
|
39
|
-
} catch (err) {
|
|
40
|
-
console.warn(
|
|
41
|
-
"[walletGeneration] Failed to derive BTC/TRX addresses:",
|
|
42
|
-
err
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const pvencstr = String(evmAccount.pvencstr || "");
|
|
47
|
-
const edp = String(evmAccount.encryptDevicePassword || "");
|
|
48
|
-
if (uid && wid && sid && pvencstr && edp) {
|
|
49
|
-
getCredentialManager().setEvmSigningCredentials({
|
|
50
|
-
uid,
|
|
51
|
-
wid,
|
|
52
|
-
sid,
|
|
53
|
-
pvencstr,
|
|
54
|
-
encryptDevicePassword: edp
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const evmWallet = {
|
|
58
|
-
uid,
|
|
59
|
-
sessionId: sid,
|
|
60
|
-
keyId: wid,
|
|
61
|
-
encryptedShare: pvencstr,
|
|
62
|
-
secretStore: edp,
|
|
63
|
-
address: genResponse.evmAddress || sid,
|
|
64
|
-
chainId: getEvmNetwork(),
|
|
65
|
-
sid,
|
|
66
|
-
type: "evm",
|
|
67
|
-
email,
|
|
68
|
-
pubkey
|
|
69
|
-
};
|
|
70
|
-
const solanaWallet = {
|
|
71
|
-
uid,
|
|
72
|
-
sessionId: String(solMaterial.shareId || ""),
|
|
73
|
-
keyId: String(solMaterial.keyId || ""),
|
|
74
|
-
encryptedShare: String(solMaterial.encryptedShare || ""),
|
|
75
|
-
secretStore: String(solMaterial.secretStore || ""),
|
|
76
|
-
shareId: String(solMaterial.shareId || ""),
|
|
77
|
-
publicKey: String(solMaterial.publicKey || ""),
|
|
78
|
-
address: genResponse.solAddress || solMaterial.address || "",
|
|
79
|
-
network: getSolanaNetwork()
|
|
80
|
-
};
|
|
81
|
-
const bitcoinWallet = {
|
|
82
|
-
uid,
|
|
83
|
-
sessionId: sid,
|
|
84
|
-
keyId: wid,
|
|
85
|
-
encryptedShare: String(evmAccount.pvencstr || ""),
|
|
86
|
-
shareId: sid,
|
|
87
|
-
publicKey: pubkey,
|
|
88
|
-
address: btcAddress,
|
|
89
|
-
addressType: "bech32",
|
|
90
|
-
network: getBitcoinNetwork()
|
|
91
|
-
};
|
|
92
|
-
const tronWallet = {
|
|
93
|
-
uid,
|
|
94
|
-
sessionId: sid,
|
|
95
|
-
keyId: wid,
|
|
96
|
-
encryptedShare: String(evmAccount.pvencstr || ""),
|
|
97
|
-
shareId: sid,
|
|
98
|
-
publicKey: pubkey,
|
|
99
|
-
address: trxAddress,
|
|
100
|
-
network: getTronNetwork()
|
|
101
|
-
};
|
|
102
|
-
return { evmWallet, solanaWallet, bitcoinWallet, tronWallet };
|
|
103
|
-
}
|
|
104
|
-
async function generateMpcWallets(hashedPin, email) {
|
|
105
|
-
const api = getTalkenApiClient();
|
|
106
|
-
if (!api) {
|
|
107
|
-
throw new AbcError(
|
|
108
|
-
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
109
|
-
"TalkenApiClient not initialized"
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
try {
|
|
113
|
-
const genResponse = await api.wallet.generate(hashedPin, email);
|
|
114
|
-
const infoResponse = await api.wallet.getInfo().catch(() => ({}));
|
|
115
|
-
return await mapApiResponseToWallets(
|
|
116
|
-
genResponse,
|
|
117
|
-
infoResponse,
|
|
118
|
-
email || ""
|
|
119
|
-
);
|
|
120
|
-
} catch (error) {
|
|
121
|
-
throw new AbcError(
|
|
122
|
-
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
123
|
-
`Failed to generate MPC wallets: ${error.message}`,
|
|
124
|
-
{ originalError: error }
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async function recoverMpcWallets(hashedPin, email) {
|
|
129
|
-
const api = getTalkenApiClient();
|
|
130
|
-
if (!api) {
|
|
131
|
-
throw new AbcError(
|
|
132
|
-
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
133
|
-
"TalkenApiClient not initialized"
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
try {
|
|
137
|
-
const genResponse = await api.wallet.recover(hashedPin, email);
|
|
138
|
-
const infoResponse = await api.wallet.getInfo().catch(() => ({}));
|
|
139
|
-
return await mapApiResponseToWallets(
|
|
140
|
-
genResponse,
|
|
141
|
-
infoResponse,
|
|
142
|
-
email || ""
|
|
143
|
-
);
|
|
144
|
-
} catch (error) {
|
|
145
|
-
throw new AbcError(
|
|
146
|
-
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */,
|
|
147
|
-
`Failed to recover MPC wallets: ${error.message}`,
|
|
148
|
-
{ originalError: error }
|
|
149
|
-
);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
function validateMpcWallets(result) {
|
|
153
|
-
const errors = [];
|
|
154
|
-
if (!result.evmWallet) {
|
|
155
|
-
errors.push("EVM wallet is missing");
|
|
156
|
-
} else {
|
|
157
|
-
if (!result.evmWallet.address || !result.evmWallet.address.startsWith("0x")) {
|
|
158
|
-
errors.push("Invalid EVM wallet address");
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
if (!result.solanaWallet) {
|
|
162
|
-
errors.push("Solana wallet is missing");
|
|
163
|
-
} else {
|
|
164
|
-
if (!result.solanaWallet.address) {
|
|
165
|
-
errors.push("Invalid Solana wallet address");
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (!result.bitcoinWallet) {
|
|
169
|
-
errors.push("Bitcoin wallet is missing");
|
|
170
|
-
} else {
|
|
171
|
-
if (!result.bitcoinWallet.address) {
|
|
172
|
-
errors.push("Invalid Bitcoin wallet address");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
if (!result.tronWallet) {
|
|
176
|
-
errors.push("TRON wallet is missing");
|
|
177
|
-
} else {
|
|
178
|
-
if (!result.tronWallet.address) {
|
|
179
|
-
errors.push("Invalid TRON wallet address");
|
|
180
|
-
} else if (!result.tronWallet.address.startsWith("T")) {
|
|
181
|
-
errors.push("Invalid TRON address format (expected T prefix)");
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
valid: errors.length === 0,
|
|
186
|
-
errors
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export {
|
|
191
|
-
generateMpcWallets,
|
|
192
|
-
recoverMpcWallets,
|
|
193
|
-
validateMpcWallets
|
|
194
|
-
};
|
|
@@ -1,445 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
WalletscanApi
|
|
4
|
-
} from "./chunk-NULM3THX.js";
|
|
5
|
-
import {
|
|
6
|
-
getCredentialManager
|
|
7
|
-
} from "./chunk-6WF4SXLB.js";
|
|
8
|
-
|
|
9
|
-
// src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
|
|
10
|
-
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
11
|
-
|
|
12
|
-
// src/utils/apiClientFactory.ts
|
|
13
|
-
function createWalletscanApi() {
|
|
14
|
-
return new WalletscanApi();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
|
|
18
|
-
var EventEmitter = class {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.events = /* @__PURE__ */ new Map();
|
|
21
|
-
}
|
|
22
|
-
on(event, listener) {
|
|
23
|
-
if (!this.events.has(event)) {
|
|
24
|
-
this.events.set(event, []);
|
|
25
|
-
}
|
|
26
|
-
this.events.get(event).push(listener);
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
off(event, listener) {
|
|
30
|
-
const listeners = this.events.get(event);
|
|
31
|
-
if (listeners) {
|
|
32
|
-
const index = listeners.indexOf(listener);
|
|
33
|
-
if (index !== -1) {
|
|
34
|
-
listeners.splice(index, 1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
removeListener(event, listener) {
|
|
40
|
-
return this.off(event, listener);
|
|
41
|
-
}
|
|
42
|
-
emit(event, ...args) {
|
|
43
|
-
const listeners = this.events.get(event);
|
|
44
|
-
if (listeners) {
|
|
45
|
-
for (const listener of listeners) {
|
|
46
|
-
listener(...args);
|
|
47
|
-
}
|
|
48
|
-
return true;
|
|
49
|
-
}
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
removeAllListeners(event) {
|
|
53
|
-
if (event) {
|
|
54
|
-
this.events.delete(event);
|
|
55
|
-
} else {
|
|
56
|
-
this.events.clear();
|
|
57
|
-
}
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var SolanaErrorCode = {
|
|
62
|
-
USER_REJECTED: 4001,
|
|
63
|
-
UNAUTHORIZED: 4100,
|
|
64
|
-
UNSUPPORTED_METHOD: 4200,
|
|
65
|
-
DISCONNECTED: 4900,
|
|
66
|
-
INVALID_PARAMS: -32602,
|
|
67
|
-
INTERNAL_ERROR: -32603
|
|
68
|
-
};
|
|
69
|
-
var SolanaProviderError = class extends Error {
|
|
70
|
-
constructor(code, message, data) {
|
|
71
|
-
super(message);
|
|
72
|
-
this.code = code;
|
|
73
|
-
this.data = data;
|
|
74
|
-
this.name = "SolanaProviderError";
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
var AbcSolanaProvider = class extends EventEmitter {
|
|
78
|
-
constructor(talkenApi) {
|
|
79
|
-
super();
|
|
80
|
-
this.wallet = null;
|
|
81
|
-
this.connected = false;
|
|
82
|
-
this.talkenApi = talkenApi;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Set request interceptor for sign/transfer confirmation modals
|
|
86
|
-
*/
|
|
87
|
-
setRequestInterceptor(interceptor) {
|
|
88
|
-
this.requestInterceptor = interceptor;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Call request interceptor if set (throws on user cancel)
|
|
92
|
-
*/
|
|
93
|
-
async callInterceptor(request) {
|
|
94
|
-
if (this.requestInterceptor) {
|
|
95
|
-
await this.requestInterceptor(request);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Set wallet information
|
|
100
|
-
*/
|
|
101
|
-
setWallet(wallet) {
|
|
102
|
-
const previousAddress = this.wallet?.address;
|
|
103
|
-
this.wallet = wallet;
|
|
104
|
-
this.connected = true;
|
|
105
|
-
if (previousAddress !== wallet.address) {
|
|
106
|
-
this.emit("accountsChanged", [wallet.address]);
|
|
107
|
-
}
|
|
108
|
-
this.emit("connect", {
|
|
109
|
-
address: wallet.address,
|
|
110
|
-
network: wallet.network
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Clear wallet (disconnect)
|
|
115
|
-
*/
|
|
116
|
-
clearWallet() {
|
|
117
|
-
this.wallet = null;
|
|
118
|
-
this.connected = false;
|
|
119
|
-
this.emit("disconnect");
|
|
120
|
-
this.emit("accountsChanged", []);
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Set TalkenApiClient for backend-proxied transaction flow
|
|
124
|
-
* When set, native SOL transfers will use a single API call instead of multi-step WaaS
|
|
125
|
-
*/
|
|
126
|
-
setTalkenApi(talkenApi) {
|
|
127
|
-
this.talkenApi = talkenApi;
|
|
128
|
-
}
|
|
129
|
-
getTalkenApiClientOrThrow() {
|
|
130
|
-
const api = this.talkenApi || getTalkenApiClient();
|
|
131
|
-
if (!api) {
|
|
132
|
-
throw new SolanaProviderError(
|
|
133
|
-
SolanaErrorCode.INTERNAL_ERROR,
|
|
134
|
-
"TalkenApiClient not initialized"
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
return api;
|
|
138
|
-
}
|
|
139
|
-
getSigningNetwork() {
|
|
140
|
-
return this.wallet?.network === "solana" ? "solana" : "solana_devnet";
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Check if connected
|
|
144
|
-
*/
|
|
145
|
-
isConnected() {
|
|
146
|
-
return this.connected && this.wallet !== null;
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Get Solana address
|
|
150
|
-
*/
|
|
151
|
-
async getAddress() {
|
|
152
|
-
if (!this.wallet) {
|
|
153
|
-
throw new SolanaProviderError(
|
|
154
|
-
SolanaErrorCode.DISCONNECTED,
|
|
155
|
-
"Wallet not connected"
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
return this.wallet.address;
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Get public key
|
|
162
|
-
*/
|
|
163
|
-
async getPublicKey() {
|
|
164
|
-
if (!this.wallet) {
|
|
165
|
-
throw new SolanaProviderError(
|
|
166
|
-
SolanaErrorCode.DISCONNECTED,
|
|
167
|
-
"Wallet not connected"
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
return this.wallet.publicKey;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Sign Solana message (no PIN required)
|
|
174
|
-
* Uses encrypted_share which doesn't require PIN
|
|
175
|
-
*/
|
|
176
|
-
async signMessage(encodedMessage, _display) {
|
|
177
|
-
if (!this.wallet) {
|
|
178
|
-
throw new SolanaProviderError(
|
|
179
|
-
SolanaErrorCode.DISCONNECTED,
|
|
180
|
-
"Wallet not connected"
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
try {
|
|
184
|
-
const decodedText = new TextDecoder().decode(encodedMessage);
|
|
185
|
-
await this.callInterceptor({
|
|
186
|
-
chain: "solana",
|
|
187
|
-
method: "signMessage",
|
|
188
|
-
address: this.wallet.address,
|
|
189
|
-
network: this.wallet.network,
|
|
190
|
-
message: decodedText
|
|
191
|
-
});
|
|
192
|
-
const messageHex = `0x${Array.from(encodedMessage).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
193
|
-
const result = await this.getTalkenApiClientOrThrow().solana.sign({
|
|
194
|
-
message: messageHex,
|
|
195
|
-
encryptedShare: this.wallet.encryptedShare,
|
|
196
|
-
keyId: this.wallet.keyId,
|
|
197
|
-
secretStore: this.wallet.secretStore || "",
|
|
198
|
-
network: this.getSigningNetwork()
|
|
199
|
-
});
|
|
200
|
-
const signatureHex = result.signature.startsWith("0x") ? result.signature.slice(2) : result.signature;
|
|
201
|
-
const signatureBytes = new Uint8Array(
|
|
202
|
-
signatureHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []
|
|
203
|
-
);
|
|
204
|
-
return { signature: signatureBytes };
|
|
205
|
-
} catch (error) {
|
|
206
|
-
this.emit("error", error);
|
|
207
|
-
throw new SolanaProviderError(
|
|
208
|
-
SolanaErrorCode.INTERNAL_ERROR,
|
|
209
|
-
"Failed to sign message",
|
|
210
|
-
error
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
/**
|
|
215
|
-
* Sign arbitrary Solana transaction (requires PIN)
|
|
216
|
-
* Supports both Legacy Transaction and VersionedTransaction
|
|
217
|
-
* Used for custom transactions, dApp interactions, and protocol integrations
|
|
218
|
-
*/
|
|
219
|
-
async signTransaction(transaction) {
|
|
220
|
-
if (!this.wallet) {
|
|
221
|
-
throw new SolanaProviderError(
|
|
222
|
-
SolanaErrorCode.DISCONNECTED,
|
|
223
|
-
"Wallet not connected"
|
|
224
|
-
);
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
let txMessage = "";
|
|
228
|
-
try {
|
|
229
|
-
txMessage = JSON.stringify(transaction, null, 2);
|
|
230
|
-
} catch {
|
|
231
|
-
txMessage = String(transaction);
|
|
232
|
-
}
|
|
233
|
-
await this.callInterceptor({
|
|
234
|
-
chain: "solana",
|
|
235
|
-
method: "signTransaction",
|
|
236
|
-
address: this.wallet.address,
|
|
237
|
-
network: this.wallet.network,
|
|
238
|
-
message: txMessage,
|
|
239
|
-
isTransaction: true
|
|
240
|
-
});
|
|
241
|
-
const { VersionedTransaction, PublicKey } = await import("@solana/web3.js");
|
|
242
|
-
const isVersioned = transaction instanceof VersionedTransaction;
|
|
243
|
-
let serialized;
|
|
244
|
-
if (isVersioned) {
|
|
245
|
-
serialized = transaction.message.serialize();
|
|
246
|
-
} else {
|
|
247
|
-
serialized = transaction.serializeMessage();
|
|
248
|
-
}
|
|
249
|
-
const messageHex = Buffer.from(serialized).toString("hex");
|
|
250
|
-
const signatureResponse = await this.getTalkenApiClientOrThrow().solana.sign({
|
|
251
|
-
keyId: this.wallet.keyId,
|
|
252
|
-
encryptedShare: this.wallet.encryptedShare,
|
|
253
|
-
secretStore: this.wallet.secretStore || "",
|
|
254
|
-
message: messageHex,
|
|
255
|
-
network: this.getSigningNetwork()
|
|
256
|
-
});
|
|
257
|
-
const signatureHex = signatureResponse.signature.startsWith("0x") ? signatureResponse.signature.slice(2) : signatureResponse.signature;
|
|
258
|
-
const signatureBytes = Buffer.from(signatureHex, "hex");
|
|
259
|
-
const publicKey = new PublicKey(this.wallet.address);
|
|
260
|
-
if (isVersioned) {
|
|
261
|
-
transaction.addSignature(publicKey, signatureBytes);
|
|
262
|
-
} else {
|
|
263
|
-
transaction.addSignature(publicKey, signatureBytes);
|
|
264
|
-
}
|
|
265
|
-
return transaction;
|
|
266
|
-
} catch (error) {
|
|
267
|
-
if (error.code === 4001 || error.cancelled) {
|
|
268
|
-
throw error;
|
|
269
|
-
}
|
|
270
|
-
this.emit("error", error);
|
|
271
|
-
throw new SolanaProviderError(
|
|
272
|
-
SolanaErrorCode.INTERNAL_ERROR,
|
|
273
|
-
"Failed to sign transaction",
|
|
274
|
-
error
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Sign multiple transactions (batch signing)
|
|
280
|
-
*/
|
|
281
|
-
async signAllTransactions(transactions) {
|
|
282
|
-
const signedTransactions = [];
|
|
283
|
-
for (const transaction of transactions) {
|
|
284
|
-
const signed = await this.signTransaction(transaction);
|
|
285
|
-
signedTransactions.push(signed);
|
|
286
|
-
}
|
|
287
|
-
return signedTransactions;
|
|
288
|
-
}
|
|
289
|
-
/**
|
|
290
|
-
* Unified transfer: SOL, SPL token, or NFT
|
|
291
|
-
* - No mintAddress → native SOL transfer (kind='native')
|
|
292
|
-
* - With mintAddress → SPL/NFT transfer (kind='spl')
|
|
293
|
-
* - NFT = transfer({ mintAddress, toAddress, amount: 1 })
|
|
294
|
-
*/
|
|
295
|
-
async transfer(params) {
|
|
296
|
-
if (!this.wallet) {
|
|
297
|
-
throw new SolanaProviderError(
|
|
298
|
-
SolanaErrorCode.DISCONNECTED,
|
|
299
|
-
"Wallet not connected"
|
|
300
|
-
);
|
|
301
|
-
}
|
|
302
|
-
try {
|
|
303
|
-
const symbol = params.mintAddress ? "SPL" : "SOL";
|
|
304
|
-
await this.callInterceptor({
|
|
305
|
-
chain: "solana",
|
|
306
|
-
method: "transfer",
|
|
307
|
-
fromAddress: this.wallet.address,
|
|
308
|
-
toAddress: params.toAddress,
|
|
309
|
-
amount: String(params.amount),
|
|
310
|
-
symbol,
|
|
311
|
-
network: this.wallet.network,
|
|
312
|
-
tokenAddress: params.mintAddress,
|
|
313
|
-
isNativeToken: !params.mintAddress,
|
|
314
|
-
feeSymbol: "SOL"
|
|
315
|
-
});
|
|
316
|
-
const pinHash = getCredentialManager().getPinHash();
|
|
317
|
-
if (!pinHash) {
|
|
318
|
-
throw new SolanaProviderError(
|
|
319
|
-
SolanaErrorCode.INTERNAL_ERROR,
|
|
320
|
-
"PIN hash not found. Please login again."
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
console.log("[AbcSolanaProvider] transfer START", {
|
|
324
|
-
kind: params.mintAddress ? "spl" : "native",
|
|
325
|
-
toAddress: params.toAddress,
|
|
326
|
-
amount: params.amount,
|
|
327
|
-
mintAddress: params.mintAddress || null,
|
|
328
|
-
network: this.wallet.network,
|
|
329
|
-
hasPinHash: !!pinHash
|
|
330
|
-
});
|
|
331
|
-
const api = this.getTalkenApiClientOrThrow();
|
|
332
|
-
const apiNetwork = this.wallet.network === "solana" ? "solana" : "solana_devnet";
|
|
333
|
-
if (params.mintAddress) {
|
|
334
|
-
const walletscanApi = createWalletscanApi();
|
|
335
|
-
const tokenMeta = await walletscanApi.getContractTokenWithTimeout({
|
|
336
|
-
contractAddress: params.mintAddress,
|
|
337
|
-
networks: apiNetwork
|
|
338
|
-
});
|
|
339
|
-
const decimals = tokenMeta?.decimals ?? 9;
|
|
340
|
-
const rawAmount = Math.floor(params.amount * 10 ** decimals);
|
|
341
|
-
const result2 = await api.solana.transfer({
|
|
342
|
-
kind: "spl",
|
|
343
|
-
toAddress: params.toAddress,
|
|
344
|
-
mintAddress: params.mintAddress,
|
|
345
|
-
amount: String(rawAmount),
|
|
346
|
-
decimals,
|
|
347
|
-
network: apiNetwork,
|
|
348
|
-
pin: pinHash
|
|
349
|
-
});
|
|
350
|
-
console.log("[AbcSolanaProvider] SPL transfer result:", result2);
|
|
351
|
-
return { signature: result2.txHash };
|
|
352
|
-
}
|
|
353
|
-
const { LAMPORTS_PER_SOL } = await import("@solana/web3.js");
|
|
354
|
-
const amountLamports = params.amount * LAMPORTS_PER_SOL;
|
|
355
|
-
console.log("[AbcSolanaProvider] native transfer request:", {
|
|
356
|
-
toAddress: params.toAddress,
|
|
357
|
-
amountLamports: String(amountLamports),
|
|
358
|
-
amountSOL: params.amount
|
|
359
|
-
});
|
|
360
|
-
const result = await api.solana.transfer({
|
|
361
|
-
kind: "native",
|
|
362
|
-
toAddress: params.toAddress,
|
|
363
|
-
amountLamports: String(amountLamports),
|
|
364
|
-
network: apiNetwork,
|
|
365
|
-
pin: pinHash
|
|
366
|
-
});
|
|
367
|
-
console.log("[AbcSolanaProvider] native transfer result:", result);
|
|
368
|
-
return { signature: result.txHash };
|
|
369
|
-
} catch (error) {
|
|
370
|
-
console.error("[AbcSolanaProvider] transfer FAILED:", {
|
|
371
|
-
message: error.message,
|
|
372
|
-
code: error.code,
|
|
373
|
-
status: error.status,
|
|
374
|
-
details: error.details || error.data
|
|
375
|
-
});
|
|
376
|
-
if (error.code === 4001 || error.cancelled) {
|
|
377
|
-
throw error;
|
|
378
|
-
}
|
|
379
|
-
this.emit("error", error);
|
|
380
|
-
throw new SolanaProviderError(
|
|
381
|
-
SolanaErrorCode.INTERNAL_ERROR,
|
|
382
|
-
"Failed to transfer",
|
|
383
|
-
error
|
|
384
|
-
);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Get wallet info
|
|
389
|
-
*/
|
|
390
|
-
getWalletInfo() {
|
|
391
|
-
if (!this.wallet)
|
|
392
|
-
return null;
|
|
393
|
-
return {
|
|
394
|
-
address: this.wallet.address,
|
|
395
|
-
publicKey: this.wallet.publicKey,
|
|
396
|
-
network: this.wallet.network
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Get SPL token balance
|
|
401
|
-
*
|
|
402
|
-
* @param mintAddress - Token mint address
|
|
403
|
-
* @returns Token balance information
|
|
404
|
-
*/
|
|
405
|
-
async getTokenBalance(mintAddress) {
|
|
406
|
-
if (!this.wallet) {
|
|
407
|
-
throw new SolanaProviderError(
|
|
408
|
-
SolanaErrorCode.DISCONNECTED,
|
|
409
|
-
"Wallet not connected"
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
try {
|
|
413
|
-
const walletscanApi = createWalletscanApi();
|
|
414
|
-
const balance = await walletscanApi.getWalletTokenBalanceWithTimeout({
|
|
415
|
-
walletAddress: this.wallet.address,
|
|
416
|
-
networks: this.wallet.network,
|
|
417
|
-
contractAddress: mintAddress
|
|
418
|
-
});
|
|
419
|
-
if (!balance) {
|
|
420
|
-
return {
|
|
421
|
-
amount: "0",
|
|
422
|
-
decimals: 0,
|
|
423
|
-
uiAmount: 0
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
return {
|
|
427
|
-
amount: String(balance.balance ?? 0),
|
|
428
|
-
decimals: balance.decimals ?? 0,
|
|
429
|
-
uiAmount: balance.hrBalance ?? 0
|
|
430
|
-
};
|
|
431
|
-
} catch (error) {
|
|
432
|
-
this.emit("error", error);
|
|
433
|
-
throw new SolanaProviderError(
|
|
434
|
-
SolanaErrorCode.INTERNAL_ERROR,
|
|
435
|
-
"Failed to get token balance",
|
|
436
|
-
error
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
export {
|
|
443
|
-
SolanaProviderError,
|
|
444
|
-
AbcSolanaProvider
|
|
445
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
TALKEN_API_ENDPOINTS
|
|
4
|
-
} from "./chunk-DPTDOCWL.js";
|
|
5
|
-
|
|
6
|
-
// src/wallets/walletConnectors/abcWallet/api/TokenApi.ts
|
|
7
|
-
import { getTalkenApiClient } from "@talken/talkenkit";
|
|
8
|
-
var TokenApi = class {
|
|
9
|
-
async getBalances(address, chainKey) {
|
|
10
|
-
const api = getTalkenApiClient();
|
|
11
|
-
if (!api)
|
|
12
|
-
throw new Error("TalkenApiClient not initialized");
|
|
13
|
-
const query = new URLSearchParams({ address, chainKey }).toString();
|
|
14
|
-
const response = await api.get(`${TALKEN_API_ENDPOINTS.TOKENS_BALANCES}?${query}`);
|
|
15
|
-
return Array.isArray(response) ? response : response.tokens ?? [];
|
|
16
|
-
}
|
|
17
|
-
async getTokenBalance(address, chainKey, tokenAddress) {
|
|
18
|
-
const balances = await this.getBalances(address, chainKey);
|
|
19
|
-
const matched = balances.find(
|
|
20
|
-
(token) => token.address?.toLowerCase() === tokenAddress.toLowerCase()
|
|
21
|
-
);
|
|
22
|
-
if (!matched?.balance)
|
|
23
|
-
return null;
|
|
24
|
-
return BigInt(matched.balance);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
TokenApi
|
|
30
|
-
};
|