@sphereon/ssi-sdk-ext.identifier-resolution 0.25.0 → 0.25.1-feature.SDK.41.oidf.support.12

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 (40) hide show
  1. package/dist/agent/IdentifierResolution.d.ts +1 -0
  2. package/dist/agent/IdentifierResolution.d.ts.map +1 -1
  3. package/dist/agent/IdentifierResolution.js +6 -0
  4. package/dist/agent/IdentifierResolution.js.map +1 -1
  5. package/dist/functions/LegacySupport.js +4 -4
  6. package/dist/functions/LegacySupport.js.map +1 -1
  7. package/dist/functions/externalIdentifierFunctions.d.ts.map +1 -1
  8. package/dist/functions/externalIdentifierFunctions.js +4 -0
  9. package/dist/functions/externalIdentifierFunctions.js.map +1 -1
  10. package/dist/functions/externalOIDFIdentifier.d.ts +19 -0
  11. package/dist/functions/externalOIDFIdentifier.d.ts.map +1 -0
  12. package/dist/functions/externalOIDFIdentifier.js +84 -0
  13. package/dist/functions/externalOIDFIdentifier.js.map +1 -0
  14. package/dist/functions/index.d.ts +1 -0
  15. package/dist/functions/index.d.ts.map +1 -1
  16. package/dist/functions/index.js +1 -0
  17. package/dist/functions/index.js.map +1 -1
  18. package/dist/types/IIdentifierResolution.d.ts +3 -1
  19. package/dist/types/IIdentifierResolution.d.ts.map +1 -1
  20. package/dist/types/IIdentifierResolution.js +1 -0
  21. package/dist/types/IIdentifierResolution.js.map +1 -1
  22. package/dist/types/common.d.ts +1 -0
  23. package/dist/types/common.d.ts.map +1 -1
  24. package/dist/types/common.js +4 -0
  25. package/dist/types/common.js.map +1 -1
  26. package/dist/types/externalIdentifierTypes.d.ts +18 -3
  27. package/dist/types/externalIdentifierTypes.d.ts.map +1 -1
  28. package/dist/types/externalIdentifierTypes.js +5 -0
  29. package/dist/types/externalIdentifierTypes.js.map +1 -1
  30. package/package.json +13 -12
  31. package/plugin.schema.json +130 -1
  32. package/src/agent/IdentifierResolution.ts +9 -2
  33. package/src/functions/LegacySupport.ts +1 -1
  34. package/src/functions/externalIdentifierFunctions.ts +6 -1
  35. package/src/functions/externalOIDFIdentifier.ts +95 -0
  36. package/src/functions/index.ts +1 -0
  37. package/src/types/IIdentifierResolution.ts +5 -1
  38. package/src/types/IJwtService.d.ts +226 -0
  39. package/src/types/common.ts +4 -0
  40. package/src/types/externalIdentifierTypes.ts +26 -3
@@ -136,6 +136,27 @@
136
136
  "required": [
137
137
  "identifier"
138
138
  ]
139
+ },
140
+ {
141
+ "type": "object",
142
+ "properties": {
143
+ "method": {
144
+ "type": "string",
145
+ "const": "entity_id"
146
+ },
147
+ "identifier": {
148
+ "$ref": "#/components/schemas/ExternalIdentifierType"
149
+ },
150
+ "trustAnchors": {
151
+ "type": "array",
152
+ "items": {
153
+ "type": "string"
154
+ }
155
+ }
156
+ },
157
+ "required": [
158
+ "identifier"
159
+ ]
139
160
  }
140
161
  ]
141
162
  },
@@ -606,6 +627,41 @@
606
627
  "method"
607
628
  ]
608
629
  },
630
+ {
631
+ "type": "object",
632
+ "properties": {
633
+ "method": {
634
+ "$ref": "#/components/schemas/ExternalIdentifierMethod"
635
+ },
636
+ "jwks": {
637
+ "type": "array",
638
+ "items": {
639
+ "$ref": "#/components/schemas/ExternalJwkInfo"
640
+ }
641
+ },
642
+ "trustedAnchors": {
643
+ "type": "object",
644
+ "additionalProperties": {
645
+ "$ref": "#/components/schemas/PublicKeyHex"
646
+ }
647
+ },
648
+ "errorList": {
649
+ "type": "object",
650
+ "additionalProperties": {
651
+ "$ref": "#/components/schemas/ErrorMessage"
652
+ }
653
+ },
654
+ "trustEstablished": {
655
+ "type": "boolean"
656
+ }
657
+ },
658
+ "required": [
659
+ "jwks",
660
+ "method",
661
+ "trustEstablished",
662
+ "trustedAnchors"
663
+ ]
664
+ },
609
665
  {
610
666
  "type": "object",
611
667
  "properties": {
@@ -643,7 +699,8 @@
643
699
  "cose_key",
644
700
  "oidc-discovery",
645
701
  "jwks-url",
646
- "oid4vci-issuer"
702
+ "oid4vci-issuer",
703
+ "entity_id"
647
704
  ]
648
705
  },
649
706
  "ExternalJwkInfo": {
@@ -1295,6 +1352,12 @@
1295
1352
  "x5c"
1296
1353
  ]
1297
1354
  },
1355
+ "PublicKeyHex": {
1356
+ "type": "string"
1357
+ },
1358
+ "ErrorMessage": {
1359
+ "type": "string"
1360
+ },
1298
1361
  "ICoseKeyJson": {
1299
1362
  "type": "object",
1300
1363
  "properties": {
@@ -1577,6 +1640,63 @@
1577
1640
  "method"
1578
1641
  ]
1579
1642
  },
1643
+ "ExternalIdentifierOIDFEntityIdOpts": {
1644
+ "type": "object",
1645
+ "properties": {
1646
+ "method": {
1647
+ "type": "string",
1648
+ "const": "entity_id"
1649
+ },
1650
+ "identifier": {
1651
+ "$ref": "#/components/schemas/ExternalIdentifierType"
1652
+ },
1653
+ "trustAnchors": {
1654
+ "type": "array",
1655
+ "items": {
1656
+ "type": "string"
1657
+ }
1658
+ }
1659
+ },
1660
+ "required": [
1661
+ "identifier"
1662
+ ]
1663
+ },
1664
+ "ExternalIdentifierOIDFEntityIdResult": {
1665
+ "type": "object",
1666
+ "properties": {
1667
+ "method": {
1668
+ "type": "string",
1669
+ "const": "entity_id"
1670
+ },
1671
+ "jwks": {
1672
+ "type": "array",
1673
+ "items": {
1674
+ "$ref": "#/components/schemas/ExternalJwkInfo"
1675
+ }
1676
+ },
1677
+ "trustedAnchors": {
1678
+ "type": "object",
1679
+ "additionalProperties": {
1680
+ "$ref": "#/components/schemas/PublicKeyHex"
1681
+ }
1682
+ },
1683
+ "errorList": {
1684
+ "type": "object",
1685
+ "additionalProperties": {
1686
+ "$ref": "#/components/schemas/ErrorMessage"
1687
+ }
1688
+ },
1689
+ "trustEstablished": {
1690
+ "type": "boolean"
1691
+ }
1692
+ },
1693
+ "required": [
1694
+ "jwks",
1695
+ "method",
1696
+ "trustEstablished",
1697
+ "trustedAnchors"
1698
+ ]
1699
+ },
1580
1700
  "ManagedIdentifierOptsOrResult": {
1581
1701
  "anyOf": [
1582
1702
  {
@@ -4116,6 +4236,15 @@
4116
4236
  "$ref": "#/components/schemas/ExternalIdentifierJwkResult"
4117
4237
  }
4118
4238
  },
4239
+ "identifierExternalResolveByOIDFEntityId": {
4240
+ "description": "",
4241
+ "arguments": {
4242
+ "$ref": "#/components/schemas/ExternalIdentifierOIDFEntityIdOpts"
4243
+ },
4244
+ "returnType": {
4245
+ "$ref": "#/components/schemas/ExternalIdentifierOIDFEntityIdResult"
4246
+ }
4247
+ },
4119
4248
  "identifierExternalResolveByX5c": {
4120
4249
  "description": "",
4121
4250
  "arguments": {
@@ -1,5 +1,5 @@
1
1
  import { IAgentContext, IAgentPlugin, IDIDManager, IKeyManager } from '@veramo/core'
2
- import { schema } from '..'
2
+ import { ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult, schema } from '..'
3
3
  import { resolveExternalIdentifier, ensureManagedIdentifierResult } from '../functions'
4
4
  import {
5
5
  ExternalIdentifierDidOpts,
@@ -30,6 +30,7 @@ import {
30
30
  ManagedIdentifierOptsOrResult,
31
31
  ManagedIdentifierOID4VCIssuerOpts
32
32
  } from '../types'
33
+ import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
33
34
 
34
35
  /**
35
36
  * @public
@@ -53,6 +54,7 @@ export class IdentifierResolution implements IAgentPlugin {
53
54
  identifierExternalResolveByX5c: this.identifierExternalResolveByX5c.bind(this),
54
55
  identifierExternalResolveByJwk: this.identifierExternalResolveByJwk.bind(this),
55
56
  identifierExternalResolveByCoseKey: this.identifierExternalResolveByCoseKey.bind(this),
57
+ identifierExternalResolveByOIDFEntityId: this.identifierExternalResolveByOIDFEntityId.bind(this),
56
58
 
57
59
  // todo: JWKSet, oidc-discovery, oid4vci-issuer etc. Anything we already can resolve and need keys of
58
60
  }
@@ -127,7 +129,7 @@ export class IdentifierResolution implements IAgentPlugin {
127
129
  return (await this.identifierGetManaged({ ...args, method: 'x5c' }, context)) as ManagedIdentifierX5cResult
128
130
  }
129
131
 
130
- private async identifierResolveExternal(args: ExternalIdentifierOpts, context: IAgentContext<IKeyManager>): Promise<ExternalIdentifierResult> {
132
+ private async identifierResolveExternal(args: ExternalIdentifierOpts, context: IAgentContext<IKeyManager | IOIDFClient>): Promise<ExternalIdentifierResult> {
131
133
  return await resolveExternalIdentifier({ ...args, crypto: this._crypto }, context)
132
134
  }
133
135
 
@@ -145,7 +147,12 @@ export class IdentifierResolution implements IAgentPlugin {
145
147
  ): Promise<ExternalIdentifierCoseKeyResult> {
146
148
  return (await this.identifierResolveExternal({ ...args, method: 'cose_key' }, context)) as ExternalIdentifierCoseKeyResult
147
149
  }
150
+
148
151
  private async identifierExternalResolveByJwk(args: ExternalIdentifierJwkOpts, context: IAgentContext<any>): Promise<ExternalIdentifierJwkResult> {
149
152
  return (await this.identifierResolveExternal({ ...args, method: 'jwk' }, context)) as ExternalIdentifierJwkResult
150
153
  }
154
+
155
+ private async identifierExternalResolveByOIDFEntityId(args: ExternalIdentifierOIDFEntityIdOpts, context: IAgentContext<IOIDFClient>): Promise<ExternalIdentifierOIDFEntityIdResult> {
156
+ return (await this.identifierResolveExternal({ ...args, method: 'entity_id' }, context)) as ExternalIdentifierOIDFEntityIdResult
157
+ }
151
158
  }
@@ -20,7 +20,7 @@ export function legacyKeyRefsToIdentifierOpts(opts: {
20
20
  opts.keyRef ??
21
21
  opts.didOpts?.idOpts?.kmsKeyRef ??
22
22
  opts.didOpts?.kid ??
23
- opts.didOpts.idOpts?.kid ??
23
+ opts.didOpts?.idOpts?.kid ??
24
24
  (typeof opts.didOpts?.idOpts.identifier === 'object' ? (opts.didOpts?.idOpts.identifier as IIdentifier).keys[0].kid : undefined)
25
25
  if (!kmsKeyRef) {
26
26
  throw Error('Key ref is needed for access token signer')
@@ -31,8 +31,11 @@ import {
31
31
  isExternalIdentifierJwksUrlOpts,
32
32
  isExternalIdentifierKidOpts,
33
33
  isExternalIdentifierOidcDiscoveryOpts,
34
+ isExternalIdentifierOIDFEntityIdOpts,
34
35
  isExternalIdentifierX5cOpts,
35
36
  } from '../types'
37
+ import { resolveExternalOIDFEntityIdIdentifier } from '.'
38
+
36
39
 
37
40
  export async function resolveExternalIdentifier(
38
41
  opts: ExternalIdentifierOpts & {
@@ -49,13 +52,15 @@ export async function resolveExternalIdentifier(
49
52
  return resolveExternalJwkIdentifier(opts, context)
50
53
  } else if (isExternalIdentifierCoseKeyOpts(opts)) {
51
54
  return resolveExternalCoseKeyIdentifier(opts, context)
55
+ } else if (isExternalIdentifierOIDFEntityIdOpts(opts)) {
56
+ return resolveExternalOIDFEntityIdIdentifier(opts, context)
52
57
  } else if (isExternalIdentifierKidOpts(opts)) {
53
58
  method = 'kid'
54
59
  } else if (isExternalIdentifierJwksUrlOpts(opts)) {
55
60
  method = 'jwks-url'
56
61
  } else if (isExternalIdentifierOidcDiscoveryOpts(opts)) {
57
62
  method = 'oidc-discovery'
58
- }
63
+ }
59
64
  throw Error(`External resolution method ${method} is not yet implemented`)
60
65
  }
61
66
 
@@ -0,0 +1,95 @@
1
+ import {
2
+ ErrorMessage,
3
+ ExternalIdentifierOIDFEntityIdOpts,
4
+ ExternalIdentifierOIDFEntityIdResult, ExternalJwkInfo,
5
+ PublicKeyHex,
6
+ TrustedAnchor,
7
+ } from '../types'
8
+ import { IAgentContext } from '@veramo/core'
9
+ import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
10
+ import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
11
+ import { JWK } from '@sphereon/ssi-types'
12
+ import { IJwsValidationResult, VerifyJwsArgs } from '../types/IJwtService'
13
+
14
+ /**
15
+ * Resolves an OIDF Entity ID against multiple trust anchors to establish trusted relationships
16
+ *
17
+ * @param opts Configuration options containing the identifier to resolve and trust anchors to validate against
18
+ * @param context Agent context that must include the OIDF client plugin and JWT verification capabilities
19
+ *
20
+ * @returns Promise resolving to an ExternalIdentifierOIDFEntityIdResult containing:
21
+ * - trustedAnchors: Record mapping trust anchors to their public key hexes
22
+ * - errorList: Optional record of errors encountered per trust anchor
23
+ * - jwks: Array of JWK information from the trust chain
24
+ * - trustEstablished: Boolean indicating if any trust relationships were established
25
+ *
26
+ * @throws Error if trust anchors are missing or JWT verification plugin is not enabled
27
+ */
28
+ export async function resolveExternalOIDFEntityIdIdentifier(
29
+ opts: ExternalIdentifierOIDFEntityIdOpts,
30
+ context: IAgentContext<IOIDFClient>
31
+ ): Promise<ExternalIdentifierOIDFEntityIdResult> {
32
+ let { trustAnchors, identifier } = opts
33
+
34
+ if (!trustAnchors || trustAnchors.length === 0) {
35
+ return Promise.reject(Error('ExternalIdentifierOIDFEntityIdOpts is missing the trustAnchors'))
36
+ }
37
+
38
+ if (!contextHasPlugin(context, 'jwtVerifyJwsSignature')) {
39
+ return Promise.reject(Error('For OIDFEntityId resolving the agent needs to have the JwtService plugin enabled'))
40
+ }
41
+
42
+ const trustedAnchors: Record<TrustedAnchor, PublicKeyHex> = {}
43
+ const errorList: Record<TrustedAnchor, ErrorMessage> = {}
44
+ const jwkInfos: Array<ExternalJwkInfo> = []
45
+
46
+ for (const trustAnchor of trustAnchors) {
47
+ const resolveResult = await context.agent.resolveTrustChain({
48
+ entityIdentifier: identifier,
49
+ trustAnchors: [trustAnchor]
50
+ })
51
+
52
+ if (resolveResult.error || !resolveResult.trustChain) {
53
+ errorList[trustAnchor] = resolveResult.errorMessage ?? 'unspecified'
54
+ } else {
55
+ const trustChain: ReadonlyArray<string> = resolveResult.trustChain.asJsReadonlyArrayView()
56
+ let authorityJWK:JWK | undefined = undefined
57
+ for (const [i, jwt] of [...trustChain].reverse().entries()) {
58
+ const isLast = i === trustChain.length - 1
59
+
60
+ const verifyArgs:VerifyJwsArgs = {jws: jwt}
61
+ if(authorityJWK && !isLast) {
62
+ verifyArgs.jwk = authorityJWK
63
+ }
64
+ const jwtVerifyResult:IJwsValidationResult = await context.agent.jwtVerifyJwsSignature(verifyArgs)
65
+ if(jwtVerifyResult.error || jwtVerifyResult.critical) {
66
+ errorList[trustAnchor] = jwtVerifyResult.message
67
+ break
68
+ }
69
+ if(jwtVerifyResult.jws.signatures.length === 0) {
70
+ errorList[trustAnchor] = 'No signature was present in the trust anchor JWS'
71
+ break
72
+ }
73
+ const signature = jwtVerifyResult.jws.signatures[0]
74
+ if(signature.identifier.jwks.length === 0) {
75
+ errorList[trustAnchor] = 'No JWK was present in the trust anchor signature'
76
+ break
77
+ }
78
+ const jwkInfo:ExternalJwkInfo = signature.identifier.jwks[0]
79
+ if(!authorityJWK) {
80
+ authorityJWK = jwkInfo.jwk
81
+ jwkInfos.push(jwkInfo)
82
+ trustedAnchors[trustAnchor] = signature.publicKeyHex // When we have multiple hits from different trust anchor authorities the caller can infer which signature came from which trust anchor
83
+ }
84
+ }
85
+ }
86
+ }
87
+
88
+ return {
89
+ method: 'entity_id',
90
+ trustedAnchors,
91
+ ...(Object.keys(errorList).length > 0 && { errorList }),
92
+ jwks: jwkInfos,
93
+ trustEstablished: Object.keys(trustedAnchors).length > 0
94
+ }
95
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './managedIdentifierFunctions'
2
2
  export * from './externalIdentifierFunctions'
3
+ export * from './externalOIDFIdentifier'
3
4
  export * from './LegacySupport'
@@ -3,7 +3,7 @@ import {
3
3
  ExternalIdentifierCoseKeyOpts,
4
4
  ExternalIdentifierCoseKeyResult,
5
5
  ExternalIdentifierDidOpts,
6
- ExternalIdentifierDidResult,
6
+ ExternalIdentifierDidResult, ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOIDFEntityIdResult,
7
7
  ExternalIdentifierJwkOpts,
8
8
  ExternalIdentifierJwkResult,
9
9
  ExternalIdentifierOpts,
@@ -29,6 +29,7 @@ import {
29
29
  ManagedIdentifierX5cOpts,
30
30
  ManagedIdentifierX5cResult,
31
31
  } from './managedIdentifierTypes'
32
+ import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
32
33
 
33
34
  // Exposing the methods here for any REST implementation
34
35
  export const identifierResolutionContextMethods: Array<string> = [
@@ -45,6 +46,7 @@ export const identifierResolutionContextMethods: Array<string> = [
45
46
  'identifierExternalResolveByX5c',
46
47
  'identifierExternalResolveByJwk',
47
48
  'identifierExternalResolveByCoseKey',
49
+ 'identifierExternalResolveByOIDFEntityId',
48
50
  ]
49
51
 
50
52
  /**
@@ -99,4 +101,6 @@ export interface IIdentifierResolution extends IPluginMethodMap {
99
101
  identifierExternalResolveByCoseKey(args: ExternalIdentifierCoseKeyOpts, context: IAgentContext<any>): Promise<ExternalIdentifierCoseKeyResult>
100
102
 
101
103
  identifierExternalResolveByX5c(args: ExternalIdentifierX5cOpts, context: IAgentContext<any>): Promise<ExternalIdentifierX5cResult>
104
+
105
+ identifierExternalResolveByOIDFEntityId(args: ExternalIdentifierOIDFEntityIdOpts, context: IAgentContext<IOIDFClient>): Promise<ExternalIdentifierOIDFEntityIdResult>
102
106
  }
@@ -0,0 +1,226 @@
1
+
2
+ // Copy of jwt-service typings since we cannot include that as devDependency due to cyclic dep
3
+
4
+ import { ExternalIdentifierDidOpts, ExternalIdentifierResult, ExternalIdentifierX5cOpts, IIdentifierResolution, ManagedIdentifierOptsOrResult, ManagedIdentifierResult } from '@sphereon/ssi-sdk-ext.identifier-resolution';
5
+ import { ClientIdScheme } from '@sphereon/ssi-sdk-ext.x509-utils';
6
+ import { BaseJWK, IValidationResult, JoseSignatureAlgorithm, JoseSignatureAlgorithmString, JWK } from '@sphereon/ssi-types';
7
+ import { IAgentContext, IKeyManager, IPluginMethodMap } from '@veramo/core';
8
+ export type IRequiredContext = IAgentContext<IIdentifierResolution & IKeyManager>;
9
+ export declare const jwtServiceContextMethods: Array<string>;
10
+ export interface IJwtService extends IPluginMethodMap {
11
+ jwtPrepareJws(args: CreateJwsJsonArgs, context: IRequiredContext): Promise<PreparedJwsObject>;
12
+ jwtCreateJwsJsonGeneralSignature(args: CreateJwsJsonArgs, context: IRequiredContext): Promise<JwsJsonGeneral>;
13
+ jwtCreateJwsJsonFlattenedSignature(args: CreateJwsFlattenedArgs, context: IRequiredContext): Promise<JwsJsonFlattened>;
14
+ jwtCreateJwsCompactSignature(args: CreateJwsCompactArgs, context: IRequiredContext): Promise<JwtCompactResult>;
15
+ jwtVerifyJwsSignature(args: VerifyJwsArgs, context: IRequiredContext): Promise<IJwsValidationResult>;
16
+ jwtEncryptJweCompactJwt(args: EncryptJweCompactJwtArgs, context: IRequiredContext): Promise<JwtCompactResult>;
17
+ jwtDecryptJweCompactJwt(args: DecryptJweCompactJwtArgs, context: IRequiredContext): Promise<JwtCompactResult>;
18
+ }
19
+ export type IJwsValidationResult = IValidationResult & {
20
+ jws: JwsJsonGeneralWithIdentifiers;
21
+ };
22
+ export interface PreparedJws {
23
+ protectedHeader: JwsHeader;
24
+ payload: Uint8Array;
25
+ unprotectedHeader?: JwsHeader;
26
+ existingSignatures?: Array<JwsJsonSignature>;
27
+ }
28
+ export interface JwsJsonSignature {
29
+ protected: string;
30
+ header?: JwsHeader;
31
+ signature: string;
32
+ }
33
+ /**
34
+ * The JWK representation of an ephemeral public key.
35
+ * See https://www.rfc-editor.org/rfc/rfc7518.html#section-6
36
+ */
37
+ export type EphemeralPublicKey = Omit<BaseJWK, 'alg'>;
38
+ export interface JweHeader extends Omit<BaseJwtHeader, 'alg'> {
39
+ alg: string;
40
+ enc: string;
41
+ jku?: string;
42
+ jwk?: BaseJWK;
43
+ epk?: EphemeralPublicKey;
44
+ x5u?: string;
45
+ x5c?: string[];
46
+ x5t?: string;
47
+ cty?: string;
48
+ crit?: string[];
49
+ [k: string]: any;
50
+ }
51
+ export interface JweRecipientUnprotectedHeader {
52
+ alg: string;
53
+ iv: string;
54
+ tag: string;
55
+ epk?: EphemeralPublicKey;
56
+ kid?: string;
57
+ apv?: string;
58
+ apu?: string;
59
+ }
60
+ export interface JweProtectedHeader extends Partial<JweHeader> {
61
+ zip?: 'DEF' | string;
62
+ }
63
+ export type Jws = JwsCompact | JwsJsonFlattened | JwsJsonGeneral;
64
+ export type JwsCompact = string;
65
+ export interface JwsJsonFlattened {
66
+ payload: string;
67
+ protected: string;
68
+ header?: JwsHeader;
69
+ signature: string;
70
+ }
71
+ export interface JwsJsonGeneral {
72
+ payload: string;
73
+ signatures: Array<JwsJsonSignature>;
74
+ }
75
+ export interface JwsJsonGeneralWithIdentifiers extends JwsJsonGeneral {
76
+ signatures: Array<JwsJsonSignatureWithIdentifier>;
77
+ }
78
+ export interface JwsJsonSignatureWithIdentifier extends JwsJsonSignature {
79
+ identifier: ExternalIdentifierResult;
80
+ publicKeyHex: string;
81
+ }
82
+ export type Jwe = JweCompact | JweJsonFlattened | JweJsonGeneral;
83
+ export type JweCompact = string;
84
+ export interface JweJsonFlattened {
85
+ protected: string;
86
+ unprotected: JweHeader;
87
+ header: JweHeader | JweRecipientUnprotectedHeader;
88
+ encrypted_key?: string;
89
+ aad?: string;
90
+ iv: string;
91
+ ciphertext: string;
92
+ tag?: string;
93
+ }
94
+ export interface JweRecipient {
95
+ header?: JweRecipientUnprotectedHeader;
96
+ encrypted_key?: string;
97
+ }
98
+ export interface JweJsonGeneral {
99
+ protected: string;
100
+ unprotected?: JweHeader;
101
+ recipients: Array<JweRecipient>;
102
+ aad?: string;
103
+ iv: string;
104
+ ciphertext: string;
105
+ tag?: string;
106
+ }
107
+ export interface PreparedJwsObject {
108
+ jws: PreparedJws;
109
+ b64: {
110
+ payload: string;
111
+ protectedHeader: string;
112
+ };
113
+ identifier: ManagedIdentifierResult;
114
+ }
115
+ export interface BaseJwtHeader {
116
+ typ?: string;
117
+ alg?: string;
118
+ kid?: string;
119
+ }
120
+ export interface BaseJwtPayload {
121
+ iss?: string;
122
+ sub?: string;
123
+ aud?: string[] | string;
124
+ exp?: number;
125
+ nbf?: number;
126
+ iat?: number;
127
+ jti?: string;
128
+ }
129
+ export interface JwsHeader extends BaseJwtHeader {
130
+ kid?: string;
131
+ jwk?: JWK;
132
+ x5c?: string[];
133
+ [key: string]: unknown;
134
+ }
135
+ export interface JwsPayload extends BaseJwtPayload {
136
+ [key: string]: unknown;
137
+ }
138
+ export interface JwsHeaderOpts {
139
+ alg: JoseSignatureAlgorithm | JoseSignatureAlgorithmString;
140
+ }
141
+ export type JwsIdentifierMode = 'x5c' | 'kid' | 'jwk' | 'did' | 'auto';
142
+ export type EncryptJweCompactJwtArgs = {
143
+ payload: JwsPayload;
144
+ protectedHeader?: JweProtectedHeader | undefined;
145
+ aad?: Uint8Array | undefined;
146
+ recipientKey: ExternalIdentifierResult & {
147
+ kid?: string;
148
+ };
149
+ alg?: JweAlg;
150
+ enc?: JweEnc;
151
+ apu?: string;
152
+ apv?: string;
153
+ expirationTime?: number | string | Date;
154
+ issuer?: string;
155
+ audience?: string | string[];
156
+ };
157
+ export type DecryptJweCompactJwtArgs = {
158
+ jwe: JweCompact;
159
+ idOpts: ManagedIdentifierOptsOrResult;
160
+ };
161
+ export type CreateJwsArgs = {
162
+ mode?: JwsIdentifierMode;
163
+ issuer: ManagedIdentifierOptsOrResult & {
164
+ noIssPayloadUpdate?: boolean;
165
+ noIdentifierInHeader?: boolean;
166
+ };
167
+ clientId?: string;
168
+ clientIdScheme?: ClientIdScheme | 'did' | string;
169
+ protectedHeader: JwsHeader;
170
+ payload: JwsPayload | Uint8Array | string;
171
+ };
172
+ export type CreateJweArgs = {
173
+ mode?: JwsIdentifierMode;
174
+ issuer: ManagedIdentifierOptsOrResult & {
175
+ noIssPayloadUpdate?: boolean;
176
+ noIdentifierInHeader?: boolean;
177
+ };
178
+ protectedHeader: JweProtectedHeader;
179
+ encryptedKey: string | EphemeralPublicKey;
180
+ iv: string;
181
+ ciphertext: string;
182
+ tag: string;
183
+ };
184
+ export type CreateJwsCompactArgs = CreateJwsArgs;
185
+ export type CreateJwsFlattenedArgs = Exclude<CreateJwsJsonArgs, 'existingSignatures'>;
186
+ export type VerifyJwsArgs = {
187
+ jws: Jws;
188
+ jwk?: JWK;
189
+ opts?: {
190
+ x5c?: Omit<ExternalIdentifierX5cOpts, 'identifier'>;
191
+ did?: Omit<ExternalIdentifierDidOpts, 'identifier'>;
192
+ };
193
+ };
194
+ /**
195
+ * @public
196
+ */
197
+ export type CreateJwsJsonArgs = CreateJwsArgs & {
198
+ unprotectedHeader?: JwsHeader;
199
+ existingSignatures?: Array<JwsJsonSignature>;
200
+ };
201
+ export type CreateJweJsonArgs = CreateJweArgs & {
202
+ unprotectedHeader?: JweHeader;
203
+ };
204
+ /**
205
+ * @public
206
+ */
207
+ export interface JwtCompactResult {
208
+ jwt: JwsCompact | JweCompact;
209
+ }
210
+ export declare function isJwsCompact(jws: Jws): jws is JwsCompact;
211
+ export declare function isJweCompact(jwe: Jwe): jwe is JweCompact;
212
+ export declare function isJwsJsonFlattened(jws: Jws): jws is JwsJsonFlattened;
213
+ export declare function isJwsJsonGeneral(jws: Jws): jws is JwsJsonGeneral;
214
+ export declare function isJweJsonFlattened(jwe: Jwe): jwe is JweJsonFlattened;
215
+ export declare function isJweJsonGeneral(jwe: Jwe): jwe is JweJsonGeneral;
216
+ export declare function isJwsHeader(header: BaseJwtHeader & Record<string, any>): header is JwsHeader;
217
+ export declare function isJweHeader(header: BaseJwtHeader & Record<string, any>): header is JweHeader;
218
+ export declare const COMPACT_JWS_REGEX: RegExp;
219
+ export declare const COMPACT_JWE_REGEX: RegExp;
220
+ export declare const JweAlgs: readonly ["RSA1_5", "RSA-OAEP", "RSA-OAEP-256", "A128KW", "A192KW", "A256KW", "dir", "ECDH-ES", "ECDH-ES+A128KW", "ECDH-ES+A192KW", "ECDH-ES+A256KW", "A128GCMKW", "A192GCMKW", "A256GCMKW", "PBES2-HS256+A128KW", "PBES2-HS384+A192KW", "PBES2-HS512+A256KW"];
221
+ export type JweAlg = typeof JweAlgs[number];
222
+ export declare function jweAlg(alg?: string | JweAlg): JweAlg | undefined;
223
+ export declare const JweEncs: readonly ["A128CBC-HS256", "A192CBC-HS384", "A256CBC-HS512", "A128GCM", "A192GCM", "A256GCM"];
224
+ export type JweEnc = typeof JweEncs[number];
225
+ export declare function jweEnc(alg?: string | JweEnc): JweEnc | undefined;
226
+ //# sourceMappingURL=IJwtService.d.ts.map
@@ -50,6 +50,10 @@ export function isCoseKeyIdentifier(identifier: ManagedIdentifierType): identifi
50
50
  return typeof identifier === 'object' && `kty` in identifier && ('baseIV' in identifier || 'x5chain' in identifier) && !('x5c' in identifier)
51
51
  }
52
52
 
53
+ export function isOIDFEntityIdIdentifier(identifier: ManagedIdentifierType): identifier is ICoseKeyJson {
54
+ return typeof identifier === 'string' && identifier.startsWith('https://')
55
+ }
56
+
53
57
  export function isX5cIdentifier(identifier: ManagedIdentifierType | ExternalIdentifierType): identifier is string[] {
54
58
  return Array.isArray(identifier) && identifier.length > 0 // todo: Do we want to do additional validation? We know it must be DER and thus hex for instance
55
59
  }