コード例 #1
0
ファイル: client.cs プロジェクト: yucaowang/xuper-sdk-csharp
        public bool SetAccountByPath(string path)
        {
            try
            {
                using (StreamReader sr = new StreamReader(path + "/address"))
                {
                    var addr = sr.ReadToEnd();
                    this.account.Address = addr;
                }
                using (StreamReader sr = new StreamReader(path + "/private.key"))
                {
                    var privkeyStr = sr.ReadToEnd();
                    var privkey    = new AccountPrivateKey();
                    privkey.ParseJSON(privkeyStr);
                    this.account.PrivateKey = privkey;
                }
                using (StreamReader sr = new StreamReader(path + "/public.key"))
                {
                    var pubkeyStr = sr.ReadToEnd();
                    var pubkey    = new AccountPublicKey();
                    pubkey.ParseJSON(pubkeyStr);
                    this.account.PublicKey = pubkey;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception in SetAccountByPath, err=" + e);
                return(false);
            }

            return(true);
        }
コード例 #2
0
ファイル: crypto.cs プロジェクト: qizheng09/xuper-sdk-csharp
        /// <summary>VerifySign verify ASN.1 DER encoded signature using given public key with data</summary>
        public static bool VerifySign(AccountPublicKey publicKey, byte[] sign, byte[] data)
        {
            var decodedSign = Asn1DecodeSign(sign);
            var ecdsa       = loadECDSAFromPublicKey(publicKey);

            return(ecdsa.VerifyHash(data, decodedSign));
        }
コード例 #3
0
ファイル: crypto.cs プロジェクト: qizheng09/xuper-sdk-csharp
        private static ECDsa loadECDSAFromPublicKey(AccountPublicKey publicKey)
        {
            var param = new ECParameters
            {
                Curve = ECCurve.NamedCurves.nistP256,
                Q     = new ECPoint
                {
                    X = XConvert.GetECBytesFromBigInteger(publicKey.X),
                    Y = XConvert.GetECBytesFromBigInteger(publicKey.Y),
                },
            };

            return(ECDsa.Create(param));
        }
コード例 #4
0
        private Pb.UtxoOutput SelectUTXO(string bcname, string address, AccountPublicKey pubkey, BigInteger amount)
        {
            var reqData = new Pb.UtxoInput()
            {
                Header    = GetDefaultHeader(),
                Bcname    = bcname,
                Address   = address,
                TotalNeed = amount.ToString(),
                NeedLock  = false,
            };
            var res = client.SelectUTXO(reqData);

            if (res.Header.Error != Pb.XChainErrorEnum.Success)
            {
                Console.WriteLine("Error in select UTXO, errcode=" + (int)res.Header.Error + ", logid=" + reqData.Header.Logid);
                return(null);
            }
            return(res);
        }