Example #1
0
    def setUp(self):
        private_key_file_path1 = join_with_root(private_key_file1)
        private_key_file_path2 = join_with_root(private_key_file2)
        password_path = join_with_root(private_key_password_file)

        with open(password_path) as f:
            password = f.read()

        self.pri_key, self.pub_key = ECCipher.load_key_pair(private_key_file_path1, password)
        self.pri_key_2, self.pub_key_2 = ECCipher.load_key_pair(private_key_file_path2, password)

        self.pub_key_string = ECCipher.serialize_public_key(self.pub_key)
        self.pub_key_string2 = ECCipher.serialize_public_key(self.pub_key_2)

        self.address = ECCipher.get_address_from_public_key(self.pub_key)
        self.address_2 = ECCipher.get_address_from_public_key(self.pub_key_2)
Example #2
0
    def buyer_place_order(self, product, proxy):
        buyer_rsa_pubkey = self.rsa_public_key

        desc_hash = Encoder.str_to_base64_byte(product['msg_hash'])

        public_key = ECCipher.create_public_key(
            Encoder.hex_to_bytes(product['owner_address']))
        seller_addr = w3.toChecksumAddress(
            ECCipher.get_address_from_public_key(public_key))
        proxy = w3.toChecksumAddress(proxy)

        product = OrderInfo(desc_hash=desc_hash,
                            buyer_rsa_pubkey=buyer_rsa_pubkey,
                            seller=seller_addr,
                            proxy=proxy,
                            secondary_proxy=proxy,
                            proxy_value=100,
                            value=product['price'],
                            time_allowed=3600 * 24)

        w3.personal.unlockAccount(self.account.address, _passphrase)

        order_id = self.buyer_agent.place_order(product)
        # w3.personal.lockAccount(self.account.address)

        # return -1 if failure
        return order_id
Example #3
0
    def test_load_key(self):
        pri_k, pub_k = ECCipher.load_key_pair(self.private_key_file_path,
                                              self.password)
        self.assertIsNotNone(pri_k)
        self.assertIsNotNone(pub_k)

        pri_key = ECCipher.load_private_key(self.private_key_file_path,
                                            self.password)
        self.assertIsNotNone(pri_key)

        msg = 'test123'
        sig = ECCipher.create_signature(pri_key, msg)
        print('sig:', sig)
        self.assertIsNotNone(sig)

        create_pub_key = ECCipher.create_public_key_from_private_key(pri_key)
        self.assertIsNotNone(create_pub_key)

        load_pub_key = ECCipher.load_public_key(self.private_key_file_path,
                                                self.password)
        self.assertIsNotNone(load_pub_key)

        v1 = ECCipher.verify_sign(load_pub_key, sig, msg)
        self.assertTrue(v1)

        v2 = ECCipher.verify_sign(create_pub_key, sig, msg)
        self.assertTrue(v2)

        addr = ECCipher.get_address_from_public_key(load_pub_key)
        print(addr)
        self.assertIsNotNone(addr)
Example #4
0
    def add_comment_by_hash(self, market_hash, comment=""):
        comment_address = ECCipher.get_address_from_public_key(self.account.public_key)
        logger.debug(comment_address)
        header = {"MARKET-KEY": self.public_key, "MARKET-TOKEN": self.token, 'Content-Type': 'application/json'}
        data = {'public_key': self.public_key, 'market_hash': market_hash, 'content': comment}
        url = utils.build_url(self.url + "comment/v1/comment/add/", {'market_hash': market_hash})

        resp = yield treq.post(url, headers=header, json=data, persistent=False)
        comment_info = yield treq.json_content(resp)
        logger.debug('upload file info to market confirm: %s', comment_info)
        return comment_info['status']
Example #5
0
        "cipher": "aes-128-ctr"
    }
}

keystore = '/tmp/keystore'

with open(keystore, 'w') as f:
    f.write(json.dumps(encrypted_key))

buyer_account = Account(keystore, b'passwd')
seller_account = Account(keystore, b'passwd')

buyer_private_key = buyer_account.private_key  #object type
buyer_public_key = ECCipher.serialize_public_key(
    buyer_account.public_key)  # string type
buyer_addr = ECCipher.get_address_from_public_key(
    buyer_account.public_key)  #string type

seller_private_key = seller_account.private_key
seller_public_key = ECCipher.serialize_public_key(
    seller_account.public_key)  #string type
seller_addr = ECCipher.get_address_from_public_key(
    seller_account.public_key)  #string type

order_id = 1
order_type = 'file'


def fake_seller_message():
    message = Message()
    seller_data = message.seller_data
    message.type = Message.SELLER_DATA
Example #6
0
def get_address_from_public_key_object(pub_key_string):
    pub_key = get_public_key(pub_key_string)
    return ECCipher.get_address_from_public_key(pub_key)
Example #7
0
def is_address_from_key(addr, public_key):
    public_key = ECCipher.create_public_key(public_key)
    public_addr = ECCipher.get_address_from_public_key(public_key)

    return addr == public_addr
Example #8
0
def get_proxy_id():
    return ECCipher.get_address_from_public_key(_proxy_account.public_key)
Example #9
0
 def __init__(self, eth_account):
     self.private_key = ECCipher.create_private_key(eth_account.privateKey)
     public_key = ECCipher.create_public_key_from_private_key(self.private_key)
     self.public_key = ECCipher.serialize_public_key(public_key)
     # self.address = eth_account.address
     self.address = ECCipher.get_address_from_public_key(public_key)