Skip to content

Commit

Permalink
Fix various warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Sep 5, 2024
1 parent 6107cba commit e6a6492
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions NBitcoin.Tests/BIP322Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ await Assert.ThrowsAsync<InvalidOperationException>(async () =>
await BIP322.SignEncoded(p2shAddress, message2of3, BIP322.SignatureType.Full, redeem, null,k2, k3);
var p2sh_signature2of3_k1_k3 =
await BIP322.SignEncoded(p2shAddress, message2of3, BIP322.SignatureType.Full, redeem, null,k1, k3);
Assert.ThrowsAsync<InvalidOperationException>(async () =>
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await BIP322.SignEncoded(p2shAddress, message2of3, BIP322.SignatureType.Full, redeem, null,k1);
});
Expand All @@ -105,7 +105,7 @@ await Assert.ThrowsAsync<InvalidOperationException>(async () =>
await BIP322.SignEncoded(p2wshAddress, message2of3, BIP322.SignatureType.Simple, redeem, null,k2, k3);
var p2wsh_signature2of3_k1_k3 =
await BIP322.SignEncoded(p2wshAddress, message2of3, BIP322.SignatureType.Simple, redeem, null,k1, k3);
Assert.ThrowsAsync<InvalidOperationException>(async () =>
await Assert.ThrowsAsync<InvalidOperationException>(async () =>
{
await BIP322.SignEncoded(p2wshAddress, message2of3, BIP322.SignatureType.Simple, redeem, null,k1);
});
Expand Down Expand Up @@ -141,8 +141,8 @@ public async Task CanVerifyBIP322Message()
Assert.Equal("b79d196740ad5217771c1098fc4a4b51e0535c32236c71f1ea4d61a2d603352b",
helloWorldToSpendTx.GetHash().ToString());

var emptyStringToSignTx = BIP322.CreateToiSignTransaction(Network.Main, emptyStringToSpendTx.GetHash());
var helloWorldToSignTx = BIP322.CreateToiSignTransaction(Network.Main, helloWorldToSpendTx.GetHash());
var emptyStringToSignTx = BIP322.CreateToSignTransaction(Network.Main, emptyStringToSpendTx.GetHash());
var helloWorldToSignTx = BIP322.CreateToSignTransaction(Network.Main, helloWorldToSpendTx.GetHash());

Assert.Equal("1e9654e951a5ba44c8604c4de6c67fd78a27e81dcadcfe1edf638ba3aaebaed6",
emptyStringToSignTx.GetHash().ToString());
Expand Down
14 changes: 7 additions & 7 deletions NBitcoin/BIP322.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static Transaction CreateToSpendTransaction(Network network, uint256 mess
return tx;
}

public static Transaction CreateToiSignTransaction(Network network, uint256 toSpendTxId,
public static Transaction CreateToSignTransaction(Network network, uint256 toSpendTxId,
WitScript? messageSignature = null,
uint version = 0, uint lockTime = 0, uint sequence = 0, ScriptCoin[]? additionalInputs = null)
{
Expand All @@ -94,11 +94,11 @@ public static Transaction CreateToiSignTransaction(Network network, uint256 toSp
return tx;
}
public static async Task<string> SignEncoded(BitcoinAddress address, string message, SignatureType type,
Script? redeemScript = null, ICoin[] additionalCoins = null, params Key[] keys) => Encoders.Base64.EncodeData(await Sign(address, Encoding.UTF8.GetBytes(message), type, keys, redeemScript, additionalCoins));
Script? redeemScript = null, ICoin[]? additionalCoins = null, params Key[] keys) => Encoders.Base64.EncodeData(await Sign(address, Encoding.UTF8.GetBytes(message), type, keys, redeemScript, additionalCoins));
public static async Task<string> SignEncoded(BitcoinAddress address, string message, SignatureType type,
params Key[] keys) => Encoders.Base64.EncodeData(await Sign(address, Encoding.UTF8.GetBytes(message), type, keys));
public static async Task<byte[]> Sign(BitcoinAddress address, byte[] message, SignatureType type,
Key[] keys, Script? redeemScript = null, ICoin[] additionalCoins = null)
Key[] keys, Script? redeemScript = null, ICoin[]? additionalCoins = null)
{
// if(address.ScriptPubKey.IsScriptType(ScriptType.P2SH) && type == SignatureType.Simple)
// throw new InvalidOperationException("Simple signatures are not supported for P2SH scripts.");
Expand Down Expand Up @@ -134,7 +134,7 @@ public static async Task<byte[]> Sign(BitcoinAddress address, byte[] message, Si
}

var toSpendTx = CreateToSpendTransaction(network, new uint256(messageHash), address.ScriptPubKey);
var toSignTx = CreateToiSignTransaction(network, toSpendTx.GetHash(), WitScript.Empty);
var toSignTx = CreateToSignTransaction(network, toSpendTx.GetHash(), WitScript.Empty);

Func<OutPoint[], Task<TxOut[]>>? proofOfFundsLookup = null;
if (additionalCoins is not null)
Expand Down Expand Up @@ -196,7 +196,7 @@ public static async Task<bool> Verify(byte[] message, BitcoinAddress address, by

var toSpend = CreateToSpendTransaction(address.Network, CreateMessageHash(message, MessageType.BIP322),
address.ScriptPubKey);
var toSign = CreateToiSignTransaction(address.Network, toSpend.GetHash(), script);
var toSign = CreateToSignTransaction(address.Network, toSpend.GetHash(), script);
ScriptEvaluationContext evalContext = new ScriptEvaluationContext()
{
ScriptVerify = ScriptVerify.Const_ScriptCode
Expand All @@ -221,7 +221,7 @@ public static async Task<bool> Verify(byte[] message, BitcoinAddress address, by
TransactionChecker checker = address.ScriptPubKey.IsScriptType(ScriptType.Taproot) ? new TransactionChecker(toSign, 0, toSpend.Outputs[0], new TaprootReadyPrecomputedTransactionData(toSign,toSpend.Outputs.ToArray())) : new TransactionChecker(toSign, 0, toSpend.Outputs[0]);
return evalContext.VerifyScript(toSign.Inputs[0].ScriptSig , script, address.ScriptPubKey, checker);
}
catch (Exception e)
catch (Exception)
{
Transaction toSign;
try
Expand All @@ -247,7 +247,7 @@ public static async Task<bool> Verify(byte[] message, BitcoinAddress address, by

return ECDSASignature.TryParseFromCompact(sig.Signature, out var ecSig) && k.Verify(hash, ecSig);
}
catch (Exception exception)
catch
{
return false;
}
Expand Down

0 comments on commit e6a6492

Please sign in to comment.