Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
		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;
		}
Ejemplo n.º 3
0
		public void Insert(uint256 value)
		{
			if (value == null) throw new ArgumentNullException("value");
			Insert(value.ToBytes());
		}
Ejemplo n.º 4
0
		public Target(uint256 target)
		{
			_Target = new BigInteger(target.ToBytes());
			_Target = new Target(this.ToCompact())._Target;
		}
Ejemplo n.º 5
0
		public WitScriptId(uint256 value)
			: base(value.ToBytes())
		{

		}
Ejemplo n.º 6
0
		public bool Contains(uint256 hash)
		{
			if (hash == null) throw new ArgumentNullException("hash");
			return Contains(hash.ToBytes());
		}
Ejemplo n.º 7
0
 private static uint256 Hash(uint256 a, uint256 b)
 {
     return Hashes.Hash256(a.ToBytes().Concat(b.ToBytes()).ToArray());
 }
Ejemplo n.º 8
0
 public Target(uint256 target)
 {
     _Target = new BigInteger(target.ToBytes(false));
     _Target = new Target(this.ToCompact())._Target;
 }
Ejemplo n.º 9
0
 public bool Contains(uint256 hash)
 {
     return Contains(hash.ToBytes());
 }
Ejemplo n.º 10
0
 public void Insert(uint256 value)
 {
     Insert(value.ToBytes());
 }
Ejemplo n.º 11
0
 private static uint256 Hash(uint256 a, uint256 b)
 {
     return(Hashes.Hash256(a.ToBytes().Concat(b.ToBytes()).ToArray()));
 }