cometa-0.1.0.0: Idiomatic Haskell bindings to cardano-c
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cometa.Crypto.Bip32.PublicKey

Description

Cardano Ed25519-BIP32 public keys: a 32-byte verification key followed by a 32-byte chain code. These are not secp256k1 Bitcoin BIP32 keys. Import validates length only; an invalid curve point can fail later derivation.

import qualified Cometa.Crypto.Bip32.PublicKey as PublicKey

roundTrip key = PublicKey.fromBytes (PublicKey.toBytes key) == Right key
Synopsis

Documentation

data PublicKey Source #

Immutable 64-byte public key and chain code. Equality compares exact bytes; ordering is lexicographic. Show is diagnostic; toHex is stable serialization.

Import and serialization

fromBytes :: ByteString -> Either Error PublicKey Source #

Import exactly 64 bytes; other lengths return InvalidBip32PublicKeyLength. Curve-point validity is not checked.

fromHex :: Text -> Either Error PublicKey Source #

Import 128 ASCII hex digits in either case, without prefix or whitespace. Empty or malformed text returns InvalidHex; a well-formed wrong length returns InvalidBip32PublicKeyLength.

toBytes :: PublicKey -> ByteString Source #

Retrieve all 64 bytes, including the chain code.

toHex :: PublicKey -> Text Source #

Render 128 lowercase ASCII hexadecimal digits without prefix or whitespace.

byteLength :: PublicKey -> Int Source #

Encoded length, always 64 bytes.

hexLength :: PublicKey -> Int Source #

Hexadecimal digit count, always 128, excluding a terminator.

Derivation and conversion

derive :: PublicKey -> [Word32] -> IO (Either Error PublicKey) Source #

Derive a path in order. Each encoded index must be in 0..2^31-1; any high-bit (hardened) index returns HardenedPublicDerivation before native work. An empty path returns the original value. Native derivation failures return NativeError. The source is unchanged.

toEd25519 :: PublicKey -> PublicKey Source #

Discard the chain code and return the first 32 bytes as an Ed25519 public key. This does not validate curve membership or identity.

hash :: PublicKey -> IO (Either Error Blake2bHash) Source #

Compute BLAKE2b-224 over all 64 bytes, including the chain code, matching the BIP32 public-key hash operation. For a payment/stake verification-key digest, convert with toEd25519 and use hash instead. Failures return NativeError.