예제 #1
0
        // Creates, encrypts and saves a new contract in the database as block
        // Currently not used - implementation pending
        public void ConcludeContract(Contract contract)
        {
            // Parse contract into json string
            var jsonToString = JsonConvert.SerializeObject(contract);

            // Encrypt string
            var encryptedData     = CryptographyService.Encrypt(jsonToString);
            var encryptedContract = encryptedData[0];
            var secretKey         = encryptedData[1];

            // Save block in the database
            var lastBlock      = _blockchainDataAccess.FindLast();
            var lastBlockIndex = lastBlock.Index;
            var lastBlockHash  = lastBlock.Hash;
            var newBlockIndex  = (Convert.ToInt64(lastBlockIndex) + 1).ToString();

            _blockchainDataAccess.Insert(new Block(newBlockIndex, encryptedContract, lastBlockHash));

            // Encrypt and send the secret key to all users included in the contract
            var signatures = (List <dynamic>)contract.Essentials["signatures"];

            foreach (var signature in signatures.Select(hashMap => (Dictionary <string, dynamic>)hashMap))
            {
                foreach (var(key, value) in signature)
                {
                    if (!key.Equals("signer") && !key.Equals("onBehalfOf"))
                    {
                        continue;
                    }
                    var encryptedSecret          = CryptographyService.EncryptWithPublicKey(secretKey, (string)value);
                    var userToBeUpdated          = _usersDataAccess.FindByPublicKey((string)value);
                    var userCorrespondingIndices = userToBeUpdated.CorrespondingIndices;
                    userCorrespondingIndices[newBlockIndex] = encryptedSecret;
                    _usersDataAccess.Update(userToBeUpdated);
                }
            }
        }
예제 #2
0
 public void Update(User user)
 {
     _usersDataAccess.Update(user);
 }