Skip to main content

secp256k1-based signer for Swarmauri

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_signing_secp256k1


Swarmauri Signing Secp256k1

An opinionated secp256k1 ECDSA signer that implements the Swarmauri ISigning interface for detached signatures over raw bytes and canonicalized envelopes.

Features

  • Asynchronous APIsign_bytes, verify_bytes, sign_envelope, and verify_envelope operate with asyncio and return canonical Swarmauri signature payloads.
  • Multiple canonicalizations – JSON canonicalization is always available, while CBOR canonicalization can be enabled with the optional cbor2 dependency.
  • Flexible key loading – accepts PEM strings/paths, JWK dictionaries, or native cryptography key objects via the KeyRef protocol.
  • Deterministic verification requirements – verification expects one or more secp256k1 public keys provided through opts["pubkeys"].
  • Signature format control – DER encoding is returned by default; supply opts={"format": "RAW"} when signing or verifying to work with JOSE-style r || s concatenated signatures.

Installation

The package requires cryptography and, optionally, cbor2 when CBOR canonicalization is needed.

pip install swarmauri_signing_secp256k1

# install with CBOR canonicalization support
pip install "swarmauri_signing_secp256k1[cbor]"
poetry add swarmauri_signing_secp256k1
uv add swarmauri_signing_secp256k1

# with the optional CBOR extra
uv add "swarmauri_signing_secp256k1[cbor]"

Usage

Sign and verify raw bytes

The signer derives a key identifier (kid) from the provided private key and requires the corresponding public key when verifying signatures.

import asyncio

from cryptography.hazmat.primitives.asymmetric import ec

from swarmauri_signing_secp256k1 import Secp256k1EnvelopeSigner


async def main() -> bool:
    signer = Secp256k1EnvelopeSigner()

    private_key = ec.generate_private_key(ec.SECP256K1())
    key_ref = {"kind": "cryptography_obj", "obj": private_key}

    payload = b"hello from secp256k1"
    signatures = await signer.sign_bytes(key_ref, payload)

    public_key_ref = {
        "kind": "cryptography_obj",
        "obj": private_key.public_key(),
    }
    is_valid = await signer.verify_bytes(
        payload,
        signatures,
        opts={"pubkeys": [public_key_ref]},
    )

    print(f"Signature valid? {is_valid}")
    assert is_valid
    return is_valid


if __name__ == "__main__":
    asyncio.run(main())

Canonicalized envelopes

To sign envelopes, pass JSON-serializable dictionaries (and optionally canon="cbor"). Canonicalization reuses the same raw signing logic shown above:

envelope = {"payload": {"msg": "hello"}}
signatures = await signer.sign_envelope(key_ref, envelope, canon="json")
is_valid = await signer.verify_envelope(
    envelope,
    signatures,
    opts={"pubkeys": [public_key_ref]},
)

Entry Point

The signer registers under the swarmauri.signings entry point as Secp256k1EnvelopeSigner.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

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_secp256k1-0.3.0.dev46.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file swarmauri_signing_secp256k1-0.3.0.dev46.tar.gz.

File metadata

  • Download URL: swarmauri_signing_secp256k1-0.3.0.dev46.tar.gz
  • Upload date:
  • Size: 13.0 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_secp256k1-0.3.0.dev46.tar.gz
Algorithm Hash digest
SHA256 58b4eab94ffab7793f13db96d7193675a1e80a734a33b7f62c9f3e12e376ca8d
MD5 146fadc2f70dacecff01bd7a733c97c7
BLAKE2b-256 c54561f57285c9cd7433f06f05126919f02b3a6116b21a063fc9cbaa5358a324

See more details on using hashes here.

File details

Details for the file swarmauri_signing_secp256k1-0.3.0.dev46-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_signing_secp256k1-0.3.0.dev46-py3-none-any.whl
  • Upload date:
  • Size: 12.9 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_secp256k1-0.3.0.dev46-py3-none-any.whl
Algorithm Hash digest
SHA256 1da2ff39f0f3c78c9ffd527a215e5f5008671e4cd162a523e45f460bf957cced
MD5 9e7f49088f6bfc19dccaf5579873b55c
BLAKE2b-256 9d618357cbea2d884ce220796542c2da2dd3b877a548c52ba111f3354c8fbc1e

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