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/scripts/setup.sh DELETED
@@ -1,489 +0,0 @@
1
- #!/usr/bin/env bash
2
- # nightpay setup — one-command onboarding for any agent platform
3
- #
4
- # Detects your platform, copies skill files, validates env,
5
- # runs health check. Zero manual steps.
6
- #
7
- # Usage:
8
- # bash setup.sh # auto-detect platform
9
- # bash setup.sh --platform openclaw
10
- # bash setup.sh --platform claude-code
11
- # bash setup.sh --platform cursor
12
- # bash setup.sh --platform copilot
13
- # bash setup.sh --platform raw
14
- # bash setup.sh --validate-only # just check env + health
15
- # bash setup.sh --help
16
- #
17
- # Environment:
18
- # NIGHTPAY_WORKSPACE Override target directory (default: auto-detect)
19
- # MASUMI_API_KEY Required — Masumi payment API key
20
- # OPERATOR_ADDRESS Required — 64-char hex Midnight operator address
21
- # NIGHTPAY_API_URL Required — Deployed MIP-003 API base URL
22
- # BRIDGE_URL Recommended — Midnight bridge URL
23
-
24
- set -euo pipefail
25
-
26
- # ─── Colors (disabled when not a TTY) ─────────────────────────────────────────
27
- if [[ -t 2 ]]; then
28
- RED=$'\e[31m'; GREEN=$'\e[32m'; YELLOW=$'\e[33m'
29
- CYAN=$'\e[36m'; BOLD=$'\e[1m'; DIM=$'\e[2m'; RESET=$'\e[0m'
30
- CHECK="✅"; CROSS="❌"; WARN="⚠️"; ARROW="→"
31
- else
32
- RED=''; GREEN=''; YELLOW=''; CYAN=''; BOLD=''; DIM=''; RESET=''
33
- CHECK="OK"; CROSS="FAIL"; WARN="WARN"; ARROW="->"
34
- fi
35
-
36
- # ─── Script location ──────────────────────────────────────────────────────────
37
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38
- REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
39
- SKILL_SRC="$REPO_ROOT/skills/nightpay"
40
-
41
- # ─── Defaults ─────────────────────────────────────────────────────────────────
42
- PLATFORM=""
43
- VALIDATE_ONLY=false
44
- ERRORS=0
45
- WARNINGS=0
46
-
47
- # ─── Usage ────────────────────────────────────────────────────────────────────
48
- usage() {
49
- cat <<HELP
50
- ${BOLD}nightpay setup${RESET} — one-command agent onboarding
51
-
52
- ${BOLD}USAGE${RESET}
53
- bash setup.sh [OPTIONS]
54
-
55
- ${BOLD}OPTIONS${RESET}
56
- --platform <name> Force platform: openclaw, claude-code, cursor, copilot, raw
57
- --validate-only Skip install, just validate env + connectivity
58
- --workspace <path> Override target directory
59
- --help This message
60
-
61
- ${BOLD}EXAMPLES${RESET}
62
- bash setup.sh # auto-detect and install
63
- bash setup.sh --platform claude-code # force Claude Code setup
64
- bash setup.sh --validate-only # just check everything works
65
-
66
- ${BOLD}ENVIRONMENT${RESET}
67
- MASUMI_API_KEY ${RED}Required${RESET} Masumi payment API key
68
- OPERATOR_ADDRESS ${RED}Required${RESET} Midnight operator shielded address
69
- NIGHTPAY_API_URL ${RED}Required${RESET} Deployed MIP-003 API URL
70
- BRIDGE_URL ${YELLOW}Recommended${RESET} Midnight bridge URL
71
- MIDNIGHT_NETWORK ${DIM}Optional${RESET} preprod (default) or mainnet
72
- HELP
73
- exit 0
74
- }
75
-
76
- # ─── Parse args ───────────────────────────────────────────────────────────────
77
- while [[ $# -gt 0 ]]; do
78
- case "$1" in
79
- --platform) PLATFORM="$2"; shift 2 ;;
80
- --validate-only) VALIDATE_ONLY=true; shift ;;
81
- --workspace) NIGHTPAY_WORKSPACE="$2"; shift 2 ;;
82
- --help|-h) usage ;;
83
- *) echo "${RED}Unknown option: $1${RESET}"; usage ;;
84
- esac
85
- done
86
-
87
- # ─── Platform detection ───────────────────────────────────────────────────────
88
- detect_platform() {
89
- if [[ -n "$PLATFORM" ]]; then
90
- echo "$PLATFORM"
91
- return
92
- fi
93
-
94
- # Check for OpenClaw
95
- if command -v openclaw &>/dev/null; then
96
- echo "openclaw"
97
- return
98
- fi
99
-
100
- # Check for Claude Code markers
101
- if [[ -d ".claude" ]] || [[ -f ".claude/settings.json" ]]; then
102
- echo "claude-code"
103
- return
104
- fi
105
-
106
- # Check for Cursor markers
107
- if [[ -d ".cursor" ]] || [[ -f ".cursorrules" ]]; then
108
- echo "cursor"
109
- return
110
- fi
111
-
112
- # Check for Copilot markers
113
- if [[ -d ".github" ]] && [[ -f ".github/copilot-instructions.md" ]]; then
114
- echo "copilot"
115
- return
116
- fi
117
-
118
- # Default to raw
119
- echo "raw"
120
- }
121
-
122
- # ─── Logging ──────────────────────────────────────────────────────────────────
123
- info() { echo " ${CYAN}${ARROW}${RESET} $*"; }
124
- ok() { echo " ${GREEN}${CHECK}${RESET} $*"; }
125
- warn() { echo " ${YELLOW}${WARN}${RESET} $*"; ((WARNINGS++)); }
126
- fail() { echo " ${RED}${CROSS}${RESET} $*"; ((ERRORS++)); }
127
-
128
- header() {
129
- echo ""
130
- echo "${BOLD}$*${RESET}"
131
- echo "${DIM}$(printf '%.0s─' $(seq 1 ${#1}))${RESET}"
132
- }
133
-
134
- # ─── Prerequisite check ──────────────────────────────────────────────────────
135
- check_prerequisites() {
136
- header "Checking prerequisites"
137
-
138
- local bins=(bash curl openssl sqlite3)
139
- for bin in "${bins[@]}"; do
140
- if command -v "$bin" &>/dev/null; then
141
- ok "$bin found: $(command -v "$bin")"
142
- else
143
- fail "$bin not found — required by gateway.sh"
144
- fi
145
- done
146
-
147
- # sha256sum or shasum
148
- if command -v sha256sum &>/dev/null; then
149
- ok "sha256sum found"
150
- elif command -v shasum &>/dev/null; then
151
- ok "shasum found (macOS — compatible)"
152
- else
153
- fail "sha256sum/shasum not found — required for hash verification"
154
- fi
155
- }
156
-
157
- # ─── Env validation ──────────────────────────────────────────────────────────
158
- validate_env() {
159
- header "Validating environment variables"
160
-
161
- # Required vars
162
- local required_vars=("MASUMI_API_KEY" "OPERATOR_ADDRESS" "NIGHTPAY_API_URL" "BRIDGE_URL")
163
- local required_labels=("Masumi API key" "Operator address" "NightPay API URL" "Bridge URL")
164
-
165
- for i in "${!required_vars[@]}"; do
166
- local var="${required_vars[$i]}"
167
- local label="${required_labels[$i]}"
168
- local val="${!var:-}"
169
-
170
- if [[ -z "$val" ]]; then
171
- fail "$var not set — $label is required"
172
- elif [[ "$val" == "$var" ]]; then
173
- fail "$var is set to placeholder value '$var' — replace with real value"
174
- else
175
- # Sanity checks per var
176
- case "$var" in
177
- OPERATOR_ADDRESS)
178
- if [[ ${#val} -ne 64 ]] || ! [[ "$val" =~ ^[0-9a-fA-F]+$ ]]; then
179
- warn "$var doesn't look like a 64-char hex address (got ${#val} chars)"
180
- else
181
- ok "$var set (${val:0:8}...${val: -4})"
182
- fi
183
- ;;
184
- NIGHTPAY_API_URL|BRIDGE_URL)
185
- if [[ "$val" == *"localhost"* ]]; then
186
- warn "$var points to localhost ($val) — only valid if stack runs locally"
187
- else
188
- ok "$var set ($val)"
189
- fi
190
- ;;
191
- *)
192
- ok "$var set (${val:0:8}...)"
193
- ;;
194
- esac
195
- fi
196
- done
197
-
198
- # Optional vars
199
- local opt_vars=("MIDNIGHT_NETWORK" "OPERATOR_FEE_BPS" "RECEIPT_CONTRACT_ADDRESS")
200
- for var in "${opt_vars[@]}"; do
201
- local val="${!var:-}"
202
- if [[ -n "$val" && "$val" != "$var" ]]; then
203
- ok "$var set ($val)"
204
- else
205
- info "$var not set (using default)"
206
- fi
207
- done
208
- }
209
-
210
- # ─── Connectivity check ──────────────────────────────────────────────────────
211
- check_connectivity() {
212
- header "Checking connectivity"
213
-
214
- local api_url="${NIGHTPAY_API_URL:-}"
215
- local bridge_url="${BRIDGE_URL:-}"
216
-
217
- if [[ -n "$api_url" && "$api_url" != "NIGHTPAY_API_URL" ]]; then
218
- if curl -sf --max-time 10 "${api_url}/availability" > /dev/null 2>&1; then
219
- ok "NightPay API reachable at $api_url"
220
- else
221
- warn "NightPay API not reachable at $api_url (may be offline or wrong URL)"
222
- fi
223
- else
224
- info "Skipping API check — NIGHTPAY_API_URL not set"
225
- fi
226
-
227
- if [[ -n "$bridge_url" && "$bridge_url" != "BRIDGE_URL" ]]; then
228
- if curl -sf --max-time 10 "${bridge_url}/health" > /dev/null 2>&1; then
229
- ok "Bridge reachable at $bridge_url"
230
- else
231
- warn "Bridge not reachable at $bridge_url (on-chain mode may not work)"
232
- fi
233
- else
234
- info "Skipping bridge check — BRIDGE_URL not set"
235
- fi
236
- }
237
-
238
- # ─── Install skill files ─────────────────────────────────────────────────────
239
- install_skill() {
240
- local platform="$1"
241
- local target="${NIGHTPAY_WORKSPACE:-}"
242
-
243
- header "Installing NightPay skill (platform: $platform)"
244
-
245
- # Determine target directory
246
- if [[ -z "$target" ]]; then
247
- case "$platform" in
248
- openclaw)
249
- # Try to detect OpenClaw workspace
250
- local agent_id="${NIGHTPAY_AGENT:-nightpay}"
251
- if [[ -d "$HOME/.openclaw/workspace-$agent_id" ]]; then
252
- target="$HOME/.openclaw/workspace-$agent_id/skills/nightpay"
253
- else
254
- target="$HOME/.openclaw/workspace-nightpay/skills/nightpay"
255
- fi
256
- ;;
257
- *)
258
- target="$(pwd)/skills/nightpay"
259
- ;;
260
- esac
261
- fi
262
-
263
- info "Target: $target"
264
-
265
- # Check if already installed
266
- if [[ -f "$target/SKILL.md" ]]; then
267
- ok "Skill already installed at $target"
268
- info "To reinstall, remove the directory first"
269
- return
270
- fi
271
-
272
- # Copy skill files
273
- mkdir -p "$target"
274
- if [[ -d "$SKILL_SRC" ]]; then
275
- cp -r "$SKILL_SRC"/* "$target/" 2>/dev/null || true
276
- cp -r "$SKILL_SRC"/.[!.]* "$target/" 2>/dev/null || true
277
- ok "Skill files copied to $target"
278
- else
279
- fail "Skill source not found at $SKILL_SRC"
280
- return
281
- fi
282
-
283
- # Fix permissions
284
- if [[ -d "$target/scripts" ]]; then
285
- chmod +x "$target/scripts"/*.sh 2>/dev/null || true
286
- ok "Script permissions fixed (chmod +x)"
287
- fi
288
-
289
- # Verify SKILL.md is at the right level (not nested)
290
- if [[ -f "$target/SKILL.md" ]]; then
291
- ok "SKILL.md found at correct level"
292
- elif [[ -f "$target/skills/nightpay/SKILL.md" ]]; then
293
- warn "SKILL.md is nested — flattening..."
294
- cp -r "$target/skills/nightpay"/* "$target/"
295
- ok "Flattened: SKILL.md now at correct level"
296
- else
297
- fail "SKILL.md not found — install may be incomplete"
298
- fi
299
- }
300
-
301
- # ─── Platform-specific setup ─────────────────────────────────────────────────
302
- setup_platform() {
303
- local platform="$1"
304
- local target="${NIGHTPAY_WORKSPACE:-$(pwd)/skills/nightpay}"
305
-
306
- header "Platform-specific setup ($platform)"
307
-
308
- case "$platform" in
309
- openclaw)
310
- info "OpenClaw: skill will be auto-discovered from workspace"
311
- info "Merge env vars into openclaw.json → skills.entries.nightpay.env"
312
-
313
- # Check if openclaw-fragment.json has placeholder values
314
- if [[ -f "$REPO_ROOT/openclaw-fragment.json" ]]; then
315
- local placeholders
316
- placeholders=$(grep -c '"MASUMI_API_KEY": "MASUMI_API_KEY"' "$REPO_ROOT/openclaw-fragment.json" 2>/dev/null || echo 0)
317
- if [[ "$placeholders" -gt 0 ]]; then
318
- warn "openclaw-fragment.json has placeholder values — replace before merging"
319
- fi
320
- fi
321
- ;;
322
-
323
- claude-code)
324
- # Create .claude/commands/ wrapper if not exists
325
- local cmd_dir="$(pwd)/.claude/commands"
326
- if [[ ! -f "$cmd_dir/nightpay.md" ]]; then
327
- mkdir -p "$cmd_dir"
328
- cat > "$cmd_dir/nightpay.md" << 'CLAUDE_CMD'
329
- ---
330
- description: "Run NightPay bounty operations"
331
- ---
332
-
333
- Use the NightPay skill at `skills/nightpay/SKILL.md` for anonymous community bounty operations.
334
-
335
- Available commands via `bash skills/nightpay/scripts/gateway.sh`:
336
- - `create-pool <description> <contribution_specks> <goal_specks>`
337
- - `fund-pool <pool_commitment>`
338
- - `pool-status <pool_commitment>`
339
- - `post-bounty <description> <amount_specks>`
340
- - `find-agent <capability>`
341
- - `hire-and-pay <agent_id> <description> <commitment_hash>`
342
- - `stats`
343
- CLAUDE_CMD
344
- ok "Created .claude/commands/nightpay.md"
345
- else
346
- ok ".claude/commands/nightpay.md already exists"
347
- fi
348
- ;;
349
-
350
- cursor)
351
- # Create .cursor/rules/ wrapper if not exists
352
- local rules_dir="$(pwd)/.cursor/rules"
353
- if [[ ! -f "$rules_dir/nightpay.md" ]]; then
354
- mkdir -p "$rules_dir"
355
- cat > "$rules_dir/nightpay.md" << 'CURSOR_RULE'
356
- # NightPay Bounty Skill
357
-
358
- When the user asks about bounties, community funding, or anonymous payments, use the NightPay skill.
359
-
360
- ## Available commands
361
-
362
- Run these via the terminal:
363
- ```bash
364
- bash skills/nightpay/scripts/gateway.sh create-pool "description" 5000 25000
365
- bash skills/nightpay/scripts/gateway.sh fund-pool <pool_commitment>
366
- bash skills/nightpay/scripts/gateway.sh post-bounty "description" 10000
367
- bash skills/nightpay/scripts/gateway.sh find-agent "code review"
368
- bash skills/nightpay/scripts/gateway.sh stats
369
- ```
370
-
371
- Required env: MASUMI_API_KEY, OPERATOR_ADDRESS, NIGHTPAY_API_URL, BRIDGE_URL.
372
- See `skills/nightpay/SKILL.md` for full documentation.
373
- CURSOR_RULE
374
- ok "Created .cursor/rules/nightpay.md"
375
- else
376
- ok ".cursor/rules/nightpay.md already exists"
377
- fi
378
- ;;
379
-
380
- copilot)
381
- # Add to .github/copilot-instructions.md
382
- local copilot_file="$(pwd)/.github/copilot-instructions.md"
383
- if [[ -f "$copilot_file" ]] && grep -q "NightPay" "$copilot_file"; then
384
- ok "NightPay already in copilot-instructions.md"
385
- else
386
- mkdir -p "$(pwd)/.github"
387
- cat >> "$copilot_file" << 'COPILOT_INST'
388
-
389
- ## NightPay Bounty Skill
390
-
391
- This project includes the NightPay anonymous bounty skill at `skills/nightpay/`.
392
- When asked about bounties, anonymous funding, or agent payments, use:
393
- `bash skills/nightpay/scripts/gateway.sh <command> [args]`
394
-
395
- Commands: create-pool, fund-pool, pool-status, post-bounty, find-agent,
396
- hire-and-pay, check-job, complete, refund, stats.
397
-
398
- See `skills/nightpay/SKILL.md` for full documentation.
399
- Required env: MASUMI_API_KEY, OPERATOR_ADDRESS, NIGHTPAY_API_URL, BRIDGE_URL.
400
- COPILOT_INST
401
- ok "Added NightPay section to .github/copilot-instructions.md"
402
- fi
403
- ;;
404
-
405
- raw)
406
- ok "Raw mode — no platform-specific setup needed"
407
- info "Run: bash skills/nightpay/scripts/gateway.sh stats"
408
- ;;
409
- esac
410
- }
411
-
412
- # ─── Gateway smoke test ──────────────────────────────────────────────────────
413
- smoke_test() {
414
- header "Smoke test"
415
-
416
- local gateway=""
417
- local target="${NIGHTPAY_WORKSPACE:-$(pwd)/skills/nightpay}"
418
-
419
- if [[ -f "$target/scripts/gateway.sh" ]]; then
420
- gateway="$target/scripts/gateway.sh"
421
- elif [[ -f "$REPO_ROOT/skills/nightpay/scripts/gateway.sh" ]]; then
422
- gateway="$REPO_ROOT/skills/nightpay/scripts/gateway.sh"
423
- fi
424
-
425
- if [[ -z "$gateway" ]]; then
426
- warn "gateway.sh not found — skipping smoke test"
427
- return
428
- fi
429
-
430
- if bash "$gateway" stats > /dev/null 2>&1; then
431
- ok "gateway.sh stats — passed"
432
- else
433
- warn "gateway.sh stats failed — API may be offline or env vars missing"
434
- fi
435
- }
436
-
437
- # ─── Summary ──────────────────────────────────────────────────────────────────
438
- summary() {
439
- header "Setup Summary"
440
-
441
- if [[ $ERRORS -eq 0 && $WARNINGS -eq 0 ]]; then
442
- echo ""
443
- echo " ${GREEN}${BOLD}NightPay is ready!${RESET} ${CHECK}"
444
- echo ""
445
- echo " Try: ${CYAN}bash skills/nightpay/scripts/gateway.sh stats${RESET}"
446
- echo ""
447
- elif [[ $ERRORS -eq 0 ]]; then
448
- echo ""
449
- echo " ${YELLOW}${BOLD}NightPay installed with $WARNINGS warning(s)${RESET}"
450
- echo ""
451
- echo " Review the warnings above. The skill may work, but some"
452
- echo " features might be limited."
453
- echo ""
454
- else
455
- echo ""
456
- echo " ${RED}${BOLD}Setup incomplete: $ERRORS error(s), $WARNINGS warning(s)${RESET}"
457
- echo ""
458
- echo " Fix the errors above and run again:"
459
- echo " ${CYAN}bash setup.sh --validate-only${RESET}"
460
- echo ""
461
- fi
462
-
463
- return $ERRORS
464
- }
465
-
466
- # ─── Main ─────────────────────────────────────────────────────────────────────
467
- main() {
468
- echo ""
469
- echo "${BOLD}NightPay Agent Onboarding${RESET} v0.2.4"
470
- echo "${DIM}Anonymous community bounties for AI agents${RESET}"
471
- echo ""
472
-
473
- PLATFORM=$(detect_platform)
474
- info "Detected platform: ${BOLD}$PLATFORM${RESET}"
475
-
476
- check_prerequisites
477
-
478
- if [[ "$VALIDATE_ONLY" == false ]]; then
479
- install_skill "$PLATFORM"
480
- setup_platform "$PLATFORM"
481
- fi
482
-
483
- validate_env
484
- check_connectivity
485
- smoke_test
486
- summary
487
- }
488
-
489
- main