public bool IsFrom(PubKey pubKey) { var template = new PayToPubkeyHashTemplate(); var result = template.ExtractScriptSigParameters(ScriptSig); return(result != null && result.PublicKey == pubKey); }
public PubKey GetSourcePubKey() { var template = new PayToPubkeyHashTemplate(); var result = template.ExtractScriptSigParameters(this); return(result == null ? null : result.PublicKey); }
public KeyId GetDestination() { var template = FindTemplate(); var payToPubKeyHash = template as PayToPubkeyHashTemplate; if (payToPubKeyHash != null) { return(payToPubKeyHash.ExtractScriptPubKeyParameters(this)); } var payToPubKey = template as PayToPubkeyTemplate; if (payToPubKey != null) { var result = new PayToPubkeyHashTemplate().ExtractScriptPubKeyParameters(this); if (result == null) { var pub = new PayToPubkeyTemplate().ExtractScriptPubKeyParameters(this); if (pub != null) { return(pub.ID); } } } return(null); }
public BitcoinScriptAddress GetScriptAddress() { if (this is BitcoinScriptAddress) { return((BitcoinScriptAddress)this); } var redeem = new PayToPubkeyHashTemplate().GenerateScriptPubKey(this); return(new BitcoinScriptAddress(redeem.ID, Network)); }
public StealthPayment(int sigCount, PubKey[] spendPubKeys, Key privateKey, PubKey publicKey, StealthMetadata metadata) { Metadata = metadata; if(sigCount == 1 && spendPubKeys.Length == 1) { var template = new PayToPubkeyHashTemplate(); SpendableScript = template.GenerateScriptPubKey(spendPubKeys[0].Uncover(privateKey, publicKey).ID); } else { var template = new PayToMultiSigTemplate(); SpendableScript = template.GenerateScriptPubKey(sigCount, spendPubKeys.Select(p => p.Uncover(privateKey, publicKey)).ToArray()); } ParseSpendable(); }
public StealthPayment(int sigCount, PubKey[] spendPubKeys, Key privateKey, PubKey publicKey, StealthMetadata metadata) { Metadata = metadata; if (sigCount == 1 && spendPubKeys.Length == 1) { var template = new PayToPubkeyHashTemplate(); SpendableScript = template.GenerateScriptPubKey(spendPubKeys[0].Uncover(privateKey, publicKey).ID); } else { var template = new PayToMultiSigTemplate(); SpendableScript = template.GenerateScriptPubKey(sigCount, spendPubKeys.Select(p => p.Uncover(privateKey, publicKey)).ToArray()); } ParseSpendable(); }
public bool SignedByMe(Transaction tx) { for (int i = 0; i < tx.Inputs.Count; i++) { var vin = tx.Inputs[i]; var key = GetKey(vin.ScriptSig.GetSourcePubKey()); if (key == null) { return(false); } var pubkeyScript = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey); var eval = new ScriptEvaluationContext(); eval.SigHash = SigHash.All; if (!eval.VerifyScript(vin.ScriptSig, pubkeyScript, tx, i)) { return(false); } } return(true); }
private void ParseSpendable() { List <KeyId> pubkeys = new List <KeyId>(); var payToHash = new PayToPubkeyHashTemplate(); var keyId = payToHash.ExtractScriptPubKeyParameters(SpendableScript); if (keyId != null) { StealthKeys = new StealthSpendKey[] { new StealthSpendKey(keyId, this) }; } else { var payToMultiSig = new PayToMultiSigTemplate(); var para = payToMultiSig.ExtractScriptPubKeyParameters(SpendableScript); if (para == null) { throw new ArgumentException("Invalid stealth spendable output script", "spendable"); } StealthKeys = para.PubKeys.Select(k => new StealthSpendKey(k.ID, this)).ToArray(); } }
public PubKey GetSourcePubKey() { var template = new PayToPubkeyHashTemplate(); var result = template.ExtractScriptSigParameters(this); return result == null ? null : result.PublicKey; }
public bool SignedByMe(Transaction tx) { for(int i = 0 ; i < tx.Inputs.Count ; i++) { var vin = tx.Inputs[i]; var key = GetKey(vin.ScriptSig.GetSourcePubKey()); if(key == null) return false; var pubkeyScript = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey); var eval = new ScriptEvaluationContext(); eval.SigHash = SigHash.All; if(!eval.VerifyScript(vin.ScriptSig, pubkeyScript, tx, i)) return false; } return true; }
public void SetDestination(BitcoinAddress address) { ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(address); }
private void SetDestination(KeyId keyId) { ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(keyId); }
public bool IsFrom(PubKey pubKey) { var template = new PayToPubkeyHashTemplate(); var result = template.ExtractScriptSigParameters(ScriptSig); return result != null && result.PublicKey == pubKey; }
public void SetDestination(BitcoinAddress address) { ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(address); }
private void SetDestination(KeyId keyId) { ScriptPubKey = new PayToPubkeyHashTemplate().GenerateScriptPubKey(keyId); }
private void ParseSpendable() { List<KeyId> pubkeys = new List<KeyId>(); var payToHash = new PayToPubkeyHashTemplate(); var keyId = payToHash.ExtractScriptPubKeyParameters(SpendableScript); if(keyId != null) { StealthKeys = new StealthSpendKey[] { new StealthSpendKey(keyId, this) }; } else { var payToMultiSig = new PayToMultiSigTemplate(); var para = payToMultiSig.ExtractScriptPubKeyParameters(SpendableScript); if(para == null) throw new ArgumentException("Invalid stealth spendable output script", "spendable"); StealthKeys = para.PubKeys.Select(k => new StealthSpendKey(k.ID, this)).ToArray(); } }
public KeyId GetDestination() { var template = FindTemplate(); var payToPubKeyHash = template as PayToPubkeyHashTemplate; if(payToPubKeyHash != null) { return payToPubKeyHash.ExtractScriptPubKeyParameters(this); } var payToPubKey = template as PayToPubkeyTemplate; if(payToPubKey != null) { var result = new PayToPubkeyHashTemplate().ExtractScriptPubKeyParameters(this); if(result == null) { var pub = new PayToPubkeyTemplate().ExtractScriptPubKeyParameters(this); if(pub != null) return pub.ID; } } return null; }