public FirstIssuanceMessageInfo FirstMessage(FirstIssuanceMessageSpec spec) { if (!issuerStore.HasValue(spec.IssuerID)) { ApiArgumentFault fault = new ApiArgumentFault(); fault.Details = "Issuer with unique ID was found"; fault.Argument = "FirstIssuanceMessageSpec.IssuerID"; fault.ArgumentValue = spec.IssuerID; throw new FaultException <ApiArgumentFault>(fault); } IssuerKeyAndParameters ikp = issuerStore.GetValue(spec.IssuerID); IssuerProtocolParameters ipp = new IssuerProtocolParameters(ikp); ipp.NumberOfTokens = spec.NumberOfTokens; ipp.Attributes = ConvertToByteArray(spec.Attributes); if (!String.IsNullOrWhiteSpace(spec.TokenInfomation)) { ipp.TokenInformation = ExtensionMethods.ToByteArray(spec.TokenInfomation); } if (!String.IsNullOrWhiteSpace(spec.Gamma)) { ipp.Gamma = ExtensionMethods.ToGroupElement(spec.Gamma, ikp.IssuerParameters); } if (!String.IsNullOrWhiteSpace(spec.DevicePublicKey)) { ipp.DevicePublicKey = ExtensionMethods.ToGroupElement(spec.DevicePublicKey, ikp.IssuerParameters); } ipp.Validate(); Issuer issuer = ipp.CreateIssuer(); FirstIssuanceMessage firstMessage = issuer.GenerateFirstMessage(); FirstIssuanceMessageInfo ret = new FirstIssuanceMessageInfo(); ret.FirstMessage = firstMessage; Guid issuerInstance = Guid.NewGuid(); ret.IssuerInstanceID = issuerInstance; ret.FirstMessageState = issuer.ExportPostFirstMessageState(); issuerInstanceDB.TryAdd(issuerInstance, new IssuerInstanceData(issuer)); return(ret); }
public void TestIssuerStateExport() { IssuerKeyAndParameters ikap; IssuerProtocolParameters ipp; ProverProtocolParameters ppp; StaticTestHelpers.GenerateTestIssuanceParameters("test issuer params", "test spec", 3, true, 6, out ikap, out ipp, out ppp); // generate test issuer parameters Issuer issuer = ipp.CreateIssuer(); IssuerParameters ip = ikap.IssuerParameters; Prover prover = ppp.CreateProver(); FirstIssuanceMessage msg1 = null; SecondIssuanceMessage msg2 = null; ThirdIssuanceMessage msg3 = null; msg1 = issuer.GenerateFirstMessage(); PostFirstMessageState state = issuer.ExportPostFirstMessageState(); string serializedState = ikap.IssuerParameters.Serialize(state); msg2 = prover.GenerateSecondMessage(msg1); // make sure the original issuer is unusable try { issuer.GenerateThirdMessage(msg2); Assert.Fail(); } catch (Exception) { // expected } // complete the issuance with a new issuer instance Issuer issuer2 = new Issuer(ikap, ikap.IssuerParameters.Deserialize <PostFirstMessageState>(serializedState)); msg3 = issuer2.GenerateThirdMessage(msg2); // make sure tokens are valid by completing the issuance prover.GenerateTokens(msg3); }