Esempio n. 1
0
    def new_import_wallet(self):
        # TODO when importing a wallet ask the user how many addresses must be recovered.
        input_dialog = NewImportWallet(self)

        if input_dialog.exec_() == QtWidgets.QDialog.Accepted:
            try:
                new_wallet = self.kmd_client.create_wallet(
                    input_dialog.return_value[0],
                    input_dialog.return_value[1],
                    master_deriv_key=to_master_derivation_key(
                        input_dialog.return_value[2]
                        if input_dialog.return_value[2] != "" else None))
            except Exception as e:
                if __debug__:
                    print(type(e), str(e), file=stderr)
                QtWidgets.QMessageBox.critical(self, "Could not create wallet",
                                               str(e))
            else:
                self.listWidget.add_widget(WalletListWidget(
                    Wallet(new_wallet)))
Esempio n. 2
0
import params
from algosdk import kmd, mnemonic

# create a kmd client
kcl = kmd.KMDClient(params.kmd_token, params.kmd_address)

# get the master derivation key from the mnemonic
backup = "alpha worry field wait hobby artist grape engine sponsor broccoli scare thing bean kind say royal inmate hood situate lock benefit omit index about usual"
mdk = mnemonic.to_master_derivation_key(backup)

# recover the wallet by passing mdk when creating a wallet
new_wallet = kcl.create_wallet("wallet40",
                               "testpassword",
                               master_deriv_key=mdk)
print("New Wallet:", new_wallet)

walletid = new_wallet.get("id")
print(walletid)

wallethandle = kcl.init_wallet_handle(walletid, "testpassword")
accounts = kcl.list_keys(wallethandle)
print("Accounts:", accounts)

# if there were accounts previously generated in this wallet, then generate_key() will regenerate them
address = kcl.generate_key(wallethandle)
print("New account:", address)
Esempio n. 3
0
def mn_for_mdk(context, mn):
    context.mn = mn
    context.mdk = mnemonic.to_master_derivation_key(mn)
Esempio n. 4
0
    def test_wallet(self):
        # initialize wallet
        w = wallet.Wallet(wallet_name, wallet_pswd, self.kcl)

        # get master derivation key
        mdk = w.export_master_derivation_key()

        # get mnemonic
        mn = w.get_mnemonic()

        # make sure mnemonic can be converted back to mdk
        self.assertEqual(mdk, mnemonic.to_master_derivation_key(mn))

        # generate account with account and check if it's valid
        private_key_1, account_1 = account.generate_account()

        # import generated account
        import_key = w.import_key(private_key_1)
        self.assertEqual(import_key, account_1)

        # check that the account is in the wallet
        keys = w.list_keys()
        self.assertIn(account_1, keys)

        # generate account with kmd
        account_2 = w.generate_key()
        private_key_2 = w.export_key(account_2)

        # get suggested parameters and fee
        params = self.acl.suggested_params()
        gen = params["genesisID"]
        gh = params["genesishashb64"]
        last_round = params["lastRound"]
        fee = params["fee"]

        # create transaction
        txn = transaction.PaymentTxn(self.account_0,
                                     fee,
                                     last_round,
                                     last_round + 100,
                                     gh,
                                     account_1,
                                     100000,
                                     gen=gen)

        # sign transaction with wallet
        signed_kmd = w.sign_transaction(txn)

        # get self.account_0 private key
        private_key_0 = w.export_key(self.account_0)

        # sign transaction with account
        signed_account = txn.sign(private_key_0)

        # check that signing both ways results in the same thing
        self.assertEqual(encoding.msgpack_encode(signed_account),
                         encoding.msgpack_encode(signed_kmd))

        # create multisig account and transaction
        msig = transaction.Multisig(1, 2, [account_1, account_2])
        txn = transaction.PaymentTxn(msig.address(),
                                     fee,
                                     last_round,
                                     last_round + 100,
                                     gh,
                                     self.account_0,
                                     1000,
                                     gen=gen)

        # import multisig account
        msig_address = w.import_multisig(msig)

        # check that the multisig account is listed
        msigs = w.list_multisig()
        self.assertIn(msig_address, msigs)

        # export multisig account
        exported = w.export_multisig(msig_address)
        self.assertEqual(len(exported.subsigs), 2)

        # create multisig transaction
        mtx = transaction.MultisigTransaction(txn, msig)

        # sign the multisig using kmd
        msig_1 = w.sign_multisig_transaction(account_1, mtx)
        signed_kmd = w.sign_multisig_transaction(account_2, msig_1)

        # sign the multisig offline
        mtx1 = transaction.MultisigTransaction(txn, msig)
        mtx1.sign(private_key_1)
        mtx2 = transaction.MultisigTransaction(txn, msig)
        mtx2.sign(private_key_2)
        signed_account = transaction.MultisigTransaction.merge([mtx1, mtx2])

        # check that they are the same
        self.assertEqual(encoding.msgpack_encode(signed_account),
                         encoding.msgpack_encode(signed_kmd))

        # delete accounts
        del_1 = w.delete_key(account_1)
        del_2 = w.delete_key(account_2)
        del_3 = w.delete_multisig(msig_address)
        self.assertTrue(del_1)
        self.assertTrue(del_2)
        self.assertTrue(del_3)

        # test renaming the wallet
        w.rename(wallet_name + "1")
        self.assertEqual(wallet_name + "1", w.info()["wallet"]["name"])
        w.rename(wallet_name)
        self.assertEqual(wallet_name, w.info()["wallet"]["name"])

        # test releasing the handle
        w.release_handle()
        self.assertRaises(error.KMDHTTPError, self.kcl.get_wallet, w.handle)

        # test handle automation
        w.info()