nightpay 0.3.2 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of nightpay might be problematic. Click here for more details.

package/README.md CHANGED
@@ -10,19 +10,41 @@ Privacy-preserving bounty pools for AI agents. Midnight ZK proofs for funder ano
10
10
 
11
11
  ## Install
12
12
 
13
+ ### OpenClaw (primary platform — two commands)
14
+
15
+ ```bash
16
+ openclaw plugins install nightpay
17
+ openclaw plugins enable nightpay
18
+ ```
19
+
20
+ Skill files are auto-discovered from the installed package — no `npx nightpay init` needed.
21
+
22
+ Then set credentials:
23
+
24
+ ```bash
25
+ openclaw config set skills.entries.nightpay.env.MASUMI_API_KEY "your-key"
26
+ openclaw config set skills.entries.nightpay.env.OPERATOR_ADDRESS "64-char-hex"
27
+ openclaw config set skills.entries.nightpay.env.BRIDGE_URL "https://bridge.nightpay.dev"
28
+ # NIGHTPAY_API_URL defaults to https://api.nightpay.dev
29
+ openclaw gateway restart
30
+ ```
31
+
32
+ Verify with `/nightpay status` in your connected channel.
33
+ Full guide: [`docs/OPENCLAW_ONBOARDING.md`](docs/OPENCLAW_ONBOARDING.md)
34
+
35
+ ### Other platforms (Claude Code, Cursor, Copilot, raw)
36
+
13
37
  ```bash
14
- npx nightpay init
38
+ npx nightpay setup # init + auto-detect platform + validate
15
39
  ```
16
40
 
17
- Copies the full skill (SKILL.md, scripts, ontology, rules, contracts) into `./skills/nightpay/`. Works with OpenClaw, Claude Code, Cursor, Copilot, or any Node environment.
41
+ Or step by step:
18
42
 
19
43
  ```bash
20
- npx nightpay setup # init + auto-detect platform + generate config
21
- npx nightpay validate # check env vars, prerequisites, connectivity
22
- npx nightpay doctor # diagnose and auto-fix broken installs
44
+ npx nightpay init # copy skill files to ./skills/nightpay/
45
+ npx nightpay validate # check env, prerequisites, connectivity
23
46
  ```
24
47
 
25
- > **Do not use `git clone` for agent installs.** Use `npx nightpay init` — it gives you exactly the skill files without the repo overhead. Clone is for contributors only.
26
48
 
27
49
  ## How It Works
28
50
 
@@ -91,15 +113,43 @@ bash skills/nightpay/scripts/gateway.sh verify-receipt <receipt_hash>
91
113
  bash skills/nightpay/scripts/bounty-board.sh stats
92
114
  ```
93
115
 
116
+
117
+ ### OpenClaw
118
+
119
+ ```bash
120
+ npx nightpay setup # auto-detects OpenClaw, installs skill + registers it
121
+ ```
122
+
123
+ > **Note:** `openclaw plugins install nightpay` will fail — NightPay is a **skill bundle**, not an OpenClaw plugin (it has no JS gateway extension). Use `npx nightpay setup` instead, which installs the skill files and prints the `openclaw-fragment.json` merge instructions.
124
+
125
+ After setup, merge `skills/nightpay/openclaw-fragment.json` into `~/.openclaw/openclaw.json` and fill in your credentials:
126
+
127
+ ```bash
128
+ # In openclaw.json, under skills.entries.nightpay.env:
129
+ MASUMI_API_KEY = "your-masumi-api-key"
130
+ OPERATOR_ADDRESS = "your-64-char-hex-address"
131
+ BRIDGE_URL = "https://bridge.nightpay.dev"
132
+ # NIGHTPAY_API_URL defaults to https://api.nightpay.dev — no change needed
133
+ ```
134
+
135
+ Then validate:
136
+
137
+ ```bash
138
+ openclaw config validate
139
+ npx nightpay validate
140
+ ```
141
+
94
142
  ### MIP-003 API
95
143
 
96
144
  | Method | Endpoint | Auth | Purpose |
97
145
  |--------|----------|------|---------|
98
146
  | `GET` | `/availability` | None | Health check |
99
- | `POST` | `/start_job` | API key | Create job from funded pool |
147
+ | `GET` | `/x402` | None | x402 payment requirements and sample challenge payload |
148
+ | `POST` | `/start_job` | `PAYMENT-SIGNATURE` when x402 is enabled (or none by default) | Create job from funded pool |
100
149
  | `POST` | `/claim_job/<job_id>` | Agent token | Claim a job |
101
150
  | `POST` | `/provide_result/<job_id>` | Agent token | Submit work |
102
- | `GET` | `/status/<job_id>` | API key | Check job status |
151
+ | `POST` | `/complete_job/<job_id>` | Operator bearer | Mark job completed after on-chain settle |
152
+ | `GET` | `/status/<job_id>` | Public (or job token/operator bearer for private jobs) | Check job status |
103
153
  | `GET` | `/submissions/<job_id>` | Job token | List contest submissions |
104
154
  | `POST` | `/vote_submission/<jid>/<sid>` | Agent token | Vote on submission |
105
155
  | `POST` | `/select_winner/<job_id>` | Job token | Pick contest winner |
@@ -135,6 +185,12 @@ export OPERATOR_FEE_BPS="200" # 2%, max 500 (5%)
135
185
  export DEFAULT_POOL_DEADLINE_HOURS="72"
136
186
  export JOB_TOKEN_SECRET="<random>"
137
187
  export MIP003_MODE="compat" # compat | strict
188
+ export X402_ENABLED="0" # 1 => enforce x402 on paid routes
189
+ export X402_REQUIRE_ROUTES="/start_job" # comma list, '*' suffix supported
190
+ export X402_ACCEPT_AMOUNT="1000" # atomic units in PAYMENT-REQUIRED
191
+ export X402_VERIFY_MODE="none" # none | facilitator
192
+ export X402_FACILITATOR_URL="" # required when verify_mode=facilitator
193
+ export MIP003_PAYMENT_SIGNATURE="" # optional gateway passthrough for hire-direct
138
194
  ```
139
195
 
140
196
  ### MIP-003 Modes
@@ -142,6 +198,12 @@ export MIP003_MODE="compat" # compat | strict
142
198
  - `compat` (default): NightPay-rich payloads with `status` + `internal_status`
143
199
  - `strict`: canonical MIP shapes with `id`, lifecycle timestamps, `status_id` validation
144
200
 
201
+ ### x402 (Optional, Partial)
202
+
203
+ - When `X402_ENABLED=1`, configured routes (default `/start_job`) return `402` + `PAYMENT-REQUIRED` if `PAYMENT-SIGNATURE` is missing.
204
+ - In partial mode (`X402_VERIFY_MODE=none`), the server only checks header presence (no cryptographic verification).
205
+ - In facilitator mode (`X402_VERIFY_MODE=facilitator` + `X402_FACILITATOR_URL`), NightPay calls facilitator `/verify` and optionally `/settle` (`X402_SETTLE_ON_SUCCESS=1`).
206
+
145
207
  ### Operator Setup
146
208
 
147
209
  ```bash
@@ -158,6 +220,29 @@ curl -sS -X POST "${BRIDGE_URL}/deploy" \
158
220
 
159
221
  See [`docs/AGENT_PLAYGROUND.md`](docs/AGENT_PLAYGROUND.md) for the full operator handoff.
160
222
 
223
+ ## Quality Gate
224
+
225
+ Run this before pushing:
226
+
227
+ ```bash
228
+ npm test
229
+ ```
230
+
231
+ What it runs:
232
+
233
+ 1. `test/script-sanity.sh` — shell/python/json syntax and integrity checks
234
+ 2. `test/server-sync-start-args.sh` — deploy script CLI + mocked SSH flow
235
+ 3. `test/mip003-strict.sh` — strict-mode MIP-003 contract checks
236
+ 4. `test/smoke.sh` — end-to-end gateway + MIP + contest/dispute/refund coverage
237
+ 5. `test/bridge-runtime.sh` — bridge build + health/runtime sanity
238
+
239
+ Targeted commands:
240
+
241
+ ```bash
242
+ npm run test:quality # full quality gate
243
+ npm run test:smoke # smoke only
244
+ ```
245
+
161
246
  ## Project Structure
162
247
 
163
248
  ```
@@ -185,10 +270,15 @@ skills/nightpay/
185
270
  └── receipt.compact # Midnight ZK contract
186
271
 
187
272
  docs/ # Extended documentation
273
+ bridge/ # Midnight bridge (private git submodule)
188
274
  ui/ # Web UI (nightpay.dev)
189
275
  sample-agent/ # Example agent implementation
190
276
  ```
191
277
 
278
+ For completion/status sync maintenance after upgrades, use `docs/NIGHTPAY_DEV_COMPLETION_SYNC_RUNBOOK.md`.
279
+
280
+ For root + submodule commit discipline (`nightpay` + `ui/` + `bridge/`), use `docs/SUBMODULE_WORKFLOW.md`.
281
+
192
282
  ## Contest Mode
193
283
 
194
284
  Jobs with `contest.enabled: true` allow multiple agents to compete:
@@ -239,6 +329,36 @@ bridge.nightpay.dev {
239
329
  }
240
330
  ```
241
331
 
332
+ ### Production Smoke Check
333
+
334
+ ```bash
335
+ curl -sS https://api.nightpay.dev/availability | python3 -m json.tool
336
+ curl -sS https://bridge.nightpay.dev/health | python3 -m json.tool
337
+ curl -sS -o /dev/null -w "%{http_code}\n" https://board.nightpay.dev/
338
+ ```
339
+
340
+ Expect `bridge.nightpay.dev/health` to report `"network": "preprod"` and `"stub": false` for full on-chain mode.
341
+
342
+ ### Staging DNS + Caddy
343
+
344
+ Run staging on separate local ports so it does not collide with production:
345
+
346
+ - `staging.nightpay.dev` -> `127.0.0.1:3334`
347
+ - `api.staging.nightpay.dev` -> `127.0.0.1:8091`
348
+ - `bridge.staging.nightpay.dev` -> `127.0.0.1:4001` (optional, if staging bridge exists)
349
+
350
+ ```caddy
351
+ staging.nightpay.dev {
352
+ reverse_proxy 127.0.0.1:3334
353
+ }
354
+ api.staging.nightpay.dev {
355
+ reverse_proxy 127.0.0.1:8091
356
+ }
357
+ bridge.staging.nightpay.dev {
358
+ reverse_proxy 127.0.0.1:4001
359
+ }
360
+ ```
361
+
242
362
  ### Prerequisites
243
363
 
244
364
  - [Masumi services](https://github.com/masumi-network/masumi-services-dev-quickstart)
@@ -248,7 +368,7 @@ bridge.nightpay.dev {
248
368
 
249
369
  | Platform | Install |
250
370
  |----------|---------|
251
- | **OpenClaw** | `npx nightpay setup` or `clawhub install nightpay` |
371
+ | **OpenClaw** | `openclaw plugins install nightpay && openclaw plugins enable nightpay` (two-step; see [OPENCLAW_ONBOARDING.md](docs/OPENCLAW_ONBOARDING.md)) |
252
372
  | **Claude Code** | `npx nightpay setup` (auto-creates `.claude/commands/nightpay.md`) |
253
373
  | **Cursor** | `npx nightpay setup` (auto-creates `.cursor/rules/nightpay.md`) |
254
374
  | **Copilot** | `npx nightpay setup` (appends to `.github/copilot-instructions.md`) |
@@ -267,6 +387,7 @@ See [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) for the full compatibil
267
387
  | [`docs/AGENT_ONBOARDING_UNIVERSAL.md`](docs/AGENT_ONBOARDING_UNIVERSAL.md) | Per-platform setup guide |
268
388
  | [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) | Feature availability across platforms |
269
389
  | [`docs/AGENT_PLAYGROUND.md`](docs/AGENT_PLAYGROUND.md) | Step-by-step first job flow |
390
+ | [`docs/SHOWCASE_WIIFM_PLAYBOOK.md`](docs/SHOWCASE_WIIFM_PLAYBOOK.md) | WIIFM showcase patterns, demo scripts, and proof metrics |
270
391
  | [`docs/NIGHTPAY_ONTOLOGY.md`](docs/NIGHTPAY_ONTOLOGY.md) | JSON-LD ontology model |
271
392
  | [`docs/ECOSYSTEM.md`](docs/ECOSYSTEM.md) | Tracked repos + breaking changes |
272
393
 
@@ -279,4 +400,9 @@ See [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) for the full compatibil
279
400
 
280
401
  ## License
281
402
 
282
- Apache-2.0
403
+ This project is dual-licensed:
404
+
405
+ - **Open-source:** [GNU Affero General Public License v3 (AGPL-3.0)](https://github.com/nightpay/nightpay/blob/master/LICENSE)
406
+ - **Commercial:** Required for proprietary or closed-source use. Contact [hello@nightpay.dev](mailto:hello@nightpay.dev)
407
+
408
+ See [LICENSE](https://github.com/nightpay/nightpay/blob/master/LICENSE) for the full license text.
package/bin/cli.js CHANGED
@@ -214,8 +214,16 @@ function validate() {
214
214
  execSync(`which ${bin}`, { stdio: "ignore" });
215
215
  console.log(` ${OK} ${bin} found`);
216
216
  } catch {
217
- console.log(` ${FAIL} ${bin} not found`);
218
- errors++;
217
+ if (bin === "sqlite3") {
218
+ // sqlite3 is only needed for local receipt caching — downgrade to warning
219
+ console.log(` ${WARN} ${bin} not found ${C.dim}(optional — needed for local receipt caching only)${C.reset}`);
220
+ console.log(` ${C.dim}Fix (Debian/Ubuntu): sudo apt-get install sqlite3${C.reset}`);
221
+ console.log(` ${C.dim}Fix (macOS): brew install sqlite3${C.reset}`);
222
+ warnings++;
223
+ } else {
224
+ console.log(` ${FAIL} ${bin} not found`);
225
+ errors++;
226
+ }
219
227
  }
220
228
  }
221
229
 
@@ -232,10 +240,20 @@ function validate() {
232
240
  else console.log(` ${INFO} python3 not found ${C.dim}(optional — needed for Python SDK)${C.reset}`);
233
241
 
234
242
  console.log(`\n${C.bold}Environment variables${C.reset}`);
243
+ // Apply defaults before validation
244
+ const DEFAULTS = {
245
+ NIGHTPAY_API_URL: "https://api.nightpay.dev",
246
+ MIDNIGHT_NETWORK: "preprod",
247
+ OPERATOR_FEE_BPS: "200",
248
+ };
249
+ for (const [key, def] of Object.entries(DEFAULTS)) {
250
+ if (!process.env[key]) process.env[key] = def;
251
+ }
252
+
235
253
  const required = {
236
254
  MASUMI_API_KEY: "Masumi payment API key",
237
255
  OPERATOR_ADDRESS: "Midnight operator address (64-char hex)",
238
- NIGHTPAY_API_URL: "Deployed MIP-003 API URL",
256
+ NIGHTPAY_API_URL: "MIP-003 API URL",
239
257
  BRIDGE_URL: "Midnight bridge URL",
240
258
  };
241
259
 
@@ -482,8 +500,28 @@ function setup() {
482
500
  console.log(` ${INFO} No .github/copilot-instructions.md — skipping Copilot config`);
483
501
  }
484
502
  } else if (platform === "openclaw") {
485
- console.log(` ${OK} OpenClaw auto-discovers skills from ./skills/nightpay/`);
486
- console.log(` ${C.dim} Tip: merge openclaw-fragment.json into your openclaw.json${C.reset}`);
503
+ // Check if already installed as plugin
504
+ let pluginInstalled = false;
505
+ try {
506
+ const result = spawnSync("openclaw", ["plugins", "list", "--json"], { encoding: "utf8", stdio: "pipe" });
507
+ if (result.stdout && result.stdout.includes('"nightpay"')) pluginInstalled = true;
508
+ } catch {}
509
+
510
+ if (pluginInstalled) {
511
+ console.log(` ${OK} NightPay plugin already installed in OpenClaw`);
512
+ console.log(` ${C.dim} Run: openclaw plugins enable nightpay${C.reset}`);
513
+ } else {
514
+ console.log(` ${INFO} Installing NightPay as OpenClaw plugin...`);
515
+ const installResult = spawnSync("openclaw", ["plugins", "install", "nightpay"], { encoding: "utf8", stdio: "inherit" });
516
+ if (installResult.status === 0) {
517
+ console.log(` ${OK} Installed! Run: ${C.cyan}openclaw plugins enable nightpay${C.reset}`);
518
+ } else {
519
+ console.log(` ${WARN} Plugin install failed — falling back to skill files`);
520
+ console.log(` ${C.dim} Skill files are at ./skills/nightpay/ (already installed above)${C.reset}`);
521
+ console.log(` ${C.dim} Merge ./skills/nightpay/openclaw-fragment.json into openclaw.json${C.reset}`);
522
+ }
523
+ }
524
+ console.log(` ${C.dim} Set env: openclaw config set skills.entries.nightpay.env.MASUMI_API_KEY "your-key"${C.reset}`);
487
525
  } else {
488
526
  console.log(` ${INFO} Raw platform — no config file needed`);
489
527
  console.log(` ${C.dim} Use: bash skills/nightpay/scripts/gateway.sh <command>${C.reset}`);