<p>You can find functions for message signing and signature checking in packacke <code>plutus-ledger</code>, module <code>Ledger.Oracle</code>.
Also, why whould you need a smart contract for this?</p>

CC BY-SA 4.0
2021-07-22T12:39:00.113Z
2021-07-22T12:39:00.113Z
Lars Brünjes
<p>I want to use my private key to sign a message, and submit the message and signatures to third party server, the third party server can verify that signatures through plutus smartcontract.
In ethereum eth_sign can achieve this, the smartcontract side have a method to recover address related to the oringal signing private key:</p>
<pre><code>pragma solidity ^0.4.25;

library ECDSA {

  /**
   * @dev Recover signer address from a message by using their signature
   * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
   * @param signature bytes signature, the signature is generated using web3.eth.sign()
   */
  function recover(bytes32 hash, bytes signature)
    internal
    pure
    returns (address)
  {
    bytes32 r;
    bytes32 s;
    uint8 v;

    // Check the signature length
    if (signature.length != 65) {
      return (address(0));
    }

    // Divide the signature in r, s and v variables with inline assembly.
    assembly {
      r := mload(add(signature, 0x20))
      s := mload(add(signature, 0x40))
      v := byte(0, mload(add(signature, 0x60)))
    }

    // Version of signature should be 27 or 28, but 0 and 1 are also possible versions
    if (v &lt; 27) {
      v += 27;
    }

    // If the version is correct return the signer address
    if (v != 27 &amp;&amp; v != 28) {
      return (address(0));
    } else {
      // solium-disable-next-line arg-overflow
      return ecrecover(hash, v, r, s);
    }
  }

  /**
    * toEthSignedMessageHash
    * @dev prefix a bytes32 value with &quot;\x19Ethereum Signed Message:&quot;
    * and hash the result
    */
  function toEthSignedMessageHash(bytes32 hash)
    internal
    pure
    returns (bytes32)
  {
    return keccak256(
      abi.encodePacked(&quot;\x19Ethereum Signed Message:\n32&quot;, hash)
    );
  }
}
</code></pre>

<plutus><plutus-pioneer-program><plutustx><solidity>
Is there any eth_sign equivalent signing method in plutus?
# Is there any eth_sign equivalent signing method in plutus?

(Asked by: username_0 on 2021-07-02)

I want to use my private key to sign a message, and submit the message and signatures to third party server, the third party server can verify that signatures through plutus smartcontract.
In ethereum eth_sign can achieve this, the smartcontract side have a method to recover address related to the oringal signing private key:
pragma solidity ^0.4.25;

library ECDSA {

  /**
   * @dev Recover signer address from a message by using their signature
   * @param hash bytes32 message, the hash is the signed message. What is recovered is the signer address.
   * @param signature bytes signature, the signature is generated using web3.eth.sign()
   */
  function recover(bytes32 hash, bytes signature)
    internal
    pure
    returns (address)
  {
    bytes32 r;
    bytes32 s;
    uint8 v;

    // Check the signature length
    if (signature.length != 65) {
      return (address(0));
    }

    // Divide the signature in r, s and v variables with inline assembly.
    assembly {
      r := mload(add(signature, 0x20))
      s := mload(add(signature, 0x40))
      v := byte(0, mload(add(signature, 0x60)))
    }

    // Version of signature should be 27 or 28, but 0 and 1 are also possible versions
    if (v < 27) {
      v += 27;
    }

    // If the version is correct return the signer address
    if (v != 27 && v != 28) {
      return (address(0));
    } else {
      // solium-disable-next-line arg-overflow
      return ecrecover(hash, v, r, s);
    }
  }

  /**
    * toEthSignedMessageHash
    * @dev prefix a bytes32 value with "\x19Ethereum Signed Message:"
    * and hash the result
    */
  function toEthSignedMessageHash(bytes32 hash)
    internal
    pure
    returns (bytes32)
  {
    return keccak256(
      abi.encodePacked("\x19Ethereum Signed Message:\n32", hash)
    );
  }
}

**Tags:** plutus, plutus-pioneer-program, plutustx, solidity

---

## 1 answers

### Answer by username_1 on 2021-07-22. Score: 1

You can find functions for message signing and signature checking in packacke `plutus-ledger`, module `Ledger.Oracle`.
Also, why whould you need a smart contract for this?


---

