mtcute/packages/client/src/methods/pasword/remove-cloud-password.ts
2021-07-25 21:03:40 +03:00

31 lines
897 B
TypeScript

import { TelegramClient } from '../../client'
import { MtqtArgumentError } from '../../types'
import { computeSrpParams } from '@mtqt/core'
/**
* Remove 2FA password from your account
*
* @param password 2FA password as plaintext
* @internal
*/
export async function removeCloudPassword(
this: TelegramClient,
password: string
): Promise<void> {
const pwd = await this.call({ _: 'account.getPassword' })
if (!pwd.hasPassword)
throw new MtqtArgumentError('Cloud password is not enabled')
const oldSrp = await computeSrpParams(this._crypto, pwd, password)
await this.call({
_: 'account.updatePasswordSettings',
password: oldSrp,
newSettings: {
_: 'account.passwordInputSettings',
newAlgo: { _: 'passwordKdfAlgoUnknown' },
newPasswordHash: Buffer.alloc(0),
hint: '',
},
})
}