Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add extra signatures to
Read
hierarchy
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
lib/wallet/src/Cardano/Wallet/Read/Primitive/Tx/Features/ExtraSigs.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE NoMonomorphismRestriction #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
|
||
-- | | ||
-- Copyright: © 2020-2022 IOHK | ||
-- License: Apache-2.0 | ||
-- | ||
|
||
module Cardano.Wallet.Read.Primitive.Tx.Features.ExtraSigs | ||
( extraSigs ) | ||
|
||
where | ||
|
||
import Prelude | ||
|
||
import Cardano.Crypto.Hash | ||
( Hash (..) ) | ||
import Cardano.Ledger.Crypto | ||
( StandardCrypto ) | ||
import Cardano.Ledger.Keys | ||
( KeyHash (..), KeyRole (..) ) | ||
import Cardano.Wallet.Read.Eras | ||
( EraFun (..), K (..) ) | ||
import Cardano.Wallet.Read.Tx.ExtraSigs | ||
( ExtraSigs (..) ) | ||
import Data.ByteString.Short | ||
( fromShort ) | ||
import Data.Foldable | ||
( toList ) | ||
import Data.Functor | ||
( (<&>) ) | ||
import Data.Set | ||
( Set ) | ||
|
||
import qualified Cardano.Wallet.Primitive.Types.Hash as W | ||
|
||
extraSigs :: EraFun ExtraSigs (K [W.Hash "ExtraSigners"]) | ||
extraSigs = EraFun | ||
{ byronFun = noExtraSigs | ||
, shelleyFun = noExtraSigs | ||
, allegraFun = noExtraSigs | ||
, maryFun = noExtraSigs | ||
, alonzoFun = yesExtraSigs | ||
, babbageFun = yesExtraSigs | ||
} | ||
where | ||
noExtraSigs = const $ K [] | ||
yesExtraSigs (ExtraSigs es) = K $ getExtraSigs es | ||
|
||
getExtraSigs | ||
:: Set (KeyHash 'Witness StandardCrypto) | ||
-> [W.Hash "ExtraSigners"] | ||
getExtraSigs es = | ||
toList es <&> \(KeyHash (UnsafeHash h)) -> W.Hash $ fromShort h | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE StandaloneDeriving #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE TypeFamilies #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
|
||
-- | | ||
-- Copyright: © 2020-2022 IOHK | ||
-- License: Apache-2.0 | ||
-- | ||
-- Raw extra signers required data extraction from 'Tx' | ||
-- | ||
|
||
module Cardano.Wallet.Read.Tx.ExtraSigs where | ||
|
||
import Prelude | ||
|
||
import Cardano.Api | ||
( AllegraEra, AlonzoEra, BabbageEra, ByronEra, MaryEra, ShelleyEra ) | ||
import Cardano.Ledger.Crypto | ||
( StandardCrypto ) | ||
import Cardano.Ledger.Keys | ||
( KeyHash, KeyRole (..) ) | ||
import Cardano.Wallet.Read.Eras | ||
( EraFun (..) ) | ||
import Cardano.Wallet.Read.Tx | ||
( Tx (..) ) | ||
import Cardano.Wallet.Read.Tx.Eras | ||
( onTx ) | ||
import Data.Set | ||
( Set ) | ||
import GHC.Records | ||
( HasField (..) ) | ||
|
||
import qualified Cardano.Ledger.Alonzo.Tx as AL | ||
|
||
type family ExtraSigsType era where | ||
ExtraSigsType ByronEra = () | ||
ExtraSigsType ShelleyEra = () | ||
ExtraSigsType AllegraEra = () | ||
ExtraSigsType MaryEra = () | ||
ExtraSigsType AlonzoEra = Set (KeyHash 'Witness StandardCrypto) | ||
ExtraSigsType BabbageEra = Set (KeyHash 'Witness StandardCrypto) | ||
|
||
newtype ExtraSigs era = ExtraSigs (ExtraSigsType era) | ||
|
||
deriving instance Show (ExtraSigsType era) => Show (ExtraSigs era) | ||
deriving instance Eq (ExtraSigsType era) => Eq (ExtraSigs era) | ||
|
||
getEraExtraSigs :: EraFun Tx ExtraSigs | ||
getEraExtraSigs | ||
= EraFun | ||
{ byronFun = \_ -> ExtraSigs () | ||
, shelleyFun = \_ -> ExtraSigs () | ||
, allegraFun = \_ -> ExtraSigs () | ||
, maryFun = \_ -> ExtraSigs () | ||
, alonzoFun = onTx $ \(AL.ValidatedTx b _ _ _) | ||
-> ExtraSigs $ getField @"reqSignerHashes" b | ||
, babbageFun = onTx $ \(AL.ValidatedTx b _ _ _) | ||
-> ExtraSigs $ getField @"reqSignerHashes" b | ||
} |