keygen

command
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 5 Imported by: 0

README

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

Default (bech32 format)
$ keygen
nsec1...|npub1...
JSON format
$ keygen -format json
{
  "nsec": "nsec1...",
  "npub": "npub1...",
  "privkey_hex": "...",
  "pubkey_hex": "..."
}
Hex format
$ 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"

Output Formats

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

Documentation

Overview

Package main provides a command-line tool for generating NOSTR keypairs.

Usage:

keygen                    # Generate new keypair
keygen -format json       # Output as JSON
keygen -format bech32     # Output as nsec|npub (default)
keygen -format hex        # Output as hex private|public

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL