Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 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_read_claim_from_other_chain():
for i in range(1,100):
alice_params = LocalParams.generate()
alice_state = State()
alice_store = {}
alice_chain = Chain(alice_store, None)
alice_state.identity_info = "Hi, I'm " + pet2ascii(alice_params.dh.pk)
with alice_params.as_default():
alice_head = alice_state.commit(alice_chain)
alice_chain = Chain(alice_store, alice_head)
bob_params = LocalParams.generate()
bob_state = State()
bob_store = {}
bob_chain = Chain(bob_store, None)
bob_state.identity_info = "Hi, I'm " + pet2ascii(bob_params.dh.pk)
with bob_params.as_default():
bob_head = bob_state.commit(bob_chain)
bob_chain = Chain(bob_store, bob_head)
bob_pk = bob_params.dh.pk
with alice_params.as_default():
alice_state[b"bobs_key"] = b"123abc"
alice_state.grant_access(bob_pk, [b"bobs_key"])
alice_head = alice_state.commit(alice_chain)
def main():
t = Tree()
from os import urandom
rep = 100000
print("For %s repetitions:" % rep)
X = [str(x) for x in xrange(rep)]
bulk = ["x" + str(x) for x in xrange(rep)]
t.multi_add(bulk)
with Timer() as tim:
t.multi_add(X)
print "Time per add: %.4f ms (total: %.2f sec)" % (tim.interval * 1000 / float(rep), tim.interval)
with Timer() as tim:
t.multi_is_in(X)
def main():
r = RedisStore()
t = Tree(store=r)
from os import urandom
for _ in range(1000):
item = urandom(32)
t.add(item)
assert t.is_in(item)
assert not t.is_in(urandom(32))
c0 += 1
claim_label = labels[fof]
vrf_value = vrfs[fof]
cap_lookup_key, encrypted_cap = encode_capability(
friend_dh_pk, nonce, claim_label, vrf_value)
capabilities += [(cap_lookup_key, encrypted_cap)]
cap_index[(friend, fof)] = (cap_lookup_key, encrypted_cap)
t1 = time.time()
print("\t\tTiming per encoded capab: %1.1f ms" % ((t1-t0) / c0 * 1000))
data = encode([enc_claims, capabilities])
print("\t\tData length: %1.1f kb" % (len(data) / 1024.0))
# Build our non-equivocable tree
t0 = time.time()
tree = Tree()
for lookup_key, enc_item in enc_claims + capabilities:
tree.add(key=lookup_key, item=enc_item)
_, evidence = tree.evidence(key=lookup_key)
assert tree.is_in(enc_item, key=lookup_key)
enc_item_hash = evidence[-1].item
tree.store[enc_item_hash] = enc_item
t1 = time.time()
print("\t\tTiming for building non-equiv. tree: %1.1f ms" % ((t1-t0) * 1000))
# Build a chain and a block
t0 = time.time()
c0 = 200
for _ in range(c0):
chain = Chain(tree.store)
payload = Payload.build(tree, nonce).export()
def main():
t = Tree()
from os import urandom
for _ in range(1000):
item = urandom(32)
t.add(item)
assert t.is_in(item)
assert not t.is_in(urandom(32))
tree = Tree()
for lookup_key, enc_item in enc_claims + capabilities:
tree.add(key=lookup_key, item=enc_item)
_, evidence = tree.evidence(key=lookup_key)
assert tree.is_in(enc_item, key=lookup_key)
enc_item_hash = evidence[-1].item
tree.store[enc_item_hash] = enc_item
t1 = time.time()
print("\t\tTiming for building non-equiv. tree: %1.1f ms" % ((t1-t0) * 1000))
# Build a chain and a block
t0 = time.time()
c0 = 200
for _ in range(c0):
chain = Chain(tree.store)
payload = Payload.build(tree, nonce).export()
def sign_block(block):
sig = sign(block.hash())
block.aux = pet2ascii(sig)
chain.multi_add([payload], pre_commit_fn=sign_block)
# Pack block
block = chain.store[chain.head]
packed_block = packb(
("S", block.index, block.fingers, block.items, block.aux))
t1 = time.time()
print("\t\tTiming for building a block: %1.1f ms" % ((t1-t0) / c0 * 1000))
def main(data):
c = DocChain()
for i in range(N):
c.multi_add([data[i]])
def main():
r = RedisStore()
t = Tree(store=r)
from os import urandom
for _ in range(1000):
item = urandom(32)
t.add(item)
assert t.is_in(item)
assert not t.is_in(urandom(32))