GitHub

web_crypto

API reference for web_crypto.

The Web Crypto API the layer_web_crypto layers run on (Effect's effect/crypto/WebCrypto).

WebCrypto is a reference holding a Crypto: get_random_values and a subtle (SubtleCrypto), as JavaScript's globalThis.crypto. Its default, host, is pyfect's own: os.urandom, hashlib and, for keys, the cryptography package (the crypto extra), with Web Crypto's key formats, usages and errors. layer(crypto) swaps it, for a hardware-backed implementation or a test double.

A SubtleCrypto method fails by raising DOMException with Web Crypto's name ("DataError", "InvalidAccessError", "NotSupportedError", "OperationError"); anything else it raises is a defect.

Types

TypeDefinitionDescription
KeyTypetype KeyType = Literal['private', 'public', 'secret']
KeyUsagetype KeyUsage = Literal['encrypt', 'decrypt', 'sign', 'verify', 'deriveKey', 'deriveBits', 'wrapKey', 'unwrapKey']
BinaryFormattype BinaryFormat = Literal['raw', 'spki', 'pkcs8']
KeyFormattype KeyFormat = Literal['raw', 'spki', 'pkcs8', 'jwk']
AlgorithmIdentifiertype AlgorithmIdentifier = str | Params

Classes

Functions

layer

layer(crypto) -> Layer[Never]

Run the layer_web_crypto layers built under it on crypto.

ParameterTypeDescription
cryptoCrypto

Returns Layer[Never]

def layer(crypto: Crypto) -> Layer[Never]:
    """Run the ``layer_web_crypto`` layers built under it on ``crypto``."""
    return layer_succeed(WebCrypto, crypto)