Authorization Capabilities for Linked Data — Python verification library
Project description
zcap-py
Authorization Capabilities for Linked Data — Python verification library.
A minimal, production-quality Python library implementing the W3C Authorization Capabilities for Linked Data (ZCAP-LD) draft specification. This is the Python counterpart to zcap-dotnet.
Features
- Ed25519 key generation and signature verification
did:keyencoding, decoding, and resolution (Ed25519 only)- Multibase-z (base58btc) and multicodec support
- Strict DID URL parsing and validation
- RFC 8785 / JCS canonicalization
- Ed25519Signature2020 proof verification (JCS-based for
zcap-dotnetinterop) - W3C-compliant Ed25519Signature2020 proof verification (URDNA2015, optional
pylddependency) - ZCAP-LD document parsing (Capability & Invocation)
- Typed exception hierarchy for controlled error handling
- 100% type-annotated public API (
mypy --strictcompliant) - Zero network I/O in core — fully offline verification
Installation
pip install zcap-py
Or with uv:
uv add zcap-py
For W3C-compliant URDNA2015 proof verification, install with the jsonld extra:
pip install zcap-py[jsonld]
Quick Start
from zcap_py import generate_ed25519_keypair, verify_document_proof
from zcap_py import canonicalize, base58btc_encode
# Generate a did:key keypair
keypair = generate_ed25519_keypair()
print(keypair.did) # did:key:z6Mk...
print(keypair.verification_method) # did:key:z6Mk...#z6Mk...
# Sign a document with an Ed25519Signature2020 proof
document = {
"id": "urn:example:cap-1",
"type": "Authorization",
"controller": keypair.did,
"invocationTarget": "https://api.example.com/docs",
"allowedAction": ["read"],
}
proof_metadata = {
"type": "Ed25519Signature2020",
"verificationMethod": keypair.verification_method,
"created": "2026-01-01T00:00:00Z",
"proofPurpose": "capabilityDelegation",
}
to_sign = {**document, "proof": proof_metadata}
signature = keypair.private_key.sign(canonicalize(to_sign))
signed = {**document, "proof": {**proof_metadata, "proofValue": base58btc_encode(signature)}}
# Verify — resolves the public key from proof.verificationMethod automatically
verify_document_proof(signed)
Examples
Runnable examples are in the examples/ directory:
| Example | Description |
|---|---|
key_generation.py |
Generate Ed25519 keypairs with did:key identifiers |
sign_and_verify.py |
Sign and verify raw messages |
resolve_did_key.py |
Resolve a did:key to a verification method |
encode_decode_did_key.py |
Convert between raw key bytes and did:key strings |
parse_did_url.py |
Strict DID and DID URL parsing |
multibase_multicodec.py |
Low-level multibase/multicodec utilities |
jcs_canonicalization.py |
RFC 8785 / JCS canonicalization |
verify_proof_jcs.py |
JCS-based proof verification (zcap-dotnet interop) |
verify_proof_w3c.py |
W3C URDNA2015 proof verification (requires pyld) |
parse_capability.py |
Parse and validate ZCAP-LD capabilities |
parse_invocation.py |
Parse and validate ZCAP-LD invocations |
error_handling.py |
Structured exception handling |
Run any example with:
uv run python examples/key_generation.py
Requirements
- Python 3.11+
- Runtime dependencies:
cryptography>=41.0,multiformats>=0.3.1,rfc8785>=0.1.4 - Optional:
pyld>=2.0(for W3C URDNA2015 proof verification — install withpip install zcap-py[jsonld])
Project Status
This library is in active development. Phase 1 (crypto & DID foundation) and Phase 2 (JCS canonicalization, proof verification, document parsing) are complete. Upcoming phases will add delegation chain verification, invocation verification, and async support.
Reference Specification
Contributing
See CONTRIBUTING.md for setup instructions and guidelines.
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zcap_py-0.6.0.tar.gz.
File metadata
- Download URL: zcap_py-0.6.0.tar.gz
- Upload date:
- Size: 137.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29d46504fcd270c49f698155e975e225f6c516f8fcd479dc329aff820314dee1
|
|
| MD5 |
f0489a4aaa4bee776ee9db2489e78b63
|
|
| BLAKE2b-256 |
ff9632a8fe5d1b833b378fcf00c298fa21c143f344d0d98f10aecd37f77b731d
|
Provenance
The following attestation bundles were made for zcap_py-0.6.0.tar.gz:
Publisher:
publish.yml on moisesja/zcap-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zcap_py-0.6.0.tar.gz -
Subject digest:
29d46504fcd270c49f698155e975e225f6c516f8fcd479dc329aff820314dee1 - Sigstore transparency entry: 1438714052
- Sigstore integration time:
-
Permalink:
moisesja/zcap-py@9e8c8fbf7f1c6e39d11d360cda8d2128c4e2ab73 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/moisesja
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e8c8fbf7f1c6e39d11d360cda8d2128c4e2ab73 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file zcap_py-0.6.0-py3-none-any.whl.
File metadata
- Download URL: zcap_py-0.6.0-py3-none-any.whl
- Upload date:
- Size: 35.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7aa9a5199ebc2a1cb2956a93796d7925dd4bf85683a80fecea56261978c6dec
|
|
| MD5 |
d6467dbb8a0a3f64b003f1b6796ee72a
|
|
| BLAKE2b-256 |
d8e8fa5a5c508f99f530ad7defb50f2c4046a5e135040231c423d4b817f0a6be
|
Provenance
The following attestation bundles were made for zcap_py-0.6.0-py3-none-any.whl:
Publisher:
publish.yml on moisesja/zcap-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
zcap_py-0.6.0-py3-none-any.whl -
Subject digest:
a7aa9a5199ebc2a1cb2956a93796d7925dd4bf85683a80fecea56261978c6dec - Sigstore transparency entry: 1438714064
- Sigstore integration time:
-
Permalink:
moisesja/zcap-py@9e8c8fbf7f1c6e39d11d360cda8d2128c4e2ab73 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/moisesja
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9e8c8fbf7f1c6e39d11d360cda8d2128c4e2ab73 -
Trigger Event:
workflow_dispatch
-
Statement type: