{"ast":null,"code":"import _asyncToGenerator from \"/home/mleku/src/orly.dev/next/signer/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { inject } from '@angular/core';\nimport { FormsModule } from '@angular/forms';\nimport { Router } from '@angular/router';\nimport { NavComponent, NostrHelper, StorageService } from '@common';\nimport { generateSecretKey } from 'nostr-tools';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport * as i0 from \"@angular/core\";\nimport * as i1 from \"@angular/forms\";\nfunction NewIdentityComponent_Conditional_17_Template(rf, ctx) {\n  if (rf & 1) {\n    i0.ɵɵelementStart(0, \"div\", 12)(1, \"div\", 13);\n    i0.ɵɵelement(2, \"i\", 14);\n    i0.ɵɵelementStart(3, \"span\");\n    i0.ɵɵtext(4);\n    i0.ɵɵelementEnd()()();\n  }\n  if (rf & 2) {\n    const ctx_r2 = i0.ɵɵnextContext();\n    i0.ɵɵadvance(4);\n    i0.ɵɵtextInterpolate(ctx_r2.alertMessage);\n  }\n}\nexport let NewIdentityComponent = /*#__PURE__*/(() => {\n  class NewIdentityComponent extends NavComponent {\n    identity = {\n      nick: '',\n      privkeyInput: ''\n    };\n    canSave = false;\n    alertMessage;\n    #storage = inject(StorageService);\n    #router = inject(Router);\n    ngAfterViewInit() {\n      document.getElementById('nickElement')?.focus();\n    }\n    toggleType(element) {\n      if (element.type === 'password') {\n        element.type = 'text';\n      } else {\n        element.type = 'password';\n      }\n    }\n    onClickGeneratePrivkey() {\n      const sk = generateSecretKey();\n      const privkey = bytesToHex(sk);\n      this.identity.privkeyInput = NostrHelper.privkey2nsec(privkey);\n      this.validateCanSave();\n    }\n    validateCanSave() {\n      if (!this.identity.nick || !this.identity.privkeyInput) {\n        this.canSave = false;\n        return;\n      }\n      try {\n        NostrHelper.getNostrPrivkeyObject(this.identity.privkeyInput.toLocaleLowerCase());\n        this.canSave = true;\n      } catch (error) {\n        console.log(error);\n        this.canSave = false;\n      }\n    }\n    onClickSave() {\n      var _this = this;\n      return _asyncToGenerator(function* () {\n        if (!_this.canSave) {\n          return;\n        }\n        if (!_this.identity.nick || !_this.identity.privkeyInput) {\n          return;\n        }\n        try {\n          yield _this.#storage.addIdentity({\n            nick: _this.identity.nick,\n            privkeyString: _this.identity.privkeyInput\n          });\n          _this.#router.navigateByUrl('/home/identities');\n        } catch (error) {\n          _this.alertMessage = error?.message;\n          setTimeout(() => {\n            _this.alertMessage = undefined;\n          }, 4500);\n        }\n      })();\n    }\n    static ɵfac = /*@__PURE__*/(() => {\n      let ɵNewIdentityComponent_BaseFactory;\n      return function NewIdentityComponent_Factory(__ngFactoryType__) {\n        return (ɵNewIdentityComponent_BaseFactory || (ɵNewIdentityComponent_BaseFactory = i0.ɵɵgetInheritedFactory(NewIdentityComponent)))(__ngFactoryType__ || NewIdentityComponent);\n      };\n    })();\n    static ɵcmp = /*@__PURE__*/i0.ɵɵdefineComponent({\n      type: NewIdentityComponent,\n      selectors: [[\"app-new-identity\"]],\n      features: [i0.ɵɵInheritDefinitionFeature],\n      decls: 18,\n      vars: 8,\n      consts: [[\"privkeyInputElement\", \"\"], [1, \"sam-text-header\"], [1, \"content\"], [\"id\", \"nickElement\", \"type\", \"text\", \"placeholder\", \"Nick\", \"autocomplete\", \"off\", 1, \"form-control\", \"form-control-lg\", 2, \"font-size\", \"1rem\", 3, \"ngModelChange\", \"ngModel\"], [1, \"sam-mt\", \"input-group\", \"mb-3\"], [\"id\", \"privkeyInputElement\", \"type\", \"password\", \"placeholder\", \"Private Key (HEX or NSEC)\", \"autocomplete\", \"off\", 1, \"form-control\", \"form-control-lg\", 2, \"font-size\", \"1rem\", 3, \"ngModelChange\", \"ngModel\"], [\"type\", \"button\", 1, \"btn\", \"btn-outline-secondary\", 3, \"click\"], [1, \"bi\", \"bi-eye\"], [\"type\", \"button\", 1, \"btn\", \"btn-link\", 3, \"click\"], [1, \"sam-footer-grid-2\"], [\"type\", \"button\", 1, \"btn\", \"btn-secondary\", 3, \"click\"], [\"type\", \"button\", 1, \"btn\", \"btn-primary\", 3, \"click\", \"disabled\"], [2, \"position\", \"absolute\", \"bottom\", \"60px\", \"align-self\", \"center\", \"margin-left\", \"16px\", \"margin-right\", \"16px\"], [\"role\", \"alert\", 1, \"alert\", \"alert-danger\", \"sam-flex-row\", \"gap\"], [1, \"bi\", \"bi-exclamation-triangle\"]],\n      template: function NewIdentityComponent_Template(rf, ctx) {\n        if (rf & 1) {\n          const _r1 = i0.ɵɵgetCurrentView();\n          i0.ɵɵelementStart(0, \"div\", 1)(1, \"span\");\n          i0.ɵɵtext(2, \"New Identity\");\n          i0.ɵɵelementEnd()();\n          i0.ɵɵelementStart(3, \"div\", 2)(4, \"input\", 3);\n          i0.ɵɵtwoWayListener(\"ngModelChange\", function NewIdentityComponent_Template_input_ngModelChange_4_listener($event) {\n            i0.ɵɵrestoreView(_r1);\n            i0.ɵɵtwoWayBindingSet(ctx.identity.nick, $event) || (ctx.identity.nick = $event);\n            return i0.ɵɵresetView($event);\n          });\n          i0.ɵɵlistener(\"ngModelChange\", function NewIdentityComponent_Template_input_ngModelChange_4_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.validateCanSave());\n          });\n          i0.ɵɵelementEnd();\n          i0.ɵɵelementStart(5, \"div\", 4)(6, \"input\", 5, 0);\n          i0.ɵɵtwoWayListener(\"ngModelChange\", function NewIdentityComponent_Template_input_ngModelChange_6_listener($event) {\n            i0.ɵɵrestoreView(_r1);\n            i0.ɵɵtwoWayBindingSet(ctx.identity.privkeyInput, $event) || (ctx.identity.privkeyInput = $event);\n            return i0.ɵɵresetView($event);\n          });\n          i0.ɵɵlistener(\"ngModelChange\", function NewIdentityComponent_Template_input_ngModelChange_6_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.validateCanSave());\n          });\n          i0.ɵɵelementEnd();\n          i0.ɵɵelementStart(8, \"button\", 6);\n          i0.ɵɵlistener(\"click\", function NewIdentityComponent_Template_button_click_8_listener() {\n            i0.ɵɵrestoreView(_r1);\n            const privkeyInputElement_r2 = i0.ɵɵreference(7);\n            return i0.ɵɵresetView(ctx.toggleType(privkeyInputElement_r2));\n          });\n          i0.ɵɵelement(9, \"i\", 7);\n          i0.ɵɵelementEnd()();\n          i0.ɵɵelementStart(10, \"button\", 8);\n          i0.ɵɵlistener(\"click\", function NewIdentityComponent_Template_button_click_10_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.onClickGeneratePrivkey());\n          });\n          i0.ɵɵtext(11, \" Generate private key \");\n          i0.ɵɵelementEnd()();\n          i0.ɵɵelementStart(12, \"div\", 9)(13, \"button\", 10);\n          i0.ɵɵlistener(\"click\", function NewIdentityComponent_Template_button_click_13_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.navigateBack());\n          });\n          i0.ɵɵtext(14, \" Cancel \");\n          i0.ɵɵelementEnd();\n          i0.ɵɵelementStart(15, \"button\", 11);\n          i0.ɵɵlistener(\"click\", function NewIdentityComponent_Template_button_click_15_listener() {\n            i0.ɵɵrestoreView(_r1);\n            return i0.ɵɵresetView(ctx.onClickSave());\n          });\n          i0.ɵɵtext(16, \" Save \");\n          i0.ɵɵelementEnd()();\n          i0.ɵɵtemplate(17, NewIdentityComponent_Conditional_17_Template, 5, 1, \"div\", 12);\n        }\n        if (rf & 2) {\n          const privkeyInputElement_r2 = i0.ɵɵreference(7);\n          i0.ɵɵadvance(4);\n          i0.ɵɵtwoWayProperty(\"ngModel\", ctx.identity.nick);\n          i0.ɵɵadvance(2);\n          i0.ɵɵtwoWayProperty(\"ngModel\", ctx.identity.privkeyInput);\n          i0.ɵɵadvance(3);\n          i0.ɵɵclassProp(\"bi-eye\", privkeyInputElement_r2.type === \"password\")(\"bi-eye-slash\", privkeyInputElement_r2.type === \"text\");\n          i0.ɵɵadvance(6);\n          i0.ɵɵproperty(\"disabled\", !ctx.canSave);\n          i0.ɵɵadvance(2);\n          i0.ɵɵconditional(ctx.alertMessage ? 17 : -1);\n        }\n      },\n      dependencies: [FormsModule, i1.DefaultValueAccessor, i1.NgControlStatus, i1.NgModel],\n      styles: [\"[_nghost-%COMP%] {\\n  height: 100%;\\n  display: flex;\\n  flex-direction: column;\\n}\\n[_nghost-%COMP%]   .content[_ngcontent-%COMP%] {\\n  padding-left: var(--size);\\n  padding-right: var(--size);\\n  flex-grow: 1;\\n  display: flex;\\n  flex-direction: column;\\n}\"]\n    });\n  }\n  return NewIdentityComponent;\n})();","map":null,"metadata":{},"sourceType":"module","externalDependencies":[]}