I am building an app where I need to generate a message signed on the backend with NodeJS, something like window.solana.signMessage('hello'). I have the user's private key, I just need a signature to authenticate the user, but I cannot find how to generate it on the server.


1 Answer 1


You can use NaCl tweet library to generate the signature on the server

     // Encode anything as bytes
      const message = new TextEncoder().encode("Your message here");
     // Sign the bytes using the wallet
     const signature = await signMessage(message);

     // Verify that the bytes were signed using the private key that matches the known public key
    const result = nacl.sign.detached.verify(
    if(!result) throw new Error('Invalid signature!');

result will be true or false depending upon whether the user is signing the message using his own private key.. Hope this helps.


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.