Skip to main content

Heavymeta Stellar Utilities for Python , By: Fibo Metavinci

Project description

hvym_stellar

A Python library for secure token generation and verification using Stellar keypairs. This package provides a robust way to create and verify tokens with support for expiration, access control, and secret sharing.

Features

  • Secure Token Generation: Create cryptographically secure tokens using Stellar keypairs
  • Token Expiration: Set token expiration times to enhance security
  • Access Control: Define fine-grained access control through caveats
  • Secret Sharing: Securely share secrets between parties
  • Backward Compatibility: Support for legacy token verification
  • Timestamp Validation: Built-in support for token expiration and max age validation

Installation

pip install hvym_stellar

Dependencies

  • PyNaCl (Python binding to libsodium)
  • pymacaroons (Macaroon token support)
  • stellar-sdk (Stellar keypair and address handling)
  • base58 (For encoding/decoding)
  • cryptography (For encryption/decryption)

Basic Usage

1. Creating a Token

from hvym_stellar import StellarSharedKeyTokenBuilder, TokenType
from stellar_sdk import Keypair

# Generate or load Stellar keypairs
sender_kp = Keypair.random()
receiver_kp = Keypair.random()

# Create a new token
token = StellarSharedKeyTokenBuilder(
    sender_kp,
    receiver_kp.public_key,
    token_type=TokenType.ACCESS,
    expires_in=3600,  # 1 hour expiration
    caveats={"user_id": "123", "role": "admin"}
)

# Serialize the token for transmission
serialized_token = token.serialize()

2. Verifying a Token

from hvym_stellar import StellarSharedKeyTokenVerifier, TokenType

# Verify the token
verifier = StellarSharedKeyTokenVerifier(
    receiver_kp,
    serialized_token,
    TokenType.ACCESS,
    expected_caveats={"user_id": "123"},
    max_age_seconds=3600  # Optional: enforce maximum token age
)

if verifier.valid():
    print("Token is valid!")
    
    # Access token claims
    print("Token expires at:", verifier.get_expiration_time())
    print("Is expired:", verifier.is_expired())

3. Sharing Secrets

# Sender: Create token with a secret
secret_data = "sensitive-information-here"
token_with_secret = StellarSharedKeyTokenBuilder(
    sender_kp,
    receiver_kp.public_key,
    token_type=TokenType.SECRET,
    secret=secret_data,
    expires_in=300  # 5 minutes
)
serialized_secret_token = token_with_secret.serialize()

# Receiver: Extract the secret
verifier = StellarSharedKeyTokenVerifier(
    receiver_kp,
    serialized_secret_token,
    TokenType.SECRET
)

if verifier.valid():
    try:
        secret = verifier.secret()
        print("Retrieved secret:", secret)
    except ValueError as e:
        print("Failed to retrieve secret:", str(e))

Token Types

Access Tokens

  • Used for API authentication and authorization
  • Can include custom caveats for access control
  • Support expiration and max age validation

Secret Tokens

  • Used for securely sharing sensitive information
  • Automatically encrypted using the receiver's public key
  • Can be decrypted only by the intended recipient

Security Considerations

  • Always use HTTPS when transmitting tokens
  • Set appropriate expiration times for tokens
  • Validate all token claims and caveats on the server side
  • Rotate encryption keys regularly
  • Keep private keys secure and never commit them to version control

License

MIT License - See LICENSE for details.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

Version History

  • 0.1.0: Initial release
  • 0.9.0: Added timestamp validation and expiration support

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

hvym_stellar-0.13.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

hvym_stellar-0.13-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file hvym_stellar-0.13.tar.gz.

File metadata

  • Download URL: hvym_stellar-0.13.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for hvym_stellar-0.13.tar.gz
Algorithm Hash digest
SHA256 05ef2d1f972bfdbb2e512af2320f0164a215654d9f41959985c8742cc213cf8c
MD5 040ab04557e7210b5f35d719b874904d
BLAKE2b-256 532c16751f43073a95f079a9f2f214c239fd6daaa1b6c84c4c3f30582d37bcf1

See more details on using hashes here.

File details

Details for the file hvym_stellar-0.13-py2.py3-none-any.whl.

File metadata

  • Download URL: hvym_stellar-0.13-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for hvym_stellar-0.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5740dc01d80b5a6c43c366091a2d22402b94ed2b71c8143efe3b06f033defa60
MD5 4be2ff0de813aad899eff0ce166b76fd
BLAKE2b-256 c67b3f30a46dbb3f0d75f35d9691d9666c7fed43553da5eff50a8d656bf2e459

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