From 43d248f046cfd3852150dfb9aa7537d2ca20c642 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 5 Feb 2021 11:11:47 +0800 Subject: [PATCH 1/2] Key: add helper method GetSeedBytes --- NBitcoin/Key.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/NBitcoin/Key.cs b/NBitcoin/Key.cs index d1e6553e3f..bd85683702 100644 --- a/NBitcoin/Key.cs +++ b/NBitcoin/Key.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using NBitcoin.DataEncoders; +using System.IO; #if !HAS_SPAN using NBitcoin.BouncyCastle.Math; #endif @@ -407,6 +408,18 @@ public BitcoinSecret GetWif(Network network) return new BitcoinSecret(this, network); } + public byte[] GetSeedBytes() + { + AssertNotDiposed(); + byte[] bytes = Enumerable.Repeat((byte)0x00, KEY_SIZE).ToArray(); + using (var bytesStream = new MemoryStream(bytes)) + { + var stream = new BitcoinStream(bytesStream, true); + ReadWrite(stream); + } + return bytes; + } + public BitcoinEncryptedSecretNoEC GetEncryptedBitcoinSecret(string password, Network network) { AssertNotDiposed(); From 5eb755e5d74377dc5b84e9189b3c6fc83134cfaa Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 5 Feb 2021 11:18:27 +0800 Subject: [PATCH 2/2] Key: reuse KEY_SIZE Similar commit as https://github.com/MetacoSA/NBitcoin/commit/ce7598f5c1bad8c49f8f71a7b5399a2fb01616bd --- NBitcoin/Key.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NBitcoin/Key.cs b/NBitcoin/Key.cs index bd85683702..945ff22da3 100644 --- a/NBitcoin/Key.cs +++ b/NBitcoin/Key.cs @@ -155,7 +155,7 @@ public SchnorrSignature SignSchnorr(uint256 hash) { AssertNotDiposed(); #if HAS_SPAN - Span h = stackalloc byte[32]; + Span h = stackalloc byte[KEY_SIZE]; hash.ToBytes(h); return new SchnorrSignature(_ECKey.SignSchnorr(h)); #else