def simple_tx_inputs_outputs(from_addr, from_addr_unspent, to_addr, amount_to_send, txfee): if get_address_network_type(from_addr) != get_address_network_type(to_addr): raise Exception('Attempting to create transaction between networks!') selected_unspent = bc.select(from_addr_unspent, amount_to_send+txfee) selected_unspent_bal = get_balance(selected_unspent) changeval = selected_unspent_bal - amount_to_send - txfee if to_addr[0] == 'v' or to_addr[0] == 'w': # stealth ephem_privkey = bc.random_key() nonce = int(bc.random_key()[:8],16) if to_addr[0] == 'v': #network = 'btc' raise Exception('Stealth address payments only supported on testnet at this time.') else: network = 'testnet' tx_outs = bc.mk_stealth_tx_outputs(to_addr, amount_to_send, ephem_privkey, nonce, network) else: tx_outs = [{'value' : amount_to_send, 'address' : to_addr}] if changeval > 0: tx_outs.append({'value' : changeval, 'address' : from_addr}) return selected_unspent, tx_outs
def simple_tx_inputs_outputs(from_addr, from_addr_unspent, to_addr, amount_to_send, txfee): if get_address_network_type(from_addr) != get_address_network_type( to_addr): raise Exception('Attempting to create transaction between networks!') selected_unspent = bc.select(from_addr_unspent, amount_to_send + txfee) selected_unspent_bal = get_balance(selected_unspent) changeval = selected_unspent_bal - amount_to_send - txfee if to_addr[0] == 'v' or to_addr[0] == 'w': # stealth ephem_privkey = bc.random_key() nonce = int(bc.random_key()[:8], 16) if to_addr[0] == 'v': #network = 'btc' raise Exception( 'Stealth address payments only supported on testnet at this time.' ) else: network = 'testnet' tx_outs = bc.mk_stealth_tx_outputs(to_addr, amount_to_send, ephem_privkey, nonce, network) else: tx_outs = [{'value': amount_to_send, 'address': to_addr}] if changeval > 0: tx_outs.append({'value': changeval, 'address': from_addr}) return selected_unspent, tx_outs
def create_wallet(self, method, input, aes_pw): privkey = '' if method == 'wif': fmt = bc.get_privkey_format(input) if fmt == 'wif': privkey = bc.encode_privkey(input, 'hex') elif fmt == 'wif_compressed': privkey = bc.encode_privkey(input, 'hex_compressed') else: raise Exception('Unrecoginized format for private key.') elif method == 'random': privkey = bc.random_key() else: raise Exception('Unsupported method: {0}.'.format(method)) wal_addr = bc.privtoaddr(privkey, self.magic_byte) encr_privkey = wallet.encrypt_privkey(privkey, aes_pw) wallet.create_wallet_file(self.wallet_filename, encr_privkey, wal_addr) # Read back from wallet to ensure consistency encr_privkey2, wal_addr2 = wallet.read_from_wallet_file(self.wallet_filename) privkey2 = wallet.decrypt_privkey(encr_privkey2, aes_pw) if encr_privkey2 != encr_privkey or wal_addr2 != wal_addr: raise Exception('Inconsistency in reading from/writing to wallet!') if privkey2 != privkey: raise Exception('Inconsistency in encrypting/decrypting private key!') return
def do_init(config, username=None): if username is None: username = config.get('DEFAULT', 'username') config.set('DEFAULT', 'username', username) print "set username: {}".format(username) save_config(config) wif_filename = config.get('DEFAULT', 'key_file') if wif_filename.endswith(".wif"): addr_filename = wif_filename[0:-len(".wif")] + ".addr" else: addr_filename = wif_filename + ".addr" if not os.path.exists(wif_filename): try: if not os.path.exists(os.path.dirname(wif_filename)): os.makedirs(os.path.dirname(wif_filename)) privkey = pybitcointools.random_key() encoded = pybitcointools.encode_privkey(privkey, 'wif') addr = pybitcointools.privtoaddr(privkey) with open(wif_filename, "w") as wif_fd: print "writing file: {}".format(wif_filename) wif_fd.write(encoded) wif_fd.write("\n") with open(addr_filename, "w") as addr_fd: print "writing file: {}".format(addr_filename) addr_fd.write(addr) addr_fd.write("\n") except IOError, ioe: raise AcException("IOError: {}".format(str(ioe)))
def create_signup_info(cls, originator_public_key_hash, most_recent_wait_certificate_id): with cls._lock: # First we need to create a public/private key pair for the PoET # enclave to use. cls._poet_private_key = pybitcointools.random_key() cls._poet_public_key = \ pybitcointools.privtopub(cls._poet_private_key) cls._active_wait_timer = None # We are going to fake out the sealing the signup data. signup_data = { 'poet_public_key': pybitcointools.encode_pubkey(cls._poet_public_key, 'hex'), 'poet_private_key': pybitcointools.encode_privkey(cls._poet_private_key, 'hex') } sealed_signup_data = \ pybitcointools.base64.b64encode(dict2json(signup_data)) # Create a fake report report_data = { 'originator_public_key_hash': originator_public_key_hash.upper(), 'poet_public_key': pybitcointools.encode_pubkey(cls._poet_public_key, 'hex').upper() } report = { 'report_data': pybitcointools.sha256(dict2json(report_data)) } # Fake our "proof" data. verification_report = { 'enclave_quote': pybitcointools.base64.b64encode(dict2json(report)), 'pse_manifest_hash': pybitcointools.base64.b64encode( pybitcointools.sha256('manifest destiny')), 'nonce': most_recent_wait_certificate_id } proof_data = { 'verification_report': dict2json(verification_report), 'signature': pybitcointools.ecdsa_sign(dict2json(verification_report), cls._report_private_key) } proof_data_dict = dict2json(proof_data) return \ EnclaveSignupInfo( poet_public_key=signup_data['poet_public_key'], proof_data=proof_data_dict, anti_sybil_id=originator_public_key_hash, sealed_signup_data=sealed_signup_data)
def on_validator_discovered(self, url): # We need a key file for the client, but as soon as the client is # created, we don't need it any more. Then create a new client and # add it to our cadre of clients to use keystring = pybitcointools.encode_privkey( pybitcointools.random_key(), 'wif') self._clients.append(IntegerKeyClient( baseurl=url, keystring=keystring))
def load_config(): home = os.path.expanduser("~") real_user = getpass.getuser() config_file = os.path.join(home, ".sawtooth", "libor.cfg") key_dir = os.path.join(home, ".sawtooth", "keys") config = ConfigParser.SafeConfigParser() config.set('DEFAULT', 'url', 'http://localhost:8800') config.set('DEFAULT', 'key_dir', key_dir) config.set('DEFAULT', 'key_file', '%(key_dir)s/%(username)s.wif') config.set('DEFAULT', 'username', real_user) # If we already have a config file, then read it. Otherwise, # we are going to write a default one. if os.path.exists(config_file): config.read(config_file) else: if not os.path.exists(os.path.dirname(config_file)): os.makedirs(os.path.dirname(config_file)) with open("{}.new".format(config_file), "w") as fd: config.write(fd) os.rename("{}.new".format(config_file), config_file) # If the key file does not already exist, then we are going # to generate one wif_filename = config.get('DEFAULT', 'key_file') if wif_filename.endswith(".wif"): addr_filename = wif_filename[0:-len(".wif")] + ".addr" else: addr_filename = wif_filename + ".addr" if not os.path.exists(wif_filename): try: if not os.path.exists(os.path.dirname(wif_filename)): os.makedirs(os.path.dirname(wif_filename)) private_key = pybitcointools.random_key() encoded_key = pybitcointools.encode_privkey(private_key, 'wif') addr = pybitcointools.privtoaddr(private_key) with open(wif_filename, "w") as wif_fd: wif_fd.write(encoded_key) wif_fd.write("\n") with open(addr_filename, "w") as addr_fd: addr_fd.write(addr) addr_fd.write("\n") except IOError as ioe: raise LIBORClientException("IOError: {}".format(str(ioe))) return config
def test_bulk_keymatch(self): """ Tests key recovery over several keys """ msg = 'foo' for _ in range(0, 20): priv = pbt.random_key() sig = pbt.ecdsa_sign(msg, priv) native_recovered = pbct_nativerecover.recover_pubkey(msg, sig) py_recovered = pbt.ecdsa_recover(msg, sig) self.assertEquals(native_recovered, py_recovered, "Priv Key that failed: {}".format(priv))
def test_bulk_keymatch(self): """ Tests key recovery over several keys """ msg = 'foo' self.longMessage = True for x in range(0, 20): priv = pbt.random_key() sig = pbt.ecdsa_sign(msg, priv) native_recovered = gossip.signed_object.get_verifying_key(msg, sig) py_recovered = pbt.ecdsa_recover(msg, sig) self.assertEquals(native_recovered, py_recovered, "Priv Key that failed: {}".format(priv))
def generate_signing_key(wifstr=None): """Returns a decoded signing key associated with wifstr or generates a random signing key. Args: wifstr (str): A private key in wif format. Returns: str: a signing key. """ if wifstr: return pybitcointools.decode_privkey(wifstr, 'wif') return pybitcointools.random_key()
def do_generate(args): private_key = pybitcointools.random_key() public_key = pybitcointools.encode_pubkey( pybitcointools.privkey_to_pubkey(private_key), "hex") words = generate_word_list(args.pool_size) batches = [] start = time.time() total_txn_count = 0 for i in xrange(0, args.count): txns = [] for _ in xrange(0, random.randint(1, args.batch_max_size)): txn = create_intkey_transaction( verb=random.choice(['set', 'inc', 'dec']), name=random.choice(words), value=random.randint(0, 100000), private_key=private_key, public_key=public_key) total_txn_count += 1 txns.append(txn) batch = create_batch( transactions=txns, private_key=private_key, public_key=public_key) batches.append(batch) if i % 100 == 0 and i != 0: stop = time.time() txn_count = 0 for batch in batches[-100:]: txn_count += len(batch.transactions) fmt = 'batches {}, batch/sec: {:.2f}, txns: {}, txns/sec: {:.2f}' print fmt.format( str(i), 100 / (stop - start), str(total_txn_count), txn_count / (stop - start)) start = stop batch_list = batch_pb2.BatchList(batches=batches) print "Writing to {}...".format(args.output) with open(args.output, "w") as fd: fd.write(batch_list.SerializeToString())
def do_init(args, config): username = config.get('DEFAULT', 'username') if args.username is not None: if len(args.username) < 3 or len(args.username) > 16: raise ClientException( "username must be between 3 and 16 characters") username = args.username config.set('DEFAULT', 'username', username) print "set username: {}".format(username) else: print "Username: {}".format(username) http_url = config.get('DEFAULT', 'url') if args.url is not None: http_url = args.url config.set('DEFAULT', 'url', http_url) print "set url to {}".format(http_url) else: print "Validator url: {}".format(http_url) save_config(config) wif_filename = config.get('DEFAULT', 'key_file') if wif_filename.endswith(".wif"): addr_filename = wif_filename[0:-len(".wif")] + ".addr" else: addr_filename = wif_filename + ".addr" if not os.path.exists(wif_filename): try: if not os.path.exists(os.path.dirname(wif_filename)): os.makedirs(os.path.dirname(wif_filename)) privkey = pybitcointools.random_key() encoded = pybitcointools.encode_privkey(privkey, 'wif') addr = pybitcointools.privtoaddr(privkey) with open(wif_filename, "w") as wif_fd: print "writing file: {}".format(wif_filename) wif_fd.write(encoded) wif_fd.write("\n") with open(addr_filename, "w") as addr_fd: print "writing file: {}".format(addr_filename) addr_fd.write(addr) addr_fd.write("\n") except IOError, ioe: raise ClientException("IOError: {}".format(str(ioe)))
def test_compressed_keys(self): """ Tests compressed key """ msg = 'foo' priv = pbt.encode_privkey(pbt.random_key(), 'hex_compressed') sig = pbt.ecdsa_sign(msg, priv) # Force old pybitcointools to behave v, r, s = pbt.decode_sig(sig) if v < 31: v += 4 sig = pbt.encode_sig(v, r, s) pub = pbt.compress(pbt.privtopub(priv)) native_recovered = pbct_nativerecover.recover_pubkey(msg, sig) self.assertEquals(native_recovered, pub, "Priv Key that failed: {}".format(priv))
def on_validator_discovered(self, url): # We need a key file for the client, but as soon as the client is # created, we don't need it any more, so a temporary file is # sufficient key_file = NamedTemporaryFile() private_key = pybitcointools.random_key() encoded_key = pybitcointools.encode_privkey(private_key, 'wif') key_file.write(encoded_key) key_file.write('\n') key_file.flush() # Create a new client and add it to our cadre of clients to use self._clients.append(XoClient(url, key_file.name)) # Closing the temporary file will cause it to also be deleted key_file.close()
def _create_temporary_key_file(): """ A useful helper method for derived classes. Remember to close the returned temporary file so that it gets deleted. Returns: A NamedTemporaryFile object. """ key_file = NamedTemporaryFile() private_key = pybitcointools.random_key() encoded_key = pybitcointools.encode_privkey(private_key, 'wif') key_file.write(encoded_key) key_file.write('\n') key_file.flush() return key_file
def test_compressed_keys(self): """ Tests compressed key """ msg = 'foo' self.longMessage = True priv = pbt.encode_privkey(pbt.random_key(), 'hex_compressed') sig = pbt.ecdsa_sign(msg, priv) # Force old pybitcointools to behave v, r, s = pbt.decode_sig(sig) if v < 31: v += 4 sig = pbt.encode_sig(v, r, s) pub = pbt.compress(pbt.privtopub(priv)) native_recovered = gossip.signed_object.get_verifying_key(msg, sig) self.assertEquals(native_recovered, pub, "Priv Key that failed: {}".format(priv))
def setup(self): self.state = mktplace_state.MarketPlaceState(self.urls[0]) with Progress("Creating participants") as p: for i in range(0, self.count): name = "actor-{}".format(i) keyfile = os.path.join(self.testDir, "{}.wif".format(name)) if os.path.exists(keyfile): key = read_key_file(keyfile) else: key = pybitcointools.encode_privkey( pybitcointools.random_key(), 'wif') write_key_file(keyfile, key) url = self.urls[random.randint(0, len(self.urls) - 1)] a = MktActor(name, url, key) self.Actors.append(a) p.step() with Progress("Registering actors assets") as p: for a in self.Actors: # create assets a.register_asset(a.Name + "-asset") p.step() self.wait_for_transaction_commits() with Progress("Registering holdings") as p: for a in self.Actors: a.update() a.offers = [] for a2 in self.Actors: count = 0 if a is a2: # for each iteration we need 1 to pay with and 1 to # give count = 2 * self.count * self.iterations for ast in a2.assets.keys(): a.register_holding(ast, count) p.step() self.wait_for_transaction_commits()
def create_signup_info(cls, originator_public_key): # First we need to create a public/private key pair for the PoET # enclave to use. cls._poet_private_key = pybitcointools.random_key() cls._poet_public_key = pybitcointools.privtopub(cls._poet_private_key) cls._active_wait_timer = None # We are going to fake out the sealing the signup data. signup_data = { 'poet_public_key': pybitcointools.encode_pubkey(cls._poet_public_key, 'hex'), 'poet_private_key': pybitcointools.encode_privkey(cls._poet_private_key, 'hex') } sealed_signup_data = \ pybitcointools.base64.b32encode(dict2json(signup_data)) # Create a fake report report_data = { 'originator_public_key_hash': pybitcointools.sha256( pybitcointools.encode_pubkey(originator_public_key, 'hex')), 'poet_public_key': pybitcointools.encode_pubkey(cls._poet_public_key, 'hex') } report = {'report_data': pybitcointools.sha256(dict2json(report_data))} report = pybitcointools.base64.b32encode(dict2json(report)) # Fake our "proof" data. proof_data = { 'attestation_evidence_payload': pybitcointools.sha256(report), 'attestation_verification_report': pybitcointools.sha256('Shave and a haircut...Two bits!') } return \ EnclaveSignupInfo( anti_sybil_id='Sally Field', poet_public_key=signup_data['poet_public_key'], proof_data=proof_data, sealed_signup_data=sealed_signup_data)
def do_init(args, config): username = config.get('DEFAULT', 'username') if args.username is not None: username = args.username config.set('DEFAULT', 'username', username) print "set username: {}".format(username) save_config(config) wif_filename = config.get('DEFAULT', 'key_file') if wif_filename.endswith(".wif"): addr_filename = wif_filename[0:-len(".wif")] + ".addr" else: addr_filename = wif_filename + ".addr" if not os.path.exists(wif_filename): try: if not os.path.exists(os.path.dirname(wif_filename)): os.makedirs(os.path.dirname(wif_filename)) privkey = pybitcointools.random_key() encoded = pybitcointools.encode_privkey(privkey, 'wif') addr = pybitcointools.privtoaddr(privkey) with open(wif_filename, "w") as wif_fd: print "writing file: {}".format(wif_filename) wif_fd.write(encoded) wif_fd.write("\n") with open(addr_filename, "w") as addr_fd: print "writing file: {}".format(addr_filename) addr_fd.write(addr) addr_fd.write("\n") except IOError, ioe: raise XoException("IOError: {}".format(str(ioe)))
raise ClientException('IOError: {}'.format(str(e))) wif_filename = os.path.join(key_dir, key_name + '.wif') addr_filename = os.path.join(key_dir, key_name + '.addr') if not args.force: file_exists = False for filename in [wif_filename, addr_filename]: if os.path.exists(filename): file_exists = True print >>sys.stderr, 'file exists: {}'.format(filename) if file_exists: raise ClientException( 'files exist, rerun with --force to overwrite existing files') privkey = pybitcointools.random_key() encoded = pybitcointools.encode_privkey(privkey, 'wif') addr = pybitcointools.privtoaddr(privkey) try: wif_exists = os.path.exists(wif_filename) with open(wif_filename, 'w') as wif_fd: if not args.quiet: if wif_exists: print 'overwriting file: {}'.format(wif_filename) else: print 'writing file: {}'.format(wif_filename) wif_fd.write(encoded) wif_fd.write('\n') addr_exists = os.path.exists(addr_filename)
def do_generate(args): private_key = pybitcointools.random_key() public_key = pybitcointools.encode_pubkey( pybitcointools.privkey_to_pubkey(private_key), "hex") words = generate_word_list(args.pool_size) txns = [] batches = [] bytecode = "" with open(args.contract, "rb") as fd: byte = fd.readline() while byte != "": bytecode += byte byte = fd.readline() byte_addr = get_address("jvm_sc", bytecode) txn = create_jvm_sc_transaction( verb='store', private_key=private_key, public_key=public_key, bytecode=bytecode, methods=["set", "inc", "dec"]) txns.append(txn) keys = [] addresses = [] for i in range(20): if len(txns) < 10: key = random.choice(words) keys.append(key) value = str(random.randint(0, 1000)) key_addr = get_address("intkey", key) addresses.append(key_addr) txn = create_jvm_sc_transaction( verb='run', private_key=private_key, public_key=public_key, byte_addr=byte_addr, method="set", parameters=["key," + key, "value," + value, "&check," + key_addr], addresses=addresses) txns.append(txn) addresses = [] else: batch = create_batch(txns, private_key, public_key) batches.append(batch) txns = [] for i in range(20): if len(txns) < 10: key = random.choice(keys) key_addr = get_address("intkey", key) addresses.append(key_addr) txn = create_jvm_sc_transaction( verb='run', private_key=private_key, public_key=public_key, byte_addr=byte_addr, method=random.choice(["inc", "dec"]), parameters=["key," + key, "&value," + key_addr, "diff,2"], addresses=addresses) txns.append(txn) addresses = [] else: batch = create_batch(txns, private_key, public_key) batches.append(batch) txns = [] batch_list = batch_pb2.BatchList(batches=batches) print "Writing to {}...".format(args.output) with open(args.output, "w") as fd: fd.write(batch_list.SerializeToString())
# Think of the WIF as the private key with metadata (this metadata indicates if WIF is a bitcoin wallet # and if it's linked with a compressed or uncompressed public key. It also includes a checksum). # # This WIF format allows portability, allowing wallet apps to know how deal with it. # # REMEMBER that the private key is not compressed or uncompressed, it's just a big number encoded # with hex. The compression can only applied to the public key. Good explanation here: # https://www.reddit.com/r/Bitcoin/comments/2u0tin/why_are_private_keys_called_compressed_if_theyre/ # # We are now generating a random private key with pybitcointools library. # IMPORTANT: I CANNOT GUARANTEE THAT THE FOLLOWING GENERATED RANDOM KEY IS SECURE. I CAN ASSUME THOUGH. # # PLEASE USE IT ONLY FOR THIS DEMO. FOR YOUR REAL LIFE BITCOIN WALLETS, USE A PROPER # OFFLINE WALLET APP. # private_key_hex = pybitcointools.random_key() # Each cryptocurrency Private Key has their own prefix version number (Bitcoin= 0x80, Litecoin=0xB0, etc). # Prepend this version number in front of the private_key_hex value. # The prefix version number is always 1 byte in size and the private_key_hex is 32 bytes. # The private_key_with_version value is always (1+32=) 33 bytes or 66 characters long. private_key_with_version = '80' + private_key_hex # WIF ADDRESS FOR UNCOMPRESSED PUBLIC KEY # # The Private Key Wallet Import Format (WIF) is just the Private Key # with metadata and encoded with Base58 (check generate_addresses.wif_private_key # function for details). # # Sometimes The WIF key is referred as "compressed or uncompressed WIF". This is confusing because # the actual private key or derived WIF is never compressed. When people mention "compressed or uncompressed WIF"
def main(args=sys.argv[1:]): parser = argparse.ArgumentParser() # The intent is that node_name and keydir both be optional at some # future point, by reading in the appropriate values from the config # file. Therefore, no default is currently set and both are marked # as required so that the future usage of using config values as # defaults can be added without breaking anything. parser.add_argument('node_name', help="name of the node") parser.add_argument('--keydir', help="directory to write key files", required=True) parser.add_argument('-f', '--force', help="overwrite files if they exist", action='store_true') parser.add_argument('-q', '--quiet', help="print no output", action='store_true') options = parser.parse_args(args) base_filename = os.path.join(options.keydir, options.node_name) wif_filename = base_filename + ".wif" addr_filename = base_filename + ".addr" if not os.path.isdir(options.keydir): print >> sys.stderr, "no such directory: {}".format(options.keydir) sys.exit(1) if not options.force: file_exists = False for filename in [wif_filename, addr_filename]: if os.path.exists(filename): file_exists = True print >> sys.stderr, "file exists: {}".format(filename) if file_exists: print >> sys.stderr, \ "rerun with --force to overwrite existing files" sys.exit(1) privkey = pybitcointools.random_key() encoded = pybitcointools.encode_privkey(privkey, 'wif') addr = pybitcointools.privtoaddr(privkey) try: wif_exists = os.path.exists(wif_filename) with open(wif_filename, "w") as wif_fd: if not options.quiet: if wif_exists: print "overwriting file: {}".format(wif_filename) else: print "writing file: {}".format(wif_filename) wif_fd.write(encoded) wif_fd.write("\n") addr_exists = os.path.exists(addr_filename) with open(addr_filename, "w") as addr_fd: if not options.quiet: if addr_exists: print "overwriting file: {}".format(addr_filename) else: print "writing file: {}".format(addr_filename) addr_fd.write(addr) addr_fd.write("\n") except IOError, ioe: print >> sys.stderr, "IOError: {}".format(str(ioe)) sys.exit(1)
def do_generate(args): private_key = pybitcointools.random_key() public_key = pybitcointools.encode_pubkey( pybitcointools.privkey_to_pubkey(private_key), "hex") words = generate_word_list(args.pool_size) txns = [] batches = [] bytecode = "" with open(args.contract, "rb") as fd: byte = fd.readline() while byte != "": bytecode += byte byte = fd.readline() byte_addr = get_address("jvm_sc", bytecode) txn = create_jvm_sc_transaction(verb='store', private_key=private_key, public_key=public_key, bytecode=bytecode, methods=["set", "inc", "dec"]) txns.append(txn) keys = [] addresses = [] for i in range(20): if len(txns) < 10: key = random.choice(words) keys.append(key) value = str(random.randint(0, 1000)) key_addr = get_address("intkey", key) addresses.append(key_addr) txn = create_jvm_sc_transaction(verb='run', private_key=private_key, public_key=public_key, byte_addr=byte_addr, method="set", parameters=[ "key," + key, "value," + value, "&check," + key_addr ], addresses=addresses) txns.append(txn) addresses = [] else: batch = create_batch(txns, private_key, public_key) batches.append(batch) txns = [] for i in range(20): if len(txns) < 10: key = random.choice(keys) key_addr = get_address("intkey", key) addresses.append(key_addr) txn = create_jvm_sc_transaction( verb='run', private_key=private_key, public_key=public_key, byte_addr=byte_addr, method=random.choice(["inc", "dec"]), parameters=["key," + key, "&value," + key_addr, "diff,2"], addresses=addresses) txns.append(txn) addresses = [] else: batch = create_batch(txns, private_key, public_key) batches.append(batch) txns = [] batch_list = batch_pb2.BatchList(batches=batches) print "Writing to {}...".format(args.output) with open(args.output, "w") as fd: fd.write(batch_list.SerializeToString())
def __init__(self): self.SigningKey = pybitcointools.random_key() self.Address = pybitcointools.privtoaddr(self.SigningKey)
def _create_random_key(cls): return pybitcointools.random_key()
def generate_privkey(): return pybitcointools.random_key()
def create_signup_info(cls, originator_public_key, validator_network_basename, most_recent_wait_certificate_id): with cls._lock: # First we need to create a public/private key pair for the PoET # enclave to use. cls._poet_private_key = pybitcointools.random_key() cls._poet_public_key = \ pybitcointools.privtopub(cls._poet_private_key) cls._active_wait_timer = None # We are going to fake out the sealing the signup data. signup_data = { 'poet_public_key': pybitcointools.encode_pubkey(cls._poet_public_key, 'hex'), 'poet_private_key': pybitcointools.encode_privkey( cls._poet_private_key, 'hex') } sealed_signup_data = \ pybitcointools.base64.b32encode(dict2json(signup_data)) # Create a fake report report_data = { 'originator_public_key_hash': pybitcointools.sha256( pybitcointools.encode_pubkey( originator_public_key, 'hex')), 'poet_public_key': pybitcointools.encode_pubkey(cls._poet_public_key, 'hex') } report = { 'report_data': pybitcointools.sha256(dict2json(report_data)), 'validator_network_basename': validator_network_basename } # Fake our "proof" data. attestation_evidence_payload = { 'enclave_quote': pybitcointools.base64.b64encode(dict2json(report)), 'pse_manifest': pybitcointools.base64.b64encode( pybitcointools.sha256( 'manifest destiny')), 'nonce': most_recent_wait_certificate_id } attestation_verification_report = { 'attestation_evidence_payload': attestation_evidence_payload, 'anti_sybil_id': cls._anti_sybil_id } proof_data = { 'attestation_verification_report': attestation_verification_report, 'signature': pybitcointools.ecdsa_sign( dict2json(attestation_verification_report), cls._report_private_key) } return \ EnclaveSignupInfo( poet_public_key=signup_data['poet_public_key'], proof_data=proof_data, sealed_signup_data=sealed_signup_data)
def _create_random_private_key(cls): return pybitcointools.random_key()
raise ClientException('IOError: {}'.format(str(e))) wif_filename = os.path.join(key_dir, key_name + '.wif') addr_filename = os.path.join(key_dir, key_name + '.addr') if not args.force: file_exists = False for filename in [wif_filename, addr_filename]: if os.path.exists(filename): file_exists = True print >> sys.stderr, 'file exists: {}'.format(filename) if file_exists: raise ClientException( 'files exist, rerun with --force to overwrite existing files') privkey = pybitcointools.random_key() encoded = pybitcointools.encode_privkey(privkey, 'wif') addr = pybitcointools.privtoaddr(privkey) try: wif_exists = os.path.exists(wif_filename) with open(wif_filename, 'w') as wif_fd: if not args.quiet: if wif_exists: print 'overwriting file: {}'.format(wif_filename) else: print 'writing file: {}'.format(wif_filename) wif_fd.write(encoded) wif_fd.write('\n') addr_exists = os.path.exists(addr_filename)
def generate_private_key(): return pybitcointools.encode_privkey(pybitcointools.random_key(), 'wif')