Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ProviderCredentialStore.ts

21 lines832 Bytes

1import * as NodeCrypto from "node:crypto";
2import * as Effect from "effect/Effect";
3import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
4​
5/** A provider binding stores opaque bytes; only its adapter decodes or refreshes them. */
6export const make = Effect.fn("ProviderCredentialStore.make")(function* (
7 driver: string,
8 bindingId: string,
9) {
10 const secrets = yield* ServerSecretStore.ServerSecretStore;
11 // Hash the tuple so arbitrary bindings cannot escape or exceed a filename.
12 const key = `provider-auth-${NodeCrypto.createHash("sha256")
13 .update(`${driver.length}:${driver}${bindingId}`)
14 .digest("hex")}`;
15 return {
16 binding: { owner: "t3" as const, key },
17 get: secrets.get(key),
18 set: (credentials: Uint8Array) => secrets.set(key, credentials),
19 remove: secrets.remove(key),
20 };
21});