Skip to main content

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

Project description

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

pip install stealth25519

Example Usage

Generating and Loading Private Keys

from cryptography.hazmat.primitives.asymmetric import ed25519
from stealth25519.key import PrivateKey, PublicKey

# Generate or load private key from cryptography or any other library as bytes array
private_spend_key_ = '6e2096a4aeb83752be2c2072d26d8c526c9bb7c5957289fc6feb85bd7da8dbf3'
private_view_key_ = ed25519.Ed25519PrivateKey.generate()

private_spend_key = PrivateKey(bytes.fromhex( private_spend_key_))
private_view_key = PrivateKey(private_view_key_.private_bytes_raw())

public_spend_key = private_spend_key.generatePublicKey()
public_view_key = private_view_key.generatePublicKey()

print('Private spend key: ', private_spend_key)
print('Private view key: ', private_view_key)
print('Public spend key: ', public_spend_key)
print('Public view key: ', public_view_key)

Output

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

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

Generating a Stealth Address

from stealth25519.generator import StealthAddressGenerator

public_spend_key_bytes = bytes.fromhex('18a498c68461e39dd180745e5aa1faacbc9b8a5f74a7eb25b5038b66db0a4af6')
public_view_key_bytes = bytes.fromhex('b52c33b513c26e17b7105cb1ed1c7022ef00f3967aaac0ff8bd9d15ccee4d94e')

public_spend_key = PublicKey(public_spend_key_bytes)
public_view_key = PublicKey(public_view_key_bytes)

generator = StealthAddressGenerator(public_spend_key, public_view_key)
stealth_address = generator.generate()
print('Stealth Address\n', stealth_address)

Output

After generating the stealth address the output would be:

Stealth Address
R: 140a81dee57fa89e92f6b66df2b33867dc0a4469fdf006249c868e7bd98f65e9
P: 6f6e46287d47112a82511c2de36ef006f1f7a7b9899645267029df9c6fb510eb

Verifying a Stealth Address

from stealth25519.verifier import StealthAddressVerifier

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

private_view_key = PrivateKey(private_view_key_bytes)
public_spend_key = PublicKey(public_spend_key_bytes)

stealth_address = StealthAddress(R, P)
verifier = StealthAddressVerifier(private_view_key, public_spend_key)
results = verifier.verify(stealth_address)

print('Stealth address verified: ', results)

Output

The verification of the stealth address would output:

Stealth address verified:  True

Signing a Stealth Address

from stealth25519.signer import StealthAddressSigner

private_spend_key_bytes = bytes.fromhex('da4956d53efc1c48472080ca284948399ef5dcb1feb47ebd5017330ca2416c30')
private_view_key_bytes = bytes.fromhex('8cdc2d3879363eff3c187ee494c7154ac63a4b94c1814488fd46c4f2bafc2239')
R = bytes.fromhex('8a7b9c5bbce1ddb29893bbf96bd3a278d9f4576018c384c1d2f337012607cc1c')
P = bytes.fromhex('1d3796436ecf22b674f60990945fb09d4a5dd4ad6c16e04dd20ff46e71935fc5')

private_spend_key = PrivateKey(private_spend_key_bytes)
private_view_key = PrivateKey(private_view_key_bytes)

msg = b'somedata'
stealth_address = StealthAddress(R, P)
signer = StealthAddressSigner(private_spend_key, private_view_key)
sig = signer.sign(stealth_address, msg)
print('Stealth signature: ', sig.hex())

Output

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).

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

Signature verification result: True

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

stealth25519-1.0.8.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

stealth25519-1.0.8-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file stealth25519-1.0.8.tar.gz.

File metadata

  • Download URL: stealth25519-1.0.8.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for stealth25519-1.0.8.tar.gz
Algorithm Hash digest
SHA256 6440cbd7d3dbbc13ae49cc428b382c771c9cbaf72584e693b36a4c46354b11f9
MD5 38e8a6d6630c083e33f179d8ba146723
BLAKE2b-256 05ede59c7ffd20495fb30b17e51ab90dc970f3dbb7f5367f74ca30aac10b6710

See more details on using hashes here.

File details

Details for the file stealth25519-1.0.8-py3-none-any.whl.

File metadata

File hashes

Hashes for stealth25519-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 22a7f8031f5f156bb51418771e097d1cbaf151e57aaf64e26b700cb1d1fe5339
MD5 de11e28b6eacc32bd77cc38022b14178
BLAKE2b-256 d7d0417bbfa97f5b748b15709eb3b336202512a617c763e5a00d63e20763835b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page