我正在为Trezor构建一个C#HID库。它运作良好。我能够通过pin条目并检索我的xpub,我可以获取地址。但是,返回的地址都不会与Trezor钱包网站中的任何地址匹配。
你可以在这里看到HID doco: 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
答案 0 :(得分:0)
此问题现已解决。 Trezor.Net有一个可以复制here的工作示例。
以下是获取地址的code:
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;
}
}