Example #1
0
func generateFromPrivate(in PrivateKeyDat, Private string) PrivateKeyDat {
	var answer PrivateKeyDat
	answer.Error = in.Error

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

	curve := bitelliptic.S256()
	if bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(Private)) == false {
		if answer.Error == "" {
			answer.Error = "Private key is not on curve"
		}
		answer.Priv2WIF = []string{Private, "", "", "", "", "", ""}
		return answer
	}
	priv := append([]byte{0x80}, mymath.Str2Hex(Private)...)
	answer.Priv2WIF = append(answer.Priv2WIF, Private)
	answer.Priv2WIF = append(answer.Priv2WIF, mymath.Hex2Str(priv))
	sha := mymath.SingleSHA(priv)
	answer.Priv2WIF = append(answer.Priv2WIF, mymath.Hex2Str(sha))
	sha = mymath.SingleSHA(sha)
	answer.Priv2WIF = append(answer.Priv2WIF, mymath.Hex2Str(sha))
	answer.Priv2WIF = append(answer.Priv2WIF, mymath.Hex2Str(sha[0:4]))
	priv = append(priv, sha[0:4]...)
	answer.Priv2WIF = append(answer.Priv2WIF, mymath.Hex2Str(priv))
	answer.Priv2WIF = append(answer.Priv2WIF, string(mymath.Hex2Base58(priv)))

	return answer
}
Example #2
0
func privateKeyTest(w http.ResponseWriter, r *http.Request) {

	if r.FormValue("Random") != "" {
		curve := bitelliptic.S256()
		priv, _, _, _ := curve.GenerateKey(rand.Reader)
		copyPriv := generateFromPrivate(DefaultPrivKeyDat, mymath.Hex2Str(priv))
		copyPriv = generateFromWIF(copyPriv, copyPriv.Priv2WIF[len(copyPriv.Priv2WIF)-1])
		copyPriv = generateFromChecksum(copyPriv, copyPriv.Priv2WIF[len(copyPriv.Priv2WIF)-1])
		PrivateKeyTestTemplate.Execute(w, copyPriv)
	} else if r.FormValue("wif") != "" {
		copyPriv := generateFromWIF(DefaultPrivKeyDat, r.FormValue("wif"))
		copyPriv = generateFromPrivate(copyPriv, copyPriv.WIF2Priv[len(copyPriv.WIF2Priv)-1])
		copyPriv = generateFromChecksum(copyPriv, r.FormValue("wif"))
		PrivateKeyTestTemplate.Execute(w, copyPriv)
	} else if r.FormValue("wif2") != "" {
		copyPriv := generateFromWIF(DefaultPrivKeyDat, r.FormValue("wif2"))
		copyPriv = generateFromPrivate(copyPriv, copyPriv.WIF2Priv[len(copyPriv.WIF2Priv)-1])
		copyPriv = generateFromChecksum(copyPriv, r.FormValue("wif2"))
		PrivateKeyTestTemplate.Execute(w, copyPriv)
	} else if r.FormValue("wif3") != "" {
		copyPriv := generateFromWIF(DefaultPrivKeyDat, r.FormValue("wif3"))
		copyPriv = generateFromPrivate(copyPriv, copyPriv.WIF2Priv[len(copyPriv.WIF2Priv)-1])
		copyPriv = generateFromChecksum(copyPriv, r.FormValue("wif3"))
		PrivateKeyTestTemplate.Execute(w, copyPriv)
	} else if r.FormValue("private") != "" {
		copyPriv := generateFromPrivate(DefaultPrivKeyDat, r.FormValue("private"))
		copyPriv = generateFromWIF(copyPriv, copyPriv.Priv2WIF[len(copyPriv.Priv2WIF)-1])
		copyPriv = generateFromChecksum(copyPriv, copyPriv.Priv2WIF[len(copyPriv.Priv2WIF)-1])
		PrivateKeyTestTemplate.Execute(w, copyPriv)

	} else if r.FormValue("private2") != "" {
		copyPriv := generateFromPrivate(DefaultPrivKeyDat, r.FormValue("private2"))
		copyPriv = generateFromWIF(copyPriv, copyPriv.Priv2WIF[len(copyPriv.Priv2WIF)-1])
		copyPriv = generateFromChecksum(copyPriv, copyPriv.Priv2WIF[len(copyPriv.Priv2WIF)-1])
		PrivateKeyTestTemplate.Execute(w, copyPriv)

	} else {
		PrivateKeyTestTemplate.Execute(w, DefaultPrivKeyDat)
	}

}
Example #3
0
func vanitySumTest(w http.ResponseWriter, r *http.Request) {
	if r.FormValue("Random") != "" {
		vd := new(VanitySumData)

		curve := bitelliptic.S256()
		priv, _, _, _ := curve.GenerateKey(rand.Reader)
		vd.Private1 = mymath.Hex2Str(priv)
		priv, _, _, _ = curve.GenerateKey(rand.Reader)
		vd.Private2 = mymath.Hex2Str(priv)

		vd.PrivateSum = mymath.Hex2Str(mymath.Big2Hex(mymath.AddPrivateKeys(vd.Private1, vd.Private2)))

		zero, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.PrivateSum))
		vd.PrivateSumPublic = mymath.Hex2Str(zero.PublicKey)
		vd.PrivateSumAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PrivateSumPublic)).Base)

		one, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.Private1))
		two, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.Private2))
		vd.Public1 = mymath.Hex2Str(one.PublicKey)
		vd.Public2 = mymath.Hex2Str(two.PublicKey)

		a, b := mymath.AddPublicKeys(vd.Public1, vd.Public2)
		vd.PublicSum = "04" + mymath.Hex2Str(mymath.Big2HexPadded(a, 32)) + mymath.Hex2Str(mymath.Big2HexPadded(b, 32))
		vd.PublicAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PublicSum)).Base)

		VanitySumTestTemplate.Execute(w, vd)
	} else if r.FormValue("Private") != "" {
		vd := new(VanitySumData)
		vd.Private1 = r.FormValue("Private1")
		vd.Private2 = r.FormValue("Private2")

		curve := bitelliptic.S256()
		if bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(vd.Private1)) == false || bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(vd.Private2)) == false {
			if bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(vd.Private1)) == false && bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(vd.Private2)) == false {
				vd.Error = "Both private keys appear to be invalid"

			} else if bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(vd.Private1)) == false {
				vd.Error = fmt.Sprintf("Private key one (%s) appears to be invalid", vd.Private1)

			} else if bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(vd.Private2)) == false {
				vd.Error = fmt.Sprintf("Private key two (%s) appears to be invalid", vd.Private2)

			} else {
				vd.Error = "One of the private keys is invalid, but we can't figure out which (this is an unexpected server behaviour)."
			}
		} else {
			vd.PrivateSum = mymath.Hex2Str(mymath.Big2Hex(mymath.AddPrivateKeys(vd.Private1, vd.Private2)))

			zero, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.PrivateSum))
			vd.PrivateSumPublic = mymath.Hex2Str(zero.PublicKey)
			vd.PrivateSumAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PrivateSumPublic)).Base)

			one, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.Private1))
			two, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.Private2))
			vd.Public1 = mymath.Hex2Str(one.PublicKey)
			vd.Public2 = mymath.Hex2Str(two.PublicKey)

			a, b := mymath.AddPublicKeys(vd.Public1, vd.Public2)
			vd.PublicSum = "04" + mymath.Hex2Str(mymath.Big2HexPadded(a, 32)) + mymath.Hex2Str(mymath.Big2HexPadded(b, 32))
			vd.PublicAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PublicSum)).Base)
		}

		VanitySumTestTemplate.Execute(w, vd)

	} else if r.FormValue("Public") != "" {
		vd := new(VanitySumData)
		vd.Public1 = r.FormValue("Public1")
		vd.Public2 = r.FormValue("Public2")

		if len(vd.Public1) != 130 || len(vd.Public2) != 130 {
			vd.Error = "Public keys are invalid"
		} else if vd.Public1[0] != '0' || vd.Public1[1] != '4' || vd.Public2[0] != '0' || vd.Public2[1] != '4' {
			vd.Error = "Public keys are invalid"
		} else {
			a, b := mymath.AddPublicKeys(vd.Public1, vd.Public2)
			vd.PublicSum = "04" + mymath.Hex2Str(mymath.Big2HexPadded(a, 32)) + mymath.Hex2Str(mymath.Big2HexPadded(b, 32))
			vd.PublicAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PublicSum)).Base)
		}

		VanitySumTestTemplate.Execute(w, vd)
	} else {
		VanitySumTestTemplate.Execute(w, DefaultVanitySumData)
	}

}
Example #4
0
func vanityMultTest(w http.ResponseWriter, r *http.Request) {
	curve := bitelliptic.S256()

	if r.FormValue("Random") != "" {
		vd := new(VanityMultData)

		priv, gx, gy, _ := curve.GenerateKey(rand.Reader)
		vd.Private1 = mymath.Hex2Str(priv)
		one, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.Private1))
		vd.Public1 = mymath.Hex2Str(one.PublicKey)

		curve2 := curve.Copy()
		curve2.Gx = gx
		curve2.Gy = gy
		priv, _, _, _ = curve2.GenerateKey(rand.Reader)
		vd.Private2 = mymath.Hex2Str(priv)

		two, _ := mymath.NewAddressFromPrivateKeyWithCurve(mymath.Str2Hex(vd.Private2), curve2)

		vd.Public2 = mymath.Hex2Str(two.PublicKey)

		vd.Public2Address = string(two.Base)

		vd.PrivateMult = mymath.Hex2Str(mymath.Big2Hex(mymath.MultiplyPrivateKeys(vd.Private1, vd.Private2)))

		zero, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.PrivateMult))
		vd.PrivateMultPublic = mymath.Hex2Str(zero.PublicKey)
		vd.PrivateMultAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PrivateMultPublic)).Base)

		VanityMultTestTemplate.Execute(w, vd)
		return
	} else if r.FormValue("Private") != "" {
		vd := new(VanityMultData)

		if bitecdsa.CheckIsOnCurve(curve, mymath.Str2Big(r.FormValue("Private1"))) != true {
			vd.Error = "Private key 1 is invalid"
		} else {
			priv1, _ := bitecdsa.GenerateFromPrivateKey(mymath.Str2Big(r.FormValue("Private1")), curve)

			vd.Private1 = mymath.Hex2Str(mymath.Big2Hex(priv1.D))
			one, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.Private1))
			vd.Public1 = mymath.Hex2Str(one.PublicKey)

			curve2 := curve.Copy()
			curve2.Gx = priv1.PublicKey.X
			curve2.Gy = priv1.PublicKey.Y
			if bitecdsa.CheckIsOnCurve(curve2, mymath.Str2Big(r.FormValue("Private2"))) != true {
				vd.Error = "Private key 2 is invalid"
			} else {
				priv2, _ := bitecdsa.GenerateFromPrivateKey(mymath.Str2Big(r.FormValue("Private2")), curve2)
				vd.Private2 = mymath.Hex2Str(mymath.Big2Hex(priv2.D))

				two, _ := mymath.NewAddressFromPrivateKeyWithCurve(mymath.Str2Hex(vd.Private2), curve2)

				vd.Public2 = mymath.Hex2Str(two.PublicKey)

				vd.Public2Address = string(two.Base)

				vd.PrivateMult = mymath.Hex2Str(mymath.Big2Hex(mymath.MultiplyPrivateKeys(vd.Private1, vd.Private2)))

				zero, _ := mymath.NewAddressFromPrivateKey(mymath.Str2Hex(vd.PrivateMult))
				vd.PrivateMultPublic = mymath.Hex2Str(zero.PublicKey)
				vd.PrivateMultAddress = string(mymath.NewFromPublicKey(0x00, mymath.Str2Hex(vd.PrivateMultPublic)).Base)
			}
		}
		VanityMultTestTemplate.Execute(w, vd)

		return
	} else if r.FormValue("Public") != "" {
		vd := new(VanityMultData)

		vd.Public1 = r.FormValue("Public1")
		if len(vd.Public1) != 130 {
			vd.Error = "Public key is invalid"
		} else if vd.Public1[0] != '0' || vd.Public1[1] != '4' {
			vd.Error = "Public key is invalid"
		} else {
			gx, gy := mymath.PublicKeyToPointCoordinates(vd.Public1)

			curve2 := curve.Copy()
			curve2.Gx = gx
			curve2.Gy = gy
			vd.Private1 = ""

			if bitecdsa.CheckIsOnCurve(curve2, mymath.Str2Big(r.FormValue("Private2"))) != true {
				vd.Error = "Private key is invalid"
			} else {

				priv2, _ := bitecdsa.GenerateFromPrivateKey(mymath.Str2Big(r.FormValue("Private2")), curve2)
				vd.Private2 = mymath.Hex2Str(mymath.Big2Hex(priv2.D))

				two, _ := mymath.NewAddressFromPrivateKeyWithCurve(mymath.Str2Hex(vd.Private2), curve2)

				vd.Public2 = mymath.Hex2Str(two.PublicKey)

				vd.Public2Address = string(two.Base)

				vd.PrivateMult = "??"

				vd.PrivateMultPublic = "??"
				vd.PrivateMultAddress = "??"
			}
		}
		VanityMultTestTemplate.Execute(w, vd)

		return
	} else {
		VanityMultTestTemplate.Execute(w, DefaultVanityMultData)
	}

}
Example #5
0
func addressTest(w http.ResponseWriter, r *http.Request) {
	c := appengine.NewContext(r)
	if r.FormValue("Random") != "" {
		var address AddressDat
		curve := bitelliptic.S256()
		priv, x, y, _ := curve.GenerateKey(rand.Reader)
		pub := append(append([]byte{0x04}, mymath.Big2HexWithMinimumLength(x, 32)...), mymath.Big2HexWithMinimumLength(y, 32)...)
		//pub=mymath.Str2Hex("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")

		st2 := mymath.SingleSHA(pub)
		st3 := mymath.Ripemd(st2)
		st4 := append([]byte{0x00}, st3[:]...)
		st5 := mymath.SingleSHA(st4)
		st6 := mymath.SingleSHA(st5)
		st7 := st6[0:4]
		st8 := append(st4[:], st7[:]...)
		st9 := mymath.Hex2Base58(st8)

		address.HashString = []string{
			mymath.Hex2Str(priv),
			mymath.Hex2Str(pub),
			mymath.Hex2Str(st2),
			mymath.Hex2Str(st3),
			mymath.Hex2Str(st4),
			mymath.Hex2Str(st5),
			mymath.Hex2Str(st6),
			mymath.Hex2Str(st7),
			mymath.Hex2Str(st8),
			string(st9)}
		AddressTestTemplate.Execute(w, address)

	} else if r.FormValue("private") != "" {
		var err error
		var address AddressDat
		curve := bitelliptic.S256()
		privs, err := bitecdsa.GenerateFromPrivateKey(mymath.Str2Big(r.FormValue("private")), curve)
		if err != nil {
			if err.Error() == "Private key is not on curve" {
				address = DefaultAddress
				address.Error = "Private key is not on curve"
				AddressTestTemplate.Execute(w, address)
			} else {
				c.Errorf("Err ", err)
				return
			}
		} else {
			priv := mymath.Big2Hex(privs.D)
			x := privs.PublicKey.X
			y := privs.PublicKey.Y
			//priv, x, y, _:=curve.GenerateKey(rand.Reader)
			pub := append(append([]byte{0x04}, mymath.Big2HexWithMinimumLength(x, 32)...), mymath.Big2HexWithMinimumLength(y, 32)...)

			st2 := mymath.SingleSHA(pub)
			st3 := mymath.Ripemd(st2)
			st4 := append([]byte{0x00}, st3[:]...)
			st5 := mymath.SingleSHA(st4)
			st6 := mymath.SingleSHA(st5)
			st7 := st6[0:4]
			st8 := append(st4[:], st7[:]...)
			st9 := mymath.Hex2Base58(st8)

			address.HashString = []string{
				mymath.Hex2Str(priv),
				mymath.Hex2Str(pub),
				mymath.Hex2Str(st2),
				mymath.Hex2Str(st3),
				mymath.Hex2Str(st4),
				mymath.Hex2Str(st5),
				mymath.Hex2Str(st6),
				mymath.Hex2Str(st7),
				mymath.Hex2Str(st8),
				string(st9)}
			AddressTestTemplate.Execute(w, address)
		}

	} else if r.FormValue("public") != "" {
		var address AddressDat

		pub := mymath.Str2Hex(r.FormValue("public"))
		if len(pub) != 65 {
			address.Error = "Invalid public key length"
		} else if pub[0] != 0x04 {
			address.Error = "Invalid public key format"
		}

		st2 := mymath.SingleSHA(pub)
		st3 := mymath.Ripemd(st2)
		st4 := append([]byte{0x00}, st3[:]...)
		st5 := mymath.SingleSHA(st4)
		st6 := mymath.SingleSHA(st5)
		st7 := st6[0:4]
		st8 := append(st4[:], st7[:]...)
		st9 := mymath.Hex2Base58(st8)

		address.HashString = []string{
			"",
			mymath.Hex2Str(pub),
			mymath.Hex2Str(st2),
			mymath.Hex2Str(st3),
			mymath.Hex2Str(st4),
			mymath.Hex2Str(st5),
			mymath.Hex2Str(st6),
			mymath.Hex2Str(st7),
			mymath.Hex2Str(st8),
			string(st9)}
		AddressTestTemplate.Execute(w, address)
	} else if r.FormValue("RIPEMD") != "" {
		var address AddressDat

		st3 := mymath.Str2Hex(r.FormValue("RIPEMD"))
		if len(st3) != 20 {
			address.Error = "Invalid RIPEMD-160 length"
		}

		st4 := append([]byte{0x00}, st3[:]...)
		st5 := mymath.SingleSHA(st4)
		st6 := mymath.SingleSHA(st5)
		st7 := st6[0:4]
		st8 := append(st4[:], st7[:]...)
		st9 := mymath.Hex2Base58(st8)

		address.HashString = []string{
			"", "", "",
			mymath.Hex2Str(st3),
			mymath.Hex2Str(st4),
			mymath.Hex2Str(st5),
			mymath.Hex2Str(st6),
			mymath.Hex2Str(st7),
			mymath.Hex2Str(st8),
			string(st9)}
		AddressTestTemplate.Execute(w, address)
	} else if r.FormValue("RIPEMDWithHash") != "" {
		var address AddressDat

		st4 := mymath.Str2Hex(r.FormValue("RIPEMDWithHash"))
		if len(st4) != 21 {
			address.Error = "Invalid RIPEMD-160 length"
		}
		st3 := st4[1:]
		st5 := mymath.SingleSHA(st4)
		st6 := mymath.SingleSHA(st5)
		st7 := st6[0:4]
		st8 := append(st4[:], st7[:]...)
		st9 := mymath.Hex2Base58(st8)

		address.HashString = []string{
			"", "", "",
			mymath.Hex2Str(st3),
			mymath.Hex2Str(st4),
			mymath.Hex2Str(st5),
			mymath.Hex2Str(st6),
			mymath.Hex2Str(st7),
			mymath.Hex2Str(st8),
			string(st9)}
		AddressTestTemplate.Execute(w, address)
	} else if r.FormValue("FullAddress") != "" {
		var address AddressDat

		st8 := mymath.Str2Hex(r.FormValue("FullAddress"))
		if len(st8) != 25 {
			address.Error = "Invalid address length"
			c.Debugf("%d", len(st8))
		}

		st3 := st8[1:21]
		st4 := append([]byte{0x00}, st3[:]...)
		st5 := mymath.SingleSHA(st4)
		st6 := mymath.SingleSHA(st5)
		st7 := st6[0:4]
		//st8:=append(st4[:], st7[:]...)
		st9 := mymath.Hex2Base58(st8)
		if len(st8) == 25 {
			if st7[3] != st8[24] || st7[2] != st8[23] || st7[1] != st8[22] || st7[0] != st8[21] {
				address.Error = "Invalid checksum"
			}
		}

		address.HashString = []string{
			"", "", "",
			mymath.Hex2Str(st3),
			mymath.Hex2Str(st4),
			mymath.Hex2Str(st5),
			mymath.Hex2Str(st6),
			mymath.Hex2Str(st7),
			mymath.Hex2Str(st8),
			string(st9)}
		AddressTestTemplate.Execute(w, address)
	} else if r.FormValue("Base58") != "" {
		var address AddressDat

		st9 := r.FormValue("Base58")
		st8 := mymath.Base582Hex(st9)
		if len(st8) != 25 {
			address.Error = "Invalid address length"
			c.Debugf("%d", len(st8))
		}

		st3 := st8[1:21]
		st4 := append([]byte{0x00}, st3[:]...)
		st5 := mymath.SingleSHA(st4)
		st6 := mymath.SingleSHA(st5)
		st7 := st6[0:4]
		//st8:=append(st4[:], st7[:]...)
		//st9:=mymath.Hex2Base58(st8)
		if len(st8) == 25 {
			if st7[3] != st8[24] || st7[2] != st8[23] || st7[1] != st8[22] || st7[0] != st8[21] {
				address.Error = "Invalid checksum"
			}
		}

		address.HashString = []string{
			"", "", "",
			mymath.Hex2Str(st3),
			mymath.Hex2Str(st4),
			mymath.Hex2Str(st5),
			mymath.Hex2Str(st6),
			mymath.Hex2Str(st7),
			mymath.Hex2Str(st8),
			string(st9)}
		AddressTestTemplate.Execute(w, address)
	} else {
		AddressTestTemplate.Execute(w, DefaultAddress)
	}

}