Exemplo n.º 1
0
        /// <summary>
        /// Create a single signature derivation strategy from public key
        /// </summary>
        /// <param name="publicKey">The public key of the wallet</param>
        /// <param name="options">Derivation options</param>
        /// <returns></returns>
        public DerivationStrategyBase CreateDirectDerivationStrategy(BitcoinExtPubKey publicKey, DerivationStrategyOptions options = null)
        {
            options = options ?? new DerivationStrategyOptions();
            DerivationStrategyBase strategy = null;

#pragma warning disable CS0618 // Type or member is obsolete
            if (options.ScriptPubKeyType != ScriptPubKeyType.TaprootBIP86)
#pragma warning restore CS0618 // Type or member is obsolete
            {
                strategy = new DirectDerivationStrategy(publicKey, options.ScriptPubKeyType != ScriptPubKeyType.Legacy, options.AdditionalOptions);
                if (options.ScriptPubKeyType == ScriptPubKeyType.Segwit && !_Network.Consensus.SupportSegwit)
                {
                    throw new InvalidOperationException("This crypto currency does not support segwit");
                }

                if (options.ScriptPubKeyType == ScriptPubKeyType.SegwitP2SH)
                {
                    strategy = new P2SHDerivationStrategy(strategy, true);
                }
            }
            else
            {
                if (!_Network.Consensus.SupportTaproot)
                {
                    throw new InvalidOperationException("This crypto currency does not support taproot");
                }
                strategy = new TaprootDerivationStrategy(publicKey, options.AdditionalOptions);
            }
            return(strategy);
        }
Exemplo n.º 2
0
        private DerivationStrategyBase ParseCore(string str)
        {
            bool legacy = false;

            ReadBool(ref str, "legacy", ref legacy);

            bool p2sh = false;

            ReadBool(ref str, "p2sh", ref p2sh);

            bool keepOrder = false;

            ReadBool(ref str, "keeporder", ref keepOrder);

            var match = MultiSigRegex.Match(str);

            if (match.Success)
            {
                var sigCount = int.Parse(match.Groups[1].Value);
                var pubKeys  = match.Groups
                               .OfType <Group>()
                               .Skip(2)
                               .SelectMany(g => g.Captures.OfType <Capture>())
                               .Select(g => new BitcoinExtPubKey(g.Value.Substring(1), Network))
                               .ToArray();
                DerivationStrategyBase derivationStrategy = new MultisigDerivationStrategy(sigCount, pubKeys)
                {
                    LexicographicOrder = !keepOrder
                };
                if (legacy)
                {
                    return(new P2SHDerivationStrategy(derivationStrategy));
                }

                derivationStrategy = new P2WSHDerivationStrategy(derivationStrategy);
                if (p2sh)
                {
                    derivationStrategy = new P2SHDerivationStrategy(derivationStrategy);
                }
                return(derivationStrategy);
            }
            else
            {
                var key = _Network.Parse <BitcoinExtPubKey>(str);
                DerivationStrategyBase strategy = new DirectDerivationStrategy(key)
                {
                    Segwit = !legacy
                };
                if (p2sh && !legacy)
                {
                    strategy = new P2SHDerivationStrategy(strategy);
                }
                return(strategy);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a single signature derivation strategy from public key
        /// </summary>
        /// <param name="publicKey">The public key of the wallet</param>
        /// <param name="options">Derivation options</param>
        /// <returns></returns>
        public DerivationStrategyBase CreateDirectDerivationStrategy(BitcoinExtPubKey publicKey, DerivationStrategyOptions options = null)
        {
            options = options ?? new DerivationStrategyOptions();
            DerivationStrategyBase strategy = new DirectDerivationStrategy(publicKey)
            {
                Segwit = !options.Legacy
            };

            if (options.P2SH && !options.Legacy)
            {
                strategy = new P2SHDerivationStrategy(strategy, true);
            }
            return(strategy);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a single signature derivation strategy from public key
        /// </summary>
        /// <param name="publicKey">The public key of the wallet</param>
        /// <param name="options">Derivation options</param>
        /// <returns></returns>
        public DerivationStrategyBase CreateDirectDerivationStrategy(BitcoinExtPubKey publicKey, DerivationStrategyOptions options = null)
        {
            options = options ?? new DerivationStrategyOptions();
            DerivationStrategyBase strategy = new DirectDerivationStrategy(publicKey, options.ScriptPubKeyType != ScriptPubKeyType.Legacy, options.AdditionalOptions);

            if (options.ScriptPubKeyType != ScriptPubKeyType.Legacy && !_Network.Consensus.SupportSegwit)
            {
                throw new InvalidOperationException("This crypto currency does not support segwit");
            }

            if (options.ScriptPubKeyType == ScriptPubKeyType.SegwitP2SH)
            {
                strategy = new P2SHDerivationStrategy(strategy, true);
            }
            return(strategy);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Create a single signature derivation strategy from public key
        /// </summary>
        /// <param name="publicKey">The public key of the wallet</param>
        /// <param name="options">Derivation options</param>
        /// <returns></returns>
        public DerivationStrategyBase CreateDirectDerivationStrategy(BitcoinExtPubKey publicKey, DerivationStrategyOptions options = null)
        {
            options = options ?? new DerivationStrategyOptions();
            DerivationStrategyBase strategy = new DirectDerivationStrategy(publicKey)
            {
                Segwit = !options.Legacy
            };

            if (!options.Legacy && !_Network.Consensus.SupportSegwit)
            {
                throw new InvalidOperationException("This crypto currency does not support segwit");
            }

            if (options.P2SH && !options.Legacy)
            {
                strategy = new P2SHDerivationStrategy(strategy, true);
            }
            return(strategy);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Create a multisig derivation strategy from public keys
        /// </summary>
        /// <param name="pubKeys">The public keys belonging to the multi sig</param>
        /// <param name="sigCount">The number of required signature</param>
        /// <param name="options">Derivation options</param>
        /// <returns>A multisig derivation strategy</returns>
        public DerivationStrategyBase CreateMultiSigDerivationStrategy(BitcoinExtPubKey[] pubKeys, int sigCount, DerivationStrategyOptions options = null)
        {
            options = options ?? new DerivationStrategyOptions();
            DerivationStrategyBase derivationStrategy = new MultisigDerivationStrategy(sigCount, pubKeys.ToArray(), options.Legacy)
            {
                LexicographicOrder = !options.KeepOrder
            };

            if (options.Legacy)
            {
                return(new P2SHDerivationStrategy(derivationStrategy, false));
            }

            derivationStrategy = new P2WSHDerivationStrategy(derivationStrategy);
            if (options.P2SH)
            {
                derivationStrategy = new P2SHDerivationStrategy(derivationStrategy, true);
            }
            return(derivationStrategy);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Create a multisig derivation strategy from public keys
        /// </summary>
        /// <param name="pubKeys">The public keys belonging to the multi sig</param>
        /// <param name="sigCount">The number of required signature</param>
        /// <param name="options">Derivation options</param>
        /// <returns>A multisig derivation strategy</returns>
        public DerivationStrategyBase CreateMultiSigDerivationStrategy(BitcoinExtPubKey[] pubKeys, int sigCount, DerivationStrategyOptions options = null)
        {
            options = options ?? new DerivationStrategyOptions();
            DerivationStrategyBase derivationStrategy = new MultisigDerivationStrategy(sigCount, pubKeys.ToArray(), options.ScriptPubKeyType == ScriptPubKeyType.Legacy, !options.KeepOrder, options.AdditionalOptions);

            if (options.ScriptPubKeyType == ScriptPubKeyType.Legacy)
            {
                return(new P2SHDerivationStrategy(derivationStrategy, false));
            }

            if (!_Network.Consensus.SupportSegwit)
            {
                throw new InvalidOperationException("This crypto currency does not support segwit");
            }
            derivationStrategy = new P2WSHDerivationStrategy(derivationStrategy);
            if (options.ScriptPubKeyType == ScriptPubKeyType.SegwitP2SH)
            {
                derivationStrategy = new P2SHDerivationStrategy(derivationStrategy, true);
            }
            return(derivationStrategy);
        }