Sync your Obsidian vault to an atproto PDS community.obsidian.md/plugins/pds-sync
0

Configure Feed

Select the types of activity you want to include in your feed.

obsidian-pds-sync / src / secrets.ts
1.3 kB 38 lines
1import type { App } from "obsidian"; 2 3/** 4 * Credential storage backed by Obsidian's SecretStorage (OS keychain - macOS 5 * Keychain, Windows Credential Manager, Linux libsecret; since Obsidian 1.11.4), 6 * with a plaintext-settings fallback for older versions / platforms without it. 7 * 8 * IDs are fixed and plugin-namespaced so they don't collide with other plugins' 9 * shared secrets and load automatically - the user never names them. 10 */ 11 12export const SECRET_APP_PASSWORD = "pds-sync-app-password"; 13export const SECRET_E2EE_PASSPHRASE = "pds-sync-e2ee-passphrase"; 14 15function storage(app: App): App["secretStorage"] | undefined { 16 return (app as Partial<App>).secretStorage; 17} 18 19export function keychainAvailable(app: App): boolean { 20 return storage(app) != null; 21} 22 23export function readSecret(app: App, id: string, fallback: string): string { 24 const ss = storage(app); 25 if (ss) return ss.getSecret(id) ?? ""; 26 return fallback; 27} 28 29/** 30 * Persist a secret. Returns true if it was stored in the keychain - in which 31 * case the caller must NOT also keep it in plaintext settings. 32 */ 33export function writeSecret(app: App, id: string, value: string): boolean { 34 const ss = storage(app); 35 if (!ss) return false; 36 ss.setSecret(id, value); 37 return true; 38}