/// <inheritdoc /> public async Task <(CredentialOfferMessage, CredentialRecord)> CreateOfferAsync( IAgentContext agentContext, OfferConfiguration config) { if (config is null) { throw new ArgumentNullException(nameof(config)); } if (config.CredentialAttributeValues == null || !config.CredentialAttributeValues.Any()) { throw new InvalidOperationException( "You must supply credential values when creating connectionless credential offer"); } var(message, record) = await CreateOfferAsync(agentContext, config, null); var provisioning = await ProvisioningService.GetProvisioningAsync(agentContext.Wallet); message.AddDecorator(provisioning.ToServiceDecorator(), DecoratorNames.ServiceDecorator); record.SetTag("OfferData", message.ToByteArray().ToBase64UrlString()); await RecordService.UpdateAsync(agentContext.Wallet, record); return(message, record); }
/// <inheritdoc /> public async Task <(CredentialOfferMessage, CredentialRecord)> CreateOfferAsync( IAgentContext agentContext, OfferConfiguration config, string connectionId) { Logger.LogInformation(LoggingEvents.CreateCredentialOffer, "DefinitionId {0}, IssuerDid {1}", config.CredentialDefinitionId, config.IssuerDid); var threadId = Guid.NewGuid().ToString(); if (!string.IsNullOrEmpty(connectionId)) { var connection = await ConnectionService.GetAsync(agentContext, connectionId); if (connection.State != ConnectionState.Connected) { throw new AriesFrameworkException(ErrorCode.RecordInInvalidState, $"Connection state was invalid. Expected '{ConnectionState.Connected}', found '{connection.State}'"); } } if (config.CredentialAttributeValues != null && config.CredentialAttributeValues.Any()) { CredentialUtils.ValidateCredentialPreviewAttributes(config.CredentialAttributeValues); } var offerJson = await AnonCreds.IssuerCreateCredentialOfferAsync( agentContext.Wallet, config.CredentialDefinitionId); var offerJobj = JObject.Parse(offerJson); var schemaId = offerJobj["schema_id"].ToObject <string>(); // Write offer record to local wallet var credentialRecord = new CredentialRecord { Id = threadId, CredentialDefinitionId = config.CredentialDefinitionId, OfferJson = offerJson, ConnectionId = connectionId, SchemaId = schemaId, CredentialAttributesValues = config.CredentialAttributeValues, State = CredentialState.Offered, }; credentialRecord.SetTag(TagConstants.LastThreadId, threadId); credentialRecord.SetTag(TagConstants.Role, TagConstants.Issuer); if (!string.IsNullOrEmpty(config.IssuerDid)) { credentialRecord.SetTag(TagConstants.IssuerDid, config.IssuerDid); } if (config.Tags != null) { foreach (var tag in config.Tags) { if (!credentialRecord.Tags.Keys.Contains(tag.Key)) { credentialRecord.Tags.Add(tag.Key, tag.Value); } } } await RecordService.AddAsync(agentContext.Wallet, credentialRecord); return(new CredentialOfferMessage(agentContext.UseMessageTypesHttps) { Id = threadId, Offers = new Attachment[] { new Attachment { Id = "libindy-cred-offer-0", MimeType = CredentialMimeTypes.ApplicationJsonMimeType, Data = new AttachmentContent { Base64 = offerJson.GetUTF8Bytes().ToBase64String() } } }, CredentialPreview = credentialRecord.CredentialAttributesValues != null ? new CredentialPreviewMessage(agentContext.UseMessageTypesHttps) { Attributes = credentialRecord.CredentialAttributesValues.Select(x => new CredentialPreviewAttribute { Name = x.Name, MimeType = x.MimeType, Value = x.Value?.ToString() }).ToArray() } : null }, credentialRecord); }