tweb/public/19.9bd29eb5a3763290dbc6.chu...

1 line
22 KiB
Plaintext

{"version":3,"sources":["webpack:///./src/pages/loginPage.ts","webpack:///./src/helpers/dom/htmlToSpan.ts","webpack:///./src/components/passwordInputField.ts","webpack:///./src/components/monkeys/password.ts","webpack:///./src/pages/pagePassword.ts","webpack:///./src/lib/mtproto/passwordManager.ts"],"names":["LoginPage","options","this","element","document","body","querySelector","className","container","createElement","imageDiv","title","titleLangKey","append","subtitle","subtitleLangKey","withInputWrapper","inputWrapper","htmlToSpan","html","span","innerHTML","PasswordInputField","super","plainText","passwordVisible","onVisibilityClick","e","toggleVisible","classList","toggle","input","type","onVisibilityClickAdditional","setAttribute","name","autocomplete","stealthy","add","tabIndex","parentElement","prepend","insertBefore","cloneNode","nextSibling","addEventListener","PasswordMonkey","passwordInputField","size","needFrame","loadPromise","loadAnimationAsAsset","loop","autoplay","width","height","noCache","then","_animation","animation","currentFrame","direction","setSpeed","pause","setDirection","curFrame","play","waitForFirstFrame","remove","passwordInput","page","btnNext","btnNextI18n","IntlElement","key","label","getStateInterval","state","getState","window","setInterval","_state","hint","wrapEmojiText","setLabel","onSubmit","value","length","update","preloader","setValueSilently","Math","random","check","response","_","clearInterval","m","default","mount","monkey","removeAttribute","catch","err","select","isMobile","Promise","all","load","focus","pushToState","passwordManager","invokeApi","result","settings","currentHashPromise","newHashPromise","params","password","new_settings","email","currentPassword","invokeCrypto","resolve","newAlgo","new_algo","salt1","Uint8Array","randomize","set","newPassword","hashes","new_password_hash","inputCheckPassword","auth","setUser","user","code"],"mappings":"uFAAA,8CAQe,MAAMA,EAQnB,YAAYC,GAMVC,KAAKC,QAAUC,SAASC,KAAKC,cAAc,IAAML,EAAQM,WAIzDL,KAAKM,UAAYJ,SAASK,cAAc,OACxCP,KAAKM,UAAUD,UAAY,yBAE3BL,KAAKQ,SAAWN,SAASK,cAAc,OACvCP,KAAKQ,SAASH,UAAY,aAE1BL,KAAKS,MAAQP,SAASK,cAAc,MACjCR,EAAQ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a,kBAAoBD,EAAO,GAExC,IAAWnB,UAAU,iCAAkCK,OAK7D,MAAMC,EAAkBzC,EAAwB5E,EAAe,IACpE,OAAO,IAAWyH,aAAa,aAAcJ,EAAUzC,GAAO,GAAOpB,KAAM4E,GAElE,IAAWrB,UAAU,qBAAsB,CAChDM,SAAUe,GACTpI,GAASwD,KAAK6E,IACD,uBAAXA,EAAKvC,GACN,IAAWwC,QAAQD,EAAKE,MAGnBF,KAKN,qBAAqBG,GAC1B,OAAO,IAAWzB,UAAU,+BAAgC,CAACyB,SAGxD,sBACL,OAAO,IAAWzB,UAAU,+BAGvB,sBACL,OAAO,IAAWA,UAAU,iCAehC,IAAeD,gBAAkBA,EAClB","file":"19.9bd29eb5a3763290dbc6.chunk.js","sourcesContent":["/*\r\n * https://github.com/morethanwords/tweb\r\n * Copyright (C) 2019-2021 Eduard Kuzmenko\r\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\r\n */\r\n\r\nimport { LangPackKey, i18n } from \"../lib/langPack\";\r\n\r\nexport default class LoginPage {\r\n public element: HTMLElement;\r\n public container: HTMLElement;\r\n public imageDiv: HTMLElement;\r\n public inputWrapper: HTMLElement;\r\n public title: HTMLElement;\r\n public subtitle: HTMLParagraphElement;\r\n\r\n constructor(options: {\r\n className: string,\r\n withInputWrapper?: boolean,\r\n titleLangKey?: LangPackKey,\r\n subtitleLangKey?: LangPackKey,\r\n }) {\r\n this.element = document.body.querySelector('.' + options.className) as HTMLDivElement;\r\n //this.element = document.createElement('div');\r\n //this.element.className = 'page-' + options.className;\r\n\r\n this.container = document.createElement('div');\r\n this.container.className = 'container center-align';\r\n\r\n this.imageDiv = document.createElement('div');\r\n this.imageDiv.className = 'auth-image';\r\n\r\n this.title = document.createElement('h4');\r\n if(options.titleLangKey) {\r\n this.title.append(i18n(options.titleLangKey));\r\n }\r\n\r\n this.subtitle = document.createElement('p');\r\n this.subtitle.className = 'subtitle';\r\n if(options.subtitleLangKey) {\r\n this.subtitle.append(i18n(options.subtitleLangKey));\r\n }\r\n \r\n this.container.append(this.imageDiv, this.title, this.subtitle);\r\n\r\n if(options.withInputWrapper) {\r\n this.inputWrapper = document.createElement('div');\r\n this.inputWrapper.className = 'input-wrapper';\r\n this.container.append(this.inputWrapper);\r\n }\r\n\r\n this.element.append(this.container);\r\n }\r\n}\r\n","/*\r\n * https://github.com/morethanwords/tweb\r\n * Copyright (C) 2019-2021 Eduard Kuzmenko\r\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\r\n */\r\n\r\nexport default function htmlToSpan(html: string) {\r\n const span = document.createElement('span');\r\n span.innerHTML = html;\r\n return span;\r\n}\r\n","/*\r\n * https://github.com/morethanwords/tweb\r\n * Copyright (C) 2019-2021 Eduard Kuzmenko\r\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\r\n */\r\n\r\n// import { IS_MOBILE_SAFARI, IS_SAFARI } from \"../environment/userAgent\";\r\nimport { cancelEvent } from \"../helpers/dom/cancelEvent\";\r\nimport InputField, { InputFieldOptions } from \"./inputField\";\r\n\r\nexport default class PasswordInputField extends InputField {\r\n public passwordVisible = false;\r\n public toggleVisible: HTMLElement;\r\n public onVisibilityClickAdditional: () => void;\r\n\r\n constructor(options: InputFieldOptions = {}) {\r\n super({\r\n plainText: true,\r\n ...options\r\n });\r\n\r\n const input = this.input as HTMLInputElement;\r\n input.type = 'password';\r\n input.setAttribute('required', '');\r\n input.name = 'notsearch_password';\r\n input.autocomplete = 'off';\r\n\r\n /* if(IS_SAFARI && !IS_MOBILE_SAFARI) {\r\n input.setAttribute('readonly', '');\r\n input.addEventListener('focus', () => {\r\n input.removeAttribute('readonly');\r\n }, {once: true});\r\n } */\r\n\r\n // * https://stackoverflow.com/a/35949954/6758968\r\n const stealthy = document.createElement('input');\r\n stealthy.classList.add('stealthy');\r\n stealthy.tabIndex = -1;\r\n stealthy.type = 'password';\r\n input.parentElement.prepend(stealthy);\r\n input.parentElement.insertBefore(stealthy.cloneNode(), input.nextSibling);\r\n\r\n const toggleVisible = this.toggleVisible = document.createElement('span');\r\n toggleVisible.classList.add('toggle-visible', 'tgico');\r\n\r\n this.container.classList.add('input-field-password');\r\n this.container.append(toggleVisible);\r\n\r\n toggleVisible.addEventListener('click', this.onVisibilityClick);\r\n toggleVisible.addEventListener('touchend', this.onVisibilityClick);\r\n }\r\n\r\n public onVisibilityClick = (e: Event) => {\r\n cancelEvent(e);\r\n this.passwordVisible = !this.passwordVisible;\r\n\r\n this.toggleVisible.classList.toggle('eye-hidden', this.passwordVisible);\r\n (this.input as HTMLInputElement).type = this.passwordVisible ? 'text' : 'password';\r\n this.onVisibilityClickAdditional && this.onVisibilityClickAdditional();\r\n };\r\n}\r\n","/*\r\n * https://github.com/morethanwords/tweb\r\n * Copyright (C) 2019-2021 Eduard Kuzmenko\r\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\r\n */\r\n\r\nimport lottieLoader, { LottieLoader } from \"../../lib/rlottie/lottieLoader\";\r\nimport RLottiePlayer from \"../../lib/rlottie/rlottiePlayer\";\r\nimport PasswordInputField from \"../passwordInputField\";\r\n\r\nexport default class PasswordMonkey {\r\n public container: HTMLElement;\r\n public animation: RLottiePlayer;\r\n public needFrame = 0;\r\n protected loadPromise: ReturnType<LottieLoader['waitForFirstFrame']>;\r\n\r\n constructor(protected passwordInputField: PasswordInputField, protected size: number) {\r\n this.container = document.createElement('div');\r\n this.container.classList.add('media-sticker-wrapper');\r\n }\r\n\r\n public load() {\r\n if(this.loadPromise) return this.loadPromise;\r\n return this.loadPromise = lottieLoader.loadAnimationAsAsset({\r\n container: this.container,\r\n loop: false,\r\n autoplay: false,\r\n width: this.size,\r\n height: this.size,\r\n noCache: true\r\n //}, 'assets/img/TwoFactorSetupMonkeyClose.tgs').then(_animation => {\r\n }, 'TwoFactorSetupMonkeyPeek').then(_animation => {\r\n //return;\r\n this.animation = _animation;\r\n this.animation.addEventListener('enterFrame', currentFrame => {\r\n //console.log('enterFrame', currentFrame, this.needFrame);\r\n\r\n if((this.animation.direction === 1 && currentFrame >= this.needFrame) ||\r\n (this.animation.direction === -1 && currentFrame <= this.needFrame)) {\r\n this.animation.setSpeed(1);\r\n this.animation.pause();\r\n } \r\n });\r\n\r\n this.passwordInputField.onVisibilityClickAdditional = () => {\r\n if(this.passwordInputField.passwordVisible) {\r\n this.animation.setDirection(1);\r\n this.animation.curFrame = 0;\r\n this.needFrame = 16;\r\n this.animation.play();\r\n } else {\r\n this.animation.setDirection(-1);\r\n this.animation.curFrame = 16;\r\n this.needFrame = 0;\r\n this.animation.play();\r\n }\r\n };\r\n\r\n return lottieLoader.waitForFirstFrame(_animation);\r\n });\r\n }\r\n\r\n public remove() {\r\n if(this.animation) {\r\n this.animation.remove();\r\n }\r\n }\r\n}\r\n","/*\r\n * https://github.com/morethanwords/tweb\r\n * Copyright (C) 2019-2021 Eduard Kuzmenko\r\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\r\n */\r\n\r\nimport { putPreloader } from '../components/misc';\r\nimport mediaSizes from '../helpers/mediaSizes';\r\nimport { AccountPassword } from '../layer';\r\nimport appStateManager from '../lib/appManagers/appStateManager';\r\nimport passwordManager from '../lib/mtproto/passwordManager';\r\nimport Page from './page';\r\nimport Button from '../components/button';\r\nimport PasswordInputField from '../components/passwordInputField';\r\nimport PasswordMonkey from '../components/monkeys/password';\r\nimport RichTextProcessor from '../lib/richtextprocessor';\r\nimport I18n from '../lib/langPack';\r\nimport LoginPage from './loginPage';\r\nimport { cancelEvent } from '../helpers/dom/cancelEvent';\r\nimport { attachClickEvent } from '../helpers/dom/clickEvent';\r\nimport htmlToSpan from '../helpers/dom/htmlToSpan';\r\nimport replaceContent from '../helpers/dom/replaceContent';\r\nimport toggleDisability from '../helpers/dom/toggleDisability';\r\n\r\nconst TEST = false;\r\nlet passwordInput: HTMLInputElement;\r\n\r\nlet onFirstMount = (): Promise<any> => {\r\n const page = new LoginPage({\r\n className: 'page-password',\r\n withInputWrapper: true,\r\n titleLangKey: 'Login.Password.Title',\r\n subtitleLangKey: 'Login.Password.Subtitle'\r\n });\r\n\r\n const btnNext = Button('btn-primary btn-color-primary');\r\n const btnNextI18n = new I18n.IntlElement({key: 'Login.Next'});\r\n\r\n btnNext.append(btnNextI18n.element);\r\n\r\n const passwordInputField = new PasswordInputField({\r\n label: 'LoginPassword',\r\n name: 'password'\r\n });\r\n\r\n passwordInput = passwordInputField.input as HTMLInputElement;\r\n\r\n page.inputWrapper.append(passwordInputField.container, btnNext);\r\n\r\n let getStateInterval: number;\r\n\r\n let getState = () => {\r\n // * just to check session relevance\r\n if(!getStateInterval) {\r\n getStateInterval = window.setInterval(getState, 10e3);\r\n }\r\n\r\n return !TEST && passwordManager.getState().then(_state => {\r\n state = _state;\r\n\r\n if(state.hint) {\r\n replaceContent(passwordInputField.label, htmlToSpan(RichTextProcessor.wrapEmojiText(state.hint)));\r\n } else {\r\n passwordInputField.setLabel();\r\n }\r\n });\r\n };\r\n\r\n let state: AccountPassword;\r\n \r\n const onSubmit = (e?: Event) => {\r\n if(e) {\r\n cancelEvent(e);\r\n }\r\n\r\n if(!passwordInput.value.length) {\r\n passwordInput.classList.add('error');\r\n return;\r\n }\r\n\r\n const toggle = toggleDisability([passwordInput, btnNext], true);\r\n let value = passwordInput.value;\r\n\r\n btnNextI18n.update({key: 'PleaseWait'});\r\n const preloader = putPreloader(btnNext);\r\n\r\n passwordInputField.setValueSilently('' + Math.random()); // prevent saving suggestion\r\n passwordInputField.setValueSilently(value); // prevent saving suggestion\r\n\r\n passwordManager.check(value, state).then((response) => {\r\n //console.log('passwordManager response:', response);\r\n \r\n switch(response._) {\r\n case 'auth.authorization':\r\n clearInterval(getStateInterval);\r\n import('./pageIm').then(m => {\r\n m.default.mount();\r\n });\r\n if(monkey) monkey.remove();\r\n break;\r\n default:\r\n btnNext.removeAttribute('disabled');\r\n btnNextI18n.update({key: response._ as any});\r\n preloader.remove();\r\n break;\r\n }\r\n }).catch((err: any) => {\r\n toggle();\r\n passwordInputField.input.classList.add('error');\r\n \r\n switch(err.type) {\r\n default:\r\n //btnNext.innerText = err.type;\r\n btnNextI18n.update({key: 'PASSWORD_HASH_INVALID'});\r\n passwordInput.select();\r\n break;\r\n }\r\n\r\n preloader.remove();\r\n \r\n getState();\r\n });\r\n };\r\n \r\n attachClickEvent(btnNext, onSubmit);\r\n\r\n passwordInput.addEventListener('keypress', function(this, e) {\r\n this.classList.remove('error');\r\n btnNextI18n.update({key: 'Login.Next'});\r\n\r\n if(e.key === 'Enter') {\r\n return onSubmit();\r\n }\r\n });\r\n\r\n const size = mediaSizes.isMobile ? 100 : 166;\r\n const monkey = new PasswordMonkey(passwordInputField, size);\r\n page.imageDiv.append(monkey.container);\r\n return Promise.all([\r\n monkey.load(),\r\n getState()\r\n ]);\r\n};\r\n\r\nconst page = new Page('page-password', true, onFirstMount, null, () => {\r\n //if(!isAppleMobile) {\r\n passwordInput.focus();\r\n //}\r\n\r\n appStateManager.pushToState('authState', {_: 'authStatePassword'});\r\n});\r\n\r\nexport default page;\r\n","/*\r\n * https://github.com/morethanwords/tweb\r\n * Copyright (C) 2019-2021 Eduard Kuzmenko\r\n * https://github.com/morethanwords/tweb/blob/master/LICENSE\r\n * \r\n * Originally from:\r\n * https://github.com/zhukov/webogram\r\n * Copyright (C) 2014 Igor Zhukov <igor.beatle@gmail.com>\r\n * https://github.com/zhukov/webogram/blob/master/LICENSE\r\n */\r\n\r\nimport type { AccountPassword, AccountUpdatePasswordSettings, InputCheckPasswordSRP, PasswordKdfAlgo } from '../../layer';\r\nimport { MOUNT_CLASS_TO } from '../../config/debug';\r\nimport apiManager from './mtprotoworker';\r\n\r\nexport class PasswordManager {\r\n public getState(): Promise<AccountPassword> {\r\n return apiManager.invokeApi('account.getPassword').then((result) => {\r\n return result;\r\n });\r\n }\r\n\r\n public updateSettings(settings: {\r\n hint?: string,\r\n email?: string,\r\n newPassword?: string,\r\n currentPassword?: string\r\n } = {}) {\r\n //state = Object.assign({}, state);\r\n //state.new_algo = Object.assign({}, state.new_algo);\r\n\r\n return this.getState().then(state => {\r\n let currentHashPromise: Promise<InputCheckPasswordSRP>;\r\n let newHashPromise: Promise<Uint8Array>;\r\n const params: AccountUpdatePasswordSettings = {\r\n password: null,\r\n new_settings: {\r\n _: 'account.passwordInputSettings',\r\n hint: settings.hint,\r\n email: settings.email\r\n }\r\n };\r\n \r\n if(settings.currentPassword) {\r\n currentHashPromise = apiManager.invokeCrypto('computeSRP', settings.currentPassword, state, false) as any;\r\n } else {\r\n currentHashPromise = Promise.resolve({\r\n _: 'inputCheckPasswordEmpty'\r\n });\r\n }\r\n \r\n // * https://core.telegram.org/api/srp#setting-a-new-2fa-password, but still there is a mistake, TDesktop passes 'new_algo' everytime\r\n const newAlgo = state.new_algo as PasswordKdfAlgo.passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow;\r\n const salt1 = new Uint8Array(newAlgo.salt1.length + 32);\r\n salt1.randomize();\r\n salt1.set(newAlgo.salt1, 0);\r\n newAlgo.salt1 = salt1;\r\n \r\n if(settings.newPassword) {\r\n newHashPromise = apiManager.invokeCrypto('computeSRP', settings.newPassword, state, true) as any;\r\n } else {\r\n newHashPromise = Promise.resolve(new Uint8Array());\r\n }\r\n \r\n return Promise.all([currentHashPromise, newHashPromise]).then((hashes) => {\r\n params.password = hashes[0];\r\n params.new_settings.new_algo = newAlgo;\r\n params.new_settings.new_password_hash = hashes[1];\r\n \r\n return apiManager.invokeApi('account.updatePasswordSettings', params);\r\n });\r\n });\r\n }\r\n\r\n public check(password: string, state: AccountPassword, options: any = {}) {\r\n return apiManager.invokeCrypto('computeSRP', password, state, false).then((inputCheckPassword) => {\r\n //console.log('SRP', inputCheckPassword);\r\n return apiManager.invokeApi('auth.checkPassword', {\r\n password: inputCheckPassword as InputCheckPasswordSRP.inputCheckPasswordSRP\r\n }, options).then(auth => {\r\n if(auth._ === 'auth.authorization') {\r\n apiManager.setUser(auth.user);\r\n }\r\n\r\n return auth;\r\n });\r\n });\r\n }\r\n\r\n public confirmPasswordEmail(code: string) {\r\n return apiManager.invokeApi('account.confirmPasswordEmail', {code});\r\n }\r\n\r\n public resendPasswordEmail() {\r\n return apiManager.invokeApi('account.resendPasswordEmail');\r\n }\r\n\r\n public cancelPasswordEmail() {\r\n return apiManager.invokeApi('account.cancelPasswordEmail');\r\n }\r\n\r\n /* public requestRecovery(options: any = {}) {\r\n return apiManager.invokeApi('auth.requestPasswordRecovery', {}, options);\r\n }\r\n\r\n public recover(code: any, options: any = {}) {\r\n return apiManager.invokeApi('auth.recoverPassword', {\r\n code\r\n }, options);\r\n } */\r\n}\r\n\r\nconst passwordManager = new PasswordManager();\r\nMOUNT_CLASS_TO.passwordManager = passwordManager;\r\nexport default passwordManager;\r\n"],"sourceRoot":""}