Skip to content

Commit

Permalink
Proof Protocol added. Issue Protocol fixes. Pool and Ledger service r…
Browse files Browse the repository at this point in the history
…efactor. (#16)

* Protocols update

Signed-off-by: Tomislav Markovski <[email protected]>

* Remove Myget repo from sources

Signed-off-by: Tomislav Markovski <[email protected]>
  • Loading branch information
tmarkovski authored Nov 13, 2019
1 parent 16af719 commit 9094cb8
Show file tree
Hide file tree
Showing 25 changed files with 588 additions and 229 deletions.
1 change: 0 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="myget.org" value="https://www.myget.org/F/agent-framework/api/v3/index.json" />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>
28 changes: 24 additions & 4 deletions src/AgentFramework.Core.Handlers/Internal/DefaultProofHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ public DefaultProofHandler(IProofService proofService)
/// <value>
/// The supported message types.
/// </value>
public IEnumerable<MessageType> SupportedMessageTypes => new[]
public IEnumerable<MessageType> SupportedMessageTypes => new MessageType[]
{
new MessageType(MessageTypes.ProofRequest),
new MessageType(MessageTypes.DisclosedProof)
MessageTypes.ProofRequest,
MessageTypes.DisclosedProof,
MessageTypes.PresentProofNames.Presentation,
MessageTypes.PresentProofNames.RequestPresentation
};

/// <summary>
Expand All @@ -39,6 +41,7 @@ public async Task<AgentMessage> ProcessAsync(IAgentContext agentContext, Message
{
switch (messageContext.GetMessageType())
{
// v0.1
case MessageTypes.ProofRequest:
{
var request = messageContext.GetMessage<ProofRequestMessage>();
Expand All @@ -47,7 +50,6 @@ public async Task<AgentMessage> ProcessAsync(IAgentContext agentContext, Message
messageContext.ContextRecord = await _proofService.GetAsync(agentContext, proofId);
break;
}

case MessageTypes.DisclosedProof:
{
var proof = messageContext.GetMessage<ProofMessage>();
Expand All @@ -56,6 +58,24 @@ public async Task<AgentMessage> ProcessAsync(IAgentContext agentContext, Message
messageContext.ContextRecord = await _proofService.GetAsync(agentContext, proofId);
break;
}

// v1.0
case MessageTypes.PresentProofNames.RequestPresentation:
{
var message = messageContext.GetMessage<RequestPresentationMessage>();
var record = await _proofService.ProcessRequestAsync(agentContext, message, messageContext.Connection);

messageContext.ContextRecord = record;
break;
}
case MessageTypes.PresentProofNames.Presentation:
{
var message = messageContext.GetMessage<PresentationMessage>();
var record = await _proofService.ProcessPresentationAsync(agentContext, message);

messageContext.ContextRecord = record;
break;
}
default:
throw new AgentFrameworkException(ErrorCode.InvalidMessage,
$"Unsupported message type {messageContext.GetMessageType()}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ public class TxnAuthorAcceptanceHostedService : IHostedService
{
private readonly IProvisioningService provisioningService;
private readonly IWalletRecordService recordService;
private readonly ILedgerService _ledgerService;
private readonly IPoolService _poolService;
private readonly IAgentProvider _agentProvider;
private readonly PoolOptions poolOptions;

public TxnAuthorAcceptanceHostedService(
IApplicationLifetime applicationLifetime,
IProvisioningService provisioningService,
IWalletRecordService recordService,
ILedgerService ledgerService,
IPoolService poolService,
IAgentProvider agentProvider,
IOptions<PoolOptions> poolOptions)
{
applicationLifetime.ApplicationStarted.Register(AcceptTxnAuthorAgreement);
this.provisioningService = provisioningService;
this.recordService = recordService;
_ledgerService = ledgerService;
_poolService = poolService;
_agentProvider = agentProvider;
this.poolOptions = poolOptions.Value;
}
Expand All @@ -42,7 +42,7 @@ private async void AcceptTxnAuthorAgreement()
if (!poolOptions.AcceptTxnAuthorAgreement) return;

var context = await _agentProvider.GetContextAsync(nameof(TxnAuthorAcceptanceHostedService));
var taa = await _ledgerService.LookupTaaAsync(context);
var taa = await _poolService.GetTaaAsync(poolOptions.PoolName);
if (taa != null)
{
var digest = GetDigest(taa);
Expand Down
8 changes: 8 additions & 0 deletions src/AgentFramework.Core/Contracts/ICredentialService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,13 @@ Task<string> ProcessCredentialRequestAsync(IAgentContext agentContext,
/// <param name="issuerDid">The DID of the issuer who issued the credential and owns the definitions</param>
/// <returns>The response async.</returns>
Task RevokeCredentialAsync(IAgentContext agentContext, string credentialId, string issuerDid);

/// <summary>
/// Deletes the credential and it's associated record
/// </summary>
/// <param name="agentContext"></param>
/// <param name="credentialId"></param>
/// <returns></returns>
Task DeleteCredentialAsync(IAgentContext agentContext, string credentialId);
}
}
17 changes: 0 additions & 17 deletions src/AgentFramework.Core/Contracts/ILedgerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,6 @@ Task RegisterAttributeAsync(IAgentContext context, string submittedDid, string t
/// <returns></returns>
Task<string> LookupNymAsync(Pool pool, string did);

/// <summary>
/// Lookup Transaction Author Agreement on the ledger
/// </summary>
/// <param name="context">The agent context</param>
/// <param name="version">Taa version. Pass null to get latest.</param>
/// <returns></returns>
Task<IndyTaa> LookupTaaAsync(IAgentContext context, string version = null);

/// <summary>
/// Lookup acceptance mechanisms list
/// </summary>
/// <param name="context">The agent context</param>
/// <param name="timestamp"></param>
/// <param name="version"></param>
/// <returns>The acceptance mechanisms list</returns>
Task<IndyAml> LookupAmlAsync(IAgentContext context, DateTimeOffset timestamp = default(DateTimeOffset), string version = null);

/// <summary>
/// Lookup the ledger transaction async.
/// </summary>
Expand Down
22 changes: 21 additions & 1 deletion src/AgentFramework.Core/Contracts/IPoolService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Threading.Tasks;
using System;
using System.Threading.Tasks;
using AgentFramework.Core.Models.Ledger;
using Hyperledger.Indy.PoolApi;

namespace AgentFramework.Core.Contracts
Expand Down Expand Up @@ -26,6 +28,24 @@ public interface IPoolService
/// <param name="poolName">Pool name.</param>
Task<Pool> GetPoolAsync(string poolName);

/// <summary>
/// Gets the transaction author agreement if one is set on
/// the ledger. Otherwise, returns null.
/// </summary>
/// <param name="poolName"></param>
/// <returns></returns>
Task<IndyTaa> GetTaaAsync(string poolName);

/// <summary>
/// Gets the acceptance mechanisms list from the ledger
/// if one is set.await Otherwise, returns null.
/// </summary>
/// <param name="poolName"></param>
/// <param name="timestamp"></param>
/// <param name="version"></param>
/// <returns></returns>
Task<IndyAml> GetAmlAsync(string poolName, DateTimeOffset timestamp = default(DateTimeOffset), string version = null);

/// <summary>
/// Creates a pool configuration.
/// </summary>
Expand Down
36 changes: 31 additions & 5 deletions src/AgentFramework.Core/Contracts/IProofService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AgentFramework.Core.Messages;
using AgentFramework.Core.Messages.Proofs;
using AgentFramework.Core.Models.Credentials;
using AgentFramework.Core.Models.Proofs;
Expand All @@ -21,9 +23,13 @@ public interface IProofService
/// <param name="proofRequest">An enumeration of attribute we wish the prover to disclose.</param>
/// <param name="connectionId">Connection identifier of who the proof request will be sent to.</param>
/// <returns>Proof Request message and identifier.</returns>
[Obsolete]
Task<(ProofRequestMessage, ProofRecord)> CreateProofRequestAsync(IAgentContext agentContext,
ProofRequest proofRequest, string connectionId = null);

Task<(RequestPresentationMessage, ProofRecord)> CreateRequestAsync(IAgentContext agentContext,
ProofRequest proofRequest, string connectionId = null);

/// <summary>
/// Creates a proof request.
/// </summary>
Expand All @@ -32,9 +38,13 @@ public interface IProofService
/// <param name="proofRequestJson">A string representation of proof request json object</param>
/// <param name="connectionId">Connection identifier of who the proof request will be sent to.</param>
/// <returns>Proof Request message and identifier.</returns>
[Obsolete]
Task<(ProofRequestMessage, ProofRecord)> CreateProofRequestAsync(IAgentContext agentContext,
string proofRequestJson, string connectionId);

Task<(RequestPresentationMessage, ProofRecord)> CreateRequestAsync(IAgentContext agentContext,
string proofRequestJson, string connectionId);

/// <summary>
/// Processes a proof request and stores it for a given connection.
/// </summary>
Expand All @@ -43,17 +53,23 @@ public interface IProofService
/// <param name="proofRequest">A proof request.</param>
/// <param name="connection">Connection.</param>
/// <returns>Proof identifier.</returns>
[Obsolete]
Task<string> ProcessProofRequestAsync(IAgentContext agentContext, ProofRequestMessage proofRequest, ConnectionRecord connection);

Task<ProofRecord> ProcessRequestAsync(IAgentContext agentContext, RequestPresentationMessage proofRequest, ConnectionRecord connection);

/// <summary>
/// Processes a proof and stores it for a given connection.
/// </summary>
/// <returns>The identifier for the stored proof.</returns>
/// <param name="agentContext">Agent Context.</param>
/// <param name="proof">A proof.</param>
/// <returns>Proof identifier.</returns>
[Obsolete]
Task<string> ProcessProofAsync(IAgentContext agentContext, ProofMessage proof);

Task<ProofRecord> ProcessPresentationAsync(IAgentContext agentContext, PresentationMessage proof);

/// <summary>
/// Processes a proof request and generates an accompanying proof.
/// </summary>
Expand All @@ -63,9 +79,13 @@ public interface IProofService
/// <returns>
/// The proof.
/// </returns>
[Obsolete]
Task<string> CreateProofAsync(IAgentContext agentContext,
ProofRequest proofRequest, RequestedCredentials requestedCredentials);

Task<string> CreatePresentationAsync(IAgentContext agentContext,
ProofRequest proofRequest, RequestedCredentials requestedCredentials);

/// <summary>
/// Creates a proof.
/// </summary>
Expand All @@ -75,24 +95,30 @@ Task<string> CreateProofAsync(IAgentContext agentContext,
/// <returns>
/// The proof.
/// </returns>
[Obsolete]
Task<(ProofMessage, ProofRecord)> CreateProofAsync(IAgentContext agentContext, string proofRequestId,
RequestedCredentials requestedCredentials);

Task<(PresentationMessage, ProofRecord)> CreatePresentationAsync(
IAgentContext agentContext,
string proofRecordId,
RequestedCredentials requestedCredentials);

/// <summary>
/// Rejects a proof request.
/// </summary>
/// <returns>The proof.</returns>
/// <param name="agentContext">Agent Context.</param>
/// <param name="proofRequestId">Identifier of the proof request.</param>
Task RejectProofRequestAsync(IAgentContext agentContext, string proofRequestId);
/// <param name="proofRecordId">Identifier of the proof request.</param>
Task RejectProofRequestAsync(IAgentContext agentContext, string proofRecordId);

/// <summary>
/// Verifies a proof.
/// </summary>
/// <param name="agentContext">Agent Context.</param>
/// <param name="proofRecId">Identifier of the proof record.</param>
/// <param name="proofRecordId">Identifier of the proof record.</param>
/// <returns>Status indicating validity of proof.</returns>
Task<bool> VerifyProofAsync(IAgentContext agentContext, string proofRecId);
Task<bool> VerifyProofAsync(IAgentContext agentContext, string proofRecordId);

/// <summary>
/// Verifies a proof.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public static async Task<SignatureDecorator> SignData<T>(IAgentContext agentCont
var sigDecorator = new SignatureDecorator
{
SignatureType = DefaultSignatureType,
SignatureData = sigData.ToBase64String(),
Signature = sig.ToBase64String(),
SignatureData = sigData.ToBase64UrlString(),
Signature = sig.ToBase64UrlString(),
Signer = signerKey
};

Expand Down
19 changes: 2 additions & 17 deletions src/AgentFramework.Core/Extensions/FormattingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,21 @@ public static byte[] ToByteArray<T>(this T value) =>
/// to an equivalent 8-bit unsigned integer array.</summary>
/// <param name="value">The value.</param>
/// <returns></returns>
[Obsolete("Please use 'BytesFromBase64' or 'BytesFromBase64Url'")]
public static byte[] GetBytesFromBase64(this string value) => Base64UrlEncoder.DecodeBytes(value);

/// <summary>
/// Converts the specified encoded string as base-64 URL,
/// to an equivalent 8-bit unsigned integer array.</summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public static byte[] BytesFromBase64Url(this string value) => Base64UrlEncoder.DecodeBytes(value);

/// <summary>
/// Converts the specified encoded string as base-64,
/// to an equivalent 8-bit unsigned integer array.</summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public static byte[] BytesFromBase64(this string value) => Convert.FromBase64String(value);

/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string
/// representation that is encoded with base-64 digits.</summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public static string ToBase64String(this byte[] value) => Base64UrlEncoder.Encode(value);
public static string ToBase64UrlString(this byte[] value) => Base64UrlEncoder.Encode(value);

/// <summary>
/// Converts an array of 8-bit unsigned integers to its equivalent string
/// representation that is encoded with base-64 digits.</summary>
/// <param name="value">The value.</param>
/// <returns></returns>
public static string ToBase64(this byte[] value) => Convert.ToBase64String(value);
public static string ToBase64String(this byte[] value) => Convert.ToBase64String(value);

private static readonly JsonSerializerSettings SerializerSettings = new JsonSerializerSettings
{
Expand Down
Loading

0 comments on commit 9094cb8

Please sign in to comment.