-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor credential sets Signed-off-by: Kevin <[email protected]> * records migration Signed-off-by: Kevin <[email protected]> * records migration 2 Signed-off-by: Kevin <[email protected]> * records migration 3 Signed-off-by: Kevin <[email protected]> * improve mDocRecord migration Signed-off-by: kenkosmowski <[email protected]> * fix mdoc migration Signed-off-by: kenkosmowski <[email protected]> * migration for OidPresentationRecord Signed-off-by: kenkosmowski <[email protected]> * fix version update for migrated records Signed-off-by: kenkosmowski <[email protected]> * remove debug code Signed-off-by: kenkosmowski <[email protected]> --------- Signed-off-by: Kevin <[email protected]> Signed-off-by: kenkosmowski <[email protected]> Co-authored-by: kenkosmowski <[email protected]>
- Loading branch information
1 parent
e33bdd4
commit 7df514a
Showing
34 changed files
with
698 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/WalletFramework.Oid4Vc/CredentialSet/CredentialSetStorage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Hyperledger.Aries; | ||
using Hyperledger.Aries.Agents; | ||
using Hyperledger.Aries.Storage; | ||
using LanguageExt; | ||
using WalletFramework.Core.Credentials; | ||
using WalletFramework.Oid4Vc.CredentialSet.Models; | ||
using WalletFramework.Oid4Vc.Oid4Vci.Abstractions; | ||
using WalletFramework.SdJwtVc.Services.SdJwtVcHolderService; | ||
using WalletFramework.Core.Functional; | ||
|
||
namespace WalletFramework.Oid4Vc.CredentialSet; | ||
|
||
public class CredentialSetStorage( | ||
IAgentProvider agentProvider, | ||
ISdJwtVcHolderService sdJwtVcHolderService, | ||
IMdocStorage mDocStorage, | ||
IWalletRecordService walletRecordService) : ICredentialSetStorage | ||
{ | ||
public async Task Add(CredentialSetRecord credentialSetRecord) | ||
{ | ||
var context = await agentProvider.GetContextAsync(); | ||
await walletRecordService.AddAsync(context.Wallet, credentialSetRecord); | ||
} | ||
|
||
public virtual async Task Delete(CredentialSetId credentialSetId) | ||
{ | ||
var context = await agentProvider.GetContextAsync(); | ||
var credentialSetRecord = | ||
await walletRecordService.GetAsync<CredentialSetRecord>(context.Wallet, credentialSetId); | ||
if (credentialSetRecord == null) | ||
throw new AriesFrameworkException(ErrorCode.RecordNotFound, "CredentialSet record not found"); | ||
|
||
var sdJwtRecords = await sdJwtVcHolderService.ListAsync(context, credentialSetId); | ||
await sdJwtRecords.Match( | ||
Some: async records => | ||
{ | ||
foreach (var record in records) | ||
await sdJwtVcHolderService.DeleteAsync(context, record.Id); | ||
}, | ||
None: () => Task.CompletedTask); | ||
|
||
var mDocRecords = await mDocStorage.List(credentialSetId); | ||
await mDocRecords.Match( | ||
Some: async records => | ||
{ | ||
foreach (var record in records) | ||
await mDocStorage.Delete(record); | ||
}, | ||
None: () => Task.CompletedTask); | ||
|
||
credentialSetRecord.State = CredentialState.Deleted; | ||
credentialSetRecord.DeletedAt = DateTime.UtcNow; | ||
await walletRecordService.UpdateAsync(context.Wallet, credentialSetRecord); | ||
} | ||
|
||
public async Task<Option<CredentialSetRecord>> Get(CredentialSetId credentialSetId) | ||
{ | ||
var context = await agentProvider.GetContextAsync(); | ||
var record = await walletRecordService.GetAsync<CredentialSetRecord>(context.Wallet, credentialSetId); | ||
|
||
return record; | ||
} | ||
|
||
public async Task<Option<IEnumerable<CredentialSetRecord>>> List( | ||
Option<ISearchQuery> query, | ||
int count = 100, | ||
int skip = 0) | ||
{ | ||
var context = await agentProvider.GetContextAsync(); | ||
var records = await walletRecordService.SearchAsync<CredentialSetRecord>( | ||
context.Wallet, | ||
query.ToNullable(), | ||
null, | ||
count, | ||
skip); | ||
|
||
if (records.Count == 0) | ||
return Option<IEnumerable<CredentialSetRecord>>.None; | ||
|
||
return records; | ||
} | ||
|
||
|
||
public virtual async Task Update(CredentialSetRecord credentialSetRecord) | ||
{ | ||
var context = await agentProvider.GetContextAsync(); | ||
await walletRecordService.UpdateAsync(context.Wallet, credentialSetRecord); | ||
} | ||
} |
Oops, something went wrong.