Metadata-Version: 2.1
Name: stealth25519
Version: 1.0.4
Summary: The Stealth25519 Python package provides functionality for the generation, verification, and signing of stealth addresses using the standard ed25519 algorithm with the ECDH protocol.
Description-Content-Type: text/markdown

# Stealth25519 Python Package

The `Stealth25519` Python package provides functionality for the generation, verification, and signing of stealth addresses using the standard ed25519 algorithm with the ECDH protocol.

## Stealth Address Features

- The sender can generate a stealth address using the public view and spend key of the recipient.
- The recipient can use their public spend key and private view key to identify transactions intended for them.
- The recipient can sign transactions for all transactions that belong to them.
- The signature generated by the recipient can be verified by anyone with the stealth address public key.

## Installation

```bash
pip install stealth25519
```

## Example Usage

### Generating and Loading Private Keys

```python
from cryptography.hazmat.primitives.asymmetric import ed25519
from stealth25519.StealthAddress import PrivateKey, PublicKey

# Generate or load private key from cryptography or any other library as bytes array
private_spend_key = ed25519.Ed25519PrivateKey.generate()
private_view_key = ed25519.Ed25519PrivateKey.generate()

privateSpendKey = PrivateKey(private_spend_key.private_bytes_raw())
privateViewKey = PrivateKey(private_view_key.private_bytes_raw())

publicSpendKey = privateSpendKey.generatePublicKey()
publicViewKey = privateViewKey.generatePublicKey()

print('Private spend key: ', privateSpendKey)
print('Private view key: ', privateViewKey)
print('Public spend key: ', publicSpendKey)
print('Public view key: ', publicViewKey)
```

### Output

After generating and loading the private keys, the output would be:

```plaintext
Private spend key:  6e2096a4aeb83752be2c2072d26d8c526c9bb7c5957289fc6feb85bd7da8dbf3
Private view key:   0f516f860b87d991924be8dbe00f15d8633ee6168b77e38ef7646771d8056d56
Public spend key:   c32dd358fa8fbea62d3b875c7b0db1631a39b643ff7a8f180de4878b2298be06
Public view key:    874e1029399477a9537b5015580ff8cc4701ecd8ced251fbe75ba7b9cc3fb3be
```



### Generating a Stealth Address

```python
from stealth25519.StealthAddress import StealthAddressGenerator

publicSpendKeyBytes = bytes.fromhex('18a498c68461e39dd180745e5aa1faacbc9b8a5f74a7eb25b5038b66db0a4af6')
publicViewKeyBytes = bytes.fromhex('b52c33b513c26e17b7105cb1ed1c7022ef00f3967aaac0ff8bd9d15ccee4d94e')

publicSpendKey = PublicKey(publicSpendKeyBytes)
publicViewKey = PublicKey(publicViewKeyBytes)

stealthAddressGenerator = StealthAddressGenerator(publicSpendKey, publicViewKey)
stealthAddress = stealthAddressGenerator.generate()
print('Stealth Address\n', stealthAddress)
```

### Output

After generating the stealth address the output would be:

```plaintext
Stealth Address
R: 140a81dee57fa89e92f6b66df2b33867dc0a4469fdf006249c868e7bd98f65e9
P: 6f6e46287d47112a82511c2de36ef006f1f7a7b9899645267029df9c6fb510eb
```

### Verifying a Stealth Address

```python
from stealth25519.StealthAddress import StealthAddressVerifier

privateViewKeyBytes = bytes.fromhex('8cdc2d3879363eff3c187ee494c7154ac63a4b94c1814488fd46c4f2bafc2239')
publicSpendKeyBytes = bytes.fromhex('18a498c68461e39dd180745e5aa1faacbc9b8a5f74a7eb25b5038b66db0a4af6')
R = bytes.fromhex('72e46affe404d301b2546ac420a209929e98120526b677b9576fd4f687691b51')
P = bytes.fromhex('f5ec778dfcf57e8b736729efdcbb458110e814c8bec4ef5667e2d7571cbbc8c4')

privateViewKey = PrivateKey(privateViewKeyBytes)
publicSpendKey = PublicKey(publicSpendKeyBytes)

stealthAddress = StealthAddress(R, P)
stealthAddressVerifier = StealthAddressVerifier(privateViewKey, publicSpendKey)
results = stealthAddressVerifier.verify(stealthAddress)

print('Stealth address verified: ', results)
```

### Output

The verification of the stealth address would output:

```plaintext
Stealth address verified:  True
```

### Signing a Stealth Address

```python
from stealth25519.StealthAddress import StealthAddressSigner

privateSpendKeyBytes = bytes.fromhex('da4956d53efc1c48472080ca284948399ef5dcb1feb47ebd5017330ca2416c30')
privateViewKeyBytes = bytes.fromhex('8cdc2d3879363eff3c187ee494c7154ac63a4b94c1814488fd46c4f2bafc2239')
R = bytes.fromhex('8a7b9c5bbce1ddb29893bbf96bd3a278d9f4576018c384c1d2f337012607cc1c')
P = bytes.fromhex('1d3796436ecf22b674f60990945fb09d4a5dd4ad6c16e04dd20ff46e71935fc5')

privateSpendKey = PrivateKey(privateSpendKeyBytes)
privateViewKey = PrivateKey(privateViewKeyBytes)

msg = b'somedata'
stealthAddress = StealthAddress(R, P)
stealthAddressSigner = StealthAddressSigner(privateSpendKey, privateViewKey)
sig = stealthAddressSigner.sign(stealthAddress, msg).hex()
print('Stealth signature: ', sig)

```

### Output
```plaintext
Stealth signature:  56dcf17a9fd91b7d3d0dffc7ea86fd1cb1dda94caff964c2533c63ecd52166377684fa60f2cfe5258f9e5c8247db4e5003a73c1d0fbd42c56f31a7b996089404
```

### Signature Verification
The signature generated using the private spend key can be verified using the public key of the stealth address (P). This verification can be done by anyone using the ed25519 signature algorithm (ECDSA). 

```python
from cryptography.hazmat.primitives.asymmetric import ed25519

def verify_ed25519_signature(public_key_bytes, signature_bytes, message):
    public_key = ed25519.Ed25519PublicKey.from_public_bytes(public_key_bytes)
    try:
        public_key.verify(signature_bytes, message)
        return True
    except Exception as e:
        print(f"Signature verification failed: {str(e)}")
        return False

public_key_hex = '1d3796436ecf22b674f60990945fb09d4a5dd4ad6c16e04dd20ff46e71935fc5'
signature_hex = '56dcf17a9fd91b7d3d0dffc7ea86fd1cb1dda94caff964c2533c63ecd52166377684fa60f2cfe5258f9e5c8247db4e5003a73c1d0fbd42c56f31a7b996089404'
message = b'somedata'

public_key_bytes = bytes.fromhex(public_key_hex)
signature_bytes = bytes.fromhex(signature_hex)


verification_result = verify_ed25519_signature(public_key_bytes, signature_bytes, message)
print('Signature verification result:', verification_result)
```

### Output
```plaintext
Signature verification result: True
```
