Exemplo n.º 1
0
async def sign_raw_tx(request):
    post = await web_base.content_type_json_check(request)
    try:
        binary = unhexlify(post['hex'].encode())
        other_pairs = dict()
        for sk in post.get('pairs', list()):
            pk = public_key(sk=sk)
            ck = get_address(pk=pk, prefix=V.BLOCK_PREFIX)
            other_pairs[ck] = (pk, sign(msg=binary, sk=sk, pk=pk))
        tx = TX(binary=binary)
        for txhash, txindex in tx.inputs:
            input_tx = tx_builder.get_tx(txhash)
            address, coin_id, amount = input_tx.outputs[txindex]
            try:
                tx.signature.append(
                    message2signature(raw=tx.b, address=address))
            except BlockChainError:
                if address not in other_pairs:
                    raise BlockChainError(
                        'Not found secret key "{}"'.format(address))
                tx.signature.append(other_pairs[address])
        data = tx.getinfo()
        return web_base.json_res({
            'hash': data['hash'],
            'signature': data['signature'],
            'hex': hexlify(tx.b).decode()
        })
    except BaseException:
        return web_base.error_res()
Exemplo n.º 2
0
 def create_account(seed=None):
     if seed is None:
         sk = secret_key()
     else:
         str = hashlib.sha512(seed).hexdigest()
         sk = secret_key(str.encode())
     pk = public_key(sk)
     ck = get_address(pk, main_net=True)
     return sk, ck
Exemplo n.º 3
0
 def calculate_address(self, is_mainnet=True):
     return get_address(self.pk, main_net=is_mainnet)
Exemplo n.º 4
0
 def NemKeypair(self, prefix=None):
     if self.public:
         raise Exception('NEM publicKey derive from secretKey directly')
     pk = public_key(sk=self.PrivateKey(), encode=bytes)
     ck = get_address(pk=pk, main_net=bool(not self.testnet), prefix=prefix)
     return pk, ck