Skip to main content

OpenPGP envelope signer for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_signing_pgp


Swarmauri Signing PGP

The swarmauri_signing_pgp package provides an OpenPGP signer for the Swarmauri SDK. It creates and verifies detached signatures over raw byte payloads or structured envelopes that are canonicalized to JSON or, optionally, CBOR.

Features

  • Detached OpenPGP signatures for bytes and envelopes
  • JSON canonicalization with optional CBOR support via cbor2
  • Multi-signer verification with configurable minimum signer requirements
  • Private key loading from in-memory pgpy objects or ASCII-armored blobs
  • Passphrase handling for locked private keys

Installation

Install the package with your preferred Python packaging tool:

pip install swarmauri_signing_pgp
poetry add swarmauri_signing_pgp
uv pip install swarmauri_signing_pgp

Optional CBOR support

Enable canonicalization to CBOR by installing the optional dependency group:

pip install "swarmauri_signing_pgp[cbor]"
poetry add swarmauri_signing_pgp -E cbor
uv pip install "swarmauri_signing_pgp[cbor]"

Usage

The signer exposes asynchronous methods from the Swarmauri signing base class. Key references are dictionaries describing how to load private keys. For pgpy objects, the signer expects a mapping such as {"kind": "pgpy_key", "priv": pgpy_key}. Verification requires the corresponding public keys supplied in the opts={"pubkeys": [...]} argument.

Sign and verify raw bytes

import asyncio

from pgpy import PGPKey, PGPUID
from pgpy.constants import (
    CompressionAlgorithm,
    HashAlgorithm,
    KeyFlags,
    PubKeyAlgorithm,
    SymmetricKeyAlgorithm,
)

from swarmauri_signing_pgp import PgpEnvelopeSigner


def make_demo_key() -> PGPKey:
    key = PGPKey.new(PubKeyAlgorithm.RSAEncryptOrSign, 2048)
    uid = PGPUID.new("Example User", email="user@example.com")
    key.add_uid(
        uid,
        usage={KeyFlags.Sign},
        hashes=[HashAlgorithm.SHA256],
        ciphers=[SymmetricKeyAlgorithm.AES256],
        compression=[CompressionAlgorithm.ZLIB],
    )
    return key


async def main() -> None:
    signer = PgpEnvelopeSigner()
    key = make_demo_key()
    key_ref = {"kind": "pgpy_key", "priv": key}
    payload = b"openpgp demo"

    signatures = await signer.sign_bytes(key_ref, payload)
    verified = await signer.verify_bytes(
        payload,
        signatures,
        opts={"pubkeys": [key.pubkey]},
    )
    print("Verified:", verified)


asyncio.run(main())

The signer returns detached signatures that include both binary and ASCII-armored representations. Passphrases for locked private keys can be supplied through opts={"passphrase": "secret"}.

Sign envelopes

Envelopes are canonicalized before signing. JSON canonicalization is always available and CBOR becomes available when the optional dependency group is installed:

envelope = {"subject": "demo", "body": "hello"}
signatures = await signer.sign_envelope(key_ref, envelope, canon="json")
await signer.verify_envelope(
    envelope,
    signatures,
    canon="json",
    opts={"pubkeys": [key.pubkey]},
)

Use canon="cbor" to opt into CBOR canonicalization. The supports() helper exposes the available algorithms, canonicalization formats, and feature flags at runtime.

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

swarmauri_signing_pgp-0.3.0.dev45.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_signing_pgp-0.3.0.dev45-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_signing_pgp-0.3.0.dev45.tar.gz.

File metadata

  • Download URL: swarmauri_signing_pgp-0.3.0.dev45.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_signing_pgp-0.3.0.dev45.tar.gz
Algorithm Hash digest
SHA256 dabbec7c85ac5ef58edf9693d6d5df8d05b18c2059d413a558fd3b6095d7fd80
MD5 336830e9b71c922f67a5f17afe83c265
BLAKE2b-256 51160e800b3459923c1a9b4c84d66c67247744115ace6e475c39d04f0e9b97e3

See more details on using hashes here.

File details

Details for the file swarmauri_signing_pgp-0.3.0.dev45-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_signing_pgp-0.3.0.dev45-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_signing_pgp-0.3.0.dev45-py3-none-any.whl
Algorithm Hash digest
SHA256 d564f1b044a44c4b55f04473361b28b89774f80d2c6810e845198e6dc2fd6d83
MD5 8367b5938c179f19d4c5ae54c0953c22
BLAKE2b-256 8bfd91b905fc58fa63e793b6dc078a0571c9b736684040155cd29d5c63dac41d

See more details on using hashes here.

Supported by

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