Commit Graph
4 Commits
Author SHA1 Message Date
CatoandClaude Opus 5 c5ff39bf04 chore(identity): one name — Cato (#894)
* chore(identity): one name — Cato

The retired name and a personal contact address were still in the repo,
including in the documents where a name is load-bearing.

- "Mao Nakamoto" -> "Cato" across 18 files: README, CLAUDE.md, two blog posts,
  config, support page, tests, and legal/ (PRIVACY_POLICY, TERMS_OF_SERVICE,
  IP_ASSIGNMENT_MEMO plus the legal-content.ts that renders them).
- mao@orangecat.ch -> hello@orangecat.ch in 12 files. The old address is the
  GDPR Data Controller contact and the ToS operator contact, so it could not
  simply be deleted; hello@ is already published on the public FAQ, which
  makes it a route known to work rather than a guess. A role address is also
  the better answer here than any personal one.
- Test fixtures using a real first name -> Cato.

**Deliberately NOT swept: the legacy handles `butaeff` and `georgy.butaev`.**
A first pass replaced them and had to be reverted. They are production data,
not name mentions: `.mailmap` uses them to map historical commits onto the
canonical identity, and the mention/lnurl tests carry comments stating those
handles are real rows. Renaming the references does not rename the rows — it
points code at handles that do not exist and turns true comments into false
ones. Retiring them is a data migration, not a find-and-replace.

Also reverted from that first pass: an edit to an applied migration's comment.
Migrations are immutable once applied, and rewriting a bug report to name a
handle that was never involved would have falsified the record. The example in
username-history.ts is now a neutral `legacy+handle` instead.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2LBioUzJP4oBL9LeH9qAe

* chore(identity): the mailmap was rewriting Cato back into the retired name

Missed by the sweep in the previous commit, which globbed *.md/*.mdx/*.ts/*.tsx
— and .mailmap has no extension.

The effect was worse than a stale file. The raw commit author was already
correct after the git config fix, and the mailmap converted it back on display:

    raw:        Cato <41178744+catomean@users.noreply.github.com>
    mailmapped: Mao Nakamoto <41178744+catomean@users.noreply.github.com>

Every new commit would have kept arriving as Cato and kept being shown as the
old name, which is the least debuggable version of this problem — the config is
right, the commit is right, and the output is wrong.

Canonical name is now Cato, and a name+email rule was added for commits
authored as "G": those carry the canonical email already, so the email-only
rules cannot reach them.

Verified over the last 400 commits: 322 Cato, 78 dependabot, nothing else.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2LBioUzJP4oBL9LeH9qAe

* fix(identity): the rename notice legitimately names the OLD handle

CI caught the sweep breaking a correct test, in exactly the way the butaeff
handles would have been broken had they not been reverted.

services/cat/handlers/context.ts builds the notice as

    `…and ${oldUsername}@orangecat.ch still reaches you.`

The address is derived from the handle the user is renaming AWAY from — that is
the whole point of the sentence, which promises their old Lightning address
keeps working. The sweep rewrote the test's expectation to hello@ and left the
source producing the old-handle address, so a correct implementation began
failing a now-incorrect assertion.

Fixed by neutralising the fixture rather than the assertion: the old handle is
now 'oldhandle', so the test asserts oldhandle@orangecat.ch and no retired name
appears. The behaviour under test is unchanged.

The rule this keeps proving: a literal that REFERS to the old identity is data,
not a stale reference, and a find-and-replace cannot tell the two apart.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G2LBioUzJP4oBL9LeH9qAe

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-06 20:35:25 +00:00
d08c182994 fix(wallets): an extended public key is not an address — stop publishing it (#743)
`GET /api/wallets?profile_id=<any>` served `address_or_xpub` to anonymous
callers through the admin client. One active wallet on production had a real
111-character zpub in that column, and it was readable without logging in — I
read it from the live site before fixing this.

A zpub is not an address. It is the key addresses are derived FROM, so
publishing one hands a visitor every past and future receiving address of that
wallet and its entire balance history, forever and irrevocably. On a platform
whose first principle is "pseudonymous by default", that is the whole game. It
also negates the feature it came from: users supply a zpub so the payments
domain can derive a FRESH address per invoice (#519) precisely to avoid address
reuse — and then the profile published the master key beside it.

The payments domain already held the right invariant; walletResolutionService
says an extended key "must never be handed to a payer verbatim". The public
wallet listing was the one surface that disagreed, and it is the only non-owner
read path for that column, so redacting there closes the class.

Redaction classifies by VALUE, not by the `wallet_type` label — a key pasted
into a row the user typed 'onchain' is still a key. Plain addresses pass through
untouched; withholding those would break the one thing the public list is for.
The public card for a withheld key now says "A fresh address is generated when
you pay" instead of falling through to the connection branch and claiming a
Bitcoin wallet "Receives Lightning payments".

Verified against the real leaking wallet: production returns the 111-char zpub
to an anonymous caller, this build returns null. Both branches proven on one
wallet — owner keeps the key intact, anonymous gets null, the wallet still lists
so payers know it exists. The temporary wallet used for that test was deleted.

Finding 6 of #563. npm run verify: exit 0 — tsc clean, lint 0 errors,
224 suites / 2244 tests.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-24 21:29:33 +00:00
Georgy ButaevandClaude Opus 4.7 cc76194fd6 feat(crypto): encrypt webhook_endpoints secrets at rest (phase 1 of 2)
The PHASE-2 debt the user explicitly chose 30+ commits ago in
2755a8a5 ("plaintext for now, encrypt later"). Webhook signing secrets
are needed at fire time (the worker must sign each delivery), so they
have to live somewhere — but a DB compromise should NOT reveal them.

This commit lands the encryption infrastructure and starts dual-write.
Commit 2 of 2 will backfill secret_encrypted (no-op today: prod has
zero webhook_endpoints rows), flip getEndpointSigningContext to
decrypt, drop secret_plaintext.

Cipher (src/lib/crypto/webhookSecretCipher.ts):
  AES-256-GCM with WEBHOOK_SECRET_KEY env var (32-byte hex). Ciphertext
  layout: IV(12B) || GCM tag(16B) || ciphertext. Authenticated — a
  flipped byte anywhere in the blob throws on decrypt, so a DB
  compromise can't return a forged secret to the worker (only DoS by
  deleting rows). loadKey() validates the env var at first use and
  caches the parsed key; resetCachedKey() is test-only.

Schema (migration 20260604000003, applied to remote):
  ALTER webhook_endpoints ADD COLUMN secret_encrypted BYTEA.
  Service dual-writes; reads still come from secret_plaintext so the
  worker keeps signing deliveries unchanged.

Service (webhookEndpointsService.createWebhookEndpoint):
  Dual-writes secret_plaintext + secret_encrypted on mint. If
  encryptWebhookSecret throws (env var missing/malformed), the mint
  fails — we never store a row that phase 2 can't decrypt.

Deploy checklist: new step 9 (WEBHOOK_SECRET_KEY env var) with
generation command, verification (mint a webhook endpoint and watch
for 500), rollback warning (rotating the key requires re-encryption,
mention of incident-response posture).

Tests (16):
  loadKey: cache, missing env, empty env, non-hex, wrong length
  round-trip: exact equality, len-1, 4KB, unicode, IV-randomness,
    blob layout assertion (12+16+len(plaintext))
  tampering: flipped ciphertext / IV / tag byte, truncated blob,
    wrong key → all throw

Suite: 55 suites · 717 tests · 0 failures (+1 suite, +16 tests).
tsc + eslint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-04 04:03:38 +02:00
Georgy ButaevandClaude Opus 4.7 e2dc220eb9 feat(integration-keys): per-key scopes with server-side enforcement
Today every integration key has full authority over its bound actor's
entities — a leaked product-only key can still fund-grab. This commit
lands least-privilege scopes end-to-end on the server. UI for picking
scopes at mint time is a follow-up; existing keys + new keys without
explicit scopes default to ['*'] (wildcard) for back-compat.

Schema (20260604000001, applied to remote):
  ALTER integration_keys ADD COLUMN scopes TEXT[] NOT NULL DEFAULT '{*}'
  Token format '<entity>.<read|write>' (e.g. 'products.write').

Service:
  - createIntegrationKey gains optional `scopes` param; empty/missing
    stores ['*'].
  - verifyIntegrationKey returns scopes alongside userId/actorId/keyId.
  - listIntegrationKeys returns them too (via the new KEY_PUBLIC_COLUMNS
    constant, deduped across mint/list selects).
  - rotateIntegrationKey preserves the source scopes — rotation is a
    pure "new secret, same authority" operation.

Middleware:
  - ResolvedRequestAuth.scopes — session auth always ['*'], integration
    key inherits the stored array (defaulting to ['*']).
  - hasScope(authScopes, required) — wildcard '*' passes anything;
    otherwise exact-token match. No prefix expansion ('products.*' is
    NOT treated as a wildcard) to keep the rule trivially auditable.

Enforcement:
  - entityPostHandler runs the scope check BEFORE idempotency claim +
    rate limit so a forbidden request can't burn a slot or quota.
  - entityListHandler enforces on integration-key auth only; anonymous
    public reads continue to pass through.
  - Both return 403 with a human-readable "this key is not allowed to
    <verb> <entity>" message.

POST /api/integration-keys now accepts an optional `scopes` array;
curl-mintable today, UI follow-up next.

Tests:
  - 6 new contract tests on hasScope: wildcard, exact match, denial,
    empty allowlist, no prefix expansion, mixed wildcard precedence.

47 suites · 610 tests · 0 failures. tsc + eslint clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-04 00:27:12 +02:00