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:]
}
这段代码展示了如何使用Go语言生成以太坊的通用地址和私钥,以及如何生成波场(TRON)地址。通过crypto库生成ECDSA密钥对,然后将公钥转换为地址,并应用特定的哈希和Base58编码过程来得到波场地址。

664

被折叠的 条评论
为什么被折叠?



