how can the solana contract verify that this signed message and the address are matched
how can the solana contract verify that this signed message and the address are matched
Loading saved threads...
carl · External communityPost link
External question — Solana Stack Exchange
Author: carl
Original post: https://solana.stackexchange.com/questions/16176
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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?"
Quote
Report
Effe2 · External communityPost link
External answer — Solana Stack Exchange
Author: Effe2
Original post: https://solana.stackexchange.com/a/16179
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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)
Quote
Report
Jon C · External communityPost link
External answer — Solana Stack Exchange
Author: Jon C
Original post: https://solana.stackexchange.com/a/16229
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
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
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Solana Stack Exchange Author: Jon C Source score (net votes, not local likes): 0 Original post: https://solana.stackexchange.com/a/16229 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. 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
Checking account access…