1305144ba969d368195e8080fcf7fd1199b66fdb29e0f86b07926b3302c45dda.json raw

   1  {"ast":null,"code":"import _asyncToGenerator from \"/home/mleku/src/orly.dev/next/signer/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\nimport { inject } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { Router } from '@angular/router';\nimport { ConfirmComponent, DerivingModalComponent, LoggerService, NostrHelper, ProfileMetadataService, StartupService, StorageService } from '@common';\nimport { getNewStorageServiceConfig } from '../../common/data/get-new-storage-service-config';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"@angular/forms\";\nconst _c0 = [\"passwordInputElement\"];\nconst _c1 = [\"derivingModal\"];\nfunction VaultLoginComponent_Conditional_24_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"div\", 19)(1, \"div\", 20);\n    i0.ɵɵelement(2, \"i\", 21);\n    i0.ɵɵelementStart(3, \"span\");\n    i0.ɵɵtext(4, \"Invalid password\");\n    i0.ɵɵelementEnd()()();\n  }\n}\nexport let VaultLoginComponent = /*#__PURE__*/(() => {\n  class VaultLoginComponent {\n    passwordInput;\n    derivingModal;\n    loginPassword = '';\n    showInvalidPasswordAlert = false;\n    #storage = inject(StorageService);\n    router = inject(Router);\n    #startup = inject(StartupService);\n    #profileMetadata = inject(ProfileMetadataService);\n    #logger = inject(LoggerService);\n    ngAfterViewInit() {\n      this.passwordInput.nativeElement.focus();\n    }\n    toggleType(element) {\n      if (element.type === 'password') {\n        element.type = 'text';\n      } else {\n        element.type = 'password';\n      }\n    }\n    loginVault() {\n      var _this = this;\n      return _asyncToGenerator(function* () {\n        console.log('[login] loginVault called');\n        if (!_this.loginPassword) {\n          console.log('[login] No password, returning');\n          return;\n        }\n        console.log('[login] Showing deriving modal');\n        // Show deriving modal during key derivation (~3-6 seconds)\n        _this.derivingModal.show('Unlocking vault');\n        try {\n          console.log('[login] Calling unlockVault...');\n          yield _this.#storage.unlockVault(_this.loginPassword);\n          console.log('[login] unlockVault succeeded!');\n        } catch (error) {\n          console.error('[login] unlockVault FAILED:', error);\n          _this.derivingModal.hide();\n          _this.showInvalidPasswordAlert = true;\n          window.setTimeout(() => {\n            _this.showInvalidPasswordAlert = false;\n          }, 2000);\n          return;\n        }\n        // Unlock succeeded - hide modal and navigate\n        console.log('[login] Hiding modal and navigating');\n        _this.derivingModal.hide();\n        _this.#logger.logVaultUnlock();\n        // Fetch profile metadata for all identities in the background\n        _this.#fetchAllProfiles();\n        _this.router.navigateByUrl('/home/identity');\n      })();\n    }\n    /**\n     * Fetch profile metadata for all identities (runs in background)\n     */\n    #fetchAllProfiles() {\n      var _this2 = this;\n      return _asyncToGenerator(function* () {\n        try {\n          const identities = _this2.#storage.getBrowserSessionHandler().browserSessionData?.identities ?? [];\n          if (identities.length === 0) {\n            return;\n          }\n          // Get all pubkeys from identities\n          const pubkeys = identities.map(identity => NostrHelper.pubkeyFromPrivkey(identity.privkey));\n          // Fetch all profiles in parallel\n          yield _this2.#profileMetadata.fetchProfiles(pubkeys);\n        } catch (error) {\n          console.error('Failed to fetch profiles:', error);\n        }\n      })();\n    }\n    onClickResetExtension() {\n      var _this3 = this;\n      return _asyncToGenerator(function* () {\n        try {\n          _this3.#logger.logVaultReset();\n          yield _this3.#storage.resetExtension();\n          _this3.#startup.startOver(getNewStorageServiceConfig());\n        } catch (error) {\n          console.log(error);\n          // TODO\n        }\n      })();\n    }\n    static ɵfac = function VaultLoginComponent_Factory(__ngFactoryType__) {\n      return new (__ngFactoryType__ || VaultLoginComponent)();\n    };\n    static ɵcmp = /*@__PURE__*/i0.ɵɵdefineComponent({\n      type: VaultLoginComponent,\n      selectors: [[\"app-vault-login\"]],\n      viewQuery: function VaultLoginComponent_Query(rf, ctx) {\n        if (rf & 1) {\n          i0.ɵɵviewQuery(_c0, 5);\n          i0.ɵɵviewQuery(_c1, 5);\n        }\n        if (rf & 2) {\n          let _t;\n          i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.passwordInput = _t.first);\n          i0.ɵɵqueryRefresh(_t = i0.ɵɵloadQuery()) && (ctx.derivingModal = _t.first);\n        }\n      },\n      decls: 27,\n      vars: 7,\n      consts: [[\"derivingModal\", \"\"], [\"passwordInputElement\", \"\"], [\"confirm\", \"\"], [1, \"sam-text-header\"], [1, \"brand\"], [1, \"content-login-vault\"], [1, \"sam-flex-column\", \"gap\", 2, \"align-items\", \"center\"], [1, \"logo-frame\"], [\"src\", \"logo.svg\", \"height\", \"120\", \"width\", \"120\", \"alt\", \"\"], [1, \"sam-mt-2\", \"input-group\"], [\"type\", \"password\", \"placeholder\", \"vault password\", 1, \"form-control\", 3, \"ngModelChange\", \"keyup.enter\", \"ngModel\"], [\"type\", \"button\", 1, \"btn\", \"btn-outline-secondary\", 3, \"click\"], [1, \"bi\", \"bi-eye\"], [\"type\", \"button\", 1, \"sam-mt\", \"btn\", \"btn-primary\", 3, \"click\", \"disabled\"], [1, \"sam-flex-row\", \"gap-h\"], [1, \"bi\", \"bi-box-arrow-in-right\"], [1, \"bottom-links\"], [\"type\", \"button\", 1, \"link-btn\", 3, \"click\"], [\"type\", \"button\", 1, \"link-btn\", \"danger\", 3, \"click\"], [2, \"position\", \"absolute\", \"bottom\", \"0\", \"align-self\", \"center\"], [\"role\", \"alert\", 1, \"alert\", \"alert-danger\", \"sam-flex-row\", \"gap\"], [1, \"bi\", \"bi-exclamation-triangle\"]],\n      template: function VaultLoginComponent_Template(rf, ctx) {\n        if (rf & 1) {\n          const _r1 = i0.ɵɵgetCurrentView();\n          i0.ɵɵelement(0, \"app-deriving-modal\", null, 0);\n          i0.ɵɵelementStart(2, \"div\", 3)(3, \"span\", 4);\n          i0.ɵɵtext(4, \"Smesh Signer\");\n          i0.ɵɵelementEnd()();\n          i0.ɵɵelementStart(5, \"div\", 5)(6, \"div\", 6)(7, \"div\", 7);\n          i0.ɵɵelement(8, \"img\", 8);\n          i0.ɵɵelementEnd();\n          i0.ɵɵelementStart(9, \"div\", 9)(10, \"input\", 10, 1);\n          i0.ɵɵtwoWayListener(\"ngModelChange\", function VaultLoginComponent_Template_input_ngModelChange_10_listener($event) {\n            i0.ɵɵrestoreView(_r1);\n            i0.ɵɵtwoWayBindingSet(ctx.loginPassword, $event) || (ctx.loginPassword = $event);\n            return i0.ɵɵresetView($event);\n          });\n          i0.ɵɵlistener(\"keyup.enter\", function VaultLoginComponent_Template_input_keyup_enter_10_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.loginPassword && ctx.loginVault());\n          });\n          i0.ɵɵelementEnd();\n          i0.ɵɵelementStart(12, \"button\", 11);\n          i0.ɵɵlistener(\"click\", function VaultLoginComponent_Template_button_click_12_listener() {\n            i0.ɵɵrestoreView(_r1);\n            const passwordInputElement_r2 = i0.ɵɵreference(11);\n            return i0.ɵɵresetView(ctx.toggleType(passwordInputElement_r2));\n          });\n          i0.ɵɵelement(13, \"i\", 12);\n          i0.ɵɵelementEnd()();\n          i0.ɵɵelementStart(14, \"button\", 13);\n          i0.ɵɵlistener(\"click\", function VaultLoginComponent_Template_button_click_14_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.loginVault());\n          });\n          i0.ɵɵelementStart(15, \"div\", 14);\n          i0.ɵɵelement(16, \"i\", 15);\n          i0.ɵɵelementStart(17, \"span\");\n          i0.ɵɵtext(18, \"Sign in\");\n          i0.ɵɵelementEnd()()()()();\n          i0.ɵɵelementStart(19, \"div\", 16)(20, \"button\", 17);\n          i0.ɵɵlistener(\"click\", function VaultLoginComponent_Template_button_click_20_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.router.navigateByUrl(\"/vault-import\"));\n          });\n          i0.ɵɵtext(21, \" Import a different vault \");\n          i0.ɵɵelementEnd();\n          i0.ɵɵelementStart(22, \"button\", 18);\n          i0.ɵɵlistener(\"click\", function VaultLoginComponent_Template_button_click_22_listener() {\n            i0.ɵɵrestoreView(_r1);\n            const confirm_r3 = i0.ɵɵreference(26);\n            return i0.ɵɵresetView(confirm_r3.show(\"Do you really want to reset the extension? All data will be lost.\", ctx.onClickResetExtension.bind(ctx)));\n          });\n          i0.ɵɵtext(23, \" Reset Extension \");\n          i0.ɵɵelementEnd()();\n          i0.ɵɵtemplate(24, VaultLoginComponent_Conditional_24_Template, 5, 0, \"div\", 19);\n          i0.ɵɵelement(25, \"lib-confirm\", null, 2);\n        }\n        if (rf & 2) {\n          const passwordInputElement_r2 = i0.ɵɵreference(11);\n          i0.ɵɵadvance(10);\n          i0.ɵɵtwoWayProperty(\"ngModel\", ctx.loginPassword);\n          i0.ɵɵadvance(3);\n          i0.ɵɵclassProp(\"bi-eye\", passwordInputElement_r2.type === \"password\")(\"bi-eye-slash\", passwordInputElement_r2.type === \"text\");\n          i0.ɵɵadvance();\n          i0.ɵɵproperty(\"disabled\", !ctx.loginPassword);\n          i0.ɵɵadvance(10);\n          i0.ɵɵconditional(ctx.showInvalidPasswordAlert ? 24 : -1);\n        }\n      },\n      dependencies: [FormsModule, i1.DefaultValueAccessor, i1.NgControlStatus, i1.NgModel, ConfirmComponent, DerivingModalComponent],\n      styles: [\"[_nghost-%COMP%] {\\n  height: 100%;\\n  display: flex;\\n  flex-direction: column;\\n  justify-items: center;\\n  position: relative;\\n}\\n[_nghost-%COMP%]   .content-login-vault[_ngcontent-%COMP%] {\\n  display: flex;\\n  flex-direction: column;\\n  height: 100%;\\n  justify-content: center;\\n  padding: 0 var(--size) var(--size) var(--size);\\n}\\n[_nghost-%COMP%]   .bottom-links[_ngcontent-%COMP%] {\\n  position: absolute;\\n  bottom: var(--size);\\n  left: var(--size);\\n  right: var(--size);\\n  display: flex;\\n  justify-content: space-between;\\n}\\n[_nghost-%COMP%]   .link-btn[_ngcontent-%COMP%] {\\n  background: transparent;\\n  border: none;\\n  color: var(--muted-foreground);\\n  font-size: 0.75rem;\\n  cursor: pointer;\\n  padding: 4px 8px;\\n}\\n[_nghost-%COMP%]   .link-btn[_ngcontent-%COMP%]:hover {\\n  color: var(--foreground);\\n  text-decoration: underline;\\n}\\n[_nghost-%COMP%]   .link-btn.danger[_ngcontent-%COMP%]:hover {\\n  color: var(--destructive);\\n}\"]\n    });\n  }\n  return VaultLoginComponent;\n})();","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}