public SecondIssuanceMessageInfo SecondMessage(SecondIssuanceMessageSpec spec) { if (spec.IssuerParameter == null) { ApiArgumentFault fault = new ApiArgumentFault(); fault.Details = "Issuer with unique ID was found"; fault.Argument = "IssuerSetupParametersSpec.ID"; fault.ArgumentValue = spec.IssuerParameter.Serialize(); throw new FaultException <ApiArgumentFault>(fault); } ProverProtocolParameters pProtoParam = new ProverProtocolParameters(spec.IssuerParameter); pProtoParam.NumberOfTokens = spec.NumberOfTokens; if (!String.IsNullOrWhiteSpace(spec.TokenInfomation)) { pProtoParam.TokenInformation = ExtensionMethods.ToByteArray(spec.TokenInfomation); } if (!String.IsNullOrWhiteSpace(spec.Gamma)) { pProtoParam.Gamma = ExtensionMethods.ToGroupElement(spec.Gamma, spec.IssuerParameter); } if (!String.IsNullOrWhiteSpace(spec.DevicePublicKey)) { pProtoParam.DevicePublicKey = ExtensionMethods.ToGroupElement(spec.DevicePublicKey, spec.IssuerParameter); } if (!String.IsNullOrWhiteSpace(spec.ProverInfomation)) { pProtoParam.ProverInformation = ExtensionMethods.ToByteArray(spec.ProverInfomation); } if (spec.RandomData != null) { pProtoParam.ProverRandomData = spec.RandomData; } if (spec.BatchSecurityLevel > 0) { pProtoParam.BatchValidationSecurityLevel = spec.BatchSecurityLevel; } pProtoParam.Validate(); Prover prover = pProtoParam.CreateProver(); SecondIssuanceMessage secondMessage = prover.GenerateSecondMessage(spec.FirstMessage); PostSecondMessageState postSecondMessageState = prover.ExportPostSecondMessageState(); SecondIssuanceMessageInfo simInfo = new SecondIssuanceMessageInfo(); simInfo.PostSecondMessageState = postSecondMessageState; simInfo.SecondMessage = secondMessage; Guid issuerInstance = Guid.NewGuid(); simInfo.ProverInstanceID = issuerInstance; proverInstanceDB.TryAdd(issuerInstance, new ProverInstanceData(prover)); return(simInfo); }
public void TestProverStateExport() { 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(); msg2 = prover.GenerateSecondMessage(msg1); PostSecondMessageState state = prover.ExportPostSecondMessageState(); string serializedState = ip.Serialize(state); // complete the issuance with a new prover instance msg3 = issuer.GenerateThirdMessage(msg2); Prover prover2 = new Prover(ip, ip.Deserialize <PostSecondMessageState>(serializedState)); prover2.GenerateTokens(msg3); // make sure the original prover is unusable try { prover.GenerateTokens(msg3); Assert.Fail(); } catch (Exception) { // expected } }