API Reference
miniethers
Circuitpython module for ethereum wallet creation and signing
Author(s): Shamba Chowdhury
Implementation Notes
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- class circuitpython_miniethers.miniethers.Signature(r=None, s=None, v=None)
ECDSA signature representation compatible with ethers.js Signature class.
Represents an Elliptic Curve Digital Signature Algorithm (ECDSA) signature with components r, s, and v. Provides methods for parsing and serializing signatures in various formats.
- Variables:
Note
Compatible with ethers.js v6 Signature format.
Initialize a Signature instance.
- Parameters:
# Create from components sig = Signature(r="0x123...", s="0xabc...", v=27) # Create empty signature sig = Signature()
- from()
Create a Signature from various input formats.
Parses and creates a Signature instance from compact signature strings, dictionaries, or existing Signature instances.
- Parameters:
sig (str or dict or Signature) – Signature in various formats
- Returns:
A new Signature instance
- Return type:
- Raises:
ValueError – If signature format is invalid
# From compact signature string sig = Signature.from_sig("0xrrr...sss...vv") # From dictionary sig = Signature.from_sig({"r": "0x...", "s": "0x...", "v": 27}) # Via getattr (to handle 'from' keyword) sig = getattr(Signature, 'from')("0xrrr...sss...vv")
Note
This method is also available as
Signature.from()via setattr, but requiresgetattr(Signature, 'from')due to Python keyword restrictions.
- static from_sig(sig)
Create a Signature from various input formats.
Parses and creates a Signature instance from compact signature strings, dictionaries, or existing Signature instances.
- Parameters:
sig (str or dict or Signature) – Signature in various formats
- Returns:
A new Signature instance
- Return type:
- Raises:
ValueError – If signature format is invalid
# From compact signature string sig = Signature.from_sig("0xrrr...sss...vv") # From dictionary sig = Signature.from_sig({"r": "0x...", "s": "0x...", "v": 27}) # Via getattr (to handle 'from' keyword) sig = getattr(Signature, 'from')("0xrrr...sss...vv")
Note
This method is also available as
Signature.from()via setattr, but requiresgetattr(Signature, 'from')due to Python keyword restrictions.
- property serialized
Compact serialized signature in hex format.
Returns the signature in compact format: r (64 chars) + s (64 chars) + v (2 chars) with 0x prefix, totaling 132 characters.
- Returns:
Compact signature string (0xrrr…sss…vv)
- Return type:
sig = Signature(r="0x123...", s="0xabc...", v=27) print(sig.serialized) # "0x123...abc...1b"
- class circuitpython_miniethers.miniethers.Wallet(private_key=None)
Ethereum wallet for signing messages and transactions.
Provides a high-level interface for Ethereum wallet operations including private key management, address derivation, and message signing compatible with ethers.js patterns. Optimized for CircuitPython and low-power devices.
- Variables:
# Create wallet from private key wallet = Wallet("0x022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc") # Access properties print(wallet.address) # "0x..." print(wallet.privateKey) # "0x..." # Sign a message signature = wallet.signMessage("hello")
Note
Compatible with ethers.js v6 Wallet API patterns.
Initialize wallet with optional private key.
- Parameters:
private_key (str or int or None) – Private key as hex string (with or without 0x prefix), integer, or None to generate random key
- Raises:
ValueError – If private key is out of valid range
# From hex string (with 0x) wallet = Wallet("0x022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc") # From hex string (without 0x) wallet = Wallet("022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc") # From integer wallet = Wallet(0x022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc) # Generate random wallet wallet = Wallet()
- property address
Ethereum address derived from public key.
Returns the Ethereum address computed from the wallet’s public key using Keccak-256 hashing. The address is cached after first computation.
- Returns:
Ethereum address with 0x prefix (42 characters)
- Return type:
wallet = Wallet("0x022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc") print(wallet.address) # "0x14791697260E4c9A71f18484C9f997B308e59325"
- get_address()
Get Ethereum address (legacy method).
Deprecated since version Use: the
addressproperty instead.- Returns:
Ethereum address with 0x prefix
- Return type:
- get_private_key()
Get private key as integer (legacy method).
Deprecated since version Use: the
privateKeyproperty for hex string representation.- Returns:
Private key as integer
- Return type:
- get_public_key()
Get public key coordinates (legacy method).
Deprecated since version Use: the
publicKeyproperty for hex string representation.- Returns:
Tuple of (x, y) coordinates as integers
- Return type:
- property privateKey
Private key as hexadecimal string.
- Returns:
Private key with 0x prefix (66 characters)
- Return type:
Warning
Never expose private keys in production environments.
- property publicKey
Uncompressed public key in hex format.
Returns the uncompressed public key (x and y coordinates concatenated) with 0x04 prefix following SEC1 encoding.
- Returns:
Uncompressed public key with 0x04 prefix (132 characters)
- Return type:
wallet = Wallet("0x022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc") print(wallet.publicKey) # "0x04..."
- signMessage(message)
Sign a personal message using ERC-191 standard.
Automatically prepends the Ethereum message prefix before signing. Compatible with ethers.js
wallet.signMessage()method.- Parameters:
- Returns:
Compact signature string (130 hex chars + 0x prefix)
- Return type:
wallet = Wallet("0x022b99092266a16a949e6a450f0e88a8288d39d5f1d75c00575a35a0ba270dbc") signature = wallet.signMessage("hello") print(signature) # "0xrrr...sss...vv" # Parse signature sig = getattr(Signature, 'from')(signature) print(sig.r, sig.s, sig.v)
See also
ERC-191 specification.
- verify_signature(message_hash, r, s)
Verify an ECDSA signature against the wallet’s public key.