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

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

Generating a Stealth Address

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:

Stealth Address
R: 140a81dee57fa89e92f6b66df2b33867dc0a4469fdf006249c868e7bd98f65e9
P: 6f6e46287d47112a82511c2de36ef006f1f7a7b9899645267029df9c6fb510eb

Verifying a Stealth Address

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:

Stealth address verified:  True

Signing a Stealth Address

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

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.3.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

stealth25519-1.0.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: stealth25519-1.0.3.tar.gz
  • Upload date:
  • Size: 5.2 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.3.tar.gz
Algorithm Hash digest
SHA256 c93a0b62fa2079bb7cc32b6722bf5b7e1bd82da98cae8ab4b36d0c6021e08891
MD5 fdc3c8de4faaeb1e31663965e237cd0e
BLAKE2b-256 db7e64838acc7d953f4f166b3046cd80c4349a89de48eeda91f44c05d1aa6dfe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for stealth25519-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9deb2f3950582c4ff6a3b2a2b8dd0838362860578b4bcc924eb65277b2140710
MD5 0eb54e6319a918b63f66f1b81ece6c1a
BLAKE2b-256 e0778b6b7f358e9e6b7da60fceea1b9f367db5d107401f9c89d381d1f6ced13a

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