1 unstable release

0.1.0 May 31, 2024

#18 in #linera

Download history 82/week @ 2024-07-22 107/week @ 2024-07-29 98/week @ 2024-08-05 112/week @ 2024-08-12 104/week @ 2024-08-19 157/week @ 2024-08-26 142/week @ 2024-09-02 272/week @ 2024-09-09 300/week @ 2024-09-16 286/week @ 2024-09-23 125/week @ 2024-09-30 155/week @ 2024-10-07 156/week @ 2024-10-14 305/week @ 2024-10-21 374/week @ 2024-10-28 558/week @ 2024-11-04

1,399 downloads per month
Used in 14 crates (9 directly)

MIT/Apache

23KB
330 lines

linera-alloy-signer

Ethereum signer abstraction.

You can implement the Signer trait to extend functionality to other signers such as Hardware Security Modules, KMS etc. See its documentation for more.

Signer implementation in Alloy:

Examples

Sign an Ethereum prefixed message (EIP-712):

use linera_alloy_signer::{Signer, SignerSync};

// Instantiate a signer.
let signer = linera_alloy_signer_wallet::LocalWallet::random();

// Sign a message.
let message = "Some data";
let signature = signer.sign_message_sync(message.as_bytes())?;

// Recover the signer from the message.
let recovered = signature.recover_address_from_msg(message)?;
assert_eq!(recovered, signer.address());
# Ok::<_, Box<dyn std::error::Error>>(())

Sign a transaction:

use linera_alloy_consensus::TxLegacy;
use linera_alloy_primitives::{U256, address, bytes};
use linera_alloy_signer::{Signer, SignerSync};
use linera_alloy_network::{TxSignerSync};

// Instantiate a signer.
let signer = "dcf2cbdd171a21c480aa7f53d77f31bb102282b3ff099c78e3118b37348c72f7"
    .parse::<linera_alloy_signer_wallet::LocalWallet>()?;

// Create a transaction.
let mut tx = TxLegacy {
    to: address!("d8dA6BF26964aF9D7eEd9e03E53415D37aA96045").into(),
    value: U256::from(1_000_000_000),
    gas_limit: 2_000_000,
    nonce: 0,
    gas_price: 21_000_000_000,
    input: bytes!(),
    chain_id: Some(1),
};

// Sign it.
let signature = signer.sign_transaction_sync(&mut tx)?;
# Ok::<_, Box<dyn std::error::Error>>(())

Dependencies

~16MB
~357K SLoC