def add_doc_key(self, doc: RegisterDocument, key: RegisterKeyBase) -> RegisterDocument:
        """
        Add a new register key to the register document
        :param doc: register document
        :param key: register key base

        :raises:
            IdentityInvalidDocumentError: if invalid document
            IdentityRegisterDocumentKeyConflictError: if key name is not unique
        """
        builder = RegisterDocumentBuilder()
        self.add_key_to_builder(builder, key)
        return builder.build_from_existing(doc)
    def revoke_doc_key(self, doc: RegisterDocument, key_name: str, revoked: bool) -> RegisterDocument:
        """
        Create a new document setting revoked to the key associated to the key name
        :param doc: a register document
        :param key_name: a key name
        :param revoked: is the key revoked
        :return: a register document

        :raises:
        - IdentityRegisterDocumentKeyNotFoundError: if the key to revoke is not found

        """
        key = self.get_key_from_doc(doc, key_name)
        if not key:
            raise IdentityRegisterDocumentKeyNotFoundError(f'Can mot revoke key {key_name} fron document {doc.did}:'
                                                           f'key not found')
        builder = RegisterDocumentBuilder() \
            .set_keys_from_existing(doc) \
            .remove_key(key_name)
        self.add_key_to_builder(builder, key.get_new_key(revoked))
        return builder.build_from_existing(doc, populate_with_doc_keys=False)
Ejemplo n.º 3
0
def test_validate_document_against_resolver_raises_validation_error_if_invalid_delegation(
        valid_doc, other_key_pair, deleg_type):
    wrong_deleg_id = make_identifier(other_key_pair.public_bytes)
    delegated_doc1, inconsistent_deleg_key = get_valid_delegated_doc_and_deleg_proof(
        new_seed(),
        '#issuer1',
        delegating_doc_id=wrong_deleg_id,
        deleg_name='#DelegDoc1')

    builder = RegisterDocumentBuilder()
    if deleg_type == 'auth':
        builder.add_authentication_delegation_obj(inconsistent_deleg_key)
    else:
        builder.add_control_delegation_obj(inconsistent_deleg_key)
    doc_with_invalid_delegation = builder.build_from_existing(valid_doc)
    resolver_client = ResolverClientTest(docs={
        valid_doc.did: valid_doc,
        delegated_doc1.did: delegated_doc1
    })
    with pytest.raises(IdentityInvalidDocumentError) as err_wrapper:
        is_validator_run_success(
            DocumentValidation.validate_document_against_resolver,
            resolver_client, doc_with_invalid_delegation)
    assert isinstance(err_wrapper.value.__cause__, IdentityInvalidProofError)