2026-06-11 10:47:13 +02:00
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
using NBitcoin;
|
|
|
|
|
|
|
|
|
|
namespace PalladiumWallet.Core.Spv;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-06-16 14:40:06 +02:00
|
|
|
/// Script hash for the indexing protocol (blueprint §0/§10): SHA-256 of the
|
|
|
|
|
/// scriptPubKey with bytes reversed, encoded as lowercase hex.
|
2026-06-11 10:47:13 +02:00
|
|
|
/// </summary>
|
|
|
|
|
public static class Scripthash
|
|
|
|
|
{
|
|
|
|
|
public static string FromScript(Script scriptPubKey)
|
|
|
|
|
{
|
|
|
|
|
var hash = SHA256.HashData(scriptPubKey.ToBytes());
|
|
|
|
|
Array.Reverse(hash);
|
|
|
|
|
return Convert.ToHexString(hash).ToLowerInvariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string FromAddress(BitcoinAddress address) =>
|
|
|
|
|
FromScript(address.ScriptPubKey);
|
|
|
|
|
}
|