UNPKG

@sphereon/ssi-sdk.wellknown-did-issuer

Version:

1 lines • 181 kB
{"version":3,"sources":["../../../node_modules/.pnpm/tsup@8.4.0_@microsoft+api-extractor@7.52.4_@types+node@20.17.30__@swc+core@1.11.21_@swc_05f46a3da13b2fa802a5152aa1615087/node_modules/tsup/assets/cjs_shims.js","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/key.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/service.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/claim.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/credential.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/presentation.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/message.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/identifier.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/utils.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/identifier/did-store.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/identifier/key-store.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/private-key.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/identifier/private-key-store.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/data-store.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/data-store-orm.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/did-discovery-provider.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/entities/PreMigrationEntities.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/migrations/migration-functions.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/migrations/1.createDatabase.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/migrations/2.simplifyRelations.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/migrations/3.createPrivateKeyStorage.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/migrations/4.allowNullVPIssuanceDate.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/migrations/index.ts","../../../node_modules/.pnpm/@veramo+data-store@4.2.0_patch_hash=25b55da53633b67af137c78afaf727c15cd0dd9f55a659a71d1_263b95400861bf291e356cdc1fd81610/node_modules/@veramo/data-store/src/index.ts","../plugin.schema.json","../src/index.ts","../src/entities/DidConfigurationResourceEntity.ts","../src/agent/WellKnownDidIssuer.ts","../src/types/IWellKnownDidIssuer.ts","../src/migrations/index.ts","../src/migrations/generic/index.ts","../src/migrations/generic/1-CreateWellknownDidIssuer.ts","../src/migrations/postgres/1661165115000-CreateWellknownDidIssuer.ts","../src/migrations/sqlite/1661161799000-CreateWellknownDidIssuer.ts"],"sourcesContent":["// Shim globals in cjs bundle\n// There's a weird bug that esbuild will always inject importMetaUrl\n// if we export it as `const importMetaUrl = ... __filename ...`\n// But using a function will not cause this issue\n\nconst getImportMetaUrl = () =>\n typeof document === 'undefined'\n ? new URL(`file:${__filename}`).href\n : (document.currentScript && document.currentScript.src) ||\n new URL('main.js', document.baseURI).href\n\nexport const importMetaUrl = /* @__PURE__ */ getImportMetaUrl()\n","import { KeyMetadata, TKeyType } from '@veramo/core'\nimport { Entity, Column, PrimaryColumn, BaseEntity, ManyToOne } from 'typeorm'\nimport { Identifier } from './identifier'\n\n/**\n * Mirrors {@link @veramo/core#TKeyType | TKeyType}\n *\n * @beta - This API may change without a BREAKING CHANGE notice.\n */\nexport type KeyType = TKeyType\n\n/**\n * Represents some properties of a {@link @veramo/core#IKey | IKey} that are stored in a TypeORM\n * database for the purpose of keeping track of the {@link @veramo/key-manager#AbstractKeyManagementSystem}\n * implementations and the keys they are able to use.\n *\n * @see {@link @veramo/data-store#KeyStore | KeyStore} for the implementation used by the\n * {@link @veramo/key-manager#KeyManager | KeyManager}.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('key')\nexport class Key extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n kid: string\n\n @Column()\n //@ts-ignore\n kms: string\n\n @Column()\n //@ts-ignore\n type: KeyType\n\n @Column()\n //@ts-ignore\n publicKeyHex: string\n\n @Column({\n type: 'simple-json',\n nullable: true,\n transformer: {\n to: (value: any): KeyMetadata | null => {\n return value\n },\n from: (value: KeyMetadata | null): object | null => {\n return value\n },\n },\n })\n meta?: KeyMetadata | null\n\n @ManyToOne((type) => Identifier, (identifier) => identifier?.keys, { onDelete: 'CASCADE' })\n //@ts-ignore\n identifier?: Identifier\n}\n","import { Entity, Column, PrimaryColumn, BaseEntity, ManyToOne } from 'typeorm'\nimport { Identifier } from './identifier'\n\n/**\n * Represents some properties of a {@link did-resolver#ServiceEndpoint | ServiceEndpoint} as it is stored in a TypeORM\n * database. This is used by {@link @veramo/data-store#DIDStore | DIDStore} to provide information to\n * {@link @veramo/did-manager#DIDManager | DIDManager} when DID management information is stored in a local TypeORM\n * database.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('service')\nexport class Service extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n id: string\n\n @Column()\n //@ts-ignore\n type: string\n\n @Column()\n //@ts-ignore\n serviceEndpoint: string\n\n @Column({ nullable: true })\n description?: string\n\n @ManyToOne((type) => Identifier, (identifier) => identifier?.services, { onDelete: 'CASCADE' })\n //@ts-ignore\n identifier?: Identifier\n}\n","import { Entity, Column, BaseEntity, ManyToOne, PrimaryColumn } from 'typeorm'\nimport { Identifier } from './identifier'\nimport { Credential } from './credential'\n\n/**\n * Represents the properties of a claim extracted from a Verifiable Credential `credentialSubject`, and stored in a\n * TypeORM database for querying.\n *\n * @see {@link @veramo/core#IDataStoreORM} for the interface defining how this can be queried.\n * @see {@link @veramo/data-store#DataStoreORM} for the implementation of the query interface.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('claim')\nexport class Claim extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n hash: string\n\n @ManyToOne((type) => Identifier, (identifier) => identifier.issuedClaims, {\n eager: true,\n onDelete: 'CASCADE',\n })\n //@ts-ignore\n issuer: Identifier\n\n @ManyToOne((type) => Identifier, (identifier) => identifier.receivedClaims, {\n eager: true,\n nullable: true,\n })\n subject?: Identifier\n\n @ManyToOne((type) => Credential, (credential) => credential.claims, {\n onDelete: 'CASCADE',\n })\n //@ts-ignore\n credential: Credential\n\n @Column()\n //@ts-ignore\n issuanceDate: Date\n\n @Column({ nullable: true })\n expirationDate?: Date\n\n @Column('simple-array')\n //@ts-ignore\n context: string[]\n\n @Column('simple-array')\n //@ts-ignore\n credentialType: string[]\n\n @Column()\n //@ts-ignore\n type: string\n\n @Column('text', { nullable: true })\n //@ts-ignore\n value: string | null\n\n @Column()\n //@ts-ignore\n isObj: boolean\n}\n","import { VerifiableCredential } from '@veramo/core'\nimport { BaseEntity, Column, Entity, ManyToMany, ManyToOne, OneToMany, PrimaryColumn } from 'typeorm'\nimport { Identifier } from './identifier'\nimport { Message } from './message'\nimport { Presentation } from './presentation'\nimport { Claim } from './claim'\nimport { asArray, computeEntryHash, extractIssuer } from '@veramo/utils'\n\n/**\n * Represents some common properties of a Verifiable Credential that are stored in a TypeORM database for querying.\n *\n * @see {@link @veramo/core#IDataStoreORM.dataStoreORMGetVerifiableCredentials | dataStoreORMGetVerifiableCredentials}\n * for the interface defining how this can be queried.\n *\n * @see {@link @veramo/data-store#DataStoreORM | DataStoreORM} for the implementation of the query interface.\n *\n * @see {@link @veramo/core#IDataStoreORM.dataStoreORMGetVerifiableCredentialsByClaims | dataStoreORMGetVerifiableCredentialsByClaims} for the interface defining how to query credentials by the claims they contain.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('credential')\nexport class Credential extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n hash: string\n\n //@ts-ignore\n private _raw: VerifiableCredential\n\n set raw(raw: VerifiableCredential) {\n this._raw = raw\n this.hash = computeEntryHash(raw)\n }\n\n @Column('simple-json')\n get raw(): VerifiableCredential {\n return this._raw\n }\n\n @ManyToOne((type) => Identifier, (identifier) => identifier.issuedCredentials, {\n cascade: ['insert'],\n eager: true,\n onDelete: 'CASCADE',\n })\n //@ts-ignore\n issuer: Identifier\n\n // Subject can be null https://w3c.github.io/vc-data-model/#credential-uniquely-identifies-a-subject\n @ManyToOne((type) => Identifier, (identifier) => identifier?.receivedCredentials, {\n cascade: ['insert'],\n eager: true,\n nullable: true,\n })\n subject?: Identifier\n\n @Column({ nullable: true })\n id?: string\n\n @Column()\n //@ts-ignore\n issuanceDate: Date\n\n @Column({ nullable: true })\n expirationDate?: Date\n\n @Column('simple-array')\n //@ts-ignore\n context: string[]\n\n @Column('simple-array')\n //@ts-ignore\n type: string[]\n\n @OneToMany((type) => Claim, (claim) => claim.credential, {\n cascade: ['insert'],\n })\n //@ts-ignore\n claims: Claim[]\n\n @ManyToMany((type) => Presentation, (presentation) => presentation.credentials)\n //@ts-ignore\n presentations: Presentation[]\n\n @ManyToMany((type) => Message, (message) => message.credentials)\n //@ts-ignore\n messages: Message[]\n}\n\nexport const createCredentialEntity = (vci: VerifiableCredential): Credential => {\n const vc = vci\n const credential = new Credential()\n credential.context = asArray(vc['@context'])\n credential.type = asArray(vc.type || [])\n credential.id = vc.id\n\n if (vc.issuanceDate) {\n credential.issuanceDate = new Date(vc.issuanceDate)\n }\n\n if (vc.expirationDate) {\n credential.expirationDate = new Date(vc.expirationDate)\n }\n\n const issuer = new Identifier()\n issuer.did = extractIssuer(vc)\n credential.issuer = issuer\n\n if (vc.credentialSubject.id) {\n const subject = new Identifier()\n subject.did = vc.credentialSubject.id\n credential.subject = subject\n }\n credential.claims = []\n for (const type in vc.credentialSubject) {\n if (vc.credentialSubject.hasOwnProperty(type)) {\n const value = vc.credentialSubject[type]\n\n if (type !== 'id') {\n const isObj = typeof value === 'function' || (typeof value === 'object' && !!value)\n const claim = new Claim()\n claim.hash = computeEntryHash(JSON.stringify(vc) + type)\n claim.type = type\n claim.value = isObj ? JSON.stringify(value) : value\n claim.isObj = isObj\n claim.issuer = credential.issuer\n claim.subject = credential.subject\n claim.expirationDate = credential.expirationDate\n claim.issuanceDate = credential.issuanceDate\n claim.credentialType = credential.type\n claim.context = credential.context\n credential.claims.push(claim)\n }\n }\n }\n\n credential.raw = vci\n return credential\n}\n","import { VerifiableCredential, VerifiablePresentation } from '@veramo/core'\n\nimport { BaseEntity, Column, Entity, JoinTable, ManyToMany, ManyToOne, PrimaryColumn } from 'typeorm'\nimport { Identifier } from './identifier'\nimport { Message } from './message'\nimport { createCredentialEntity, Credential } from './credential'\nimport { asArray, computeEntryHash } from '@veramo/utils'\nimport { normalizeCredential } from 'did-jwt-vc'\n\n/**\n * Represents some common properties of a Verifiable Presentation that are stored in a TypeORM database for querying.\n *\n * @see {@link @veramo/core#IDataStoreORM.dataStoreORMGetVerifiablePresentations | dataStoreORMGetVerifiablePresentations} for the interface defining how this can be queried.\n *\n * @see {@link @veramo/data-store#DataStoreORM | DataStoreORM} for the implementation of the query interface.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('presentation')\nexport class Presentation extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n hash: string\n\n //@ts-ignore\n private _raw: IVerifiablePresentation\n\n set raw(raw: VerifiablePresentation) {\n this._raw = raw\n this.hash = computeEntryHash(raw)\n }\n\n @Column({ type: 'simple-json' })\n get raw(): VerifiablePresentation {\n return this._raw\n }\n\n @ManyToOne((type) => Identifier, (identifier) => identifier.issuedPresentations, {\n cascade: ['insert'],\n eager: true,\n onDelete: 'CASCADE',\n })\n //@ts-ignore\n holder: Identifier\n\n @ManyToMany((type) => Identifier, (identifier) => identifier?.receivedPresentations, {\n cascade: ['insert'],\n eager: true,\n nullable: true,\n })\n @JoinTable()\n //@ts-ignore\n verifier?: Identifier[]\n\n @Column({ nullable: true })\n id?: String\n\n @Column()\n //@ts-ignore\n issuanceDate: Date\n\n @Column({ nullable: true })\n expirationDate?: Date\n\n @Column('simple-array')\n //@ts-ignore\n context: string[]\n\n @Column('simple-array')\n //@ts-ignore\n type: string[]\n\n @ManyToMany((type) => Credential, (credential) => credential.presentations, {\n cascade: true,\n })\n @JoinTable()\n //@ts-ignore\n credentials: Credential[]\n\n @ManyToMany((type) => Message, (message) => message.presentations)\n //@ts-ignore\n messages: Message[]\n}\n\nexport const createPresentationEntity = (vpi: VerifiablePresentation): Presentation => {\n const vp = vpi\n const presentation = new Presentation()\n presentation.context = asArray(vp['@context'])\n presentation.type = asArray(vp.type || [])\n presentation.id = vp.id\n\n if (vp.issuanceDate) {\n presentation.issuanceDate = new Date(vp.issuanceDate)\n }\n\n if (vp.expirationDate) {\n presentation.expirationDate = new Date(vp.expirationDate)\n }\n\n const holder = new Identifier()\n holder.did = vp.holder\n presentation.holder = holder\n\n presentation.verifier = asArray(vp.verifier || []).map((verifierDid) => {\n const id = new Identifier()\n id.did = verifierDid\n return id\n })\n\n presentation.raw = vpi\n\n presentation.credentials = (vp.verifiableCredential || [])\n .map((cred) => {\n if (typeof cred === 'string') {\n return normalizeCredential(cred)\n } else {\n return <VerifiableCredential>cred\n }\n })\n .map(createCredentialEntity)\n return presentation\n}\n","import {\n BaseEntity,\n BeforeInsert,\n BeforeUpdate,\n Column,\n Entity,\n JoinTable,\n ManyToMany,\n ManyToOne,\n PrimaryColumn,\n} from 'typeorm'\nimport { IMessage } from '@veramo/core'\nimport { Identifier } from './identifier'\nimport { createPresentationEntity, Presentation } from './presentation'\nimport { createCredentialEntity, Credential } from './credential'\nimport { computeEntryHash } from '@veramo/utils'\nimport { v4 as uuidv4 } from 'uuid'\n\n/**\n * Represents message metadata as it is stored by {@link @veramo/data-store#DataStore | DataStore}.\n *\n * This metadata is most often used by {@link @veramo/message-handler#MessageHandler | MessageHandler} and\n * {@link @veramo/core#IMessageHandler | IMessageHandler} implementations to decorate messages that are interpreted and\n * decoded, but not returned as final, as they pass through the message handler chain.\n *\n * @beta - This API may change without a BREAKING CHANGE notice.\n */\nexport interface MetaData {\n type: string\n value?: string\n}\n\n/**\n * Represents some common properties of an {@link @veramo/core#IMessage} that are stored in a TypeORM database for\n * querying.\n *\n * @see {@link @veramo/core#IDataStoreORM.dataStoreORMGetMessages | dataStoreORMGetMessages}\n * for the interface defining how this can be queried\n *\n * @see {@link @veramo/data-store#DataStoreORM | DataStoreORM} for the implementation of the query interface.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('message')\nexport class Message extends BaseEntity {\n @BeforeInsert()\n setId() {\n if (!this.id) {\n this.id = computeEntryHash(this.raw || uuidv4())\n }\n }\n\n @PrimaryColumn()\n //@ts-ignore\n id: string\n\n @BeforeInsert()\n setSaveDate() {\n this.saveDate = new Date()\n this.updateDate = new Date()\n }\n\n @BeforeUpdate()\n setUpdateDate() {\n this.updateDate = new Date()\n }\n\n @Column({ select: false })\n //@ts-ignore\n saveDate: Date\n\n @Column({ select: false })\n //@ts-ignore\n updateDate: Date\n\n @Column({ nullable: true })\n createdAt?: Date\n\n @Column({ nullable: true })\n expiresAt?: Date\n\n @Column({ nullable: true })\n threadId?: string\n\n @Column()\n //@ts-ignore\n type: string\n\n @Column({ nullable: true })\n raw?: string\n\n @Column('simple-json', { nullable: true })\n data?: object | null\n\n // https://github.com/decentralized-identifier/didcomm-messaging/blob/41f35f992275dd71d459504d14eb8d70b4185533/jwm.md#jwm-profile\n\n @Column('simple-array', { nullable: true })\n replyTo?: string[]\n\n @Column({ nullable: true })\n replyUrl?: string\n\n @ManyToOne((type) => Identifier, (identifier) => identifier.sentMessages, {\n nullable: true,\n cascade: ['insert'],\n eager: true,\n onDelete: 'CASCADE',\n })\n from?: Identifier\n\n @ManyToOne((type) => Identifier, (identifier) => identifier.receivedMessages, {\n nullable: true,\n cascade: ['insert'],\n eager: true,\n onDelete: 'CASCADE',\n })\n to?: Identifier\n\n @Column('simple-json', { nullable: true })\n metaData?: MetaData[] | null\n\n @ManyToMany((type) => Presentation, (presentation) => presentation.messages, {\n cascade: true,\n })\n @JoinTable()\n //@ts-ignore\n presentations: Presentation[]\n\n @ManyToMany((type) => Credential, (credential) => credential.messages, { cascade: true })\n @JoinTable()\n //@ts-ignore\n credentials: Credential[]\n}\n\nexport const createMessageEntity = (args: IMessage): Message => {\n const message = new Message()\n message.id = args.id\n message.threadId = args.threadId\n message.type = args.type\n message.raw = args.raw\n message.data = args.data\n message.metaData = args.metaData\n\n if (args.replyTo) {\n message.replyTo = args.replyTo\n }\n if (args.replyUrl) {\n message.replyUrl = args.replyUrl\n }\n\n if (args.createdAt) {\n message.createdAt = new Date(args.createdAt)\n }\n\n if (args.expiresAt) {\n message.createdAt = new Date(args.expiresAt)\n }\n\n if (args.from) {\n const from = new Identifier()\n from.did = args.from\n message.from = from\n }\n\n if (args.to) {\n const to = new Identifier()\n to.did = args.to\n message.to = to\n }\n\n if (args.presentations) {\n message.presentations = args.presentations.map(createPresentationEntity)\n }\n\n if (args.credentials) {\n message.credentials = args.credentials.map(createCredentialEntity)\n }\n\n return message\n}\n\nexport const createMessage = (args: Message): IMessage => {\n const message: Partial<IMessage> = {\n id: args.id,\n type: args.type,\n raw: args.raw,\n data: args.data,\n metaData: args.metaData,\n }\n\n if (args.threadId) {\n message.threadId = args.threadId\n }\n\n if (args.replyTo) {\n message.replyTo = args.replyTo\n }\n\n if (args.replyTo) {\n message.replyUrl = args.replyUrl\n }\n\n if (args.createdAt) {\n message.createdAt = args.createdAt.toISOString()\n }\n\n if (args.expiresAt) {\n message.expiresAt = args.expiresAt.toISOString()\n }\n\n if (args.from) {\n message.from = args.from.did\n }\n\n if (args.to) {\n message.to = args.to.did\n }\n\n if (args.presentations) {\n message.presentations = args.presentations.map((vp) => vp.raw)\n }\n\n if (args.credentials) {\n message.credentials = args.credentials.map((vc) => vc.raw)\n }\n\n return message as IMessage\n}\n","import {\n Entity,\n Column,\n Connection,\n PrimaryColumn,\n BaseEntity,\n OneToMany,\n ManyToMany,\n Index,\n BeforeInsert,\n BeforeUpdate,\n} from 'typeorm'\nimport { Key } from './key'\nimport { Service } from './service'\nimport { Message } from './message'\nimport { Presentation } from './presentation'\nimport { Credential } from './credential'\nimport { Claim } from './claim'\n\n/**\n * Represents some properties and relationships of an {@link @veramo/core#IIdentifier} that are stored in a TypeORM\n * database for the purpose of keeping track of keys and services associated with a DID managed by a Veramo agent.\n *\n * @see {@link @veramo/data-store#DIDStore | DIDStore} for the implementation used by the\n * {@link @veramo/did-manager#DIDManager | DIDManager}.\n * @see {@link @veramo/data-store#DataStoreORM | DataStoreORM} for the implementation of the query interface.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('identifier')\n@Index(['alias', 'provider'], { unique: true })\nexport class Identifier extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n did: string\n\n @Column({ nullable: true })\n //@ts-ignore\n provider?: string\n\n @Column({ nullable: true })\n //@ts-ignore\n alias?: string\n\n @BeforeInsert()\n setSaveDate() {\n this.saveDate = new Date()\n this.updateDate = new Date()\n }\n\n @BeforeUpdate()\n setUpdateDate() {\n this.updateDate = new Date()\n }\n\n @Column({ select: false })\n //@ts-ignore\n saveDate: Date\n\n @Column({ select: false })\n //@ts-ignore\n updateDate: Date\n\n @Column({ nullable: true })\n //@ts-ignore\n controllerKeyId?: string\n\n @OneToMany((type) => Key, (key) => key.identifier)\n //@ts-ignore\n keys: Key[]\n\n @OneToMany((type) => Service, (service) => service.identifier, {\n cascade: true,\n })\n //@ts-ignore\n services: Service[]\n\n @OneToMany((type) => Message, (message) => message.from)\n //@ts-ignore\n sentMessages: Message[]\n\n @OneToMany((type) => Message, (message) => message.to)\n //@ts-ignore\n receivedMessages: Message[]\n\n @OneToMany((type) => Presentation, (presentation) => presentation.holder)\n //@ts-ignore\n issuedPresentations: Presentation[]\n\n @ManyToMany((type) => Presentation, (presentation) => presentation.verifier)\n //@ts-ignore\n receivedPresentations: Presentation[]\n\n @OneToMany((type) => Credential, (credential) => credential.issuer)\n //@ts-ignore\n issuedCredentials: Credential[]\n\n @OneToMany((type) => Credential, (credential) => credential.subject)\n //@ts-ignore\n receivedCredentials: Credential[]\n\n @OneToMany((type) => Claim, (claim) => claim.issuer)\n //@ts-ignore\n issuedClaims: Claim[]\n\n @OneToMany((type) => Claim, (claim) => claim.subject)\n //@ts-ignore\n receivedClaims: Claim[]\n\n /**\n * Convenience method to get the most recent information about a subject DID as described by Verifiable Credential\n * claims.\n *\n * Example:\n * ```typescript\n * // get the latest claim value for credentials containing `credentialSubject.name` and this Identifier as subject.\n * const name = await identifier.getLatestClaimValue({type: 'name'})\n * ```\n *\n * @param where - The TypeORM `where` filter to use.\n */\n async getLatestClaimValue(\n dbConnection: Promise<Connection>,\n where: any,\n ): Promise<string | null | undefined> {\n const claim = await (await dbConnection).getRepository(Claim).findOne({\n where: {\n ...where,\n subject: this.did,\n },\n order: {\n issuanceDate: 'DESC',\n },\n })\n return claim?.value\n }\n\n shortDid() {\n return `${this.did.slice(0, 15)}...${this.did.slice(-4)}`\n }\n}\n","import { DataSource } from 'typeorm'\nimport { OrPromise } from \"@veramo/utils\";\n\n/**\n * Ensures that the provided DataSource is connected.\n *\n * @param dbConnection - a TypeORM DataSource or a Promise that resolves to a DataSource\n */\nexport async function getConnectedDb(dbConnection: OrPromise<DataSource>): Promise<DataSource> {\n if (dbConnection instanceof Promise) {\n return await dbConnection\n } else if (!dbConnection.isInitialized) {\n return await (<DataSource>dbConnection).initialize()\n } else {\n return dbConnection\n }\n}\n","import { IIdentifier, IKey } from '@veramo/core'\nimport { AbstractDIDStore } from '@veramo/did-manager'\nimport { Identifier } from '../entities/identifier'\nimport { Credential } from '../entities/credential'\nimport { Key } from '../entities/key'\nimport { Service } from '../entities/service'\nimport { DataSource, IsNull, Not } from 'typeorm'\n\nimport Debug from 'debug'\nimport { Presentation } from '../entities/presentation'\nimport { OrPromise } from \"@veramo/utils\";\nimport { getConnectedDb } from \"../utils\";\n\nconst debug = Debug('veramo:typeorm:identifier-store')\n\n/**\n * An implementation of {@link @veramo/did-manager#AbstractDIDStore | AbstractDIDStore} that uses a TypeORM database to\n * store the relationships between DIDs, their providers and controllers and their keys and services as they are known\n * and managed by a Veramo agent.\n *\n * An instance of this class can be used by {@link @veramo/did-manager#DIDManager} as the data storage layer.\n *\n * To make full use of this class, it should use the same database as the one used by\n * {@link @veramo/data-store#KeyStore | KeyStore}.\n *\n * @public\n */\nexport class DIDStore extends AbstractDIDStore {\n constructor(private dbConnection: OrPromise<DataSource>) {\n super()\n }\n\n async get({\n did,\n alias,\n provider,\n }: {\n did: string\n alias: string\n provider: string\n }): Promise<IIdentifier> {\n let where = {}\n if (did !== undefined && alias === undefined) {\n where = { did }\n } else if (did === undefined && alias !== undefined && provider !== undefined) {\n where = { alias, provider }\n } else {\n throw Error('[veramo:data-store:identifier-store] Get requires did or (alias and provider)')\n }\n\n const identifier = await (await getConnectedDb(this.dbConnection)).getRepository(Identifier).findOne({\n where,\n relations: ['keys', 'services'],\n })\n\n if (!identifier) throw Error('Identifier not found')\n const result: IIdentifier = {\n did: identifier.did,\n controllerKeyId: identifier.controllerKeyId,\n provider: identifier.provider!!,\n services: identifier.services.map((service) => {\n let endpoint = service.serviceEndpoint.toString()\n try {\n endpoint = JSON.parse(service.serviceEndpoint)\n } catch {}\n return {\n id: service.id,\n type: service.type,\n serviceEndpoint: endpoint,\n description: service.description,\n }\n }),\n keys: identifier.keys.map(\n (k) =>\n ({\n kid: k.kid,\n type: k.type,\n kms: k.kms,\n publicKeyHex: k.publicKeyHex,\n meta: k.meta,\n } as IKey),\n ),\n }\n if (identifier.alias) {\n result.alias = identifier.alias\n }\n return result\n }\n\n async delete({ did }: { did: string }) {\n const identifier = await (await getConnectedDb(this.dbConnection)).getRepository(Identifier).findOne({\n where: { did },\n relations: ['keys', 'services', 'issuedCredentials', 'issuedPresentations'],\n })\n if (!identifier || typeof identifier === 'undefined') {\n return true\n }\n // some drivers don't support cascading so we delete these manually\n\n //unlink existing keys that are no longer tied to this identifier\n let existingKeys = identifier.keys.map((key) => {\n delete key.identifier\n return key\n })\n await (await getConnectedDb(this.dbConnection)).getRepository(Key).save(existingKeys)\n\n if (identifier.issuedCredentials || typeof identifier.issuedCredentials !== 'undefined') {\n await (await getConnectedDb(this.dbConnection)).getRepository(Credential).remove(identifier.issuedCredentials)\n }\n\n if (identifier.issuedPresentations || typeof identifier.issuedPresentations !== 'undefined') {\n await (await getConnectedDb(this.dbConnection)).getRepository(Presentation).remove(identifier.issuedPresentations)\n }\n\n //delete existing services that are no longer tied to this identifier\n let oldServices = identifier.services\n const srvRepo = await (await getConnectedDb(this.dbConnection)).getRepository(Service).remove(oldServices)\n\n if (!identifier) throw Error('Identifier not found')\n debug('Deleting', did)\n await (await getConnectedDb(this.dbConnection)).getRepository(Identifier).remove(identifier)\n\n return true\n }\n\n async import(args: IIdentifier) {\n const identifier = new Identifier()\n identifier.did = args.did\n if (args.controllerKeyId) {\n identifier.controllerKeyId = args.controllerKeyId\n }\n identifier.provider = args.provider\n if (args.alias) {\n identifier.alias = args.alias\n }\n\n identifier.keys = []\n for (const argsKey of args.keys) {\n const key = new Key()\n key.kid = argsKey.kid\n key.publicKeyHex = argsKey.publicKeyHex\n key.kms = argsKey.kms\n key.meta = argsKey.meta\n identifier.keys.push(key)\n }\n\n identifier.services = []\n for (const argsService of args.services) {\n const service = new Service()\n service.id = argsService.id\n service.type = argsService.type\n service.serviceEndpoint = (typeof argsService.serviceEndpoint === 'string') ? argsService.serviceEndpoint : JSON.stringify(argsService.serviceEndpoint)\n service.description = argsService.description\n identifier.services.push(service)\n }\n\n await (await getConnectedDb(this.dbConnection)).getRepository(Identifier).save(identifier)\n\n debug('Saving', args.did)\n return true\n }\n\n async list(args: { alias?: string; provider?: string }): Promise<IIdentifier[]> {\n const where: any = { provider: args?.provider || Not(IsNull()) }\n if (args?.alias) {\n where['alias'] = args.alias\n }\n const identifiers = await (await getConnectedDb(this.dbConnection)).getRepository(Identifier).find({\n where,\n relations: ['keys', 'services'],\n })\n return identifiers.map((identifier) => {\n const i = identifier\n if (i.alias === null) {\n delete i.alias\n }\n return i as IIdentifier\n })\n }\n}\n","import { IKey, ManagedKeyInfo } from '@veramo/core'\nimport { AbstractKeyStore } from '@veramo/key-manager'\nimport { DataSource } from 'typeorm'\n\nimport { Key } from '../entities/key'\n\nimport Debug from 'debug'\nimport { OrPromise } from \"@veramo/utils\";\nimport { getConnectedDb } from \"../utils\";\nconst debug = Debug('veramo:typeorm:key-store')\n\n/**\n * An implementation of {@link @veramo/key-manager#AbstractKeyStore | AbstractKeyStore} that uses a TypeORM database to\n * store the relationships between keys, their IDs, aliases and\n * {@link @veramo/key-manager#AbstractKeyManagementSystem | KMS implementations}, as they are known and managed by a\n * Veramo agent.\n *\n * An instance of this class can be used by {@link @veramo/key-manager#KeyManager} as the data storage layer.\n *\n * To make full use of this class, it should use the same database as the one used by\n * {@link @veramo/data-store#DIDStore | DIDStore}.\n *\n * @public\n */\nexport class KeyStore extends AbstractKeyStore {\n constructor(private dbConnection: OrPromise<DataSource>) {\n super()\n }\n\n async get({ kid }: { kid: string }): Promise<IKey> {\n const key = await (await getConnectedDb(this.dbConnection)).getRepository(Key).findOneBy({ kid })\n if (!key) throw Error('Key not found')\n return key as IKey\n }\n\n async delete({ kid }: { kid: string }) {\n const key = await (await getConnectedDb(this.dbConnection)).getRepository(Key).findOneBy({ kid })\n if (!key) throw Error('Key not found')\n debug('Deleting key', kid)\n await (await getConnectedDb(this.dbConnection)).getRepository(Key).remove(key)\n return true\n }\n\n async import(args: IKey) {\n const key = new Key()\n key.kid = args.kid\n key.publicKeyHex = args.publicKeyHex\n key.type = args.type\n key.kms = args.kms\n key.meta = args.meta\n debug('Saving key', args.kid)\n await (await getConnectedDb(this.dbConnection)).getRepository(Key).save(key)\n return true\n }\n\n async list(args: {} = {}): Promise<ManagedKeyInfo[]> {\n const keys = await (await getConnectedDb(this.dbConnection)).getRepository(Key).find()\n const managedKeys: ManagedKeyInfo[] = keys.map((key) => {\n const { kid, publicKeyHex, type, meta, kms } = key\n return { kid, publicKeyHex, type, meta, kms } as IKey\n })\n return managedKeys\n }\n}\n","import { KeyType } from './key'\nimport { Entity, Column, PrimaryColumn, BaseEntity } from 'typeorm'\n\n/**\n * Represents some properties of a {@link @veramo/key-manager#ManagedPrivateKey | ManagedPrivateKey} that are stored in\n * a TypeORM database when using a {@link @veramo/data-store#PrivateKeyStore | PrivateKeyStore} to store private key\n * data.\n *\n * @see {@link @veramo/kms-local#KeyManagementSystem | KeyManagementSystem} for an implementation of a KMS that can\n * make use of such stored keys.\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\n@Entity('private-key')\nexport class PrivateKey extends BaseEntity {\n @PrimaryColumn()\n //@ts-ignore\n alias: string\n\n @Column()\n //@ts-ignore\n type: KeyType\n\n @Column()\n //@ts-ignore\n privateKeyHex: string\n}\n","import { AbstractSecretBox, AbstractPrivateKeyStore } from '@veramo/key-manager'\nimport { DataSource } from 'typeorm'\nimport { ImportablePrivateKey, ManagedPrivateKey } from '@veramo/key-manager'\nimport { PrivateKey } from '../entities/private-key'\nimport { v4 as uuid4 } from 'uuid'\nimport Debug from 'debug'\nimport { OrPromise } from '@veramo/utils'\nimport { getConnectedDb } from '../utils'\n\nconst debug = Debug('veramo:typeorm:key-store')\n\n/**\n * An implementation of {@link @veramo/key-manager#AbstractPrivateKeyStore | AbstractPrivateKeyStore} that uses a\n * TypeORM database connection to store private key material.\n *\n * The keys can be encrypted while at rest if this class is initialized with an\n * {@link @veramo/key-manager#AbstractSecretBox | AbstractSecretBox} implementation.\n *\n * @public\n */\nexport class PrivateKeyStore extends AbstractPrivateKeyStore {\n constructor(private dbConnection: OrPromise<DataSource>, private secretBox?: AbstractSecretBox) {\n super()\n if (!secretBox) {\n console.warn('Please provide SecretBox to the KeyStore')\n }\n }\n\n async get({ alias }: { alias: string }): Promise<ManagedPrivateKey> {\n const key = await (await getConnectedDb(this.dbConnection)).getRepository(PrivateKey).findOneBy({ alias })\n if (!key) throw Error('Key not found')\n if (this.secretBox && key.privateKeyHex) {\n key.privateKeyHex = await this.secretBox.decrypt(key.privateKeyHex)\n }\n return key as ManagedPrivateKey\n }\n\n async delete({ alias }: { alias: string }) {\n const key = await (await getConnectedDb(this.dbConnection)).getRepository(PrivateKey).findOneBy({ alias })\n if (!key) throw Error(`not_found: Private Key data not found for alias=${alias}`)\n debug('Deleting private key data', alias)\n await (await getConnectedDb(this.dbConnection)).getRepository(PrivateKey).remove(key)\n return true\n }\n\n async import(args: ImportablePrivateKey): Promise<ManagedPrivateKey> {\n const key = new PrivateKey()\n key.alias = args.alias || uuid4()\n key.privateKeyHex = args.privateKeyHex\n if (this.secretBox && key.privateKeyHex) {\n key.privateKeyHex = await this.secretBox.encrypt(key.privateKeyHex)\n }\n key.type = args.type\n debug('Saving private key data', args.alias)\n const keyRepo = await (await getConnectedDb(this.dbConnection)).getRepository(PrivateKey)\n const existingKey = await keyRepo.findOneBy({ alias: key.alias })\n if (existingKey && existingKey.privateKeyHex !== key.privateKeyHex) {\n throw new Error(\n `key_already_exists: A key with this alias exists but with different data. Please use a different alias.`,\n )\n }\n await keyRepo.save(key)\n return key\n }\n\n async list(): Promise<Array<ManagedPrivateKey>> {\n const keys = await (await getConnectedDb(this.dbConnection)).getRepository(PrivateKey).find()\n return keys\n }\n}\n","import {\n IAgentPlugin,\n IDataStore,\n IDataStoreDeleteVerifiableCredentialArgs,\n IDataStoreGetMessageArgs,\n IDataStoreGetVerifiableCredentialArgs,\n IDataStoreGetVerifiablePresentationArgs,\n IDataStoreSaveMessageArgs,\n IDataStoreSaveVerifiableCredentialArgs,\n IDataStoreSaveVerifiablePresentationArgs,\n IMessage,\n schema,\n VerifiableCredential,\n VerifiablePresentation,\n} from '@veramo/core'\nimport { createMessage, createMessageEntity, Message } from './entities/message'\nimport { createCredentialEntity, Credential } from './entities/credential'\nimport { Claim } from './entities/claim'\nimport { createPresentationEntity, Presentation } from './entities/presentation'\nimport { DataSource } from 'typeorm'\nimport { getConnectedDb } from './utils'\nimport { OrPromise } from '@veramo/utils'\n\n/**\n * This class implements the {@link @veramo/core#IDataStore} interface using a TypeORM compatible database.\n *\n * This allows you to store and retrieve Verifiable Credentials, Presentations and Messages by their IDs.\n *\n * For more complex queries you should use {@link @veramo/data-store#DataStoreORM} which is the default way to query\n * the stored data by some common properties. These two classes MUST also share the same database connection.\n *\n * @see {@link @veramo/core#IDataStoreORM}\n * @see {@link @veramo/core#IDataStore}\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport class DataStore implements IAgentPlugin {\n readonly methods: IDataStore\n readonly schema = schema.IDataStore\n private dbConnection: OrPromise<DataSource>\n\n constructor(dbConnection: OrPromise<DataSource>) {\n this.dbConnection = dbConnection\n\n this.methods = {\n dataStoreSaveMessage: this.dataStoreSaveMessage.bind(this),\n dataStoreGetMessage: this.dataStoreGetMessage.bind(this),\n dataStoreDeleteVerifiableCredential: this.dataStoreDeleteVerifiableCredential.bind(this),\n dataStoreSaveVerifiableCredential: this.dataStoreSaveVerifiableCredential.bind(this),\n dataStoreGetVerifiableCredential: this.dataStoreGetVerifiableCredential.bind(this),\n dataStoreSaveVerifiablePresentation: this.dataStoreSaveVerifiablePresentation.bind(this),\n dataStoreGetVerifiablePresentation: this.dataStoreGetVerifiablePresentation.bind(this),\n }\n }\n\n async dataStoreSaveMessage(args: IDataStoreSaveMessageArgs): Promise<string> {\n const message = await (await getConnectedDb(this.dbConnection))\n .getRepository(Message)\n .save(createMessageEntity(args.message))\n return message.id\n }\n\n async dataStoreGetMessage(args: IDataStoreGetMessageArgs): Promise<IMessage> {\n const messageEntity = await (await getConnectedDb(this.dbConnection)).getRepository(Message).findOne({\n where: { id: args.id },\n relations: ['credentials', 'presentations'],\n })\n if (!messageEntity) throw new Error('not_found: Message not found')\n\n return createMessage(messageEntity)\n }\n\n async dataStoreDeleteVerifiableCredential(\n args: IDataStoreDeleteVerifiableCredentialArgs,\n ): Promise<boolean> {\n const credentialEntity = await (await getConnectedDb(this.dbConnection))\n .getRepository(Credential)\n .findOneBy({ hash: args.hash })\n if (!credentialEntity) {\n return false\n }\n\n const claims = await (await getConnectedDb(this.dbConnection))\n .getRepository(Claim)\n .find({ where: { credential: { id: credentialEntity.id } } })\n\n await (await getConnectedDb(this.dbConnection)).getRepository(Claim).remove(claims)\n\n await (await getConnectedDb(this.dbConnection)).getRepository(Credential).remove(credentialEntity)\n\n return true\n }\n\n async dataStoreSaveVerifiableCredential(args: IDataStoreSaveVerifiableCredentialArgs): Promise<string> {\n const verifiableCredential = await (await getConnectedDb(this.dbConnection))\n .getRepository(Credential)\n .save(createCredentialEntity(args.verifiableCredential))\n return verifiableCredential.hash\n }\n\n async dataStoreGetVerifiableCredential(\n args: IDataStoreGetVerifiableCredentialArgs,\n ): Promise<VerifiableCredential> {\n const credentialEntity = await (await getConnectedDb(this.dbConnection))\n .getRepository(Credential)\n .findOneBy({ hash: args.hash })\n if (!credentialEntity) throw new Error('not_found: Verifiable credential not found')\n\n return credentialEntity.raw\n }\n\n async dataStoreSaveVerifiablePresentation(args: IDataStoreSaveVerifiablePresentationArgs): Promise<string> {\n const verifiablePresentation = await (await getConnectedDb(this.dbConnection))\n .getRepository(Presentation)\n .save(createPresentationEntity(args.verifiablePresentation))\n return verifiablePresentation.hash\n }\n\n async dataStoreGetVerifiablePresentation(\n args: IDataStoreGetVerifiablePresentationArgs,\n ): Promise<VerifiablePresentation> {\n const presentationEntity = await (await getConnectedDb(this.dbConnection))\n .getRepository(Presentation)\n .findOneBy({ hash: args.hash })\n if (!presentationEntity) throw new Error('not_found: Verifiable presentation not found')\n\n return presentationEntity.raw\n }\n}\n","import {\n AuthorizedDIDContext,\n FindArgs,\n IAgentPlugin,\n IDataStoreORM,\n IIdentifier,\n IMessage,\n PartialIdentifier,\n schema,\n TClaimsColumns,\n TCredentialColumns,\n TIdentifiersColumns,\n TMessageColumns,\n TPresentationColumns,\n UniqueVerifiableCredential,\n UniqueVerifiablePresentation,\n Where,\n} from '@veramo/core'\nimport { createMessage, Message } from './entities/message'\nimport { Claim } from './entities/claim'\nimport { Credential } from './entities/credential'\nimport { Presentation } from './entities/presentation'\nimport { Identifier } from './entities/identifier'\nimport {\n Any,\n Between,\n Brackets,\n DataSource,\n Equal,\n In,\n IsNull,\n LessThan,\n LessThanOrEqual,\n Like,\n MoreThan,\n MoreThanOrEqual,\n Not,\n SelectQueryBuilder,\n} from 'typeorm'\nimport { getConnectedDb } from \"./utils\";\nimport { OrPromise } from \"@veramo/utils\";\n\n/**\n * This class implements the {@link @veramo/core#IDataStoreORM} query interface using a TypeORM compatible database.\n *\n * This allows you to filter Verifiable Credentials, Presentations and Messages by some common properties that are\n * parsed and stored in database tables.\n *\n * This class is designed to work with {@link @veramo/data-store#DataStore} which is the default way to populate the\n * database with Credentials, Presentations and Messages in such a way that they can be queried by this class.\n * These two classes MUST also share the same database connection.\n *\n * @see {@link @veramo/core#IDataStoreORM}\n * @see {@link @veramo/core#IDataStore}\n *\n * @beta This API may change without a BREAKING CHANGE notice.\n */\nexport class DataStoreORM implements IAgentPlugin {\n readonly methods: IDataStoreORM\n readonly schema = schema.IDataStoreORM\n private dbConnection: OrPromise<DataSource>\n\n constructor(dbConnection: OrPromise<DataSource>) {\n this.dbConnection = dbConnection\n\n this.methods = {\n dataStoreORMGetIdentifiers: this.dataStoreORMGetIdentifiers.bind(this),\n dataStoreORMGetIdentifiersCount: this.dataStoreORMGetIdentifiersCount.bind(this),\n dataStoreORMGetMessages: this.dataStoreORMGetMessages.bind(this),\n dataStoreORMGetMessagesCount: this.dataStoreORMGetMessagesCount.bind(this),\n dataStoreORMGetVerifiableCredentialsByClaims:\n this.dataStoreORMGetVerifiableCredentialsByClaims.bind(this),\n dataStoreORMGetVerifiableCredentialsByClaimsCount:\n this.dataStoreORMGetVerifiableCredentialsByClaimsCount.bind(this),\n dataStoreORMGetVerifiableCredentials: this.dataStoreORMGetVerifiableCredentials.bind(this),\n dataStoreORMGetVerifiableCredentialsCount: this.dataStoreORMGetVerifiableCredentialsCount.bind(this),\n dataStoreORMGetVerifiablePresentations: this.dataStoreORMGetVerifiablePresentations.bind(this),\n dataStoreORMGetVerifiablePresentationsCount:\n this.dataStoreORMGetVerifiablePresentationsCount.bind(this),\n }\n }\n\n // Identifiers\n\n private async identifiersQuery(\n args: FindArgs<TIdentifiersColumns>,\n context: AuthorizedDIDContext,\n ): Promise<SelectQueryBuilder<Identifier>> {\n const where = createWhereObject(args)\n let qb = (await getConnectedDb(this.dbConnection))\n .getRepository(Identifier)\n .createQueryBuilder('identifier')\n .leftJoinAndSelect('identifier.keys', 'keys')\n .leftJoinAndSelect('identifier.services', 'services')\n .where(where)\n qb = decorateQB(qb, 'message', args)\n return qb\n }\n\n async dataStoreORMGetIdentifiers(\n args: FindArgs<TIdentifiersColumns>,\n context: AuthorizedDIDContext,\n ): Promise<PartialIdentifier[]> {\n const identifiers = await (await this.identifiersQuery(args, context)).getMany()\n return identifiers.map((i) => {\n const identifier: PartialIdentifier = i as PartialIdentifier\n if (identifier.controllerKeyId === null) {\n delete identifier.controllerKeyId\n }\n if (identifier.alias === null) {\n delete identifier.alias\n }\n if (identifier.provider === null) {\n delete identifier.provider\n }\n return identifier as IIdentifier\n })\n }\n\n async dataStoreORMGetIdentifiersCount(\n args: FindArgs<TIdentifiersColumns>,\n context: AuthorizedDIDContext,\n ): Promise<number> {\n return await (await this.identifiersQuery(args, context)).getCount()\n }\n\n // Messages\n\n private async messagesQuery(\n args: FindArgs<TMessageColumns>,\n context: AuthorizedDIDContext,\n ): Promise<SelectQueryBuilder<Message>> {