keys/hd/address.go
func SignBTCMessage(privKey string, message string, compress bool) string {
	prefixBytes := []byte("Bitcoin Signed Message:\n")
	messageBytes := []byte(message)
	bytes := []byte{}
	bytes = append(bytes, byte(len(prefixBytes)))
	bytes = append(bytes, prefixBytes...)
	bytes = append(bytes, byte(len(messageBytes)))
	bytes = append(bytes, messageBytes...)
	privKeyBytes := HexDecode(privKey)
	x, y := btcec.S256().ScalarBaseMult(privKeyBytes)
	ecdsaPubKey := ecdsa.PublicKey{
		Curve: btcec.S256(),
		X:     x,
		Y:     y,
	}
	ecdsaPrivKey := &btcec.PrivateKey{
		PublicKey: ecdsaPubKey,
		D:         new(big.Int).SetBytes(privKeyBytes),
	}
	sigbytes, err := btcec.SignCompact(btcec.S256(), ecdsaPrivKey, CalcHash256(bytes), compress)
	if err != nil {
		panic(err)
	}
	return base64.StdEncoding.EncodeToString(sigbytes)
}
func SignBTCMessage(privKey string, message string, compress bool) string {
	prefixBytes := []byte("Bitcoin Signed Message:\n")
	messageBytes := []byte(message)
	bytes := []byte{}
	bytes = append(bytes, byte(len(prefixBytes)))
	bytes = append(bytes, prefixBytes...)
	bytes = append(bytes, byte(len(messageBytes)))
	bytes = append(bytes, messageBytes...)
	privKeyBytes := HexDecode(privKey)
	x, y := btcec.S256().ScalarBaseMult(privKeyBytes)
	ecdsaPubKey := ecdsa.PublicKey{
		Curve: btcec.S256(),
		X:     x,
		Y:     y,
	}
	ecdsaPrivKey := &btcec.PrivateKey{
		PublicKey: ecdsaPubKey,
		D:         new(big.Int).SetBytes(privKeyBytes),
	}
	sigbytes, err := btcec.SignCompact(btcec.S256(), ecdsaPrivKey, CalcHash256(bytes), compress)
	if err != nil {
		panic(err)
	}
	return base64.StdEncoding.EncodeToString(sigbytes)
}
func SignBTCMessage ( privKey string , message string , compress bool ) string { prefixBytes := [ ] byte ( " \n " ) messageBytes := [ ] byte ( message ) bytes := [ ] byte { } bytes = append ( bytes , byte ( len ( prefixBytes ) ) ) bytes = append ( bytes , prefixBytes ... ) bytes = append ( bytes , byte ( len ( messageBytes ) ) ) bytes = append ( bytes , messageBytes ... ) privKeyBytes := HexDecode ( privKey ) x , y := btcec . S256 ( ) . ScalarBaseMult ( privKeyBytes ) ecdsaPubKey := ecdsa . PublicKey { Curve : btcec . S256 ( ) , X : x , Y : y , } ecdsaPrivKey := & btcec . PrivateKey { PublicKey : ecdsaPubKey , D : new ( big . Int ) . SetBytes ( privKeyBytes ) , } sigbytes , err := btcec . SignCompact ( btcec . S256 ( ) , ecdsaPrivKey , CalcHash256 ( bytes ) , compress ) if err != nil { panic ( err ) } return base64 . StdEncoding . EncodeToString ( sigbytes ) }
// SignBTCMessage signs a "Bitcoin Signed Message".
SignBTCMessage signs a Bitcoin Signed Message .