onenoly11 commited on
Commit
bbb8e71
Β·
verified Β·
1 Parent(s): ddb7292

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +164 -162
README.md CHANGED
@@ -1,162 +1,164 @@
1
- # Quantum Pi Forge (v6)
2
-
3
- This repository powers the Quantum Pi Forge site. It currently ships as a Create React App but includes the scaffolding for a Next.js static export; the Netlify deployment (see below) relies on the Next configuration in `next.config.mjs`.
4
-
5
- ## Prerequisites
6
-
7
- - Node.js 18+ and `corepack` (bundled with Node 18+). `corepack` lets us invoke `pnpm` without a global install.
8
- - One of the supported package managers (this repo uses `pnpm`).
9
-
10
- ## Getting started
11
-
12
- 1. Install dependencies:
13
-
14
- ```powershell
15
- corepack pnpm install
16
- ```
17
-
18
- 1. Start the development server:
19
-
20
- ```powershell
21
- corepack pnpm start
22
- ```
23
-
24
- 1. Build for production (runs the CRA-based compiler that currently drives the site):
25
-
26
- ```powershell
27
- corepack pnpm build
28
- ```
29
-
30
- ## Deploying to Vercel (production)
31
-
32
- The CRA portion still runs via `corepack pnpm build`, but the payment workflow now lives inside Vercel Serverless functions. Configure your site in the Vercel dashboard (or run `vercel --prod`) after the build artifact is ready.
33
-
34
- ### Vercel configuration
35
-
36
- `vercel.json` wires everything together:
37
-
38
- ```json
39
- {
40
- "version": 3,
41
- "routes": [
42
- {
43
- "src": "/validation-key.txt",
44
- "dest": "/public/validation-key.txt",
45
- "headers": {
46
- "Cache-Control": "public, max-age=0, must-revalidate",
47
- "Content-Type": "text/plain; charset=utf-8"
48
- }
49
- },
50
- {
51
- "src": "/.well-known/validation-key.txt",
52
- "dest": "/public/validation-key.txt",
53
- "headers": {
54
- "Cache-Control": "public, max-age=0, must-revalidate",
55
- "Content-Type": "text/plain; charset=utf-8"
56
- }
57
- }
58
- ],
59
- "functions": {
60
- "api/**/*.ts": {
61
- "memory": 1024,
62
- "maxDuration": 30
63
- }
64
- },
65
- "rewrites": [
66
- {
67
- "source": "/.netlify/functions/(.*)",
68
- "destination": "/api/$1"
69
- }
70
- ],
71
- "headers": [
72
- {
73
- "source": "/api/(.*)",
74
- "headers": [
75
- { "key": "Access-Control-Allow-Origin", "value": "*" },
76
- { "key": "Access-Control-Allow-Headers", "value": "Content-Type, Authorization, X-Signature, X-Timestamp" },
77
- { "key": "Access-Control-Allow-Methods", "value": "GET, POST, OPTIONS" }
78
- ]
79
- }
80
- ]
81
- }
82
- ```
83
-
84
- ### Pi Mainnet validation bundle
85
-
86
- The static `public/validation-key.txt` file exposes the Pi validation key at both `/validation-key.txt` and `/.well-known/validation-key.txt` so that the Pi Developer Portal can immediately confirm `quantumpiforge.com`. The routes above force `text/plain` semantics and disable caching so the validation status is always fresh.
87
-
88
- To confirm the file locally before deployment run:
89
-
90
- ```bash
91
- curl -s https://quantumpiforge.com/validation-key.txt
92
- ```
93
-
94
- Once deployed, rerun the same command or execute the `test-validation.js` helper to ensure the response is `50f70d548675a0db693c46b99c0eff07e2`. Run it with `node test-validation.js` after a short delay to verify the deployment pulls the correct key, then trigger the Pi Developer Console validation flow and expect the domain to turn green automatically. A GitHub Action (`.github/workflows/validation-check.yml`) already runs this same script hourly (and on every `main` push) to detect if the validation key ever becomes unreachable and fail the workflow so it can be investigated.
95
-
96
- ### Pi Mainnet activation checklist
97
-
98
- After the validation key is live, add a Pi App Manifest so the Pi Studio checks the metadata immediately. Create `public/pi-app-manifest.json` with the following content before deploying:
99
-
100
- ```json
101
- {
102
- "name": "Quantum Pi Forge",
103
- "description": "A Sovereign App built on Pi Network.",
104
- "url": "https://quantumpiforge.com",
105
- "permissions": ["username", "payments"]
106
- }
107
- ```
108
-
109
- Once deployed, confirm these resources return 200 before pressing **Verify Domain** in Pi Studio:
110
-
111
- - `https://quantumpiforge.com/pi-app-manifest.json`
112
- - `https://quantumpiforge.com/validation-key.txt`
113
- - `https://quantumpiforge.com` loads without TLS issues
114
-
115
- Pi Studio will then verify the manifest, call the validation key, and let you submit the app for Pi Mainnet.
116
-
117
- The rewrite keeps older webhooks that still call `/.netlify/functions/...` intact; all the logic now executes in `api/*` handlers so you can delete the legacy `netlify/` files once you confirm the new functions behave identically.
118
-
119
- ## Serverless functions
120
-
121
- All backend behavior lives inside `api/*.ts`. Each file imports `lib/tracing.ts` so the OpenTelemetry SDK bootstraps before business logic runs, preserving the existing tracing output in the AI Toolkit Trace Viewer.
122
-
123
- | Handler | Responsibility |
124
- | --- | --- |
125
- | `api/pi-create-payment.ts` | Accepts POST requests that create Pi payments, enriches metadata, and points the webhook to `api/pi-payment-webhook`. Uses `PI_BACKEND_URL`, `URL`, and `TEAM_TOKEN` to speak to the Pi backend and internal alerts. |
126
- | `api/pi-payment-webhook.ts` | Validates `x-pi-signature` via `PI_PAYMENT_SECRET`, deduplicates `payment_id`, upserts into Supabase (service key), and triggers `api/ethical-audit.ts` when an ethical audit is due. Alerts and retries go through `api/alert-webhook.ts`. |
127
- | `api/ethical-audit.ts` | Inserts audit entries into Supabase after verifying `X-Signature` + timestamp signed with `WEBHOOK_SECRET`, and responds with the inserted row ID so downstream UI can surface progress. |
128
- | `api/alert-webhook.ts` | Lightweight logging endpoint used by the webhook pipeline to capture failure contexts, keeping the same payloads as the prior Netlify handler. |
129
- | `api/auth-callback.ts` | Supabase auth callback used in the Pi Developer Console; exchanges the OAuth `code` for a session and redirects to `/auth/success`. |
130
-
131
- These handlers rely on the same environment secrets you had for Netlify, but the `URL` variable should now point at `https://quantumpiforge.com` (or whichever Vercel domain hosts the functions) so each helper can call its peers via `https://<site>/api/...`.
132
-
133
- ### Asynchronous Pi payment flow
134
-
135
- The Supabase schema remains unchanged – keep the `payments` table defined as before, with indexes on `payment_id` and auditing columns. When `pi-create-payment` responds with a `payment_id`, show `Pending` on the frontend and watch Supabase Realtime for updates to that row. Once `status = 'completed' && audit_completed = true`, display the audit score and mining boost.
136
-
137
- ### Environment checklist
138
-
139
- These values are still required inside Vercel Environment Variables:
140
-
141
- 1. `PI_PAYMENT_SECRET` – Pi webhook HMAC secret.
142
- 2. `SUPABASE_URL` & `SUPABASE_SERVICE_KEY` – Service key for inserts/updates.
143
- 3. `URL` – Vercel site URL so functions can call each other (e.g., `https://quantumpiforge.com`).
144
- 4. `TEAM_TOKEN` – Internal auth token that gates audit/alert calls.
145
- 5. `PI_BACKEND_URL` – Backend proxy that actually talks to Pi Network.
146
- 6. `WEBHOOK_SECRET` – Signing secret for `ethical-audit`.
147
- 7. `PI_BACKEND_URL` – Keep referencing to talk to the payment backend.
148
- 8. (Optional) `PI_DEVELOPER_REDIRECT` – Keep this aligned with `https://quantumpiforge.com/api/auth-callback` when updating Pi Developer Console redirect URIs.
149
-
150
- ## Tracing
151
-
152
- All Vercel API handlers import `lib/tracing.ts`, so OpenTelemetry spans continue to stream to AI Toolkit. Start tracing locally with `ai-mlstudio.tracing.open` and inspect data in the Trace Viewer the same way you did for Netlify functions:
153
-
154
- - **Collector endpoint:** `http://localhost:4318/v1/traces` (override with `OTLP_ENDPOINT`).
155
- - **Trace scope:** HTTP entry spans, Supabase writes, HMAC validations, and internal fetch calls between functions.
156
- - **What to watch:** `pi-payment-webhook` spans should show audit calls, alert fallbacks, and Supabase upserts within a single trace.
157
-
158
- ## Legacy Netlify notes
159
-
160
- - `.github/workflows/netlify-guardian.yml` is retained for reference, but it only applies while Netlify still owns the domain. Once `quantumpiforge.com` is fully on Vercel you can remove the workflow and the `netlify/` functions directory.
161
- - `netlify/functions/*` still exists for history, but all production traffic now hits `api/*` with the same request/response contracts.
162
-
 
 
 
1
+ ---
2
+ sdk: gradio
3
+ ---
4
+ # Quantum Pi Forge (v6)
5
+
6
+ This repository powers the Quantum Pi Forge site. It currently ships as a Create React App but includes the scaffolding for a Next.js static export; the Netlify deployment (see below) relies on the Next configuration in `next.config.mjs`.
7
+
8
+ ## Prerequisites
9
+
10
+ - Node.js 18+ and `corepack` (bundled with Node 18+). `corepack` lets us invoke `pnpm` without a global install.
11
+ - One of the supported package managers (this repo uses `pnpm`).
12
+
13
+ ## Getting started
14
+
15
+ 1. Install dependencies:
16
+
17
+ ```powershell
18
+ corepack pnpm install
19
+ ```
20
+
21
+ 1. Start the development server:
22
+
23
+ ```powershell
24
+ corepack pnpm start
25
+ ```
26
+
27
+ 1. Build for production (runs the CRA-based compiler that currently drives the site):
28
+
29
+ ```powershell
30
+ corepack pnpm build
31
+ ```
32
+
33
+ ## Deploying to Vercel (production)
34
+
35
+ The CRA portion still runs via `corepack pnpm build`, but the payment workflow now lives inside Vercel Serverless functions. Configure your site in the Vercel dashboard (or run `vercel --prod`) after the build artifact is ready.
36
+
37
+ ### Vercel configuration
38
+
39
+ `vercel.json` wires everything together:
40
+
41
+ ```json
42
+ {
43
+ "version": 3,
44
+ "routes": [
45
+ {
46
+ "src": "/validation-key.txt",
47
+ "dest": "/public/validation-key.txt",
48
+ "headers": {
49
+ "Cache-Control": "public, max-age=0, must-revalidate",
50
+ "Content-Type": "text/plain; charset=utf-8"
51
+ }
52
+ },
53
+ {
54
+ "src": "/.well-known/validation-key.txt",
55
+ "dest": "/public/validation-key.txt",
56
+ "headers": {
57
+ "Cache-Control": "public, max-age=0, must-revalidate",
58
+ "Content-Type": "text/plain; charset=utf-8"
59
+ }
60
+ }
61
+ ],
62
+ "functions": {
63
+ "api/**/*.ts": {
64
+ "memory": 1024,
65
+ "maxDuration": 30
66
+ }
67
+ },
68
+ "rewrites": [
69
+ {
70
+ "source": "/.netlify/functions/(.*)",
71
+ "destination": "/api/$1"
72
+ }
73
+ ],
74
+ "headers": [
75
+ {
76
+ "source": "/api/(.*)",
77
+ "headers": [
78
+ { "key": "Access-Control-Allow-Origin", "value": "*" },
79
+ { "key": "Access-Control-Allow-Headers", "value": "Content-Type, Authorization, X-Signature, X-Timestamp" },
80
+ { "key": "Access-Control-Allow-Methods", "value": "GET, POST, OPTIONS" }
81
+ ]
82
+ }
83
+ ]
84
+ }
85
+ ```
86
+
87
+ ### Pi Mainnet validation bundle
88
+
89
+ The static `public/validation-key.txt` file exposes the Pi validation key at both `/validation-key.txt` and `/.well-known/validation-key.txt` so that the Pi Developer Portal can immediately confirm `quantumpiforge.com`. The routes above force `text/plain` semantics and disable caching so the validation status is always fresh.
90
+
91
+ To confirm the file locally before deployment run:
92
+
93
+ ```bash
94
+ curl -s https://quantumpiforge.com/validation-key.txt
95
+ ```
96
+
97
+ Once deployed, rerun the same command or execute the `test-validation.js` helper to ensure the response is `50f70d548675a0db693c46b99c0eff07e2`. Run it with `node test-validation.js` after a short delay to verify the deployment pulls the correct key, then trigger the Pi Developer Console validation flow and expect the domain to turn green automatically. A GitHub Action (`.github/workflows/validation-check.yml`) already runs this same script hourly (and on every `main` push) to detect if the validation key ever becomes unreachable and fail the workflow so it can be investigated.
98
+
99
+ ### Pi Mainnet activation checklist
100
+
101
+ After the validation key is live, add a Pi App Manifest so the Pi Studio checks the metadata immediately. Create `public/pi-app-manifest.json` with the following content before deploying:
102
+
103
+ ```json
104
+ {
105
+ "name": "Quantum Pi Forge",
106
+ "description": "A Sovereign App built on Pi Network.",
107
+ "url": "https://quantumpiforge.com",
108
+ "permissions": ["username", "payments"]
109
+ }
110
+ ```
111
+
112
+ Once deployed, confirm these resources return 200 before pressing **Verify Domain** in Pi Studio:
113
+
114
+ - `https://quantumpiforge.com/pi-app-manifest.json`
115
+ - `https://quantumpiforge.com/validation-key.txt`
116
+ - `https://quantumpiforge.com` loads without TLS issues
117
+
118
+ Pi Studio will then verify the manifest, call the validation key, and let you submit the app for Pi Mainnet.
119
+
120
+ The rewrite keeps older webhooks that still call `/.netlify/functions/...` intact; all the logic now executes in `api/*` handlers so you can delete the legacy `netlify/` files once you confirm the new functions behave identically.
121
+
122
+ ## Serverless functions
123
+
124
+ All backend behavior lives inside `api/*.ts`. Each file imports `lib/tracing.ts` so the OpenTelemetry SDK bootstraps before business logic runs, preserving the existing tracing output in the AI Toolkit Trace Viewer.
125
+
126
+ | Handler | Responsibility |
127
+ | --- | --- |
128
+ | `api/pi-create-payment.ts` | Accepts POST requests that create Pi payments, enriches metadata, and points the webhook to `api/pi-payment-webhook`. Uses `PI_BACKEND_URL`, `URL`, and `TEAM_TOKEN` to speak to the Pi backend and internal alerts. |
129
+ | `api/pi-payment-webhook.ts` | Validates `x-pi-signature` via `PI_PAYMENT_SECRET`, deduplicates `payment_id`, upserts into Supabase (service key), and triggers `api/ethical-audit.ts` when an ethical audit is due. Alerts and retries go through `api/alert-webhook.ts`. |
130
+ | `api/ethical-audit.ts` | Inserts audit entries into Supabase after verifying `X-Signature` + timestamp signed with `WEBHOOK_SECRET`, and responds with the inserted row ID so downstream UI can surface progress. |
131
+ | `api/alert-webhook.ts` | Lightweight logging endpoint used by the webhook pipeline to capture failure contexts, keeping the same payloads as the prior Netlify handler. |
132
+ | `api/auth-callback.ts` | Supabase auth callback used in the Pi Developer Console; exchanges the OAuth `code` for a session and redirects to `/auth/success`. |
133
+
134
+ These handlers rely on the same environment secrets you had for Netlify, but the `URL` variable should now point at `https://quantumpiforge.com` (or whichever Vercel domain hosts the functions) so each helper can call its peers via `https://<site>/api/...`.
135
+
136
+ ### Asynchronous Pi payment flow
137
+
138
+ The Supabase schema remains unchanged – keep the `payments` table defined as before, with indexes on `payment_id` and auditing columns. When `pi-create-payment` responds with a `payment_id`, show `Pending` on the frontend and watch Supabase Realtime for updates to that row. Once `status = 'completed' && audit_completed = true`, display the audit score and mining boost.
139
+
140
+ ### Environment checklist
141
+
142
+ These values are still required inside Vercel Environment Variables:
143
+
144
+ 1. `PI_PAYMENT_SECRET` – Pi webhook HMAC secret.
145
+ 2. `SUPABASE_URL` & `SUPABASE_SERVICE_KEY` – Service key for inserts/updates.
146
+ 3. `URL` – Vercel site URL so functions can call each other (e.g., `https://quantumpiforge.com`).
147
+ 4. `TEAM_TOKEN` – Internal auth token that gates audit/alert calls.
148
+ 5. `PI_BACKEND_URL` – Backend proxy that actually talks to Pi Network.
149
+ 6. `WEBHOOK_SECRET` – Signing secret for `ethical-audit`.
150
+ 7. `PI_BACKEND_URL` – Keep referencing to talk to the payment backend.
151
+ 8. (Optional) `PI_DEVELOPER_REDIRECT` – Keep this aligned with `https://quantumpiforge.com/api/auth-callback` when updating Pi Developer Console redirect URIs.
152
+
153
+ ## Tracing
154
+
155
+ All Vercel API handlers import `lib/tracing.ts`, so OpenTelemetry spans continue to stream to AI Toolkit. Start tracing locally with `ai-mlstudio.tracing.open` and inspect data in the Trace Viewer the same way you did for Netlify functions:
156
+
157
+ - **Collector endpoint:** `http://localhost:4318/v1/traces` (override with `OTLP_ENDPOINT`).
158
+ - **Trace scope:** HTTP entry spans, Supabase writes, HMAC validations, and internal fetch calls between functions.
159
+ - **What to watch:** `pi-payment-webhook` spans should show audit calls, alert fallbacks, and Supabase upserts within a single trace.
160
+
161
+ ## Legacy Netlify notes
162
+
163
+ - `.github/workflows/netlify-guardian.yml` is retained for reference, but it only applies while Netlify still owns the domain. Once `quantumpiforge.com` is fully on Vercel you can remove the workflow and the `netlify/` functions directory.
164
+ - `netlify/functions/*` still exists for history, but all production traffic now hits `api/*` with the same request/response contracts.