1

a quick beginner's question... is it possible to sign a message twice with web3? For example Alice creates a message and signs it. Then it is sent to Bob. Can Bob sign the message before he executes the transaction to make sure that the message was accepted by both of them?

Thanks a lot!

1
  • You can always sign a message multiple times. What do you want to do with the signatures?
    – Ismael
    Commented Feb 4, 2019 at 7:47

2 Answers 2

1

Just take the signed message of Alice and use it as a message to sign by Bob

var alice_signature;
var message = "Some Text ";
web3.personal.sign( web3.fromUtf8( message), <Alice> , function( err, signature ) {
      alice_signature = signature;
      send_to_bob(signature,message);
})

And then, for example

var message = message_from_alice + signature_from alice
web3.personal.sign( web3.fromUtf8( message ), <Bob> , function( err, signature ) {
      console.log(signature);
})
4
  • With resulting signature you cannot verify the message was signed by alice.
    – Ismael
    Commented Feb 4, 2019 at 7:45
  • 1
    @Ismael why not?
    – P_F
    Commented Feb 4, 2019 at 11:05
  • @Ismael what? Yes you can! You can verify a signature with the recover functionality in web3js, even in solidity web3js.readthedocs.io/en/1.0/web3-eth-accounts.html#recover, and you can verify that Alice signed the message if you have bob_signature and bob_message, as alice_message and alice_signature are both inside bob_message
    – waytosay
    Commented Feb 4, 2019 at 12:47
  • @P_F If you call recover with last signature and message you will recover Bob address. With message_from_alice and signature_from_alice you will recover Alice address. But you are using two different messages.
    – Ismael
    Commented Feb 4, 2019 at 19:56
0
        {
            const message = "Hello, world!"
            const messageHash = ethers.utils.solidityKeccak256(["string"], [message])
            const messageHashBinary = ethers.utils.arrayify(messageHash)
            const signature = await signer.signMessage(messageHashBinary)
            const verified = ethers.utils.verifyMessage(messageHashBinary, signature)

            console.log("Signer: ", signer.address)
            console.log("Original MSGHash: \n", messageHash, "Binary: \n", messageHashBinary)
            console.log("Original signature: \n", signature)
            console.log("Verified with signer: \n", verified, "\n")

            const newmessage = signature + message
            const newMessageHash = ethers.utils.solidityKeccak256(["string"], [newmessage])
            const newMessageHashBinary = ethers.utils.arrayify(newMessageHash)
            const newSignature = await wrongSigner.signMessage(newMessageHashBinary)
            const newVerified = ethers.utils.verifyMessage(newMessageHashBinary, newSignature)

            console.log("Wrong Signer: ", wrongSigner.address)
            console.log("New MSGHash: \n", newMessageHash, "Binary: \n", newMessageHashBinary)
            console.log("New signature: \n", newSignature)
            console.log("Verified with wrongSigner: \n", newVerified, "\n")
        }

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.