public void ReadWrite(BitcoinStream stream) { AssertNotDiposed(); #if HAS_SPAN Span <byte> tmp = stackalloc byte[KEY_SIZE]; if (!stream.Serializing) { stream.ReadWrite(ref tmp); if (NBitcoinContext.Instance.TryCreateECPrivKey(tmp, out var k) && k is Secp256k1.ECPrivKey) { _ECKey = k; } else { throw new FormatException("Unvalid private key"); } } else { _ECKey.WriteToSpan(tmp); stream.ReadWrite(ref tmp); } #else stream.ReadWrite(ref vch); if (!stream.Serializing) { _ECKey = new ECKey(vch, true); } #endif }
public byte[] ToBytes() { AssertNotDisposed(); #if HAS_SPAN var b = new byte[KEY_SIZE]; _ECKey.WriteToSpan(b); return(b); #else return(vch.ToArray()); #endif }