From 78810d1666a37f78e8c2370b35a4b7bf5bf12224 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Wed, 5 Jun 2024 18:12:17 -0400 Subject: [PATCH] feat: address hash function Signed-off-by: Chris Gianelloni --- ledger/address.go | 12 ++++++++++++ ledger/certs.go | 1 - 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ledger/address.go b/ledger/address.go index 1c792660..428f391f 100644 --- a/ledger/address.go +++ b/ledger/address.go @@ -43,6 +43,8 @@ const ( AddressTypeNoneScript = 0b1111 ) +type AddrKeyHash Blake2b224 + type Address struct { addressType uint8 networkId uint8 @@ -191,6 +193,11 @@ func (a Address) PaymentAddress() *Address { return newAddr } +// PaymentKeyHash returns a new Blake2b224 hash of the payment key +func (a *Address) PaymentKeyHash() Blake2b224 { + return Blake2b224(a.paymentAddress[:]) +} + // StakeAddress returns a new Address with only the stake key portion. This will return nil if the address is not a payment/staking key pair func (a Address) StakeAddress() *Address { var addrType uint8 @@ -212,6 +219,11 @@ func (a Address) StakeAddress() *Address { return newAddr } +// StakeKeyHash returns a new Blake2b224 hash of the stake key +func (a *Address) StakeKeyHash() Blake2b224 { + return Blake2b224(a.stakingAddress[:]) +} + func (a Address) generateHRP() string { var ret string if a.addressType == AddressTypeNoneKey || diff --git a/ledger/certs.go b/ledger/certs.go index bd6832a3..bc0c7d31 100644 --- a/ledger/certs.go +++ b/ledger/certs.go @@ -221,7 +221,6 @@ func (c *StakeDelegationCertificate) Utxorpc() *utxorpc.Certificate { } } -type AddrKeyHash Blake2b224 type PoolKeyHash Blake2b224 type PoolMetadataHash Blake2b256 type VrfKeyHash Blake2b256