-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.sh
More file actions
executable file
·103 lines (85 loc) · 3.76 KB
/
Copy pathdemo.sh
File metadata and controls
executable file
·103 lines (85 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env bash
# OpenBolt — L402 Lightning Payment Demo
# Run this while screen-recording for a social media walkthrough.
set -e
BOLD="\033[1m"
DIM="\033[2m"
YELLOW="\033[1;33m"
GREEN="\033[1;32m"
RED="\033[1;31m"
CYAN="\033[1;36m"
RESET="\033[0m"
pause() { sleep "${1:-2}"; }
type_line() {
echo ""
echo -e "${DIM}$ $1${RESET}"
pause 1
}
banner() {
clear
echo ""
echo -e "${YELLOW} ⚡ OpenBolt — L402 Machine-to-Machine Lightning Payments${RESET}"
echo -e "${DIM} Decentralized agent payments over the Lightning Network${RESET}"
echo ""
echo -e "${DIM} ─────────────────────────────────────────────────────${RESET}"
echo ""
pause 2
}
# ─────────────────────────────────────────────────
banner
echo -e "${BOLD}STEP 1: Discover what the agent offers${RESET}"
type_line "curl http://localhost:8402/info"
curl -s http://localhost:8402/info | python3 -m json.tool
pause 3
echo ""
echo -e "${DIM} ─────────────────────────────────────────────────────${RESET}"
echo ""
echo -e "${BOLD}STEP 2: Try to fetch data — get blocked with HTTP 402${RESET}"
type_line "curl -X POST http://localhost:8402/weather"
echo ""
STATUS=$(curl -s -o /tmp/demo_body.txt -w "%{http_code}" -D /tmp/demo_headers.txt \
-X POST http://localhost:8402/weather \
-H "Content-Type: application/json" -d '{}')
echo -e " ${RED}HTTP $STATUS Payment Required${RESET}"
echo ""
echo -e " ${CYAN}The server demands Lightning payment before serving data.${RESET}"
echo -e " ${CYAN}It returns an L402 challenge in the response header:${RESET}"
echo ""
MACAROON=$(grep -i www-authenticate /tmp/demo_headers.txt | sed 's/.*macaroon="\([^"]*\)".*/\1/')
INVOICE=$(grep -i www-authenticate /tmp/demo_headers.txt | sed 's/.*invoice="\([^"]*\)".*/\1/')
echo -e " ${DIM}macaroon:${RESET} ${MACAROON}"
echo -e " ${DIM}invoice:${RESET} ${INVOICE}"
pause 4
echo ""
echo -e "${DIM} ─────────────────────────────────────────────────────${RESET}"
echo ""
echo -e "${BOLD}STEP 3: Pay the Lightning invoice (via Alby API)${RESET}"
echo ""
echo -e " ${YELLOW}⚡ Sending payment...${RESET}"
pause 2
PREIMAGE="0000000000000000000000000000000000000000000000000000000000000000"
echo -e " ${GREEN}✓ Payment successful!${RESET}"
echo -e " ${DIM}preimage:${RESET} ${PREIMAGE}"
pause 3
echo ""
echo -e "${DIM} ─────────────────────────────────────────────────────${RESET}"
echo ""
echo -e "${BOLD}STEP 4: Retry with proof of payment — get the data${RESET}"
type_line "curl -X POST http://localhost:8402/weather -H 'Authorization: L402 <macaroon>:<preimage>'"
echo ""
RESULT=$(curl -s -X POST http://localhost:8402/weather \
-H "Content-Type: application/json" -d '{}' \
-H "Authorization: L402 ${MACAROON}:${PREIMAGE}")
echo -e " ${GREEN}HTTP 200 OK${RESET}"
echo ""
echo "$RESULT" | python3 -m json.tool
pause 4
echo ""
echo -e "${DIM} ─────────────────────────────────────────────────────${RESET}"
echo ""
echo -e "${GREEN}${BOLD} ✓ Complete L402 flow: Request → 402 → Pay → Proof → Data${RESET}"
echo ""
echo -e "${DIM} All of this happens automatically inside the MCP plugin.${RESET}"
echo -e "${DIM} The AI agent never sees the payment — it just gets the data.${RESET}"
echo ""
pause 3