@@ -219,85 +219,81 @@ export default class LNC {
219219 // make sure the WASM client binary is downloaded first
220220 if ( ! this . isReady ) await this . preload ( ) ;
221221
222- try {
223- let localKey = '' ;
224- let remoteKey = '' ;
225-
226- if ( this . _localKey ) {
227- localKey = this . _localKey ;
228- } else if ( localStorage . getItem ( `${ this . _namespace } :localKey` ) ) {
229- const data = localStorage . getItem (
230- `${ this . _namespace } :localKey`
231- ) ;
232- if (
233- ! verifyTestCipher (
234- this . testCipher ,
235- this . _password ,
236- this . salt
237- )
238- ) {
239- throw new Error ( 'Invalid Password' ) ;
240- }
241- localKey = this . _password
242- ? decrypt ( data , this . _password , this . salt )
243- : data ;
222+ let localKey = '' ;
223+ let remoteKey = '' ;
224+
225+ if ( this . _localKey ) {
226+ localKey = this . _localKey ;
227+ } else if ( localStorage . getItem ( `${ this . _namespace } :localKey` ) ) {
228+ const data = localStorage . getItem (
229+ `${ this . _namespace } :localKey`
230+ ) ;
231+ if (
232+ ! verifyTestCipher (
233+ this . testCipher ,
234+ this . _password ,
235+ this . salt
236+ )
237+ ) {
238+ throw new Error ( 'Invalid Password' ) ;
244239 }
240+ localKey = this . _password
241+ ? decrypt ( data , this . _password , this . salt )
242+ : data ;
243+ }
245244
246- if ( this . _remoteKey ) {
247- remoteKey = this . _remoteKey ;
248- } else if ( localStorage . getItem ( `${ this . _namespace } :remoteKey` ) ) {
249- const data = localStorage . getItem (
250- `${ this . _namespace } :remoteKey`
251- ) ;
252- if (
253- ! verifyTestCipher (
254- this . testCipher ,
255- this . _password ,
256- this . salt
257- )
258- ) {
259- throw new Error ( 'Invalid password' ) ;
260- }
261- remoteKey = this . _password
262- ? decrypt ( data , this . _password , this . salt )
263- : data ;
245+ if ( this . _remoteKey ) {
246+ remoteKey = this . _remoteKey ;
247+ } else if ( localStorage . getItem ( `${ this . _namespace } :remoteKey` ) ) {
248+ const data = localStorage . getItem (
249+ `${ this . _namespace } :remoteKey`
250+ ) ;
251+ if (
252+ ! verifyTestCipher (
253+ this . testCipher ,
254+ this . _password ,
255+ this . salt
256+ )
257+ ) {
258+ throw new Error ( 'Invalid password' ) ;
264259 }
260+ remoteKey = this . _password
261+ ? decrypt ( data , this . _password , this . salt )
262+ : data ;
263+ }
265264
266- log . debug ( 'localKey' , localKey ) ;
267- log . debug ( 'remoteKey' , remoteKey ) ;
268-
269- global . onLocalPrivCreate =
270- this . _onLocalPrivCreate || this . onLocalPrivCreate ;
271-
272- global . onRemoteKeyReceive =
273- this . _onRemoteKeyReceive || this . onRemoteKeyReceive ;
274-
275- global . onAuthData = ( keyHex : string ) => {
276- log . debug ( 'auth data received: ' + keyHex ) ;
277- } ;
278-
279- this . go . argv = [
280- 'wasm-client' ,
281- '--debuglevel=trace' ,
282- '--namespace=' + this . _namespace ,
283- '--localprivate=' + localKey ,
284- '--remotepublic=' + remoteKey ,
285- '--onlocalprivcreate=onLocalPrivCreate' ,
286- '--onremotekeyreceive=onRemoteKeyReceive' ,
287- '--onauthdata=onAuthData'
288- ] ;
289-
290- if ( this . result ) {
291- this . go . run ( this . result . instance ) ;
292- await WebAssembly . instantiate (
293- this . result . module ,
294- this . go . importObject
295- ) ;
296- } else {
297- throw new Error ( "Can't find WASM instance." ) ;
298- }
299- } catch {
300- throw new Error ( 'The password provided is not valid.' ) ;
265+ log . debug ( 'localKey' , localKey ) ;
266+ log . debug ( 'remoteKey' , remoteKey ) ;
267+
268+ global . onLocalPrivCreate =
269+ this . _onLocalPrivCreate || this . onLocalPrivCreate ;
270+
271+ global . onRemoteKeyReceive =
272+ this . _onRemoteKeyReceive || this . onRemoteKeyReceive ;
273+
274+ global . onAuthData = ( keyHex : string ) => {
275+ log . debug ( 'auth data received: ' + keyHex ) ;
276+ } ;
277+
278+ this . go . argv = [
279+ 'wasm-client' ,
280+ '--debuglevel=trace' ,
281+ '--namespace=' + this . _namespace ,
282+ '--localprivate=' + localKey ,
283+ '--remotepublic=' + remoteKey ,
284+ '--onlocalprivcreate=onLocalPrivCreate' ,
285+ '--onremotekeyreceive=onRemoteKeyReceive' ,
286+ '--onauthdata=onAuthData'
287+ ] ;
288+
289+ if ( this . result ) {
290+ this . go . run ( this . result . instance ) ;
291+ await WebAssembly . instantiate (
292+ this . result . module ,
293+ this . go . importObject
294+ ) ;
295+ } else {
296+ throw new Error ( "Can't find WASM instance." ) ;
301297 }
302298 }
303299
0 commit comments