-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdemo-402.sh
More file actions
executable file
·56 lines (51 loc) · 1.88 KB
/
demo-402.sh
File metadata and controls
executable file
·56 lines (51 loc) · 1.88 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
#!/bin/bash
# Demo: HTTP 402 Payment-Gated Article
# Requires: JSS running on localhost:3000 with --pay --pay-cost 10
BASE="http://localhost:3000"
echo "=== Setting up payment-gated article demo ==="
# 1. Create the premium article
echo "Creating premium article..."
curl -s -X PUT "$BASE/premium/article.jsonld" \
-H "Content-Type: application/ld+json" \
-d '{
"@context": "https://schema.org",
"@type": "Article",
"headline": "The Future of Web Payments",
"author": "Melvin Carvalho",
"datePublished": "2026-03-26",
"articleBody": "This premium article explains how HTTP 402 enables native web payments. The decentralised web finally has a business model. No Stripe. No PayPal. No app store taking 30%. Just HTTP status codes and Lightning invoices."
}'
# 2. Create the ACL with PaymentCondition
echo "Creating payment-gated ACL..."
curl -s -X PUT "$BASE/premium/article.jsonld.acl" \
-H "Content-Type: application/ld+json" \
-d '{
"@context": {
"acl": "http://www.w3.org/ns/auth/acl#",
"foaf": "http://xmlns.com/foaf/0.1/"
},
"@graph": [{
"@id": "#paid",
"@type": "acl:Authorization",
"acl:agentClass": { "@id": "acl:AuthenticatedAgent" },
"acl:accessTo": { "@id": "'$BASE'/premium/article.jsonld" },
"acl:mode": [{ "@id": "acl:Read" }],
"acl:condition": {
"@type": "PaymentCondition",
"amount": "10",
"currency": "sats",
"chain": "tbtc4"
}
}]
}'
echo ""
echo "=== Demo ready ==="
echo ""
echo "1. Try accessing the article (should get 402):"
echo " curl $BASE/premium/article.jsonld"
echo ""
echo "2. Deposit testnet4 sats:"
echo " curl -X POST -H 'Authorization: Nostr <nip98-token>' $BASE/pay/.deposit -d 'txo:tbtc4:txid:vout'"
echo ""
echo "3. Try again (should get 200 + article):"
echo " curl -H 'Authorization: Nostr <nip98-token>' $BASE/premium/article.jsonld"