Skip to content

fix(server): initialize genesis repo when creating an account with an existing did - #122

Open
edmundedgar wants to merge 1 commit into
haileyok:mainfrom
edmundedgar:fix/init-repo-for-existing-did-signup-minimal-diff
Open

fix(server): initialize genesis repo when creating an account with an existing did#122
edmundedgar wants to merge 1 commit into
haileyok:mainfrom
edmundedgar:fix/init-repo-for-existing-did-signup-minimal-diff

Conversation

@edmundedgar

Copy link
Copy Markdown

What

A new account needs initialization with a genesis repo commit before you can write to it. This was correctly done when the PDS creates the account along with a brand new DID, and also when you imported an account from another PDS. However, if you created the DID for a new account yourself, then called createAccount, rev/root would stay ""/NULL forever.

Motivation

I want to do this as part of a flow where you create a fully self-custodial account on the client side and the only rotation key in the history is custodied by the user, never the PDS.

How it works

The commit-and-record logic that used to run only inside if request.Did == nil is extracted into initializeGenesisRepo and now called unconditionally. This shouldn't affect importRepo which unconditionally overwrites root/rev from the uploaded CAR regardless of prior state, so an empty genesis commit doesn't conflict with a later import.

Surface

  • server/handle_server_create_account.go: new initializeGenesisRepo(ctx, did, signingKey) (cid.Cid, string, error), handleCreateAccount calls it unconditionally instead of only when request.Did == nil.
  • server/handle_server_create_account_test.go: new test.

Tests

TestCreateAccountInitializesRepoForExistingDID creates an account via the existing-DID path and asserts rev/root are populated and both #identity and #sync events are recorded. Confirmed it catches the bug: temporarily restored the old if request.Did == nil gate, watched it fail, reverted.

go vet ./... and go test -race ./... pass; gofmt -l . is clean.

handleCreateAccount only committed an empty MST and announced the new
identity (#identity, #sync) inside `if request.Did == nil`, i.e. only
when cocoon minted the DID itself. Accounts created by passing an
existing DID (the self-custodied-rotation-key flow: mint your own
did:plc, then create the account against it with a service-auth JWT)
got a Repo/Actor row but no commit — rev stayed "" and root stayed
NULL forever, since nothing else ever initializes it. Any subsequent
write (e.g. creating a post) failed with an "invalid cid" error trying
to build on a nonexistent repo state, and the account was never
announced via #identity/#sync on the firehose (only #account, later,
from activateAccount) — see the defensive `if len(urepo.Repo.Root) > 0`
guard already in handleServerActivateAccount before it emits #sync,
which was silently no-op'ing for exactly this reason.

Extracted the commit-and-record logic into initializeGenesisRepo and
call it unconditionally for every new account rather than only when
cocoon minted the DID. Confirmed safe with respect to the repo-import
flow: handleRepoImportRepo unconditionally overwrites root/rev from
the uploaded CAR regardless of prior state, so an empty genesis commit
doesn't conflict with a later importRepo call.

Test (server/handle_server_create_account_test.go):
- TestCreateAccountInitializesRepoForExistingDID — creates an account
  via the existing-DID path (mints a k256 key, seeds a passport cache
  with a matching DID doc so validateServiceAuth resolves it without a
  network call, signs a service-auth JWT, POSTs createAccount), then
  asserts rev/root are populated and both #identity and #sync are in
  event_records for the DID. Confirmed this test is actually catching
  the bug: temporarily re-added the old `if request.Did == nil` gate
  around just the initializeGenesisRepo call, watched the test fail
  with "repo has no rev after account creation via the existing-DID
  flow", then reverted.

go vet ./... and go test -race ./... pass; gofmt -l . is clean.

@haileyok haileyok left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

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.

2 participants