keygen - NOSTR Keypair Generator
Generate NOSTR keypairs (nsec/npub) for testing and development.
Installation
go install github.com/niallyoung/goNDK/examples/keygen@latest
Or build locally:
cd examples/keygen
go build
Usage
$ keygen
nsec1...|npub1...
$ keygen -format json
{
"nsec": "nsec1...",
"npub": "npub1...",
"privkey_hex": "...",
"pubkey_hex": "..."
}
$ keygen -format hex
<64-char-privkey>|<64-char-pubkey>
Examples
Generate and store in variables
KEY=$(keygen)
NSEC=$(echo $KEY | cut -d'|' -f1)
NPUB=$(echo $KEY | cut -d'|' -f2)
echo "Private: $NSEC"
echo "Public: $NPUB"
Generate and save to files
keygen -format json > keypair.json
Use in scripts
#!/bin/bash
KEY=$(keygen)
NSEC=$(echo $KEY | cut -d'|' -f1)
# Store in AWS SSM
aws ssm put-parameter \
--name "/my-service/PrivateKey" \
--value "$NSEC" \
--type "SecureString"
bech32 (default)
- Format:
nsec1...|npub1...
- Use: Human-readable, NOSTR standard
- Length: 63 characters each
hex
- Format:
<privkey>|<pubkey>
- Use: Programming, cryptographic operations
- Length: 64 hex characters each
json
- Format: JSON object with all representations
- Use: Structured data, APIs
- Fields: nsec, npub, privkey_hex, pubkey_hex
Testing
go test -v
Security Notes
- Private keys (nsec): Keep secret, never commit to git
- Public keys (npub): Safe to share
- Production: Use hardware security modules or key management services
- Storage: Encrypt private keys at rest
See Also