Make sure we don't confuse user between derivation scheme of coldcard or btcpay

This commit is contained in:
nicolas.dorier 2019-05-09 00:54:53 +09:00
parent f2da64adad
commit 836c3a5b3a
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
2 changed files with 5 additions and 2 deletions

View file

@ -53,7 +53,7 @@ namespace BTCPayServer
return new DirectDerivationStrategy(extPubKey) { Segwit = true };
if (labels[0] == "legacy")
return new DirectDerivationStrategy(extPubKey) { Segwit = false };
if (labels[0] == "p2sh")
if (labels[0] == "p2sh") // segwit p2sh
return new DerivationStrategyFactory(Network).Parse(extPubKey.ToString() + "-[p2sh]");
throw new FormatException();
}

View file

@ -30,6 +30,7 @@ namespace BTCPayServer
if (network == null)
throw new ArgumentNullException(nameof(network));
var result = new DerivationSchemeSettings();
result.Source = "Coldcard";
var derivationSchemeParser = new DerivationSchemeParser(network.NBitcoinNetwork);
JObject jobj = null;
try
@ -48,6 +49,8 @@ namespace BTCPayServer
{
result.AccountOriginal = jobj["xpub"].Value<string>().Trim();
result.AccountDerivation = derivationSchemeParser.ParseElectrum(result.AccountOriginal);
if (result.AccountDerivation is DirectDerivationStrategy direct && !direct.Segwit)
result.AccountOriginal = null; // Saving this would be confusing for user, as xpub of electrum is legacy derivation, but for btcpay, it is segwit derivation
}
catch
{
@ -109,7 +112,7 @@ namespace BTCPayServer
}
[JsonIgnore]
public BTCPayNetwork Network { get; set; }
public string Source { get; set; }
public KeyPath AccountKeyPath { get; set; }
public DerivationStrategyBase AccountDerivation { get; set; }