@abstraxn/signer-react-native 0.0.0-stage → 0.2.1
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 +107 -2
- package/dist/AbstraxnProvider.d.ts +13 -0
- package/dist/AbstraxnProvider.d.ts.map +1 -0
- package/dist/AbstraxnProvider.js +506 -0
- package/dist/AbstraxnProvider.js.map +1 -0
- package/dist/OnboardingUI.d.ts +7 -0
- package/dist/OnboardingUI.d.ts.map +1 -0
- package/dist/OnboardingUI.js +207 -0
- package/dist/OnboardingUI.js.map +1 -0
- package/dist/context.d.ts +3 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +6 -0
- package/dist/context.js.map +1 -0
- package/dist/hooks.d.ts +161 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +825 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +230 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +60 -4
package/dist/hooks.js
ADDED
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hooks for Abstraxn React Native SDK
|
|
3
|
+
*/
|
|
4
|
+
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
5
|
+
import { serializeTransaction } from "viem";
|
|
6
|
+
import { SolanaRelayer } from "@abstraxn/solana-relayer";
|
|
7
|
+
import { LAMPORTS_PER_SOL, PublicKey, } from "@solana/web3.js";
|
|
8
|
+
import { AbstraxnContext } from "./context";
|
|
9
|
+
export function useAbstraxnWallet() {
|
|
10
|
+
const context = useContext(AbstraxnContext);
|
|
11
|
+
if (!context) {
|
|
12
|
+
throw new Error("useAbstraxnWallet must be used within AbstraxnProvider");
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
}
|
|
16
|
+
export function useIsConnected() {
|
|
17
|
+
const { isConnected } = useAbstraxnWallet();
|
|
18
|
+
return isConnected;
|
|
19
|
+
}
|
|
20
|
+
export function useAddress() {
|
|
21
|
+
const { address } = useAbstraxnWallet();
|
|
22
|
+
return address;
|
|
23
|
+
}
|
|
24
|
+
export function useWhoami() {
|
|
25
|
+
const { whoami } = useAbstraxnWallet();
|
|
26
|
+
return whoami;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Hook to get Solana balance (in lamports and formatted SOL) for the active Solana address.
|
|
30
|
+
* Uses `whoami.solanaAddress` and provider `solanaConnection` from AbstraxnProvider config.
|
|
31
|
+
*/
|
|
32
|
+
export function useSolanaBalance() {
|
|
33
|
+
const { whoami, solanaConnection } = useAbstraxnWallet();
|
|
34
|
+
const address = whoami?.solanaAddress ?? null;
|
|
35
|
+
const [lamports, setLamports] = useState(null);
|
|
36
|
+
const [formattedBalance, setFormattedBalance] = useState("0");
|
|
37
|
+
const [loading, setLoading] = useState(false);
|
|
38
|
+
const [error, setError] = useState(null);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
setLamports(null);
|
|
41
|
+
setFormattedBalance("0");
|
|
42
|
+
setError(null);
|
|
43
|
+
if (!solanaConnection || !address) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let cancelled = false;
|
|
47
|
+
const fetchBalance = async () => {
|
|
48
|
+
setLoading(true);
|
|
49
|
+
try {
|
|
50
|
+
const balance = await solanaConnection.getBalance(new PublicKey(address), "confirmed");
|
|
51
|
+
if (cancelled)
|
|
52
|
+
return;
|
|
53
|
+
const asBigInt = BigInt(balance);
|
|
54
|
+
setLamports(asBigInt);
|
|
55
|
+
const sol = Number(asBigInt) / LAMPORTS_PER_SOL;
|
|
56
|
+
setFormattedBalance(sol.toFixed(6));
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
if (cancelled)
|
|
60
|
+
return;
|
|
61
|
+
setError(e instanceof Error ? e : new Error("Failed to load Solana balance"));
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
if (!cancelled) {
|
|
65
|
+
setLoading(false);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
void fetchBalance();
|
|
70
|
+
return () => {
|
|
71
|
+
cancelled = true;
|
|
72
|
+
};
|
|
73
|
+
}, [solanaConnection, address]);
|
|
74
|
+
return {
|
|
75
|
+
address,
|
|
76
|
+
lamports,
|
|
77
|
+
formattedBalance,
|
|
78
|
+
loading,
|
|
79
|
+
error,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function useWallet() {
|
|
83
|
+
const { wallet } = useAbstraxnWallet();
|
|
84
|
+
return wallet;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Hook to export wallet private key.
|
|
88
|
+
* Returns the decrypted export bundle when `privateKey` is provided.
|
|
89
|
+
*/
|
|
90
|
+
export function useExportWallet() {
|
|
91
|
+
const { wallet, isConnected, address } = useAbstraxnWallet();
|
|
92
|
+
const exportWallet = useCallback(async (targetPublicKey, privateKey, blockchain) => {
|
|
93
|
+
if (!isConnected || !wallet) {
|
|
94
|
+
throw new Error("Wallet is not connected");
|
|
95
|
+
}
|
|
96
|
+
return await wallet.exportWallet(targetPublicKey, privateKey, blockchain);
|
|
97
|
+
}, [isConnected, wallet]);
|
|
98
|
+
const exportPrivateKey = useCallback(async (blockchain) => {
|
|
99
|
+
if (!isConnected || !wallet) {
|
|
100
|
+
throw new Error("Wallet is not connected");
|
|
101
|
+
}
|
|
102
|
+
return await wallet.exportPrivateKey(blockchain);
|
|
103
|
+
}, [isConnected, wallet]);
|
|
104
|
+
return { exportWallet, exportPrivateKey, isConnected, address };
|
|
105
|
+
}
|
|
106
|
+
export function useMfaStatus() {
|
|
107
|
+
const { getMfaStatus } = useAbstraxnWallet();
|
|
108
|
+
return { getMfaStatus };
|
|
109
|
+
}
|
|
110
|
+
function isSignMfaRequiredError(error) {
|
|
111
|
+
const e = error;
|
|
112
|
+
const code = String(e?.code ?? e?.response?.data?.code ?? "");
|
|
113
|
+
const status = Number(e?.status ?? e?.response?.status);
|
|
114
|
+
const message = String(e?.message ?? e?.response?.data?.message ?? "").toLowerCase();
|
|
115
|
+
return (code === "SIGN_MFA_REQUIRED" ||
|
|
116
|
+
status === 403 ||
|
|
117
|
+
message.includes("sign_mfa_required") ||
|
|
118
|
+
message.includes("mfa verification required before signing"));
|
|
119
|
+
}
|
|
120
|
+
async function resolveSignMfaCode(resolver) {
|
|
121
|
+
if (!resolver) {
|
|
122
|
+
throw new Error("Sign MFA code is required. Pass a code or resolver to handle SIGN_MFA_REQUIRED.");
|
|
123
|
+
}
|
|
124
|
+
if (typeof resolver === "string") {
|
|
125
|
+
if (!resolver.trim())
|
|
126
|
+
throw new Error("Sign MFA code cannot be empty.");
|
|
127
|
+
return resolver.trim();
|
|
128
|
+
}
|
|
129
|
+
const code = await resolver();
|
|
130
|
+
const normalized = String(code ?? "").trim();
|
|
131
|
+
if (!normalized)
|
|
132
|
+
throw new Error("Sign MFA code cannot be empty.");
|
|
133
|
+
return normalized;
|
|
134
|
+
}
|
|
135
|
+
export function useEnableMfa() {
|
|
136
|
+
const { enableMfa, verifySetupMfa, verifySignMfa } = useAbstraxnWallet();
|
|
137
|
+
const verifySetupMfaWithSignRetry = useCallback(async (code, signMfaCodeOrResolver) => {
|
|
138
|
+
try {
|
|
139
|
+
return await verifySetupMfa(code);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
if (!isSignMfaRequiredError(error))
|
|
143
|
+
throw error;
|
|
144
|
+
const signMfaCode = await resolveSignMfaCode(signMfaCodeOrResolver);
|
|
145
|
+
await verifySignMfa(signMfaCode);
|
|
146
|
+
return await verifySetupMfa(code);
|
|
147
|
+
}
|
|
148
|
+
}, [verifySetupMfa, verifySignMfa]);
|
|
149
|
+
return { enableMfa, verifySetupMfa, verifySetupMfaWithSignRetry };
|
|
150
|
+
}
|
|
151
|
+
export function useDisableMfa() {
|
|
152
|
+
const { disableMfaWithSignedPayload, verifySignMfa } = useAbstraxnWallet();
|
|
153
|
+
const disableMfaWithSignRetry = useCallback(async (signMfaCodeOrResolver) => {
|
|
154
|
+
try {
|
|
155
|
+
return await disableMfaWithSignedPayload();
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (!isSignMfaRequiredError(error))
|
|
159
|
+
throw error;
|
|
160
|
+
const signMfaCode = await resolveSignMfaCode(signMfaCodeOrResolver);
|
|
161
|
+
await verifySignMfa(signMfaCode);
|
|
162
|
+
return await disableMfaWithSignedPayload();
|
|
163
|
+
}
|
|
164
|
+
}, [disableMfaWithSignedPayload, verifySignMfa]);
|
|
165
|
+
return { disableMfaWithSignedPayload, disableMfaWithSignRetry };
|
|
166
|
+
}
|
|
167
|
+
export function useLinkedAuthMethods() {
|
|
168
|
+
const { getSupportedAuthMethods, getLinkedAuthMethods, initiateLinkAuth, submitLinkAuthStamped, linkPasskey, requestOtpForEmailLink, linkEmail, unlinkAuthMethod, } = useAbstraxnWallet();
|
|
169
|
+
return {
|
|
170
|
+
getSupportedAuthMethods,
|
|
171
|
+
getLinkedAuthMethods,
|
|
172
|
+
initiateLinkAuth,
|
|
173
|
+
submitLinkAuthStamped,
|
|
174
|
+
linkPasskey,
|
|
175
|
+
requestOtpForEmailLink,
|
|
176
|
+
linkEmail,
|
|
177
|
+
unlinkAuthMethod,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const AUTH_METHOD_LINK_PROVIDER_ALLOWLIST = new Set(["google", "discord", "twitter", "x", "passkey"]);
|
|
181
|
+
const AUTH_METHOD_OAUTH_PROVIDER_ALLOWLIST = new Set(["google", "discord", "twitter", "x"]);
|
|
182
|
+
const AUTH_METHOD_UNLINK_PROVIDER_ALLOWLIST = new Set([
|
|
183
|
+
"google",
|
|
184
|
+
"discord",
|
|
185
|
+
"x",
|
|
186
|
+
"email",
|
|
187
|
+
"passkey",
|
|
188
|
+
]);
|
|
189
|
+
function normalizeAuthMethodProviderForApi(provider) {
|
|
190
|
+
const normalized = provider.trim().toLowerCase();
|
|
191
|
+
if (normalized === "otp")
|
|
192
|
+
return "email";
|
|
193
|
+
if (normalized === "twitter")
|
|
194
|
+
return "x";
|
|
195
|
+
return normalized;
|
|
196
|
+
}
|
|
197
|
+
function normalizeAuthMethodProviderForMatch(provider) {
|
|
198
|
+
const normalized = normalizeAuthMethodProviderForApi(provider);
|
|
199
|
+
if (normalized === "twitter" || normalized === "x")
|
|
200
|
+
return "x";
|
|
201
|
+
return normalized;
|
|
202
|
+
}
|
|
203
|
+
function normalizeAuthMethodErrorMessage(message) {
|
|
204
|
+
return message.replace(/^network error:\s*/i, "").trim();
|
|
205
|
+
}
|
|
206
|
+
function toAuthMethodError(error, fallbackMessage) {
|
|
207
|
+
if (error instanceof Error) {
|
|
208
|
+
return new Error(normalizeAuthMethodErrorMessage(error.message || fallbackMessage));
|
|
209
|
+
}
|
|
210
|
+
if (typeof error === "string" && error.trim() !== "") {
|
|
211
|
+
return new Error(normalizeAuthMethodErrorMessage(error));
|
|
212
|
+
}
|
|
213
|
+
return new Error(fallbackMessage);
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Managed auth-linking hook for React Native.
|
|
217
|
+
* Unlike web popup-based linking, social link flows are split into
|
|
218
|
+
* `startOAuthLink` + `completeOAuthLink` to support deep-link return handling.
|
|
219
|
+
*/
|
|
220
|
+
export function useAuthMethodLinking() {
|
|
221
|
+
const { wallet, whoami, getSupportedAuthMethods, getLinkedAuthMethods, requestOtpForEmailLink, linkEmail, unlinkAuthMethod, linkPasskey, initiateLinkAuth, submitLinkAuthStamped, } = useAbstraxnWallet();
|
|
222
|
+
const [supportedMethods, setSupportedMethods] = useState([]);
|
|
223
|
+
const [linkedMethods, setLinkedMethods] = useState([]);
|
|
224
|
+
const [queryLoading, setQueryLoading] = useState(false);
|
|
225
|
+
const [actionProvider, setActionProvider] = useState(null);
|
|
226
|
+
const [error, setError] = useState(null);
|
|
227
|
+
const requireConnectedWallet = useCallback(() => {
|
|
228
|
+
if (!wallet?.isConnected) {
|
|
229
|
+
throw new Error("Wallet not connected");
|
|
230
|
+
}
|
|
231
|
+
return wallet;
|
|
232
|
+
}, [wallet]);
|
|
233
|
+
const refreshAuthMethods = useCallback(async (_options) => {
|
|
234
|
+
const activeWallet = requireConnectedWallet();
|
|
235
|
+
setQueryLoading(true);
|
|
236
|
+
setError(null);
|
|
237
|
+
try {
|
|
238
|
+
const supportedRequest = getSupportedAuthMethods != null
|
|
239
|
+
? getSupportedAuthMethods()
|
|
240
|
+
: activeWallet.getSupportedAuthMethods();
|
|
241
|
+
const linkedRequest = getLinkedAuthMethods != null ? getLinkedAuthMethods() : activeWallet.getLinkedAuthMethods();
|
|
242
|
+
const [supportedResponse, linkedResponse] = await Promise.all([supportedRequest, linkedRequest]);
|
|
243
|
+
const loginProvider = normalizeAuthMethodProviderForMatch(String(whoami?.loginProvider ?? ""));
|
|
244
|
+
const allSupportedMethods = supportedResponse.supportedMethods ?? [];
|
|
245
|
+
const filteredMethods = loginProvider !== ""
|
|
246
|
+
? allSupportedMethods.filter((method) => normalizeAuthMethodProviderForMatch(method.provider) !== loginProvider)
|
|
247
|
+
: allSupportedMethods;
|
|
248
|
+
setSupportedMethods(filteredMethods);
|
|
249
|
+
setLinkedMethods(linkedResponse.linkedMethods ?? []);
|
|
250
|
+
}
|
|
251
|
+
catch (err) {
|
|
252
|
+
const nextError = toAuthMethodError(err, "Failed to load auth methods");
|
|
253
|
+
setSupportedMethods([]);
|
|
254
|
+
setLinkedMethods([]);
|
|
255
|
+
setError(nextError.message);
|
|
256
|
+
throw nextError;
|
|
257
|
+
}
|
|
258
|
+
finally {
|
|
259
|
+
setQueryLoading(false);
|
|
260
|
+
}
|
|
261
|
+
}, [getLinkedAuthMethods, getSupportedAuthMethods, requireConnectedWallet, whoami]);
|
|
262
|
+
const isLinked = useCallback((provider) => {
|
|
263
|
+
const normalizedProvider = normalizeAuthMethodProviderForMatch(provider);
|
|
264
|
+
return linkedMethods.some((method) => normalizeAuthMethodProviderForMatch(method.authProvider) === normalizedProvider);
|
|
265
|
+
}, [linkedMethods]);
|
|
266
|
+
const startOAuthLink = useCallback(async (provider) => {
|
|
267
|
+
const activeWallet = requireConnectedWallet();
|
|
268
|
+
const normalizedProvider = normalizeAuthMethodProviderForApi(provider);
|
|
269
|
+
if (!AUTH_METHOD_OAUTH_PROVIDER_ALLOWLIST.has(normalizedProvider)) {
|
|
270
|
+
throw new Error(`Unsupported OAuth provider for linking: ${provider}`);
|
|
271
|
+
}
|
|
272
|
+
setActionProvider(normalizedProvider);
|
|
273
|
+
setError(null);
|
|
274
|
+
try {
|
|
275
|
+
const { authUrl, message } = await (initiateLinkAuth != null
|
|
276
|
+
? initiateLinkAuth(normalizedProvider)
|
|
277
|
+
: activeWallet.initiateLinkAuth(normalizedProvider));
|
|
278
|
+
return {
|
|
279
|
+
provider: normalizedProvider,
|
|
280
|
+
authUrl,
|
|
281
|
+
...(message ? { message } : {}),
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
const nextError = toAuthMethodError(err, "Failed to start auth method link");
|
|
286
|
+
setError(nextError.message);
|
|
287
|
+
throw nextError;
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
setActionProvider(null);
|
|
291
|
+
}
|
|
292
|
+
}, [initiateLinkAuth, requireConnectedWallet]);
|
|
293
|
+
const completeOAuthLink = useCallback(async (provider, activityBody) => {
|
|
294
|
+
const activeWallet = requireConnectedWallet();
|
|
295
|
+
const normalizedProvider = normalizeAuthMethodProviderForApi(provider);
|
|
296
|
+
const trimmedBody = activityBody.trim();
|
|
297
|
+
if (!AUTH_METHOD_OAUTH_PROVIDER_ALLOWLIST.has(normalizedProvider)) {
|
|
298
|
+
throw new Error(`Unsupported OAuth provider for linking: ${provider}`);
|
|
299
|
+
}
|
|
300
|
+
if (!trimmedBody) {
|
|
301
|
+
throw new Error("activityBody is required to finalize OAuth linking");
|
|
302
|
+
}
|
|
303
|
+
setActionProvider(normalizedProvider);
|
|
304
|
+
setError(null);
|
|
305
|
+
try {
|
|
306
|
+
if (submitLinkAuthStamped != null) {
|
|
307
|
+
await submitLinkAuthStamped(normalizedProvider, trimmedBody);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
await activeWallet.submitLinkAuthStamped(normalizedProvider, trimmedBody);
|
|
311
|
+
}
|
|
312
|
+
await refreshAuthMethods({ force: true });
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
const nextError = toAuthMethodError(err, "Failed to finalize auth method link");
|
|
316
|
+
setError(nextError.message);
|
|
317
|
+
throw nextError;
|
|
318
|
+
}
|
|
319
|
+
finally {
|
|
320
|
+
setActionProvider(null);
|
|
321
|
+
}
|
|
322
|
+
}, [refreshAuthMethods, requireConnectedWallet, submitLinkAuthStamped]);
|
|
323
|
+
const linkProvider = useCallback(async (provider) => {
|
|
324
|
+
const activeWallet = requireConnectedWallet();
|
|
325
|
+
const normalizedProvider = normalizeAuthMethodProviderForApi(provider);
|
|
326
|
+
if (!AUTH_METHOD_LINK_PROVIDER_ALLOWLIST.has(normalizedProvider)) {
|
|
327
|
+
throw new Error(`Unsupported provider for linking: ${provider}`);
|
|
328
|
+
}
|
|
329
|
+
setActionProvider(normalizedProvider);
|
|
330
|
+
setError(null);
|
|
331
|
+
try {
|
|
332
|
+
if (normalizedProvider === "passkey") {
|
|
333
|
+
if (linkPasskey != null) {
|
|
334
|
+
await linkPasskey();
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
await activeWallet.linkPasskey();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
throw new Error("Social linking in React Native is a two-step flow. Call startOAuthLink(provider), complete your deep-link callback, then call completeOAuthLink(provider, activityBody).");
|
|
342
|
+
}
|
|
343
|
+
await refreshAuthMethods({ force: true });
|
|
344
|
+
}
|
|
345
|
+
catch (err) {
|
|
346
|
+
const nextError = toAuthMethodError(err, "Failed to link auth method");
|
|
347
|
+
setError(nextError.message);
|
|
348
|
+
throw nextError;
|
|
349
|
+
}
|
|
350
|
+
finally {
|
|
351
|
+
setActionProvider(null);
|
|
352
|
+
}
|
|
353
|
+
}, [linkPasskey, refreshAuthMethods, requireConnectedWallet]);
|
|
354
|
+
const requestEmailLinkOtp = useCallback(async (email) => {
|
|
355
|
+
const activeWallet = requireConnectedWallet();
|
|
356
|
+
const trimmedEmail = email.trim();
|
|
357
|
+
if (!trimmedEmail) {
|
|
358
|
+
throw new Error("Email is required");
|
|
359
|
+
}
|
|
360
|
+
setActionProvider("email");
|
|
361
|
+
setError(null);
|
|
362
|
+
try {
|
|
363
|
+
if (requestOtpForEmailLink != null) {
|
|
364
|
+
return await requestOtpForEmailLink(trimmedEmail);
|
|
365
|
+
}
|
|
366
|
+
return await activeWallet.requestOtpForEmailLink(trimmedEmail);
|
|
367
|
+
}
|
|
368
|
+
catch (err) {
|
|
369
|
+
const nextError = toAuthMethodError(err, "Failed to send email verification code");
|
|
370
|
+
setError(nextError.message);
|
|
371
|
+
throw nextError;
|
|
372
|
+
}
|
|
373
|
+
finally {
|
|
374
|
+
setActionProvider(null);
|
|
375
|
+
}
|
|
376
|
+
}, [requestOtpForEmailLink, requireConnectedWallet]);
|
|
377
|
+
const confirmEmailLink = useCallback(async (otpId, otpCode) => {
|
|
378
|
+
const activeWallet = requireConnectedWallet();
|
|
379
|
+
const trimmedOtpId = otpId.trim();
|
|
380
|
+
const trimmedOtpCode = otpCode.trim();
|
|
381
|
+
if (!trimmedOtpId || !trimmedOtpCode) {
|
|
382
|
+
throw new Error("otpId and otpCode are required");
|
|
383
|
+
}
|
|
384
|
+
setActionProvider("email");
|
|
385
|
+
setError(null);
|
|
386
|
+
try {
|
|
387
|
+
if (linkEmail != null) {
|
|
388
|
+
await linkEmail(trimmedOtpId, trimmedOtpCode);
|
|
389
|
+
}
|
|
390
|
+
else {
|
|
391
|
+
await activeWallet.linkEmail(trimmedOtpId, trimmedOtpCode);
|
|
392
|
+
}
|
|
393
|
+
await refreshAuthMethods({ force: true });
|
|
394
|
+
}
|
|
395
|
+
catch (err) {
|
|
396
|
+
const nextError = toAuthMethodError(err, "Failed to link email");
|
|
397
|
+
setError(nextError.message);
|
|
398
|
+
throw nextError;
|
|
399
|
+
}
|
|
400
|
+
finally {
|
|
401
|
+
setActionProvider(null);
|
|
402
|
+
}
|
|
403
|
+
}, [linkEmail, refreshAuthMethods, requireConnectedWallet]);
|
|
404
|
+
const unlinkProvider = useCallback(async (provider) => {
|
|
405
|
+
const activeWallet = requireConnectedWallet();
|
|
406
|
+
const normalizedProvider = normalizeAuthMethodProviderForApi(provider);
|
|
407
|
+
if (!AUTH_METHOD_UNLINK_PROVIDER_ALLOWLIST.has(normalizedProvider)) {
|
|
408
|
+
throw new Error(`Unsupported provider for unlinking: ${provider}`);
|
|
409
|
+
}
|
|
410
|
+
setActionProvider(normalizedProvider);
|
|
411
|
+
setError(null);
|
|
412
|
+
try {
|
|
413
|
+
if (unlinkAuthMethod != null) {
|
|
414
|
+
await unlinkAuthMethod(normalizedProvider);
|
|
415
|
+
}
|
|
416
|
+
else {
|
|
417
|
+
await activeWallet.unlinkAuthMethod(normalizedProvider);
|
|
418
|
+
}
|
|
419
|
+
await refreshAuthMethods({ force: true });
|
|
420
|
+
}
|
|
421
|
+
catch (err) {
|
|
422
|
+
const nextError = toAuthMethodError(err, "Failed to unlink auth method");
|
|
423
|
+
setError(nextError.message);
|
|
424
|
+
throw nextError;
|
|
425
|
+
}
|
|
426
|
+
finally {
|
|
427
|
+
setActionProvider(null);
|
|
428
|
+
}
|
|
429
|
+
}, [refreshAuthMethods, requireConnectedWallet, unlinkAuthMethod]);
|
|
430
|
+
return {
|
|
431
|
+
supportedMethods,
|
|
432
|
+
linkedMethods,
|
|
433
|
+
loading: queryLoading || actionProvider !== null,
|
|
434
|
+
actionProvider,
|
|
435
|
+
error,
|
|
436
|
+
refreshAuthMethods,
|
|
437
|
+
isLinked,
|
|
438
|
+
linkProvider,
|
|
439
|
+
requestEmailLinkOtp,
|
|
440
|
+
confirmEmailLink,
|
|
441
|
+
unlinkProvider,
|
|
442
|
+
startOAuthLink,
|
|
443
|
+
completeOAuthLink,
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Hook to sign a transaction via backend API.
|
|
448
|
+
* Mirrors useSignTxn from signer-react (web) but uses rpcUrl instead of PublicClient.
|
|
449
|
+
*/
|
|
450
|
+
export function useSignTxn(rpcUrl) {
|
|
451
|
+
const { wallet, isConnected, address, signTransactionViaAPI } = useAbstraxnWallet();
|
|
452
|
+
const signTxn = useCallback(async (params) => {
|
|
453
|
+
const { from, to, value = 0n, data = "0x", chainId, gas } = params;
|
|
454
|
+
if (!isConnected || !wallet) {
|
|
455
|
+
throw new Error("Wallet is not connected");
|
|
456
|
+
}
|
|
457
|
+
if (!rpcUrl) {
|
|
458
|
+
throw new Error("RPC URL is required");
|
|
459
|
+
}
|
|
460
|
+
if (!from)
|
|
461
|
+
throw new Error("From address is required");
|
|
462
|
+
if (!to)
|
|
463
|
+
throw new Error("To address is required");
|
|
464
|
+
let targetChainId = chainId;
|
|
465
|
+
if (targetChainId === undefined) {
|
|
466
|
+
const chainIdRes = await fetch(rpcUrl, {
|
|
467
|
+
method: "POST",
|
|
468
|
+
headers: { "Content-Type": "application/json" },
|
|
469
|
+
body: JSON.stringify({
|
|
470
|
+
jsonrpc: "2.0",
|
|
471
|
+
method: "eth_chainId",
|
|
472
|
+
params: [],
|
|
473
|
+
id: 1,
|
|
474
|
+
}),
|
|
475
|
+
});
|
|
476
|
+
const chainIdData = await chainIdRes.json();
|
|
477
|
+
if (chainIdData.error || chainIdData.result == null)
|
|
478
|
+
throw new Error(chainIdData.error?.message || "Failed to get chain ID from RPC");
|
|
479
|
+
targetChainId = Number(chainIdData.result);
|
|
480
|
+
}
|
|
481
|
+
const valueInWei = typeof value === "bigint" ? value : BigInt(value === "0x" || value === "" ? "0" : value);
|
|
482
|
+
const nonceRes = await fetch(rpcUrl, {
|
|
483
|
+
method: "POST",
|
|
484
|
+
headers: { "Content-Type": "application/json" },
|
|
485
|
+
body: JSON.stringify({
|
|
486
|
+
jsonrpc: "2.0",
|
|
487
|
+
method: "eth_getTransactionCount",
|
|
488
|
+
params: [from, "latest"],
|
|
489
|
+
id: 1,
|
|
490
|
+
}),
|
|
491
|
+
});
|
|
492
|
+
const nonceData = await nonceRes.json();
|
|
493
|
+
if (nonceData.error)
|
|
494
|
+
throw new Error(nonceData.error.message || "Failed to get nonce");
|
|
495
|
+
const nonce = Number(nonceData.result);
|
|
496
|
+
let gasPrice = gas?.gasPrice;
|
|
497
|
+
const hasEip1559 = gas?.maxFeePerGas !== undefined || gas?.maxPriorityFeePerGas !== undefined;
|
|
498
|
+
if (!hasEip1559 && gasPrice === undefined) {
|
|
499
|
+
const gasRes = await fetch(rpcUrl, {
|
|
500
|
+
method: "POST",
|
|
501
|
+
headers: { "Content-Type": "application/json" },
|
|
502
|
+
body: JSON.stringify({
|
|
503
|
+
jsonrpc: "2.0",
|
|
504
|
+
method: "eth_gasPrice",
|
|
505
|
+
params: [],
|
|
506
|
+
id: 1,
|
|
507
|
+
}),
|
|
508
|
+
});
|
|
509
|
+
const gasData = await gasRes.json();
|
|
510
|
+
if (!gasData.error && gasData.result)
|
|
511
|
+
gasPrice = BigInt(gasData.result);
|
|
512
|
+
}
|
|
513
|
+
if (!hasEip1559 && gasPrice === undefined)
|
|
514
|
+
gasPrice = 0n;
|
|
515
|
+
const baseTx = {
|
|
516
|
+
chainId: targetChainId,
|
|
517
|
+
from: from,
|
|
518
|
+
to: to,
|
|
519
|
+
data: data || "0x",
|
|
520
|
+
value: valueInWei,
|
|
521
|
+
nonce,
|
|
522
|
+
type: hasEip1559 ? "eip1559" : "legacy",
|
|
523
|
+
gas: gas?.gasLimit ?? 21000n,
|
|
524
|
+
...(hasEip1559
|
|
525
|
+
? {
|
|
526
|
+
maxFeePerGas: gas?.maxFeePerGas ?? gasPrice,
|
|
527
|
+
maxPriorityFeePerGas: gas?.maxPriorityFeePerGas ?? gasPrice,
|
|
528
|
+
}
|
|
529
|
+
: { gasPrice }),
|
|
530
|
+
};
|
|
531
|
+
const serializedTx = serializeTransaction(baseTx);
|
|
532
|
+
const result = await signTransactionViaAPI(serializedTx, from);
|
|
533
|
+
return {
|
|
534
|
+
unsignedTransaction: serializedTx,
|
|
535
|
+
signedTransaction: result.signedTransaction,
|
|
536
|
+
};
|
|
537
|
+
}, [rpcUrl, isConnected, wallet, signTransactionViaAPI]);
|
|
538
|
+
return { signTxn, isConnected, address };
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Hook to sign a transaction via backend API and send it via the given RPC URL.
|
|
542
|
+
* Mirrors useSignAndSendTxn from signer-react (web) but uses rpcUrl instead of PublicClient.
|
|
543
|
+
*/
|
|
544
|
+
export function useSignAndSendTxn(rpcUrl) {
|
|
545
|
+
const { wallet, isConnected, address, signAndSendTransaction } = useAbstraxnWallet();
|
|
546
|
+
const signAndSendTxn = useCallback(async (params) => {
|
|
547
|
+
const { from, to, value = 0n, data = "0x", chainId, gas } = params;
|
|
548
|
+
if (!isConnected || !wallet) {
|
|
549
|
+
throw new Error("Wallet is not connected");
|
|
550
|
+
}
|
|
551
|
+
if (!rpcUrl) {
|
|
552
|
+
throw new Error("RPC URL is required");
|
|
553
|
+
}
|
|
554
|
+
if (!from)
|
|
555
|
+
throw new Error("From address is required");
|
|
556
|
+
if (!to)
|
|
557
|
+
throw new Error("To address is required");
|
|
558
|
+
let targetChainId = chainId;
|
|
559
|
+
if (targetChainId === undefined) {
|
|
560
|
+
const chainIdRes = await fetch(rpcUrl, {
|
|
561
|
+
method: "POST",
|
|
562
|
+
headers: { "Content-Type": "application/json" },
|
|
563
|
+
body: JSON.stringify({
|
|
564
|
+
jsonrpc: "2.0",
|
|
565
|
+
method: "eth_chainId",
|
|
566
|
+
params: [],
|
|
567
|
+
id: 1,
|
|
568
|
+
}),
|
|
569
|
+
});
|
|
570
|
+
const chainIdData = await chainIdRes.json();
|
|
571
|
+
if (chainIdData.error || chainIdData.result == null)
|
|
572
|
+
throw new Error(chainIdData.error?.message || "Failed to get chain ID from RPC");
|
|
573
|
+
targetChainId = Number(chainIdData.result);
|
|
574
|
+
}
|
|
575
|
+
const valueInWei = typeof value === "bigint" ? value : BigInt(value === "0x" || value === "" ? "0" : value);
|
|
576
|
+
const nonceRes = await fetch(rpcUrl, {
|
|
577
|
+
method: "POST",
|
|
578
|
+
headers: { "Content-Type": "application/json" },
|
|
579
|
+
body: JSON.stringify({
|
|
580
|
+
jsonrpc: "2.0",
|
|
581
|
+
method: "eth_getTransactionCount",
|
|
582
|
+
params: [from, "latest"],
|
|
583
|
+
id: 1,
|
|
584
|
+
}),
|
|
585
|
+
});
|
|
586
|
+
const nonceData = await nonceRes.json();
|
|
587
|
+
if (nonceData.error)
|
|
588
|
+
throw new Error(nonceData.error.message || "Failed to get nonce");
|
|
589
|
+
const nonce = Number(nonceData.result);
|
|
590
|
+
let gasPrice = gas?.gasPrice;
|
|
591
|
+
const hasEip1559 = gas?.maxFeePerGas !== undefined || gas?.maxPriorityFeePerGas !== undefined;
|
|
592
|
+
if (!hasEip1559 && gasPrice === undefined) {
|
|
593
|
+
const gasRes = await fetch(rpcUrl, {
|
|
594
|
+
method: "POST",
|
|
595
|
+
headers: { "Content-Type": "application/json" },
|
|
596
|
+
body: JSON.stringify({
|
|
597
|
+
jsonrpc: "2.0",
|
|
598
|
+
method: "eth_gasPrice",
|
|
599
|
+
params: [],
|
|
600
|
+
id: 1,
|
|
601
|
+
}),
|
|
602
|
+
});
|
|
603
|
+
const gasData = await gasRes.json();
|
|
604
|
+
if (!gasData.error && gasData.result)
|
|
605
|
+
gasPrice = BigInt(gasData.result);
|
|
606
|
+
}
|
|
607
|
+
if (!hasEip1559 && gasPrice === undefined)
|
|
608
|
+
gasPrice = 0n;
|
|
609
|
+
const baseTx = {
|
|
610
|
+
chainId: targetChainId,
|
|
611
|
+
from: from,
|
|
612
|
+
to: to,
|
|
613
|
+
data: data || "0x",
|
|
614
|
+
value: valueInWei,
|
|
615
|
+
nonce,
|
|
616
|
+
type: hasEip1559 ? "eip1559" : "legacy",
|
|
617
|
+
gas: gas?.gasLimit ?? 21000n,
|
|
618
|
+
...(hasEip1559
|
|
619
|
+
? {
|
|
620
|
+
maxFeePerGas: gas?.maxFeePerGas ?? gasPrice,
|
|
621
|
+
maxPriorityFeePerGas: gas?.maxPriorityFeePerGas ?? gasPrice,
|
|
622
|
+
}
|
|
623
|
+
: { gasPrice }),
|
|
624
|
+
};
|
|
625
|
+
console.log("[useSignAndSendTxn] transaction params:", {
|
|
626
|
+
chainId: baseTx.chainId,
|
|
627
|
+
from: baseTx.from,
|
|
628
|
+
to: baseTx.to,
|
|
629
|
+
value: String(baseTx.value),
|
|
630
|
+
data: baseTx.data,
|
|
631
|
+
nonce: baseTx.nonce,
|
|
632
|
+
type: baseTx.type,
|
|
633
|
+
gas: baseTx.gas,
|
|
634
|
+
gasPrice: baseTx.gasPrice,
|
|
635
|
+
maxFeePerGas: baseTx.maxFeePerGas,
|
|
636
|
+
maxPriorityFeePerGas: baseTx.maxPriorityFeePerGas,
|
|
637
|
+
});
|
|
638
|
+
const serializedTx = serializeTransaction(baseTx);
|
|
639
|
+
const result = await signAndSendTransaction(serializedTx, from, rpcUrl);
|
|
640
|
+
return {
|
|
641
|
+
hash: result.hash,
|
|
642
|
+
unsignedTransaction: serializedTx,
|
|
643
|
+
// signAndSendTransaction does not currently return the signed raw tx.
|
|
644
|
+
signedTransaction: undefined,
|
|
645
|
+
};
|
|
646
|
+
}, [rpcUrl, isConnected, wallet, signAndSendTransaction]);
|
|
647
|
+
return { signAndSendTxn, isConnected, address };
|
|
648
|
+
}
|
|
649
|
+
function isInvalidDeviceIdError(error) {
|
|
650
|
+
const candidate = error;
|
|
651
|
+
return (candidate?.code === "INVALID_DEVICE_ID" ||
|
|
652
|
+
candidate?.name === "InvalidDeviceIdError" ||
|
|
653
|
+
(typeof candidate?.message === "string" && candidate.message.includes("INVALID_DEVICE_ID")));
|
|
654
|
+
}
|
|
655
|
+
async function runWithSolanaSignRetry(performSign, verifySignMfa, signMfaResolver) {
|
|
656
|
+
try {
|
|
657
|
+
return await performSign();
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
if (isInvalidDeviceIdError(error)) {
|
|
661
|
+
throw new Error("Your device verification expired. Please try signing again.");
|
|
662
|
+
}
|
|
663
|
+
if (!isSignMfaRequiredError(error))
|
|
664
|
+
throw error;
|
|
665
|
+
const code = await resolveSignMfaCode(signMfaResolver);
|
|
666
|
+
let verifyResponse;
|
|
667
|
+
try {
|
|
668
|
+
verifyResponse = await verifySignMfa(code);
|
|
669
|
+
}
|
|
670
|
+
catch (verifyError) {
|
|
671
|
+
throw new Error(verifyError instanceof Error
|
|
672
|
+
? `MFA verification failed: ${verifyError.message}`
|
|
673
|
+
: "MFA verification failed. Please check your code and try again.");
|
|
674
|
+
}
|
|
675
|
+
if (!verifyResponse?.verified) {
|
|
676
|
+
throw new Error("Incorrect MFA code. Please try again.");
|
|
677
|
+
}
|
|
678
|
+
try {
|
|
679
|
+
return await performSign();
|
|
680
|
+
}
|
|
681
|
+
catch (retryError) {
|
|
682
|
+
if (isSignMfaRequiredError(retryError)) {
|
|
683
|
+
throw new Error("MFA step-up expired before signing. Please retry the transaction.");
|
|
684
|
+
}
|
|
685
|
+
throw retryError;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
function hexToBase64SignedTransaction(signedHex) {
|
|
690
|
+
const hex = signedHex.startsWith("0x") ? signedHex.slice(2) : signedHex;
|
|
691
|
+
const bytes = new Uint8Array(hex.match(/.{1,2}/g)?.map((byte) => parseInt(byte, 16)) ?? []);
|
|
692
|
+
if (typeof btoa === "function") {
|
|
693
|
+
let binary = "";
|
|
694
|
+
for (let i = 0; i < bytes.length; i++)
|
|
695
|
+
binary += String.fromCharCode(bytes[i]);
|
|
696
|
+
return btoa(binary);
|
|
697
|
+
}
|
|
698
|
+
const BufferCtor = globalThis
|
|
699
|
+
.Buffer;
|
|
700
|
+
if (BufferCtor?.from) {
|
|
701
|
+
return BufferCtor.from(bytes).toString("base64");
|
|
702
|
+
}
|
|
703
|
+
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
704
|
+
let output = "";
|
|
705
|
+
const len = bytes.length;
|
|
706
|
+
for (let i = 0; i < len; i += 3) {
|
|
707
|
+
const b1 = bytes[i];
|
|
708
|
+
const b2 = bytes[i + 1];
|
|
709
|
+
const b3 = bytes[i + 2];
|
|
710
|
+
const triple = (b1 << 16) | ((b2 ?? 0) << 8) | (b3 ?? 0);
|
|
711
|
+
output += chars[(triple >> 18) & 63];
|
|
712
|
+
output += chars[(triple >> 12) & 63];
|
|
713
|
+
output += b2 !== undefined ? chars[(triple >> 6) & 63] : "=";
|
|
714
|
+
output += b3 !== undefined ? chars[triple & 63] : "=";
|
|
715
|
+
}
|
|
716
|
+
return output;
|
|
717
|
+
}
|
|
718
|
+
export function useSolanaGasless(options) {
|
|
719
|
+
const { isConnected, whoami, solanaConnection, signSolanaTransactionViaAPI, verifySignMfa, solanaGaslessConfig, } = useAbstraxnWallet();
|
|
720
|
+
const signMfaResolver = options?.signMfaResolver;
|
|
721
|
+
const resolvedConfig = useMemo(() => {
|
|
722
|
+
if (!solanaGaslessConfig?.enabled)
|
|
723
|
+
return null;
|
|
724
|
+
const relayerUrl = solanaGaslessConfig.relayerUrl?.trim();
|
|
725
|
+
if (!relayerUrl)
|
|
726
|
+
return null;
|
|
727
|
+
return {
|
|
728
|
+
enabled: true,
|
|
729
|
+
relayerUrl,
|
|
730
|
+
defaultPollMs: solanaGaslessConfig.defaultPollMs,
|
|
731
|
+
defaultTimeoutMs: solanaGaslessConfig.defaultTimeoutMs,
|
|
732
|
+
};
|
|
733
|
+
}, [solanaGaslessConfig]);
|
|
734
|
+
const relayerClient = useMemo(() => {
|
|
735
|
+
if (!resolvedConfig)
|
|
736
|
+
return null;
|
|
737
|
+
return new SolanaRelayer({
|
|
738
|
+
relayerUrl: resolvedConfig.relayerUrl,
|
|
739
|
+
defaultPollMs: resolvedConfig.defaultPollMs,
|
|
740
|
+
defaultTimeoutMs: resolvedConfig.defaultTimeoutMs,
|
|
741
|
+
});
|
|
742
|
+
}, [resolvedConfig]);
|
|
743
|
+
const ensureReady = useCallback(() => {
|
|
744
|
+
if (!isConnected)
|
|
745
|
+
throw new Error("Wallet is not connected");
|
|
746
|
+
if (!resolvedConfig) {
|
|
747
|
+
throw new Error("Solana gasless is not configured. Set config.solanaGasless with enabled and relayerUrl.");
|
|
748
|
+
}
|
|
749
|
+
if (!relayerClient)
|
|
750
|
+
throw new Error("Failed to initialize Solana relayer client");
|
|
751
|
+
if (!signSolanaTransactionViaAPI) {
|
|
752
|
+
throw new Error("Solana transaction signing is not supported by this wallet");
|
|
753
|
+
}
|
|
754
|
+
const sender = whoami?.solanaAddress ?? null;
|
|
755
|
+
if (!sender)
|
|
756
|
+
throw new Error("Solana address is required for gasless flow");
|
|
757
|
+
return { sender };
|
|
758
|
+
}, [isConnected, relayerClient, resolvedConfig, signSolanaTransactionViaAPI, whoami]);
|
|
759
|
+
const buildGaslessTx = useCallback(async (params) => {
|
|
760
|
+
const { sender } = ensureReady();
|
|
761
|
+
const connection = params.connection ?? solanaConnection;
|
|
762
|
+
if (!connection)
|
|
763
|
+
throw new Error("Solana connection is required (set config.solanaEndpoint or pass connection)");
|
|
764
|
+
const { connection: _connection, sender: _sender, ...rest } = params;
|
|
765
|
+
return await relayerClient.buildTx({
|
|
766
|
+
connection,
|
|
767
|
+
sender: _sender ?? sender,
|
|
768
|
+
...rest,
|
|
769
|
+
});
|
|
770
|
+
}, [ensureReady, solanaConnection, relayerClient]);
|
|
771
|
+
const signGaslessTx = useCallback(async (params) => {
|
|
772
|
+
const { sender } = ensureReady();
|
|
773
|
+
const unsignedBytes = params.transaction.serialize({ requireAllSignatures: false });
|
|
774
|
+
const unsignedHex = Array.from(unsignedBytes)
|
|
775
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
776
|
+
.join("");
|
|
777
|
+
const signWith = params.sender ?? sender;
|
|
778
|
+
const { signedTransaction } = await runWithSolanaSignRetry(() => signSolanaTransactionViaAPI(unsignedHex, signWith), verifySignMfa, signMfaResolver);
|
|
779
|
+
return {
|
|
780
|
+
signedTransactionHex: signedTransaction,
|
|
781
|
+
signedTransactionBase64: hexToBase64SignedTransaction(signedTransaction),
|
|
782
|
+
};
|
|
783
|
+
}, [ensureReady, signSolanaTransactionViaAPI, verifySignMfa, signMfaResolver]);
|
|
784
|
+
const sendGaslessTx = useCallback(async (params) => {
|
|
785
|
+
ensureReady();
|
|
786
|
+
return await relayerClient.sendTx({
|
|
787
|
+
signedTransaction: params.signedTransactionBase64,
|
|
788
|
+
lastValidBlockHeight: params.lastValidBlockHeight,
|
|
789
|
+
});
|
|
790
|
+
}, [ensureReady, relayerClient]);
|
|
791
|
+
const getGaslessTxStatus = useCallback(async (txnId) => {
|
|
792
|
+
ensureReady();
|
|
793
|
+
return await relayerClient.getTxStatus({ txnId });
|
|
794
|
+
}, [ensureReady, relayerClient]);
|
|
795
|
+
return {
|
|
796
|
+
isEnabled: !!resolvedConfig,
|
|
797
|
+
config: resolvedConfig,
|
|
798
|
+
relayerClient,
|
|
799
|
+
buildGaslessTx,
|
|
800
|
+
signGaslessTx,
|
|
801
|
+
sendGaslessTx,
|
|
802
|
+
getGaslessTxStatus,
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
export function useSignAndSendSolanaGaslessTxn(options) {
|
|
806
|
+
const { buildGaslessTx, signGaslessTx, sendGaslessTx } = useSolanaGasless(options);
|
|
807
|
+
const signAndSendGaslessTx = useCallback(async (params) => {
|
|
808
|
+
const built = await buildGaslessTx(params);
|
|
809
|
+
const signed = await signGaslessTx({ transaction: built.tx, sender: params.sender });
|
|
810
|
+
const relay = await sendGaslessTx({
|
|
811
|
+
signedTransactionBase64: signed.signedTransactionBase64,
|
|
812
|
+
lastValidBlockHeight: built.lastValidBlockHeight,
|
|
813
|
+
});
|
|
814
|
+
return {
|
|
815
|
+
txnId: relay.txnId,
|
|
816
|
+
status: relay.status,
|
|
817
|
+
preview: built.preview,
|
|
818
|
+
signedTransactionHex: signed.signedTransactionHex,
|
|
819
|
+
signedTransactionBase64: signed.signedTransactionBase64,
|
|
820
|
+
lastValidBlockHeight: built.lastValidBlockHeight,
|
|
821
|
+
};
|
|
822
|
+
}, [buildGaslessTx, sendGaslessTx, signGaslessTx]);
|
|
823
|
+
return { signAndSendGaslessTx };
|
|
824
|
+
}
|
|
825
|
+
//# sourceMappingURL=hooks.js.map
|