// One vault: its secret names (which the server can see) and, once the member // pastes their identity key, the values (which it cannot). Decryption happens // in public/vault.js with the same libsodium calls the CLI makes; the key is // checked against the public key the server holds before anything is opened, // and it is never sent anywhere. import { esc } from "./html.mjs"; const VAULT_SEP = "--"; /** `--` back into its parts, as the CLI's splitVaultName does. */ export function splitVaultName(name) { const at = name.indexOf(VAULT_SEP); if (at <= 0) return null; const env = name.slice(at + VAULT_SEP.length); if (!env || env.includes(VAULT_SEP)) return null; return { project: name.slice(0, at), env }; } const when = (ms) => (ms ? new Date(Number(ms)).toISOString().slice(0, 16).replace("T", " ") : "—"); /** How to get the key onto the clipboard, for the machine that ran `logicsrc login`. */ export const KEY_HELP = `
Where do I find my key?

It is the identity secret key the logicsrc CLI created the first time you ran logicsrc login. It lives only on that machine, in ~/.config/logicsrc/identity.json. On that machine, run:

logicsrc teams key

That needs CLI 0.5.0 or later (curl -fsSL https://logicsrc.com/install.sh | sh -s -- update). On an older CLI, either of these prints the same thing:

jq -r .keys.secretKey ~/.config/logicsrc/identity.json
node -p 'require(require("os").homedir()+"/.config/logicsrc/identity.json").keys.secretKey'

Pasting the whole identity.json works too; only secretKey is read. Installs from before the config move keep it at ~/.logicsrc/identity.json. Anyone holding this key can read every vault you can, so treat it like a password.

`; function keyCard({ publicKey, hasGrant, grantCommand }) { if (!publicKey) { // No identity registered yet: offer to make one here. Only in this state -- // replacing a registered key would orphan every grant sealed to the old one. return `
Read the values

You have no identity key yet, so no vault can be shared with you. Values are encrypted to a key only you hold. Make one in either place:

  • In a terminal: curl -fsSL https://logicsrc.com/install.sh | sh, then logicsrc login. Then logicsrc teams key prints the key to paste here.
  • Or here in this browser:

`; } return `
Read the valueslocked
${hasGrant ? "" : `
You have not been granted this vault yet, so your key cannot open it. Ask a member who can to run ${esc(grantCommand)}.
`}

${KEY_HELP}
`; } /** * The page body below the app bar. `secrets` are rows of credshare_secrets * (name, version, updated_at only — ciphertext is fetched by vault.js). */ /** * The caller's machine keys for this vault's team. Granting one seals the * vault key to the machine's own public key, in the browser, after unlock -- * the same crypto_box_seal the CLI's `teams grant --key` does. */ function machineKeysCard({ machineKeys, team, parts }) { if (!machineKeys || machineKeys.length === 0) return ""; const grantCmd = (name) => `logicsrc teams grant ${team.slug} ${parts ? `${parts.project} ${parts.env}` : " "} --key ${name}`; const rows = machineKeys.map((k) => { const state = k.granted ? `granted ` : k.publicKey ? `` : `not used yet run one command with the key on the box first`; return `${esc(k.name)} ${esc(k.prefix)}…${k.readOnly ? "read-only" : "read-write"}
${state}
`; }).join(""); return `
Machine keys

Your machine API keys scoped to this vault. Unlock above, then grant: the vault key is sealed to the machine's own key in this browser. Or from a terminal: ${esc(grantCmd(machineKeys[0].name))}

${rows}
KeyAccess

`; } export function vaultPageBody({ team, vault, secrets, hasGrant, publicKey, email, machineKeys = [] }) { const parts = splitVaultName(vault.name); const grantCommand = `logicsrc teams grant ${team.slug} ${parts ? `${parts.project} ${parts.env}` : " "} ${email || ""}`; const rows = secrets.map((s) => ` ${esc(s.name)} •••••••• ${Number(s.version) || 1} ${esc(when(s.updated_at))} `).join(""); return `

teams / ${esc(team.slug)} / vaults

${esc(vault.name)}

${secrets.length}
${keyCard({ publicKey, hasGrant, grantCommand })} ${machineKeysCard({ machineKeys, team, parts })}
${secrets.length ? `
${rows}
NameValuevUpdated (UTC)
` : `

This vault is empty. Push to it from the CLI: logicsrc teams push ${esc(team.slug)} ${parts ? `${esc(parts.project)} ${esc(parts.env)}` : "<project> <env>"}

`}
`; }