interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / social / signin.sh

43 lines · 2468 bytes Raw Blame History
1#!/bin/sh
2# Interplane sign-in. Run the one command the sign-in page shows you:
3# curl -fsSL https://interplane.io/signin.sh | sh -s -- <code from the page>
4# It makes your key the first time (kept on this computer in ~/.interplane/key, never sent anywhere),
5# signs the page's one-time code, and gives you one block of text to paste into the box on the page.
6set -eu
7c=${1:-}
8case $c in
9interplane-forge-login:*) ;;
10*) echo "Copy the whole command from the sign-in page (https://interplane.io/login) and run it again." >&2; exit 2 ;;
11esac
12case $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
13command -v ssh-keygen > /dev/null 2>&1 || { echo "This needs ssh-keygen (OpenSSH), which is missing on this computer." >&2; exit 2; }
14k=${INTERPLANE_KEY:-$HOME/.interplane/key}
15if [ ! -f "$k" ]; then
16 mkdir -p "$(dirname "$k")"; chmod 700 "$(dirname "$k")"
17 ssh-keygen -q -t ed25519 -N '' -C interplane -f "$k"
18 echo "Made your Interplane key: $k (this file is your account; keep it)" >&2
19fi
20[ -f "$k.pub" ] || ssh-keygen -y -f "$k" > "$k.pub"
21case $(cut -d' ' -f1 "$k.pub") in ssh-ed25519) ;; *) echo "The key $k is not an Ed25519 key." >&2; exit 2 ;; esac
22sig=$(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; }
23b64d() { base64 -d 2> /dev/null || base64 -D; }
24# the account id: did:key:z + base58(0xed 0x01 + the 32 bytes of the public key)
25id=$(cut -d' ' -f2 "$k.pub" | b64d | od -An -v -tu1 | tr -s ' \n' ' ' | awk '{
26 n = 0; b[n++] = 237; b[n++] = 1; for (i = NF - 31; i <= NF; i++) b[n++] = $i + 0
27 al = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; s = ""; st = 0
28 while (st < n) { r = 0; for (i = st; i < n; i++) { v = r * 256 + b[i]; b[i] = int(v / 58); r = v % 58 }
29 s = substr(al, r + 1, 1) s; while (st < n && b[st] == 0) st++ }
30 printf "did:key:z%s", s }')
31out=$(printf '%s\n%s\n' "$id" "$sig")
32copied=
33for t in pbcopy wl-copy "xclip -selection clipboard" "xsel --clipboard --input" clip.exe; do
34 if command -v "${t%% *}" > /dev/null 2>&1 && printf '%s\n' "$out" | $t 2> /dev/null; then copied=1; break; fi
35done
36echo
37printf '%s\n' "$out"
38echo
39if [ -n "$copied" ]; then
40 echo "Copied. Go back to the sign-in page, paste into the box, press Sign in." >&2
41else
42 echo "Copy everything between the blank lines above, paste it into the box on the sign-in page, press Sign in." >&2
43fi