Exemplo n.º 1
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
Exemplo n.º 2
0
def derive_proxy_data(msg):

    msg = unpackb(msg, raw=False)

    public_key = ECCipher.create_public_key(msg['public_key'])
    data = msg['data']
    signature = msg['signature']

    valid = ECCipher.verify_sign(public_key, signature, data)
    if valid:
        return data
Exemplo n.º 3
0
def sign_message_verify(sign_message):

    try:
        public_key = ECCipher.create_public_key(sign_message.public_key)

        valid = ECCipher.verify_sign(public_key, sign_message.signature,
                                     sign_message.data)
    except:
        return False

    else:
        return valid
Exemplo n.º 4
0
def get_public_key(public_key_string):
    pub_key_bytes = Encoder.hex_to_bytes(public_key_string)
    return ECCipher.create_public_key(pub_key_bytes)
Exemplo n.º 5
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
Exemplo n.º 6
0
def is_valid_signature(public_key_string, raw_data, signature):
    public_key_bytes = Encoder.hex_to_bytes(public_key_string)
    public_key = ECCipher.create_public_key(public_key_bytes)
    logger.debug("is_valid_verify_code public_key:" + public_key_string +
                 ",raw_data:" + raw_data + ",signature:" + signature)
    return verify_signature(public_key, signature, raw_data)