Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Revocation Implementation
Browse files Browse the repository at this point in the history
Resolver Implementation
  • Loading branch information
MarGaaya committed May 22, 2024
1 parent 22ca51a commit e0715f3
Show file tree
Hide file tree
Showing 27 changed files with 1,008 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Hyperledger.Aries/Hyperledger.Aries.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Hyperledger.Indy-VDR" Version="$(HyperledgerIndyVdrVersion)" />
<PackageReference Include="Hyperledger.Anoncreds-Rs" Version="0.3.23" />
<PackageReference Include="Hyperledger.Aries-Askar" Version="0.2.16" />
<PackageReference Include="Hyperledger.Indy-VDR" Version="0.4.6" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="$(MicrosoftExtensionsHostingVersion)" />
<PackageReference Include="Microsoft.Extensions.Http" Version="$(MicrosoftExtensionsHttpVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="$(MicrosoftExtensionsLoggingVersion)" />
<PackageReference Include="System.Reactive.Linq" Version="$(SystemReactiveLinqVersion)" />
<PackageReference Include="System.Text.Json" Version="$(SystemTextJsonVersion)" />

<PackageReference Include="Flurl" Version="$(FlurlVersion)" />
<PackageReference Include="Hyperledger.Indy.Sdk" Version="$(HyperledgerIndySdkVersion)" />
<PackageReference Include="Hyperledger.Indy.Sdk" Version="1.16.0" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" />
<PackageReference Include="Polly" Version="$(PollyVersion)" />
<PackageReference Include="Stateless" Version="$(StatelessVersion)" />
Expand Down
50 changes: 50 additions & 0 deletions src/Hyperledger.Aries/Ledger/V2/DefaultLedgerServiceV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,5 +246,55 @@ async Task<string> 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<string> LookupdGetTxnAuthorAgreementRequestAsync(IAgentContext agentContext)
{
var req = await LedgerApi.BuildGetTxnAuthorAgreementRequestAsync();

return await SubmitRequestAsync(agentContext, req);
}

public async Task<string> LookupTxnRequestAsync(IAgentContext agentContext, int ledgerType, int seqNo)
{
var req = await LedgerApi.BuildGetTxnRequestAsync(ledgerType, seqNo);

return await SubmitRequestAsync(agentContext, req);
}

public async Task<string> 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);
}
}
}
10 changes: 10 additions & 0 deletions src/Hyperledger.Aries/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"profiles": {
"Hyperledger.Aries": {
"commandName": "Project",
"environmentVariables": {
"PATH": "C:\\Rustlibs"
}
}
}
}
33 changes: 33 additions & 0 deletions src/Hyperledger.Aries/Resolver/DefaultResolverService.cs
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");
}
}
}
10 changes: 10 additions & 0 deletions src/Hyperledger.Aries/Resolver/IResolverService.cs
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
{
}
}
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 src/Hyperledger.Aries/Revocation/DefaultRevocationService.cs
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];
}

}




}
10 changes: 10 additions & 0 deletions src/Hyperledger.Aries/Revocation/Enum/Enum.cs
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 src/Hyperledger.Aries/Revocation/Models/AskarAnoncredsProfile.cs
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 src/Hyperledger.Aries/Revocation/Models/BaseAnonCredsRegistrar.cs
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);


}
34 changes: 34 additions & 0 deletions src/Hyperledger.Aries/Revocation/Models/BaseInjector.cs
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();


}
}
Loading

0 comments on commit e0715f3

Please sign in to comment.