@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 49 lines 1.9 KB
Raw
1 import * as paymentcryptographydata from "@distilled.cloud/aws/payment-cryptography-data";
2 import * as Effect from "effect/Effect";
3 import * as Layer from "effect/Layer";
4 import * as AWSBindings from "../AWSBindings.ts";
5 import type { Key } from "./Key.ts";
6 import { TranslateKeyMaterial, type TranslateKeyMaterialRequest } from "./TranslateKeyMaterial.ts";
7
8 /**
9 * HTTP implementation of {@link TranslateKeyMaterial} — bespoke (not
10 * scaffolded): the key identifiers live in nested request structures
11 * (`IncomingKeyMaterial.DiffieHellmanTr31KeyBlock.PrivateKeyIdentifier`,
12 * `OutgoingKeyMaterial.Tr31KeyBlock.WrappingKeyIdentifier`) whose union arms
13 * vary by exchange scheme, so nothing is injected. The deploy-time half
14 * grants `payment-cryptography:TranslateKeyMaterial` on every bound
15 * {@link Key}; the caller supplies the full request (resolving each key's
16 * ARN itself).
17 */
18 export const TranslateKeyMaterialHttp = Layer.effect(
19 TranslateKeyMaterial,
20 Effect.gen(function* () {
21 const bind = yield* AWSBindings.Bind;
22 const translateKeyMaterial = yield* AWSBindings.withCredentials(
23 paymentcryptographydata.translateKeyMaterial,
24 );
25
26 return Effect.fn(function* (...keys: readonly [Key, ...Key[]]) {
27 if (!globalThis.__ALCHEMY_RUNTIME__) {
28 for (const key of keys) {
29 yield* bind`AWS.PaymentCryptography.TranslateKeyMaterial(${key})`({
30 policyStatements: [
31 {
32 Effect: "Allow",
33 Action: ["payment-cryptography:TranslateKeyMaterial"],
34 Resource: [key.keyArn],
35 },
36 ],
37 });
38 }
39 }
40 return Effect.fn(
41 `AWS.PaymentCryptography.TranslateKeyMaterial(${keys
42 .map((key) => key.LogicalId)
43 .join(", ")})`,
44 )(function* (request: TranslateKeyMaterialRequest) {
45 return yield* translateKeyMaterial(request);
46 });
47 });
48 }),
49 );