Skip to content

Commit

Permalink
Generate an OOB invitation with a pres req
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas ONeil <[email protected]>
  • Loading branch information
loneil committed Jun 18, 2024
1 parent f9c8a3f commit 6f7e324
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 29 deletions.
33 changes: 32 additions & 1 deletion oidc-controller/api/core/acapy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ..config import settings
from .config import AgentConfig, MultiTenantAcapy, SingleTenantAcapy
from .models import CreatePresentationResponse, WalletDid
from .models import CreatePresentationResponse, OobCreateInvitationResponse, WalletDid

_client = None
logger = structlog.getLogger(__name__)
Expand All @@ -16,6 +16,7 @@
PUBLIC_WALLET_DID_URI = "/wallet/did/public"
CREATE_PRESENTATION_REQUEST_URL = "/present-proof/create-request"
PRESENT_PROOF_RECORDS = "/present-proof/records"
OOB_CREATE_INVITATION = "/out-of-band/create-invitation"


class AcapyClient:
Expand Down Expand Up @@ -125,3 +126,33 @@ def get_wallet_did(self, public=False) -> WalletDid:

logger.debug(f"<<< get_wallet_did -> {did}")
return did

def oob_create_invitation(
self, presentation_exchange: dict, use_public_did: bool
) -> OobCreateInvitationResponse:
logger.debug(">>> oob_create_invitation")
create_invitation_payload = {
"attachments": [
{
"id": presentation_exchange["presentation_exchange_id"],
"type": "present-proof",
"data": {"json": presentation_exchange},
}
],
"use_public_did": use_public_did,
}

resp_raw = requests.post(
self.acapy_host + OOB_CREATE_INVITATION,
headers=self.agent_config.get_headers(),
json=create_invitation_payload,
)

# TODO: Determine if this should assert it received a json object
assert resp_raw.status_code == 200, resp_raw.content

resp = json.loads(resp_raw.content)
result = OobCreateInvitationResponse.parse_obj(resp)

logger.debug("<<< oob_create_invitation")
return result
10 changes: 10 additions & 0 deletions oidc-controller/api/core/acapy/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional, Dict
from ..aries import OutOfBandMessage

from pydantic import BaseModel

Expand All @@ -17,3 +18,12 @@ class CreatePresentationResponse(BaseModel):
thread_id: str
presentation_exchange_id: str
presentation_request: Dict


class OobCreateInvitationResponse(BaseModel):
invi_msg_id: str
invitation_url: str
oob_id: str
trace: bool
state: str
invitation: OutOfBandMessage
6 changes: 3 additions & 3 deletions oidc-controller/api/core/aries/service_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ServiceDecorator(BaseModel):

class OOBServiceDecorator(ServiceDecorator):
# ServiceDecorator
recipient_keys: Optional[List[str]] = None
routing_keys: Optional[List[str]] = Field(default=[])
service_endpoint: Optional[str] = None
recipient_keys: Optional[List[str]] = Field(default=None, alias="recipientKeys")
routing_keys: Optional[List[str]] = Field(default=None, alias="routingKeys")
service_endpoint: Optional[str] = Field(default=None, alias="serviceEndpoint")
id: str = Field(default="did:vc-authn-oidc:123456789zyxwvutsr#did-communication")
type: str = Field(default="did-communication")
priority: int = 0
Expand Down
28 changes: 3 additions & 25 deletions oidc-controller/api/routers/oidc.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
from ..authSessions.models import AuthSessionPatch, AuthSessionState
from ..core.acapy.client import AcapyClient
from ..core.aries import (
OOBServiceDecorator,
OutOfBandMessage,
OutOfBandPresentProofAttachment,
PresentationRequestMessage,
PresentProofv10Attachment,
ServiceDecorator,
Expand Down Expand Up @@ -124,29 +121,10 @@ async def get_authorize(request: Request, db: Database = Depends(get_db)):

msg = None
if settings.USE_OOB_PRESENT_PROOF:
if settings.USE_OOB_LOCAL_DID_SERVICE:
oob_s_d = OOBServiceDecorator(
service_endpoint=client.service_endpoint,
recipient_keys=[wallet_did.verkey],
).dict()
else:
oob_s_d = wallet_did.verkey

msg = PresentationRequestMessage(
id=pres_exch_dict["thread_id"],
request=[byo_attachment],
)
oob_msg = OutOfBandMessage(
request_attachments=[
OutOfBandPresentProofAttachment(
id="request-0",
data={"json": msg.dict(by_alias=True)},
)
],
id=pres_exch_dict["thread_id"],
services=[oob_s_d],
oob_invite_response = client.oob_create_invitation(
pres_exch_dict, use_public_did
)
msg_contents = oob_msg
msg_contents = oob_invite_response.invitation
else:
s_d = ServiceDecorator(
service_endpoint=client.service_endpoint, recipient_keys=[wallet_did.verkey]
Expand Down

0 comments on commit 6f7e324

Please sign in to comment.