forked from jb55/nostril
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgnostr-nip
executable file
·441 lines (396 loc) · 12 KB
/
gnostr-nip
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#!/usr/bin/env bash
#
#
## echo
## echo "# arguments called with ----> ${@} "
## echo "# \$# arg count ------------> $# "
## echo "# \$1 ----------------------> $1 "
## echo "# \$2 ----------------------> $2 "
## echo "# \$3 ----------------------> $3 "
## echo "# \$4 ----------------------> $4 "
## echo "# path to me ---------------> ${0} "
## echo "# parent path --------------> ${0%/*} "
## echo "# my name ------------------> ${0##*/} "
## echo
## exit
#
#
#GNOSTR=$(which gnostr || which gnostr-am)
WHICH_GNOSTR=$(which nostril)
WHICH_GNOSTR_AM=$(which gnostr-am)
export WHICH_GNOSTR_AM
GNOSTR=${WHICH_GNOSTR:-$WHICH_GNOSTR_AM}
export GNOSTR
echo using $GNOSTR
declare CALLED_FROM
declare PRIVKEY
declare KIND
declare NIP
## PRIVKEY=${PRIVKEY:-$(GNOSTR --hash)}
PRIVKEY=${PRIVKEY:-}
if [ "$1" == "--sec" ]; then
if [ "$2" == "" ]; then
echo "provide a sha256 hash for private key"
else
PRIVKEY=$2
fi
fi
## echo 11:$PRIVKEY
## echo $2
## echo '$2'
## echo "$2"
## exit
## PUBKEY for 0000000000000000000000000000000000000000000000000000000000000001
## 79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
## TESTS=$(echo {0000000000000000000000000000000000000000000000000000000000000001..0000000000000000000000000000000000000000000000000000000000001000})
## for ms in $TESTS
## do
## echo $ms 2>/dev/null
## done
## exit
kinds(){
BANNER="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $BANNER
PICTURE="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $PICTURE
##exit;
##
WEBSITE=gnostr.org
#echo "$WEBSITE"
DAMUS_DONATION_V2=0
#echo "$DAMUS_DONATION_V2"
#REF: https://github.com/lnurl/luds/blob/luds/06.md
LUD06="[email protected]"
#echo "$LUD06"
#REF: https://github.com/lnurl/luds/blob/luds/16.md
LUD16="[email protected]"
DISPLAY_NAME=$(gnostr-weeble)
#echo "$DISPLAY_NAME"
ABOUT_ME="#gnostr/$(gnostr-weeble)"
#echo "$ABOUT"
NAME=$(gnostr-weeble)
#echo "$NAME"
NIP_05="[email protected]"
CREATED_AT=$(date +%s)
## echo $CREATED_AT
## echo 55:KIND=$KIND
if [[ "$KIND" == "0" ]];
then
MESSAGE="{\"banner\":\"$BANNER\",\"website\":\"$WEBSITE\",\"lud06\":\"$LUD06\",\"lud16\":\"$LUD16\",\"nip05\":\"$NIP_05\",\"picture\":\"https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4\",\"display_name\":\"$DISPLAY_NAME\",\"about\":\"$ABOUT_ME\",\"name\":\"$NAME\"}"
fi
if [[ "$KIND" == "1" ]];
then
MESSAGE="{\"banner\":\"$BANNER\",\"website\":\"$WEBSITE\",\"lud06\":\"$LUD06\",\"lud16\":\"$LUD16\",\"nip05\":\"$NIP_05\",\"picture\":\"https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4\",\"display_name\":\"$DISPLAY_NAME\",\"about\":\"$ABOUT_ME\",\"name\":\"$NAME\"}"
fi
if [[ "$KIND" == "2" ]];
then
MESSAGE="{\"banner\":\"$BANNER\",\"website\":\"$WEBSITE\",\"lud06\":\"$LUD06\",\"lud16\":\"$LUD16\",\"nip05\":\"$NIP_05\",\"picture\":\"https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4\",\"display_name\":\"$DISPLAY_NAME\",\"about\":\"$ABOUT_ME\",\"name\":\"$NAME\"}"
else
## default to kind 0 for now
KIND=0
MESSAGE="{\"banner\":\"$BANNER\",\"website\":\"$WEBSITE\",\"lud06\":\"$LUD06\",\"lud16\":\"$LUD16\",\"nip05\":\"$NIP_05\",\"picture\":\"https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4\",\"display_name\":\"$DISPLAY_NAME\",\"about\":\"$ABOUT_ME\",\"name\":\"$NAME\"}"
fi
# echo 80:PRIVKEY=$PRIVKEY
$GNOSTR --sec $PRIVKEY \
--kind $KIND \
-t gnostr \
--tag gnostr gnostr \
--tag weeble $(gnostr-weeble) \
--tag wobble $(gnostr-wobble) \
--tag block $(gnostr-blockheight) \
--content "$MESSAGE" && true || help;exit;
} ## end kind0
kind1(){
echo kind1 stub;
}
nips(){
## echo nips stub;
if [[ "$NIP" == "0" ]];
then
echo ##NIP=$NIP
fi
KIND=NIP
echo #"calling kinds instead";
kinds;
}
test_zero(){
BANNER="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $BANNER
PICTURE="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $PICTURE
##exit;
##
WEBSITE=gnostr.org
#echo "$WEBSITE"
DAMUS_DONATION_V2=0
#echo "$DAMUS_DONATION_V2"
#REF: https://github.com/lnurl/luds/blob/luds/06.md
LUD06="[email protected]"
#echo "$LUD06"
#REF: https://github.com/lnurl/luds/blob/luds/16.md
LUD16="[email protected]"
#echo "$LUD16"
DISPLAY_NAME=$(gnostr-weeble)
#echo "$DISPLAY_NAME"
ABOUT_ME="#gnostr/$(gnostr-weeble)"
#echo "$ABOUT"
NAME=$(gnostr-weeble)
#echo "$NAME"
PICTURE="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $PICTURE
exit
CREATED_AT=$(date +%s)
#echo $CREATED_AT
MESSAGE="{\"banner\":\"$BANNER\",\"website\":\"$WEBSITE\",\"lud06\":\"$LUD06\",\"nip05\":\"$NIP_05\",\"picture\":\"$PICTURE\",\"display_name\":\"$DISPLAY_NAME\",\"about\":\"$ABOUT_ME\",\"name\":\"$NAME\"}"
}
test_one(){
declare REPO
REPO=$(pwd | grep -o '[^/]*$')
## echo $REPO
declare BRANCH
BRANCH=$(echo $(git branch --show-current) | sed -e 's/\//-/g')
## echo $BRANCH
declare UTC_SECS
UTC_SECS=$(date +%s)
## echo $UTC_SECS
BANNER="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $BANNER
PICTURE="https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4"
#echo $PICTURE
##exit;
##
WEBSITE=gnostr.org/$REPO
#echo "$WEBSITE"
DAMUS_DONATION_V2=0
#echo "$DAMUS_DONATION_V2"
LUD06=""
#echo "$LUD06"
DISPLAY_NAME=$REPO/$(gnostr-weeble)
#echo "$DISPLAY_NAME"
ABOUT_ME="#$REPO/$(gnostr-weeble)"
#echo "$ABOUT"
NAME=$REPO/$(gnostr-weeble)
#echo "$NAME"
CREATED_AT=$(date +%s)
#echo $CREATED_AT
MESSAGE="{\"banner\":\"$BANNER\",\"website\":\"$WEBSITE\",\"lud06\":\"$LUD06\",\"nip05\":\"$NIP_05\",\"picture\":\"https://avatars.githubusercontent.com/u/135379339?s=400&u=e38855df24087feb9a6679c5e3974816e6aa3753&v=4\",\"display_name\":\"$DISPLAY_NAME\",\"about\":\"$ABOUT_ME\",\"name\":\"$NAME\"}"
#echo "test_one()";
PREVKEY=0000000000000000000000000000000000000000000000000000000000000000
#echo PREVKEY=$PREVKEY
## for i in {1..100}
## do
## printf "%064d\n" $i
## done
for i in $(seq -f "%064g" 1 10)
do
#echo $i
PRIVKEY=$i
#echo PRIVKEY=$PRIVKEY
##nip0
$GNOSTR --sec $i \
--kind 0 \
--pow 1 \
-t gnostr \
--tag repo $REPO \
--tag branch $BRANCH \
-t $(gnostr-weeble) \
-t $(gnostr-blockheight) \
-t $(gnostr-wobble) \
--content "$MESSAGE" | \
gnostr-post-event
$GNOSTR --sec $i \
--kind 1 \
--pow 1 \
-t gnostr \
-t $(gnostr-weeble) \
-t $(gnostr-blockheight) \
-t $(gnostr-wobble) \
--content "$REPO/$(gnostr-weeble)/$(gnostr-blockheight)/$(gnostr-wobble):$i" | \
gnostr-post-event
done
exit
#echo PRIVKEY=$PRIVKEY
$GNOSTR --sec $PRIVKEY;
#$GNOSTR --sec '$PRIVKEY';##this will fail
$GNOSTR --sec "$PRIVKEY";
exit;
}
if \
[[ \
$2 \
== \
"0000000000000000000000000000000000000000000000000000000000000000" \
]];
then
test_zero;
exit;
fi
if \
[[ \
$2 \
== \
"0000000000000000000000000000000000000000000000000000000000000001" \
]];
then
test_one;
exit;
fi
test_zero(){
#echo "test_zero()";
$GNOSTR --sec $2;
exit;
}
test_one(){
#echo "test_one()";
$GNOSTR --sec $2;
exit;
}
default(){
##CALLED_FROM=default
echo #help
}
help(){
## echo 259:CALLED_FROM=$CALLED_FROM
if [[ ! -z $CALLED_FROM ]];
then
true
## echo 262:CALLED_FROM=$CALLED_FROM
fi
printf "\nUsage:\n"
printf "\n"
printf "gnostr-nip --sec <sha256_hash>\n"
printf "\n"
printf "gnostr-nip --sec $(gnostr-sha256 $$)\n"
printf "\n"
printf "\nContext:\n"
printf "\n"
printf "gnostr-nip --sec \$(gnostr-xor 1 \$(gnostr-sha256 \$\$))\n"
printf "\n"
printf "gnostr-nip --sec $(gnostr-xor 1 $(gnostr-sha256 $$))\n"
printf "\n"
printf "Test triggers:\n"
printf "\n"
printf "gnostr-nip --sec 0000000000000000000000000000000000000000000000000000000000000001\n"
exit;
}
##if [ ! -z "$1" ]; then
## if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
## help
## if [ "$2" == "0" ]; then
## echo "NIP-0: metadata: the content is set to a stringified JSON object {name: <username>, about: <string>, picture: <url, string>} describing the user who created the event. A relay may delete older events once it gets a new one for the same pubkey.";
## fi
## if [ "$2" == "1" ]; then
## echo "NIP-1:"
## fi
## if [ "$2" == "2" ]; then
## echo "NIP-2:"
## fi
## fi
## if [ "$1" == "--sec" ]; then
## if [ "$2" == "" ]; then
## echo "provide a sha256 hash for private key"
## else
## PRIVKEY=$2
## mkdir -p ~/.gnostr
## #touch ~/.gnostr/$PRIVKEY
## nip0
## fi
## fi
##exit
##fi
# gnostr-query -i $(gnostr-nip0 | jq .[1] | tr -d "\"" ) | gnostr-cat -u wss://nos.lol
#
# gnostr-query -k 0 -l 1 | gnostr-cat -u wss://nos.lol | jq .[2].content | tr -d "\""
#
# echo $(./template/gnostr-nip0) #| gnostr-relays
#
# echo $(./template/gnostr-nip0) | gnostr-cat -u wss://nos.lol | jq .[1] | tr -d "\""
#
# echo $(gnostr-query -k 0 -l 1 | gnostr-cat -u wss://nos.lol | jq .[2].content | jq | tr -d "\"") | tr -d "\\"
#
# gnostr --sec $(gnostr-sha256) --envelope --content $(echo gnostr-query -k 0 -l 1 | gnostr-cat -u wss://nos.lol | jq .[2].content ) | tr -d "\\"
#
for ((i=1; i<=$#; i++)); do
## echo "282:i=${!i}"
## positional V V
if [[ ${!i} == "-h" ]] || [[ $1 == "--help" ]] || [[ $1 == "help" ]]; then
#CALLED_FROM=321 && \
help
exit
fi
## positional V V
if [[ ${!i} == "-v" ]] || [[ $1 == "--version" ]] || [[ $1 == "version" ]]; then
echo v0.0.0
exit
fi
## positional V V
# if [[ ${!i} == "-s" ]] || [[ $1 == "--sec" ]] || [[ $1 == "sec" ]]; then
if [[ ${!i} == "-s" ]] || [[ ${!i} == "--sec" ]] || [[ ${!i} == "sec" ]]; then
((i++))
#echo $i
## TODO more test for hash
if [[ ! -z ${!i} ]]; then
#echo \${!i}=${!i}
PRIVKEY=${!i}
export PRIVKEY
#echo 337:PRIVKEY=$PRIVKEY
## echo "${!i} is a number"
## echo DEPTH=$DEPTH
((i++))
else
echo #"${!i} is not a valid sha256 hash"
#CALLED_FROM=345 && \
##help
fi
fi ## end if -ss --sec sec
## non-positional
## V V V
if [[ ${!i} == "-k" ]] || [[ ${!i} == "--kind" ]] || [[ ${!i} == "kind" ]]; then
((i++))
if [[ ! -z ${!i} ]] && [[ ${!i} =~ ^[0-9]+$ ]]; then
KIND=${!i}
#echo 352:KIND=$KIND
((i++))
else
echo #"${!i} is not a number"
#CALLED_FROM=359 && \
#help
fi
fi
## non-positional
## V V V
if [[ ${!i} == "-n" ]] || [[ ${!i} == "--nip" ]] || [[ ${!i} == "nip" ]]; then
#echo 365:i=${!i};
((i++))
#echo 367:i=${!i};
## i not empty and a number
if [[ ! -z ${!i} ]] && [[ ${!i} =~ ^[0-9]+$ ]]; then
#echo 370:i=${!i};
NIP=${!i}
#echo 370:NIP=$NIP
#echo 371:kind\$NIP=kind$NIP
## nip$NIP
## echo "${!i} is a number"
## echo DEPTH=$DEPTH
((i++))
## else ## already tested - no need to catch
echo #"${!i} is not a number"
## CALLED_FROM=378 && \
#help
fi
fi
if [[ ${!i} == "-2" ]] || [[ $1 == "--sha2" ]] || [[ $1 == "--sha256" ]]; then
((i++))
## hash the next i and assign
SHA2=$(gnostr --hash ${!i})
echo $SHA2;exit;
((i++))
## else # no need to catch
## CALLED_FROM=377 && default || help
fi
## calling nips first or kinds
## TODO: print nip summary/syntax
nips || kinds
exit
done
#CALLED_FROM=393 && default || help