Example #1
0
        private void SetupIdentityProviders(ScenarioDefinition scenarioDefinition, long scenarioSessionId)
        {
            foreach (var scenarioAccount in scenarioDefinition.Setup.Accounts.Where(a => a.AccountType == AccountType.IdentityProvider))
            {
                long accountId = _accountsService.Create(AccountType.IdentityProvider, scenarioAccount.AccountInfo, "qqq", true);
                _dataAccessService.AddScenarionSessionAccount(scenarioSessionId, accountId);
                AccountDescriptor accountDescriptor = _accountsService.Authenticate(accountId, "qqq");
                _executionContextManager.InitializeStateExecutionServices(accountId, accountDescriptor.SecretSpendKey);

                foreach (var attributeScheme in scenarioAccount.IdentityScheme)
                {
                    long schemeId = _dataAccessService.AddAttributeToScheme(accountDescriptor.PublicSpendKey.ToHexString(), attributeScheme.AttributeName, attributeScheme.AttributeSchemeName, attributeScheme.Alias, null);

                    if (attributeScheme.CanBeRoot)
                    {
                        _dataAccessService.ToggleOnRootAttributeScheme(schemeId);
                    }
                }

                IdentitiesScheme rootScheme = _dataAccessService.GetRootIdentityScheme(accountDescriptor.PublicSpendKey.ToHexString());
                foreach (var identity in scenarioAccount.Identities)
                {
                    IEnumerable <(string attributeName, string content)> attrs = GetAttribitesAndContent(identity, accountDescriptor);
                    Identity identityDb = _dataAccessService.CreateIdentity(accountDescriptor.AccountId, identity.Alias, attrs.ToArray());
                }
            }
        }
Example #2
0
        public async Task <IActionResult> CreateIdentity(long accountId, [FromBody] IdentityDto identity)
        {
            //StatePersistency statePersistency = _executionContextManager.ResolveStateExecutionServices(accountId);
            AccountDescriptor account = _accountsService.GetById(accountId);

            //byte[] assetId = await _assetsService.GenerateAssetId(identity.RootAttribute.SchemeName, identity.RootAttribute.Content, account.PublicSpendKey.ToHexString()).ConfigureAwait(false);
            //statePersistency.TransactionsService.IssueBlindedAsset(assetId, 0UL.ToByteArray(32), out byte[] originatingCommitment);
            //identity.RootAttribute.OriginatingCommitment = originatingCommitment.ToHexString();

            IEnumerable <(string attributeName, string content)> attrs = await GetAttribitesAndContent(identity, account).ConfigureAwait(false);

            Identity identityDb = _dataAccessService.CreateIdentity(account.AccountId, identity.Description, attrs.ToArray());

            identity.Id = identityDb.IdentityId.ToString(CultureInfo.InvariantCulture);

            return(Ok(identity.Id));
        }
Example #3
0
        private Identity CreateIdentityInDb(AccountDescriptor account, IEnumerable <AttributeIssuanceDetails> issuanceInputDetails)
        {
            var      rootAttributeDetails = issuanceInputDetails.First(a => a.Definition.IsRoot);
            Identity identity             = _dataAccessService.GetIdentityByAttribute(account.AccountId, rootAttributeDetails.Definition.AttributeName, rootAttributeDetails.Value.Value);

            if (identity == null)
            {
                _dataAccessService.CreateIdentity(account.AccountId,
                                                  rootAttributeDetails.Value.Value,
                                                  issuanceInputDetails.Select(d => (d.Definition.AttributeName, d.Value.Value)).ToArray());
                identity = _dataAccessService.GetIdentityByAttribute(account.AccountId, rootAttributeDetails.Definition.AttributeName, rootAttributeDetails.Value.Value);
            }

            return(identity);
        }
Example #4
0
        public IActionResult CreateIdentity([FromBody] IdentityDto identity)
        {
            ulong accountId = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture);

            StatePersistency statePersistency = _executionContextManager.ResolveStateExecutionServices(accountId);
            Account          account          = _accountsService.GetById(accountId);

            byte[] assetId = _assetsService.GenerateAssetId((AttributeType)identity.RootAttribute.AttributeType, identity.RootAttribute.Content);
            statePersistency.TransactionsService.IssueBlindedAsset(assetId, 0UL.ToByteArray(32), out byte[] originatingCommitment);
            identity.RootAttribute.OriginatingCommitment = originatingCommitment.ToHexString();

            Identity identityDb = _externalDataAccessService.CreateIdentity(accountId, identity.Description, new IdentityAttribute {
                AttributeType = AttributeType.IdCard, Content = identity.RootAttribute.Content, Subject = ClaimSubject.User, Commitment = originatingCommitment
            });

            identity.Id = identityDb.IdentityId.ToString(CultureInfo.InvariantCulture);

            string imageContent = null;

            foreach (var identityAttributeDto in identity.AssociatedAttributes)
            {
                IdentityAttribute identityAttribute = new IdentityAttribute
                {
                    AttributeType = (AttributeType)identityAttributeDto.AttributeType,
                    Content       = identityAttributeDto.Content,
                    Subject       = ClaimSubject.User
                };
                _externalDataAccessService.AddAssociatedIdentityAttribute(identityDb.IdentityId, ref identityAttribute);

                if (((AttributeType)identityAttributeDto.AttributeType) == AttributeType.PassportPhoto)
                {
                    imageContent = identityAttributeDto.Content;
                }
            }

            if (!string.IsNullOrEmpty(identity.RootAttribute.Content) && !string.IsNullOrEmpty(imageContent))
            {
                $"{Request.Scheme}://{Request.Host.ToUriComponent()}/biometric/".AppendPathSegment("RegisterPerson").PostJsonAsync(new BiometricPersonDataDto {
                    Requester = account.PublicSpendKey.ToHexString(), PersonData = identity.RootAttribute.Content, ImageString = imageContent
                });
            }

            _hubContext.Clients.Group(User.Identity.Name).SendAsync("PushIdentity", identity);

            return(Ok());
        }