Esempio n. 1
0
 def _export(self, private=False):
     result = {}
     for name, attr in asdict(self, recurse=False).items():
         if isinstance(attr, Keypair):
             result[name + '_pk'] = pet2ascii(attr.pk)
             if private:
                 result[name + '_sk'] = pet2ascii(attr.sk)
     return result
Esempio n. 2
0
 def register_peer(self, addr, root_hash, store_url, chain=None):
     # TODO: check for existing entries
     if not chain:
         chain = self.get_chain(store_url, root_hash)
     assert chain
     view = View(chain)
     pk = view.params.dh.pk
     assert pk
     self.add_claim((addr,
                     dict(root_hash=root_hash,
                          store_url=store_url,
                          public_key=pet2ascii(pk))))
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)
        alice_chain = Chain(alice_store, alice_head)

        with alice_params.as_default():
            value = View(alice_chain)[b'bobs_key'].decode('utf-8')

        assert value == "123abc"

        with bob_params.as_default():
            value = View(alice_chain)[b'bobs_key'].decode('utf-8')

        assert value == "123abc"
Esempio n. 4
0
 def init_crypto_identity(self):
     identity_file = os.path.join(self.accountdir, 'identity.json')
     if not os.path.exists(identity_file):
         self.params = LocalParams.generate()
         self.state = State()
         self.state.identity_info = "Hi, I'm " + pet2ascii(
             self.params.dh.pk)
         assert self.head_imprint is None
         self.commit_to_chain()
         assert self.head_imprint
         with open(identity_file, 'w') as fp:
             json.dump(self.params.private_export(), fp)
     else:
         with open(identity_file, 'r') as fp:
             params_raw = json.load(fp)
             self.params = LocalParams.from_dict(params_raw)
         self._load_state()
 def sign_block(block):
     sig = sign(block.hash())
     block.aux = pet2ascii(sig)
Esempio n. 6
0
 def public_export(self):
     result = {}
     for name, attr in asdict(self, recurse=False).items():
         if isinstance(attr, Keypair):
             result[name + '_pk'] = pet2ascii(attr.pk)
     return result