@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 60 lines 1.64 KB
Raw
1 import type { EncryptSecretKeyError } from "@distilled.cloud/fly-io/machines";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import type * as Effect from "effect/Effect";
5 import type { SecretKey } from "./SecretKey.ts";
6
7 export interface EncryptRequest {
8 /** Bytes to encrypt. */
9 plaintext: Uint8Array | ArrayLike<number>;
10 /** Optional AEAD associated data. */
11 associatedData?: Uint8Array | ArrayLike<number>;
12 }
13
14 export interface EncryptResult {
15 ciphertext: Uint8Array;
16 }
17
18 /**
19 * Encrypt with a Fly {@link SecretKey} (`nacl_box`, `nacl_secretbox`,
20 * `xaes256gcm`, …). The App and key name are fixed by `Encrypt(key)`.
21 *
22 *
23 * ### Encrypt a payload
24 * Provide {@link EncryptHttp} on the Action or Service Effect. Fly
25 * crypto ops need a KMS token. Org API tokens are typed `Forbidden`.
26 *
27 * **Example:** Encrypt
28 * ```typescript
29 * const encrypt = yield* Fly.Encrypt(Box);
30 * const { ciphertext } = yield* encrypt({
31 * plaintext: new TextEncoder().encode("attack at dawn"),
32 * });
33 * ```
34 *
35 * ### Associated data
36 * `associatedData` is optional AEAD associated data. {@link Decrypt}
37 * must pass the same bytes.
38 *
39 * **Example:** AEAD
40 * ```typescript
41 * const { ciphertext } = yield* encrypt({
42 * plaintext: bytes,
43 * associatedData: nonce,
44 * });
45 * ```
46 *
47 * @binding
48 * @product Secret Key
49 */
50 export interface Encrypt extends Binding.Service<
51 Encrypt,
52 "Fly.Encrypt",
53 (
54 key: SecretKey,
55 ) => Effect.Effect<
56 (request: EncryptRequest) => Effect.Effect<EncryptResult, EncryptSecretKeyError, RuntimeContext>
57 >
58 > {}
59
60 export const Encrypt = Binding.Service<Encrypt>("Fly.Encrypt");