Skip to content

Commit

Permalink
Update from review comments
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Jan 23, 2025
1 parent 8e87d99 commit 82fefd9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
20 changes: 11 additions & 9 deletions acapy_agent/config/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ async def _attempt_open_profile(


def _log_provision_info(profile: Profile) -> None:
print(f"{'Created new profile' if profile.created else 'Opened existing profile'}")
print(f"Profile name: {profile.name} Profile backend: {profile.backend}")
LOGGER.info(
f"{'Created new profile' if profile.created else 'Opened existing profile'}"
)
LOGGER.info(f"Profile name: {profile.name} Profile backend: {profile.backend}")


async def _initialize_with_public_did(
Expand All @@ -86,13 +88,13 @@ async def _initialize_with_public_did(
+ f" public did {public_did}"
)

print("Replacing public DID due to --replace-public-did flag")
LOGGER.info("Replacing public DID due to --replace-public-did flag")
replace_did_info = await wallet.create_local_did(
method=SOV, key_type=ED25519, seed=wallet_seed
)
public_did = replace_did_info.did
await wallet.set_public_did(public_did)
print(
LOGGER.info(
f"Created new public DID: {public_did}, with verkey: {replace_did_info.verkey}" # noqa: E501
)

Expand Down Expand Up @@ -125,16 +127,16 @@ async def _initialize_with_seed(
)
local_did = local_did_info.did
if provision:
print(f"Created new local DID: {local_did}")
print(f"Verkey: {local_did_info.verkey}")
LOGGER.info(f"Created new local DID: {local_did}")
LOGGER.info(f"Verkey: {local_did_info.verkey}")
else:
public_did_info = await wallet.create_public_did(
method=SOV, key_type=ED25519, seed=seed
)
public_did = public_did_info.did
if provision:
print(f"Created new public DID: {public_did}")
print(f"Verkey: {public_did_info.verkey}")
LOGGER.info(f"Created new public DID: {public_did}")
LOGGER.info(f"Verkey: {public_did_info.verkey}")


async def wallet_config(
Expand Down Expand Up @@ -173,7 +175,7 @@ async def wallet_config(
)

if provision and not create_local_did and not public_did:
print("No public DID")
LOGGER.info("No public DID")

await _initialize_with_debug_settings(settings, wallet)

Expand Down
2 changes: 1 addition & 1 deletion acapy_agent/wallet/askar.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ async def set_did_endpoint(
"""
did_info = await self.get_local_did(did)
if did_info.method != SOV and did_info.method != INDY:
if did_info.method not in (SOV, INDY):
raise WalletError(
"Setting DID endpoint is only allowed for did:sov or did:indy DIDs"
)
Expand Down
5 changes: 4 additions & 1 deletion acapy_agent/wallet/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ def seed_to_did(seed: str, method: Optional[DIDMethod] = SOV) -> str:
if method == SOV:
return bytes_to_b58(verkey[:16])
if method == INDY:
return f"did:indy:{bytes_to_b58(hashlib.sha256(verkey).digest()[:16])}"
# Hash the verkey, take the first 16 bytes, and convert to a base58 string
hashed_verkey = hashlib.sha256(verkey).digest()
did = bytes_to_b58(hashed_verkey[:16])
return f"did:indy:{did}"
raise WalletError(f"Unsupported DID method: {method.method_name}")


Expand Down
10 changes: 5 additions & 5 deletions acapy_agent/wallet/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,13 @@ async def wallet_create_did(request: web.BaseRequest):

method = did_methods.from_method(body.get("method", "sov"))
if not method:
raise web.HTTPForbidden(
raise web.HTTPBadRequest(
reason=f"method {body.get('method')} is not supported by the agent."
)

# Don't support Indy DID method from this endpoint
if method.method_name == INDY.method_name:
raise web.HTTPForbidden(
raise web.HTTPBadRequest(
reason="Indy did method is supported from /did/indy/create endpoint."
)

Expand All @@ -602,7 +602,7 @@ async def wallet_create_did(request: web.BaseRequest):
or ED25519
)
if not method.supports_key_type(key_type):
raise web.HTTPForbidden(
raise web.HTTPBadRequest(
reason=(
f"method {method.method_name} does not"
f" support key type {key_type.key_type}"
Expand All @@ -611,7 +611,7 @@ async def wallet_create_did(request: web.BaseRequest):

did = body.get("options", {}).get("did")
if method.holder_defined_did() == HolderDefinedDid.NO and did:
raise web.HTTPForbidden(
raise web.HTTPBadRequest(
reason=f"method {method.method_name} does not support user-defined DIDs"
)
elif method.holder_defined_did() == HolderDefinedDid.REQUIRED and not did:
Expand All @@ -621,7 +621,7 @@ async def wallet_create_did(request: web.BaseRequest):

wallet = session.inject_or(BaseWallet)
if not wallet:
raise web.HTTPForbidden(reason="No wallet available")
raise web.HTTPBadRequest(reason="No wallet available")
try:
is_did_peer_2 = method.method_name == PEER2.method_name
is_did_peer_4 = method.method_name == PEER4.method_name
Expand Down

0 comments on commit 82fefd9

Please sign in to comment.