Repository navigation
Expand file tree
/
Copy pathexample.sh
More file actions
executable file
·49 lines (39 loc) · 1.54 KB
/
Copy pathexample.sh
File metadata and controls
executable file
·49 lines (39 loc) · 1.54 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
#!/bin/bash
# this script sends a request to the notary and gets an invoice
# once the invoice is paid, it gets a proof and asks the notary to verify it
#url=http://localhost:5455/n/api
url=https://notary.electrum.org/n/api
if [[ -z "$2" ]] ; then
usage="usage: $0 event_id amount [privkey]"
echo $usage
exit 1
fi
nonce=$(hexdump -n32 -e '16/1 "%02x"' /dev/urandom)
if [[ -z "$3" ]] ; then
request="{\"event_id\":\"$1\",\"value_sats\":$2,\"nonce\":\"$nonce\"}"
else
event_id="$1"
value_sats="$2"
privkey="$3"
r=$( $(dirname "$0")/sign_request.py $privkey $event_id $value_sats $nonce)
signature=$(echo $r|jq -r '.signature')
pubkey=$(echo $r|jq -r '.pubkey')
request="{\"event_id\":\"$1\",\"value_sats\":$2,\"nonce\":\"$nonce\",\"upvoter_pubkey\":\"$pubkey\",\"upvoter_signature\":\"$signature\"}"
fi
echo "your request"
echo $request | jq --color-output
invoice=$(curl -s -X POST $url/add_request -H 'Content-Type: application/json' -d @<(echo $request))
echo "notary invoice:"
echo $invoice | jq --color-output
proof="{\"error\":\"initializing...\"}"
while error=$(echo $proof|jq '.error') && [[ $error != null ]]; do
printf "$error\r"
sleep 1
proof=$(curl -s -X POST $url/get_proof -H 'Content-Type: application/json' -d @<(echo $invoice))
done
printf " \r"
echo "proof:"
echo $proof | jq --color-output
echo "proof verification:"
verify=$(curl -s -X POST $url/verify_proof -H 'Content-Type: application/json' -d @<(echo $proof))
echo $verify | jq --color-output