Skip to content

refactor(e2eecrypto): move accountKey wrap/unwrap out of e2eeclient - #321

Merged
attson merged 1 commit into
mainfrom
refactor/move-account-key-crypto
Aug 4, 2026
Merged

refactor(e2eecrypto): move accountKey wrap/unwrap out of e2eeclient#321
attson merged 1 commit into
mainfrom
refactor/move-account-key-crypto

Conversation

@attson

@attson attson commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

Milestone 6-b. Password → wrap_key derivation (Argon2id) + AEAD seal/open of the `account_key` envelope are cryptographic primitives, not HTTP-client concerns. The functions lived inside `internal/e2eeclient/client.go` by history — that package is otherwise the OPAQUE HTTP round-tripper, and it was dragging in `golang.org/x/crypto/argon2` + `chacha20poly1305` for no reason.

Move to `internal/e2eecrypto/accountkey.go`, exported as `WrapAccountKey` / `UnwrapAccountKey`. Consolidates all `account_key` crypto in one package alongside the session-key derivation (HKDF) and frame envelope AEAD that were already there.

Changes:

  • `wrapAccountKey` → `e2eecrypto.WrapAccountKey`
  • `unwrapAccountKey` → `e2eecrypto.UnwrapAccountKey`
  • `KDFParams` + `DefaultKDFParams` + `KDFParams.Marshal` move with them (no consumer outside e2eeclient).
  • AAD constant `atterm-account-key-v1` promoted to a named const so future migrations flip it in one place.
  • Error text `e2eeclient: invalid password` → `e2eecrypto: invalid password`.
  • `e2eeclient/client.go`: drop `argon2` / `chacha20poly1305` imports, drop local functions, import `e2eecrypto` at the two call sites (Register + Login). Package doc-comment updated: the SDK no longer "owns the crypto".
  • Tests: `TestWrapUnwrap_RoundTrip` + `TestUnwrap_WrongPassword` move to `e2eecrypto/accountkey_test.go` (same-package internal test in the new home). `TestClient_*` stay in `e2eeclient`.
  • `e2eecrypto/sessionkey.go` package doc rewritten to describe the 3-file layout (accountkey / sessionkey / envelope).
  • `.gitignore`: add `.claude/` so the local worktree state stays out.

Wire format is unchanged: same `AccountKeyWrap` struct in `opaquesuite`, same Argon2id parameters (64 MiB, t=3, p=1), same AAD string. A wrap envelope written by main can be opened by this branch and vice-versa.

Test plan

  • `go test ./...` green (all packages)
  • Specifically `go test ./internal/e2eecrypto/ ./internal/e2eeclient/` — TestWrapUnwrap_RoundTrip runs in the new home; TestClient_RegisterAndLogin still round-trips against the in-process relay
  • Manual: fresh Register → Login on another device restores the same account_key (round-trip proof)

Password → wrap_key derivation (Argon2id) + AEAD seal/open of the
account_key envelope are cryptographic primitives, not HTTP-client
concerns. The functions lived inside internal/e2eeclient/client.go by
history — that package is otherwise the OPAQUE HTTP round-tripper, and
now drags in golang.org/x/crypto/argon2 + chacha20poly1305 for no
reason.

Move to internal/e2eecrypto/accountkey.go, exported as
`WrapAccountKey` / `UnwrapAccountKey`. Consolidates all account_key
crypto in one package alongside the session-key derivation (HKDF) and
frame envelope AEAD that were already there.

- Renamed `wrapAccountKey` → `e2eecrypto.WrapAccountKey`
- Renamed `unwrapAccountKey` → `e2eecrypto.UnwrapAccountKey`
- `KDFParams` + `DefaultKDFParams` + `KDFParams.Marshal` move with them
  (no consumer outside e2eeclient).
- AAD constant `atterm-account-key-v1` promoted to a named const so
  future migrations flip it in one place.
- Error text `e2eeclient: invalid password` → `e2eecrypto: invalid password`
  (matches the new package location).
- e2eeclient/client.go: drop argon2 / chacha20poly1305 imports, drop the
  local functions, import e2eecrypto at the two call sites (Register +
  Login). Package doc-comment rewrites the "SDK owns the crypto"
  sentence — it doesn't anymore.
- Tests: TestWrapUnwrap_RoundTrip + TestUnwrap_WrongPassword move to
  e2eecrypto/accountkey_test.go (same-package internal test in the new
  home). TestClient_* stay in e2eeclient.
- e2eecrypto/sessionkey.go package doc updated to list the three files
  (accountkey / sessionkey / envelope) and note that e2eeclient now
  imports this package rather than duplicating.

Wire format is unchanged: same AccountKeyWrap struct in opaquesuite,
same Argon2id parameters, same AAD string. `go test ./...` green.
@attson
attson merged commit cc5009a into main Aug 4, 2026
7 checks passed
@attson
attson deleted the refactor/move-account-key-crypto branch August 4, 2026 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant