コード例 #1
0
        public static CetSigs ParseFromTLV(TLVReader reader)
        {
            CetSigs cet = new CetSigs();

            using (var r = reader.StartReadRecord())
            {
                if (r.Type != AdaptorSigsTLVType)
                {
                    throw new FormatException("Invalid TLV type, expected adaptor sigs");
                }
                List <AdaptorSignature> sigs = new List <AdaptorSignature>();
                while (!r.IsEnd)
                {
                    sigs.Add(AdaptorSignature.ParseFromTLV(reader));
                }
                cet.OutcomeSigs = sigs.ToArray();
            }
            Span <byte> buf = stackalloc byte[64];

            reader.ReadBytes(buf);
            if (!ECDSASignature.TryParseFromCompact(buf, out var sig))
            {
                throw new FormatException("Invalid DER signature");
            }
            cet.RefundSig = sig;
            return(cet);
        }
コード例 #2
0
        public static bool TryParse(string str, out AdaptorSignature?result)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }
            var bytes = Encoders.Hex.DecodeData(str);

            if (bytes.Length == 65 + 97 &&
                SecpECDSAAdaptorSignature.TryCreate(bytes.AsSpan().Slice(0, 65), out var sig) &&
                SecpECDSAAdaptorProof.TryCreate(bytes.AsSpan().Slice(65), out var proof) &&
                sig is SecpECDSAAdaptorSignature && proof is SecpECDSAAdaptorProof)
            {
                result = new AdaptorSignature(sig, proof);
                return(true);
            }
            result = null;
            return(false);
        }