diff --git a/src/index.ts b/src/index.ts index 128ecdd1..7ef8644c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { Domain } from "@input-output-hk/atala-prism-wallet-sdk"; +import type { Domain } from "@input-output-hk/atala-prism-wallet-sdk"; import { getRxStorageDexie } from "rxdb/plugins/storage-dexie"; import { wrappedKeyEncryptionCryptoJsStorage } from "rxdb/plugins/encryption-crypto-js"; import { createRxDatabase } from "rxdb"; @@ -8,7 +8,7 @@ import { RxDBMigrationPlugin } from "rxdb/plugins/migration"; import MessageSchema from "./schemas/Message"; import DIDSchema from "./schemas/DID"; -import { PlutoDatabase } from "./types"; +import { PlutoCollections, PlutoDatabase } from "./types"; import CredentialSchema from "./schemas/Credential"; import DIDPairSchema from "./schemas/DIDPair"; import MediatorSchema from "./schemas/Mediator"; @@ -16,6 +16,7 @@ import PrivateKeySchema from "./schemas/PrivateKey"; addRxPlugin(RxDBMigrationPlugin); //New change + export class Database implements Domain.Pluto { constructor(private db: PlutoDatabase) {} @@ -29,14 +30,14 @@ export class Database implements Domain.Pluto { }), password: Buffer.from(encryptionKey).toString("hex"), }); - await myDatabase.addCollections({ + await myDatabase.addCollections({ messages: { schema: MessageSchema, }, dids: { schema: DIDSchema, }, - credentials: { + verifiableCredentials: { schema: CredentialSchema, }, didpairs: { @@ -73,7 +74,7 @@ export class Database implements Domain.Pluto { throw new Error("Method not implemented."); } - storePrismDID( + async storePrismDID( did: Domain.DID, keyPathIndex: number, privateKey: Domain.PrivateKey, @@ -114,6 +115,7 @@ export class Database implements Domain.Pluto { ): Promise { throw new Error("Method not implemented."); } + storeCredential(credential: Domain.VerifiableCredential): Promise { throw new Error("Method not implemented."); } @@ -150,7 +152,6 @@ export class Database implements Domain.Pluto { getPairByName(name: string): Promise { throw new Error("Method not implemented."); } - getAllMessagesByDID(did: Domain.DID): Promise { throw new Error("Method not implemented."); } diff --git a/src/schemas/Mediator.ts b/src/schemas/Mediator.ts index 3fbf799d..5d8c22c3 100644 --- a/src/schemas/Mediator.ts +++ b/src/schemas/Mediator.ts @@ -1,11 +1,6 @@ -import { GenerateDBSchema } from "../types"; +import { GenerateDBSchema, MediarorSchemaType } from "../types"; -const MediatorSchema: GenerateDBSchema<{ - id: string; - mediatorDID: string; - hostDID: string; - routingDID: string; -}> = { +const MediatorSchema: GenerateDBSchema = { version: 0, primaryKey: "id", type: "object", diff --git a/src/schemas/Message.ts b/src/schemas/Message.ts index 7417b427..4870c734 100644 --- a/src/schemas/Message.ts +++ b/src/schemas/Message.ts @@ -1,7 +1,6 @@ -import { Domain } from "@input-output-hk/atala-prism-wallet-sdk"; -import { GenerateDBSchema } from "../types"; +import { GenerateDBSchema, MessageSchemaType } from "../types"; -const MessageSchema: GenerateDBSchema = { +const MessageSchema: GenerateDBSchema = { version: 0, primaryKey: "id", type: "object", diff --git a/src/types.ts b/src/types.ts index 70266f06..55bed25e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,13 +1,14 @@ -import { Domain } from "@input-output-hk/atala-prism-wallet-sdk"; +import type { Domain } from "@input-output-hk/atala-prism-wallet-sdk"; import { RxJsonSchema, RxCollection, RxDatabase } from "rxdb"; -export type ExcludeKeys = Omit; + +export type ExcludeKeys = { + [P in Exclude]: T[P]; +}; + export type GenerateDBSchema = RxJsonSchema & { encrypted: (keyof T)[]; }; -export type MessagesCollection = RxCollection; -export type PlutoDatabase = RxDatabase<{ - messages: MessagesCollection; -}>; + export type CredentialSchemaType = Domain.VerifiableCredential; export type DIDSchemaType = ExcludeKeys< Domain.DID & { readonly alias: string; readonly did: string }, @@ -15,24 +16,31 @@ export type DIDSchemaType = ExcludeKeys< >; export type DIDPairSchemaType = Domain.DIDPair & { readonly id: string }; export type KeySchemaType = ExcludeKeys< - ExcludeKeys< - ExcludeKeys< - ExcludeKeys< - ExcludeKeys< - ExcludeKeys< - ExcludeKeys< - ExcludeKeys, - "size" - >, - "getProperty" - >, - "isDerivable" - >, - "isSignable" - >, - "getEncoded" - >, - "canVerify" - >, - "isCurve" + Domain.Key & { readonly id: string }, + | "isExportable" + | "size" + | "getProperty" + | "isDerivable" + | "isSignable" + | "getEncoded" + | "canVerify" + | "isCurve" >; + +export type MediarorSchemaType = { + id: string; + mediatorDID: string; + hostDID: string; + routingDID: string; +}; +export type MessageSchemaType = Domain.Message; + +export type PlutoCollections = { + messages: RxCollection; + dids: RxCollection; + verifiableCredentials: RxCollection; + didpairs: RxCollection; + mediators: RxCollection; + privateKeys: RxCollection; +}; +export type PlutoDatabase = RxDatabase;