Skip to content

royal-markets/eth-signature-verifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Universal Etheruem signature verification with ERC-6492

This crate verifies any Ethereum signature including:

  • EOAs
  • Smart contract wallets with ERC-1271
  • Predeploy contract wallets with ERC-6492

Usage

This crate uses Alloy and requires an RPC provider in order to verify all signature types.

use alloy::primitives::{address, bytes, eip191_hash_message};
use alloy::providers::{network::Ethereum, ReqwestProvider};
use eth_signature_verifier::verify_signature;

#[tokio::main]
async fn main() {
    let address = address!("0xc0ffee254729296a45a3885639AC7E10F9d54979");
    let message = "coffee";
    let signature = bytes!("0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658");
    let provider = ReqwestProvider::<Ethereum>::new_http("https://rpc.example.com");

    let verification = verify_signature(signature, address, message, provider).await.unwrap();
    if verification.is_valid() {
        // signature valid
    }
}

This crate also allows for the extracting of an address from a signature, as shown below:

use eth_signature_verifier::extract_address;

#[tokio::main]
async fn main() {
    let signature = bytes!("0x9c22ff5f21f0b81b113e63f7db6da94fedef11b2119b4088b89664fb9a3cb658")
    let address = extract_address(signature).await.unwrap(); // works for EOA, ERC1271, ERC6492
    dbg!(address);
}

See test cases in src/lib.rs for more examples.

About

Universal Etheruem signature verification with ERC-6492

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published