Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check DID Identifier checksum in validation #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timchurchard
Copy link
Contributor

No description provided.

@timchurchard timchurchard changed the base branch from main to tc_fixes June 2, 2021 15:03
Base automatically changed from tc_fixes to main June 4, 2021 13:06
@timchurchard timchurchard marked this pull request as ready for review August 9, 2021 11:10
Copy link
Member

@smartrics smartrics left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a few minor comments
(I assume this isn't going to affect teh golang impl?)

@@ -83,9 +83,14 @@ def other_key_pair(other_key_pair_secrets):

@pytest.fixture
def doc_did():
return 'did:iotics:iotHHHHKpPGWyEC4FFo4d6oyzVVk6MXLmEgY'
return 'did:iotics:iotDadb3rSWedk8iqExSbwqLtijG5XQByHC7'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is a magic string that's repeated in many tests, would it be better to have it in a constant with a meaningful name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it would be clearer. I did not want to refactor too much of the tests. I had to override this value because it does not pass the identifier checksum validation.

@@ -37,4 +37,5 @@ def make_identifier(public_bytes: bytes) -> str:
checksum = bytearray.fromhex(cl2.hexdigest())[:4]

return IDENTIFIER_PREFIX + base58.b58encode(bytes([IDENTIFIER_METHOD, IDENTIFIER_VERSION, IDENTIFIER_PAD])
+ pk_digest + checksum).decode('ascii')
+ pk_digest + checksum,
alphabet=base58.BITCOIN_ALPHABET).decode('ascii')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the use of this alphabet is fundamental - how do other impl of the spec would know about this?
would all of them need to use the same "bitcoin_alphabet" ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

base58 was written for bitcoin so the default is "bitcoin alphabet". I only specify here in case the default in the upstream library changes and to make the code clearer to read. I'm happy to revert this override if you prefer.

@@ -20,6 +23,17 @@ def validate_identifier(did: str):
if result is None:
raise IdentityValidationError(f'Identifier does not match pattern {did} - {IDENTIFIER_ID_PATTERN}')

did_bytes = base58.b58decode(did[len(IDENTIFIER_PREFIX):], alphabet=base58.BITCOIN_ALPHABET)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

following up the comment above, should this magic number be put in a constant (since it's repeated in many places or maybe have a id_sdk.did_decode/id_sdk.did_encode functions that wrap base58.b58decode/b58encode(alphabet=base58.BITCOIN_APLHABET) ?
just saying in order to have our custom logic somewhere in one place only

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants