Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions NBitcoin.Tests/Secp256k1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4114,9 +4114,7 @@ public void musig_tweak_vectors()
private MusigPrivNonce ToMusigPrivNonce(string hex)
{
var b = Encoders.Hex.DecodeData(hex);
return new MusigPrivNonce(ECPrivKey.Create(b.AsSpan().Slice(0, 32)),
ECPrivKey.Create(b.AsSpan().Slice(32, 32)),
ECPubKey.Create(b.AsSpan().Slice(64, 33)));
return MusigPrivNonce.Load(b);
}

[Fact]
Expand Down
11 changes: 10 additions & 1 deletion NBitcoin/Secp256k1/Musig/MusigPrivNonce.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MusigPrivNonce : IDisposable
{
readonly static RandomNumberGenerator rand = RandomNumberGenerator.Create();


/// <summary>
/// This function derives a secret nonce that will be required for signing and
/// creates a private nonce whose public part intended to be sent to other signers.
Expand Down Expand Up @@ -175,6 +174,16 @@ internal MusigPrivNonce(ECPrivKey k1, ECPrivKey k2, ECPubKey pk)
this.pk = pk;
}

public static MusigPrivNonce Load(Span<byte> bytes)
{
if(bytes.Length != 97)
throw new FormatException("Invalid private nonce, expected 97 bytes");
var k1 = ECPrivKey.Create(bytes[..32]);
var k2 = ECPrivKey.Create(bytes[32..64]);
var pk = ECPubKey.Create(bytes[64..]);
return new MusigPrivNonce(k1, k2, pk);
}

public void Dispose()
{
k1.Dispose();
Expand Down
Loading