Tkey generates privatekry not secp256k1

After the private creation process from Tkey is completed, I receive a privatekey. But the length of private key hex is 62 characters, it does not match the 64 standard.


    tKey.serviceProvider.postboxKey = new BN(boxKey, 16);
    await tKey.initialize();
    const { shareDescriptions } = tKey.getKeyDetails();
    let privKey: BN;
    if (shareDescriptions) {
      await (tKey.modules
        .securityQuestions as SecurityQuestionsModule).inputShareFromSecurityQuestions(
        password
      );

      const reconstructKey = await tKey.reconstructKey();
      privKey = reconstructKey.privKey;
    } else {
      const initializeNewKey = await tKey._initializeNewKey({
        initializeModules: true,
      });

      await (tKey.modules
        .securityQuestions as SecurityQuestionsModule).generateNewShareWithSecurityQuestions(
        password,
        QUESTIONS
      );
      privKey = initializeNewKey.privKey;
    }
    if (!privKey) {
      throw new Error("reconstructKey null");
    }
    return privKey;
    

@le.van.thanh.line Thanks for your patience.

Could you please try this solution: wallets - Serious problem! web3j-android EckeyPair returning Private Key length of 63 characters, not 64 - Ethereum Stack Exchange

// Sometimes TKey will generate a random number between 1 and 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141 (the range of valid private keys) and is occasionally less than 64 digits long.
// Although the key generated is of type secp256k1, ethers.Wallet will error with INVALID_ARGUMENT if the private key is less than 64 digits.
// To circumvent this issue, we add the leading zero.
function ensure64DigitPrivateKey(privateKey: string): string {
  if (privateKey.length < 64) {
    return privateKey.padStart(64, "0");
  }
  return privateKey;
}

// ...
const eoaSigner = new ethers.Wallet(
    ensure64DigitPrivateKey(privateKey)
);

Thanks, I will try.

Can you check this?

Please let me know if the solution worked for you?

It working Thanks <3

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.