diff --git a/src/Hyperledger.Aries/Anoncreds/Presentation/DefaultPresentationService.cs b/src/Hyperledger.Aries/Anoncreds/Presentation/DefaultPresentationService.cs new file mode 100644 index 00000000..6661fc22 --- /dev/null +++ b/src/Hyperledger.Aries/Anoncreds/Presentation/DefaultPresentationService.cs @@ -0,0 +1,50 @@ +using System; +using anoncreds_rs_dotnet.Models; +using System.Threading.Tasks; +using System.Collections.Generic; +using anoncreds_rs_dotnet.Anoncreds; +using Hyperledger.Aries.Features.IssueCredential; +using Hyperledger.Aries.Agents; +using Hyperledger.Aries.Contracts; +using Newtonsoft.Json.Linq; + +namespace Hyperledger.Aries.Anoncreds.Presentation +{ + public class DefaultPresentationService : IPresentationService + { + ISchemaService schemaService; + ILedgerService ledgerService; + + public async Task VerifyPresentationAsync(IAgentContext context, string presReqJson, string presentationJson) + { + var presentation = PresentationApi.CreatePresentationFromJsonAsync(presentationJson); + var presentationRequest = PresentationRequestApi.CreatePresReqFromJsonAsync(presReqJson); + + List schemaIds = new List(), credentialDefinitionIds = new List(), revocationRegistryDefinitionIds = new List(); + var schemas = new List(); + var credentialDefinitions = new List(); + var revocationRegistryDefinitions = new List(); + var revocationStatusList = new List(); + + foreach (var identifier in presentation.Result.Identifiers) + { + schemaIds.Add(identifier.SchemaId.ToString()); + credentialDefinitionIds.Add(identifier.CredentialDefinitionId.ToString()); + revocationRegistryDefinitionIds.Add(identifier.RevocationRegistryId.ToString()); + + var schema = await schemaService.LookupSchemaAsync(context, identifier.SchemaId.ToString()); + schemas.Add(new Schema { JsonString = schema }) ; + + var credentialDef = await schemaService.LookupCredentialDefinitionAsync(context, identifier.CredentialDefinitionId.ToString()); + credentialDefinitions.Add(new CredentialDefinition { JsonString = credentialDef }); + + var revRegDefinition = await ledgerService.LookupRevocationRegistryDefinitionAsync(context, identifier.RevocationRegistryId.ToString()); + revocationRegistryDefinitions.Add(new RevocationRegistryDefinition { JsonString = revRegDefinition.ObjectJson }); + + var revocationStatus = await ledgerService.LookupRevocationRegistryAsync(context, identifier.RevocationRegistryId.ToString(), identifier.Timestamp); + revocationStatusList.Add(new RevocationStatusList { JsonString = revocationStatus.ObjectJson }); + } + return await PresentationApi.VerifyPresentationAsync(presentation.Result, presentationRequest.Result, schemas, schemaIds, credentialDefinitions, credentialDefinitionIds, revocationRegistryDefinitions, revocationRegistryDefinitionIds, revocationStatusList); + } + } +} diff --git a/src/Hyperledger.Aries/Anoncreds/Presentation/IPresentationService.cs b/src/Hyperledger.Aries/Anoncreds/Presentation/IPresentationService.cs new file mode 100644 index 00000000..03312d05 --- /dev/null +++ b/src/Hyperledger.Aries/Anoncreds/Presentation/IPresentationService.cs @@ -0,0 +1,11 @@ +using anoncreds_rs_dotnet.Models; +using Hyperledger.Aries.Agents; +using System.Threading.Tasks; + +namespace Hyperledger.Aries.Anoncreds.Presentation +{ + public interface IPresentationService + { + Task VerifyPresentationAsync(IAgentContext context, string presReqJson, string presentationJson); + } +} diff --git a/src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs b/src/Hyperledger.Aries/Anoncreds/Revocation/DefaultRevocationService.cs similarity index 71% rename from src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs rename to src/Hyperledger.Aries/Anoncreds/Revocation/DefaultRevocationService.cs index 90a835ad..8e84a57a 100644 --- a/src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs +++ b/src/Hyperledger.Aries/Anoncreds/Revocation/DefaultRevocationService.cs @@ -3,27 +3,22 @@ using Hyperledger.Aries.Agents; using Hyperledger.Aries.Configuration; using Hyperledger.Aries.Contracts; -using Hyperledger.Aries.Extensions; -using Hyperledger.Aries.Models.Records; -using Hyperledger.Aries.Revocation.Abstractions; -using Hyperledger.Aries.Revocation.Models; -using Hyperledger.Aries.Revocation.Utils; -using Hyperledger.Indy.AnonCredsApi; -using indy_vdr_dotnet.libindy_vdr; -using Microsoft.Extensions.Options; -using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; -using static Hyperledger.Aries.Revocation.Models.RevRegDefinitionState; -namespace Hyperledger.Aries.Revocation + +namespace Hyperledger.Aries.Anoncreds.Revocation { public class DefaultRevocationService : IRevocationService { public readonly ILedgerService LedgerService; private readonly IProvisioningService ProvisioningService; + + public Regex SupportedIdentifiersRegex => throw new NotImplementedException(); + public async Task CreateAndRegisterRevocationRegistryDefinitionAsync(IAgentContext context, string originDid, CredentialDefinition credDefObject, string credDefId, string tag, RegistryType revRegType, long maxCredNumber, string tailsDirPath) { var req = await RevocationApi.CreateRevocationRegistryDefinitionAsync(originDid, credDefObject, credDefId, tag, revRegType, maxCredNumber, tailsDirPath); @@ -33,16 +28,11 @@ public async Task CreateAndRegisterRevocationRegistryDefinitionAsync(IAgentConte var provisioning = await ProvisioningService.GetProvisioningAsync(context.Wallet); revRegDef.IssuerId ??= provisioning.IssuerDid; - var definitionRecord = new DefinitionRecord(); - definitionRecord.IssuerDid = revRegDef.IssuerId; - await LedgerService.RegisterRevocationRegistryDefinitionAsync( context: context, submitterDid: revRegDef.IssuerId, data: revRegDef.JsonString, paymentInfo: null); - - } } } diff --git a/src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs b/src/Hyperledger.Aries/Anoncreds/Revocation/IRevocationService.cs similarity index 71% rename from src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs rename to src/Hyperledger.Aries/Anoncreds/Revocation/IRevocationService.cs index 2014bf5f..a9e3670f 100644 --- a/src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs +++ b/src/Hyperledger.Aries/Anoncreds/Revocation/IRevocationService.cs @@ -1,12 +1,8 @@ using anoncreds_rs_dotnet.Models; using Hyperledger.Aries.Agents; -using Hyperledger.Aries.Revocation.Models; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading.Tasks; -namespace Hyperledger.Aries.Revocation.Abstractions +namespace Hyperledger.Aries.Anoncreds.Revocation { public interface IRevocationService { diff --git a/src/Hyperledger.Aries/Anoncreds/Schema/DefaultSchemaService.cs b/src/Hyperledger.Aries/Anoncreds/Schema/DefaultSchemaService.cs new file mode 100644 index 00000000..071ed78a --- /dev/null +++ b/src/Hyperledger.Aries/Anoncreds/Schema/DefaultSchemaService.cs @@ -0,0 +1,22 @@ +using anoncreds_rs_dotnet.Anoncreds; +using anoncreds_rs_dotnet.Models; +using Hyperledger.Aries.Agents; +using Hyperledger.Aries.Contracts; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Hyperledger.Aries.Anoncreds.AnoncredsSchema +{ + public class DefaultSchemaService : ISchemaService + { + public readonly ILedgerService LedgerService; + public async Task CreateAndRegisterSchemaAsync(IAgentContext context, string issuerDid, string schemaName, string schemaVersion, List attrNames) + { + var schemaJson = await SchemaApi.CreateSchemaJsonAsync(issuerDid, schemaName, schemaVersion, attrNames); + + await LedgerService.RegisterSchemaAsync(context, issuerDid, schemaJson); + } + } +} diff --git a/src/Hyperledger.Aries/Anoncreds/Schema/ISchemaService.cs b/src/Hyperledger.Aries/Anoncreds/Schema/ISchemaService.cs new file mode 100644 index 00000000..61d71cc0 --- /dev/null +++ b/src/Hyperledger.Aries/Anoncreds/Schema/ISchemaService.cs @@ -0,0 +1,12 @@ +using anoncreds_rs_dotnet.Models; +using Hyperledger.Aries.Agents; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Hyperledger.Aries.Anoncreds.AnoncredsSchema +{ + public interface ISchemaService + { + Task CreateAndRegisterSchemaAsync(IAgentContext context, string issuerDid, string schemaName, string schemaVersion, List attrNames); + } +} diff --git a/src/Hyperledger.Aries/Revocation/DefaultRegistryService.cs b/src/Hyperledger.Aries/Revocation/DefaultRegistryService.cs deleted file mode 100644 index 04b25b51..00000000 --- a/src/Hyperledger.Aries/Revocation/DefaultRegistryService.cs +++ /dev/null @@ -1,47 +0,0 @@ -using anoncreds_rs_dotnet.Models; -using Hyperledger.Aries.Revocation.Abstractions; -using Hyperledger.Aries.Revocation.Models; -using Hyperledger.Aries.Revocation.Utils; -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace Hyperledger.Aries.Revocation -{ - public class DefaultRegistryService : IRegistryService - { - private List registrars; - public async Task RegisterRevocationRegistryDefinition(RevocationRegistryDefinition revRegDef) - { - RevRegDefResult result; - var registrar = await _registrar_for_identifier(revRegDef.IssuerId); - result = await registrar.RegisterRevocationRegistryDefinition(revRegDef); - return result; - } - - public async Task _registrar_for_identifier(string IssuerId) - { - List matchingRegistrars = new List(); - foreach (var registrar in registrars) - { - if (await registrar.SupportsAsync(IssuerId)) - { - matchingRegistrars.Add(registrar); - } - } - - if (matchingRegistrars.Count == 0) - { - throw new AnonCredsRegistrationError($"No registrar available for identifier {IssuerId}"); - } - - if (matchingRegistrars.Count > 1) - { - throw new AnonCredsRegistrationError($"More than one registrar found for identifier {IssuerId}"); - } - - return matchingRegistrars[0]; - } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Enum/Enum.cs b/src/Hyperledger.Aries/Revocation/Enum/Enum.cs deleted file mode 100644 index 35aeae7a..00000000 --- a/src/Hyperledger.Aries/Revocation/Enum/Enum.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Enum -{ - public class Enum - { - } -} diff --git a/src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs b/src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs deleted file mode 100644 index ade7765f..00000000 --- a/src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs +++ /dev/null @@ -1,30 +0,0 @@ -// Technology stack: C# -// Framework: .NET - -using anoncreds_rs_dotnet.Models; -using Hyperledger.Aries.Ledger.Models; -using Hyperledger.Aries.Revocation.Models; -using System; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using System.Threading.Tasks; - -public abstract class BaseAnonCredsRegistrar -{ - // Base Anon Creds Handler. - - public abstract Regex SupportedIdentifiersRegex { get; } - - public async Task SupportsAsync(string identifier) - { - // Determine whether this registry supports the given identifier. - return SupportedIdentifiersRegex.IsMatch(identifier); - } - - /// - /// Register a revocation registry definition on the registry. - /// - public abstract Task RegisterRevocationRegistryDefinition(RevocationRegistryDefinition revocationRegistryDefinition); - - -} diff --git a/src/Hyperledger.Aries/Revocation/Models/Event.cs b/src/Hyperledger.Aries/Revocation/Models/Event.cs deleted file mode 100644 index b5f8249c..00000000 --- a/src/Hyperledger.Aries/Revocation/Models/Event.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Models -{ - public class Event - { - // A simple event object. - - private string _topic; - private object _payload; - - public Event(string topic, object payload = null) - { - // Create a new event. - _topic = topic; - _payload = payload; - } - - public string Topic - { - // Return this event's topic. - get { return _topic; } - } - - public object Payload - { - // Return this event's payload. - get { return _payload; } - } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Models/RevRegDef.cs b/src/Hyperledger.Aries/Revocation/Models/RevRegDef.cs deleted file mode 100644 index 07cd6655..00000000 --- a/src/Hyperledger.Aries/Revocation/Models/RevRegDef.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Models -{ - public class RevRegDef - { - public string issuerId { get; set; } - public string type { get; set; } - public string credDefId { get; set; } - public string Tag { get; set; } - public RevRegDefValue value { get; set; } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Models/RevRegDefResult.cs b/src/Hyperledger.Aries/Revocation/Models/RevRegDefResult.cs deleted file mode 100644 index 0efb2d71..00000000 --- a/src/Hyperledger.Aries/Revocation/Models/RevRegDefResult.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; - - -namespace Hyperledger.Aries.Revocation.Models -{ - public class RevRegDefResult - { - public IntPtr Handle { get; set; } - - [JsonProperty] - public string JobId { get; set; } - - [JsonProperty] - public string revRegDefId { get { return this.revRegDefinitionState.revRegDefId; } } - - [JsonProperty] - public RevRegDef revRegDef { get { return this.revRegDefinitionState.revRegDef; } } - [JsonProperty] - public RevRegDefinitionState revRegDefinitionState { get; set; } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Models/RevRegDefValue.cs b/src/Hyperledger.Aries/Revocation/Models/RevRegDefValue.cs deleted file mode 100644 index 130dcb6f..00000000 --- a/src/Hyperledger.Aries/Revocation/Models/RevRegDefValue.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Models -{ - public class RevRegDefValue - { - public Dictionary PublicKeys { get; set; } - public int MaxCredNum { get; set; } - public string TailsLocation { get; set; } - public string TailsHash { get; set; } - - } -} diff --git a/src/Hyperledger.Aries/Revocation/Models/RevRegDefinitionState.cs b/src/Hyperledger.Aries/Revocation/Models/RevRegDefinitionState.cs deleted file mode 100644 index 7e1cde9d..00000000 --- a/src/Hyperledger.Aries/Revocation/Models/RevRegDefinitionState.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Newtonsoft.Json; -using System; -using System.Collections; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Models -{ - public class RevRegDefinitionState - { - [JsonProperty] - public string revRegDefId { get; set; } - - [JsonProperty] - public RevRegDef revRegDef { get; set; } - - [JsonProperty] - public RevRegDefState revRegDefState { get; set; } - - - public enum RevRegDefState - { - STATE_FINISHED = 0, - STATE_FAILED = 1, - STATE_ACTION = 2, - STATE_WAIT = 3, - STATE_DECOMMISSIONED = 4, - STATE_FULL = 5 - } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRegistrationError.cs b/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRegistrationError.cs deleted file mode 100644 index f9dd2a68..00000000 --- a/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRegistrationError.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Utils -{ - public class AnonCredsRegistrationError : Exception - { - public AnonCredsRegistrationError(string message) : base(message) { } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRevocationException.cs b/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRevocationException.cs deleted file mode 100644 index 2e6bf9b8..00000000 --- a/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRevocationException.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Utils -{ - public class AnonCredsRevocationException : Exception - { - public AnonCredsRevocationException(string message) : base(message) { } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Utils/BaseError.cs b/src/Hyperledger.Aries/Revocation/Utils/BaseError.cs deleted file mode 100644 index 124ca3d4..00000000 --- a/src/Hyperledger.Aries/Revocation/Utils/BaseError.cs +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; - -namespace Hyperledger.Aries.Revocation.Utils -{ - public class BaseError: Exception - { - /* Generic exception class which other exceptions should inherit from. */ - - public string ErrorCode { get; set; } - public string[] args { get; set; } - - public BaseError(string message, string errorCode = null) : base(message) - { - /* Initialize a BaseError instance. */ - ErrorCode = errorCode ?? null; - } - - public string Message - { - /* Accessor for the error message. */ - get { return (args != null && args.Length > 0) ? args[0].ToString().Trim() : ""; } - } - - public string RollUp - { - /* Accessor for nested error messages rolled into one line. */ - get - { - string flatten(Exception exc) - { - return string.Join(".", ( - Regex.Replace( - exc.Data != null && exc.Data.Count > 0 ? exc.Data[0].ToString().Trim() : exc.GetType().Name, - @"\n\s*", - ". " - ).Trim() - ).Split('.', 2)); - } - - string line = flatten(this); - var err = this; - while (err.InnerException != null) - { - err = (BaseError)err.InnerException; - line += $". {flatten(err)}"; - } - return $"{line.Trim()}."; - } - } - } - - public class AnonCredsRevocationError : BaseError - { - public AnonCredsRevocationError(string message, string errorCode = null) : base(message, errorCode) - { - } - } -} diff --git a/src/Hyperledger.Aries/Revocation/Utils/Consts.cs b/src/Hyperledger.Aries/Revocation/Utils/Consts.cs deleted file mode 100644 index ef863d35..00000000 --- a/src/Hyperledger.Aries/Revocation/Utils/Consts.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Hyperledger.Aries.Revocation.Utils -{ - public class Consts - { - public const string CATEGORY_REV_LIST = "revocation_list"; - public const string CATEGORY_REV_REG_DEF = "revocation_reg_def"; - public const string CATEGORY_REV_REG_DEF_PRIVATE = "revocation_reg_def_private"; - public const string CATEGORY_REV_REG_ISSUER = "revocation_reg_def_issuer"; - public const string STATE_REVOCATION_POSTED = "posted"; - public const string STATE_REVOCATION_PENDING = "pending"; - public const string REV_REG_DEF_STATE_ACTIVE = "active"; - } -}