astroport/zen/tools/make_G1SSB_secret.sh

160 lines
4.8 KiB
Bash
Executable File

#!/bin/bash
########################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
echo '
########################################################################
# \\///
# qo-op
############# '$MY_PATH/$ME'
########################################################################
# Make a G1SSB Account
########################################################################
'
# INSTALL Silkaj, CLI for Duniter
if [[ ! $(which silkaj) ]]; then
echo '**************************************************************
__ ___
(_ | | |/ /\ |
__) _|_ |_ |\ /--\ \_|
#Libre Money Layer
'
mkdir -p ~/.zen
sudo apt update || true
libzzz=$(sudo apt-cache search libsodium | awk '{print $1}' | grep libsodium2)
sudo apt install build-essential jq $libzzz -y
sudo pip3 install base58
sudo apt install python3-pip python3-setuptools python3-wheel -y
pip3 install silkaj --user
echo 'PATH=$PATH:~/.local/bin' >> ~/.bashrc && source ~/.bashrc
fi
# INSTALL sbotc
if [[ ! $(which sbotc) ]]; then
cd /tmp
sudo apt install libsodium-dev jq -y
git clone https://git.scuttlebot.io/%25133ulDgs%2FoC1DXjoK04vDFy6DgVBB%2FZok15YJmuhD5Q%3D.sha256 sbotc
cd sbotc
make
sudo make install
cd $MY_PATH
fi
if [[ -d ~/.ssb ]]; then
echo "ScuttleButt is already installed...??"
echo "Do you want to create a new ~/.ssb identity ? (y)/n"
read isitok
if [[ "$isitok" == "y" ]]; then
# TEST ssb-server Install
ssbSERVER=$(which ssb-server)
# If exists backup ~/.ssb to ~/.ssb_$USER SSB (one time only !)
[[ -d ~/.ssb_$USER ]] && echo "BACKUP already existing... ~/.ssb_$USER !!! Manual check please..." && exit 1
[[ $ssbSERVER == "" ]] && echo "Check your ssb-server install... Cannot find it !!" && exit 1 \
|| kill -9 $(ps auxf --sort=+utime | grep -w ssb-server| grep -v -E 'color=auto|grep' | tail -n 1 | awk '{print $2}')
[[ -d ~/.ssb ]] && [[ ! -d ~/.ssb_$USER ]] && mv ~/.ssb ~/.ssb_$USER
# CREATE ~/.ssb_astroport
[[ ! -d ~/.ssb_astroport ]] && mkdir -p ~/.ssb_astroport && cd ~/.ssb_astroport
# Symlink ~/.ssb -> ~/.ssb_astroport
[[ -L ~/.ssb ]] && rm ~/.ssb
[[ -d ~/.ssb_astroport ]] && ln -s ~/.ssb_astroport ~/.ssb
else
echo "You must remove '~/.ssb' before running $ME";
exit 1;
fi
fi
mkdir -p ~/.ssb
echo "WELCOME CREATING YOUR G1 SSB ACCOUNT !!!"
echo '
__ __ __ _
/__ /| (_ (_ |_)
\_| | __) __) |_)
CHOOSE YOU LOGIN or LEAVE BLANK & HIT ENTER FOR AUTO GENERATION
'
read salt
[[ $salt != "" ]] && echo "CHOOSE PASSWORD?" && read pepper && [[ $pepper == "" ]] && exit 1
if [[ "$salt" == "" && "$pepper" == "" ]]; then
echo '
._ _ ._ _ ._ _ _ ._ o _
| | | | | (/_ | | | (_) | | | (_
passphrase generator...'
# GENERATE MNEMONIC KEY: 9 MOTS
# LOGIN (=SALT) 6 WORDS
salt="$($MY_PATH/diceware.sh 6)"
# PASS (=PEPPER) 3 WORDS
pepper="$($MY_PATH/diceware.sh 3)"
echo "........."
echo "REMEMBER YOUR CREDENTIALS !!!
login (salt) : $salt
password : $pepper"
fi
# CREATE ~/.ssb/secret.dunikey
python3 $MY_PATH/key_create_dunikey.py "$salt" "$pepper"
[[ -f /tmp/secret.dunikey ]] && mv /tmp/secret.dunikey ~/.ssb/secret.dunikey || exit 1
# CREATE SSB secret
g1pub=$(cat ~/.ssb/secret.dunikey | grep "pub" | cut -d ' ' -f 2)
g1priv=$(cat ~/.ssb/secret.dunikey | grep "sec" | cut -d ' ' -f 2)
ssbpub=$(echo $g1pub | base58 -d | base64)
ssbpriv=$(echo $g1priv | base58 -d | base64)
cat > ~/.ssb/secret <<EOF
# This secret is related to your G1Wallet - https://cesium.app
# silkaj balance $g1pub
# ID (salt): $salt / Pass: $pepper
# THIS KEY IS YOURS! REMIND IT AND KEEP IT SAFE AS A REAL WALLET
# chmod 400 ~/.zen/secret
{
"curve": "ed25519",
"public": "$ssbpub.ed25519",
"private": "$ssbpriv.ed25519",
"id": "@$ssbpub.ed25519"
}
# WARNING! It's vital that you DO NOT edit OR share your secret name
# instead, share your public name
# your SSB public name: @$ssbpub.ed25519
EOF
echo "
_
|__|_ \ / _ o | _.
|_ |_ \/ (_) | | (_|
Your G1SSB KEY is made !!
# Your SSB ID is @$ssbpub.ed25519
Install Patchwork : https://github.com/ssbc/patchwork/releases/
# Libre Money Wallet
Use your credential with https://cesium.app
login (salt) : $salt
password : $pepper
"
# INITIALISE manifest
[[ $ssbSERVER ]] && [[ ! -f ~/.ssb/manifest.json ]] && printf '{"manifest":"sync"}' > ~/.ssb/manifest.json
[[ $ssbSERVER ]] && ssb-server start &
[[ $ssbSERVER ]] && [[ ! -f ~/.ssb/manifest.json ]] && sbotc -t async manifest > ~/.ssb/manifest.json
exit 0