@@ -155,6 +155,22 @@ export function VaultProvider({ children }: { children: React.ReactNode }) {
155155 [ ]
156156 ) ;
157157
158+ const unlockWithDerivedKey = useCallback (
159+ async ( vmk : CryptoKey ) : Promise < void > => {
160+ const sessionKey = generateSessionKey ( ) ;
161+ const encryptedVMK = await encryptVMKForSession ( vmk , sessionKey ) ;
162+
163+ const connected = await connectVaultWebSocket ( encryptedVMK . ciphertext , encryptedVMK . nonce , sessionKey ) ;
164+ if ( ! connected ) {
165+ throw new Error ( 'Failed to establish vault WebSocket connection' ) ;
166+ }
167+
168+ storeSession ( { sessionKey } ) ;
169+ vmkRef . current = vmk ;
170+ } ,
171+ [ connectVaultWebSocket ] ,
172+ ) ;
173+
158174 // Fetch vault status
159175 const refreshStatus = useCallback ( async ( ) => {
160176 if ( ! isAuthenticated ) {
@@ -276,9 +292,8 @@ export function VaultProvider({ children }: { children: React.ReactNode }) {
276292 setLoading ( false ) ;
277293 throw error ;
278294 }
279-
280295 } ,
281- [ setLoading , setError ]
296+ [ setLoading , setError , unlockWithDerivedKey ] ,
282297 ) ;
283298
284299 // Setup with passkey (WebAuthn PRF)
@@ -381,24 +396,8 @@ export function VaultProvider({ children }: { children: React.ReactNode }) {
381396 setLoading ( false ) ;
382397 throw error ;
383398 }
384- } , [ setLoading , setError , user ] ) ;
385-
386- const unlockWithDerivedKey = async ( vmk : CryptoKey ) : Promise < void > => {
387- const sessionKey = generateSessionKey ( ) ;
388- const encryptedVMK = await encryptVMKForSession ( vmk , sessionKey ) ;
389-
390- const connected = await connectVaultWebSocket (
391- encryptedVMK . ciphertext ,
392- encryptedVMK . nonce ,
393- sessionKey
394- ) ;
395- if ( ! connected ) {
396- throw new Error ( 'Failed to establish vault WebSocket connection' ) ;
397- }
399+ } , [ setLoading , setError , unlockWithDerivedKey , user ] ) ;
398400
399- storeSession ( { sessionKey } ) ;
400- vmkRef . current = vmk ;
401- } ;
402401
403402 // Unlock with password
404403 const unlockWithPassword = useCallback (
@@ -447,7 +446,7 @@ export function VaultProvider({ children }: { children: React.ReactNode }) {
447446 return { success : false , error : message } ;
448447 }
449448 } ,
450- [ setLoading , setError ]
449+ [ setLoading , setError , unlockWithDerivedKey ]
451450 ) ;
452451
453452 // Unlock with passkey
@@ -520,7 +519,7 @@ export function VaultProvider({ children }: { children: React.ReactNode }) {
520519 setLoading ( false ) ;
521520 return { success : false , error : message } ;
522521 }
523- } , [ setLoading , setError ] ) ;
522+ } , [ setLoading , setError , unlockWithDerivedKey ] ) ;
524523
525524 // Unlock with recovery code
526525 const unlockWithRecoveryCode = useCallback (
@@ -569,7 +568,7 @@ export function VaultProvider({ children }: { children: React.ReactNode }) {
569568 return { success : false , error : message } ;
570569 }
571570 } ,
572- [ setLoading , setError ]
571+ [ setLoading , setError , unlockWithDerivedKey ]
573572 ) ;
574573
575574 const lockVault = useCallback ( async ( ) : Promise < void > => {
0 commit comments