blsttc


Nameblsttc JSON
Version 8.0.4 PyPI version JSON
download
home_pageNone
SummaryBLS threshold token cryptography
upload_time2024-12-23 00:41:13
maintainerNone
docs_urlNone
authorMaidSafe Developers <dev@maidsafe.net>
requires_python>=3.8
licenseMIT OR Apache-2.0
keywords cryptography bls threshold
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # BLSTTC Python Bindings

Python bindings for the BLSTTC (BLS Threshold Token Cryptography) library, providing BLS (Boneh-Lynn-Shacham) signatures and threshold cryptography functionality.

## Installation

```bash
pip install blsttc
```

## Features

- **BLS Signatures**: Create and verify BLS signatures
- **Public Key Encryption**: Encrypt and decrypt messages using BLS public keys
- **Threshold Signatures**: Create threshold signature schemes where t+1 parties must collaborate to sign
- **Threshold Encryption**: Implement threshold encryption where t+1 parties must collaborate to decrypt
- **Derived Keys**: Generate child keys from master keys

## Quick Start

Here's a simple example demonstrating basic signature functionality:

```python
from blsttc import SecretKey

# Create a new secret key
sk = SecretKey()

# Get the corresponding public key
pk = sk.public_key()

# Sign a message
message = b"Hello, BLS!"
signature = sk.sign(message)

# Verify the signature
assert pk.verify(signature, message)
```

## API Reference

### SecretKey

Secret key for signing and deriving child keys.

Methods:
- `new()`: Create a new random secret key
- `sign(message: bytes) -> Signature`: Sign a message
- `public_key() -> PublicKey`: Get the corresponding public key
- `derive_child(index: bytes) -> SecretKey`: Derive a child secret key
- `to_bytes() -> bytes`: Serialize the secret key
- `from_bytes(bytes) -> SecretKey`: Deserialize a secret key

### PublicKey

Public key for signature verification and encryption.

Methods:
- `verify(signature: Signature, message: bytes) -> bool`: Verify a signature
- `encrypt(message: bytes) -> bytes`: Encrypt a message
- `to_bytes() -> bytes`: Serialize the public key
- `from_bytes(bytes) -> PublicKey`: Deserialize a public key

### SecretKeySet

A set of secret keys for threshold schemes.

Methods:
- `new(threshold: int) -> SecretKeySet`: Create a new threshold key set
- `threshold() -> int`: Get the threshold value
- `secret_key_share(index: int) -> SecretKey`: Get a secret key share
- `public_keys() -> PublicKeySet`: Get the corresponding public key set
- `decrypt_share(index: int, ciphertext: bytes) -> DecryptionShare`: Generate a decryption share

### PublicKeySet

A set of public keys for threshold schemes.

Methods:
- `threshold() -> int`: Get the threshold value
- `public_key() -> PublicKey`: Get the master public key
- `public_key_share(index: int) -> PublicKey`: Get a public key share
- `decrypt(shares: List[Tuple[int, DecryptionShare]], ciphertext: bytes) -> bytes`: Combine shares to decrypt

### DecryptionShare

A share of a decrypted ciphertext in threshold encryption.

Methods:
- `to_bytes() -> bytes`: Serialize the decryption share
- `from_bytes(bytes) -> DecryptionShare`: Deserialize a decryption share

## Examples

### Threshold Signatures

```python
from blsttc import SecretKeySet

# Create a threshold signature scheme (threshold = 2)
sks = SecretKeySet(2)
pks = sks.public_keys()

# Get individual key shares
sk_share1 = sks.secret_key_share(1)
sk_share2 = sks.secret_key_share(2)
sk_share3 = sks.secret_key_share(3)

# Get corresponding public key shares
pk_share1 = pks.public_key_share(1)
pk_share2 = pks.public_key_share(2)
pk_share3 = pks.public_key_share(3)
```

### Threshold Encryption

```python
from blsttc import SecretKeySet

# Create a threshold encryption scheme (threshold = 2)
sks = SecretKeySet(2)
pks = sks.public_keys()

# Encrypt a message with the master public key
message = b"Secret message requiring multiple parties to decrypt!"
ciphertext = bytes(pks.public_key().encrypt(message))

# Get decryption shares from different parties
shares = []
for i in [1, 2, 3]:  # We need threshold + 1 = 3 shares
    share = sks.decrypt_share(i, ciphertext)
    shares.append((i, share))

# Combine shares to decrypt the message
decrypted = bytes(pks.decrypt(shares, ciphertext))
assert decrypted == message
```

### Derived Keys

```python
from blsttc import SecretKey

# Create a master key
master_sk = SecretKey()
master_pk = master_sk.public_key()

# Derive child keys
child_index = b"child_1"
child_sk = master_sk.derive_child(child_index)
child_pk = child_sk.public_key()

# Sign with both keys
message = b"Test message"
master_sig = master_sk.sign(message)
child_sig = child_sk.sign(message)

# Verify signatures
assert master_pk.verify(master_sig, message)
assert child_pk.verify(child_sig, message)
```

### Creating Keys from Bytes

You can create deterministic keys by providing specific bytes:

```python
from blsttc import SecretKey
import os

# Create a deterministic key from 32 bytes
seed = os.urandom(32)  # In practice, use a proper seed generation method
sk = SecretKey.from_bytes(seed)
pk = sk.public_key()

# This will always create the same key pair given the same seed bytes
sk2 = SecretKey.from_bytes(seed)
assert sk2.public_key().to_bytes() == pk.to_bytes()
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

## License

This project is licensed under either of

 * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
   http://www.apache.org/licenses/LICENSE-2.0)
 * MIT license ([LICENSE-MIT](LICENSE-MIT) or
   http://opensource.org/licenses/MIT)

at your option.


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "blsttc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "cryptography, BLS, threshold",
    "author": "MaidSafe Developers <dev@maidsafe.net>",
    "author_email": "MaidSafe Developers <dev@maidsafe.net>",
    "download_url": "https://files.pythonhosted.org/packages/84/2d/b87a3857f971a35332c9d7843c796fab4bf90704c78a0b7390c220b47bad/blsttc-8.0.4.tar.gz",
    "platform": null,
    "description": "# BLSTTC Python Bindings\n\nPython bindings for the BLSTTC (BLS Threshold Token Cryptography) library, providing BLS (Boneh-Lynn-Shacham) signatures and threshold cryptography functionality.\n\n## Installation\n\n```bash\npip install blsttc\n```\n\n## Features\n\n- **BLS Signatures**: Create and verify BLS signatures\n- **Public Key Encryption**: Encrypt and decrypt messages using BLS public keys\n- **Threshold Signatures**: Create threshold signature schemes where t+1 parties must collaborate to sign\n- **Threshold Encryption**: Implement threshold encryption where t+1 parties must collaborate to decrypt\n- **Derived Keys**: Generate child keys from master keys\n\n## Quick Start\n\nHere's a simple example demonstrating basic signature functionality:\n\n```python\nfrom blsttc import SecretKey\n\n# Create a new secret key\nsk = SecretKey()\n\n# Get the corresponding public key\npk = sk.public_key()\n\n# Sign a message\nmessage = b\"Hello, BLS!\"\nsignature = sk.sign(message)\n\n# Verify the signature\nassert pk.verify(signature, message)\n```\n\n## API Reference\n\n### SecretKey\n\nSecret key for signing and deriving child keys.\n\nMethods:\n- `new()`: Create a new random secret key\n- `sign(message: bytes) -> Signature`: Sign a message\n- `public_key() -> PublicKey`: Get the corresponding public key\n- `derive_child(index: bytes) -> SecretKey`: Derive a child secret key\n- `to_bytes() -> bytes`: Serialize the secret key\n- `from_bytes(bytes) -> SecretKey`: Deserialize a secret key\n\n### PublicKey\n\nPublic key for signature verification and encryption.\n\nMethods:\n- `verify(signature: Signature, message: bytes) -> bool`: Verify a signature\n- `encrypt(message: bytes) -> bytes`: Encrypt a message\n- `to_bytes() -> bytes`: Serialize the public key\n- `from_bytes(bytes) -> PublicKey`: Deserialize a public key\n\n### SecretKeySet\n\nA set of secret keys for threshold schemes.\n\nMethods:\n- `new(threshold: int) -> SecretKeySet`: Create a new threshold key set\n- `threshold() -> int`: Get the threshold value\n- `secret_key_share(index: int) -> SecretKey`: Get a secret key share\n- `public_keys() -> PublicKeySet`: Get the corresponding public key set\n- `decrypt_share(index: int, ciphertext: bytes) -> DecryptionShare`: Generate a decryption share\n\n### PublicKeySet\n\nA set of public keys for threshold schemes.\n\nMethods:\n- `threshold() -> int`: Get the threshold value\n- `public_key() -> PublicKey`: Get the master public key\n- `public_key_share(index: int) -> PublicKey`: Get a public key share\n- `decrypt(shares: List[Tuple[int, DecryptionShare]], ciphertext: bytes) -> bytes`: Combine shares to decrypt\n\n### DecryptionShare\n\nA share of a decrypted ciphertext in threshold encryption.\n\nMethods:\n- `to_bytes() -> bytes`: Serialize the decryption share\n- `from_bytes(bytes) -> DecryptionShare`: Deserialize a decryption share\n\n## Examples\n\n### Threshold Signatures\n\n```python\nfrom blsttc import SecretKeySet\n\n# Create a threshold signature scheme (threshold = 2)\nsks = SecretKeySet(2)\npks = sks.public_keys()\n\n# Get individual key shares\nsk_share1 = sks.secret_key_share(1)\nsk_share2 = sks.secret_key_share(2)\nsk_share3 = sks.secret_key_share(3)\n\n# Get corresponding public key shares\npk_share1 = pks.public_key_share(1)\npk_share2 = pks.public_key_share(2)\npk_share3 = pks.public_key_share(3)\n```\n\n### Threshold Encryption\n\n```python\nfrom blsttc import SecretKeySet\n\n# Create a threshold encryption scheme (threshold = 2)\nsks = SecretKeySet(2)\npks = sks.public_keys()\n\n# Encrypt a message with the master public key\nmessage = b\"Secret message requiring multiple parties to decrypt!\"\nciphertext = bytes(pks.public_key().encrypt(message))\n\n# Get decryption shares from different parties\nshares = []\nfor i in [1, 2, 3]:  # We need threshold + 1 = 3 shares\n    share = sks.decrypt_share(i, ciphertext)\n    shares.append((i, share))\n\n# Combine shares to decrypt the message\ndecrypted = bytes(pks.decrypt(shares, ciphertext))\nassert decrypted == message\n```\n\n### Derived Keys\n\n```python\nfrom blsttc import SecretKey\n\n# Create a master key\nmaster_sk = SecretKey()\nmaster_pk = master_sk.public_key()\n\n# Derive child keys\nchild_index = b\"child_1\"\nchild_sk = master_sk.derive_child(child_index)\nchild_pk = child_sk.public_key()\n\n# Sign with both keys\nmessage = b\"Test message\"\nmaster_sig = master_sk.sign(message)\nchild_sig = child_sk.sign(message)\n\n# Verify signatures\nassert master_pk.verify(master_sig, message)\nassert child_pk.verify(child_sig, message)\n```\n\n### Creating Keys from Bytes\n\nYou can create deterministic keys by providing specific bytes:\n\n```python\nfrom blsttc import SecretKey\nimport os\n\n# Create a deterministic key from 32 bytes\nseed = os.urandom(32)  # In practice, use a proper seed generation method\nsk = SecretKey.from_bytes(seed)\npk = sk.public_key()\n\n# This will always create the same key pair given the same seed bytes\nsk2 = SecretKey.from_bytes(seed)\nassert sk2.public_key().to_bytes() == pk.to_bytes()\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.\n\n## License\n\nThis project is licensed under either of\n\n * Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or\n   http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or\n   http://opensource.org/licenses/MIT)\n\nat your option.\n\n",
    "bugtrack_url": null,
    "license": "MIT OR Apache-2.0",
    "summary": "BLS threshold token cryptography",
    "version": "8.0.4",
    "project_urls": {
        "Source Code": "https://github.com/maidsafe/blsttc"
    },
    "split_keywords": [
        "cryptography",
        " bls",
        " threshold"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "842db87a3857f971a35332c9d7843c796fab4bf90704c78a0b7390c220b47bad",
                "md5": "7cff64fc203b30d5d949337ec9255bc5",
                "sha256": "291fb7b1be525809f1b5e1502a74302b7df8af45ad69f643f2227e2d09dd9870"
            },
            "downloads": -1,
            "filename": "blsttc-8.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "7cff64fc203b30d5d949337ec9255bc5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 74652,
            "upload_time": "2024-12-23T00:41:13",
            "upload_time_iso_8601": "2024-12-23T00:41:13.592101Z",
            "url": "https://files.pythonhosted.org/packages/84/2d/b87a3857f971a35332c9d7843c796fab4bf90704c78a0b7390c220b47bad/blsttc-8.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-23 00:41:13",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "maidsafe",
    "github_project": "blsttc",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "blsttc"
}
        
Elapsed time: 2.20680s