Skip to content

Commit

Permalink
Merge branch 'Matthew.Spence-VE-3338-Issuer-Setup-v0.7' into 'main'
Browse files Browse the repository at this point in the history
VE 3338: Add issuerSetup v0.7 to sdk

Closes VE-3338

See merge request evernym/verity/verity-sdk!97
  • Loading branch information
Matt-Spence committed Jul 13, 2022
2 parents d700db9 + fbb3752 commit 6e9c4d0
Show file tree
Hide file tree
Showing 17 changed files with 984 additions and 17 deletions.
Empty file added sdk/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void testGetMessageType()
{
string msgName = "msg name";

IssuerSetupV0_6 t = IssuerSetup.v0_6();
IssuerSetupV0_7 t = IssuerSetup.v0_7();

string expectedType = Util.getMessageType(
Util.EVERNYM_MSG_QUALIFIER,
Expand All @@ -28,20 +28,44 @@ public void testGetMessageType()
[TestMethod]
public void testGetThreadId()
{
IssuerSetupV0_6 testProtocol = IssuerSetup.v0_6();
IssuerSetupV0_7 testProtocol = IssuerSetup.v0_7();
Assert.IsNotNull(testProtocol.getThreadId());
}

[TestMethod]
public void testCreateMessages()
{
Context context = TestHelpers.getContext();
IssuerSetupV0_6 p = IssuerSetup.v0_6();
JsonObject msg = p.createMsg(context);
IssuerSetupV0_7 p = IssuerSetup.v0_7();
JsonObject msg = p.createMsg(context, "did:indy:sovrin:builder");
Assert.AreEqual(
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.6/create",
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.7/create",
msg.getAsString("@type")
);
Assert.AreEqual(
msg.getAsString("ledgerPrefix"),
"did:indy:sovrin:builder"
);
Assert.IsNotNull(msg.getAsString("@id"));
}

public void testCreateMessagesWithEndorser()
{
Context context = TestHelpers.getContext();
IssuerSetupV0_7 p = IssuerSetup.v0_7();
JsonObject msg = p.createMsg(context, "did:indy:sovrin:builder", "someEndorser");
Assert.AreEqual(
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.7/create",
msg.getAsString("@type")
);
Assert.AreEqual(
msg.getAsString("ledgerPrefix"),
"did:indy:sovrin:builder"
);
Assert.AreEqual(
msg.getAsString("endorser"),
"someEndorser"
);
Assert.IsNotNull(msg.getAsString("@id"));
}

Expand All @@ -50,11 +74,11 @@ public void testCreate()
{
withContext(context =>
{
IssuerSetupV0_6 testProtocol = IssuerSetup.v0_6();
byte[] message = testProtocol.createMsgPacked(context);
IssuerSetupV0_7 testProtocol = IssuerSetup.v0_7();
byte[] message = testProtocol.createMsgPacked(context, "did:indy:sovrin:builder");
JsonObject unpackedMessage = TestHelpers.unpackForwardMessage(context, message);
Assert.AreEqual(
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.6/create",
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.7/create",
unpackedMessage.getAsString("@type"));
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Json;
using VeritySDK.Protocols.IssuerSetup;
using VeritySDK.Utils;

namespace VeritySDK.Test
{
[TestClass]
public class IssuerSetupTest_0_6 : TestBase
{

[TestMethod]
public void testGetMessageType()
{
string msgName = "msg name";

IssuerSetupV0_6 t = IssuerSetup.v0_6();

string expectedType = Util.getMessageType(
Util.EVERNYM_MSG_QUALIFIER,
t.family(),
t.version(),
msgName);

Assert.AreEqual(expectedType, t.messageType(msgName));
}

[TestMethod]
public void testGetThreadId()
{
IssuerSetupV0_6 testProtocol = IssuerSetup.v0_6();
Assert.IsNotNull(testProtocol.getThreadId());
}

[TestMethod]
public void testCreateMessages()
{
Context context = TestHelpers.getContext();
IssuerSetupV0_6 p = IssuerSetup.v0_6();
JsonObject msg = p.createMsg(context);
Assert.AreEqual(
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.6/create",
msg.getAsString("@type")
);
Assert.IsNotNull(msg.getAsString("@id"));
}

[TestMethod]
public void testCreate()
{
withContext(context =>
{
IssuerSetupV0_6 testProtocol = IssuerSetup.v0_6();
byte[] message = testProtocol.createMsgPacked(context);
JsonObject unpackedMessage = TestHelpers.unpackForwardMessage(context, message);
Assert.AreEqual(
Util.EVERNYM_MSG_QUALIFIER + "/issuer-setup/0.6/create",
unpackedMessage.getAsString("@type"));
});
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,14 @@ public static IssuerSetupV0_6 v0_6()
{
return new IssuerSetupV0_6();
}

/// <summary>
/// Constructor for the 0.7 IssuerSetup object. This constructor creates an object that is ready to start the setup process of an issuer.
/// </summary>
/// <returns>0.7 IssuerSetup object</returns>
public static IssuerSetupV0_7 v0_7()
{
return new IssuerSetupV0_7();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
using System.Json;
using VeritySDK.Protocols;
using VeritySDK.Utils;

namespace VeritySDK.Protocols.IssuerSetup
{
/// <summary>
/// A class for controlling a 0.7 IssuerSetup protocol.
/// </summary>
public class IssuerSetupV0_7 : AbstractProtocol
{
#region Protocol identificator

/// <summary>
/// The qualifier for the message family. Uses Evernym's qualifier.
/// </summary>
public override string qualifier() { return Util.EVERNYM_MSG_QUALIFIER; }

/// <summary>
/// The name for the message family.
/// </summary>
public override string family() { return "issuer-setup"; }

/// <summary>
/// The version for the message family.
/// </summary>
public override string version() { return "0.7"; }

#endregion

#region Constructors

/// <summary>
/// Constructor
/// </summary>
public IssuerSetupV0_7() { }

/// <summary>
/// Constructor
/// </summary>
public IssuerSetupV0_7(string threadId) : base(threadId) { }

#endregion

/// <summary>
/// Name for 'create' control message
/// </summary>
public string CREATE = "create";

/// <summary>
/// Name for 'current-public-identifier' control message
/// </summary>
public string CURRENT_PUBLIC_IDENTIFIER = "current-public-identifier";

/// <summary>
/// Directs verity-application to start and create an issuer identity and set it up
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <param name="ledgerPrefix">a string indicating the location that the issuer identifier should be published to. Verity can publish to the following locations, indicated by the values in quotes:
/// [Sovrin Builder Net: "did:indy:sovrin:builder",
/// Sovrin Staging Net: "did:indy:sovrin:staging",
/// Sovrin Main Net: "did:indy:sovrin"]
/// The locations which are available to your Verity tenant will be configured based on your customer agreement.</param>
public void create(Context context, string ledgerPrefix)
{
send(context, createMsg(context, ledgerPrefix));
}

/// <summary>
/// Directs verity-application to start and create an issuer identity and set it up
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <param name="ledgerPrefix">a string indicating the location that the issuer identifier should be published to. Verity can publish to the following locations, indicated by the values in quotes:
/// [Sovrin Builder Net: "did:indy:sovrin:builder",
/// Sovrin Staging Net: "did:indy:sovrin:staging",
/// Sovrin Main Net: "did:indy:sovrin"]
/// The locations which are available to your Verity tenant will be configured based on your customer agreement.</param>
/// <param name="endorser">Optional: the desired endorser did. If left empty then Verity will attempt to use it's own endorser, otherwise it will return a transaction for manual endorsement</param>
public void create(Context context, string ledgerPrefix, string endorser)
{
send(context, createMsg(context, ledgerPrefix, endorser));
}

/// <summary>
/// Creates the control message without packaging and sending it.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <param name="ledgerPrefix">a string indicating the location that the issuer identifier should be published to. Verity can publish to the following locations, indicated by the values in quotes:
/// [Sovrin Builder Net: "did:indy:sovrin:builder",
/// Sovrin Staging Net: "did:indy:sovrin:staging",
/// Sovrin Main Net: "did:indy:sovrin"]
/// The locations which are available to your Verity tenant will be configured based on your customer agreement.</param>
/// <returns>the constructed message (JSON object)</returns>
public JsonObject createMsg(Context context, string ledgerPrefix)
{
JsonObject message = new JsonObject();
message.Add("@type", messageType(CREATE));
message.Add("@id", getNewId());
message.Add("ledgerPrefix", ledgerPrefix);
addThread(message);
return message;
}

/// <summary>
/// Creates the control message without packaging and sending it.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <param name="ledgerPrefix">a string indicating the location that the issuer identifier should be published to. Verity can publish to the following locations, indicated by the values in quotes:
/// [Sovrin Builder Net: "did:indy:sovrin:builder",
/// Sovrin Staging Net: "did:indy:sovrin:staging",
/// Sovrin Main Net: "did:indy:sovrin"]
/// The locations which are available to your Verity tenant will be configured based on your customer agreement.</param>
/// <param name="endorser">Optional: the desired endorser did. If left empty then Verity will attempt to use it's own endorser, otherwise it will return a transaction for manual endorsement</param>
/// <returns>the constructed message (JSON object)</returns>
public JsonObject createMsg(Context context, string ledgerPrefix, string endorser)
{
JsonObject message = new JsonObject();
message.Add("@type", messageType(CREATE));
message.Add("@id", getNewId());
message.Add("endorser", endorser);
message.Add("ledgerPrefix", ledgerPrefix);
addThread(message);
return message;
}

/// <summary>
/// Creates and packages message without sending it.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <param name="ledgerPrefix">a string indicating the location that the issuer identifier should be published to. Verity can publish to the following locations, indicated by the values in quotes:
/// [Sovrin Builder Net: "did:indy:sovrin:builder",
/// Sovrin Staging Net: "did:indy:sovrin:staging",
/// Sovrin Main Net: "did:indy:sovrin"]
/// The locations which are available to your Verity tenant will be configured based on your customer agreement.</param>
/// <returns>the byte array ready for transport</returns>
public byte[] createMsgPacked(Context context, string ledgerPrefix)
{
return packMsg(context, createMsg(context, ledgerPrefix));
}

/// <summary>
/// Creates and packages message without sending it.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <param name="ledgerPrefix">a string indicating the location that the issuer identifier should be published to. Verity can publish to the following locations, indicated by the values in quotes:
/// [Sovrin Builder Net: "did:indy:sovrin:builder",
/// Sovrin Staging Net: "did:indy:sovrin:staging",
/// Sovrin Main Net: "did:indy:sovrin"]
/// The locations which are available to your Verity tenant will be configured based on your customer agreement.</param>
/// <param name="endorser">Optional: the desired endorser did. If left empty then Verity will attempt to use it's own endorser, otherwise it will return a transaction for manual endorsement</param>
/// <returns>the byte array ready for transport</returns>
public byte[] createMsgPacked(Context context, string ledgerPrefix, string endorser)
{
return packMsg(context, createMsg(context, ledgerPrefix, endorser));
}

/// <summary>
/// Asks the verity-application for the current issuer identity that is setup.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
public void currentPublicIdentifier(Context context)
{
send(context, currentPublicIdentifierMsg(context));
}

/// <summary>
/// Creates the control message without packaging and sending it.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <returns>the constructed message (JSON object)</returns>
public JsonObject currentPublicIdentifierMsg(Context context)
{
JsonObject message = new JsonObject();
message.Add("@type", messageType(CURRENT_PUBLIC_IDENTIFIER));
message.Add("@id", getNewId());
addThread(message);
return message;
}

/// <summary>
/// Creates and packages message without sending it.
/// </summary>
/// <param name="context">an instance of the Context object initialized to a verity-application agent</param>
/// <returns>the byte array ready for transport</returns>
public byte[] currentPublicIdentifierMsgPacked(Context context)
{
return packMsg(context, currentPublicIdentifierMsg(context));
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.evernym.verity.sdk.protocols.issuersetup;

import com.evernym.verity.sdk.protocols.issuersetup.v0_6.IssuerSetupV0_6;
import com.evernym.verity.sdk.protocols.issuersetup.v0_7.IssuerSetupV0_7;

/**
* Factory for the IssuerSetup protocol objects
Expand All @@ -23,4 +24,13 @@ private IssuerSetup() {}
public static IssuerSetupV0_6 v0_6() {
return new IssuerSetupImplV0_6();
}

/**
* Constructor for the 0.7 IssuerSetup object. This constructor creates an object that is ready to start the setup
* process of an issuer.
* @return 0.7 IssuerSetup object
*/
public static IssuerSetupV0_7 v0_7() {
return new IssuerSetupImplV0_7();
}
}
Loading

0 comments on commit 6e9c4d0

Please sign in to comment.