Ejemplo n.º 1
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)
	}

}
Ejemplo n.º 2
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)
	}

}