@sphereon/oid4vci-common 0.4.1-next.285
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/LICENSE +201 -0
- package/dist/functions/CredentialOfferUtil.d.ts +25 -0
- package/dist/functions/CredentialOfferUtil.d.ts.map +1 -0
- package/dist/functions/CredentialOfferUtil.js +303 -0
- package/dist/functions/CredentialOfferUtil.js.map +1 -0
- package/dist/functions/CredentialRequestUtil.d.ts +3 -0
- package/dist/functions/CredentialRequestUtil.d.ts.map +1 -0
- package/dist/functions/CredentialRequestUtil.js +8 -0
- package/dist/functions/CredentialRequestUtil.js.map +1 -0
- package/dist/functions/Encoding.d.ts +20 -0
- package/dist/functions/Encoding.d.ts.map +1 -0
- package/dist/functions/Encoding.js +164 -0
- package/dist/functions/Encoding.js.map +1 -0
- package/dist/functions/HttpUtils.d.ts +33 -0
- package/dist/functions/HttpUtils.d.ts.map +1 -0
- package/dist/functions/HttpUtils.js +146 -0
- package/dist/functions/HttpUtils.js.map +1 -0
- package/dist/functions/IssuerMetadataUtils.d.ts +10 -0
- package/dist/functions/IssuerMetadataUtils.d.ts.map +1 -0
- package/dist/functions/IssuerMetadataUtils.js +89 -0
- package/dist/functions/IssuerMetadataUtils.js.map +1 -0
- package/dist/functions/TypeConversionUtils.d.ts +2 -0
- package/dist/functions/TypeConversionUtils.d.ts.map +1 -0
- package/dist/functions/TypeConversionUtils.js +8 -0
- package/dist/functions/TypeConversionUtils.js.map +1 -0
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/functions/index.js +20 -0
- package/dist/functions/index.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/types/Authorization.types.d.ts +198 -0
- package/dist/types/Authorization.types.d.ts.map +1 -0
- package/dist/types/Authorization.types.js +40 -0
- package/dist/types/Authorization.types.js.map +1 -0
- package/dist/types/CredentialIssuance.types.d.ts +139 -0
- package/dist/types/CredentialIssuance.types.d.ts.map +1 -0
- package/dist/types/CredentialIssuance.types.js +10 -0
- package/dist/types/CredentialIssuance.types.js.map +1 -0
- package/dist/types/Generic.types.d.ts +156 -0
- package/dist/types/Generic.types.d.ts.map +1 -0
- package/dist/types/Generic.types.js +11 -0
- package/dist/types/Generic.types.js.map +1 -0
- package/dist/types/OAuth2ASMetadata.d.ts +41 -0
- package/dist/types/OAuth2ASMetadata.d.ts.map +1 -0
- package/dist/types/OAuth2ASMetadata.js +3 -0
- package/dist/types/OAuth2ASMetadata.js.map +1 -0
- package/dist/types/OpenID4VCIErrors.d.ts +34 -0
- package/dist/types/OpenID4VCIErrors.d.ts.map +1 -0
- package/dist/types/OpenID4VCIErrors.js +38 -0
- package/dist/types/OpenID4VCIErrors.js.map +1 -0
- package/dist/types/OpenID4VCIServerMetadata.d.ts +4 -0
- package/dist/types/OpenID4VCIServerMetadata.d.ts.map +1 -0
- package/dist/types/OpenID4VCIServerMetadata.js +17 -0
- package/dist/types/OpenID4VCIServerMetadata.js.map +1 -0
- package/dist/types/OpenID4VCIVersions.types.d.ts +11 -0
- package/dist/types/OpenID4VCIVersions.types.d.ts.map +1 -0
- package/dist/types/OpenID4VCIVersions.types.js +16 -0
- package/dist/types/OpenID4VCIVersions.types.js.map +1 -0
- package/dist/types/StateManager.types.d.ts +33 -0
- package/dist/types/StateManager.types.d.ts.map +1 -0
- package/dist/types/StateManager.types.js +3 -0
- package/dist/types/StateManager.types.js.map +1 -0
- package/dist/types/Token.types.d.ts +15 -0
- package/dist/types/Token.types.d.ts.map +1 -0
- package/dist/types/Token.types.js +30 -0
- package/dist/types/Token.types.js.map +1 -0
- package/dist/types/index.d.ts +13 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +29 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/v1_0_08.types.d.ts +38 -0
- package/dist/types/v1_0_08.types.d.ts.map +1 -0
- package/dist/types/v1_0_08.types.js +3 -0
- package/dist/types/v1_0_08.types.js.map +1 -0
- package/dist/types/v1_0_09.types.d.ts +29 -0
- package/dist/types/v1_0_09.types.d.ts.map +1 -0
- package/dist/types/v1_0_09.types.js +9 -0
- package/dist/types/v1_0_09.types.js.map +1 -0
- package/dist/types/v1_0_11.types.d.ts +49 -0
- package/dist/types/v1_0_11.types.d.ts.map +1 -0
- package/dist/types/v1_0_11.types.js +9 -0
- package/dist/types/v1_0_11.types.js.map +1 -0
- package/lib/__tests__/CredentialOfferUtil.spec.ts +55 -0
- package/lib/functions/CredentialOfferUtil.ts +338 -0
- package/lib/functions/CredentialRequestUtil.ts +5 -0
- package/lib/functions/Encoding.ts +166 -0
- package/lib/functions/HttpUtils.ts +168 -0
- package/lib/functions/IssuerMetadataUtils.ts +101 -0
- package/lib/functions/TypeConversionUtils.ts +3 -0
- package/lib/functions/index.ts +3 -0
- package/lib/index.ts +2 -0
- package/lib/types/Authorization.types.ts +234 -0
- package/lib/types/CredentialIssuance.types.ts +167 -0
- package/lib/types/Generic.types.ts +234 -0
- package/lib/types/OAuth2ASMetadata.ts +49 -0
- package/lib/types/OpenID4VCIErrors.ts +35 -0
- package/lib/types/OpenID4VCIServerMetadata.ts +20 -0
- package/lib/types/OpenID4VCIVersions.types.ts +11 -0
- package/lib/types/StateManager.types.ts +45 -0
- package/lib/types/Token.types.ts +29 -0
- package/lib/types/index.ts +12 -0
- package/lib/types/v1_0_08.types.ts +44 -0
- package/lib/types/v1_0_09.types.ts +36 -0
- package/lib/types/v1_0_11.types.ts +68 -0
- package/package.json +49 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CredentialIssuerMetadata,
|
|
3
|
+
CredentialOfferFormat,
|
|
4
|
+
CredentialSupported,
|
|
5
|
+
CredentialSupportedTypeV1_0_08,
|
|
6
|
+
CredentialSupportedV1_0_08,
|
|
7
|
+
IssuerMetadataV1_0_08,
|
|
8
|
+
OpenId4VCIVersion,
|
|
9
|
+
} from '../types';
|
|
10
|
+
|
|
11
|
+
export function getSupportedCredentials(opts?: {
|
|
12
|
+
issuerMetadata?: CredentialIssuerMetadata | IssuerMetadataV1_0_08;
|
|
13
|
+
version: OpenId4VCIVersion;
|
|
14
|
+
credentialTypes?: (CredentialOfferFormat | string)[];
|
|
15
|
+
supportedType?: CredentialOfferFormat | string;
|
|
16
|
+
}): CredentialSupported[] {
|
|
17
|
+
const { issuerMetadata } = opts ?? {};
|
|
18
|
+
let credentialsSupported: CredentialSupported[];
|
|
19
|
+
if (!issuerMetadata) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
const { version, credentialTypes, supportedType } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 };
|
|
23
|
+
if (version === OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) {
|
|
24
|
+
credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported);
|
|
25
|
+
/* const credentialsSupportedV8: CredentialSupportedV1_0_08 = credentialsSupported as CredentialSupportedV1_0_08
|
|
26
|
+
// const initiationTypes = credentialTypes.map(type => typeof type === 'string' ? [type] : type.types)
|
|
27
|
+
const supported: IssuerCredentialSubject = {}
|
|
28
|
+
for (const [key, value] of Object.entries(credentialsSupportedV8)) {
|
|
29
|
+
if (initiationTypes.find((type) => (typeof type === 'string' ? type === key : type.types.includes(key)))) {
|
|
30
|
+
supported[key] = value
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// todo: fix this later. we're returning CredentialSupportedV1_0_08 as a list of CredentialSupported (for v09 onward)
|
|
34
|
+
return supported as unknown as CredentialSupported[]*/
|
|
35
|
+
} else {
|
|
36
|
+
credentialsSupported = (issuerMetadata as CredentialIssuerMetadata).credentials_supported;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (credentialsSupported === undefined || credentialsSupported.length === 0) {
|
|
40
|
+
return [];
|
|
41
|
+
} else if (!credentialTypes || credentialTypes.length === 0) {
|
|
42
|
+
return credentialsSupported;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* the following (not array part is a legacy code from version 1_0-08 which JFF plugfest 2 implementors used)
|
|
46
|
+
*/
|
|
47
|
+
const initiationTypes = supportedType ? [supportedType] : credentialTypes;
|
|
48
|
+
|
|
49
|
+
const credentialSupportedOverlap: CredentialSupported[] = [];
|
|
50
|
+
for (const offerType of initiationTypes) {
|
|
51
|
+
if (typeof offerType === 'string') {
|
|
52
|
+
const supported = credentialsSupported.find((sup) => sup.id === offerType || sup.types.includes(offerType));
|
|
53
|
+
if (supported) {
|
|
54
|
+
credentialSupportedOverlap.push(supported);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
const supported = credentialsSupported.find((sup) => arrayEqualsIgnoreOrder(sup.types, offerType.types) && sup.format === offerType.format);
|
|
58
|
+
if (supported) {
|
|
59
|
+
credentialSupportedOverlap.push(supported);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return credentialSupportedOverlap;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function arrayEqualsIgnoreOrder(a: string[], b: string[]) {
|
|
67
|
+
if (a.length !== b.length) return false;
|
|
68
|
+
const uniqueValues = new Set([...a, ...b]);
|
|
69
|
+
for (const v of uniqueValues) {
|
|
70
|
+
const aCount = a.filter((e) => e === v).length;
|
|
71
|
+
const bCount = b.filter((e) => e === v).length;
|
|
72
|
+
if (aCount !== bCount) return false;
|
|
73
|
+
}
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function credentialsSupportedV8ToV11(supportedV8: CredentialSupportedTypeV1_0_08): CredentialSupported[] {
|
|
78
|
+
return Object.entries(supportedV8).flatMap((entry) => {
|
|
79
|
+
const type = entry[0];
|
|
80
|
+
const supportedV8 = entry[1];
|
|
81
|
+
return credentialSupportedV8ToV11(type, supportedV8);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function credentialSupportedV8ToV11(key: string, supportedV8: CredentialSupportedV1_0_08): CredentialSupported[] {
|
|
86
|
+
return Object.entries(supportedV8.formats).map((entry) => {
|
|
87
|
+
const format = entry[0];
|
|
88
|
+
const credentialSupportBrief = entry[1];
|
|
89
|
+
if (typeof format !== 'string') {
|
|
90
|
+
throw Error(`Unknown format received ${JSON.stringify(format)}`);
|
|
91
|
+
}
|
|
92
|
+
let credentialSupport: Partial<CredentialSupported> = {};
|
|
93
|
+
credentialSupport = {
|
|
94
|
+
format,
|
|
95
|
+
display: supportedV8.display,
|
|
96
|
+
...credentialSupportBrief,
|
|
97
|
+
credentialSubject: supportedV8.claims,
|
|
98
|
+
};
|
|
99
|
+
return credentialSupport as CredentialSupported;
|
|
100
|
+
});
|
|
101
|
+
}
|
package/lib/index.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { CredentialOfferPayload, UniformCredentialOffer } from './CredentialIssuance.types';
|
|
2
|
+
import {
|
|
3
|
+
EndpointMetadata,
|
|
4
|
+
ErrorResponse,
|
|
5
|
+
IssuerCredentialDefinition,
|
|
6
|
+
IssuerCredentialSubject,
|
|
7
|
+
OID4VCICredentialFormat,
|
|
8
|
+
PRE_AUTH_CODE_LITERAL,
|
|
9
|
+
} from './Generic.types';
|
|
10
|
+
|
|
11
|
+
export interface CommonAuthorizationRequest {
|
|
12
|
+
/**
|
|
13
|
+
* REQUIRED. Value MUST be set to "code". for Authorization Code Grant
|
|
14
|
+
*/
|
|
15
|
+
response_type: ResponseType.AUTH_CODE;
|
|
16
|
+
/**
|
|
17
|
+
* The authorization server issues the registered client a client
|
|
18
|
+
* identifier -- a unique string representing the registration
|
|
19
|
+
* information provided by the client.
|
|
20
|
+
*/
|
|
21
|
+
client_id: string;
|
|
22
|
+
/**
|
|
23
|
+
* If the "code_challenge_method" from Section 4.3 was "S256", the
|
|
24
|
+
* received "code_verifier" is hashed by SHA-256, base64url-encoded, and
|
|
25
|
+
* then compared to the "code_challenge", i.e.:
|
|
26
|
+
* BASE64URL-ENCODE(SHA256(ASCII(code_verifier))) == code_challenge
|
|
27
|
+
*
|
|
28
|
+
* If the "code_challenge_method" from Section 4.3 was "plain", they are
|
|
29
|
+
* compared directly, i.e.:
|
|
30
|
+
* code_verifier == code_challenge.
|
|
31
|
+
*/
|
|
32
|
+
code_challenge: string;
|
|
33
|
+
/**
|
|
34
|
+
* value must be set either to "S256" or a value defined by a cryptographically secure
|
|
35
|
+
*/
|
|
36
|
+
code_challenge_method: CodeChallengeMethod;
|
|
37
|
+
/**
|
|
38
|
+
* The redirection endpoint URI MUST be an absolute URI as defined by: absolute-URI = scheme ":" hier-part [ "?" query ]
|
|
39
|
+
*/
|
|
40
|
+
redirect_uri: string;
|
|
41
|
+
/**
|
|
42
|
+
* The value of the scope parameter is expressed as a list of space-delimited, case-sensitive strings.
|
|
43
|
+
*/
|
|
44
|
+
scope?: string;
|
|
45
|
+
/**
|
|
46
|
+
* There are two possible ways to request issuance of a specific Credential type in an Authorization Request.
|
|
47
|
+
* One way is to use of the authorization_details request parameter as defined in [I-D.ietf-oauth-rar]
|
|
48
|
+
* with one or more authorization details objects of type openid_credential Section 5.1.1.
|
|
49
|
+
* (The other is through the use of scopes as defined in Section 5.1.2.)
|
|
50
|
+
*/
|
|
51
|
+
authorization_details?: AuthorizationDetails[] | AuthorizationDetails;
|
|
52
|
+
/**
|
|
53
|
+
* OPTIONAL. JSON string containing the Wallet's OpenID Connect issuer URL. The Credential Issuer will use the discovery process as defined in
|
|
54
|
+
* [SIOPv2] to determine the Wallet's capabilities and endpoints. RECOMMENDED in Dynamic Credential Request.
|
|
55
|
+
*/
|
|
56
|
+
wallet_issuer?: string;
|
|
57
|
+
/**
|
|
58
|
+
* OPTIONAL. JSON string containing an opaque user hint the Wallet MAY use in subsequent callbacks to optimize the user's experience.
|
|
59
|
+
* RECOMMENDED in Dynamic Credential Request.
|
|
60
|
+
*/
|
|
61
|
+
user_hint?: string;
|
|
62
|
+
/**
|
|
63
|
+
* OPTIONAL. String value identifying a certain processing context at the Credential Issuer. A value for this parameter is typically passed in
|
|
64
|
+
* an issuance initation request from the Credential Issuer to the Wallet (see (Section 4.1). This request parameter is used to pass the
|
|
65
|
+
* issuer_state value back to the Credential Issuer.
|
|
66
|
+
*/
|
|
67
|
+
issuer_state?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* string type added for conformity with our previous code in the client
|
|
72
|
+
*/
|
|
73
|
+
export type AuthorizationDetails = AuthorizationDetailsJwtVcJson | AuthorizationRequestJwtVcJsonLdAndLdpVc | string;
|
|
74
|
+
|
|
75
|
+
export type AuthorizationRequest = AuthorizationRequestJwtVcJson | AuthorizationDetailsJwtVcJsonLdAndLdpVc;
|
|
76
|
+
|
|
77
|
+
export interface AuthorizationRequestJwtVcJson extends CommonAuthorizationRequest {
|
|
78
|
+
authorization_details?: AuthorizationDetailsJwtVcJson[];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface AuthorizationRequestJwtVcJsonLdAndLdpVc extends CommonAuthorizationRequest {
|
|
82
|
+
authorization_details?: AuthorizationDetailsJwtVcJsonLdAndLdpVc[];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface CommonAuthorizationDetails {
|
|
86
|
+
/**
|
|
87
|
+
* REQUIRED. JSON string that determines the authorization details type.
|
|
88
|
+
* MUST be set to openid_credential for the purpose of this specification.
|
|
89
|
+
*/
|
|
90
|
+
type: 'openid_credential' | string;
|
|
91
|
+
/**
|
|
92
|
+
* REQUIRED. JSON string representing the format in which the Credential is requested to be issued.
|
|
93
|
+
* This Credential format identifier determines further claims in the authorization details object
|
|
94
|
+
* specifically used to identify the Credential type to be issued. This specification defines
|
|
95
|
+
* Credential Format Profiles in Appendix E.
|
|
96
|
+
*/
|
|
97
|
+
format: OID4VCICredentialFormat;
|
|
98
|
+
/**
|
|
99
|
+
* If the Credential Issuer metadata contains an authorization_server parameter,
|
|
100
|
+
* the authorization detail's locations common data field MUST be set to the Credential Issuer Identifier value.
|
|
101
|
+
*/
|
|
102
|
+
locations?: string[];
|
|
103
|
+
types: string[]; // This claim contains the type values the Wallet requests authorization for at the issuer.
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
105
|
+
[key: string]: any;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface AuthorizationDetailsJwtVcJson extends CommonAuthorizationDetails {
|
|
109
|
+
/**
|
|
110
|
+
* A JSON object containing a list of key value pairs, where the key identifies the claim offered in the Credential.
|
|
111
|
+
* The value MAY be a dictionary, which allows to represent the full (potentially deeply nested) structure of the
|
|
112
|
+
* verifiable credential to be issued. This object indicates the claims the Wallet would like to turn up in the
|
|
113
|
+
* credential to be issued.
|
|
114
|
+
*/
|
|
115
|
+
credentialSubject?: IssuerCredentialSubject;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface AuthorizationDetailsJwtVcJsonLdAndLdpVc extends CommonAuthorizationDetails {
|
|
119
|
+
/**
|
|
120
|
+
* REQUIRED. JSON object containing (and isolating) the detailed description of the credential type.
|
|
121
|
+
* This object MUST be processed using full JSON-LD processing. It consists of the following sub-claims:
|
|
122
|
+
* - @context: REQUIRED. JSON array as defined in Appendix E.1.3.2
|
|
123
|
+
* - types: REQUIRED. JSON array as defined in Appendix E.1.3.2.
|
|
124
|
+
* This claim contains the type values the Wallet shall request in the subsequent Credential Request
|
|
125
|
+
*/
|
|
126
|
+
credential_definition: IssuerCredentialDefinition;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export enum GrantTypes {
|
|
130
|
+
AUTHORIZATION_CODE = 'authorization_code',
|
|
131
|
+
PRE_AUTHORIZED_CODE = 'urn:ietf:params:oauth:grant-type:pre-authorized_code',
|
|
132
|
+
PASSWORD = 'password',
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export enum Encoding {
|
|
136
|
+
FORM_URL_ENCODED = 'application/x-www-form-urlencoded',
|
|
137
|
+
UTF_8 = 'UTF-8',
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export enum ResponseType {
|
|
141
|
+
AUTH_CODE = 'code',
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export enum CodeChallengeMethod {
|
|
145
|
+
TEXT = 'text',
|
|
146
|
+
SHA256 = 'S256',
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface AuthorizationServerOpts {
|
|
150
|
+
allowInsecureEndpoints?: boolean;
|
|
151
|
+
as?: string; // If not provided the issuer hostname will be used!
|
|
152
|
+
tokenEndpoint?: string; // Allows to override the default '/token' endpoint
|
|
153
|
+
clientId?: string;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export interface IssuerOpts {
|
|
157
|
+
issuer: string;
|
|
158
|
+
tokenEndpoint?: string;
|
|
159
|
+
fetchMetadata?: boolean;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export interface AccessTokenRequestOpts {
|
|
163
|
+
credentialOffer: UniformCredentialOffer;
|
|
164
|
+
asOpts?: AuthorizationServerOpts;
|
|
165
|
+
metadata?: EndpointMetadata;
|
|
166
|
+
codeVerifier?: string; // only required for authorization flow
|
|
167
|
+
code?: string; // only required for authorization flow
|
|
168
|
+
redirectUri?: string; // only required for authorization flow
|
|
169
|
+
pin?: string; // Pin-number. Only used when required
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface AuthorizationRequestOpts {
|
|
173
|
+
clientId: string;
|
|
174
|
+
codeChallenge: string;
|
|
175
|
+
codeChallengeMethod: CodeChallengeMethod;
|
|
176
|
+
authorizationDetails?: AuthorizationDetails[];
|
|
177
|
+
redirectUri: string;
|
|
178
|
+
scope?: string;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface AuthorizationGrantResponse {
|
|
182
|
+
grant_type: string;
|
|
183
|
+
code: string;
|
|
184
|
+
scope?: string;
|
|
185
|
+
state?: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface AccessTokenRequest {
|
|
189
|
+
client_id?: string;
|
|
190
|
+
code?: string;
|
|
191
|
+
code_verifier?: string;
|
|
192
|
+
grant_type: GrantTypes;
|
|
193
|
+
'pre-authorized_code': string;
|
|
194
|
+
redirect_uri?: string;
|
|
195
|
+
scope?: string;
|
|
196
|
+
user_pin?: string;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface OpenIDResponse<T> {
|
|
200
|
+
origResponse: Response;
|
|
201
|
+
successBody?: T;
|
|
202
|
+
errorBody?: ErrorResponse;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export interface AccessTokenResponse {
|
|
206
|
+
access_token: string;
|
|
207
|
+
scope?: string;
|
|
208
|
+
token_type?: string;
|
|
209
|
+
expires_in?: number; // in seconds
|
|
210
|
+
c_nonce?: string;
|
|
211
|
+
c_nonce_expires_in?: number; // in seconds
|
|
212
|
+
authorization_pending?: boolean;
|
|
213
|
+
interval?: number; // in seconds
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export enum AuthzFlowType {
|
|
217
|
+
AUTHORIZATION_CODE_FLOW = 'Authorization Code Flow',
|
|
218
|
+
PRE_AUTHORIZED_CODE_FLOW = 'Pre-Authorized Code Flow',
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
222
|
+
export namespace AuthzFlowType {
|
|
223
|
+
export function valueOf(request: CredentialOfferPayload): AuthzFlowType {
|
|
224
|
+
if (PRE_AUTH_CODE_LITERAL in request) {
|
|
225
|
+
return AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW;
|
|
226
|
+
}
|
|
227
|
+
return AuthzFlowType.AUTHORIZATION_CODE_FLOW;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface PushedAuthorizationResponse {
|
|
232
|
+
request_uri: string;
|
|
233
|
+
expires_in: number;
|
|
234
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { W3CVerifiableCredential } from '@sphereon/ssi-types';
|
|
2
|
+
|
|
3
|
+
import { AuthzFlowType } from './Authorization.types';
|
|
4
|
+
import { OID4VCICredentialFormat } from './Generic.types';
|
|
5
|
+
import { OpenId4VCIVersion } from './OpenID4VCIVersions.types';
|
|
6
|
+
import { CredentialOfferPayloadV1_0_08 } from './v1_0_08.types';
|
|
7
|
+
import { CredentialOfferPayloadV1_0_09, CredentialOfferV1_0_09 } from './v1_0_09.types';
|
|
8
|
+
import { CredentialOfferPayloadV1_0_11, CredentialOfferV1_0_11 } from './v1_0_11.types';
|
|
9
|
+
|
|
10
|
+
export interface CredentialResponse {
|
|
11
|
+
credential?: W3CVerifiableCredential; // OPTIONAL. Contains issued Credential. MUST be present when acceptance_token is not returned. MAY be a JSON string or a JSON object, depending on the Credential format. See Appendix E for the Credential format specific encoding requirements
|
|
12
|
+
format: OID4VCICredentialFormat /* | OID4VCICredentialFormat[]*/; // REQUIRED. JSON string denoting the format of the issued Credential
|
|
13
|
+
acceptance_token?: string; // OPTIONAL. A JSON string containing a security token subsequently used to obtain a Credential. MUST be present when credential is not returned
|
|
14
|
+
c_nonce?: string; // OPTIONAL. JSON string containing a nonce to be used to create a proof of possession of key material when requesting a Credential (see Section 7.2). When received, the Wallet MUST use this nonce value for its subsequent credential requests until the Credential Issuer provides a fresh nonce
|
|
15
|
+
c_nonce_expires_in?: number; // OPTIONAL. JSON integer denoting the lifetime in seconds of the c_nonce
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface CredentialOfferRequestWithBaseUrl extends UniformCredentialOfferRequest {
|
|
19
|
+
scheme: string;
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
userPinRequired: boolean;
|
|
22
|
+
issuerState?: string;
|
|
23
|
+
preAuthorizedCode?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type CredentialOffer = CredentialOfferV1_0_09 | CredentialOfferV1_0_11;
|
|
27
|
+
|
|
28
|
+
export type CredentialOfferPayload = CredentialOfferPayloadV1_0_08 | CredentialOfferPayloadV1_0_09 | CredentialOfferPayloadV1_0_11;
|
|
29
|
+
|
|
30
|
+
export interface AssertedUniformCredentialOffer extends UniformCredentialOffer {
|
|
31
|
+
credential_offer: UniformCredentialOfferPayload;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface UniformCredentialOffer {
|
|
35
|
+
credential_offer?: UniformCredentialOfferPayload;
|
|
36
|
+
credential_offer_uri?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface UniformCredentialOfferRequest extends AssertedUniformCredentialOffer {
|
|
40
|
+
original_credential_offer: CredentialOfferPayload;
|
|
41
|
+
version: OpenId4VCIVersion;
|
|
42
|
+
supportedFlows: AuthzFlowType[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type UniformCredentialOfferPayload = CredentialOfferPayloadV1_0_11;
|
|
46
|
+
|
|
47
|
+
export interface ProofOfPossession {
|
|
48
|
+
proof_type: 'jwt';
|
|
49
|
+
jwt: string;
|
|
50
|
+
|
|
51
|
+
[x: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type SearchValue = {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
[Symbol.replace](string: string, replacer: (substring: string, ...args: any[]) => string): string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type EncodeJsonAsURIOpts = {
|
|
60
|
+
uriTypeProperties?: string[];
|
|
61
|
+
arrayTypeProperties?: string[];
|
|
62
|
+
baseUrl?: string;
|
|
63
|
+
param?: string;
|
|
64
|
+
version?: OpenId4VCIVersion;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type DecodeURIAsJsonOpts = {
|
|
68
|
+
requiredProperties?: string[];
|
|
69
|
+
arrayTypeProperties?: string[];
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export interface BaseJWK {
|
|
73
|
+
kty?: string;
|
|
74
|
+
crv?: string;
|
|
75
|
+
x?: string;
|
|
76
|
+
y?: string;
|
|
77
|
+
e?: string;
|
|
78
|
+
n?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface JWK extends BaseJWK {
|
|
82
|
+
alg?: string;
|
|
83
|
+
d?: string;
|
|
84
|
+
dp?: string;
|
|
85
|
+
dq?: string;
|
|
86
|
+
ext?: boolean;
|
|
87
|
+
k?: string;
|
|
88
|
+
key_ops?: string[];
|
|
89
|
+
kid?: string;
|
|
90
|
+
oth?: Array<{
|
|
91
|
+
d?: string;
|
|
92
|
+
r?: string;
|
|
93
|
+
t?: string;
|
|
94
|
+
}>;
|
|
95
|
+
p?: string;
|
|
96
|
+
q?: string;
|
|
97
|
+
qi?: string;
|
|
98
|
+
use?: string;
|
|
99
|
+
x5c?: string[];
|
|
100
|
+
x5t?: string;
|
|
101
|
+
'x5t#S256'?: string;
|
|
102
|
+
x5u?: string;
|
|
103
|
+
[propName: string]: unknown;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface Jwt {
|
|
107
|
+
header: JWTHeader;
|
|
108
|
+
payload: JWTPayload;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface ProofOfPossessionCallbacks {
|
|
112
|
+
signCallback: JWTSignerCallback;
|
|
113
|
+
verifyCallback?: JWTVerifyCallback;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export enum Alg {
|
|
117
|
+
EdDSA = 'EdDSA',
|
|
118
|
+
ES256 = 'ES256',
|
|
119
|
+
ES256K = 'ES256K',
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type Typ =
|
|
123
|
+
| 'jwt'
|
|
124
|
+
// https://www.rfc-editor.org/rfc/rfc8725.pdf#name-use-explicit-typing
|
|
125
|
+
// https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#section-7.2.1-2.1.2.1.2.1.1
|
|
126
|
+
| 'openid4vci-proof+jwt';
|
|
127
|
+
|
|
128
|
+
export interface JoseHeaderParameters {
|
|
129
|
+
kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.
|
|
130
|
+
x5t?: string;
|
|
131
|
+
x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.
|
|
132
|
+
x5u?: string;
|
|
133
|
+
jku?: string;
|
|
134
|
+
jwk?: BaseJWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.
|
|
135
|
+
typ?: string; //JWT always
|
|
136
|
+
cty?: string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export interface JWSHeaderParameters extends JoseHeaderParameters {
|
|
140
|
+
alg?: Alg | string; // REQUIRED by the JWT signer
|
|
141
|
+
b64?: boolean;
|
|
142
|
+
crit?: string[];
|
|
143
|
+
[propName: string]: unknown;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export interface CompactJWSHeaderParameters extends JWSHeaderParameters {
|
|
147
|
+
alg: string;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export interface JWTHeaderParameters extends CompactJWSHeaderParameters {
|
|
151
|
+
b64?: true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type JWTHeader = JWTHeaderParameters;
|
|
155
|
+
|
|
156
|
+
export interface JWTPayload {
|
|
157
|
+
iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.
|
|
158
|
+
aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.
|
|
159
|
+
iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].
|
|
160
|
+
nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow
|
|
161
|
+
jti?: string; // A new nonce chosen by the wallet. Used to prevent replay
|
|
162
|
+
exp?: number; // Not longer than 5 minutes
|
|
163
|
+
[s: string]: unknown;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export type JWTSignerCallback = (jwt: Jwt, kid?: string) => Promise<string>;
|
|
167
|
+
export type JWTVerifyCallback = (args: { jwt: string; kid?: string }) => Promise<Jwt>;
|