@volr/react 0.1.89 → 0.1.91

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/index.d.cts CHANGED
@@ -96,9 +96,11 @@ declare class APIClient {
96
96
  /**
97
97
  * PRF Input DTO
98
98
  * Input parameters for WebAuthn PRF extension
99
+ *
100
+ * Note: origin is NOT included for cross-domain wallet support.
101
+ * WebAuthn's rpId binding provides domain security.
99
102
  */
100
103
  interface PrfInputDto {
101
- origin: string;
102
104
  projectId: string;
103
105
  credentialId: string;
104
106
  salt?: Uint8Array;
@@ -999,4 +1001,140 @@ declare function getPasskeyAuthGuidance(passkeyPlatform?: string | null): string
999
1001
  */
1000
1002
  declare function checkPrfExtensionAvailable(): Promise<boolean>;
1001
1003
 
1002
- export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, type ContractAnalysisResult, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type ERC20BalanceComparison, type Erc20Token$1 as Erc20Token, type EvmClient, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, PasskeyNotFoundError, type PlatformCheckResult, type PrfInputDto, PrfNotSupportedError, type SendBatchOverloads, type SendTxOptions, type SignerType, type SiweSession, type SiweSessionStatus, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, UserCancelledError, type UserDto, type VolrClient, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, type WalletStateComparison, analyzeContractForEIP7702, buildCall, buildCalls, checkPrfExtensionAvailable, checkPrfSupport, compareERC20Balances, compareWalletStates, createGetNetworkInfo, createPasskeyAdapter, debugTransactionFailure, defaultIdempotencyKey, diagnoseTransactionFailure, getERC20Balance, getPasskeyAuthGuidance, getWalletState, isEIP7702Delegated, isUserCancelledError, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, useVolr, useVolrAuthCallback, useVolrContext, useVolrLogin };
1004
+ /**
1005
+ * Passkey migration (headless)
1006
+ * Cross-domain wallet migration using postMessage
1007
+ */
1008
+
1009
+ interface MigrationRequestParams {
1010
+ /** APIClient instance */
1011
+ client: APIClient;
1012
+ /** Target domain to migrate to */
1013
+ targetOrigin: string;
1014
+ }
1015
+ interface MigrationRequestResult {
1016
+ /** Migration token from backend */
1017
+ migrationToken: string;
1018
+ /** Target origin confirmed by backend */
1019
+ targetOrigin: string;
1020
+ /** Token expiration timestamp */
1021
+ expiresAt: number;
1022
+ }
1023
+ interface MigrationCompleteParams {
1024
+ /** APIClient instance */
1025
+ client: APIClient;
1026
+ /** Base URL for API calls */
1027
+ baseUrl: string;
1028
+ /** Project API key */
1029
+ apiKey: string;
1030
+ /** User ID */
1031
+ userId: string;
1032
+ /** Project ID */
1033
+ projectId: string;
1034
+ /** Migration token from source domain */
1035
+ migrationToken: string;
1036
+ /** Master seed from source domain (decrypted) */
1037
+ masterSeed: Uint8Array;
1038
+ /**
1039
+ * WebAuthn rpId for this domain
1040
+ * @default window.location.hostname
1041
+ */
1042
+ rpId?: string;
1043
+ /** Relying Party Name */
1044
+ rpName?: string;
1045
+ /** User email (for WebAuthn displayName) */
1046
+ userEmail?: string | null;
1047
+ }
1048
+ interface MigrationCompleteResult {
1049
+ /** New credential ID */
1050
+ credentialId: string;
1051
+ /** New blob URL */
1052
+ blobUrl: string;
1053
+ /** rpId used for registration */
1054
+ rpId: string;
1055
+ }
1056
+ interface MigrationSeedRequest {
1057
+ type: 'VOLR_MIGRATION_SEED_REQUEST';
1058
+ migrationToken: string;
1059
+ }
1060
+ interface MigrationSeedResponse {
1061
+ type: 'VOLR_MIGRATION_SEED_RESPONSE';
1062
+ masterSeed: number[];
1063
+ userId: string;
1064
+ projectId: string;
1065
+ }
1066
+ interface MigrationError {
1067
+ type: 'VOLR_MIGRATION_ERROR';
1068
+ code: string;
1069
+ message: string;
1070
+ }
1071
+ type MigrationMessage = MigrationSeedRequest | MigrationSeedResponse | MigrationError;
1072
+ /**
1073
+ * Request migration token from backend
1074
+ * Called on the source domain to initiate migration
1075
+ */
1076
+ declare function requestMigration(params: MigrationRequestParams): Promise<MigrationRequestResult>;
1077
+ /**
1078
+ * Open target domain popup for migration
1079
+ * Called on the source domain after getting migration token
1080
+ *
1081
+ * @param targetOrigin - Target domain URL
1082
+ * @param migrationToken - Token from requestMigration
1083
+ * @param migrationPath - Path on target domain for migration (default: /wallet/migrate)
1084
+ * @returns Window reference to the popup
1085
+ */
1086
+ declare function openMigrationPopup(targetOrigin: string, migrationToken: string, migrationPath?: string): Window | null;
1087
+ /**
1088
+ * Handle seed request from target domain
1089
+ * Called on source domain when popup requests the master seed
1090
+ *
1091
+ * @param masterSeed - Decrypted master seed
1092
+ * @param userId - User ID
1093
+ * @param projectId - Project ID
1094
+ * @param targetOrigin - Target origin (for postMessage security)
1095
+ * @param popup - Reference to the popup window
1096
+ */
1097
+ declare function sendSeedToPopup(masterSeed: Uint8Array, userId: string, projectId: string, targetOrigin: string, popup: Window): void;
1098
+ /**
1099
+ * Listen for seed requests from target domain
1100
+ * Set up message listener on source domain
1101
+ *
1102
+ * @param allowedOrigins - List of allowed target origins
1103
+ * @param getMasterSeed - Callback to get decrypted master seed (may trigger WebAuthn)
1104
+ * @param getUserInfo - Callback to get user info
1105
+ * @returns Cleanup function to remove listener
1106
+ */
1107
+ declare function listenForSeedRequests(allowedOrigins: string[], getMasterSeed: () => Promise<Uint8Array>, getUserInfo: () => {
1108
+ userId: string;
1109
+ projectId: string;
1110
+ }): () => void;
1111
+ /**
1112
+ * Request master seed from source domain
1113
+ * Called on target domain (in popup)
1114
+ *
1115
+ * @param sourceOrigin - Source domain origin
1116
+ * @param migrationToken - Migration token
1117
+ * @param timeout - Timeout in milliseconds (default: 60000)
1118
+ * @returns Master seed and user info from source domain
1119
+ */
1120
+ declare function requestSeedFromOpener(sourceOrigin: string, migrationToken: string, timeout?: number): Promise<{
1121
+ masterSeed: Uint8Array;
1122
+ userId: string;
1123
+ projectId: string;
1124
+ }>;
1125
+ /**
1126
+ * Complete migration on target domain
1127
+ * Creates new passkey, encrypts master seed, and registers with backend
1128
+ */
1129
+ declare function completeMigration(params: MigrationCompleteParams): Promise<MigrationCompleteResult>;
1130
+ /**
1131
+ * Get all user credentials from backend
1132
+ */
1133
+ declare function getUserCredentials(client: APIClient): Promise<Array<{
1134
+ rpId: string;
1135
+ credentialId: string;
1136
+ platform: string | null;
1137
+ createdAt: string;
1138
+ }>>;
1139
+
1140
+ export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, type ContractAnalysisResult, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type ERC20BalanceComparison, type Erc20Token$1 as Erc20Token, type EvmClient, type KeyStorageType, type MigrationCompleteParams, type MigrationCompleteResult, type MigrationError, type MigrationMessage, type MigrationRequestParams, type MigrationRequestResult, type MigrationSeedRequest, type MigrationSeedResponse, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, PasskeyNotFoundError, type PlatformCheckResult, type PrfInputDto, PrfNotSupportedError, type SendBatchOverloads, type SendTxOptions, type SignerType, type SiweSession, type SiweSessionStatus, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, UserCancelledError, type UserDto, type VolrClient, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, type WalletStateComparison, analyzeContractForEIP7702, buildCall, buildCalls, checkPrfExtensionAvailable, checkPrfSupport, compareERC20Balances, compareWalletStates, completeMigration, createGetNetworkInfo, createPasskeyAdapter, debugTransactionFailure, defaultIdempotencyKey, diagnoseTransactionFailure, getERC20Balance, getPasskeyAuthGuidance, getUserCredentials, getWalletState, isEIP7702Delegated, isUserCancelledError, listenForSeedRequests, normalizeHex, normalizeHexArray, openMigrationPopup, requestMigration, requestSeedFromOpener, sendSeedToPopup, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, useVolr, useVolrAuthCallback, useVolrContext, useVolrLogin };
package/dist/index.d.ts CHANGED
@@ -96,9 +96,11 @@ declare class APIClient {
96
96
  /**
97
97
  * PRF Input DTO
98
98
  * Input parameters for WebAuthn PRF extension
99
+ *
100
+ * Note: origin is NOT included for cross-domain wallet support.
101
+ * WebAuthn's rpId binding provides domain security.
99
102
  */
100
103
  interface PrfInputDto {
101
- origin: string;
102
104
  projectId: string;
103
105
  credentialId: string;
104
106
  salt?: Uint8Array;
@@ -999,4 +1001,140 @@ declare function getPasskeyAuthGuidance(passkeyPlatform?: string | null): string
999
1001
  */
1000
1002
  declare function checkPrfExtensionAvailable(): Promise<boolean>;
1001
1003
 
1002
- export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, type ContractAnalysisResult, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type ERC20BalanceComparison, type Erc20Token$1 as Erc20Token, type EvmClient, type KeyStorageType, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, PasskeyNotFoundError, type PlatformCheckResult, type PrfInputDto, PrfNotSupportedError, type SendBatchOverloads, type SendTxOptions, type SignerType, type SiweSession, type SiweSessionStatus, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, UserCancelledError, type UserDto, type VolrClient, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, type WalletStateComparison, analyzeContractForEIP7702, buildCall, buildCalls, checkPrfExtensionAvailable, checkPrfSupport, compareERC20Balances, compareWalletStates, createGetNetworkInfo, createPasskeyAdapter, debugTransactionFailure, defaultIdempotencyKey, diagnoseTransactionFailure, getERC20Balance, getPasskeyAuthGuidance, getWalletState, isEIP7702Delegated, isUserCancelledError, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, useVolr, useVolrAuthCallback, useVolrContext, useVolrLogin };
1004
+ /**
1005
+ * Passkey migration (headless)
1006
+ * Cross-domain wallet migration using postMessage
1007
+ */
1008
+
1009
+ interface MigrationRequestParams {
1010
+ /** APIClient instance */
1011
+ client: APIClient;
1012
+ /** Target domain to migrate to */
1013
+ targetOrigin: string;
1014
+ }
1015
+ interface MigrationRequestResult {
1016
+ /** Migration token from backend */
1017
+ migrationToken: string;
1018
+ /** Target origin confirmed by backend */
1019
+ targetOrigin: string;
1020
+ /** Token expiration timestamp */
1021
+ expiresAt: number;
1022
+ }
1023
+ interface MigrationCompleteParams {
1024
+ /** APIClient instance */
1025
+ client: APIClient;
1026
+ /** Base URL for API calls */
1027
+ baseUrl: string;
1028
+ /** Project API key */
1029
+ apiKey: string;
1030
+ /** User ID */
1031
+ userId: string;
1032
+ /** Project ID */
1033
+ projectId: string;
1034
+ /** Migration token from source domain */
1035
+ migrationToken: string;
1036
+ /** Master seed from source domain (decrypted) */
1037
+ masterSeed: Uint8Array;
1038
+ /**
1039
+ * WebAuthn rpId for this domain
1040
+ * @default window.location.hostname
1041
+ */
1042
+ rpId?: string;
1043
+ /** Relying Party Name */
1044
+ rpName?: string;
1045
+ /** User email (for WebAuthn displayName) */
1046
+ userEmail?: string | null;
1047
+ }
1048
+ interface MigrationCompleteResult {
1049
+ /** New credential ID */
1050
+ credentialId: string;
1051
+ /** New blob URL */
1052
+ blobUrl: string;
1053
+ /** rpId used for registration */
1054
+ rpId: string;
1055
+ }
1056
+ interface MigrationSeedRequest {
1057
+ type: 'VOLR_MIGRATION_SEED_REQUEST';
1058
+ migrationToken: string;
1059
+ }
1060
+ interface MigrationSeedResponse {
1061
+ type: 'VOLR_MIGRATION_SEED_RESPONSE';
1062
+ masterSeed: number[];
1063
+ userId: string;
1064
+ projectId: string;
1065
+ }
1066
+ interface MigrationError {
1067
+ type: 'VOLR_MIGRATION_ERROR';
1068
+ code: string;
1069
+ message: string;
1070
+ }
1071
+ type MigrationMessage = MigrationSeedRequest | MigrationSeedResponse | MigrationError;
1072
+ /**
1073
+ * Request migration token from backend
1074
+ * Called on the source domain to initiate migration
1075
+ */
1076
+ declare function requestMigration(params: MigrationRequestParams): Promise<MigrationRequestResult>;
1077
+ /**
1078
+ * Open target domain popup for migration
1079
+ * Called on the source domain after getting migration token
1080
+ *
1081
+ * @param targetOrigin - Target domain URL
1082
+ * @param migrationToken - Token from requestMigration
1083
+ * @param migrationPath - Path on target domain for migration (default: /wallet/migrate)
1084
+ * @returns Window reference to the popup
1085
+ */
1086
+ declare function openMigrationPopup(targetOrigin: string, migrationToken: string, migrationPath?: string): Window | null;
1087
+ /**
1088
+ * Handle seed request from target domain
1089
+ * Called on source domain when popup requests the master seed
1090
+ *
1091
+ * @param masterSeed - Decrypted master seed
1092
+ * @param userId - User ID
1093
+ * @param projectId - Project ID
1094
+ * @param targetOrigin - Target origin (for postMessage security)
1095
+ * @param popup - Reference to the popup window
1096
+ */
1097
+ declare function sendSeedToPopup(masterSeed: Uint8Array, userId: string, projectId: string, targetOrigin: string, popup: Window): void;
1098
+ /**
1099
+ * Listen for seed requests from target domain
1100
+ * Set up message listener on source domain
1101
+ *
1102
+ * @param allowedOrigins - List of allowed target origins
1103
+ * @param getMasterSeed - Callback to get decrypted master seed (may trigger WebAuthn)
1104
+ * @param getUserInfo - Callback to get user info
1105
+ * @returns Cleanup function to remove listener
1106
+ */
1107
+ declare function listenForSeedRequests(allowedOrigins: string[], getMasterSeed: () => Promise<Uint8Array>, getUserInfo: () => {
1108
+ userId: string;
1109
+ projectId: string;
1110
+ }): () => void;
1111
+ /**
1112
+ * Request master seed from source domain
1113
+ * Called on target domain (in popup)
1114
+ *
1115
+ * @param sourceOrigin - Source domain origin
1116
+ * @param migrationToken - Migration token
1117
+ * @param timeout - Timeout in milliseconds (default: 60000)
1118
+ * @returns Master seed and user info from source domain
1119
+ */
1120
+ declare function requestSeedFromOpener(sourceOrigin: string, migrationToken: string, timeout?: number): Promise<{
1121
+ masterSeed: Uint8Array;
1122
+ userId: string;
1123
+ projectId: string;
1124
+ }>;
1125
+ /**
1126
+ * Complete migration on target domain
1127
+ * Creates new passkey, encrypts master seed, and registers with backend
1128
+ */
1129
+ declare function completeMigration(params: MigrationCompleteParams): Promise<MigrationCompleteResult>;
1130
+ /**
1131
+ * Get all user credentials from backend
1132
+ */
1133
+ declare function getUserCredentials(client: APIClient): Promise<Array<{
1134
+ rpId: string;
1135
+ credentialId: string;
1136
+ platform: string | null;
1137
+ createdAt: string;
1138
+ }>>;
1139
+
1140
+ export { type ApiResponse, type AuthRefreshResponseDto, type AuthResult, type BuildCallOptions, type ContractAnalysisResult, DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, type DepositAsset$1 as DepositAsset, type DepositConfig, type ERC20BalanceComparison, type Erc20Token$1 as Erc20Token, type EvmClient, type KeyStorageType, type MigrationCompleteParams, type MigrationCompleteResult, type MigrationError, type MigrationMessage, type MigrationRequestParams, type MigrationRequestResult, type MigrationSeedRequest, type MigrationSeedResponse, type MpcConnectionStep, type NetworkDto, type NetworkInfo, type PasskeyAdapterOptions, type PasskeyEnrollmentStep, PasskeyNotFoundError, type PlatformCheckResult, type PrfInputDto, PrfNotSupportedError, type SendBatchOverloads, type SendTxOptions, type SignerType, type SiweSession, type SiweSessionStatus, type SocialProvider, type TransactionDto, type TransactionStatus, type UseMpcConnectionReturn, type UsePasskeyEnrollmentReturn, type UseVolrAuthCallbackOptions, type UseVolrAuthCallbackReturn, type UseVolrLoginReturn, UserCancelledError, type UserDto, type VolrClient, type VolrConfig, type VolrContextValue, VolrProvider, type VolrUser, type WalletStateComparison, analyzeContractForEIP7702, buildCall, buildCalls, checkPrfExtensionAvailable, checkPrfSupport, compareERC20Balances, compareWalletStates, completeMigration, createGetNetworkInfo, createPasskeyAdapter, debugTransactionFailure, defaultIdempotencyKey, diagnoseTransactionFailure, getERC20Balance, getPasskeyAuthGuidance, getUserCredentials, getWalletState, isEIP7702Delegated, isUserCancelledError, listenForSeedRequests, normalizeHex, normalizeHexArray, openMigrationPopup, requestMigration, requestSeedFromOpener, sendSeedToPopup, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, useVolr, useVolrAuthCallback, useVolrContext, useVolrLogin };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as nc from 'crypto';
2
2
  import { createContext, useRef, useEffect, useMemo, useState, useCallback, useContext } from 'react';
3
- import { createPasskeyProvider, createMpcProvider, signSession, getAuthNonce, signAuthorization, deriveWrapKey, createMasterKeyProvider, sealMasterSeed, uploadBlob, deriveEvmKey, ZERO_HASH, selectSigner, VolrError } from '@volr/sdk-core';
3
+ import { createPasskeyProvider, createMpcProvider, deriveWrapKey, sealMasterSeed, uploadBlob, signSession, getAuthNonce, signAuthorization, createMasterKeyProvider, deriveEvmKey, ZERO_HASH, selectSigner, VolrError } from '@volr/sdk-core';
4
4
  export { createMasterKeyProvider, createMpcProvider, createPasskeyProvider, deriveEvmKey, deriveWrapKey, sealMasterSeed, uploadBlob } from '@volr/sdk-core';
5
5
  import axios from 'axios';
6
6
  import { jsx } from 'react/jsx-runtime';
@@ -9757,7 +9757,9 @@ async function restorePasskey(params) {
9757
9757
  userId,
9758
9758
  blobUrl,
9759
9759
  prfInput,
9760
- credentialId: providedCredentialId
9760
+ credentialId: providedCredentialId,
9761
+ rpId = typeof window !== "undefined" ? window.location.hostname : "localhost",
9762
+ rpName = "Volr"
9761
9763
  } = params;
9762
9764
  const credentialId = providedCredentialId || prfInput.credentialId || safeStorage.getItem(STORAGE_KEYS.credentialId);
9763
9765
  if (!credentialId) {
@@ -9786,7 +9788,7 @@ async function restorePasskey(params) {
9786
9788
  `volr/master-seed/v1|${userId}|${keyStorageType}|${version5}`
9787
9789
  );
9788
9790
  const passkeyAdapter = createPasskeyAdapter({
9789
- rpId: typeof window !== "undefined" ? window.location.hostname : "localhost"});
9791
+ rpId});
9790
9792
  const provider = createPasskeyProvider(passkeyAdapter, {
9791
9793
  prfInput: {
9792
9794
  ...prfInput,
@@ -19179,9 +19181,7 @@ async function enrollPasskey(params) {
19179
19181
  crypto.getRandomValues(challenge2);
19180
19182
  const userHandle = new TextEncoder().encode(userId);
19181
19183
  const tempCredentialId = "temp-" + Date.now();
19182
- const origin = typeof window !== "undefined" ? window.location.origin : "https://localhost";
19183
19184
  const tempPrfInput = {
19184
- origin,
19185
19185
  projectId,
19186
19186
  credentialId: tempCredentialId
19187
19187
  };
@@ -19224,7 +19224,6 @@ async function enrollPasskey(params) {
19224
19224
  const prfOutputBuffer = extensionResults.prf.results.first;
19225
19225
  const prfOutput = new Uint8Array(prfOutputBuffer);
19226
19226
  const prfInput = {
19227
- origin,
19228
19227
  projectId,
19229
19228
  credentialId
19230
19229
  };
@@ -19260,7 +19259,6 @@ async function enrollPasskey(params) {
19260
19259
  apiKey,
19261
19260
  accessToken,
19262
19261
  blob
19263
- // Don't pass axiosInstance - let uploadBlob create its own
19264
19262
  });
19265
19263
  if (!blobUrl) {
19266
19264
  throw new Error("Failed to upload blob: missing key");
@@ -19273,7 +19271,6 @@ async function enrollPasskey(params) {
19273
19271
  credentialId,
19274
19272
  blobUrl,
19275
19273
  prfInput: {
19276
- origin,
19277
19274
  projectId,
19278
19275
  credentialId
19279
19276
  },
@@ -19947,6 +19944,232 @@ async function checkPrfExtensionAvailable() {
19947
19944
  const { prfSupported } = checkPrfSupport();
19948
19945
  return prfSupported;
19949
19946
  }
19947
+ async function requestMigration(params) {
19948
+ const { client, targetOrigin } = params;
19949
+ const response = await client.post("/wallet/migration/request", { targetOrigin });
19950
+ return {
19951
+ migrationToken: response.migrationToken,
19952
+ targetOrigin: response.targetOrigin,
19953
+ expiresAt: response.expiresAt
19954
+ };
19955
+ }
19956
+ function openMigrationPopup(targetOrigin, migrationToken, migrationPath = "/wallet/migrate") {
19957
+ const url = new URL(migrationPath, targetOrigin);
19958
+ url.searchParams.set("migration_token", migrationToken);
19959
+ const width = 500;
19960
+ const height = 600;
19961
+ const left = window.screenX + (window.outerWidth - width) / 2;
19962
+ const top = window.screenY + (window.outerHeight - height) / 2;
19963
+ return window.open(
19964
+ url.toString(),
19965
+ "volr_migration",
19966
+ `width=${width},height=${height},left=${left},top=${top},popup=1`
19967
+ );
19968
+ }
19969
+ function sendSeedToPopup(masterSeed, userId, projectId, targetOrigin, popup) {
19970
+ const response = {
19971
+ type: "VOLR_MIGRATION_SEED_RESPONSE",
19972
+ masterSeed: Array.from(masterSeed),
19973
+ userId,
19974
+ projectId
19975
+ };
19976
+ popup.postMessage(response, targetOrigin);
19977
+ }
19978
+ function listenForSeedRequests(allowedOrigins, getMasterSeed, getUserInfo) {
19979
+ const handleMessage = async (event) => {
19980
+ if (!allowedOrigins.includes(event.origin)) {
19981
+ return;
19982
+ }
19983
+ const data = event.data;
19984
+ if (data?.type !== "VOLR_MIGRATION_SEED_REQUEST") {
19985
+ return;
19986
+ }
19987
+ try {
19988
+ const masterSeed = await getMasterSeed();
19989
+ const { userId, projectId } = getUserInfo();
19990
+ const response = {
19991
+ type: "VOLR_MIGRATION_SEED_RESPONSE",
19992
+ masterSeed: Array.from(masterSeed),
19993
+ userId,
19994
+ projectId
19995
+ };
19996
+ event.source?.postMessage(response, { targetOrigin: event.origin });
19997
+ } catch (error) {
19998
+ const errorResponse = {
19999
+ type: "VOLR_MIGRATION_ERROR",
20000
+ code: "SEED_RETRIEVAL_FAILED",
20001
+ message: error instanceof Error ? error.message : "Failed to retrieve master seed"
20002
+ };
20003
+ event.source?.postMessage(errorResponse, { targetOrigin: event.origin });
20004
+ }
20005
+ };
20006
+ window.addEventListener("message", handleMessage);
20007
+ return () => {
20008
+ window.removeEventListener("message", handleMessage);
20009
+ };
20010
+ }
20011
+ function requestSeedFromOpener(sourceOrigin, migrationToken, timeout = 6e4) {
20012
+ return new Promise((resolve, reject) => {
20013
+ if (!window.opener) {
20014
+ reject(new Error("No opener window found. This page must be opened as a popup."));
20015
+ return;
20016
+ }
20017
+ const timeoutId = setTimeout(() => {
20018
+ window.removeEventListener("message", handleMessage);
20019
+ reject(new Error("Seed request timed out"));
20020
+ }, timeout);
20021
+ const handleMessage = (event) => {
20022
+ if (event.origin !== sourceOrigin) {
20023
+ return;
20024
+ }
20025
+ const data = event.data;
20026
+ if (data?.type === "VOLR_MIGRATION_SEED_RESPONSE") {
20027
+ clearTimeout(timeoutId);
20028
+ window.removeEventListener("message", handleMessage);
20029
+ resolve({
20030
+ masterSeed: new Uint8Array(data.masterSeed),
20031
+ userId: data.userId,
20032
+ projectId: data.projectId
20033
+ });
20034
+ } else if (data?.type === "VOLR_MIGRATION_ERROR") {
20035
+ clearTimeout(timeoutId);
20036
+ window.removeEventListener("message", handleMessage);
20037
+ reject(new Error(`${data.code}: ${data.message}`));
20038
+ }
20039
+ };
20040
+ window.addEventListener("message", handleMessage);
20041
+ const request = {
20042
+ type: "VOLR_MIGRATION_SEED_REQUEST",
20043
+ migrationToken
20044
+ };
20045
+ window.opener.postMessage(request, sourceOrigin);
20046
+ });
20047
+ }
20048
+ function detectPlatform3() {
20049
+ if (typeof navigator === "undefined") return "Unknown";
20050
+ const ua = navigator.userAgent;
20051
+ const platform = navigator.platform || "";
20052
+ if (/iPhone|iPad|iPod/.test(ua) || platform === "MacIntel" && navigator.maxTouchPoints > 1) {
20053
+ return "iOS";
20054
+ }
20055
+ if (/Android/.test(ua)) return "Android";
20056
+ if (/Mac/.test(platform)) return "macOS";
20057
+ if (/Win/.test(platform)) return "Windows";
20058
+ if (/CrOS/.test(ua)) return "ChromeOS";
20059
+ if (/Linux/.test(platform)) return "Linux";
20060
+ return "Unknown";
20061
+ }
20062
+ async function completeMigration(params) {
20063
+ const {
20064
+ client,
20065
+ baseUrl,
20066
+ apiKey,
20067
+ userId,
20068
+ projectId,
20069
+ migrationToken,
20070
+ masterSeed,
20071
+ rpId = typeof window !== "undefined" ? window.location.hostname : "localhost",
20072
+ rpName = "Volr",
20073
+ userEmail
20074
+ } = params;
20075
+ if (!navigator.credentials || !navigator.credentials.create) {
20076
+ throw new Error("WebAuthn API is not supported");
20077
+ }
20078
+ const challenge2 = new Uint8Array(32);
20079
+ crypto.getRandomValues(challenge2);
20080
+ const userHandle = new TextEncoder().encode(userId);
20081
+ const displayName = userEmail || `Volr Wallet (${userId.substring(0, 8)}...)`;
20082
+ const tempCredentialId = "temp-" + Date.now();
20083
+ const tempPrfInput = {
20084
+ projectId,
20085
+ credentialId: tempCredentialId
20086
+ };
20087
+ const prfSalt = deriveWrapKey(tempPrfInput);
20088
+ const publicKeyCredentialCreationOptions = {
20089
+ challenge: challenge2,
20090
+ rp: {
20091
+ name: rpName,
20092
+ id: rpId
20093
+ },
20094
+ user: {
20095
+ id: userHandle,
20096
+ name: displayName,
20097
+ displayName
20098
+ },
20099
+ pubKeyCredParams: PUBKEY_CRED_PARAMS,
20100
+ authenticatorSelection: AUTHENTICATOR_SELECTION,
20101
+ timeout: WEBAUTHN_TIMEOUT,
20102
+ attestation: ATTESTATION,
20103
+ extensions: {
20104
+ prf: {
20105
+ eval: {
20106
+ first: prfSalt.buffer
20107
+ }
20108
+ }
20109
+ }
20110
+ };
20111
+ const credential = await navigator.credentials.create({
20112
+ publicKey: publicKeyCredentialCreationOptions
20113
+ });
20114
+ if (!credential || !("response" in credential)) {
20115
+ throw new Error("Failed to create passkey credential");
20116
+ }
20117
+ const credentialId = Array.from(new Uint8Array(credential.rawId)).map((b) => b.toString(16).padStart(2, "0")).join("");
20118
+ const extensionResults = credential.getClientExtensionResults();
20119
+ if (!extensionResults.prf?.results?.first) {
20120
+ throw new Error("PRF extension not supported or PRF output missing");
20121
+ }
20122
+ const prfOutputBuffer = extensionResults.prf.results.first;
20123
+ const prfOutput = new Uint8Array(prfOutputBuffer);
20124
+ const wrapKey = prfOutput;
20125
+ const keyStorageType = "passkey";
20126
+ const version5 = "v1";
20127
+ const aadBytes = new TextEncoder().encode(
20128
+ `volr/master-seed/v1|${userId}|${keyStorageType}|${version5}`
20129
+ );
20130
+ const encryptedBlob = await sealMasterSeed(masterSeed, wrapKey, aadBytes);
20131
+ const blob = new Blob(
20132
+ [
20133
+ encryptedBlob.cipher,
20134
+ encryptedBlob.nonce
20135
+ ],
20136
+ { type: "application/octet-stream" }
20137
+ );
20138
+ const accessToken = client.getAccessToken();
20139
+ if (!accessToken) {
20140
+ throw new Error("Access token is required");
20141
+ }
20142
+ const { key: blobUrl } = await uploadBlob({
20143
+ baseUrl,
20144
+ apiKey,
20145
+ accessToken,
20146
+ blob
20147
+ });
20148
+ if (!blobUrl) {
20149
+ throw new Error("Failed to upload blob");
20150
+ }
20151
+ const platform = detectPlatform3();
20152
+ await client.post("/wallet/migration/complete", {
20153
+ migrationToken,
20154
+ credentialId,
20155
+ blobUrl,
20156
+ prfInput: {
20157
+ projectId,
20158
+ credentialId
20159
+ },
20160
+ rpId,
20161
+ platform
20162
+ });
20163
+ return {
20164
+ credentialId,
20165
+ blobUrl,
20166
+ rpId
20167
+ };
20168
+ }
20169
+ async function getUserCredentials(client) {
20170
+ const response = await client.get("/wallet/credentials");
20171
+ return response.credentials;
20172
+ }
19950
20173
  /*! Bundled license information:
19951
20174
 
19952
20175
  @noble/hashes/esm/utils.js:
@@ -19961,6 +20184,6 @@ async function checkPrfExtensionAvailable() {
19961
20184
  (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
19962
20185
  */
19963
20186
 
19964
- export { DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, PasskeyNotFoundError, PrfNotSupportedError, UserCancelledError, VolrProvider, analyzeContractForEIP7702, buildCall, buildCalls, checkPrfExtensionAvailable, checkPrfSupport, compareERC20Balances, compareWalletStates, createGetNetworkInfo, createPasskeyAdapter, debugTransactionFailure, defaultIdempotencyKey, diagnoseTransactionFailure, getERC20Balance, getPasskeyAuthGuidance, getWalletState, isEIP7702Delegated, isUserCancelledError, normalizeHex, normalizeHexArray, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, useVolr, useVolrAuthCallback, useVolrContext, useVolrLogin };
20187
+ export { DEFAULT_EXPIRES_IN_SEC, DEFAULT_MODE, PasskeyNotFoundError, PrfNotSupportedError, UserCancelledError, VolrProvider, analyzeContractForEIP7702, buildCall, buildCalls, checkPrfExtensionAvailable, checkPrfSupport, compareERC20Balances, compareWalletStates, completeMigration, createGetNetworkInfo, createPasskeyAdapter, debugTransactionFailure, defaultIdempotencyKey, diagnoseTransactionFailure, getERC20Balance, getPasskeyAuthGuidance, getUserCredentials, getWalletState, isEIP7702Delegated, isUserCancelledError, listenForSeedRequests, normalizeHex, normalizeHexArray, openMigrationPopup, requestMigration, requestSeedFromOpener, sendSeedToPopup, uploadBlobViaPresign, useDepositListener, useInternalAuth, useMpcConnection, usePasskeyEnrollment, useVolr, useVolrAuthCallback, useVolrContext, useVolrLogin };
19965
20188
  //# sourceMappingURL=index.js.map
19966
20189
  //# sourceMappingURL=index.js.map