1import type * as kms from "@distilled.cloud/gcp/cloudkms_v1";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { CryptoKey } from "./CryptoKey.ts";
6
7export interface EncryptRequest extends Omit<
8 kms.EncryptProjectsLocationsKeyRingsCryptoKeysRequest,
9 "name"
10> {}
11
12/**
13 * Runtime binding for Cloud KMS `cryptoKeys.encrypt`.
14 *
15 * Bind this operation to a {@link CryptoKey} in a Function/Action init
16 * phase. Provide {@link EncryptHttp}. The CryptoKey purpose must be
17 * `ENCRYPT_DECRYPT` and it must have an enabled primary version.
18 *
19 * ### Encrypting Data
20 * **Example:** Encrypt a payload
21 * ```typescript
22 * const encrypt = yield* GCP.KMS.Encrypt(key);
23 * const { ciphertext } = yield* encrypt({
24 * body: { plaintext: btoa("hello") },
25 * });
26 * ```
27 *
28 * @binding
29 * @category KMS
30 */
31export interface Encrypt extends Binding.Service<
32 Encrypt,
33 "GCP.KMS.Encrypt",
34 (
35 key: CryptoKey,
36 ) => Effect.Effect<
37 (
38 request?: EncryptRequest,
39 ) => Effect.Effect<
40 kms.EncryptResponse,
41 kms.EncryptProjectsLocationsKeyRingsCryptoKeysError,
42 RuntimeContext
43 >
44 >
45> {}
46
47export const Encrypt = Binding.Service<Encrypt>("GCP.KMS.Encrypt");