Code Monkey home page Code Monkey logo

apduboy's Introduction

apduboy

APDUs for Humans ™️

apduboy provides a collection of Pythonic stubs that generate APDUs to communicate with the Ledger Nano S/X hardware wallet.

Installing

pip install apduboy

Examples

Retrieve Ethereum addresses

from ledgerwallet.client import LedgerClient
from ledgerwallet.transport import enumerate_devices

from apduboy.ethereum import GetEthPublicAddressOpts, get_eth_public_address
from apduboy.lib.bip32 import h, m

client = LedgerClient(enumerate_devices()[0])
opts = GetEthPublicAddressOpts(display_address=False, return_chain_code=False)

for index in range(5):
    path = m / h(44) / h(60) / h(index) / 0 / 0
    cmd = get_eth_public_address(path=path, opts=opts)
    response = cmd(client)
    print(f"Address at path {path} => 0x{response.address}")

Retrieve Bitcoin addresses

from ledgerwallet.client import LedgerClient
from ledgerwallet.transport import enumerate_devices

from apduboy.bitcoin import GetWalletPublicKeyOpts, get_wallet_public_key
from apduboy.lib.bip32 import h, m

client = LedgerClient(enumerate_devices()[0])

path = m / h(84) / h(1) / h(7) / 0 / 1234
opts = GetWalletPublicKeyOpts(display_address=False, scheme=None)
cmd = get_wallet_public_key(path=path, opts=opts)
response = cmd(client)
print(f"Address at path {path} => {response.address}")

Generate a cryptographically secure random number

from ledgerwallet.client import LedgerClient
from ledgerwallet.transport import enumerate_devices

from apduboy.bitcoin import get_random

client = LedgerClient(enumerate_devices()[0])

cmd = get_random()
response = cmd(client)
print(f"True Random Number (hex): {response.hex()}")

Sign Ethereum Transaction

from apduboy.ethereum import Ether, GWei, Transaction, sign_transaction
from apduboy.lib.bip32 import h, m

path = m / h(44) / h(60) / h(777) / 0 / 0
tx = Transaction(
    nonce=0,
    gas_price=50 * GWei,
    gas=21000,
    data=b"",
    to=bytes.fromhex("004ec07d2329997267ec62b4166639513386f32e"),
    value=32 * Ether,
)

cmd = sign_transaction(path=path, tx=tx)
response = cmd(device)  # device can be anything that provides an APDU exchange.

apduboy is currently in alpha. Please do NOT use this for signing real transactions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.