Example #1
0
        private bool CheckSpIdentityValidation(byte[] commitment, AssociatedProofs[] associatedProofsList, SpIdenitityValidation spIdentityValidation, string sessionKey)
        {
            byte[] groupId = _identityAttributesService.GetGroupId(spIdentityValidation.AttributeType);

            AssociatedProofs associatedProofs = associatedProofsList.FirstOrDefault(P => P.AssociatedAssetGroupId.Equals32(groupId));

            if (associatedProofs == null)
            {
                _idenitiesHubContext.Clients.Group(sessionKey).SendAsync("PushSpAuthorizationFailed", new { Code = 3, Message = "Validation proofs were not complete" }).Wait();
                return(false);
            }

            bool associatedProofValid;

            if (associatedProofs is AssociatedAssetProofs associatedAssetProofs)
            {
                associatedProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(associatedAssetProofs.AssociationProofs, associatedAssetProofs.AssociatedAssetCommitment);
            }
            else
            {
                associatedProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(associatedProofs.AssociationProofs, commitment);
            }

            bool rootProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(associatedProofs.RootProofs, commitment);

            if (!rootProofValid || !associatedProofValid)
            {
                _idenitiesHubContext.Clients.Group(sessionKey).SendAsync("PushSpAuthorizationFailed", new { Code = 3, Message = "Validation proofs were not correct" }).Wait();
                return(false);
            }

            //TODO: !!! adjust checking either against Gateway or against local database
            bool found = true;             // associatedProofs.AssociationProofs.AssetCommitments.Any(a => associatedProofs.RootProofs.AssetCommitments.Any(r => _dataAccessService.CheckAssociatedAtributeExist(null, a, r)));

            if (!found)
            {
                _idenitiesHubContext.Clients.Group(sessionKey).SendAsync("PushSpAuthorizationFailed", new { Code = 3, Message = "Validation proofs were not correct" }).Wait();
                return(false);
            }

            return(true);
        }
Example #2
0
        private async Task CheckSpIdentityValidation(Memory <byte> commitment, AssociatedProofs[] associatedProofsList, SpIdenitityValidation spIdentityValidation, string issuer)
        {
            byte[] groupId = await _identityAttributesService.GetGroupId(spIdentityValidation.SchemeName, issuer).ConfigureAwait(false);

            AssociatedProofs associatedProofs = associatedProofsList.FirstOrDefault(P => P.AssociatedAssetGroupId.Equals32(groupId));

            if (associatedProofs == null)
            {
                throw new ValidationProofsWereNotCompleteException(spIdentityValidation);
            }

            bool associatedProofValid;

            if (associatedProofs is AssociatedAssetProofs associatedAssetProofs)
            {
                associatedProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(associatedAssetProofs.AssociationProofs, associatedAssetProofs.AssociatedAssetCommitment);
            }
            else
            {
                associatedProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(associatedProofs.AssociationProofs, commitment.Span);
            }

            bool rootProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(associatedProofs.RootProofs, commitment.Span);

            if (!rootProofValid || !associatedProofValid)
            {
                throw new ValidationProofFailedException(spIdentityValidation);
            }

            //TODO: !!! adjust checking either against Gateway or against local database
            bool found = true; // associatedProofs.AssociationProofs.AssetCommitments.Any(a => associatedProofs.RootProofs.AssetCommitments.Any(r => _dataAccessService.CheckAssociatedAtributeExist(null, a, r)));

            if (!found)
            {
                throw new ValidationProofFailedException(spIdentityValidation);
            }
        }
Example #3
0
        protected override Memory <byte> ParseUtxoConfidential(ushort version, Memory <byte> spanBody, out UtxoConfidentialBase utxoConfidentialBase)
        {
            UtxoConfidentialBase block = null;

            if (version == 1)
            {
                int readBytes = 0;

                ReadCommitment(ref spanBody, ref readBytes, out byte[] assetCommitment);
                ReadEcdhTupleProofs(ref spanBody, ref readBytes, out EcdhTupleProofs ecdhTuple);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof ownershipProofs);
                ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof eligibilityProofs);

                byte associatedProofsCount = spanBody.Slice(readBytes++).Span[0];

                AssociatedProofs[] associatedProofs = new AssociatedProofs[associatedProofsCount];

                for (int i = 0; i < associatedProofsCount; i++)
                {
                    byte associatedProofType = spanBody.Slice(readBytes++).Span[0];

                    AssociatedProofs associatedProof;

                    if (associatedProofType == 1)
                    {
                        ReadCommitment(ref spanBody, ref readBytes, out byte[] associatedAssetCommitment);
                        associatedProof = new AssociatedAssetProofs
                        {
                            AssociatedAssetCommitment = associatedAssetCommitment
                        };
                    }
                    else
                    {
                        associatedProof = new AssociatedProofs();
                    }

                    ReadCommitment(ref spanBody, ref readBytes, out byte[] associatedGroupId);
                    ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof associationProofs);
                    ReadSurjectionProof(ref spanBody, ref readBytes, out SurjectionProof rootProofs);

                    associatedProof.AssociatedAssetGroupId = associatedGroupId;
                    associatedProof.AssociationProofs      = associationProofs;
                    associatedProof.RootProofs             = rootProofs;

                    associatedProofs[i] = associatedProof;
                }

                block = new TransitionOnboardingDisclosingProofs
                {
                    AssetCommitment  = assetCommitment,
                    EcdhTuple        = ecdhTuple,
                    OwnershipProof   = ownershipProofs,
                    EligibilityProof = eligibilityProofs,
                    AssociatedProofs = associatedProofs
                };

                utxoConfidentialBase = block;

                return(spanBody.Slice(readBytes));
            }

            throw new BlockVersionNotSupportedException(version, BlockType);
        }