Skip to content

feat(stellar): add Stellar account fields and Privy user linking flow#53

Open
libby-coder wants to merge 1 commit into
Chainmove:mainfrom
libby-coder:feat/stellar-account-fields-privy-linking
Open

feat(stellar): add Stellar account fields and Privy user linking flow#53
libby-coder wants to merge 1 commit into
Chainmove:mainfrom
libby-coder:feat/stellar-account-fields-privy-linking

Conversation

@libby-coder

Copy link
Copy Markdown

Summary

  • Fix duplicate stellarPublicKey field in models/User.ts — the schema had two definitions of the same field (one with unique: true, one with index: true). Merged into a single correct definition with unique, sparse, trim, and index all set.
  • Add all four Stellar user fields as optional schema additions: stellarPublicKey, stellarAccountType, stellarLinkedAt, stellarLastSyncedAt. All fields default gracefully so existing users are unaffected with no migration needed.
  • Set stellarLinkedAt on first link in POST /api/auth/stellar/link — the timestamp is recorded when a key is first attached and is never overwritten on subsequent re-links.
  • Extend route tests with two new cases: verifying stellarLinkedAt is set on first link and is preserved (not reset) on re-link.
  • Add docs/auth-stellar.md — documents how Privy auth and Stellar account linking fit together, the security properties of each layer (public-key-only storage, StrKey checksum validation, unique index + 409 race protection), relevant environment variables, and contributor setup instructions.

Files changed

File Change
models/User.ts Remove duplicate stellarPublicKey; keep single definition with unique, sparse, trim, index
app/api/auth/stellar/link/route.ts Set stellarLinkedAt on first link only
app/api/auth/stellar/link/route.test.ts Add tests for stellarLinkedAt first-link and re-link preservation
docs/auth-stellar.md New — Privy + Stellar architecture, security properties, env vars, contributor guide

Acceptance criteria checklist

  • User model supports optional Stellar account fields
  • Existing users continue to work (all fields optional, no migration)
  • Stellar public key validation is applied before saving (StrKey + CRC16 checksum)
  • Privy remains the authentication layer
  • No private key is stored or exposed
  • stellarLinkedAt is recorded on first link
  • Documentation added explaining how Privy auth and Stellar accounts fit together

Closes #27

- Fix duplicate stellarPublicKey field in models/User.ts by removing the
  first definition (which lacked unique/index) and keeping a single correct
  field with unique, sparse, trim, and index options set
- Add stellarAccountType, stellarLinkedAt, and stellarLastSyncedAt fields
  to the User schema; all four Stellar fields are optional so existing
  users are unaffected
- Update POST /api/auth/stellar/link to set stellarLinkedAt on first link
  without overwriting it on subsequent re-links
- Extend route tests to assert stellarLinkedAt is set on first link and
  preserved on re-link
- Add docs/auth-stellar.md documenting how Privy auth and Stellar account
  linking fit together, including the security properties of each layer

Closes Chainmove#27
@Obiajulu-gif

Copy link
Copy Markdown
Collaborator

@libby-coder great work sir, can you fix the lint error

@libby-coder

Copy link
Copy Markdown
Author

@libby-coder great work sir, can you fix the lint error

The typecheck CI failure is not caused by changes in this PR. The four files I modified are:

models/User.ts
app/api/auth/stellar/link/route.ts
app/api/auth/stellar/link/route.test.ts
docs/auth-stellar.md

Every error reported by tsc --noEmit is in unrelated files (app/dashboard/admin/loans/page.tsx, components/ui/chart.tsx, components/providers.tsx, components/dashboard/advanced-analytics.tsx, etc.) that this PR does not touch. These errors exist on main and pre-date this branch — verifiable with git diff main...HEAD --name-only.

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.

[STELLAR] Add Stellar account fields and Privy user linking flow

2 participants