Tenth plugin out, and the one whose extraction turned on a permission decision rather than a mechanical move. The wallet permission was kind: 'admin' — owner only, not grantable, invisible to every other account. Plugin permissions are ALWAYS kind: 'app': mount.ts forces it and the manifest has no field for anything else, deliberately, so that "can a plugin escalate itself" is a question which cannot be asked. So extraction could not preserve admin, and that was raised as a blocker before any code moved. It was the right change anyway, and the objection inverts. Every wallet query is scoped by user_id, and that id comes from X-Officer-User which the platform injects from the authenticated session — a caller cannot name someone else's. So granting this gives an account ITS OWN wallet. Not through the API and not with root either does it hand over anyone else's, because their seed is sealed under a passphrase the server never stores. kind: 'admin' was single-user thinking; grantable is how a second person gets a wallet at all. Named bitcoin-wallet rather than wallet: it is a bitcoin wallet specifically, and the appName drives the route, the API prefix, the table prefix and the install key together. Tables renamed to bitcoin_wallet_* accordingly — the prefix guard normalises the hyphen. Free only because no wallet table existed on any server, which was checked before deciding: db:push treats a rename as a drop plus a create. The three custody test files moved with it and still run — 72 tests over scrypt sealing, envelope open and bolt11. bunfig.toml's test root was widened on 2026-08-15 after music took lyrics.test.ts and the suite silently shrank by nine, so that trap was already closed. 68 palette classes converted, five status vocabularies hoisted into shared.ts. Two deliberate flattenings recorded in PLUGIN.md: testnet/signet/regtest all read as warning, and the bitcoin and lightning rails no longer differ by hue. Deferred on purpose: watch-only data (xpubs, balances, history) stays unencrypted so a locked wallet still shows a balance. Anyone with the database can therefore SEE any user's balances; they can never move a coin.
120 lines
4.3 KiB
TypeScript
120 lines
4.3 KiB
TypeScript
import type { WalletSummary } from '../shared';
|
|
import { useState } from 'react';
|
|
import { Loader2, TriangleAlert } from 'lucide-react';
|
|
import { Button } from '@/components/ui/button';
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from '@/components/ui/dialog';
|
|
import { Input } from '@/components/ui/input';
|
|
import { Label } from '@/components/ui/label';
|
|
import { useWalletLifecycle } from '../useWalletData';
|
|
|
|
// Delete a wallet. For a seeded wallet this destroys the only copy of the key material Officer holds, so
|
|
// the sidecar demands the passphrase even when the wallet is currently unlocked — an open session must not
|
|
// be enough to erase a seed. Typing the wallet's name is the second check against the wrong row, and it is
|
|
// sent rather than merely enforced here: a wallet with no seed has no passphrase gate, so without it the
|
|
// only thing standing between a node wallet and deletion was a dialog anything could route around.
|
|
|
|
type DeleteWalletDialogProps = {
|
|
open: boolean;
|
|
onOpenChange: (open: boolean) => void;
|
|
wallet: WalletSummary;
|
|
onDeleted?: () => void;
|
|
};
|
|
|
|
export const DeleteWalletDialog = ({ open, onOpenChange, wallet, onDeleted }: DeleteWalletDialogProps) => {
|
|
const { remove } = useWalletLifecycle();
|
|
// Never persisted: no localStorage, no sessionStorage, no React Query cache, no URL.
|
|
const [passphrase, setPassphrase] = useState('');
|
|
const [confirmName, setConfirmName] = useState('');
|
|
|
|
const close = () => {
|
|
setPassphrase('');
|
|
setConfirmName('');
|
|
onOpenChange(false);
|
|
};
|
|
|
|
const nameMatches = confirmName.trim() === wallet.name;
|
|
const canSubmit = nameMatches && (!wallet.hasSeed || !!passphrase) && !remove.isPending;
|
|
|
|
const submit = async (ev: React.FormEvent) => {
|
|
ev.preventDefault();
|
|
if (!canSubmit) return;
|
|
try {
|
|
await remove.mutateAsync({
|
|
walletId: wallet.id,
|
|
confirmName: confirmName.trim(),
|
|
passphrase: wallet.hasSeed ? passphrase : undefined,
|
|
});
|
|
close();
|
|
onDeleted?.();
|
|
} finally {
|
|
setPassphrase('');
|
|
}
|
|
};
|
|
|
|
return (
|
|
<Dialog open={open} onOpenChange={(next) => (next ? onOpenChange(true) : close())}>
|
|
<DialogContent className="max-w-md">
|
|
<form onSubmit={submit}>
|
|
<DialogHeader>
|
|
<DialogTitle className="flex items-center gap-2">
|
|
<TriangleAlert className="h-5 w-5 text-destructive" />
|
|
Delete {wallet.name}
|
|
</DialogTitle>
|
|
<DialogDescription>
|
|
{wallet.hasSeed
|
|
? 'This erases the encrypted seed. Without your written-down recovery phrase the coins are gone for good.'
|
|
: 'This removes the connection to that node. Nothing on the node itself is touched.'}
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
|
|
<div className="mt-4 space-y-4">
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="wallet-delete-name">
|
|
Type <span className="font-mono">{wallet.name}</span> to confirm
|
|
</Label>
|
|
<Input
|
|
id="wallet-delete-name"
|
|
autoFocus
|
|
autoComplete="off"
|
|
value={confirmName}
|
|
onChange={(ev) => setConfirmName(ev.target.value)}
|
|
/>
|
|
</div>
|
|
|
|
{wallet.hasSeed && (
|
|
<div className="space-y-1.5">
|
|
<Label htmlFor="wallet-delete-pass">Passphrase</Label>
|
|
{/* Controlled input → request body → cleared. Never written to any store. */}
|
|
<Input
|
|
id="wallet-delete-pass"
|
|
type="password"
|
|
autoComplete="off"
|
|
value={passphrase}
|
|
onChange={(ev) => setPassphrase(ev.target.value)}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<DialogFooter className="mt-6">
|
|
<Button type="button" variant="ghost" onClick={close}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" variant="destructive" disabled={!canSubmit}>
|
|
{remove.isPending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
|
|
Delete wallet
|
|
</Button>
|
|
</DialogFooter>
|
|
</form>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
};
|