예제 #1
0
        private Task <BlockIoResponse <dynamic> > _withdraw(string Method, string Path, dynamic args)
        {
            BlockIoResponse <dynamic> res = null;
            dynamic argsObj = args;
            string  pin;

            if (argsObj.GetType().GetProperty("pin") != null)
            {
                pin = argsObj.GetType().GetProperty("pin").GetValue(argsObj, null);
            }
            else
            {
                pin = this.Pin;
            }

            Task <BlockIoResponse <dynamic> > RequestTask = _request(Method, Path, argsObj);

            res = RequestTask.Result;

            if (res.Status == "fail" || res.Data.reference_id == null ||
                res.Data.encrypted_passphrase == null || res.Data.encrypted_passphrase.passphrase == null)
            {
                return(RequestTask);
            }

            if (pin == null)
            {
                if (Opts.AllowNoPin)
                {
                    return(RequestTask);
                }
                throw new Exception("Public key mismatch. Invalid Secret PIN detected.");
            }

            string enrypted_passphrase = res.Data.encrypted_passphrase.passphrase;
            string aesKey  = this.AesKey != null ? this.AesKey : Helper.PinToAesKey(pin);
            Key    privKey = new Key().ExtractKeyFromEncryptedPassphrase(enrypted_passphrase, aesKey);
            string pubKey  = privKey.PubKey.ToHex();

            if (pubKey != res.Data.encrypted_passphrase.signer_public_key.ToString())
            {
                throw new Exception("Public key mismatch. Invalid Secret PIN detected.");
            }

            foreach (dynamic input in res.Data.inputs)
            {
                foreach (dynamic signer in input.signers)
                {
                    signer.signed_data = Helper.SignInputs(privKey, input.data_to_sign.ToString(), pubKey);
                }
            }

            dynamic signAndFinalizeRequestJson = new { res.Data.reference_id, res.Data.inputs };

            return(_request(Method, "sign_and_finalize_withdrawal", JsonConvert.SerializeObject(signAndFinalizeRequestJson)));
        }
예제 #2
0
        private Task <BlockIoResponse <dynamic> > _withdraw(string Method, string Path, string args)
        {
            BlockIoResponse <dynamic> res = null;

            try
            {
                dynamic argsObj = JsonConvert.DeserializeObject(args);
                string  pin     = argsObj.pin != null ? argsObj.pin : this.Pin;
                argsObj.pin = "";
                Task <BlockIoResponse <dynamic> > RequestTask = _request(Method, Path, args);
                res = RequestTask.Result;
                if (res.Status == "fail" || res.Data.reference_id == null ||
                    res.Data.encrypted_passphrase == null || res.Data.encrypted_passphrase.passphrase == null)
                {
                    return(RequestTask);
                }

                if (pin == null)
                {
                    if (this.Options.allowNoPin == true)
                    {
                        return(RequestTask);
                    }
                    throw new Exception("Public key mismatch. Invalid Secret PIN detected.");
                }

                string enrypted_passphrase = res.Data.encrypted_passphrase.passphrase;
                string aesKey  = this.AesKey != null ? this.AesKey: Helper.PinToAesKey(pin);
                Key    privKey = new Key().ExtractKeyFromEncryptedPassphrase(enrypted_passphrase, aesKey);
                string pubKey  = privKey.PubKey.ToHex();
                if (pubKey != res.Data.encrypted_passphrase.signer_public_key.ToString())
                {
                    throw new Exception("Public key mismatch. Invalid Secret PIN detected.");
                }

                foreach (dynamic input in res.Data.inputs)
                {
                    foreach (dynamic signer in input.signers)
                    {
                        signer.signed_data = Helper.SignInputs(privKey, input.data_to_sign.ToString(), pubKey);
                    }
                }

                aesKey  = "";
                privKey = null;
                return(_request(Method, "sign_and_finalize_withdrawal", res.Data.ToString()));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
예제 #3
0
        private Task <BlockIoResponse <dynamic> > _sweep(string Method, string Path, string args)
        {
            Key KeyFromWif = null;
            BlockIoResponse <dynamic> res = null;

            try
            {
                dynamic argsObj = JsonConvert.DeserializeObject(args);

                if (argsObj.to_address == null)
                {
                    throw new Exception("Missing mandatory private_key argument.");
                }

                string PrivKeyStr = argsObj.private_key.ToString();
                KeyFromWif          = new Key().FromWif(PrivKeyStr);
                argsObj.public_key  = KeyFromWif.PubKey.ToHex();
                argsObj.private_key = "";
                args = JsonConvert.SerializeObject(argsObj);

                Task <BlockIoResponse <dynamic> > RequestTask = _request(Method, Path, args);
                res = RequestTask.Result;
                if (res.Data.reference_id == null)
                {
                    return(RequestTask);
                }
                foreach (dynamic input in res.Data.inputs)
                {
                    foreach (dynamic signer in input.signers)
                    {
                        signer.signed_data = Helper.SignInputs(KeyFromWif, input.data_to_sign.ToString(), argsObj.public_key.ToString());
                    }
                }
                KeyFromWif = null;
                return(_request(Method, "sign_and_finalize_sweep", res.Data.ToString()));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
예제 #4
0
        private Task <BlockIoResponse <dynamic> > _sweep(string Method, string Path, dynamic args)
        {
            Key KeyFromWif = null;
            BlockIoResponse <dynamic> res = null;
            var argsObj = args;

            if (argsObj.GetType().GetProperty("to_address") == null)
            {
                throw new Exception("Missing mandatory private_key argument.");
            }

            string PrivKeyStr = argsObj.GetType().GetProperty("private_key").GetValue(argsObj, null);

            KeyFromWif = new Key().FromWif(PrivKeyStr);
            string to_address   = argsObj.GetType().GetProperty("to_address").GetValue(argsObj, null);
            string from_address = argsObj.GetType().GetProperty("from_address").GetValue(argsObj, null);

            argsObj = new { to_address, from_address, public_key = KeyFromWif.PubKey.ToHex() };
            args    = argsObj;

            Task <BlockIoResponse <dynamic> > RequestTask = _request(Method, Path, args);

            res = RequestTask.Result;

            if (res.Data.reference_id == null)
            {
                return(RequestTask);
            }
            foreach (dynamic input in res.Data.inputs)
            {
                foreach (dynamic signer in input.signers)
                {
                    signer.signed_data = Helper.SignInputs(KeyFromWif, input.data_to_sign.ToString(), argsObj.public_key.ToString());
                }
            }

            dynamic signAndFinalizeRequestJson = new { res.Data.reference_id, res.Data.inputs };

            return(_request(Method, "sign_and_finalize_sweep", JsonConvert.SerializeObject(signAndFinalizeRequestJson)));
        }