2019-11-18 13:34:06 +00:00
|
|
|
package chain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
2019-11-18 13:34:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// WalletAddress implements NEO address.
|
|
|
|
type WalletAddress [AddressLength]byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
// AddressLength contains size of address,
|
2020-07-17 14:59:19 +00:00
|
|
|
// 1 byte of address version + 20 bytes of ScriptHash + 4 bytes of checksum.
|
2019-11-18 13:34:06 +00:00
|
|
|
AddressLength = 25
|
|
|
|
)
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
// KeyToAddress returns NEO address composed from public key.
|
|
|
|
func KeyToAddress(key *ecdsa.PublicKey) string {
|
|
|
|
if key == nil {
|
2019-11-18 13:34:06 +00:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
neoPublicKey := keys.PublicKey{
|
|
|
|
X: key.X,
|
|
|
|
Y: key.Y,
|
2019-11-18 13:34:06 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 14:59:19 +00:00
|
|
|
return neoPublicKey.Address()
|
2019-11-18 13:34:06 +00:00
|
|
|
}
|