Open History to see the last commit
1import * as Crypto from "effect/Crypto";
2import * as Effect from "effect/Effect";
3import * as Hex from "effect/encoding/Hex";
4import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
5
6export const make = Effect.fn("ProviderCredentialStore.make")(function* (
7 driver: string,
8 bindingId: string,
9) {
10 const secrets = yield* ServerSecretStore.ServerSecretStore;
11 const crypto = yield* Crypto.Crypto;
12 // Hash the tuple so arbitrary bindings cannot escape or exceed a filename.
13 const bindingHash = yield* crypto
14 .digest("SHA-256", new TextEncoder().encode(`${driver.length}:${driver}${bindingId}`))
15 .pipe(Effect.map(Hex.encode), Effect.orDie);
16 const key = `provider-auth-${bindingHash}`;
17 return {
18 binding: { owner: "t3" as const, key },
19 get: secrets.get(key),
20 set: (credentials: Uint8Array) => secrets.set(key, credentials),
21 remove: secrets.remove(key),
22 };
23});