From a6332d50cbba6cbf545effa28216a29228a0ac31 Mon Sep 17 00:00:00 2001 From: "Charles E. Lehner" Date: Fri, 11 Feb 2022 17:05:18 -0500 Subject: [PATCH] Add ION example scripts --- cli/README.md | 7 ++++ cli/tests/ion-create-deactivate.sh | 48 +++++++++++++++++++++++++ cli/tests/ion-create-recover.sh | 52 +++++++++++++++++++++++++++ cli/tests/ion-create-update-svc.sh | 55 ++++++++++++++++++++++++++++ cli/tests/ion-create-update-vm.sh | 57 ++++++++++++++++++++++++++++++ 5 files changed, 219 insertions(+) create mode 100755 cli/tests/ion-create-deactivate.sh create mode 100755 cli/tests/ion-create-recover.sh create mode 100755 cli/tests/ion-create-update-svc.sh create mode 100755 cli/tests/ion-create-update-vm.sh diff --git a/cli/README.md b/cli/README.md index bfe4d731..483b4aa9 100644 --- a/cli/README.md +++ b/cli/README.md @@ -335,6 +335,13 @@ DIDKit's DID method operation commands ([create](#didkit-did-create-did-method), See the included [shell script](tests/example.sh). +See also the following shell scripts demonstrating create, update, recover and deactivate operations: +- [create and update service](tests/ion-create-update-svc.sh) +- [create and update verification method](tests/ion-create-update-vm.sh) +- [create and recover](tests/ion-create-recover.sh) +- [create and deactivate](tests/ion-create-deactivate.sh) + +[ssi]: https://github.com/spruceid/ssi [JWK]: https://tools.ietf.org/html/rfc7517 [ld-proofs]: https://w3c-ccg.github.io/ld-proofs/ [vc-http-api]: https://w3c-ccg.github.io/vc-http-api/ diff --git a/cli/tests/ion-create-deactivate.sh b/cli/tests/ion-create-deactivate.sh new file mode 100755 index 00000000..1a956d63 --- /dev/null +++ b/cli/tests/ion-create-deactivate.sh @@ -0,0 +1,48 @@ +#!/bin/sh +set -e +cd "$(dirname "$0")" + +# Create and use temp directory if does not already exist +dir=did-ion-test +if test -d "$dir" +then + printf 'Directory already exists: %s\n' "$dir" >&2 + exit 1 +fi +mkdir "$dir" +cd "$dir" + +# Generate initial update keypair and initial recovery keypair +didkit key generate secp256k1 > 1-u.jwk +didkit key generate secp256k1 > 1-r.jwk +# Construct Create operation with initial public keys +didkit did-create ion -r 1-r.jwk -u 1-u.jwk | tee 1-create.json +# Get long-form and short-form DID from Create operation +longdid=$(didkit did-from-tx < 1-create.json) +shortdid=$(echo -n "$longdid" | sed 's/:[^:]*$//') +didsuffix=$(echo -n "$shortdid" | sed 's/.*://') +echo "Sidetree DID Suffix: $didsuffix" +echo "DID (long-form/unpublished): $longdid" +echo "DID (short-form/canonical): $shortdid" + +# Now that the DID suffix is set, rename the directory to it. +cd .. +mv "$dir" "$didsuffix" +cd "$didsuffix" + +# Submit Create operation +export DID_ION_API_URL=http://localhost:3000/ +read -p "Press enter to submit Create operation. " _ +didkit did-submit-tx < 1-create.json + +# Construct Deactivate operation +didkit did-deactivate "$shortdid" -k 1-r.jwk | tee 2-deactivate.json +# Submit operation +read -p 'Press enter to submit Deactivate operation. ' _ +if ! didkit did-submit-tx < 2-deactivate.json +then + # Provide retry in case submission failed, e.g. because the + # create operation has not yet been processed. + read -p 'Press enter to retry Deactivate operation. ' _ + didkit did-submit-tx < 2-deactivate.json +fi diff --git a/cli/tests/ion-create-recover.sh b/cli/tests/ion-create-recover.sh new file mode 100755 index 00000000..45efab64 --- /dev/null +++ b/cli/tests/ion-create-recover.sh @@ -0,0 +1,52 @@ +#!/bin/sh +set -e +cd "$(dirname "$0")" + +# Create and use temp directory if does not already exist +dir=did-ion-test +if test -d "$dir" +then + printf 'Directory already exists: %s\n' "$dir" >&2 + exit 1 +fi +mkdir "$dir" +cd "$dir" + +# Generate initial update keypair and initial recovery keypair +didkit key generate secp256k1 > 1-u.jwk +didkit key generate secp256k1 > 1-r.jwk +# Construct Create operation with initial public keys +didkit did-create ion -r 1-r.jwk -u 1-u.jwk | tee 1-create.json +# Get long-form and short-form DID from Create operation +longdid=$(didkit did-from-tx < 1-create.json) +shortdid=$(echo -n "$longdid" | sed 's/:[^:]*$//') +didsuffix=$(echo -n "$shortdid" | sed 's/.*://') +echo "Sidetree DID Suffix: $didsuffix" +echo "DID (long-form/unpublished): $longdid" +echo "DID (short-form/canonical): $shortdid" + +# Now that the DID suffix is set, rename the directory to it. +cd .. +mv "$dir" "$didsuffix" +cd "$didsuffix" + +# Submit Create operation +export DID_ION_API_URL=http://localhost:3000/ +read -p "Press enter to submit Create operation. " _ +didkit did-submit-tx < 1-create.json + +# Generate new update keypair and recovery keypair for recover operation +didkit key generate secp256k1 > 2-u.jwk +didkit key generate secp256k1 > 2-r.jwk + +# Construct Recover operation +didkit did-recover "$shortdid" -R 1-r.jwk -r 2-r.jwk -u 2-u.jwk | tee 2-recover.json +# Submit operation +read -p 'Press enter to submit Recover operation. ' _ +if ! didkit did-submit-tx < 2-recover.json +then + # Provide retry in case submission failed, e.g. because the + # create operation has not yet been processed. + read -p 'Press enter to retry Recover operation. ' _ + didkit did-submit-tx < 2-recover.json +fi diff --git a/cli/tests/ion-create-update-svc.sh b/cli/tests/ion-create-update-svc.sh new file mode 100755 index 00000000..a0c8482d --- /dev/null +++ b/cli/tests/ion-create-update-svc.sh @@ -0,0 +1,55 @@ +#!/bin/sh +set -e +cd "$(dirname "$0")" +export DID_ION_API_URL=http://localhost:3000/ + +# Create and use temp directory if does not already exist +dir=did-ion-test +if test -d "$dir" +then + printf 'Directory already exists: %s\n' "$dir" >&2 + exit 1 +fi +mkdir "$dir" +cd "$dir" + +# Generate initial update keypair and initial recovery keypair +didkit key generate secp256k1 > 1-u.jwk +didkit key generate secp256k1 > 1-r.jwk +# Construct Create operation with initial public keys +didkit did-create ion -r 1-r.jwk -u 1-u.jwk | tee 1-create.json +# Get long-form and short-form DID from Create operation +longdid=$(didkit did-from-tx < 1-create.json) +shortdid=$(echo -n "$longdid" | sed 's/:[^:]*$//') +didsuffix=$(echo -n "$shortdid" | sed 's/.*://') +echo "Sidetree DID Suffix: $didsuffix" +echo "DID (long-form/unpublished): $longdid" +echo "DID (short-form/canonical): $shortdid" + +# Now that the DID suffix is set, rename the directory to it. +cd .. +mv "$dir" "$didsuffix" +cd "$didsuffix" + + +# Submit Create operation +read -p "Press enter to submit Create operation. " _ +didkit did-submit-tx < 1-create.json + +# Construct DID URL for new service endpoint +svc="$shortdid#svc-1" + +# Construct Update operation to add verification key to DID document +didkit did-update -U 1-u.jwk -u 2-u.jwk \ + set-service "$svc" \ + -t DIDKitDemoService \ + -e https://demo.didkit.dev/ \ + | tee 2-update.json +# Submit Update operation +read -p 'Press enter to submit Update operation. ' _ +if ! didkit did-submit-tx < 2-update.json +then + read -p 'Press enter to retry submit operation. ' _ + didkit did-submit-tx < 2-update.json +fi + diff --git a/cli/tests/ion-create-update-vm.sh b/cli/tests/ion-create-update-vm.sh new file mode 100755 index 00000000..f105790b --- /dev/null +++ b/cli/tests/ion-create-update-vm.sh @@ -0,0 +1,57 @@ +#!/bin/sh +set -e +cd "$(dirname "$0")" + +# Create and use temp directory if does not already exist +dir=did-ion-test +if test -d "$dir" +then + printf 'Directory already exists: %s\n' "$dir" >&2 + exit 1 +fi +mkdir "$dir" +cd "$dir" + +# Generate initial update keypair and initial recovery keypair +didkit key generate secp256k1 > 1-u.jwk +didkit key generate secp256k1 > 1-r.jwk +# Construct Create operation with initial public keys +didkit did-create ion -r 1-r.jwk -u 1-u.jwk | tee 1-create.json +# Get long-form and short-form DID from Create operation +longdid=$(didkit did-from-tx < 1-create.json) +shortdid=$(echo -n "$longdid" | sed 's/:[^:]*$//') +didsuffix=$(echo -n "$shortdid" | sed 's/.*://') +echo "Sidetree DID Suffix: $didsuffix" +echo "DID (long-form/unpublished): $longdid" +echo "DID (short-form/canonical): $shortdid" + +# Now that the DID suffix is set, rename the directory to it. +cd .. +mv "$dir" "$didsuffix" +cd "$didsuffix" + +# Submit Create operation +export DID_ION_API_URL=http://localhost:3000/ +read -p "Press enter to submit Create operation. " _ +didkit did-submit-tx < 1-create.json + +# Generate verification key to be added to DID document +didkit key generate secp256k1 > 2-v.jwk +# Construct DID URL for new verification method +vm="$shortdid#key-1" + +# Generate new update key keypair +didkit key generate secp256k1 > 2-u.jwk +# Construct Update operation to add verification key to DID document +didkit did-update -U 1-u.jwk -u 2-u.jwk \ + set-verification-method "$vm" -k 2-v.jwk \ + --authentication --assertionMethod -t JsonWebKey2020 \ + | tee 2-update.json +# Submit Update operation +read -p 'Press enter to submit Update operation. ' _ +if ! didkit did-submit-tx < 2-update.json +then + read -p 'Press enter to retry submit operation. ' _ + didkit did-submit-tx < 2-update.json +fi +