Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Implement Askar-Store Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MarGaaya committed Jun 5, 2024
1 parent 2b74964 commit e1ba60e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Hyperledger.Aries.AskarStore
namespace Hyperledger.Aries.AskarStore.Abstractions
{
public interface IStorageRecordService
{
Expand All @@ -15,5 +15,6 @@ public interface IStorageRecordService
Task<StorageRecord> GetRecord(Store store, string recordType, string recordId, bool for_update = false);
Task<StorageRecord> FindRecord(Store store, StorageRecord record, string tag_query, long limit, bool for_update = false);
Task<IEnumerable<StorageRecord>> FindAllRecord(Store store, StorageRecord record, string tag_query, long limit, bool for_update = false);
Task<long> RemoveAllRecords(Store store, StorageRecord record, string tagFilter = null);
}
}
22 changes: 22 additions & 0 deletions src/Hyperledger.Aries/AskarStore/Abstractions/IStorageService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using aries_askar_dotnet.Models;
using Hyperledger.Aries.AskarStore.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Hyperledger.Aries.AskarStore.Abstractions
{
public interface IStorageService
{
Task<bool> RemoveStoreAsync(Store store);
Task<Store> OpenStoreAsync(Store store, bool provision = false);
Task<string> GenerateRawKeyAsync(string Seed = null);
Task<string> CreateProfileAsync(Store store, string profile = null);
Task<string> GetProfileNameAsync(Store store);
Task<string> GetDefaultProfileAsync(Store store);
Task<bool> SetDefaultProfileAsync(Store store, string profile);
Task<bool> RemoveProfileAsync(Store store, string profile);
Task<IEnumerable<AskarProfile>> GetListProfilesAsync(Store store);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using aries_askar_dotnet.AriesAskar;
using aries_askar_dotnet.Models;
using Hyperledger.Aries.AskarStore.Abstractions;
using Hyperledger.Aries.AskarStore.Models;
using Hyperledger.Aries.Extensions;
using Newtonsoft.Json;
Expand Down Expand Up @@ -71,11 +72,17 @@ public async Task<IEnumerable<StorageRecord>> FindAllRecord(Store store, Storage
Session session = await CreateSession(store);
var items = await session.FetchAllAsync(record.Type, tag_query, limit, for_update);
var rows = JsonConvert.DeserializeObject<IEnumerable<StorageRecord>>(items.ToJson());
var results = new List<StorageRecord >();
var results = new List<StorageRecord>();
foreach (StorageRecord row in rows) {
results.Add(row);
}
return results;
}

public async Task<long> RemoveAllRecords(Store store, StorageRecord record, string tagFilter = null)
{
Session session = await CreateSession(store);
return await session.RemoveAllAsync(record.Type, tagFilter);
}
}
}
50 changes: 47 additions & 3 deletions src/Hyperledger.Aries/AskarStore/DefaultStorageService.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
using aries_askar_dotnet.AriesAskar;
using aries_askar_dotnet.Models;
using Hyperledger.Aries.AskarStore.Abstractions;
using Hyperledger.Aries.AskarStore.Models;
using Hyperledger.Aries.Extensions;
using Newtonsoft.Json.Linq;
using Stateless.Graph;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace Hyperledger.Aries.AskarStore
{
public class DefaultStorageService : IStorageService
{
public async Task<string> CreateProfileAsync(Store store, string profile = null)
{
return await store.CreateProfileAsync(profile);
}

public Task<string> GenerateRawKeyAsync(string Seed = null)
{
var key = StoreApi.GenerateRawKeyAsync(Seed);
return key;
return StoreApi.GenerateRawKeyAsync(Seed);
}

public async Task<string> GetDefaultProfileAsync(Store store)
{
return await store.GetDefaultProfileAsync();
}

public async Task<Store> OpenStore(Store store, bool provision = false)
public async Task<string> GetProfileNameAsync(Store store)
{
return await store.GetProfileNameAsync();
}
public async Task<bool> RemoveProfileAsync(Store store, string profile)
{
return await store.RemoveProfileAsync(profile);
}

public async Task<Store> OpenStoreAsync(Store store, bool provision = false)
{
if (provision)
{
Expand All @@ -33,5 +57,25 @@ public Task<bool> RemoveStoreAsync(Store store)
{
return StoreApi.CloseAsync(store);
}

public async Task<bool> SetDefaultProfileAsync(Store store, string profile)
{
return await store.SetDefaultProfileAsync(profile);
}

public async Task<IEnumerable<AskarProfile>> GetListProfilesAsync(Store store)
{
var response = await store.GetListProfilesAsync();
var jobj = JArray.Parse(response.ToJson());
var profileList = new List<AskarProfile>();
foreach (var item in jobj)
{
profileList.Add(new AskarProfile
{
Name = item["profile_id"].ToString()
});
}
return profileList;
}
}
}
15 changes: 0 additions & 15 deletions src/Hyperledger.Aries/AskarStore/IStorageService.cs

This file was deleted.

13 changes: 13 additions & 0 deletions src/Hyperledger.Aries/AskarStore/Models/AskarProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using aries_askar_dotnet.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace Hyperledger.Aries.AskarStore.Models
{
public class AskarProfile
{
public string Name { get; set; }
public bool Opened { get; set; }
}
}

0 comments on commit e1ba60e

Please sign in to comment.