-1

我正在为 Trezor 构建一个 C# HID 库。它运作良好。我能够越过 pin 条目并检索我的 xpub,并且可以获得地址。但是,返回的地址与我在 Trezor 钱包网站上的任何地址都不匹配。

您可以在此处查看 HID 文档: https ://doc.satoshilabs.com/trezor-tech/api-workflows.html#passphrase-meta-workflow

这不是一个真正的 C# 问题。相反,对于任何 Trezor HID 开发人员来说,这是一个普遍的问题。最大的问题是,如果我将 HDNodePathType 消息作为 GetAddress 方法的 Multisig 属性传递,我会收到错误“无法编码地址”。我需要通过 GetAddress 消息传递什么来获取有效地址?

这是一个 Android 存储库: https ://github.com/trezor/trezor-android

4

1 回答 1

0

现在这个问题已经解决了。Trezor.Net 有一个可以在此处克隆的工作示例。

下面是获取地址的代码:

public async Task<string> GetAddressAsync(IAddressPath addressPath, bool isPublicKey, bool display, AddressType addressType, InputScriptType inputScriptType, string coinName)
{
    try
    {
        var path = addressPath.ToArray();

        if (isPublicKey)
        {
            var publicKey = await SendMessageAsync<PublicKey, GetPublicKey>(new GetPublicKey { CoinName = coinName, AddressNs = path, ShowDisplay = display, ScriptType = inputScriptType });
            return publicKey.Xpub;
        }
        else
        {
            switch (addressType)
            {
                case AddressType.Bitcoin:

                    //Ultra hack to deal with a coin name change in Firmware Version 1.6.2
                    if ((Features.MajorVersion <= 1 && Features.MinorVersion < 6) && coinName == "Bgold")
                    {
                        coinName = "Bitcoin Gold";
                    }

                    return (await SendMessageAsync<Address, GetAddress>(new GetAddress { ShowDisplay = display, AddressNs = path, CoinName = coinName, ScriptType = inputScriptType })).address;

                case AddressType.Ethereum:

                    var ethereumAddress = await SendMessageAsync<EthereumAddress, EthereumGetAddress>(new EthereumGetAddress { ShowDisplay = display, AddressNs = path });

                    var sb = new StringBuilder();
                    foreach (var b in ethereumAddress.Address)
                    {
                        sb.Append(b.ToString("X2").ToLower());
                    }

                    var hexString = sb.ToString();

                    return $"0x{hexString}";
                default:
                    throw new NotImplementedException();
            }
        }
    }
    catch (Exception ex)
    {
        Logger?.Log("Error Getting Trezor Address", LogSection, ex, LogLevel.Error);
        throw;
    }
}
于 2019-02-21T20:05:37.427 回答