Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Browse files Browse the repository at this point in the history
…allet into feat/peer-connection-storage
  • Loading branch information
Sotatek-HocNguyena committed May 8, 2024
2 parents 1e55db1 + e5839a8 commit 42a5ed1
Show file tree
Hide file tree
Showing 90 changed files with 3,755 additions and 801 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
"env": {
"browser": true,
"es2021": true,
"jest": true
"jest": true,
"node": true
},
"globals": {
"__dirname": true,
"NodeJS": true
"NodeJS": true,
"process": "readonly"
},
"extends": [
"eslint:recommended",
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@capacitor-community/barcode-scanner": "^4.0.1",
"@capacitor-community/sqlite": "^5.5.0",
"@capacitor/android": "^5.0.0",
"@capacitor/app": "^5.0.7",
"@capacitor/clipboard": "^5.0.0",
"@capacitor/core": "^5.0.0",
"@capacitor/ios": "^5.0.0",
Expand Down
69 changes: 59 additions & 10 deletions src/core/agent/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ import { EventService } from "./services/eventService";
import {
BasicRecord,
BasicStorage,
ConnectionNoteRecord,
ConnectionNoteStorage,
ConnectionRecord,
ConnectionStorage,
CredentialMetadataRecord,
CredentialStorage,
IdentifierMetadataRecord,
IdentifierStorage,
PeerConnectionMetadataRecord,
PeerConnectionStorage,
NotificationRecord,
NotificationStorage,
} from "./records";
import { KeyStoreKeys, SecureStorage } from "../storage";
import { MultiSigService } from "./services/multiSigService";
Expand All @@ -47,6 +53,12 @@ class Agent {
private storageSession!: SqliteSession | IonicSession;

private basicStorageService!: BasicStorage;
private identifierStorage!: IdentifierStorage;
private credentialStorage!: CredentialStorage;
private connectionStorage!: ConnectionStorage;
private connectionNoteStorage!: ConnectionNoteStorage;
private notificationStorage!: NotificationStorage;

private signifyClient!: SignifyClient;
static ready = false;

Expand All @@ -62,37 +74,56 @@ class Agent {

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

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

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

get connections() {
if (!this.connectionService) {
this.connectionService = new ConnectionService(this.agentServicesProps);
this.connectionService = new ConnectionService(
this.agentServicesProps,
this.connectionStorage,
this.connectionNoteStorage,
this.credentialStorage
);
}
return this.connectionService;
}

get credentials() {
if (!this.credentialService) {
this.credentialService = new CredentialService(this.agentServicesProps);
this.credentialService = new CredentialService(
this.agentServicesProps,
this.credentialStorage,
this.notificationStorage
);
}
return this.credentialService;
}
Expand All @@ -113,7 +144,8 @@ class Agent {
get signifyNotifications() {
if (!this.signifyNotificationService) {
this.signifyNotificationService = new SignifyNotificationService(
this.agentServicesProps
this.agentServicesProps,
this.notificationStorage
);
}
return this.signifyNotificationService;
Expand All @@ -135,6 +167,25 @@ class Agent {
async start(): Promise<void> {
if (!Agent.ready) {
await this.storageSession.open(walletId);
this.basicStorageService = new BasicStorage(
this.getStorageService<BasicRecord>(this.storageSession)
);
this.identifierStorage = new IdentifierStorage(
this.getStorageService<IdentifierMetadataRecord>(this.storageSession)
);
this.credentialStorage = new CredentialStorage(
this.getStorageService<CredentialMetadataRecord>(this.storageSession)
);
this.connectionStorage = new ConnectionStorage(
this.getStorageService<ConnectionRecord>(this.storageSession)
);
this.connectionNoteStorage = new ConnectionNoteStorage(
this.getStorageService<ConnectionNoteRecord>(this.storageSession)
);
this.notificationStorage = new NotificationStorage(
this.getStorageService<NotificationRecord>(this.storageSession)
);

await signifyReady();
const bran = await this.getBran();
// @TODO - foconnor: Review of Tier level.
Expand All @@ -150,11 +201,8 @@ class Agent {
await this.signifyClient.boot();
await this.signifyClient.connect();
}
this.basicStorageService = new BasicStorage(
this.getStorageService<BasicRecord>(this.storageSession)
);

this.agentServicesProps = {
basicStorage: this.basicStorageService,
signifyClient: this.signifyClient,
eventService: new EventService(),
identifierStorage: new IdentifierStorage(
Expand All @@ -169,6 +217,7 @@ class Agent {
)
),
};

Agent.ready = true;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import { EventService } from "./services/eventService";
import { IdentifierStorage } from "./records/identifierStorage";
import { CredentialStorage } from "./records/credentialStorage";
import { BasicStorage } from "./records/basicStorage";
import { ConnectionHistoryType } from "./services/connection.types";
import { PeerConnectionStorage } from "./records";

Expand Down Expand Up @@ -97,7 +96,6 @@ interface KeriaNotificationMarker {
}

interface AgentServicesProps {
basicStorage: BasicStorage;
signifyClient: SignifyClient;
eventService: EventService;
identifierStorage: IdentifierStorage;
Expand Down
41 changes: 41 additions & 0 deletions src/core/agent/records/connectionNoteRecord.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { v4 as uuidv4 } from "uuid";
import { BaseRecord, Tags } from "../../storage/storage.types";

interface ConnectionNoteRecordStorageProps {
id?: string;
createdAt?: Date;
tags?: Tags;
connectionId: string;
title: string;
message: string;
}

class ConnectionNoteRecord extends BaseRecord {
connectionId!: string;
title!: string;
message!: string;
static readonly type = "ConnectionRecord";
readonly type = ConnectionNoteRecord.type;

constructor(props: ConnectionNoteRecordStorageProps) {
super();
if (props) {
this.id = props.id ?? uuidv4();
this.createdAt = props.createdAt ?? new Date();
this.connectionId = props.connectionId;
this.title = props.title;
this.message = props.message;
this._tags = props.tags ?? {};
}
}

getTags() {
return {
connectionId: this.connectionId,
...this._tags,
};
}
}

export type { ConnectionNoteRecordStorageProps };
export { ConnectionNoteRecord };

0 comments on commit 42a5ed1

Please sign in to comment.