1.生成 通用地址
import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
)
func generateKeyPair() (ad string, pk string) {
privateKey, _ := crypto.GenerateKey()
privateKeyBytes := crypto.FromECDSA(privateKey)
publicKey := privateKey.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()[2:]
return address, hexutil.Encode(privateKeyBytes)[2:]
}
2.生成波厂地址
func s256(s []byte) []byte {
h := sha256.New()
h.Write(s)
bs := h.Sum(nil)
return bs
}
func generateKeyPair() (b5 string, pk string) {
privateKey, _ := crypto.GenerateKey()
privateKeyBytes := crypto.FromECDSA(privateKey)
publicKey := privateKey.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
address := crypto.PubkeyToAddress(*publicKeyECDSA).Hex()
address = "41" + address[2:]
addb, _ := hex.DecodeString(address)
hash1 := s256(s256(addb))
secret := hash1[:4]
for _, v := range secret {
addb = append(addb, v)
}
return base58.Encode(addb), hexutil.Encode(privateKeyBytes)[2:]
}