@credo-ts/drizzle-storage 0.6.0-pr-2324-20250708122805 → 0.6.0-pr-2324-20250709075226
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/cli/drizzle.config.ts +1 -1
- package/cli-build/drizzle.config.js +1 -1
- package/cli-build/drizzle.config.js.map +1 -1
- package/package.json +18 -17
- package/src/DrizzleDatabase.ts +29 -0
- package/src/DrizzleRecord.ts +73 -0
- package/src/DrizzleStorageModule.ts +112 -0
- package/src/DrizzleStorageModuleConfig.ts +48 -0
- package/src/action-menu/action-menu/DrizzleDidcommActionMenuRecordAdapter.ts +46 -0
- package/src/action-menu/action-menu/index.ts +10 -0
- package/src/action-menu/action-menu/postgres.ts +31 -0
- package/src/action-menu/action-menu/sqlite.ts +34 -0
- package/src/action-menu/bundle.ts +18 -0
- package/src/action-menu/postgres.ts +1 -0
- package/src/action-menu/sqlite.ts +1 -0
- package/src/adapter/BaseDrizzleRecordAdapter.ts +319 -0
- package/src/adapter/__tests__/queryToDrizzlePostgres.drizzle.e2e.test.ts +330 -0
- package/src/adapter/__tests__/queryToDrizzleSqlite.test.ts +324 -0
- package/src/adapter/index.ts +6 -0
- package/src/adapter/queryToDrizzlePostgres.ts +217 -0
- package/src/adapter/queryToDrizzleSqlite.ts +213 -0
- package/src/anoncreds/bundle.ts +34 -0
- package/src/anoncreds/credential/DrizzleAnonCredsCredentialRecordAdapter.ts +93 -0
- package/src/anoncreds/credential/index.ts +10 -0
- package/src/anoncreds/credential/postgres.ts +27 -0
- package/src/anoncreds/credential/sqlite.ts +27 -0
- package/src/anoncreds/credential-definition/DrizzleAnonCredsCredentialDefinitionRecordAdapter.ts +72 -0
- package/src/anoncreds/credential-definition/index.ts +10 -0
- package/src/anoncreds/credential-definition/postgres.ts +23 -0
- package/src/anoncreds/credential-definition/sqlite.ts +23 -0
- package/src/anoncreds/credential-definition-private/DrizzleAnonCredsCredentialDefinitionPrivateRecordAdapter.ts +48 -0
- package/src/anoncreds/credential-definition-private/index.ts +10 -0
- package/src/anoncreds/credential-definition-private/postgres.ts +14 -0
- package/src/anoncreds/credential-definition-private/sqlite.ts +14 -0
- package/src/anoncreds/key-correctness-proof/DrizzleAnonCredsKeyCorrectnessProofRecordAdapter.ts +46 -0
- package/src/anoncreds/key-correctness-proof/index.ts +10 -0
- package/src/anoncreds/key-correctness-proof/postgres.ts +13 -0
- package/src/anoncreds/key-correctness-proof/sqlite.ts +14 -0
- package/src/anoncreds/link-secret/DrizzleAnonCredsLinkSecretRecordAdapter.ts +45 -0
- package/src/anoncreds/link-secret/index.ts +10 -0
- package/src/anoncreds/link-secret/postgres.ts +18 -0
- package/src/anoncreds/link-secret/sqlite.ts +18 -0
- package/src/anoncreds/postgres.ts +8 -0
- package/src/anoncreds/revocation-registry-definition/DrizzleAnonCredsRevocationRegistryDefinitionRecordAdapter.ts +52 -0
- package/src/anoncreds/revocation-registry-definition/index.ts +10 -0
- package/src/anoncreds/revocation-registry-definition/postgres.ts +18 -0
- package/src/anoncreds/revocation-registry-definition/sqlite.ts +20 -0
- package/src/anoncreds/revocation-registry-definition-private/DrizzleAnonCredsRevocationRegistryDefinitionPrivateRecordAdapter.ts +53 -0
- package/src/anoncreds/revocation-registry-definition-private/index.ts +10 -0
- package/src/anoncreds/revocation-registry-definition-private/postgres.ts +22 -0
- package/src/anoncreds/revocation-registry-definition-private/sqlite.ts +18 -0
- package/src/anoncreds/schema/DrizzleAnonCredsSchemaRecordAdapter.ts +54 -0
- package/src/anoncreds/schema/__tests__/schema.drizzle.e2e.test.ts +70 -0
- package/src/anoncreds/schema/index.ts +10 -0
- package/src/anoncreds/schema/postgres.ts +22 -0
- package/src/anoncreds/schema/sqlite.ts +22 -0
- package/src/anoncreds/sqlite.ts +8 -0
- package/src/applyReactNativeMigrations.ts +24 -0
- package/src/combineSchemas.ts +44 -0
- package/src/core/bundle.ts +33 -0
- package/src/core/context/index.ts +8 -0
- package/src/core/context/postgres.ts +5 -0
- package/src/core/context/sqlite.ts +5 -0
- package/src/core/did/DrizzleDidRecordAdapter.ts +71 -0
- package/src/core/did/index.ts +10 -0
- package/src/core/did/postgres.ts +28 -0
- package/src/core/did/sqlite.ts +26 -0
- package/src/core/genericRecord/DrizzleGenericRecordAdapter.ts +36 -0
- package/src/core/genericRecord/index.ts +10 -0
- package/src/core/genericRecord/postgres.ts +12 -0
- package/src/core/genericRecord/sqlite.ts +12 -0
- package/src/core/mdoc/DrizzleMdocRecordAdapter.ts +44 -0
- package/src/core/mdoc/index.ts +10 -0
- package/src/core/mdoc/postgres.ts +15 -0
- package/src/core/mdoc/sqlite.ts +15 -0
- package/src/core/postgres.ts +8 -0
- package/src/core/sdJwtVc/DrizzleSdJwtVcRecordAdapter.ts +46 -0
- package/src/core/sdJwtVc/index.ts +10 -0
- package/src/core/sdJwtVc/postgres.ts +17 -0
- package/src/core/sdJwtVc/sqlite.ts +17 -0
- package/src/core/singleContextLruCache/DrizzleSingleContextLruCacheRecordAdapter.ts +43 -0
- package/src/core/singleContextLruCache/index.ts +10 -0
- package/src/core/singleContextLruCache/postgres.ts +12 -0
- package/src/core/singleContextLruCache/sqlite.ts +13 -0
- package/src/core/sqlite.ts +8 -0
- package/src/core/storageVersion/DrizzleStorageVersionRecordAdapter.ts +36 -0
- package/src/core/storageVersion/index.ts +10 -0
- package/src/core/storageVersion/postgres.ts +13 -0
- package/src/core/storageVersion/sqlite.ts +13 -0
- package/src/core/w3cCredential/DrizzleW3cCredentialRecordAdapter.ts +95 -0
- package/src/core/w3cCredential/index.ts +10 -0
- package/src/core/w3cCredential/postgres.ts +31 -0
- package/src/core/w3cCredential/sqlite.ts +29 -0
- package/src/didcomm/basic-message/DrizzleDidcommBasicMessageRecordAdapter.ts +54 -0
- package/src/didcomm/basic-message/index.ts +10 -0
- package/src/didcomm/basic-message/postgres.ts +30 -0
- package/src/didcomm/basic-message/sqlite.ts +29 -0
- package/src/didcomm/bundle.ts +34 -0
- package/src/didcomm/connection/DrizzleDidcommConnectionRecordAdapter.ts +70 -0
- package/src/didcomm/connection/index.ts +10 -0
- package/src/didcomm/connection/postgres.ts +55 -0
- package/src/didcomm/connection/sqlite.ts +39 -0
- package/src/didcomm/credential-exchange/DrizzleDidcommCredentialExchangeRecordAdapter.ts +64 -0
- package/src/didcomm/credential-exchange/__tests__/credentialExchange.drizzle.e2e.test.ts +104 -0
- package/src/didcomm/credential-exchange/index.ts +10 -0
- package/src/didcomm/credential-exchange/postgres.ts +45 -0
- package/src/didcomm/credential-exchange/sqlite.ts +39 -0
- package/src/didcomm/didcomm-message/DrizzleDidcommMessageRecordAdapter.ts +75 -0
- package/src/didcomm/didcomm-message/index.ts +10 -0
- package/src/didcomm/didcomm-message/postgres.ts +27 -0
- package/src/didcomm/didcomm-message/sqlite.ts +26 -0
- package/src/didcomm/mediation/DrizzleDidcommMediationRecordAdapter.ts +51 -0
- package/src/didcomm/mediation/index.ts +10 -0
- package/src/didcomm/mediation/postgres.ts +33 -0
- package/src/didcomm/mediation/sqlite.ts +31 -0
- package/src/didcomm/mediator-routing/DrizzleDidcommMediatorRoutingRecordAdapter.ts +49 -0
- package/src/didcomm/mediator-routing/index.ts +10 -0
- package/src/didcomm/mediator-routing/postgres.ts +14 -0
- package/src/didcomm/mediator-routing/sqlite.ts +17 -0
- package/src/didcomm/out-of-band/DrizzleDidcommOutOfBandRecordAdapter.ts +85 -0
- package/src/didcomm/out-of-band/__tests__/outOfBand.drizzle.e2e.test.ts +88 -0
- package/src/didcomm/out-of-band/index.ts +10 -0
- package/src/didcomm/out-of-band/postgres.ts +46 -0
- package/src/didcomm/out-of-band/sqlite.ts +46 -0
- package/src/didcomm/postgres.ts +8 -0
- package/src/didcomm/proof-exchange/DrizzleDidcommProofExchangeRecordAdapter.ts +51 -0
- package/src/didcomm/proof-exchange/index.ts +10 -0
- package/src/didcomm/proof-exchange/postgres.ts +33 -0
- package/src/didcomm/proof-exchange/sqlite.ts +29 -0
- package/src/didcomm/sqlite.ts +8 -0
- package/src/drpc/bundle.ts +18 -0
- package/src/drpc/drpc/DrizzleDidcommDrpcRecordAdapter.ts +44 -0
- package/src/drpc/drpc/index.ts +10 -0
- package/src/drpc/drpc/postgres.ts +31 -0
- package/src/drpc/drpc/sqlite.ts +29 -0
- package/src/drpc/postgres.ts +1 -0
- package/src/drpc/sqlite.ts +1 -0
- package/src/error/CredoDrizzleColumnDoesNotExistError.ts +21 -0
- package/src/error/CredoDrizzleStorageError.ts +7 -0
- package/src/error/index.ts +2 -0
- package/src/index.ts +29 -0
- package/src/openid4vc/bundle.ts +26 -0
- package/src/openid4vc/openid4vc-issuance-session/DrizzleOpenId4VcIssuanceSessionRecordAdapter.ts +90 -0
- package/src/openid4vc/openid4vc-issuance-session/index.ts +10 -0
- package/src/openid4vc/openid4vc-issuance-session/postgres.ts +54 -0
- package/src/openid4vc/openid4vc-issuance-session/sqlite.ts +54 -0
- package/src/openid4vc/openid4vc-issuer/DrizzleOpenid4vcIssuerRecordAdapter.ts +50 -0
- package/src/openid4vc/openid4vc-issuer/index.ts +10 -0
- package/src/openid4vc/openid4vc-issuer/postgres.ts +31 -0
- package/src/openid4vc/openid4vc-issuer/sqlite.ts +40 -0
- package/src/openid4vc/openid4vc-verification-session/DrizzleOpenId4VcVerificationSessionRecordAdapter.ts +62 -0
- package/src/openid4vc/openid4vc-verification-session/index.ts +10 -0
- package/src/openid4vc/openid4vc-verification-session/postgres.ts +46 -0
- package/src/openid4vc/openid4vc-verification-session/sqlite.ts +40 -0
- package/src/openid4vc/openid4vc-verifier/DrizzleOpenid4vcVerifierRecordAdapter.ts +43 -0
- package/src/openid4vc/openid4vc-verifier/index.ts +10 -0
- package/src/openid4vc/openid4vc-verifier/postgres.ts +14 -0
- package/src/openid4vc/openid4vc-verifier/sqlite.ts +19 -0
- package/src/openid4vc/postgres.ts +4 -0
- package/src/openid4vc/sqlite.ts +4 -0
- package/src/postgres/baseRecord.ts +44 -0
- package/src/postgres/index.ts +1 -0
- package/src/question-answer/bundle.ts +18 -0
- package/src/question-answer/postgres.ts +1 -0
- package/src/question-answer/question-answer/DrizzleDidcommQuestionAnswerRecordAdapter.ts +52 -0
- package/src/question-answer/question-answer/index.ts +10 -0
- package/src/question-answer/question-answer/postgres.ts +34 -0
- package/src/question-answer/question-answer/sqlite.ts +32 -0
- package/src/question-answer/sqlite.ts +1 -0
- package/src/sqlite/baseRecord.ts +38 -0
- package/src/sqlite/index.ts +1 -0
- package/src/storage/DrizzleStorageService.ts +87 -0
- package/src/storage/index.ts +1 -0
- package/src/tenants/bundle.ts +19 -0
- package/src/tenants/postgres.ts +2 -0
- package/src/tenants/sqlite.ts +2 -0
- package/src/tenants/tenant/DrizzleTenantRecordAdapter.ts +45 -0
- package/src/tenants/tenant/index.ts +10 -0
- package/src/tenants/tenant/postgres.ts +16 -0
- package/src/tenants/tenant/sqlite.ts +16 -0
- package/src/tenants/tenant-routing/DrizzleTenantRoutingRecordAdapter.ts +44 -0
- package/src/tenants/tenant-routing/index.ts +10 -0
- package/src/tenants/tenant-routing/postgres.ts +20 -0
- package/src/tenants/tenant-routing/sqlite.ts +20 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { OutOfBandInlineServiceKey, OutOfBandRole, OutOfBandState, PlaintextMessage } from '@credo-ts/didcomm'
|
|
2
|
+
import { boolean, jsonb, pgEnum, pgTable, text } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
4
|
+
|
|
5
|
+
export const didcommOutOfBandRoleEnum = pgEnum('DidcommOutOfBandRole', OutOfBandRole)
|
|
6
|
+
export const didcommOutOfBandStateEnum = pgEnum('DidcommOutOfBandState', OutOfBandState)
|
|
7
|
+
|
|
8
|
+
export const didcommOutOfBand = pgTable(
|
|
9
|
+
'DidcommOutOfBand',
|
|
10
|
+
{
|
|
11
|
+
...getPostgresBaseRecordTable(),
|
|
12
|
+
|
|
13
|
+
outOfBandInvitation: jsonb('out_of_band_invitation').$type<PlaintextMessage>().notNull(),
|
|
14
|
+
role: didcommOutOfBandRoleEnum().notNull(),
|
|
15
|
+
state: didcommOutOfBandStateEnum().notNull(),
|
|
16
|
+
alias: text(),
|
|
17
|
+
reusable: boolean().notNull(),
|
|
18
|
+
autoAcceptConnection: boolean('auto_accept_connection'),
|
|
19
|
+
mediatorId: text('mediator_id'),
|
|
20
|
+
reuseConnectionId: text('reuse_connection_id'),
|
|
21
|
+
invitationInlineServiceKeys: jsonb('invitation_inline_service_keys').$type<OutOfBandInlineServiceKey[]>(),
|
|
22
|
+
|
|
23
|
+
// Tags not on record
|
|
24
|
+
threadId: text('thread_id').notNull(),
|
|
25
|
+
invitationRequestsThreadIds: text('invitation_requests_thread_ids').array(),
|
|
26
|
+
|
|
27
|
+
// Custom tags
|
|
28
|
+
recipientKeyFingerprints: text('recipient_key_fingerprints').array(),
|
|
29
|
+
recipientRoutingKeyFingerprint: text('recipient_routing_key_fingerprint'),
|
|
30
|
+
},
|
|
31
|
+
(table) => [
|
|
32
|
+
...postgresBaseRecordIndexes(table, 'didcommOutOfBand'),
|
|
33
|
+
// foreignKey({
|
|
34
|
+
// columns: [table.reuseConnectionId, table.contextCorrelationId],
|
|
35
|
+
// foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
36
|
+
// }).onDelete('set default'),
|
|
37
|
+
|
|
38
|
+
// Do we want to delete connections when the mediator is removed?
|
|
39
|
+
// Or do we want to restrict it, and first require all connections
|
|
40
|
+
// to be removed?
|
|
41
|
+
// foreignKey({
|
|
42
|
+
// columns: [table.mediatorId, table.contextCorrelationId],
|
|
43
|
+
// foreignColumns: [didcommMediator.id, didcommMediator.contextCorrelationId],
|
|
44
|
+
// }).onDelete('cascade'),
|
|
45
|
+
]
|
|
46
|
+
)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
|
|
3
|
+
import { OutOfBandInlineServiceKey, OutOfBandRole, OutOfBandState, PlaintextMessage } from '@credo-ts/didcomm'
|
|
4
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
5
|
+
|
|
6
|
+
export const didcommOutOfBand = sqliteTable(
|
|
7
|
+
'DidcommOutOfBand',
|
|
8
|
+
{
|
|
9
|
+
...getSqliteBaseRecordTable(),
|
|
10
|
+
|
|
11
|
+
outOfBandInvitation: text('out_of_band_invitation', { mode: 'json' }).$type<PlaintextMessage>().notNull(),
|
|
12
|
+
role: text().$type<OutOfBandRole>().notNull(),
|
|
13
|
+
state: text().$type<OutOfBandState>().notNull(),
|
|
14
|
+
alias: text(),
|
|
15
|
+
reusable: integer({ mode: 'boolean' }).notNull(),
|
|
16
|
+
autoAcceptConnection: integer('auto_accept_connection', { mode: 'boolean' }),
|
|
17
|
+
mediatorId: text('mediator_id'),
|
|
18
|
+
reuseConnectionId: text('reuse_connection_id'),
|
|
19
|
+
invitationInlineServiceKeys: text('invitation_inline_service_keys', { mode: 'json' }).$type<
|
|
20
|
+
OutOfBandInlineServiceKey[]
|
|
21
|
+
>(),
|
|
22
|
+
|
|
23
|
+
// Tags not in record
|
|
24
|
+
threadId: text('thread_id').notNull(),
|
|
25
|
+
invitationRequestsThreadIds: text('invitation_requests_thread_ids', { mode: 'json' }).$type<string[]>(),
|
|
26
|
+
|
|
27
|
+
// Custom tags
|
|
28
|
+
recipientKeyFingerprints: text('recipient_key_fingerprints', { mode: 'json' }).$type<string[]>(),
|
|
29
|
+
recipientRoutingKeyFingerprint: text('recipient_routing_key_fingerprint'),
|
|
30
|
+
},
|
|
31
|
+
(table) => [
|
|
32
|
+
...sqliteBaseRecordIndexes(table, 'didcommOutOfBand'),
|
|
33
|
+
// foreignKey({
|
|
34
|
+
// columns: [table.reuseConnectionId, table.contextCorrelationId],
|
|
35
|
+
// foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
36
|
+
// }).onDelete('set default'),
|
|
37
|
+
|
|
38
|
+
// Do we want to delete connections when the mediator is removed?
|
|
39
|
+
// Or do we want to restrict it, and first require all connections
|
|
40
|
+
// to be removed?
|
|
41
|
+
// foreignKey({
|
|
42
|
+
// columns: [table.mediatorId, table.contextCorrelationId],
|
|
43
|
+
// foreignColumns: [didcommMediator.id, didcommMediator.contextCorrelationId],
|
|
44
|
+
// }).onDelete('cascade'),
|
|
45
|
+
]
|
|
46
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './basic-message/postgres'
|
|
2
|
+
export * from './connection/postgres'
|
|
3
|
+
export * from './credential-exchange/postgres'
|
|
4
|
+
export * from './didcomm-message/postgres'
|
|
5
|
+
export * from './mediation/postgres'
|
|
6
|
+
export * from './mediator-routing/postgres'
|
|
7
|
+
export * from './out-of-band/postgres'
|
|
8
|
+
export * from './proof-exchange/postgres'
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BaseDrizzleRecordAdapter,
|
|
5
|
+
DrizzleAdapterRecordValues,
|
|
6
|
+
DrizzleAdapterValues,
|
|
7
|
+
} from '../../adapter/BaseDrizzleRecordAdapter'
|
|
8
|
+
|
|
9
|
+
import { ProofExchangeRecord } from '@credo-ts/didcomm'
|
|
10
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
11
|
+
import * as postgres from './postgres'
|
|
12
|
+
import * as sqlite from './sqlite'
|
|
13
|
+
|
|
14
|
+
type DrizzleDidcommProofExchangeAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['didcommProofExchange']>
|
|
15
|
+
export class DrizzleDidcommProofExchangeRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
16
|
+
ProofExchangeRecord,
|
|
17
|
+
typeof postgres.didcommProofExchange,
|
|
18
|
+
typeof postgres,
|
|
19
|
+
typeof sqlite.didcommProofExchange,
|
|
20
|
+
typeof sqlite
|
|
21
|
+
> {
|
|
22
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
23
|
+
super(database, { postgres: postgres.didcommProofExchange, sqlite: sqlite.didcommProofExchange }, 'ProofRecord')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public getValues(record: ProofExchangeRecord): DrizzleAdapterValues<(typeof sqlite)['didcommProofExchange']> {
|
|
27
|
+
const { role, connectionId, parentThreadId, threadId, state, ...customTags } = record.getTags()
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
connectionId,
|
|
31
|
+
threadId,
|
|
32
|
+
protocolVersion: record.protocolVersion,
|
|
33
|
+
parentThreadId,
|
|
34
|
+
isVerified: record.isVerified,
|
|
35
|
+
state,
|
|
36
|
+
role,
|
|
37
|
+
autoAcceptProof: record.autoAcceptProof,
|
|
38
|
+
errorMessage: record.errorMessage,
|
|
39
|
+
customTags,
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public toRecord(values: DrizzleDidcommProofExchangeAdapterValues): ProofExchangeRecord {
|
|
44
|
+
const { customTags, ...remainingValues } = values
|
|
45
|
+
|
|
46
|
+
const record = JsonTransformer.fromJSON(remainingValues, ProofExchangeRecord)
|
|
47
|
+
record.setTags(customTags as TagsBase)
|
|
48
|
+
|
|
49
|
+
return record
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleDidcommProofExchangeRecordAdapter } from './DrizzleDidcommProofExchangeRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const didcommProofExchangeDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleDidcommProofExchangeRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AutoAcceptProof, ProofRole, ProofState } from '@credo-ts/didcomm'
|
|
2
|
+
import { boolean, foreignKey, pgEnum, pgTable, text, unique } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
4
|
+
import { didcommConnection } from '../postgres'
|
|
5
|
+
|
|
6
|
+
export const didcommProofExchangeRoleEnum = pgEnum('DidcommProofExchangeRole', ProofRole)
|
|
7
|
+
export const didcommProofExchangeStateEnum = pgEnum('DidcommProofExchangeState', ProofState)
|
|
8
|
+
export const didcommProofExchangeAutoAcceptEnum = pgEnum('DidcommProofExchangeAutoAccept', AutoAcceptProof)
|
|
9
|
+
|
|
10
|
+
export const didcommProofExchange = pgTable(
|
|
11
|
+
'DidcommProofExchange',
|
|
12
|
+
{
|
|
13
|
+
...getPostgresBaseRecordTable(),
|
|
14
|
+
|
|
15
|
+
connectionId: text('connection_id'),
|
|
16
|
+
threadId: text('thread_id').notNull(),
|
|
17
|
+
protocolVersion: text('protocol_version').notNull(),
|
|
18
|
+
parentThreadId: text('parent_thread_id'),
|
|
19
|
+
isVerified: boolean('is_verified'),
|
|
20
|
+
state: didcommProofExchangeRoleEnum().notNull(),
|
|
21
|
+
role: didcommProofExchangeRoleEnum().notNull(),
|
|
22
|
+
autoAcceptProof: didcommProofExchangeAutoAcceptEnum('auto_accept_proof'),
|
|
23
|
+
errorMessage: text('error_message'),
|
|
24
|
+
},
|
|
25
|
+
(table) => [
|
|
26
|
+
...postgresBaseRecordIndexes(table, 'didcommProofExchange'),
|
|
27
|
+
foreignKey({
|
|
28
|
+
columns: [table.connectionId, table.contextCorrelationId],
|
|
29
|
+
foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
30
|
+
}).onDelete('cascade'),
|
|
31
|
+
unique().on(table.contextCorrelationId, table.threadId, table.role),
|
|
32
|
+
]
|
|
33
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { foreignKey, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
|
|
3
|
+
import { AutoAcceptProof, ProofRole, ProofState } from '@credo-ts/didcomm'
|
|
4
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
5
|
+
import { didcommConnection } from '../sqlite'
|
|
6
|
+
|
|
7
|
+
export const didcommProofExchange = sqliteTable(
|
|
8
|
+
'DidcommProofExchange',
|
|
9
|
+
{
|
|
10
|
+
...getSqliteBaseRecordTable(),
|
|
11
|
+
|
|
12
|
+
connectionId: text('connection_id'),
|
|
13
|
+
threadId: text('thread_id').notNull(),
|
|
14
|
+
protocolVersion: text('protocol_version').notNull(),
|
|
15
|
+
parentThreadId: text('parent_thread_id'),
|
|
16
|
+
isVerified: integer('is_verified', { mode: 'boolean' }),
|
|
17
|
+
state: text().$type<ProofState>().notNull(),
|
|
18
|
+
role: text().$type<ProofRole>().notNull(),
|
|
19
|
+
autoAcceptProof: text('auto_accept_proof').$type<AutoAcceptProof>(),
|
|
20
|
+
errorMessage: text('error_message'),
|
|
21
|
+
},
|
|
22
|
+
(table) => [
|
|
23
|
+
...sqliteBaseRecordIndexes(table, 'didcommProofExchange'),
|
|
24
|
+
foreignKey({
|
|
25
|
+
columns: [table.connectionId, table.contextCorrelationId],
|
|
26
|
+
foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
27
|
+
}).onDelete('cascade'),
|
|
28
|
+
]
|
|
29
|
+
)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './basic-message/sqlite'
|
|
2
|
+
export * from './connection/sqlite'
|
|
3
|
+
export * from './credential-exchange/sqlite'
|
|
4
|
+
export * from './didcomm-message/sqlite'
|
|
5
|
+
export * from './mediation/sqlite'
|
|
6
|
+
export * from './mediator-routing/sqlite'
|
|
7
|
+
export * from './out-of-band/sqlite'
|
|
8
|
+
export * from './proof-exchange/sqlite'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DrizzleRecordBundle } from '../DrizzleRecord'
|
|
2
|
+
import { didcommDrpcDrizzleRecord } from './drpc'
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
name: 'drpc',
|
|
6
|
+
records: [didcommDrpcDrizzleRecord],
|
|
7
|
+
|
|
8
|
+
migrations: {
|
|
9
|
+
postgres: {
|
|
10
|
+
schemaModule: '@credo-ts/drizzle-storage/drpc/postgres',
|
|
11
|
+
migrationsPath: '../../migrations/drpc/postgres',
|
|
12
|
+
},
|
|
13
|
+
sqlite: {
|
|
14
|
+
schemaModule: '@credo-ts/drizzle-storage/drpc/sqlite',
|
|
15
|
+
migrationsPath: '../../migrations/drpc/sqlite',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
} as const satisfies DrizzleRecordBundle
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import { BaseDrizzleRecordAdapter, DrizzleAdapterRecordValues } from '../../adapter/BaseDrizzleRecordAdapter'
|
|
4
|
+
|
|
5
|
+
import { DrpcRecord } from '@credo-ts/drpc'
|
|
6
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
7
|
+
import * as postgres from './postgres'
|
|
8
|
+
import * as sqlite from './sqlite'
|
|
9
|
+
|
|
10
|
+
type DrizzleDidcommDrpcAdapterValues = DrizzleAdapterRecordValues<(typeof sqlite)['didcommDrpc']>
|
|
11
|
+
export class DrizzleDidcommDrpcRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
12
|
+
DrpcRecord,
|
|
13
|
+
typeof postgres.didcommDrpc,
|
|
14
|
+
typeof postgres,
|
|
15
|
+
typeof sqlite.didcommDrpc,
|
|
16
|
+
typeof sqlite
|
|
17
|
+
> {
|
|
18
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
19
|
+
super(database, { postgres: postgres.didcommDrpc, sqlite: sqlite.didcommDrpc }, 'DrpcRecord')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public getValues(record: DrpcRecord) {
|
|
23
|
+
const { connectionId, threadId, ...customTags } = record.getTags()
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
threadId,
|
|
27
|
+
connectionId,
|
|
28
|
+
state: record.state,
|
|
29
|
+
role: record.role,
|
|
30
|
+
request: record.request,
|
|
31
|
+
response: record.response,
|
|
32
|
+
customTags,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public toRecord(values: DrizzleDidcommDrpcAdapterValues): DrpcRecord {
|
|
37
|
+
const { customTags, ...remainingValues } = values
|
|
38
|
+
|
|
39
|
+
const record = JsonTransformer.fromJSON(remainingValues, DrpcRecord)
|
|
40
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
41
|
+
|
|
42
|
+
return record
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleDidcommDrpcRecordAdapter } from './DrizzleDidcommDrpcRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const didcommDrpcDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleDidcommDrpcRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DrpcRequest, DrpcResponse, DrpcRole, DrpcState } from '@credo-ts/drpc'
|
|
2
|
+
import { foreignKey, jsonb, pgEnum, pgTable, text, unique } from 'drizzle-orm/pg-core'
|
|
3
|
+
import { didcommConnection } from '../../didcomm/connection/postgres'
|
|
4
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
5
|
+
|
|
6
|
+
export const didcommDrpcStateEnum = pgEnum('DidcommDrpcState', DrpcState)
|
|
7
|
+
export const didcommDrpcRoleEnum = pgEnum('DidcommDrpcRole', DrpcRole)
|
|
8
|
+
|
|
9
|
+
export const didcommDrpc = pgTable(
|
|
10
|
+
'DidcommDrpc',
|
|
11
|
+
{
|
|
12
|
+
...getPostgresBaseRecordTable(),
|
|
13
|
+
|
|
14
|
+
request: jsonb().$type<DrpcRequest>(),
|
|
15
|
+
response: jsonb().$type<DrpcResponse>(),
|
|
16
|
+
|
|
17
|
+
state: didcommDrpcStateEnum().notNull(),
|
|
18
|
+
role: didcommDrpcRoleEnum().notNull(),
|
|
19
|
+
|
|
20
|
+
connectionId: text('connection_id').notNull(),
|
|
21
|
+
threadId: text('thread_id').notNull(),
|
|
22
|
+
},
|
|
23
|
+
(table) => [
|
|
24
|
+
...postgresBaseRecordIndexes(table, 'didcommDrpc'),
|
|
25
|
+
unique().on(table.contextCorrelationId, table.threadId),
|
|
26
|
+
foreignKey({
|
|
27
|
+
columns: [table.connectionId, table.contextCorrelationId],
|
|
28
|
+
foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
29
|
+
}).onDelete('cascade'),
|
|
30
|
+
]
|
|
31
|
+
)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { foreignKey, sqliteTable, text, unique } from 'drizzle-orm/sqlite-core'
|
|
2
|
+
|
|
3
|
+
import { DrpcRequest, DrpcResponse, DrpcRole, DrpcState } from '@credo-ts/drpc'
|
|
4
|
+
import { didcommConnection } from '../../didcomm/connection/sqlite'
|
|
5
|
+
import { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from '../../sqlite/baseRecord'
|
|
6
|
+
|
|
7
|
+
export const didcommDrpc = sqliteTable(
|
|
8
|
+
'DidcommDrpc',
|
|
9
|
+
{
|
|
10
|
+
...getSqliteBaseRecordTable(),
|
|
11
|
+
|
|
12
|
+
request: text({ mode: 'json' }).$type<DrpcRequest>(),
|
|
13
|
+
response: text({ mode: 'json' }).$type<DrpcResponse>(),
|
|
14
|
+
|
|
15
|
+
state: text('state').$type<DrpcState>().notNull(),
|
|
16
|
+
role: text('role').$type<DrpcRole>().notNull(),
|
|
17
|
+
|
|
18
|
+
connectionId: text('connection_id').notNull(),
|
|
19
|
+
threadId: text('thread_id').notNull(),
|
|
20
|
+
},
|
|
21
|
+
(table) => [
|
|
22
|
+
...sqliteBaseRecordIndexes(table, 'didcommDrpc'),
|
|
23
|
+
unique().on(table.contextCorrelationId, table.threadId),
|
|
24
|
+
foreignKey({
|
|
25
|
+
columns: [table.connectionId, table.contextCorrelationId],
|
|
26
|
+
foreignColumns: [didcommConnection.id, didcommConnection.contextCorrelationId],
|
|
27
|
+
}).onDelete('cascade'),
|
|
28
|
+
]
|
|
29
|
+
)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './drpc/postgres'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './drpc/sqlite'
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CredoDrizzleStorageError } from './CredoDrizzleStorageError'
|
|
2
|
+
|
|
3
|
+
export class CredoDrizzleColumnDoesNotExistError extends CredoDrizzleStorageError {
|
|
4
|
+
public databaseType: 'sqlite' | 'postgres'
|
|
5
|
+
public recordType: string
|
|
6
|
+
public column: string
|
|
7
|
+
|
|
8
|
+
public constructor({
|
|
9
|
+
cause,
|
|
10
|
+
databaseType,
|
|
11
|
+
column,
|
|
12
|
+
recordType,
|
|
13
|
+
}: { cause?: Error; databaseType: 'postgres' | 'sqlite'; column: string; recordType: string }) {
|
|
14
|
+
const message = `Column '${column}' does not exist for record '${recordType}' in ${databaseType} database`
|
|
15
|
+
super(message, { cause })
|
|
16
|
+
|
|
17
|
+
this.databaseType = databaseType
|
|
18
|
+
this.column = column
|
|
19
|
+
this.recordType = recordType
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Adapter
|
|
2
|
+
export {
|
|
3
|
+
BaseDrizzleRecordAdapter,
|
|
4
|
+
AnyDrizzleAdapter,
|
|
5
|
+
DrizzleAdapterRecordValues,
|
|
6
|
+
DrizzleAdapterValues,
|
|
7
|
+
} from './adapter'
|
|
8
|
+
|
|
9
|
+
// Storage
|
|
10
|
+
export { DrizzleStorageService } from './storage'
|
|
11
|
+
|
|
12
|
+
// Module
|
|
13
|
+
export { DrizzleStorageModule } from './DrizzleStorageModule'
|
|
14
|
+
export { DrizzleStorageModuleConfig } from './DrizzleStorageModuleConfig'
|
|
15
|
+
|
|
16
|
+
export { DrizzleDatabase } from './DrizzleDatabase'
|
|
17
|
+
|
|
18
|
+
export { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from './postgres'
|
|
19
|
+
export { getSqliteBaseRecordTable, sqliteBaseRecordIndexes } from './sqlite'
|
|
20
|
+
|
|
21
|
+
export type { DrizzleRecord, DrizzleRecordBundle } from './DrizzleRecord'
|
|
22
|
+
|
|
23
|
+
export { GetSchemaFromDrizzleRecords, getSchemaFromDrizzleRecords } from './combineSchemas'
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
ReactNativeDrizzleMigration,
|
|
27
|
+
ReactNativeDrizzleMigrationsOptions,
|
|
28
|
+
applyReactNativeMigrations,
|
|
29
|
+
} from './applyReactNativeMigrations'
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { DrizzleRecordBundle } from '../DrizzleRecord'
|
|
2
|
+
import { openId4VcIssuanceSessionDrizzleRecord } from './openid4vc-issuance-session'
|
|
3
|
+
import { openid4vcIssuerDrizzleRecord } from './openid4vc-issuer'
|
|
4
|
+
import { openId4VcVerificationSessionDrizzleRecord } from './openid4vc-verification-session'
|
|
5
|
+
import { openid4vcVerifierDrizzleRecord } from './openid4vc-verifier'
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
name: 'openid4vc',
|
|
9
|
+
records: [
|
|
10
|
+
openid4vcIssuerDrizzleRecord,
|
|
11
|
+
openId4VcIssuanceSessionDrizzleRecord,
|
|
12
|
+
openid4vcVerifierDrizzleRecord,
|
|
13
|
+
openId4VcVerificationSessionDrizzleRecord,
|
|
14
|
+
],
|
|
15
|
+
|
|
16
|
+
migrations: {
|
|
17
|
+
postgres: {
|
|
18
|
+
schemaModule: '@credo-ts/drizzle-storage/openid4vc/postgres',
|
|
19
|
+
migrationsPath: '../../migrations/openid4vc/postgres',
|
|
20
|
+
},
|
|
21
|
+
sqlite: {
|
|
22
|
+
schemaModule: '@credo-ts/drizzle-storage/openid4vc/sqlite',
|
|
23
|
+
migrationsPath: '../../migrations/openid4vc/sqlite',
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
} as const satisfies DrizzleRecordBundle
|
package/src/openid4vc/openid4vc-issuance-session/DrizzleOpenId4VcIssuanceSessionRecordAdapter.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { JsonTransformer, TagsBase } from '@credo-ts/core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
BaseDrizzleRecordAdapter,
|
|
5
|
+
DrizzleAdapterRecordValues,
|
|
6
|
+
DrizzleAdapterValues,
|
|
7
|
+
} from '../../adapter/BaseDrizzleRecordAdapter'
|
|
8
|
+
|
|
9
|
+
import { OpenId4VcIssuanceSessionRecord } from '@credo-ts/openid4vc'
|
|
10
|
+
import { DrizzleDatabase } from '../../DrizzleDatabase'
|
|
11
|
+
import * as postgres from './postgres'
|
|
12
|
+
import * as sqlite from './sqlite'
|
|
13
|
+
|
|
14
|
+
type DrizzleOpenId4VcIssuanceSessionMenuAdapterValues = DrizzleAdapterRecordValues<
|
|
15
|
+
(typeof sqlite)['openId4VcIssuanceSession']
|
|
16
|
+
>
|
|
17
|
+
export class DrizzleOpenId4VcIssuanceSessionRecordAdapter extends BaseDrizzleRecordAdapter<
|
|
18
|
+
OpenId4VcIssuanceSessionRecord,
|
|
19
|
+
typeof postgres.openId4VcIssuanceSession,
|
|
20
|
+
typeof postgres,
|
|
21
|
+
typeof sqlite.openId4VcIssuanceSession,
|
|
22
|
+
typeof sqlite
|
|
23
|
+
> {
|
|
24
|
+
public constructor(database: DrizzleDatabase<typeof postgres, typeof sqlite>) {
|
|
25
|
+
super(
|
|
26
|
+
database,
|
|
27
|
+
{ postgres: postgres.openId4VcIssuanceSession, sqlite: sqlite.openId4VcIssuanceSession },
|
|
28
|
+
'OpenId4VcIssuanceSessionRecord'
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public tagKeyMapping = {
|
|
33
|
+
issuerState: ['authorization', 'issuerState'],
|
|
34
|
+
authorizationCode: ['authorization', 'code'],
|
|
35
|
+
authorizationSubject: ['authorization', 'subject'],
|
|
36
|
+
presentationAuthSession: ['presentation', 'authSession'],
|
|
37
|
+
} as const
|
|
38
|
+
|
|
39
|
+
public getValues(
|
|
40
|
+
record: OpenId4VcIssuanceSessionRecord
|
|
41
|
+
): DrizzleAdapterValues<(typeof sqlite)['openId4VcIssuanceSession']> {
|
|
42
|
+
const {
|
|
43
|
+
authorizationCode,
|
|
44
|
+
authorizationSubject,
|
|
45
|
+
credentialOfferId,
|
|
46
|
+
credentialOfferUri,
|
|
47
|
+
issuerId,
|
|
48
|
+
issuerState,
|
|
49
|
+
preAuthorizedCode,
|
|
50
|
+
presentationAuthSession,
|
|
51
|
+
state,
|
|
52
|
+
...customTags
|
|
53
|
+
} = record.getTags()
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
credentialOfferId,
|
|
57
|
+
credentialOfferUri,
|
|
58
|
+
issuerId,
|
|
59
|
+
preAuthorizedCode,
|
|
60
|
+
state,
|
|
61
|
+
|
|
62
|
+
credentialOfferPayload: record.credentialOfferPayload,
|
|
63
|
+
authorization: record.authorization
|
|
64
|
+
? {
|
|
65
|
+
...record.authorization,
|
|
66
|
+
codeExpiresAt: record.authorization.codeExpiresAt?.toISOString(),
|
|
67
|
+
}
|
|
68
|
+
: undefined,
|
|
69
|
+
clientId: record.clientId,
|
|
70
|
+
dpop: record.dpop,
|
|
71
|
+
errorMessage: record.errorMessage,
|
|
72
|
+
issuanceMetadata: record.issuanceMetadata,
|
|
73
|
+
issuedCredentials: record.issuedCredentials,
|
|
74
|
+
pkce: record.pkce,
|
|
75
|
+
presentation: record.presentation,
|
|
76
|
+
userPin: record.userPin,
|
|
77
|
+
walletAttestation: record.walletAttestation,
|
|
78
|
+
customTags,
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public toRecord(values: DrizzleOpenId4VcIssuanceSessionMenuAdapterValues): OpenId4VcIssuanceSessionRecord {
|
|
83
|
+
const { customTags, ...remainingValues } = values
|
|
84
|
+
|
|
85
|
+
const record = JsonTransformer.fromJSON(remainingValues, OpenId4VcIssuanceSessionRecord)
|
|
86
|
+
if (customTags) record.setTags(customTags as TagsBase)
|
|
87
|
+
|
|
88
|
+
return record
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DrizzleRecord } from '../../DrizzleRecord'
|
|
2
|
+
import { DrizzleOpenId4VcIssuanceSessionRecordAdapter } from './DrizzleOpenId4VcIssuanceSessionRecordAdapter'
|
|
3
|
+
import * as postgres from './postgres'
|
|
4
|
+
import * as sqlite from './sqlite'
|
|
5
|
+
|
|
6
|
+
export const openId4VcIssuanceSessionDrizzleRecord = {
|
|
7
|
+
adapter: DrizzleOpenId4VcIssuanceSessionRecordAdapter,
|
|
8
|
+
postgres,
|
|
9
|
+
sqlite,
|
|
10
|
+
} satisfies DrizzleRecord
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenId4VcIssuanceSessionAuthorization,
|
|
3
|
+
OpenId4VcIssuanceSessionDpop,
|
|
4
|
+
OpenId4VcIssuanceSessionPkce,
|
|
5
|
+
OpenId4VcIssuanceSessionPresentation,
|
|
6
|
+
OpenId4VcIssuanceSessionState,
|
|
7
|
+
OpenId4VcIssuanceSessionWalletAttestation,
|
|
8
|
+
OpenId4VciCredentialOfferPayload,
|
|
9
|
+
} from '@credo-ts/openid4vc'
|
|
10
|
+
import { jsonb, pgEnum, pgTable, text } from 'drizzle-orm/pg-core'
|
|
11
|
+
import { getPostgresBaseRecordTable, postgresBaseRecordIndexes } from '../../postgres/baseRecord'
|
|
12
|
+
import { openid4vcIssuer } from '../postgres'
|
|
13
|
+
|
|
14
|
+
export const openId4VcIssuanceSessionStateEnum = pgEnum('OpenId4VcIssuanceSessionState', OpenId4VcIssuanceSessionState)
|
|
15
|
+
|
|
16
|
+
export const openId4VcIssuanceSession = pgTable(
|
|
17
|
+
'OpenId4VcIssuanceSession',
|
|
18
|
+
{
|
|
19
|
+
...getPostgresBaseRecordTable(),
|
|
20
|
+
|
|
21
|
+
issuerId: text('issuer_id')
|
|
22
|
+
.notNull()
|
|
23
|
+
.references(() => openid4vcIssuer.issuerId, { onDelete: 'cascade' }),
|
|
24
|
+
|
|
25
|
+
state: openId4VcIssuanceSessionStateEnum().notNull(),
|
|
26
|
+
issuedCredentials: text('issued_credentials').array(),
|
|
27
|
+
|
|
28
|
+
// Pre-authorized flow
|
|
29
|
+
preAuthorizedCode: text('pre_authorized_code'),
|
|
30
|
+
userPin: text('user_pin'),
|
|
31
|
+
|
|
32
|
+
// Client and authentication
|
|
33
|
+
clientId: text('client_id'),
|
|
34
|
+
|
|
35
|
+
pkce: jsonb().$type<OpenId4VcIssuanceSessionPkce>(),
|
|
36
|
+
walletAttestation: jsonb('wallet_attestation').$type<OpenId4VcIssuanceSessionWalletAttestation>(),
|
|
37
|
+
dpop: jsonb().$type<OpenId4VcIssuanceSessionDpop>(),
|
|
38
|
+
authorization: jsonb().$type<
|
|
39
|
+
Omit<OpenId4VcIssuanceSessionAuthorization, 'codeExpiresAt'> & { codeExpiresAt?: string }
|
|
40
|
+
>(),
|
|
41
|
+
presentation: jsonb().$type<OpenId4VcIssuanceSessionPresentation>(),
|
|
42
|
+
|
|
43
|
+
// Metadata and error handling
|
|
44
|
+
issuanceMetadata: jsonb('issuance_metadata').$type<Record<string, unknown>>(),
|
|
45
|
+
|
|
46
|
+
// Credential offer
|
|
47
|
+
credentialOfferUri: text('credential_offer_uri'),
|
|
48
|
+
credentialOfferId: text('credential_offer_id'),
|
|
49
|
+
credentialOfferPayload: jsonb('credential_offer_payload').$type<OpenId4VciCredentialOfferPayload>().notNull(),
|
|
50
|
+
|
|
51
|
+
errorMessage: text('error_message'),
|
|
52
|
+
},
|
|
53
|
+
(table) => postgresBaseRecordIndexes(table, 'openId4VcIssuanceSession')
|
|
54
|
+
)
|