private static string Validate(string base58, ref Network expectedNetwork) { PubKey p = null; TxDestination h = null; return(Validate(base58, ref expectedNetwork, ref p, ref h)); }
public override bool Equals(object obj) { TxDestination item = obj as TxDestination; if (item == null) { return(false); } return(Utils.ArrayEqual(_DestBytes, item._DestBytes) && item.GetType() == this.GetType()); }
public override bool Equals(object obj) { TxDestination item = obj as TxDestination; if (item == null) { return(false); } return(_Dest.Equals(item._Dest)); }
public BitcoinBlindedAddress(PubKey blindingKey, TxDestination keyId, Network network) : base(NotNull(keyId, nameof(keyId)) ?? NotNull(blindingKey, nameof(blindingKey)) ?? Network.CreateBase58(Base58Type.BLINDED_ADDRESS, network.GetVersionBytes(((IBase58Data)keyId.GetAddress(network)).Type, true) .Concat(blindingKey.ToBytes()) .Concat(keyId.ToBytes()), network), network) { _BlindingKey = blindingKey; _Hash = keyId; }
/// <summary> /// Create scriptPubKey from destination id /// </summary> /// <param name="id"></param> /// <returns></returns> public static Script CreateFromDestination(TxDestination id) { if (id is ScriptId) { return(PayToScriptHashTemplate.Instance.GenerateScriptPubKey((ScriptId)id)); } if (id is KeyId) { return(PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey((KeyId)id)); } throw new NotSupportedException(); }
public BitcoinBlindedAddress(string base58, Network expectedNetwork = null) : base(Validate(base58, ref expectedNetwork), expectedNetwork) { var data = Encoders.Base58Check.DecodeData(base58); PubKey p = null; TxDestination h = null; Validate(base58, ref expectedNetwork, ref p, ref h); _Hash = h; _BlindingKey = p; }
public BitcoinAddress CreateBitcoinAddress(TxDestination dest) { if (dest == null) { throw new ArgumentNullException("dest"); } if (dest is ScriptId) { return(CreateBitcoinScriptAddress((ScriptId)dest)); } if (dest is KeyId) { return(new BitcoinAddress((KeyId)dest, this)); } throw new ArgumentException("Invalid dest type", "dest"); }
/// <summary> /// Create scriptPubKey from destination id /// </summary> /// <param name="id"></param> /// <returns></returns> public static Script CreateFromDestination(TxDestination id) { var scriptId = id as ScriptId; if (scriptId != null) { return(PayToScriptHashTemplate.Instance.GenerateScriptPubKey(scriptId)); } var pubkeyHash = id as KeyId; if (pubkeyHash != null) { return(PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(pubkeyHash)); } throw new NotSupportedException(); }
public ScriptCoin AssertCoherent(Network network) { if (Redeem == null) { throw new ArgumentException("redeem cannot be null", "redeem"); } TxDestination expectedDestination = GetRedeemHash(network, TxOut.ScriptPubKey); if (expectedDestination == null) { throw new ArgumentException("the provided scriptPubKey is not P2SH or P2WSH"); } if (expectedDestination is ScriptId) { if (PayToWitScriptHashTemplate.Instance.CheckScriptPubKey(network, Redeem)) { throw new ArgumentException("The redeem script provided must be the witness one, not the P2SH one"); } if (expectedDestination.ScriptPubKey != Redeem.Hash.ScriptPubKey) { if (Redeem.WitHash.ScriptPubKey.Hash.ScriptPubKey != expectedDestination.ScriptPubKey) { throw new ArgumentException("The redeem provided does not match the scriptPubKey of the coin"); } } } else if (expectedDestination is WitScriptId) { if (expectedDestination.ScriptPubKey != Redeem.WitHash.ScriptPubKey) { throw new ArgumentException("The redeem provided does not match the scriptPubKey of the coin"); } } else { throw new NotSupportedException("Not supported redeemed scriptPubkey"); } return(this); }
public static BitcoinAddress Create(TxDestination id, Network network) { if (id == null) { throw new ArgumentNullException("id"); } if (network == null) { throw new ArgumentNullException("network"); } if (id is KeyId) { return(new BitcoinAddress(id, network)); } if (id is ScriptId) { return(new BitcoinScriptAddress((ScriptId)id, network)); } throw new NotSupportedException(); }
protected BitcoinAddress(TxDestination dest, Network network) : base(dest.ToBytes(), network) { }
public static BitcoinAddress Create(TxDestination id, Network network) { if(id == null) throw new ArgumentNullException("id"); if(network == null) throw new ArgumentNullException("network"); if(id is KeyId) return new BitcoinAddress(id, network); if(id is ScriptId) return new BitcoinScriptAddress((ScriptId)id, network); throw new NotSupportedException(); }
/// <summary> /// Create scriptPubKey from destination id /// </summary> /// <param name="id"></param> /// <returns></returns> public static Script CreateFromDestination(TxDestination id) { var scriptId = id as ScriptId; if(scriptId != null) return PayToScriptHashTemplate.Instance.GenerateScriptPubKey(scriptId); var pubkeyHash = id as KeyId; if(pubkeyHash != null) return PayToPubkeyHashTemplate.Instance.GenerateScriptPubKey(pubkeyHash); throw new NotSupportedException(); }
private static string Validate(string base58, ref Network expectedNetwork, ref PubKey blinding, ref TxDestination hash) { if (base58 == null) { throw new ArgumentNullException("base58"); } var networks = expectedNetwork == null?Network.GetNetworks() : new[] { expectedNetwork }; var data = Encoders.Base58Check.DecodeData(base58); foreach (var network in networks) { bool isP2SH = false; var versionBytes = network.GetVersionBytes(Base58Type.BLINDED_ADDRESS, false); if (versionBytes == null || !data.StartWith(versionBytes)) { continue; } var innerData = data.Skip(versionBytes.Length).ToArray(); var versionBytes2 = network.GetVersionBytes(Base58Type.PUBKEY_ADDRESS, false); if (!innerData.StartWith(versionBytes2)) { versionBytes2 = network.GetVersionBytes(Base58Type.SCRIPT_ADDRESS, false); if (!innerData.StartWith(versionBytes2)) { continue; } isP2SH = true; } if (innerData.Length != versionBytes2.Length + 33 + 20) { continue; } try { blinding = new PubKey(innerData.SafeSubarray(versionBytes2.Length, 33)); var h = innerData.SafeSubarray(versionBytes2.Length + 33, 20); hash = isP2SH ? (TxDestination) new ScriptId(h) : new KeyId(h); } catch (FormatException) { continue; } expectedNetwork = network; return(base58); } throw new FormatException("Invalid BitcoinBlindedAddress"); }
public BitcoinAddress(TxDestination id, Network network) : base(id.ToBytes(), network) { }
private void SetDestination(TxDestination destination) { ScriptPubKey = destination.CreateScriptPubKey(); }
private Key FindKey(TransactionSigningContext ctx, TxDestination id) { return(_Keys .Concat(ctx.AdditionalKeys) .FirstOrDefault(k => k.PubKey.Hash == id)); }