Skip to content

Commit c1af1d7

Browse files
authored
Self attest with non-auto attestation (#1755)
* Self attest with non-auto attestation Signed-off-by: jamshale <[email protected]> * Fix: json loads default Signed-off-by: jamshale <[email protected]> * Fix: repair unit test Signed-off-by: jamshale <[email protected]> * Refactor more server client code Signed-off-by: jamshale <[email protected]> * Update/Add integration tests Signed-off-by: jamshale <[email protected]> * Update: comments Signed-off-by: jamshale <[email protected]> * Initiate the server client once when controller created Signed-off-by: jamshale <[email protected]> --------- Signed-off-by: jamshale <[email protected]>
1 parent 395e741 commit c1af1d7

File tree

12 files changed

+342
-289
lines changed

12 files changed

+342
-289
lines changed

webvh/.devcontainer/post-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ WORKSPACE_DIR=$(pwd)
88
python -m pip install --upgrade pip
99

1010
# Generate Poetry Lock file
11-
poetry lock --no-update
11+
poetry lock

webvh/integration/tests/test_anoncreds.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@
2222
async def create_did(agent):
2323
await agent.post(
2424
"/did/webvh/configuration",
25-
json={"server_url": SERVER_URL, "witness_key": WITNESS_KEY, "witness": True},
25+
json={
26+
"server_url": SERVER_URL,
27+
"witness_key": WITNESS_KEY,
28+
"witness": True,
29+
"auto_attest": True,
30+
},
2631
)
2732
identifier = str(uuid.uuid4())
2833
response = await agent.post(

webvh/integration/tests/test_register_did.py

Lines changed: 50 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,10 @@
44

55
import asyncio
66
import uuid
7-
from typing import Optional
87

98
import pytest
109
from acapy_controller import Controller
1110
from acapy_controller.controller import params
12-
from acapy_controller.protocols import (
13-
ConnRecord,
14-
InvitationMessage,
15-
OobRecord,
16-
oob_invitation,
17-
)
1811

1912
from .constants import (
2013
CONTROLLER_ENV,
@@ -26,89 +19,6 @@
2619
)
2720

2821

29-
async def didexchange(
30-
inviter: Controller,
31-
invitee: Controller,
32-
*,
33-
invite: Optional[InvitationMessage] = None,
34-
use_existing_connection: bool = False,
35-
alias: Optional[str] = None,
36-
):
37-
"""Connect two agents using did exchange protocol."""
38-
if not invite:
39-
invite = await oob_invitation(inviter)
40-
41-
invitee_oob_record = await invitee.post(
42-
"/out-of-band/receive-invitation",
43-
json=invite,
44-
params=params(
45-
use_existing_connection=use_existing_connection,
46-
alias=alias,
47-
),
48-
response=OobRecord,
49-
)
50-
51-
if use_existing_connection and invitee_oob_record == "reuse-accepted":
52-
inviter_oob_record = await inviter.event_with_values(
53-
topic="out_of_band",
54-
invi_msg_id=invite.id,
55-
event_type=OobRecord,
56-
)
57-
inviter_conn = await inviter.get(
58-
f"/connections/{inviter_oob_record.connection_id}",
59-
response=ConnRecord,
60-
)
61-
invitee_conn = await invitee.get(
62-
f"/connections/{invitee_oob_record.connection_id}",
63-
response=ConnRecord,
64-
)
65-
return inviter_conn, invitee_conn
66-
67-
invitee_conn = await invitee.post(
68-
f"/didexchange/{invitee_oob_record.connection_id}/accept-invitation",
69-
response=ConnRecord,
70-
)
71-
inviter_oob_record = await inviter.event_with_values(
72-
topic="out_of_band",
73-
invi_msg_id=invite.id,
74-
state="done",
75-
event_type=OobRecord,
76-
)
77-
inviter_conn = await inviter.event_with_values(
78-
topic="connections",
79-
event_type=ConnRecord,
80-
rfc23_state="request-received",
81-
invitation_key=inviter_oob_record.our_recipient_key,
82-
)
83-
# TODO Remove after ACA-Py 0.12.0
84-
# There's a bug with race conditions in the OOB multiuse handling
85-
await asyncio.sleep(1)
86-
inviter_conn = await inviter.post(
87-
f"/didexchange/{inviter_conn.connection_id}/accept-request",
88-
response=ConnRecord,
89-
)
90-
91-
await invitee.event_with_values(
92-
topic="connections",
93-
connection_id=invitee_conn.connection_id,
94-
rfc23_state="response-received",
95-
)
96-
invitee_conn = await invitee.event_with_values(
97-
topic="connections",
98-
connection_id=invitee_conn.connection_id,
99-
rfc23_state="completed",
100-
event_type=ConnRecord,
101-
)
102-
inviter_conn = await inviter.event_with_values(
103-
topic="connections",
104-
connection_id=inviter_conn.connection_id,
105-
rfc23_state="completed",
106-
event_type=ConnRecord,
107-
)
108-
109-
return inviter_conn, invitee_conn
110-
111-
11222
@pytest.mark.asyncio
11323
async def test_create_single_tenant():
11424
"""Test Controller protocols."""
@@ -314,3 +224,53 @@ async def test_create_with_witness_and_manual_attest():
314224
did_web = f"did:web:{WEBVH_DOMAIN}:{TEST_NAMESPACE}:{identifier}"
315225
assert response["did_document"]["id"] == did_web
316226
assert response["did_document"]["alsoKnownAs"][0].startswith("did:webvh:")
227+
228+
229+
@pytest.mark.asyncio
230+
async def test_create_self_witness_and_manual_attest():
231+
"""Test Controller protocols."""
232+
async with Controller(base_url=WITNESS) as witness:
233+
witness_config = (await witness.get("/status/config"))["config"]
234+
server_url: str = witness_config["plugin_config"]["did-webvh"]["server_url"]
235+
236+
# Configure WebVH Witness
237+
response = await witness.post(
238+
"/did/webvh/configuration",
239+
json={
240+
"server_url": server_url,
241+
"witness_key": WITNESS_KEY,
242+
"witness": True,
243+
"auto_attest": False,
244+
},
245+
)
246+
assert response["multikey"] == WITNESS_KEY
247+
248+
# Ensure the witness key is properly configured
249+
response = await witness.get(f"/wallet/keys/{WITNESS_KEY}")
250+
assert response["kid"] == WITNESS_KID
251+
252+
# Create the initial did
253+
identifier = str(uuid.uuid4())
254+
response = await witness.post(
255+
"/did/webvh/controller/create",
256+
json={"options": {"namespace": TEST_NAMESPACE, "identifier": identifier}},
257+
)
258+
259+
status = response.get("status")
260+
assert status == "pending"
261+
262+
response = await witness.get("/did/webvh/witness/registrations")
263+
entry = response.get("results", []).pop()
264+
assert isinstance(entry, dict)
265+
266+
await witness.post(
267+
"/did/webvh/witness/registrations",
268+
params=params(did=entry["id"]),
269+
)
270+
await asyncio.sleep(3)
271+
272+
# Confirm DID is published
273+
response = await witness.get(f"/resolver/resolve/{entry['id']}")
274+
did_web = f"did:web:{WEBVH_DOMAIN}:{TEST_NAMESPACE}:{identifier}"
275+
assert response["did_document"]["id"] == did_web
276+
assert response["did_document"]["alsoKnownAs"][0].startswith("did:webvh:")

webvh/poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webvh/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ python = "^3.12"
1111
# explicitly installed with the plugin if desired.
1212
acapy-agent = { version = "~1.3.0", optional = true }
1313

14-
did-webvh = "^1.0.0rc0"
14+
did-webvh = "1.0.0rc0"
1515
jcs = "^0.2.1"
1616
multiformats = "^0.3.1.post4"
1717
bitstring = "^4.3.0"

webvh/webvh/did/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
}
1515

1616
SUPPORTED_KEY_TYPES = ["Multikey", "JsonWebKey"]
17+
18+
WEBVH_METHOD = "did:webvh:1.0"

0 commit comments

Comments
 (0)