Esempio n. 1
0
        public (long registrationId, bool isNew) HandleAccount(long accountId, Memory <byte> assetCommitment, SurjectionProof authenticationProof)
        {
            if (_dataAccessService.GetServiceProviderRegistrationId(accountId, authenticationProof.AssetCommitments[0], out long registrationId))
            {
                bool isAuthenticationProofValid = ConfidentialAssetsHelper.VerifySurjectionProof(authenticationProof, assetCommitment.Span);

                if (!isAuthenticationProofValid)
                {
                    throw new SpAuthenticationProofsFailedException();
                }

                return(registrationId, false);
            }
            else
            {
                long id = _dataAccessService.AddServiceProviderRegistration(accountId, authenticationProof.AssetCommitments[0]);
                return(id, true);
            }
        }
Esempio n. 2
0
        private void ProcessOnboarding(OnboardingRequest packet)
        {
            _clientCryptoService.DecodeEcdhTuple(packet.EcdhTuple, packet.TransactionPublicKey, out byte[] blindingFactor, out byte[] assetId, out byte[] issuer, out byte[] payload);
            string sessionKey = payload.ToHexString();

            if (_dataAccessService.GetServiceProviderRegistrationId(_accountId, packet.AssetCommitment, out ulong registrationId))
            {
                _idenitiesHubContext.Clients.Group(sessionKey).SendAsync("PushUserAlreadyRegistered", new ServiceProviderRegistrationDto {
                    ServiceProviderRegistrationId = registrationId.ToString(CultureInfo.InvariantCulture), Commitment = packet.AssetCommitment.ToHexString()
                });
            }
            else
            {
                AttributeType attributeType = _assetsService.GetAttributeType(assetId);

                bool isEligibilityCorrect = CheckEligibilityProofs(packet.AssetCommitment, packet.EligibilityProof, issuer);

                if (!isEligibilityCorrect)
                {
                    _idenitiesHubContext.Clients.Group(sessionKey).SendAsync("PushSpAuthorizationFailed", new { Code = 2, Message = "Eligibility proofs were wrong" }).Wait();
                    return;
                }

                IEnumerable <SpIdenitityValidation> spIdenitityValidations = _dataAccessService.GetSpIdenitityValidations(_accountId);
                if (!CheckSpIdentityValidations(packet.AssetCommitment, packet.AssociatedProofs, spIdenitityValidations, sessionKey))
                {
                    return;
                }

                ulong id = _dataAccessService.AddServiceProviderRegistration(_accountId, packet.AssetCommitment);
                _idenitiesHubContext.Clients.Group(_accountId.ToString(CultureInfo.InvariantCulture)).SendAsync("PushRegistration", new ServiceProviderRegistrationDto {
                    ServiceProviderRegistrationId = id.ToString(CultureInfo.InvariantCulture), Commitment = packet.AssetCommitment.ToHexString()
                });
                _idenitiesHubContext.Clients.Group(sessionKey).SendAsync("PushUserRegistration", new ServiceProviderRegistrationDto {
                    ServiceProviderRegistrationId = id.ToString(CultureInfo.InvariantCulture), Commitment = packet.AssetCommitment.ToHexString()
                });
            }
        }