Exemplo n.º 1
0
        public static Wallet FromPrivateKey(string privateKey, BinanceDexEnvironmentData env)
        {
            BigInteger privateKeyBigInteger = BigInteger.Parse("0" + privateKey, NumberStyles.HexNumber); // append "0" to get unsigned BigInteger
            Key        key    = new Key(privateKeyBigInteger.ToByteArray(true, true));
            Wallet     wallet = new Wallet(key, env);

            wallet.PrivateKey = privateKey;
            return(wallet);
        }
Exemplo n.º 2
0
        public static Wallet FromMnemonicCode(string mnemonicCode, BinanceDexEnvironmentData env)
        {
            Mnemonic mnemonic = new Mnemonic(mnemonicCode);

            byte[]  seed    = mnemonic.DeriveSeed();
            ExtKey  extKey  = new ExtKey(seed);
            KeyPath keyPath = KeyPath.Parse(hdPath);
            ExtKey  derived = extKey.Derive(keyPath);
            Wallet  wallet  = new Wallet(derived.PrivateKey, env);

            wallet.Mnemonic = mnemonicCode;
            return(wallet);
        }
Exemplo n.º 3
0
        public Wallet(Key key, BinanceDexEnvironmentData env)
        {
            EcKey = key;
            Env   = env;
            Bech32Encoder bech32Encoder = Encoders.Bech32(Env.Hrp);

            AddressBytes = EcKey.PubKey.Hash.ToBytes();
            string b32 = Encoders.Base32.EncodeData(AddressBytes);

            byte[] address32 = new byte[b32.Length];
            for (int i = 0; i < b32.Length; i++)
            {
                address32[i] = (byte)pbase32.IndexOf(b32[i]);
            }
            Address = bech32Encoder.EncodeData(address32);
            byte[] pubKey       = EcKey.PubKey.ToBytes();
            byte[] pubKeyPrefix = MessageType.GetTransactionType(EMessageType.PubKey);
            PubKeyForSign = new byte[pubKey.Length + pubKeyPrefix.Length + 1];
            pubKeyPrefix.CopyTo(PubKeyForSign, 0);
            PubKeyForSign[pubKeyPrefix.Length] = 33;
            pubKey.CopyTo(PubKeyForSign, pubKeyPrefix.Length + 1);

            client = new HttpApiClient(Env);
        }
Exemplo n.º 4
0
        public static Wallet FromRandomMnemonicCode(BinanceDexEnvironmentData env)
        {
            Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.TwentyFour);

            return(FromMnemonicCode(mnemonic.ToString(), env));
        }
Exemplo n.º 5
0
 public HttpApiClient(BinanceDexEnvironmentData binanceDexEnvironmentData)
 {
     restClient = new RestClient(binanceDexEnvironmentData.BaseUrl).UseSerializer(() => new JsonNetSerializer());
 }