コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #6
0
 public LineStrategy(DirectDerivationStrategy up, ExtPubKey root, bool change)
 {
     this.up        = up;
     Path           = new KeyPath(change ? "1" : "0");
     rootDerivation = root.Derive(Path);
 }