Skip to content

Instantly share code, notes, and snippets.

@davecgh
Created February 10, 2016 21:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davecgh/a74eb9e3a9ac4bd1214d to your computer and use it in GitHub Desktop.
Save davecgh/a74eb9e3a9ac4bd1214d to your computer and use it in GitHub Desktop.
Simple utility to convert DCR seed hex to seed words.
package main
import (
"encoding/hex"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/decred/dcrwallet/pgpwordlist"
)
func main() {
// Ensure seed hex was specified.
if len(os.Args) < 2 {
appName := filepath.Base(os.Args[0])
appName = strings.TrimSuffix(appName, filepath.Ext(appName))
fmt.Fprintf(os.Stderr, "Seed hex argument not specified\n\n")
fmt.Fprintln(os.Stderr, "Usage:")
fmt.Fprintf(os.Stderr, " %s <seedhex>\n", appName)
os.Exit(1)
}
// Ensure the hex is the appropriate length for a 256-bit seed.
seedStr := strings.TrimSpace(os.Args[1])
if len(seedStr) != 64 {
fmt.Println("The specified seed must have a length of 64 characters")
os.Exit(1)
}
// Decode hex to bytes.
seedBytes, err := hex.DecodeString(seedStr)
if err != nil {
fmt.Println("Specified seed hex is not valid. It must only " +
"contain numbers and letters in the range [a-f]")
os.Exit(1)
}
// Convert bytes to seed words with checksum.
seedWords, err := pgpwordlist.ToStringChecksum(seedBytes)
if err != nil {
fmt.Printf("Unable to encode seed bytes: %v", err)
os.Exit(1)
}
fmt.Println(seedWords)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment