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); }
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); }
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); }
public static Wallet FromRandomMnemonicCode(BinanceDexEnvironmentData env) { Mnemonic mnemonic = new Mnemonic(Wordlist.English, WordCount.TwentyFour); return(FromMnemonicCode(mnemonic.ToString(), env)); }
public HttpApiClient(BinanceDexEnvironmentData binanceDexEnvironmentData) { restClient = new RestClient(binanceDexEnvironmentData.BaseUrl).UseSerializer(() => new JsonNetSerializer()); }