Skip to content

Commit

Permalink
guard shelley address
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Mar 30, 2023
1 parent f56c82d commit ffd0b7f
Showing 1 changed file with 15 additions and 3 deletions.
@@ -1,11 +1,13 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE RoleAnnotations #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
Expand Down Expand Up @@ -55,11 +57,13 @@ import Cardano.Crypto.Wallet
import Cardano.Mnemonic
( SomeMnemonic (..), entropyToBytes, mnemonicToEntropy )
import Cardano.Wallet.Primitive.AddressDerivation
( BoundedAddressLength (..)
( AddressParts (..)
, BoundedAddressLength (..)
, DelegationAddress (..)
, Depth (..)
, DerivationIndex (..)
, DerivationType (..)
, ErrMkKeyFingerprint (..)
, HardDerivation (..)
, Index (..)
, KeyFingerprint (..)
Expand All @@ -76,6 +80,7 @@ import Cardano.Wallet.Primitive.AddressDerivation
, fromHex
, hex
, mutableAccount
, toAddressParts
)
import Cardano.Wallet.Primitive.AddressDiscovery
( DiscoverTxs (..), GetPurpose (..), IsOurs (..), MaybeLight (..) )
Expand Down Expand Up @@ -350,8 +355,15 @@ instance DelegationAddress ('Testnet pm) ShelleyKey 'CredFromKeyK where
networkId = 0

instance MkKeyFingerprint ShelleyKey Address where
paymentKeyFingerprint (Address bytes) =
Right $ KeyFingerprint $ BS.take hashSize $ BS.drop 1 bytes
paymentKeyFingerprint addr =
let AddressParts{..} = toAddressParts addr
baseAddr = 0b00000000 -- keyhash; keyhash
enterpriseAddr = 0b01100000 -- keyhash
rewardAcct = 0b11100000 -- keyhash
in if addrType `elem` [baseAddr, enterpriseAddr, rewardAcct] then
Right $ KeyFingerprint $ BS.take hashSize credentials
else
Left $ ErrInvalidAddress addr (Proxy @ShelleyKey)

instance MkKeyFingerprint ShelleyKey (Proxy (n :: NetworkDiscriminant), ShelleyKey 'CredFromKeyK XPub) where
paymentKeyFingerprint (_, paymentK) =
Expand Down

0 comments on commit ffd0b7f

Please sign in to comment.