public static ExtPubKey Parse(string wif, Network expectedNetwork) { if (expectedNetwork == null) { throw new ArgumentNullException(nameof(expectedNetwork)); } if (wif == null) { throw new ArgumentNullException(nameof(wif)); } return(expectedNetwork.Parse <BitcoinExtPubKey>(wif).ExtPubKey); }
public static T ToNetwork <T>(this T obj, Network network) where T : IBitcoinString { if (network == null) { throw new ArgumentNullException(nameof(network)); } if (obj == null) { throw new ArgumentNullException(nameof(obj)); } if (obj.Network == network) { return(obj); } if (obj is IBase58Data) { var b58 = (IBase58Data)obj; if (b58.Type != Base58Type.COLORED_ADDRESS) { byte[] version = network.GetVersionBytes(b58.Type, true); var enc = network.NetworkStringParser.GetBase58CheckEncoder(); var inner = enc.DecodeData(b58.ToString()).Skip(version.Length).ToArray(); var newBase58 = enc.EncodeData(version.Concat(inner).ToArray()); return(Network.Parse <T>(newBase58, network)); } else { var colored = BitcoinColoredAddress.GetWrappedBase58(obj.ToString(), obj.Network); var address = Network.Parse <BitcoinAddress>(colored, obj.Network).ToNetwork(network); return((T)(object)address.ToColoredAddress()); } } else if (obj is IBech32Data) { var b32 = (IBech32Data)obj; var encoder = b32.Network.GetBech32Encoder(b32.Type, true); byte wit; var data = encoder.Decode(b32.ToString(), out wit); encoder = network.GetBech32Encoder(b32.Type, true); var str = encoder.Encode(wit, data); return((T)(object)Network.Parse <T>(str, network)); } else { throw new NotSupportedException(); } }
public static T ToNetwork <T>(this T obj, Network network) where T : IBitcoinString { if (network == null) { throw new ArgumentNullException("network"); } if (obj == null) { throw new ArgumentNullException("obj"); } if (obj.Network == network) { return(obj); } if (obj is IBase58Data) { var b58 = (IBase58Data)obj; byte[] version = network.GetVersionBytes(b58.Type, true); byte[] inner = Encoders.Base58Check.DecodeData(b58.ToString()).Skip(version.Length).ToArray(); string newBase58 = Encoders.Base58Check.EncodeData(version.Concat(inner).ToArray()); return(Network.Parse <T>(newBase58, network)); } else if (obj is IBech32Data) { var b32 = (IBech32Data)obj; Bech32Encoder encoder = b32.Network.GetBech32Encoder(b32.Type, true); byte wit; byte[] data = encoder.Decode(b32.ToString(), out wit); encoder = network.GetBech32Encoder(b32.Type, true); string str = encoder.Encode(wit, data); return((T)(object)Network.Parse <T>(str, network)); } else { throw new NotSupportedException(); } }
public static BitcoinEncryptedSecret Create(string wif, Network expectedNetwork = null) { return(Network.Parse <BitcoinEncryptedSecret>(wif, expectedNetwork)); }
public static Key Parse(string wif, string password, Network network = null) { return(Network.Parse <BitcoinEncryptedSecret>(wif, network).GetKey(password)); }
public static Key Parse(string wif, Network network = null) { return(Network.Parse <BitcoinSecret>(wif, network).PrivateKey); }
/// <summary> /// Parses the Base58 data (checking the network if specified), checks it represents the /// correct type of item, and then returns the corresponding ExtKey. /// </summary> public static ExtKey Parse(string wif, Network expectedNetwork = null) { return(Network.Parse <BitcoinExtKey>(wif, expectedNetwork).ExtKey); }