Exemplo n.º 1
0
		public static StealthMetadata CreateMetadata(Key ephemKey, BitField bitField = null)
		{
			for(uint nonce = 0 ; nonce < uint.MaxValue ; nonce++)
			{
				var metadata = new StealthMetadata(ephemKey, nonce);
				if(bitField == null || bitField.Match(metadata.BitField))
					return metadata;
			}
			throw new ArgumentException("No nonce can satisfy the given bitfield, use another ephemKey");
		}
Exemplo n.º 2
0
		public StealthPayment(BitcoinStealthAddress address, Key ephemKey, StealthMetadata metadata)
		{
			Metadata = metadata;
			ScriptPubKey = CreatePaymentScript(address.SignatureCount, address.SpendPubKeys, ephemKey, address.ScanPubKey);

			if(address.SignatureCount > 1)
			{
				Redeem = ScriptPubKey;
				ScriptPubKey = ScriptPubKey.Hash.ScriptPubKey;
			}
			SetStealthKeys();
		}
Exemplo n.º 3
0
		private static bool Fill(StealthMetadata output, Script metadata)
		{
			var datas = _Template.ExtractScriptPubKeyParameters(metadata);
			if(datas == null)
				return false;
			foreach(var data in datas)
			{
				if(Fill(output, metadata, data))
					return true;
			}
			return false;
		}
Exemplo n.º 4
0
		public static StealthMetadata TryParse(Script metadata)
		{
			StealthMetadata result = new StealthMetadata();
			try
			{
				if(!Fill(result, metadata))
					return null;
			}
			catch(Exception)
			{
				return null;
			}
			return result;
		}
Exemplo n.º 5
0
		private static bool Fill(StealthMetadata output, Script metadata, byte[] data)
		{
			if(data == null || data.Length != 1 + 4 + 33)
				return false;
			MemoryStream ms = new MemoryStream(data);
			output.Version = ms.ReadByte();
			if(output.Version != 6)
				return false;
			output.Nonce = ms.ReadBytes(4);
			output.EphemKey = new PubKey(ms.ReadBytes(33));
			output.Script = metadata;
			output.Hash = Hashes.Hash256(data);
			var msprefix = new MemoryStream(output.Hash.ToBytes(false));
			output.BitField = Utils.ToUInt32(msprefix.ReadBytes(4), true);
			return true;
		}
Exemplo n.º 6
0
		private static bool Fill(StealthMetadata output, Script metadata)
		{
			var ops = metadata.ToOps().ToArray();
			if(ops.Length != 2 || ops[0].Code != OpcodeType.OP_RETURN)
				return false;
			var data = ops[1].PushData;
			if(data == null || data.Length != 1 + 4 + 33)
				return false;
			MemoryStream ms = new MemoryStream(data);
			output.Version = ms.ReadByte();
			if(output.Version != 6)
				return false;
			output.Nonce = ms.ReadBytes(4);
			output.EphemKey = new PubKey(ms.ReadBytes(33));
			output.Script = metadata;
			output.Hash = Hashes.Hash256(data);
			var msprefix = new MemoryStream(output.Hash.ToBytes(false));
			output.BitField = Utils.ToUInt32(msprefix.ReadBytes(4), true);
			return true;
		}
Exemplo n.º 7
0
        private static bool Fill(StealthMetadata output, Script metadata, byte[] data)
        {
            if (data == null || data.Length != 1 + 4 + 33)
            {
                return(false);
            }
            MemoryStream ms = new MemoryStream(data);

            output.Version = ms.ReadByte();
            if (output.Version != 6)
            {
                return(false);
            }
            output.Nonce    = ms.ReadBytes(4);
            output.EphemKey = new PubKey(ms.ReadBytes(33));
            output.Script   = metadata;
            output.Hash     = Hashes.Hash256(data);
            var msprefix = new MemoryStream(output.Hash.ToBytes(false));

            output.BitField = Utils.ToUInt32(msprefix.ReadBytes(4), true);
            return(true);
        }
Exemplo n.º 8
0
		public StealthPayment(Script scriptPubKey, Script redeem, StealthMetadata metadata)
		{
			Metadata = metadata;
			ScriptPubKey = scriptPubKey;
			Redeem = redeem;
			SetStealthKeys();
		}
Exemplo n.º 9
0
		public bool Match(StealthMetadata metadata)
		{
			if(metadata == null)
				throw new ArgumentNullException("metadata");
			return Match(metadata.BitField);
		}
Exemplo n.º 10
0
 public bool Match(StealthMetadata metadata)
 {
     return(Match(metadata.BitField));
 }