Skip to content

A simple, fast, and concurrent command-line tool for generating secure, URL-friendly unique string IDs using the NanoID Go implementation.

License

Notifications You must be signed in to change notification settings

sixafter/nanoid-cli

NanoID CLI

A simple, fast, and concurrent command-line tool for generating secure, URL-friendly unique string IDs using the NanoID Go implementation.

Go Report Card License: Apache 2.0 Go Go Reference

Status

Build & Test

CI GitHub issues

Quality

Quality Gate Status CodeQL Security Rating

Package and Deploy

Release

Features

  • Customizable Length: Specify the length of the generated Nano ID.
  • Custom Alphabet: Define your own set of characters for ID generation.
  • Multiple ID Generation: Generate multiple IDs in a single command.
  • Verbose Mode: Enable detailed logs during ID generation.

Verify with Cosign

Cosign is used to sign releases for integrity verification.

To verify the integrity of the release, you can use Cosign to check the signature and checksums. Follow these steps:

# Fetch the latest release tag from GitHub API (e.g., "v1.38.0")
TAG=$(curl -s https://api.github.com/repos/sixafter/nanoid-cli/releases/latest | jq -r .tag_name)

# Remove leading "v" for filenames (e.g., "v1.38.0" -> "1.38.0")
VERSION=${TAG#v}

# Verify the release tarball
cosign verify-blob \
  --key https://raw.githubusercontent.com/sixafter/nanoid-cli/main/cosign.pub \
  --signature nanoid-${VERSION}.tar.gz.sig \
  nanoid-${VERSION}.tar.gz

# Download checksums.txt and its signature from the latest release assets
curl -LO https://github.com/sixafter/nanoid-cli/releases/download/${TAG}/checksums.txt
curl -LO https://github.com/sixafter/nanoid-cli/releases/download/${TAG}/checksums.txt.sig

# Verify checksums.txt with cosign
cosign verify-blob \
  --key https://raw.githubusercontent.com/sixafter/nanoid-cli/main/cosign.pub \
  --signature checksums.txt.sig \
  checksums.txt

If valid, Cosign will output:

Verified OK

Installation

Clone the repository and build the executable:

git clone https://github.com/sixafter/nanoid-cli.git
cd nanoid-cli
make build

This command compiles the main.go file and produces an executable named nanoid in the ./out directory.

Homebrew

brew tap sixafter/tap
brew install --cask nanoid

For casks to work, you'll need curl installed. If you don't have it, you can install it with:

brew install curl

Note for macOS users: If you see a killed error when running nanoid, macOS may have quarantined the binary due to it being unsigned or unnotarized. To resolve:

sudo xattr -d com.apple.quarantine /opt/homebrew/bin/nanoid

Usage

Run the CLI to Generate a Default Nano ID:

nanoid generate

Output:

V1StGXR8_Z5jdHi6B-myT

Generate a Nano ID with a Custom Length:

nanoid generate --length 30

Output:

mJzY8fK3Lq7B9sR2dT4hV5nG1aC0eX

Generate a Nano ID with a Custom Alphabet:

nanoid generate --alphabet "abcdef123456"

Output:

1a2b3c4d5e6f1a2b3c4d5e6f1a2b3c4

Generate Multiple Nano IDs with verbose output:

nanoid generate --count 10 --verbose

Output:

_OKhyfsfINNfokJZxyj4j
HZUZ7sTHlLpub0rryyLsr
_agY2S55BoYSdipGVaL4P
FgrdoVAzzFZWS2bc42bre
saM2-PnvwIIyt312rkGbS
RCdECZCOr7VTkGXx5CoQo
bCX2GTzXJ22Azn0MAYkQ3
Fh7-65FYU9Higp7scLBht
uC87QtpSLb8ZX5oENCHJP
bTPg9AynQtzldZazM-wKV

Start Time..............: 2025-04-14T16:30:03-05:00
Total IDs generated.....: 10
Total time taken........: 46.959µs
Average time per ID.....: 4.695µs
Throughput..............: 212951.72 IDs/sec
Estimated output size...: 220 B
Estimated entropy per ID: 126.00 bits
Memory used.............: 0.32 MiB

Contributing

Contributions are welcome. See CONTRIBUTING


License

This project is licensed under the Apache 2.0 License. See LICENSE file.

About

A simple, fast, and concurrent command-line tool for generating secure, URL-friendly unique string IDs using the NanoID Go implementation.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published