@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 44 lines 1.4 KB
Raw
1 import * as machines from "@distilled.cloud/fly-io/machines";
2 import * as Effect from "effect/Effect";
3 import * as FetchHttpClient from "effect/http/FetchHttpClient";
4 import * as Layer from "effect/Layer";
5 import { CredentialsFromAmbientOrEnv } from "./Credentials.ts";
6 import { base64ToBytes, bytesToBase64, makeHttpSecretKeyBinding } from "./SecretKeyHttp.ts";
7 import { Sign, type SignRequest } from "./Sign.ts";
8
9 /**
10 * HTTP implementation of {@link Sign}. Provide it on the
11 * {@link Service} or Action Effect.
12 *
13 *
14 * ### Provide the layer
15 * **Example:** On a Service
16 * ```typescript
17 * Effect.gen(function* () {
18 * const sign = yield* Fly.Sign(Signing);
19 * // ...
20 * }).pipe(Effect.provide(Fly.SignHttp))
21 * ```
22 *
23 * @layer
24 * @product Secret Key
25 * @provides Fly.Sign
26 */
27 export const SignHttp = Layer.effect(
28 Sign,
29 Effect.suspend(() =>
30 makeHttpSecretKeyBinding({
31 makeClient: (auth, appName, secretName) =>
32 Effect.fn("Fly.Sign")(function* (request: SignRequest) {
33 const res = yield* auth.authorize(
34 machines.signSecretKey({
35 app_name: yield* appName,
36 secret_name: yield* secretName,
37 plaintext: bytesToBase64(request.plaintext),
38 }),
39 );
40 return { signature: base64ToBytes(res.signature) };
41 }),
42 }),
43 ),
44 ).pipe(Layer.provide(FetchHttpClient.layer), Layer.provide(CredentialsFromAmbientOrEnv));