Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Key: add helper method GetSeedBytes #969

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion NBitcoin/Key.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Text;
using NBitcoin.DataEncoders;
using System.IO;
#if !HAS_SPAN
using NBitcoin.BouncyCastle.Math;
#endif
Expand Down Expand Up @@ -154,7 +155,7 @@ public SchnorrSignature SignSchnorr(uint256 hash)
{
AssertNotDiposed();
#if HAS_SPAN
Span<byte> h = stackalloc byte[32];
Span<byte> h = stackalloc byte[KEY_SIZE];
hash.ToBytes(h);
return new SchnorrSignature(_ECKey.SignSchnorr(h));
#else
Expand Down Expand Up @@ -407,6 +408,18 @@ public BitcoinSecret GetWif(Network network)
return new BitcoinSecret(this, network);
}

public byte[] GetSeedBytes()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call it ToBytes and follow how I implemented it in PubKey.
Your version is super inefficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sure

{
AssertNotDiposed();
byte[] bytes = Enumerable.Repeat((byte)0x00, KEY_SIZE).ToArray();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new byte[32] is clearly overrated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops! didn't realize that the bytes would be overriden later anyway, was just monkey-translating F# code to C# code from somewhere else

using (var bytesStream = new MemoryStream(bytes))
{
var stream = new BitcoinStream(bytesStream, true);
ReadWrite(stream);
}
return bytes;
}

public BitcoinEncryptedSecretNoEC GetEncryptedBitcoinSecret(string password, Network network)
{
AssertNotDiposed();
Expand Down