-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split off
Cardano.Wallet.Deposit.Write.Keys
- Loading branch information
1 parent
f1f8390
commit 39897fd
Showing
3 changed files
with
85 additions
and
37 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
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
80 changes: 80 additions & 0 deletions
80
lib/customer-deposit-wallet/src/Cardano/Wallet/Deposit/Write/Keys.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,80 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
|
||
-- | Module for converting key types from | ||
-- @Cardano.Ledger@ with key types from @Cardano.Crypto.Wallet@. | ||
-- | ||
-- TODO: Match this up with the @Write@ hierarchy. | ||
module Cardano.Wallet.Deposit.Write.Keys | ||
( enterpriseAddressFromVKey | ||
, vkeyFromXPub | ||
, signedDSIGNfromXSignature | ||
) where | ||
|
||
import Prelude | ||
|
||
import Cardano.Crypto.Wallet | ||
( xpubPublicKey | ||
) | ||
import Cardano.Ledger.Keys | ||
( SignedDSIGN | ||
, VKey (..) | ||
) | ||
import Cardano.Wallet.Address.BIP32_Ed25519 | ||
( XPub | ||
, XSignature | ||
, rawSerialiseXSignature | ||
) | ||
import Cardano.Wallet.Deposit.Read | ||
( Address | ||
) | ||
import Data.Maybe | ||
( fromMaybe | ||
) | ||
|
||
import qualified Cardano.Crypto.DSIGN as DSIGN | ||
import qualified Cardano.Ledger.Address as L | ||
import qualified Cardano.Ledger.Api as L | ||
import qualified Cardano.Ledger.BaseTypes as L | ||
import qualified Cardano.Ledger.Credential as L | ||
import qualified Cardano.Ledger.Hashes as L | ||
import qualified Cardano.Ledger.Keys as L | ||
|
||
{----------------------------------------------------------------------------- | ||
Key conversion | ||
------------------------------------------------------------------------------} | ||
-- | Create an enterprise address from a ledger 'VKey'. | ||
enterpriseAddressFromVKey | ||
:: L.Network | ||
-> VKey 'L.Witness L.StandardCrypto | ||
-> Address | ||
enterpriseAddressFromVKey network = | ||
mkEnterpriseAddress | ||
. L.coerceKeyRole | ||
. L.hashKey | ||
where | ||
mkEnterpriseAddress h = | ||
L.compactAddr | ||
$ L.Addr network (L.KeyHashObj h) L.StakeRefNull | ||
|
||
-- | Convert 'XPub' to a ledger verification key. | ||
vkeyFromXPub :: XPub -> VKey 'L.Witness L.StandardCrypto | ||
vkeyFromXPub = | ||
VKey | ||
. fromMaybe impossible | ||
. DSIGN.rawDeserialiseVerKeyDSIGN | ||
. xpubPublicKey | ||
where | ||
impossible = error "impossible: Cannot convert XPub to VKey" | ||
|
||
-- | Convert 'XSignature' to a ledger signature. | ||
signedDSIGNfromXSignature | ||
:: XSignature | ||
-> SignedDSIGN L.StandardCrypto | ||
(L.Hash L.StandardCrypto L.EraIndependentTxBody) | ||
signedDSIGNfromXSignature = | ||
DSIGN.SignedDSIGN | ||
. fromMaybe impossible | ||
. DSIGN.rawDeserialiseSigDSIGN | ||
. rawSerialiseXSignature | ||
where | ||
impossible = error "impossible: Cannot convert XSignature to SignedDSIGN" |