Overview
This library enables Internet Computer canisters to sign transactions for EVM-compatible blockchains.
This is a two-part process:
- Create new addresses on the Internet Computer using distributed ECDSA key generation
- Sign transactions with these addresses as the canister itself or in behalve of the canister users using threshold ECDSA signatures
There an example project at ic-evm-sign-starter.
Features
- Create EVM addresses
- Sign EVM transactions
- Manages transaction nonce
- Supports different chain ids
- Takes care of various tx types
Supported Tx Types: Legacy, EIP1559, EIP2930
Getting Started
Starter Project
You can get start quickly with ic-evm-sign-starter.
Existing Project
1. Install the library
Run cargo add ic-evm-sign in your project
2. Create new EVM address
Create a new EVM-compatible address from a canister
use ic_evm_sign;
async
Test locally with:
3. Sign EVM transaction
Sign an EVM-compatible transaction from a canister
use ic_evm_sign;
async
Test it locally with:
Example:
For transaction hex:
0xec808505428728bd8275309470997970c51812dc3a010c7d01b50e0d17dc79c8880de0b6b3a764000000808080
How it works
New Address
- Receive principal from the canister
- Creates a new ECDSA public key on IC
- Calculates the EVM address from the public key
- Saves the new address to the canister state based on principal
Transaction Signing
- Receive a raw transaction, chain id and a principal from the canister
- Gets principal's public key from the canister state
- Prepares "message" to sign from raw transaction and chain id
- Signs "message" to sign and gets transaction signature
- Calculates recovery id from "message" to sign, signature and public key
- And then gets the signed transaction from raw transaction, chain id and recovery id
- Stores the transaction to the canister state based on principal
How to's & guides
Different EVMs
Use a different EVM-compatible blockchain using chain_id in:
sign
Find chain ids at: https://chainlist.org
Transaction types
You can sign different transaction types hex by passing their corresponding hex using hex_raw_tx in:
sign
Find transaction types at: https://github.com/ethereum/execution-specs
Contributing
Get started
- Download the repo with
git clone - Run unit tests with
cargo test
To develop on the local frontend:
- Start a hardhat node with
npm startindev/local-node(terminal 1) - Requiresnpm i - Run an ic replica with
dfx start(terminal 2) - And deploy the example canister with
dfx deploy - Then start the example frontend with
npm start(terminal 3) indev/frontend- Requiresnpm i