| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.Crypto.Ed25519.SigningKey
Description
Scoped Ed25519 signing keys. Normal keys contain a 32-byte seed; extended keys contain a 64-byte expanded scalar and nonce prefix, rather than a seed/public-key pair. Keys have no printable or equality representation.
The continuation receives a key valid until its scope exits. Keeping the
handle afterward is possible, but all subsequent operations return
SigningKeyClosed. Scope exit and close wait for ongoing operations.
Callback exceptions, including cancellation, propagate after cleanup.
Closing a key ends access through its handle. It does not erase the input bytes or text supplied by the application, or any explicitly exported copies.
import qualified Cometa.Crypto.Ed25519.SigningKey as SigningKey -- seed must contain exactly 32 bytes obtained from the application. signMessage seed message = SigningKey.withNormalKey seed $ key -> SigningKey.sign key message
Synopsis
- data SigningKey
- withNormalKey :: ByteString -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value)
- withExtendedKey :: ByteString -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value)
- withNormalKeyHex :: Text -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value)
- withExtendedKeyHex :: Text -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value)
- withClone :: SigningKey -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value)
- close :: SigningKey -> IO ()
- byteLength :: SigningKey -> IO (Either Error Int)
- hexLength :: SigningKey -> IO (Either Error Int)
- publicKey :: SigningKey -> IO (Either Error PublicKey)
- sign :: SigningKey -> ByteString -> IO (Either Error Signature)
- exportBytes :: SigningKey -> IO (Either Error ByteString)
- exportHex :: SigningKey -> IO (Either Error Text)
Documentation
data SigningKey Source #
An opaque scoped secret. Escaping a scope does not extend its usable lifetime. Keys of both supported formats use the same operations.
Scoped import and copying
withNormalKey :: ByteString -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value) Source #
Import exactly 32 seed bytes and run the continuation. Invalid length returns
InvalidEd25519SigningKeyLength with expected then actual byte counts, without
invoking the continuation. Its expected failures are returned directly.
Imported bytes remain in application memory after the scoped key closes.
withExtendedKey :: ByteString -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value) Source #
Import exactly 64 expanded scalar and nonce-prefix bytes and run the continuation. This is
the Cardano extended format, not a normal seed followed by a public key.
Length is validated; an unusable scalar can fail later derivation or signing.
Failure and cleanup behavior matches withNormalKey.
withNormalKeyHex :: Text -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value) Source #
Import 64 ASCII hex digits representing a normal 32-byte seed. Both letter
cases are accepted; no prefix or whitespace is allowed. Malformed or empty
text returns InvalidHex; well-formed wrong length returns
InvalidEd25519SigningKeyLength. Closing the key does not erase the supplied text.
withExtendedKeyHex :: Text -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value) Source #
Import 128 ASCII hex digits representing an expanded 64-byte scalar and nonce-prefix key.
Validation and lifetime limitations match withNormalKeyHex.
withClone :: SigningKey -> (SigningKey -> IO (Either Error value)) -> IO (Either Error value) Source #
Run a continuation with an independent secret copy. Closing the source does
not close the copy, and closing the copy does not close its source. The copy
closes on every exit. A closed source returns SigningKeyClosed.
close :: SigningKey -> IO () Source #
Close the key; repeated calls have no effect. Wait for ongoing operations before returning; no new operation can use the closed handle. Scope exit also closes it.
Inspection and signing
byteLength :: SigningKey -> IO (Either Error Int) Source #
Number of secret bytes: 32 for a normal seed, 64 for an extended key.
This reveals no secret contents. A closed handle returns SigningKeyClosed.
hexLength :: SigningKey -> IO (Either Error Int) Source #
Number of hexadecimal digits, excluding any terminator: 64 or 128. No secret
copy is created. A closed handle returns SigningKeyClosed.
publicKey :: SigningKey -> IO (Either Error PublicKey) Source #
Derive an immutable public key which remains usable after this key closes.
A closed handle returns SigningKeyClosed; derivation failures retain their
structured native status without including any secret input.
sign :: SigningKey -> ByteString -> IO (Either Error Signature) Source #
Sign the exact message bytes. Empty messages are supported. The returned
signature remains usable after this key closes. This does not prehash or encode
a message on the caller's behalf: transaction signing requires the raw body
digest, rather than full transaction CBOR or its hexadecimal representation.
A closed handle returns SigningKeyClosed; failures never include key bytes.
Explicit secret export
exportBytes :: SigningKey -> IO (Either Error ByteString) Source #
Explicitly copy the secret into a new Haskell ByteString. The result can
outlive this key and its scope. Closing cannot erase that copy or control
copies made by the application; use this only when secret export is intended.
A closed handle returns SigningKeyClosed.
exportHex :: SigningKey -> IO (Either Error Text) Source #
Explicitly export lowercase ASCII hexadecimal secret text without a prefix.
The exported text remains available after this key closes; closure does not erase it.
A closed handle returns SigningKeyClosed.