Skip to content

Instantly share code, notes, and snippets.

@mankins
Created February 20, 2024 12:17
Show Gist options
  • Save mankins/768456d1bac79bca1fb06c453a065396 to your computer and use it in GitHub Desktop.
Save mankins/768456d1bac79bca1fb06c453a065396 to your computer and use it in GitHub Desktop.
dibs for bash
#!/bin/bash
# debug mode
DEBUG_MODE=0
# read file from command line
if [ -z "$@" ]; then
echo "Usage: $0 <file>"
exit 1
fi
# calculate the sha256 of the file
sha256=$(openssl dgst -sha256 "$@" | sed 's/^.* //')
if [ $DEBUG_MODE -eq 1 ]; then
echo "sha256: $sha256"
fi
# generate 16 bytes of random data, converted to hex
nonce=$(openssl rand -hex 16)
if [ $DEBUG_MODE -eq 1 ]; then
echo "nonce: $nonce"
fi
# create a new tmp file which is the concatenation of the nonce and the file (in that order)
tmp=$(mktemp)
echo -n $nonce > $tmp
cat "$@" >> $tmp
# calculate the sha256 of the tmp file
proof_sha256=$(openssl dgst -sha256 $tmp | sed 's/^.* //')
if [ $DEBUG_MODE -eq 1 ]; then
echo "proof_sha256: $proof_sha256"
fi
# open the url in the default browser
open "https://dibs.directory/id/check/$sha256/sha256?nonce=$nonce&proof=$proof_sha256"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment