def test_state_proof_returned_for_get_attr(looper,
                                           sdk_added_raw_attribute,
                                           attributeName,
                                           attributeData,
                                           sdk_pool_handle,
                                           sdk_wallet_client):
    """
    Tests that state proof is returned in the reply for GET_ATTR transactions.
    Use different submitter and reader!
    """
    get_attr_operation = {
        TARGET_NYM: sdk_added_raw_attribute['operation']['dest'],
        TXN_TYPE: GET_ATTR,
        RAW: attributeName
    }
    replies = sdk_submit_operation_and_get_replies(looper, sdk_pool_handle,
                                                   sdk_wallet_client,
                                                   get_attr_operation)
    expected_data = attrib_raw_data_serializer.deserialize(attributeData)
    for reply in replies:
        result = reply[1]['result']
        assert DATA in result
        data = attrib_raw_data_serializer.deserialize(result[DATA])
        assert data == expected_data
        assert result[TXN_TIME]
        check_valid_proof(reply[1])
def test_state_proof_returned_for_get_attr(looper,
                                           nodeSetWithOneNodeResponding,
                                           sdk_added_raw_attribute,
                                           attributeName,
                                           attributeData,
                                           sdk_pool_handle,
                                           sdk_wallet_client):
    """
    Tests that state proof is returned in the reply for GET_ATTR transactions.
    Use different submitter and reader!
    """
    get_attr_operation = {
        TARGET_NYM: sdk_added_raw_attribute['result']['txn']['data']['dest'],
        TXN_TYPE: GET_ATTR,
        RAW: attributeName
    }

    result = sdk_submit_operation_and_get_result(looper, sdk_pool_handle,
                                                 sdk_wallet_client,
                                                 get_attr_operation)
    expected_data = attrib_raw_data_serializer.deserialize(attributeData)
    assert DATA in result
    data = attrib_raw_data_serializer.deserialize(result[DATA])
    assert data == expected_data
    assert result[TXN_TIME]
    check_valid_proof(result)
def test_state_proof_returned_for_get_attr(looper,
                                           addedRawAttribute,
                                           attributeName,
                                           attributeData,
                                           trustAnchor,
                                           trustAnchorWallet):
    """
    Tests that state proof is returned in the reply for GET_ATTR transactions
    """
    client = trustAnchor
    get_attr_operation = {
        TARGET_NYM: addedRawAttribute.dest,
        TXN_TYPE: GET_ATTR,
        RAW: attributeName
    }
    get_attr_request = trustAnchorWallet.signOp(get_attr_operation)
    trustAnchorWallet.pendRequest(get_attr_request)
    pending = trustAnchorWallet.preparePending()
    client.submitReqs(*pending)
    waitForSufficientRepliesForRequests(looper, trustAnchor, requests=pending)
    replies = getRepliesFromClientInbox(client.inBox, get_attr_request.reqId)
    expected_data = attrib_raw_data_serializer.deserialize(attributeData)
    for reply in replies:
        result = reply['result']
        assert DATA in result
        data = attrib_raw_data_serializer.deserialize(result[DATA])
        assert data == expected_data
        assert result[TXN_TIME]
        check_valid_proof(reply, client)
def test_state_proof_returned_for_get_attr(looper,
                                           addedRawAttribute,
                                           attributeName,
                                           attributeData,
                                           client1, wallet1):
    """
    Tests that state proof is returned in the reply for GET_ATTR transactions.
    Use different submitter and reader!
    """
    get_attr_operation = {
        TARGET_NYM: addedRawAttribute.dest,
        TXN_TYPE: GET_ATTR,
        RAW: attributeName
    }
    replies = submit_operation_and_get_replies(looper,
                                               wallet1, client1,
                                               get_attr_operation)
    expected_data = attrib_raw_data_serializer.deserialize(attributeData)
    for reply in replies:
        result = reply['result']
        assert DATA in result
        data = attrib_raw_data_serializer.deserialize(result[DATA])
        assert data == expected_data
        assert result[TXN_TIME]
        check_valid_proof(reply, client1)
示例#5
0
    def _validateAttrib(self, req: Request):
        origin = req.identifier
        op = req.operation

        if not (not op.get(TARGET_NYM) or
                self.hasNym(op[TARGET_NYM], isCommitted=False)):
            raise InvalidClientRequest(origin, req.reqId,
                                       '{} should be added before adding '
                                       'attribute for it'.
                                       format(TARGET_NYM))

        is_owner = self.idrCache.getOwnerFor(op[TARGET_NYM],
                                             isCommitted=False) == origin
        field = None
        value = None
        for key in (RAW, ENC, HASH):
            if key in op:
                field = key
                value = op[key]
                break
        if field is None or value is None:
            raise LogicError('Attribute data cannot be empty')

        get_key = None
        if field == RAW:
            try:
                get_key = attrib_raw_data_serializer.deserialize(value)
                if len(get_key) == 0:
                    raise InvalidClientRequest(origin, req.reqId,
                                               '"row" attribute field must contain non-empty dict'.
                                               format(TARGET_NYM))
                get_key = next(iter(get_key.keys()))
            except JSONDecodeError:
                raise InvalidClientRequest(origin, req.reqId,
                                           'Attribute field must be dict while adding it as a row field'.
                                           format(TARGET_NYM))
        else:
            get_key = value

        if get_key is None:
            raise LogicError('Attribute data must be parsed')

        old_value, seq_no, _, _ = self.getAttr(op[TARGET_NYM], get_key, field, isCommitted=False)

        if seq_no is not None:
            self.write_req_validator.validate(req,
                                              [AuthActionEdit(txn_type=ATTRIB,
                                                              field=field,
                                                              old_value=old_value,
                                                              new_value=value,
                                                              is_owner=is_owner)])
        else:
            self.write_req_validator.validate(req,
                                              [AuthActionAdd(txn_type=ATTRIB,
                                                             field=field,
                                                             value=value,
                                                             is_owner=is_owner)])
示例#6
0
 def _getAttrReply(self, result, preparedReq):
     # TODO: Confirm if we need to add the retrieved attribute to the wallet.
     # If yes then change the graph query on node to return the sequence
     # number of the attribute txn too.
     attr_type, attr_key = domain._extract_attr_typed_value(result)
     for attrib in self.getAttributesForNym(result[TARGET_NYM]):
         if attrib.name == attr_key:
             attrib.seqNo = result[f.SEQ_NO.nm]
             attrib.value = result[DATA]
             if attr_type == 'raw':
                 attrib.value = attrib_raw_data_serializer.deserialize(attrib.value)
                 attrib.value = attrib_raw_data_serializer.serialize(attrib.value, toBytes=False)
示例#7
0
 def _getAttrReply(self, result, preparedReq):
     # TODO: Confirm if we need to add the retrieved attribute to the wallet.
     # If yes then change the graph query on node to return the sequence
     # number of the attribute txn too.
     attr_type, attr_key = domain._extract_attr_typed_value(result)
     for attrib in self.getAttributesForNym(result[TARGET_NYM]):
         if attrib.name == attr_key:
             attrib.seqNo = result[f.SEQ_NO.nm]
             attrib.value = result[DATA]
             if attr_type == 'raw':
                 attrib.value = attrib_raw_data_serializer.deserialize(attrib.value)
                 attrib.value = attrib_raw_data_serializer.serialize(attrib.value, toBytes=False)
示例#8
0
def parse_attr_txn(txn):
    attr_type, attr = _extract_attr_typed_value(txn)

    if attr_type == RAW:
        data = attrib_raw_data_serializer.deserialize(attr)
        # To exclude user-side formatting issues
        re_raw = attrib_raw_data_serializer.serialize(data, toBytes=False)
        key, _ = data.popitem()
        return attr_type, key, re_raw
    if attr_type == ENC:
        return attr_type, attr, attr
    if attr_type == HASH:
        return attr_type, attr, None
示例#9
0
def test_state_proof_returned_for_get_attr(looper, addedRawAttribute,
                                           attributeName, attributeData,
                                           client1, wallet1):
    """
    Tests that state proof is returned in the reply for GET_ATTR transactions.
    Use different submitter and reader!
    """
    get_attr_operation = {
        TARGET_NYM: addedRawAttribute.dest,
        TXN_TYPE: GET_ATTR,
        RAW: attributeName
    }
    replies = submit_operation_and_get_replies(looper, wallet1, client1,
                                               get_attr_operation)
    expected_data = attrib_raw_data_serializer.deserialize(attributeData)
    for reply in replies:
        result = reply['result']
        assert DATA in result
        data = attrib_raw_data_serializer.deserialize(result[DATA])
        assert data == expected_data
        assert result[TXN_TIME]
        check_valid_proof(reply, client1)
示例#10
0
def parse_attr_txn(txn_data):
    attr_type, attr = _extract_attr_typed_value(txn_data)

    if attr_type == RAW:
        data = attrib_raw_data_serializer.deserialize(attr)
        # To exclude user-side formatting issues
        re_raw = attrib_raw_data_serializer.serialize(data,
                                                      toBytes=False)
        key, _ = data.popitem()
        return attr_type, key, re_raw
    if attr_type == ENC:
        return attr_type, attr, attr
    if attr_type == HASH:
        return attr_type, attr, None
示例#11
0
    def additional_dynamic_validation(self, request: Request,
                                      req_pp_time: Optional[int]):
        self._validate_request_type(request)

        identifier, req_id, operation = get_request_data(request)

        if not (not operation.get(TARGET_NYM)
                or self.__has_nym(operation[TARGET_NYM], is_committed=False)):
            raise InvalidClientRequest(
                identifier, request.reqId, '{} should be added before adding '
                'attribute for it'.format(TARGET_NYM))

        is_owner = self.database_manager.idr_cache.getOwnerFor(
            operation[TARGET_NYM], isCommitted=False) == identifier
        field = None
        value = None
        for key in (RAW, ENC, HASH):
            if key in operation:
                field = key
                value = operation[key]
                break

        if field == RAW:
            get_key = attrib_raw_data_serializer.deserialize(value)
            get_key = list(get_key.keys())[0]
        else:
            get_key = value

        old_value, seq_no, _ = self._get_attr(operation[TARGET_NYM], get_key,
                                              field)

        if seq_no is not None:
            self.write_req_validator.validate(request, [
                AuthActionEdit(txn_type=ATTRIB,
                               field=field,
                               old_value=old_value,
                               new_value=value,
                               is_owner=is_owner)
            ])
        else:
            self.write_req_validator.validate(request, [
                AuthActionAdd(txn_type=ATTRIB,
                              field=field,
                              value=value,
                              is_owner=is_owner)
            ])
示例#12
0
    def static_validation(self, request: Request):
        self._validate_request_type(request)
        identifier, req_id, operation = get_request_data(request)

        if not validate_attrib_keys(operation):
            raise InvalidClientRequest(identifier, req_id,
                                       '{} should have one and only one of '
                                       '{}, {}, {}'
                                       .format(ATTRIB, RAW, ENC, HASH))

        if RAW in operation:
            try:
                get_key = attrib_raw_data_serializer.deserialize(operation[RAW])
                if len(get_key) == 0:
                    raise InvalidClientRequest(identifier, request.reqId,
                                               '"row" attribute field must contain non-empty dict'.
                                               format(TARGET_NYM))
            except JSONDecodeError:
                raise InvalidClientRequest(identifier, request.reqId,
                                           'Attribute field must be dict while adding it as a row field'.
                                           format(TARGET_NYM))