简体   繁体   English

是否可以从Ledger Nano S Ethereum钱包中导出Xpub Key

[英]Is it possible to export Xpub Key from Ledger Nano S Ethereum Wallet

I need to give payment ETH address to my customers for deposit ETH their accounts. 我需要向我的客户提供付款ETH地址,以便存入他们的账户。 I want to use a HD ETH wallet for this and I am using Ledger Nano S now. 我想使用HD ETH钱包,我现在正在使用Ledger Nano S. But Ledger showing me only 1 receive address so I need ETH wallet's XPub for generate many address from it for distribute to users. 但Ledger只向我显示了1个接收地址,因此我需要ETH钱包的XPub来生成许多地址以便分发给用户。

If Ledger support HD, How can I export XPub? 如果Ledger支持HD,我该如何导出XPub? If ledger does not support, Which wallet can usable for this purpose. 如果分类帐不支持,哪个钱包可以用于此目的。

Any suggestions. 有什么建议。

You can't export the xpub directly from a ledger nano s with the default bitcoin or ethereum apps. 您无法使用默认的比特币或以太坊应用程序直接从分类帐nano导出xpub。

But you can construct an xpub using the data you can extract from the ledger. 但是您可以使用可以从分类帐中提取的数据构建xpub。

What you need is the public key and chaincode for the bip32 path you're interested in and the public key of the parent of that path. 您需要的是您感兴趣的bip32路径的公钥和链码以及该路径的键的公钥。

In the ethereum app you would use getaddress (currently there is a restriction to m/44/60', m/44'/61', and m/44'/1' and below for this app (I have an issue here to hopefully remove that restriction). In the bitcoin app you would use getwalletpublickey . There is no bip32 path restrictions in the bitcoin app. 在以太坊应用程序中,您将使用getaddress (目前对此应用程序有m / 44/60',m / 44'/ 61'和m / 44'/ 1'及以下的限制(我在这里有一个问题)希望删除那个限制)。在比特币应用程序中你会使用getwalletpublickey 。比特币应用程序中没有bip32路径限制。

Once you have the two public keys and the chain code, you can construct the xpub. 一旦有了两个公钥和链码,就可以构造xpub。 Here is a chunk of python that can accomplish this. 这是一块可以实现这一目标的python。 It uses the un-maintained pybitcointools, so user-beware. 它使用未维护的pybitcointools,因此用户要小心。

#!/usr/bin/env python

import sys
import binascii
from bitcoin import bin_hash160
from bitcoin import bip32_serialize
from bitcoin import compress

def main(parent_pubkey, pubkey, chaincode, depth, index, network):
    if (network.lower() == "main"):
        network_bytes = b'\x04\x88\xb2\x1e'
    elif (network.lower() == "test"):
        network_bytes = b'\x04\x35\x87\xcf'
    else:
        sys.exit("network must be either main or test")

    compressed_pubkey_bytes = binascii.unhexlify(compress(pubkey))
    fingerprint_bytes =  bin_hash160(binascii.unhexlify(compress(parent_pubkey)))[:4]
    chaincode_bytes = binascii.unhexlify(chaincode)

    deserialized = (network_bytes, int(depth), fingerprint_bytes, int(index), chaincode_bytes, compressed_pubkey_bytes)
    xpub = bip32_serialize(deserialized)
    print(xpub)

if __name__ == '__main__':
    if (len(sys.argv) < 7):
        sys.exit("USAGE: generate_xpub PARENT_PUBLICKEY PUBLICKEY CHAINCODE DEPTH INDEX (MAIN|TEST)")
    main(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5], sys.argv[6])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM