Skip to main content

A library to convert between Sigstore Bundles and PEP-740 Attestation objects

Project description

PyPI Attestation Models

CI PyPI version Packaging status

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypi_attestation_models-0.0.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

pypi_attestation_models-0.0.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file pypi_attestation_models-0.0.3.tar.gz.

File metadata

File hashes

Hashes for pypi_attestation_models-0.0.3.tar.gz
Algorithm Hash digest
SHA256 6ed9749e839b264b33c66ce4aa628ab1287014f5e2ae3a5738364f7511be08d5
MD5 79e21089b3c07d58d6377d878e0cbb17
BLAKE2b-256 481b6bb195314a5a26298dd4739ee6c8ea80957aba7580344b328ce9d625ac45

See more details on using hashes here.

File details

Details for the file pypi_attestation_models-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for pypi_attestation_models-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e5fe84f92f37a03c1a69de5d060cd54b59a2f5728a5c20cf0ae3aa3303be8863
MD5 2b0b8f1bacae23970566673cb29fdcce
BLAKE2b-256 72e9910fa4f1f2439bb0fca55683b2e3b09ba59720b5e9081d1883bf5fbe2fc9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page