public void Add(BTCPayNetwork network) { _Networks.Add(network.CryptoCode.ToUpperInvariant(), network); }
public bool IsAvailable(BTCPayNetwork network) { return(IsAvailable(network.CryptoCode)); }
public static bool TryParseFromColdcard(string coldcardExport, BTCPayNetwork network, out DerivationSchemeSettings settings) { settings = null; if (coldcardExport == null) { throw new ArgumentNullException(nameof(coldcardExport)); } if (network == null) { throw new ArgumentNullException(nameof(network)); } var result = new DerivationSchemeSettings(); result.Source = "Coldcard"; var derivationSchemeParser = new DerivationSchemeParser(network); JObject jobj = null; try { jobj = JObject.Parse(coldcardExport); jobj = (JObject)jobj["keystore"]; } catch { return(false); } if (jobj.ContainsKey("xpub")) { try { result.AccountOriginal = jobj["xpub"].Value <string>().Trim(); result.AccountDerivation = derivationSchemeParser.ParseElectrum(result.AccountOriginal); result.AccountKeySettings = new AccountKeySettings[1]; result.AccountKeySettings[0] = new AccountKeySettings(); result.AccountKeySettings[0].AccountKey = result.AccountDerivation.GetExtPubKeys().Single().GetWif(network.NBitcoinNetwork); 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 { return(false); } } else { return(false); } if (jobj.ContainsKey("label")) { try { result.Label = jobj["label"].Value <string>(); } catch { return(false); } } if (jobj.ContainsKey("ckcc_xfp")) { try { result.AccountKeySettings[0].RootFingerprint = new HDFingerprint(jobj["ckcc_xfp"].Value <uint>()); } catch { return(false); } } if (jobj.ContainsKey("derivation")) { try { result.AccountKeySettings[0].AccountKeyPath = new KeyPath(jobj["derivation"].Value <string>()); } catch { return(false); } } settings = result; settings.Network = network; return(true); }
public static string ShowMoney(this IMoney money, BTCPayNetwork network) { return(money.GetValue(network).ShowMoney(network.Divisibility)); }
public static bool TryParseFromWalletFile(string fileContents, BTCPayNetwork network, out DerivationSchemeSettings settings) { settings = null; if (fileContents == null) { throw new ArgumentNullException(nameof(fileContents)); } if (network == null) { throw new ArgumentNullException(nameof(network)); } var result = new DerivationSchemeSettings(); var derivationSchemeParser = new DerivationSchemeParser(network); JObject jobj = null; try { jobj = JObject.Parse(fileContents); } catch { result.Source = "GenericFile"; return(TryParseXpub(fileContents, derivationSchemeParser, ref result)); } //electrum if (jobj.ContainsKey("keystore")) { result.Source = "ElectrumFile"; jobj = (JObject)jobj["keystore"]; if (!jobj.ContainsKey("xpub") || !TryParseXpub(jobj["xpub"].Value <string>(), derivationSchemeParser, ref result)) { return(false); } if (jobj.ContainsKey("label")) { try { result.Label = jobj["label"].Value <string>(); } catch { return(false); } } if (jobj.ContainsKey("ckcc_xfp")) { try { result.AccountKeySettings[0].RootFingerprint = new HDFingerprint(jobj["ckcc_xfp"].Value <uint>()); } catch { return(false); } } if (jobj.ContainsKey("derivation")) { try { result.AccountKeySettings[0].AccountKeyPath = new KeyPath(jobj["derivation"].Value <string>()); } catch { return(false); } } } else { result.Source = "WasabiFile"; //wasabi format if (!jobj.ContainsKey("ExtPubKey") || !TryParseXpub(jobj["ExtPubKey"].Value <string>(), derivationSchemeParser, ref result, false)) { return(false); } if (jobj.ContainsKey("MasterFingerprint")) { try { var mfpString = jobj["MasterFingerprint"].ToString().Trim(); // https://github.com/zkSNACKs/WalletWasabi/pull/1663#issuecomment-508073066 if (uint.TryParse(mfpString, out var fingerprint)) { result.AccountKeySettings[0].RootFingerprint = new HDFingerprint(fingerprint); } else { var shouldReverseMfp = jobj.ContainsKey("ColdCardFirmwareVersion") && jobj["ColdCardFirmwareVersion"].ToString() == "2.1.0"; var bytes = Encoders.Hex.DecodeData(mfpString); result.AccountKeySettings[0].RootFingerprint = shouldReverseMfp ? new HDFingerprint(bytes.Reverse().ToArray()) : new HDFingerprint(bytes); } } catch { return(false); } } if (jobj.ContainsKey("AccountKeyPath")) { try { result.AccountKeySettings[0].AccountKeyPath = new KeyPath(jobj["AccountKeyPath"].Value <string>()); } catch { return(false); } } if (jobj.ContainsKey("DerivationPath")) { try { result.AccountKeySettings[0].AccountKeyPath = new KeyPath(jobj["DerivationPath"].Value <string>().ToLowerInvariant()); } catch { return(false); } } if (jobj.ContainsKey("ColdCardFirmwareVersion")) { result.Source = "ColdCard"; } if (jobj.ContainsKey("CoboVaultFirmwareVersion")) { result.Source = "CoboVault"; } } settings = result; settings.Network = network; return(true); }
public static async Task <Dictionary <uint256, TransactionResult> > GetTransactions(this BTCPayWallet client, BTCPayNetwork network, uint256[] hashes, CancellationToken cts = default(CancellationToken)) { hashes = hashes.Distinct().ToArray(); var transactions = hashes .Select(async o => await client.GetTransactionAsync(network, o, cts)) .ToArray(); await Task.WhenAll(transactions).ConfigureAwait(false); return(transactions.Select(t => t.Result).Where(t => t != null).ToDictionary(o => o.Transaction.GetHash())); }
public static bool TryParseFromElectrumWallet(string coldcardExport, BTCPayNetwork network, out DerivationSchemeSettings settings) { settings = null; if (coldcardExport == null) { throw new ArgumentNullException(nameof(coldcardExport)); } if (network == null) { throw new ArgumentNullException(nameof(network)); } var result = new DerivationSchemeSettings(); result.Source = "Electrum/Airgap hardware wallet"; var derivationSchemeParser = new DerivationSchemeParser(network); JObject jobj = null; try { jobj = JObject.Parse(coldcardExport); jobj = (JObject)jobj["keystore"]; } catch { return(TryParseXpub(coldcardExport, derivationSchemeParser, ref result)); } if (!jobj.ContainsKey("xpub") || !TryParseXpub(jobj["xpub"].Value <string>(), derivationSchemeParser, ref result)) { return(false); } if (jobj.ContainsKey("label")) { try { result.Label = jobj["label"].Value <string>(); } catch { return(false); } } if (jobj.ContainsKey("ckcc_xfp")) { try { result.AccountKeySettings[0].RootFingerprint = new HDFingerprint(jobj["ckcc_xfp"].Value <uint>()); } catch { return(false); } } if (jobj.ContainsKey("derivation")) { try { result.AccountKeySettings[0].AccountKeyPath = new KeyPath(jobj["derivation"].Value <string>()); } catch { return(false); } } settings = result; settings.Network = network; return(true); }
public void Add(BTCPayNetwork network) { _Networks.Add(network.CryptoCode, network); }