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
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
-
Sorry my question was not detailed enough. We use NodeJS on the server. I am able to find the source code via github.com/solana-labs/solana/blob/master/keygen/src/keygen.rs, but I am looking for the javascript version of this Commented Sep 15, 2022 at 14:32
-