Skip to content

Commit 92decb7

Browse files
committed
initial commit
Signed-off-by: pstlouis <patrick.st-louis@opsecid.ca>
1 parent ac44ee4 commit 92decb7

22 files changed

Lines changed: 947 additions & 43 deletions

.github/workflows/static.yml

Lines changed: 0 additions & 43 deletions
This file was deleted.

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
venv/
2+
.venv/
3+
*.egg-info/
4+
.python-version
5+
uv.lock
6+
outputs/*
7+
__pycache__/

README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# WebVH Tutorial
2+
3+
## Task 1: Set Up Your Environment
4+
5+
### GH Page & Repository
6+
7+
Create a new repo from this [template](https://github.com/new?template_name=didwebvh-tutorial&template_owner=OpSecId)
8+
Enable GH pages Settings -> Pages
9+
Set the source to Deploy from a branch
10+
Deploy from the main branch `/(root)` directory
11+
12+
### Docker & CLI
13+
14+
```bash
15+
# Clone tutorial repo and cd into root directory
16+
git clone https://github.com/opsecid/didwebvh-tutorial
17+
cd didwebvh-tutorial
18+
19+
# Ensure docker is properly configured
20+
docker compose version
21+
22+
# Build and start the tutorial containers
23+
docker compose up -d --build
24+
25+
# To clear the agent wallet and restart
26+
docker compose up -d --build --force-recreate
27+
28+
# Confirm cli container is functional
29+
docker exec webvh-tutorial-cli webvh
30+
31+
# Create cli alias
32+
alias webvh-cli="docker exec webvh-tutorial-cli webvh"
33+
34+
# Confirm alias is registered
35+
webvh-cli --help
36+
37+
```
38+
39+
## Task 2: Create the first log entry
40+
41+
```bash
42+
# Run the new-did command, using the gh-page url as the origin value
43+
webvh-cli new-did --origin https://example.com
44+
45+
# Create the authorization key pair
46+
webvh-cli new-key
47+
48+
# Define the DID parameters
49+
webvh-cli did-params --update-key <multikey> --method 0.5
50+
51+
# Generate the SCID input file with a current timestamp
52+
webvh-cli gen-scid-input --version-time <datetime>
53+
54+
```
55+
56+
## Task 3: Generate the SCID (Self-Certifying Identifier)
57+
58+
```bash
59+
# Run the following command to generate the scid value and add an alsoKnownAs reference to our DID document:
60+
webvh-cli gen-scid-value
61+
62+
```
63+
64+
## Task 4: Generate the Version ID (Entry Hash)
65+
66+
Run the following command to generate the version ID:
67+
`webvh-cli gen-version-id`
68+
69+
## Task 5: Generate the Data Integrity Proof
70+
71+
Run the following command to sign the log entry with the update key, and add the line to our log file:
72+
`webvh-cli add-proof --update-key <>`
73+
74+
## Task 6: Publish the DID Log Entry
75+
76+
Use the new-line command to add the current line to the log file
77+
`webvh-cli new-line`
78+
79+
Commit the `did.json` and `did.jsonl` files and their content at the root of the repository you created at step one.
80+
81+
## Task 7: Resolve the DID
82+
83+
Resolve your DID with the tutorial agent
84+
http://agent.webvh-tutorial.localhost/api/doc#/resolver/get_resolver_resolve__did_
85+
86+
You can also visit https://uniresolver.io
87+
88+
You can resolve both the webvh and web did.
89+
90+
## Task 8: Update the DID
91+
92+
```bash
93+
# Create a keypair and add a verification method
94+
webvh-cli new-key
95+
webvh-cli add-vm --multikey <>
96+
97+
# Generate the new version ID and sign the log entry
98+
webvh-cli gen-version-id
99+
webvh-cli add-proof --update-key <>
100+
101+
# Add to the log file
102+
webvh-cli new-line
103+
104+
```
105+
106+
Resolve your DID again.
107+
108+
109+
110+
## Commands
111+
```bash
112+
_________________________________________________________________
113+
Usage: webvh [OPTIONS] COMMAND [ARGS]...
114+
115+
WebVH Tutorial
116+
117+
Options:
118+
--help Show this message and exit.
119+
120+
Commands:
121+
add-proof Add a Data Integrity Proof to the log entry with a...
122+
add-vm Add a verification method to the did document.
123+
did-params Set the DID parameters and update key.
124+
gen-scid-input Generate the scid input.
125+
gen-scid-value Generate the SCID value from the input.
126+
gen-version-id Generate the version ID.
127+
new-did Configure the base did document from a DID location URL.
128+
new-key Create new key pair.
129+
new-line Append line to log file and add alsoKnownAs reference...
130+
_________________________________________________________________
131+
Usage: webvh new-did [OPTIONS]
132+
133+
Configure the base did document from a DID location URL.
134+
135+
Options:
136+
--auto Automate creation.
137+
--origin TEXT The DID location URL.
138+
_________________________________________________________________
139+
Usage: webvh did-params [OPTIONS]
140+
141+
Set the DID parameters and update key.
142+
143+
Options:
144+
--method TEXT Method to use.
145+
--update-key TEXT Provided update key value to use.
146+
_________________________________________________________________
147+
Usage: webvh gen-scid-input [OPTIONS]
148+
149+
Generate the scid input.
150+
151+
Options:
152+
--version-time TEXT The version time.
153+
_________________________________________________________________
154+
Usage: webvh add-proof [OPTIONS]
155+
156+
Add a Data Integrity Proof to the log entry with a provided update key.
157+
158+
Options:
159+
--update-key TEXT The update key to use.
160+
_________________________________________________________________
161+
```

cli/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.12
2+
3+
WORKDIR /cli
4+
5+
COPY pyproject.toml main.py ./
6+
7+
RUN pip install -e .

cli/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#
File renamed without changes.

cli/commands/__init__.py

Whitespace-only changes.

cli/commands/setup.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import click
2+
import json
3+
from did_webvh.core.date_utils import make_timestamp
4+
from did_webvh.core.state import DocumentState
5+
from .utils import (
6+
insert_placeholder,
7+
insert_scid,
8+
setup_files,
9+
write_document,
10+
origin_to_did,
11+
create_key,
12+
add_also_known_as,
13+
initial_state
14+
)
15+
from ..main import DID_CORE_CONTEXT, WEBVH_METHODS, SCID_PLACEHOLDER
16+
17+
@click.command('new-did-config')
18+
@click.option('--origin', help='The DID location URL.')
19+
def new_did_config(origin):
20+
"""Configure the base did document from a DID location URL."""
21+
22+
if not origin:
23+
raise click.ClickException('Missing DID location URL.')
24+
25+
setup_files()
26+
27+
did_doc = {
28+
"@context": [DID_CORE_CONTEXT],
29+
"id": origin_to_did(origin)
30+
}
31+
32+
click.echo(write_document('did', did_doc))
33+
34+
@click.command('set-parameters')
35+
@click.option('--method', default='1.0', help='Method to use.')
36+
def set_parameters(update_key, method):
37+
"""Set the DID parameters and update key."""
38+
39+
if method not in WEBVH_METHODS:
40+
raise click.ClickException('Invalid method version.')
41+
42+
parameters = {
43+
"scid": SCID_PLACEHOLDER,
44+
"method": f'did:webvh:{method}',
45+
"updateKeys": [create_key().get('multikey')]
46+
}
47+
48+
click.echo(write_document('parameters', parameters))
49+
50+
@click.command('gen-scid-input')
51+
@click.option('--version-time', help='The version time.')
52+
def gen_scid_input(version_time):
53+
"""Generate the scid input."""
54+
55+
with open('outputs/did.json', 'r') as f:
56+
did_doc = json.loads(f.read())
57+
58+
with open('outputs/parameters.json', 'r') as f:
59+
parameters = json.loads(f.read())
60+
61+
scid_input = {
62+
"versionTime": version_time or make_timestamp()[1],
63+
"parameters": parameters,
64+
"state": insert_placeholder(did_doc)
65+
}
66+
67+
click.echo(write_document('scid_input', scid_input))
68+
69+
@click.command('gen-scid-value')
70+
def gen_scid_value():
71+
"""Generate the SCID value from the input and add alsoKnownAs reference to DID doducment."""
72+
73+
with open('outputs/scid_input.json', 'r') as f:
74+
scid_input = json.loads(f.read())
75+
76+
# genesis = DocumentState.initial(
77+
# params=scid_input.get('parameters'),
78+
# document=scid_input.get('state'),
79+
# timestamp=scid_input.get('versionTime')
80+
# )
81+
82+
genesis = initial_state(scid_input)
83+
add_also_known_as(genesis.document.get('id'))
84+
draft_log_entry = insert_scid(scid_input, genesis.scid)
85+
86+
click.echo(write_document('draft_log_entry', draft_log_entry))

0 commit comments

Comments
 (0)