Skip to content

Commit 7b56058

Browse files
committed
Merge remote-tracking branch 'thiagoromanos/feat/use-besu-vdr' into feat/indy-besu-cpqd
2 parents 89957ac + 14e54bb commit 7b56058

17 files changed

Lines changed: 3034 additions & 286 deletions

File tree

aries_cloudagent/admin/server.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import aiohttp_cors
1313
import jwt
1414
from aiohttp import web
15+
from aiohttp.web_log import AccessLogger
1516
from aiohttp_apispec import (
1617
docs,
1718
response_schema,
1819
setup_aiohttp_apispec,
1920
validation_middleware,
2021
)
21-
2222
from marshmallow import fields
2323

2424
from ..config.injection_context import InjectionContext
@@ -59,6 +59,18 @@
5959
}
6060

6161

62+
class CustomAccessLogger(AccessLogger):
63+
"""Custom logger that doesn't logs healthcheck endpoints."""
64+
65+
def log(
66+
self, request: web.BaseRequest, response: web.StreamResponse, time: float
67+
) -> None:
68+
"""Log everything but ready and live."""
69+
if request.path == "/status/ready" or request.path == "/status/live":
70+
return
71+
return super().log(request, response, time)
72+
73+
6274
class AdminModulesSchema(OpenAPISchema):
6375
"""Schema for the modules endpoint."""
6476

@@ -218,6 +230,21 @@ async def debug_middleware(request: web.BaseRequest, handler: Coroutine):
218230
return await handler(request)
219231

220232

233+
@web.middleware
234+
async def debug_middleware_supress(request: web.BaseRequest, handler: Coroutine):
235+
"""Show request detail in debug log, except for live and ready status."""
236+
237+
if LOGGER.isEnabledFor(logging.DEBUG) and not (
238+
request.path == "/status/ready" or request.path == "/status/live"
239+
):
240+
LOGGER.debug(f"Incoming request: {request.method} {request.path_qs}")
241+
LOGGER.debug(f"Match info: {request.match_info}")
242+
body = await request.text() if request.body_exists else None
243+
LOGGER.debug(f"Body: {body}")
244+
245+
return await handler(request)
246+
247+
221248
def const_compare(string1, string2):
222249
"""Compare two strings in constant time."""
223250
if string1 is None or string2 is None:
@@ -257,6 +284,9 @@ def __init__(
257284
self.admin_insecure_mode = bool(
258285
context.settings.get("admin.admin_insecure_mode")
259286
)
287+
self.supressHealthEndpoints = bool(
288+
context.settings.get("log.supress-healthcheck-log")
289+
)
260290
self.host = host
261291
self.port = port
262292
self.context = context
@@ -299,7 +329,13 @@ def _matches_additional_routes(self, path: str) -> bool:
299329
async def make_application(self) -> web.Application:
300330
"""Get the aiohttp application instance."""
301331

302-
middlewares = [ready_middleware, debug_middleware]
332+
middlewares = [ready_middleware]
333+
334+
(
335+
middlewares.append(debug_middleware)
336+
if not self.supressHealthEndpoints
337+
else middlewares.append(debug_middleware_supress)
338+
)
303339

304340
# admin-token and admin-token are mutually exclusive and required.
305341
# This should be enforced during parameter parsing but to be sure,
@@ -529,7 +565,13 @@ def sort_dict(raw: dict) -> dict:
529565
return dict(sorted(raw.items(), key=lambda x: x[0]))
530566

531567
self.app = await self.make_application()
532-
runner = web.AppRunner(self.app)
568+
569+
runner = (
570+
web.AppRunner(self.app, access_log_class=CustomAccessLogger)
571+
if self.supressHealthEndpoints
572+
else web.AppRunner(self.app)
573+
)
574+
533575
await runner.setup()
534576

535577
plugin_registry = self.context.inject_or(PluginRegistry)

aries_cloudagent/anoncreds/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ async def setup(context: InjectionContext):
1515
LOGGER.error("No AnonCredsRegistry instance found in context!!!")
1616
return
1717

18+
besu_registry = ClassProvider(
19+
"aries_cloudagent.anoncreds.default.did_besu.registry.DIDBesuRegistry",
20+
# supported_identifiers=[],
21+
# method_name="did:indy2",
22+
).provide(context.settings, context.injector)
23+
await besu_registry.setup(context)
24+
registry.register(besu_registry)
25+
1826
indy_registry = ClassProvider(
1927
"aries_cloudagent.anoncreds.default.did_indy.registry.DIDIndyRegistry",
2028
# supported_identifiers=[],

aries_cloudagent/anoncreds/default/did_besu/__init__.py

Whitespace-only changes.

aries_cloudagent/anoncreds/default/did_besu/registry.py

Lines changed: 960 additions & 0 deletions
Large diffs are not rendered by default.

aries_cloudagent/anoncreds/holder.py

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
from ..wallet.error import WalletNotFoundError
2727
from .error_messages import ANONCREDS_PROFILE_REQUIRED_MSG
2828
from .models.anoncreds_cred_def import CredDef
29+
from base58 import alphabet
30+
31+
B58 = alphabet if isinstance(alphabet, str) else alphabet.decode("ascii")
2932

3033
LOGGER = logging.getLogger(__name__)
3134

@@ -143,8 +146,8 @@ async def create_credential_request(
143146
) = await asyncio.get_event_loop().run_in_executor(
144147
None,
145148
CredentialRequest.create,
149+
holder_did, # FIX ME PLEEEEASE
146150
None,
147-
holder_did,
148151
credential_definition.to_native(),
149152
secret,
150153
AnonCredsHolder.MASTER_SECRET_ID,
@@ -207,27 +210,53 @@ async def store_credential(
207210

208211
schema_id = cred_recvd.schema_id
209212
schema_id_parts = re.match(r"^(\w+):2:([^:]+):([^:]+)$", schema_id)
213+
if 'indy2'in schema_id:
214+
INDY_SCHEMA_ID = rf"^(did:indy2)?:.+:[{B58}]{{21,22}}/anoncreds/v0/SCHEMA/.+/[0-9.]+$"
215+
schema_id_parts = re.match(INDY_SCHEMA_ID, schema_id)
210216
if not schema_id_parts:
211217
raise AnonCredsHolderError(
212218
f"Error parsing credential schema ID: {schema_id}"
213219
)
214-
cred_def_id = cred_recvd.cred_def_id
215-
cdef_id_parts = re.match(r"^(\w+):3:CL:([^:]+):([^:]+)$", cred_def_id)
220+
cred_def_id = cred_recvd.cred_def_id
221+
cdef_id_parts = re.match(r"^(\w+):3:CL:([^:]+):([^:]+)$", cred_def_id)
222+
if 'indy2' in cred_def_id:
223+
INDY_CRED_DEF_ID = (
224+
rf"^((did:indy2)?:.+:[{B58}]{{21,22}})" # issuer DID
225+
f"/anoncreds/v0/CLAIM_DEF/" # cred def id marker
226+
# f":CL" # sig alg
227+
rf"((did:indy2)?:.+:[{B58}]{{21,22}}/anoncreds/v0/SCHEMA/.+/[0-9.]+)" # schema txn / id
228+
f"/(.+)?$" # tag
229+
)
230+
cdef_id_parts = re.match(INDY_CRED_DEF_ID, cred_def_id)
216231
if not cdef_id_parts:
217232
raise AnonCredsHolderError(
218233
f"Error parsing credential definition ID: {cred_def_id}"
219234
)
220235

221236
credential_id = credential_id or str(uuid.uuid4())
222-
tags = {
223-
"schema_id": schema_id,
224-
"schema_issuer_did": schema_id_parts[1],
225-
"schema_name": schema_id_parts[2],
226-
"schema_version": schema_id_parts[3],
227-
"issuer_did": cdef_id_parts[1],
228-
"cred_def_id": cred_def_id,
229-
"rev_reg_id": cred_recvd.rev_reg_id or "None",
230-
}
237+
tags = {}
238+
if 'indy2' in cred_def_id and 'indy2' in schema_id:
239+
schema_id_parts = schema_id.split('/')
240+
cdef_id_parts = cred_def_id.split('/')
241+
tags = {
242+
"schema_id": schema_id,
243+
"schema_issuer_did": schema_id_parts[0],
244+
"schema_name": schema_id_parts[4],
245+
"schema_version": schema_id_parts[5],
246+
"issuer_did": cdef_id_parts[0],
247+
"cred_def_id": cred_def_id,
248+
"rev_reg_id": cred_recvd.rev_reg_id or "None",
249+
}
250+
else:
251+
tags = {
252+
"schema_id": schema_id,
253+
"schema_issuer_did": schema_id_parts[1],
254+
"schema_name": schema_id_parts[2],
255+
"schema_version": schema_id_parts[3],
256+
"issuer_did": cdef_id_parts[1],
257+
"cred_def_id": cred_def_id,
258+
"rev_reg_id": cred_recvd.rev_reg_id or "None",
259+
}
231260

232261
# FIXME - sdk has some special handling for fully qualified DIDs here
233262

aries_cloudagent/askar/profile_anon.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import time
66

77
# import traceback
8-
98
from typing import Any, Mapping
109
from weakref import ref
1110

@@ -19,14 +18,21 @@
1918
from ..indy.holder import IndyHolder
2019
from ..indy.issuer import IndyIssuer
2120
from ..ledger.base import BaseLedger
21+
from ..ledger.besu_vdr import (
22+
CREDENTIAL_DEFINITION_REGISTRY,
23+
INDY_DID_REGISTRY,
24+
REVOCATION_REGISTRY,
25+
SCHEMA_REGISTRY,
26+
BesuVdrLedger,
27+
BesuVDRWeb3Config,
28+
)
2229
from ..ledger.indy_vdr import IndyVdrLedger, IndyVdrLedgerPool
2330
from ..storage.base import BaseStorage, BaseStorageSearch
2431
from ..storage.vc_holder.base import VCHolder
2532
from ..utils.multi_ledger import get_write_ledger_config_for_profile
2633
from ..wallet.base import BaseWallet
2734
from ..wallet.crypto import validate_seed
28-
29-
from .store import AskarStoreConfig, AskarOpenStore
35+
from .store import AskarOpenStore, AskarStoreConfig
3036

3137
LOGGER = logging.getLogger(__name__)
3238

@@ -48,6 +54,7 @@ def __init__(
4854
super().__init__(context=context, name=opened.name, created=opened.created)
4955
self.opened = opened
5056
self.ledger_pool: IndyVdrLedgerPool = None
57+
self.besu_configs: BesuVDRWeb3Config = None
5158
self.profile_id = profile_id
5259
self.init_ledger_pool()
5360
self.bind_providers()
@@ -89,6 +96,26 @@ def init_ledger_pool(self):
8996
read_only=read_only,
9097
socks_proxy=socks_proxy,
9198
)
99+
elif self.settings.get("ledger.besu_provider_url"):
100+
self.besu_configs = BesuVDRWeb3Config(
101+
ledgerAddr=self.settings.get("ledger.besu_provider_url"),
102+
trusteeAccount=self.settings.get("ledger.account_address"),
103+
trusteePKey=self.settings.get("ledger.private_account_key"),
104+
contractAddrs={
105+
SCHEMA_REGISTRY: self.settings.get(
106+
"ledger.schema_contract_address"
107+
),
108+
CREDENTIAL_DEFINITION_REGISTRY: self.settings.get(
109+
"ledger.credef_contract_address"
110+
),
111+
REVOCATION_REGISTRY: self.settings.get(
112+
"ledger.revocation_contract_address"
113+
),
114+
INDY_DID_REGISTRY: self.settings.get(
115+
"ledger.indy_did_contract_address"
116+
),
117+
},
118+
)
92119

93120
def bind_providers(self):
94121
"""Initialize the profile-level instance providers."""
@@ -161,6 +188,10 @@ def bind_providers(self):
161188
injector.bind_provider(
162189
BaseLedger, ClassProvider(IndyVdrLedger, self.ledger_pool, ref(self))
163190
)
191+
elif self.besu_configs:
192+
injector.bind_provider(
193+
BaseLedger, ClassProvider(BesuVdrLedger, self.besu_configs, ref(self))
194+
)
164195

165196
def session(
166197
self, context: InjectionContext = None

0 commit comments

Comments
 (0)