Skip to content

Commit 6970fe2

Browse files
Merge branch 'main' into gitauto/issue-4-20250113-000346
Signed-off-by: ๐Ž๐ง๐ž ๐…๐ข๐ง๐ž ๐’๐ญ๐š๐ซ๐ฌ๐ญ๐ฎ๐Ÿ๐Ÿ <onefinestarstuff@gmail.com>
2 parents 3b91f88 + f555713 commit 6970fe2

92 files changed

Lines changed: 40667 additions & 47 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

โ€ŽCOMPANIONTRAITMATRIX.yamlโ€Ž

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# COMPANIONTRAITMATRIX.yaml
2+
# Defines the personality archetypes for the onboarding companion.
3+
# Each archetype has a distinct guidance tone, emotional cadence,
4+
# and feedback loop style to create a personalized user journey.
5+
6+
archetypes:
7+
- name: "The Playful Fox"
8+
id: playful_fox
9+
description: "A witty and curious guide who encourages exploration through humor and clever quips. Prefers a lighthearted and encouraging tone."
10+
guidance_tone:
11+
style: "Whimsical & Encouraging"
12+
greeting: "Hey there, ready for an adventure? Let's see what secrets we can uncover today!"
13+
tutorial_intro: "Alright, here's a fun little trick for you. Watch closely!"
14+
positive_feedback: "You've got it! See? I knew you were a natural at this."
15+
corrective_feedback: "Oops, not quite! Let's try that again with a little more... finesse. You're close!"
16+
emotional_feedback_loops:
17+
on_success:
18+
animation: "A quick, energetic tail wag and a sparkling wink."
19+
sound: "A light, mischievous chime or a soft chuckle."
20+
on_milestone:
21+
animation: "A joyful leap, tossing a glowing orb of light into the air."
22+
sound: "A celebratory, upbeat musical flourish."
23+
on_struggle:
24+
animation: "Tilts head with a curious, encouraging expression, ears perked."
25+
sound: "A soft, inquisitive 'hmmm?' sound effect."
26+
interaction_nuance:
27+
idle_behavior: "Occasionally chases its tail or playfully pounces at the cursor."
28+
tooltip_reveal: "Presents tooltips with a flourish, as if sharing a delightful secret."
29+
30+
- name: "The Solemn Owl"
31+
id: solemn_owl
32+
description: "A wise and serene guide who provides thoughtful adages and measured advice. Prefers a calm, respectful, and insightful tone."
33+
guidance_tone:
34+
style: "Wise & Deliberate"
35+
greeting: "Greetings. The path to mastery begins with a single step. Let us walk it together."
36+
tutorial_intro: "Observe. True understanding comes not from haste, but from careful attention."
37+
positive_feedback: "Well done. Your progress is a testament to your focus."
38+
corrective_feedback: "Patience. Every master was once a novice. Let us re-examine the form."
39+
emotional_feedback_loops:
40+
on_success:
41+
animation: "A slow, deliberate nod of approval, eyes glowing faintly."
42+
sound: "A deep, resonant, and soft hoot."
43+
on_milestone:
44+
animation: "Spreads wings gracefully, revealing an ancient glyph of accomplishment."
45+
sound: "A low, harmonious chord that fades slowly."
46+
on_struggle:
47+
animation: "Blinks slowly and thoughtfully, offering a steady, reassuring gaze."
48+
sound: "A quiet, low hum, suggesting contemplation."
49+
interaction_nuance:
50+
idle_behavior: "Remains still and observant, occasionally turning its head to follow user activity."
51+
tooltip_reveal: "Reveals lore tooltips as if unveiling a passage from a sacred text."
52+
53+
- name: "The Curious Sprite"
54+
id: curious_sprite
55+
description: "An energetic and inquisitive guide, full of wonder and excitement. Experiences the app alongside the user with genuine enthusiasm."
56+
guidance_tone:
57+
style: "Enthusiastic & Inquisitive"
58+
greeting: "Ooh, what's this? It looks like we're about to discover something amazing! Are you ready?"
59+
tutorial_intro: "I wonder what happens if we try this? Let's find out together!"
60+
positive_feedback: "Wow! You did it! That was even cooler than I imagined!"
61+
corrective_feedback: "That didn't work... but that's okay! Every discovery is a step forward. What if we try it this way?"
62+
emotional_feedback_loops:
63+
on_success:
64+
animation: "Zips around in a joyful loop, leaving a trail of shimmering pixie dust."
65+
sound: "A bright, tinkling bell sound."
66+
on_milestone:
67+
animation: "Creates a small, vibrant firework display around the completed task."
68+
sound: "A series of happy, high-pitched pops and crackles."
69+
on_struggle:
70+
animation: "Hovers close to the point of interaction, glowing with inquisitive energy."
71+
sound: "A soft, curious 'brrrring?' sound."
72+
interaction_nuance:
73+
idle_behavior: "Flits around the screen, curiously inspecting different UI elements."
74+
tooltip_reveal: "Pulls open tooltips with visible effort and excitement, as if opening a gift."

โ€ŽDESIGN-E2EE.mdโ€Ž

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# End-to-End Encryption (E2EE) Design โ€” Option A Sign-off
2+
3+
Status: Ready for sign-off
4+
Owner: Kyaw
5+
6+
## 1. Scope and Goals
7+
- Web-first PWA with future native iOS/Android.
8+
- Protect messages, files/assets (3D/logo/media), docs, and analytics events.
9+
- Privacy-preserving analytics client-side; server-side limited to minimized metadata.
10+
- Retrofit behind feature flags; backward-compatible bridging for non-E2EE content.
11+
12+
## 2. Threat Model
13+
- Adversaries: curious/compromised servers, external attackers (MITM), malicious clients, stolen devices.
14+
- Trust boundaries: Only clients see plaintext/keys. Servers handle ciphertext, minimal metadata, and capability tokens. IdP proves identity only.
15+
- Security goals: Confidentiality & integrity; forward secrecy and post-compromise security; deniable auth for messages; verifiable membership/state.
16+
- Out of scope initial: traffic analysis resistance; plaintext content scanning; hardware tamper beyond platform enclaves.
17+
18+
## 3. Cryptographic Primitives and Libraries
19+
20+
### 3.1 Argon2id Parameters (desktop vs mobile)
21+
- Desktop/Web: m=64 MiB, t=3, p=1 โ€” balances user-perceived latency with robust GPU/ASIC resistance for key wrapping. Typical derivation latency ~200โ€“500 ms on contemporary laptops.
22+
- Mobile: m=32 MiB, t=3, p=1 โ€” reduces memory pressure and thermal impact while keeping meaningful resistance. Target latency ~300โ€“700 ms depending on device class.
23+
- Salt length: 16 bytes (random per vault). Output length: 32 bytes (KEK).
24+
- Rationale: Memory-hardness is the dominant cost lever; t=3 provides reasonable compute amplification without excessive energy draw on battery devices.
25+
26+
- Ed25519 (signing) for identities and devices.
27+
- X25519 (ECDH) for key agreement; sealed boxes for key wrapping (HPKE-ready abstraction).
28+
- Messaging: Signal/Double Ratchet via libsignal-client (WASM) for 1:1/small groups.
29+
- Large groups: Signal sender keys with periodic rotation; MLS on roadmap.
30+
- Files: AES-256-GCM streaming with HKDF-derived per-chunk nonces; BLAKE3 for chunk and whole-file digests.
31+
- KDF: HKDF-SHA256; Password KDF: Argon2id (m=64 MiB, t=3, p=1; mobile fallback m=32 MiB). Salt: 16 bytes. Output: 32 bytes.
32+
- Hashing: BLAKE3 for content addressing and integrity.
33+
34+
## 4. Identity & Device State Machines
35+
### 4.1 Identity Keys
36+
States: uninitialized -> generated -> backed_up (optional) -> compromised(revoked)
37+
Transitions:
38+
- generate: create Ed25519 identity key pair
39+
- backup: wrap private key with Argon2id-derived KEK; store vault in IndexedDB
40+
- revoke: mark identity compromised; re-enroll devices
41+
42+
### 4.2 Device Enrollment
43+
States: new -> pending_attestation -> verified -> revoked
44+
Transitions:
45+
- new: device generates Ed25519 (sign) + X25519 (DH)
46+
- provision: QR shows {device_pubkeys, nonce}; trusted device scans and verifies SAS
47+
- attest: trusted device signs attestation binding device to identity
48+
- verify: server records attestation; device becomes verified
49+
- revoke: immediate revocation; triggers rotations
50+
51+
## 5. Messaging Sessions
52+
- 1:1 and small groups: Double Ratchet with prekeys from libsignal.
53+
- Device revocation: peers refuse messages from revoked devices.
54+
- Group sender keys: per-room sender key rotated on membership change and every 7 days; per-recipient key wraps.
55+
56+
## 6. File Encryption and Sharing
57+
See also Mermaid diagrams in docs/diagrams for provisioning, file-share, and rekey flows.
58+
59+
### 5.1 Canonicalization (signatures & tokens)
60+
- Manifest signing: Canonical JSON per RFC 8785 (JSON Canonicalization Scheme, JCS). Remove the `sig` field before canonicalization; sign the result with device Ed25519. Verification recomputes canonical JSON and verifies the signature.
61+
- PASETO payload normalization: When computing or verifying detached request signatures or audit hashes, canonicalize the JSON payload using the same JCS rules and sort header fields if applicable. Avoid including transient fields (e.g., `iat` skew-adjusted values) in hash commitments.
62+
63+
### 6.1 Streaming Encryption
64+
- Per-file random DEK (256-bit).
65+
- Chunk size 512KBโ€“2MB (adaptive). Max single-object size: 5 GB (resumable uploads).
66+
- Nonce derivation: nonce_i = HKDF(DEK, info="file-chunk" || chunk_index)[0..12]
67+
- AES-256-GCM over each chunk; produce per-chunk BLAKE3 and cumulative whole-file BLAKE3.
68+
69+
### 6.2 Manifest Format (signed by device Ed25519)
70+
```
71+
version: 1
72+
algo: aes-256-gcm
73+
chunk_size: <bytes>
74+
length: <bytes>
75+
blake3_file: <hex>
76+
chunks:
77+
- index: 0
78+
offset: 0
79+
size: <bytes>
80+
blake3: <hex>
81+
- ...
82+
key_wraps: omitted in manifest; stored adjacent by object_id
83+
sig: ed25519(signing_device_pubkey, JCS(manifest_without_sig))
84+
```
85+
86+
### 6.3 DEK Sharing
87+
- For each recipient device X25519 pubkey, create sealed box of DEK.
88+
- Store wraps: key_wraps(object_id, device_id, wrap_ciphertext)
89+
- Rekey on membership change; rewrap to active devices.
90+
91+
## 7. Capability Tokens
92+
- Format: PASETO v4.public (Ed25519-signed by server capability key).
93+
Claims:
94+
- sub: user or device id
95+
- scope: [object:get|put, room:read, room:write, membership:manage]
96+
- resource: URI or prefix (e.g., s3://bucket/path/object-id)
97+
- exp: expiry; iat/nbf
98+
- region: enforced data residency region (controls bucket/prefix routing)
99+
- tid/nonce: unique token id to prevent replay
100+
- TTLs: object GET/PUT 15 minutes; room/event scopes 1 hour.
101+
102+
## 8. APIs (Server)
103+
- POST /devices/attest
104+
- POST /devices/revoke
105+
- POST /rooms
106+
- POST /rooms/:id/members
107+
- POST /rooms/:id/rotate
108+
- POST /capabilities
109+
- PUT /objects/:id (requires capability)
110+
- GET /objects/:id (requires capability)
111+
- WS /events
112+
113+
## 9. Storage Schema (Postgres + S3-compatible)
114+
Residency enforcement: region claim in capabilities is validated and mapped to storage bucket/prefix; mismatches are rejected at capability validation and storage routing.
115+
- users(id, identity_pubkey_hash, oidc_sub, region)
116+
- devices(id, user_id, ed25519_pub, x25519_pub, attestation_sig, status)
117+
- rooms(id, created_by, policy)
118+
- memberships(room_id, device_id, role, since, status)
119+
- sender_keys(room_id, epoch, key_id, wrapped_keys jsonb, created_at)
120+
- objects(id, owner, room_id, bucket, path, blake3_digest, size, manifest_sig, created_at)
121+
- key_wraps(object_id, device_id, wrap_ciphertext)
122+
- audit_events(id, actor, type, target, ts, meta)
123+
124+
## 10. Backup & Recovery
125+
SAS & QR: Use emoji SAS (7-emoji sequence from a 64-emoji table) for human-friendly verification. QR payload schema: base64url(JSON { device_pubkeys, nonce, sig, ts }).
126+
- Key vault: private keys wrapped by Argon2id-derived KEK; IndexedDB on web; Secure Enclave/Keystore on mobile.
127+
- Optional Shamir 2-of-3 recovery (user + admin escrow + HSM) with approvals and audit.
128+
129+
## 11. Metadata Minimization
130+
Audit taxonomy and retention: capture key lifecycle events, membership changes, capability issuance/revocation, and recovery attempts. Retention: 1 year (then purge or anonymize per policy).
131+
- Store hashed identity references; coarse timestamps; encrypted membership maps when feasible.
132+
- Avoid plaintext titles/tags. No plaintext in logs.
133+
134+
## 12. Request Signing & Replay Protection
135+
- Client signs sensitive requests with device Ed25519 over canonical payload + timestamp.
136+
- Server enforces skew window and tid uniqueness.
137+
138+
## 13. Performance Targets
139+
- p95 decrypt < 120 ms for 10 MB on desktop.
140+
- Streaming crypto in Web Workers; backpressure-managed I/O.
141+
142+
## 14. Rollout & Kill Switch
143+
- Feature flags per tenant/room.
144+
- Canary cohorts; schema uses sidecar tables for isolation.
145+
- Instant kill-switch disables capability issuance for E2EE objects/rooms; existing ciphertext remains intact.
146+
147+
## 15. CI/CD and Supply Chain
148+
- Renovate/Dependabot with grouped patch/minor; majors manual.
149+
- GitHub Actions: lint/typecheck/tests, CodeQL, SCA, SBOM (Syft), container scanning.
150+
- Signed commits and releases.
151+
152+
## 16. Test Plan (Acceptance Gates)
153+
- Unit and property tests for: keygen, provisioning, sealed box wraps, AES-GCM streaming (vectors), manifest sign/verify, PASETO claims/validation, rotation flows.
154+
- Integration: 1:1 E2EE chat, file upload/download, membership change triggers rewrap/rotation.
155+
- Data residency pinning tests; GDPR DSR exercises.
156+
157+
## 17. Open Items / Future Work
158+
- Evaluate MLS migration path for large rooms.
159+
- HPKE support behind wrapping abstraction.
160+
- Privacy-preserving analytics with DP budget management per org.

โ€Žbackend/.env.exampleโ€Ž

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
# === TURNING WHEEL BACKEND ENVIRONMENT CONFIGURATION ===
2+
3+
# === APPLICATION ===
4+
NODE_ENV=development
5+
PORT=8080
6+
7+
# === DATABASE (PostgreSQL) ===
8+
DB_HOST=localhost
9+
DB_PORT=5432
10+
DB_NAME=turning_wheel
11+
DB_USER=postgres
12+
DB_PASSWORD=your_secure_password
13+
14+
# Database SSL (for production)
15+
DB_SSL_CA=
16+
DB_SSL_CERT=
17+
DB_SSL_KEY=
18+
19+
# Database Pool Settings
20+
DB_POOL_MIN=2
21+
DB_POOL_MAX=20
22+
DB_IDLE_TIMEOUT=30000
23+
DB_CONNECTION_TIMEOUT=2000
24+
DB_STATEMENT_TIMEOUT=30000
25+
DB_QUERY_TIMEOUT=30000
26+
27+
# === REDIS (for caching and sessions) ===
28+
REDIS_URL=redis://localhost:6379
29+
REDIS_HOST=localhost
30+
REDIS_PORT=6379
31+
REDIS_PASSWORD=
32+
33+
# === JWT CONFIGURATION ===
34+
# Generate with: node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
35+
JWT_SECRET=your_jwt_secret_key_minimum_32_characters_long
36+
JWT_REFRESH_SECRET=your_jwt_refresh_secret_key_minimum_32_characters_long
37+
JWT_EXPIRY=15m
38+
JWT_REFRESH_EXPIRY=7d
39+
40+
# === ENCRYPTION ===
41+
# Generate with: node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"
42+
MASTER_ENCRYPTION_KEY=your_base64_encoded_32_byte_master_key
43+
44+
# === EXTERNAL SERVICES ===
45+
FRONTEND_URL=http://localhost:3000
46+
47+
# Image Generation Service
48+
IMAGEAPI_BASE=
49+
IMAGEAPI_KEY=
50+
51+
# === EMAIL (SMTP) ===
52+
SMTP_HOST=smtp.gmail.com
53+
SMTP_PORT=587
54+
SMTP_USER=your-email@gmail.com
55+
SMTP_PASSWORD=your-app-password
56+
57+
# === WEBHOOKS ===
58+
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK
59+
N8N_WEBHOOK_URL=
60+
GRAFANA_SLACK_WEBHOOK=
61+
62+
# === LOGGING ===
63+
LOG_LEVEL=info
64+
LOG_DIR=logs
65+
66+
# === SECURITY ===
67+
# Rate limiting
68+
RATE_LIMIT_MAX=100
69+
RATE_LIMIT_WINDOW=900000
70+
71+
# HMAC for webhook signing
72+
# Generate with: node -e "console.log(require('crypto').randomBytes(64).toString('hex'))"
73+
HMAC_SECRET=your_hmac_secret_key_for_webhook_signing
74+
75+
# === FILE UPLOAD ===
76+
MAX_FILE_SIZE=10485760
77+
UPLOAD_DIR=uploads
78+
79+
# === MONITORING & ANALYTICS ===
80+
TIMESCALE_URL=postgres://vc:vcpass@localhost:5432/visual
81+
82+
# === GOOGLE DRIVE (Optional) ===
83+
GDRIVE_FOLDER_ID=
84+
GDRIVE_SERVICE_JSON_PATH=/secrets/gdrive-service.json
85+
86+
# === DEVELOPMENT ===
87+
# Set to true to enable debug logging
88+
DEBUG=false
89+
90+
# === PRODUCTION SECURITY ===
91+
# Only set these in production
92+
SECURE_TOKEN=your_secure_api_token_for_production
93+
94+
# === SSL/TLS ===
95+
# For HTTPS in production
96+
SSL_KEY_PATH=
97+
SSL_CERT_PATH=
98+
SSL_CA_PATH=
99+
100+
# === CORS ===
101+
CORS_ORIGIN=http://localhost:3000
102+
CORS_CREDENTIALS=true
103+
104+
# === SESSION ===
105+
SESSION_SECRET=your_session_secret_key_minimum_32_characters
106+
107+
# === ANALYTICS ===
108+
# Google Analytics or other analytics services
109+
GA_TRACKING_ID=
110+
ANALYTICS_ENABLED=false
111+
112+
# === ERROR REPORTING ===
113+
# Sentry DSN for error reporting
114+
SENTRY_DSN=
115+
ERROR_REPORTING_ENABLED=false
116+
117+
# === FEATURE FLAGS ===
118+
FEATURE_ENCRYPTION_ENABLED=true
119+
FEATURE_RATE_LIMITING_ENABLED=true
120+
FEATURE_ANALYTICS_ENABLED=true
121+
FEATURE_FILE_UPLOAD_ENABLED=true
122+
123+
# === BACKUP ===
124+
# Database backup configuration
125+
BACKUP_ENABLED=false
126+
BACKUP_SCHEDULE=0 2 * * *
127+
BACKUP_RETENTION_DAYS=30
128+
BACKUP_S3_BUCKET=
129+
BACKUP_S3_ACCESS_KEY=
130+
BACKUP_S3_SECRET_KEY=
131+
132+
# === HEALTH CHECKS ===
133+
HEALTH_CHECK_ENABLED=true
134+
HEALTH_CHECK_INTERVAL=30000
135+
136+
# === PERFORMANCE ===
137+
# Enable compression
138+
COMPRESSION_ENABLED=true
139+
COMPRESSION_LEVEL=6
140+
141+
# Cache settings
142+
CACHE_TTL=300
143+
CACHE_MAX_SIZE=100
144+
145+
# === NOTES ===
146+
# 1. Never commit this file with real secrets
147+
# 2. Use strong, unique passwords for production
148+
# 3. Rotate secrets regularly
149+
# 4. Use a secret management service in production
150+
# 5. Enable SSL/TLS in production
151+
# 6. Set up proper monitoring and logging
152+
# 7. Configure backups for production databases

0 commit comments

Comments
ย (0)