2020-07-12 03:06:41 +02:00
#!/bin/bash
2020-07-12 03:36:24 +02:00
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)
2020-07-12 03:06:41 +02:00
sendmsg( ) {
2020-07-22 21:12:27 +02:00
local chan = " $1 "
local msg = " ${ @ : 2 } "
2020-07-12 03:06:41 +02:00
2020-07-18 02:59:31 +02:00
[ [ ! $chan || ! $msg ] ] && echo "Please select user and message." && exit 0
2020-07-12 03:06:41 +02:00
2020-07-18 02:59:31 +02:00
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
}
2020-07-23 02:16:31 +02:00
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é. "
}
2020-07-18 02:59:31 +02:00
info_account( ) {
2020-07-22 21:12:27 +02:00
local chan = " $1 "
2020-07-18 02:59:31 +02:00
[ [ ! $chan ] ] && echo "Please select user." && exit 0
2020-07-22 21:12:27 +02:00
local homedir = " $HOME /.bog/ids/axiomchat/ $chan "
2020-07-18 02:59:31 +02:00
if [ [ -d $homedir ] ] ; then
source $homedir /db
2020-07-22 21:12:27 +02:00
sendmsg $chan " Voici les identifiants de connexion de votre ḠCompte: \n \
Login: **$salt **\n Mot de passe: **$pepper **\n Clé 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 ** "
2020-07-18 02:59:31 +02:00
else
echo "Vous n'avez pas de compte chez nous."
fi
}
init_account( ) {
2020-07-22 21:12:27 +02:00
local chan = " $1 "
2020-07-18 02:59:31 +02:00
[ [ ! $chan ] ] && echo "Please select user." && exit 0
2020-07-22 21:12:27 +02:00
local homedir = " $HOME /.bog/ids/axiomchat/ $chan "
2020-07-18 02:59:31 +02:00
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
2020-07-22 21:12:27 +02:00
else
sendmsg $dest "Création de votre portefeuille..."
2020-07-18 02:59:31 +02:00
fi
# LOGIN (=SALT)
2020-07-22 21:12:27 +02:00
local salt = " $( $MY_PATH /../dunikey/diceware.sh 6) "
2020-07-18 02:59:31 +02:00
# PASS (=PEPPER)
2020-07-22 21:12:27 +02:00
local pepper = " $( $MY_PATH /../dunikey/diceware.sh 4) "
2020-07-18 02:59:31 +02:00
# The pubkey for this salt/papper peer
2020-07-22 21:12:27 +02:00
local pubkey = $( python3 $MY_PATH /../dunikey/key_create_dunikey.py " $salt " " $pepper " )
2020-07-18 02:59:31 +02:00
[ [ ! -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
2020-07-22 21:12:27 +02:00
# info_account $chan
echo -e " Votre ḠCompte a bien été créé.\nPubkey: ** $pubkey ** "
2020-07-18 02:59:31 +02:00
}
rm_account( ) {
2020-07-22 21:12:27 +02:00
local chan = " $1 "
2020-07-18 02:59:31 +02:00
[ [ ! $chan ] ] && echo "Please select user." && exit 0
2020-07-22 21:12:27 +02:00
local homedir = " $HOME /.bog/ids/axiomchat/ $chan "
2020-07-18 02:59:31 +02:00
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
2020-07-12 03:06:41 +02:00
}
2020-07-12 03:36:24 +02:00
2020-07-22 21:12:27 +02:00
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."
2020-07-23 02:16:31 +02:00
[ [ $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
2020-07-22 21:12:27 +02:00
local result = $( $silkaj --auth-file --file ~/.bog/ids/axiomchat/$chan /secret.dunikey tx --amount $amount --output $dest --comment " $comment " -y)
2020-07-23 02:16:31 +02:00
[ [ -n $result ] ] && echo " \`\`\` $result \`\`\` " || echo "Une erreur est survenu, votre transaction n'a pas été effecutée." && exit 0
2020-07-22 21:12:27 +02:00
}
2020-07-23 02:16:31 +02:00
history_account( ) {
2020-07-22 21:12:27 +02:00
local chan = " $1 "
local homedir = " $HOME /.bog/ids/axiomchat/ $chan "
source $homedir /db
2020-07-23 02:16:31 +02:00
# echo "$silkaj history $pubkey"
2020-07-22 21:12:27 +02:00
local result = $( $silkaj history $pubkey )
echo " \`\`\` $result \`\`\` "
}
2020-07-13 14:43:54 +02:00
#[[ $(type $@ | grep "est une fonction") ]] && $@ || echo "Veuillez préciser votre commande"