internal static Network GetNetworkFromBase58Data(string base58, Base58Type?expectedType = null)
 {
     foreach (Network network in GetNetworks())
     {
         Base58Type?type = network.GetBase58Type(base58);
         if (type.HasValue)
         {
             if (expectedType != null && expectedType.Value != type.Value)
             {
                 continue;
             }
             if (type.Value == Base58Type.COLORED_ADDRESS)
             {
                 byte[] raw     = Encoders.Base58Check.DecodeData(base58);
                 byte[] version = network.GetVersionBytes(type.Value, false);
                 if (version == null)
                 {
                     continue;
                 }
                 raw    = raw.Skip(version.Length).ToArray();
                 base58 = Encoders.Base58Check.EncodeData(raw);
                 return(GetNetworkFromBase58Data(base58, null));
             }
             return(network);
         }
     }
     return(null);
 }
示例#2
0
        public static object InterpretAddress(string what)
        {
            if (what == null)
            {
                return(null);
            }

            what = what.Trim();
            Base58Type?type    = GetBase58Type(what);
            Network    network = Network.TestNet;

            if (type == null)
            {
                return(null);
            }

            switch (type)
            {
            case Base58Type.COLORED_ADDRESS:                                // BitcoinColoredAddress(BitcoinAddress);
                return(new BitcoinColoredAddress(what, network));

            case Base58Type.PUBKEY_ADDRESS:                                 // Key.PubKey.GetAddress(Network.TestNet);
                return(new BitcoinAddress(what, network));

            case Base58Type.SCRIPT_ADDRESS:                                 // PubKey.ScriptPubKey.GetScriptAddress(Network.TestNet)
                return(new BitcoinScriptAddress(what, network));

            case Base58Type.STEALTH_ADDRESS:                                // BitcoinStealthAddress( Key.PubKey, new[] { Key.PubKey }, 1, null, Network.TestNet);
                return(new BitcoinStealthAddress(what, network));

            default:
                return(null);
            }
        }
示例#3
0
 private static IEnumerable <IBase58Data> GetCandidates(IEnumerable <Network> networks, string base58)
 {
     if (base58 == null)
     {
         throw new ArgumentNullException("base58");
     }
     foreach (Network network in networks)
     {
         Base58Type?type = network.GetBase58Type(base58);
         if (type.HasValue)
         {
             IBase58Data data = null;
             try
             {
                 data = network.CreateBase58Data(type.Value, base58);
             }
             catch (FormatException)
             {
             }
             if (data != null)
             {
                 yield return(data);
             }
         }
     }
 }
示例#4
0
        public static object Interpret(string what)
        {
            if (what == null)
            {
                return(null);
            }

            what = what.Trim();
            Base58Type?type    = GetBase58Type(what);
            Network    network = Network.TestNet;

            if (type == null)
            {
                return(null);
            }

            switch (type)
            {
            case Base58Type.ASSET_ID:                                       // AssetId(BitcoinAddress).GetWif(Network.TestNet);
                return(new BitcoinAssetId(what));

            case Base58Type.COLORED_ADDRESS:                                // BitcoinColoredAddress(BitcoinAddress);
                return(new BitcoinColoredAddress(what, network));

            case Base58Type.CONFIRMATION_CODE:                              // Key.ConfirmationCode
                return(new BitcoinConfirmationCode(what, network));

            case Base58Type.ENCRYPTED_SECRET_KEY_EC:                        // BitcoinPassphraseCode("my secret", Network.TestNet, null).GenerateEncryptedSecret().EncryptedKey
                return(new BitcoinEncryptedSecretEC(what, network));

            case Base58Type.ENCRYPTED_SECRET_KEY_NO_EC:                     // BitcoinEncryptedSecretNoEC(Key,"Password", Network.TestNet);
                return(new BitcoinEncryptedSecretNoEC(what, network));

            case Base58Type.EXT_PUBLIC_KEY:                                 // Key.PubKey;
                return(ExtPubKey.Parse(what, Network.TestNet));

            case Base58Type.EXT_SECRET_KEY:                                 // BitcoinExtKey(ExtKey.GetWif(Network.TestNet), Network.TestNet);
                return(new BitcoinExtKey(what, network));

            case Base58Type.PASSPHRASE_CODE:                                // BitcoinPassphraseCode("my secret", Network.TestNet, null);
                return(new BitcoinPassphraseCode(what, network));

            case Base58Type.PUBKEY_ADDRESS:                                 // Key.PubKey.GetAddress(Network.TestNet);
                return(new BitcoinAddress(what, network));

            case Base58Type.SCRIPT_ADDRESS:                                 // PubKey.ScriptPubKey.GetScriptAddress(Network.TestNet)
                return(new BitcoinScriptAddress(what, network));

            case Base58Type.SECRET_KEY:                                     // Key.GetBitcoinSecret(Network.TestNet)
                return(new BitcoinSecret(what, network));

            case Base58Type.STEALTH_ADDRESS:                                // BitcoinStealthAddress( Key.PubKey, new[] { Key.PubKey }, 1, null, Network.TestNet);
                return(new BitcoinStealthAddress(what, network));

            case Base58Type.MAX_BASE58_TYPES:
            default:
                return(null);
            }
        }
示例#5
0
 /// <summary>
 /// Create a bitcoin address from base58 data, return a BitcoinAddress or BitcoinScriptAddress
 /// </summary>
 /// <param name="base58">base58 address</param>
 /// <exception cref="System.FormatException">Invalid base58 address</exception>
 /// <returns>BitcoinScriptAddress, BitcoinAddress</returns>
 public BitcoinAddress CreateBitcoinAddress(string base58)
 {
     Base58Type? type = GetBase58Type(base58);
     if (!type.HasValue)
         throw new FormatException("Invalid Base58 version");
     if (type == Base58Type.PUBKEY_ADDRESS)
         return CreateBitcoinPubKeyAddress(base58);
     if (type == Base58Type.SCRIPT_ADDRESS)
         return CreateBitcoinScriptAddress(base58);
     throw new FormatException("Invalid Base58 version");
 }
 private static IEnumerable <IBase58Data> GetCandidates(IEnumerable <Network> networks, string base58)
 {
     if (base58 == null)
     {
         throw new ArgumentNullException("base58");
     }
     foreach (Network network in networks)
     {
         Base58Type?type = network.GetBase58Type(base58);
         if (type.HasValue)
         {
             if (type.Value == Base58Type.COLORED_ADDRESS)
             {
                 string     wrapped     = BitcoinColoredAddress.GetWrappedBase58(base58, network);
                 Base58Type?wrappedType = network.GetBase58Type(wrapped);
                 if (wrappedType == null)
                 {
                     continue;
                 }
                 try
                 {
                     IBase58Data inner = network.CreateBase58Data(wrappedType.Value, wrapped);
                     if (inner.Network != network)
                     {
                         continue;
                     }
                 }
                 catch (FormatException)
                 {
                 }
             }
             IBase58Data data = null;
             try
             {
                 data = network.CreateBase58Data(type.Value, base58);
             }
             catch (FormatException)
             {
             }
             if (data != null)
             {
                 yield return(data);
             }
         }
     }
 }
示例#7
0
        internal static Network GetNetworkFromBase58Data(string base58, Base58Type?expectedType = null)
        {
            foreach (Network network in GetNetworks())
            {
                Base58Type?type = network.GetBase58Type(base58);
                if (type.HasValue)
                {
                    if (expectedType != null && expectedType.Value != type.Value)
                    {
                        continue;
                    }

                    return(network);
                }
            }
            return(null);
        }
示例#8
0
        public static object InterpretKey(string what)
        {
            if (what == null)
            {
                return(null);
            }

            what = what.Trim();
            Base58Type?type    = GetBase58Type(what);
            Network    network = Network.TestNet;

            if (type == null)
            {
                return(null);
            }

            switch (type)
            {
            case Base58Type.ENCRYPTED_SECRET_KEY_EC:                        // BitcoinPassphraseCode("my secret", Network.TestNet, null).GenerateEncryptedSecret().EncryptedKey
                return(new BitcoinEncryptedSecretEC(what, network));

            case Base58Type.ENCRYPTED_SECRET_KEY_NO_EC:                     // BitcoinEncryptedSecretNoEC(Key,"Password", Network.TestNet);
                return(new BitcoinEncryptedSecretNoEC(what, network));

            case Base58Type.EXT_PUBLIC_KEY:                                 // Key.PubKey;
                return(ExtPubKey.Parse(what, Network.TestNet));

            case Base58Type.EXT_SECRET_KEY:                                 // BitcoinExtKey(ExtKey.GetWif(Network.TestNet), Network.TestNet);
                return(new BitcoinExtKey(what, network));

            case Base58Type.SECRET_KEY:                                     // Key.GetBitcoinSecret(Network.TestNet)
                return(new BitcoinSecret(what, network));

            case Base58Type.PASSPHRASE_CODE:                                // BitcoinPassphraseCode("my secret", Network.TestNet, null);
                return(new BitcoinPassphraseCode(what, network));

            default:
                return(null);
            }
        }
 public static Network GetNetworkFromBase58Data(string base58, Base58Type?expectedType = null)
 {
     //foreach (var network in GetNetworks())
     //{
     //    var lBase58Type = network.GetBase58Type(base58);
     //    if (lBase58Type.HasValue)
     //    {
     //        if (expectedType != null && expectedType.Value != lBase58Type.Value)
     //            continue;
     //        //if(lBase58Type.Value == Base58Type.COLORED_ADDRESS)
     //        //{
     //        //    var raw = Encoders.Base58Check.DecodeData(base58);
     //        //    var version = network.GetVersionBytes(lBase58Type.Value, false);
     //        //    if(version == null)
     //        //        continue;
     //        //    raw = raw.Skip(version.Length).ToArray();
     //        //    base58 = Encoders.Base58Check.EncodeData(raw);
     //        //    return GetNetworkFromBase58Data(base58, null);
     //        //}
     //        return network;
     //    }
     //}
     return(null);
 }