Giter Site home page Giter Site logo

Comments (3)

MyZest avatar MyZest commented on June 18, 2024
import bigInt from 'big-integer';
import {
  concatBytes,
  bytesToBigInt,
} from '@mtproto/core/src/utils/common/index.js';
import crypto from 'crypto';

export async function getVParams(api, password) {
  const getPasswordConf = await api.call('account.getPassword');
  const { new_algo = {} } = getPasswordConf;

  const {
    g, p, salt1, salt2 
  } = new_algo;

  const SH = (data, salt) => {
    const hash = crypto.createHash('sha256');
    hash.update(concatBytes(salt, data, salt));
    return hash.digest();
  };

  const PH1 = (password, salt1, salt2) => {
    const hash1 = SH(SH(password, salt1), salt2);
    return hash1;
  };

  const PH2 = (password, salt1, salt2) => {
    const ph1Result = PH1(password, salt1, salt2);
    const pbkdf2Result = crypto.pbkdf2Sync(
      ph1Result,
      salt1,
      100000,
      32,
      'sha256'
    );
    return SH(pbkdf2Result, salt2);
  };

  const encoder = new TextEncoder();

  const gBigInt = bigInt(g);
  const pBigInt = bytesToBigInt(p);
  const x = PH2(encoder.encode(password), salt1, salt2);
  const xBigInt = bytesToBigInt(x);
  const vBigInt = gBigInt.modPow(xBigInt, pBigInt);
  console.log('vBigInt:', vBigInt);
  const new_password_hash = crypto
    .createHash('sha256')
    .update(vBigInt.toString())
    .digest();
  // 将 Buffer 转换为 Uint8Array
  const new_password_hash_uint8 = new Uint8Array(new_password_hash.buffer);
  console.log('new_password_hash:', new_password_hash);
  return {
    ...getPasswordConf,
    new_password_hash: new_password_hash_uint8,
  };
}

from mtproto-core.

MyZest avatar MyZest commented on June 18, 2024

{
"code": 400,
"msg": "NEW_SALT_INVALID"
}
or
{
"code": 400,
"msg": "NEW_PASSWORD_BAD"
}

from mtproto-core.

MyZest avatar MyZest commented on June 18, 2024

please help me

from mtproto-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.