@tkey/core sdk generating odd length private key

Please provide the following details too when asking for help in this category:

  • SDK Version:
  • Verifier Details:
    • Verifier Name:
    • JWKS Endpoint:
    • Sample idToken(JWT)

I tried to use node-sfa sdk to create a private key for a user by passing the JWT from my backend to the node-sfa sdk as done here in this latest node-sfa sdk at https://github.com/Web3Auth/web3auth-core-kit-examples/tree/main/node-sdk/node-backend-example

I then use this private key to initialize tKey and generate another private key. But
What i have observed is sometimes i am getting 63 characters long private key and sometimes i get full 64 character long private key from this sdk. We found a workaround by appending ‘0’ at the beginning of those keys to be used . Is this the correct approach to handle this ? Can there be cases where a previously 64 character private key can somehow lose 1 character and come out to be 63 character private key ?

Why is there discrepancy in the functioning of tKey like this ?

@abhisheksagu Can you try the below solution:

// 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)
);```

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