Introduction to Nostr Development
Nostr is a simple, open protocol that powers decentralized communication. In this example, you will learn how to generate key pairs, sign messages, and send events to relays.
Key Formats in Nostr
Nostr keys are represented mainly in three formats:
- Uint8Array: The binary representation of the key.
- Hex format: The base16 (hexadecimal) representation of the key.
- npub/nsec format: A human-readable format of the key encoded in Bech32, which has a built-in checksum.
- npub: This is the public key for sharing with others, providing clients with read access to your data.
- nsec: This is the private key for signing messages, providing clients with write access to your data. Never share this key!
Here’s an example:
- npub (public key):
npub1abcxyz...
- nsec (private key):
nsec1xyz...
Alternatively, keys can be represented in hexadecimal format:
- Public key (hex):
abcdef123456...
- Private key (hex):
9876abcdef...
The npub/nsec format is simply a user-friendly way to represent the same key data in a more readable form.