Skip to content

Commit a3b500a

Browse files
committed
Add CLI example/test script
1 parent 4ed5107 commit a3b500a

4 files changed

Lines changed: 102 additions & 0 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ jobs:
4848
- name: Test
4949
run: cargo test --verbose --workspace
5050

51+
- name: Test CLI
52+
run: cli/tests/example.sh
53+
5154
- name: Install Rust Android targets
5255
run: make -C lib install-rustup-android
5356

‎cli/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ Corresponds to [/verify/presentations](https://w3c-ccg.github.io/vc-http-api/#/V
104104

105105
Options and output format are the same as for [didkit vc-verify-credential](#didkit-vc-verify-credential).
106106

107+
## Examples
108+
109+
See the included [shell script](tests/example.sh).
110+
107111
[JWK]: https://tools.ietf.org/html/rfc7517
108112
[ld-proofs]: https://w3c-ccg.github.io/ld-proofs/
109113
[vc-http-api]: https://w3c-ccg.github.io/vc-http-api/

‎cli/tests/.gitignore‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
credential-signed.jsonld
2+
credential-verify-result.json
3+
key.jwk
4+
presentation-signed.jsonld
5+
presentation-unsigned-constructed.jsonld
6+
presentation-verify-result.json

‎cli/tests/example.sh‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/bin/sh
2+
# Example script using DIDKit for key generation, credential/presentation
3+
# issuance and verification.
4+
5+
# Exit if anything fails
6+
set -e
7+
8+
# Pretty-print JSON
9+
print_json() {
10+
file=${1?file}
11+
if command -v jq >/dev/null 2>&1; then
12+
jq . "$file"
13+
elif command -v json_pp >/dev/null 2>&1; then
14+
json_pp "$file"
15+
else
16+
cat "$file"
17+
fi
18+
}
19+
20+
# Run in source directory
21+
cd "$(dirname "$0")"
22+
23+
# Build didkit CLI
24+
cargo build -p didkit_cli
25+
26+
# Get didkit in $PATH
27+
export PATH=$PWD/../../target/debug:$PATH
28+
29+
# Create a keypair if needed
30+
if [ -e key.jwk ]; then
31+
echo 'Using existing keypair.'
32+
else
33+
didkit generate-ed25519-key > key.jwk
34+
echo 'Generated keypair.'
35+
fi
36+
echo
37+
38+
# Get DID (did:key) for keypair
39+
did=$(didkit key-to-did-key -k key.jwk)
40+
printf 'DID: %s\n\n' "$did"
41+
42+
# Issue verifiable credential
43+
didkit vc-issue-credential \
44+
-k key.jwk \
45+
-v "$did" \
46+
-p assertionMethod \
47+
< credential-unsigned.jsonld \
48+
> credential-signed.jsonld
49+
echo 'Issued verifiable credential:'
50+
print_json credential-signed.jsonld
51+
echo
52+
53+
# Verify verifiable credential
54+
didkit vc-verify-credential \
55+
-p assertionMethod \
56+
< credential-signed.jsonld \
57+
> credential-verify-result.json
58+
echo 'Verified verifiable credential:'
59+
print_json credential-verify-result.json
60+
echo
61+
62+
# Create presentation embedding verifiable credential
63+
{
64+
echo '{"verifiableCredential": '
65+
cat credential-signed.jsonld
66+
echo ','
67+
tail +2 presentation-unsigned.jsonld
68+
} > presentation-unsigned-constructed.jsonld
69+
echo 'Created presentation.'
70+
echo
71+
72+
# Issue verifiable presentation
73+
didkit vc-issue-presentation \
74+
-k key.jwk \
75+
-v "$did" \
76+
-p authentication \
77+
< presentation-unsigned-constructed.jsonld \
78+
> presentation-signed.jsonld
79+
echo 'Issued verifiable presentation:'
80+
print_json presentation-signed.jsonld
81+
echo
82+
83+
# Verify verifiable presentation
84+
didkit vc-verify-presentation \
85+
-p authentication \
86+
< presentation-signed.jsonld \
87+
> presentation-verify-result.json
88+
echo 'Verified verifiable presentation:'
89+
print_json presentation-verify-result.json

0 commit comments

Comments
 (0)