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"); }
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(); }
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; }
public static StealthMetadata TryParse(Script metadata) { StealthMetadata result = new StealthMetadata(); try { if(!Fill(result, metadata)) return null; } catch(Exception) { return null; } return result; }
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; }
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; }
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); }
public StealthPayment(Script scriptPubKey, Script redeem, StealthMetadata metadata) { Metadata = metadata; ScriptPubKey = scriptPubKey; Redeem = redeem; SetStealthKeys(); }
public bool Match(StealthMetadata metadata) { if(metadata == null) throw new ArgumentNullException("metadata"); return Match(metadata.BitField); }
public bool Match(StealthMetadata metadata) { return(Match(metadata.BitField)); }