Skip to content

Instantly share code, notes, and snippets.

@tluyben
Created May 5, 2018 16:18
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 tluyben/ccda1d741fecfaa76af7ba8c9500f11b to your computer and use it in GitHub Desktop.
Save tluyben/ccda1d741fecfaa76af7ba8c9500f11b to your computer and use it in GitHub Desktop.
Calculate WIF from a private key
package main
import (
"fmt"
"os"
"encoding/hex"
"github.com/mr-tron/base58/base58"
)
func main() {
exampleBase58Encoded := []string{
"1QCaxc8hutpdZ62iKZsn1TCG3nh7uPZojq",
"1DhRmSGnhPjUaVPAj48zgPV9e2oRhAQFUb",
"17LN2oPYRYsXS9TdYdXCCDvF2FegshLDU2",
"14h2bDLZSuvRFhUL45VjPHJcW667mmRAAn",
}
// If a base58 string is on the command line, then use that instead of the 4 exampels above.
if len(os.Args) > 1 {
exampleBase58Encoded = os.Args[1:]
}
for _, vv := range exampleBase58Encoded {
hexbytes, err := hex.DecodeString(vv)
if err != nil {
fmt.Printf("Seems input is not a hex string\n")
continue
}
num := base58.Encode(hexbytes)
fmt.Printf("%s\n", num)
}
}
#!/bin/bash
# implements this: https://en.bitcoin.it/wiki/Wallet_import_format
EXT=80
EXTKEY=`echo ${EXT}$1`
KEY1=`echo ${EXTKEY} |sha256sum|awk '{print \$1}'`
KEY2=`echo ${KEY1} |sha256sum|awk '{print \$1}'`
CHECKSUM=`echo ${KEY2} |cut -c1-8`
CHECKEDKEY=`echo ${EXTKEY}${CHECKSUM}`
RESULT=`./cli ${CHECKEDKEY}`
echo $RESULT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment