module Cometa.Crypto.Bip32
( deriveAccountPublicKey,
derivePublicKey,
)
where
import qualified Cometa.Crypto.Bip32.PrivateKey as PrivateKey
import Cometa.Crypto.Bip32.PublicKey (PublicKey)
import Cometa.Crypto.DerivationPath (AccountPath, DerivationPath)
import qualified Cometa.Crypto.DerivationPath as Path
import Cometa.Error (Error)
import Data.ByteString (ByteString)
import Data.Word (Word32)
deriveAccountPublicKey :: ByteString -> ByteString -> AccountPath -> IO (Either Error PublicKey)
deriveAccountPublicKey :: ByteString
-> ByteString -> AccountPath -> IO (Either Error PublicKey)
deriveAccountPublicKey ByteString
password ByteString
entropy AccountPath
path = ByteString -> ByteString -> [Word32] -> IO (Either Error PublicKey)
deriveIndices ByteString
password ByteString
entropy (AccountPath -> [Word32]
Path.accountIndices AccountPath
path)
derivePublicKey :: ByteString -> ByteString -> DerivationPath -> IO (Either Error PublicKey)
derivePublicKey :: ByteString
-> ByteString -> DerivationPath -> IO (Either Error PublicKey)
derivePublicKey ByteString
password ByteString
entropy DerivationPath
path = ByteString -> ByteString -> [Word32] -> IO (Either Error PublicKey)
deriveIndices ByteString
password ByteString
entropy (DerivationPath -> [Word32]
Path.toIndices DerivationPath
path)
deriveIndices :: ByteString -> ByteString -> [Word32] -> IO (Either Error PublicKey)
deriveIndices :: ByteString -> ByteString -> [Word32] -> IO (Either Error PublicKey)
deriveIndices ByteString
password ByteString
entropy [Word32]
indices =
ByteString
-> ByteString
-> (PrivateKey -> IO (Either Error PublicKey))
-> IO (Either Error PublicKey)
forall value.
ByteString
-> ByteString
-> (PrivateKey -> IO (Either Error value))
-> IO (Either Error value)
PrivateKey.withEntropy ByteString
password ByteString
entropy ((PrivateKey -> IO (Either Error PublicKey))
-> IO (Either Error PublicKey))
-> (PrivateKey -> IO (Either Error PublicKey))
-> IO (Either Error PublicKey)
forall a b. (a -> b) -> a -> b
$ \PrivateKey
root ->
PrivateKey
-> [Word32]
-> (PrivateKey -> IO (Either Error PublicKey))
-> IO (Either Error PublicKey)
forall value.
PrivateKey
-> [Word32]
-> (PrivateKey -> IO (Either Error value))
-> IO (Either Error value)
PrivateKey.withDerived PrivateKey
root [Word32]
indices PrivateKey -> IO (Either Error PublicKey)
PrivateKey.publicKey