-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve routes and did registration process
Signed-off-by: PatStLouis <[email protected]>
- Loading branch information
1 parent
1629591
commit f61facd
Showing
14 changed files
with
205 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
.env* | ||
__pycache__/ | ||
*cache* | ||
*.db | ||
venv/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
FROM python:3.12 | ||
|
||
WORKDIR /trustdidweb-server-py | ||
WORKDIR /fastapi | ||
|
||
ENV VIRTUAL_ENV=/opt/venv | ||
RUN python3 -m venv $VIRTUAL_ENV | ||
ENV PATH="$VIRTUAL_ENV/bin:$PATH" | ||
|
||
COPY server/* ./ | ||
COPY requirements.txt ./ | ||
|
||
RUN pip install --upgrade pip | ||
RUN pip install -r requirements.txt | ||
|
||
COPY app ./app | ||
COPY config.py main.py ./ | ||
|
||
CMD [ "python", "main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from fastapi import FastAPI, APIRouter | ||
from fastapi.responses import JSONResponse | ||
from app.routers import identifiers | ||
from config import settings | ||
from app.plugins import AskarStorage | ||
|
||
app = FastAPI(title=settings.PROJECT_TITLE, version=settings.PROJECT_VERSION) | ||
|
||
|
||
api_router = APIRouter() | ||
|
||
|
||
@api_router.get("/server/status", tags=["Server"], include_in_schema=False) | ||
async def server_status(): | ||
return JSONResponse(status_code=200, content={"status": "ok"}) | ||
|
||
|
||
@api_router.get("/.well-known/did.json", tags=["Server"], include_in_schema=False) | ||
async def get_main_did_document(): | ||
did_document = await AskarStorage().fetch("didDocument", settings.DID_WEB_BASE) | ||
return JSONResponse(status_code=200, content=did_document) | ||
|
||
|
||
api_router.include_router(identifiers.router, tags=["Identifiers"]) | ||
|
||
|
||
app.include_router(api_router) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,13 @@ | ||
from fastapi import HTTPException | ||
from config import settings | ||
from app.models.web_requests import RegisterDID | ||
from app.plugins import AskarVerifier, AskarStorage | ||
from app.utilities import find_key, find_proof | ||
from app.plugins import AskarStorage | ||
|
||
|
||
async def identifier_available(namespace: str, identifier: str): | ||
if await AskarStorage().fetch("didDocument", f"{namespace}:{identifier}"): | ||
if await AskarStorage().fetch("didDocument", f"{settings.DID_WEB_BASE}:{namespace}:{identifier}"): | ||
raise HTTPException(status_code=409, detail="Identifier unavailable.") | ||
|
||
|
||
async def did_document_exists(namespace: str, identifier: str): | ||
if not await AskarStorage().fetch("didDocument", f"{namespace}:{identifier}"): | ||
if not await AskarStorage().fetch("didDocument", f"{settings.DID_WEB_BASE}:{namespace}:{identifier}"): | ||
raise HTTPException(status_code=404, detail="Ressource not found.") | ||
|
||
|
||
async def valid_did_registration( | ||
namespace: str, identifier: str, request_body: RegisterDID | ||
): | ||
document = request_body.model_dump(by_alias=True, exclude_none=True)["didDocument"] | ||
proofs = document.pop("proof") | ||
try: | ||
assert ( | ||
document["id"] == f"{settings.DID_WEB_BASE}:{namespace}:{identifier}" | ||
), "Id mismatch between DID Document and requested endpoint." | ||
assert ( | ||
len(document["verificationMethod"]) >= 1 | ||
), "DID Documentmust contain at least 1 verificationMethod." | ||
assert ( | ||
isinstance(proofs, list) and len(proofs) == 2 | ||
), "Insuficient proofs, must contain a client and an endorser proof." | ||
except AssertionError as msg: | ||
raise HTTPException(status_code=400, detail=str(msg)) | ||
|
||
endorser_proof = find_proof(proofs, f"{settings.DID_WEB_BASE}#key-01") | ||
endorser_key = settings.ENDORSER_MULTIKEY | ||
AskarVerifier(endorser_key).verify_proof(document, endorser_proof) | ||
|
||
client_proof = find_proof(proofs, document["verificationMethod"][0]["id"]) | ||
client_key = find_key(document, client_proof["verificationMethod"]) | ||
AskarVerifier(client_key).verify_proof(document, client_proof) | ||
|
||
return document |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from typing import Dict, Any | ||
from pydantic import BaseModel, Field | ||
from .did_document import SecuredDidDocument | ||
|
||
|
||
class BaseModel(BaseModel): | ||
def model_dump(self, **kwargs) -> Dict[str, Any]: | ||
return super().model_dump(by_alias=True, exclude_none=True, **kwargs) | ||
|
||
|
||
class RegisterDID(BaseModel): | ||
didDocument: SecuredDidDocument = Field() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.