mtcute/packages/client/src/methods/pasword/remove-cloud-password.ts

32 lines
895 B
TypeScript
Raw Normal View History

2021-05-09 14:35:47 +03:00
import { TelegramClient } from '../../client'
2021-08-05 20:38:24 +03:00
import { MtArgumentError } from '../../types'
import { computeSrpParams } from '@mtcute/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,
password: string
2021-05-09 14:35:47 +03:00
): Promise<void> {
const pwd = await this.call({ _: 'account.getPassword' })
if (!pwd.hasPassword)
2021-08-05 20:38:24 +03:00
throw new MtArgumentError('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),
hint: '',
},
2021-05-09 14:35:47 +03:00
})
}