2021-05-09 14:35:47 +03:00
|
|
|
import { TelegramClient } from '../../client'
|
2021-07-25 21:03:40 +03:00
|
|
|
import { MtqtArgumentError } from '../../types'
|
|
|
|
import { computeSrpParams } from '@mtqt/core'
|
2021-05-09 14:35:47 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove 2FA password from your account
|
|
|
|
*
|
|
|
|
* @param password 2FA password as plaintext
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
export async function removeCloudPassword(
|
|
|
|
this: TelegramClient,
|
2021-06-06 15:20:41 +03:00
|
|
|
password: string
|
2021-05-09 14:35:47 +03:00
|
|
|
): Promise<void> {
|
|
|
|
const pwd = await this.call({ _: 'account.getPassword' })
|
|
|
|
if (!pwd.hasPassword)
|
2021-07-25 21:03:40 +03:00
|
|
|
throw new MtqtArgumentError('Cloud password is not enabled')
|
2021-05-09 14:35:47 +03:00
|
|
|
|
|
|
|
const oldSrp = await computeSrpParams(this._crypto, pwd, password)
|
|
|
|
|
|
|
|
await this.call({
|
|
|
|
_: 'account.updatePasswordSettings',
|
|
|
|
password: oldSrp,
|
|
|
|
newSettings: {
|
|
|
|
_: 'account.passwordInputSettings',
|
|
|
|
newAlgo: { _: 'passwordKdfAlgoUnknown' },
|
|
|
|
newPasswordHash: Buffer.alloc(0),
|
2021-06-06 15:20:41 +03:00
|
|
|
hint: '',
|
|
|
|
},
|
2021-05-09 14:35:47 +03:00
|
|
|
})
|
|
|
|
}
|