A library to convert between Sigstore Bundles and PEP-740 Attestation objects
Project description
PyPI Attestation Models
A library to convert between Sigstore Bundles and PEP 740 Attestation objects
Installation
python -m pip install pypi-attestation-models
Usage
See the full API documentation here.
Signing and verification
Use these APIs to create a PEP 740-compliant Attestation
object by signing a Python artifact
(i.e: sdist or wheel files), and to verify an Attestation
object against a Python artifact.
from pathlib import Path
from pypi_attestation_models import Attestation, AttestationPayload
from sigstore.oidc import Issuer
from sigstore.sign import SigningContext
from sigstore.verify import Verifier, policy
artifact_path = Path("test_package-0.0.1-py3-none-any.whl")
# Sign a Python artifact
issuer = Issuer.production()
identity_token = issuer.identity_token()
signing_ctx = SigningContext.production()
with signing_ctx.signer(identity_token, cache=True) as signer:
attestation = AttestationPayload.from_dist(artifact_path).sign(signer)
print(attestation.model_dump_json())
# Verify an attestation against a Python artifact
attestation_path = Path("test_package-0.0.1-py3-none-any.whl.attestation")
attestation = Attestation.model_validate_json(attestation_path.read_bytes())
verifier = Verifier.production()
policy = policy.Identity(identity="example@gmail.com", issuer="https://accounts.google.com")
attestation.verify(verifier, policy, attestation_path)
Low-level model conversions
These conversions assume that any Sigstore Bundle used as an input was created
by signing an AttestationPayload
object.
from pathlib import Path
from pypi_attestation_models import pypi_to_sigstore, sigstore_to_pypi, Attestation
from sigstore.models import Bundle
# Sigstore Bundle -> PEP 740 Attestation object
bundle_path = Path("test_package-0.0.1-py3-none-any.whl.sigstore")
with bundle_path.open("rb") as f:
sigstore_bundle = Bundle.from_json(f.read())
attestation_object = sigstore_to_pypi(sigstore_bundle)
print(attestation_object.model_dump_json())
# PEP 740 Attestation object -> Sigstore Bundle
attestation_path = Path("attestation.json")
with attestation_path.open("rb") as f:
attestation = Attestation.model_validate_json(f.read())
bundle = pypi_to_sigstore(attestation)
print(bundle.to_json())
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file pypi_attestation_models-0.0.1.tar.gz
.
File metadata
- Download URL: pypi_attestation_models-0.0.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0c4c93e298f2b30f67d6fdb361e6f116de54f45163b8b85b643e4dc76075a29 |
|
MD5 | 3ecd272b889024bdf4694f595f2d9aae |
|
BLAKE2b-256 | ef6a5916e9a759a3a2e2c5623665510c1b0ee84b0b29a01f497f6116c4016521 |
File details
Details for the file pypi_attestation_models-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pypi_attestation_models-0.0.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26949a4acc81f2ed7a920ec8044bc567b4aa82b55b02f126e7b4e7a48150f6ca |
|
MD5 | a12dee0b3d8f1f0eb5bf61fb673e37f7 |
|
BLAKE2b-256 | df146ef517e450ca8d4116d611a201389dc911e5a530e24ff6440006605af20b |