func NewAddressFromPrivateKeyOtherNets(netByte byte, privateKey []byte) (*BitAddress, error) {
	curve := bitelliptic.S256()

	priv, err := bitecdsa.GenerateFromPrivateKey(Hex2Big(privateKey), curve)

	if err != nil {
		return nil, err
	}
	ba := new(BitAddress)
	ba.PrivateKey = Big2Hex(priv.D)
	ba.Encrypted = false
	ba.PublicKey = append(append([]byte{netByte}, Big2Hex(priv.PublicKey.X)...), Big2Hex(priv.PublicKey.Y)...)
	ba.Hash160 = SHARipemd(ba.PublicKey)
	ba.Hash = append(append([]byte{0x00}, ba.Hash160...), DoubleSHA(append([]byte{0x00}, ba.Hash160...))[0:4]...)
	ba.Base = Hex2Base58(ba.Hash)

	return ba, nil
}
Пример #2
0
func FromPrivateKeyRaw(privKey []byte, compressed bool, addrVersion byte) (*KeyPair, error) {
	curve := bitelliptic.S256()
	k := KeyPair{
		privKey:     privKey,
		compressed:  compressed,
		addrVersion: addrVersion,
	}

	if ecdsakey, err := bitecdsa.GenerateFromPrivateKey(new(big.Int).SetBytes(k.privKey), curve); err != nil {
		return nil, err
	} else {
		k.ecdsakey = ecdsakey
	}

	if pubkey, err := EncodePublicKey(k.ecdsakey.X, k.ecdsakey.Y, k.compressed); err != nil {
		panic(err) // Shouldn't happen
	} else {
		k.address = PublicKeyToBitcoinAddress(addrVersion, pubkey)
	}

	return &k, nil
}
func CheckSolution(pubKey, solution, pattern string, netByte byte) (string, string) {

	d := big.NewInt(0)
	d.SetString(solution, 16)

	private, err := bitecdsa.GenerateFromPrivateKey(d, bitelliptic.S256())
	if err != nil {
		log.Printf("vanitymath err - %s", err)
		return "", err.Error()
	}
	a, b := PublicKeyToPointCoordinates(pubKey)

	x, y := bitelliptic.S256().Add(a, b, private.PublicKey.X, private.PublicKey.Y)

	ba := NewFromPublicKeyString(netByte, PointCoordinatesToPublicKey(x, y))
	address := string(ba.Base)
	for i := 0; i < len(pattern); i++ {
		if address[i] != pattern[i] {
			return "", "Wrong pattern"
		}
	}
	return address, ""
}