Skip to content

Commit

Permalink
renaming Role->WithRole, changeCode->ruleCode
Browse files Browse the repository at this point in the history
use Role and WithRole as expected
  • Loading branch information
paweljakubas committed Sep 21, 2020
1 parent ec0ee26 commit f572fb0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
6 changes: 3 additions & 3 deletions core/lib/Cardano/Address/Derivation.hs
Expand Up @@ -356,7 +356,7 @@ data DerivationType = Hardened | Soft | WholeDomain
class HardDerivation (key :: Depth -> * -> *) where
type AccountIndexDerivationType key :: DerivationType
type AddressIndexDerivationType key :: DerivationType
type WithAccountStyle key :: *
type WithRole key :: *

-- | Derives account private key from the given root private key, using
-- derivation scheme 2 (see <https://github.com/input-output-hk/cardano-crypto/ cardano-crypto>
Expand All @@ -375,7 +375,7 @@ class HardDerivation (key :: Depth -> * -> *) where
-- @since 1.0.0
deriveAddressPrivateKey
:: key 'AccountK XPrv
-> WithAccountStyle key
-> WithRole key
-> Index (AddressIndexDerivationType key) 'AddressK
-> key 'AddressK XPrv

Expand All @@ -390,7 +390,7 @@ class HardDerivation key => SoftDerivation (key :: Depth -> * -> *) where
-- @since 1.0.0
deriveAddressPublicKey
:: key 'AccountK XPub
-> WithAccountStyle key
-> WithRole key
-> Index 'Soft 'AddressK
-> key 'AddressK XPub

Expand Down
2 changes: 1 addition & 1 deletion core/lib/Cardano/Address/Style/Byron.hs
Expand Up @@ -220,7 +220,7 @@ instance Internal.GenMasterKey Byron where
instance Internal.HardDerivation Byron where
type AddressIndexDerivationType Byron = 'WholeDomain
type AccountIndexDerivationType Byron = 'WholeDomain
type WithAccountStyle Byron = ()
type WithRole Byron = ()

deriveAccountPrivateKey rootXPrv accIx = Byron
{ getKey = deriveXPrv DerivationScheme1 (getKey rootXPrv) accIx
Expand Down
10 changes: 5 additions & 5 deletions core/lib/Cardano/Address/Style/Icarus.hs
Expand Up @@ -219,7 +219,7 @@ instance Internal.GenMasterKey Icarus where
instance Internal.HardDerivation Icarus where
type AccountIndexDerivationType Icarus = 'Hardened
type AddressIndexDerivationType Icarus = 'Soft
type WithAccountStyle Icarus = Role
type WithRole Icarus = Role

deriveAccountPrivateKey (Icarus rootXPrv) accIx =
let
Expand All @@ -238,9 +238,9 @@ instance Internal.HardDerivation Icarus where

deriveAddressPrivateKey (Icarus accXPrv) role addrIx =
let
changeCode = toEnum @(Index 'Soft _) $ fromEnum role
roleCode = toEnum @(Index 'Soft _) $ fromEnum role
changeXPrv = -- lvl4 derivation; soft derivation of change chain
deriveXPrv DerivationScheme2 accXPrv changeCode
deriveXPrv DerivationScheme2 accXPrv roleCode
addrXPrv = -- lvl5 derivation; soft derivation of address index
deriveXPrv DerivationScheme2 changeXPrv addrIx
in
Expand All @@ -249,9 +249,9 @@ instance Internal.HardDerivation Icarus where
instance Internal.SoftDerivation Icarus where
deriveAddressPublicKey (Icarus accXPub) role addrIx =
fromMaybe errWrongIndex $ do
let changeCode = toEnum @(Index 'Soft _) $ fromEnum role
let roleCode = toEnum @(Index 'Soft _) $ fromEnum role
changeXPub <- -- lvl4 derivation in bip44 is derivation of change chain
deriveXPub DerivationScheme2 accXPub changeCode
deriveXPub DerivationScheme2 accXPub roleCode
addrXPub <- -- lvl5 derivation in bip44 is derivation of address chain
deriveXPub DerivationScheme2 changeXPub addrIx
return $ Icarus addrXPub
Expand Down
10 changes: 5 additions & 5 deletions core/lib/Cardano/Address/Style/Jormungandr.hs
Expand Up @@ -221,7 +221,7 @@ instance Internal.GenMasterKey Jormungandr where
instance Internal.HardDerivation Jormungandr where
type AccountIndexDerivationType Jormungandr = 'Hardened
type AddressIndexDerivationType Jormungandr = 'Soft
type WithAccountStyle Jormungandr = Role
type WithRole Jormungandr = Role

deriveAccountPrivateKey (Jormungandr rootXPrv) accIx =
let
Expand All @@ -240,9 +240,9 @@ instance Internal.HardDerivation Jormungandr where

deriveAddressPrivateKey (Jormungandr accXPrv) role addrIx =
let
changeCode = toEnum @(Index 'Soft _) $ fromEnum role
roleCode = toEnum @(Index 'Soft _) $ fromEnum role
changeXPrv = -- lvl4 derivation; soft derivation of change chain
deriveXPrv DerivationScheme2 accXPrv changeCode
deriveXPrv DerivationScheme2 accXPrv roleCode
addrXPrv = -- lvl5 derivation; soft derivation of address index
deriveXPrv DerivationScheme2 changeXPrv addrIx
in
Expand All @@ -251,9 +251,9 @@ instance Internal.HardDerivation Jormungandr where
instance Internal.SoftDerivation Jormungandr where
deriveAddressPublicKey (Jormungandr accXPub) role addrIx =
fromMaybe errWrongIndex $ do
let changeCode = toEnum @(Index 'Soft _) $ fromEnum role
let roleCode = toEnum @(Index 'Soft _) $ fromEnum role
changeXPub <- -- lvl4 derivation in bip44 is derivation of change chain
deriveXPub DerivationScheme2 accXPub changeCode
deriveXPub DerivationScheme2 accXPub roleCode
addrXPub <- -- lvl5 derivation in bip44 is derivation of address chain
deriveXPub DerivationScheme2 changeXPub addrIx
return $ Jormungandr addrXPub
Expand Down
11 changes: 5 additions & 6 deletions core/lib/Cardano/Address/Style/Shelley.hs
Expand Up @@ -251,7 +251,7 @@ instance Internal.GenMasterKey Shelley where
instance Internal.HardDerivation Shelley where
type AccountIndexDerivationType Shelley = 'Hardened
type AddressIndexDerivationType Shelley = 'Soft
type WithAccountStyle Shelley = Role
type WithRole Shelley = Role

deriveAccountPrivateKey (Shelley rootXPrv) accIx =
let
Expand All @@ -270,10 +270,9 @@ instance Internal.HardDerivation Shelley where

deriveAddressPrivateKey (Shelley accXPrv) role addrIx =
let
changeCode =
toEnum @(Index 'Soft _) $ fromEnum role
roleCode = toEnum @(Index 'Soft _) $ fromEnum role
changeXPrv = -- lvl4 derivation; soft derivation of change chain
deriveXPrv DerivationScheme2 accXPrv changeCode
deriveXPrv DerivationScheme2 accXPrv roleCode
addrXPrv = -- lvl5 derivation; soft derivation of address index
deriveXPrv DerivationScheme2 changeXPrv addrIx
in
Expand All @@ -282,9 +281,9 @@ instance Internal.HardDerivation Shelley where
instance Internal.SoftDerivation Shelley where
deriveAddressPublicKey (Shelley accXPub) role addrIx =
fromMaybe errWrongIndex $ do
let changeCode = toEnum @(Index 'Soft _) $ fromEnum role
let roleCode = toEnum @(Index 'Soft _) $ fromEnum role
changeXPub <- -- lvl4 derivation in bip44 is derivation of change chain
deriveXPub DerivationScheme2 accXPub changeCode
deriveXPub DerivationScheme2 accXPub roleCode
addrXPub <- -- lvl5 derivation in bip44 is derivation of address chain
deriveXPub DerivationScheme2 changeXPub addrIx
return $ Shelley addrXPub
Expand Down

0 comments on commit f572fb0

Please sign in to comment.