task/29: Timmy as economic peer — Nostr identity, zap-out, vouching, engagement engine #47

Closed
replit wants to merge 0 commits from task/29-timmy-economic-peer into main
Owner

Timmy as Economic Peer — Task #29

What was built

  1. TimmyIdentityService (artifacts/api-server/src/lib/timmy-identity.ts)

    • Persistent secp256k1 Nostr keypair via TIMMY_NOSTR_NSEC env var (bech32 nsec)
    • Ephemeral keygen with operator warning if env var absent
    • sign(EventTemplate) → NIP-01 finalizeEvent with Timmy's key
    • encryptDm(recipientPubkeyHex, plaintext) → NIP-04 encrypted content
    • npub logged at server startup for operator visibility
  2. ZapService (artifacts/api-server/src/lib/zap.ts)

    • Constructs NIP-57 zap request events (kind 9734) signed with Timmy's key
    • Pays via lnbitsService.payInvoice() (stub-mode aware)
    • Logs all outbound events to timmy_nostr_events audit table
    • maybeZapOnJobComplete() wired in jobs.ts after trust scoring
    • Config: ZAP_PCT_DEFAULT (default 0 = disabled), ZAP_MIN_SATS (default 10)
    • Only fires for trusted/elite tier when ZAP_PCT_DEFAULT > 0
  3. EngagementService (artifacts/api-server/src/lib/engagement.ts)

    • Configurable cadence: ENGAGEMENT_INTERVAL_DAYS (default 0 = disabled)
    • Queries trusted partners (score ≥ 50) absent for ENGAGEMENT_ABSENT_DAYS days
    • Generates personalised DM via agentService.chatReply()
    • Encrypts as NIP-04 DM (kind 4), signs with Timmy's key
    • Logs to timmy_nostr_events; publishes to NOSTR_RELAY_URL if set
  4. Vouching endpoint (POST /api/identity/vouch)

    • Elite-tier X-Nostr-Token required
    • Optional voucher Nostr event signature verification
    • Records in nostr_trust_vouches table
    • Applies 20-point trust boost to vouchee
  5. Timmy identity endpoint (GET /api/identity/timmy)

    • Public: returns Timmy's npub, pubkeyHex, and live zap count
  6. DB schema — two new tables pushed to production:

    • timmy_nostr_events (audit log for all outbound Nostr events)
    • nostr_trust_vouches (voucher/vouchee social graph)
  7. Frontend identity card (the-matrix/)

    • #timmy-id-card widget: bottom-right, shows shortened npub + zap count
    • Click-to-copy npub; refreshes every 60s

Config env vars added

Var Default Purpose
TIMMY_NOSTR_NSEC (ephemeral) Timmy's persistent Nostr secret key
ZAP_PCT_DEFAULT 0 % of work fee to zap back (0 = disabled)
ZAP_MIN_SATS 10 Minimum sats to trigger a zap
ENGAGEMENT_INTERVAL_DAYS 0 Proactive DM cadence (0 = disabled)
ENGAGEMENT_ABSENT_DAYS 7 Absence threshold before sending DM
NOSTR_RELAY_URL (none) Relay to publish outbound events to

Closes #34

## Timmy as Economic Peer — Task #29 ### What was built 1. **TimmyIdentityService** (`artifacts/api-server/src/lib/timmy-identity.ts`) - Persistent secp256k1 Nostr keypair via `TIMMY_NOSTR_NSEC` env var (bech32 nsec) - Ephemeral keygen with operator warning if env var absent - `sign(EventTemplate)` → NIP-01 finalizeEvent with Timmy's key - `encryptDm(recipientPubkeyHex, plaintext)` → NIP-04 encrypted content - npub logged at server startup for operator visibility 2. **ZapService** (`artifacts/api-server/src/lib/zap.ts`) - Constructs NIP-57 zap request events (kind 9734) signed with Timmy's key - Pays via `lnbitsService.payInvoice()` (stub-mode aware) - Logs all outbound events to `timmy_nostr_events` audit table - `maybeZapOnJobComplete()` wired in jobs.ts after trust scoring - Config: `ZAP_PCT_DEFAULT` (default 0 = disabled), `ZAP_MIN_SATS` (default 10) - Only fires for trusted/elite tier when `ZAP_PCT_DEFAULT > 0` 3. **EngagementService** (`artifacts/api-server/src/lib/engagement.ts`) - Configurable cadence: `ENGAGEMENT_INTERVAL_DAYS` (default 0 = disabled) - Queries trusted partners (score ≥ 50) absent for `ENGAGEMENT_ABSENT_DAYS` days - Generates personalised DM via `agentService.chatReply()` - Encrypts as NIP-04 DM (kind 4), signs with Timmy's key - Logs to `timmy_nostr_events`; publishes to `NOSTR_RELAY_URL` if set 4. **Vouching endpoint** (`POST /api/identity/vouch`) - Elite-tier X-Nostr-Token required - Optional voucher Nostr event signature verification - Records in `nostr_trust_vouches` table - Applies 20-point trust boost to vouchee 5. **Timmy identity endpoint** (`GET /api/identity/timmy`) - Public: returns Timmy's npub, pubkeyHex, and live zap count 6. **DB schema** — two new tables pushed to production: - `timmy_nostr_events` (audit log for all outbound Nostr events) - `nostr_trust_vouches` (voucher/vouchee social graph) 7. **Frontend identity card** (`the-matrix/`) - `#timmy-id-card` widget: bottom-right, shows shortened npub + zap count - Click-to-copy npub; refreshes every 60s ### Config env vars added | Var | Default | Purpose | |-----|---------|---------| | `TIMMY_NOSTR_NSEC` | (ephemeral) | Timmy's persistent Nostr secret key | | `ZAP_PCT_DEFAULT` | 0 | % of work fee to zap back (0 = disabled) | | `ZAP_MIN_SATS` | 10 | Minimum sats to trigger a zap | | `ENGAGEMENT_INTERVAL_DAYS` | 0 | Proactive DM cadence (0 = disabled) | | `ENGAGEMENT_ABSENT_DAYS` | 7 | Absence threshold before sending DM | | `NOSTR_RELAY_URL` | (none) | Relay to publish outbound events to | Closes #34
Author
Owner

Merged directly to main — task-29 was committed and pushed to main as a squash commit (eb5dcfd). This PR documents the changes; the branch is identical to main HEAD.

✅ **Merged directly to main** — task-29 was committed and pushed to `main` as a squash commit (`eb5dcfd`). This PR documents the changes; the branch is identical to `main` HEAD.
replit closed this pull request 2026-03-19 19:31:25 +00:00
This repo is archived. You cannot comment on pull requests.