Пример #1
0
        public async Task <KeyPath> GetKeyPath(BTCPayNetwork network, DirectDerivationStrategy directStrategy)
        {
            List <KeyPath> derivations = new List <KeyPath>();

            if (network.NBitcoinNetwork.Consensus.SupportSegwit)
            {
                derivations.Add(new KeyPath("49'"));
            }
            derivations.Add(new KeyPath("44'"));
            KeyPath foundKeyPath = null;

            foreach (var account in
                     derivations
                     .Select(purpose => purpose.Derive(network.CoinType))
                     .SelectMany(coinType => Enumerable.Range(0, 5).Select(i => coinType.Derive(i, true))))
            {
                try
                {
                    var extpubkey = await GetExtPubKey(_Ledger, network, account, true);

                    if (directStrategy.Root.PubKey == extpubkey.ExtPubKey.PubKey)
                    {
                        foundKeyPath = account;
                        break;
                    }
                }
                catch (FormatException)
                {
                    throw new Exception($"The opened ledger app does not support {network.NBitcoinNetwork.Name}");
                }
            }

            return(foundKeyPath);
        }
Пример #2
0
 private static KeyPathInformation CreateKeyPathInformation(DirectDerivationStrategy pubKey, KeyPath keyPath)
 {
     return(new KeyPathInformation()
     {
         Feature = DerivationFeature.Deposit, DerivationStrategy = pubKey, KeyPath = keyPath
     });
 }
Пример #3
0
 public async Task <bool> SupportDerivation(BTCPayNetwork network, DirectDerivationStrategy strategy)
 {
     if (network == null)
     {
         throw new ArgumentNullException(nameof(Network));
     }
     if (strategy == null)
     {
         throw new ArgumentNullException(nameof(strategy));
     }
     return(await GetKeyPath(_Ledger, network, strategy) != null);
 }
Пример #4
0
        public BtcWallet(ILogger logger, WalletContext db, bool mainnet, Uri nbxplorerAddress, bool useLegacyAddrs = false) : base(logger, db, mainnet)
        {
            this.nbxplorerAddress = nbxplorerAddress;

            // create extended key
            var network = GetNetwork();

            key = new BitcoinExtKey(new ExtKey(seedHex), network);
            var strpubkey = $"{key.Neuter().ToString()}";

            if (useLegacyAddrs)
            {
                strpubkey = strpubkey + "-[legacy]";
            }
            pubkey = (DirectDerivationStrategy) new DerivationStrategyFactory(network).Parse(strpubkey);
        }
Пример #5
0
 private static DirectDerivationStrategy CreateDerivationStrategy(ExtPubKey pubKey = null)
 {
     pubKey = pubKey ?? new ExtKey().Neuter();
     return((DirectDerivationStrategy) new DerivationStrategyFactory(Network.RegTest).Parse($"{pubKey.ToString(Network.RegTest)}-[legacy]"));
 }
 public async Task <Transaction> SendToAddress(DirectDerivationStrategy strategy,
                                               ReceivedCoin[] coins, BTCPayNetwork network,
                                               (IDestination destination, Money amount, bool substractFees)[] send,
        private static async Task <KeyPath> GetKeyPath(LedgerClient ledger, BTCPayNetwork network, DirectDerivationStrategy directStrategy)
        {
            KeyPath foundKeyPath = null;

            foreach (var account in
                     new[] { new KeyPath("49'"), new KeyPath("44'") }
                     .Select(purpose => purpose.Derive(network.CoinType))
                     .SelectMany(coinType => Enumerable.Range(0, 5).Select(i => coinType.Derive(i, true))))
            {
                try
                {
                    var extpubkey = await GetExtPubKey(ledger, network, account, true);

                    if (directStrategy.Root.PubKey == extpubkey.ExtPubKey.PubKey)
                    {
                        foundKeyPath = account;
                        break;
                    }
                }
                catch (FormatException)
                {
                    throw new Exception($"The opened ledger app does not support {network.NBitcoinNetwork.Name}");
                }
            }

            return(foundKeyPath);
        }
        public async Task <bool> CanSign(BTCPayNetwork network, DirectDerivationStrategy strategy, KeyPath keyPath, CancellationToken cancellation)
        {
            var hwKey = await GetExtPubKey(Ledger, network, keyPath, true, cancellation);

            return(hwKey.ExtPubKey.PubKey == strategy.Root.PubKey);
        }