예제 #1
0
 def _open(self) -> TrezorClient:
     try:
         client = get_default_client()
     except TransportException:
         raise self.NoDeviceDetected("Could not find a TREZOR device to connect to. "
                                     "Is it connected and unlocked?")
     return client
예제 #2
0
def get_trezor_public_key():
    address = trezor_stellar.DEFAULT_BIP32_PATH
    address_n = trezor_tools.parse_path(address)
    m = messages.StellarGetAddress(address_n=address_n)
    c = client.get_default_client()
    r = c.call(m)
    return r.address
예제 #3
0
def main():
    # Use first connected device
    client = get_default_client()

    # Print out Trezor's features and settings
    print(client.features)

    # Get the first address of first BIP44 account
    bip32_path = parse_path("44'/0'/0'/0/0")
    address = btc.get_address(client, "Bitcoin", bip32_path, True)
    print("Bitcoin address:", address)
예제 #4
0
def main():
    # Use first connected device
    client = get_default_client()

    # Print out TREZOR's features and settings
    print(client.features)

    # Get the first address of first BIP44 account
    # (should be the same address as shown in wallet.trezor.io)
    bip32_path = parse_path("44'/0'/0'/0/0")
    address = btc.get_address(client, "Bitcoin", bip32_path, True)
    print("Bitcoin address:", address)
예제 #5
0
def sign_trezor_transaction(transaction, public_key, network_passphrase):
    xdr_data = transaction.to_xdr()
    address_n = trezor_tools.parse_path(trezor_stellar.DEFAULT_BIP32_PATH)
    tx, operations = trezor_stellar.parse_transaction_bytes(
        base64.b64decode(xdr_data))
    resp = trezor_stellar.sign_tx(client.get_default_client(), tx, operations,
                                  address_n, network_passphrase)
    signature = resp.signature
    s_element = DecoratedSignature(SignatureHint(public_key.signature_hint()),
                                   Signature(signature))
    transaction.signatures.append(s_element)
    return transaction
예제 #6
0
def main():
    coins = [
        "Bitcoin"
    ]  # See trezorlib to see what Bitcoin-compatible coins are supported, e.g. "Litecoin". Putting Ethereum, Monero, Ripple here will NOT work unless you make other changes to this program!
    showOnScreen = False  # Show address also on screen of Model T, True or False; turned off
    amountOfAddresses = 100  # number of addresses to be printed. Number of addresses up to 1000000 is ok, for addresses 1000001 or larger Model T gives Warning on screen
    bips = [
        "44", "49", "84"
    ]  # for BTC use "44","49", and/or "84". Other coins might use other values.
    cointType = "0"  # Bitcoin uses "0" real network, i.e. mainnet; "1" test network. Other coins might use other values.
    accounts = [
        "0", "1", "2"
    ]  # accounts up to 20 is ok, for accounts 21 or larger Model T gives Warning on screen
    changeTypes = [
        "0", "1"
    ]  # Bitcoin uses 0 for external and 1 for internal=change. Other coins might use other values.

    logging.basicConfig(stream=sys.stderr,
                        level=logging.WARNING)  # INFO, DEBUG

    # Use first connected device
    client = get_default_client()

    # Print out Trezor's features and settings
    logging.debug(client.features)

    for coin in coins:
        logging.debug("======== Addresses for coin %s ========", coin)

        for bip in bips:
            logging.debug("======== Addresses for BIP %s ========", bip)

            for account in accounts:
                logging.debug("======== Addresses for account %s========",
                              account)

                for changeType in changeTypes:
                    logging.debug(
                        "======== Addresses for change type %s (0=external, 1=internal/change) ========",
                        changeType)

                    # Printing addresses from 0 up to amountOfAddresses
                    for addressIndex in range(amountOfAddresses + 1):

                        pathString = bip + "'/" + cointType + "'/" + account + "'/" + changeType + "/" + str(
                            addressIndex)
                        bip32_path = parse_path(pathString)
                        # script_type: 0...bip44..."address", 4...bip49..."p2shsegwit", 3...bip84..."segwit"
                        # script_type: messages.InputScriptType.SPENDADDRESS, messages.InputScriptType.SPENDWITNESS, messages.InputScriptType.SPENDP2SHWITNESS
                        # get_address(client,coin_name,address_n,show_display=False,multisig=None,script_type=messages.InputScriptType.SPENDADDRESS,)
                        if bip == "44":
                            scriptType = messages.InputScriptType.SPENDADDRESS
                        elif bip == "49":
                            scriptType = messages.InputScriptType.SPENDP2SHWITNESS
                        elif bip == "84":
                            scriptType = messages.InputScriptType.SPENDWITNESS
                        else:
                            sys.exit(
                                "Error: Unknown bip, unknown purpose-field %s in BIP32 address path. Quitting.",
                                bip)

                        address = btc.get_address(client,
                                                  coin,
                                                  bip32_path,
                                                  showOnScreen,
                                                  multisig=None,
                                                  script_type=scriptType)
                        print("Coin: %s, path: m/%s, address: %s" %
                              (coin, pathString, address))
예제 #7
0
 def __init__(self):
     self.client = get_default_client()
     print(self.get_features())
예제 #8
0
args = parser.parse_args()

# Can choose autoconfirm everything on the device (in the device-tests-style)
# (Suitable for long/repetitive transactions)
if args.autoconfirm:
    print("Autoconfirming everything on the device.")
    for device in enumerate_devices():
        try:
            CLIENT = TrezorClientDebugLink(device, auto_interact=True)
            break
        except Exception:
            pass
    else:
        raise RuntimeError("Could not find device")
else:
    CLIENT = get_default_client()
# Choosing between Mainnet and Testnet
if args.testnet:
    COIN = "Testnet"
    URL = "https://tbtc1.trezor.io/api/tx-specific"
else:
    COIN = "Bitcoin"
    URL = "https://btc1.trezor.io/api/tx-specific"
print(f"Operating on {COIN} at {URL}")

# Specific example of generating and signing a transaction with 255 outputs
# (Could be tried on `all all all...` seed on testnet)
# (--autoconfirm really helps here)
INPUTS = [
    messages.TxInputType(
        address_n=parse_path(