public static BinanceEnvironment GetEnvironment(Network env)
        {
            BinanceEnvironment be = new BinanceEnvironment();

            be.Network = env;
            if (env == Network.Test)
            {
                be._hrp             = "tbnb";
                be._chainId         = "Binance-Chain-Nile";
                be._httpsApiAddress = "https://testnet-dex.binance.org/api/v1";
                be._wssApiAddress   = "wss://testnet-dex.binance.org/api/ws";
            }
            else if (env == Network.Mainnet)
            {
                be._hrp             = "bnb";
                be._chainId         = "Binance-Chain-Tigris";
                be._httpsApiAddress = "https://dex.binance.org/api/v1";
                be._wssApiAddress   = "wss://dex.binance.org/api/ws";
            }
            else
            {
                throw new Exception("Unknown environment");
            }
            return(be);
        }
Ejemplo n.º 2
0
        public static Wallet RestoreWalletFromMnemonic(string mnemonicStr, Network env)
        {
            Mnemonic mnemonic = new Mnemonic(mnemonicStr);

            var seed = mnemonic.DeriveSeed();
            var pk   = new ExtKey(seed);
            var kp   = KeyPath.Parse(keyPath);
            var key  = pk.Derive(kp);

            var privKey = key.PrivateKey;
            var bytes   = privKey.ToBytes();

            Wallet w = new Wallet();

            w._env            = BinanceEnvironment.GetEnvironment(env);
            w._privateKey     = privKey;
            w._privateKeyStr  = BitConverter.ToString(bytes).Replace("-", string.Empty);
            w._publicKey      = w._privateKey.PubKey.Compress();
            w._publicKeyBytes = w._publicKey.ToBytes();
            w._AddressBytes   = w._publicKey.Hash.ToBytes();
            w._addressStr     = Bech32Engine.Encode(w.Env.Hrp, w._AddressBytes);


            w.Init();

            return(w);
        }
Ejemplo n.º 3
0
        public Wallet(string privateKey, Network env)
        {
            _env            = BinanceEnvironment.GetEnvironment(env);
            _privateKey     = new Key(Helpers.StringToByteArrayFastest(privateKey));
            _privateKeyStr  = privateKey;
            _publicKey      = _privateKey.PubKey.Compress();
            _publicKeyBytes = _publicKey.ToBytes();
            _AddressBytes   = _publicKey.Hash.ToBytes();
            _addressStr     = Bech32Engine.Encode(_env.Hrp, _AddressBytes);

            Init();
        }
Ejemplo n.º 4
0
        public static CreateRandomAccountResponse CreateRandomAccount(Network network)
        {
            var env      = BinanceEnvironment.GetEnvironment(network);
            var response = new CreateRandomAccountResponse();

            response.Network = network;
            Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.TwentyFour);

            response.Mnemonic = mnemonic.ToString();
            var seed    = mnemonic.DeriveSeed();
            var pk      = new ExtKey(seed);
            var kp      = KeyPath.Parse(keyPath);
            var key     = pk.Derive(kp);
            var privKey = key.PrivateKey;

            response.PrivateKey = BitConverter.ToString(privKey.ToBytes()).Replace("-", string.Empty);
            response.Address    = Bech32Engine.Encode(env.Hrp, privKey.PubKey.Hash.ToBytes());

            return(response);
        }