diff --git a/src/Hyperledger.Aries/Hyperledger.Aries.csproj b/src/Hyperledger.Aries/Hyperledger.Aries.csproj index a2e97bd9..2a237e7b 100644 --- a/src/Hyperledger.Aries/Hyperledger.Aries.csproj +++ b/src/Hyperledger.Aries/Hyperledger.Aries.csproj @@ -5,7 +5,9 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - + + + @@ -13,7 +15,7 @@ - + diff --git a/src/Hyperledger.Aries/Ledger/V2/DefaultLedgerServiceV2.cs b/src/Hyperledger.Aries/Ledger/V2/DefaultLedgerServiceV2.cs index 9f56b0c9..b56deab0 100644 --- a/src/Hyperledger.Aries/Ledger/V2/DefaultLedgerServiceV2.cs +++ b/src/Hyperledger.Aries/Ledger/V2/DefaultLedgerServiceV2.cs @@ -246,5 +246,55 @@ async Task SubmitAsync() exceptionPredicate: (IndyVdrException e) => e.Message.Contains("PoolTimeout") || e.Message.Contains("Service unavailable")); } + + + public async Task RegisterCustomAsync(IAgentContext context, string requestJson, TransactionCost paymentInfo = null) + { + var req = await LedgerApi.BuildCustomRequest(requestJson); + + await SignAndSubmitRequestAsync(context, requestJson, req); + } + + public async Task RegisterDisableAllTxnAuthorAgreementsAsync(IAgentContext context, string submitterDid) + { + var req = await LedgerApi.BuildDisableAllTxnAuthorAgreementsRequest(submitterDid); + + await SignAndSubmitRequestAsync(context, submitterDid, req); + } + + public async Task LookupdGetTxnAuthorAgreementRequestAsync(IAgentContext agentContext) + { + var req = await LedgerApi.BuildGetTxnAuthorAgreementRequestAsync(); + + return await SubmitRequestAsync(agentContext, req); + } + + public async Task LookupTxnRequestAsync(IAgentContext agentContext, int ledgerType, int seqNo) + { + var req = await LedgerApi.BuildGetTxnRequestAsync(ledgerType, seqNo); + + return await SubmitRequestAsync(agentContext, req); + } + + public async Task BuildGetValidatorInfoRequestAsync(IAgentContext context, string submitterDid) + { + var req = await LedgerApi.BuildGetValidatorInfoRequestAsync(submitterDid); + + return await SubmitRequestAsync(context, req); + } + + public async Task RegisterTxnAuthorAgreementRequestAsync(IAgentContext context, string submitterDid, string text, string version, long ratificationTs, long retirementTs) + { + var req = await LedgerApi.BuildTxnAuthorAgreementRequestAsync(submitterDid, text, version, ratificationTs, retirementTs); + + await SignAndSubmitRequestAsync(context, submitterDid, req); + } + + public async Task RegisterRichSchemaRequestAsync(IAgentContext context, string submitterDid, string rsId, string rsContent, string rsName, string rsVersion, string rsType, string ver) + { + var req = await LedgerApi.BuildRichSchemaRequestAsync(submitterDid, rsId, rsContent, rsName, rsVersion, rsType, ver); + + await SignAndSubmitRequestAsync(context, submitterDid, req); + } } } diff --git a/src/Hyperledger.Aries/Properties/launchSettings.json b/src/Hyperledger.Aries/Properties/launchSettings.json new file mode 100644 index 00000000..00687ee5 --- /dev/null +++ b/src/Hyperledger.Aries/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Hyperledger.Aries": { + "commandName": "Project", + "environmentVariables": { + "PATH": "C:\\Rustlibs" + } + } + } +} \ No newline at end of file diff --git a/src/Hyperledger.Aries/Resolver/DefaultResolverService.cs b/src/Hyperledger.Aries/Resolver/DefaultResolverService.cs new file mode 100644 index 00000000..cdf58844 --- /dev/null +++ b/src/Hyperledger.Aries/Resolver/DefaultResolverService.cs @@ -0,0 +1,33 @@ +using Hyperledger.Aries.Agents; +using Hyperledger.Aries.Ledger; +using indy_vdr_dotnet.libindy_vdr; +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Hyperledger.Aries.Resolver +{ + public class DefaultResolverService : IResolverService + { + public async Task ResolveAsync(PoolAwaitable poolHandle, string did) + { + if (await poolHandle is IntPtr pHandle) + { + var response = await ResolverApi.ResolveAsync(pHandle, did); + return response; + } + throw new NotImplementedException("Unsupported request handle"); + } + public async Task DereferenceAsync(PoolAwaitable poolHandle, string did_url) + { + if (await poolHandle is IntPtr pHandle) + { + var response = await ResolverApi.DereferenceAsync(pHandle, did_url); + return response; + } + throw new NotImplementedException("Unsupported request handle"); + } + } +} diff --git a/src/Hyperledger.Aries/Resolver/IResolverService.cs b/src/Hyperledger.Aries/Resolver/IResolverService.cs new file mode 100644 index 00000000..10f9d575 --- /dev/null +++ b/src/Hyperledger.Aries/Resolver/IResolverService.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Resolver +{ + public interface IResolverService + { + } +} diff --git a/src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs b/src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs new file mode 100644 index 00000000..4da6e42d --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs @@ -0,0 +1,15 @@ +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 +{ + public interface IRevocationService + { + Task RegisterRevocationRegistryDefinition(Profile profile, RevocationRegistryDefinition revRegDef); + } +} diff --git a/src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs b/src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs new file mode 100644 index 00000000..79b0d594 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs @@ -0,0 +1,89 @@ +using anoncreds_rs_dotnet.Anoncreds; +using anoncreds_rs_dotnet.Models; +using Hyperledger.Aries.Agents; +using Hyperledger.Aries.Extensions; +using Hyperledger.Aries.Revocation.Abstractions; +using Hyperledger.Aries.Revocation.Models; +using Hyperledger.Aries.Revocation.Utils; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using static Hyperledger.Aries.Revocation.Models.RevRegDefinitionState; + +namespace Hyperledger.Aries.Revocation +{ + public class DefaultRevocationService :IRevocationService + { + private List registrars; + private Profile _profile; + + + public DefaultRevocationService(Profile profile) + { + _profile = profile; + } + + public Profile Profile + { + // Accessor for the profile instance + + get + { + if (!(_profile is AskarAnoncredsProfile)) + { + throw new Exception("AnonCreds interface requires AskarAnoncreds profile"); + } + + return _profile; + } + } + public async Task CreateAndRegisterRevocationRegistryDefinitionAsync(Profile profile, 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); + RevocationRegistryDefinition revRegDef = req.Item1; + RevocationRegistryDefinitionPrivate revRegDefPrivate = req.Item2; + RevRegDefResult result = await RegisterRevocationRegistryDefinition(profile, revRegDef); + return result; + } + + public async Task RegisterRevocationRegistryDefinition(Profile profile, RevocationRegistryDefinition revRegDef) + { + RevRegDefResult result; + var registrar = await _registrar_for_identifier(revRegDef.IssuerId); + result = await registrar.RegisterRevocationRegistryDefinition(profile, 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 new file mode 100644 index 00000000..35aeae7a --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Enum/Enum.cs @@ -0,0 +1,10 @@ +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/AskarAnoncredsProfile.cs b/src/Hyperledger.Aries/Revocation/Models/AskarAnoncredsProfile.cs new file mode 100644 index 00000000..290877ec --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/AskarAnoncredsProfile.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Revocation.Models +{ + public class AskarAnoncredsProfile + { + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs b/src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs new file mode 100644 index 00000000..0f17aa6f --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs @@ -0,0 +1,30 @@ +// 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(Profile profile, RevocationRegistryDefinition revocationRegistryDefinition); + + +} diff --git a/src/Hyperledger.Aries/Revocation/Models/BaseInjector.cs b/src/Hyperledger.Aries/Revocation/Models/BaseInjector.cs new file mode 100644 index 00000000..219c0293 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/BaseInjector.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Revocation.Models +{ + public abstract class BaseInjector + { + /// + /// Get the provided instance of a given class identifier. + /// + /// The base class to retrieve an instance of + /// An optional mapping providing configuration to the provider + /// An instance of the base class, or null + public abstract T Inject(T baseCls, IDictionary settings = null); + + /// + /// Get the provided instance of a given class identifier or default if not found. + /// + /// The base class to retrieve an instance of + /// An optional mapping providing configuration to the provider + /// Default return value if no instance is found + /// An instance of the base class, or null + public abstract T InjectOr(T baseCls, IDictionary settings = null); + + /// + /// Produce a copy of the injector instance. + /// + /// A copy of the injector instance + public abstract BaseInjector Copy(); + + + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/BaseSettings.cs b/src/Hyperledger.Aries/Revocation/Models/BaseSettings.cs new file mode 100644 index 00000000..64e10e4e --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/BaseSettings.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Revocation.Models +{ + public abstract class BaseSettings : IDictionary + { + // Base settings class + + public abstract object GetValue(object defaultVal = null, params object[] varNames); + + public virtual bool? GetBool(bool? defaultVal = null, params string[] varNames) + { + var value = GetValue(varNames, defaultVal); + if (value != null) + { + value = Convert.ToBoolean(value) && !new List { "false", "False", "0" }.Contains(value.ToString()); + } + + return value as bool?; + } + + public virtual int? GetInt(int? defaultVal = null, params string[] varNames) + { + var value = GetValue(varNames, defaultVal); + if (value != null) + { + value = Convert.ToInt32(value); + } + + return value as int?; + } + + public virtual string GetStr(string defaultVal = null, params string[] varNames) + { + var value = GetValue(varNames, defaultVal); + if (value != null) + { + value = value.ToString(); + } + + return value as string; + } + + public abstract void CopyTo(KeyValuePair[] array, int arrayIndex); + + public abstract bool Contains(KeyValuePair item); + + public abstract void Add(KeyValuePair item); + + public abstract bool Remove(KeyValuePair item); + + public abstract IEnumerator> GetEnumerator(); + + public abstract bool TryGetValue(string key, out object value); + + public abstract bool ContainsKey(string key); + + public abstract void Add(string key, object value); + + public abstract bool Remove(string key); + + public abstract void Clear(); + + public abstract ICollection Keys { get; } + + public abstract ICollection Values { get; } + + public abstract bool IsReadOnly { get; } + + public abstract object this[string key] { get; set; } + + public abstract int Count { get; } + + public abstract IEnumerable> Items { get; } + + public abstract BaseSettings Copy(); + + public abstract BaseSettings Extend(IDictionary other); + + public abstract Dictionary ToDictionary(); + + public override string ToString() + { + var items = string.Join(", ", Items); + return $"<{GetType().Name}({items})>"; + } + + IEnumerator IEnumerable.GetEnumerator() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/Event.cs b/src/Hyperledger.Aries/Revocation/Models/Event.cs new file mode 100644 index 00000000..b5f8249c --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/Event.cs @@ -0,0 +1,33 @@ +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/InjectionContext.cs b/src/Hyperledger.Aries/Revocation/Models/InjectionContext.cs new file mode 100644 index 00000000..e348768d --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/InjectionContext.cs @@ -0,0 +1,107 @@ +using anoncreds_rs_dotnet; +using Hyperledger.Aries.Revocation.Utils; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Revocation.Models +{ + public class InjectionContext : BaseInjector + { + public const string ROOT_SCOPE = "application"; + + private Injector _injector; + private string _scopeName; + private List _scopes; + + public InjectionContext(Settings settings = null, bool enforceTyping = true) + { + _injector = new Injector(settings, enforceTyping); + _scopeName = ROOT_SCOPE; + _scopes = new List(); + } + + public Injector Injector + { + get { return _injector; } + set { _injector = value; } + } + + public string ScopeName + { + get { return _scopeName; } + set { _scopeName = value; } + } + + public Settings Settings + { + get { return _injector.Settings; } + } + + public InjectionContext StartScope(string scope_name, Dictionary settings = null) + { + if (string.IsNullOrEmpty(scope_name)) + { + throw new InjectionContextError("Scope name must be non-empty"); + } + if (_scopeName == scope_name) + { + throw new InjectionContextError("Cannot re-enter scope: " + scope_name); + } + foreach (Scope scope in _scopes) + { + if (scope.Name == scope_name) + { + throw new InjectionContextError("Cannot re-enter scope: " + scope_name); + } + } + InjectionContext result = (InjectionContext)Copy(); + _scopes.Add(new Scope(scope_name, _injector)); + _scopeName = scope_name; + if (settings != null) + { + result.UpdateSettings(settings); + } + return result; + } + + public void UpdateSettings(Dictionary settings) + { + // Update the scope with additional settings + if (settings != null) + { + this.Injector.Settings.Update(settings); + } + } + public override InjectionContext Inject(InjectionContext baseCls, IDictionary settings = null) + { + throw new NotImplementedException(); + } + + public override InjectionContext InjectOr(InjectionContext baseCls, IDictionary settings = null) + { + throw new NotImplementedException(); + } + + public override BaseInjector Copy() + { + // Produce a copy of the injector instance. + InjectionContext result = (InjectionContext)this.MemberwiseClone(); + result._injector = _injector; + result._scopes = this._scopes; + return result; + } + } + + public class Scope + { + public string Name { get; set; } + public Injector Injector { get; set; } + + public Scope(string name, Injector injector) + { + Name = name; + Injector = injector; + } + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/Injector.cs b/src/Hyperledger.Aries/Revocation/Models/Injector.cs new file mode 100644 index 00000000..0c194ab7 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/Injector.cs @@ -0,0 +1,47 @@ +using anoncreds_rs_dotnet; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Revocation.Models +{ + public class Injector : BaseInjector + { + private bool enforceTyping; + private Dictionary providers = new Dictionary(); + private Settings settings; + + public Injector(Settings settings = null, bool enforceTyping = true) + { + this.enforceTyping = enforceTyping; + this.settings = settings; + } + + public Settings Settings + { + get + { + return this.settings; + } + set + { + this.settings = value; + } + } + + public override BaseInjector Copy() + { + throw new NotImplementedException(); + } + + public override Injector Inject(Injector baseCls, IDictionary settings = null) + { + throw new NotImplementedException(); + } + + public override Injector InjectOr(Injector baseCls, IDictionary settings = null) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/Profile.cs b/src/Hyperledger.Aries/Revocation/Models/Profile.cs new file mode 100644 index 00000000..76c6c560 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/Profile.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace Hyperledger.Aries.Revocation.Models +{ + public abstract class Profile + { + public string BACKEND_NAME = null; + public string DEFAULT_NAME = "default"; + + private InjectionContext _context; + private bool _created; + private string _name; + + public Profile(InjectionContext context = null, string name = null, bool created = false) + { + // Initialize a base profile. + _context = context ?? new InjectionContext(); + _created = created; + _name = name ?? DEFAULT_NAME; + } + + public string Backend + { + // Accessor for the backend implementation name. + get { return BACKEND_NAME; } + } + + public InjectionContext Context + { + // Accessor for the injection context. + get { return _context; } + } + public bool Created + { + // Accessor for the created flag indicating a new profile. + get { return _created; } + } + + public string Name + { + // Accessor for the profile name. + get { return _name; } + } + public BaseSettings Settings + { + // Accessor for scope-specific settings. + get { return _context.Settings; } + } + + public abstract ProfileSession Session(InjectionContext context = null); + + public abstract ProfileSession Transaction(InjectionContext context = null); + + + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/ProfileSession.cs b/src/Hyperledger.Aries/Revocation/Models/ProfileSession.cs new file mode 100644 index 00000000..99d5398b --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/ProfileSession.cs @@ -0,0 +1,47 @@ +using Hyperledger.Aries.Revocation.Utils; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Data; +using System.Text; +using System.Threading.Tasks; + +namespace Hyperledger.Aries.Revocation.Models +{ + public abstract class ProfileSession + { + // An active connection to the profile management backend. + + private bool _active; + private bool _awaited; + private int _entered; + private InjectionContext _context; + private Profile _profile; + private List _events; + + public ProfileSession(Profile profile, InjectionContext context = null, Dictionary settings = null) + { + // Initialize a base profile session. + _active = false; + _awaited = false; + _entered = 0; + _context = (context ?? profile.Context).StartScope("session", settings); + _profile = profile; + _events = new List(); + } + + public bool Active { get { return _active; } } + + public InjectionContext Context { get { return _context; } } + + public BaseSettings Settings { get { return _context.Settings; } } + + public bool IsTransaction { get { return false; } } + + public Profile Profile { get { return _profile; } } + + public abstract Task Teardown(bool commit = false); + + + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/RevRegDef.cs b/src/Hyperledger.Aries/Revocation/Models/RevRegDef.cs new file mode 100644 index 00000000..07cd6655 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/RevRegDef.cs @@ -0,0 +1,15 @@ +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 new file mode 100644 index 00000000..91bafb9c --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/RevRegDefResult.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + + +namespace Hyperledger.Aries.Revocation.Models +{ + public class RevRegDefResult + { + [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 new file mode 100644 index 00000000..130dcb6f --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/RevRegDefValue.cs @@ -0,0 +1,15 @@ +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 new file mode 100644 index 00000000..6e6d1b65 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/RevRegDefinitionState.cs @@ -0,0 +1,39 @@ +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 + } + public static Dictionary RevRegDefStateames = new Dictionary(){ + { RevRegDefState.STATE_FINISHED , "finished" }, + { RevRegDefState.STATE_FAILED , "failed" }, + { RevRegDefState.STATE_ACTION , "action" }, + { RevRegDefState.STATE_WAIT , "wait" }, + { RevRegDefState.STATE_DECOMMISSIONED , "decommissioned" }, + { RevRegDefState.STATE_FULL , "full" } + }; + } +} diff --git a/src/Hyperledger.Aries/Revocation/Models/Settings.cs b/src/Hyperledger.Aries/Revocation/Models/Settings.cs new file mode 100644 index 00000000..22308852 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Models/Settings.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace Hyperledger.Aries.Revocation.Models +{ + public class Settings : BaseSettings, IDictionary + { + // Mutable settings implementation. + + private Dictionary _values = new Dictionary(); + + public Settings(Dictionary values = null) + { + // Initialize a Settings object. + + if (values != null) + { + foreach (var item in values) + { + _values.Add(item.Key, item.Value); + } + } + } + + public override object this[string key] { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } + + public override ICollection Keys => throw new NotImplementedException(); + + public override ICollection Values => throw new NotImplementedException(); + + public override bool IsReadOnly => throw new NotImplementedException(); + + public override int Count => throw new NotImplementedException(); + + public override IEnumerable> Items => throw new NotImplementedException(); + + public override void Add(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public override void Add(string key, object value) + { + throw new NotImplementedException(); + } + + public override void Clear() + { + throw new NotImplementedException(); + } + + public override bool Contains(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public override bool ContainsKey(string key) + { + throw new NotImplementedException(); + } + + public override BaseSettings Copy() + { + throw new NotImplementedException(); + } + + public override void CopyTo(KeyValuePair[] array, int arrayIndex) + { + throw new NotImplementedException(); + } + + public override BaseSettings Extend(IDictionary other) + { + throw new NotImplementedException(); + } + + public override IEnumerator> GetEnumerator() + { + throw new NotImplementedException(); + } + + public override object GetValue(object defaultVal = null, params object[] varNames) + { + throw new NotImplementedException(); + } + + public override bool Remove(KeyValuePair item) + { + throw new NotImplementedException(); + } + + public override bool Remove(string key) + { + throw new NotImplementedException(); + } + + public override Dictionary ToDictionary() + { + throw new NotImplementedException(); + } + + public override bool TryGetValue(string key, out object value) + { + throw new NotImplementedException(); + } + + public void Update(Dictionary other) + { + // Update the settings in place. + _values = other; + } + // Other methods and properties from BaseSettings class + } +} diff --git a/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRegistrationError.cs b/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRegistrationError.cs new file mode 100644 index 00000000..f9dd2a68 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRegistrationError.cs @@ -0,0 +1,11 @@ +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 new file mode 100644 index 00000000..2e6bf9b8 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Utils/AnonCredsRevocationException.cs @@ -0,0 +1,11 @@ +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 new file mode 100644 index 00000000..0f494f02 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Utils/BaseError.cs @@ -0,0 +1,68 @@ +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 ProfileSessionInactiveError : BaseError + { + public ProfileSessionInactiveError(string message, string errorCode = null) : base(message, errorCode) + { + } + } + + public class InjectionContextError : BaseError + { + public InjectionContextError(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 new file mode 100644 index 00000000..ef863d35 --- /dev/null +++ b/src/Hyperledger.Aries/Revocation/Utils/Consts.cs @@ -0,0 +1,17 @@ +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"; + } +} diff --git a/test/Hyperledger.Aries.Tests/Properties/launchSettings.json b/test/Hyperledger.Aries.Tests/Properties/launchSettings.json new file mode 100644 index 00000000..3690dd62 --- /dev/null +++ b/test/Hyperledger.Aries.Tests/Properties/launchSettings.json @@ -0,0 +1,10 @@ +{ + "profiles": { + "Hyperledger.Aries.Tests": { + "commandName": "Project", + "environmentVariables": { + "PATH": "C:\\Rustlibs" + } + } + } +} \ No newline at end of file