Skip to content

Instantly share code, notes, and snippets.

@jpitts
Last active November 4, 2020 19:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpitts/73acca4969fcb3ddd8a62d2666d116ed to your computer and use it in GitHub Desktop.
Save jpitts/73acca4969fcb3ddd8a62d2666d116ed to your computer and use it in GitHub Desktop.
How To Checksum A Dapp

How To Checksum A Dapp

For use with the How To Checksum A Dapp Medium article.

This example is for the dapp https://launchpad.ethereum.org, currently built from git commit c2e194e on 2020–11-04.

Full command

$ export DAPP_URL=https://launchpad.ethereum.org
$ export DAPP_DIR=$(echo "$DAPP_URL" | sed -e "s/\:\/\//__/" -e "s/\//__/")
$ date +%FT%H:%M:%S | awk -v dapp_dir="$DAPP_DIR" '{print dapp_dir "__" $1}' \
  | xargs mv $DAPP_DIR 2>/dev/null
$ wget -q -r --no-parent -k --restrict-file-names=unix --no-host-directories -P $DAPP_DIR $DAPP_URL \
  && find $DAPP_DIR -type f -print0 | xargs -0 -n1 shasum -a 384 \
    | sort -k2 | sed -e "s/$DAPP_DIR//" \
    | awk '{print "\"" $2 "\"" "," "\"" $1 "\"";}' > dapp_file_checksums.csv \
  && shasum -a 384 dapp_file_checksums.csv | awk 'NR==1{print $1}'

364fdd3eee6af86f43877be7547a4ddafe9795dd4f73b85fe3a577aec96ca09fba61ce04d48786670c5ac3416060c1b1

Command components

The following breaks the full command down into its component parts in order to understand how it works. This can also help you understand why the dapp checksum may be failing to generate the correct result.

Set the DAPP_URL, the URL of the website

$ export DAPP_URL=https://launchpad.ethereum.org

Set the DAPP_DIR, the website download directory

$ export DAPP_DIR=$(echo "$DAPP_URL" | sed -e "s/\:\/\//__/" -e "s/\//__/")

Move any present DAPP_DIR and files out of the way

$ date +%FT%H:%M:%S | awk -v dapp_dir="$DAPP_DIR" '{print dapp_dir "__" $1}' \
    | xargs mv $DAPP_DIR 2>/dev/null

Download the entire dapp website to the DAPP_DIR

$ wget -q -r --no-parent -k --restrict-file-names=unix --no-host-directories -P $DAPP_DIR $DAPP_URL

The above command results in a directory containing the files from the website:

$ ls -la

https__launchpad.ethereum.org

$ find $DAPP_DIR -type f | sort | sed -e "s/$DAPP_DIR//" 

/apple-touch-icon.png
/favicon-16x16.png
/favicon-32x32.png
/index.html
/robots.txt
/static/css/2.d9ee7e2f.chunk.css
/static/js/2.d0a1f97f.chunk.js
/static/js/main.ccc0b010.chunk.js

Perform a sha384 checksum on each file

$ find $DAPP_DIR -type f -print0 | xargs -0 -n1 shasum -a 384 \
    | sort -k2 | sed -e "s/$DAPP_DIR//"

The above command results in checksums on the contents of each file from the downloaded website:

856832c71f630cc4983338e70b309a9cc8c9e55a8c0069a8bc6c65650038237a5c8b2ed3dccd4a9fbaca53ea63459f58  /apple-touch-icon.png
6d5fe7dbc6995dda924df92fb7bbbec5f540ff6369816aa743958a47f8b54c904c7a5b90ab0bef5b57858bebbfe17ee5  /favicon-16x16.png
d4682e89467618c5be091b5773e86a5d04e5a8f7849a09a9699daedd558ca970cf42904fc5440038699bbd9127ca481b  /favicon-32x32.png
386ed2c468b28501a2c3a36fe471283c09e5c3716c0237839ef8f79959025394d0dd0e7a592e31100ba9db50b58ad5cf  /index.html
386ed2c468b28501a2c3a36fe471283c09e5c3716c0237839ef8f79959025394d0dd0e7a592e31100ba9db50b58ad5cf  /robots.txt
d6b56101048deae9b65796cf4d388fa196b93670b3fa79eabd0cf183ddfa23ace39556988ff23aa43dd41a1077fee111  /static/css/2.d9ee7e2f.chunk.css
32e22c3bad09f7c0d531ab3681b041f6394e0bf21f8f8c9659f8e495df1442e612e0cdee8088f01a9b05527fcf881041  /static/js/2.d0a1f97f.chunk.js
74b559835c5abc1e87d29d0461a412fabae612eaef143cc631cd88f8944d39f5cc453d069762a9a7498bd0b38741280a  /static/js/main.ccc0b010.chunk.js

Create a CSV file from the sha384 checksums on each file

$ find $DAPP_DIR -type f -print0 | xargs -0 -n1 shasum -a 384 \
    | sort -k2 | sed -e "s/$DAPP_DIR//" \
    | awk '{print "\"" $2 "\"" "," "\"" $1 "\"";}' > dapp_file_checksums.csv

Results in a CSV file containing file names and checksums of their contents:

$ cat dapp_file_checksums.csv

"/apple-touch-icon.png","856832c71f630cc4983338e70b309a9cc8c9e55a8c0069a8bc6c65650038237a5c8b2ed3dccd4a9fbaca53ea63459f58"
"/favicon-16x16.png","6d5fe7dbc6995dda924df92fb7bbbec5f540ff6369816aa743958a47f8b54c904c7a5b90ab0bef5b57858bebbfe17ee5"
"/favicon-32x32.png","d4682e89467618c5be091b5773e86a5d04e5a8f7849a09a9699daedd558ca970cf42904fc5440038699bbd9127ca481b"
"/index.html","386ed2c468b28501a2c3a36fe471283c09e5c3716c0237839ef8f79959025394d0dd0e7a592e31100ba9db50b58ad5cf"
"/robots.txt","386ed2c468b28501a2c3a36fe471283c09e5c3716c0237839ef8f79959025394d0dd0e7a592e31100ba9db50b58ad5cf"
"/static/css/2.d9ee7e2f.chunk.css","d6b56101048deae9b65796cf4d388fa196b93670b3fa79eabd0cf183ddfa23ace39556988ff23aa43dd41a1077fee111"
"/static/js/2.d0a1f97f.chunk.js","32e22c3bad09f7c0d531ab3681b041f6394e0bf21f8f8c9659f8e495df1442e612e0cdee8088f01a9b05527fcf881041"
"/static/js/main.ccc0b010.chunk.js","74b559835c5abc1e87d29d0461a412fabae612eaef143cc631cd88f8944d39f5cc453d069762a9a7498bd0b38741280a"

Perform a sha384 checksum on the dapp_file_checksums.csv file

$ shasum -a 384 dapp_file_checksums.csv | awk 'NR==1{print $1}'

364fdd3eee6af86f43877be7547a4ddafe9795dd4f73b85fe3a577aec96ca09fba61ce04d48786670c5ac3416060c1b1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment