@@ -96,20 +96,27 @@ func GetAddressFromPrivateKey(privateKey string) (string, error) {
9696 return "" , err
9797 }
9898 var address * bsvutil.LegacyAddressPubKeyHash
99- if address , err = GetAddressFromPubKey (rawKey .PubKey ()); err != nil {
99+ if address , err = GetAddressFromPubKey (rawKey .PubKey (), true ); err != nil {
100100 return "" , err
101101 }
102102 return address .EncodeAddress (), nil
103103}
104104
105105// GetAddressFromPubKey gets a bsvutil.LegacyAddressPubKeyHash from a bsvec.PublicKey
106- func GetAddressFromPubKey (publicKey * bsvec.PublicKey ) (* bsvutil.LegacyAddressPubKeyHash , error ) {
106+ func GetAddressFromPubKey (publicKey * bsvec.PublicKey , compressed bool ) (* bsvutil.LegacyAddressPubKeyHash , error ) {
107107 if publicKey == nil {
108108 return nil , fmt .Errorf ("publicKey cannot be nil" )
109109 } else if publicKey .X == nil {
110110 return nil , fmt .Errorf ("publicKey.X cannot be nil" )
111111 }
112- return bsvutil .NewLegacyAddressPubKeyHash (bsvutil .Hash160 (publicKey .SerializeCompressed ()), & chaincfg .MainNetParams )
112+ var serializedPublicKey []byte
113+ if compressed {
114+ serializedPublicKey = publicKey .SerializeCompressed ()
115+ } else {
116+ serializedPublicKey = publicKey .SerializeUncompressed ()
117+ }
118+
119+ return bsvutil .NewLegacyAddressPubKeyHash (bsvutil .Hash160 (serializedPublicKey ), & chaincfg .MainNetParams )
113120}
114121
115122// GetAddressFromPubKeyString is a convenience function to use a hex string pubKey
@@ -118,7 +125,7 @@ func GetAddressFromPubKeyString(pubKey string) (*bsvutil.LegacyAddressPubKeyHash
118125 if err != nil {
119126 return nil , err
120127 }
121- return GetAddressFromPubKey (rawPubKey )
128+ return GetAddressFromPubKey (rawPubKey , true )
122129}
123130
124131// GetAddressFromScript will take an output script and extract a standard bitcoin address
0 commit comments