Skip to content

Commit

Permalink
Add ION example scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
clehner committed Feb 11, 2022
1 parent ffada32 commit 9c51b9a
Show file tree
Hide file tree
Showing 4 changed files with 221 additions and 0 deletions.
48 changes: 48 additions & 0 deletions cli/tests/ion-create-deactivate.sh
Original file line number Diff line number Diff line change
@@ -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 generate-secp256k1-key > 1-u.jwk
didkit generate-secp256k1-key > 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 to add verification key to DID document
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
52 changes: 52 additions & 0 deletions cli/tests/ion-create-recover.sh
Original file line number Diff line number Diff line change
@@ -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 generate-secp256k1-key > 1-u.jwk
didkit generate-secp256k1-key > 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 generate-secp256k1-key > 2-u.jwk
didkit generate-secp256k1-key > 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
64 changes: 64 additions & 0 deletions cli/tests/ion-create-update-svc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/sh
set -e
cd "$(dirname "$0")"
export DID_ION_API_URL=http://localhost:3000/

if false; then

# 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 generate-secp256k1-key > 1-u.jwk
didkit generate-secp256k1-key > 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

else

cd EiD9XruTmYlnZNAqYMjKDSosqnHkAHuw8GeR8nIGpr7nCg
shortdid=did:ion:test:EiD9XruTmYlnZNAqYMjKDSosqnHkAHuw8GeR8nIGpr7nCg

fi

# 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

57 changes: 57 additions & 0 deletions cli/tests/ion-create-update-vm.sh
Original file line number Diff line number Diff line change
@@ -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 generate-secp256k1-key > 1-u.jwk
didkit generate-secp256k1-key > 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 generate-secp256k1-key > 2-v.jwk
# Construct DID URL for new verification method
vm="$shortdid#key-1"

# Generate new update key keypair
didkit generate-secp256k1-key > 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

0 comments on commit 9c51b9a

Please sign in to comment.