forked from axiom-team/astroport
309 lines
12 KiB
Bash
Executable File
309 lines
12 KiB
Bash
Executable File
#!/bin/bash
|
|
########################################################################
|
|
# Author: Fred (support@qo-op.com)
|
|
# Version: 2020.03.18
|
|
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
|
|
########################################################################
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
ME="${0##*/}"
|
|
echo '
|
|
########################################################################
|
|
# \\///
|
|
# qo-op
|
|
############# '$ME' ZEN TXHASH FILE READ PARK
|
|
########################################################################
|
|
# ex: ./'$ME' 1000 TXHASH ./myfile.wav 1 10
|
|
# IPFS DATASTRUCTURE ~/.zen/tag/sha256sum(_tag.uid)
|
|
########################################################################
|
|
# [ASTROPORT](https://astroport.com)
|
|
########################################################################'
|
|
ZEN="$1" # Zen amount
|
|
TXHASH="$2" # G1 TX HASH
|
|
PASSENGER="$3" # /path/file.ext to include into ZenTag (add to IPFS datastructure)
|
|
READ="$4" # Zen amount asked to allow passenger reading
|
|
PARK="$5" # Zen amount payed for IPFS PIN by passenger everyday
|
|
[[ $READ == "" ]] && READ=1
|
|
[[ $PARK == "" ]] && PARK=10
|
|
##############################################
|
|
# NODE ENVIRONEMENT DETECTION
|
|
##############################################
|
|
ipfsnodeid=$(ipfs id -f='<id>\n')
|
|
[[ ! -f ~/.ssb/secret.dunikey ]] && $MY_PATH/tools/secret2dunikey.sh
|
|
g1pub=$(cat ~/.ssb/secret.dunikey | grep 'pub:' | cut -d ' ' -f 2)
|
|
echo "G1SSB Wallet: $g1pub
|
|
IPFS: $ipfsnodeid
|
|
__ __ _ _ _______
|
|
_______ _ __ | \/ | / \ | |/ / ____|
|
|
|_ / _ \ '_ \ | |\/| | / _ \ | ' /| _|
|
|
/ / __/ | | | | | | |/ ___ \| . \| |___
|
|
/___\___|_| |_| |_| |_/_/ \_\_|\_\_____|
|
|
|
|
########################################################################
|
|
# ZenTag is an IPFS/IPNS datastructure put into IPFS, publish
|
|
# ~~~ Draft ~~~~ Draft ~~~~ Draft ~~~~ Draft ~~~~ Draft ~~~~
|
|
# _chain # ZenTag IPFS Hash
|
|
# _chain.n # Sequence Number
|
|
# _chain.nanodate # Current nanodate
|
|
# _chain.prev # Previous IPFS Hash
|
|
# _g1.node.creator # G1SSB wallet pubkey
|
|
# _g1.issuer # G1TX ISSUER pubkey
|
|
# _g1.txhash # G1TX HASH
|
|
# _ipfs.node.creatorcat # NODE IPFS ID
|
|
# _ipfs.publishkey.BB.aes # BB SYMcypher of IPNS publish key
|
|
# _ipfs.publishkey.crypt # G1SSB ASYMcypher of IPNS publish key
|
|
# _tag.BB.sha # BB sha512sum
|
|
# _tag.uid # ZenTag UID
|
|
# _tag.zen # ZentTag balance
|
|
# _ipns # /ipns/ address
|
|
# PASSENGER FILE OPTIONNAL
|
|
# _passenger.filename # Passenger filename
|
|
# _passenger.ipfs.crypt # G1SSB cyphered IPFS Passenger link
|
|
# _passenger.read # Zen value asked for READING
|
|
# _passenger.park # Zen value paid for PARKING
|
|
# Read code to discover use.
|
|
# TODO: Could be converted into yaml or json if you like...
|
|
########################################################################
|
|
"
|
|
[[ $ZEN == "" || $TXHASH == "" ]] && echo "ERROR... Please provide Zen value" && exit 1
|
|
|
|
# UNCOMMENT TO ACTIVATE (G1 <=> ZEN) STRICT RELATION
|
|
# ACTIVATES "GREEN FLAG" LIBRE ASTROPORT
|
|
# FULLY BACKED ON IRL G1 LIBRE MONEY (https://cesium.app)
|
|
# ____ ____ _____ _____ _ _
|
|
# / ___| _ \| ____| ____| \ | | _______ _ __
|
|
# | | _| |_) | _| | _| | \| | |_ / _ \ '_ \
|
|
# | |_| | _ <| |___| |___| |\ | / / __/ | | |
|
|
# \____|_| \_\_____|_____|_| \_| /___\___|_| |_|
|
|
#
|
|
# CONTROL IF TXHASH is REAL, see ./g1_TX2ZEN.sh for cache
|
|
#[[ ! -f ~/.zen/scan/zen.$TXHASH ]] && echo "ERROR# UNKNOWN TX $TXHASH !!" && exit 1
|
|
#ISSUER=$(cat ~/.zen/scan/zen.$TXHASH)
|
|
#[[ $ISSUER == "" ]] && echo "ERROR# NO ISSUER FOUND FOR TX $TXHASH !!" && exit 1
|
|
|
|
########################################################################
|
|
# CREATE ZEN TAG
|
|
########################################################################
|
|
# Produce unique 6 words diceware to give a name _tag.uid
|
|
AA=$(echo $($MY_PATH/tools/diceware.sh 6 | xargs) | sed s/\ /_/g ) # ZenTag Name = Diceware_6_words
|
|
AAH=$(echo -n ${AA} | sha256sum | cut -d ' ' -f 1) # ZenTag Name SHA256
|
|
|
|
# TODO ACTIVATE SWARM UNICITY CHECK
|
|
# Create Unique Zentag for all IPFS SWARM!
|
|
#while [[ $(grep -Rwl "$AA" ~/.zen/ipfs_swarm/.Qm*/TAG/) ]]; do
|
|
# AA=$(echo $($MY_PATH/tools/diceware.sh 6 | xargs) | sed s/\ /_/g )
|
|
# AAH=$(echo -n ${AA} | sha256sum | cut -d ' ' -f 1)
|
|
#done
|
|
|
|
# BB key is a 4 word diceware printed on QRCode for Human use.
|
|
# SHA512 PASSWORD CHECK FOR ALLOWING WRITE ACTION
|
|
BB=$($MY_PATH/tools/diceware.sh 4 | xargs);
|
|
BBH=$(echo -n "$BB" | sha512sum | cut -d ' ' -f 1)
|
|
|
|
########################################################################
|
|
# INITIAL DATA STRUCTURE
|
|
########################################################################
|
|
mkdir -p ~/.zen/tag/${AAH}
|
|
# LOG
|
|
echo "
|
|
_____ _____ _ ____
|
|
|__ /___ _ _|_ _|/ \ / ___| __/\__
|
|
/ // _ \ °_ \| | / _ \| | _ \ /
|
|
/ /| __/ | | | |/ ___ \ |_| | /_ _\
|
|
/____\___|_| |_|_/_/ \_\____| \/
|
|
|
|
${AAH}
|
|
|
|
$AA $ZEN Zen
|
|
|
|
*******************************************************
|
|
"
|
|
|
|
# COPY ZENTAG TO LOCAL ~/.zen/tag
|
|
echo "$AA" > ~/.zen/tag/${AAH}/_tag.uid # Nom du ZenTAG
|
|
echo "$ZEN" > ~/.zen/tag/${AAH}/_tag.zen # Tag ZEN amount
|
|
echo "${ipfsnodeid}" > ~/.zen/tag/${AAH}/_ipfs.node.creator # NODE IPFS ID
|
|
echo "$TXHASH" > ~/.zen/tag/${AAH}/_g1.txhash # HASH G1 TX/IN
|
|
echo "$g1pub" > ~/.zen/tag/${AAH}/_g1.node.creator # CREATOR IPFS NODE G1PUBKEY
|
|
echo "$ISSUER" > ~/.zen/tag/${AAH}/_g1.issuer # TX ISSUER G1PUBKEY
|
|
|
|
########################################################################
|
|
# Create IPNS publishing key ${AA}.key
|
|
# =====================================
|
|
# BB encrypted version for IRL use
|
|
# g1pub for current G1SSB Node later access...
|
|
# Using sha512sum / openssl / natools.py (libsodium)
|
|
########################################################################
|
|
[[ ! -f ~/.ipfs/keystore/${AA}.key ]] && J=$(ipfs key gen -t rsa -s 2048 ${AA}.key)
|
|
# WRITE BBH for QRCode BB verification
|
|
echo "$BBH" > ~/.zen/tag/${AAH}/_tag.BB.sha
|
|
# BB pgp symetric publishkey
|
|
openssl aes-256-cbc -pbkdf2 -k "$BB" -salt -in ~/.ipfs/keystore/${AA}.key -out ~/.zen/tag/${AAH}/_ipfs.publishkey.BB.aes
|
|
# GIVE IPFS CREATOR NODE ACCESS TO ZEN TAG
|
|
$MY_PATH/tools/natools.py encrypt -p $g1pub -i ~/.ipfs/keystore/${AA}.key -o ~/.zen/tag/${AAH}/_ipfs.publishkey.crypt
|
|
# LOG
|
|
echo "
|
|
|
|
CYPHERING PUBLISH KEY
|
|
__ _
|
|
_/_/ __/|_ __/|_ | |
|
|
/ / | / | / / /
|
|
/ / /_ __| /_ __| / /
|
|
/ / |/ |/ _/_/
|
|
|_| /_/
|
|
|
|
KEY : $BB
|
|
BBH : $BBH
|
|
"
|
|
#######################################################################
|
|
# PASSENGER FILE is added to IPFS then link is cyphered
|
|
# https://beechat.network/how-beechats-encryption-works/
|
|
if [[ -f $PASSENGER ]]; then
|
|
echo "
|
|
_ _ _ _ _ _ _ _ _
|
|
/ \ / \ / \ / \ / \ / \ / \ / \ / \
|
|
( p | a | s | s | e | n | g | e | r )
|
|
\_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/ \_/
|
|
|
|
"
|
|
# ADD PASSENGER TO IPFS
|
|
IPASSENGER=$(ipfs add -q "$PASSENGER" -w | tail -n 1)
|
|
echo "$IPASSENGER" > ~/.zen/tag/${AAH}/_passenger.ipfs
|
|
# GET FILE NAME
|
|
PASSENGERNAME=$(basename -- "$PASSENGER")
|
|
echo "$PASSENGERNAME" > ~/.zen/tag/${AAH}/_passenger.filename
|
|
|
|
# G1SSB NODE ACCESS
|
|
$MY_PATH/tools/natools.py encrypt -p $g1pub -i ~/.zen/tag/${AAH}/_passenger.ipfs -o ~/.zen/tag/${AAH}/_passenger.ipfs.crypt
|
|
# BB OWNER ACCESS
|
|
openssl aes-256-cbc -pbkdf2 -k "$BB" -salt -in ~/.zen/tag/${AAH}/_passenger.ipfs -out ~/.zen/tag/${AAH}/_passenger.ipfs.BB.aes
|
|
# CLEAN CLEARTEXT IPFS link
|
|
rm -r ~/.zen/tag/${AAH}/_passenger.ipfs
|
|
|
|
# ZEN ECONOMY: ZEN READ payment + PARK rental
|
|
echo "$READ" > ~/.zen/tag/${AAH}/_passenger.read
|
|
echo "$PARK" > ~/.zen/tag/${AAH}/_passenger.park
|
|
|
|
echo "
|
|
_passenger.filename : $PASSENGERNAME
|
|
_passenger.ipfs : $IPASSENGER
|
|
|
|
# #### ## ##### ###### #####
|
|
# # # # # # # # # #
|
|
# # # # # # # ##### # #
|
|
# # # ###### # # # # #
|
|
# # # # # # # # # #
|
|
###### #### # # ##### ###### #####
|
|
|
|
##################################################################
|
|
# DECODE AND READ _passenger.ipfs with BB Passphrase
|
|
##################################################################
|
|
openssl aes-256-cbc -pbkdf2 -k \"$BB\" -d -salt -in ~/.zen/tag/${AAH}/_passenger.ipfs.BB.aes -out /tmp/_passenger.ipfs
|
|
ipfs get -o /tmp \"/ipfs/$IPASSENGER/$PASSENGERNAME\" && vlc \"/tmp/$PASSENGERNAME\" 2>/dev/null
|
|
|
|
READ : $READ Zen
|
|
PARK : $PARK Zen
|
|
|
|
"
|
|
fi
|
|
########################################################################
|
|
# if [[ -d $PASSENGER ]]; then
|
|
########################################################################
|
|
# TODO # tar.gz and encrypt a whole directory #
|
|
# tar -zcf - directory | openssl aes-128-cbc -pbkdf2 -k "$BB" -salt -out directory.tar.gz.aes # Encrypt
|
|
# openssl aes-128-cbc -pbkdf2 -k "$BB" -d -salt -in directory.tar.gz.aes | tar -xz -f - # Decrypt
|
|
########################################################################
|
|
|
|
|
|
###########################################################
|
|
# Copy TAG into IPFS + ipfs name publish -k ${AA}.key
|
|
###########################################################
|
|
# ZenTAG CHAIN
|
|
echo "0" > ~/.zen/tag/${AAH}/_chain.n # Tag modification number (0 first)
|
|
|
|
NANODATE=$(date -u +%s%N)
|
|
echo "$NANODATE" > ~/.zen/tag/${AAH}/_chain.nanodate # Nanodate notification
|
|
|
|
echo "
|
|
_|_ _.o._
|
|
(_| |(_||| | : $NANODATE : 0
|
|
"
|
|
I=$(ipfs add -qr ~/.zen/tag/${AAH} | tail -n 1)
|
|
echo "${I}" > ~/.zen/tag/${AAH}/_chain
|
|
|
|
# Double IPFS add for _chain INIT
|
|
I=$(ipfs add -qr ~/.zen/tag/${AAH} | tail -n 1)
|
|
cp -f ~/.zen/tag/${AAH}/_chain ~/.zen/tag/${AAH}/_chain.prev
|
|
echo "${I}" > ~/.zen/tag/${AAH}/_chain
|
|
|
|
# IPNS name publish
|
|
J=$(ipfs name publish -k ${AA}.key --quieter /ipfs/${I})
|
|
echo "${J}" > ~/.zen/tag/${AAH}/_ipns
|
|
|
|
# INDEXING ZenTag to SWARM
|
|
mkdir -p ~/.zen/ipfs/.$ipfsnodeid/TAG/${J}
|
|
echo "${AA}" > ~/.zen/ipfs/.$ipfsnodeid/TAG/${J}/_tag.uid
|
|
# TODO add METADATA
|
|
# echo "" > ~/.zen/ipfs/.$ipfsnodeid/TAG/${J}/_tag.metadata.json
|
|
|
|
IWALLETS=$(ipfs add -rHq ~/.zen/ipfs | tail -n 1)
|
|
NODEIPNS=$(ipfs name publish --quieter /ipfs/$IWALLETS)
|
|
|
|
echo "
|
|
_ ____
|
|
(_)___ / __/____
|
|
/ / __ \/ /_/ ___/
|
|
/ / /_/ / __(__ )
|
|
/_/ .___/_/ /____/
|
|
/_/
|
|
$I
|
|
|
|
ZenTAG : ipfs ls /ipns/$J
|
|
NODE index : ipfs ls /ipns/$NODEIPNS/.$ipfsnodeid
|
|
"
|
|
|
|
########################################################################
|
|
# CREATE ZenTAG READ/WRITE QRCODES
|
|
### PRINTER IS HOOKED TO G1SSB NODE = G1DAB
|
|
########################################################################
|
|
echo "
|
|
_ _ _ _ _ _
|
|
/ \|_) / / \| \|_
|
|
\_X| \ \_\_/|_/|_ .................................
|
|
"
|
|
# READ QRCODE
|
|
qrencode -s 5 -o ~/.zen/tag/${AAH}/_QRCODE.read.png "RJ:${AA}#${J}"
|
|
# WRITE QRCODE
|
|
qrencode -s 5 -o ~/.zen/tag/${AAH}/_QRCODE.write.png "BJ:${BB}#${J}"
|
|
|
|
echo "CREATED !!
|
|
${AA}"
|
|
|
|
|
|
########################################################################
|
|
# SBOT PUBLISH
|
|
########################################################################
|
|
echo '
|
|
__ _ ____
|
|
(_ |_)/ \|
|
|
__)|_)\_/| POST
|
|
|
|
'
|
|
sbotc publish '{"type":"post","text":"ZenTAG created : ipfs ls /ipns/$J"}'
|
|
|
|
|
|
########################################################################
|
|
# IPFS CLEANING (MANUAL OPERATION)
|
|
########################################################################
|
|
echo "
|
|
|
|
>>> CLEAN IPFS REPO
|
|
##################################################################
|
|
ipfs pin ls -q --type recursive | xargs ipfs pin rm && ipfs repo gc
|
|
rm -f ~/.ipfs/keystore/*.key
|
|
rm -Rf ~/.zen/tag/*
|
|
rm -Rf ~/.zen/ipfs/.$ipfsnodeid/TAG
|
|
##################################################################"
|
|
########################################################################
|
|
exit 0
|