Something went wrong. Try again.
Something went wrong. Try again.
1.1 kB · 37 lines
TypeScript
at main
1234567891011121314151617181920212223242526272829303132333435363738import { spawn } from "bun";
const SERVICE = "sh.tangled.cli";
export async function setPassword(did: string, password: string): Promise<void> { const proc = spawn({ cmd: ["security", "add-generic-password", "-U", "-a", did, "-s", SERVICE, "-w", password], stdout: "pipe", stderr: "pipe", }); const code = await proc.exited; if (code !== 0) { const err = await new Response(proc.stderr).text(); throw new Error(`keychain write failed: ${err.trim()}`); }}
export async function getPassword(did: string): Promise<string | null> { const proc = spawn({ cmd: ["security", "find-generic-password", "-a", did, "-s", SERVICE, "-w"], stdout: "pipe", stderr: "pipe", }); const code = await proc.exited; if (code !== 0) return null; const out = await new Response(proc.stdout).text(); return out.replace(/\n$/, "");}
export async function deletePassword(did: string): Promise<void> { const proc = spawn({ cmd: ["security", "delete-generic-password", "-a", did, "-s", SERVICE], stdout: "pipe", stderr: "pipe", }); await proc.exited;}