docs(keybase): document keybase guidelines chore: add search summary feat: add package lock file
1.9 KiB
1.9 KiB
Keybase Guidelines (internal/keybase)
Generated: 2026-01-10 | Namespace: internal/keybase
OVERVIEW
Core database layer utilizing SQLite as a "DID CPU" with custom crypto functions and action dispatching.
STRUCTURE
exec.go: Action dispatcher mapping resource/action pairs to Go handlers.functions.go: Registration of custom SQLite functions (mpc_sign,bip44_derive).store.go:Keybasesingleton managing the SQLite connection, mutex, and DID state.actions.go:ActionManagerproviding thread-safe high-level API for database operations.actions_*.go: Resource-specific handlers (accounts, credentials, enclaves, etc.).
WHERE TO LOOK
| Task | Location |
|---|---|
Add new exec action |
exec.go (update handlers map) |
| Implement action logic | actions_<resource>.go |
| Define new SQLite function | functions.go (use conn.CreateFunction) |
| Register SQLite function | functions.go -> RegisterMPCFunctions |
| Database schema/queries | internal/migrations/ (SQLC source) |
CONVENTIONS
- Handler Signature:
func handle<Res><Act>(ctx, am *ActionManager, subject string) (json.RawMessage, error) - Thread Safety: All
ActionManagermethods MUST useam.kb.mu.RLock()(reads) oram.kb.mu.Lock()(writes). - Return Type: Handlers must return
json.RawMessageor an error. Usejson.Marshalfor outputs. - Transactions: Use
am.kb.WithTx(ctx, func(q *Queries) error { ... })for multi-step atomic operations. - Subject Parsing: Parse the
subjectstring in handlers (e.g.,id:dataoraddress).
ANTI-PATTERNS
- Accessing
kb.dborkb.querieswithout holding thekb.mumutex. - Performing heavy crypto operations inside a write lock (blocks all reads/writes).
- Hardcoding SQL strings outside of
internal/migrations/or simpledb.Execupdates. - Returning raw internal structs; always map to
*Resulttypes for JSON output.