@sphereon/ssi-sdk.data-store 0.18.2-unstable.98 → 0.19.1-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/contact/AbstractContactStore.d.ts.map +1 -1
- package/dist/contact/AbstractContactStore.js.map +1 -1
- package/dist/contact/ContactStore.d.ts.map +1 -1
- package/dist/contact/ContactStore.js +12 -6
- package/dist/contact/ContactStore.js.map +1 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -10
- package/dist/index.js.map +1 -1
- package/dist/issuanceBranding/IssuanceBrandingStore.d.ts.map +1 -1
- package/dist/issuanceBranding/IssuanceBrandingStore.js.map +1 -1
- package/dist/migrations/generic/index.d.ts +0 -2
- package/dist/migrations/generic/index.d.ts.map +1 -1
- package/dist/migrations/generic/index.js +1 -4
- package/dist/migrations/generic/index.js.map +1 -1
- package/dist/migrations/index.d.ts +1 -1
- package/dist/migrations/index.d.ts.map +1 -1
- package/dist/migrations/index.js +1 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/types/contact/contact.d.ts.map +1 -1
- package/dist/types/contact/contact.js.map +1 -1
- package/package.json +4 -5
- package/src/__tests__/contact.entities.test.ts +32 -15
- package/src/__tests__/contact.store.test.ts +71 -28
- package/src/contact/AbstractContactStore.ts +3 -2
- package/src/contact/ContactStore.ts +15 -9
- package/src/entities/contact/PhysicalAddressEntity.ts +1 -1
- package/src/index.ts +0 -9
- package/src/issuanceBranding/IssuanceBrandingStore.ts +6 -8
- package/src/migrations/generic/index.ts +0 -3
- package/src/migrations/index.ts +0 -1
- package/src/types/contact/contact.ts +13 -2
- package/dist/digitalCredential/AbstractDigitalCredentialStore.d.ts +0 -10
- package/dist/digitalCredential/AbstractDigitalCredentialStore.d.ts.map +0 -1
- package/dist/digitalCredential/AbstractDigitalCredentialStore.js +0 -7
- package/dist/digitalCredential/AbstractDigitalCredentialStore.js.map +0 -1
- package/dist/digitalCredential/DigitalCredentialStore.d.ts +0 -15
- package/dist/digitalCredential/DigitalCredentialStore.d.ts.map +0 -1
- package/dist/digitalCredential/DigitalCredentialStore.js +0 -118
- package/dist/digitalCredential/DigitalCredentialStore.js.map +0 -1
- package/dist/entities/digitalCredential/DigitalCredentialEntity.d.ts +0 -23
- package/dist/entities/digitalCredential/DigitalCredentialEntity.d.ts.map +0 -1
- package/dist/entities/digitalCredential/DigitalCredentialEntity.js +0 -93
- package/dist/entities/digitalCredential/DigitalCredentialEntity.js.map +0 -1
- package/dist/migrations/generic/6-CreateDigitalCredential.d.ts +0 -7
- package/dist/migrations/generic/6-CreateDigitalCredential.d.ts.map +0 -1
- package/dist/migrations/generic/6-CreateDigitalCredential.js +0 -78
- package/dist/migrations/generic/6-CreateDigitalCredential.js.map +0 -1
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.d.ts +0 -7
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.d.ts.map +0 -1
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js +0 -59
- package/dist/migrations/postgres/1708525189001-CreateDigitalCredential.js.map +0 -1
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.d.ts +0 -7
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.d.ts.map +0 -1
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js +0 -50
- package/dist/migrations/sqlite/1708525189002-CreateDigitalCredential.js.map +0 -1
- package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.d.ts +0 -42
- package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.d.ts.map +0 -1
- package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.js +0 -3
- package/dist/types/digitalCredential/IAbstractDigitalCredentialStore.js.map +0 -1
- package/dist/types/digitalCredential/digitalCredential.d.ts +0 -42
- package/dist/types/digitalCredential/digitalCredential.d.ts.map +0 -1
- package/dist/types/digitalCredential/digitalCredential.js +0 -28
- package/dist/types/digitalCredential/digitalCredential.js.map +0 -1
- package/dist/utils/SortingUtils.d.ts +0 -3
- package/dist/utils/SortingUtils.d.ts.map +0 -1
- package/dist/utils/SortingUtils.js +0 -18
- package/dist/utils/SortingUtils.js.map +0 -1
- package/dist/utils/digitalCredential/MappingUtils.d.ts +0 -7
- package/dist/utils/digitalCredential/MappingUtils.d.ts.map +0 -1
- package/dist/utils/digitalCredential/MappingUtils.js +0 -99
- package/dist/utils/digitalCredential/MappingUtils.js.map +0 -1
- package/src/__tests__/digitalCredential.entities.test.ts +0 -254
- package/src/__tests__/digitalCredential.store.test.ts +0 -294
- package/src/digitalCredential/AbstractDigitalCredentialStore.ts +0 -17
- package/src/digitalCredential/DigitalCredentialStore.ts +0 -127
- package/src/entities/digitalCredential/DigitalCredentialEntity.ts +0 -64
- package/src/migrations/generic/6-CreateDigitalCredential.ts +0 -66
- package/src/migrations/postgres/1708525189001-CreateDigitalCredential.ts +0 -44
- package/src/migrations/sqlite/1708525189002-CreateDigitalCredential.ts +0 -34
- package/src/types/digitalCredential/IAbstractDigitalCredentialStore.ts +0 -37
- package/src/types/digitalCredential/digitalCredential.ts +0 -46
- package/src/utils/SortingUtils.ts +0 -16
- package/src/utils/digitalCredential/MappingUtils.ts +0 -122
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { MigrationInterface, QueryRunner } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
export class CreateDigitalCredential1708525189002 implements MigrationInterface {
|
|
4
|
-
name = 'CreateDigitalCredential1708525189002'
|
|
5
|
-
|
|
6
|
-
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
-
await queryRunner.query(`
|
|
8
|
-
CREATE TABLE "DigitalCredential" (
|
|
9
|
-
"id" varchar PRIMARY KEY NOT NULL,
|
|
10
|
-
"document_type" varchar CHECK( "document_type" IN ('VC', 'VP', 'C', 'P') ) NOT NULL,
|
|
11
|
-
"document_format" varchar CHECK( "document_format" IN ('JSON_LD', 'JWT', 'SD_JWT', 'MDOC') ) NOT NULL,
|
|
12
|
-
"raw_document" text NOT NULL,
|
|
13
|
-
"uniform_document" text NOT NULL,
|
|
14
|
-
"hash" text NOT NULL UNIQUE,
|
|
15
|
-
"issuer_correlation_type" varchar CHECK( "issuer_correlation_type" IN ('DID') ) NOT NULL,
|
|
16
|
-
"subject_correlation_type" varchar CHECK( "subject_correlation_type" IN ('DID') ),
|
|
17
|
-
"issuer_correlation_id" text NOT NULL,
|
|
18
|
-
"subject_correlation_id" text,
|
|
19
|
-
"verified_state" varchar CHECK( "verified_state" IN ('REVOKED', 'VERIFIED', 'EXPIRED') ),
|
|
20
|
-
"tenant_id" text,
|
|
21
|
-
"created_at" datetime NOT NULL DEFAULT (datetime('now')),
|
|
22
|
-
"last_updated_at" datetime NOT NULL DEFAULT (datetime('now')),
|
|
23
|
-
"valid_from" datetime,
|
|
24
|
-
"valid_until" datetime,
|
|
25
|
-
"verified_at" datetime,
|
|
26
|
-
"revoked_at" datetime
|
|
27
|
-
)
|
|
28
|
-
`)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
32
|
-
await queryRunner.query(`DROP TABLE "DigitalCredential"`)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { CredentialCorrelationType, CredentialStateType, DigitalCredential } from './digitalCredential'
|
|
2
|
-
import { Hasher } from '@sphereon/ssi-types'
|
|
3
|
-
import { FindOptionsOrder } from 'typeorm'
|
|
4
|
-
import { DigitalCredentialEntity } from '../../entities/digitalCredential/DigitalCredentialEntity'
|
|
5
|
-
|
|
6
|
-
export type GetCredentialArgs = { id: string } | { hash: string }
|
|
7
|
-
|
|
8
|
-
export type FindDigitalCredentialArgs = Array<Partial<DigitalCredential>>
|
|
9
|
-
|
|
10
|
-
export type GetCredentialsArgs = {
|
|
11
|
-
filter?: FindDigitalCredentialArgs
|
|
12
|
-
offset?: number
|
|
13
|
-
limit?: number
|
|
14
|
-
order?: string | FindOptionsOrder<DigitalCredentialEntity>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type GetCredentialsResponse = {
|
|
18
|
-
data: Array<DigitalCredential>
|
|
19
|
-
total: number
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type AddCredentialArgs = {
|
|
23
|
-
rawDocument: string
|
|
24
|
-
issuerCorrelationType: CredentialCorrelationType
|
|
25
|
-
subjectCorrelationType?: CredentialCorrelationType
|
|
26
|
-
issuerCorrelationId: string
|
|
27
|
-
subjectCorrelationId?: string
|
|
28
|
-
tenantId?: string
|
|
29
|
-
state?: CredentialStateType
|
|
30
|
-
verifiedAt?: Date
|
|
31
|
-
revokedAt?: Date
|
|
32
|
-
opts?: { maxTimeSkewInMS?: number; hasher?: Hasher }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type UpdateCredentialStateArgs = GetCredentialArgs & { verifiedState: CredentialStateType; verifiedAt?: Date; revokedAt?: Date }
|
|
36
|
-
|
|
37
|
-
export type RemoveCredentialArgs = GetCredentialArgs
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export type NonPersistedDigitalCredential = Omit<DigitalCredential, 'id'>
|
|
2
|
-
|
|
3
|
-
export type DigitalCredential = {
|
|
4
|
-
id: string
|
|
5
|
-
documentType: DocumentType
|
|
6
|
-
documentFormat: CredentialDocumentFormat
|
|
7
|
-
rawDocument: string
|
|
8
|
-
uniformDocument: string
|
|
9
|
-
hash: string
|
|
10
|
-
issuerCorrelationType: CredentialCorrelationType
|
|
11
|
-
subjectCorrelationType?: CredentialCorrelationType
|
|
12
|
-
issuerCorrelationId: string
|
|
13
|
-
subjectCorrelationId?: string
|
|
14
|
-
verifiedState?: CredentialStateType
|
|
15
|
-
tenantId?: string
|
|
16
|
-
createdAt: Date
|
|
17
|
-
lastUpdatedAt: Date
|
|
18
|
-
validUntil?: Date
|
|
19
|
-
validFrom?: Date
|
|
20
|
-
verifiedAt?: Date
|
|
21
|
-
revokedAt?: Date
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export enum DocumentType {
|
|
25
|
-
VC = 'VC',
|
|
26
|
-
VP = 'VP',
|
|
27
|
-
P = 'P',
|
|
28
|
-
C = 'C',
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export enum CredentialDocumentFormat {
|
|
32
|
-
JSON_LD = 'JSON_LD',
|
|
33
|
-
JWT = 'JWT',
|
|
34
|
-
SD_JWT = 'SD_JWT',
|
|
35
|
-
MDOC = 'MDOC',
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum CredentialCorrelationType {
|
|
39
|
-
DID = 'DID',
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export enum CredentialStateType {
|
|
43
|
-
REVOKED = 'REVOKED',
|
|
44
|
-
VERIFIED = 'VERIFIED',
|
|
45
|
-
EXPIRED = 'EXPIRED',
|
|
46
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { BaseEntity, FindOptionsOrder } from 'typeorm'
|
|
2
|
-
|
|
3
|
-
export const parseAndValidateOrderOptions = <T extends BaseEntity>(order: string): FindOptionsOrder<T> => {
|
|
4
|
-
const orderPairs = order.split(',').map((pair) => pair.trim().split('.'))
|
|
5
|
-
const orderOptions: FindOptionsOrder<T> = {}
|
|
6
|
-
|
|
7
|
-
orderPairs.forEach(([field, direction]) => {
|
|
8
|
-
const dir = direction.toUpperCase()
|
|
9
|
-
if (dir !== 'ASC' && dir !== 'DESC') {
|
|
10
|
-
throw new Error(`Invalid order direction: '${direction}'. Must be 'asc' or 'desc'.`)
|
|
11
|
-
}
|
|
12
|
-
;(orderOptions as any)[field] = dir
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
return orderOptions
|
|
16
|
-
}
|
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
import { AddCredentialArgs } from '../../types/digitalCredential/IAbstractDigitalCredentialStore'
|
|
2
|
-
import { DigitalCredentialEntity } from '../../entities/digitalCredential/DigitalCredentialEntity'
|
|
3
|
-
import {
|
|
4
|
-
CredentialMapper,
|
|
5
|
-
decodeSdJwtVc,
|
|
6
|
-
DocumentFormat,
|
|
7
|
-
IVerifiableCredential,
|
|
8
|
-
IVerifiablePresentation,
|
|
9
|
-
OriginalVerifiableCredential,
|
|
10
|
-
OriginalVerifiablePresentation,
|
|
11
|
-
SdJwtDecodedVerifiableCredentialPayload,
|
|
12
|
-
} from '@sphereon/ssi-types'
|
|
13
|
-
import {
|
|
14
|
-
CredentialDocumentFormat,
|
|
15
|
-
DocumentType,
|
|
16
|
-
DigitalCredential,
|
|
17
|
-
NonPersistedDigitalCredential,
|
|
18
|
-
} from '../../types/digitalCredential/digitalCredential'
|
|
19
|
-
import { computeEntryHash } from '@veramo/utils'
|
|
20
|
-
|
|
21
|
-
function determineDocumentType(raw: string): DocumentType {
|
|
22
|
-
const rawDocument = parseRawDocument(raw)
|
|
23
|
-
if (!rawDocument) {
|
|
24
|
-
throw new Error(`Couldn't parse the credential: ${raw}`)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const hasProof = CredentialMapper.hasProof(rawDocument)
|
|
28
|
-
const isCredential = CredentialMapper.isCredential(rawDocument)
|
|
29
|
-
const isPresentation = CredentialMapper.isPresentation(rawDocument)
|
|
30
|
-
|
|
31
|
-
if (isCredential) {
|
|
32
|
-
return hasProof ? DocumentType.VC : DocumentType.C
|
|
33
|
-
} else if (isPresentation) {
|
|
34
|
-
return hasProof ? DocumentType.VP : DocumentType.P
|
|
35
|
-
}
|
|
36
|
-
throw new Error(`Couldn't determine the type of the credential: ${raw}`)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function parseRawDocument(raw: string): OriginalVerifiableCredential | OriginalVerifiablePresentation {
|
|
40
|
-
if (CredentialMapper.isJwtEncoded(raw) || CredentialMapper.isSdJwtEncoded(raw)) {
|
|
41
|
-
return raw
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
return JSON.parse(raw)
|
|
45
|
-
} catch (e) {
|
|
46
|
-
throw new Error(`Can't parse the raw credential: ${raw}`)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function determineCredentialDocumentFormat(documentFormat: DocumentFormat): CredentialDocumentFormat {
|
|
51
|
-
switch (documentFormat) {
|
|
52
|
-
case DocumentFormat.JSONLD:
|
|
53
|
-
return CredentialDocumentFormat.JSON_LD
|
|
54
|
-
case DocumentFormat.JWT:
|
|
55
|
-
return CredentialDocumentFormat.JWT
|
|
56
|
-
case DocumentFormat.SD_JWT_VC:
|
|
57
|
-
return CredentialDocumentFormat.SD_JWT
|
|
58
|
-
default:
|
|
59
|
-
throw new Error(`Not supported document format: ${documentFormat}`)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function getValidUntil(uniformDocument: IVerifiableCredential | IVerifiablePresentation | SdJwtDecodedVerifiableCredentialPayload): Date | undefined {
|
|
64
|
-
if ('expirationDate' in uniformDocument) {
|
|
65
|
-
return new Date(uniformDocument.expirationDate)
|
|
66
|
-
} else if ('validUntil' in uniformDocument) {
|
|
67
|
-
return new Date(uniformDocument.validUntil)
|
|
68
|
-
} else if ('exp' in uniformDocument) {
|
|
69
|
-
return new Date(uniformDocument.exp)
|
|
70
|
-
}
|
|
71
|
-
return undefined
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function getValidFrom(uniformDocument: IVerifiableCredential | IVerifiablePresentation | SdJwtDecodedVerifiableCredentialPayload): Date | undefined {
|
|
75
|
-
if ('issuanceDate' in uniformDocument) {
|
|
76
|
-
return new Date(uniformDocument.issuanceDate)
|
|
77
|
-
} else if ('validFrom' in uniformDocument) {
|
|
78
|
-
return new Date(uniformDocument['validFrom'])
|
|
79
|
-
} else if ('nbf' in uniformDocument) {
|
|
80
|
-
return new Date(uniformDocument['nbf'] * 1000)
|
|
81
|
-
} else if ('iat' in uniformDocument) {
|
|
82
|
-
return new Date(uniformDocument['iat'] * 1000)
|
|
83
|
-
}
|
|
84
|
-
return undefined
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const nonPersistedDigitalCredentialEntityFromAddArgs = (addCredentialArgs: AddCredentialArgs): NonPersistedDigitalCredential => {
|
|
88
|
-
const documentType: DocumentType = determineDocumentType(addCredentialArgs.rawDocument)
|
|
89
|
-
const documentFormat: DocumentFormat = CredentialMapper.detectDocumentType(addCredentialArgs.rawDocument)
|
|
90
|
-
if (documentFormat === DocumentFormat.SD_JWT_VC && !addCredentialArgs.opts?.hasher) {
|
|
91
|
-
throw new Error('No hasher function is provided for SD_JWT credential.')
|
|
92
|
-
}
|
|
93
|
-
const uniformDocument =
|
|
94
|
-
documentFormat === DocumentFormat.SD_JWT_VC
|
|
95
|
-
? decodeSdJwtVc(addCredentialArgs.rawDocument, addCredentialArgs.opts!.hasher!).decodedPayload
|
|
96
|
-
: documentType === DocumentType.VC || documentType === DocumentType.C
|
|
97
|
-
? CredentialMapper.toUniformCredential(addCredentialArgs.rawDocument)
|
|
98
|
-
: CredentialMapper.toUniformPresentation(addCredentialArgs.rawDocument)
|
|
99
|
-
const validFrom: Date | undefined = getValidFrom(uniformDocument)
|
|
100
|
-
const validUntil: Date | undefined = getValidUntil(uniformDocument)
|
|
101
|
-
return {
|
|
102
|
-
...addCredentialArgs,
|
|
103
|
-
documentType,
|
|
104
|
-
documentFormat: determineCredentialDocumentFormat(documentFormat),
|
|
105
|
-
createdAt: new Date(),
|
|
106
|
-
hash: computeEntryHash(addCredentialArgs.rawDocument),
|
|
107
|
-
uniformDocument: JSON.stringify(uniformDocument),
|
|
108
|
-
validFrom,
|
|
109
|
-
validUntil,
|
|
110
|
-
lastUpdatedAt: new Date(),
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export const digitalCredentialFrom = (credentialEntity: DigitalCredentialEntity): DigitalCredential => {
|
|
115
|
-
return {
|
|
116
|
-
...credentialEntity,
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export const digitalCredentialsFrom = (credentialEntities: Array<DigitalCredentialEntity>): DigitalCredential[] => {
|
|
121
|
-
return credentialEntities.map((credentialEntity) => digitalCredentialFrom(credentialEntity))
|
|
122
|
-
}
|