def commit_claims(state, claims, caps=None): for label, content in claims: state[label] = content for reader_dh_pk, label in (caps or []): state.grant_access(reader_dh_pk, label) store = {} chain = hippiehug.Chain(store) head = state.commit(chain) block = store[head] block_content = block.items[0] nonce = ascii2bytes(block_content['nonce']) # Get associated Merkle tree mtr_hash = ascii2bytes(block_content['mtr_hash']) tree = hippiehug.Tree(store, root_hash=mtr_hash) return nonce, chain, tree
def test_claim_headers_in_encrypted_mail(account_maker, tmpdir): acc1, acc2 = account_maker(), account_maker() send_mail(acc1, acc2) pah, dec_msg = send_encrypted_mail(acc2, acc1) cc2 = get_cc_account(acc2) root_hash = dec_msg['GossipClaims'] url = dec_msg['ClaimStore'] assert root_hash == cc2.head_imprint assert cc2.read_claim(acc1.addr) store = FileStore(str(tmpdir), url) assert store[ascii2bytes(root_hash)]
def process_incoming_gossip(self, addr2pagh, account_key, dec_msg): root_hash = dec_msg["GossipClaims"] store = FileStore(dec_msg["ChainStore"]) peers_chain = Chain(store, root_hash=ascii2bytes(root_hash)) assert peers_chain view = View(peers_chain) peers_pk = view.params.dh.pk assert peers_pk sender = parse_email_addr(dec_msg["From"]) self.addr2root_hash[sender] = root_hash self.addr2pk[sender] = peers_pk recipients = get_target_emailadr(dec_msg) for recipient in recipients: pagh = addr2pagh[recipient] value = self.read_claim_from(peers_chain, recipient) if value: # for now we can only read claims about ourselves... # so if we get a value it must be our head imprint. assert value == bytes2ascii(pagh.keydata)
def get_chain(self, store_url, root_hash): cache_dir = os.path.join(self.accountdir, 'cache') store = FileStore(cache_dir, store_url) return Chain(store, root_hash=ascii2bytes(root_hash))