public TaprootSignature SignTaprootKeySpend(uint256 hash, uint256?merkleRoot, uint256?aux, TaprootSigHash sigHash) { if (hash == null) { throw new ArgumentNullException(nameof(hash)); } AssertNotDisposed(); var eckey = _ECKey; if (PubKey.Parity) { eckey = new Secp256k1.ECPrivKey(_ECKey.sec.Negate(), _ECKey.ctx, true); } Span <byte> buf = stackalloc byte[32]; TaprootFullPubKey.ComputeTapTweak(PubKey.TaprootInternalKey, merkleRoot, buf); eckey = eckey.TweakAdd(buf); hash.ToBytes(buf); var sig = aux?.ToBytes() is byte[] auxbytes?eckey.SignBIP340(buf, auxbytes) : eckey.SignBIP340(buf); return(new TaprootSignature(new SchnorrSignature(sig), sigHash)); }
private static BitArray CalculateChecksum(uint256 blockId, int txIndex, int txOutIndex, Script scriptPubKey, int bitCount) { //All in little endian var hashed = blockId .ToBytes(true) .Concat(Utils.ToBytes((uint)txIndex, true)) .Concat(Utils.ToBytes((uint)txOutIndex, true)) .Concat(scriptPubKey.ToBytes(true)) .ToArray(); var hash = Hashes.Hash256(hashed); var bytes = hash.ToBytes(true); BitArray result = new BitArray(bitCount); for(int i = 0 ; i < bitCount ; i++) { int byteIndex = i / 8; int bitIndex = i % 8; result.Set(i, ((bytes[byteIndex] >> bitIndex) & 1) == 1); } return result; }
public void Insert(uint256 value) { if (value == null) throw new ArgumentNullException("value"); Insert(value.ToBytes()); }
public Target(uint256 target) { _Target = new BigInteger(target.ToBytes()); _Target = new Target(this.ToCompact())._Target; }
public WitScriptId(uint256 value) : base(value.ToBytes()) { }
public bool Contains(uint256 hash) { if (hash == null) throw new ArgumentNullException("hash"); return Contains(hash.ToBytes()); }
private static uint256 Hash(uint256 a, uint256 b) { return Hashes.Hash256(a.ToBytes().Concat(b.ToBytes()).ToArray()); }
public Target(uint256 target) { _Target = new BigInteger(target.ToBytes(false)); _Target = new Target(this.ToCompact())._Target; }
public bool Contains(uint256 hash) { return Contains(hash.ToBytes()); }
public void Insert(uint256 value) { Insert(value.ToBytes()); }
private static uint256 Hash(uint256 a, uint256 b) { return(Hashes.Hash256(a.ToBytes().Concat(b.ToBytes()).ToArray())); }