コード例 #1
0
        public async Task <RevealItem> Reveal(SignedItem item)
        {
            var revealItem = await storage.Get <RevealItem>(item.Sign);

            if (!cryptoService.VerifySignature(revealItem.ToString(), revealItem.Sign, revealItem.PubKey))
            {
                throw new ArgumentException("Invalid signature");
            }
            ;

            return(revealItem);
        }
コード例 #2
0
ファイル: DemoProtocolService.cs プロジェクト: SP8DE/protocol
        public async Task <ProtocolTransactionResponse> RevealTransaction(string transactionId, List <RevealItem> items)
        {
            var tx = await storage.Get <ProtocolTransactionResponse>(transactionId);

            var commitItem = tx.Items.First(x => x.PubKey == tx.Signer);

            items.Add(await storage.Get <RevealItem>(commitItem.Sign));

            foreach (var revealItem in items)
            {
                if (!cryptoService.VerifySignature(revealItem.ToString(), revealItem.Sign, revealItem.PubKey))
                {
                    throw new ArgumentException($"Invalid signature for {revealItem.PubKey}");
                }
                ;
            }

            var finishTx = new ProtocolTransactionResponse()
            {
                Id        = TxIdHelper.GenerateId(),
                DependsOn = transactionId,
                Signer    = keySecret.PublicAddress.ToLowerInvariant(),
                Items     = items.Select(x => new SignedItem()
                {
                    Type   = x.Type,
                    PubKey = x.PubKey,
                    Seed   = x.Seed,
                    Sign   = x.Sign,
                    Nonce  = x.Nonce,
                }).ToList()
            };

            await AddAnchors(finishTx);

            await storage.Add(finishTx.Id, finishTx);

            return(finishTx);
        }