@@ -71,37 +71,42 @@ patch(FormController.prototype, {
7171 * @private
7272 */
7373 async _newVaultKeyPair ( ) {
74- // Get the current private key
75- const private_key = await this . vault . get_private_key ( ) ;
76-
77- // Generate new keys
78- await this . vault . generate_keys ( ) ;
79-
80- const public_key = await this . vault . get_public_key ( ) ;
74+ this . uuid = await this . vault . _check_database ( ) ;
75+ if ( this . uuid ) {
76+ // The user has a private key so get it
77+ const private_key = await this . vault . get_private_key ( ) ;
78+
79+ // Generate new keys
80+ await this . vault . generate_keys ( ) ;
81+
82+ const public_key = await this . vault . get_public_key ( ) ;
83+
84+ // Re-encrypt the master keys
85+ const master_keys = await rpc ( "/vault/rights/get" ) ;
86+ let result = { } ;
87+ for ( const uuid in master_keys ) {
88+ result [ uuid ] = await this . vault_utils . wrap (
89+ await this . vault_utils . unwrap ( master_keys [ uuid ] , private_key ) ,
90+ public_key
91+ ) ;
92+ }
8193
82- // Re-encrypt the master keys
83- const master_keys = await rpc ( "/vault/rights/get" ) ;
84- let result = { } ;
85- for ( const uuid in master_keys ) {
86- result [ uuid ] = await this . vault_utils . wrap (
87- await this . vault_utils . unwrap ( master_keys [ uuid ] , private_key ) ,
88- public_key
89- ) ;
90- }
94+ await rpc ( "/vault/rights/store" , { keys : result } ) ;
9195
92- await rpc ( "/vault/rights/store" , { keys : result } ) ;
96+ // Re-encrypt the inboxes to not loose it
97+ const inbox_keys = await rpc ( "/vault/inbox/get" ) ;
98+ result = { } ;
99+ for ( const uuid in inbox_keys ) {
100+ result [ uuid ] = await this . vault_utils . wrap (
101+ await this . vault_utils . unwrap ( inbox_keys [ uuid ] , private_key ) ,
102+ public_key
103+ ) ;
104+ }
93105
94- // Re-encrypt the inboxes to not loose it
95- const inbox_keys = await rpc ( "/vault/inbox/get" ) ;
96- result = { } ;
97- for ( const uuid in inbox_keys ) {
98- result [ uuid ] = await this . vault_utils . wrap (
99- await this . vault_utils . unwrap ( inbox_keys [ uuid ] , private_key ) ,
100- public_key
101- ) ;
106+ await rpc ( "/vault/inbox/store" , { keys : result } ) ;
107+ } else {
108+ await this . vault . _initialize_keys ( ) ;
102109 }
103-
104- await rpc ( "/vault/inbox/store" , { keys : result } ) ;
105110 } ,
106111
107112 /**
0 commit comments