Skip to content

Commit

Permalink
feat: address hash function (#651)
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored Jun 6, 2024
1 parent 20eaad0 commit e9f6e15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
12 changes: 12 additions & 0 deletions ledger/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
AddressTypeNoneScript = 0b1111
)

type AddrKeyHash Blake2b224

type Address struct {
addressType uint8
networkId uint8
Expand Down Expand Up @@ -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
Expand All @@ -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 ||
Expand Down
1 change: 0 additions & 1 deletion ledger/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ func (c *StakeDelegationCertificate) Utxorpc() *utxorpc.Certificate {
}
}

type AddrKeyHash Blake2b224
type PoolKeyHash Blake2b224
type PoolMetadataHash Blake2b256
type VrfKeyHash Blake2b256
Expand Down

0 comments on commit e9f6e15

Please sign in to comment.