Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): Improve delegation flow #420

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
5f87d7a
feat: add new interface for stored record
Sotatek-BaoHoanga Mar 12, 2024
b4979df
feat: add full function for ionic
Sotatek-BaoHoanga Mar 13, 2024
af94c42
feat: add sqlite basic storage
Sotatek-BaoHoanga Mar 17, 2024
d867517
fix: datetime parser with BasicRecord
Sotatek-BaoHoanga Mar 17, 2024
d7c4d23
fix: add missing case when filter condition is empty object
Sotatek-BaoHoanga Mar 17, 2024
e493db5
test: fix unit test signify notification
Sotatek-BaoHoanga Mar 17, 2024
3c3cc8d
feat: move signify api outside aries
Sotatek-BaoHoanga Mar 17, 2024
2d9a169
feat: remove aries in connection service
Sotatek-BaoHoanga Mar 18, 2024
3febc61
feat: remove aries in agent.ts
Sotatek-BaoHoanga Mar 18, 2024
6d63a9d
feat: remove Aries part 1
Sotatek-BaoHoanga Mar 19, 2024
8219a11
test: fix unit test for connection service
Sotatek-BaoHoanga Mar 19, 2024
0588f09
feat: remove Aries part 2
Sotatek-BaoHoanga Mar 20, 2024
849441c
feat: remove aries next step
Sotatek-BaoHoanga Mar 22, 2024
ee530a3
Merge branch 'develop' into feat/DTIS-720-aries-removal
Sotatek-BaoHoanga Mar 22, 2024
38d981a
feat: remove all aries things and can start wallet
Sotatek-BaoHoanga Mar 22, 2024
07447e5
fix: connection keri establish
Sotatek-BaoHoanga Mar 22, 2024
6e02f68
fix: credential acdc issuance
Sotatek-BaoHoanga Mar 22, 2024
bcad2a9
refactor: structure folder and unit test
Sotatek-BaoHoanga Mar 24, 2024
e1f0fa2
feat: remove aries on creds server
Sotatek-BaoHoanga Mar 24, 2024
94ab67d
feat: remove service for aries in docker-compose
Sotatek-BaoHoanga Mar 24, 2024
fa150cc
Merge branch 'develop' into feat/DTIS-720-aries-removal
Sotatek-BaoHoanga Mar 25, 2024
03d4652
Merge branch 'develop' into feat/DTIS-720-aries-removal
Sotatek-BaoHoanga Mar 25, 2024
57bc668
Merge branch 'feat/DTIS-720-aries-removal' into feat/aries-removal-in…
Sotatek-BaoHoanga Mar 25, 2024
0dea50b
fix: import failed for api
Sotatek-BaoHoanga Mar 25, 2024
713705f
test: fix unit test for aries remove
Sotatek-BaoHoanga Mar 25, 2024
f07b0c2
test: fix signify test
Sotatek-BaoHoanga Mar 25, 2024
6b53a0e
test: fix unit test for UI
Sotatek-BaoHoanga Mar 25, 2024
5f90a5d
fix: remove temporarily UI for testing
Sotatek-BaoHoanga Mar 25, 2024
c32e974
fix: try catch error when init basic storage
Sotatek-BaoHoanga Mar 25, 2024
8700d20
test: comment some unit test to pass pipeline
Sotatek-BaoHoanga Mar 25, 2024
33c3196
Merge branch 'feat/DTIS-720-aries-removal' into feat/aries-removal-in…
Sotatek-BaoHoanga Mar 25, 2024
e898bd3
feat: add JSONObject interface to cast data
Sotatek-BaoHoanga Mar 25, 2024
3de8a9c
test: open some test to pass cicd
Sotatek-BaoHoanga Mar 25, 2024
63e1aa5
Merge branch 'feat/DTIS-720-aries-removal' into feat/aries-removal-in…
Sotatek-BaoHoanga Mar 25, 2024
6a3d52a
fix: remove strip back UI related to Aries
Sotatek-BaoHoanga Mar 26, 2024
94551da
fix: remove unused import and did image
Sotatek-BaoHoanga Mar 26, 2024
bf17823
test: refactoring the UI test with removed type
Sotatek-BaoHoanga Mar 26, 2024
d276655
test: refactor bulk unit tests
Sotatek-BaoHoanga Mar 27, 2024
f024c83
feat: restructure agent service temporarily
Sotatek-BaoHoanga Apr 1, 2024
ffb2624
feat: restructure agent service part 2 - no unit test
Sotatek-BaoHoanga Apr 1, 2024
4c6a0b8
test: fix bulk unit tests
Sotatek-BaoHoanga Apr 2, 2024
50c461b
test: fix unit test and increase test coverage
Sotatek-BaoHoanga Apr 2, 2024
bd5371f
fix: remove stuffs
Sotatek-BaoHoanga Apr 2, 2024
4467b17
refactor: rename singleSigService to identifierService
Sotatek-BaoHoanga Apr 3, 2024
70b2ada
test: refactor all multisig test
Sotatek-BaoHoanga Apr 3, 2024
9e540ed
Merge branch 'develop' into feat/DTIS-728-agent-services-re-work
Sotatek-BaoHoanga Apr 9, 2024
ee2a22d
fix: merge develop phase 1
Sotatek-BaoHoanga Apr 9, 2024
e3f57df
test: fix all unit test when merge develop
Sotatek-BaoHoanga Apr 10, 2024
304e598
test: add unit test for storage
Sotatek-BaoHoanga Apr 10, 2024
5fdd7be
refactor: remove some stuff and add missing unittest
Sotatek-BaoHoanga Apr 11, 2024
d6b156e
Merge branch 'develop' into feat/DTIS-728-agent-services-re-work
Sotatek-BaoHoanga Apr 11, 2024
3370458
fix: some stuffs and move the function
Sotatek-BaoHoanga Apr 11, 2024
deb59c5
refactor: move the function to sense file
Sotatek-BaoHoanga Apr 11, 2024
541af85
feat: make storage more generic
Sotatek-BaoHoanga Apr 15, 2024
f1aeb0b
Merge branch 'develop' into feat/DTIS-728-agent-services-re-work
Sotatek-BaoHoanga Apr 15, 2024
bfa22ad
feat: improve delegation flow
Sotatek-BaoHoanga Apr 16, 2024
b110163
feat: update delegate prefix from URL
Sotatek-BaoHoanga Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-assets/mediator/Caddyfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
# format single_field common_log
level DEBUG
}
}
}
149 changes: 114 additions & 35 deletions src/core/agent/agent.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,115 @@
import { Capacitor } from "@capacitor/core";
import {
randomPasscode,
SignifyClient,
ready as signifyReady,
Tier,
} from "signify-ts";
import { Storage } from "@ionic/storage";
import {
ConnectionService,
CredentialService,
IdentifierService,
} from "./services";
import { SignifyNotificationService } from "./services/signifyNotificationService";
import { StorageApi } from "../storage/storage.types";
import { SqliteStorage } from "../storage/sqliteStorage";
import { AgentServicesProps } from "./agent.types";
import { EventService } from "./services/eventService";
import {
BasicRecord,
BasicStorage,
CredentialMetadataRecord,
CredentialStorage,
IdentifierMetadataRecord,
IdentifierStorage,
} from "./records";
import { KeyStoreKeys, SecureStorage } from "../storage";
import { MultiSigService } from "./services/multiSigService";
import { IpexCommunicationService } from "./services/ipexCommunicationService";
import { SqliteSession } from "../storage/sqliteStorage/sqliteSession";
import { IonicSession } from "../storage/ionicStorage/ionicSession";
import { IonicStorage } from "../storage/ionicStorage";
import { SignifyApi } from "./modules/signify/signifyApi";

const config = {
label: "idw-agent",
walletConfig: {
id: "idw",
key: "idw", // Right now, this key isn't used as we don't have encryption.
},
autoUpdateStorageOnStartup: true,
};
import { SqliteStorage } from "../storage/sqliteStorage";
import { BaseRecord } from "../storage/storage.types";

const walletId = "idw";
class Agent {
static readonly LOCAL_KERIA_ENDPOINT =
"https://dev.keria.cf-keripy.metadata.dev.cf-deployments.org";
static readonly LOCAL_KERIA_BOOT_ENDPOINT =
"https://dev.keria-boot.cf-keripy.metadata.dev.cf-deployments.org";

private static instance: Agent;
private basicRecordStorage!: StorageApi;
private signifyApi!: SignifyApi;
private agentServicesProps!: AgentServicesProps;

private storageSession!: SqliteSession | IonicSession;

private basicStorage!: BasicStorage;
private signifyClient!: SignifyClient;
static ready = false;

// @TODO - foconnor: Registering these should be more generic, but OK for now
private identifierService!: IdentifierService;
private multiSigService!: MultiSigService;
private ipexCommunicationService!: IpexCommunicationService;

private connectionService!: ConnectionService;
private credentialService!: CredentialService;
private signifyNotificationService!: SignifyNotificationService;

get identifiers() {
if (!this.identifierService) {
this.identifierService = new IdentifierService(
this.basicRecordStorage,
this.signifyApi
);
this.identifierService = new IdentifierService(this.agentServicesProps);
}
return this.identifierService;
}

get multiSigs() {
if (!this.multiSigService) {
this.multiSigService = new MultiSigService(this.agentServicesProps);
}
return this.multiSigService;
}

get ipexCommunications() {
if (!this.ipexCommunicationService) {
this.ipexCommunicationService = new IpexCommunicationService(
this.agentServicesProps
);
}
return this.ipexCommunicationService;
}

get connections() {
if (!this.connectionService) {
this.connectionService = new ConnectionService(
this.basicRecordStorage,
this.signifyApi
);
this.connectionService = new ConnectionService(this.agentServicesProps);
}
return this.connectionService;
}

get credentials() {
if (!this.credentialService) {
this.credentialService = new CredentialService(
this.basicRecordStorage,
this.signifyApi
);
this.credentialService = new CredentialService(this.agentServicesProps);
}
return this.credentialService;
}

get basicStorages() {
return this.basicRecordStorage;
return this.basicStorage;
}

get signifyNotifications() {
if (!this.signifyNotificationService) {
this.signifyNotificationService = new SignifyNotificationService(
this.basicRecordStorage,
this.signifyApi
this.agentServicesProps
);
}
return this.signifyNotificationService;
}

private constructor() {
this.basicRecordStorage = Capacitor.isNativePlatform()
? new SqliteStorage()
: new IonicStorage();
this.signifyApi = new SignifyApi();
this.storageSession = Capacitor.isNativePlatform()
? new SqliteSession()
: new IonicSession();
}

static get agent() {
Expand All @@ -90,11 +121,59 @@ class Agent {

async start(): Promise<void> {
if (!Agent.ready) {
await this.basicRecordStorage.open(config.walletConfig?.id || "idw");
await this.signifyApi.start();
await this.storageSession.open(walletId);
await signifyReady();
const bran = await this.getBran();
// @TODO - foconnor: Review of Tier level.
this.signifyClient = new SignifyClient(
Agent.LOCAL_KERIA_ENDPOINT,
bran,
Tier.low,
Agent.LOCAL_KERIA_BOOT_ENDPOINT
);
try {
await this.signifyClient.connect();
} catch (err) {
await this.signifyClient.boot();
await this.signifyClient.connect();
}
this.basicStorage = new BasicStorage(
this.getStorageService<BasicRecord>(this.storageSession)
);
this.agentServicesProps = {
basicStorage: this.basicStorage,
signifyClient: this.signifyClient,
eventService: new EventService(),
identifierStorage: new IdentifierStorage(
this.getStorageService<IdentifierMetadataRecord>(this.storageSession)
),
credentialStorage: new CredentialStorage(
this.getStorageService<CredentialMetadataRecord>(this.storageSession)
),
};
Agent.ready = true;
}
}

private async getBran(): Promise<string> {
let bran;
try {
bran = await SecureStorage.get(KeyStoreKeys.SIGNIFY_BRAN);
} catch (error) {
bran = randomPasscode();
await SecureStorage.set(KeyStoreKeys.SIGNIFY_BRAN, bran);
}
return bran as string;
}

private getStorageService<T extends BaseRecord>(
instance: IonicSession | SqliteSession
) {
if (instance instanceof IonicSession) {
return new IonicStorage<T>(instance.session!);
}
return new SqliteStorage<T>(instance.session!);
}
}

export { Agent };
154 changes: 154 additions & 0 deletions src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { SignifyClient } from "signify-ts";
import {
CredentialShortDetails,
CredentialStatus,
} from "./services/credentialService.types";
import { EventService } from "./services/eventService";
import { IdentifierStorage } from "./records/identifierStorage";
import { CredentialStorage } from "./records/credentialStorage";
import { BasicStorage } from "./records/basicStorage";

enum Blockchain {
CARDANO = "Cardano",
Expand Down Expand Up @@ -103,13 +108,153 @@ interface KeriaNotificationMarker {
lastNotificationId: string;
}

interface AgentServicesProps {
basicStorage: BasicStorage;
signifyClient: SignifyClient;
eventService: EventService;
identifierStorage: IdentifierStorage;
credentialStorage: CredentialStorage;
}
enum MultiSigRoute {
ROT = "/multisig/rot",
ICP = "/multisig/icp",
IXN = "/multisig/ixn",
}

interface CreateIdentifierResult {
signifyName: string;
identifier: string;
}

interface KeriContact {
alias: string;
id: string;
oobi: string;
challenges: string[];
wellKnowns: string[];
}

interface IdentifierResult {
name: string;
prefix: string;
salty: any;
}

interface IdentifiersListResult {
aids: IdentifierResult[];
start: 0;
end: 0;
total: 0;
}

interface CreateMultisigExnPayload {
gid: string;
smids: any[];
rmids: any;
rstates: any;
name: string;
}

interface Aid {
name: string;
prefix: string;
salty: any;
transferable: boolean;
state: {
vn: number[];
i: string;
s: string;
p: string;
d: string;
f: string;
dt: string;
et: string;
kt: string;
k: string[];
nt: string;
n: string[];
bt: string;
b: string[];
c: string[];
ee: {
s: string;
d: string;
br: any[];
ba: any[];
};
di: string;
};
windexes: number[];
}

interface MultiSigExnMessage {
exn: {
v: string;
t: string;
d: string;
i: string;
p: string;
dt: string;
r: string;
q: any;
a: {
gid: string;
smids: string[];
rmids: string[];
rstates: Aid["state"][];
name: string;
};
e: {
icp: {
v: string;
t: string;
d: string;
i: string;
s: string;
kt: string;
k: string[];
nt: string;
n: string[];
bt: string;
b: string[];
c: any[];
a: any[];
};
d: string;
};
};
}

enum NotificationRoute {
Credential = "/exn/ipex/grant",
MultiSigIcp = "/multisig/icp",
MultiSigRot = "/multisig/rot",
}

enum OOBIScan {
Delegated,
Aid,
}

type ScanOOBIRes =
| {
oobiType: OOBIScan.Aid;
}
| {
oobiType: OOBIScan.Delegated;
delegatePrefix: string;
};

export {
Blockchain,
ConnectionStatus,
ConnectionHistoryType,
MiscRecordId,
ConnectionKeriEventTypes,
AcdcKeriEventTypes,
NotificationRoute,
MultiSigRoute,
OOBIScan,
};

export type {
Expand All @@ -124,4 +269,13 @@ export type {
AcdcKeriStateChangedEvent,
BaseEventEmitter,
KeriaNotificationMarker,
AgentServicesProps,
CreateIdentifierResult,
KeriContact,
IdentifiersListResult,
CreateMultisigExnPayload,
MultiSigExnMessage,
Aid,
IdentifierResult,
ScanOOBIRes,
};
Loading
Loading