Last active
January 29, 2018 22:52
-
-
Save Netherdrake/32ffb5aa98471aef0c339734a4edd95d to your computer and use it in GitHub Desktop.
Generate a bunch of ETH and BTC addresses in bulk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import binascii | |
from trezorlib.client import TrezorClient, CallException | |
from trezorlib import messages as proto | |
def get_transport_class_by_name(name): | |
if name == 'usb': | |
from trezorlib.transport_hid import HidTransport | |
return HidTransport | |
if name == 'udp': | |
from trezorlib.transport_udp import UdpTransport | |
return UdpTransport | |
if name == 'pipe': | |
from trezorlib.transport_pipe import PipeTransport | |
return PipeTransport | |
if name == 'bridge': | |
from trezorlib.transport_bridge import BridgeTransport | |
return BridgeTransport | |
raise NotImplementedError('Unknown transport: "%s"' % name) | |
def get_transport(transport_name, path): | |
transport = get_transport_class_by_name(transport_name) | |
dev = transport.find_by_path(path) | |
return dev | |
# first USB trezor | |
trezor = TrezorClient(get_transport('usb', None)) | |
def bitcoin_address(address_n): | |
return trezor.get_address( | |
'Bitcoin', | |
trezor.expand_path("m/49'/0'/0'/0/%s" % address_n), | |
show_display=False, | |
script_type=proto.InputScriptType.SPENDP2SHWITNESS, | |
) | |
def ethereum_address(address_n): | |
address = trezor.ethereum_get_address( | |
trezor.expand_path("m/44'/60'/0'/0/%s" % address_n), | |
show_display=False, | |
) | |
return '0x%s' % binascii.hexlify(address).decode() | |
if __name__ == "__main__": | |
try: | |
_, num_of_addresses = sys.argv | |
num_of_addresses = int(num_of_addresses) | |
except: | |
print("Usage: python3 gen.py <number_of_addresses>") | |
addresses = { | |
'bitcoin': [bitcoin_address(x) for x in range(0, num_of_addresses)], | |
'ethereum': [ethereum_address(x) for x in range(0, num_of_addresses)], | |
} | |
print(json.dumps(addresses, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment