pub const BYNK_CRYPTO_SRC: &str = "adapter bynk.crypto {\n\texports capability { Crypto }\n\texports transparent { Digest, Signature, CryptoError }\n\texports opaque { SigningKey, VerifyKey }\n\n\t---\n\tA hash function for `Crypto.digest`, `Crypto.hmac` and `Crypto.verifyHmac`.\n\tThe set is what every platform\'s Web Crypto supports. It may gain\n\tmembers in a minor release, so a `match` over it needs a wildcard.\n\t---\n\ttype Digest = enum { Sha256, Sha384, Sha512 }\n\n\t---\n\tA signature algorithm, fixed when a key is imported. `Ed25519` takes the\n\tkey formats Web Crypto does for it (PKCS#8 to sign, SPKI or 32 raw bytes\n\tto verify); `EcdsaP256Sha256` is ECDSA over P-256 with SHA-256 and signs\n\tand verifies the raw (IEEE P1363, `r || s`) form; `RsaPkcs1Sha256` is\n\tRSASSA-PKCS1-v1_5 with SHA-256. It may gain members in a minor release,\n\tso a `match` over it needs a wildcard.\n\t---\n\ttype Signature = enum { Ed25519, EcdsaP256Sha256, RsaPkcs1Sha256 }\n\n\t---\n\tWhy a key import failed. Neither variant carries key material: `reason`\n\tand `name` describe the failure, never the bytes. `InvalidKey` is a key\n\tthe platform could not parse for the algorithm; `UnsupportedAlgorithm`\n\tis an algorithm this platform\'s Web Crypto does not provide (an older\n\tbrowser without Ed25519, say), named so the failure is never silent. It\n\tmay gain variants in a minor release, so a `match` over it needs a\n\twildcard.\n\t---\n\ttype CryptoError =\n\t\t| InvalidKey(reason: String)\n\t\t| UnsupportedAlgorithm(name: String)\n\n\t---\n\tA key that signs, imported by `Crypto.importSigningKey`. It is opaque: its\n\tbytes cannot be read back, and the platform holds it non-extractable. Like\n\ta `Stream`, it lives for the call that imported it. It cannot be stored,\n\tpersisted, logged or sent, so it is refused in a `store`, a record or event\n\tfield, a handler parameter or result, and a wire type\n\t(`bynk.types.key_at_boundary`). Import it again where it is needed.\n\t---\n\ttype SigningKey = opaque Bytes\n\n\t---\n\tA key that verifies, imported by `Crypto.importVerifyKey` or\n\t`Crypto.importVerifyJwk`. Opaque and unstorable exactly as `SigningKey` is.\n\t---\n\ttype VerifyKey = opaque Bytes\n\n\t---\n\tCryptography over Web Crypto (`crypto.subtle`): digests, HMAC, constant-time\n\tcomparison, and signing and verification with imported keys. Every operation\n\tis an `Effect` because `crypto.subtle` is asynchronous on every platform, so\n\tthere is no hashing in pure functions, refinements or invariants. Encodings\n\t(`Bytes.toHex`, `Bytes.fromBase64`, \u{2026}) stay pure.\n\n\tNo third-party crypto runs and nothing is polyfilled: a platform without\n\t`crypto.subtle` (a browser outside a secure context) fails loudly.\n\n\tTiming. `verifyHmac`, `verify` and `equal` do not return early on the first\n\tdiffering byte, so they are the only way to compare a secret, a MAC, a\n\tsignature or a token\'s digest; `Bytes.compare` is not constant-time and must\n\tnever compare secrets. `digest`, `hmac` and `sign` run in time that does not\n\tdepend on the data in a way a program can exploit.\n\t---\n\tcapability Crypto {\n\t\tfn digest(algorithm: Digest, data: Bytes) -> Effect[Bytes]\n\t\tfn hmac(algorithm: Digest, key: Bytes, data: Bytes) -> Effect[Bytes]\n\t\tfn verifyHmac(algorithm: Digest, key: Bytes, data: Bytes, mac: Bytes) -> Effect[Bool]\n\t\tfn equal(a: Bytes, b: Bytes) -> Effect[Bool]\n\t\tfn importSigningKey(\n\t\t\talgorithm: Signature,\n\t\t\tpkcs8: Bytes\n\t\t) -> Effect[Result[SigningKey, CryptoError]]\n\t\tfn importVerifyKey(\n\t\t\talgorithm: Signature,\n\t\t\tkey: Bytes\n\t\t) -> Effect[Result[VerifyKey, CryptoError]]\n\t\tfn importVerifyJwk(jwk: String) -> Effect[Result[VerifyKey, CryptoError]]\n\t\tfn sign(key: SigningKey, data: Bytes) -> Effect[Bytes]\n\t\tfn verify(key: VerifyKey, data: Bytes, signature: Bytes) -> Effect[Bool]\n\t}\n\n\tprovides Crypto = CryptoProvider\n}\n";Expand description
bynk.crypto — digests, HMAC, constant-time comparison, and signing and
verification with imported keys, as Effects over Web Crypto.