def import_key(self, sec, password): try: pubkey = public_key_from_private_key(sec) except Exception: traceback.print_exc() raise BaseException('Invalid private key') # allow overwrite self.keypairs[pubkey] = pw_encode(sec, password) return pubkey
def create(cls, sec, password): try: pubkey = public_key_from_private_key(sec) except Exception: traceback.print_exc() raise BaseException('Invalid private key') return SimpleKeyStore({ 'type': 'simple', 'pub_key': pubkey, 'encrypt_priv_key': pw_encode(sec, password), 'address': public_key_to_p2pkh(pubkey.decode('hex')) })
def test_cold_hot_wallet(): global network, hot_wallet set_testnet() logging.config.fileConfig('logging.conf') # drop() init() network = NetWorkManager() network.start_ioloop() network.start_client() BlockChain().init_header() network.add_message(Version(["2.8.2", "0.10"])) network.add_message(GetHistory(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj'])) network.add_message(GetMempool(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj'])) network.add_message(GetBalance(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj'])) network.add_message(Listunspent(['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj'])) network.add_message(address_subscribe( ['mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj'])) # 'mmXqJTLjjyD6Xp2tJ7syCeZTcwvRjcojLz' hot_wallet = WatchOnlySimpleWallet(WalletConfig(store_path='watch_only_simple_wallet.json')) secret = '\x20\x12\x10\x09' + '\x09' * 28 if hot_wallet.keystore is None: hot_wallet.init_key_store( WatchOnlySimpleKeyStore.create(public_key_from_private_key(secret))) # hot_wallet.sync() inputs = [ {'prevout_hash': e[0], 'prevout_n': e[1], 'scriptSig': e[2], 'value': e[3], 'address': e[4], 'coinbase': False, 'height': 10000} for e in TxStore().get_unspend_outs('mzSwHcXhWF8bgLtxF7NXE8FF1w8BZhQwSj')] outputs = [] outputs.append(Output((TYPE_ADDRESS, 'mkp8FGgySzhh5mmmHDcxRxmeS3X5fXm68i', 100000))) tx = hot_wallet.make_unsigned_transaction(inputs, outputs, {}) print tx cold_wallet = ColdSimpleWallet(WalletConfig(store_path='cold_simple_wallet.json')) if cold_wallet.keystore is None: cold_wallet.init_key_store(SimpleKeyStore.create(SecretToASecret(secret, True), None)) cold_wallet.sign_transaction(tx, None) # SecretToASecret('\x11'*16, True) print tx
def _get_private_key(self, pubkey, password): pk = pw_decode(self.encrypt_priv_key, password) # this checks the password if pubkey != public_key_from_private_key(pk): raise InvalidPassword() return pk