Esempio n. 1
0
def test_is_equal_register_public_key(valid_key_name, valid_public_key_base58):
    key1 = RegisterPublicKey.build(valid_key_name,
                                   valid_public_key_base58,
                                   revoked=False)
    key2 = RegisterPublicKey.build(valid_key_name,
                                   valid_public_key_base58,
                                   revoked=False)
    assert key1.is_equal(key2)
def test_can_revoke_delegation_proof(base_doc_issuer, valid_key_pair,
                                     get_api_call, doc_deleg_set,
                                     deleg_doc_did, deleg_name):
    doc = get_doc_with_keys(deleg_control=[
        RegisterDelegationProof.build('#Deleg1',
                                      controller=Issuer(
                                          deleg_doc_did, '#plop2'),
                                      proof='proof',
                                      revoked=False)
    ],
                            deleg_auth=[
                                RegisterDelegationProof.build(
                                    '#Deleg2',
                                    controller=Issuer(deleg_doc_did, '#plop2'),
                                    proof='proof',
                                    revoked=False)
                            ],
                            public_keys=[
                                RegisterPublicKey.build('#MandatoryKey',
                                                        'base58Key1',
                                                        revoked=False)
                            ],
                            did=base_doc_issuer.did)
    resolver_client = ResolverClientTest(docs={base_doc_issuer.did: doc})
    assert not doc_deleg_set(doc)[deleg_name].revoked
    api = AdvancedIdentityRegisterApi(resolver_client)
    get_api_call(api)(deleg_name,
                      revoked=True,
                      doc_owner_issuer=base_doc_issuer,
                      doc_owner_key_pair=valid_key_pair)
    updated_doc = resolver_client.docs[base_doc_issuer.did]
    assert doc_deleg_set(updated_doc)[deleg_name].revoked
Esempio n. 3
0
def get_delegation_doc_for(controller_name: str, doc_id: str,
                           public_base58: str) -> RegisterDocument:
    return get_doc_with_keys(did=doc_id,
                             public_keys=[
                                 RegisterPublicKey.build(controller_name,
                                                         public_base58,
                                                         revoked=False),
                             ])
Esempio n. 4
0
def invalid_doc(doc_did, valid_issuer_key):
    return get_doc_with_keys(did=doc_did,
                             public_keys=[
                                 RegisterPublicKey.build(
                                     '#Key1',
                                     valid_issuer_key.public_key_base58,
                                     revoked=False),
                             ])
Esempio n. 5
0
def get_docs_for_issuer_key_from_public_keys(
        doc_did: str, issuer: Issuer) -> Dict[str, RegisterDocument]:
    """
    The issuer is directly in the current doc public keys
    """
    doc = get_doc_with_keys(public_keys=[
        RegisterPublicKey.build(issuer.name, 'base58Key1', revoked=False)
    ])
    return {doc_did: doc}
Esempio n. 6
0
def simple_doc(doc_did, valid_issuer_key):
    return get_doc_with_keys(
        did=doc_did,
        public_keys=[
            RegisterPublicKey.build(valid_issuer_key.issuer.name,
                                    valid_issuer_key.public_key_base58,
                                    revoked=False)
        ],
    )
Esempio n. 7
0
def doc_with_doc_deleg(valid_issuer_key, doc_did, deleg_doc_did):
    doc = get_doc_with_keys(
        did=doc_did,
        public_keys=[
            RegisterPublicKey.build('#Key1', 'base58Key1', revoked=False)
        ],
        deleg_control=[
            RegisterDelegationProof.build(valid_issuer_key.issuer.name,
                                          controller=Issuer.build(
                                              deleg_doc_did, '#plop1'),
                                          proof='aproof',
                                          revoked=False),
        ],
    )

    deleg_doc = get_doc_with_keys(did=deleg_doc_did,
                                  public_keys=[
                                      RegisterPublicKey.build(
                                          valid_issuer_key.issuer.name,
                                          valid_issuer_key.public_key_base58,
                                          revoked=False),
                                  ])
    return doc, deleg_doc
Esempio n. 8
0
def test_can_build_register_public_key(valid_key_name,
                                       valid_public_key_base58):
    key = RegisterPublicKey.build(valid_key_name,
                                  valid_public_key_base58,
                                  revoked=False)
    assert key.name == valid_key_name
    assert key.base58 == valid_public_key_base58
    assert not key.revoked

    assert key.to_dict() == {
        'id': valid_key_name,
        'type': DOCUMENT_PUBLIC_KEY_TYPE,
        'publicKeyBase58': valid_public_key_base58,
        'revoked': False
    }
Esempio n. 9
0
    def add_public_key(self, name: str, public_base58: str,
                       revoked: Optional[bool] = False) -> 'RegisterDocumentBuilder':
        """
        Add public key to document under build.
        :param name: key name
        :param public_base58: public key base58
        :param revoked: is revoked (default=False)
        :return: self

        :raises:
            IdentityValidationError: if invalid public key
            IdentityRegisterDocumentKeyConflictError: if key name is not unique
        """
        key = RegisterPublicKey.build(name, public_base58, revoked)
        self._check_and_update_map(name, key, self.public_keys, 'Public key name')
        return self
Esempio n. 10
0
def get_docs_for_issuer_key_from_auth_delegation(
        doc_did: str, deleg_doc_did: str,
        issuer: Issuer) -> Dict[str, RegisterDocument]:
    """
    The issuer is in the auth delegation of the provided doc
    And the issuer is in the auth keys of the delegation doc
    """

    doc = get_doc_with_keys(deleg_control=[
        RegisterDelegationProof.build(issuer.name,
                                      controller=Issuer(
                                          'deleg_doc_did', '#plop'),
                                      proof='proof',
                                      revoked=False),
    ])
    deleg_doc = get_doc_with_keys(public_keys=[
        RegisterPublicKey.build(issuer.name, 'base58Key1', revoked=False)
    ])
    return {doc_did: doc, deleg_doc_did: deleg_doc}
Esempio n. 11
0
def test_validate_delegation_raises_validation_error_if_public_key_not_in_deleg_controller_doc(
        doc_did, deleg_doc_did, valid_issuer_key, valid_key_pair_secrets):
    controller_name = '#AController'
    deleg_proof = get_delegation_register_proof(
        subject_key_pair_secrets=valid_key_pair_secrets,
        content=doc_did.encode(),
        p_type=DelegationProofType.DID,
        subject_issuer=Issuer.build(deleg_doc_did, controller_name))
    deleg_doc = get_doc_with_keys(did=doc_did,
                                  public_keys=[
                                      RegisterPublicKey.build(
                                          '#NotMatchingTheController',
                                          valid_issuer_key.public_key_base58,
                                          revoked=False),
                                  ])
    resolver_client = ResolverClientTest({deleg_doc_did: deleg_doc})
    with pytest.raises(IdentityInvalidDocumentDelegationError) as err_wrapper:
        DelegationValidation.validate_delegation(resolver_client,
                                                 doc_id=doc_did,
                                                 deleg_proof=deleg_proof)
    assert isinstance(err_wrapper.value.__cause__, IdentityValidationError)
Esempio n. 12
0
    def add_public_key_to_document(self, name: str,
                                   new_public_key_base58: str,
                                   doc_owner_key_pair: KeyPair,
                                   doc_owner_issuer: Issuer) -> Issuer:
        """
        Add a new register public key to a register document.
        :param name: new public key name
        :param new_public_key_base58: public key base 58
        :param doc_owner_key_pair: register document owner key pair
        :param doc_owner_issuer: register document owner issuer
        :return: new register document owner issuer

        :raises:
            IdentityValidationError: if invalid new public key name
            IdentityRegisterDocumentKeyConflictError: if public key name is not unique within the register document
            IdentityInvalidDocumentError: if invalid register document
            IdentityResolverError: if resolver error
        """
        new_key = RegisterPublicKey.build(name, new_public_key_base58)
        self._update_doc(doc_owner_key_pair, doc_owner_issuer, get_updated_doc=self.public_key_api.add_doc_key,
                         key=new_key)
        return Issuer.build(doc_owner_issuer.did, name)
Esempio n. 13
0
def test_build_register_public_key_raises_validation_error_if_invalid_name(
        valid_public_key_base58):
    with pytest.raises(IdentityValidationError):
        RegisterPublicKey.build('Invalid_name',
                                valid_public_key_base58,
                                revoked=False)
Esempio n. 14
0
def register_doc_and_deleg_doc(
        doc_did: str,
        deleg_doc_did: str) -> Tuple[RegisterDocument, RegisterDocument]:
    """
    Creates a document and a delegation document with all the key combinations (See KEY_NAMES)
    for the "get issuer from" tests with and without delegation and with and without included authentication
    """
    doc = get_doc_with_keys(
        did=doc_did,
        public_keys=[
            RegisterPublicKey.build(KEYS_NAMES.key_only_in_doc_pub_keys,
                                    'base58Key1',
                                    revoked=False)
        ],
        auth_keys=[
            RegisterAuthenticationPublicKey.build(
                KEYS_NAMES.key_only_in_doc_auth_keys,
                'base58Key2',
                revoked=False)
        ],
        deleg_control=[
            RegisterDelegationProof.build(
                KEYS_NAMES.key_in_doc_control_deleg_and_deleg_doc_pub_keys,
                controller=Issuer('deleg_doc_did', '#plop1'),
                proof='aproof',
                revoked=False),
            RegisterDelegationProof.build(
                KEYS_NAMES.key_in_doc_control_deleg_and_deleg_doc_auth_keys,
                controller=Issuer('deleg_doc_did', '#plop2'),
                proof='aproof',
                revoked=False),
            RegisterDelegationProof.build(
                KEYS_NAMES.key_in_doc_control_deleg_and_not_in_deleg_doc,
                controller=Issuer('deleg_doc_did', '#plop3'),
                proof='aproof',
                revoked=False),
        ],
        deleg_auth=[
            RegisterDelegationProof.build(
                KEYS_NAMES.key_in_doc_auth_deleg_and_deleg_doc_pub_keys,
                controller=Issuer('deleg_doc_did', '#plop4'),
                proof='aproof',
                revoked=False),
            RegisterDelegationProof.build(
                KEYS_NAMES.key_in_doc_auth_deleg_and_deleg_doc_auth_keys,
                controller=Issuer('deleg_doc_did', '#plop5'),
                proof='aproof',
                revoked=False),
            RegisterDelegationProof.build(
                KEYS_NAMES.key_in_doc_auth_deleg_and_not_in_deleg_doc,
                controller=Issuer('deleg_doc_did', '#plop6'),
                proof='aproof',
                revoked=False),
        ],
    )

    deleg_doc = get_doc_with_keys(
        did=deleg_doc_did,
        public_keys=[
            RegisterPublicKey.build(
                KEYS_NAMES.key_in_doc_control_deleg_and_deleg_doc_pub_keys,
                'base58K11',
                revoked=False),
            RegisterPublicKey.build(
                KEYS_NAMES.key_in_doc_auth_deleg_and_deleg_doc_pub_keys,
                'base58K12',
                revoked=False)
        ],
        auth_keys=[
            RegisterAuthenticationPublicKey.build(
                KEYS_NAMES.key_in_doc_control_deleg_and_deleg_doc_auth_keys,
                'base58K13',
                revoked=False),
            RegisterAuthenticationPublicKey.build(
                KEYS_NAMES.key_in_doc_auth_deleg_and_deleg_doc_auth_keys,
                'base58K14',
                revoked=False)
        ])
    return doc, deleg_doc
Esempio n. 15
0
def public_keys():
    return {
        '#Key1': RegisterPublicKey.build('#Key1', 'base58Key1', revoked=False),
        '#Key2': RegisterPublicKey.build('#Key2', 'base58Key2', revoked=False),
        '#Key3': RegisterPublicKey.build('#Key3', 'base58Key3', revoked=False)
    }