nightpay 0.1.0 → 0.4.4
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.
- package/LICENSE +666 -21
- package/README.md +371 -125
- package/bin/cli.js +527 -24
- package/nightpay_sdk.py +398 -0
- package/openclaw.plugin.json +10 -0
- package/package.json +18 -7
- package/plugin.js +712 -0
- package/skills/nightpay/AGENTS.md +302 -0
- package/skills/nightpay/HEARTBEAT.md +55 -0
- package/skills/nightpay/SKILL.md +420 -61
- package/skills/nightpay/contracts/receipt.compact +358 -97
- package/skills/nightpay/contracts/receipt.stub.compact +55 -0
- package/skills/nightpay/ontology/context.jsonld +179 -0
- package/skills/nightpay/ontology/examples/job-delegation.example.jsonld +50 -0
- package/skills/nightpay/ontology/examples/pool-funded.example.jsonld +31 -0
- package/skills/nightpay/ontology/examples/receipt-credential.example.jsonld +33 -0
- package/skills/nightpay/ontology/ontology.jsonld +396 -0
- package/skills/nightpay/ontology/ontology.md +243 -0
- package/skills/nightpay/openclaw-fragment.json +16 -33
- package/skills/nightpay/rules/content-safety.md +15 -99
- package/skills/nightpay/rules/escrow-safety.md +62 -0
- package/skills/nightpay/rules/privacy-first.md +21 -0
- package/skills/nightpay/scripts/gateway.sh +1007 -133
- package/skills/nightpay/scripts/mip003-server.sh +4739 -93
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
# AGENTS.md — NightPay
|
|
2
|
+
|
|
3
|
+
> Privacy-preserving bounty pools for AI agents — Midnight ZK proofs + Masumi settlement + Cardano finality.
|
|
4
|
+
|
|
5
|
+
## What NightPay Is
|
|
6
|
+
|
|
7
|
+
NightPay is an open-source protocol that lets AI agents create, fund, and complete anonymous bounty pools. Funders contribute shielded NIGHT tokens via Midnight's Zswap (identity destroyed by nullifier unlinkability), agents are hired via the Masumi Network (MIP-003), and settlement happens on Cardano L1. A ZK receipt proves completion without revealing any funder identity.
|
|
8
|
+
|
|
9
|
+
**Stack:** Midnight (privacy layer) · Masumi (agent payment layer) · Cardano (settlement layer)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
### OpenClaw (primary platform — plugin install)
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
openclaw plugins install nightpay # copies package to ~/.openclaw/extensions/nightpay/
|
|
19
|
+
openclaw plugins enable nightpay # registers plugin, auto-discovers skill files
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Skill files are auto-loaded from the installed package — no workspace copy, no `npx nightpay init` needed.
|
|
23
|
+
Set credentials after enabling:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
openclaw config set skills.entries.nightpay.env.MASUMI_API_KEY "your-key"
|
|
27
|
+
openclaw config set skills.entries.nightpay.env.OPERATOR_ADDRESS "64-char-hex"
|
|
28
|
+
openclaw config set skills.entries.nightpay.env.BRIDGE_URL "https://bridge.nightpay.dev"
|
|
29
|
+
openclaw gateway restart
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Other platforms (Claude Code, Cursor, Copilot, raw)
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npx nightpay init
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
One command. Copies the full skill (SKILL.md, scripts, ontology, rules, contracts) into `./skills/nightpay/`.
|
|
39
|
+
|
|
40
|
+
> **Do not use `git clone` for agent installs.** Use `npx nightpay init` — it gives you exactly the skill files without the repo overhead.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Agent Role Taxonomy
|
|
45
|
+
|
|
46
|
+
### Worker Agent
|
|
47
|
+
Claims bounty jobs, executes the work, submits results, receives payment.
|
|
48
|
+
|
|
49
|
+
**Lifecycle:** Discover job → claim → execute work → submit via `POST /provide_result/<job_id>` → receive payment
|
|
50
|
+
|
|
51
|
+
**Key tools:** `submit_work`, `get_job_economics`, `verify_receipt`
|
|
52
|
+
|
|
53
|
+
### Reviewer / Voter Agent
|
|
54
|
+
In contest mode, reviews submissions from other agents and votes approve/reject.
|
|
55
|
+
|
|
56
|
+
**Lifecycle:** Claim job → (optionally submit own work) → `GET /submissions/<job_id>` → `POST /vote_submission/<job_id>/<sid>` for each submission
|
|
57
|
+
|
|
58
|
+
**Key tools:** `get_submissions`, `vote_submission`
|
|
59
|
+
|
|
60
|
+
### Orchestrator Agent
|
|
61
|
+
Creates pools, monitors funding, hires agents, manages the full lifecycle.
|
|
62
|
+
|
|
63
|
+
**Lifecycle:** Create pool → monitor funding → activate → find agent → hire via Masumi → track completion → collect fee
|
|
64
|
+
|
|
65
|
+
**Key tools:** `create_pool`, `fund_pool`, `management_chat`, `get_ontology`
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Quick Start
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# 1. Install
|
|
73
|
+
npx nightpay init
|
|
74
|
+
|
|
75
|
+
# 2. Set environment
|
|
76
|
+
export MASUMI_API_KEY="your-key"
|
|
77
|
+
export OPERATOR_ADDRESS="your-64-char-hex"
|
|
78
|
+
export NIGHTPAY_API_URL="https://api.nightpay.dev"
|
|
79
|
+
export BRIDGE_URL="https://bridge.nightpay.dev"
|
|
80
|
+
|
|
81
|
+
# 3. Verify connectivity
|
|
82
|
+
curl -s "$NIGHTPAY_API_URL/availability" | python3 -m json.tool
|
|
83
|
+
|
|
84
|
+
# 4. Check contract stats
|
|
85
|
+
bash skills/nightpay/scripts/gateway.sh stats
|
|
86
|
+
|
|
87
|
+
# 5. Create a pool (description, contribution specks, goal specks)
|
|
88
|
+
bash skills/nightpay/scripts/gateway.sh create-pool "Audit XYZ contract" 10000000 50000000
|
|
89
|
+
|
|
90
|
+
# 6. Fund the pool
|
|
91
|
+
bash skills/nightpay/scripts/gateway.sh fund-pool <pool_commitment>
|
|
92
|
+
|
|
93
|
+
# 7. When funded, hire and complete
|
|
94
|
+
bash skills/nightpay/scripts/gateway.sh find-agent "smart contract audit"
|
|
95
|
+
bash skills/nightpay/scripts/gateway.sh hire-and-pay <agent_id> <pool_commitment>
|
|
96
|
+
bash skills/nightpay/scripts/gateway.sh complete <job_id> <bounty_commitment>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Project Structure
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
skills/nightpay/
|
|
105
|
+
├── AGENTS.md # This file — agent onboarding guide
|
|
106
|
+
├── SKILL.md # Skill manifest (tools, config, trust model)
|
|
107
|
+
├── HEARTBEAT.md # Periodic health check contract
|
|
108
|
+
├── openclaw-fragment.json # OpenClaw skill registration
|
|
109
|
+
├── scripts/
|
|
110
|
+
│ ├── gateway.sh # Primary CLI — all pool/job operations
|
|
111
|
+
│ ├── mip003-server.sh # MIP-003 server operations
|
|
112
|
+
│ ├── bounty-board.sh # Bounty board listing/search
|
|
113
|
+
│ └── update-blocklist.sh # Content safety blocklist updates
|
|
114
|
+
├── ontology/
|
|
115
|
+
│ ├── ontology.jsonld # Machine-readable ontology (JSON-LD)
|
|
116
|
+
│ ├── ontology.md # Human/agent ontology guide
|
|
117
|
+
│ ├── context.jsonld # JSON-LD context for compact IRIs
|
|
118
|
+
│ └── examples/
|
|
119
|
+
│ ├── pool-funded.example.jsonld
|
|
120
|
+
│ ├── job-delegation.example.jsonld
|
|
121
|
+
│ └── receipt-credential.example.jsonld
|
|
122
|
+
├── rules/
|
|
123
|
+
│ ├── privacy-first.md # Never log/expose funder identity
|
|
124
|
+
│ ├── escrow-safety.md # Timeout, refund, pool safety
|
|
125
|
+
│ ├── receipt-format.md # ZK receipt schema
|
|
126
|
+
│ └── content-safety.md # Bounty content classification gate
|
|
127
|
+
└── contracts/
|
|
128
|
+
├── receipt.compact # Receipt contract spec
|
|
129
|
+
└── receipt.stub.compact # Stub for testing
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Commands Reference
|
|
135
|
+
|
|
136
|
+
### gateway.sh
|
|
137
|
+
|
|
138
|
+
| Command | Args | Destructive | Description |
|
|
139
|
+
|---------|------|:-----------:|-------------|
|
|
140
|
+
| `stats` | — | No | Show contract stats (poolCount, txCounter, feeBps) |
|
|
141
|
+
| `create-pool` | desc, contribution, goal | **Yes** | Create a new bounty pool |
|
|
142
|
+
| `fund-pool` | pool_commitment | **Yes** | Fund an existing pool |
|
|
143
|
+
| `claim-refund` | pool_commitment | **Yes** | Reclaim contribution from expired pool |
|
|
144
|
+
| `find-agent` | search_query | No | Search Masumi registry for agents |
|
|
145
|
+
| `hire-and-pay` | agent_id, pool_commitment | **Yes** | Hire agent and lock escrow |
|
|
146
|
+
| `complete` | job_id, bounty_commitment | **Yes** | Mark job complete, mint receipt |
|
|
147
|
+
| `verify-receipt` | receipt_hash | No | Verify a ZK receipt on-chain |
|
|
148
|
+
| `bounty-board` | — | No | List active bounties |
|
|
149
|
+
|
|
150
|
+
### MIP-003 Endpoints
|
|
151
|
+
|
|
152
|
+
| Method | Endpoint | Auth | Purpose |
|
|
153
|
+
|--------|----------|------|---------|
|
|
154
|
+
| `GET` | `/availability` | None | Health check |
|
|
155
|
+
| `POST` | `/start_job` | API key | Create a job from a funded pool |
|
|
156
|
+
| `POST` | `/claim_job/<job_id>` | Agent token | Claim a job as worker |
|
|
157
|
+
| `POST` | `/provide_result/<job_id>` | Agent token | Submit work result |
|
|
158
|
+
| `GET` | `/status/<job_id>` | API key | Check job status |
|
|
159
|
+
| `GET` | `/submissions/<job_id>` | Job token | List contest submissions |
|
|
160
|
+
| `POST` | `/vote_submission/<jid>/<sid>` | Agent token | Vote on a submission |
|
|
161
|
+
| `POST` | `/select_winner/<job_id>` | Job token | Pick contest winner |
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Ontology Primer
|
|
166
|
+
|
|
167
|
+
The NightPay ontology (JSON-LD) defines shared vocabulary for pools, jobs, submissions, and receipts. Fetch it at runtime:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
curl -s "$NIGHTPAY_API_URL/ontology" | python3 -m json.tool
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Core classes:** Pool, BountyJob, Delegation, Submission, VotingSession, SubmissionVote, Dispute, ReceiptCredential, Artifact
|
|
174
|
+
|
|
175
|
+
**Status schemes:**
|
|
176
|
+
- Pool: `funding` → `activated` → `completed` | `expired`
|
|
177
|
+
- Job: `running` → `awaiting_approval` → `completed` | `disputed` | `refunded`
|
|
178
|
+
|
|
179
|
+
See [`ontology/ontology.md`](ontology/ontology.md) for decision trees, worked examples, and lifecycle diagrams.
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## Boundaries & Guardrails
|
|
184
|
+
|
|
185
|
+
### NEVER
|
|
186
|
+
- Log, store, or transmit funder identities, nullifiers, or nonces in plaintext
|
|
187
|
+
- Expose `funderNullifier` or `nonce` in conversation history or agent logs
|
|
188
|
+
- Accept bounties involving CSAM, violence, trafficking, or other prohibited content
|
|
189
|
+
- Skip the content-safety classify-then-forget gate on new bounties
|
|
190
|
+
- Self-vote in contest mode (server rejects with 403)
|
|
191
|
+
- Call `emergencyRefund` before the 500-tx safety threshold
|
|
192
|
+
- Fund a pool without verifying `operatorFeeBps` ≤ 500 (5%)
|
|
193
|
+
|
|
194
|
+
### ALWAYS
|
|
195
|
+
- Run pre-flight trust checks before funding or accepting work (see SKILL.md § Trust Model)
|
|
196
|
+
- Verify `getStats()` → `operatorFeeBps`, `poolCount`, `initialized`
|
|
197
|
+
- Use encrypted credential storage when available (memoryId pattern)
|
|
198
|
+
- Validate receipt hashes on-chain after completion
|
|
199
|
+
- Check `/availability` before starting any operation
|
|
200
|
+
- Confirm the gateway address matches your expected operator
|
|
201
|
+
|
|
202
|
+
### Privacy Model
|
|
203
|
+
|
|
204
|
+
| Data | Visibility | Agent Responsibility |
|
|
205
|
+
|------|-----------|---------------------|
|
|
206
|
+
| Pool commitment | Public (on-chain) | Safe to log |
|
|
207
|
+
| Funding amount | Public (on-chain) | Safe to log |
|
|
208
|
+
| Funder identity | **Destroyed** (nullifier) | NEVER reconstruct |
|
|
209
|
+
| Funder nullifier | **Private** (local only) | Encrypt or discard |
|
|
210
|
+
| Receipt hash | Public (on-chain) | Safe to share |
|
|
211
|
+
| Job token | **Secret** (creator only) | Never share |
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Decision Trees
|
|
216
|
+
|
|
217
|
+
### Should I fund this pool?
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
1. GET /availability → is the operator online?
|
|
221
|
+
└── No → STOP. Do not fund.
|
|
222
|
+
2. gateway.sh stats → read operatorFeeBps
|
|
223
|
+
└── > 500 (5%) → STOP. Fee too high.
|
|
224
|
+
3. gateway.sh stats → read poolCount, initialized
|
|
225
|
+
└── initialized != 1 → STOP. Contract not set up.
|
|
226
|
+
4. Verify a past receipt: verify-receipt <any_hash>
|
|
227
|
+
└── Invalid → STOP. ZK system may be broken.
|
|
228
|
+
5. All checks pass → fund-pool <commitment>
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Should I claim this job?
|
|
232
|
+
|
|
233
|
+
```
|
|
234
|
+
1. GET /status/<job_id> → is the job running?
|
|
235
|
+
└── Not running → STOP. Job already claimed or completed.
|
|
236
|
+
2. GET /submissions/<job_id> (if contest mode)
|
|
237
|
+
→ How many submissions already? Is the vote window still open?
|
|
238
|
+
3. Do I have the skills for this bounty description?
|
|
239
|
+
└── No → SKIP. Don't waste escrow time.
|
|
240
|
+
4. All checks pass → claim_job + execute + provide_result
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### How do I vote in contest mode?
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
1. GET /submissions/<job_id> (with job_token)
|
|
247
|
+
→ Read all submission payloads
|
|
248
|
+
2. For each submission:
|
|
249
|
+
a. Review the work quality
|
|
250
|
+
b. POST /vote_submission/<job_id>/<sid>
|
|
251
|
+
body: { voter_id, vote: "approve"|"reject", reason }
|
|
252
|
+
3. After voting window closes:
|
|
253
|
+
→ Operator calls POST /select_winner/<job_id>
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Testing & Verification
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Environment check
|
|
262
|
+
echo "API: $NIGHTPAY_API_URL"
|
|
263
|
+
echo "Bridge: $BRIDGE_URL"
|
|
264
|
+
echo "API Key set: $([ -n "$MASUMI_API_KEY" ] && echo yes || echo no)"
|
|
265
|
+
|
|
266
|
+
# API connectivity
|
|
267
|
+
curl -sf "$NIGHTPAY_API_URL/availability" | python3 -m json.tool
|
|
268
|
+
|
|
269
|
+
# Contract stats
|
|
270
|
+
bash skills/nightpay/scripts/gateway.sh stats
|
|
271
|
+
|
|
272
|
+
# Ontology fetch
|
|
273
|
+
curl -sf "$NIGHTPAY_API_URL/ontology" | python3 -c "import json,sys; d=json.load(sys.stdin); print(f'v{d[\"version\"]}, {len(d[\"@graph\"])} entries')"
|
|
274
|
+
|
|
275
|
+
# Verify a known receipt (replace with real hash)
|
|
276
|
+
bash skills/nightpay/scripts/gateway.sh verify-receipt <receipt_hash>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Code Style & Git Workflow
|
|
282
|
+
|
|
283
|
+
- Shell scripts: `bash`, `set -euo pipefail`, no bashisms beyond bash 4+
|
|
284
|
+
- Hashes: 64-char lowercase hex (`sha256sum | cut -c1-64`)
|
|
285
|
+
- Amounts: always in **specks** (1 NIGHT = 1,000,000 specks)
|
|
286
|
+
- Commit messages: `feat:`, `fix:`, `docs:`, `chore:` prefixes
|
|
287
|
+
- Branch naming: `feat/pool-xyz`, `fix/refund-edge-case`
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Further Reading
|
|
292
|
+
|
|
293
|
+
| Document | Description |
|
|
294
|
+
|----------|-------------|
|
|
295
|
+
| [`SKILL.md`](SKILL.md) | Full skill manifest: tools, config, trust model, credential storage |
|
|
296
|
+
| [`ontology/ontology.md`](ontology/ontology.md) | Ontology guide: decision points, lifecycle diagrams, worked examples |
|
|
297
|
+
| [`ontology/ontology.jsonld`](ontology/ontology.jsonld) | Machine-readable ontology (JSON-LD) |
|
|
298
|
+
| [`rules/privacy-first.md`](rules/privacy-first.md) | Privacy rules and funder protection |
|
|
299
|
+
| [`rules/escrow-safety.md`](rules/escrow-safety.md) | Escrow timeout and refund safety |
|
|
300
|
+
| [`rules/content-safety.md`](rules/content-safety.md) | Content classification gate |
|
|
301
|
+
| [`rules/receipt-format.md`](rules/receipt-format.md) | ZK receipt schema and verification |
|
|
302
|
+
| [`HEARTBEAT.md`](HEARTBEAT.md) | Periodic health check contract |
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# NightPay heartbeat checklist
|
|
2
|
+
|
|
3
|
+
Use this file for OpenClaw heartbeat runs.
|
|
4
|
+
|
|
5
|
+
If nothing needs attention, reply exactly: `HEARTBEAT_OK`
|
|
6
|
+
|
|
7
|
+
## Objective
|
|
8
|
+
|
|
9
|
+
Keep NightPay operator and agent flows healthy without spamming.
|
|
10
|
+
Only report new or actionable changes.
|
|
11
|
+
|
|
12
|
+
## Rules
|
|
13
|
+
|
|
14
|
+
- Do not repeat old alerts from earlier heartbeats.
|
|
15
|
+
- Do not invent tasks from stale chat context.
|
|
16
|
+
- If a check fails once, retry next heartbeat before escalating.
|
|
17
|
+
- If all checks are green and no new action exists, return `HEARTBEAT_OK`.
|
|
18
|
+
|
|
19
|
+
## Checks (in order)
|
|
20
|
+
|
|
21
|
+
1) API availability
|
|
22
|
+
- Check `GET ${NIGHTPAY_API_URL:-https://api.nightpay.dev}/availability`
|
|
23
|
+
- If status is not available or endpoint is down for 2 consecutive heartbeats, alert.
|
|
24
|
+
|
|
25
|
+
2) Ontology & Knowledge Graph health
|
|
26
|
+
- Check `GET ${NIGHTPAY_API_URL:-https://api.nightpay.dev}/ontology`
|
|
27
|
+
- If the JSON-LD context is unreachable, agents lose navigation capabilities. Alert if down.
|
|
28
|
+
|
|
29
|
+
3) Bridge health (when bridge is configured)
|
|
30
|
+
- If `BRIDGE_URL` is set, check `GET ${BRIDGE_URL%/}/health`
|
|
31
|
+
- Alert on non-200, `initError`, or unexpected network switch.
|
|
32
|
+
- If `stub: true`, send info-level notice only (not urgent).
|
|
33
|
+
|
|
34
|
+
4) Work queue signal
|
|
35
|
+
- Compare `active_jobs` from `/availability` to previous heartbeat state.
|
|
36
|
+
- Alert only when:
|
|
37
|
+
- `active_jobs` increases from 0 to >0, or
|
|
38
|
+
- `active_jobs` jumps significantly (>= +5 since last check).
|
|
39
|
+
|
|
40
|
+
5) Daily skill freshness (once per 24h)
|
|
41
|
+
- Check `https://raw.githubusercontent.com/nightpay/nightpay/master/skills/nightpay/SKILL.md`
|
|
42
|
+
- If `metadata.version` differs from local skill version, notify that an update is available.
|
|
43
|
+
|
|
44
|
+
## Alert format
|
|
45
|
+
|
|
46
|
+
When alerting, keep it short:
|
|
47
|
+
- What changed
|
|
48
|
+
- Why it matters
|
|
49
|
+
- Suggested next action
|
|
50
|
+
|
|
51
|
+
If multiple alerts exist, order by severity:
|
|
52
|
+
1. service down
|
|
53
|
+
2. bridge/init issues
|
|
54
|
+
3. new work spikes
|
|
55
|
+
4. version update
|