예제 #1
0
        public UserIdentitiesUpdater(ulong accountId, IUtxoClientCryptoService clientCryptoService, IAssetsService assetsService, IDataAccessService externalDataAccessService, IHubContext <IdentitiesHub> idenitiesHubContext, IRelationsProofsValidationService relationsProofsValidationService, ITrackingService trackingService)
        {
            _accountId           = accountId;
            _clientCryptoService = clientCryptoService;
            _assetsService       = assetsService;
            _dataAccessService   = externalDataAccessService;
            _idenitiesHubContext = idenitiesHubContext;
            _relationsProofsValidationService = relationsProofsValidationService;
            _trackingService = trackingService;
            PipeIn           = new ActionBlock <PacketBase>(p =>
            {
                try
                {
                    if (p is TransferAssetToUtxo packet)
                    {
                        _clientCryptoService.DecodeEcdhTuple(packet.TransferredAsset.EcdhTuple, packet.TransactionPublicKey, out byte[] blindingFactor, out byte[] assetId);
                        AttributeType attributeType = _assetsService.GetAttributeType(assetId);

                        _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushAttribute", new UserAttributeDto {
                            AttributeType = attributeType.ToString(), Source = packet.Signer.ArraySegment.Array.ToHexString(), AssetId = assetId.ToHexString(), OriginalBlindingFactor = blindingFactor.ToHexString(), OriginalCommitment = packet.TransferredAsset.AssetCommitment.ToHexString(), LastBlindingFactor = blindingFactor.ToHexString(), LastCommitment = packet.TransferredAsset.AssetCommitment.ToHexString(), LastTransactionKey = packet.TransactionPublicKey.ToHexString(), LastDestinationKey = packet.DestinationKey.ToHexString(), Validated = false, IsOverriden = false
                        });
                    }
                    else if (p is GroupsRelationsProofs relationsProofs && _clientCryptoService.CheckTarget(relationsProofs.DestinationKey2, relationsProofs.TransactionPublicKey))
                    {
                        RelationProofsValidationResults validationResults = _relationsProofsValidationService.VerifyRelationProofs(relationsProofs, _clientCryptoService);

                        _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushRelationValidation", validationResults);
                    }
                }
                catch
                {
                }
            });
        }
예제 #2
0
        public RelationProofsValidationResults VerifyRelationProofs(GroupsRelationsProofs relationsProofs, IUtxoClientCryptoService clientCryptoService)
        {
            //TODO: need to add eligibility proofs

            RelationProofsValidationResults validationResults = new RelationProofsValidationResults();

            clientCryptoService.DecodeEcdhTuple(relationsProofs.EcdhTuple, relationsProofs.TransactionPublicKey, out byte[] sessionKey, out byte[] imageHash);

            RelationProofSession proofSession = _gatewayService.PopRelationProofSession(sessionKey.ToHexString());

            byte[] image = Convert.FromBase64String(proofSession.ImageContent);
            validationResults.ImageContent = proofSession.ImageContent;
            byte[] imageHashFromSession = ConfidentialAssetsHelper.FastHash256(image);

            validationResults.IsImageCorrect = imageHashFromSession.Equals32(imageHash);

            foreach (var relationEntry in proofSession.RelationEntries)
            {
                bool isRelationContentMatching = false;

                foreach (var relationProof in relationsProofs.RelationProofs)
                {
                    byte[] registrationCommitment = relationProof.RelationProof.AssetCommitments[0];
                    byte[] groupNameCommitment    = _gatewayService.GetEmployeeRecordGroup(relationProof.GroupOwner, registrationCommitment);
                    bool   isRelationProofCorrect = groupNameCommitment != null?ConfidentialAssetsHelper.VerifySurjectionProof(relationProof.RelationProof, relationsProofs.AssetCommitment) : false;

                    if (isRelationProofCorrect)
                    {
                        byte[] relationAssetId = _assetsService.GenerateAssetId(AttributeType.EmployeeGroup, relationProof.GroupOwner.ToHexString() + relationEntry.RelatedAssetName);
                        if (ConfidentialAssetsHelper.VerifyIssuanceSurjectionProof(relationProof.GroupNameProof, groupNameCommitment, new byte[][] { relationAssetId }))
                        {
                            isRelationContentMatching = true;
                            break;
                        }
                    }
                }

                validationResults.ValidationResults.Add(new RelationProofValidationResult {
                    RelatedAttributeOwner = relationEntry.RelatedAssetOwnerName, RelatedAttributeContent = relationEntry.RelatedAssetName, IsRelationCorrect = isRelationContentMatching
                });
            }

            return(validationResults);
        }