Beispiel #1
0
        public static async Task <OwnershipVerificationCodeDto> GetCodeInDto(string txid, EncryptionKey key)
        {
            var dto = new OwnershipVerificationCodeDto();

            dto.TxId      = txid;
            dto.Signature = (await GetCode(txid, key)).Item2;
            return(dto);
        }
Beispiel #2
0
        /*
         * public static async Task<(bool,(OwnershipVerificationCodeDto,byte[]))> GetQRCode(string txid, EncryptionKey key)
         * {
         *  var signature = await GetCode(txid, key);
         *  if (signature.Item1)
         *  {
         *      var dto = new OwnershipVerificationCodeDto();
         *      dto.TxId = txid;
         *      dto.Signature = signature.Item2;
         *      var dtos = JsonConvert.SerializeObject(dto);
         *      if (dtos != null)
         *      {
         *          QRCodeData qrCodeData = qrGenerator.CreateQrCode(dtos, QRCodeGenerator.ECCLevel.Q);
         *          var qrCode = new BitmapByteQRCode(qrCodeData);
         *          var g = qrCode.GetGraphic(20);
         *          return (true, (dto, g));
         *      }
         *  }
         *  return (false, (null, null));
         * }
         */

        public static async Task <OwnershipVerificationResult> VerifyOwner(OwnershipVerificationCodeDto dto)
        {
            var msg = CreateMessage(dto.TxId);
            var res = await NFTHelpers.GetNFTWithOwner(dto.TxId);

            if (res.Item1)
            {
                //var ownerpubkey = await NFTHelpers.GetPubKeyFromProfileNFTTx(res.Item2.Owner);

                /*var ownerpubkey = await NFTHelpers.GetPubKeyFromLastFoundTx(res.Item2.Owner);
                 * if (!ownerpubkey.Item1)
                 *  return new OwnershipVerificationResult()
                 *  {
                 *      Owner = res.Item2.Owner,
                 *      Sender = res.Item2.Sender,
                 *      NFT = res.Item2.NFT,
                 *      Message = msg,
                 *      VerifyResult = "Cannot get owner pubkey. He probably did not allow this function."
                 *  };*/

                var r = await ECDSAProvider.VerifyMessage(msg, dto.Signature, res.Item2.Owner);

                if (r.Item1)
                {
                    return(new OwnershipVerificationResult()
                    {
                        Owner = res.Item2.Owner,
                        Sender = res.Item2.Sender,
                        NFT = res.Item2.NFT,
                        Message = msg,
                        VerifyResult = "Verified. This is owner. Signature is valid."
                    });
                }
                else
                {
                    if (r.Item2 != null)
                    {
                        return new OwnershipVerificationResult()
                               {
                                   Owner        = res.Item2.Owner,
                                   Sender       = res.Item2.Sender,
                                   NFT          = res.Item2.NFT,
                                   Message      = msg,
                                   VerifyResult = "Not Owner of NFT or provided signature is no longer valid."
                               }
                    }
                    ;
                }
            }
            return(new OwnershipVerificationResult()
            {
                VerifyResult = "Not Valid input."
            });
        }
Beispiel #3
0
        public static async Task <(bool, (OwnershipVerificationCodeDto, byte[]))> GetQRCode(string txid, NBitcoin.BitcoinSecret key)
        {
            var signature = await GetCode(txid, key);

            if (signature.Item1)
            {
                var dto = new OwnershipVerificationCodeDto();
                dto.TxId      = txid;
                dto.Signature = signature.Item2;
                var dtos = JsonConvert.SerializeObject(dto);
                if (dtos != null)
                {
                    //QRCodeData qrCodeData = qrGenerator.CreateQrCode(dtos, QRCodeGenerator.ECCLevel.Q);
                    //var qrCode = new BitmapByteQRCode(qrCodeData);
                    //var g = qrCode.GetGraphic(20);

                    return(true, (dto, new byte[0]));
                }
            }
            return(false, (null, null));
        }