Skip to content

Commit

Permalink
IN PROGRESS: did helpers: ecdsa p-384 key loading
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Nov 15, 2023
1 parent a4bc402 commit ebfbdd3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
[pytest]
# https://docs.pytest.org/en/7.1.x/how-to/doctest.html#using-doctest-options
doctest_optionflags = NORMALIZE_WHITESPACE IGNORE_EXCEPTION_DETAIL
# Alternatively, options can be enabled by an inline comment in the doc test itself:
# >>> something_that_raises() # doctest: +IGNORE_EXCEPTION_DETAIL
# Traceback (most recent call last):
# ValueError: ...
addopts = --doctest-modules
30 changes: 29 additions & 1 deletion scitt_emulator/did_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,38 @@ class DIDKeyDecoderNotFoundError(NotImplementedError):

DID_KEY_METHOD = "did:key:"

def did_key_decode(
did_key_without_method_or_key_type_prefix: str,
) -> tuple[str, bytes]:
return


import snoop

@snoop
def did_key_to_jwk_dict_is_p_384_startswith_z82(did_key: str) -> dict[str, str]:
did_key = did_key.replace(DID_KEY_METHOD, "", 1)
return
# 3.1.3 Decode Public Key Algorithm

# The following algorithm can be used for expanding a multibase-encoded multicodec value to decoded public key components. A multibaseValue and options are the required inputs. A decodedPublicKey is the output.

# Set decodedPublicKey to an empty object.
decoded_public_key = None

# Decode multibaseValue using the base58-btc multibase alphabet and set multicodecValue to the multicodec header for the decoded value. Implementers are cautioned to ensure that the multicodecValue is set to the result after performing varint decoding.
import base58
multibase_value = base58.b58decode_check(did_key)[:2]
# multibase_value_header = multibase_value[:?]
# 3.1.2.3
if multibase_value[0] != 0x12:
multibase_value = multibase_value[0]
multibase_value_header = multibase_value[0]

# Set the rawPublicKeyBytes to the bytes remaining after the multicodec header.
raw_public_key_bytes = multibase_value[len(multibase_value_header):]

# Return multicodecValue and rawPublicKeyBytes as the decodedPublicKey.
return multibase_value, raw_public_key_bytes


def did_key_to_jwk_dict(
Expand Down

0 comments on commit ebfbdd3

Please sign in to comment.