Expand description
§crypto-signer
High-performance, low-latency, lightweight multi-chain signing primitives.
§Ethereum / EVM (EIP-712)
use crypto_signer::{Address, Domain, PermitBuilder};
use crypto_signer::backends::local_k256::LocalK256Signer;
use k256::ecdsa::SigningKey;
let key = SigningKey::from_bytes(&[0x01; 32].into()).unwrap();
let signer = LocalK256Signer::from_signing_key(key);
let domain = Domain::new("USDC", "1", 137, Address::new([0x11; 20]));
let signed = PermitBuilder::new(domain)
.spender(Address::new([0x22; 20]))
.value(1_000_000)
.nonce(0)
.deadline(1_700_000_000)
.build_and_sign(&signer)
.expect("signing is infallible with a valid key");
let (v, r, s) = signed.vrs();
assert!(v == 27 || v == 28);§Bitcoin (PSBT via hardware wallet)
ⓘ
use crypto_signer::chains::bitcoin::{sign_psbt, PsbtBytes};
use crypto_signer::hw::DerivationPath;
// m/84'/0'/0'/0/0 — native SegWit
let path = DerivationPath(vec![0x8000_0054, 0x8000_0000, 0x8000_0000, 0, 0]);
let signed_psbt = sign_psbt(&ledger, &path, PsbtBytes(raw_psbt))?;§Solana (Ed25519 via hardware wallet)
ⓘ
use crypto_signer::chains::solana::{sign_transaction, SolanaTxBytes};
use crypto_signer::hw::DerivationPath;
// m/44'/501'/0'/0'
let path = DerivationPath(vec![0x8000_002c, 0x8000_01f5, 0x8000_0000, 0x8000_0000]);
let sig = sign_transaction(&ledger, &path, SolanaTxBytes(tx_bytes))?;
assert_eq!(sig.0.len(), 64);§Cosmos (SignDoc SHA-256)
use crypto_signer::chains::cosmos::SignDoc;
use crypto_signer::Signer;
use crypto_signer::backends::local_k256::LocalK256Signer;
use k256::ecdsa::SigningKey;
let key = SigningKey::from_bytes(&[0x02; 32].into()).unwrap();
let signer = LocalK256Signer::from_signing_key(key);
let doc = SignDoc {
body_bytes: vec![0x0a, 0x01, 0x01],
auth_info_bytes: vec![0x12, 0x01, 0x02],
chain_id: "osmosis-1".to_string(),
account_number: 42,
sequence: 1,
};
let hash = doc.signing_hash();
let signature = signer.sign_hash(hash).expect("valid key");Re-exports§
pub use signer::BuildError;pub use signer::Signer;pub use signer::SignerType;pub use types::Address;pub use types::Signature;pub use evm::domain::Domain;pub use evm::eip712::Eip712Type;pub use evm::eip712::Signed;pub use evm::eip712::TypedMessage;pub use evm::eip712::Unsigned;pub use evm::messages::Order;pub use evm::messages::Permit;pub use evm::messages::PermitBuilder;pub use evm::messages::PermitSignError;pub use evm::network::NetworkConfig;pub use evm::RecoveryError;pub use evm::recover_signer;