コード例 #1
0
        public void TrySign(IHDScriptPubKey accountHDScriptPubKey, IHDKey accountKey, RootedKeyPath accountKeyPath, SigHash sigHash = SigHash.All)
        {
            if (accountKey == null)
            {
                throw new ArgumentNullException(nameof(accountKey));
            }
            if (accountHDScriptPubKey == null)
            {
                throw new ArgumentNullException(nameof(accountHDScriptPubKey));
            }
            var cache = accountKey.AsHDKeyCache();

            accountHDScriptPubKey = accountHDScriptPubKey.AsHDKeyCache();
            foreach (var hdk in this.HDKeysFor(accountHDScriptPubKey, cache, accountKeyPath))
            {
                if (((HDKeyCache)cache.Derive(hdk.AddressKeyPath)).Inner is ISecret k)
                {
                    Sign(k.PrivateKey, sigHash);
                }
                else
                {
                    throw new ArgumentException(paramName: nameof(accountKey), message: "This should be a private key");
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Filter the keys which contains the <paramref name="accountKey"/> and <paramref name="accountKeyPath"/> in the HDKeys and whose input/output
 /// the same scriptPubKeys as <paramref name="accountHDScriptPubKey"/>.
 /// </summary>
 /// <param name="accountHDScriptPubKey">The hdScriptPubKey used to generate addresses</param>
 /// <param name="accountKey">The account key that will be used to sign (ie. 49'/0'/0')</param>
 /// <param name="accountKeyPath">The account key path</param>
 /// <returns>HD Keys matching master root key</returns>
 public IEnumerable <PSBTHDKeyMatch> HDKeysFor(IHDScriptPubKey accountHDScriptPubKey, IHDKey accountKey, RootedKeyPath accountKeyPath = null)
 {
     if (accountKey == null)
     {
         throw new ArgumentNullException(nameof(accountKey));
     }
     if (accountHDScriptPubKey == null)
     {
         throw new ArgumentNullException(nameof(accountHDScriptPubKey));
     }
     accountHDScriptPubKey = accountHDScriptPubKey.AsHDKeyCache();
     accountKey            = accountKey.AsHDKeyCache();
     return(Inputs.HDKeysFor(accountHDScriptPubKey, accountKey, accountKeyPath).OfType <PSBTHDKeyMatch>().Concat(Outputs.HDKeysFor(accountHDScriptPubKey, accountKey, accountKeyPath)));
 }
コード例 #3
0
        internal IEnumerable <PSBTHDKeyMatch <T> > GetHDKeys(IHDScriptPubKey hdScriptPubKey, IHDKey accountKey, RootedKeyPath accountKeyPath = null)
        {
            if (accountKey == null)
            {
                throw new ArgumentNullException(nameof(accountKey));
            }
            accountKey     = accountKey.AsHDKeyCache();
            hdScriptPubKey = hdScriptPubKey?.AsHDKeyCache();
            var accountFingerprint = accountKey.GetPublicKey().GetHDFingerPrint();

            foreach (var c in this)
            {
                foreach (var match in c.HDKeysFor(hdScriptPubKey, accountKey, accountKeyPath, accountFingerprint))
                {
                    yield return((PSBTHDKeyMatch <T>)match);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Sign all inputs which derive addresses from <paramref name="accountHDScriptPubKey"/> and that need to be signed by <paramref name="accountKey"/>.
        /// </summary>
        /// <param name="accountHDScriptPubKey">The address generator</param>
        /// <param name="accountKey">The account key with which to sign</param>
        /// <param name="accountKeyPath">The account key path (eg. [masterFP]/49'/0'/0')</param>
        /// <param name="sigHash">The SigHash</param>
        /// <returns>This PSBT</returns>
        public PSBT SignAll(IHDScriptPubKey accountHDScriptPubKey, IHDKey accountKey, RootedKeyPath accountKeyPath, SigHash sigHash = SigHash.All)
        {
            if (accountKey == null)
            {
                throw new ArgumentNullException(nameof(accountKey));
            }
            if (accountHDScriptPubKey == null)
            {
                throw new ArgumentNullException(nameof(accountHDScriptPubKey));
            }
            accountHDScriptPubKey = accountHDScriptPubKey.AsHDKeyCache();
            accountKey            = accountKey.AsHDKeyCache();
            Money total = Money.Zero;

            foreach (var o in Inputs.CoinsFor(accountHDScriptPubKey, accountKey, accountKeyPath))
            {
                o.TrySign(accountHDScriptPubKey, accountKey, accountKeyPath, sigHash);
            }
            return(this);
        }