| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cometa.KeyHandler.Software
Description
Scoped encrypted software key storage. Each public-key operation requests a password from the supplied action. Passwords are raw bytes (including NUL), 1 through 128 bytes; no text normalization is performed. Keep application-owned inputs and callback results only as long as your application requires: closing cannot erase those Haskell values or copies made by the application.
A handler closes on every continuation exit, including exceptions. Escaped
handles reject further operations. Operations on independent handlers may run
concurrently; overlap and callback reentry on the same handler return
KeyHandlerBusy. A password action must not wait for another operation on
its own handler. Cancellation waits for the password action and native work
to unwind; an action that masks cancellation can delay cleanup.
import qualified Cometa.KeyHandler.Software as Software storeEntropy entropy encryptionPassword requestPassword = Software.withEntropy entropy encryptionPassword requestPassword Software.serialize
Synopsis
- data Handler mode
- data Bip32
- data Ed25519
- data LoadedHandler
- withEntropy :: ByteString -> ByteString -> IO ByteString -> (Handler Bip32 -> IO (Either Error value)) -> IO (Either Error value)
- withSigningKey :: SigningKey -> ByteString -> IO ByteString -> (Handler Ed25519 -> IO (Either Error value)) -> IO (Either Error value)
- withSerialized :: ByteString -> IO ByteString -> (LoadedHandler -> IO (Either Error value)) -> IO (Either Error value)
- close :: Handler mode -> IO (Either Error ())
- accountPublicKey :: Handler Bip32 -> AccountPath -> IO (Either Error PublicKey)
- publicKey :: Handler Ed25519 -> IO (Either Error PublicKey)
- name :: Handler mode -> IO (Either Error Text)
- serialize :: Handler mode -> IO (Either Error ByteString)
- signTransaction :: Handler Ed25519 -> Transaction -> IO (Either Error EncodedWitnesses)
- signTransactionAt :: Handler Bip32 -> NonEmpty DerivationPath -> Transaction -> IO (Either Error EncodedWitnesses)
- signSubTransaction :: Handler Ed25519 -> SubTransaction -> IO (Either Error EncodedWitnesses)
- signSubTransactionAt :: Handler Bip32 -> NonEmpty DerivationPath -> SubTransaction -> IO (Either Error EncodedWitnesses)
Capabilities
A scoped handler whose capability determines the available operations. No equality or printable representation exposes secret storage.
Ed25519 capability: recover the public key associated with encrypted key bytes.
data LoadedHandler Source #
The serialized format determines the handler capability. Metadata is CRC protected, not authenticated; accept storage only from a trusted source.
Constructors
| Bip32Handler (Handler Bip32) | A handler storing BIP39 entropy for hierarchical account derivation. |
| Ed25519Handler (Handler Ed25519) | A handler storing a normal or extended Ed25519 signing key. |
Scoped construction
withEntropy :: ByteString -> ByteString -> IO ByteString -> (Handler Bip32 -> IO (Either Error value)) -> IO (Either Error value) Source #
Encrypt BIP39 entropy (16, 20, 24, 28 or 32 bytes) immediately with the supplied encryption password, then run the continuation. The request action supplies a fresh password for each derivation. Root derivation uses the empty BIP39 password; the encryption password only protects storage.
withSigningKey :: SigningKey -> ByteString -> IO ByteString -> (Handler Ed25519 -> IO (Either Error value)) -> IO (Either Error value) Source #
Encrypt a copy of a scoped normal or extended signing key. The source stays
usable independently. A closed source returns SigningKeyClosed.
withSerialized :: ByteString -> IO ByteString -> (LoadedHandler -> IO (Either Error value)) -> IO (Either Error value) Source #
Open the native binary storage format. Validates framing, type, canonical encrypted payload sizes and checksum before invoking the continuation. It does not request a password or authenticate the encrypted payload until a public-key operation is requested. Wrong passwords fail that later operation.
Operations
close :: Handler mode -> IO (Either Error ()) Source #
Close immediately, or return KeyHandlerBusy if an operation is active.
Repeated close succeeds. Scope exit waits for ongoing work and closes even
when a prior explicit close returned busy.
accountPublicKey :: Handler Bip32 -> AccountPath -> IO (Either Error PublicKey) Source #
Derive the account extended public key at three hardened path components. The public result remains usable after this handler closes.
publicKey :: Handler Ed25519 -> IO (Either Error PublicKey) Source #
Recover the Ed25519 public key. Each call requests a password, and the returned immutable key remains usable after this handler closes.
name :: Handler mode -> IO (Either Error Text) Source #
Implementation name for diagnostics. Does not request a password.
serialize :: Handler mode -> IO (Either Error ByteString) Source #
Copy encrypted storage bytes for persistence; does not request a password. The binary format contains encrypted key material and CRC-protected metadata. The metadata is not cryptographically authenticated. The result can outlive the scope; protect it against unauthorized modification and password guessing.
signTransaction :: Handler Ed25519 -> Transaction -> IO (Either Error EncodedWitnesses) Source #
Sign the exact transaction-body hash using the encrypted Ed25519 key.
Requests a password once and returns partial witnesses, without changing the
transaction. Merge with addWitnesses to retain existing signatures.
Closed, busy, password and native failures follow the ordinary handler contract.
signTransactionAt :: Handler Bip32 -> NonEmpty DerivationPath -> Transaction -> IO (Either Error EncodedWitnesses) Source #
Derive each nonempty five-level path and sign the exact body hash. Requests a password once for the whole batch. Returns only the generated witnesses; duplicate paths are idempotent. No transaction bytes are changed.
signSubTransaction :: Handler Ed25519 -> SubTransaction -> IO (Either Error EncodedWitnesses) Source #
Sign a sub-transaction's own exact body hash using the encrypted Ed25519 key. The enclosing body and its signatures are independent of this operation.
signSubTransactionAt :: Handler Bip32 -> NonEmpty DerivationPath -> SubTransaction -> IO (Either Error EncodedWitnesses) Source #
Derive the supplied paths and sign this sub-transaction's own body hash. Requests a password once and returns partial witnesses without changing input.