Skip to content

Commit

Permalink
🗑️ Remove v1 protocol version and default to v2 (#902)
Browse files Browse the repository at this point in the history
* ✅ remove v1 protocol version from parameterised tests

* 🎨 use "v2"

* 🔥 delete v1 services

* ✅ remove v1 from tests, or switch to v2 protocol

* 🎨 remove usage of v1 protocol version or models

* 🎨 remove protocol_version from request bodies in docs / switch to v2 in response

* 🎨 remove protocol_version from request bodies / remove need for custom Verifier facade

* ✅ update tests to no longer set protocol_version in request bodies

* ✅ fix tests

* 🎨

* 🔥 remove unused methods

* ✅ 100% test coverage again

* 🎨

* ✅ add look_back to fix sporadic error

* 🔊 Change ledger-browser and -nodes log level to WARN

* 🎨 fix test module name

* 🗑️ drop protocol_version from exchange models

* 🎨 update docs to no longer reference protocol_version

* 🧪 remove test usage or assertion of protocol_version

* 📝 Update openapi docs

* 🎨 apply pretty print formatting

Compacted with `https://jsonformatter.org/json-pretty-print` and then formatted with `prettier`

* 📝 Update openapi docs with protocol version changes
  • Loading branch information
ff137 authored Oct 9, 2024
1 parent f5c3e72 commit 5bc9c02
Show file tree
Hide file tree
Showing 60 changed files with 342 additions and 2,708 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ method. For example:

```bash
poetry run pytest \
app/tests/e2e/test_verifier.py::test_accept_proof_request_oob_v1 \
app/tests/e2e/test_verifier_oob.py::test_accept_proof_request_oob \
--log-cli-level=1
```

Expand Down
9 changes: 2 additions & 7 deletions app/models/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator

from shared.exceptions import CloudApiValueError
from shared.models.protocol import IssueCredentialProtocolVersion


class CredentialType(str, Enum):
Expand Down Expand Up @@ -51,15 +50,11 @@ class CredentialWithConnection(CredentialBase):
connection_id: str


class CredentialWithProtocol(CredentialBase):
protocol_version: IssueCredentialProtocolVersion = IssueCredentialProtocolVersion.V2


class SendCredential(CredentialWithProtocol, CredentialWithConnection):
class SendCredential(CredentialWithConnection):
pass


class CreateOffer(CredentialWithProtocol):
class CreateOffer(CredentialBase):
pass


Expand Down
2 changes: 0 additions & 2 deletions app/models/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from pydantic import BaseModel, Field, ValidationInfo, field_validator, model_validator

from shared.exceptions import CloudApiValueError
from shared.models.protocol import PresentProofProtocolVersion


class ProofRequestType(str, Enum):
Expand Down Expand Up @@ -60,7 +59,6 @@ def check_indy_proof_request(cls, values: Union[dict, "ProofRequestBase"]):


class ProofRequestMetadata(BaseModel):
protocol_version: PresentProofProtocolVersion = PresentProofProtocolVersion.V2
comment: Optional[str] = None


Expand Down
63 changes: 12 additions & 51 deletions app/routes/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@
from app.services import revocation_registry
from app.services.acapy_ledger import schema_id_from_credential_definition_id
from app.services.acapy_wallet import assert_public_did
from app.services.issuer.acapy_issuer_v2 import IssuerV2
from app.services.trust_registry.util.issuer import assert_valid_issuer
from app.util.acapy_issuer_utils import (
IssueCredentialFacades,
issuer_from_id,
issuer_from_protocol_version,
)
from app.util.did import did_from_credential_definition_id, qualified_did_sov
from app.util.pagination import (
descending_query_parameter,
Expand All @@ -37,12 +33,7 @@
)
from app.util.retry_method import coroutine_with_retry_until_value
from shared.log_config import get_logger
from shared.models.credential_exchange import (
CredentialExchange,
Role,
State,
back_to_v1_credential_state,
)
from shared.models.credential_exchange import CredentialExchange, Role, State

logger = get_logger(__name__)

Expand All @@ -67,7 +58,6 @@ async def send_credential(
"ld_credential_detail": {...}, <-- Required if type is ld_proof
"save_exchange_record": true, <-- Whether the credential exchange record should be saved on completion.
"connection_id": "string", <-- The issuer's reference to the connection they want to submit the credential to.
"protocol_version": "v2" <-- v1 is supported, but deprecated.
}
```
Setting the `save_exchange_record` field to True will save the exchange record after the credential is accepted.
Expand All @@ -90,14 +80,11 @@ async def send_credential(
body={
# Do not log credential attributes:
"connection_id": credential.connection_id,
"protocol_version": credential.protocol_version,
"credential_type": credential.type,
}
)
bound_logger.debug("POST request received: Send credential")

issuer = issuer_from_protocol_version(credential.protocol_version)

async with client_from_auth(auth) as aries_controller:
# Assert the agent has a public did
try:
Expand All @@ -122,7 +109,7 @@ async def send_credential(

try:
bound_logger.debug("Sending credential")
result = await issuer.send_credential(
result = await IssuerV2.send_credential(
controller=aries_controller, credential=credential
)
except CloudApiException as e:
Expand Down Expand Up @@ -162,7 +149,6 @@ async def create_offer(
"indy_credential_detail": {...}, <-- Required if type is indy
"ld_credential_detail": {...}, <-- Required if type is ld_proof
"save_exchange_record": true, <-- Whether the credential exchange record should be saved on completion.
"protocol_version": "v2" <-- v1 is supported, but deprecated.
}
```
For a detailed technical specification of the credential issuing process, refer to the [Aries Issue Credential v2
Expand All @@ -181,14 +167,11 @@ async def create_offer(
bound_logger = logger.bind(
body={
# Do not log credential attributes:
"protocol_version": credential.protocol_version,
"credential_type": credential.type,
}
)
bound_logger.debug("POST request received: Create credential offer")

issuer = issuer_from_protocol_version(credential.protocol_version)

async with client_from_auth(auth) as aries_controller:
# Assert the agent has a public did
try:
Expand All @@ -212,7 +195,7 @@ async def create_offer(
await assert_valid_issuer(public_did, schema_id)

bound_logger.debug("Creating offer")
result = await issuer.create_offer(
result = await IssuerV2.create_offer(
controller=aries_controller,
credential=credential,
)
Expand Down Expand Up @@ -251,11 +234,9 @@ async def request_credential(
bound_logger = logger.bind(body={"credential_exchange_id": credential_exchange_id})
bound_logger.debug("POST request received: Send credential request")

issuer = issuer_from_id(credential_exchange_id)

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Fetching records")
record = await issuer.get_record(aries_controller, credential_exchange_id)
record = await IssuerV2.get_record(aries_controller, credential_exchange_id)

schema_id = None
if record.type == "indy":
Expand All @@ -279,7 +260,7 @@ async def request_credential(
# Make sure the issuer is allowed to issue this credential according to trust registry rules

bound_logger.debug("Requesting credential")
result = await issuer.request_credential(
result = await IssuerV2.request_credential(
controller=aries_controller, credential_exchange_id=credential_exchange_id
)

Expand Down Expand Up @@ -323,11 +304,9 @@ async def store_credential(
bound_logger = logger.bind(body={"credential_exchange_id": credential_exchange_id})
bound_logger.debug("POST request received: Store credential")

issuer = issuer_from_id(credential_exchange_id)

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Storing credential")
result = await issuer.store_credential(
result = await IssuerV2.store_credential(
controller=aries_controller, credential_exchange_id=credential_exchange_id
)

Expand Down Expand Up @@ -389,21 +368,8 @@ async def get_credentials(
bound_logger.debug("GET request received: Get credentials")

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Fetching v1 records")
v1_records = await IssueCredentialFacades.V1.value.get_records(
controller=aries_controller,
limit=limit,
offset=offset,
order_by=order_by,
descending=descending,
connection_id=connection_id,
role=role,
state=back_to_v1_credential_state(state) if state else None,
thread_id=str(thread_id) if thread_id else None,
)

bound_logger.debug("Fetching v2 records")
v2_records = await IssueCredentialFacades.V2.value.get_records(
result = await IssuerV2.get_records(
controller=aries_controller,
limit=limit,
offset=offset,
Expand All @@ -415,11 +381,10 @@ async def get_credentials(
thread_id=str(thread_id) if thread_id else None,
)

result = v1_records + v2_records
if result:
bound_logger.debug("Successfully fetched v1 and v2 records.")
bound_logger.debug("Successfully fetched records.")
else:
bound_logger.debug("No v1 or v2 records returned.")
bound_logger.debug("No records returned.")
return result


Expand Down Expand Up @@ -462,11 +427,9 @@ async def get_credential(
bound_logger = logger.bind(body={"credential_exchange_id": credential_exchange_id})
bound_logger.debug("GET request received: Get credentials by credential id")

issuer = issuer_from_id(credential_exchange_id)

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Getting credential record")
result = await issuer.get_record(
result = await IssuerV2.get_record(
controller=aries_controller, credential_exchange_id=credential_exchange_id
)

Expand Down Expand Up @@ -500,11 +463,9 @@ async def remove_credential_exchange_record(
"DELETE request received: Remove credential exchange record by id"
)

issuer = issuer_from_id(credential_exchange_id)

async with client_from_auth(auth) as aries_controller:
bound_logger.debug("Deleting credential")
await issuer.delete_credential_exchange_record(
await IssuerV2.delete_credential_exchange_record(
controller=aries_controller, credential_exchange_id=credential_exchange_id
)

Expand Down
Loading

0 comments on commit 5bc9c02

Please sign in to comment.