def test_state_proofs_for_get_attr(request_handler):
    # Adding attribute
    nym = 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'
    attr_key = 'last_name'
    raw_attribute = '{"last_name":"Anderson"}'
    seq_no = 0
    txn_time = int(time.time())
    txn = {
        TXN_TYPE: ATTRIB,
        TARGET_NYM: nym,
        RAW: raw_attribute,
        f.SEQ_NO.nm: seq_no,
        TXN_TIME: txn_time,
    }
    request_handler._addAttr(txn)
    request_handler.state.commit()
    multi_sig = save_multi_sig(request_handler)

    # Getting attribute
    get_request = Request(operation={
        TARGET_NYM: nym,
        RAW: 'last_name'
    },
                          protocolVersion=CURRENT_PROTOCOL_VERSION)
    result = request_handler.handleGetAttrsReq(get_request, 'Sender')

    proof = extract_proof(result, multi_sig)
    attr_value = result[DATA]
    assert attr_value == raw_attribute

    # Verifying signed state proof
    path = domain.make_state_path_for_attr(nym, attr_key)
    assert is_proof_verified(request_handler, proof, path,
                             domain.hash_of(attr_value), seq_no, txn_time)
Exemplo n.º 2
0
    def transform_attrib_for_ledger(txn):
        """
        Creating copy of result so that `RAW`, `ENC` or `HASH` can be
        replaced by their hashes. We do not insert actual attribute data
        in the ledger but only the hash of it.
        """
        txn = deepcopy(txn)
        attr_type, _, value = domain.parse_attr_txn(txn)
        if attr_type in [RAW, ENC]:
            txn[attr_type] = domain.hash_of(value) if value else ''

        return txn
Exemplo n.º 3
0
    def transform_attrib_for_ledger(txn):
        """
        Creating copy of result so that `RAW`, `ENC` or `HASH` can be
        replaced by their hashes. We do not insert actual attribute data
        in the ledger but only the hash of it.
        """
        txn = deepcopy(txn)
        attr_type, _, value = domain.parse_attr_txn(txn)
        if attr_type in [RAW, ENC]:
            txn[attr_type] = domain.hash_of(value) if value else ''

        return txn
Exemplo n.º 4
0
 def prepare_attr_for_state(txn, path_only=False):
     """
     Make key(path)-value pair for state from ATTRIB or GET_ATTR
     :return: state path, state value, value for attribute store
     """
     assert get_type(txn) == ATTRIB
     txn_data = get_payload_data(txn)
     nym = txn_data[TARGET_NYM]
     attr_type, attr_key, value = AttributeHandler.parse_attr_txn(txn_data)
     path = AttributeHandler.make_state_path_for_attr(nym, attr_key, attr_type == HASH)
     if path_only:
         return path
     hashed_value = domain.hash_of(value) if value else ''
     seq_no = get_seq_no(txn)
     txn_time = get_txn_time(txn)
     value_bytes = encode_state_value(hashed_value, seq_no, txn_time)
     return attr_type, path, value, hashed_value, value_bytes
Exemplo n.º 5
0
    def transform_attrib_for_ledger(txn):
        """
        Creating copy of result so that `RAW`, `ENC` or `HASH` can be
        replaced by their hashes. We do not insert actual attribute data
        in the ledger but only the hash of it.
        """
        txn = deepcopy(txn)
        attr_key, value = domain.parse_attr_txn(txn)
        hashed_val = domain.hash_of(value) if value else ''

        if RAW in txn:
            txn[RAW] = hashed_val
        elif ENC in txn:
            txn[ENC] = hashed_val
        elif HASH in txn:
            txn[HASH] = txn[HASH]
        return txn
Exemplo n.º 6
0
def test_state_proofs_for_get_attr(write_manager, read_manager, db_manager):
    # Adding attribute
    nym = 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'
    attr_key = 'last_name'
    raw_attribute = '{"last_name":"Anderson"}'
    seq_no = 0
    txn_time = int(time.time())
    identifier = "6ouriXMZkLeHsuXrN1X1fd"
    txn = {
        TXN_TYPE: ATTRIB,
        TARGET_NYM: nym,
        RAW: raw_attribute,
    }
    txn = append_txn_metadata(reqToTxn(
        Request(operation=txn,
                protocolVersion=CURRENT_PROTOCOL_VERSION,
                identifier=identifier)),
                              seq_no=seq_no,
                              txn_time=txn_time)
    write_manager.update_state(txn)
    db_manager.get_state(DOMAIN_LEDGER_ID).commit()
    multi_sig = save_multi_sig(db_manager)

    # Getting attribute
    get_request = Request(operation={
        TARGET_NYM: nym,
        RAW: 'last_name',
        TXN_TYPE: GET_ATTR,
    },
                          signatures={},
                          protocolVersion=CURRENT_PROTOCOL_VERSION)
    result = read_manager.get_result(get_request)

    proof = extract_proof(result, multi_sig)
    attr_value = result[DATA]
    assert attr_value == raw_attribute

    # Verifying signed state proof
    path = domain.make_state_path_for_attr(nym, attr_key)
    assert is_proof_verified(db_manager, proof, path,
                             domain.hash_of(attr_value), seq_no, txn_time)
def test_state_proofs_for_get_attr(request_handler):
    # Adding attribute
    nym = 'Gw6pDLhcBcoQesN72qfotTgFa7cbuqZpkX3Xo6pLhPhv'
    attr_key = 'last_name'
    raw_attribute = '{"last_name":"Anderson"}'
    seq_no = 0
    txn_time = int(time.time())
    txn = {
        TXN_TYPE: ATTRIB,
        TARGET_NYM: nym,
        RAW: raw_attribute,
        f.SEQ_NO.nm: seq_no,
        TXN_TIME: txn_time,
    }
    request_handler._addAttr(txn)
    request_handler.state.commit()
    multi_sig = save_multi_sig(request_handler)

    # Getting attribute
    get_request = Request(
        operation={
            TARGET_NYM: nym,
            RAW: 'last_name'
        },
        signatures={},
        protocolVersion=CURRENT_PROTOCOL_VERSION
    )
    result = request_handler.handleGetAttrsReq(get_request)

    proof = extract_proof(result, multi_sig)
    attr_value = result[DATA]
    assert attr_value == raw_attribute

    # Verifying signed state proof
    path = domain.make_state_path_for_attr(nym, attr_key)
    assert is_proof_verified(request_handler,
                             proof, path,
                             domain.hash_of(attr_value), seq_no, txn_time)