SerializedBiscuit(byte[] authority, List <byte[]> blocks, List <RistrettoElement> keys, TokenSignature signature) { this.authority = authority; this.blocks = blocks; this.keys = keys; this.signature = signature; }
public Either <FormatError, SerializedBiscuit> Append(RNGCryptoServiceProvider rng, KeyPair keypair, Block block) { Format.Schema.Block b = block.Serialize(); try { MemoryStream stream = new MemoryStream(); b.WriteTo(stream); byte[] data = stream.ToArray(); TokenSignature signature = this.signature.Sign(rng, keypair, data); List <RistrettoElement> keys = new List <RistrettoElement>(); keys.AddRange(this.keys); keys.Add(keypair.PublicKey); List <byte[]> blocks = new List <byte[]>(); blocks.AddRange(this.blocks); blocks.Add(data); return(new Right(new SerializedBiscuit(authority, blocks, keys, signature))); } catch (IOException e) { return(new Left(new SerializationError(e.ToString()))); } }
public Notification( IUserRepository userRepository, IEmailSender emailSender) { _userRepository = userRepository; _emailSender = emailSender; _web3 = new Web3("https://ropsten.infura.io/E8XftGiqmaErL2KN5Cp3"); _unitConversion = new UnitConversion(); _tokenSignature = new TokenSignature(); Addresses = new ConcurrentDictionary <BigInteger, NotificationModel>(); Task.Run(async() => await FillAddress()); }
private async Task NotifyEyEmail(Transaction transactions, NotificationModel user, string to, BigInteger value) { string tokenSymbol = "Ether"; if (TokenSignature.IsTransfer(transactions.Input)) { var contract = _web3.Eth.GetContract(TokenSignature.StandartABI, transactions.To); tokenSymbol = _tokenSignature.GetTokenSymbol(contract).Result; } await _emailSender.SendEmailAsync(user.Email, "Guapcoin Notification Service", "Guapcoin\n\n" + $"You received {_unitConversion.FromWei(value)} {tokenSymbol}, in your address {to}.\n\n" + "For detailed information please open this link: " + $"https://ropsten.etherscan.io/tx/{transactions.TransactionHash}\n\n"); }
/// <summary> /// Deserializes a SerializedBiscuit from a byte array /// </summary> /// <param name="slice"></param> /// <returns></returns> static public Either <Error, SerializedBiscuit> FromBytes(byte[] slice) { try { Format.Schema.Biscuit data = Format.Schema.Biscuit.Parser.ParseFrom(slice); List <RistrettoElement> keys = data.Keys .Select(key => new CompressedRistretto(key.ToByteArray()).Decompress()) .ToList(); byte[] authority = data.Authority.ToByteArray(); List <byte[]> blocks = data.Blocks.Select(block => block.ToByteArray()).ToList(); Either <Error, TokenSignature> signatureRes = TokenSignature.Deserialize(data.Signature); if (signatureRes.IsLeft) { return(signatureRes.Left); } TokenSignature signature = signatureRes.Right; SerializedBiscuit biscuitResult = new SerializedBiscuit(authority, blocks, keys, signature); Either <Error, Void> res = biscuitResult.Verify(); if (res.IsLeft) { return(res.Left); } else { return(biscuitResult); } } catch (InvalidProtocolBufferException e) { return(new DeserializationError(e.ToString())); } catch (InvalidEncodingException e) { return(new DeserializationError(e.ToString())); } }
static public Either <FormatError, SerializedBiscuit> Make(RNGCryptoServiceProvider rng, KeyPair root, Block authority) { Format.Schema.Block b = authority.Serialize(); try { using MemoryStream stream = new MemoryStream(); b.WriteTo(stream); byte[] data = stream.ToArray(); TokenSignature signature = new TokenSignature(rng, root, data); List <RistrettoElement> keys = new List <RistrettoElement> { root.PublicKey }; return(new SerializedBiscuit(data, new List <byte[]>(), keys, signature)); } catch (IOException e) { return(new SerializationError(e.ToString())); } }
private async Task ProcessBlockNumber(BigInteger newBlock) { var transactions = await _web3.Eth.Blocks.GetBlockWithTransactionsByNumber .SendRequestAsync(new HexBigInteger(newBlock)); if (transactions != null) { foreach (var it in transactions.Transactions) { if (string.IsNullOrEmpty(it.To)) { continue; } string to; BigInteger value; if (TokenSignature.IsTransfer(it.Input)) { to = TokenSignature.TransferTo(it.Input); value = TokenSignature.TransferValue(it.Input); } else { to = it.To; value = it.Value.Value; } if (Addresses.TryGetValue(new HexBigInteger(to).Value, out var notifData)) { if (notifData.NotificationsEnabled) { await NotifyEyEmail(it, notifData, to, value); } } } } }