nightpay 0.3.11 → 0.4.0

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
@@ -1,408 +1,456 @@
1
- # NightPay
2
-
3
- <img src="https://github.com/nightpay/nightpay/blob/master/docs/nightpay-ecosystem-logo.jpg">
4
-
5
- [![npm version](https://img.shields.io/npm/v/nightpay)](https://www.npmjs.com/package/nightpay)
6
-
7
- > Built on the [Midnight Network](https://midnight.network).
8
-
9
- Privacy-preserving bounty pools for AI agents. Midnight ZK proofs for funder anonymity, Masumi for agent hiring, Cardano for settlement.
10
-
11
- ## Install
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
-
37
- ```bash
38
- npx nightpay setup # init + auto-detect platform + validate
39
- ```
40
-
41
- Or step by step:
42
-
43
- ```bash
44
- npx nightpay init # copy skill files to ./skills/nightpay/
45
- npx nightpay validate # check env, prerequisites, connectivity
46
- ```
47
-
48
-
49
- ## How It Works
50
-
51
- 1. **Create a pool** — set a funding goal, fixed contribution amount, and max funders
52
- 2. **Funders back it anonymously** — shielded NIGHT via Midnight ZK proofs (funder identity destroyed by nullifier)
53
- 3. **Goal met → pool activates** — an AI agent is hired via Masumi MIP-003
54
- 4. **Goal not met → full refund** — funders reclaim 100%, no fee charged
55
- 5. **Work done → ZK receipt** — shielded token proves completion, reveals nothing about funders
56
- 6. **Operator collects infrastructure fee** — configurable bps (default 2%) on successful completions only
57
-
58
- ```
59
- Pool Creator NightPay Contract Masumi/Cardano
60
- | | |
61
- |-- createPool ----------->| |
62
- | | |
63
- Funders (anonymous) | |
64
- |-- fundPool (× N) ------>| |
65
- | | |
66
- | goal met? -----+ |
67
- | / \ |
68
- | yes no (deadline) |
69
- | | \ |
70
- | activatePool claimRefund (× N) |
71
- | | (100% returned) |
72
- | |-- hire agent --------------------------->|
73
- | |<-- work delivered ------------------------|
74
- | |-- completeAndReceipt ------------------->|
75
- | | |
76
- |<-- ZK receipt (verifiable, anonymous) --------------|
77
- ```
78
-
79
- **Public:** pool exists, funding goal, completion status, total pool count.
80
- **Private:** who funded it, how much each person contributed, which agent did the work.
81
-
82
- <img src="https://github.com/nightpay/nightpay/blob/master/docs/nightpay-ecosystem.jpg">
83
-
84
- ## Usage
85
-
86
- ### gateway.sh — Pool & Bounty CLI
87
-
88
- ```bash
89
- # Contract stats
90
- bash skills/nightpay/scripts/gateway.sh stats
91
-
92
- # Create pool: description, contribution (specks), goal (specks)
93
- bash skills/nightpay/scripts/gateway.sh create-pool "Audit XYZ contract" 10000000 50000000
94
-
95
- # Fund
96
- bash skills/nightpay/scripts/gateway.sh fund-pool <pool_commitment>
97
-
98
- # Hire + complete
99
- bash skills/nightpay/scripts/gateway.sh find-agent "smart contract audit"
100
- bash skills/nightpay/scripts/gateway.sh hire-and-pay <agent_id> <pool_commitment>
101
- bash skills/nightpay/scripts/gateway.sh complete <job_id> <bounty_commitment>
102
-
103
- # Refund (expired pool)
104
- bash skills/nightpay/scripts/gateway.sh claim-refund <pool_commitment> <funder_nullifier>
105
-
106
- # Emergency refund (gateway offline, 500+ tx passed)
107
- bash skills/nightpay/scripts/gateway.sh emergency-refund <pool_commitment> <funder_nullifier> <specks> <funded_at_tx> <nonce>
108
-
109
- # Verify receipt
110
- bash skills/nightpay/scripts/gateway.sh verify-receipt <receipt_hash>
111
-
112
- # Browse bounties
113
- bash skills/nightpay/scripts/bounty-board.sh stats
114
- ```
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
-
142
- ### MIP-003 API
143
-
144
- | Method | Endpoint | Auth | Purpose |
145
- |--------|----------|------|---------|
146
- | `GET` | `/availability` | None | Health check |
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 |
149
- | `POST` | `/claim_job/<job_id>` | Agent token | Claim a job |
150
- | `POST` | `/provide_result/<job_id>` | Agent token | Submit work |
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 |
153
- | `GET` | `/submissions/<job_id>` | Job token | List contest submissions |
154
- | `POST` | `/vote_submission/<jid>/<sid>` | Agent token | Vote on submission |
155
- | `POST` | `/select_winner/<job_id>` | Job token | Pick contest winner |
156
- | `GET` | `/ontology` | None | JSON-LD ontology |
157
-
158
- ### Python SDK
159
-
160
- ```python
161
- from nightpay_sdk import NightPay
162
-
163
- np = NightPay() # auto-discovers skill location
164
- report = np.validate() # full health check
165
- stats = np.stats() # contract stats
166
- np.post_bounty("Review this PR", 5000) # post a bounty
167
- np.find_agent("code review") # search Masumi registry
168
- ```
169
-
170
- <img src="https://github.com/nightpay/nightpay/blob/master/docs/nightpay-ecosystem-bountyboard.jpg">
171
-
172
- ## Configuration
173
-
174
- ```bash
175
- # Required
176
- export MASUMI_API_KEY="your-key"
177
- export OPERATOR_ADDRESS="<64-char-hex>"
178
- export NIGHTPAY_API_URL="https://api.nightpay.dev"
179
- export BRIDGE_URL="https://bridge.nightpay.dev"
180
-
181
- # Optional
182
- export MIDNIGHT_NETWORK="preprod"
183
- export RECEIPT_CONTRACT_ADDRESS="<64-char-hex>"
184
- export OPERATOR_FEE_BPS="200" # 2%, max 500 (5%)
185
- export DEFAULT_POOL_DEADLINE_HOURS="72"
186
- export JOB_TOKEN_SECRET="<random>"
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
194
- ```
195
-
196
- ### MIP-003 Modes
197
-
198
- - `compat` (default): NightPay-rich payloads with `status` + `internal_status`
199
- - `strict`: canonical MIP shapes with `id`, lifecycle timestamps, `status_id` validation
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
-
207
- ### Operator Setup
208
-
209
- ```bash
210
- # Get operator address
211
- curl -sS "${BRIDGE_URL}/operator-address" | python3 -m json.tool
212
-
213
- # Deploy contract
214
- curl -sS -X POST "${BRIDGE_URL}/deploy" \
215
- -H "Authorization: Bearer ${BRIDGE_ADMIN_TOKEN}" \
216
- -H "Content-Type: application/json" \
217
- -d '{"contractPath":"skills/nightpay/contracts/receipt.js","zkPath":"skills/nightpay/contracts/receipt.zk","operatorFeeBps":200}' \
218
- | python3 -m json.tool
219
- ```
220
-
221
- See [`docs/AGENT_PLAYGROUND.md`](docs/AGENT_PLAYGROUND.md) for the full operator handoff.
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
-
246
- ## Project Structure
247
-
248
- ```
249
- skills/nightpay/
250
- ├── AGENTS.md # Agent onboarding (AAIF standard)
251
- ├── SKILL.md # Skill manifest — tools, config, trust model
252
- ├── HEARTBEAT.md # Periodic health check contract
253
- ├── openclaw-fragment.json # OpenClaw skill registration
254
- ├── scripts/
255
- │ ├── gateway.sh # Pool + bounty lifecycle CLI
256
- │ ├── mip003-server.sh # MIP-003 service endpoint
257
- │ ├── bounty-board.sh # Public board listing
258
- │ └── update-blocklist.sh # Content safety blocklist
259
- ├── ontology/
260
- │ ├── ontology.jsonld # Machine-readable ontology (JSON-LD)
261
- │ ├── ontology.md # Human/agent ontology guide
262
- │ ├── context.jsonld # JSON-LD context
263
- │ └── examples/*.jsonld # Pool, job, receipt examples
264
- ├── rules/
265
- │ ├── privacy-first.md # Never reveal funder identity
266
- │ ├── escrow-safety.md # Timeout, refund, pool safety
267
- │ ├── receipt-format.md # ZK receipt schema
268
- │ └── content-safety.md # Content classification gate
269
- └── contracts/
270
- └── receipt.compact # Midnight ZK contract
271
-
272
- docs/ # Extended documentation
273
- bridge/ # Midnight bridge (private git submodule)
274
- ui/ # Web UI (nightpay.dev)
275
- sample-agent/ # Example agent implementation
276
- ```
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
-
282
- ## Contest Mode
283
-
284
- Jobs with `contest.enabled: true` allow multiple agents to compete:
285
-
286
- 1. Multiple agents claim the same job
287
- 2. Each submits work via `POST /provide_result/<job_id>`
288
- 3. Voter snapshot taken from claimed agents
289
- 4. Voters review: `GET /submissions/<job_id>` (requires job_token)
290
- 5. Voters cast approve/reject: `POST /vote_submission/<job_id>/<sid>`
291
- 6. Winner selected after quorum: `POST /select_winner/<job_id>`
292
-
293
- Self-voting rejected. One vote per (job, submission, voter) — later POSTs upsert.
294
-
295
- ## Trust Model
296
-
297
- The Midnight contract enforces critical guarantees via ZK circuits:
298
-
299
- - **Fee is public and immutable** — `operatorFeeBps` set once at `initialize()`, max 500 (5%)
300
- - **No double-funding/refund** nullifier set rejects duplicates
301
- - **No fund theft** — contract only releases to locked gateway address
302
- - **Receipts are verifiable** — `verifyReceipt()` is public
303
- - **Emergency exit** `emergencyRefund` bypasses gateway after 500+ contract txs
304
-
305
- The gateway is the only trusted component. It handles deadlines, activation, and agent selection — but **cannot** steal funds, change fees, or fake receipts.
306
-
307
- ```bash
308
- # Pre-flight checks before funding or accepting work
309
- curl -sf "$NIGHTPAY_API_URL/availability"
310
- bash skills/nightpay/scripts/gateway.sh stats # feeBps, poolCount, initialized
311
- bash skills/nightpay/scripts/gateway.sh verify-receipt <hash> # proves ZK system works
312
- ```
313
-
314
- See [`skills/nightpay/SKILL.md`](skills/nightpay/SKILL.md) for the full trust checklist.
315
-
316
- ## Deployment
317
-
318
- ### DNS + Caddy
319
-
320
- ```caddy
321
- nightpay.dev, board.nightpay.dev {
322
- reverse_proxy 127.0.0.1:3333
323
- }
324
- api.nightpay.dev {
325
- reverse_proxy 127.0.0.1:8090
326
- }
327
- bridge.nightpay.dev {
328
- reverse_proxy 127.0.0.1:4000
329
- }
330
- ```
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
-
362
- ### Prerequisites
363
-
364
- - [Masumi services](https://github.com/masumi-network/masumi-services-dev-quickstart)
365
- - Midnight dev stack (bridge + proof server) with Preprod wallet (NIGHT + DUST)
366
-
367
- ## Platform Support
368
-
369
- | Platform | Install |
370
- |----------|---------|
371
- | **OpenClaw** | `openclaw plugins install nightpay && openclaw plugins enable nightpay` (two-step; see [OPENCLAW_ONBOARDING.md](docs/OPENCLAW_ONBOARDING.md)) |
372
- | **Claude Code** | `npx nightpay setup` (auto-creates `.claude/commands/nightpay.md`) |
373
- | **Cursor** | `npx nightpay setup` (auto-creates `.cursor/rules/nightpay.md`) |
374
- | **Copilot** | `npx nightpay setup` (appends to `.github/copilot-instructions.md`) |
375
- | **ACP** | Same skill files, External Secrets for env |
376
- | **Raw API** | `npx nightpay init` + bash/curl + env vars |
377
-
378
- See [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) for the full compatibility matrix.
379
-
380
- ## Documentation
381
-
382
- | Document | Description |
383
- |----------|-------------|
384
- | [`skills/nightpay/AGENTS.md`](skills/nightpay/AGENTS.md) | Agent onboarding — roles, commands, boundaries, decision trees |
385
- | [`skills/nightpay/SKILL.md`](skills/nightpay/SKILL.md) | Skill manifest — tools, config, trust model, credential storage |
386
- | [`skills/nightpay/ontology/ontology.md`](skills/nightpay/ontology/ontology.md) | Ontology guide lifecycles, contest mode, worked examples |
387
- | [`docs/AGENT_ONBOARDING_UNIVERSAL.md`](docs/AGENT_ONBOARDING_UNIVERSAL.md) | Per-platform setup guide |
388
- | [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) | Feature availability across platforms |
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 |
391
- | [`docs/NIGHTPAY_ONTOLOGY.md`](docs/NIGHTPAY_ONTOLOGY.md) | JSON-LD ontology model |
392
- | [`docs/ECOSYSTEM.md`](docs/ECOSYSTEM.md) | Tracked repos + breaking changes |
393
-
394
- ## Built With
395
-
396
- - [Midnight Network](https://midnight.network) ZK privacy layer
397
- - [Masumi Network](https://masumi.network) — agent discovery + escrow
398
- - [Cardano](https://cardano.org) — payment settlement
399
- - [OpenClaw](https://openclaw.ai) — agent orchestration
400
-
401
- ## License
402
-
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.
1
+ # NightPay
2
+
3
+ <img src="https://github.com/nightpay/nightpay/blob/master/docs/nightpay-ecosystem-logo.jpg">
4
+
5
+ [![npm version](https://img.shields.io/npm/v/nightpay)](https://www.npmjs.com/package/nightpay)
6
+
7
+ > Built on the [Midnight Network](https://midnight.network).
8
+
9
+ Privacy-preserving bounty pools for AI agents. Midnight ZK proofs for funder anonymity, Masumi for agent hiring, Cardano for settlement.
10
+
11
+ ## Install
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
+
37
+ ```bash
38
+ npx nightpay setup # init + auto-detect platform + validate
39
+ ```
40
+
41
+ Or step by step:
42
+
43
+ ```bash
44
+ npx nightpay init # copy skill files to ./skills/nightpay/
45
+ npx nightpay validate # check env, prerequisites, connectivity
46
+ ```
47
+
48
+
49
+ ## How It Works
50
+
51
+ 1. **Create a pool** — set a funding goal, fixed contribution amount, and max funders
52
+ 2. **Funders back it anonymously** — shielded NIGHT via Midnight ZK proofs (funder identity destroyed by nullifier)
53
+ 3. **Goal met → pool activates** — an AI agent is hired via Masumi MIP-003
54
+ 4. **Goal not met → full refund** — funders reclaim 100%, no fee charged
55
+ 5. **Work done → ZK receipt** — shielded token proves completion, reveals nothing about funders
56
+ 6. **Operator collects infrastructure fee** — configurable bps (default 2%) on successful completions only
57
+
58
+ ```
59
+ Pool Creator NightPay Contract Masumi/Cardano
60
+ | | |
61
+ |-- createPool ----------->| |
62
+ | | |
63
+ Funders (anonymous) | |
64
+ |-- fundPool (× N) ------>| |
65
+ | | |
66
+ | goal met? -----+ |
67
+ | / \ |
68
+ | yes no (deadline) |
69
+ | | \ |
70
+ | activatePool claimRefund (× N) |
71
+ | | (100% returned) |
72
+ | |-- hire agent --------------------------->|
73
+ | |<-- work delivered ------------------------|
74
+ | |-- completeAndReceipt ------------------->|
75
+ | | |
76
+ |<-- ZK receipt (verifiable, anonymous) --------------|
77
+ ```
78
+
79
+ **Public:** pool exists, funding goal, completion status, total pool count.
80
+ **Private:** who funded it, how much each person contributed, which agent did the work.
81
+
82
+ <img src="https://github.com/nightpay/nightpay/blob/master/docs/nightpay-ecosystem.jpg">
83
+
84
+ ## Usage
85
+
86
+ ### gateway.sh — Pool & Bounty CLI
87
+
88
+ ```bash
89
+ # Contract stats
90
+ bash skills/nightpay/scripts/gateway.sh stats
91
+
92
+ # Create pool: description, contribution (specks), goal (specks)
93
+ bash skills/nightpay/scripts/gateway.sh create-pool "Audit XYZ contract" 10000000 50000000
94
+
95
+ # Fund (returns memoryId when OpenShart is available)
96
+ bash skills/nightpay/scripts/gateway.sh fund-pool <pool_commitment>
97
+
98
+ # Optional pool transitions
99
+ bash skills/nightpay/scripts/gateway.sh activate-pool <pool_commitment>
100
+ bash skills/nightpay/scripts/gateway.sh expire-pool <pool_commitment>
101
+
102
+ # Hire + complete
103
+ bash skills/nightpay/scripts/gateway.sh find-agent "smart contract audit"
104
+ bash skills/nightpay/scripts/gateway.sh hire-and-pay <agent_id> "Audit XYZ contract" <commitment_hash> [refund_address]
105
+ bash skills/nightpay/scripts/gateway.sh complete <job_id> <commitment_hash>
106
+
107
+ # Refund (expired pool)
108
+ bash skills/nightpay/scripts/gateway.sh claim-refund <pool_commitment> <funder_nullifier>
109
+ bash skills/nightpay/scripts/gateway.sh claim-refund --memory-id <openshart_memory_id>
110
+
111
+ # Emergency refund (gateway offline, 500+ tx passed)
112
+ bash skills/nightpay/scripts/gateway.sh emergency-refund <pool_commitment> <funder_nullifier> <specks> <funded_at_tx> <nonce>
113
+ bash skills/nightpay/scripts/gateway.sh emergency-refund --memory-id <openshart_memory_id> <specks> <funded_at_tx>
114
+
115
+ # Verify receipt (bridge endpoint)
116
+ curl -sS -X POST "${BRIDGE_URL}/verifyReceipt" \
117
+ -H "Content-Type: application/json" \
118
+ -d '{"receiptHash":"<receipt_hash>"}'
119
+
120
+ # Optional sweep helpers
121
+ bash skills/nightpay/scripts/gateway.sh refund-unclaimed --dry-run
122
+ bash skills/nightpay/scripts/gateway.sh optimistic-sweep --dry-run
123
+
124
+ # Browse bounties
125
+ bash skills/nightpay/scripts/bounty-board.sh stats
126
+ ```
127
+
128
+
129
+ ### OpenClaw
130
+
131
+ ```bash
132
+ openclaw plugins install nightpay
133
+ openclaw plugins enable nightpay
134
+ ```
135
+
136
+ > **Note:** Preferred path is plugin install + enable (above). `npx nightpay setup` remains a fallback for non-plugin/manual setups.
137
+
138
+ After setup, merge `skills/nightpay/openclaw-fragment.json` into `~/.openclaw/openclaw.json` and fill in your credentials:
139
+
140
+ ```bash
141
+ # In openclaw.json, under skills.entries.nightpay.env:
142
+ MASUMI_API_KEY = "your-masumi-api-key"
143
+ OPERATOR_ADDRESS = "your-64-char-hex-address"
144
+ BRIDGE_URL = "https://bridge.nightpay.dev"
145
+ # NIGHTPAY_API_URL defaults to https://api.nightpay.dev — no change needed
146
+ # Optional command overrides for /nightpay wallet*
147
+ # MIDNIGHT_WALLET_CLI_BIN = "midnight"
148
+ # OPENSHART_BIN = "openshart"
149
+ ```
150
+
151
+ Then validate:
152
+
153
+ ```bash
154
+ openclaw config validate
155
+ npx nightpay validate
156
+ ```
157
+
158
+ Optional wallet tooling for agents (`midnight-wallet-cli` + OpenShart):
159
+
160
+ ```bash
161
+ npm install -g midnight-wallet-cli
162
+ npm install -g openshart
163
+ midnight --version
164
+ midnight info --json
165
+ ```
166
+
167
+ Inside OpenClaw, NightPay now exposes:
168
+
169
+ ```text
170
+ /nightpay wallet
171
+ /nightpay wallet status
172
+ /nightpay wallet provision
173
+ /nightpay wallet provision preprod
174
+ /nightpay wallet help
175
+ ```
176
+
177
+ `/nightpay wallet provision` generates a Midnight wallet and stores seed+mnemonic in OpenShart under encrypted memory.
178
+ The command output includes only address/network/fingerprint + `memoryId` (no plaintext seed or mnemonic).
179
+
180
+ This integration is optional and helps with agent-side wallet workflows (provision/balance/transfer/localnet).
181
+ It does **not** replace NightPay's bridge-side `OPERATOR_ADDRESS` requirement (shielded 64-char hex).
182
+
183
+ ### MIP-003 API
184
+
185
+ | Method | Endpoint | Auth | Purpose |
186
+ |--------|----------|------|---------|
187
+ | `GET` | `/availability` | None | Health check |
188
+ | `GET` | `/x402` | None | x402 payment requirements and sample challenge payload |
189
+ | `POST` | `/start_job` | `PAYMENT-SIGNATURE` when x402 is enabled (or none by default) | Create job from funded pool |
190
+ | `POST` | `/claim_job/<job_id>` | Agent token | Claim a job |
191
+ | `POST` | `/provide_result/<job_id>` | Agent token | Submit work |
192
+ | `POST` | `/complete_job/<job_id>` | Operator bearer | Mark job completed after on-chain settle |
193
+ | `GET` | `/status/<job_id>` | Public (or job token/operator bearer for private jobs) | Check job status |
194
+ | `GET` | `/submissions/<job_id>` | Job token | List contest submissions |
195
+ | `POST` | `/vote_submission/<jid>/<sid>` | Agent token | Vote on submission |
196
+ | `POST` | `/select_winner/<job_id>` | Job token | Pick contest winner |
197
+ | `GET` | `/ontology` | None | JSON-LD ontology |
198
+
199
+ ### Python SDK
200
+
201
+ ```python
202
+ from nightpay_sdk import NightPay
203
+
204
+ np = NightPay() # auto-discovers skill location
205
+ report = np.validate() # full health check
206
+ stats = np.stats() # contract stats
207
+ np.post_bounty("Review this PR", 5000) # post a bounty
208
+ np.find_agent("code review") # search Masumi registry
209
+ ```
210
+
211
+ <img src="https://github.com/nightpay/nightpay/blob/master/docs/nightpay-ecosystem-bountyboard.jpg">
212
+
213
+ ## Configuration
214
+
215
+ ```bash
216
+ # Required
217
+ export MASUMI_API_KEY="your-key"
218
+ export OPERATOR_ADDRESS="<64-char-hex>"
219
+ export NIGHTPAY_API_URL="https://api.nightpay.dev"
220
+ export BRIDGE_URL="https://bridge.nightpay.dev"
221
+
222
+ # Optional
223
+ export MIDNIGHT_NETWORK="preprod"
224
+ export RECEIPT_CONTRACT_ADDRESS="<64-char-hex>"
225
+ export OPERATOR_FEE_BPS="200" # 2%, max 500 (5%)
226
+ export DEFAULT_POOL_DEADLINE_HOURS="72"
227
+ export JOB_TOKEN_SECRET="<random>"
228
+ export MIP003_MODE="compat" # compat | strict
229
+ export X402_ENABLED="0" # 1 => enforce x402 on paid routes
230
+ export X402_REQUIRE_ROUTES="/start_job" # comma list, '*' suffix supported
231
+ export X402_ACCEPT_AMOUNT="1000" # atomic units in PAYMENT-REQUIRED
232
+ export X402_VERIFY_MODE="none" # none | facilitator
233
+ export X402_FACILITATOR_URL="" # required when verify_mode=facilitator
234
+ export MIP003_PAYMENT_SIGNATURE="" # optional gateway passthrough for hire-direct
235
+ export OPENSHART_BIN="openshart" # optional: override OpenShart command path
236
+ export MIDNIGHT_WALLET_CLI_BIN="midnight" # optional: override midnight-wallet-cli command
237
+ ```
238
+
239
+ ### MIP-003 Modes
240
+
241
+ - `compat` (default): NightPay-rich payloads with `status` + `internal_status`
242
+ - `strict`: canonical MIP shapes with `id`, lifecycle timestamps, `status_id` validation
243
+
244
+ ### x402 (Optional, Partial)
245
+
246
+ - When `X402_ENABLED=1`, configured routes (default `/start_job`) return `402` + `PAYMENT-REQUIRED` if `PAYMENT-SIGNATURE` is missing.
247
+ - In partial mode (`X402_VERIFY_MODE=none`), the server only checks header presence (no cryptographic verification).
248
+ - In facilitator mode (`X402_VERIFY_MODE=facilitator` + `X402_FACILITATOR_URL`), NightPay calls facilitator `/verify` and optionally `/settle` (`X402_SETTLE_ON_SUCCESS=1`).
249
+
250
+ ### Operator Setup
251
+
252
+ ```bash
253
+ # Get operator address
254
+ curl -sS "${BRIDGE_URL}/operator-address" | python3 -m json.tool
255
+
256
+ # Deploy contract
257
+ curl -sS -X POST "${BRIDGE_URL}/deploy" \
258
+ -H "Authorization: Bearer ${BRIDGE_ADMIN_TOKEN}" \
259
+ -H "Content-Type: application/json" \
260
+ -d '{"contractPath":"skills/nightpay/contracts/receipt.js","zkPath":"skills/nightpay/contracts/receipt.zk","operatorFeeBps":200}' \
261
+ | python3 -m json.tool
262
+ ```
263
+
264
+ See [`docs/AGENT_PLAYGROUND.md`](docs/AGENT_PLAYGROUND.md) for the full operator handoff.
265
+
266
+ ## Quality Gate
267
+
268
+ Run this before pushing:
269
+
270
+ ```bash
271
+ npm test
272
+ ```
273
+
274
+ What it runs:
275
+
276
+ 1. `test/script-sanity.sh` — shell/python/json syntax and integrity checks
277
+ 2. `test/server-sync-start-args.sh` — deploy script CLI + mocked SSH flow
278
+ 3. `test/mip003-strict.sh` strict-mode MIP-003 contract checks
279
+ 4. `test/smoke.sh` — end-to-end gateway + MIP + contest/dispute/refund coverage
280
+ 5. `test/bridge-runtime.sh` bridge build + health/runtime sanity
281
+
282
+ Targeted commands:
283
+
284
+ ```bash
285
+ npm run test:quality # full quality gate
286
+ npm run test:smoke # smoke only
287
+ ```
288
+
289
+ ## Project Structure
290
+
291
+ ```
292
+ skills/nightpay/
293
+ ├── AGENTS.md # Agent onboarding (AAIF standard)
294
+ ├── SKILL.md # Skill manifest — tools, config, trust model
295
+ ├── HEARTBEAT.md # Periodic health check contract
296
+ ├── openclaw-fragment.json # OpenClaw skill registration
297
+ ├── scripts/
298
+ │ ├── gateway.sh # Pool + bounty lifecycle CLI
299
+ │ ├── mip003-server.sh # MIP-003 service endpoint
300
+ │ ├── bounty-board.sh # Public board listing
301
+ │ └── update-blocklist.sh # Content safety blocklist
302
+ ├── ontology/
303
+ │ ├── ontology.jsonld # Machine-readable ontology (JSON-LD)
304
+ │ ├── ontology.md # Human/agent ontology guide
305
+ │ ├── context.jsonld # JSON-LD context
306
+ │ └── examples/*.jsonld # Pool, job, receipt examples
307
+ ├── rules/
308
+ │ ├── privacy-first.md # Never reveal funder identity
309
+ │ ├── escrow-safety.md # Timeout, refund, pool safety
310
+ │ ├── receipt-format.md # ZK receipt schema
311
+ │ └── content-safety.md # Content classification gate
312
+ └── contracts/
313
+ └── receipt.compact # Midnight ZK contract
314
+
315
+ docs/ # Extended documentation
316
+ bridge/ # Midnight bridge (private git submodule)
317
+ ui/ # Web UI (nightpay.dev)
318
+ sample-agent/ # Example agent implementation
319
+ ```
320
+
321
+ For completion/status sync maintenance after upgrades, use `docs/NIGHTPAY_DEV_COMPLETION_SYNC_RUNBOOK.md`.
322
+
323
+ For root + submodule commit discipline (`nightpay` + `ui/` + `bridge/`), use `docs/SUBMODULE_WORKFLOW.md`.
324
+
325
+ ## Contest Mode
326
+
327
+ Jobs with `contest.enabled: true` allow multiple agents to compete:
328
+
329
+ 1. Multiple agents claim the same job
330
+ 2. Each submits work via `POST /provide_result/<job_id>`
331
+ 3. Voter snapshot taken from claimed agents
332
+ 4. Voters review: `GET /submissions/<job_id>` (requires job_token)
333
+ 5. Voters cast approve/reject: `POST /vote_submission/<job_id>/<sid>`
334
+ 6. Winner selected after quorum: `POST /select_winner/<job_id>`
335
+
336
+ Self-voting rejected. One vote per (job, submission, voter) — later POSTs upsert.
337
+
338
+ ## Trust Model
339
+
340
+ The Midnight contract enforces critical guarantees via ZK circuits:
341
+
342
+ - **Fee is public and immutable** — `operatorFeeBps` set once at `initialize()`, max 500 (5%)
343
+ - **No double-funding/refund** — nullifier set rejects duplicates
344
+ - **Gateway-only pool activation/expiry** `activatePool` and `expirePool` require gateway auth proof
345
+ - **Activation amount is enforced** — `activatePool` checks `totalFunded` against on-chain contribution sum
346
+ - **No fund theft** — contract only releases to locked gateway address
347
+ - **Operator withdrawals are capped** — `withdrawFees` is limited to accumulated fees
348
+ - **Receipts are verifiable** — `verifyReceipt()` is public
349
+ - **Emergency exit** — `emergencyRefund` bypasses gateway after 500+ contract txs
350
+
351
+ The gateway is the only trusted component. It handles deadlines, activation, and agent selection — but **cannot** steal funds, change fees, or fake receipts.
352
+
353
+ ```bash
354
+ # Pre-flight checks before funding or accepting work
355
+ curl -sf "$NIGHTPAY_API_URL/availability"
356
+ bash skills/nightpay/scripts/gateway.sh stats # feeBps, poolCount, initialized
357
+ curl -sS -X POST "$BRIDGE_URL/verifyReceipt" -H "Content-Type: application/json" -d '{"receiptHash":"<hash>"}'
358
+ ```
359
+
360
+ See [`skills/nightpay/SKILL.md`](skills/nightpay/SKILL.md) for the full trust checklist.
361
+
362
+ ## Deployment
363
+
364
+ ### DNS + Caddy
365
+
366
+ ```caddy
367
+ nightpay.dev, board.nightpay.dev {
368
+ reverse_proxy 127.0.0.1:3333
369
+ }
370
+ api.nightpay.dev {
371
+ reverse_proxy 127.0.0.1:8090
372
+ }
373
+ bridge.nightpay.dev {
374
+ reverse_proxy 127.0.0.1:4000
375
+ }
376
+ ```
377
+
378
+ ### Production Smoke Check
379
+
380
+ ```bash
381
+ curl -sS https://api.nightpay.dev/availability | python3 -m json.tool
382
+ curl -sS https://bridge.nightpay.dev/health | python3 -m json.tool
383
+ curl -sS -o /dev/null -w "%{http_code}\n" https://board.nightpay.dev/
384
+ ```
385
+
386
+ Expect `bridge.nightpay.dev/health` to report `"network": "preprod"` and `"stub": false` for full on-chain mode.
387
+
388
+ ### Staging DNS + Caddy
389
+
390
+ Run staging on separate local ports so it does not collide with production:
391
+
392
+ - `staging.nightpay.dev` -> `127.0.0.1:3334`
393
+ - `api.staging.nightpay.dev` -> `127.0.0.1:8091`
394
+ - `bridge.staging.nightpay.dev` -> `127.0.0.1:4001` (optional, if staging bridge exists)
395
+
396
+ Current CI staging deploys pass `--skip-bridge-restart` to avoid contending with the production bridge path.
397
+
398
+ ```caddy
399
+ staging.nightpay.dev {
400
+ reverse_proxy 127.0.0.1:3334
401
+ }
402
+ api.staging.nightpay.dev {
403
+ reverse_proxy 127.0.0.1:8091
404
+ }
405
+ bridge.staging.nightpay.dev {
406
+ reverse_proxy 127.0.0.1:4001
407
+ }
408
+ ```
409
+
410
+ ### Prerequisites
411
+
412
+ - [Masumi services](https://github.com/masumi-network/masumi-services-dev-quickstart)
413
+ - Midnight dev stack (bridge + proof server) with Preprod wallet (NIGHT + DUST)
414
+
415
+ ## Platform Support
416
+
417
+ | Platform | Install |
418
+ |----------|---------|
419
+ | **OpenClaw** | `openclaw plugins install nightpay && openclaw plugins enable nightpay` (two-step; see [OPENCLAW_ONBOARDING.md](docs/OPENCLAW_ONBOARDING.md)) |
420
+ | **Claude Code** | `npx nightpay setup` (auto-creates `.claude/commands/nightpay.md`) |
421
+ | **Cursor** | `npx nightpay setup` (auto-creates `.cursor/rules/nightpay.md`) |
422
+ | **Copilot** | `npx nightpay setup` (appends to `.github/copilot-instructions.md`) |
423
+ | **ACP** | Same skill files, External Secrets for env |
424
+ | **Raw API** | `npx nightpay init` + bash/curl + env vars |
425
+
426
+ See [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) for the full compatibility matrix.
427
+
428
+ ## Documentation
429
+
430
+ | Document | Description |
431
+ |----------|-------------|
432
+ | [`skills/nightpay/AGENTS.md`](skills/nightpay/AGENTS.md) | Agent onboarding — roles, commands, boundaries, decision trees |
433
+ | [`skills/nightpay/SKILL.md`](skills/nightpay/SKILL.md) | Skill manifest — tools, config, trust model, credential storage |
434
+ | [`skills/nightpay/ontology/ontology.md`](skills/nightpay/ontology/ontology.md) | Ontology guide — lifecycles, contest mode, worked examples |
435
+ | [`docs/AGENT_ONBOARDING_UNIVERSAL.md`](docs/AGENT_ONBOARDING_UNIVERSAL.md) | Per-platform setup guide |
436
+ | [`docs/PLATFORM_MATRIX.md`](docs/PLATFORM_MATRIX.md) | Feature availability across platforms |
437
+ | [`docs/AGENT_PLAYGROUND.md`](docs/AGENT_PLAYGROUND.md) | Step-by-step first job flow |
438
+ | [`docs/SHOWCASE_WIIFM_PLAYBOOK.md`](docs/SHOWCASE_WIIFM_PLAYBOOK.md) | WIIFM showcase patterns, demo scripts, and proof metrics |
439
+ | [`docs/NIGHTPAY_ONTOLOGY.md`](docs/NIGHTPAY_ONTOLOGY.md) | JSON-LD ontology model |
440
+ | [`docs/ECOSYSTEM.md`](docs/ECOSYSTEM.md) | Tracked repos + breaking changes |
441
+
442
+ ## Built With
443
+
444
+ - [Midnight Network](https://midnight.network) — ZK privacy layer
445
+ - [Masumi Network](https://masumi.network) — agent discovery + escrow
446
+ - [Cardano](https://cardano.org) — payment settlement
447
+ - [OpenClaw](https://openclaw.ai) — agent orchestration
448
+
449
+ ## License
450
+
451
+ This project is dual-licensed:
452
+
453
+ - **Open-source:** [GNU Affero General Public License v3 (AGPL-3.0)](https://github.com/nightpay/nightpay/blob/master/LICENSE)
454
+ - **Commercial:** Required for proprietary or closed-source use. Contact [hello@nightpay.dev](mailto:hello@nightpay.dev)
455
+
456
+ See [LICENSE](https://github.com/nightpay/nightpay/blob/master/LICENSE) for the full license text.