@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.32.1-next.54 → 0.33.1-feature.jose.vcdm.55

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.
Files changed (86) hide show
  1. package/dist/index.cjs +2451 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +559 -0
  4. package/dist/index.d.ts +555 -8
  5. package/dist/index.js +2420 -31
  6. package/dist/index.js.map +1 -1
  7. package/package.json +44 -30
  8. package/src/agent/DidAuthSiopOpAuthenticator.ts +132 -53
  9. package/src/services/Siopv2MachineService.ts +130 -20
  10. package/src/session/OID4VP.ts +8 -8
  11. package/src/session/OpSession.ts +18 -17
  12. package/src/types/IDidAuthSiopOpAuthenticator.ts +20 -7
  13. package/src/types/siop-service/index.ts +9 -6
  14. package/src/utils/CredentialUtils.ts +71 -0
  15. package/src/utils/dcql.ts +36 -0
  16. package/dist/agent/DidAuthSiopOpAuthenticator.d.ts +0 -31
  17. package/dist/agent/DidAuthSiopOpAuthenticator.d.ts.map +0 -1
  18. package/dist/agent/DidAuthSiopOpAuthenticator.js +0 -323
  19. package/dist/agent/DidAuthSiopOpAuthenticator.js.map +0 -1
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/link-handler/index.d.ts +0 -22
  22. package/dist/link-handler/index.d.ts.map +0 -1
  23. package/dist/link-handler/index.js +0 -57
  24. package/dist/link-handler/index.js.map +0 -1
  25. package/dist/localization/Localization.d.ts +0 -9
  26. package/dist/localization/Localization.d.ts.map +0 -1
  27. package/dist/localization/Localization.js +0 -46
  28. package/dist/localization/Localization.js.map +0 -1
  29. package/dist/localization/translations/en.json +0 -9
  30. package/dist/localization/translations/nl.json +0 -8
  31. package/dist/machine/CallbackStateListener.d.ts +0 -3
  32. package/dist/machine/CallbackStateListener.d.ts.map +0 -1
  33. package/dist/machine/CallbackStateListener.js +0 -48
  34. package/dist/machine/CallbackStateListener.js.map +0 -1
  35. package/dist/machine/Siopv2Machine.d.ts +0 -8
  36. package/dist/machine/Siopv2Machine.d.ts.map +0 -1
  37. package/dist/machine/Siopv2Machine.js +0 -364
  38. package/dist/machine/Siopv2Machine.js.map +0 -1
  39. package/dist/services/IdentifierService.d.ts +0 -3
  40. package/dist/services/IdentifierService.d.ts.map +0 -1
  41. package/dist/services/IdentifierService.js +0 -28
  42. package/dist/services/IdentifierService.js.map +0 -1
  43. package/dist/services/Siopv2MachineService.d.ts +0 -16
  44. package/dist/services/Siopv2MachineService.d.ts.map +0 -1
  45. package/dist/services/Siopv2MachineService.js +0 -201
  46. package/dist/services/Siopv2MachineService.js.map +0 -1
  47. package/dist/session/OID4VP.d.ts +0 -72
  48. package/dist/session/OID4VP.d.ts.map +0 -1
  49. package/dist/session/OID4VP.js +0 -223
  50. package/dist/session/OID4VP.js.map +0 -1
  51. package/dist/session/OpSession.d.ts +0 -39
  52. package/dist/session/OpSession.d.ts.map +0 -1
  53. package/dist/session/OpSession.js +0 -365
  54. package/dist/session/OpSession.js.map +0 -1
  55. package/dist/session/functions.d.ts +0 -37
  56. package/dist/session/functions.d.ts.map +0 -1
  57. package/dist/session/functions.js +0 -163
  58. package/dist/session/functions.js.map +0 -1
  59. package/dist/session/index.d.ts +0 -4
  60. package/dist/session/index.d.ts.map +0 -1
  61. package/dist/session/index.js +0 -20
  62. package/dist/session/index.js.map +0 -1
  63. package/dist/types/IDidAuthSiopOpAuthenticator.d.ts +0 -116
  64. package/dist/types/IDidAuthSiopOpAuthenticator.d.ts.map +0 -1
  65. package/dist/types/IDidAuthSiopOpAuthenticator.js +0 -10
  66. package/dist/types/IDidAuthSiopOpAuthenticator.js.map +0 -1
  67. package/dist/types/error/index.d.ts +0 -8
  68. package/dist/types/error/index.d.ts.map +0 -1
  69. package/dist/types/error/index.js +0 -3
  70. package/dist/types/error/index.js.map +0 -1
  71. package/dist/types/identifier/index.d.ts +0 -53
  72. package/dist/types/identifier/index.d.ts.map +0 -1
  73. package/dist/types/identifier/index.js +0 -5
  74. package/dist/types/identifier/index.js.map +0 -1
  75. package/dist/types/index.d.ts +0 -6
  76. package/dist/types/index.d.ts.map +0 -1
  77. package/dist/types/index.js +0 -22
  78. package/dist/types/index.js.map +0 -1
  79. package/dist/types/machine/index.d.ts +0 -124
  80. package/dist/types/machine/index.d.ts.map +0 -1
  81. package/dist/types/machine/index.js +0 -57
  82. package/dist/types/machine/index.js.map +0 -1
  83. package/dist/types/siop-service/index.d.ts +0 -78
  84. package/dist/types/siop-service/index.d.ts.map +0 -1
  85. package/dist/types/siop-service/index.js +0 -14
  86. package/dist/types/siop-service/index.js.map +0 -1
@@ -20,21 +20,21 @@ import { encodeBase64url } from '@sphereon/ssi-sdk.core'
20
20
  import {
21
21
  CompactSdJwtVc,
22
22
  CredentialMapper,
23
- Hasher,
23
+ HasherSync,
24
24
  OriginalVerifiableCredential,
25
25
  parseDid,
26
26
  PresentationSubmission,
27
27
  W3CVerifiablePresentation,
28
28
  } from '@sphereon/ssi-types'
29
29
  import { IIdentifier, IVerifyResult, TKeyType } from '@veramo/core'
30
- import Debug from 'debug'
31
30
  import { v4 } from 'uuid'
32
31
  import { IOPOptions, IOpSessionArgs, IOpSessionGetOID4VPArgs, IOpsSendSiopAuthorizationResponseArgs, IRequiredContext } from '../types'
33
32
  import { createOP } from './functions'
34
33
  import { OID4VP } from './OID4VP'
35
34
  import { PEX } from '@sphereon/pex'
35
+ import { Loggers } from '@sphereon/ssi-types'
36
36
 
37
- const debug = Debug(`sphereon:sdk:siop:op-session`)
37
+ const logger = Loggers.DEFAULT.get('sphereon:oid4vp:OpSession')
38
38
 
39
39
  export class OpSession {
40
40
  public readonly ts = new Date().getDate()
@@ -100,9 +100,9 @@ export class OpSession {
100
100
  public async getSupportedDIDMethods(didPrefix?: boolean): Promise<string[]> {
101
101
  const agentMethods = this.getAgentDIDMethodsSupported({ didPrefix })
102
102
  let rpMethods = await this.getRPDIDMethodsSupported({ didPrefix, agentMethods })
103
- debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`)
103
+ logger.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`)
104
104
  if (rpMethods.dids.length === 0) {
105
- debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`)
105
+ logger.debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`)
106
106
  return []
107
107
  }
108
108
 
@@ -125,7 +125,7 @@ export class OpSession {
125
125
 
126
126
  private getAgentDIDMethodsSupported(opts: { didPrefix?: boolean }) {
127
127
  const agentMethods = this.options.supportedDIDMethods?.map((method) => convertDidMethod(method, opts.didPrefix))
128
- debug(`agent methods: ${JSON.stringify(agentMethods)}`)
128
+ logger.debug(`agent methods: ${JSON.stringify(agentMethods)}`)
129
129
  return agentMethods
130
130
  }
131
131
 
@@ -139,17 +139,17 @@ export class OpSession {
139
139
  let keyType: TKeyType | undefined
140
140
  const agentMethods =
141
141
  (opts.agentMethods ?? this.getAgentDIDMethodsSupported(opts))?.map((method) => convertDidMethod(method, opts.didPrefix)) ?? []
142
- debug(`agent methods supported: ${JSON.stringify(agentMethods)}`)
142
+ logger.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`)
143
143
  const authReq = await this.getAuthorizationRequest()
144
144
  const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported
145
145
  ?.map((method) => convertDidMethod(method, opts.didPrefix))
146
146
  .filter((val) => !val.startsWith('did'))
147
- debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`)
147
+ logger.debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`)
148
148
  const aud = await authReq.authorizationRequest.getMergedProperty<string>('aud')
149
149
  let rpMethods: string[] = []
150
150
  if (aud && aud.startsWith('did:')) {
151
151
  const didMethod = convertDidMethod(parseDid(aud).method, opts.didPrefix)
152
- debug(`aud did method: ${didMethod}`)
152
+ logger.debug(`aud did method: ${didMethod}`)
153
153
 
154
154
  // The RP knows our DID, so we can use it to determine the supported DID methods
155
155
  // If the aud did:method is not in the supported types, there still is something wrong, unless the RP signals to support all did methods
@@ -172,7 +172,7 @@ export class OpSession {
172
172
  (authReq.issuer?.includes('.ebsi.eu') || (await authReq.authorizationRequest.getMergedProperty<string>('client_id'))?.includes('.ebsi.eu'))
173
173
  let codecName: string | undefined = undefined
174
174
  if (isEBSI && (!aud || !aud.startsWith('http'))) {
175
- debug(`EBSI detected, adding did:key to supported DID methods for RP`)
175
+ logger.debug(`EBSI detected, adding did:key to supported DID methods for RP`)
176
176
  const didKeyMethod = convertDidMethod('did:key', opts.didPrefix)
177
177
  if (!agentMethods?.includes(didKeyMethod)) {
178
178
  throw Error(`EBSI detected, but agent did not support did:key. Please reconfigure agent`)
@@ -187,7 +187,7 @@ export class OpSession {
187
187
  public async getSupportedIdentifiers(opts?: { createInCaseNoDIDFound?: boolean }): Promise<IIdentifier[]> {
188
188
  // todo: we also need to check signature algo
189
189
  const methods = await this.getSupportedDIDMethods(true)
190
- debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`)
190
+ logger.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`)
191
191
  if (methods.length === 0) {
192
192
  throw Error(`No DID methods are supported`)
193
193
  }
@@ -195,7 +195,7 @@ export class OpSession {
195
195
  .didManagerFind()
196
196
  .then((ids: IIdentifier[]) => ids.filter((id) => methods.includes(id.provider)))
197
197
  if (identifiers.length === 0) {
198
- debug(`No identifiers available in agent supporting methods ${JSON.stringify(methods)}`)
198
+ logger.debug(`No identifiers available in agent supporting methods ${JSON.stringify(methods)}`)
199
199
  if (opts?.createInCaseNoDIDFound !== false) {
200
200
  const { codecName, keyType } = await this.getRPDIDMethodsSupported({
201
201
  didPrefix: true,
@@ -205,11 +205,11 @@ export class OpSession {
205
205
  provider: methods[0],
206
206
  options: { codecName, keyType, type: keyType }, // both keyType and type, because not every did provider has the same param
207
207
  })
208
- debug(`Created a new identifier for the SIOP interaction: ${identifier.did}`)
208
+ logger.debug(`Created a new identifier for the SIOP interaction: ${identifier.did}`)
209
209
  identifiers.push(identifier)
210
210
  }
211
211
  }
212
- debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`)
212
+ logger.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`)
213
213
  return identifiers
214
214
  }
215
215
 
@@ -293,8 +293,8 @@ export class OpSession {
293
293
  .jwtEncryptJweCompactJwt({
294
294
  recipientKey,
295
295
  protectedHeader: {},
296
- alg: requestObjectPayload.client_metadata.authorization_encrypted_response_alg as JweAlg | undefined ?? 'ECDH-ES',
297
- enc: requestObjectPayload.client_metadata.authorization_encrypted_response_enc as JweEnc | undefined ?? 'A256GCM',
296
+ alg: (requestObjectPayload.client_metadata.authorization_encrypted_response_alg as JweAlg | undefined) ?? 'ECDH-ES',
297
+ enc: (requestObjectPayload.client_metadata.authorization_encrypted_response_enc as JweEnc | undefined) ?? 'A256GCM',
298
298
  apv: encodeBase64url(opts.requestObjectPayload.nonce),
299
299
  apu: encodeBase64url(v4()),
300
300
  payload: authResponse,
@@ -367,6 +367,7 @@ export class OpSession {
367
367
  presentationSubmission: args.presentationSubmission,
368
368
  } as PresentationExchangeResponseOpts,
369
369
  }),
370
+ dcqlQuery: args.dcqlResponse,
370
371
  }
371
372
 
372
373
  const authResponse = await op.createAuthorizationResponse(request, responseOpts)
@@ -379,7 +380,7 @@ export class OpSession {
379
380
  }
380
381
  }
381
382
 
382
- private countVCsInAllVPs(verifiablePresentations: W3CVerifiablePresentation[], hasher?: Hasher) {
383
+ private countVCsInAllVPs(verifiablePresentations: W3CVerifiablePresentation[], hasher?: HasherSync) {
383
384
  return verifiablePresentations.reduce((sum, vp) => {
384
385
  if (CredentialMapper.isMsoMdocDecodedPresentation(vp) || CredentialMapper.isMsoMdocOid4VPEncoded(vp)) {
385
386
  return sum + 1
@@ -1,4 +1,5 @@
1
1
  import {
2
+ DcqlResponseOpts,
2
3
  PresentationDefinitionWithLocation,
3
4
  PresentationSignCallback,
4
5
  ResponseMode,
@@ -18,7 +19,7 @@ import { ICredentialStore, UniqueDigitalCredential } from '@sphereon/ssi-sdk.cre
18
19
  import { Party } from '@sphereon/ssi-sdk.data-store'
19
20
  import { IPDManager } from '@sphereon/ssi-sdk.pd-manager'
20
21
  import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt'
21
- import { Hasher, OriginalVerifiableCredential, PresentationSubmission, W3CVerifiablePresentation } from '@sphereon/ssi-types'
22
+ import { HasherSync, OriginalVerifiableCredential, PresentationSubmission, W3CVerifiablePresentation } from '@sphereon/ssi-types'
22
23
  import { VerifyCallback } from '@sphereon/wellknown-dids-client'
23
24
  import {
24
25
  IAgentContext,
@@ -122,7 +123,8 @@ export interface IOpsSendSiopAuthorizationResponseArgs {
122
123
  // verifiedAuthorizationRequest: VerifiedAuthorizationRequest
123
124
  presentationSubmission?: PresentationSubmission
124
125
  verifiablePresentations?: W3CVerifiablePresentation[]
125
- hasher?: Hasher
126
+ dcqlResponse?: DcqlResponseOpts
127
+ hasher?: HasherSync
126
128
  isFirstParty?: boolean
127
129
  }
128
130
 
@@ -160,7 +162,7 @@ export interface IOPOptions {
160
162
  presentationSignCallback?: PresentationSignCallback
161
163
 
162
164
  resolveOpts?: ResolveOpts
163
- hasher?: Hasher
165
+ hasher?: HasherSync
164
166
  }
165
167
 
166
168
  /*
@@ -183,19 +185,30 @@ export interface VerifiablePresentationWithDefinition extends VerifiablePresenta
183
185
 
184
186
  export interface IOpSessionGetOID4VPArgs {
185
187
  allIdentifiers?: string[]
186
- hasher?: Hasher
188
+ hasher?: HasherSync
187
189
  }
188
190
 
189
191
  export interface IOID4VPArgs {
190
192
  session: OpSession
191
193
  allIdentifiers?: string[]
192
- hasher?: Hasher
194
+ hasher?: HasherSync
193
195
  }
194
196
 
195
197
  export interface IGetPresentationExchangeArgs {
196
198
  verifiableCredentials: OriginalVerifiableCredential[]
197
199
  allIdentifiers?: string[]
198
- hasher?: Hasher
199
- }
200
+ hasher?: HasherSync
201
+ }
202
+
203
+ // It was added here because it's not exported from DCQL anymore
204
+ export type Json =
205
+ | string
206
+ | number
207
+ | boolean
208
+ | null
209
+ | {
210
+ [key: string]: Json
211
+ }
212
+ | Json[]
200
213
 
201
214
  export const DEFAULT_JWT_PROOF_TYPE = 'JwtProof2020'
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  PresentationDefinitionWithLocation,
3
3
  PresentationSignCallback,
4
- RPRegistrationMetadataPayload, VerifiedAuthorizationRequest
4
+ RPRegistrationMetadataPayload,
5
+ VerifiedAuthorizationRequest,
5
6
  } from '@sphereon/did-auth-siop'
6
7
  import { IIdentifierResolution, ManagedIdentifierOptsOrResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
7
8
  import { IContactManager } from '@sphereon/ssi-sdk.contact-manager'
@@ -11,14 +12,15 @@ import { IIssuanceBranding } from '@sphereon/ssi-sdk.issuance-branding'
11
12
  import { IAgentContext, IDIDManager, IIdentifier, IResolver } from '@veramo/core'
12
13
  import { IDidAuthSiopOpAuthenticator } from '../IDidAuthSiopOpAuthenticator'
13
14
  import { Siopv2MachineContext, Siopv2MachineInterpreter, Siopv2MachineState } from '../machine'
14
- import { Hasher } from '@sphereon/ssi-types'
15
+ import { DcqlQuery } from 'dcql'
16
+ import { HasherSync } from '@sphereon/ssi-types'
15
17
 
16
18
  export type DidAuthSiopOpAuthenticatorOptions = {
17
19
  presentationSignCallback?: PresentationSignCallback
18
20
  customApprovals?: Record<string, (verifiedAuthorizationRequest: VerifiedAuthorizationRequest, sessionId: string) => Promise<void>>
19
21
  onContactIdentityCreated?: (args: OnContactIdentityCreatedArgs) => Promise<void>
20
22
  onIdentifierCreated?: (args: OnIdentifierCreatedArgs) => Promise<void>
21
- hasher?: Hasher
23
+ hasher?: HasherSync
22
24
  }
23
25
 
24
26
  export type GetMachineArgs = {
@@ -29,14 +31,14 @@ export type GetMachineArgs = {
29
31
 
30
32
  export type CreateConfigArgs = { url: string }
31
33
  export type CreateConfigResult = Omit<DidAuthConfig, 'stateId' | 'idOpts'>
32
- export type GetSiopRequestArgs = { didAuthConfig?: Omit<DidAuthConfig, 'identifier'>, url: string }
34
+ export type GetSiopRequestArgs = { didAuthConfig?: Omit<DidAuthConfig, 'identifier'>; url: string }
33
35
  // FIXME it would be nicer if these function are not tied to a certain machine so that we can start calling them for anywhere
34
36
  export type RetrieveContactArgs = Pick<Siopv2MachineContext, 'url' | 'authorizationRequestData'>
35
37
  // FIXME it would be nicer if these function are not tied to a certain machine so that we can start calling them for anywhere
36
38
  export type AddIdentityArgs = Pick<Siopv2MachineContext, 'contact' | 'authorizationRequestData'>
37
39
  export type SendResponseArgs = {
38
- didAuthConfig?: Omit<DidAuthConfig, 'identifier'>,
39
- authorizationRequestData?: Siopv2AuthorizationRequestData,
40
+ didAuthConfig?: Omit<DidAuthConfig, 'identifier'>
41
+ authorizationRequestData?: Siopv2AuthorizationRequestData
40
42
  selectedCredentials: Array<UniqueDigitalCredential>
41
43
  idOpts?: ManagedIdentifierOptsOrResult
42
44
  isFirstParty?: boolean
@@ -68,6 +70,7 @@ export type Siopv2AuthorizationRequestData = {
68
70
  uri?: URL
69
71
  clientId?: string
70
72
  presentationDefinitions?: PresentationDefinitionWithLocation[]
73
+ dcqlQuery?: DcqlQuery
71
74
  }
72
75
 
73
76
  export type SelectableCredentialsMap = Map<string, Array<SelectableCredential>>
@@ -0,0 +1,71 @@
1
+ import { CredentialMapper, HasherSync, ICredential, IVerifiableCredential, OriginalVerifiableCredential } from '@sphereon/ssi-types'
2
+ import { VerifiableCredential } from '@veramo/core'
3
+ import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
4
+
5
+ /**
6
+ * Return the type(s) of a VC minus the VerifiableCredential type which should always be present
7
+ * @param credential The input credential
8
+ */
9
+ export const getCredentialTypeAsString = (credential: ICredential | VerifiableCredential): string => {
10
+ if (!credential.type) {
11
+ return 'Verifiable Credential'
12
+ } else if (typeof credential.type === 'string') {
13
+ return credential.type
14
+ }
15
+ return credential.type.filter((type: string): boolean => type !== 'VerifiableCredential').join(', ')
16
+ }
17
+
18
+ /**
19
+ * Returns a Unique Verifiable Credential (with hash) as stored in Veramo, based upon matching the id of the input VC or the proof value of the input VC
20
+ * @param uniqueVCs The Unique VCs to search in
21
+ * @param searchVC The VC to search for in the unique VCs array
22
+ */
23
+ export const getMatchingUniqueDigitalCredential = (
24
+ uniqueVCs: UniqueDigitalCredential[],
25
+ searchVC: OriginalVerifiableCredential,
26
+ ): UniqueDigitalCredential | undefined => {
27
+ // Since an ID is optional in a VC according to VCDM, and we really need the matches, we have a fallback match on something which is guaranteed to be unique for any VC (the proof(s))
28
+ return uniqueVCs.find(
29
+ (uniqueVC: UniqueDigitalCredential) =>
30
+ (typeof searchVC !== 'string' &&
31
+ (uniqueVC.id === (<IVerifiableCredential>searchVC).id ||
32
+ (uniqueVC.originalVerifiableCredential as VerifiableCredential).proof === (<IVerifiableCredential>searchVC).proof)) ||
33
+ (typeof searchVC === 'string' && (uniqueVC.uniformVerifiableCredential as VerifiableCredential)?.proof?.jwt === searchVC) ||
34
+ // We are ignoring the signature of the sd-jwt as PEX signs the vc again and it will not match anymore with the jwt in the proof of the stored jsonld vc
35
+ (typeof searchVC === 'string' &&
36
+ CredentialMapper.isSdJwtEncoded(searchVC) &&
37
+ uniqueVC.uniformVerifiableCredential?.proof &&
38
+ 'jwt' in uniqueVC.uniformVerifiableCredential.proof &&
39
+ uniqueVC.uniformVerifiableCredential.proof.jwt?.split('.')?.slice(0, 2)?.join('.') === searchVC.split('.')?.slice(0, 2)?.join('.')),
40
+ )
41
+ }
42
+
43
+ type InputCredential = UniqueDigitalCredential | VerifiableCredential | ICredential | OriginalVerifiableCredential
44
+
45
+ /**
46
+ * Get an original verifiable credential. Maps to wrapped Verifiable Credential first, to get an original JWT as Veramo stores these with a special proof value
47
+ * @param credential The input VC
48
+ */
49
+
50
+ export const getOriginalVerifiableCredential = (credential: InputCredential): OriginalVerifiableCredential => {
51
+ if (isUniqueDigitalCredential(credential)) {
52
+ if (!credential.originalVerifiableCredential) {
53
+ throw new Error('originalVerifiableCredential is not defined in UniqueDigitalCredential')
54
+ }
55
+ return getCredentialFromProofOrWrapped(credential.originalVerifiableCredential)
56
+ }
57
+
58
+ return getCredentialFromProofOrWrapped(credential)
59
+ }
60
+
61
+ const getCredentialFromProofOrWrapped = (cred: any, hasher?: HasherSync): OriginalVerifiableCredential => {
62
+ if (typeof cred === 'object' && 'proof' in cred && 'jwt' in cred.proof && CredentialMapper.isSdJwtEncoded(cred.proof.jwt)) {
63
+ return cred.proof.jwt
64
+ }
65
+
66
+ return CredentialMapper.toWrappedVerifiableCredential(cred as OriginalVerifiableCredential, { hasher }).original
67
+ }
68
+
69
+ export const isUniqueDigitalCredential = (credential: InputCredential): credential is UniqueDigitalCredential => {
70
+ return (credential as UniqueDigitalCredential).digitalCredential !== undefined
71
+ }
@@ -0,0 +1,36 @@
1
+ import { UniqueDigitalCredential } from '@sphereon/ssi-sdk.credential-store'
2
+ import { DcqlCredential, DcqlSdJwtVcCredential, DcqlW3cVcCredential } from 'dcql'
3
+ import { CredentialMapper, HasherSync, OriginalVerifiableCredential } from '@sphereon/ssi-types'
4
+ import { isUniqueDigitalCredential } from './CredentialUtils'
5
+
6
+ export function convertToDcqlCredentials(credential: UniqueDigitalCredential | OriginalVerifiableCredential, hasher?: HasherSync): DcqlCredential {
7
+ let payload
8
+ if (isUniqueDigitalCredential(credential)) {
9
+ if (!credential.originalVerifiableCredential) {
10
+ throw new Error('originalVerifiableCredential is not defined in UniqueDigitalCredential')
11
+ }
12
+ payload = CredentialMapper.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher)
13
+ } else {
14
+ payload = CredentialMapper.decodeVerifiableCredential(credential as OriginalVerifiableCredential, hasher)
15
+ }
16
+
17
+ if (!payload) {
18
+ throw new Error('No payload found')
19
+ }
20
+
21
+ if ('decodedPayload' in payload && payload.decodedPayload) {
22
+ payload = payload.decodedPayload
23
+ }
24
+
25
+ if ('vct' in payload!) {
26
+ return { vct: payload.vct, claims: payload, credential_format: 'vc+sd-jwt' } satisfies DcqlSdJwtVcCredential // TODO dc+sd-jwt support?
27
+ } else if ('docType' in payload! && 'namespaces' in payload) {
28
+ // mdoc
29
+ return { docType: payload.docType, namespaces: payload.namespaces, claims: payload }
30
+ } else {
31
+ return {
32
+ claims: payload,
33
+ credential_format: 'jwt_vc_json', // TODO jwt_vc_json-ld support
34
+ } as DcqlW3cVcCredential
35
+ }
36
+ }
@@ -1,31 +0,0 @@
1
- import { IAgentPlugin } from '@veramo/core';
2
- import { DidAuthSiopOpAuthenticatorOptions, RequiredContext } from '../index';
3
- import { IDidAuthSiopOpAuthenticator } from '../types';
4
- export declare const didAuthSiopOpAuthenticatorMethods: Array<string>;
5
- export declare class DidAuthSiopOpAuthenticator implements IAgentPlugin {
6
- readonly schema: any;
7
- readonly methods: IDidAuthSiopOpAuthenticator;
8
- private readonly hasher?;
9
- private readonly sessions;
10
- private readonly customApprovals;
11
- private readonly presentationSignCallback?;
12
- private readonly onContactIdentityCreated?;
13
- private readonly onIdentifierCreated?;
14
- private readonly eventEmitter?;
15
- constructor(options?: DidAuthSiopOpAuthenticatorOptions);
16
- onEvent(event: any, context: RequiredContext): Promise<void>;
17
- private siopGetOPSession;
18
- private siopRegisterOPSession;
19
- private siopRemoveOPSession;
20
- private siopRegisterOPCustomApproval;
21
- private siopRemoveOPCustomApproval;
22
- private siopGetMachineInterpreter;
23
- private siopCreateConfig;
24
- private siopGetSiopRequest;
25
- private determineCorrelationId;
26
- private siopRetrieveContact;
27
- private siopAddContactIdentity;
28
- private siopSendResponse;
29
- private siopGetSelectableCredentials;
30
- }
31
- //# sourceMappingURL=DidAuthSiopOpAuthenticator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DidAuthSiopOpAuthenticator.d.ts","sourceRoot":"","sources":["../../src/agent/DidAuthSiopOpAuthenticator.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,OAAO,EACL,iCAAiC,EAIjC,eAAe,EAKhB,MAAM,UAAU,CAAA;AAQjB,OAAO,EAKL,2BAA2B,EAc5B,MAAM,UAAU,CAAA;AAKjB,eAAO,MAAM,iCAAiC,EAAE,KAAK,CAAC,MAAM,CAW3D,CAAA;AAED,qBAAa,0BAA2B,YAAW,YAAY;IAC7D,QAAQ,CAAC,MAAM,MAAqC;IACpD,QAAQ,CAAC,OAAO,EAAE,2BAA2B,CAc5C;IAED,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAQ;IAChC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAkH;IAClJ,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAA0B;IACpE,OAAO,CAAC,QAAQ,CAAC,wBAAwB,CAAC,CAAuD;IACjG,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAC,CAAkD;IACvF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAc;gBAEhC,OAAO,CAAC,EAAE,iCAAiC;IAiB1C,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;YAa3D,gBAAgB;YAShB,qBAAqB;YAcrB,mBAAmB;YAInB,4BAA4B;YAQ5B,0BAA0B;YAI1B,yBAAyB;YAyBzB,gBAAgB;YAehB,kBAAkB;YA+ClB,sBAAsB;YAsBtB,mBAAmB;YAuBnB,sBAAsB;YAuCtB,gBAAgB;YAoEhB,4BAA4B;CAgB3C"}