Skip to content

Commit

Permalink
introduce mkByronWitness
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljakubas committed Jul 6, 2020
1 parent 159f285 commit 36c57d9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/shelley/cardano-wallet-shelley.cabal
Expand Up @@ -42,6 +42,7 @@ library
, cardano-config
, cardano-crypto
, cardano-crypto-class
, cardano-crypto-wrapper
, cardano-ledger
, cardano-slotting
, cardano-wallet-cli
Expand Down
8 changes: 8 additions & 0 deletions lib/shelley/src/Cardano/Wallet/Shelley/Compatibility.hs
Expand Up @@ -73,6 +73,7 @@ module Cardano.Wallet.Shelley.Compatibility
, fromChainHash
, fromGenesisData
, fromNetworkMagic
, toByronNetworkMagic
, fromSlotNo
, fromTip
, fromTip'
Expand Down Expand Up @@ -757,6 +758,13 @@ fromNetworkDiscriminant _ =
Just{} -> SL.Mainnet
Nothing -> SL.Testnet

toByronNetworkMagic :: W.ProtocolMagic -> Byron.NetworkMagic
toByronNetworkMagic pm@(W.ProtocolMagic magic) =
if pm == W.mainnetMagic then
Byron.NetworkMainOrStage
else
Byron.NetworkTestnet (fromIntegral magic)

-- NOTE: Arguably breaks naming conventions. Perhaps fromCardanoSignedTx instead
toSealed :: SL.Tx TPraosStandardCrypto -> (W.Tx, W.SealedTx)
toSealed tx =
Expand Down
21 changes: 20 additions & 1 deletion lib/shelley/src/Cardano/Wallet/Shelley/Transaction.hs
Expand Up @@ -37,7 +37,7 @@ module Cardano.Wallet.Shelley.Transaction
import Prelude

import Cardano.Address.Derivation
( XPrv, XPub, toXPub, xpubPublicKey )
( XPrv, XPub, toXPub, xprvToBytes, xpubPublicKey )
import Cardano.Binary
( serialize' )
import Cardano.Crypto.DSIGN
Expand Down Expand Up @@ -80,6 +80,7 @@ import Cardano.Wallet.Shelley.Compatibility
( Shelley
, TPraosStandardCrypto
, fromNetworkDiscriminant
, toByronNetworkMagic
, toCardanoLovelace
, toCardanoTxIn
, toCardanoTxOut
Expand Down Expand Up @@ -123,6 +124,8 @@ import Type.Reflection

import qualified Cardano.Api as Cardano
import qualified Cardano.Byron.Codec.Cbor as CBOR
import qualified Cardano.Chain.Common as Byron
import qualified Cardano.Crypto as Crypto
import qualified Cardano.Crypto.Hash.Class as Hash
import qualified Cardano.Crypto.Wallet as CC
import qualified Cardano.Wallet.Primitive.CoinSelection as CS
Expand All @@ -136,6 +139,7 @@ import qualified Data.ByteString.Lazy.Char8 as L8
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import qualified Shelley.Spec.Ledger.Address.Bootstrap as SL
import qualified Shelley.Spec.Ledger.BaseTypes as SL
import qualified Shelley.Spec.Ledger.Coin as SL
import qualified Shelley.Spec.Ledger.Credential as SL
Expand Down Expand Up @@ -551,6 +555,21 @@ unsafeMkEd25519 :: XPub -> Ed25519.PublicKey
unsafeMkEd25519 =
throwCryptoError . Ed25519.publicKey . xpubPublicKey

mkByronWitness
:: SL.TxBody TPraosStandardCrypto
-> ProtocolMagic
-> (XPrv, Passphrase "encryption")
-> SL.BootstrapWitness TPraosStandardCrypto
mkByronWitness body protocolMagic (prv, pwd) =
let signingKey = Crypto.SigningKey prv
bytes = xprvToBytes prv
addrAttr = Byron.AddrAttributes
(Just $ Byron.HDAddressPayload bytes)
(toByronNetworkMagic protocolMagic)
(SL.TxId txHash) = SL.txid body
in error "waiting for proper cardano-ledger-spec"
--SL.makeBootstrapWitness txHash signingKey addrAttr

--------------------------------------------------------------------------------
-- Extra validations on coin selection
--
Expand Down

0 comments on commit 36c57d9

Please sign in to comment.