/// <summary>
        ///character string to sign of transaction processing under password management mode
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string ReqChainCodeReqMac(NodeApiReqBody <ReqChainCodeReqBody> req)
        {
            //assemble the original string to sign
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.userName)
            .Append(req.body.nonce)
            .Append(req.body.chainCode)
            .Append(req.body.funcName);
            if (req.body.args != null && req.body.args.Length > 0)
            {
                for (int i = 0; i < req.body.args.Length; i++)
                {
                    strBuilder.Append(req.body.args[i]);
                }
            }

            if (req.body.transientData != null && req.body.transientData.Count > 0)
            {
                foreach (var t in req.body.transientData)
                {
                    strBuilder.Append(t.Key);
                    strBuilder.Append(t.Value);
                }
            }

            return(strBuilder.ToString());
        }
Example #2
0
        /// <summary>
        /// character string to sign to logout event
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetFiscoEventRemoveReqMac(NodeApiReqBody <RemoveReqDataBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.EventId);
            return(strBuilder.ToString());
        }
Example #3
0
        /// <summary>
        /// character string to sign to get the transacion receipt
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetFiscoTxReceiptReqMac(NodeApiReqBody <FiscoTxReqDataBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.TxHash);
            return(strBuilder.ToString());
        }
Example #4
0
        /// <summary>
        /// character string to sign to get the user registered
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetRegisterUserReqMac(NodeApiReqBody <FiscoRegisterReqBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.UserId);
            return(strBuilder.ToString());
        }
 /// <summary>
 /// user cert application
 /// </summary>
 /// <param name="config">basic information</param>
 /// <param name="reqBody">user cert requests</param>
 /// <returns></returns>
 public Tuple <bool, string> EnrollUser(EnrollUserReqBody reqBody)
 {
     try
     {
         NodeApiReqBody <EnrollUserReqBody> req = new NodeApiReqBody <EnrollUserReqBody>()
         {
             body = new EnrollUserReqBody()
             {
                 name   = reqBody.name,
                 secret = reqBody.secret
             },
             header = new ReqHeader()
             {
                 appCode  = config.appInfo.AppCode,
                 userCode = config.userCode
             }
         };
         ////get csr
         var resCsr = config.appInfo.AlgorithmType == EmAlgorithmType.SM2 ?
                      CsrHelper.GetSMCsr(string.Format("{0}@{1}", reqBody.name, config.appInfo.AppCode))
           : CsrHelper.GetCsr(string.Format("{0}@{1}", reqBody.name, config.appInfo.AppCode));
         req.body.csrPem = resCsr.Item1.Replace("\r", "");
         // assemble the original string to sign
         var data = ReqMacExtends.GetEnrollUserReqMac(req);
         req.mac = sign.Sign(data);
         var res = SendHelper.SendPost <NodeApiResBody <EnrollUserResBody> >(config.reqUrl + EnrollUserUrl, JsonConvert.SerializeObject(req), config.httpsCert);
         if (res != null)
         {
             //check the status codes in turn
             if (res.header.code != 0)
             {
                 return(new Tuple <bool, string>(false, res.header.msg));
             }
             //assemble the original string to sign
             var datares = ResMacExtends.GetEnrollUserResMac(res);
             //verify data
             if (sign.Verify(res.mac, datares))
             {
                 //save the private key and cert
                 if (!string.IsNullOrEmpty(res.body.cert))
                 {
                     CertStore.SaveCert(res.body.cert, Path.Combine(config.mspDir, string.Format("{0}@{1}_cert.pem", reqBody.name, config.appInfo.AppCode)));
                     ECDSAStore.SavePriKey(resCsr.Item2, Path.Combine(config.mspDir, string.Format("{0}@{1}_sk.pem", reqBody.name, config.appInfo.AppCode)));
                 }
                 return(new Tuple <bool, string>(true, "cert registration successful"));
             }
             else
             {
                 return(new Tuple <bool, string>(false, "failed to verify the signature"));
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(new Tuple <bool, string>(false, "failed to verify the cert"));
 }
Example #6
0
        /// <summary>
        /// character string to sign to get the block information
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetFiscoBlockInfoReqMac(NodeApiReqBody <FiscoBlockReqDataBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.BlockNumber)
            .Append(req.body.BlockHash);
            return(strBuilder.ToString());
        }
Example #7
0
        /// <summary>
        /// character string to sign of transaction processing under key upload mode
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetFiscoTransReqMac(NodeApiReqBody <FiscoTransReqBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.ContractName)
            .Append(req.body.TransData);
            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign to logout event chaincode
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string EventRemoveReqMac(NodeApiReqBody <EventRemoveReqBody> req)
        {
            //assemble original character string
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.eventId);
            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign to get the transaction information
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetTransactionReqMac(NodeApiReqBody <GetTransReqBody> req)
        {
            //assemble the original string to sign
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.txId);
            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign to get the user registered
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetRegisterUserReqMac(NodeApiReqBody <RegisterUserReqBody> req)
        {
            //assemble the original string to sign
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.name)
            .Append(req.body.secret);
            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign of transaction processing under random password mode
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string TransReqMac(NodeApiReqBody <TransReqBody> req)
        {
            //assemble the original character string
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.transData);

            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign to get the block information
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetBlockInfoReqMac(NodeApiReqBody <GetBlockReqBody> req)
        {
            //assemble the original character string to sign
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.blockNumber)
            .Append(req.body.blockHash)
            .Append(req.body.txId);
            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign of transaction processing under key trust mode
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetCitaTransReqMac(NodeApiReqBody <CitaTransReqDataBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.UserId)
            .Append(req.body.ContractName)
            .Append(req.body.FuncName)
            .Append(req.body.FuncParam);
            return(strBuilder.ToString());
        }
Example #14
0
        /// <summary>
        /// character string to sign to register event
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string GetFiscoEventRegisterReqMac(NodeApiReqBody <FiscoRegisterReqDataBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.EventType)
            .Append(req.body.ContractAddress)
            .Append(req.body.ContractName)
            .Append(req.body.NotifyUrl)
            .Append(req.body.AttachArgs);
            return(strBuilder.ToString());
        }
        /// <summary>
        /// character string to sign to register event chaincode
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static string EventRegisterReqMac(NodeApiReqBody <EventRegisterReqBody> req)
        {
            //assemble the original character string
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.chainCode)
            .Append(req.body.eventKey)
            .Append(req.body.notifyUrl)
            .Append(req.body.attachArgs);
            return(strBuilder.ToString());
        }
Example #16
0
        /// <summary>
        /// chaincode event registration
        /// </summary>
        /// <param name="config"></param>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, EventRegisterResBody> EventRegister(EventRegisterReqBody reqBody)
        {
            try
            {
                NodeApiReqBody <EventRegisterReqBody> req = new NodeApiReqBody <EventRegisterReqBody>()
                {
                    header = new ReqHeader()
                    {
                        appCode  = config.appInfo.AppCode,
                        userCode = config.userCode
                    },
                    body = new EventRegisterReqBody()
                    {
                        attachArgs = reqBody.attachArgs,
                        chainCode  = reqBody.chainCode,
                        eventKey   = reqBody.eventKey,
                        notifyUrl  = reqBody.notifyUrl
                    }
                };
                //assemble the original string to sign
                var data = ReqMacExtends.EventRegisterReqMac(req);
                //sign data
                req.mac = sign.Sign(data);

                var res = SendHelper.SendPost <NodeApiResBody <EventRegisterResBody> >(config.reqUrl + EventRegisterUrl, JsonConvert.SerializeObject(req), config.httpsCert);
                if (res != null)
                {
                    //check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, EventRegisterResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to be checked
                    var datares = ResMacExtends.EventRegisterResMac(res);

                    //verify data
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, EventRegisterResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, EventRegisterResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, EventRegisterResBody>(false, "failed to register chaincode event", null));
        }
Example #17
0
        /// <summary>
        /// get block data
        /// </summary>
        /// <param name="config"></param>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, GetBlockDataResBody> GetBlockData(GetBlockReqBody reqBody)
        {
            try
            {
                NodeApiReqBody <GetBlockReqBody> req = new NodeApiReqBody <GetBlockReqBody>()
                {
                    body = new GetBlockReqBody()
                    {
                        txId        = reqBody.txId,
                        blockHash   = reqBody.blockHash,
                        blockNumber = reqBody.blockNumber,
                        dataType    = reqBody.dataType
                    },
                    header = new ReqHeader()
                    {
                        appCode  = config.appInfo.AppCode,
                        userCode = config.userCode
                    }
                };
                //assemble the string to sign
                var data = ReqMacExtends.GetBlockInfoReqMac(req);
                //sign the data
                req.mac = sign.Sign(data);

                var res = SendHelper.SendPost <NodeApiResBody <GetBlockDataResBody> >(config.reqUrl + GetBlockDataUrl, JsonConvert.SerializeObject(req), config.httpsCert);
                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, GetBlockDataResBody>(false, res.header.msg, null));
                    }
                    //Assemble the original string to sign
                    var datares = ResMacExtends.GetBlockDataResMac(res);

                    //verify data
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, GetBlockDataResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, GetBlockDataResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, GetBlockDataResBody>(false, "failed to get block data", null));
        }
Example #18
0
        /// <summary>
        /// transaction processing under Key-Upload Mode
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, CitaTransResBody> SDKTrans(CitaTransReq reqBody)
        {
            try
            {
                if (config.appInfo.CAType == EmCAType.Trusteeship)
                {
                    return(new Tuple <bool, string, CitaTransResBody>(false, "the trusteeship application cannot call the api", null));
                }
                var tx = new CitaClient(config).GetTransData(reqBody);
                if (!string.IsNullOrEmpty(tx.Item2))
                {
                    return(new Tuple <bool, string, CitaTransResBody>(false, tx.Item2, null));
                }

                NodeApiReqBody <CitaTransReqBody> req = new NodeApiReqBody <CitaTransReqBody>
                {
                    header = GetReqHeader()
                };
                req.body = new CitaTransReqBody()
                {
                    ContractName = reqBody.Contract.ContractName,
                    TransData    = "0x" + tx.Item1
                };
                req.mac = sign.Sign(CitaReqMacExtends.GetSDKTransReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <CitaTransResBody> >(config.reqUrl + TransUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, CitaTransResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = CitaResMacExtends.GetCitaTransactionResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, CitaTransResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, CitaTransResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, CitaTransResBody>(false, "The deal failed", null));
        }
        public static string ReqChainCodeReqMac(NodeApiReqBody <CallContractReqDataReqDataBody> req)
        {
            StringBuilder strBuilder = new StringBuilder();

            strBuilder.Append(GetReqHeaderMac(req.header))
            .Append(req.body.UserId)
            .Append(req.body.UserAddr)
            .Append(req.body.ContractName)
            .Append(req.body.FuncName)
            .Append(req.body.FuncParam);

            return(strBuilder.ToString());
        }
Example #20
0
        /// <summary>
        /// user registration
        /// </summary>
        /// <param name="req">request content</param>
        /// <param name="url">interface address</param>
        /// <param name="certPath">https cert path</param>
        /// <returns></returns>
        public Tuple <bool, string, RegisterUserResBody> RegisterUser(RegisterUserReqBody reqBody)
        {
            try
            {
                NodeApiReqBody <RegisterUserReqBody> req = new NodeApiReqBody <RegisterUserReqBody>()
                {
                    body = new RegisterUserReqBody()
                    {
                        name             = reqBody.name,   //one user can only be registered once, the second call returns a failed registration
                        secret           = reqBody.secret, //If the password is empty, a random password will be returned. Users under Key Mode needs to store the returned random password and pass it in when registering the certificate
                        extendProperties = reqBody.extendProperties
                    },
                    header = new ReqHeader()
                    {
                        appCode  = config.appInfo.AppCode,
                        userCode = config.userCode
                    }
                };
                // assemble the orginal string to sign
                var data = ReqMacExtends.GetRegisterUserReqMac(req);
                //data signature
                req.mac = sign.Sign(data);

                var res = SendHelper.SendPost <NodeApiResBody <RegisterUserResBody> >(config.reqUrl + registerUserUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, RegisterUserResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = ResMacExtends.GetRegisterUserResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, RegisterUserResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, RegisterUserResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, RegisterUserResBody>(false, "failed to register the user", null));;
        }
Example #21
0
        /// <summary>
        /// event chaincode logout
        /// </summary>
        /// <param name="config"></param>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string> EventRemove(EventRemoveReqBody reqBody)
        {
            try
            {
                NodeApiReqBody <EventRemoveReqBody> req = new NodeApiReqBody <EventRemoveReqBody>
                {
                    header = new ReqHeader()
                    {
                        appCode  = config.appInfo.AppCode,
                        userCode = config.userCode
                    },
                    body = new EventRemoveReqBody()
                    {
                        eventId = reqBody.eventId
                    }
                };
                //assemble the original string to sign
                var data = ReqMacExtends.EventRemoveReqMac(req);
                //sign data
                req.mac = sign.Sign(data);

                var res = SendHelper.SendPost <NodeApiRes>(config.reqUrl + EventRemoveUrl, JsonConvert.SerializeObject(req), config.httpsCert);
                if (res != null)
                {
                    //check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string>(false, res.header.msg));
                    }
                    //assemble the original string to sign
                    var datares = ResMacExtends.GetResHeaderMac(res.header);

                    //verify data
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string>(true, res.header.msg));
                    }
                    else
                    {
                        return(new Tuple <bool, string>(false, "failed to sign the signature"));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string>(false, "failed to logout event chaincode"));
        }
Example #22
0
        /// <summary>
        /// transaction processing under Key-Upload Mode
        /// </summary>
        /// <param name="config"></param>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, ReqChainCodeResBody> Trans(TransRequest reqBody)
        {
            try
            {
                NodeApiReqBody <TransReqBody> req = new NodeApiReqBody <TransReqBody>()
                {
                    header = new ReqHeader()
                    {
                        appCode  = config.appInfo.AppCode,
                        userCode = config.userCode
                    },
                    body = new TransReqBody()
                    {
                        transData = Transaction.CreateRequest(config, reqBody)
                    }
                };
                //Assemble the original string to sign
                var data = ReqMacExtends.TransReqMac(req);
                //sign data
                req.mac = sign.Sign(data);

                var res = SendHelper.SendPost <NodeApiResBody <ReqChainCodeResBody> >(config.reqUrl + TransUrl, JsonConvert.SerializeObject(req), config.httpsCert);
                if (res != null)
                {
                    //check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, ReqChainCodeResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to sign
                    var datares = ResMacExtends.ReqChainCodeResMac(res);

                    //verify data
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, ReqChainCodeResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, ReqChainCodeResBody>(false, "failed to verify data", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, ReqChainCodeResBody>(false, "failed to process transactions under Key-Trust Mode", null));
        }
Example #23
0
        /// <summary>
        /// register an user
        /// </summary>
        public Tuple <bool, string, FiscoRegisterUserResBody> RegisterUser(FiscoRegisterReqBody reqBody)
        {
            try
            {
                NodeApiReqBody <FiscoRegisterReqBody> req = new NodeApiReqBody <FiscoRegisterReqBody>()
                {
                    body = new FiscoRegisterReqBody()
                    {
                        UserId = reqBody.UserId,//同一个用户名只能注册一次,第二次调用会返回注册失败
                    },
                    header = GetReqHeader()
                };
                //数据进行Base64编码
                req.mac = sign.Sign(FiscoReqMacExtends.GetRegisterUserReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <FiscoRegisterUserResBody> >(config.reqUrl + registerUserUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, FiscoRegisterUserResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = FiscoResMacExtends.GetRegisterUserResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, FiscoRegisterUserResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, FiscoRegisterUserResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, FiscoRegisterUserResBody>(false, "用户注册失败", null));;
        }
Example #24
0
        /// <summary>
        /// gets the total number of transactions in the block
        /// </summary>
        /// <returns></returns>
        public Tuple <bool, string, GetBlockHeightResBody> GetTxCountByBlockNumber(string blockNumber)
        {
            try
            {
                NodeApiReqBody <FiscoBlockReqDataBody> req = new NodeApiReqBody <FiscoBlockReqDataBody>
                {
                    header = GetReqHeader(),
                    body   = new FiscoBlockReqDataBody()
                    {
                        BlockNumber = blockNumber
                    }
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoBlockInfoReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <GetBlockHeightResBody> >(config.reqUrl + GetTxCountByBlockNumberUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, GetBlockHeightResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = FiscoResMacExtends.GetBlockHeightResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, GetBlockHeightResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, GetBlockHeightResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, GetBlockHeightResBody>(false, "failed to get the total number of transactions in the block", null));
        }
Example #25
0
        /// <summary>
        /// register an user
        /// </summary>
        public Tuple <bool, string, CitaRegisterUserResBody> RegisterUser(CitaRegisterReqBody reqBody)
        {
            try
            {
                NodeApiReqBody <CitaRegisterReqBody> req = new NodeApiReqBody <CitaRegisterReqBody>()
                {
                    body = new CitaRegisterReqBody()
                    {
                        UserId = reqBody.UserId,//one user can only be registered once, the second call returns a failed registration
                    },
                    header = GetReqHeader()
                };
                req.mac = sign.Sign(CitaReqMacExtends.GetRegisterUserReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <CitaRegisterUserResBody> >(config.reqUrl + registerUserUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, CitaRegisterUserResBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = CitaResMacExtends.GetRegisterUserResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, CitaRegisterUserResBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, CitaRegisterUserResBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, CitaRegisterUserResBody>(false, "failed to register the user", null));;
        }
        /// <summary>
        /// transactions under Key-Trust Mode
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, CallContractResDataBody> ReqChainCode(CallContractReqDataReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <CallContractReqDataReqDataBody> req = new NodeApiReqBody <CallContractReqDataReqDataBody>()
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };

                var data = XuperchainReqMacExtends.ReqChainCodeReqMac(req);

                req.mac = sign.Sign(data);
                var res = SendHelper.SendPost <NodeApiResBody <CallContractResDataBody> >(config.reqUrl + ReqChainCodeUrl, JsonConvert.SerializeObject(req), config.httpsCert);
                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, CallContractResDataBody>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = XuperchainResMacExtends.ReqChainCodeResMac(res);

                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, CallContractResDataBody>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, CallContractResDataBody>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, CallContractResDataBody>(false, "failed to transact", null));
        }
Example #27
0
        /// <summary>
        /// event  logout
        /// </summary>
        /// <returns></returns>
        public Tuple <bool, string, NodeApiRes> EventRemove(RemoveReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <RemoveReqDataBody> req = new NodeApiReqBody <RemoveReqDataBody>()
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoEventRemoveReqMac(req));
                var res = SendHelper.SendPost <NodeApiRes>(config.reqUrl + EventremoveUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, NodeApiRes>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = ResMacExtends.GetResHeaderMac(res.header);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, NodeApiRes>(true, res.header.msg, res));
                    }
                    else
                    {
                        return(new Tuple <bool, string, NodeApiRes>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, NodeApiRes>(false, "failed to logout event chaincode", null));
        }
Example #28
0
        /// <summary>
        /// get block info
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, FiscoBlockData> GetBlockInfo(FiscoBlockReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <FiscoBlockReqDataBody> req = new NodeApiReqBody <FiscoBlockReqDataBody>
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };
                req.mac = sign.Sign(FiscoReqMacExtends.GetFiscoBlockInfoReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <FiscoBlockData> >(config.reqUrl + BlockInfoUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, FiscoBlockData>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = FiscoResMacExtends.GetFiscoBlockInfoResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, FiscoBlockData>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, FiscoBlockData>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, FiscoBlockData>(false, "failed to get block info", null));
        }
Example #29
0
        /// <summary>
        /// event registration
        /// </summary>
        /// <param name="reqBody"></param>
        /// <returns></returns>
        public Tuple <bool, string, CitaRegisterEventResData> EventRegister(CitaRegisterEventReqDataBody reqBody)
        {
            try
            {
                NodeApiReqBody <CitaRegisterEventReqDataBody> req = new NodeApiReqBody <CitaRegisterEventReqDataBody>
                {
                    header = GetReqHeader(),
                    body   = reqBody
                };
                req.mac = sign.Sign(CitaReqMacExtends.GetCitaEventRegisterReqMac(req));
                var res = SendHelper.SendPost <NodeApiResBody <CitaRegisterEventResData> >(config.reqUrl + EventRegisterUrl, JsonConvert.SerializeObject(req), config.httpsCert);

                if (res != null)
                {
                    //Check the status codes in turn
                    if (res.header.code != 0)
                    {
                        return(new Tuple <bool, string, CitaRegisterEventResData>(false, res.header.msg, null));
                    }
                    //assemble the original string to verify
                    var datares = CitaResMacExtends.GetCitaEventRegisterResMac(res);
                    //data verified
                    if (sign.Verify(res.mac, datares))
                    {
                        return(new Tuple <bool, string, CitaRegisterEventResData>(true, res.header.msg, res.body));
                    }
                    else
                    {
                        return(new Tuple <bool, string, CitaRegisterEventResData>(false, "failed to verify the signature", null));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(new Tuple <bool, string, CitaRegisterEventResData>(false, "failed to register chaincode event", null));
        }