-- | Leios specific key types and their 'Key' class instances
--
-- This module now lives in the cardano-keys package; re-exported here for compatibility.
module Cardano.Api.Key.Internal.Leios
  ( module Cardano.Keys.Leios

    -- * Internal conversion functions
  , toLedgerBlsKey
  )
where

import Cardano.Crypto.DSIGN.BLS12381 qualified as Crypto
import Cardano.Crypto.DSIGN.Class qualified as Crypto
import Cardano.Keys.Leios
import Cardano.Ledger.State qualified as Ledger

-- | Derive the pair a pool has to register -- verification key plus proof of
-- possession -- from a BLS signing key, which is otherwise fiddly to assemble
-- from the pieces 'Cardano.Keys.Leios' exports.
--
-- Both halves are derived straight from the signing key rather than via
-- 'createBlsPossessionProof', because 'BlsPossessionProof' is exported from
-- 'Cardano.Keys.Leios' as an abstract type, so its payload cannot be unwrapped
-- here.
toLedgerBlsKey :: SigningKey BlsKey -> Ledger.BlsKey
toLedgerBlsKey :: SigningKey BlsKey -> BlsKey
toLedgerBlsKey (BlsSigningKey SignKeyDSIGN BLS12381MinSigDSIGN
sk) =
  Ledger.BlsKey
    { blsPubKey :: VerKeyDSIGN BLS12381MinSigDSIGN
Ledger.blsPubKey = SignKeyDSIGN BLS12381MinSigDSIGN -> VerKeyDSIGN BLS12381MinSigDSIGN
forall v. DSIGNAlgorithm v => SignKeyDSIGN v -> VerKeyDSIGN v
Crypto.deriveVerKeyDSIGN SignKeyDSIGN BLS12381MinSigDSIGN
sk
    , blsPossessionProof :: PossessionProofDSIGN BLS12381MinSigDSIGN
Ledger.blsPossessionProof = ContextDSIGN BLS12381MinSigDSIGN
-> SignKeyDSIGN BLS12381MinSigDSIGN
-> PossessionProofDSIGN BLS12381MinSigDSIGN
forall v.
(DSIGNAggregatable v, HasCallStack) =>
ContextDSIGN v -> SignKeyDSIGN v -> PossessionProofDSIGN v
Crypto.createPossessionProofDSIGN ContextDSIGN BLS12381MinSigDSIGN
BLS12381SignContext
Crypto.minSigPoPDST SignKeyDSIGN BLS12381MinSigDSIGN
sk
    }