1import type { VerifySecretKeyError } from "@distilled.cloud/fly-io/machines";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../Binding.ts";
4import type { RuntimeContext } from "../RuntimeContext.ts";
5import type { SecretKey } from "./SecretKey.ts";
6
7export interface VerifyRequest {
8 /** Original payload. */
9 plaintext: Uint8Array | ArrayLike<number>;
10 /** Signature produced by {@link Sign}. */
11 signature: Uint8Array | ArrayLike<number>;
12}
13
14export interface VerifyResult {
15 /** Fly returns 200 only when the signature is valid. */
16 valid: true;
17}
18
19/**
20 * Verify a signature with a Fly {@link SecretKey}. The App and key
21 * name are fixed by `Verify(key)`.
22 *
23 *
24 * ### Verify a signature
25 * Provide {@link VerifyHttp}. A bad signature is a typed error from
26 * the Machines API, not `valid: false`.
27 *
28 * **Example:** Verify
29 * ```typescript
30 * const verify = yield* Fly.Verify(Signing);
31 * const { valid } = yield* verify({ plaintext, signature });
32 * ```
33 *
34 * @binding
35 * @product Secret Key
36 */
37export interface Verify extends Binding.Service<
38 Verify,
39 "Fly.Verify",
40 (
41 key: SecretKey,
42 ) => Effect.Effect<
43 (
44 request: VerifyRequest,
45 ) => Effect.Effect<VerifyResult, VerifySecretKeyError, RuntimeContext>
46 >
47> {}
48
49export const Verify = Binding.Service<Verify>("Fly.Verify");