Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How to derive KeyPair from private key hex? #6

Open
Halimao opened this issue Aug 14, 2024 · 0 comments
Open

[Question] How to derive KeyPair from private key hex? #6

Halimao opened this issue Aug 14, 2024 · 0 comments

Comments

@Halimao
Copy link

Halimao commented Aug 14, 2024

I have exported from OKX web3 wallet and got a private key hex string with length 64.

How can I derive my account from this private key hex string?

Image the value of private key string named privKey is a3f1c2d4e5b67890abcdef1234567890abcdef1234567890abcdef1234567890


I have tried keyPairFromSecretKey and keyPairFromSeed, but both don't work.

const keyPair = keyPairFromSecretKey(Buffer.from(privKey, 'hex'));

this will cause

// Error: bad secret key size
    at nacl.sign.keyPair.fromSecretKey

keyPairFromSeed(Buffer.from(privKey, 'hex'));
const workchain = 0;
const wallet = WalletContractV4.create({
      workchain,
      publicKey: keyPair.publicKey,
 });
console.log(wallet.address);

This won't cause error, but got a different address from OKX wallet shows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant