@volr/react 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/dist/index.cjs +112 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -8
- package/dist/index.d.ts +13 -8
- package/dist/index.js +112 -20
- package/dist/index.js.map +1 -1
- package/package.json +2 -3
package/dist/index.d.cts
CHANGED
|
@@ -189,7 +189,6 @@ interface VolrUser {
|
|
|
189
189
|
* Volr configuration
|
|
190
190
|
*/
|
|
191
191
|
type VolrConfig = {
|
|
192
|
-
apiBaseUrl: string;
|
|
193
192
|
defaultChainId: number;
|
|
194
193
|
projectApiKey: string;
|
|
195
194
|
rpcOverrides?: Record<string, string>;
|
|
@@ -201,12 +200,6 @@ type VolrConfig = {
|
|
|
201
200
|
* Deposit/Topup configuration for multi-chain, multi-token support
|
|
202
201
|
*/
|
|
203
202
|
deposit?: DepositConfig;
|
|
204
|
-
/**
|
|
205
|
-
* @internal 개발용: API Base URL 오버라이드
|
|
206
|
-
* 일반 사용자는 타입 체크로 접근 불가
|
|
207
|
-
* 개발 시에는 @ts-expect-error 주석 필요
|
|
208
|
-
*/
|
|
209
|
-
__devApiBaseUrl?: string;
|
|
210
203
|
};
|
|
211
204
|
/**
|
|
212
205
|
* Public context value
|
|
@@ -482,6 +475,18 @@ interface UseVolrLoginReturn {
|
|
|
482
475
|
*/
|
|
483
476
|
declare function useVolrLogin(): UseVolrLoginReturn;
|
|
484
477
|
|
|
478
|
+
interface UseVolrAuthCallbackOptions {
|
|
479
|
+
onSuccess?: (user: VolrUser) => void;
|
|
480
|
+
onError?: (error: string) => void;
|
|
481
|
+
}
|
|
482
|
+
interface UseVolrAuthCallbackReturn {
|
|
483
|
+
isLoading: boolean;
|
|
484
|
+
error: string | null;
|
|
485
|
+
isNewUser: boolean;
|
|
486
|
+
user: VolrUser | null;
|
|
487
|
+
}
|
|
488
|
+
declare function useVolrAuthCallback(options?: UseVolrAuthCallbackOptions): UseVolrAuthCallbackReturn;
|
|
489
|
+
|
|
485
490
|
type Erc20Token = {
|
|
486
491
|
address: `0x${string}`;
|
|
487
492
|
decimals: number;
|
|
@@ -637,4 +642,4 @@ declare function normalizeHex(value: `0x${string}` | string): `0x${string}`;
|
|
|
637
642
|
*/
|
|
638
643
|
declare function normalizeHexArray(values: (`0x${string}` | string)[]): `0x${string}`[];
|
|
639
644
|
|
|
640
|
-
export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrLogin, useVolrWallet };
|
|
645
|
+
export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrAuthCallback, useVolrLogin, useVolrWallet };
|
package/dist/index.d.ts
CHANGED
|
@@ -189,7 +189,6 @@ interface VolrUser {
|
|
|
189
189
|
* Volr configuration
|
|
190
190
|
*/
|
|
191
191
|
type VolrConfig = {
|
|
192
|
-
apiBaseUrl: string;
|
|
193
192
|
defaultChainId: number;
|
|
194
193
|
projectApiKey: string;
|
|
195
194
|
rpcOverrides?: Record<string, string>;
|
|
@@ -201,12 +200,6 @@ type VolrConfig = {
|
|
|
201
200
|
* Deposit/Topup configuration for multi-chain, multi-token support
|
|
202
201
|
*/
|
|
203
202
|
deposit?: DepositConfig;
|
|
204
|
-
/**
|
|
205
|
-
* @internal 개발용: API Base URL 오버라이드
|
|
206
|
-
* 일반 사용자는 타입 체크로 접근 불가
|
|
207
|
-
* 개발 시에는 @ts-expect-error 주석 필요
|
|
208
|
-
*/
|
|
209
|
-
__devApiBaseUrl?: string;
|
|
210
203
|
};
|
|
211
204
|
/**
|
|
212
205
|
* Public context value
|
|
@@ -482,6 +475,18 @@ interface UseVolrLoginReturn {
|
|
|
482
475
|
*/
|
|
483
476
|
declare function useVolrLogin(): UseVolrLoginReturn;
|
|
484
477
|
|
|
478
|
+
interface UseVolrAuthCallbackOptions {
|
|
479
|
+
onSuccess?: (user: VolrUser) => void;
|
|
480
|
+
onError?: (error: string) => void;
|
|
481
|
+
}
|
|
482
|
+
interface UseVolrAuthCallbackReturn {
|
|
483
|
+
isLoading: boolean;
|
|
484
|
+
error: string | null;
|
|
485
|
+
isNewUser: boolean;
|
|
486
|
+
user: VolrUser | null;
|
|
487
|
+
}
|
|
488
|
+
declare function useVolrAuthCallback(options?: UseVolrAuthCallbackOptions): UseVolrAuthCallbackReturn;
|
|
489
|
+
|
|
485
490
|
type Erc20Token = {
|
|
486
491
|
address: `0x${string}`;
|
|
487
492
|
decimals: number;
|
|
@@ -637,4 +642,4 @@ declare function normalizeHex(value: `0x${string}` | string): `0x${string}`;
|
|
|
637
642
|
*/
|
|
638
643
|
declare function normalizeHexArray(values: (`0x${string}` | string)[]): `0x${string}`[];
|
|
639
644
|
|
|
640
|
-
export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrLogin, useVolrWallet };
|
|
645
|
+
export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type Erc20Token$1 as Erc20Token, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, type PrfInputDto, type SendTxOptions, type SignerType, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UsePrecheckReturn, type UseRelayReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, type UseVolrWalletReturn, type UserDto, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrAuthCallback, useVolrLogin, useVolrWallet };
|
package/dist/index.js
CHANGED
|
@@ -69,7 +69,7 @@ var safeStorage = {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
//
|
|
72
|
+
// ../shared/src/constants/storage.ts
|
|
73
73
|
var STORAGE_KEYS = {
|
|
74
74
|
accessToken: "volr:accessToken",
|
|
75
75
|
user: "volr:user",
|
|
@@ -345,6 +345,17 @@ var SessionSync = class {
|
|
|
345
345
|
}
|
|
346
346
|
};
|
|
347
347
|
|
|
348
|
+
// src/config/backend.ts
|
|
349
|
+
var DEFAULT_API_BASE_URL = "https://api.volr.io";
|
|
350
|
+
function resolveApiBaseUrl(config) {
|
|
351
|
+
const anyConfig = config;
|
|
352
|
+
const override = anyConfig.apiBaseUrl;
|
|
353
|
+
if (override && typeof override === "string") {
|
|
354
|
+
return override.replace(/\/+$/, "");
|
|
355
|
+
}
|
|
356
|
+
return DEFAULT_API_BASE_URL;
|
|
357
|
+
}
|
|
358
|
+
|
|
348
359
|
// src/config/webauthn.ts
|
|
349
360
|
var AUTHENTICATOR_SELECTION = {
|
|
350
361
|
authenticatorAttachment: "platform",
|
|
@@ -644,18 +655,18 @@ function VolrProvider({ config, children }) {
|
|
|
644
655
|
providerCountRef.current--;
|
|
645
656
|
};
|
|
646
657
|
}, []);
|
|
658
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
647
659
|
const client = useMemo(() => {
|
|
648
660
|
if (!config.projectApiKey) {
|
|
649
661
|
throw new Error(
|
|
650
662
|
"VolrProvider requires config.projectApiKey. Please set VITE_PROJECT_API_KEY environment variable or provide projectApiKey in config."
|
|
651
663
|
);
|
|
652
664
|
}
|
|
653
|
-
const baseUrl = config.__devApiBaseUrl || config.apiBaseUrl;
|
|
654
665
|
return new APIClient({
|
|
655
|
-
baseUrl,
|
|
666
|
+
baseUrl: apiBaseUrl,
|
|
656
667
|
apiKey: config.projectApiKey
|
|
657
668
|
});
|
|
658
|
-
}, [
|
|
669
|
+
}, [apiBaseUrl, config.projectApiKey]);
|
|
659
670
|
const [user, setUser] = useState(() => {
|
|
660
671
|
if (typeof window === "undefined") return null;
|
|
661
672
|
const userStr = safeStorage.getItem(STORAGE_KEYS.user);
|
|
@@ -1860,9 +1871,10 @@ function useVolrLogin() {
|
|
|
1860
1871
|
credentialId: u.credentialId ?? void 0
|
|
1861
1872
|
};
|
|
1862
1873
|
}, []);
|
|
1874
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
1863
1875
|
const api = useMemo(
|
|
1864
|
-
() => createAxiosInstance(
|
|
1865
|
-
[
|
|
1876
|
+
() => createAxiosInstance(apiBaseUrl, config.projectApiKey),
|
|
1877
|
+
[apiBaseUrl, config.projectApiKey]
|
|
1866
1878
|
);
|
|
1867
1879
|
const requestEmailCode = useCallback(
|
|
1868
1880
|
async (email) => {
|
|
@@ -1930,11 +1942,11 @@ function useVolrLogin() {
|
|
|
1930
1942
|
const handleSocialLogin = useCallback(
|
|
1931
1943
|
async (provider) => {
|
|
1932
1944
|
if (typeof window !== "undefined") {
|
|
1933
|
-
const baseUrl =
|
|
1945
|
+
const baseUrl = apiBaseUrl.replace(/\/+$/, "");
|
|
1934
1946
|
window.location.href = `${baseUrl}/auth/${provider}`;
|
|
1935
1947
|
}
|
|
1936
1948
|
},
|
|
1937
|
-
[
|
|
1949
|
+
[apiBaseUrl]
|
|
1938
1950
|
);
|
|
1939
1951
|
const requestSiweNonce = useCallback(async () => {
|
|
1940
1952
|
const response = await api.get("/auth/siwe/nonce");
|
|
@@ -2006,6 +2018,91 @@ function useVolrLogin() {
|
|
|
2006
2018
|
handlePasskeyComplete
|
|
2007
2019
|
};
|
|
2008
2020
|
}
|
|
2021
|
+
function useVolrAuthCallback(options = {}) {
|
|
2022
|
+
const { config, setUser } = useVolr();
|
|
2023
|
+
const { refreshAccessToken, setAccessToken } = useInternalAuth();
|
|
2024
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
2025
|
+
const [error, setError] = useState(null);
|
|
2026
|
+
const [isNewUser, setIsNewUser] = useState(false);
|
|
2027
|
+
const [user, setLocalUser] = useState(null);
|
|
2028
|
+
const toVolrUser = useCallback((u) => {
|
|
2029
|
+
return {
|
|
2030
|
+
id: u.id,
|
|
2031
|
+
email: u.email,
|
|
2032
|
+
accountId: u.accountId ?? void 0,
|
|
2033
|
+
evmAddress: u.evmAddress,
|
|
2034
|
+
keyStorageType: u.keyStorageType ?? void 0,
|
|
2035
|
+
signerType: u.signerType ?? void 0,
|
|
2036
|
+
walletConnector: u.walletConnector ?? void 0,
|
|
2037
|
+
lastWalletChainId: u.lastWalletChainId ?? void 0,
|
|
2038
|
+
blobUrl: u.blobUrl ?? void 0,
|
|
2039
|
+
prfInput: u.prfInput ?? void 0,
|
|
2040
|
+
credentialId: u.credentialId ?? void 0
|
|
2041
|
+
};
|
|
2042
|
+
}, []);
|
|
2043
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
2044
|
+
useEffect(() => {
|
|
2045
|
+
const handleCallback = async () => {
|
|
2046
|
+
if (typeof window === "undefined") return;
|
|
2047
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
2048
|
+
const success = searchParams.get("success");
|
|
2049
|
+
const errorParam = searchParams.get("error");
|
|
2050
|
+
const userId = searchParams.get("userId");
|
|
2051
|
+
const isNew = searchParams.get("isNewUser") === "true";
|
|
2052
|
+
if (errorParam) {
|
|
2053
|
+
const errorMsg = `Authentication failed: ${errorParam}`;
|
|
2054
|
+
setError(errorMsg);
|
|
2055
|
+
setIsLoading(false);
|
|
2056
|
+
options.onError?.(errorMsg);
|
|
2057
|
+
return;
|
|
2058
|
+
}
|
|
2059
|
+
if (success !== "true" || !userId) {
|
|
2060
|
+
const errorMsg = "Invalid callback parameters";
|
|
2061
|
+
setError(errorMsg);
|
|
2062
|
+
setIsLoading(false);
|
|
2063
|
+
options.onError?.(errorMsg);
|
|
2064
|
+
return;
|
|
2065
|
+
}
|
|
2066
|
+
try {
|
|
2067
|
+
setIsNewUser(isNew);
|
|
2068
|
+
await refreshAccessToken();
|
|
2069
|
+
const api = createAxiosInstance(
|
|
2070
|
+
apiBaseUrl,
|
|
2071
|
+
config.projectApiKey
|
|
2072
|
+
);
|
|
2073
|
+
const userRes = await api.get(`/auth/onboarding/${userId}`);
|
|
2074
|
+
if (!userRes.data?.ok) {
|
|
2075
|
+
throw new Error("Failed to fetch user details");
|
|
2076
|
+
}
|
|
2077
|
+
const refreshRes = await api.post("/auth/refresh");
|
|
2078
|
+
if (!refreshRes.data?.ok) {
|
|
2079
|
+
throw new Error("Failed to refresh session");
|
|
2080
|
+
}
|
|
2081
|
+
const userData = refreshRes.data.data.user;
|
|
2082
|
+
const accessToken = refreshRes.data.data.accessToken;
|
|
2083
|
+
setAccessToken(accessToken);
|
|
2084
|
+
const volrUser = toVolrUser(userData);
|
|
2085
|
+
setUser(volrUser);
|
|
2086
|
+
setLocalUser(volrUser);
|
|
2087
|
+
setIsLoading(false);
|
|
2088
|
+
options.onSuccess?.(volrUser);
|
|
2089
|
+
} catch (err) {
|
|
2090
|
+
console.error("Callback error:", err);
|
|
2091
|
+
const errorMsg = err.message || "Failed to complete authentication";
|
|
2092
|
+
setError(errorMsg);
|
|
2093
|
+
setIsLoading(false);
|
|
2094
|
+
options.onError?.(errorMsg);
|
|
2095
|
+
}
|
|
2096
|
+
};
|
|
2097
|
+
handleCallback();
|
|
2098
|
+
}, [apiBaseUrl, config.projectApiKey, refreshAccessToken, setAccessToken, setUser, toVolrUser]);
|
|
2099
|
+
return {
|
|
2100
|
+
isLoading,
|
|
2101
|
+
error,
|
|
2102
|
+
isNewUser,
|
|
2103
|
+
user
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2009
2106
|
async function jsonRpc(rpcUrl, method, params) {
|
|
2010
2107
|
const payload = {
|
|
2011
2108
|
jsonrpc: "2.0",
|
|
@@ -2299,6 +2396,7 @@ function usePasskeyEnrollment() {
|
|
|
2299
2396
|
const [isEnrolling, setIsEnrolling] = useState(false);
|
|
2300
2397
|
const [error, setError] = useState(null);
|
|
2301
2398
|
const isEnrollingRef = useRef(false);
|
|
2399
|
+
const apiBaseUrl = resolveApiBaseUrl(config);
|
|
2302
2400
|
const enroll = useCallback(async () => {
|
|
2303
2401
|
if (isEnrollingRef.current || isEnrolling) return;
|
|
2304
2402
|
isEnrollingRef.current = true;
|
|
@@ -2314,13 +2412,15 @@ function usePasskeyEnrollment() {
|
|
|
2314
2412
|
}
|
|
2315
2413
|
const accessToken = client.getAccessToken();
|
|
2316
2414
|
if (!accessToken) {
|
|
2317
|
-
throw new Error(
|
|
2415
|
+
throw new Error(
|
|
2416
|
+
"Access token is required for passkey enrollment. Please login first."
|
|
2417
|
+
);
|
|
2318
2418
|
}
|
|
2319
2419
|
const projectId = user.id;
|
|
2320
2420
|
setStep("encrypting");
|
|
2321
2421
|
const result = await enrollPasskey({
|
|
2322
2422
|
client,
|
|
2323
|
-
baseUrl:
|
|
2423
|
+
baseUrl: apiBaseUrl,
|
|
2324
2424
|
apiKey: config.projectApiKey,
|
|
2325
2425
|
userId: user.id,
|
|
2326
2426
|
userEmail: user.email,
|
|
@@ -2365,15 +2465,7 @@ function usePasskeyEnrollment() {
|
|
|
2365
2465
|
setIsEnrolling(false);
|
|
2366
2466
|
isEnrollingRef.current = false;
|
|
2367
2467
|
}
|
|
2368
|
-
}, [
|
|
2369
|
-
client,
|
|
2370
|
-
config.apiBaseUrl,
|
|
2371
|
-
config.projectApiKey,
|
|
2372
|
-
user,
|
|
2373
|
-
setProvider,
|
|
2374
|
-
setUser,
|
|
2375
|
-
isEnrolling
|
|
2376
|
-
]);
|
|
2468
|
+
}, [apiBaseUrl, client, config.projectApiKey, user, setProvider, setUser, isEnrolling]);
|
|
2377
2469
|
return {
|
|
2378
2470
|
enroll,
|
|
2379
2471
|
step,
|
|
@@ -2554,6 +2646,6 @@ async function uploadBlobViaPresign(params) {
|
|
|
2554
2646
|
return { s3Key };
|
|
2555
2647
|
}
|
|
2556
2648
|
|
|
2557
|
-
export { DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, VolrProvider, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrLogin, useVolrWallet };
|
|
2649
|
+
export { DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, VolrProvider, buildCall, buildCalls, createGetNetworkInfo, createPasskeyAdapter, defaultIdempotencyKey, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, usePrecheck, useRelay, useVolr, useVolrAuthCallback, useVolrLogin, useVolrWallet };
|
|
2558
2650
|
//# sourceMappingURL=index.js.map
|
|
2559
2651
|
//# sourceMappingURL=index.js.map
|