ProofedMesh/services/approval-service/internal/store/postgres.go

42 lines
1.6 KiB
Go
Raw Permalink Normal View History

approval-service: Phase-1 content-binding approval service (DEV-608) New services/approval-service with the Session → Preview → Confirm pipeline required by DEV-606/DEV-608: * POST /api/v1/sessions starts a Pocket-ID-bound approval session. * POST /api/v1/approvals/preview renders content server-side, computes H_content = sha256(canonical JSON), stores the (nonce, salt, canonical, challenge) tuple and returns the human verification digits plus the WebAuthn challenge = nonce || H_content. * POST /api/v1/approvals/confirm verifies the WebAuthn assertion against the stored challenge, DSSE-signs the Approval statement via the signing-service (key_ref=trust-api/approval-signer-2026-q4), submits to the transparency-log, and returns {approval_id, attestation_ref, log_index}. TLog failures leave the row at attestation-pending for the reconciler. * db/trust/migrations/0004_approval_sessions.{up,down}.sql: new tables approval_sessions, approval_previews, approvals (schema matches the Phase 1 store contract). * internal/content: canonical JSON + H_content + 6-digit verification code (byte-compatible with signing-service/internal/canonical). * internal/webauthn: stdlib-only Phase-1 verifier; wire shape stays WebAuthn-compatible for the Phase-2 swap to go-webauthn/webauthn. * internal/signer, internal/tlog: HTTP clients mapping 5xx / connection errors to typed ErrSignerUnavailable / ErrTLogUnavailable so the HTTP layer can return 502 for signing failures and persist attestation-pending on TLog failure. * internal/service.Orchestrator ties the pipeline together and persists the Approval BEFORE the TLog submit (never return a log_index for an un-persisted approval). Tests cover: happy path, tampered H_content → 400, expired challenge → 403, signer 5xx + conn-refused → 502, TLog failure → row stays attestation-pending, duplicate confirm → 409, session expired → 403. go vet clean, go test ./... passes. Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-25 19:42:06 +00:00
package store
import (
"context"
"errors"
"time"
)
// Postgres is the production Store. **Skeleton** mirroring the pattern used
// by services/admin-api/internal/store/postgres.go: every method returns
// errPGUnimplemented until the pgxpool wiring lands. The schema is
// authoritative in db/trust/migrations/0004_approval_sessions.*.sql.
type Postgres struct {
// pool *pgxpool.Pool // kept out of go.mod in the skeleton
}
var errPGUnimplemented = errors.New("postgres store is a skeleton; use NewMemory for Phase 1")
// NewPostgres returns a zero-value Postgres. Real wiring is Phase 2.
func NewPostgres( /* conn string, logger */ ) (*Postgres, error) {
return &Postgres{}, nil
}
func (p *Postgres) CreateSession(_ context.Context, _ Session) error { return errPGUnimplemented }
func (p *Postgres) GetSession(_ context.Context, _ string) (Session, error) {
return Session{}, errPGUnimplemented
}
func (p *Postgres) SavePreview(_ context.Context, _ Preview) error { return errPGUnimplemented }
func (p *Postgres) GetPreview(_ context.Context, _ string) (Preview, error) {
return Preview{}, errPGUnimplemented
}
func (p *Postgres) ConsumePreview(_ context.Context, _ string, _ time.Time) (Preview, error) {
return Preview{}, errPGUnimplemented
}
func (p *Postgres) SaveApproval(_ context.Context, _ Approval) error { return errPGUnimplemented }
func (p *Postgres) MarkApprovalLogged(_ context.Context, _ string, _ int64, _ time.Time) error {
return errPGUnimplemented
}
func (p *Postgres) MarkApprovalTLogError(_ context.Context, _ string, _ string) error {
return errPGUnimplemented
}