diff --git a/packages/database/src/index.ts b/packages/database/src/index.ts index 6e9fcaa0..c994e0b3 100644 --- a/packages/database/src/index.ts +++ b/packages/database/src/index.ts @@ -4,7 +4,7 @@ * * */ -import { Domain, PeerDID } from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' import { type MangoQuerySelector, type RxCollectionCreator, type RxDatabase, @@ -68,7 +68,7 @@ export type PlutoDatabase = RxDatabase * which will be implemented using this SDK. Implement this interface using your * preferred underlying storage technology, most appropriate for your use case. */ -export class Database implements Domain.Pluto { +export class Database implements SDK.Domain.Pluto { private _db!: RxDatabase protected get db() { @@ -422,7 +422,7 @@ export class Database implements Domain.Pluto { * @param id * @returns [Message](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) */ - async getMessage(id: string): Promise { + async getMessage(id: string): Promise { const message = await this.db.messages.findOne({ selector: { id: { @@ -441,7 +441,7 @@ export class Database implements Domain.Pluto { * @param [Message](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) * @returns void */ - async storeMessage(message: Domain.Message): Promise { + async storeMessage(message: SDK.Domain.Message): Promise { const existing = await this.db.messages .findOne({ selector: { @@ -470,7 +470,7 @@ export class Database implements Domain.Pluto { * @param [Message[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) * @returns void */ - async storeMessages(messages: Domain.Message[]): Promise { + async storeMessages(messages: SDK.Domain.Message[]): Promise { for (const message of messages) { await this.storeMessage(message) } @@ -480,7 +480,7 @@ export class Database implements Domain.Pluto { * Get all the stored messages * @returns [Message[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) */ - async getAllMessages(): Promise { + async getAllMessages(): Promise { const messages = await this.db.messages.find().exec() return messages.map((message) => message.toDomainMessage()) } @@ -557,9 +557,9 @@ export class Database implements Domain.Pluto { * @param alias */ async storePrismDID( - did: Domain.DID, + did: SDK.Domain.DID, keyPathIndex: number, - privateKey: Domain.PrivateKey, + privateKey: SDK.Domain.PrivateKey, _privateKeyMetaId?: string | null, alias?: string | undefined ): Promise { @@ -583,8 +583,8 @@ export class Database implements Domain.Pluto { * @param privateKeys */ async storePeerDID( - did: Domain.DID, - privateKeys: Domain.PrivateKey[] + did: SDK.Domain.DID, + privateKeys: SDK.Domain.PrivateKey[] ): Promise { await this.db.dids.insert({ did: did.toString(), @@ -625,8 +625,8 @@ export class Database implements Domain.Pluto { * @param name */ async storeDIDPair( - host: Domain.DID, - receiver: Domain.DID, + host: SDK.Domain.DID, + receiver: SDK.Domain.DID, name: string ): Promise { await this.db.didpairs.insert({ @@ -644,8 +644,8 @@ export class Database implements Domain.Pluto { * @param _metaId */ async storePrivateKeys( - privateKey: Domain.PrivateKey, - did: Domain.DID, + privateKey: SDK.Domain.PrivateKey, + did: SDK.Domain.DID, keyPathIndex: number ): Promise { await this.db.privatekeys.insert({ @@ -681,12 +681,11 @@ export class Database implements Domain.Pluto { * Gets all the stores didPairs * @returns [Domain.DIDPair[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.DIDPair.html) */ - async getAllDidPairs(): Promise { - const { DID, DIDPair } = Domain + async getAllDidPairs(): Promise { const results = await this.db.didpairs.find().exec() return results.map( ({ hostDID, receiverDID, name }) => - new DIDPair(DID.fromString(hostDID), DID.fromString(receiverDID), name) + new SDK.Domain.DIDPair(SDK.Domain.DID.fromString(hostDID), SDK.Domain.DID.fromString(receiverDID), name) ) } @@ -695,8 +694,7 @@ export class Database implements Domain.Pluto { * @param did * @returns [Domain.DIDPair](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.DIDPair.html) */ - async getPairByDID(did: Domain.DID): Promise { - const { DID, DIDPair } = Domain + async getPairByDID(did: SDK.Domain.DID): Promise { const didPair = await this.db.didpairs .findOne({ selector: { @@ -711,16 +709,15 @@ export class Database implements Domain.Pluto { } }).exec() return didPair - ? new DIDPair( - DID.fromString(didPair.hostDID), - DID.fromString(didPair.receiverDID), + ? new SDK.Domain.DIDPair( + SDK.Domain.DID.fromString(didPair.hostDID), + SDK.Domain.DID.fromString(didPair.receiverDID), didPair.name ) : null } - async getPairByName(name: string): Promise { - const { DID, DIDPair } = Domain + async getPairByName(name: string): Promise { const didPair = await this.db.didpairs .findOne({ selector: { @@ -733,9 +730,9 @@ export class Database implements Domain.Pluto { }).exec() return didPair - ? new DIDPair( - DID.fromString(didPair.hostDID), - DID.fromString(didPair.receiverDID), + ? new SDK.Domain.DIDPair( + SDK.Domain.DID.fromString(didPair.hostDID), + SDK.Domain.DID.fromString(didPair.receiverDID), didPair.name ) : null @@ -743,11 +740,11 @@ export class Database implements Domain.Pluto { private getPrivateKeyFromDB( privateKey: PrivateKeyDocument - ): Domain.PrivateKey { + ): SDK.Domain.PrivateKey { return privateKey.toDomainPrivateKey() } - async getDIDPrivateKeysByDID(did: Domain.DID): Promise { + async getDIDPrivateKeysByDID(did: SDK.Domain.DID): Promise { const privateKeys = await this.db.privatekeys .find({ selector: { @@ -761,7 +758,7 @@ export class Database implements Domain.Pluto { }) } - async getDIDPrivateKeyByID(id: string): Promise { + async getDIDPrivateKeyByID(id: string): Promise { const privateKey = await this.db.privatekeys.findOne({ selector: { id: { @@ -773,9 +770,9 @@ export class Database implements Domain.Pluto { } async storeMediator( - mediator: Domain.DID, - host: Domain.DID, - routing: Domain.DID + mediator: SDK.Domain.DID, + host: SDK.Domain.DID, + routing: SDK.Domain.DID ): Promise { await this.db.mediators.insert({ id: uuidv4(), @@ -785,7 +782,7 @@ export class Database implements Domain.Pluto { }) } - async getAllPrismDIDs(): Promise { + async getAllPrismDIDs(): Promise { const dids = await this.db.dids.find({ selector: { method: { @@ -794,19 +791,19 @@ export class Database implements Domain.Pluto { } }).exec() - const prismDIDInfo: Domain.PrismDIDInfo[] = [] + const prismDIDInfo: SDK.Domain.PrismDIDInfo[] = [] for (const did of dids) { const didPrivateKeys = await this.getDIDPrivateKeysByDID( - Domain.DID.fromString(did.did) + SDK.Domain.DID.fromString(did.did) ) for (const privateKey of didPrivateKeys) { - const indexProp = privateKey.getProperty(Domain.KeyProperties.index)! + const indexProp = privateKey.getProperty(SDK.Domain.KeyProperties.index)! prismDIDInfo.push( - new Domain.PrismDIDInfo( - Domain.DID.fromString(did.did), + new SDK.Domain.PrismDIDInfo( + SDK.Domain.DID.fromString(did.did), parseInt(indexProp), did.alias ) @@ -817,7 +814,7 @@ export class Database implements Domain.Pluto { return prismDIDInfo } - async getDIDInfoByDID(did: Domain.DID): Promise { + async getDIDInfoByDID(did: SDK.Domain.DID): Promise { const didDB = await this.db.dids .findOne({ selector: { @@ -827,7 +824,7 @@ export class Database implements Domain.Pluto { if (didDB) { const privateKeys = await this.getDIDPrivateKeysByDID( - Domain.DID.fromString(didDB.did) + SDK.Domain.DID.fromString(didDB.did) ) /* istanbul ignore if */ if (privateKeys.length === 0) { @@ -837,10 +834,10 @@ export class Database implements Domain.Pluto { } const indexProp = privateKeys .at(0)! - .getProperty(Domain.KeyProperties.index) + .getProperty(SDK.Domain.KeyProperties.index) const index = indexProp ? parseInt(indexProp) : undefined - return new Domain.PrismDIDInfo( - Domain.DID.fromString(didDB.did), + return new SDK.Domain.PrismDIDInfo( + SDK.Domain.DID.fromString(didDB.did), index, didDB.alias ) @@ -849,7 +846,7 @@ export class Database implements Domain.Pluto { return null } - async getDIDInfoByAlias(alias: string): Promise { + async getDIDInfoByAlias(alias: string): Promise { const dids = await this.db.dids.find({ selector: { alias: { @@ -857,16 +854,16 @@ export class Database implements Domain.Pluto { } } }).exec() - const prismDIDInfo: Domain.PrismDIDInfo[] = [] + const prismDIDInfo: SDK.Domain.PrismDIDInfo[] = [] for (const did of dids) { const didPrivateKeys = await this.getDIDPrivateKeysByDID( - Domain.DID.fromString(did.did) + SDK.Domain.DID.fromString(did.did) ) for (const privateKey of didPrivateKeys) { - const indexProp = privateKey.getProperty(Domain.KeyProperties.index)! + const indexProp = privateKey.getProperty(SDK.Domain.KeyProperties.index)! prismDIDInfo.push( - new Domain.PrismDIDInfo( - Domain.DID.fromString(did.did), + new SDK.Domain.PrismDIDInfo( + SDK.Domain.DID.fromString(did.did), parseInt(indexProp), did.alias ) @@ -876,7 +873,7 @@ export class Database implements Domain.Pluto { return prismDIDInfo } - async getAllMessagesByDID(did: Domain.DID): Promise { + async getAllMessagesByDID(did: SDK.Domain.DID): Promise { const messages = await this.db.messages .find({ selector: { @@ -894,13 +891,13 @@ export class Database implements Domain.Pluto { return messages.map((message) => message.toDomainMessage()) } - async getAllMessagesSent(): Promise { + async getAllMessagesSent(): Promise { const messages = await this.db.messages .find({ selector: { $or: [ { - direction: Domain.MessageDirection.SENT + direction: SDK.Domain.MessageDirection.SENT } ] } @@ -909,13 +906,13 @@ export class Database implements Domain.Pluto { return messages.map((message) => message.toDomainMessage()) } - async getAllMessagesReceived(): Promise { + async getAllMessagesReceived(): Promise { const messages = await this.db.messages .find({ selector: { $or: [ { - direction: Domain.MessageDirection.RECEIVED + direction: SDK.Domain.MessageDirection.RECEIVED } ] } @@ -924,7 +921,7 @@ export class Database implements Domain.Pluto { return messages.map((message) => message.toDomainMessage()) } - async getAllMessagesSentTo(did: Domain.DID): Promise { + async getAllMessagesSentTo(did: SDK.Domain.DID): Promise { const messages = await this.db.messages .find({ selector: { @@ -933,7 +930,7 @@ export class Database implements Domain.Pluto { to: did.toString() }, { - direction: Domain.MessageDirection.SENT + direction: SDK.Domain.MessageDirection.SENT } ] } @@ -941,7 +938,7 @@ export class Database implements Domain.Pluto { return messages.map((message) => message.toDomainMessage()) } - async getAllMessagesReceivedFrom(did: Domain.DID): Promise { + async getAllMessagesReceivedFrom(did: SDK.Domain.DID): Promise { const messages = await this.db.messages .find({ selector: { @@ -950,7 +947,7 @@ export class Database implements Domain.Pluto { from: did.toString() }, { - direction: Domain.MessageDirection.RECEIVED + direction: SDK.Domain.MessageDirection.RECEIVED } ] } @@ -960,8 +957,8 @@ export class Database implements Domain.Pluto { async getAllMessagesOfType( type: string, - relatedWithDID?: Domain.DID | undefined - ): Promise { + relatedWithDID?: SDK.Domain.DID | undefined + ): Promise { const query: Array> = [ { piuri: type @@ -990,9 +987,9 @@ export class Database implements Domain.Pluto { } async getAllMessagesByFromToDID( - from: Domain.DID, - to: Domain.DID - ): Promise { + from: SDK.Domain.DID, + to: SDK.Domain.DID + ): Promise { const messages = await this.db.messages .find({ selector: { @@ -1010,7 +1007,7 @@ export class Database implements Domain.Pluto { return messages.map((message) => message.toDomainMessage()) } - async getPrismDIDKeyPathIndex(did: Domain.DID): Promise { + async getPrismDIDKeyPathIndex(did: SDK.Domain.DID): Promise { const [key] = await this.getDIDPrivateKeysByDID(did) if (!key) { return null @@ -1026,8 +1023,8 @@ export class Database implements Domain.Pluto { return Math.max(...results.map((result) => result.keyPathIndex)) } - async getAllPeerDIDs(): Promise { - const peerDIDs: PeerDID[] = [] + async getAllPeerDIDs(): Promise { + const peerDIDs: SDK.PeerDID[] = [] const dids = await this.db.dids.find({ selector: { method: { @@ -1036,10 +1033,10 @@ export class Database implements Domain.Pluto { } }).exec() for (const did of dids) { - const peerDID = Domain.DID.fromString(did.did) + const peerDID = SDK.Domain.DID.fromString(did.did) const keys = await this.getDIDPrivateKeysByDID(peerDID) peerDIDs.push( - new PeerDID( + new SDK.PeerDID( peerDID, keys.map((key) => ({ keyCurve: { @@ -1053,7 +1050,7 @@ export class Database implements Domain.Pluto { return peerDIDs } - async storeCredential(credential: Domain.Credential): Promise { + async storeCredential(credential: SDK.Domain.Credential): Promise { if (!credential.isStorable || !credential.isStorable()) { throw new Error('Credential is not storable') } @@ -1064,12 +1061,12 @@ export class Database implements Domain.Pluto { await this.db.credentials.insert(storable) } - async getAllMediators(): Promise { + async getAllMediators(): Promise { const mediators = await this.db.mediators.find().exec() return mediators.map((mediator) => mediator.toDomainMediator()) } - async getAllCredentials(): Promise { + async getAllCredentials(): Promise { const credentials = await this.db.credentials.find().exec() return credentials.map( (verifiableCredential) => verifiableCredential.toDomainCredential() @@ -1110,7 +1107,7 @@ export class Database implements Domain.Pluto { } async storeCredentialMetadata( - metadata: Domain.Anoncreds.CredentialRequestMeta, + metadata: SDK.Domain.Anoncreds.CredentialRequestMeta, linkSecret: string ): Promise { await this.db.credentialrequestmetadatas.insert({ @@ -1122,7 +1119,7 @@ export class Database implements Domain.Pluto { async fetchCredentialMetadata( linkSecretName: string - ): Promise { + ): Promise { const credentialRequestMetadata = await this.db.credentialrequestmetadatas .findOne({ selector: { diff --git a/packages/database/src/schemas/Credential.ts b/packages/database/src/schemas/Credential.ts index f696f84f..0e35b3fd 100644 --- a/packages/database/src/schemas/Credential.ts +++ b/packages/database/src/schemas/Credential.ts @@ -1,11 +1,4 @@ -import { - AnonCredsCredential, - AnonCredsCredentialProperties, - AnonCredsRecoveryId, - type Domain, - JWTCredential, - JWTVerifiableCredentialRecoveryId -} from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' import type { Schema } from '../types' import { type RxCollection, type RxDocument } from 'rxdb' @@ -78,27 +71,27 @@ const CredentialSchema: Schema = { export type CredentialDocument = RxDocument export interface CredentialMethodTypes { - toDomainCredential: (this: CredentialSchemaType) => Domain.Credential + toDomainCredential: (this: CredentialSchemaType) => SDK.Domain.Credential } export const CredentialMethods: CredentialMethodTypes = { toDomainCredential: function toDomainCredential(this: CredentialSchemaType) { - if (this.recoveryId === JWTVerifiableCredentialRecoveryId) { + if (this.recoveryId === SDK.JWTVerifiableCredentialRecoveryId) { const jwtString = Buffer.from(this.credentialData).toString() const jwtObj = JSON.parse(jwtString) - return JWTCredential.fromJWT(jwtObj, jwtString) - } else if (this.recoveryId === AnonCredsRecoveryId) { + return SDK.JWTCredential.fromJWT(jwtObj, jwtString) + } else if (this.recoveryId === SDK.AnonCredsRecoveryId) { const credentialData = Buffer.from(this.credentialData).toString() const credentialJson = JSON.parse(credentialData) - return new AnonCredsCredential({ - schema_id: credentialJson[AnonCredsCredentialProperties.schemaId], + return new SDK.AnonCredsCredential({ + schema_id: credentialJson[SDK.AnonCredsCredentialProperties.schemaId], cred_def_id: - credentialJson[AnonCredsCredentialProperties.credentialDefinitionId], - values: credentialJson[AnonCredsCredentialProperties.values], - signature: credentialJson[AnonCredsCredentialProperties.signature], + credentialJson[SDK.AnonCredsCredentialProperties.credentialDefinitionId], + values: credentialJson[SDK.AnonCredsCredentialProperties.values], + signature: credentialJson[SDK.AnonCredsCredentialProperties.signature], signature_correctness_proof: credentialJson[ - AnonCredsCredentialProperties.signatureCorrectnessProof + SDK.AnonCredsCredentialProperties.signatureCorrectnessProof ] }) } else { diff --git a/packages/database/src/schemas/CredentialRequestMetadata.ts b/packages/database/src/schemas/CredentialRequestMetadata.ts index 87d712b1..085a40cd 100644 --- a/packages/database/src/schemas/CredentialRequestMetadata.ts +++ b/packages/database/src/schemas/CredentialRequestMetadata.ts @@ -1,6 +1,4 @@ -import { - type Domain -} from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' import type { Schema } from '../types' import { type RxCollection, type RxDocument } from 'rxdb' @@ -48,13 +46,13 @@ export type CredentialRequestMetadataDocument = export interface CredentialRequestMetadataMethodTypes { toDomainCredentialRequestMetadata: ( this: CredentialRequestMetadataSchemaType - ) => Domain.Anoncreds.CredentialRequestMeta + ) => SDK.Domain.Anoncreds.CredentialRequestMeta } export const CredentialRequestMetadataMethods: CredentialRequestMetadataMethodTypes = { toDomainCredentialRequestMetadata: - function toDomainCredentialRequestMetadata ( + function toDomainCredentialRequestMetadata( this: CredentialRequestMetadataSchemaType ) { return this @@ -62,9 +60,9 @@ export const CredentialRequestMetadataMethods: CredentialRequestMetadataMethodTy } export type CredentialRequestMetadataCollection = RxCollection< -CredentialRequestMetadataSchemaType, -CredentialRequestMetadataMethodTypes, -CredentialRequestMetadataDocument + CredentialRequestMetadataSchemaType, + CredentialRequestMetadataMethodTypes, + CredentialRequestMetadataDocument > export default CredentialRequestMetadataSchema diff --git a/packages/database/src/schemas/LinkSecret.ts b/packages/database/src/schemas/LinkSecret.ts index 5ef3d830..bf179c27 100644 --- a/packages/database/src/schemas/LinkSecret.ts +++ b/packages/database/src/schemas/LinkSecret.ts @@ -1,4 +1,4 @@ -import { type Domain } from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' import type { Schema } from '../types' import { type RxCollection, type RxDocument } from 'rxdb' @@ -25,22 +25,22 @@ const LinkSecretSchema: Schema = { } export type LinkSecretDocument = RxDocument< -LinkSecretSchemaType, -LinkSecretMethodTypes + LinkSecretSchemaType, + LinkSecretMethodTypes > export interface LinkSecretMethodTypes { - toDomainLinkSecret: (this: LinkSecretDocument) => Domain.Anoncreds.LinkSecret + toDomainLinkSecret: (this: LinkSecretDocument) => SDK.Domain.Anoncreds.LinkSecret } export type LinkSecretColletion = RxCollection< -LinkSecretSchemaType, -LinkSecretMethodTypes, -LinkSecretDocument + LinkSecretSchemaType, + LinkSecretMethodTypes, + LinkSecretDocument > export const LinkSecretMethods: LinkSecretMethodTypes = { - toDomainLinkSecret: function toDomainLinkSecret (this: LinkSecretDocument) { + toDomainLinkSecret: function toDomainLinkSecret(this: LinkSecretDocument) { return this.secret } } diff --git a/packages/database/src/schemas/Mediator.ts b/packages/database/src/schemas/Mediator.ts index 001c41c7..f51a5ffa 100644 --- a/packages/database/src/schemas/Mediator.ts +++ b/packages/database/src/schemas/Mediator.ts @@ -1,6 +1,6 @@ import { type RxCollection, type RxDocument } from 'rxdb' import type { Schema } from '../types' -import { Domain } from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' export interface MediatorSchemaType { id: string @@ -34,21 +34,21 @@ const MediatorSchema: Schema = { export type MediatorDocument = RxDocument export interface MediatorMethodTypes { - toDomainMediator: (this: RxDocument) => Domain.Mediator + toDomainMediator: (this: RxDocument) => SDK.Domain.Mediator } export type MediatorCollection = RxCollection< -MediatorSchemaType, -MediatorMethodTypes, -MediatorDocument + MediatorSchemaType, + MediatorMethodTypes, + MediatorDocument > export const MediatorMethods: MediatorMethodTypes = { - toDomainMediator: function toDomainMediator (this: RxDocument) { + toDomainMediator: function toDomainMediator(this: RxDocument) { const mediator = this.toJSON() return { - hostDID: Domain.DID.fromString(mediator.hostDID), - routingDID: Domain.DID.fromString(mediator.routingDID), - mediatorDID: Domain.DID.fromString(mediator.mediatorDID) + hostDID: SDK.Domain.DID.fromString(mediator.hostDID), + routingDID: SDK.Domain.DID.fromString(mediator.routingDID), + mediatorDID: SDK.Domain.DID.fromString(mediator.mediatorDID) } } } diff --git a/packages/database/src/schemas/Message.ts b/packages/database/src/schemas/Message.ts index 4969959d..4713d43c 100644 --- a/packages/database/src/schemas/Message.ts +++ b/packages/database/src/schemas/Message.ts @@ -1,4 +1,4 @@ -import { Domain } from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' import type { Schema } from '../types' import { type RxCollection, type RxDocument } from 'rxdb' @@ -8,13 +8,13 @@ export interface MessageSchemaType { readonly piuri: string readonly from?: string | undefined readonly to?: string | undefined - readonly attachments: Domain.AttachmentDescriptor[] + readonly attachments: SDK.Domain.AttachmentDescriptor[] readonly thid?: string readonly extraHeaders: string[] readonly createdTime: string readonly expiresTimePlus: string readonly ack: string[] - readonly direction: Domain.MessageDirection + readonly direction: SDK.Domain.MessageDirection readonly fromPrior?: string | undefined readonly pthid?: string | undefined } @@ -107,18 +107,18 @@ const MessageSchema: Schema = { export type MessageDocument = RxDocument export interface MessageMethodTypes { - toDomainMessage: (this: MessageDocument) => Domain.Message + toDomainMessage: (this: MessageDocument) => SDK.Domain.Message } export type MessageColletion = RxCollection< -MessageSchemaType, -MessageMethodTypes, -MessageDocument + MessageSchemaType, + MessageMethodTypes, + MessageDocument > export const MessageMethods: MessageMethodTypes = { - toDomainMessage: function toDomainMessage (this: MessageDocument) { - return Domain.Message.fromJson(JSON.stringify(this)) + toDomainMessage: function toDomainMessage(this: MessageDocument) { + return SDK.Domain.Message.fromJson(JSON.stringify(this)) } } diff --git a/packages/database/src/schemas/PrivateKey.ts b/packages/database/src/schemas/PrivateKey.ts index 2105fa1d..d55fde25 100644 --- a/packages/database/src/schemas/PrivateKey.ts +++ b/packages/database/src/schemas/PrivateKey.ts @@ -1,13 +1,8 @@ -import { - Ed25519PrivateKey, - KeyProperties, - Secp256k1PrivateKey, - X25519PrivateKey, - Domain -} from '@atala/prism-wallet-sdk' +import SDK from '@atala/prism-wallet-sdk' import type { Schema } from '../types' import { type RxCollection, type RxDocument } from 'rxdb' + export interface KeySpec { name: string type: string @@ -59,28 +54,28 @@ const PrivateKeySchema: Schema = { } export interface PrivateKeyMethodTypes { - toDomainPrivateKey: (this: PrivateKeyDocument) => Domain.PrivateKey + toDomainPrivateKey: (this: PrivateKeyDocument) => SDK.Domain.PrivateKey } export type PrivateKeyColletion = RxCollection< -KeySchemaType, -PrivateKeyMethodTypes, -PrivateKeyDocument + KeySchemaType, + PrivateKeyMethodTypes, + PrivateKeyDocument > export type PrivateKeyDocument = RxDocument< -KeySchemaType, -PrivateKeyMethodTypes + KeySchemaType, + PrivateKeyMethodTypes > export const PrivateKeyMethods: PrivateKeyMethodTypes = { - toDomainPrivateKey: function toDomainPrivateKey (this: PrivateKeyDocument) { + toDomainPrivateKey: function toDomainPrivateKey(this: PrivateKeyDocument) { const { type, keySpecification } = this const curve = keySpecification.find( - (item) => item.name === KeyProperties.curve + (item) => item.name === SDK.KeyProperties.curve ) const raw = keySpecification.find( - (item) => item.name === KeyProperties.rawKey + (item) => item.name === SDK.KeyProperties.rawKey ) - if (!(type in Domain.KeyTypes)) { + if (!(type in SDK.Domain.KeyTypes)) { throw new Error(`Invalid KeyType ${type || 'undefined'}`) } if (!curve) { @@ -88,9 +83,9 @@ export const PrivateKeyMethods: PrivateKeyMethodTypes = { } if ( - curve.value !== Domain.Curve.SECP256K1 && - curve.value !== Domain.Curve.ED25519 && - curve.value !== Domain.Curve.X25519 + curve.value !== SDK.Domain.Curve.SECP256K1 && + curve.value !== SDK.Domain.Curve.ED25519 && + curve.value !== SDK.Domain.Curve.X25519 ) { throw new Error(`Invalid key curve ${curve.value}`) } @@ -100,59 +95,59 @@ export const PrivateKeyMethods: PrivateKeyMethodTypes = { } /* istanbul ignore else -- @preserve */ - if (curve.value === Domain.Curve.SECP256K1) { + if (curve.value === SDK.Domain.Curve.SECP256K1) { const index = keySpecification.find( - (item) => item.name === KeyProperties.index + (item) => item.name === SDK.KeyProperties.index ) const seed = keySpecification.find( - (item) => item.name === KeyProperties.seed + (item) => item.name === SDK.KeyProperties.seed ) - const privateKey = new Secp256k1PrivateKey( + const privateKey = new SDK.Secp256k1PrivateKey( Buffer.from(raw.value, 'hex') ) - privateKey.keySpecification.set(Domain.KeyProperties.rawKey, raw.value) + privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) privateKey.keySpecification.set( - Domain.KeyProperties.curve, - Domain.Curve.SECP256K1 + SDK.Domain.KeyProperties.curve, + SDK.Domain.Curve.SECP256K1 ) if (index) { privateKey.keySpecification.set( - Domain.KeyProperties.index, + SDK.Domain.KeyProperties.index, index.value ) } if (seed) { privateKey.keySpecification.set( - Domain.KeyProperties.seed, + SDK.Domain.KeyProperties.seed, seed.value ) } return privateKey - } else if (curve.value === Domain.Curve.ED25519) { - const privateKey = new Ed25519PrivateKey(Buffer.from(raw.value, 'hex')) + } else if (curve.value === SDK.Domain.Curve.ED25519) { + const privateKey = new SDK.Ed25519PrivateKey(Buffer.from(raw.value, 'hex')) - privateKey.keySpecification.set(Domain.KeyProperties.rawKey, raw.value) + privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) privateKey.keySpecification.set( - Domain.KeyProperties.curve, - Domain.Curve.ED25519 + SDK.Domain.KeyProperties.curve, + SDK.Domain.Curve.ED25519 ) return privateKey - } else if (curve.value === Domain.Curve.X25519) { - const privateKey = new X25519PrivateKey(Buffer.from(raw.value, 'hex')) + } else if (curve.value === SDK.Domain.Curve.X25519) { + const privateKey = new SDK.X25519PrivateKey(Buffer.from(raw.value, 'hex')) - privateKey.keySpecification.set(Domain.KeyProperties.rawKey, raw.value) + privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) privateKey.keySpecification.set( - Domain.KeyProperties.curve, - Domain.Curve.X25519 + SDK.Domain.KeyProperties.curve, + SDK.Domain.Curve.X25519 ) return privateKey diff --git a/packages/database/tests/fixtures.ts b/packages/database/tests/fixtures.ts index b8079bfc..3dadd966 100644 --- a/packages/database/tests/fixtures.ts +++ b/packages/database/tests/fixtures.ts @@ -1,4 +1,5 @@ -import { +import SDK from "@atala/prism-wallet-sdk"; +const { Ed25519KeyPair, Ed25519PrivateKey, Secp256k1KeyPair, @@ -6,7 +7,8 @@ import { X25519KeyPair, X25519PrivateKey, Domain, -} from "@atala/prism-wallet-sdk"; +} = SDK; + const secpPrivateKey = new Secp256k1PrivateKey( new Uint8Array([ 45, 182, 188, 189, 107, 229, 136, 180, 199, 177, 110, 84, 98, 140, 121, 84, diff --git a/packages/database/tests/pluto.test.ts b/packages/database/tests/pluto.test.ts index 2c7ae65c..b07e1940 100644 --- a/packages/database/tests/pluto.test.ts +++ b/packages/database/tests/pluto.test.ts @@ -1,16 +1,10 @@ import "./setup"; -import { describe, it, vi, beforeEach, afterEach } from 'vitest'; +import { describe, it, beforeEach, afterEach } from 'vitest'; import fs from 'fs'; import path from 'path'; import { randomUUID } from "crypto"; -import { - AnonCredsCredential, - Apollo, - Castor, - Domain, - Pollux, -} from "@atala/prism-wallet-sdk"; +import SDK from "@atala/prism-wallet-sdk"; import * as sinon from "sinon"; import { RxStorage } from "rxdb"; import InMemory from "../../inmemory/src"; @@ -20,6 +14,13 @@ import { createLevelDBStorage } from '../../leveldb/src' import * as Fixtures from "./fixtures"; import { Database, PrivateKeyMethods } from "../src"; +const { + AnonCredsCredential, + Apollo, + Castor, + Pollux, +} = SDK; + const pollux = new Pollux(new Castor(new Apollo())); const keyData = new Uint8Array(32); const jwtParts = [ @@ -29,11 +30,11 @@ const jwtParts = [ ]; const messageType = "https://didcomm.org/basicmessage/2.0/message"; const createMessage = ( - from?: Domain.DID, - to?: Domain.DID, - direction: Domain.MessageDirection = Domain.MessageDirection.SENT + from?: SDK.Domain.DID, + to?: SDK.Domain.DID, + direction: SDK.Domain.MessageDirection = SDK.Domain.MessageDirection.SENT ) => { - const message = new Domain.Message( + const message = new SDK.Domain.Message( "{}", randomUUID(), messageType, @@ -103,7 +104,7 @@ describe("Pluto encrypted testing with different storages", () => { } ); await db.getAllPrismDIDs() - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); const privateKey = Fixtures.secp256K1.privateKey; @@ -173,13 +174,13 @@ describe("Pluto encrypted testing with different storages", () => { it(storageName + "Should store a new Prism DID and its privateKeys", async ({ expect }) => { expect(await db.getPrismLastKeyPathIndex()).toBe(0); - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); - const did2 = Domain.DID.fromString( + const did2 = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw1" ); - const did3 = Domain.DID.fromString( + const did3 = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw2" ); const privateKey = Fixtures.secp256K1.privateKey; @@ -213,7 +214,7 @@ describe("Pluto encrypted testing with different storages", () => { }).toThrowError(new Error(`Invalid KeyType sds`)); const wrongKey3: any = { - type: Domain.KeyTypes.Curve25519, + type: SDK.Domain.KeyTypes.Curve25519, keySpecification: [], toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, }; @@ -222,10 +223,10 @@ describe("Pluto encrypted testing with different storages", () => { }).toThrowError(new Error("Undefined key curve")); const wrongKey4: any = { - type: Domain.KeyTypes.Curve25519, + type: SDK.Domain.KeyTypes.Curve25519, keySpecification: [ { - name: Domain.KeyProperties.curve, + name: SDK.Domain.KeyProperties.curve, type: "string", value: "asd", }, @@ -237,12 +238,12 @@ describe("Pluto encrypted testing with different storages", () => { }).toThrowError(new Error("Invalid key curve asd")); const wrongKey5: any = { - type: Domain.KeyTypes.Curve25519, + type: SDK.Domain.KeyTypes.Curve25519, keySpecification: [ { - name: Domain.KeyProperties.curve, + name: SDK.Domain.KeyProperties.curve, type: "string", - value: Domain.Curve.ED25519, + value: SDK.Domain.Curve.ED25519, }, ], toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, @@ -252,15 +253,15 @@ describe("Pluto encrypted testing with different storages", () => { }).toThrowError(new Error("Undefined key raw")); const correctKey: any = { - type: Domain.KeyTypes.EC, + type: SDK.Domain.KeyTypes.EC, keySpecification: [ { - name: Domain.KeyProperties.curve, + name: SDK.Domain.KeyProperties.curve, type: "string", - value: Domain.Curve.SECP256K1, + value: SDK.Domain.Curve.SECP256K1, }, { - name: Domain.KeyProperties.rawKey, + name: SDK.Domain.KeyProperties.rawKey, type: "string", value: Buffer.from(Fixtures.secp256K1.privateKey.raw).toString( "hex" @@ -273,27 +274,27 @@ describe("Pluto encrypted testing with different storages", () => { correctKey.toDomainPrivateKey(); const correctKeyWithIndex: any = { - type: Domain.KeyTypes.EC, + type: SDK.Domain.KeyTypes.EC, keySpecification: [ { - name: Domain.KeyProperties.curve, + name: SDK.Domain.KeyProperties.curve, type: "string", - value: Domain.Curve.SECP256K1, + value: SDK.Domain.Curve.SECP256K1, }, { - name: Domain.KeyProperties.rawKey, + name: SDK.Domain.KeyProperties.rawKey, type: "string", value: Buffer.from(Fixtures.secp256K1.privateKey.raw).toString( "hex" ), }, { - name: Domain.KeyProperties.index, + name: SDK.Domain.KeyProperties.index, type: "string", value: Fixtures.secp256K1.privateKey.index, }, { - name: Domain.KeyProperties.seed, + name: SDK.Domain.KeyProperties.seed, type: "string", value: "A12456", }, @@ -304,15 +305,15 @@ describe("Pluto encrypted testing with different storages", () => { correctKeyWithIndex.toDomainPrivateKey(); const correctEd25519Key: any = { - type: Domain.KeyTypes.EC, + type: SDK.Domain.KeyTypes.EC, keySpecification: [ { - name: Domain.KeyProperties.curve, + name: SDK.Domain.KeyProperties.curve, type: "string", - value: Domain.Curve.ED25519, + value: SDK.Domain.Curve.ED25519, }, { - name: Domain.KeyProperties.rawKey, + name: SDK.Domain.KeyProperties.rawKey, type: "string", value: Buffer.from(Fixtures.ed25519.privateKey.raw).toString("hex"), }, @@ -323,15 +324,15 @@ describe("Pluto encrypted testing with different storages", () => { correctEd25519Key.toDomainPrivateKey(); const correctX25519Key: any = { - type: Domain.KeyTypes.Curve25519, + type: SDK.Domain.KeyTypes.Curve25519, keySpecification: [ { - name: Domain.KeyProperties.curve, + name: SDK.Domain.KeyProperties.curve, type: "string", - value: Domain.Curve.X25519, + value: SDK.Domain.Curve.X25519, }, { - name: Domain.KeyProperties.rawKey, + name: SDK.Domain.KeyProperties.rawKey, type: "string", value: Buffer.from(Fixtures.x25519.privateKey.raw).toString("hex"), }, @@ -343,7 +344,7 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should return null when no privateKey is found by its id", async ({ expect }) => { - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); expect(await db.getDIDInfoByDID(did)).toBe(null); @@ -354,14 +355,14 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should return null when no privateKey is found by its did", async ({ expect }) => { - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism::t8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); expect((await db.getDIDPrivateKeysByDID(did)).length).toBe(0); }); it(storageName + "Should store a new Prism DID and its privateKeys with privateKeyMetadataId", async ({ expect }) => { - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); const privateKey = Fixtures.secp256K1.privateKey; @@ -370,7 +371,7 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should store a new Prism DID and its privateKeys with privateKeyMetadataId and alias", async ({ expect }) => { - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); const privateKey = Fixtures.secp256K1.privateKey; @@ -385,7 +386,7 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should store a new Prism DID and its privateKeys and fetch it by its alias", async ({ expect }) => { - const did = Domain.DID.fromString( + const did = SDK.Domain.DID.fromString( "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); const alias = "default"; @@ -423,14 +424,14 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should fetch stored messages either by type or by did", async ({ expect }) => { - const from = Domain.DID.fromString("did:prism:123456"); - const to = Domain.DID.fromString("did:prism:654321"); - const from2 = Domain.DID.fromString("did:prism:12345644"); - const to2 = Domain.DID.fromString("did:prism:65432133"); + const from = SDK.Domain.DID.fromString("did:prism:123456"); + const to = SDK.Domain.DID.fromString("did:prism:654321"); + const from2 = SDK.Domain.DID.fromString("did:prism:12345644"); + const to2 = SDK.Domain.DID.fromString("did:prism:65432133"); await db.storeMessages([ - createMessage(from, to, Domain.MessageDirection.RECEIVED), - createMessage(from2, to2, Domain.MessageDirection.SENT), + createMessage(from, to, SDK.Domain.MessageDirection.RECEIVED), + createMessage(from2, to2, SDK.Domain.MessageDirection.SENT), ]); const byType = await db.getAllMessagesOfType(messageType); @@ -471,7 +472,7 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should store a peerDID", async ({ expect }) => { - const did = new Domain.DID( + const did = new SDK.Domain.DID( "did", "peer", "2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0" @@ -486,15 +487,15 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should store a didPair", async ({ expect }) => { - const host = Domain.DID.fromString("did:prism:123456"); - const receiver = Domain.DID.fromString("did:prism:654321"); + const host = SDK.Domain.DID.fromString("did:prism:123456"); + const receiver = SDK.Domain.DID.fromString("did:prism:654321"); const name = "example"; await db.storeDIDPair(host, receiver, name); }); it(storageName + "Should get all the didPairs", async ({ expect }) => { - const host = Domain.DID.fromString("did:prism:123456"); - const receiver = Domain.DID.fromString("did:prism:654321"); + const host = SDK.Domain.DID.fromString("did:prism:123456"); + const receiver = SDK.Domain.DID.fromString("did:prism:654321"); const name = "example"; expect((await db.getAllDidPairs()).length).toBe(0); await db.storeDIDPair(host, receiver, name); @@ -502,21 +503,21 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should get a did pair by its did", async ({ expect }) => { - const host = Domain.DID.fromString("did:prism:123456"); - const receiver = Domain.DID.fromString("did:prism:654321"); + const host = SDK.Domain.DID.fromString("did:prism:123456"); + const receiver = SDK.Domain.DID.fromString("did:prism:654321"); const name = "example"; await db.storeDIDPair(host, receiver, name); expect(await db.getPairByDID(host)).not.toBe(null); }); it(storageName + "Should return null when a pair is fetched by a non existing did", async ({ expect }) => { - const notfound = Domain.DID.fromString("did:prism:65432155555"); + const notfound = SDK.Domain.DID.fromString("did:prism:65432155555"); expect(await db.getPairByDID(notfound)).toBe(null); }); it(storageName + "Should get a did pair by its name", async ({ expect }) => { - const host = Domain.DID.fromString("did:prism:123456"); - const receiver = Domain.DID.fromString("did:prism:654321"); + const host = SDK.Domain.DID.fromString("did:prism:123456"); + const receiver = SDK.Domain.DID.fromString("did:prism:654321"); const name = "example"; await db.storeDIDPair(host, receiver, name); expect(await db.getPairByName(name)).not.toBe(null); @@ -527,9 +528,9 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should store a mediator", async ({ expect }) => { - const host = Domain.DID.fromString("did:prism:333333"); - const mediator = Domain.DID.fromString("did:prism:444444"); - const routing = Domain.DID.fromString("did:prism:555555"); + const host = SDK.Domain.DID.fromString("did:prism:333333"); + const mediator = SDK.Domain.DID.fromString("did:prism:444444"); + const routing = SDK.Domain.DID.fromString("did:prism:555555"); expect((await db.getAllMediators()).length).toBe(0); await db.storeMediator(mediator, host, routing); @@ -537,9 +538,9 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should go a backup of all the database and restore it", async ({ expect }) => { - const host = Domain.DID.fromString("did:prism:333333"); - const mediator = Domain.DID.fromString("did:prism:444444"); - const routing = Domain.DID.fromString("did:prism:555555"); + const host = SDK.Domain.DID.fromString("did:prism:333333"); + const mediator = SDK.Domain.DID.fromString("did:prism:444444"); + const routing = SDK.Domain.DID.fromString("did:prism:555555"); expect((await db.getAllMediators()).length).toBe(0); await db.storeMediator(mediator, host, routing); expect((await db.getAllMediators()).length).toBe(1); @@ -568,7 +569,7 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should throw an error when an incomplete did is loaded from db", async ({ expect }) => { - const did = Domain.DID.fromString("did:prism:65432133"); + const did = SDK.Domain.DID.fromString("did:prism:65432133"); await (db as any).db.dids.insert({ did: did.toString(), @@ -582,21 +583,21 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should get a privateKey by its ID", async ({ expect }) => { - const did = Domain.DID.fromString("did:prism:65432133"); + const did = SDK.Domain.DID.fromString("did:prism:65432133"); await (db as any).db.privatekeys.insert({ id: "123", did: did.toString(), - type: Domain.KeyTypes.EC, + type: SDK.Domain.KeyTypes.EC, keySpecification: [ { name: "curve", - value: Domain.Curve.ED25519, + value: SDK.Domain.Curve.ED25519, type: "string", }, { name: "curve", - value: Domain.Curve.ED25519, + value: SDK.Domain.Curve.ED25519, type: "string", }, { @@ -620,12 +621,12 @@ describe("Pluto encrypted testing with different storages", () => { const jwtPayload = Fixtures.createJWTPayload( "jwtid", "proof", - Domain.CredentialType.JWT + SDK.Domain.CredentialType.JWT ); const encoded = encodeJWTCredential(jwtPayload); const result = await pollux.parseCredential(Buffer.from(encoded), { - type: Domain.CredentialType.JWT, + type: SDK.Domain.CredentialType.JWT, }); await db.storeCredential(result); const results = await db.getAllCredentials()