def getAttr(self, did: str, key: str, attr_type, isCommitted=True) -> (str, int, int, list): assert did is not None assert key is not None path = domain.make_state_path_for_attr(did, key, attr_type == HASH) try: hashed_val, lastSeqNo, lastUpdateTime, proof = \ self.lookup(path, isCommitted) except KeyError: return None, None, None, None if not hashed_val or hashed_val == '': # Its a HASH attribute return hashed_val, lastSeqNo, lastUpdateTime, proof else: try: value = self.attributeStore.get(hashed_val) except KeyError: logger.error( 'Could not get value from attribute store for {}'.format( hashed_val)) return None, None, None, None return value, lastSeqNo, lastUpdateTime, proof
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)
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)
def getAttr(self, did: str, key: str, attr_type, isCommitted=True) -> (str, int, int, list): assert did is not None assert key is not None path = domain.make_state_path_for_attr(did, key, attr_type == HASH) try: hashed_val, lastSeqNo, lastUpdateTime, proof = \ self.lookup(path, isCommitted) except KeyError: return None, None, None, None if not hashed_val or hashed_val == '': # Its a HASH attribute return hashed_val, lastSeqNo, lastUpdateTime, proof else: try: value = self.attributeStore.get(hashed_val) except KeyError: logger.error('Could not get value from attribute store for {}' .format(hashed_val)) return None, None, None, None return value, lastSeqNo, lastUpdateTime, proof