File tree Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Expand file tree Collapse file tree 3 files changed +22
-5
lines changed Original file line number Diff line number Diff line change @@ -229,6 +229,12 @@ export default class LNC {
229229 clearInterval ( interval ) ;
230230 resolve ( ) ;
231231 log . info ( 'The WASM client is connected to the server' ) ;
232+
233+ // clear the in-memory credentials after connecting if the
234+ // credentials are persisted in local storage
235+ if ( this . credentials . password ) {
236+ this . credentials . clear ( true ) ;
237+ }
232238 } else if ( counter > 20 ) {
233239 clearInterval ( interval ) ;
234240 reject (
Original file line number Diff line number Diff line change @@ -132,6 +132,11 @@ export interface CredentialStore {
132132 * credentials persisted in the store
133133 */
134134 isPaired : boolean ;
135- /** Clears any persisted data in the store */
136- clear ( ) : void ;
135+ /**
136+ * Clears the in-memory and persisted data in the store.
137+ * @param memoryOnly If `true`, only the in-memory data will be cleared. If
138+ * `false` or `undefined`, the persisted data will be cleared as well.
139+ * The default is `undefined`.
140+ */
141+ clear ( memoryOnly ?: boolean ) : void ;
137142}
Original file line number Diff line number Diff line change @@ -105,6 +105,10 @@ export default class LncCredentialStore implements CredentialStore {
105105 if ( this . remoteKey )
106106 this . persisted . remoteKey = this . _encrypt ( this . remoteKey ) ;
107107 this . _save ( ) ;
108+
109+ // once the encrypted data is persisted, we can clear the plain text
110+ // credentials from memory
111+ this . clear ( true ) ;
108112 }
109113 }
110114
@@ -170,9 +174,11 @@ export default class LncCredentialStore implements CredentialStore {
170174 }
171175
172176 /** Clears any persisted data in the store */
173- clear ( ) {
174- const key = `${ STORAGE_KEY } :${ this . namespace } ` ;
175- localStorage . removeItem ( key ) ;
177+ clear ( memoryOnly ?: boolean ) {
178+ if ( ! memoryOnly ) {
179+ const key = `${ STORAGE_KEY } :${ this . namespace } ` ;
180+ localStorage . removeItem ( key ) ;
181+ }
176182 this . persisted = {
177183 salt : '' ,
178184 cipher : '' ,
You can’t perform that action at this time.
0 commit comments