Example #1
0
def test_incorrect_checksum():
    with pytest.raises(ValidationError,
                       match=".* not a valid BIP39 mnemonic phrase!"):
        # Moved 12th word of valid phrase to be 1st
        Account.from_mnemonic(
            "student into trim cross then helmet popular suit hammer cart shrug oval"
        )
Example #2
0
    def add_account(self, *args):
        # Registration
        Account.enable_unaudited_hdwallet_features() 
        acct, mnemonic = Account.create_with_mnemonic()
        # Get private key
        private_class = Account.from_mnemonic(mnemonic) 
        private_dict = private_class.__dict__ 
        private_key = str(private_dict['_key_obj'])

        CteaPerceApp.mnemonic = mnemonic   
        CteaPerceApp.public = acct.address
        CteaPerceApp.private_key = private_key
Example #3
0
def get_account_from_words(words: str, index: int = 0, hd_path: str = ETHEREUM_DEFAULT_PATH) -> LocalAccount:
    """
    :param words: Mnemonic words(BIP39) for a Hierarchical Deterministic Wallet(BIP32)
    :param index: Index of account
    :param hd_path: BIP44 Path. By default Ethereum with 0 index is used
    :return: Ethereum Account
    :raises: eth_utils.ValidationError
    """
    Account.enable_unaudited_hdwallet_features()
    if index:
        hd_path = f'{ETHEREUM_BASE_PATH}/{index}'
    return Account.from_mnemonic(words, account_path=hd_path)
Example #4
0
 def reg(self):
     try:
         Account.enable_unaudited_hdwallet_features()
         mnem = self.ids['mnemonictext'].text
         acct = Account.from_mnemonic(mnem)
         public = acct._address
         private_key = Web3.toHex(acct._key_obj.__dict__['_raw_key'])
         CteaPerceApp.private_key = private_key
         CteaPerceApp.mnemonic = mnem
         CteaPerceApp.public = public
         self.manager.current = 'PickPasswordSign'
     except:
         self.ids['stat'].text = 'Фраза введена неверно'
Example #5
0
def test_compatibility(seed, language, account_path):
    mnemonic = Mnemonic(language).to_mnemonic(seed)
    acct = Account.from_mnemonic(mnemonic, account_path=account_path)
    # NOTE Must do `cd tests/integration/ethers-cli && npm install -g .
    ethers_cli = subprocess.run(
        ['ethers-cli', '-m', mnemonic, '-l', language, '-p', account_path],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )
    if ethers_cli.stderr:
        raise IOError(ethers_cli.stderr.decode("utf-8"))
    ethers_address = ethers_cli.stdout.decode("utf-8").strip()
    assert acct.address == ethers_address
Example #6
0
def generate_accounts(*,
                      mnemonic: Optional[str] = None,
                      num_words=24,
                      limit=12) -> list[GeneratedAccount]:
    result: list[GeneratedAccount] = []
    if not mnemonic:
        mnemonic = generate_mnemonic(num_words)
    for i in range(limit):
        path = f"m/44'/60'/0'/0/{i}"
        acc = Account.from_mnemonic(mnemonic=mnemonic, account_path=path)
        result.append(GeneratedAccount(path, acc.address,
                                       acc.privateKey.hex()))
    return result
Example #7
0
    def action() -> int:
        if not check_pow():
            print("bad pow")
            return 1

        headers = {
            "X-Auth-Key": load_auth_key(),
        }

        data = requests.post(
            f"{INTERNAL_URL}/new",
            headers=headers,
        ).json()

        if data["ok"] == False:
            print("failed to launch instance! please try again")
            return 1

        uuid = data["uuid"]
        mnemonic = data["mnemonic"]

        provider = Web3.HTTPProvider(
            f"{INTERNAL_URL}/{uuid}",
            request_kwargs={
                "headers": {
                    "X-Auth-Key": load_auth_key(),
                    "Content-Type": "application/json",
                },
            },
        )
        web3 = Web3(provider)

        deployer_addr = Account.create().address

        def send_txs(txs) -> str:
            deployed: Optional[str] = None
            for tx in txs:
                rcpt = send_tx(web3, tx, deployer_addr)
                if not rcpt:
                    print(
                        "internal error while performing setup, please try again"
                    )
                    return 1
                if deployed is None and rcpt.contractAddress:
                    deployed = rcpt.contractAddress
            if not deployed:
                print("failed to deploy contract, please try again")
                return 1
            return deployed

        setup_addr = send_txs([
            {
                "from": "0x000000000000000000000000000000000000dEaD",
                "to": "deployer",
                "value": Web3.toWei(10000, "ether"),
            },
            {
                "from": "deployer",
                "value": deploy_value,
                "data": load_bytecode(contract_name),
            },
        ])

        if get_other_txs:
            send_txs(get_other_txs(setup_addr))

        with open(f"/tmp/{uuid}", "w") as f:
            f.write(setup_addr)

        player_acct = Account.from_mnemonic(mnemonic)
        print()
        print(f"your private blockchain has been deployed")
        print(f"it will automatically terminate in 30 minutes")
        print(f"here's some useful information")
        print(f"uuid:           {uuid}")
        print(f"rpc endpoint:   {PUBLIC_URL}/{uuid}")
        print(f"private key:    {player_acct.privateKey.hex()}")
        print(f"setup contract: {setup_addr}")
        return 0
Example #8
0
def test_bad_account_path1():
    with pytest.raises(ValidationError, match="Path is not valid.*"):
        Account.from_mnemonic(
            "finish oppose decorate face calm tragic certain desk hour urge dinosaur mango",
            account_path='not an account path')
Example #9
0
def test_malformed_seed():
    with pytest.raises(ValidationError,
                       match=".* not a valid BIP39 mnemonic phrase!"):
        # Missing 12th word
        Account.from_mnemonic(
            "into trim cross then helmet popular suit hammer cart shrug oval")
Example #10
0
def test_incorrect_size():
    with pytest.raises(ValidationError, match="Language not detected .*"):
        Account.from_mnemonic("this is not a seed phrase")
Example #11
0
def test_bad_passphrase():
    a1, mnemonic = Account.create_with_mnemonic(passphrase="My passphrase")
    a2 = Account.from_mnemonic(mnemonic, passphrase="Not my passphrase")
    assert a1.address != a2.address
Example #12
0
def test_account_restore():
    a1, mnemonic = Account.create_with_mnemonic(num_words=24,
                                                passphrase="TESTING")
    a2 = Account.from_mnemonic(mnemonic, passphrase="TESTING")
    assert a1.address == a2.address
Example #13
0
def test_account_derivation(mnemonic, account_path, expected_address):
    a = Account.from_mnemonic(mnemonic, account_path=account_path)
    assert a.address == expected_address