Skip to main content

fastweb3-keypass

Simple EVM account management tool.

NOTE: This library is still in early alpha development. Prior to a v1.0.0 (which may never come), expect breaking changes and no backward compatibility between versions.

Installation

You can install the latest release via pip:

pip install fastweb3-keypass

Or clone the repository for the most up-to-date version:

git clone https://github.com/iamdefinitelyahuman/fastweb3-keypass.git
cd fastweb3-keypass
pip install -e .

Usage

1. Create and access a Keypass

Creating a keypass is a single function call. The result is a persistent database stored on disk.

>>> import fw3_keypass

>>> kp = fw3_keypass.create("main")
Create password for new keypass 'main': ***

>>> kp
<KeypassDB path=/home/user/.local/share/fastweb3-keypass/main.sqlite3 unlocked>

Once created, it can be opened and unlocked in another session.

>>> import fw3_keypass

>>> kp = fw3_keypass.open("main")
>>> kp.unlock()
Enter the password for keypass 'main': ***

# alternatively use the top-level "unlock" to open and unlock in a single action
>>> kp = fw3_keypass.unlock("main", password="mypassword")

2. Create an account

A new account can be generated directly inside the keypass. Its private key is encrypted and stored in the database.

>>> acct = kp.create_account()
>>> acct
<Account 0x0D3AaC9458167352493864Af54D1CBD7F1B8fF68 signable>

3. Import existing accounts

A keypass can hold multiple accounts.

You can import an existing account from a raw private key:

>>> kp.add_private_key(
...     "0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
...     alias="imported-key",
... )
<Account 0xFCAd0B19bB29D4674531d6f115237E16AfCE377c signable>

Or import from an Ethereum keystore JSON:

>>> kp.import_keystore(
...     "./my-keystore.json",
...     password="keystore-password",
...     alias="imported-json",
... )
<Account 0x104da57BF95262B119553181bA62dD5B8F204f49 signable>

4. Set aliases

You can set aliases for accounts to simplify retrieval later. A single account can have multiple aliases.

>>> kp.set_alias(acct, "hot")
>>> kp.set_alias(acct, "trading")

>>> kp["hot"]
<Account 0x0D3AaC9458167352493864Af54D1CBD7F1B8fF68 signable>

>>> kp["0x0D3AaC9458167352493864Af54D1CBD7F1B8fF68"]
<Account 0x0D3AaC9458167352493864Af54D1CBD7F1B8fF68 signable>

>>> kp["hot"] == kp["trading"] == acct
True

5. Add watch-only accounts

If you assign an alias to an address that has no private key in the keypass, it is stored as a watch-only account.

This lets you keep named references to important addresses and retrieve them later by alias.

>>> kp.set_alias("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", "vitalik")

>>> kp["vitalik"]
<Account 0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 watch-only>

6. Sign a transaction

Here we build a transaction from one of our signing accounts to send to one of our watch-only accounts.

>>> tx = {
...     "to": kp["vitalik"],
...     "value": 10**18,
...     "gas": 21_000,
...     "maxFeePerGas": 30_000_000_000,
...     "maxPriorityFeePerGas": 2_000_000_000,
...     "nonce": 0,
...     "chainId": 1
... }
>>> signed = kp["hot"].sign_transaction(tx)

>>> signed
SignedTransaction(raw_transaction=b'\x02...', hash=b'\xa1...', r=..., s=..., v=1)

7. Sign messages

The Account object also exposes methods for signing messages and authorizations.

Account.sign_authorization(authorization_dict: dict[str, Any])
Account.sign_message(signable_message: Any)
Account.sign_typed_data(
    domain_data: dict[str, Any] | None = None,
    message_types: dict[str, Any] | None = None,
    message_data: dict[str, Any] | None = None,
    full_message: dict[str, Any] | None = None,
)

All signing methods implement an equivalent API to the same-named functions in the eth-account library.

8. Default keypass and accounts

You can create a "default" keypass by calling create with no arguments:

>>> fw3_keypass.create()
Create password for new keypass 'default':
<KeypassDB path=/home/user/.local/share/fw3-keypass/default.sqlite3 unlocked>

Every keypass also maintains a default account.

>>> kp.default_account
fw3_keypass.errors.NoDefaultAccountError: database has no default account set

>>> kp.create_account(alias="degen", set_as_default=True)
<Account 0xcc27b3Be484E3692737993ca8273349e9483454D signable>

>>> kp.default_account
<Account 0xcc27b3Be484E3692737993ca8273349e9483454D signable>

This makes portable scripts possible. Each user signs using their own default keypass and account.

import fw3_keypass

kp = fw3_keypass.unlock()

acct = kp.default_account
acct.sign_transaction(...)

Tests

First, install the dev dependencies:

pip install -e ".[dev]"

To run the test suite:

pytest

License

This project is licensed under the MIT license.

Metadata

Release files for fastweb3-keypass 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastweb3-keypass 0.1.3
File Size Uploaded Provenance
fastweb3_keypass-0.1.3.tar.gz 27.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fastweb3-keypass 0.1.3
File Interpreter ABI Platform
fastweb3_keypass-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 60.4 kB

Release files / fastweb3_keypass-0.1.3.tar.gz

Download URL fastweb3_keypass-0.1.3.tar.gz
Size 27.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ab72577b9d9fd15222ad013082dbf408d3c8131f119e23c5ef33b78aa3760cbd
BLAKE2b-256 checksum
How to use checksums
d4746707d0b0dc5529bc222b2ff92915d9197658ee89beb22aa2a685da87b55e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release files / fastweb3_keypass-0.1.3-py3-none-any.whl

Download URL fastweb3_keypass-0.1.3-py3-none-any.whl
Size 33.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
eaa85da449bb4f5a9e69d1d787ea3f1439afdd6c82b40de3cb3b7e3473923f6c
BLAKE2b-256 checksum
How to use checksums
3762238c3c71614775955b349db43362dc60b876bd77310ca2a54dec9c783f40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Security for fastweb3-keypass 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page