Signing issue using nacl
Nagaraj007 opened this issue · 2 comments
I am generating new key pair its working,But when i try to use signing function its throws the error Uncaught Error: bad secret key size
//Generate new keyPair
function generateNewKeyPair(menomic)
{
var Password=""
const wallet = HDWallet.fromMnemonic(menomic);
var publickey=wallet.getPublicKey(0)
var seceretkey=wallet.getSecret(0)
var keyPair=wallet.getKeypair(0);
signTransaction(keyPair.rawSecretKey(),publickey);
}
//signTransaction
function signTransaction(seceretkey,publicKey)
{
var data = 'data to sign';
var signature = steller.sign(data,seceretkey);
if (steller.verify(data, signature,publicKey)) {
console.log('OK!');
} else {
console.log('Bad signature!');
}
}
generateNewKeyPair();
so looks like the bad signature problem is because the verify call expects publicKey to be a Buffer but above it's passed as a string. see stellar-base signing.js.
an easier way is to use the Keypair sign and verify instead. can just do this without extracting the public key:
keypair.sign(data)
keypair.verify(data, sig)
api here https://stellar.github.io/js-stellar-sdk/Keypair.html#sign