Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#19 from krzosa/master
Browse files Browse the repository at this point in the history
Merge with krzosa/master
  • Loading branch information
Krzosa Karol authored Mar 26, 2021
2 parents 1c6ddca + 04e4c1b commit 794fdfb
Show file tree
Hide file tree
Showing 43 changed files with 780 additions and 536 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,22 +208,6 @@ To start debugging hit Ctrl + Shift + P (The command menu) type in start debuggi
* Proof presentation step might not work properly if all the schema fields are not filled so that it doesnt have the None value(can be filled even with meaningless info)
* Errors seem to be propagated to the next stage of the protocol, even though first stage passed the next stage can throw a invalid structure error

### Code Keywords to look for what changed (case insensitive)

* Original
* Krzosa
* THCF












# Hyperledger Aries Cloud Agent - Python <!-- omit in toc -->

Expand Down
9 changes: 9 additions & 0 deletions aries_cloudagent/aathcf/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from aries_cloudagent.messaging.base_handler import HandlerException


def run_standalone_async(name, func):
if name == "__main__":
import asyncio

loop = asyncio.get_event_loop()
loop.run_until_complete(func())
loop.close()


def debug_handler(log, context, MessageClass):
"""
Checks if MessageClass is of correct type, checks if connection is intact
Expand Down
2 changes: 1 addition & 1 deletion aries_cloudagent/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def execute(argv: Sequence[str] = None):

# thcf
settings["personal_storage_registered_types"] = {
"local": "aries_cloudagent.pdstorage_thcf.local.LocalPersonalDataStorage",
"local": "aries_cloudagent.pdstorage_thcf.local.LocalPDS",
"data_vault": "aries_cloudagent.pdstorage_thcf.data_vault.DataVault",
"own_your_data": "aries_cloudagent.pdstorage_thcf.own_your_data.OwnYourDataVault",
}
Expand Down
4 changes: 2 additions & 2 deletions aries_cloudagent/config/default_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from ..wallet.provider import WalletProvider


from ..pdstorage_thcf.base import BasePersonalDataStorage
from ..pdstorage_thcf.base import BasePDS
from ..pdstorage_thcf.provider import PersonalDataStorageProvider


Expand Down Expand Up @@ -82,7 +82,7 @@ async def bind_providers(self, context: InjectionContext):
)

context.injector.bind_provider(
BasePersonalDataStorage,
BasePDS,
PersonalDataStorageProvider(),
)

Expand Down
16 changes: 8 additions & 8 deletions aries_cloudagent/config/pdstorage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .injection_context import InjectionContext
from ..pdstorage_thcf.models.saved_personal_storage import SavedPersonalStorage
from ..pdstorage_thcf.base import BasePersonalDataStorage
from ..pdstorage_thcf.models.saved_personal_storage import SavedPDS
from ..pdstorage_thcf.base import BasePDS
from ..storage.error import StorageNotFoundError


Expand All @@ -9,25 +9,25 @@ async def personal_data_storage_config(context: InjectionContext):
When package gets loaded by acapy, create singleton instances for
all saved personal storages
"""
all_saved_storages = await SavedPersonalStorage.query(context)
all_saved_storages = await SavedPDS.query(context)
print("SETUP !", all_saved_storages)
for saved_storage in all_saved_storages:
pds: BasePersonalDataStorage = await context.inject(
BasePersonalDataStorage,
pds: BasePDS = await context.inject(
BasePDS,
{"personal_storage_type": saved_storage.get_pds_name()},
)
pds.settings = saved_storage.settings

if all_saved_storages == []:
default_storage = SavedPersonalStorage(state=SavedPersonalStorage.ACTIVE)
default_storage = SavedPDS(state=SavedPDS.ACTIVE)

await default_storage.save(context)
print("CREATED DEFAULT STORAGE")

# make sure an active storage exists
try:
await SavedPersonalStorage.retrieve_active(context)
await SavedPDS.retrieve_active(context)
except StorageNotFoundError:
default_storage = SavedPersonalStorage(state=SavedPersonalStorage.ACTIVE)
default_storage = SavedPDS(state=SavedPDS.ACTIVE)

await default_storage.save(context)
82 changes: 82 additions & 0 deletions aries_cloudagent/generated_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# this is auto-generated by swagger-marshmallow-codegen
from marshmallow import (
Schema,
fields,
INCLUDE,
)


class ServiceIssueQuery(Schema):
label = fields.String()
connection_id = fields.String()
author = fields.String()
service_id = fields.String()
exchange_id = fields.String()
state = fields.String()

class Meta:
unknown = INCLUDE


class ServiceIssue(Schema):
service_id = fields.String()

class Meta:
unknown = INCLUDE


class ServiceIssueResponse(Schema):
success = fields.Boolean()
result = fields.List(fields.Nested(lambda: ServiceIssue()))

class Meta:
unknown = INCLUDE


class PDSSettingsExample(Schema):
client_id = fields.String(missing=lambda: "1321wrf1g3f1412rsrfer")
client_secret = fields.String(missing=lambda: "12341551513qw42as")
optional_instance_name = fields.String(missing=lambda: "default")
grant_type = fields.String(missing=lambda: "client_credentials")

class Meta:
unknown = INCLUDE


class PDSSetSettingsExampleResponse(Schema):
success = fields.Boolean()
result = fields.Nested(lambda: PDSSettingsExample())

class Meta:
unknown = INCLUDE


class PDSGetSettingsSchemaResponse(Schema):
success = fields.Boolean()
result = fields.Nested(lambda: PDSGetSettingsSchemaResponseResult())

class Meta:
unknown = INCLUDE


class PDSGetSettingsSchemaResponseResult(Schema):
pds_name_1 = fields.Nested(lambda: PDSSettingsExample())
pds_name_2 = fields.Field()

class Meta:
unknown = INCLUDE


class Payload(Schema):
payload = fields.String()

class Meta:
unknown = INCLUDE


class DRIResponse(Schema):
dri = fields.String()
success = fields.Boolean(missing=lambda: True)

class Meta:
unknown = INCLUDE
2 changes: 1 addition & 1 deletion aries_cloudagent/holder/pds.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def create_presentation(
credential_id = requested_credentials.get("credential_id")

if credential_id is None:
raise HolderError("Provided credentials are empty " + requested_credentials)
raise HolderError(f"Provided credentials are empty {requested_credentials}")

"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,23 @@
from aries_cloudagent.connections.models.connection_record import ConnectionRecord
from ...issuer.tests.test_pds import create_test_credential
from aries_cloudagent.messaging.util import time_now
from aries_cloudagent.config.injection_context import InjectionContext
from aries_cloudagent.wallet.base import BaseWallet
from aries_cloudagent.storage.base import BaseStorage
from aries_cloudagent.pdstorage_thcf.routes import pds_activate
from aries_cloudagent.config.pdstorage import personal_data_storage_config
from aries_cloudagent.pdstorage_thcf.base import BasePDS
from aries_cloudagent.pdstorage_thcf.local import LocalPDS
from aries_cloudagent.pdstorage_thcf.models.saved_personal_storage import (
SavedPDS,
)

presentation_request = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://www.w3.org/2018/credentials/examples/v1",
],
"type": ["VerifiablePresentation", "CredentialManagerPresentation"],
"nonce": "1234678",
"requested_attributes": {
"first_name": {"restrictions": [{"issuer_did": "1234"}]},
},
"schema_base_dri": "12345",
"requested_attributes": ["first_name"],
}

requested_credentials = {
"requested_attributes": {
"first_name": {"cred_id": "1234", "revealed": True},
},
# "requested_predicates": {}, TODO
# "self_attested_attributes": {}, TODO
}
requested_credentials = {"credential_id": "12345"}

presentation_example = {
"@context": [
Expand All @@ -49,13 +46,28 @@ async def setUp(self):
self.context: InjectionContext = InjectionContext()
storage = BasicStorage()
self.wallet = BasicWallet()
self.holder = PDSHolder(self.wallet, storage)
await self.wallet.create_public_did()
public_did = await self.wallet.get_public_did()
assert public_did != None
self.holder = PDSHolder(self.wallet, storage, self.context)
issuer = PDSIssuer(self.wallet)

self.context.injector.bind_instance(BaseWallet, self.wallet)
self.context.injector.bind_instance(BaseStorage, storage)

self.context.settings.set_value(
"personal_storage_registered_types",
{"local": "aries_cloudagent.pdstorage_thcf.local.LocalPDS"},
)

pds = LocalPDS()
self.context.injector.bind_instance(BasePDS, pds)
new_storage = SavedPDS(state=SavedPDS.ACTIVE)
await new_storage.save(self.context)

self.credential = await create_test_credential(issuer)
self.cred_id = await self.holder.store_credential({}, self.credential, {})
requested_credentials["credential_id"] = self.cred_id

async def test_retrieve_records_are_the_same(self):
cred_holder = await self.holder.get_credential(self.cred_id)
Expand All @@ -68,24 +80,21 @@ async def test_store_credential_retrieve_and_delete(self):
cred_serialized = json.loads(cred)
assert cred_serialized == self.credential

await self.holder.delete_credential(self.cred_id)
with self.assertRaises(HolderError):
cred = await self.holder.get_credential(self.cred_id)
with self.assertRaises(HolderError):
cred = await self.holder.delete_credential(self.cred_id)
# await self.holder.delete_credential(self.cred_id)
# with self.assertRaises(HolderError):
# cred = await self.holder.get_credential(self.cred_id)
# with self.assertRaises(HolderError):
# cred = await self.holder.delete_credential(self.cred_id)

async def test_invalid_parameters_getters(self):
with self.assertRaises(HolderError):
cred = await self.holder.get_credential("12")

with self.assertRaises(HolderError):
await self.holder.delete_credential("34")
# with self.assertRaises(HolderError):
# await self.holder.delete_credential("34")

async def test_invalid_parameters_create_pres(self):
schema_with_credential_ids = requested_credentials.copy()
schema_with_credential_ids["requested_attributes"]["first_name"][
"cred_id"
] = self.cred_id

with self.assertRaises(HolderError):
await self.holder.create_presentation(
Expand All @@ -96,31 +105,17 @@ async def test_invalid_parameters_create_pres(self):

async def test_create_presentation(self):
cred = requested_credentials.copy()
cred["requested_attributes"]["first_name"]["cred_id"] = self.cred_id
presentation = await self.holder.create_presentation(
presentation_request, cred, {}, {}
)
presentation = json.loads(presentation)
presentation = json.loads(presentation, object_pairs_hook=OrderedDict)
assert await verify_proof(self.wallet, presentation) == True
assert isinstance(presentation["id"], str)
assert presentation["id"].startswith("urn:uuid:")
assert presentation["context"] == presentation_example["@context"]
assert len(presentation["type"]) == 2
assert len(presentation["context"]) == 2

async def test_create_presentation_invalid_parameters_passed(self):
with self.assertRaises(HolderError):
await self.holder.create_presentation(
presentation_request, requested_credentials, {}, {}
)

with self.assertRaises(HolderError):
request = presentation_request.copy()
request.pop("@context")
await self.holder.create_presentation(
request, requested_credentials, {}, {}
)

with self.assertRaises(HolderError):
request = presentation_request.copy()
request.pop("requested_attributes")
Expand Down
21 changes: 21 additions & 0 deletions aries_cloudagent/issuer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from abc import ABC, ABCMeta, abstractmethod
from typing import Sequence, Tuple
from collections import OrderedDict

from ..core.error import BaseError

Expand Down Expand Up @@ -139,6 +140,26 @@ async def create_credential(
"""

@abstractmethod
async def create_credential_ex(
self,
credential_values,
credential_type: str or list = None,
subject_public_did: str = None,
) -> str:
"""
Create a credential.
Args
credential_values - dict which contains the credential content
credential_type - additional credential type
subject_public_did - did of the agent which credential_values describe
Returns:
created credential
"""

@abstractmethod
async def revoke_credentials(
self, revoc_reg_id: str, tails_file_path: str, cred_revoc_ids: Sequence[str]
Expand Down
Loading

0 comments on commit 794fdfb

Please sign in to comment.