async def send_transaction(self, transaction): chain_tag = int((await thor.get_block(0))["hash"][-2:], 16) blk_ref = int(strip_0x((await thor.get_block("best"))["hash"])[:8], 16) tx = ThorTransaction(chain_tag, blk_ref, transaction) tx.sign(self.account_manager.get_priv_by_addr(transaction["from"])) raw = "0x{}".format(encode_hex(rlp.encode(tx))) return await self.send_raw_transaction(raw)
def decode_keystore_json(jsondata, pw): # Get KDF function and parameters if "crypto" in jsondata: cryptdata = jsondata["crypto"] elif "Crypto" in jsondata: cryptdata = jsondata["Crypto"] else: raise Exception("JSON data must contain \"crypto\" object") kdfparams = cryptdata["kdfparams"] kdf = cryptdata["kdf"] if cryptdata["kdf"] not in kdfs: raise Exception("Hash algo %s not supported" % kdf) kdfeval = kdfs[kdf]["calc"] # Get cipher and parameters cipherparams = cryptdata["cipherparams"] cipher = cryptdata["cipher"] if cryptdata["cipher"] not in ciphers: raise Exception("Encryption algo %s not supported" % cipher) decrypt = ciphers[cipher]["decrypt"] # Compute the derived key derivedkey = kdfeval(pw, kdfparams) assert len(derivedkey) >= 32, \ "Derived key must be at least 32 bytes long" # print(b'derivedkey: ' + encode_hex(derivedkey)) enckey = derivedkey[:16] # print(b'enckey: ' + encode_hex(enckey)) ctext = decode_hex(cryptdata["ciphertext"]) # Decrypt the ciphertext o = decrypt(ctext, enckey, cipherparams) # Compare the provided MAC with a locally computed MAC mac1 = sha3(derivedkey[16:32] + ctext) mac2 = decode_hex(cryptdata["mac"]) if mac1 != mac2: raise ValueError("MAC mismatch. Passcode incorrect?") return encode_hex(o)
def send_transaction(self, transaction): tx = ThorTransaction(self, transaction) tx.sign( self.account_manager.get_priv_by_addr( force_obj_to_bytes(transaction["from"]))) data = {"raw": "0x{}".format(encode_hex(rlp.encode(tx)))} result = self.transaction(None)(post, data=data) return None if result is None else result["id"]
def send_transaction(self, transaction): tx = ThorTransaction(self, transaction) tx.sign(self.account_manager.get_priv_by_addr(transaction["from"])) data = { "raw": "0x{}".format(encode_hex(rlp.encode(tx))) } result = self.transactions.make_request(post, data=data) return _attribute(result, "id")
def sign_transaction(self, transaction, from_key): tx = ThorTransaction(self, transaction) tx.sign(from_key) return "0x{}".format(encode_hex(rlp.encode(tx)))
def aes_mkparams(): return {"iv": encode_hex(os.urandom(16))}
def mk_scrypt_params(): params = SCRYPT_CONSTANTS.copy() params['salt'] = encode_hex(os.urandom(16)) return params
def mk_pbkdf2_params(): params = PBKDF2_CONSTANTS.copy() params['salt'] = encode_hex(os.urandom(16)) return params
def priv_to_addr(x): if len(x) > 32: x = decode_hex(x) return add_0x(encode_hex(sha3(bitcoin.privtopub(x)[1:])[12:]))