public IActionResult ProcessRootIdentityRequest(string issuer, [FromBody] IdentityRequestDto identityRequest) { Account identityProviderAccount = _accountsService.GetByPublicKey(issuer.HexStringToByteArray()); StatePersistency statePersistency = _executionContextManager.ResolveStateExecutionServices(identityProviderAccount.AccountId); Tuple <bool, bool> proceed = VerifyFaceImage(identityRequest.FaceImageContent, identityRequest.RootAttributeContent, issuer); if (proceed.Item1) { byte[] rootAssetId = _assetsService.GenerateAssetId(AttributeType.IdCard, identityRequest.RootAttributeContent); byte[] faceImageAssetId = _assetsService.GenerateAssetId(AttributeType.PassportPhoto, identityRequest.FaceImageContent); ProcessIssuingAssociatedAttributes(identityRequest, statePersistency.TransactionsService, rootAssetId, faceImageAssetId); return(TransferAssetToUtxo(statePersistency.TransactionsService, new ConfidentialAccount { PublicSpendKey = identityRequest.RequesterPublicSpendKey.HexStringToByteArray(), PublicViewKey = identityRequest.RequesterPublicViewKey.HexStringToByteArray() }, rootAssetId)); } else { if (!proceed.Item2) { return(BadRequest(new { Message = $"Failed to find person with ID Card number {identityRequest.RootAttributeContent}" })); } return(BadRequest(new { Message = "Captured face does not match to registered one" })); } }
public IActionResult RequestForIdentity([FromBody] RequestForIdentityDto requestForIdentity) { ulong accountId = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture); Account account = _accountsService.GetById(accountId); string blindingFactorSeedString = $"{requestForIdentity.IdCardContent}{requestForIdentity.Password}"; byte[] blindingFactorSeed = ConfidentialAssetsHelper.FastHash256(Encoding.ASCII.GetBytes(blindingFactorSeedString)); byte[] blindingFactor = ConfidentialAssetsHelper.ReduceScalar32(blindingFactorSeed); byte[] blindingPoint = ConfidentialAssetsHelper.GetPublicKey(blindingFactor); IdentityRequestDto identityRequest = new IdentityRequestDto { RequesterPublicSpendKey = account.PublicSpendKey.ToHexString(), RequesterPublicViewKey = account.PublicViewKey.ToHexString(), RootAttributeContent = requestForIdentity.IdCardContent, BlindingPoint = blindingPoint.ToHexString(), FaceImageContent = requestForIdentity.ImageContent }; byte[] b = Convert.FromBase64String(requestForIdentity.Target); string uri = Encoding.UTF8.GetString(b); HttpResponseMessage httpResponse = uri.PostJsonAsync(identityRequest).Result; if (httpResponse.IsSuccessStatusCode) { //TODO: this step should be done if Identity Provider API returned OK _dataAccessService.UpdateUserAssociatedAttributes(accountId, new List <Tuple <AttributeType, string> > { new Tuple <AttributeType, string>(AttributeType.PassportPhoto, requestForIdentity.ImageContent) }); return(Ok()); } return(BadRequest(httpResponse.Content.ReadAsAsync <string>().Result)); }
private void ProcessIssuingAssociatedAttributes(IdentityRequestDto identityRequest, IStateTransactionsService transactionsService, byte[] rootAssetId, byte[] faceImage) { byte[] blindingPoint = identityRequest.BlindingPoint.HexStringToByteArray(); Identity identity = _externalDataAccessService.GetIdentityByRootAttribute(identityRequest.RootAttributeContent); if (identity != null) { foreach (var identityAttribute in identity.AssociatedAttributes) { ProcessIssuingAssociatedAttribute(identityAttribute, blindingPoint, rootAssetId, transactionsService); } } }