Learning LibraryBlockchain & DeFi LibraryTeens

Wallets and keys: proving ownership without secrets

A crypto wallet doesn't hold coins — it holds keys. A private key you guard like a password, and a public key you share freely. Together they let you prove ownership without ever revealing the secret.

The big idea

A private key is a secret only you hold; a public key derives from it and is shared; a signature made with the private key proves ownership to anyone.

See it in code

1The basics

A wallet starts with one secret: the private key. From it you derive a public key by hashing — a one-way step, so the public key is safe to share but can't be run backward to the secret. (Simplified for learning; real wallets use much stronger math.)

python
import hashlib

def h(text):
    return hashlib.sha256(text.encode()).hexdigest()[:12]

# SIMPLIFIED for learning - real wallets use much stronger math.
private_key = "my-secret-2718"   # never share this
public_key = h(private_key)      # safe to share

print("Public key:", public_key)
Run it — a public key derived from the secret you keep hidden:
Public key: 51bcfbd1651f

The public key came from the private key, but the one-way hash means no one can reverse it to find your secret. Next, that secret does something only its owner can: sign a message.

2A step further

To prove you're the owner, combine the private key with an exact message and hash them into a signature. Only someone holding the secret could produce this code for this message:

python
import hashlib

def h(text):
    return hashlib.sha256(text.encode()).hexdigest()[:12]

private_key = "my-secret-2718"
message = "Alice pays Bob 5 coins"

signature = h(private_key + message)  # only the key holder can make this
print("Signature:", signature)
Run it — a signature that could only come from the key holder:
Signature: 4f8870df1d83

This signature ties the secret to that exact message — change one character of the message and the signature changes completely. Put the public key and signature together and you have the full wallet.

3In our world

Put it together: derive the public key to share, and sign the message with the private key. The holder publishes both — proof of ownership without ever revealing the secret:

python
import hashlib

def h(text):
    return hashlib.sha256(text.encode()).hexdigest()[:12]

# SIMPLIFIED for learning - real wallets use much stronger math.
private_key = "my-secret-2718"        # never share this
public_key = h(private_key)           # safe to share

message = "Alice pays Bob 5 coins"
signature = h(private_key + message)  # only the key holder can make this

print("Public key:", public_key)
print("Signature:", signature)
Run it — a public key to share and a signature that proves the secret:
Public key: 51bcfbd1651f
Signature: 4f8870df1d83

The public key came from the private key, but you can't run it backward to recover the secret — same one-way property as any hash. The signature ties this exact message to the private key, so anyone with the public key can trust it came from the owner, without ever seeing the secret.

The same idea, everywhere

Public/private key pairs secure far more than crypto: they're behind HTTPS (the padlock in your browser), SSH logins, signed software updates, and digital signatures on documents. The pattern — keep one key secret, publish the other — is the foundation of modern digital trust.

Try it yourself

Change one character of the message and watch the signature change completely — proof that a signature commits to exact content. Then imagine an attacker with only the public key: they can verify signatures, but can't forge one.

The common mistake

Ever sharing or hard-coding a private key. Whoever holds the private key controls the wallet — leak it, and it's gone. (This toy uses a fake secret for illustration; never put a real private key in code or a screenshot.) Real security also uses proper cryptographic signing, not a hash of the key plus message.

What it unlocks

Keys and signatures make transactions trustworthy, build on hashing, and connect to the security mindset of guarding secrets.