Esempio n. 1
0
        public Coin Create(Transfer transfer, Coin coin, string privateRSAKey)
        {
            string sig = transfer.Signature;

            transfer.Signature = null;
            string jTransfer   = JsonConvert.SerializeObject(transfer);
            bool   canTransfer = false;

            for (int i = 0; i < coin.Holders.Count; i++)
            {
                if (CoinTools.ECVerify(jTransfer, sig, coin.Holders[i].PublicKey))
                {
                    canTransfer = true;
                }
            }

            if (canTransfer)
            {
                //Perform transfer
                coin.Holders    = transfer.Holders;
                coin.HolderHash = null;
                string jCoin = JsonConvert.SerializeObject(coin);
                coin.HolderHash = CoinTools.ECSign(jCoin, privateRSAKey);
            }

            return(coin);
        }
Esempio n. 2
0
        public Coin Create(string issuingAuthority, string countryCode, string currencyCode, string purposeCode, decimal value, string privateKey, List <string> publicKey)
        {
            Coin coin = new Coin()
            {
                CountryCode = countryCode, IssueDate = DateTime.UtcNow, CurrencyCode = currencyCode, PurposeCode = purposeCode, IssuingAuthority = issuingAuthority, SerialNumber = Guid.NewGuid(), Value = value, Holders = new List <Holder>()
            };

            string jCoin = JsonConvert.SerializeObject(coin);

            coin.IssuingHash = CoinTools.ECSign(jCoin, privateKey);

            for (int i = 0; i < publicKey.Count; i++)
            {
                coin.Holders.Add(new Holder()
                {
                    PublicKey = publicKey[i]
                });
            }

            jCoin           = JsonConvert.SerializeObject(coin);
            coin.HolderHash = CoinTools.ECSign(jCoin, privateKey);

            return(coin);
        }