This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolver Implementation
- Loading branch information
Showing
27 changed files
with
1,008 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"profiles": { | ||
"Hyperledger.Aries": { | ||
"commandName": "Project", | ||
"environmentVariables": { | ||
"PATH": "C:\\Rustlibs" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<string> 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<string> 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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Hyperledger.Aries.Resolver | ||
{ | ||
public interface IResolverService | ||
{ | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Hyperledger.Aries/Revocation/Abstractions/IRevocationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<RevRegDefResult> RegisterRevocationRegistryDefinition(Profile profile, RevocationRegistryDefinition revRegDef); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BaseAnonCredsRegistrar> 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<RevRegDefResult> 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<RevRegDefResult> 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<BaseAnonCredsRegistrar> _registrar_for_identifier(string IssuerId) | ||
{ | ||
List<BaseAnonCredsRegistrar> matchingRegistrars = new List<BaseAnonCredsRegistrar>(); | ||
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]; | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Hyperledger.Aries.Revocation.Enum | ||
{ | ||
public class Enum | ||
{ | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Hyperledger.Aries/Revocation/Models/AskarAnoncredsProfile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Hyperledger.Aries.Revocation.Models | ||
{ | ||
public class AskarAnoncredsProfile | ||
{ | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<bool> SupportsAsync(string identifier) | ||
{ | ||
// Determine whether this registry supports the given identifier. | ||
return SupportedIdentifiersRegex.IsMatch(identifier); | ||
} | ||
|
||
/// <summary> | ||
/// Register a revocation registry definition on the registry. | ||
/// </summary> | ||
public abstract Task<RevRegDefResult> RegisterRevocationRegistryDefinition(Profile profile, RevocationRegistryDefinition revocationRegistryDefinition); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Hyperledger.Aries.Revocation.Models | ||
{ | ||
public abstract class BaseInjector<T> | ||
{ | ||
/// <summary> | ||
/// Get the provided instance of a given class identifier. | ||
/// </summary> | ||
/// <param name="baseCls">The base class to retrieve an instance of</param> | ||
/// <param name="settings">An optional mapping providing configuration to the provider</param> | ||
/// <returns>An instance of the base class, or null</returns> | ||
public abstract T Inject(T baseCls, IDictionary<string, object> settings = null); | ||
|
||
/// <summary> | ||
/// Get the provided instance of a given class identifier or default if not found. | ||
/// </summary> | ||
/// <param name="baseCls">The base class to retrieve an instance of</param> | ||
/// <param name="settings">An optional mapping providing configuration to the provider</param> | ||
/// <param name="default">Default return value if no instance is found</param> | ||
/// <returns>An instance of the base class, or null</returns> | ||
public abstract T InjectOr(T baseCls, IDictionary<string, object> settings = null); | ||
|
||
/// <summary> | ||
/// Produce a copy of the injector instance. | ||
/// </summary> | ||
/// <returns>A copy of the injector instance</returns> | ||
public abstract BaseInjector<T> Copy(); | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.