Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

feat(vaults): create signing keys + create-form UX (tags, host allow-list, default group) (#701)

Call White65e984fa94f5
diff --git a/ui/src/components/ui/tag-input.tsx b/ui/src/components/ui/tag-input.tsx
new file mode 100644
index 000000000..746cf0273
--- /dev/null
+++ b/ui/src/components/ui/tag-input.tsx
@@ -0,0 +1,133 @@
+import { useState } from 'react';
+import type { KeyboardEvent, ClipboardEvent } from 'react';
+import { X } from 'lucide-react';
+
+import { cn } from '@/lib/utils';
+
+export type TagInputProps = {
+ values: string[];
+ onChange: (next: string[]) => void;
+ placeholder?: string;
+ /**
+ * Normalize/validate a raw entry. Return the cleaned value to accept it, or
+ * `null` to reject. Defaults to a trimmed, non-empty string.
+ */
+ normalize?: (raw: string) => string | null;
+ ariaLabel?: string;
+ /** Localized aria-label for a chip's remove button. Defaults to English. */
+ removeLabel?: (value: string) => string;
+ /** Notified when the uncommitted draft becomes non-empty / empty, so the form
+ * can block submitting while a chip is half-typed. */
+ onPendingChange?: (pending: boolean) => void;
+ className?: string;
+ inputClassName?: string;
+};
+
+const defaultNormalize = (raw: string): string | null => {
+ const trimmed = raw.trim();
+ return trimmed.length ? trimmed : null;
+};
+
+/**
+ * Chip-style multi-value input: type a value and press Enter or comma to add a
+ * tag, click the × (or Backspace on an empty field) to remove one. Used for
+ * vault secret tags and allowed-host lists.
+ */
+export const TagInput: React.FC<TagInputProps> = ({
+ values,
+ onChange,
+ placeholder,
+ normalize = defaultNormalize,
+ ariaLabel,
+ removeLabel = (value) => `Remove ${value}`,
+ onPendingChange,
+ className,
+ inputClassName,
+}) => {
+ const [draft, setDraft] = useState('');
+
+ const setDraftSafe = (next: string) => {
+ setDraft(next);
+ onPendingChange?.(next.trim().length > 0);
+ };
+
+ // Live feedback so a typed-but-uncommitted value the matcher would reject (a URL,
+ // a host:port) is visibly invalid instead of being silently dropped on submit.
+ const draftInvalid = draft.trim().length > 0 && normalize(draft) === null;
+
+ const commit = (raw: string) => {
+ const cleaned = normalize(raw);
+ if (!cleaned) return;
+ if (!values.includes(cleaned)) onChange([...values, cleaned]);
+ setDraftSafe('');
+ };
+
+ const removeAt = (index: number) => onChange(values.filter((_, i) => i !== index));
+
+ const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ if (event.key === 'Enter' || event.key === ',') {
+ event.preventDefault();
+ commit(draft);
+ } else if (event.key === 'Backspace' && draft === '' && values.length) {
+ event.preventDefault();
+ removeAt(values.length - 1);
+ }
+ };
+
+ const onPaste = (event: ClipboardEvent<HTMLInputElement>) => {
+ const text = event.clipboardData.getData('text');
+ if (!text.includes(',') && !text.includes('\n')) return;
+ event.preventDefault();
+ const parts = text.split(/[,\n]/);
+ const next = [...values];
+ for (const part of parts) {
+ const cleaned = normalize(part);
+ if (cleaned && !next.includes(cleaned)) next.push(cleaned);
+ }
+ onChange(next);
+ setDraftSafe('');
+ };
+
+ return (
+ <div
+ className={cn(
+ 'flex flex-wrap items-center gap-1.5 rounded-md border bg-surface px-2 py-1.5',
+ draftInvalid ? 'border-destructive' : 'border-border focus-within:border-mint',
+ className,
+ )}
+ >
+ {values.map((value, index) => (
+ <span
+ key={value}
+ className="flex items-center gap-1 rounded bg-surface-2 px-1.5 py-0.5 font-mono text-xs text-foreground"
+ >
+ {value}
+ <button
+ type="button"
+ onClick={() => removeAt(index)}
+ aria-label={removeLabel(value)}
+ className="text-muted hover:text-foreground"
+ >
+ <X className="size-3" />
+ </button>
+ </span>
+ ))}
+ <input
+ value={draft}
+ onChange={(event) => setDraftSafe(event.target.value)}
+ onKeyDown={onKeyDown}
+ onPaste={onPaste}
+ onBlur={() => commit(draft)}
+ placeholder={values.length ? undefined : placeholder}
+ aria-label={ariaLabel}
+ aria-invalid={draftInvalid || undefined}
+ autoComplete="off"
+ spellCheck={false}
+ className={cn(
+ 'min-w-[8ch] flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground',
+ inputClassName,
+ )}
+ />
+ </div>
+ );
+};
diff --git a/ui/src/components/ui/vault-secret-form.tsx b/ui/src/components/ui/vault-secret-form.tsx
index 9c9366624..72418e0fc 100644
--- a/ui/src/components/ui/vault-secret-form.tsx
+++ b/ui/src/components/ui/vault-secret-form.tsx
@@ -1,18 +1,63 @@
-import { useEffect, useMemo, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
import type { FormEvent } from 'react';
-import { Eye, EyeOff, Loader2, Server, ShieldCheck } from 'lucide-react';
+import {
+ Check,
+ ChevronDown,
+ ChevronRight,
+ Copy,
+ Eye,
+ EyeOff,
+ KeyRound,
+ Loader2,
+ RefreshCw,
+ Server,
+ ShieldCheck,
+ Wallet,
+} from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { ApiError, useApi, type DependencyItem } from '@/context/ApiContext';
import { cn } from '@/lib/utils';
-import { sealBlindBox, standardCreateBlindBoxContext, type ProtectedRecordEnvelope } from '@/lib/vaultCrypto';
+import {
+ generateSigningKey,
+ importSigningKey,
+ sealBlindBox,
+ standardCreateBlindBoxContext,
+ type ProtectedRecordEnvelope,
+ type SigningKeyMaterial,
+} from '@/lib/vaultCrypto';
import { useProtectedVault } from '@/lib/useProtectedVault';
import { Button } from './button';
import { Combobox } from './combobox';
import { Input } from './input';
+import { TagInput } from './tag-input';
import { VaultProtectedUnlock } from './vault-protected-unlock';
+type VaultKind = 'static' | 'keypair';
+
const AVAULT_P2_MIN_VERSION = '0.1.3';
+const DEFAULT_GROUP = 'default';
+
+// Accept only what the brokered fetch matcher (`_host_allowed` in vibe/cli.py) can
+// actually match against `urlsplit(url).hostname`: a bare hostname (`api.example.com`,
+// `localhost`), a leading-dot subdomain entry (`.example.com`), or an IPv6 literal
+// (`::1`, `2001:db8::1` — matched exactly, ::1 treated as loopback). No port, scheme,
+// path, or wildcard — those would persist a policy that never authorizes a request.
+function normalizeHost(raw: string): string | null {
+ const host = raw.trim().toLowerCase();
+ if (!host) return null;
+ if (host.includes(':')) {
+ // IPv6 literal (urlsplit().hostname form, no brackets) — validate via the URL parser.
+ try {
+ return new URL(`http://[${host}]/`).hostname ? host : null;
+ } catch {
+ return null;
+ }
+ }
+ const core = host.startsWith('.') ? host.slice(1) : host;
+ const label = '[a-z0-9](?:[a-z0-9-]*[a-z0-9])?';
+ return new RegExp(`^${label}(?:\\.${label})*$`).test(core) ? host : null;
+}
type VaultProtection = 'standard' | 'protected';
function versionAtLeast(current: string | null | undefined, minimum: string): boolean {
@@ -66,9 +111,19 @@ export const VaultSecretForm: React.FC<{
const api = useApi();
const [name, setName] = useState(fixedName ?? '');
const [value, setValue] = useState('');
- const [group, setGroup] = useState('');
+ const [kind, setKind] = useState<VaultKind>('static');
+ const [signingSource, setSigningSource] = useState<'generate' | 'import'>('generate');
+ const [importHex, setImportHex] = useState('');
+ const [signingKey, setSigningKey] = useState<SigningKeyMaterial | null>(null);
+ const [signingError, setSigningError] = useState<string | null>(null);
+ const [copied, setCopied] = useState(false);
+ const [group, setGroup] = useState(DEFAULT_GROUP);
+ const [tags, setTags] = useState<string[]>([]);
const [description, setDescription] = useState('');
- const [allowHosts, setAllowHosts] = useState('');
+ const [allowHosts, setAllowHosts] = useState<string[]>([]);
+ const [hostsOpen, setHostsOpen] = useState(false);
+ const [tagsPending, setTagsPending] = useState(false);
+ const [hostsPending, setHostsPending] = useState(false);
const [protection, setProtection] = useState<VaultProtection>(defaultProtection);
const [showValue, setShowValue] = useState(false);
const [submitting, setSubmitting] = useState(false);
@@ -108,8 +163,44 @@ export const VaultSecretForm: React.FC<{
const standardCreateReady = useMemo(() => avaultInstalled(avaultDep), [avaultDep]);
const secretName = (fixedName ?? name).trim().toUpperCase();
const protectedCreateReady = protectedVault.status === 'unlocked';
+ const isKeypair = kind === 'keypair';
+
+ // Hold the latest key material in a ref too, so the unmount cleanup can zero
+ // the *current* private key (a [] effect would capture a stale value).
+ const signingKeyRef = useRef<SigningKeyMaterial | null>(null);
+
+ // Replace the in-memory signing key, zeroing the previous private key so raw
+ // key material never lingers longer than needed.
+ const applySigningKey = (next: SigningKeyMaterial | null) => {
+ if (signingKeyRef.current && signingKeyRef.current !== next) {
+ signingKeyRef.current.privateKey.fill(0);
+ }
+ signingKeyRef.current = next;
+ setSigningKey(next);
+ setCopied(false);
+ };
+
+ // Signing keys are sealed in the browser and signed locally by avault, so they
+ // require the P2 avault surface and (this version) the standard tier; the
+ // protected tier's browser signing sandbox lands next version.
+ useEffect(() => {
+ if (isKeypair && protection !== 'standard') setProtection('standard');
+ }, [isKeypair, protection]);
+
+ // Zero any held private key when the form unmounts.
+ useEffect(
+ () => () => {
+ if (signingKeyRef.current) signingKeyRef.current.privateKey.fill(0);
+ signingKeyRef.current = null;
+ },
+ [],
+ );
+
+ const valueReady = isKeypair ? signingKey != null : Boolean(value);
+ const keypairRequirementsMet = !isKeypair || p2Ready;
const canSubmit =
- Boolean(secretName && value) &&
+ Boolean(secretName && valueReady) &&
+ keypairRequirementsMet &&
!submitting &&
((protection === 'standard' && standardCreateReady) || (protection === 'protected' && protectedCreateReady));
@@ -125,20 +216,35 @@ export const VaultSecretForm: React.FC<{
const onSubmit = async (event: FormEvent) => {
event.preventDefault();
if (!canSubmit) return;
+ // Don't silently drop a half-typed tag/host chip the user can still see.
+ if (tagsPending || (hostsOpen && hostsPending)) {
+ setError(t('vaults.dialog.errors.pendingDraft'));
+ return;
+ }
setSubmitting(true);
setError(null);
try {
- const hosts = allowHosts
- .split(',')
- .map((host) => host.trim())
- .filter(Boolean);
const base = {
name: secretName,
protection,
group: group.trim() || undefined,
description: description.trim() || undefined,
- policy: hosts.length ? { allowed_hosts: hosts } : undefined,
+ tags: tags.length ? tags : undefined,
+ policy: allowHosts.length ? { allowed_hosts: allowHosts } : undefined,
+ ...(isKeypair && signingKey
+ ? {
+ kind: 'keypair',
+ signer_kind: 'local',
+ // Chain-agnostic: only the compressed secp256k1 public key is pinned
+ // in the clear; the scheme is chosen at sign time, not here.
+ public_meta: { signing_public_key: { curve: 'secp256k1', public_key: signingKey.publicKey } },
+ }
+ : {}),
};
+ // For a signing key the sealed value is the raw 32-byte private key (avault
+ // opens it back into a 32-byte signing key); for a static secret it is the
+ // entered string.
+ const plaintext: Uint8Array | string = isKeypair && signingKey ? signingKey.privateKey : value;
let cryptoFields:
| { sealed: ProtectedRecordEnvelope }
| { blind_box: Awaited<ReturnType<typeof sealBlindBox>> }
@@ -151,8 +257,10 @@ export const VaultSecretForm: React.FC<{
establishingVmk = sealed.establishingVmk;
} else if (p2Ready) {
const pubkey = await api.getVaultPubkey();
- cryptoFields = { blind_box: await sealBlindBox(value, pubkey, standardCreateBlindBoxContext(secretName)) };
+ cryptoFields = { blind_box: await sealBlindBox(plaintext, pubkey, standardCreateBlindBoxContext(secretName)) };
} else {
+ // Plain-value fallback exists only for static secrets; signing keys require
+ // the avault P2 surface (gated by canSubmit), so plaintext is a string here.
cryptoFields = { value };
}
const created = await api.createVaultSecret(
@@ -175,6 +283,8 @@ export const VaultSecretForm: React.FC<{
}
if (protection === 'protected') protectedVault.afterCreated();
setValue('');
+ applySigningKey(null);
+ setImportHex('');
onCreated(secretName, 'created');
} catch (err: unknown) {
if (err instanceof Error && err.message.includes('fingerprint mismatch')) {
@@ -201,33 +311,188 @@ export const VaultSecretForm: React.FC<{
<Input value={name} onChange={(event) => setName(event.target.value)} autoFocus required />
</label>
)}
- <label className="flex flex-col gap-1.5 text-sm font-medium">
- {t('vaults.dialog.value')}
- <div className="flex items-center gap-2">
- <Input
- type={showValue ? 'text' : 'password'}
- value={value}
- onChange={(event) => setValue(event.target.value)}
- placeholder={t('vaults.dialog.valuePlaceholder')}
- autoFocus={Boolean(fixedName)}
- required
- className="min-w-0 flex-1 font-mono"
- />
- <Button
- type="button"
- variant="ghost"
- size="icon"
- onClick={() => setShowValue((current) => !current)}
- aria-label={showValue ? t('vaults.dialog.hideValue') : t('vaults.dialog.showValue')}
- >
- {showValue ? <EyeOff className="size-4" /> : <Eye className="size-4" />}
- </Button>
+ {/* Provision ($NAME) requests are for a specific value the agent asked for, so
+ the type selector is hidden there — a provision must stay a static secret,
+ not be fulfilled with a signing key. */}
+ {!fixedName && (
+ <div className="flex flex-col gap-1.5 text-sm font-medium">
+ <span>{t('vaults.dialog.kindLabel')}</span>
+ <div className="grid grid-cols-2 gap-2.5">
+ {(
+ [
+ { key: 'static', icon: KeyRound, title: t('vaults.dialog.kindStatic'), desc: t('vaults.dialog.kindStaticHelp') },
+ { key: 'keypair', icon: Wallet, title: t('vaults.dialog.kindKeypair'), desc: t('vaults.dialog.kindKeypairHelp') },
+ ] as const
+ ).map(({ key, icon: Icon, title, desc }) => {
+ const selected = kind === key;
+ return (
+ <button
+ key={key}
+ type="button"
+ aria-pressed={selected}
+ disabled={submitting}
+ onClick={() => {
+ setKind(key);
+ // Leaving keypair: drop any held private key so unused key material
+ // isn't kept in memory until the dialog closes.
+ if (key === 'static') {
+ applySigningKey(null);
+ setImportHex('');
+ setSigningError(null);
+ }
+ }}
+ className={cn(
+ 'flex flex-col gap-1.5 rounded-lg border p-3 text-left transition-colors disabled:opacity-50',
+ selected ? 'border-mint bg-mint-soft' : 'border-border bg-surface hover:bg-surface-2',
+ )}
+ >
+ <span className="flex items-center gap-2">
+ <Icon className={cn('size-4', selected ? 'text-mint' : 'text-muted')} />
+ <span className="text-sm font-semibold text-foreground">{title}</span>
+ </span>
+ <span className="text-xs font-normal text-muted-foreground">{desc}</span>
+ </button>
+ );
+ })}
</div>
- </label>
+ </div>
+ )}
+
+ {!isKeypair && (
+ <label className="flex flex-col gap-1.5 text-sm font-medium">
+ {t('vaults.dialog.value')}
+ <div className="flex items-center gap-2">
+ <Input
+ type={showValue ? 'text' : 'password'}
+ value={value}
+ onChange={(event) => setValue(event.target.value)}
+ placeholder={t('vaults.dialog.valuePlaceholder')}
+ autoFocus={Boolean(fixedName)}
+ required
+ className="min-w-0 flex-1 font-mono"
+ />
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ onClick={() => setShowValue((current) => !current)}
+ aria-label={showValue ? t('vaults.dialog.hideValue') : t('vaults.dialog.showValue')}
+ >
+ {showValue ? <EyeOff className="size-4" /> : <Eye className="size-4" />}
+ </Button>
+ </div>
+ </label>
+ )}
+
+ {isKeypair && (
+ <div className="flex flex-col gap-2.5 rounded-lg border border-border bg-surface-2 px-3 py-3">
+ <span className="text-xs text-muted-foreground">{t('vaults.dialog.signingKeyHelp')}</span>
+ <div className="grid grid-cols-2 gap-2">
+ {(['generate', 'import'] as const).map((src) => (
+ <Button
+ key={src}
+ type="button"
+ size="sm"
+ variant={signingSource === src ? 'secondary' : 'ghost'}
+ disabled={submitting}
+ onClick={() => {
+ setSigningSource(src);
+ setSigningError(null);
+ applySigningKey(null);
+ setImportHex('');
+ }}
+ >
+ {src === 'generate' ? t('vaults.dialog.signingGenerate') : t('vaults.dialog.signingImport')}
+ </Button>
+ ))}
+ </div>
+
+ {signingSource === 'generate' && (
+ <Button
+ type="button"
+ variant="secondary"
+ disabled={submitting}
+ onClick={() => {
+ try {
+ applySigningKey(generateSigningKey());
+ setSigningError(null);
+ } catch (err) {
+ setSigningError(err instanceof Error ? err.message : String(err));
+ }
+ }}
+ >
+ <RefreshCw className="size-4" />
+ {signingKey ? t('vaults.dialog.signingRegenerate') : t('vaults.dialog.signingGenerateCta')}
+ </Button>
+ )}
+
+ {signingSource === 'import' && (
+ <Input
+ value={importHex}
+ spellCheck={false}
+ autoComplete="off"
+ disabled={submitting}
+ placeholder={t('vaults.dialog.signingImportPlaceholder')}
+ className="font-mono"
+ onChange={(event) => {
+ const next = event.target.value;
+ setImportHex(next);
+ const trimmed = next.trim();
+ if (!trimmed) {
+ applySigningKey(null);
+ setSigningError(null);
+ return;
+ }
+ try {
+ applySigningKey(importSigningKey(trimmed));
+ setSigningError(null);
+ } catch {
+ applySigningKey(null);
+ setSigningError(t('vaults.dialog.errors.invalidPrivateKey'));
+ }
+ }}
+ />
+ )}
+
+ {signingKey && (
+ <div className="flex flex-col gap-1.5">
+ <span className="text-xs font-medium text-muted-foreground">{t('vaults.dialog.signingPublicKey')}</span>
+ <div className="flex items-center gap-2">
+ <code className="min-w-0 flex-1 truncate rounded-md border border-border bg-surface px-2 py-1.5 font-mono text-xs">
+ {signingKey.publicKey}
+ </code>
+ <Button
+ type="button"
+ variant="ghost"
+ size="icon"
+ aria-label={t('vaults.dialog.copyPublicKey')}
+ onClick={() => {
+ void navigator.clipboard?.writeText(signingKey.publicKey).then(() => {
+ setCopied(true);
+ window.setTimeout(() => setCopied(false), 1500);
+ });
+ }}
+ >
+ {copied ? <Check className="size-4 text-mint" /> : <Copy className="size-4" />}
+ </Button>
+ </div>
+ <span className="text-xs text-muted-foreground">{t('vaults.dialog.signingPublicKeyHint')}</span>
+ </div>
+ )}
+
+ {signingError && <span className="text-xs text-destructive">{signingError}</span>}
+
+ {!p2Ready && (
+ <div className="rounded-md border border-warning/40 bg-warning/10 px-2.5 py-1.5 text-xs text-warning">
+ {t('vaults.dialog.signingNeedsAvault', { version: AVAULT_P2_MIN_VERSION })}
+ </div>
+ )}
+ </div>
+ )}
<label className="flex flex-col gap-1.5 text-sm font-medium">
{t('vaults.dialog.group')}
<Combobox
- options={groups.map((g) => ({ value: g, label: g }))}
+ options={[...new Set([DEFAULT_GROUP, ...groups])].map((g) => ({ value: g, label: g }))}
value={group}
onValueChange={setGroup}
allowCustomValue
@@ -242,11 +507,51 @@ export const VaultSecretForm: React.FC<{
{t('vaults.dialog.description')}
<Input value={description} onChange={(event) => setDescription(event.target.value)} />
</label>
- <label className="flex flex-col gap-1.5 text-sm font-medium">
- {t('vaults.dialog.allowHosts')}
- <Input value={allowHosts} onChange={(event) => setAllowHosts(event.target.value)} />
- <span className="text-xs text-muted-foreground">{t('vaults.dialog.allowHostsHelp')}</span>
- </label>
+ <div className="flex flex-col gap-1.5 text-sm font-medium">
+ <span>{t('vaults.dialog.tags')}</span>
+ <TagInput
+ values={tags}
+ onChange={setTags}
+ placeholder={t('vaults.dialog.tagsPlaceholder')}
+ ariaLabel={t('vaults.dialog.tags')}
+ removeLabel={(value) => t('vaults.dialog.removeChip', { value })}
+ onPendingChange={setTagsPending}
+ />
+ <span className="text-xs font-normal text-muted-foreground">{t('vaults.dialog.tagsHelp')}</span>
+ </div>
+ <div className="flex flex-col gap-1.5 text-sm font-medium">
+ <button
+ type="button"
+ onClick={() =>
+ setHostsOpen((open) => {
+ if (open) setHostsPending(false);
+ return !open;
+ })
+ }
+ aria-expanded={hostsOpen}
+ className="flex items-center gap-1.5 text-left text-sm font-medium text-muted-foreground hover:text-foreground"
+ >
+ {hostsOpen ? <ChevronDown className="size-4 shrink-0" /> : <ChevronRight className="size-4 shrink-0" />}
+ {t('vaults.dialog.allowHosts')}
+ {!hostsOpen && allowHosts.length > 0 && (
+ <span className="rounded bg-surface-2 px-1.5 py-0.5 text-xs font-normal text-foreground">{allowHosts.length}</span>
+ )}
+ </button>
+ {hostsOpen && (
+ <>
+ <TagInput
+ values={allowHosts}
+ onChange={setAllowHosts}
+ normalize={normalizeHost}
+ placeholder={t('vaults.dialog.allowHostsPlaceholder')}
+ ariaLabel={t('vaults.dialog.allowHosts')}
+ removeLabel={(value) => t('vaults.dialog.removeChip', { value })}
+ onPendingChange={setHostsPending}
+ />
+ <span className="text-xs font-normal text-muted-foreground">{t('vaults.dialog.allowHostsHelp')}</span>
+ </>
+ )}
+ </div>
<div className="flex flex-col gap-1.5 text-sm font-medium">
<span>{t('vaults.dialog.protection')}</span>
<div className="grid grid-cols-2 gap-2.5">
@@ -257,14 +562,21 @@ export const VaultSecretForm: React.FC<{
] as const
).map(({ key, icon: Icon, title, desc }) => {
const selected = protection === key;
+ // Protected signing keys need the browser signing sandbox (next version),
+ // so the protected tier is disabled while creating a keypair.
+ const optionDisabled = key === 'protected' && isKeypair;
return (
<button
key={key}
type="button"
aria-pressed={selected}
- onClick={() => setProtection(key)}
+ disabled={optionDisabled}
+ onClick={() => {
+ if (!optionDisabled) setProtection(key);
+ }}
className={cn(
'flex flex-col gap-1.5 rounded-lg border p-3 text-left transition-colors',
+ optionDisabled && 'cursor-not-allowed opacity-50',
selected ? 'border-mint bg-mint-soft' : 'border-border bg-surface hover:bg-surface-2',
)}
>
@@ -277,6 +589,9 @@ export const VaultSecretForm: React.FC<{
);
})}
</div>
+ {isKeypair && (
+ <span className="text-xs font-normal text-muted-foreground">{t('vaults.dialog.protectedKeypairNextVersion')}</span>
+ )}
</div>
{protection === 'protected' && <VaultProtectedUnlock vault={protectedVault} />}
{protection === 'standard' && checkingAvault && (
@@ -285,7 +600,7 @@ export const VaultSecretForm: React.FC<{
{t('vaults.dialog.checkingAvault')}
</div>
)}
- {protection === 'standard' && !checkingAvault && !p2Ready && (
+ {protection === 'standard' && !isKeypair && !checkingAvault && !p2Ready && (
<div className="rounded-lg border border-warning/40 bg-warning/10 px-3 py-2 text-sm text-warning">
{standardCreateReady
? t('vaults.dialog.p2UnavailableStandardFallback', {
diff --git a/ui/src/components/workbench/VaultsPage.tsx b/ui/src/components/workbench/VaultsPage.tsx
index 97300ee21..c684fd87c 100644
--- a/ui/src/components/workbench/VaultsPage.tsx
+++ b/ui/src/components/workbench/VaultsPage.tsx
@@ -1,5 +1,5 @@
import { useCallback, useEffect, useMemo, useState } from 'react';
-import { Clock, History, KeyRound, Layers, Loader2, Plus, Puzzle, RefreshCw, ShieldCheck, ShieldOff, Trash2, Wallet } from 'lucide-react';
+import { Check, Clock, Copy, History, KeyRound, Layers, Loader2, Plus, Puzzle, RefreshCw, ShieldCheck, ShieldOff, Trash2, Wallet } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { CapabilityTabs } from './CapabilityTabs';
import { WorkbenchPageHeader } from './WorkbenchPageHeader';
@@ -45,6 +45,8 @@ const SecretRow: React.FC<{ secret: VaultSecret; onDelete: (name: string) => voi
const { t } = useTranslation();
const isKeypair = s.kind === 'keypair';
const isProtected = s.protection === 'protected';
+ const [copied, setCopied] = useState(false);
+ const publicKey = s.signing_public_key?.public_key;
return (
<div className="flex items-center gap-3.5 rounded-xl border border-border bg-surface px-4 py-3">
<div
@@ -69,11 +71,33 @@ const SecretRow: React.FC<{ secret: VaultSecret; onDelete: (name: string) => voi
</Badge>
) : null}
{hasProxy(s) ? <Badge variant="info">{t('vaults.proxyBound')}</Badge> : null}
+ {s.tags?.map((tag) => (
+ <Badge key={tag} variant="outline" className="text-muted">
+ {tag}
+ </Badge>
+ ))}
</div>
<span className="truncate text-xs text-muted">
{s.description ? `${s.description} · ` : ''}
{s.last_used_at ? t('vaults.used', { count: s.use_count }) : t('vaults.neverUsed')}
</span>
+ {isKeypair && publicKey && (
+ <button
+ type="button"
+ onClick={() => {
+ void navigator.clipboard?.writeText(publicKey).then(() => {
+ setCopied(true);
+ window.setTimeout(() => setCopied(false), 1500);
+ });
+ }}
+ className="flex max-w-full items-center gap-1 text-xs text-muted hover:text-foreground"
+ aria-label={t('vaults.dialog.copyPublicKey')}
+ title={publicKey}
+ >
+ <span className="truncate font-mono">{publicKey}</span>
+ {copied ? <Check className="size-3 shrink-0 text-mint" /> : <Copy className="size-3 shrink-0" />}
+ </button>
+ )}
</div>
<div className="ml-auto">
<Button variant="ghost" size="icon" onClick={() => onDelete(s.name)} aria-label={t('vaults.delete')}>
diff --git a/ui/src/context/ApiContext.tsx b/ui/src/context/ApiContext.tsx
index 76896cbea..a23dbdb2c 100644
--- a/ui/src/context/ApiContext.tsx
+++ b/ui/src/context/ApiContext.tsx
@@ -23,6 +23,9 @@ export type VaultSecret = {
kind: string;
protection: string;
signer_kind: string | null;
+ /** Pinned public key for keypair secrets (non-secret); surfaced so the saved
+ * signing key's public key is recoverable after the create dialog closes. */
+ signing_public_key?: { curve?: string; public_key: string } | null;
source: string;
description?: string | null;
policy: Record<string, unknown>;
diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.json
index 29c69ca57..7af1c4201 100644
--- a/ui/src/i18n/en.json
+++ b/ui/src/i18n/en.json
@@ -2192,6 +2192,22 @@
"valuePlaceholder": "Browser-side sealing is required before saving",
"showValue": "Show value",
"hideValue": "Hide value",
+ "kindLabel": "Secret type",
+ "kindStatic": "Value",
+ "kindStaticHelp": "A token, password, or any text value.",
+ "kindKeypair": "Signing key",
+ "kindKeypairHelp": "A signing key generated in your browser.",
+ "signingKeyHelp": "A new secp256k1 signing key is created in your browser. The private key is sealed like any other standard secret and avault signs with it locally; only the public key is stored in the clear.",
+ "signingGenerate": "Generate",
+ "signingImport": "Import",
+ "signingGenerateCta": "Generate signing key",
+ "signingRegenerate": "Generate a different key",
+ "signingImportPlaceholder": "Paste a 32-byte hex private key (64 hex chars)",
+ "signingPublicKey": "Public key",
+ "copyPublicKey": "Copy public key",
+ "signingPublicKeyHint": "Share this public key freely. The private key never leaves your vault, and the chain and signature scheme are chosen at signing time.",
+ "signingNeedsAvault": "Signing keys need avault {{version}} or newer installed.",
+ "protectedKeypairNextVersion": "Protected signing keys arrive with the browser signing sandbox (next version).",
"checkingAvault": "Checking avault…",
"p2Unavailable": "Browser-side vault create requires avault {{version}} or newer. Installed: {{installed}}. Use the CLI stdin/file path until a compatible avault release is installed.",
"p2UnavailableStandardFallback": "Browser-side sealing requires avault {{version}} or newer. Installed: {{installed}}. Standard secrets can still be saved through the local avault seal fallback.",
@@ -2202,20 +2218,27 @@
"groupCreate": "Use \"{{name}}\"",
"groupCreateHeading": "New group",
"description": "Description",
- "allowHosts": "Allowed hosts (for vault fetch)",
- "allowHostsHelp": "Comma-separated. Required to use this secret via the brokered HTTP proxy; '.example.com' matches subdomains.",
+ "allowHosts": "Restrict to specific hosts",
+ "allowHostsPlaceholder": "host, then Enter (e.g. api.example.com)",
+ "allowHostsHelp": "Only needed when this secret is used through the brokered HTTP proxy; '.example.com' matches subdomains.",
+ "tags": "Tags",
+ "tagsPlaceholder": "tag, then Enter",
+ "tagsHelp": "Optional labels to find and group secrets.",
+ "removeChip": "Remove {{value}}",
"protection": "Protection",
"protectedProtection": "Protected",
"standardProtection": "Standard",
"protectedHelp": "Requires browser unlock and approval before agent use.",
- "standardHelp": "Can be used headlessly through avault's standard delivery path.",
+ "standardHelp": "The agent can use it automatically through avault, without an extra unlock each time.",
"protectedCreatePending": "Protected web create is not available in this build yet. Choose Standard only for secrets that may be used headlessly.",
"save": "Save",
"cancel": "Cancel",
"errors": {
"aadFieldTooLarge": "The sealed vault request is too large.",
"invalidPublicKey": "avault returned an invalid public key. Repair the avault dependency and try again.",
+ "invalidPrivateKey": "That isn't a valid secp256k1 private key. It must be 32 bytes (64 hex characters).",
"fingerprintMismatch": "The avault public key fingerprint changed. Verify the local avault install before saving this secret.",
+ "pendingDraft": "Press Enter to add the value in the input, or clear it, before saving.",
"secretExists": "A secret with this name already exists."
}
},
diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.json
index c9a90b6cb..4a224178f 100644
--- a/ui/src/i18n/zh.json
+++ b/ui/src/i18n/zh.json
@@ -2191,6 +2191,22 @@
"valuePlaceholder": "保存前需要浏览器侧封箱",
"showValue": "显示值",
"hideValue": "隐藏值",
+ "kindLabel": "密钥类型",
+ "kindStatic": "值",
+ "kindStaticHelp": "令牌、密码,或任意文本值。",
+ "kindKeypair": "签名密钥",
+ "kindKeypairHelp": "在你浏览器里生成的签名私钥。",
+ "signingKeyHelp": "会在你的浏览器里新生成一把 secp256k1 签名密钥。私钥像其他标准密钥一样被封存、由本机 avault 签名;只有公钥明文保存。",
+ "signingGenerate": "生成",
+ "signingImport": "导入",
+ "signingGenerateCta": "生成签名密钥",
+ "signingRegenerate": "换一把新密钥",
+ "signingImportPlaceholder": "粘贴 32 字节十六进制私钥(64 个字符)",
+ "signingPublicKey": "公钥",
+ "copyPublicKey": "复制公钥",
+ "signingPublicKeyHint": "公钥可以放心分享。私钥始终留在你的保险库里;用哪条链、哪种签名方案,在签名时再定。",
+ "signingNeedsAvault": "签名密钥需要安装 avault {{version}} 或更新版本。",
+ "protectedKeypairNextVersion": "保护层签名密钥将随浏览器签名沙箱在下个版本到来。",
"checkingAvault": "正在检查 avault…",
"p2Unavailable": "浏览器侧保险库创建需要 avault {{version}} 或更新版本。当前安装:{{installed}}。在兼容的 avault 发布版安装前,请使用 CLI stdin/file 路径。",
"p2UnavailableStandardFallback": "浏览器侧封装需要 avault {{version}} 或更新版本。当前安装:{{installed}}。标准密钥仍可通过本机 avault seal fallback 保存。",
@@ -2201,20 +2217,27 @@
"groupCreate": "使用「{{name}}」",
"groupCreateHeading": "新建分组",
"description": "描述",
- "allowHosts": "允许的域名(用于 vault fetch)",
- "allowHostsHelp": "逗号分隔。通过认证代理使用该密钥时必填;'.example.com' 匹配子域。",
+ "allowHosts": "限制到特定域名",
+ "allowHostsPlaceholder": "输入域名后回车(如 api.example.com)",
+ "allowHostsHelp": "仅当该密钥通过认证 HTTP 代理使用时才需要;'.example.com' 匹配子域。",
+ "tags": "标签",
+ "tagsPlaceholder": "输入标签后回车",
+ "tagsHelp": "可选,用来查找和归类密钥。",
+ "removeChip": "移除 {{value}}",
"protection": "保护级别",
"protectedProtection": "受保护",
"standardProtection": "标准",
"protectedHelp": "Agent 使用前需要浏览器解锁和批准。",
- "standardHelp": "可通过 avault 标准交付路径无头使用。",
- "protectedCreatePending": "当前构建尚不支持受保护的 Web 创建。只有可被无头使用的密钥才选择标准。",
+ "standardHelp": "Agent 通过 avault 自动取用,不必每次额外解锁。",
+ "protectedCreatePending": "当前构建尚不支持受保护的 Web 创建。需要 Agent 自动取用的密钥请选标准。",
"save": "保存",
"cancel": "取消",
"errors": {
"aadFieldTooLarge": "这次保险库封箱请求过大。",
"invalidPublicKey": "avault 返回了无效公钥。请修复 avault 依赖后重试。",
+ "invalidPrivateKey": "这不是有效的 secp256k1 私钥,必须是 32 字节(64 个十六进制字符)。",
"fingerprintMismatch": "avault 公钥指纹已变化。请先确认本机 avault 安装可信,再保存该密钥。",
+ "pendingDraft": "请先按回车把输入框里的内容加进去,或清空它,再保存。",
"secretExists": "同名密钥已存在。"
}
},
diff --git a/ui/src/lib/vaultCrypto.test.ts b/ui/src/lib/vaultCrypto.test.ts
index 21b500af1..09d68b6d1 100644
--- a/ui/src/lib/vaultCrypto.test.ts
+++ b/ui/src/lib/vaultCrypto.test.ts
@@ -20,6 +20,8 @@ import {
bytesFromHex,
bytesToHexString,
derivePasskeyKek,
+ generateSigningKey,
+ importSigningKey,
newVmk,
passkeyPrfSaltEntries,
passkeyPrfSalts,
@@ -521,3 +523,36 @@ describe('protected record storage composition', () => {
expect(() => packProtectedRecord(sealed, once.wrap_meta)).toThrow();
});
});
+
+describe('vaultCrypto signing key generation', () => {
+ it('generates a valid, chain-agnostic secp256k1 signing key', () => {
+ const key = generateSigningKey();
+ expect(key.privateKey).toBeInstanceOf(Uint8Array);
+ expect(key.privateKey.length).toBe(32);
+ // Compressed secp256k1 public key: 33 bytes (66 hex), 0x02/0x03 prefix.
+ expect(key.publicKey).toMatch(/^0[23][0-9a-f]{64}$/);
+ // The key works with the supported signing schemes (signDigest copies its
+ // input, so the private key stays usable afterwards).
+ expect(() =>
+ signDigest(key.privateKey, p2.signing.digest_hex, SIGN_SCHEME_ECDSA_SECP256K1_RECOVERABLE),
+ ).not.toThrow();
+ expect(key.privateKey.some((b) => b !== 0)).toBe(true);
+ });
+
+ it('derives the same public key on import as on generation', () => {
+ const key = generateSigningKey();
+ expect(importSigningKey(key.privateKey).publicKey).toBe(key.publicKey);
+ });
+
+ it('imports a known private key deterministically (hex)', () => {
+ const a = importSigningKey(p2.signing.private_key_hex);
+ const b = importSigningKey(p2.signing.private_key_hex);
+ expect(a.publicKey).toBe(b.publicKey);
+ expect(a.publicKey).toMatch(/^0[23][0-9a-f]{64}$/);
+ });
+
+ it('rejects an invalid private key', () => {
+ expect(() => importSigningKey('00'.repeat(32))).toThrow(); // zero scalar
+ expect(() => importSigningKey('zz')).toThrow(); // not hex / wrong length
+ });
+});
diff --git a/ui/src/lib/vaultCrypto.ts b/ui/src/lib/vaultCrypto.ts
index 71240ab5b..aa0fa4580 100644
--- a/ui/src/lib/vaultCrypto.ts
+++ b/ui/src/lib/vaultCrypto.ts
@@ -923,6 +923,32 @@ function normalizeHexOrBytes(value: HexOrBytes, field: string): Uint8Array {
return typeof value === 'string' ? hexToBytes(value) : toUint8Array(value, field);
}
+export type SigningKeyMaterial = {
+ /** Raw 32-byte secp256k1 private key. The caller MUST zero it after sealing. */
+ privateKey: Uint8Array;
+ /**
+ * Compressed secp256k1 public key (33 bytes), hex. A signing key is
+ * chain-agnostic: the signature scheme (ECDSA / Schnorr) is chosen at sign
+ * time, not at creation, so this is the only public material we pin.
+ */
+ publicKey: string;
+};
+
+/** Generate a fresh, chain-agnostic secp256k1 signing key. */
+export function generateSigningKey(): SigningKeyMaterial {
+ const privateKey = secp256k1.utils.randomSecretKey();
+ return { privateKey, publicKey: bytesToHex(secp256k1.getPublicKey(privateKey, true)) };
+}
+
+/**
+ * Validate + load an imported secp256k1 private key (hex or raw bytes) and
+ * derive its compressed public key. Throws if it is not a valid 32-byte key.
+ */
+export function importSigningKey(privateKey: BytesLike | string): SigningKeyMaterial {
+ const key = normalizePrivateKey(privateKey);
+ return { privateKey: key, publicKey: bytesToHex(secp256k1.getPublicKey(key, true)) };
+}
+
function validateSecretName(name: string): string {
if (typeof name !== 'string' || !SECRET_NAME_PATTERN.test(name)) {
throw new Error('vault secret name must match ^[A-Z][A-Z0-9_]*$');