@talken/talkenkit 2.4.13 → 2.4.15
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-25AKGPRG.js +184 -0
- package/dist/abcWallet-2SXWQ2M6.js +184 -0
- package/dist/abcWallet-3E6Y5QS4.js +184 -0
- package/dist/abcWallet-3HKYSDOS.js +184 -0
- package/dist/abcWallet-6VIUP4H3.js +184 -0
- package/dist/abcWallet-7CXDTXHX.js +184 -0
- package/dist/abcWallet-A3PX6AEW.js +184 -0
- package/dist/abcWallet-A6CRIFP2.js +184 -0
- package/dist/abcWallet-ACAOT2F3.js +184 -0
- package/dist/abcWallet-AWALYVJ7.js +184 -0
- package/dist/abcWallet-CEW3E2AX.js +184 -0
- package/dist/abcWallet-CEZAQ3ES.js +184 -0
- package/dist/abcWallet-CURD64AW.js +184 -0
- package/dist/abcWallet-E2A433S3.js +184 -0
- package/dist/abcWallet-ER37COEQ.js +184 -0
- package/dist/abcWallet-ETWMKZKD.js +184 -0
- package/dist/abcWallet-F6JAVHHQ.js +184 -0
- package/dist/abcWallet-GEHOIOZN.js +184 -0
- package/dist/abcWallet-H22OANDE.js +184 -0
- package/dist/abcWallet-H5BBPLGS.js +184 -0
- package/dist/abcWallet-I5BENZSH.js +184 -0
- package/dist/abcWallet-LABFRLNR.js +184 -0
- package/dist/abcWallet-MB2IAXV5.js +184 -0
- package/dist/abcWallet-MH6OGFBO.js +184 -0
- package/dist/abcWallet-NJGYOH52.js +184 -0
- package/dist/abcWallet-OG6ZQORS.js +184 -0
- package/dist/abcWallet-OJ7VCWHZ.js +184 -0
- package/dist/abcWallet-PBEQA5UT.js +184 -0
- package/dist/abcWallet-PMJEDGRW.js +184 -0
- package/dist/abcWallet-SX35BIXB.js +184 -0
- package/dist/abcWallet-TQTXUPJZ.js +184 -0
- package/dist/abcWallet-VKVKBQYN.js +184 -0
- package/dist/abcWallet-W6OZE7QD.js +184 -0
- package/dist/abcWallet-WH2J2YAV.js +184 -0
- package/dist/abcWallet-XA5DX7XK.js +184 -0
- package/dist/abcWallet-XANCTLMU.js +184 -0
- package/dist/abcWallet-XDP764EW.js +184 -0
- package/dist/abcWallet-Y3DONK5H.js +184 -0
- package/dist/abcWallet-YLBGJ5K6.js +184 -0
- package/dist/abcWallet-ZSL4HH7M.js +184 -0
- package/dist/chunk-2D6TXDN2.js +7450 -0
- package/dist/chunk-3K7INMEV.js +7470 -0
- package/dist/chunk-5FE4YAGR.js +7423 -0
- package/dist/chunk-5LD4QGWP.js +7423 -0
- package/dist/chunk-64RMUCRE.js +7447 -0
- package/dist/chunk-6KTOC6CY.js +7464 -0
- package/dist/chunk-6QW7GFF5.js +7450 -0
- package/dist/chunk-6RCVLZFG.js +7462 -0
- package/dist/chunk-7Y3M3LG3.js +7446 -0
- package/dist/chunk-A3EBU637.js +7441 -0
- package/dist/chunk-BVBWXZCX.js +7450 -0
- package/dist/chunk-CAXCHVY2.js +7469 -0
- package/dist/chunk-CBJW7X7O.js +7382 -0
- package/dist/chunk-CD36XA5S.js +7417 -0
- package/dist/chunk-EAKUQPJO.js +7463 -0
- package/dist/chunk-ER7H33CO.js +7450 -0
- package/dist/chunk-FCENPWP5.js +7452 -0
- package/dist/chunk-FPMB7NJE.js +7366 -0
- package/dist/chunk-GWIJVQBX.js +7420 -0
- package/dist/chunk-HGOFSTGT.js +7474 -0
- package/dist/chunk-JJ4CTD2J.js +7428 -0
- package/dist/chunk-JMBGLDYV.js +7368 -0
- package/dist/chunk-KBMHNBKL.js +7449 -0
- package/dist/chunk-KZRFIJW2.js +7452 -0
- package/dist/chunk-L6TCA4IF.js +7378 -0
- package/dist/chunk-LTRXFRER.js +7472 -0
- package/dist/chunk-MRLTYAPE.js +7451 -0
- package/dist/chunk-N3QOWEYR.js +7393 -0
- package/dist/chunk-NII34OZB.js +7442 -0
- package/dist/chunk-OAHLI7TU.js +7368 -0
- package/dist/chunk-RFJBWB7F.js +7467 -0
- package/dist/chunk-SBRDMKB6.js +7408 -0
- package/dist/chunk-SDRSLETV.js +7428 -0
- package/dist/chunk-SWO7BZQD.js +7463 -0
- package/dist/chunk-TR4Q6WOC.js +7427 -0
- package/dist/chunk-UBBAWTXE.js +7370 -0
- package/dist/chunk-VEOSJOVN.js +7377 -0
- package/dist/chunk-VGF34W25.js +7370 -0
- package/dist/chunk-VXSGQUAL.js +7458 -0
- package/dist/chunk-Z3FKXPV6.js +7430 -0
- package/dist/hooks/useSolanaWallet.d.ts +33 -1
- package/dist/index.css +24 -24
- package/dist/index.js +2610 -2445
- package/dist/solana/SolanaWalletProvider.d.ts +1 -1
- package/dist/solana/config.d.ts +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.d.ts +52 -4
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaProvider.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/abcSolanaWalletAdapter.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.d.ts +52 -1
- package/dist/wallets/walletConnectors/abcWallet/api/SolanaApi.js +1 -1
- package/dist/wallets/walletConnectors/abcWallet/api/index.js +2 -2
- package/dist/wallets/walletConnectors/abcWallet/index.js +3 -3
- package/dist/wallets/walletConnectors/abcWallet/types.d.ts +2 -2
- package/dist/wallets/walletConnectors/chunk-2FUWP3CE.js +330 -0
- package/dist/wallets/walletConnectors/chunk-2HZI5GNW.js +422 -0
- package/dist/wallets/walletConnectors/chunk-2OTYM5YW.js +461 -0
- package/dist/wallets/walletConnectors/chunk-2PVZZB7V.js +179 -0
- package/dist/wallets/walletConnectors/chunk-2SKUK3XZ.js +336 -0
- package/dist/wallets/walletConnectors/chunk-2THGB26Q.js +483 -0
- package/dist/wallets/walletConnectors/chunk-353AHAZG.js +420 -0
- package/dist/wallets/walletConnectors/chunk-3AV4L2Z3.js +63 -0
- package/dist/wallets/walletConnectors/chunk-3DMYAF74.js +495 -0
- package/dist/wallets/walletConnectors/chunk-3EVUNPYA.js +63 -0
- package/dist/wallets/walletConnectors/chunk-45FLFWVV.js +473 -0
- package/dist/wallets/walletConnectors/chunk-4JRATGCT.js +484 -0
- package/dist/wallets/walletConnectors/chunk-5AL2CK6V.js +336 -0
- package/dist/wallets/walletConnectors/chunk-5FSXV7UD.js +63 -0
- package/dist/wallets/walletConnectors/chunk-5JHX6GDO.js +63 -0
- package/dist/wallets/walletConnectors/chunk-5QGNWYOO.js +63 -0
- package/dist/wallets/walletConnectors/chunk-6I7AIIUA.js +330 -0
- package/dist/wallets/walletConnectors/chunk-A2AVZXFM.js +467 -0
- package/dist/wallets/walletConnectors/chunk-AB6IIS4Y.js +359 -0
- package/dist/wallets/walletConnectors/chunk-AB6NV5DJ.js +469 -0
- package/dist/wallets/walletConnectors/chunk-AYAW5CRA.js +459 -0
- package/dist/wallets/walletConnectors/chunk-BCO6YLPB.js +505 -0
- package/dist/wallets/walletConnectors/chunk-BK65Y46D.js +494 -0
- package/dist/wallets/walletConnectors/chunk-BKJVG4GQ.js +463 -0
- package/dist/wallets/walletConnectors/chunk-BWVC6F6J.js +467 -0
- package/dist/wallets/walletConnectors/chunk-D3USECVX.js +333 -0
- package/dist/wallets/walletConnectors/chunk-DCBHTSF2.js +63 -0
- package/dist/wallets/walletConnectors/chunk-DNYWTUT5.js +63 -0
- package/dist/wallets/walletConnectors/chunk-DSTCYPGN.js +314 -0
- package/dist/wallets/walletConnectors/chunk-DWPUUKA4.js +63 -0
- package/dist/wallets/walletConnectors/chunk-E33VQYPO.js +302 -0
- package/dist/wallets/walletConnectors/chunk-EBBETASF.js +424 -0
- package/dist/wallets/walletConnectors/chunk-GMEXP6OH.js +314 -0
- package/dist/wallets/walletConnectors/chunk-HB7QT3ZB.js +332 -0
- package/dist/wallets/walletConnectors/chunk-HDXQ7BO6.js +314 -0
- package/dist/wallets/walletConnectors/chunk-HQQESMZJ.js +299 -0
- package/dist/wallets/walletConnectors/chunk-HWWFK52B.js +63 -0
- package/dist/wallets/walletConnectors/chunk-HYADQWNX.js +47 -0
- package/dist/wallets/walletConnectors/chunk-I56RJQOO.js +63 -0
- package/dist/wallets/walletConnectors/chunk-JY4WWUAC.js +503 -0
- package/dist/wallets/walletConnectors/chunk-KIKTI2QW.js +313 -0
- package/dist/wallets/walletConnectors/chunk-KPXEV65I.js +481 -0
- package/dist/wallets/walletConnectors/chunk-KXRUCXYG.js +63 -0
- package/dist/wallets/walletConnectors/chunk-L3ZUQ2FT.js +494 -0
- package/dist/wallets/walletConnectors/chunk-LKM4HFVX.js +63 -0
- package/dist/wallets/walletConnectors/chunk-LKSMH5O4.js +63 -0
- package/dist/wallets/walletConnectors/chunk-NSAHMWXK.js +468 -0
- package/dist/wallets/walletConnectors/chunk-NY3HZ7C7.js +428 -0
- package/dist/wallets/walletConnectors/chunk-OA6D52JF.js +303 -0
- package/dist/wallets/walletConnectors/chunk-OSJ2GO4U.js +63 -0
- package/dist/wallets/walletConnectors/chunk-OYDALF2T.js +63 -0
- package/dist/wallets/walletConnectors/chunk-P5CZ24LM.js +312 -0
- package/dist/wallets/walletConnectors/chunk-PER2ACFG.js +443 -0
- package/dist/wallets/walletConnectors/chunk-PGPH245S.js +63 -0
- package/dist/wallets/walletConnectors/chunk-PNE3IGZM.js +63 -0
- package/dist/wallets/walletConnectors/chunk-Q2WYW3LQ.js +63 -0
- package/dist/wallets/walletConnectors/chunk-Q3KCTIZB.js +458 -0
- package/dist/wallets/walletConnectors/chunk-Q3W2LKFS.js +498 -0
- package/dist/wallets/walletConnectors/chunk-QAD7DCJI.js +473 -0
- package/dist/wallets/walletConnectors/chunk-QG6HVKA7.js +458 -0
- package/dist/wallets/walletConnectors/chunk-QHCY3K35.js +466 -0
- package/dist/wallets/walletConnectors/chunk-QHRV2IC7.js +63 -0
- package/dist/wallets/walletConnectors/chunk-QWEA3UTQ.js +313 -0
- package/dist/wallets/walletConnectors/chunk-QYUVI6LM.js +500 -0
- package/dist/wallets/walletConnectors/chunk-RFNPDZJ5.js +299 -0
- package/dist/wallets/walletConnectors/chunk-SUBWGTWM.js +459 -0
- package/dist/wallets/walletConnectors/chunk-TASM5LUN.js +276 -0
- package/dist/wallets/walletConnectors/chunk-U4DSASHD.js +63 -0
- package/dist/wallets/walletConnectors/chunk-UCKLTSEQ.js +467 -0
- package/dist/wallets/walletConnectors/chunk-UWC6AXPI.js +63 -0
- package/dist/wallets/walletConnectors/chunk-V5LV4P2L.js +63 -0
- package/dist/wallets/walletConnectors/chunk-VP6SWGCN.js +63 -0
- package/dist/wallets/walletConnectors/chunk-W4MD4LZF.js +464 -0
- package/dist/wallets/walletConnectors/chunk-XHNXMXXX.js +493 -0
- package/dist/wallets/walletConnectors/chunk-XHOWI6QG.js +399 -0
- package/dist/wallets/walletConnectors/chunk-YDCQB2MV.js +309 -0
- package/dist/wallets/walletConnectors/chunk-Z4LE4R6P.js +63 -0
- package/dist/wallets/walletConnectors/chunk-ZE3USY6D.js +156 -0
- package/dist/wallets/walletConnectors/chunk-ZHHPZPSF.js +489 -0
- package/dist/wallets/walletConnectors/chunk-ZOJTTG4G.js +63 -0
- package/dist/wallets/walletConnectors/index.js +49 -49
- package/package.json +2 -1
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/wallets/walletConnectors/abcWallet/abcSolanaProvider.ts
|
|
4
|
+
var EventEmitter = class {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.events = /* @__PURE__ */ new Map();
|
|
7
|
+
}
|
|
8
|
+
on(event, listener) {
|
|
9
|
+
if (!this.events.has(event)) {
|
|
10
|
+
this.events.set(event, []);
|
|
11
|
+
}
|
|
12
|
+
this.events.get(event).push(listener);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
off(event, listener) {
|
|
16
|
+
const listeners = this.events.get(event);
|
|
17
|
+
if (listeners) {
|
|
18
|
+
const index = listeners.indexOf(listener);
|
|
19
|
+
if (index !== -1) {
|
|
20
|
+
listeners.splice(index, 1);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
removeListener(event, listener) {
|
|
26
|
+
return this.off(event, listener);
|
|
27
|
+
}
|
|
28
|
+
emit(event, ...args) {
|
|
29
|
+
const listeners = this.events.get(event);
|
|
30
|
+
if (listeners) {
|
|
31
|
+
for (const listener of listeners) {
|
|
32
|
+
listener(...args);
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
removeAllListeners(event) {
|
|
39
|
+
if (event) {
|
|
40
|
+
this.events.delete(event);
|
|
41
|
+
} else {
|
|
42
|
+
this.events.clear();
|
|
43
|
+
}
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var SolanaErrorCode = {
|
|
48
|
+
USER_REJECTED: 4001,
|
|
49
|
+
UNAUTHORIZED: 4100,
|
|
50
|
+
UNSUPPORTED_METHOD: 4200,
|
|
51
|
+
DISCONNECTED: 4900,
|
|
52
|
+
INVALID_PARAMS: -32602,
|
|
53
|
+
INTERNAL_ERROR: -32603
|
|
54
|
+
};
|
|
55
|
+
var SolanaProviderError = class extends Error {
|
|
56
|
+
constructor(code, message, data) {
|
|
57
|
+
super(message);
|
|
58
|
+
this.code = code;
|
|
59
|
+
this.data = data;
|
|
60
|
+
this.name = "SolanaProviderError";
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var AbcSolanaProvider = class extends EventEmitter {
|
|
64
|
+
constructor(client) {
|
|
65
|
+
super();
|
|
66
|
+
this.wallet = null;
|
|
67
|
+
this.connected = false;
|
|
68
|
+
this.requestPinCallback = null;
|
|
69
|
+
this.client = client;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Set wallet information
|
|
73
|
+
*/
|
|
74
|
+
setWallet(wallet) {
|
|
75
|
+
const previousAddress = this.wallet?.address;
|
|
76
|
+
this.wallet = wallet;
|
|
77
|
+
this.connected = true;
|
|
78
|
+
if (previousAddress !== wallet.address) {
|
|
79
|
+
this.emit("accountsChanged", [wallet.address]);
|
|
80
|
+
}
|
|
81
|
+
this.emit("connect", {
|
|
82
|
+
address: wallet.address,
|
|
83
|
+
network: wallet.network
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Clear wallet (disconnect)
|
|
88
|
+
*/
|
|
89
|
+
clearWallet() {
|
|
90
|
+
this.wallet = null;
|
|
91
|
+
this.connected = false;
|
|
92
|
+
this.emit("disconnect");
|
|
93
|
+
this.emit("accountsChanged", []);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Set PIN request callback for transaction signing
|
|
97
|
+
*/
|
|
98
|
+
setRequestPinCallback(callback) {
|
|
99
|
+
this.requestPinCallback = callback;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Check if connected
|
|
103
|
+
*/
|
|
104
|
+
isConnected() {
|
|
105
|
+
return this.connected && this.wallet !== null;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get Solana address
|
|
109
|
+
*/
|
|
110
|
+
async getAddress() {
|
|
111
|
+
if (!this.wallet) {
|
|
112
|
+
throw new SolanaProviderError(
|
|
113
|
+
SolanaErrorCode.DISCONNECTED,
|
|
114
|
+
"Wallet not connected"
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return this.wallet.address;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get public key
|
|
121
|
+
*/
|
|
122
|
+
async getPublicKey() {
|
|
123
|
+
if (!this.wallet) {
|
|
124
|
+
throw new SolanaProviderError(
|
|
125
|
+
SolanaErrorCode.DISCONNECTED,
|
|
126
|
+
"Wallet not connected"
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
return this.wallet.publicKey;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Sign Solana message (no PIN required)
|
|
133
|
+
* Uses encrypted_share which doesn't require PIN
|
|
134
|
+
*/
|
|
135
|
+
async signMessage(encodedMessage, _display) {
|
|
136
|
+
if (!this.wallet) {
|
|
137
|
+
throw new SolanaProviderError(
|
|
138
|
+
SolanaErrorCode.DISCONNECTED,
|
|
139
|
+
"Wallet not connected"
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
try {
|
|
143
|
+
const messageHex = `0x${Array.from(encodedMessage).map((b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
144
|
+
const result = await this.client.solana.signSolanaMessage({
|
|
145
|
+
message: messageHex,
|
|
146
|
+
encryptedShare: this.wallet.encryptedShare,
|
|
147
|
+
keyId: this.wallet.keyId,
|
|
148
|
+
secretStore: this.wallet.secretStore || ""
|
|
149
|
+
});
|
|
150
|
+
const signatureHex = result.signature.startsWith("0x") ? result.signature.slice(2) : result.signature;
|
|
151
|
+
const signatureBytes = new Uint8Array(
|
|
152
|
+
signatureHex.match(/.{1,2}/g)?.map((byte) => Number.parseInt(byte, 16)) || []
|
|
153
|
+
);
|
|
154
|
+
return { signature: signatureBytes };
|
|
155
|
+
} catch (error) {
|
|
156
|
+
this.emit("error", error);
|
|
157
|
+
throw new SolanaProviderError(
|
|
158
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
159
|
+
"Failed to sign message",
|
|
160
|
+
error
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Sign arbitrary Solana transaction (requires PIN)
|
|
166
|
+
* Supports both Legacy Transaction and VersionedTransaction
|
|
167
|
+
* Used for custom transactions, dApp interactions, and protocol integrations
|
|
168
|
+
*/
|
|
169
|
+
async signTransaction(transaction) {
|
|
170
|
+
if (!this.wallet) {
|
|
171
|
+
throw new SolanaProviderError(
|
|
172
|
+
SolanaErrorCode.DISCONNECTED,
|
|
173
|
+
"Wallet not connected"
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (!this.requestPinCallback) {
|
|
177
|
+
throw new SolanaProviderError(
|
|
178
|
+
SolanaErrorCode.UNAUTHORIZED,
|
|
179
|
+
"PIN callback not set"
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const pin = await this.requestPinCallback();
|
|
184
|
+
const encoder = new TextEncoder();
|
|
185
|
+
const data = encoder.encode(pin);
|
|
186
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
187
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
188
|
+
const pinHash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
189
|
+
const storedPinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
190
|
+
if (storedPinHash && pinHash !== storedPinHash) {
|
|
191
|
+
throw new SolanaProviderError(
|
|
192
|
+
SolanaErrorCode.UNAUTHORIZED,
|
|
193
|
+
"Incorrect PIN"
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
const { Transaction, VersionedTransaction, PublicKey } = await import("@solana/web3.js");
|
|
197
|
+
const isVersioned = transaction instanceof VersionedTransaction;
|
|
198
|
+
let serialized;
|
|
199
|
+
if (isVersioned) {
|
|
200
|
+
serialized = transaction.message.serialize();
|
|
201
|
+
} else {
|
|
202
|
+
serialized = transaction.serializeMessage();
|
|
203
|
+
}
|
|
204
|
+
const messageHex = Buffer.from(serialized).toString("hex");
|
|
205
|
+
const signatureResponse = await this.client.solana.signSolanaTransaction({
|
|
206
|
+
keyId: this.wallet.keyId,
|
|
207
|
+
encryptedShare: this.wallet.encryptedShare,
|
|
208
|
+
secretStore: this.wallet.secretStore || "",
|
|
209
|
+
message: messageHex
|
|
210
|
+
});
|
|
211
|
+
const signatureHex = signatureResponse.signature.startsWith("0x") ? signatureResponse.signature.slice(2) : signatureResponse.signature;
|
|
212
|
+
const signatureBytes = Buffer.from(signatureHex, "hex");
|
|
213
|
+
const publicKey = new PublicKey(this.wallet.address);
|
|
214
|
+
if (isVersioned) {
|
|
215
|
+
transaction.addSignature(publicKey, signatureBytes);
|
|
216
|
+
} else {
|
|
217
|
+
transaction.addSignature(publicKey, signatureBytes);
|
|
218
|
+
}
|
|
219
|
+
return transaction;
|
|
220
|
+
} catch (error) {
|
|
221
|
+
if (error.code === 4001 || error.cancelled) {
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
this.emit("error", error);
|
|
225
|
+
throw new SolanaProviderError(
|
|
226
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
227
|
+
"Failed to sign transaction",
|
|
228
|
+
error
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Sign multiple transactions (batch signing)
|
|
234
|
+
* Used for multi-step operations and protocol interactions
|
|
235
|
+
*/
|
|
236
|
+
async signAllTransactions(transactions) {
|
|
237
|
+
const signedTransactions = [];
|
|
238
|
+
for (const transaction of transactions) {
|
|
239
|
+
const signed = await this.signTransaction(transaction);
|
|
240
|
+
signedTransactions.push(signed);
|
|
241
|
+
}
|
|
242
|
+
return signedTransactions;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Send Solana transaction (with PIN verification)
|
|
246
|
+
*/
|
|
247
|
+
async sendTransaction(params) {
|
|
248
|
+
if (!this.wallet) {
|
|
249
|
+
throw new SolanaProviderError(
|
|
250
|
+
SolanaErrorCode.DISCONNECTED,
|
|
251
|
+
"Wallet not connected"
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
if (!this.requestPinCallback) {
|
|
255
|
+
throw new SolanaProviderError(
|
|
256
|
+
SolanaErrorCode.UNAUTHORIZED,
|
|
257
|
+
"PIN callback not set"
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
const pin = await this.requestPinCallback();
|
|
262
|
+
const encoder = new TextEncoder();
|
|
263
|
+
const data = encoder.encode(pin);
|
|
264
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
265
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
266
|
+
const pinHash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
267
|
+
const storedPinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
268
|
+
if (storedPinHash && pinHash !== storedPinHash) {
|
|
269
|
+
throw new SolanaProviderError(
|
|
270
|
+
SolanaErrorCode.UNAUTHORIZED,
|
|
271
|
+
"Incorrect PIN"
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
const { LAMPORTS_PER_SOL } = await import("@solana/web3.js");
|
|
275
|
+
const network = this.wallet.network || "solana_devnet";
|
|
276
|
+
const amountLamports = params.amount * LAMPORTS_PER_SOL;
|
|
277
|
+
const txGenResponse = await this.client.solana.generateTransferTransaction({
|
|
278
|
+
network,
|
|
279
|
+
amount: amountLamports,
|
|
280
|
+
fromAddress: this.wallet.address,
|
|
281
|
+
toAddress: params.toAddress,
|
|
282
|
+
feePayerAddress: this.wallet.address
|
|
283
|
+
});
|
|
284
|
+
const signatureResponse = await this.client.solana.signSolanaTransaction({
|
|
285
|
+
keyId: this.wallet.keyId,
|
|
286
|
+
encryptedShare: this.wallet.encryptedShare,
|
|
287
|
+
secretStore: this.wallet.secretStore || "",
|
|
288
|
+
message: txGenResponse.serialized_tx
|
|
289
|
+
});
|
|
290
|
+
const result = await this.client.solana.sendSolanaTransaction({
|
|
291
|
+
network,
|
|
292
|
+
serializedTX: txGenResponse.serialized_tx,
|
|
293
|
+
signatures: [signatureResponse.signature]
|
|
294
|
+
});
|
|
295
|
+
return {
|
|
296
|
+
signature: result.txHash,
|
|
297
|
+
serializedTx: txGenResponse.serialized_tx
|
|
298
|
+
};
|
|
299
|
+
} catch (error) {
|
|
300
|
+
if (error.code === 4001 || error.cancelled) {
|
|
301
|
+
throw error;
|
|
302
|
+
}
|
|
303
|
+
this.emit("error", error);
|
|
304
|
+
throw new SolanaProviderError(
|
|
305
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
306
|
+
"Failed to send transaction",
|
|
307
|
+
error
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get wallet info
|
|
313
|
+
*/
|
|
314
|
+
getWalletInfo() {
|
|
315
|
+
if (!this.wallet)
|
|
316
|
+
return null;
|
|
317
|
+
return {
|
|
318
|
+
address: this.wallet.address,
|
|
319
|
+
publicKey: this.wallet.publicKey,
|
|
320
|
+
network: this.wallet.network
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Transfer SPL token (requires PIN)
|
|
325
|
+
*
|
|
326
|
+
* @param params - Transfer parameters
|
|
327
|
+
* @returns Transaction signature and serialized transaction
|
|
328
|
+
*/
|
|
329
|
+
async transferSPL(params) {
|
|
330
|
+
if (!this.wallet) {
|
|
331
|
+
throw new SolanaProviderError(
|
|
332
|
+
SolanaErrorCode.DISCONNECTED,
|
|
333
|
+
"Wallet not connected"
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
if (!this.requestPinCallback) {
|
|
337
|
+
throw new SolanaProviderError(
|
|
338
|
+
SolanaErrorCode.UNAUTHORIZED,
|
|
339
|
+
"PIN callback not set"
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
try {
|
|
343
|
+
const pin = await this.requestPinCallback();
|
|
344
|
+
const encoder = new TextEncoder();
|
|
345
|
+
const data = encoder.encode(pin);
|
|
346
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
347
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
348
|
+
const pinHash = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
349
|
+
const storedPinHash = localStorage.getItem("talkenkit_abc_pin_hash");
|
|
350
|
+
if (storedPinHash && pinHash !== storedPinHash) {
|
|
351
|
+
throw new SolanaProviderError(
|
|
352
|
+
SolanaErrorCode.UNAUTHORIZED,
|
|
353
|
+
"Incorrect PIN"
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
const apiNetwork = this.wallet.network === "solana" ? "solana_mainnet" : this.wallet.network;
|
|
357
|
+
const accountInfo = await this.client.solana.rpcCall({
|
|
358
|
+
network: apiNetwork,
|
|
359
|
+
method: "getParsedAccountInfo",
|
|
360
|
+
params: [
|
|
361
|
+
params.mintAddress,
|
|
362
|
+
{ encoding: "jsonParsed" }
|
|
363
|
+
]
|
|
364
|
+
});
|
|
365
|
+
const decimals = accountInfo.value?.data?.parsed?.info?.decimals || 9;
|
|
366
|
+
const rawAmount = Math.floor(params.amount * 10 ** decimals);
|
|
367
|
+
const txGenResponse = await this.client.solana.generateSPLTransferTransaction({
|
|
368
|
+
network: apiNetwork,
|
|
369
|
+
mintAddress: params.mintAddress,
|
|
370
|
+
fromAddress: this.wallet.address,
|
|
371
|
+
toAddress: params.toAddress,
|
|
372
|
+
amount: rawAmount,
|
|
373
|
+
decimals,
|
|
374
|
+
// Uses transferChecked instruction
|
|
375
|
+
feePayerAddress: this.wallet.address
|
|
376
|
+
});
|
|
377
|
+
const signatureResponse = await this.client.solana.signSolanaTransaction({
|
|
378
|
+
keyId: this.wallet.keyId,
|
|
379
|
+
encryptedShare: this.wallet.encryptedShare,
|
|
380
|
+
secretStore: this.wallet.secretStore || "",
|
|
381
|
+
message: txGenResponse.serialized_tx
|
|
382
|
+
});
|
|
383
|
+
const result = await this.client.solana.sendSolanaTransaction({
|
|
384
|
+
network: apiNetwork,
|
|
385
|
+
serializedTX: txGenResponse.serialized_tx,
|
|
386
|
+
signatures: [signatureResponse.signature]
|
|
387
|
+
});
|
|
388
|
+
return {
|
|
389
|
+
signature: result.txHash,
|
|
390
|
+
serializedTx: txGenResponse.serialized_tx
|
|
391
|
+
};
|
|
392
|
+
} catch (error) {
|
|
393
|
+
console.error("[AbcSolanaProvider] \u274C SPL transfer failed:", error);
|
|
394
|
+
if (error.code === 4001 || error.cancelled) {
|
|
395
|
+
throw error;
|
|
396
|
+
}
|
|
397
|
+
this.emit("error", error);
|
|
398
|
+
throw new SolanaProviderError(
|
|
399
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
400
|
+
"Failed to transfer SPL token",
|
|
401
|
+
error
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Transfer NFT (Solana NFT = SPL token with decimals: 0, amount: 1)
|
|
407
|
+
*
|
|
408
|
+
* @param params - Transfer parameters
|
|
409
|
+
* @returns Transaction signature and serialized transaction
|
|
410
|
+
*/
|
|
411
|
+
async transferNFT(params) {
|
|
412
|
+
return this.transferSPL({
|
|
413
|
+
mintAddress: params.mintAddress,
|
|
414
|
+
toAddress: params.toAddress,
|
|
415
|
+
amount: 1,
|
|
416
|
+
// NFTs always transfer 1 unit
|
|
417
|
+
createAccountIfNeeded: params.createAccountIfNeeded
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Get SPL token balance
|
|
422
|
+
*
|
|
423
|
+
* @param mintAddress - Token mint address
|
|
424
|
+
* @returns Token balance information
|
|
425
|
+
*/
|
|
426
|
+
async getTokenBalance(mintAddress) {
|
|
427
|
+
if (!this.wallet) {
|
|
428
|
+
throw new SolanaProviderError(
|
|
429
|
+
SolanaErrorCode.DISCONNECTED,
|
|
430
|
+
"Wallet not connected"
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
try {
|
|
434
|
+
const { PublicKey } = await import("@solana/web3.js");
|
|
435
|
+
const { getAssociatedTokenAddress, TOKEN_PROGRAM_ID } = await import("@solana/spl-token");
|
|
436
|
+
const mintPubkey = new PublicKey(mintAddress);
|
|
437
|
+
const ownerPubkey = new PublicKey(this.wallet.address);
|
|
438
|
+
const tokenAccount = await getAssociatedTokenAddress(
|
|
439
|
+
mintPubkey,
|
|
440
|
+
ownerPubkey,
|
|
441
|
+
false,
|
|
442
|
+
TOKEN_PROGRAM_ID
|
|
443
|
+
);
|
|
444
|
+
const network = this.wallet.network === "solana" ? "solana_mainnet" : this.wallet.network;
|
|
445
|
+
const balance = await this.client.solana.rpcCall({
|
|
446
|
+
network,
|
|
447
|
+
method: "getTokenAccountBalance",
|
|
448
|
+
params: [tokenAccount.toBase58()]
|
|
449
|
+
});
|
|
450
|
+
return {
|
|
451
|
+
amount: balance.value.amount,
|
|
452
|
+
decimals: balance.value.decimals,
|
|
453
|
+
uiAmount: balance.value.uiAmount || 0
|
|
454
|
+
};
|
|
455
|
+
} catch (error) {
|
|
456
|
+
this.emit("error", error);
|
|
457
|
+
throw new SolanaProviderError(
|
|
458
|
+
SolanaErrorCode.INTERNAL_ERROR,
|
|
459
|
+
"Failed to get token balance",
|
|
460
|
+
error
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
export {
|
|
467
|
+
SolanaProviderError,
|
|
468
|
+
AbcSolanaProvider
|
|
469
|
+
};
|