#!/bin/sh # Interplane sign-in. Run the one command the sign-in page shows you: # curl -fsSL https://interplane.io/signin.sh | sh -s -- # It makes your key the first time (kept on this computer in ~/.interplane/key, never sent anywhere), # signs the page's one-time code, and gives you one block of text to paste into the box on the page. set -eu c=${1:-} case $c in interplane-forge-login:*) ;; *) echo "Copy the whole command from the sign-in page (https://interplane.io/login) and run it again." >&2; exit 2 ;; esac case $c in *[!a-z0-9:-]*) echo "That code does not look right. Copy the command from the sign-in page again." >&2; exit 2 ;; esac command -v ssh-keygen > /dev/null 2>&1 || { echo "This needs ssh-keygen (OpenSSH), which is missing on this computer." >&2; exit 2; } k=${INTERPLANE_KEY:-$HOME/.interplane/key} if [ ! -f "$k" ]; then mkdir -p "$(dirname "$k")"; chmod 700 "$(dirname "$k")" ssh-keygen -q -t ed25519 -N '' -C interplane -f "$k" echo "Made your Interplane key: $k (this file is your account; keep it)" >&2 fi [ -f "$k.pub" ] || ssh-keygen -y -f "$k" > "$k.pub" case $(cut -d' ' -f1 "$k.pub") in ssh-ed25519) ;; *) echo "The key $k is not an Ed25519 key." >&2; exit 2 ;; esac sig=$(printf %s "$c" | ssh-keygen -Y sign -f "$k" -n interplane-forge 2> /dev/null) || { echo "Signing failed with the key $k." >&2; exit 2; } b64d() { base64 -d 2> /dev/null || base64 -D; } # the account id: did:key:z + base58(0xed 0x01 + the 32 bytes of the public key) id=$(cut -d' ' -f2 "$k.pub" | b64d | od -An -v -tu1 | tr -s ' \n' ' ' | awk '{ n = 0; b[n++] = 237; b[n++] = 1; for (i = NF - 31; i <= NF; i++) b[n++] = $i + 0 al = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; s = ""; st = 0 while (st < n) { r = 0; for (i = st; i < n; i++) { v = r * 256 + b[i]; b[i] = int(v / 58); r = v % 58 } s = substr(al, r + 1, 1) s; while (st < n && b[st] == 0) st++ } printf "did:key:z%s", s }') out=$(printf '%s\n%s\n' "$id" "$sig") copied= for t in pbcopy wl-copy "xclip -selection clipboard" "xsel --clipboard --input" clip.exe; do if command -v "${t%% *}" > /dev/null 2>&1 && printf '%s\n' "$out" | $t 2> /dev/null; then copied=1; break; fi done echo printf '%s\n' "$out" echo if [ -n "$copied" ]; then echo "Copied. Go back to the sign-in page, paste into the box, press Sign in." >&2 else echo "Copy everything between the blank lines above, paste it into the box on the sign-in page, press Sign in." >&2 fi