Exemplo n.º 1
0
        public void ReadWrite(BitcoinStream stream)
        {
#if HAS_SPAN
            if (stream.Serializing)
            {
                Span <byte> tmp = stackalloc byte[65];
                _ECKey.WriteToSpan(compressed, tmp, out var l);
                tmp = tmp.Slice(0, l);
                stream.ReadWrite(ref tmp);
            }
            else
            {
                Span <byte> tmp = stackalloc byte[compressed ? 33 : 65];
                stream.ReadWrite(ref tmp);
                if (NBitcoinContext.Instance.TryCreatePubKey(tmp, out var p) && p is Secp256k1.ECPubKey)
                {
                    _ECKey = p;
                }
                else
                {
                    throw new FormatException("Deserializing invalid pubkey");
                }
            }
#else
            stream.ReadWrite(ref vch);
            if (!stream.Serializing)
            {
                _ECKey = new ECKey(vch, false);
            }
#endif
        }
Exemplo n.º 2
0
 public void ToBytes(Span <byte> output, out int length)
 {
     _ECKey.WriteToSpan(compressed, output, out length);
 }