Beispiel #1
0
func generateFromChecksum(in PrivateKeyDat, WIF string) PrivateKeyDat {
	var answer PrivateKeyDat
	answer.Error = in.Error

	answer.Priv2WIF = in.Priv2WIF
	answer.WIF2Priv = in.WIF2Priv
	answer.WIFChecksum = []string{}
	answer.Minikey = in.Minikey

	hex := mymath.Base582Hex(WIF)
	if mymath.Hex2Base58(hex) != mymath.Base58(WIF) {
		if answer.Error == "" {
			answer.Error = "Invalid Base58 encoding"
		}
		answer.WIFChecksum = []string{WIF, "", "", "", "", "", ""}
		return answer
	}
	answer.WIFChecksum = append(answer.WIFChecksum, WIF)
	answer.WIFChecksum = append(answer.WIFChecksum, mymath.Hex2Str(hex))
	answer.WIFChecksum = append(answer.WIFChecksum, mymath.Hex2Str(hex[0:len(hex)-4]))
	sha := mymath.SingleSHA(hex[0 : len(hex)-4])
	answer.WIFChecksum = append(answer.WIFChecksum, mymath.Hex2Str(sha))
	sha = mymath.SingleSHA(sha)
	answer.WIFChecksum = append(answer.WIFChecksum, mymath.Hex2Str(sha))
	answer.WIFChecksum = append(answer.WIFChecksum, mymath.Hex2Str(sha[0:4]))
	answer.WIFChecksum = append(answer.WIFChecksum, mymath.Hex2Str(hex[len(hex)-4:]))

	return answer
}
Beispiel #2
0
func generateFromWIF(in PrivateKeyDat, WIF string) PrivateKeyDat {
	var answer PrivateKeyDat
	answer.Error = in.Error

	answer.Priv2WIF = in.Priv2WIF
	answer.WIF2Priv = []string{}
	answer.WIFChecksum = in.WIFChecksum
	answer.Minikey = in.Minikey

	hex := mymath.Base582Hex(WIF)
	if mymath.Hex2Base58(hex) != mymath.Base58(WIF) {
		if answer.Error == "" {
			answer.Error = "Invalid Base58 encoding"
		}
		answer.WIF2Priv = []string{WIF, "", "", ""}
		return answer
	}
	answer.WIF2Priv = append(answer.WIF2Priv, WIF)
	answer.WIF2Priv = append(answer.WIF2Priv, mymath.Hex2Str(hex))
	answer.WIF2Priv = append(answer.WIF2Priv, mymath.Hex2Str(hex[0:len(hex)-4]))
	answer.WIF2Priv = append(answer.WIF2Priv, mymath.Hex2Str(hex[1:len(hex)-4]))

	return answer
}