1

I have signed a message using solana/web3.js. How can I verify in a contract that this signed message and the address are matched?

const web3 = require('@solana/web3.js'); const messageBuffer = Buffer.from('testMessage'); const signature = nacl.sign.detached(messageBuffer, keypair.secretKey); const base58String = bs58.encode(signature);

"How can the contract verify that this signed message and the address are matched?"

2 Answers 2

0

you don't need to check it in a program, you can check it in javascript :

const message = new TextEncoder().encode("testMessage")
const uint8arraySignature = base58.decode(signature);

const walletIsSigner = nacl.sign.detached.verify(
    message,
    uint8arraySignature,
    publicKey.toBuffer()
  )

as far as i know messages are not meant to be sent to the blockchain (thus are not meant to be checked in a program)

0

You can use the ed25519 program to verify additional signatures in your transaction. You can create an instruction simply doing the following:

let ix = new_ed25519_instruction(keypair, "testMessage");

And then you can add it to a transaction. When the node receives your transaction, it will check that the keypair correctly signed that message. For another contract to use that information, however, it will need to use the "instructions" sysvar and read the instruction data from there.

More information at https://docs.solanalabs.com/runtime/programs#ed25519-program and https://github.com/anza-xyz/agave/blob/164d37c526ba46cffed765416344013e2c1807c7/sdk/src/ed25519_instruction.rs#L37 and https://docs.solanalabs.com/implemented-proposals/instruction_introspection

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.