Skip to main content

Provable SDK for Python

Project description

Provable SDK for Python

A Python SDK for interacting with the Provable Kayros API.

Installation

pip install provable-sdk

Usage

from provable_sdk import (
    keccak256,
    keccak256_str,
    sha256,
    sha256_str,
    prove_single_hash,
    get_record_by_hash,
    prove_data,
    prove_data_str,
    verify,
    KayrosEnvelope,
)

# Hash bytes (keccak256)
data = b'\x01\x02\x03\x04'
data_hash = keccak256(data)

# Hash string (sha256 - default)
text = "Hello, Provable!"
str_hash = sha256_str(text)

# Prove a hash
proof = prove_single_hash(data_hash)

# Get a record by hash
record = get_record_by_hash(proof["data"]["computed_hash_hex"])

# Prove data directly
data_proof = prove_data(data)

# Prove string data directly
str_proof = prove_data_str(text)

# Create and verify a KayrosEnvelope
envelope = KayrosEnvelope(
    data={"message": "Hello, Provable!"},
    kayros={
        "hash": str_hash,
        "hashAlgorithm": "sha256",
        "timestamp": {
            "service": "kayros",
            "response": proof,
        },
    },
)

result = verify(envelope)
if result["valid"]:
    print("Verification successful!")
else:
    print(f"Verification failed: {result['error']}")

API

Hash Functions

  • keccak256(data: bytes) -> str - Compute keccak256 hash of bytes
  • keccak256_str(s: str) -> str - Compute keccak256 hash of a UTF-8 string
  • sha256(data: bytes) -> str - Compute SHA-256 hash of bytes
  • sha256_str(s: str) -> str - Compute SHA-256 hash of a UTF-8 string
  • hash / hash_str - Aliases for keccak256 functions

Prove Functions

  • prove_single_hash(data_hash: str) -> ProveSingleHashResponse - Prove a hash via Kayros API
  • prove_data(data: bytes) -> ProveSingleHashResponse - Hash and prove bytes
  • prove_data_str(s: str) -> ProveSingleHashResponse - Hash and prove a string

Record Functions

  • get_record_by_hash(record_hash: str) -> GetRecordResponse - Get Kayros record by hash

Verify Function

  • verify(envelope: KayrosEnvelope) -> VerifyResult - Verify data against Kayros proof

KayrosEnvelope

The KayrosEnvelope class wraps data with Kayros proof metadata:

envelope = KayrosEnvelope(data=my_data, kayros=kayros_metadata)

# Helper methods
envelope.get_data()           # Get data as bytes (decodes base64 for V0)
envelope.get_data_hash()      # Get the data hash (data_item_hex)
envelope.get_data_type()      # Get the data type (data_type_hex)
envelope.get_kayros_hash()    # Get the Kayros hash (computed_hash_hex)
envelope.get_time_uuid()      # Get the time UUID (timeuuid_hex)
envelope.get_hash_algorithm() # Get hash algorithm (defaults to 'sha256')
envelope.is_v0()              # Check if V0 format (legacy, for email proofs)

Envelope Formats

  • V1 (default): Hash stored in kayros["hash"], data is plain string or object
  • V0 (legacy): Hash in kayros["data"]["data_item_hex"], data is base64-encoded bytes (used for email proofs)

License

MIT

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

provable_sdk-0.0.7.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

provable_sdk-0.0.7-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file provable_sdk-0.0.7.tar.gz.

File metadata

  • Download URL: provable_sdk-0.0.7.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for provable_sdk-0.0.7.tar.gz
Algorithm Hash digest
SHA256 2977156cdc4ba22b270757c1a9d59ee18b8acb4cf210a3b54faef34dd355bad0
MD5 247b685f570150bae0fd27160faea69b
BLAKE2b-256 507dbeeedbeb77201ac784f4dd2aaeac1b11cad072518caae802cb5438714c40

See more details on using hashes here.

File details

Details for the file provable_sdk-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: provable_sdk-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.4

File hashes

Hashes for provable_sdk-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 2758c60c6b28f090c5c49580e7f85a41c14e86bd8b587248efcb089f0d393b25
MD5 3bb9614133cab7c215878bf51f261233
BLAKE2b-256 ad020c42b87b7bc7400e3e5fc836743b5b8b165fdd8414a6ef9afdbd3ef7bd2c

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