1

If we have both a wallet address and private key, what is the best way to determine if the private key is indeed corresponding to the wallet address using a NodeJS server. Is the best way to sign a message with private key and verify the signature with public key, or is there a better way?

1 Answer 1

1

Using solana-keygen cli tool you can verify by running this,

solana-keygen verify <walletPublickey> path_to_wallet/keypair.json

Yes, we sign a message with a private key and verify the signature with public key.

In NodeJs:-

Solana web3 package has a Keypair class using that one can verify a secret belongs to a publicKey or not.

const { Keypair } = require('@solana/web3.js');

const data = require('path_to_keypair.json'); // this is just an array, need to create a Uint8 array

const secretKey = new Uint8Array(data);
let account = Keypair.fromSecretKey(secretKey);

console.log(account.publicKey.toBase58()); // publicKey 
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.