Generates Solidity code to verify EIP-712 style signatures

Related tags

Cryptography eip712
Overview

eip712

Generates Solidity code to verify EIP-712 style signatures.

Usage

First, create an abstract contract implementing the functionality you want:

// SPDX-License-Identifier: CC0-1.0

pragma solidity ^0.8.11;

abstract contract NameRegistry {
    mapping (string => address) public nameToAddress;
    mapping (address => string) public addressToName;

    // This `claim` function implements the functionality you want to expose
    // via an EIP-712 signature.
    //
    // Importantly, the first argument must be the sender's address, and
    // the function must be internal.
    function claim(address sender, string memory name) internal {
        require(bytes(addressToName[sender]).length == 0, "address already registered");
        require(nameToAddress[name] == address(0), "name already registered");

        addressToName[sender] = name;
        nameToAddress[name] = sender;
    }

    // You can optionally expose your functionality using `msg.sender`.
    function claim(string memory name) external {
        claim(msg.sender, name);
    }

    // Finally, you should declare an abstract function that accepts a signature.
    //
    // The implementation will be generated for you.
    function claim(string memory name, uint8 v, bytes32 r, bytes32 s) external virtual;
}

As a Library

For advanced uses, this crate can be used as a library from Rust or JavaScript.

Rust

::new("NameRegistry") // Name of the base contract. .signing_domain("NameRegistry") // Name for the EIP-712 domain. .version("1") // Contract version. .read_str(abi) .unwrap() .generate(&mut output) .unwrap(); std::io::stdout().write_all(output.as_bytes()).unwrap(); }">
use eip712::Eip712;

use std::io::Write;

fn main() {
    // Read the ABI file (normally generated by `solc`.)
    let abi = include_str!("NameRegistry.json");

    let mut output = String::new();

    // Configure and run the generator.
    Eip712::<()>::new("NameRegistry")       // Name of the base contract.
        .signing_domain("NameRegistry")     // Name for the EIP-712 domain.
        .version("1")                       // Contract version.
        .read_str(abi)
        .unwrap()
        .generate(&mut output)
        .unwrap();

    std::io::stdout().write_all(output.as_bytes()).unwrap();
}

JavaScript

import { default as eip712, Eip712 } from './eip712.js';

async function main() {
    await eip712();

    // Read the ABI file (normally generated by `solc`.)
    const resp = await fetch("./NameRegistry.json");
    const abi = await resp.text();

    // Configure and run the generator.
    const output = new Eip712("NameRegistry")   // Name of the base contract.
        .error(console.log)                     // Error handler.
        .warning(console.log)                   // Warning handler.
        .signing_domain("NameRegistry")         // Name for the EIP-712 domain.
        .version("1")                           // Contract version.
        .read_str(abi)
        .generate();

    let elem = document.createElement('pre');
    elem.innerText = output;
    document.body.appendChild(elem);
}

main();
You might also like...
evm2near compiles Solidity contracts into NEAR WebAssembly contracts.

EVM → NEAR evm2near is a project for compiling EVM bytecode into wasm bytecode, with the particular goal of having that wasm artifact be executable on

A Solidity static analyzer to identify contract vulnerabilities and gas efficiencies.

solstat A Solidity static analyzer to identify contract vulnerabilities and gas efficiencies. .------. .------. .------. .------. .------. .------. .-

Rust bindings for Solidity's AST and visitors

solc-ast solc-ast provides rust bindings for the solidity AST and visitors. The visitors were built to be 1-1 compatible with the visitors from solc.

An automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function call efficiency.

Solidity-Gas-Optimizoor An high performance automated CLI tool that optimizes gas usage in Solidity smart contracts, focusing on storage and function

Generates a Nix expression for buildDotnetModule, with support for non nuget.org repos.

nuget2nix Generates a Nix expression for buildDotnetModule, with support for non nuget.org repos. Usage Similar to the nuget-to-nix command available

Generates a unique hash/identifier for a system given a set of parameters.

uniqueid 🔍 Generates a unique hash/identifier for a system given a set of parameters. Example usage use uniqueid; pub fn main() { let data = vec

Generates a big overview of dependencies between microservices using pact-broker
Generates a big overview of dependencies between microservices using pact-broker

Pact graph network Generates a schema of dependencies between microservices using pact-broker data. Table of contents Screenshots Tech Stack Features

deductive verification of Rust code. (semi) automatically prove your code satisfies your specifications!
deductive verification of Rust code. (semi) automatically prove your code satisfies your specifications!

Le marteau-pilon, forges et aciéries de Saint-Chamond, Joseph-Fortuné LAYRAUD, 1889 About Creusot is a tool for deductive verification of Rust code. I

A cryptographically verifiable code review system for the cargo (Rust) package manager.
A cryptographically verifiable code review system for the cargo (Rust) package manager.

A cryptographically verifiable code review system for the cargo (Rust) package manager.

Releases(v0.1.0)
  • v0.1.0(Mar 11, 2022)

    An initial preview release that covers the basic functionality, and sets up the workflow for contributors.

    The generated Solidity hasn't been tested.

    Source code(tar.gz)
    Source code(zip)
Owner
Sam Wilson
eipnft:samwilsn.eth
Sam Wilson
Zei is a library that provide tools to create and verify public transaction with confidential data.

#Zei: Findora's Cryptographic Library Zei is a library that provide tools to create and verify public transaction with confidential data. Support: Bas

Findora Foundation 0 Oct 23, 2022
P2P Network to verify authorship & ownership, store & deliver proofs.

Anagolay Network Node Anagolay is a next-generation framework for ownerships, copyrights and digital licenses. ?? Local Development The installation a

Anagolay Network 5 May 30, 2022
Noir implementation of RSA-verify

noir-rsa This repository contains an implementation of a RSA signature verify for the Noir language. Currently supports pkcs1v15 + sha256 and exponent

Set Labs 5 Jul 22, 2023
Multi Party Key Management System (KMS) for Secp256k1 Elliptic curve based digital signatures.

Key Management System (KMS) for curve Secp256k1 Multi Party Key Management System (KMS) for Secp256k1 Elliptic curve based digital signatures. Introdu

[ZenGo X] 61 Dec 28, 2022
A pairing-based threshold cryptosystem for collaborative decryption and signatures used in HoneybadgerBFT implementation

threshold_crypto A pairing-based threshold cryptosystem for collaborative decryption and signatures. The threshold_crypto crate provides cryptographic

null 166 Dec 29, 2022
Rust implementation of multi-party Schnorr signatures over elliptic curves.

Multi Party Schnorr Signatures This library contains several Rust implementations of multi-signature Schnorr schemes. Generally speaking, these scheme

[ZenGo X] 148 Dec 15, 2022
NIST P-256 signatures for Cortex-M4 microcontrollers

nisty NIST P256 signatures for Cortex-M4 microcontrollers What is this? Sometimes NIST P256 signatures need to be used. This is an attempt to create a

null 13 Mar 14, 2021
BLS Signatures in Rust

BLS Signatures Implementation of BLS signatures in pure Rust. Development BLST Portability To enable the portable feature when building blst dependenc

Filecoin 50 Dec 25, 2022
Schnorr VRFs and signatures on the Ristretto group

schnorrkel Schnorrkel implements Schnorr signature on Ristretto compressed Ed25519 points, as well as related protocols like HDKD, MuSig, and a verifi

Web3 Foundation 252 Dec 21, 2022
L2 validity rollup combined with blind signatures over elliptic curves inside zkSNARK, to provide offchain anonymous voting with onchain binding execution on Ethereum

blind-ovote Blind-OVOTE is a L2 voting solution which combines the validity rollup ideas with blind signatures over elliptic curves inside zkSNARK, to

Aragon ZK Research 3 Nov 18, 2022