Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- type MasterSecret = FBits 256
- type ChildKey (didxs :: DerivationHier ) = Key
- type Key = ( FBits 256, FBits 256, ChainCode )
- type Public = ( PointCompressed , ChainCode )
- type PointCompressed = FBits 256
-
newtype
ChainCode
=
ChainCode
{
- unChainCode :: Bytes 32
- newtype Hash n = Hash { }
- type Tag = Bytes 1
- newtype SerializedIndex = SerializedIndex ( Bytes 4)
- type HMAC_SHA512 = Bytes 64
- data DerivationType
- data DerivationMaterial
- data DerivationIndex (k :: DerivationType ) (n :: Nat ) = DerivationIndex
- data DerivationHier
- type MaxHardIndex = 4294967295
- type MinHardIndex = 2147483648
- type MaxSoftIndex = MinHardIndex - 1
- type MinSoftIndex = 0
-
data
ValidIndex
::
Nat
->
Type
where
- IsValidIndex :: ( ValidDerivationIndex n :~: ' True ) -> ValidIndex n
- IsNotValidIndex :: ( ValidDerivationIndex n :~: ' False ) -> ValidIndex n
-
data
ValidHardIndex
::
Nat
->
Type
where
- IsValidHardIndex :: ( ValidDerivationHardIndex n :~: ' True ) -> ValidHardIndex n
- IsNotValidHardIndex :: ( ValidDerivationHardIndex n :~: ' False ) -> ValidHardIndex n
-
data
ValidSoftIndex
::
Nat
->
Type
where
- IsValidSoftIndex :: ( ValidDerivationSoftIndex n :~: ' True ) -> ValidSoftIndex n
- IsNotValidSoftIndex :: ( ValidDerivationSoftIndex n :~: ' False ) -> ValidSoftIndex n
- getValidIndex :: KnownNat n => Proxy n -> Maybe ( ValidDerivationIndex n :~: ' True )
- isValidIndex :: KnownNat n => Proxy n -> ValidIndex n
- getValidHardIndex :: KnownNat n => Proxy n -> Maybe ( ValidDerivationHardIndex n :~: ' True )
- isValidHardIndex :: KnownNat n => Proxy n -> ValidHardIndex n
- getValidSoftIndex :: KnownNat n => Proxy n -> Maybe ( ValidDerivationSoftIndex n :~: ' True )
- isValidSoftIndex :: KnownNat n => Proxy n -> ValidSoftIndex n
- type ValidDerivationIndex (n :: Nat ) = ( MinSoftIndex <=? n) && (n <=? MaxHardIndex )
- type ValidDerivationHardIndex (n :: Nat ) = ( MinHardIndex <=? n) && (n <=? MaxHardIndex )
- type ValidDerivationSoftIndex (n :: Nat ) = ( MinSoftIndex <=? n) && (n <=? MaxSoftIndex )
- type family ValidDerivationIndexForType (k :: DerivationType ) (n :: Nat ) :: Bool where ...
- type family DerivationTag (ty :: DerivationType ) (material :: DerivationMaterial ) :: Nat where ...
- leftHalfValid :: FBits 256 -> Bool
- toPublic :: Key -> Public
- kToPoint :: FBits 256 -> PointCompressed
- pointAdd :: PointCompressed -> PointCompressed -> PointCompressed
- pointToRepr :: PointCompressed -> PointCompressed
- pointFromRepr :: PointCompressed -> PointCompressed
- type family BitsToHashScheme (n :: Nat ) where ...
- type ValidTag tag = (0 <= tag, tag <= 3)
- fcp :: forall tag idx deriveType deriveMaterial. ( KnownNat ( DerivationTag deriveType deriveMaterial), KnownNat idx, DerivationTag deriveType deriveMaterial ~ tag, ValidDerivationIndex idx ~ ' True , ValidDerivationIndexForType deriveType idx ~ ' True ) => Proxy deriveMaterial -> Proxy deriveType -> Proxy idx -> ChainCode -> DerivationIndex deriveType idx -> [ Word8 ] -> HMAC_SHA512
- hmacSHA512 :: Bytes keyLength -> Bytes input -> HMAC_SHA512
-
class
GetDerivationMaterial
(dtype ::
DerivationType
) mat
where
- getDerivationMaterial :: Proxy dtype -> mat -> [ Word8 ]
- derive :: forall dtype idx. ( KnownNat ( DerivationTag dtype ' KeyMaterial ), KnownNat ( DerivationTag dtype ' ChainCodeMaterial ), KnownNat idx, ValidDerivationIndex idx ~ ' True , ValidDerivationIndexForType dtype idx ~ ' True , GetDerivationMaterial dtype Key ) => DerivationIndex dtype idx -> Key -> Key
- derivePublic :: forall idx dtype. (dtype ~ ' Soft , KnownNat ( DerivationTag dtype ' KeyMaterial ), KnownNat ( DerivationTag dtype ' ChainCodeMaterial ), KnownNat idx, ValidDerivationIndex idx ~ ' True , ValidDerivationIndexForType dtype idx ~ ' True , GetDerivationMaterial dtype PointCompressed ) => DerivationIndex ' Soft idx -> PointCompressed -> ChainCode -> ( PointCompressed , ChainCode )
- step2 :: Bytes 64 -> ( FBits 256, FBits 256)
- indexSerialized :: forall idx. ( KnownNat idx, ValidDerivationIndex idx ~ ' True ) => Proxy idx -> SerializedIndex
Documentation
type MasterSecret = FBits 256 Source #
A Master secret is a 256 bits random quantity
type ChildKey (didxs :: DerivationHier ) = Key Source #
A child key is similar to the key in structure
except it has an additional annotation representing
the indexes for the hierarchy derivation indexes from
a base
Key
(usually the root key)
type Key = ( FBits 256, FBits 256, ChainCode ) Source #
A key is a 512 bit random value and a chaincode
Left half need to have: * Lowest 3 bits clear * Highest bit clear * Second highest bit set * Third highest bit clear
Right half doesn't have any particular structure.
type Public = ( PointCompressed , ChainCode ) Source #
A public part of a key
type PointCompressed = FBits 256 Source #
A point is 1 bit of x sign and 255 bit of y coordinate (y's 256th bit is always 0)
A 256 bits chain code
ChainCode | |
|
Instances
Eq ChainCode Source # | |
GetDerivationMaterial ' Hard Key Source # | |
Defined in Crypto.ECC.Ed25519BIP32 |
|
GetDerivationMaterial ' Soft Key Source # | |
Defined in Crypto.ECC.Ed25519BIP32 |
A n bits Digest
newtype SerializedIndex Source #
Serialized Index
SerializedIndex ( Bytes 4) |
Instances
Eq SerializedIndex Source # | |
Defined in Crypto.ECC.Ed25519BIP32 (==) :: SerializedIndex -> SerializedIndex -> Bool Source # (/=) :: SerializedIndex -> SerializedIndex -> Bool Source # |
type HMAC_SHA512 = Bytes 64 Source #
data DerivationType Source #
data DerivationIndex (k :: DerivationType ) (n :: Nat ) Source #
type MaxHardIndex = 4294967295 Source #
type MinHardIndex = 2147483648 Source #
type MaxSoftIndex = MinHardIndex - 1 Source #
type MinSoftIndex = 0 Source #
data ValidIndex :: Nat -> Type where Source #
IsValidIndex :: ( ValidDerivationIndex n :~: ' True ) -> ValidIndex n | |
IsNotValidIndex :: ( ValidDerivationIndex n :~: ' False ) -> ValidIndex n |
data ValidHardIndex :: Nat -> Type where Source #
IsValidHardIndex :: ( ValidDerivationHardIndex n :~: ' True ) -> ValidHardIndex n | |
IsNotValidHardIndex :: ( ValidDerivationHardIndex n :~: ' False ) -> ValidHardIndex n |
data ValidSoftIndex :: Nat -> Type where Source #
IsValidSoftIndex :: ( ValidDerivationSoftIndex n :~: ' True ) -> ValidSoftIndex n | |
IsNotValidSoftIndex :: ( ValidDerivationSoftIndex n :~: ' False ) -> ValidSoftIndex n |
getValidIndex :: KnownNat n => Proxy n -> Maybe ( ValidDerivationIndex n :~: ' True ) Source #
isValidIndex :: KnownNat n => Proxy n -> ValidIndex n Source #
getValidHardIndex :: KnownNat n => Proxy n -> Maybe ( ValidDerivationHardIndex n :~: ' True ) Source #
isValidHardIndex :: KnownNat n => Proxy n -> ValidHardIndex n Source #
getValidSoftIndex :: KnownNat n => Proxy n -> Maybe ( ValidDerivationSoftIndex n :~: ' True ) Source #
isValidSoftIndex :: KnownNat n => Proxy n -> ValidSoftIndex n Source #
type ValidDerivationIndex (n :: Nat ) = ( MinSoftIndex <=? n) && (n <=? MaxHardIndex ) Source #
type ValidDerivationHardIndex (n :: Nat ) = ( MinHardIndex <=? n) && (n <=? MaxHardIndex ) Source #
type ValidDerivationSoftIndex (n :: Nat ) = ( MinSoftIndex <=? n) && (n <=? MaxSoftIndex ) Source #
type family ValidDerivationIndexForType (k :: DerivationType ) (n :: Nat ) :: Bool where ... Source #
type family DerivationTag (ty :: DerivationType ) (material :: DerivationMaterial ) :: Nat where ... Source #
DerivationTag ' Hard ' KeyMaterial = 0 | |
DerivationTag ' Hard ' ChainCodeMaterial = 1 | |
DerivationTag ' Soft ' KeyMaterial = 2 | |
DerivationTag ' Soft ' ChainCodeMaterial = 3 |
leftHalfValid :: FBits 256 -> Bool Source #
Check if the left half is valid
kToPoint :: FBits 256 -> PointCompressed Source #
type family BitsToHashScheme (n :: Nat ) where ... Source #
BitsToHashScheme 256 = SHA256 | |
BitsToHashScheme 512 = SHA512 |
fcp :: forall tag idx deriveType deriveMaterial. ( KnownNat ( DerivationTag deriveType deriveMaterial), KnownNat idx, DerivationTag deriveType deriveMaterial ~ tag, ValidDerivationIndex idx ~ ' True , ValidDerivationIndexForType deriveType idx ~ ' True ) => Proxy deriveMaterial -> Proxy deriveType -> Proxy idx -> ChainCode -> DerivationIndex deriveType idx -> [ Word8 ] -> HMAC_SHA512 Source #
Compute the HMAC-SHA512 using the ChainCode as the key
hmacSHA512 :: Bytes keyLength -> Bytes input -> HMAC_SHA512 Source #
class GetDerivationMaterial (dtype :: DerivationType ) mat where Source #
getDerivationMaterial :: Proxy dtype -> mat -> [ Word8 ] Source #
Instances
GetDerivationMaterial ' Hard Key Source # | |
Defined in Crypto.ECC.Ed25519BIP32 |
|
GetDerivationMaterial ' Soft PointCompressed Source # | |
Defined in Crypto.ECC.Ed25519BIP32 getDerivationMaterial :: Proxy ' Soft -> PointCompressed -> [ Word8 ] Source # |
|
GetDerivationMaterial ' Soft Key Source # | |
Defined in Crypto.ECC.Ed25519BIP32 |
derive :: forall dtype idx. ( KnownNat ( DerivationTag dtype ' KeyMaterial ), KnownNat ( DerivationTag dtype ' ChainCodeMaterial ), KnownNat idx, ValidDerivationIndex idx ~ ' True , ValidDerivationIndexForType dtype idx ~ ' True , GetDerivationMaterial dtype Key ) => DerivationIndex dtype idx -> Key -> Key Source #
derivePublic :: forall idx dtype. (dtype ~ ' Soft , KnownNat ( DerivationTag dtype ' KeyMaterial ), KnownNat ( DerivationTag dtype ' ChainCodeMaterial ), KnownNat idx, ValidDerivationIndex idx ~ ' True , ValidDerivationIndexForType dtype idx ~ ' True , GetDerivationMaterial dtype PointCompressed ) => DerivationIndex ' Soft idx -> PointCompressed -> ChainCode -> ( PointCompressed , ChainCode ) Source #
indexSerialized :: forall idx. ( KnownNat idx, ValidDerivationIndex idx ~ ' True ) => Proxy idx -> SerializedIndex Source #
Serialized index