@authon/react-native 0.2.2 → 0.3.0
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.ko.md +154 -0
- package/README.md +412 -50
- package/dist/index.cjs +262 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +85 -2
- package/dist/index.d.ts +85 -2
- package/dist/index.js +257 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { AuthonUser as AuthonUser$1, OAuthProviderType, BrandingConfig } from '@authon/shared';
|
|
3
|
+
import { AuthonUser as AuthonUser$1, OAuthProviderType, BrandingConfig, Web3Chain, Web3WalletType, Web3NonceResponse, Web3Wallet, PasskeyCredential } from '@authon/shared';
|
|
4
4
|
export { BrandingConfig, OAuthProviderType } from '@authon/shared';
|
|
5
5
|
import { ViewStyle, TextStyle } from 'react-native';
|
|
6
6
|
|
|
@@ -94,6 +94,39 @@ declare class AuthonMobileClient {
|
|
|
94
94
|
user: AuthonUser;
|
|
95
95
|
}>;
|
|
96
96
|
getApiUrl(): string;
|
|
97
|
+
web3GetNonce(address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number): Promise<Web3NonceResponse>;
|
|
98
|
+
web3Verify(message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType): Promise<{
|
|
99
|
+
tokens: TokenPair;
|
|
100
|
+
user: AuthonUser;
|
|
101
|
+
}>;
|
|
102
|
+
web3GetWallets(): Promise<Web3Wallet[]>;
|
|
103
|
+
web3LinkWallet(params: {
|
|
104
|
+
address: string;
|
|
105
|
+
chain: Web3Chain;
|
|
106
|
+
walletType: Web3WalletType;
|
|
107
|
+
chainId?: number;
|
|
108
|
+
message: string;
|
|
109
|
+
signature: string;
|
|
110
|
+
}): Promise<Web3Wallet>;
|
|
111
|
+
web3UnlinkWallet(walletId: string): Promise<void>;
|
|
112
|
+
passwordlessSendCode(identifier: string, type?: 'email' | 'sms'): Promise<void>;
|
|
113
|
+
passwordlessVerifyCode(identifier: string, code: string): Promise<{
|
|
114
|
+
tokens: TokenPair;
|
|
115
|
+
user: AuthonUser;
|
|
116
|
+
}>;
|
|
117
|
+
passkeyStartRegister(name?: string): Promise<{
|
|
118
|
+
options: Record<string, unknown>;
|
|
119
|
+
}>;
|
|
120
|
+
passkeyCompleteRegister(credential: Record<string, unknown>): Promise<PasskeyCredential>;
|
|
121
|
+
passkeyStartAuth(email?: string): Promise<{
|
|
122
|
+
options: Record<string, unknown>;
|
|
123
|
+
}>;
|
|
124
|
+
passkeyCompleteAuth(credential: Record<string, unknown>): Promise<{
|
|
125
|
+
tokens: TokenPair;
|
|
126
|
+
user: AuthonUser;
|
|
127
|
+
}>;
|
|
128
|
+
passkeyList(): Promise<PasskeyCredential[]>;
|
|
129
|
+
passkeyDelete(credentialId: string): Promise<void>;
|
|
97
130
|
on<K extends AuthonEventType>(event: K, listener: AuthonEvents[K]): () => void;
|
|
98
131
|
private emit;
|
|
99
132
|
destroy(): void;
|
|
@@ -103,6 +136,7 @@ declare class AuthonMobileClient {
|
|
|
103
136
|
private scheduleRefresh;
|
|
104
137
|
private persistTokens;
|
|
105
138
|
private toTokenPair;
|
|
139
|
+
private requestAuth;
|
|
106
140
|
private request;
|
|
107
141
|
}
|
|
108
142
|
|
|
@@ -147,6 +181,55 @@ declare function useUser(): {
|
|
|
147
181
|
user: AuthonUser | null;
|
|
148
182
|
};
|
|
149
183
|
|
|
184
|
+
interface Web3LinkWalletParams {
|
|
185
|
+
address: string;
|
|
186
|
+
chain: Web3Chain;
|
|
187
|
+
walletType: Web3WalletType;
|
|
188
|
+
chainId?: number;
|
|
189
|
+
message: string;
|
|
190
|
+
signature: string;
|
|
191
|
+
}
|
|
192
|
+
interface UseAuthonWeb3Return {
|
|
193
|
+
getNonce: (address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number) => Promise<Web3NonceResponse | null>;
|
|
194
|
+
verify: (message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType) => Promise<boolean>;
|
|
195
|
+
getWallets: () => Promise<Web3Wallet[] | null>;
|
|
196
|
+
linkWallet: (params: Web3LinkWalletParams) => Promise<Web3Wallet | null>;
|
|
197
|
+
unlinkWallet: (walletId: string) => Promise<boolean>;
|
|
198
|
+
isLoading: boolean;
|
|
199
|
+
error: Error | null;
|
|
200
|
+
}
|
|
201
|
+
declare function useAuthonWeb3(): UseAuthonWeb3Return;
|
|
202
|
+
|
|
203
|
+
interface UseAuthonPasswordlessReturn {
|
|
204
|
+
sendCode: (identifier: string, type?: 'email' | 'sms') => Promise<boolean>;
|
|
205
|
+
verifyCode: (identifier: string, code: string) => Promise<{
|
|
206
|
+
tokens: TokenPair;
|
|
207
|
+
user: AuthonUser;
|
|
208
|
+
} | null>;
|
|
209
|
+
isLoading: boolean;
|
|
210
|
+
error: Error | null;
|
|
211
|
+
}
|
|
212
|
+
declare function useAuthonPasswordless(): UseAuthonPasswordlessReturn;
|
|
213
|
+
|
|
214
|
+
interface UseAuthonPasskeysReturn {
|
|
215
|
+
startRegister: (name?: string) => Promise<{
|
|
216
|
+
options: Record<string, unknown>;
|
|
217
|
+
} | null>;
|
|
218
|
+
completeRegister: (credential: Record<string, unknown>) => Promise<PasskeyCredential | null>;
|
|
219
|
+
startAuth: (email?: string) => Promise<{
|
|
220
|
+
options: Record<string, unknown>;
|
|
221
|
+
} | null>;
|
|
222
|
+
completeAuth: (credential: Record<string, unknown>) => Promise<{
|
|
223
|
+
tokens: TokenPair;
|
|
224
|
+
user: AuthonUser;
|
|
225
|
+
} | null>;
|
|
226
|
+
listPasskeys: () => Promise<PasskeyCredential[] | null>;
|
|
227
|
+
deletePasskey: (credentialId: string) => Promise<boolean>;
|
|
228
|
+
isLoading: boolean;
|
|
229
|
+
error: Error | null;
|
|
230
|
+
}
|
|
231
|
+
declare function useAuthonPasskeys(): UseAuthonPasskeysReturn;
|
|
232
|
+
|
|
150
233
|
interface IconProps {
|
|
151
234
|
size?: number;
|
|
152
235
|
color?: string;
|
|
@@ -197,4 +280,4 @@ interface SocialButtonsProps {
|
|
|
197
280
|
}
|
|
198
281
|
declare function SocialButtons({ onSuccess, onError, style, gap, compact, labels, buttonProps, }: SocialButtonsProps): react_jsx_runtime.JSX.Element | null;
|
|
199
282
|
|
|
200
|
-
export { type AuthState, AuthonContext, type AuthonContextValue, type AuthonEventType, type AuthonEvents, AuthonMobileClient, AuthonProvider, type AuthonReactNativeConfig, type AuthonUser, ProviderIcon, type SignInParams, type SignUpParams, SocialButton, type SocialButtonProps, SocialButtons, type SocialButtonsProps, type TokenPair, useAuthon, useUser };
|
|
283
|
+
export { type AuthState, AuthonContext, type AuthonContextValue, type AuthonEventType, type AuthonEvents, AuthonMobileClient, AuthonProvider, type AuthonReactNativeConfig, type AuthonUser, ProviderIcon, type SignInParams, type SignUpParams, SocialButton, type SocialButtonProps, SocialButtons, type SocialButtonsProps, type TokenPair, type UseAuthonPasskeysReturn, type UseAuthonPasswordlessReturn, type UseAuthonWeb3Return, type Web3LinkWalletParams, useAuthon, useAuthonPasskeys, useAuthonPasswordless, useAuthonWeb3, useUser };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { AuthonUser as AuthonUser$1, OAuthProviderType, BrandingConfig } from '@authon/shared';
|
|
3
|
+
import { AuthonUser as AuthonUser$1, OAuthProviderType, BrandingConfig, Web3Chain, Web3WalletType, Web3NonceResponse, Web3Wallet, PasskeyCredential } from '@authon/shared';
|
|
4
4
|
export { BrandingConfig, OAuthProviderType } from '@authon/shared';
|
|
5
5
|
import { ViewStyle, TextStyle } from 'react-native';
|
|
6
6
|
|
|
@@ -94,6 +94,39 @@ declare class AuthonMobileClient {
|
|
|
94
94
|
user: AuthonUser;
|
|
95
95
|
}>;
|
|
96
96
|
getApiUrl(): string;
|
|
97
|
+
web3GetNonce(address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number): Promise<Web3NonceResponse>;
|
|
98
|
+
web3Verify(message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType): Promise<{
|
|
99
|
+
tokens: TokenPair;
|
|
100
|
+
user: AuthonUser;
|
|
101
|
+
}>;
|
|
102
|
+
web3GetWallets(): Promise<Web3Wallet[]>;
|
|
103
|
+
web3LinkWallet(params: {
|
|
104
|
+
address: string;
|
|
105
|
+
chain: Web3Chain;
|
|
106
|
+
walletType: Web3WalletType;
|
|
107
|
+
chainId?: number;
|
|
108
|
+
message: string;
|
|
109
|
+
signature: string;
|
|
110
|
+
}): Promise<Web3Wallet>;
|
|
111
|
+
web3UnlinkWallet(walletId: string): Promise<void>;
|
|
112
|
+
passwordlessSendCode(identifier: string, type?: 'email' | 'sms'): Promise<void>;
|
|
113
|
+
passwordlessVerifyCode(identifier: string, code: string): Promise<{
|
|
114
|
+
tokens: TokenPair;
|
|
115
|
+
user: AuthonUser;
|
|
116
|
+
}>;
|
|
117
|
+
passkeyStartRegister(name?: string): Promise<{
|
|
118
|
+
options: Record<string, unknown>;
|
|
119
|
+
}>;
|
|
120
|
+
passkeyCompleteRegister(credential: Record<string, unknown>): Promise<PasskeyCredential>;
|
|
121
|
+
passkeyStartAuth(email?: string): Promise<{
|
|
122
|
+
options: Record<string, unknown>;
|
|
123
|
+
}>;
|
|
124
|
+
passkeyCompleteAuth(credential: Record<string, unknown>): Promise<{
|
|
125
|
+
tokens: TokenPair;
|
|
126
|
+
user: AuthonUser;
|
|
127
|
+
}>;
|
|
128
|
+
passkeyList(): Promise<PasskeyCredential[]>;
|
|
129
|
+
passkeyDelete(credentialId: string): Promise<void>;
|
|
97
130
|
on<K extends AuthonEventType>(event: K, listener: AuthonEvents[K]): () => void;
|
|
98
131
|
private emit;
|
|
99
132
|
destroy(): void;
|
|
@@ -103,6 +136,7 @@ declare class AuthonMobileClient {
|
|
|
103
136
|
private scheduleRefresh;
|
|
104
137
|
private persistTokens;
|
|
105
138
|
private toTokenPair;
|
|
139
|
+
private requestAuth;
|
|
106
140
|
private request;
|
|
107
141
|
}
|
|
108
142
|
|
|
@@ -147,6 +181,55 @@ declare function useUser(): {
|
|
|
147
181
|
user: AuthonUser | null;
|
|
148
182
|
};
|
|
149
183
|
|
|
184
|
+
interface Web3LinkWalletParams {
|
|
185
|
+
address: string;
|
|
186
|
+
chain: Web3Chain;
|
|
187
|
+
walletType: Web3WalletType;
|
|
188
|
+
chainId?: number;
|
|
189
|
+
message: string;
|
|
190
|
+
signature: string;
|
|
191
|
+
}
|
|
192
|
+
interface UseAuthonWeb3Return {
|
|
193
|
+
getNonce: (address: string, chain: Web3Chain, walletType: Web3WalletType, chainId?: number) => Promise<Web3NonceResponse | null>;
|
|
194
|
+
verify: (message: string, signature: string, address: string, chain: Web3Chain, walletType: Web3WalletType) => Promise<boolean>;
|
|
195
|
+
getWallets: () => Promise<Web3Wallet[] | null>;
|
|
196
|
+
linkWallet: (params: Web3LinkWalletParams) => Promise<Web3Wallet | null>;
|
|
197
|
+
unlinkWallet: (walletId: string) => Promise<boolean>;
|
|
198
|
+
isLoading: boolean;
|
|
199
|
+
error: Error | null;
|
|
200
|
+
}
|
|
201
|
+
declare function useAuthonWeb3(): UseAuthonWeb3Return;
|
|
202
|
+
|
|
203
|
+
interface UseAuthonPasswordlessReturn {
|
|
204
|
+
sendCode: (identifier: string, type?: 'email' | 'sms') => Promise<boolean>;
|
|
205
|
+
verifyCode: (identifier: string, code: string) => Promise<{
|
|
206
|
+
tokens: TokenPair;
|
|
207
|
+
user: AuthonUser;
|
|
208
|
+
} | null>;
|
|
209
|
+
isLoading: boolean;
|
|
210
|
+
error: Error | null;
|
|
211
|
+
}
|
|
212
|
+
declare function useAuthonPasswordless(): UseAuthonPasswordlessReturn;
|
|
213
|
+
|
|
214
|
+
interface UseAuthonPasskeysReturn {
|
|
215
|
+
startRegister: (name?: string) => Promise<{
|
|
216
|
+
options: Record<string, unknown>;
|
|
217
|
+
} | null>;
|
|
218
|
+
completeRegister: (credential: Record<string, unknown>) => Promise<PasskeyCredential | null>;
|
|
219
|
+
startAuth: (email?: string) => Promise<{
|
|
220
|
+
options: Record<string, unknown>;
|
|
221
|
+
} | null>;
|
|
222
|
+
completeAuth: (credential: Record<string, unknown>) => Promise<{
|
|
223
|
+
tokens: TokenPair;
|
|
224
|
+
user: AuthonUser;
|
|
225
|
+
} | null>;
|
|
226
|
+
listPasskeys: () => Promise<PasskeyCredential[] | null>;
|
|
227
|
+
deletePasskey: (credentialId: string) => Promise<boolean>;
|
|
228
|
+
isLoading: boolean;
|
|
229
|
+
error: Error | null;
|
|
230
|
+
}
|
|
231
|
+
declare function useAuthonPasskeys(): UseAuthonPasskeysReturn;
|
|
232
|
+
|
|
150
233
|
interface IconProps {
|
|
151
234
|
size?: number;
|
|
152
235
|
color?: string;
|
|
@@ -197,4 +280,4 @@ interface SocialButtonsProps {
|
|
|
197
280
|
}
|
|
198
281
|
declare function SocialButtons({ onSuccess, onError, style, gap, compact, labels, buttonProps, }: SocialButtonsProps): react_jsx_runtime.JSX.Element | null;
|
|
199
282
|
|
|
200
|
-
export { type AuthState, AuthonContext, type AuthonContextValue, type AuthonEventType, type AuthonEvents, AuthonMobileClient, AuthonProvider, type AuthonReactNativeConfig, type AuthonUser, ProviderIcon, type SignInParams, type SignUpParams, SocialButton, type SocialButtonProps, SocialButtons, type SocialButtonsProps, type TokenPair, useAuthon, useUser };
|
|
283
|
+
export { type AuthState, AuthonContext, type AuthonContextValue, type AuthonEventType, type AuthonEvents, AuthonMobileClient, AuthonProvider, type AuthonReactNativeConfig, type AuthonUser, ProviderIcon, type SignInParams, type SignUpParams, SocialButton, type SocialButtonProps, SocialButtons, type SocialButtonsProps, type TokenPair, type UseAuthonPasskeysReturn, type UseAuthonPasswordlessReturn, type UseAuthonWeb3Return, type Web3LinkWalletParams, useAuthon, useAuthonPasskeys, useAuthonPasswordless, useAuthonWeb3, useUser };
|
package/dist/index.js
CHANGED
|
@@ -184,6 +184,100 @@ var AuthonMobileClient = class {
|
|
|
184
184
|
getApiUrl() {
|
|
185
185
|
return this.apiUrl;
|
|
186
186
|
}
|
|
187
|
+
// ── Web3 ──
|
|
188
|
+
async web3GetNonce(address, chain, walletType, chainId) {
|
|
189
|
+
return this.request("POST", "/v1/auth/web3/nonce", {
|
|
190
|
+
address,
|
|
191
|
+
chain,
|
|
192
|
+
walletType,
|
|
193
|
+
...chainId != null ? { chainId } : {}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
async web3Verify(message, signature, address, chain, walletType) {
|
|
197
|
+
const res = await this.request("POST", "/v1/auth/web3/verify", {
|
|
198
|
+
message,
|
|
199
|
+
signature,
|
|
200
|
+
address,
|
|
201
|
+
chain,
|
|
202
|
+
walletType
|
|
203
|
+
});
|
|
204
|
+
this.tokens = this.toTokenPair(res);
|
|
205
|
+
this.user = res.user;
|
|
206
|
+
await this.persistTokens();
|
|
207
|
+
this.scheduleRefresh(this.tokens.expiresAt);
|
|
208
|
+
this.emit("signedIn", res.user);
|
|
209
|
+
return { tokens: this.tokens, user: res.user };
|
|
210
|
+
}
|
|
211
|
+
async web3GetWallets() {
|
|
212
|
+
return this.request("GET", "/v1/auth/web3/wallets");
|
|
213
|
+
}
|
|
214
|
+
async web3LinkWallet(params) {
|
|
215
|
+
return this.request("POST", "/v1/auth/web3/wallets/link", params);
|
|
216
|
+
}
|
|
217
|
+
async web3UnlinkWallet(walletId) {
|
|
218
|
+
await this.requestAuth("DELETE", `/v1/auth/web3/wallets/${walletId}`);
|
|
219
|
+
}
|
|
220
|
+
// ── Passwordless ──
|
|
221
|
+
async passwordlessSendCode(identifier, type = "email") {
|
|
222
|
+
if (type === "sms") {
|
|
223
|
+
await this.request("POST", "/v1/auth/passwordless/sms-otp", { phone: identifier });
|
|
224
|
+
} else {
|
|
225
|
+
await this.request("POST", "/v1/auth/passwordless/email-otp", { email: identifier });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
async passwordlessVerifyCode(identifier, code) {
|
|
229
|
+
const res = await this.request("POST", "/v1/auth/passwordless/verify", {
|
|
230
|
+
email: identifier,
|
|
231
|
+
code
|
|
232
|
+
});
|
|
233
|
+
this.tokens = this.toTokenPair(res);
|
|
234
|
+
this.user = res.user;
|
|
235
|
+
await this.persistTokens();
|
|
236
|
+
this.scheduleRefresh(this.tokens.expiresAt);
|
|
237
|
+
this.emit("signedIn", res.user);
|
|
238
|
+
return { tokens: this.tokens, user: res.user };
|
|
239
|
+
}
|
|
240
|
+
// ── Passkeys ──
|
|
241
|
+
async passkeyStartRegister(name) {
|
|
242
|
+
return this.requestAuth(
|
|
243
|
+
"POST",
|
|
244
|
+
"/v1/auth/passkeys/register/options",
|
|
245
|
+
name ? { name } : void 0
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
async passkeyCompleteRegister(credential) {
|
|
249
|
+
return this.requestAuth(
|
|
250
|
+
"POST",
|
|
251
|
+
"/v1/auth/passkeys/register/verify",
|
|
252
|
+
credential
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
async passkeyStartAuth(email) {
|
|
256
|
+
return this.request(
|
|
257
|
+
"POST",
|
|
258
|
+
"/v1/auth/passkeys/authenticate/options",
|
|
259
|
+
email ? { email } : void 0
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
async passkeyCompleteAuth(credential) {
|
|
263
|
+
const res = await this.request(
|
|
264
|
+
"POST",
|
|
265
|
+
"/v1/auth/passkeys/authenticate/verify",
|
|
266
|
+
credential
|
|
267
|
+
);
|
|
268
|
+
this.tokens = this.toTokenPair(res);
|
|
269
|
+
this.user = res.user;
|
|
270
|
+
await this.persistTokens();
|
|
271
|
+
this.scheduleRefresh(this.tokens.expiresAt);
|
|
272
|
+
this.emit("signedIn", res.user);
|
|
273
|
+
return { tokens: this.tokens, user: res.user };
|
|
274
|
+
}
|
|
275
|
+
async passkeyList() {
|
|
276
|
+
return this.requestAuth("GET", "/v1/auth/passkeys");
|
|
277
|
+
}
|
|
278
|
+
async passkeyDelete(credentialId) {
|
|
279
|
+
await this.requestAuth("DELETE", `/v1/auth/passkeys/${credentialId}`);
|
|
280
|
+
}
|
|
187
281
|
// ── Event system ──
|
|
188
282
|
on(event, listener) {
|
|
189
283
|
if (!this.listeners.has(event)) this.listeners.set(event, /* @__PURE__ */ new Set());
|
|
@@ -236,6 +330,10 @@ var AuthonMobileClient = class {
|
|
|
236
330
|
expiresAt: Date.now() + res.expiresIn * 1e3
|
|
237
331
|
};
|
|
238
332
|
}
|
|
333
|
+
async requestAuth(method, path, body) {
|
|
334
|
+
if (!this.tokens?.accessToken) throw new Error("Must be signed in");
|
|
335
|
+
return this.request(method, path, body);
|
|
336
|
+
}
|
|
239
337
|
async request(method, path, body) {
|
|
240
338
|
const headers = {
|
|
241
339
|
"Content-Type": "application/json",
|
|
@@ -418,6 +516,160 @@ function useUser() {
|
|
|
418
516
|
return { isLoaded, isSignedIn, user };
|
|
419
517
|
}
|
|
420
518
|
|
|
519
|
+
// src/useAuthonWeb3.ts
|
|
520
|
+
import { useCallback as useCallback2, useContext as useContext2, useState as useState2 } from "react";
|
|
521
|
+
function useAuthonWeb3() {
|
|
522
|
+
const ctx = useContext2(AuthonContext);
|
|
523
|
+
if (!ctx) throw new Error("useAuthonWeb3 must be used within <AuthonProvider>");
|
|
524
|
+
const [isLoading, setIsLoading] = useState2(false);
|
|
525
|
+
const [error, setError] = useState2(null);
|
|
526
|
+
const wrap = useCallback2(async (fn) => {
|
|
527
|
+
setIsLoading(true);
|
|
528
|
+
setError(null);
|
|
529
|
+
try {
|
|
530
|
+
return await fn();
|
|
531
|
+
} catch (err) {
|
|
532
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
533
|
+
return null;
|
|
534
|
+
} finally {
|
|
535
|
+
setIsLoading(false);
|
|
536
|
+
}
|
|
537
|
+
}, []);
|
|
538
|
+
const getNonce = useCallback2(
|
|
539
|
+
(address, chain, walletType, chainId) => wrap(() => ctx.client.web3GetNonce(address, chain, walletType, chainId)),
|
|
540
|
+
[ctx.client, wrap]
|
|
541
|
+
);
|
|
542
|
+
const verify = useCallback2(
|
|
543
|
+
async (message, signature, address, chain, walletType) => {
|
|
544
|
+
const result = await wrap(
|
|
545
|
+
() => ctx.client.web3Verify(message, signature, address, chain, walletType)
|
|
546
|
+
);
|
|
547
|
+
return result !== null;
|
|
548
|
+
},
|
|
549
|
+
[ctx.client, wrap]
|
|
550
|
+
);
|
|
551
|
+
const getWallets = useCallback2(
|
|
552
|
+
() => wrap(() => ctx.client.web3GetWallets()),
|
|
553
|
+
[ctx.client, wrap]
|
|
554
|
+
);
|
|
555
|
+
const linkWallet = useCallback2(
|
|
556
|
+
(params) => wrap(() => ctx.client.web3LinkWallet(params)),
|
|
557
|
+
[ctx.client, wrap]
|
|
558
|
+
);
|
|
559
|
+
const unlinkWallet = useCallback2(
|
|
560
|
+
async (walletId) => {
|
|
561
|
+
const result = await wrap(() => ctx.client.web3UnlinkWallet(walletId));
|
|
562
|
+
return result !== null;
|
|
563
|
+
},
|
|
564
|
+
[ctx.client, wrap]
|
|
565
|
+
);
|
|
566
|
+
return {
|
|
567
|
+
getNonce,
|
|
568
|
+
verify,
|
|
569
|
+
getWallets,
|
|
570
|
+
linkWallet,
|
|
571
|
+
unlinkWallet,
|
|
572
|
+
isLoading,
|
|
573
|
+
error
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
// src/useAuthonPasswordless.ts
|
|
578
|
+
import { useCallback as useCallback3, useContext as useContext3, useState as useState3 } from "react";
|
|
579
|
+
function useAuthonPasswordless() {
|
|
580
|
+
const ctx = useContext3(AuthonContext);
|
|
581
|
+
if (!ctx) throw new Error("useAuthonPasswordless must be used within <AuthonProvider>");
|
|
582
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
583
|
+
const [error, setError] = useState3(null);
|
|
584
|
+
const wrap = useCallback3(async (fn) => {
|
|
585
|
+
setIsLoading(true);
|
|
586
|
+
setError(null);
|
|
587
|
+
try {
|
|
588
|
+
return await fn();
|
|
589
|
+
} catch (err) {
|
|
590
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
591
|
+
return null;
|
|
592
|
+
} finally {
|
|
593
|
+
setIsLoading(false);
|
|
594
|
+
}
|
|
595
|
+
}, []);
|
|
596
|
+
const sendCode = useCallback3(
|
|
597
|
+
async (identifier, type = "email") => {
|
|
598
|
+
const result = await wrap(() => ctx.client.passwordlessSendCode(identifier, type));
|
|
599
|
+
return result !== null;
|
|
600
|
+
},
|
|
601
|
+
[ctx.client, wrap]
|
|
602
|
+
);
|
|
603
|
+
const verifyCode = useCallback3(
|
|
604
|
+
(identifier, code) => wrap(() => ctx.client.passwordlessVerifyCode(identifier, code)),
|
|
605
|
+
[ctx.client, wrap]
|
|
606
|
+
);
|
|
607
|
+
return {
|
|
608
|
+
sendCode,
|
|
609
|
+
verifyCode,
|
|
610
|
+
isLoading,
|
|
611
|
+
error
|
|
612
|
+
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/useAuthonPasskeys.ts
|
|
616
|
+
import { useCallback as useCallback4, useContext as useContext4, useState as useState4 } from "react";
|
|
617
|
+
function useAuthonPasskeys() {
|
|
618
|
+
const ctx = useContext4(AuthonContext);
|
|
619
|
+
if (!ctx) throw new Error("useAuthonPasskeys must be used within <AuthonProvider>");
|
|
620
|
+
const [isLoading, setIsLoading] = useState4(false);
|
|
621
|
+
const [error, setError] = useState4(null);
|
|
622
|
+
const wrap = useCallback4(async (fn) => {
|
|
623
|
+
setIsLoading(true);
|
|
624
|
+
setError(null);
|
|
625
|
+
try {
|
|
626
|
+
return await fn();
|
|
627
|
+
} catch (err) {
|
|
628
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
629
|
+
return null;
|
|
630
|
+
} finally {
|
|
631
|
+
setIsLoading(false);
|
|
632
|
+
}
|
|
633
|
+
}, []);
|
|
634
|
+
const startRegister = useCallback4(
|
|
635
|
+
(name) => wrap(() => ctx.client.passkeyStartRegister(name)),
|
|
636
|
+
[ctx.client, wrap]
|
|
637
|
+
);
|
|
638
|
+
const completeRegister = useCallback4(
|
|
639
|
+
(credential) => wrap(() => ctx.client.passkeyCompleteRegister(credential)),
|
|
640
|
+
[ctx.client, wrap]
|
|
641
|
+
);
|
|
642
|
+
const startAuth = useCallback4(
|
|
643
|
+
(email) => wrap(() => ctx.client.passkeyStartAuth(email)),
|
|
644
|
+
[ctx.client, wrap]
|
|
645
|
+
);
|
|
646
|
+
const completeAuth = useCallback4(
|
|
647
|
+
(credential) => wrap(() => ctx.client.passkeyCompleteAuth(credential)),
|
|
648
|
+
[ctx.client, wrap]
|
|
649
|
+
);
|
|
650
|
+
const listPasskeys = useCallback4(
|
|
651
|
+
() => wrap(() => ctx.client.passkeyList()),
|
|
652
|
+
[ctx.client, wrap]
|
|
653
|
+
);
|
|
654
|
+
const deletePasskey = useCallback4(
|
|
655
|
+
async (credentialId) => {
|
|
656
|
+
const result = await wrap(() => ctx.client.passkeyDelete(credentialId));
|
|
657
|
+
return result !== null;
|
|
658
|
+
},
|
|
659
|
+
[ctx.client, wrap]
|
|
660
|
+
);
|
|
661
|
+
return {
|
|
662
|
+
startRegister,
|
|
663
|
+
completeRegister,
|
|
664
|
+
startAuth,
|
|
665
|
+
completeAuth,
|
|
666
|
+
listPasskeys,
|
|
667
|
+
deletePasskey,
|
|
668
|
+
isLoading,
|
|
669
|
+
error
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
|
|
421
673
|
// src/icons.tsx
|
|
422
674
|
import "react";
|
|
423
675
|
import Svg, { Path, Rect } from "react-native-svg";
|
|
@@ -588,7 +840,7 @@ var styles = StyleSheet.create({
|
|
|
588
840
|
});
|
|
589
841
|
|
|
590
842
|
// src/SocialButtons.tsx
|
|
591
|
-
import { useState as
|
|
843
|
+
import { useState as useState5 } from "react";
|
|
592
844
|
import { View, StyleSheet as StyleSheet2, Linking } from "react-native";
|
|
593
845
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
594
846
|
function SocialButtons({
|
|
@@ -601,7 +853,7 @@ function SocialButtons({
|
|
|
601
853
|
buttonProps
|
|
602
854
|
}) {
|
|
603
855
|
const { providers, startOAuth, completeOAuth } = useAuthon();
|
|
604
|
-
const [loadingProvider, setLoadingProvider] =
|
|
856
|
+
const [loadingProvider, setLoadingProvider] = useState5(null);
|
|
605
857
|
if (providers.length === 0) return null;
|
|
606
858
|
const resolvedGap = gap ?? (compact ? 12 : 10);
|
|
607
859
|
const handlePress = async (provider) => {
|
|
@@ -660,6 +912,9 @@ export {
|
|
|
660
912
|
SocialButton,
|
|
661
913
|
SocialButtons,
|
|
662
914
|
useAuthon,
|
|
915
|
+
useAuthonPasskeys,
|
|
916
|
+
useAuthonPasswordless,
|
|
917
|
+
useAuthonWeb3,
|
|
663
918
|
useUser
|
|
664
919
|
};
|
|
665
920
|
//# sourceMappingURL=index.js.map
|