/// <summary>
        /// Get sign parameter object.
        /// </summary>
        /// <param name="signaturehashType">sighash type</param>
        /// <returns>sign parameter object.</returns>
        public SignParameter GetSignData(SignatureHashType signaturehashType)
        {
            var sig     = data;
            var sigType = sighashType;

            if ((data.Length == Size * 2) && (signaturehashType.SighashType != CfdSighashType.Default))
            {
                using (var handle = new ErrorHandle())
                {
                    var ret = NativeMethods.CfdAddSighashTypeInSchnorrSignature(
                        handle.GetHandle(), data, signaturehashType.GetValue(),
                        signaturehashType.IsSighashAnyoneCanPay,
                        out IntPtr addedSignature);
                    if (ret != CfdErrorCode.Success)
                    {
                        handle.ThrowError(ret);
                    }
                    sig = CCommon.ConvertToString(addedSignature);
                }
                sigType = signaturehashType;
            }

            var signData = new SignParameter(sig);

            signData.SetSignatureHashType(sigType);
            return(signData);
        }
Example #2
0
 /// <summary>
 /// Calculate ec-signature.
 /// </summary>
 /// <param name="sighash">signature hash.</param>
 /// <param name="hasGrindR">use grind-R.</param>
 /// <returns></returns>
 public SignParameter CalculateEcSignature(ByteData sighash, bool hasGrindR)
 {
     if (sighash is null)
     {
         throw new ArgumentNullException(nameof(sighash));
     }
     using (var handle = new ErrorHandle())
     {
         var ret = NativeMethods.CfdCalculateEcSignature(
             handle.GetHandle(), sighash.ToHexString(),
             privkey, privkeyWif, (int)networkType, hasGrindR,
             out IntPtr signatureHex);
         if (ret != CfdErrorCode.Success)
         {
             handle.ThrowError(ret);
         }
         SignParameter     signature   = new SignParameter(CCommon.ConvertToString(signatureHex));
         SignatureHashType sighashType = new SignatureHashType(CfdSighashType.All, false);
         signature.SetDerEncode(sighashType);
         signature.SetRelatedPubkey(GetPubkey());
         return(signature);
     }
 }
Example #3
0
 /// <summary>
 /// decode from DER.
 /// </summary>
 /// <param name="derSignature">DER encoded data</param>
 /// <returns>signature (SignParameter object)</returns>
 public static SignParameter DecodeFromDer(ByteData derSignature)
 {
     if (derSignature is null)
     {
         throw new ArgumentNullException(nameof(derSignature));
     }
     using (var handle = new ErrorHandle())
     {
         var ret = NativeMethods.CfdDecodeSignatureFromDer(
             handle.GetHandle(), derSignature.ToHexString(),
             out IntPtr signature,
             out int signatureHashType,
             out bool _);
         if (ret != CfdErrorCode.Success)
         {
             handle.ThrowError(ret);
         }
         string            signatureStr = CCommon.ConvertToString(signature);
         SignatureHashType sighashType  = new SignatureHashType(signatureHashType);
         SignParameter     signParam    = new SignParameter(signatureStr);
         signParam.SetDerEncode(sighashType);
         return(signParam);
     }
 }