//GetAddress returns bitcoin address from PublicKey func (pub *PublicKey) GetAddress() (string, []byte) { var publicKeyPrefix byte if pub.isTestnet { publicKeyPrefix = 0x6F } else { publicKeyPrefix = 0x00 } //Next we get a sha256 hash of the public key generated //via ECDSA, and then get a ripemd160 hash of the sha256 hash. var shadPublicKeyBytes [32]byte if pub.isCompressed { shadPublicKeyBytes = sha256.Sum256(pub.key.SerializeCompressed()) } else { shadPublicKeyBytes = sha256.Sum256(pub.key.SerializeUncompressed()) } ripeHash := ripemd160.New() ripeHash.Write(shadPublicKeyBytes[:]) ripeHashedBytes := ripeHash.Sum(nil) publicKeyEncoded := base58check.Encode(publicKeyPrefix, ripeHashedBytes) return publicKeyEncoded, ripeHashedBytes }
//GetWIFAddress returns WIF format string from PrivateKey func (priv *PrivateKey) GetWIFAddress() string { var privateKeyPrefix byte if priv.isTestnet { privateKeyPrefix = 0xEF } else { privateKeyPrefix = 0x80 } return base58check.Encode(privateKeyPrefix, priv.key.Serialize()) }
// GetAddress creates P2SH multisig addresses. func (rs *RedeemScript) GetAddress() string { //Get P2SH address by base58 encoding with P2SH prefix 0x05 var prefix byte if rs.PublicKeys[0].isTestnet { prefix = 0xc4 } else { prefix = 0x5 } return base58check.Encode(prefix, rs.getHash()) }