minizign
Fast, lightweight Python bindings for the Zig minisign implementation.
minizign provides high-performance cryptographic signing and verification using Ed25519 and Blake2b-512 with full Minisign format compatibility.
Features
- Standard Minisign Compatibility: Interoperable with official
minisignfiles, keys, and signatures. - Multiple Input Types: Sign and verify
str,bytes,bytearray,memoryview, integer file descriptors (int), and file-like objects. - Streaming Hashing: Fast chunked hashing (Blake2b-512) for large files and file descriptors without loading entire files into memory.
- Direct Output Writing: Write signatures and keys directly to integer file descriptors or file-like streams.
- Full Comment Support: Custom trusted comments and untrusted comments on signatures, public keys, and secret keys.
- Type Annotations: Fully typed with PEP 561
.pyistubs.
Installation from PyPi
pip install minizign
Quickstart
Keypair Generation
import minizign
# Generate a new random secret key
sk = minizign.SecretKey(untrusted_comment="my secret key")
# Derive the corresponding public key
pk = sk.getPublicKey(untrusted_comment="my public key")
# Export keys as Minisign formatted strings
sk_str = sk.toString()
pk_str = pk.toString()
print("Public Key:")
print(pk_str)
Signing and Verifying Data
import minizign
sk = minizign.SecretKey()
pk = sk.getPublicKey()
# Sign a string or bytes
message = "Hello, world!"
sig = sk.sign(
message,
trusted_comment="trusted timestamp",
untrusted_comment="signature from minizign"
)
# Verify with PublicKey or Signature object
is_valid = pk.verify(message, sig)
print("Valid:", is_valid) # True
# Verify using top-level helper
print("Valid:", minizign.verify(message, sig, pk)) # True
Signing Files and File Descriptors (Streaming)
import os
import minizign
sk = minizign.SecretKey()
pk = sk.getPublicKey()
# Sign a file stream directly
with open("large_dataset.tar.gz", "rb") as f:
sig = sk.sign(f, trusted_comment="release archive")
# Verify with file object
with open("large_dataset.tar.gz", "rb") as f:
assert pk.verify(f, sig)
# Sign using an OS file descriptor and write signature directly to another fd
fd_in = os.open("document.pdf", os.O_RDONLY)
fd_out = os.open("document.pdf.minisig", os.O_WRONLY | os.O_CREAT | os.O_TRUNC)
sig = sk.sign(fd_in, out=fd_out, trusted_comment="approved")
os.close(fd_in)
os.close(fd_out)
Loading Keys and Signatures
import minizign
# Load from serialized strings
pk = minizign.PublicKey("untrusted comment: minisign public key\nRWR...\n")
sig = minizign.Signature("untrusted comment: ...\n...\ntrusted comment: ...\n...\n")
# Load from file or file descriptor
with open("minisign.pub", "r") as f:
pk_from_file = minizign.PublicKey(f)
# Inspect properties
print(sig.trusted_comment)
print(sig.untrusted_comment)
print(sig.signature) # 64 bytes
print(sig.global_signature) # 64 bytes
print(sig.key_id) # 8 bytes
API Reference
Module Functions
-
minizign.sign(secret_key, message, trusted_comment=None, untrusted_comment=None, out=None, timestamp=None) -> Signature
Sign a message with aSecretKey. Output can optionally be written to a file descriptor or file object. A customtimestamp(int,float, orstr) can be supplied. -
minizign.verify(message, signature, public_key) -> bool
Verify a signature against a message and aPublicKey.
SecretKey
SecretKey(str=None, *, untrusted_comment=None, comment=None): Generate a new random key or load from input (str,bytes,intfd, or file object).sk.getPublicKey(untrusted_comment=None, *, comment=None) -> PublicKey: Extract the corresponding public key.sk.sign(message, trusted_comment=None, untrusted_comment=None, out=None, timestamp=None) -> Signature: Signmessage(str,bytes,bytearray,memoryview,intfd, or file).sk.signBytes(data, ...)/sk.signString(message, ...): Aliases forsign.sk.toString(out=None, *, untrusted_comment=None, comment=None) -> Optional[str]: Format as serialized Minisign secret key string or write toout.sk.write(out, *, untrusted_comment=None, comment=None) -> None: Write secret key to an output destination.- Properties:
untrusted_comment,comment,key_id,secret_key.
PublicKey
PublicKey(str=None, *, untrusted_comment=None, comment=None): Load a public key from string, bytes, file descriptor, or file.pk.verify(message, signature) -> bool: Verify a signature against a message (str,bytes,bytearray,memoryview,intfd, or file).pk.verifyString(message, signature) -> bool: Alias forverify.pk.toString(out=None, *, untrusted_comment=None, comment=None) -> Optional[str]: Format as Minisign public key string or write toout.pk.write(out, *, untrusted_comment=None, comment=None) -> None: Write public key to an output destination.- Properties:
untrusted_comment,comment,key_id,key,public_key.
Signature
Signature(str=None, *, untrusted_comment=None, comment=None): Parse a signature from string, bytes, file descriptor, or file.sig.verify(message, public_key) -> bool: Verify this signature against a message and public key.sig.toString(out=None) -> Optional[str]: Format as Minisign signature string or write toout.sig.write(out) -> None: Write signature to an output destination.- Properties:
trusted_comment,untrusted_comment,comment,signature,global_signature,key_id.
License
MIT / Apache-2.0
Metadata
Release files for minizign 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| minizign-0.0.4.tar.gz | 73.8 kB | Without provenance | Details for minizign-0.0.4.tar.gz |
Release files / minizign-0.0.4.tar.gz
| Download URL | minizign-0.0.4.tar.gz |
|---|---|
| Size | 73.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ec68983572be94fa5d0a19b4fa67067f515ae6379a335d4c1900803f2b404bb6
|
|
BLAKE2b-256 checksum How to use checksums |
9ac546a0b3efdb5c367d03351c47d79c2c90bc5da8b714968aea05f2a98c890b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.21
|
Security for minizign 0.0.4
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.