private IActionResult GetServiceProviderActionType(IUtxoClientCryptoService clientCryptoService, string actionDecoded) { ulong accountId = ulong.Parse(User.Identity.Name, CultureInfo.InvariantCulture); UriBuilder uriBuilder = new UriBuilder(actionDecoded); string actionType = uriBuilder.Uri.ParseQueryString()["actionType"]; string registrationKey; byte[] targetBytes = uriBuilder.Uri.ParseQueryString()["publicKey"]?.HexStringToByteArray(); UserRootAttribute rootAttribute = _dataAccessService.GetUserAttributes(accountId).FirstOrDefault(); if (actionType == "0") // Login and register { clientCryptoService.GetBoundedCommitment(rootAttribute.AssetId, targetBytes, out byte[] blindingFactor, out byte[] assetCommitment); registrationKey = assetCommitment.ToHexString(); NameValueCollection queryParams = uriBuilder.Uri.ParseQueryString(); queryParams["registrationKey"] = registrationKey; uriBuilder.Query = queryParams.ToString(); } else if (actionType == "1") // employee registration { registrationKey = rootAttribute.AssetId.ToHexString(); NameValueCollection queryParams = uriBuilder.Uri.ParseQueryString(); queryParams["registrationKey"] = registrationKey; uriBuilder.Query = queryParams.ToString(); } else if (actionType == "2") // document sign { } ServiceProviderActionAndValidationsDto serviceProviderActionAndValidations = uriBuilder.Uri.ToString().GetJsonAsync <ServiceProviderActionAndValidationsDto>().Result; string validationsExpression = string.Empty; if ((serviceProviderActionAndValidations.Validations?.Count ?? 0) > 0) { validationsExpression = ":" + serviceProviderActionAndValidations.Validations.JoinStrings("|"); } if (actionType == "2") { return(Ok(new { Action = "6", ActionInfo = $"{serviceProviderActionAndValidations.PublicKey}:{serviceProviderActionAndValidations.SessionKey}:{serviceProviderActionAndValidations.ExtraInfo}{validationsExpression}" })); } else { if (serviceProviderActionAndValidations.IsRegistered) { return(Ok(new { Action = actionType == "0" ? "3" : "5", ActionInfo = $"{serviceProviderActionAndValidations.PublicKey}:{serviceProviderActionAndValidations.SessionKey}:{serviceProviderActionAndValidations.ExtraInfo}{validationsExpression}" })); } else { return(Ok(new { Action = actionType == "0" ? "2" : "4", ActionInfo = $"{serviceProviderActionAndValidations.PublicKey}:{serviceProviderActionAndValidations.SessionKey}:{serviceProviderActionAndValidations.ExtraInfo}{validationsExpression}" })); } } }
public IActionResult GetActionInfo([FromQuery(Name = "t")] int actionType, [FromQuery(Name = "pk")] string publicKey, [FromQuery(Name = "sk")] string sessionKey, [FromQuery(Name = "rk")] string registrationKey) { AccountDescriptor spAccount = _accountsService.GetByPublicKey(publicKey.HexStringToByteArray()); bool isRegistered = false; string extraInfo = null; List <string> validations = new List <string>(); string[] details = Array.Empty <string>(); // Onboarding & Login if (actionType == 0) { ServiceProviderRegistration serviceProviderRegistration = _dataAccessService.GetServiceProviderRegistration(spAccount.AccountId, registrationKey.HexStringToByteArray()); ; isRegistered = serviceProviderRegistration != null; } // Employee registration else if (actionType == 1) { List <SpEmployee> spEmployees = _dataAccessService.GetSpEmployees(spAccount.AccountId, registrationKey.DecodeFromString64()); extraInfo = ""; foreach (SpEmployee spEmployee in spEmployees) { if (!string.IsNullOrEmpty(extraInfo)) { extraInfo += "/"; } extraInfo += $"{spAccount.AccountInfo}|{spEmployee?.SpEmployeeGroup?.GroupName}|{!string.IsNullOrEmpty(spEmployee.RegistrationCommitment)}"; } isRegistered = spEmployees.Count > 0; } // Document sign else if (actionType == 2) { SignedDocumentEntity spDocument = _dataAccessService.GetSpDocument(spAccount.AccountId, registrationKey); if (spDocument != null) { isRegistered = true; extraInfo = $"{spDocument.DocumentName}|{spDocument.Hash}|{spDocument.LastChangeRecordHeight}"; foreach (var allowedSigner in spDocument.AllowedSigners) { validations.Add($"{allowedSigner.GroupIssuer};{allowedSigner.GroupName}"); } } } bool isBiometryRequired = false; if (actionType == 0 || actionType == 1) { IEnumerable <SpIdenitityValidation> spIdenitityValidations = _dataAccessService.GetSpIdenitityValidations(spAccount.AccountId); if (spIdenitityValidations != null && spIdenitityValidations.Count() > 0) { //IEnumerable<Tuple<AttributeType, string>> attributeDescriptions = _identityAttributesService.GetAssociatedAttributeTypes(); //IEnumerable<Tuple<ValidationType, string>> validationDescriptions = _identityAttributesService.GetAssociatedValidationTypes(); foreach (SpIdenitityValidation spIdenitityValidation in spIdenitityValidations) { if (!AttributesSchemes.ATTR_SCHEME_NAME_PASSPORTPHOTO.Equals(spIdenitityValidation.SchemeName)) { validations.Add($"{spIdenitityValidation.SchemeName}:{spIdenitityValidation.ValidationType}"); } else { isBiometryRequired = true; } // if (spIdenitityValidation.AttributeType != AttributeType.DateOfBirth) //{ // validityInfo.Add(attributeDescriptions.FirstOrDefault(d => d.Item1 == spIdenitityValidation.AttributeType)?.Item2 ?? spIdenitityValidation.AttributeType.ToString()); // } // else //{ // validityInfo.Add(validationDescriptions.FirstOrDefault(d => d.Item1 == spIdenitityValidation.ValidationType)?.Item2 ?? spIdenitityValidation.ValidationType.ToString()); //} } } } ServiceProviderActionAndValidationsDto serviceProviderActionAndValidations = new ServiceProviderActionAndValidationsDto { SpInfo = spAccount.AccountInfo, IsRegistered = isRegistered, PublicKey = publicKey, SessionKey = sessionKey, ExtraInfo = extraInfo, IsBiometryRequired = isBiometryRequired, Validations = validations }; return(Ok(serviceProviderActionAndValidations)); }