133 lines
5.3 KiB
Bash
Executable File
133 lines
5.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
MY_PATH="`dirname \"$0\"`" # relative
|
|
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
|
|
|
|
[[ -n $MY_PATH/.env ]] && source $MY_PATH/.env || (echo "Please create $MY_PATH/.env as $MY_PATH/.env.example" && exit 1)
|
|
|
|
sendmsg() {
|
|
local chan="$1"
|
|
local msg="${@:2}"
|
|
|
|
[[ ! $chan || ! $msg ]] && echo "Please select user and message." && exit 0
|
|
|
|
curl -s -H "X-Auth-Token: $API_TOKEN" \
|
|
-H "X-User-Id: $API_ID" \
|
|
-H "Content-type:application/json" \
|
|
$API_URL/api/v1/chat.postMessage \
|
|
-d "{ \"channel\": \"$chan\", \"text\": \"$msg\" }" > /dev/null 2>&1
|
|
}
|
|
|
|
getPubkey() {
|
|
url="$node/wot/members"
|
|
[[ -z $username || $username == "bot" ]] && username=$(echo $1 | tr -d '@')
|
|
# old way: local pubkey=$(curl -m 5 -s $url | grep -wiB 1 $username | grep "pubkey" | awk -F '"' '{ print $4 }')
|
|
local pubkey=$(curl -m 10 -s $url | jq -r --arg username "$username" '.results[] | select(.uid==$username) | .pubkey')
|
|
[[ $pubkey ]] && echo "$pubkey" || echo "none"
|
|
}
|
|
|
|
getPseudo() {
|
|
url="$node/wot/members"
|
|
args=$(echo $@ | tr ' ' '\n' | grep -v 'biz' | tr '\n' ' ')
|
|
[ $(echo $args | wc -w) -ge 2 ] && pubkey=$(echo $args | awk '{ print $2 }') || pubkey=$1
|
|
# pubkey="$1"
|
|
pubkey=$(echo $pubkey | tr -d '@')
|
|
local pseudo=$(curl -m 10 -s $url | jq -r --arg pubkey "$pubkey" '.results[] | select(.pubkey==$pubkey) | .uid')
|
|
[[ $pseudo ]] && echo "Le pseudo correspondant à la clé publique $pubkey est: @$pseudo" || echo "La clé publique $pubkey n'a pas de pseudo associé."
|
|
}
|
|
|
|
info_account() {
|
|
local chan="$1"
|
|
[[ ! $chan ]] && echo "Please select user." && exit 0
|
|
local homedir="$HOME/.bog/ids/axiomchat/$chan"
|
|
|
|
if [[ -d $homedir ]]; then
|
|
source $homedir/db
|
|
sendmsg $chan "Voici les identifiants de connexion de votre ḠCompte: \n \
|
|
Login: **$salt**\nMot de passe: **$pepper**\nClé publique: **$pubkey** \n \
|
|
Calcul du solde de votre compte en cours ..."
|
|
|
|
local solde=$($silkaj balance $pubkey | grep "Total Quantitative" | awk -F= '{ print $2 }' | cut -c2-)
|
|
echo "Votre solde est de **$solde**"
|
|
else
|
|
echo "Vous n'avez pas de compte chez nous."
|
|
fi
|
|
}
|
|
|
|
init_account() {
|
|
local chan="$1"
|
|
[[ ! $chan ]] && echo "Please select user." && exit 0
|
|
local homedir="$HOME/.bog/ids/axiomchat/$chan"
|
|
if [[ -f $homedir/secret.dunikey ]]; then
|
|
pubkey=$(cat $homedir/secret.dunikey| grep "pub: " | awk '{ print $2 }')
|
|
echo "Vous disposez déjà d'un portefeuille Ḡ1: **$pubkey**"
|
|
exit 0
|
|
else
|
|
sendmsg $dest "Création de votre portefeuille..."
|
|
fi
|
|
|
|
# LOGIN (=SALT)
|
|
local salt="$($MY_PATH/../dunikey/diceware.sh 6)"
|
|
# PASS (=PEPPER)
|
|
local pepper="$($MY_PATH/../dunikey/diceware.sh 4)"
|
|
# The pubkey for this salt/papper peer
|
|
local pubkey=$(python3 $MY_PATH/../dunikey/key_create_dunikey.py "$salt" "$pepper")
|
|
|
|
[[ ! -f /tmp/secret.dunikey ]] && echo "Arf, problem happens making your secret.dunikey" && exit 0
|
|
[[ ! -d $homedir ]] && mkdir -p $homedir
|
|
[[ -f /tmp/secret.dunikey ]] && rm -f $homedir/secret.dunikey && mv /tmp/secret.dunikey $homedir/secret.dunikey
|
|
|
|
echo -e "salt=\"$salt\"\npepper=\"$pepper\"\npubkey=\"$pubkey\"" > $homedir/db
|
|
|
|
# info_account $chan
|
|
echo -e "Votre ḠCompte a bien été créé.\nPubkey: **$pubkey**"
|
|
}
|
|
|
|
rm_account() {
|
|
local chan="$1"
|
|
[[ ! $chan ]] && echo "Please select user." && exit 0
|
|
local homedir="$HOME/.bog/ids/axiomchat/$chan"
|
|
|
|
if [[ -d $homedir ]]; then
|
|
source $homedir/db
|
|
echo "Suppression des données de votre portefeuille de votre ḠBanque."
|
|
echo -e "Login: **$salt**\nMot de passe: **$pepper**\nClé publique: **$pubkey**"
|
|
rm -r $homedir
|
|
echo "Suppression terminé, nous ne disposons plus d'aucune donnée vous concernant."
|
|
else
|
|
echo "Vous n'avez pas de compte chez nous."
|
|
fi
|
|
}
|
|
|
|
tx() {
|
|
local chan="$1"
|
|
local dest="$2"
|
|
local amount=$(echo "$3" | tr ',' '.')
|
|
local comment="${@:4}"
|
|
local homedir="$HOME/.bog/ids/axiomchat/$chan"
|
|
|
|
! [[ $dest && $amount ]] && echo "Des arguments sont manquants. Ex: pay Do99s6wQR2JLfhirPdpAERSjNbmjjECzGxHNJMiNKT3p 10 Merci pour la tarte" && exit 0
|
|
|
|
#This shoudl works, but accents are ok and should not... [[ ! "$comment" =~ [^a-zA-Z0-9\ ] ]] && echo OK
|
|
[[ "$comment" =~ [^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-?:'('')'.+\ ] ]] && echo "Votre commentaire contient des charactères non autorisés." && exit 0
|
|
[[ -z "$comment" ]] && local comment="Transaction effectuee avec BoG."
|
|
[[ $amount =~ '-' ]] && echo "La somme de votre transaction ne peut être négative: **$amount** Ḡ1" && exit 0
|
|
[[ $(echo $dest | wc -c) -le 43 ]] && local dest=$(getPubkey $dest)
|
|
[[ $dest == "none" ]] && echo "Ce pseudo ne correspond à aucun membre Ḡ1 connu." && exit 0
|
|
|
|
local result=$($silkaj --auth-file --file ~/.bog/ids/axiomchat/$chan/secret.dunikey tx --amount $amount --output $dest --comment "$comment" -y)
|
|
[[ -n $result ]] && echo "\`\`\`$result\`\`\`" || echo "Une erreur est survenu, votre transaction n'a pas été effecutée." && exit 0
|
|
}
|
|
|
|
history_account() {
|
|
local chan="$1"
|
|
local homedir="$HOME/.bog/ids/axiomchat/$chan"
|
|
source $homedir/db
|
|
|
|
# echo "$silkaj history $pubkey"
|
|
local result=$($silkaj history $pubkey)
|
|
echo "\`\`\`$result\`\`\`"
|
|
}
|
|
|
|
#[[ $(type $@ | grep "est une fonction") ]] && $@ || echo "Veuillez préciser votre commande"
|