@sphereon/oid4vci-common 0.17.0 → 0.17.1-feature.esm.cjs.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1918 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1900 -0
- package/dist/index.d.ts +1900 -8
- package/dist/index.js +1761 -23
- package/dist/index.js.map +1 -1
- package/package.json +22 -13
- package/dist/events/index.d.ts +0 -18
- package/dist/events/index.d.ts.map +0 -1
- package/dist/events/index.js +0 -22
- package/dist/events/index.js.map +0 -1
- package/dist/experimental/holder-vci.d.ts +0 -13
- package/dist/experimental/holder-vci.d.ts.map +0 -1
- package/dist/experimental/holder-vci.js +0 -9
- package/dist/experimental/holder-vci.js.map +0 -1
- package/dist/functions/AuthorizationResponseUtil.d.ts +0 -3
- package/dist/functions/AuthorizationResponseUtil.d.ts.map +0 -1
- package/dist/functions/AuthorizationResponseUtil.js +0 -21
- package/dist/functions/AuthorizationResponseUtil.js.map +0 -1
- package/dist/functions/CredentialOfferUtil.d.ts +0 -30
- package/dist/functions/CredentialOfferUtil.d.ts.map +0 -1
- package/dist/functions/CredentialOfferUtil.js +0 -440
- package/dist/functions/CredentialOfferUtil.js.map +0 -1
- package/dist/functions/CredentialRequestUtil.d.ts +0 -6
- package/dist/functions/CredentialRequestUtil.d.ts.map +0 -1
- package/dist/functions/CredentialRequestUtil.js +0 -68
- package/dist/functions/CredentialRequestUtil.js.map +0 -1
- package/dist/functions/CredentialResponseUtil.d.ts +0 -13
- package/dist/functions/CredentialResponseUtil.d.ts.map +0 -1
- package/dist/functions/CredentialResponseUtil.js +0 -80
- package/dist/functions/CredentialResponseUtil.js.map +0 -1
- package/dist/functions/Encoding.d.ts +0 -28
- package/dist/functions/Encoding.d.ts.map +0 -1
- package/dist/functions/Encoding.js +0 -168
- package/dist/functions/Encoding.js.map +0 -1
- package/dist/functions/FormatUtils.d.ts +0 -15
- package/dist/functions/FormatUtils.d.ts.map +0 -1
- package/dist/functions/FormatUtils.js +0 -44
- package/dist/functions/FormatUtils.js.map +0 -1
- package/dist/functions/HttpUtils.d.ts +0 -33
- package/dist/functions/HttpUtils.d.ts.map +0 -1
- package/dist/functions/HttpUtils.js +0 -147
- package/dist/functions/HttpUtils.js.map +0 -1
- package/dist/functions/IssuerMetadataUtils.d.ts +0 -24
- package/dist/functions/IssuerMetadataUtils.d.ts.map +0 -1
- package/dist/functions/IssuerMetadataUtils.js +0 -175
- package/dist/functions/IssuerMetadataUtils.js.map +0 -1
- package/dist/functions/ProofUtil.d.ts +0 -41
- package/dist/functions/ProofUtil.d.ts.map +0 -1
- package/dist/functions/ProofUtil.js +0 -142
- package/dist/functions/ProofUtil.js.map +0 -1
- package/dist/functions/RandomUtils.d.ts +0 -10
- package/dist/functions/RandomUtils.d.ts.map +0 -1
- package/dist/functions/RandomUtils.js +0 -70
- package/dist/functions/RandomUtils.js.map +0 -1
- package/dist/functions/TypeConversionUtils.d.ts +0 -19
- package/dist/functions/TypeConversionUtils.d.ts.map +0 -1
- package/dist/functions/TypeConversionUtils.js +0 -104
- package/dist/functions/TypeConversionUtils.js.map +0 -1
- package/dist/functions/index.d.ts +0 -14
- package/dist/functions/index.d.ts.map +0 -1
- package/dist/functions/index.js +0 -31
- package/dist/functions/index.js.map +0 -1
- package/dist/functions/randomBytes.d.ts +0 -7
- package/dist/functions/randomBytes.d.ts.map +0 -1
- package/dist/functions/randomBytes.js +0 -56
- package/dist/functions/randomBytes.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/types/Authorization.types.d.ts +0 -409
- package/dist/types/Authorization.types.d.ts.map +0 -1
- package/dist/types/Authorization.types.js +0 -78
- package/dist/types/Authorization.types.js.map +0 -1
- package/dist/types/CredentialIssuance.types.d.ts +0 -145
- package/dist/types/CredentialIssuance.types.d.ts.map +0 -1
- package/dist/types/CredentialIssuance.types.js +0 -27
- package/dist/types/CredentialIssuance.types.js.map +0 -1
- package/dist/types/Generic.types.d.ts +0 -323
- package/dist/types/Generic.types.d.ts.map +0 -1
- package/dist/types/Generic.types.js +0 -6
- package/dist/types/Generic.types.js.map +0 -1
- package/dist/types/OpenID4VCIErrors.d.ts +0 -37
- package/dist/types/OpenID4VCIErrors.d.ts.map +0 -1
- package/dist/types/OpenID4VCIErrors.js +0 -41
- package/dist/types/OpenID4VCIErrors.js.map +0 -1
- package/dist/types/OpenID4VCIVersions.types.d.ts +0 -13
- package/dist/types/OpenID4VCIVersions.types.d.ts.map +0 -1
- package/dist/types/OpenID4VCIVersions.types.js +0 -18
- package/dist/types/OpenID4VCIVersions.types.js.map +0 -1
- package/dist/types/OpenIDClient.d.ts +0 -35
- package/dist/types/OpenIDClient.d.ts.map +0 -1
- package/dist/types/OpenIDClient.js +0 -3
- package/dist/types/OpenIDClient.js.map +0 -1
- package/dist/types/QRCode.types.d.ts +0 -206
- package/dist/types/QRCode.types.d.ts.map +0 -1
- package/dist/types/QRCode.types.js +0 -3
- package/dist/types/QRCode.types.js.map +0 -1
- package/dist/types/ServerMetadata.d.ts +0 -70
- package/dist/types/ServerMetadata.d.ts.map +0 -1
- package/dist/types/ServerMetadata.js +0 -37
- package/dist/types/ServerMetadata.js.map +0 -1
- package/dist/types/StateManager.types.d.ts +0 -65
- package/dist/types/StateManager.types.d.ts.map +0 -1
- package/dist/types/StateManager.types.js +0 -16
- package/dist/types/StateManager.types.js.map +0 -1
- package/dist/types/Token.types.d.ts +0 -16
- package/dist/types/Token.types.d.ts.map +0 -1
- package/dist/types/Token.types.js +0 -31
- package/dist/types/Token.types.js.map +0 -1
- package/dist/types/index.d.ts +0 -15
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -31
- package/dist/types/index.js.map +0 -1
- package/dist/types/v1_0_08.types.d.ts +0 -42
- package/dist/types/v1_0_08.types.d.ts.map +0 -1
- package/dist/types/v1_0_08.types.js +0 -3
- package/dist/types/v1_0_08.types.js.map +0 -1
- package/dist/types/v1_0_09.types.d.ts +0 -29
- package/dist/types/v1_0_09.types.d.ts.map +0 -1
- package/dist/types/v1_0_09.types.js +0 -9
- package/dist/types/v1_0_09.types.js.map +0 -1
- package/dist/types/v1_0_11.types.d.ts +0 -83
- package/dist/types/v1_0_11.types.d.ts.map +0 -1
- package/dist/types/v1_0_11.types.js +0 -9
- package/dist/types/v1_0_11.types.js.map +0 -1
- package/dist/types/v1_0_12.types.d.ts +0 -32
- package/dist/types/v1_0_12.types.d.ts.map +0 -1
- package/dist/types/v1_0_12.types.js +0 -3
- package/dist/types/v1_0_12.types.js.map +0 -1
- package/dist/types/v1_0_13.types.d.ts +0 -166
- package/dist/types/v1_0_13.types.d.ts.map +0 -1
- package/dist/types/v1_0_13.types.js +0 -23
- package/dist/types/v1_0_13.types.js.map +0 -1
- package/lib/__tests__/CredentialOfferUtil.spec.ts +0 -120
- package/lib/__tests__/Encoding.spec.ts +0 -15
- package/lib/__tests__/IssuerMetadataUtils.spec.ts +0 -38
- package/lib/__tests__/randomBytes.spec.ts +0 -15
- package/lib/events/index.ts +0 -21
- package/lib/experimental/holder-vci.ts +0 -19
- package/lib/functions/AuthorizationResponseUtil.ts +0 -20
- package/lib/functions/CredentialOfferUtil.ts +0 -479
- package/lib/functions/CredentialRequestUtil.ts +0 -79
- package/lib/functions/CredentialResponseUtil.ts +0 -90
- package/lib/functions/Encoding.ts +0 -168
- package/lib/functions/FormatUtils.ts +0 -52
- package/lib/functions/HttpUtils.ts +0 -187
- package/lib/functions/IssuerMetadataUtils.ts +0 -206
- package/lib/functions/ProofUtil.ts +0 -188
- package/lib/functions/RandomUtils.ts +0 -43
- package/lib/functions/TypeConversionUtils.ts +0 -134
- package/lib/functions/index.ts +0 -14
- package/lib/functions/randomBytes.js +0 -61
- package/lib/index.ts +0 -9
- package/lib/types/Authorization.types.ts +0 -505
- package/lib/types/CredentialIssuance.types.ts +0 -183
- package/lib/types/Generic.types.ts +0 -437
- package/lib/types/OpenID4VCIErrors.ts +0 -40
- package/lib/types/OpenID4VCIVersions.types.ts +0 -13
- package/lib/types/OpenIDClient.ts +0 -45
- package/lib/types/QRCode.types.ts +0 -227
- package/lib/types/ServerMetadata.ts +0 -153
- package/lib/types/StateManager.types.ts +0 -79
- package/lib/types/Token.types.ts +0 -30
- package/lib/types/index.ts +0 -14
- package/lib/types/v1_0_08.types.ts +0 -49
- package/lib/types/v1_0_09.types.ts +0 -36
- package/lib/types/v1_0_11.types.ts +0 -109
- package/lib/types/v1_0_12.types.ts +0 -42
- package/lib/types/v1_0_13.types.ts +0 -265
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1918 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// lib/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR: () => ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
|
|
35
|
+
ALG_ERROR: () => ALG_ERROR,
|
|
36
|
+
AUD_ERROR: () => AUD_ERROR,
|
|
37
|
+
Alg: () => Alg,
|
|
38
|
+
AuthorizationChallengeError: () => AuthorizationChallengeError,
|
|
39
|
+
AuthzFlowType: () => AuthzFlowType,
|
|
40
|
+
BAD_PARAMS: () => BAD_PARAMS,
|
|
41
|
+
CODE_VERIFIER_DEFAULT_LENGTH: () => CODE_VERIFIER_DEFAULT_LENGTH,
|
|
42
|
+
CREDENTIAL_MISSING_ERROR: () => CREDENTIAL_MISSING_ERROR,
|
|
43
|
+
CodeChallengeMethod: () => CodeChallengeMethod,
|
|
44
|
+
CreateRequestObjectMode: () => CreateRequestObjectMode,
|
|
45
|
+
CredentialEventNames: () => CredentialEventNames,
|
|
46
|
+
CredentialOfferEventNames: () => CredentialOfferEventNames,
|
|
47
|
+
DID_NO_DIDDOC_ERROR: () => DID_NO_DIDDOC_ERROR,
|
|
48
|
+
DefaultURISchemes: () => DefaultURISchemes,
|
|
49
|
+
EVENTS: () => EVENTS,
|
|
50
|
+
EXPERIMENTAL_SUBJECT_PROOF_MODE_ENABLED: () => EXPERIMENTAL_SUBJECT_PROOF_MODE_ENABLED,
|
|
51
|
+
EXPIRED_PRE_AUTHORIZED_CODE: () => EXPIRED_PRE_AUTHORIZED_CODE,
|
|
52
|
+
Encoding: () => Encoding,
|
|
53
|
+
GRANTS_MUST_NOT_BE_UNDEFINED: () => GRANTS_MUST_NOT_BE_UNDEFINED,
|
|
54
|
+
GrantTypes: () => GrantTypes,
|
|
55
|
+
IAT_ERROR: () => IAT_ERROR,
|
|
56
|
+
INVALID_PRE_AUTHORIZED_CODE: () => INVALID_PRE_AUTHORIZED_CODE,
|
|
57
|
+
ISSUER_CONFIG_ERROR: () => ISSUER_CONFIG_ERROR,
|
|
58
|
+
ISS_MUST_BE_CLIENT_ID: () => ISS_MUST_BE_CLIENT_ID,
|
|
59
|
+
ISS_PRESENT_IN_PRE_AUTHORIZED_CODE_CONTEXT: () => ISS_PRESENT_IN_PRE_AUTHORIZED_CODE_CONTEXT,
|
|
60
|
+
IssueStatus: () => IssueStatus,
|
|
61
|
+
JWS_NOT_VALID: () => JWS_NOT_VALID,
|
|
62
|
+
JWT_SIGNER_CALLBACK_REQUIRED_ERROR: () => JWT_SIGNER_CALLBACK_REQUIRED_ERROR,
|
|
63
|
+
JWT_VERIFY_CONFIG_ERROR: () => JWT_VERIFY_CONFIG_ERROR,
|
|
64
|
+
JsonURIMode: () => JsonURIMode,
|
|
65
|
+
KID_DID_NO_DID_ERROR: () => KID_DID_NO_DID_ERROR,
|
|
66
|
+
KID_JWK_X5C_ERROR: () => KID_JWK_X5C_ERROR,
|
|
67
|
+
NONCE_ERROR: () => NONCE_ERROR,
|
|
68
|
+
NONCE_LENGTH: () => NONCE_LENGTH,
|
|
69
|
+
NONCE_STATE_MANAGER_REQUIRED_ERROR: () => NONCE_STATE_MANAGER_REQUIRED_ERROR,
|
|
70
|
+
NO_ISS_IN_AUTHORIZATION_CODE_CONTEXT: () => NO_ISS_IN_AUTHORIZATION_CODE_CONTEXT,
|
|
71
|
+
NO_JWT_PROVIDED: () => NO_JWT_PROVIDED,
|
|
72
|
+
NotificationStatusEventNames: () => NotificationStatusEventNames,
|
|
73
|
+
OpenId4VCIVersion: () => OpenId4VCIVersion,
|
|
74
|
+
PARMode: () => PARMode,
|
|
75
|
+
PIN_NOT_MATCH_ERROR: () => PIN_NOT_MATCH_ERROR,
|
|
76
|
+
PIN_VALIDATION_ERROR: () => PIN_VALIDATION_ERROR,
|
|
77
|
+
PRE_AUTHORIZED_CODE_REQUIRED_ERROR: () => PRE_AUTHORIZED_CODE_REQUIRED_ERROR,
|
|
78
|
+
PRE_AUTH_CODE_LITERAL: () => PRE_AUTH_CODE_LITERAL,
|
|
79
|
+
PRE_AUTH_GRANT_LITERAL: () => PRE_AUTH_GRANT_LITERAL,
|
|
80
|
+
PROOF_CANT_BE_CONSTRUCTED: () => PROOF_CANT_BE_CONSTRUCTED,
|
|
81
|
+
ResponseType: () => ResponseType,
|
|
82
|
+
STATE_MANAGER_REQUIRED_ERROR: () => STATE_MANAGER_REQUIRED_ERROR,
|
|
83
|
+
STATE_MISSING_ERROR: () => STATE_MISSING_ERROR,
|
|
84
|
+
TYP_ERROR: () => TYP_ERROR,
|
|
85
|
+
TokenError: () => TokenError,
|
|
86
|
+
TokenErrorResponse: () => TokenErrorResponse,
|
|
87
|
+
UNKNOWN_CLIENT_ERROR: () => UNKNOWN_CLIENT_ERROR,
|
|
88
|
+
UNSUPPORTED_GRANT_TYPE_ERROR: () => UNSUPPORTED_GRANT_TYPE_ERROR,
|
|
89
|
+
URL_NOT_VALID: () => URL_NOT_VALID,
|
|
90
|
+
USER_PIN_NOT_REQUIRED_ERROR: () => USER_PIN_NOT_REQUIRED_ERROR,
|
|
91
|
+
USER_PIN_REQUIRED_ERROR: () => USER_PIN_REQUIRED_ERROR,
|
|
92
|
+
USER_PIN_TX_CODE_SPEC_ERROR: () => USER_PIN_TX_CODE_SPEC_ERROR,
|
|
93
|
+
VCI_LOGGERS: () => VCI_LOGGERS,
|
|
94
|
+
VCI_LOG_COMMON: () => VCI_LOG_COMMON,
|
|
95
|
+
WRONG_METADATA_FORMAT: () => WRONG_METADATA_FORMAT,
|
|
96
|
+
WellKnownEndpoints: () => WellKnownEndpoints,
|
|
97
|
+
acquireDeferredCredential: () => acquireDeferredCredential,
|
|
98
|
+
adjustUrl: () => adjustUrl,
|
|
99
|
+
assertValidCodeVerifier: () => assertValidCodeVerifier,
|
|
100
|
+
assertedUniformCredentialOffer: () => assertedUniformCredentialOffer,
|
|
101
|
+
authorizationServerMetadataFieldNames: () => authorizationServerMetadataFieldNames,
|
|
102
|
+
convertJsonToURI: () => convertJsonToURI,
|
|
103
|
+
convertURIToJsonObject: () => convertURIToJsonObject,
|
|
104
|
+
createCodeChallenge: () => createCodeChallenge,
|
|
105
|
+
createProofOfPossession: () => createProofOfPossession,
|
|
106
|
+
credentialIssuerMetadataFieldNames: () => credentialIssuerMetadataFieldNames,
|
|
107
|
+
credentialSupportedV8ToV13: () => credentialSupportedV8ToV13,
|
|
108
|
+
credentialsSupportedV8ToV13: () => credentialsSupportedV8ToV13,
|
|
109
|
+
decodeJsonProperties: () => decodeJsonProperties,
|
|
110
|
+
determineFlowType: () => determineFlowType,
|
|
111
|
+
determineGrantTypes: () => determineGrantTypes,
|
|
112
|
+
determineSpecVersionFromOffer: () => determineSpecVersionFromOffer,
|
|
113
|
+
determineSpecVersionFromScheme: () => determineSpecVersionFromScheme,
|
|
114
|
+
determineSpecVersionFromURI: () => determineSpecVersionFromURI,
|
|
115
|
+
determineVersionsFromIssuerMetadata: () => determineVersionsFromIssuerMetadata,
|
|
116
|
+
extractBearerToken: () => extractBearerToken,
|
|
117
|
+
formPost: () => formPost,
|
|
118
|
+
generateCodeVerifier: () => generateCodeVerifier,
|
|
119
|
+
generateNonce: () => generateNonce,
|
|
120
|
+
generateRandomString: () => generateRandomString,
|
|
121
|
+
getClientIdFromCredentialOfferPayload: () => getClientIdFromCredentialOfferPayload,
|
|
122
|
+
getCredentialOfferPayload: () => getCredentialOfferPayload,
|
|
123
|
+
getCredentialRequestForVersion: () => getCredentialRequestForVersion,
|
|
124
|
+
getFormatForVersion: () => getFormatForVersion,
|
|
125
|
+
getIssuerDisplays: () => getIssuerDisplays,
|
|
126
|
+
getIssuerFromCredentialOfferPayload: () => getIssuerFromCredentialOfferPayload,
|
|
127
|
+
getIssuerName: () => getIssuerName,
|
|
128
|
+
getJson: () => getJson,
|
|
129
|
+
getNumberOrUndefined: () => getNumberOrUndefined,
|
|
130
|
+
getScheme: () => getScheme,
|
|
131
|
+
getStateFromCredentialOfferPayload: () => getStateFromCredentialOfferPayload,
|
|
132
|
+
getSupportedCredential: () => getSupportedCredential,
|
|
133
|
+
getSupportedCredentials: () => getSupportedCredentials,
|
|
134
|
+
getTypesFromAuthorizationDetails: () => getTypesFromAuthorizationDetails,
|
|
135
|
+
getTypesFromCredentialOffer: () => getTypesFromCredentialOffer,
|
|
136
|
+
getTypesFromCredentialSupported: () => getTypesFromCredentialSupported,
|
|
137
|
+
getTypesFromObject: () => getTypesFromObject,
|
|
138
|
+
getTypesFromOfferV1_0_11: () => getTypesFromOfferV1_0_11,
|
|
139
|
+
getTypesFromRequest: () => getTypesFromRequest,
|
|
140
|
+
getURIComponentsAsArray: () => getURIComponentsAsArray,
|
|
141
|
+
getUniformFormat: () => getUniformFormat,
|
|
142
|
+
isAuthorizationRequestV1_0_09: () => isAuthorizationRequestV1_0_09,
|
|
143
|
+
isAuthorizationRequestV1_0_11: () => isAuthorizationRequestV1_0_11,
|
|
144
|
+
isCredentialOfferVersion: () => isCredentialOfferVersion,
|
|
145
|
+
isDeferredCredentialIssuancePending: () => isDeferredCredentialIssuancePending,
|
|
146
|
+
isDeferredCredentialResponse: () => isDeferredCredentialResponse,
|
|
147
|
+
isFormat: () => isFormat,
|
|
148
|
+
isJWS: () => isJWS,
|
|
149
|
+
isNotFormat: () => isNotFormat,
|
|
150
|
+
isPreAuthCode: () => isPreAuthCode,
|
|
151
|
+
isValidURL: () => isValidURL,
|
|
152
|
+
isW3cCredentialSupported: () => isW3cCredentialSupported,
|
|
153
|
+
post: () => post,
|
|
154
|
+
randomBytes: () => randomBytes,
|
|
155
|
+
resolveCredentialOfferURI: () => resolveCredentialOfferURI,
|
|
156
|
+
toAuthorizationResponsePayload: () => toAuthorizationResponsePayload,
|
|
157
|
+
toUniformCredentialOfferPayload: () => toUniformCredentialOfferPayload,
|
|
158
|
+
toUniformCredentialOfferRequest: () => toUniformCredentialOfferRequest,
|
|
159
|
+
trimBoth: () => trimBoth,
|
|
160
|
+
trimEnd: () => trimEnd,
|
|
161
|
+
trimStart: () => trimStart,
|
|
162
|
+
validateJWT: () => validateJWT
|
|
163
|
+
});
|
|
164
|
+
module.exports = __toCommonJS(index_exports);
|
|
165
|
+
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
166
|
+
|
|
167
|
+
// lib/functions/randomBytes.cjs
|
|
168
|
+
var MAX_BYTES = 65536;
|
|
169
|
+
var MAX_UINT32 = 4294967295;
|
|
170
|
+
function oldBrowser() {
|
|
171
|
+
throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11");
|
|
172
|
+
}
|
|
173
|
+
__name(oldBrowser, "oldBrowser");
|
|
174
|
+
var _global = typeof globalThis !== "undefined" ? globalThis : global;
|
|
175
|
+
var crypto = _global.crypto || _global.msCrypto;
|
|
176
|
+
if (!crypto) {
|
|
177
|
+
try {
|
|
178
|
+
crypto = require("crypto");
|
|
179
|
+
} catch (err) {
|
|
180
|
+
throw Error("crypto module is not available");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
var randomBytes = /* @__PURE__ */ __name((size) => {
|
|
184
|
+
if (size > MAX_UINT32) throw new Error("requested too many random bytes");
|
|
185
|
+
const bytes = Buffer.allocUnsafe(size);
|
|
186
|
+
if (size > 0) {
|
|
187
|
+
if (size > MAX_BYTES) {
|
|
188
|
+
for (let generated = 0; generated < size; generated += MAX_BYTES) {
|
|
189
|
+
crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES));
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
crypto.getRandomValues(bytes);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return Uint8Array.from(bytes);
|
|
196
|
+
}, "randomBytes");
|
|
197
|
+
if (crypto && crypto.getRandomValues) {
|
|
198
|
+
module.exports = randomBytes;
|
|
199
|
+
} else {
|
|
200
|
+
module.exports = oldBrowser;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// lib/types/Generic.types.ts
|
|
204
|
+
var PRE_AUTH_CODE_LITERAL = "pre-authorized_code";
|
|
205
|
+
var PRE_AUTH_GRANT_LITERAL = "urn:ietf:params:oauth:grant-type:pre-authorized_code";
|
|
206
|
+
|
|
207
|
+
// lib/types/Authorization.types.ts
|
|
208
|
+
var AuthorizationChallengeError = /* @__PURE__ */ function(AuthorizationChallengeError2) {
|
|
209
|
+
AuthorizationChallengeError2["invalid_request"] = "invalid_request";
|
|
210
|
+
AuthorizationChallengeError2["invalid_client"] = "invalid_client";
|
|
211
|
+
AuthorizationChallengeError2["unauthorized_client"] = "unauthorized_client";
|
|
212
|
+
AuthorizationChallengeError2["invalid_session"] = "invalid_session";
|
|
213
|
+
AuthorizationChallengeError2["invalid_scope"] = "invalid_scope";
|
|
214
|
+
AuthorizationChallengeError2["insufficient_authorization"] = "insufficient_authorization";
|
|
215
|
+
AuthorizationChallengeError2["redirect_to_web"] = "redirect_to_web";
|
|
216
|
+
return AuthorizationChallengeError2;
|
|
217
|
+
}({});
|
|
218
|
+
var GrantTypes = /* @__PURE__ */ function(GrantTypes2) {
|
|
219
|
+
GrantTypes2["AUTHORIZATION_CODE"] = "authorization_code";
|
|
220
|
+
GrantTypes2["PRE_AUTHORIZED_CODE"] = "urn:ietf:params:oauth:grant-type:pre-authorized_code";
|
|
221
|
+
GrantTypes2["PASSWORD"] = "password";
|
|
222
|
+
return GrantTypes2;
|
|
223
|
+
}({});
|
|
224
|
+
var Encoding = /* @__PURE__ */ function(Encoding2) {
|
|
225
|
+
Encoding2["FORM_URL_ENCODED"] = "application/x-www-form-urlencoded";
|
|
226
|
+
Encoding2["UTF_8"] = "UTF-8";
|
|
227
|
+
return Encoding2;
|
|
228
|
+
}({});
|
|
229
|
+
var ResponseType = /* @__PURE__ */ function(ResponseType2) {
|
|
230
|
+
ResponseType2["AUTH_CODE"] = "code";
|
|
231
|
+
return ResponseType2;
|
|
232
|
+
}({});
|
|
233
|
+
var CodeChallengeMethod = /* @__PURE__ */ function(CodeChallengeMethod2) {
|
|
234
|
+
CodeChallengeMethod2["plain"] = "plain";
|
|
235
|
+
CodeChallengeMethod2["S256"] = "S256";
|
|
236
|
+
return CodeChallengeMethod2;
|
|
237
|
+
}({});
|
|
238
|
+
var PARMode = /* @__PURE__ */ function(PARMode2) {
|
|
239
|
+
PARMode2[PARMode2["REQUIRE"] = 0] = "REQUIRE";
|
|
240
|
+
PARMode2[PARMode2["AUTO"] = 1] = "AUTO";
|
|
241
|
+
PARMode2[PARMode2["NEVER"] = 2] = "NEVER";
|
|
242
|
+
return PARMode2;
|
|
243
|
+
}({});
|
|
244
|
+
var CreateRequestObjectMode = /* @__PURE__ */ function(CreateRequestObjectMode2) {
|
|
245
|
+
CreateRequestObjectMode2[CreateRequestObjectMode2["NONE"] = 0] = "NONE";
|
|
246
|
+
CreateRequestObjectMode2[CreateRequestObjectMode2["REQUEST_OBJECT"] = 1] = "REQUEST_OBJECT";
|
|
247
|
+
CreateRequestObjectMode2[CreateRequestObjectMode2["REQUEST_URI"] = 2] = "REQUEST_URI";
|
|
248
|
+
return CreateRequestObjectMode2;
|
|
249
|
+
}({});
|
|
250
|
+
var AuthzFlowType = /* @__PURE__ */ function(AuthzFlowType2) {
|
|
251
|
+
AuthzFlowType2["AUTHORIZATION_CODE_FLOW"] = "Authorization Code Flow";
|
|
252
|
+
AuthzFlowType2["PRE_AUTHORIZED_CODE_FLOW"] = "Pre-Authorized Code Flow";
|
|
253
|
+
return AuthzFlowType2;
|
|
254
|
+
}({});
|
|
255
|
+
(function(AuthzFlowType2) {
|
|
256
|
+
function valueOf(request) {
|
|
257
|
+
if (PRE_AUTH_CODE_LITERAL in request) {
|
|
258
|
+
return "Pre-Authorized Code Flow";
|
|
259
|
+
}
|
|
260
|
+
return "Authorization Code Flow";
|
|
261
|
+
}
|
|
262
|
+
__name(valueOf, "valueOf");
|
|
263
|
+
AuthzFlowType2.valueOf = valueOf;
|
|
264
|
+
})(AuthzFlowType || (AuthzFlowType = {}));
|
|
265
|
+
|
|
266
|
+
// lib/types/CredentialIssuance.types.ts
|
|
267
|
+
var JsonURIMode = /* @__PURE__ */ function(JsonURIMode2) {
|
|
268
|
+
JsonURIMode2[JsonURIMode2["JSON_STRINGIFY"] = 0] = "JSON_STRINGIFY";
|
|
269
|
+
JsonURIMode2[JsonURIMode2["X_FORM_WWW_URLENCODED"] = 1] = "X_FORM_WWW_URLENCODED";
|
|
270
|
+
return JsonURIMode2;
|
|
271
|
+
}({});
|
|
272
|
+
var Alg = /* @__PURE__ */ function(Alg2) {
|
|
273
|
+
Alg2["EdDSA"] = "EdDSA";
|
|
274
|
+
Alg2["ES256"] = "ES256";
|
|
275
|
+
Alg2["ES256K"] = "ES256K";
|
|
276
|
+
Alg2["PS256"] = "PS256";
|
|
277
|
+
Alg2["PS384"] = "PS384";
|
|
278
|
+
Alg2["PS512"] = "PS512";
|
|
279
|
+
Alg2["RS256"] = "RS256";
|
|
280
|
+
Alg2["RS384"] = "RS384";
|
|
281
|
+
Alg2["RS512"] = "RS512";
|
|
282
|
+
return Alg2;
|
|
283
|
+
}({});
|
|
284
|
+
|
|
285
|
+
// lib/types/v1_0_09.types.ts
|
|
286
|
+
function isAuthorizationRequestV1_0_09(request) {
|
|
287
|
+
return request && "op_state" in request;
|
|
288
|
+
}
|
|
289
|
+
__name(isAuthorizationRequestV1_0_09, "isAuthorizationRequestV1_0_09");
|
|
290
|
+
|
|
291
|
+
// lib/types/v1_0_11.types.ts
|
|
292
|
+
function isAuthorizationRequestV1_0_11(request) {
|
|
293
|
+
return request && "issuer_state" in request;
|
|
294
|
+
}
|
|
295
|
+
__name(isAuthorizationRequestV1_0_11, "isAuthorizationRequestV1_0_11");
|
|
296
|
+
|
|
297
|
+
// lib/types/v1_0_13.types.ts
|
|
298
|
+
var credentialIssuerMetadataFieldNames = [
|
|
299
|
+
// Required fields
|
|
300
|
+
"credential_issuer",
|
|
301
|
+
"credential_configurations_supported",
|
|
302
|
+
"credential_endpoint",
|
|
303
|
+
// Optional fields from CredentialIssuerMetadataOpts
|
|
304
|
+
"batch_credential_endpoint",
|
|
305
|
+
"deferred_credential_endpoint",
|
|
306
|
+
"notification_endpoint",
|
|
307
|
+
"credential_response_encryption",
|
|
308
|
+
"authorization_servers",
|
|
309
|
+
"token_endpoint",
|
|
310
|
+
"display",
|
|
311
|
+
"credential_supplier_config",
|
|
312
|
+
// Optional fields from v1.0.13
|
|
313
|
+
"credential_identifiers_supported",
|
|
314
|
+
"signed_metadata"
|
|
315
|
+
];
|
|
316
|
+
|
|
317
|
+
// lib/types/ServerMetadata.ts
|
|
318
|
+
var authorizationServerMetadataFieldNames = [
|
|
319
|
+
"issuer",
|
|
320
|
+
"authorization_endpoint",
|
|
321
|
+
"authorization_challenge_endpoint",
|
|
322
|
+
"token_endpoint",
|
|
323
|
+
"jwks_uri",
|
|
324
|
+
"registration_endpoint",
|
|
325
|
+
"scopes_supported",
|
|
326
|
+
"response_types_supported",
|
|
327
|
+
"response_modes_supported",
|
|
328
|
+
"grant_types_supported",
|
|
329
|
+
"token_endpoint_auth_methods_supported",
|
|
330
|
+
"token_endpoint_auth_signing_alg_values_supported",
|
|
331
|
+
"service_documentation",
|
|
332
|
+
"ui_locales_supported",
|
|
333
|
+
"op_policy_uri",
|
|
334
|
+
"op_tos_uri",
|
|
335
|
+
"revocation_endpoint",
|
|
336
|
+
"revocation_endpoint_auth_methods_supported",
|
|
337
|
+
"revocation_endpoint_auth_signing_alg_values_supported",
|
|
338
|
+
"introspection_endpoint",
|
|
339
|
+
"introspection_endpoint_auth_methods_supported",
|
|
340
|
+
"introspection_endpoint_auth_signing_alg_values_supported",
|
|
341
|
+
"code_challenge_methods_supported",
|
|
342
|
+
"signed_metadata"
|
|
343
|
+
];
|
|
344
|
+
var WellKnownEndpoints = /* @__PURE__ */ function(WellKnownEndpoints2) {
|
|
345
|
+
WellKnownEndpoints2["OPENID_CONFIGURATION"] = "/.well-known/openid-configuration";
|
|
346
|
+
WellKnownEndpoints2["OAUTH_AS"] = "/.well-known/oauth-authorization-server";
|
|
347
|
+
WellKnownEndpoints2["OPENID4VCI_ISSUER"] = "/.well-known/openid-credential-issuer";
|
|
348
|
+
return WellKnownEndpoints2;
|
|
349
|
+
}({});
|
|
350
|
+
|
|
351
|
+
// lib/types/OpenID4VCIErrors.ts
|
|
352
|
+
var BAD_PARAMS = "Wrong parameters provided";
|
|
353
|
+
var URL_NOT_VALID = "Request url is not valid";
|
|
354
|
+
var JWS_NOT_VALID = "JWS is not valid";
|
|
355
|
+
var PROOF_CANT_BE_CONSTRUCTED = "Proof can't be constructed.";
|
|
356
|
+
var NO_JWT_PROVIDED = "No JWT provided";
|
|
357
|
+
var TYP_ERROR = 'Typ must be "openid4vci-proof+jwt"';
|
|
358
|
+
var ALG_ERROR = `Algorithm is a required field, you are free to use the signing algorithm of your choice or one of the following: ${Object.keys(Alg).join(", ")}`;
|
|
359
|
+
var KID_JWK_X5C_ERROR = "Only one must be present: x5c should not present when kid and/or jwk is already present";
|
|
360
|
+
var KID_DID_NO_DID_ERROR = "A DID value needs to be returned when kid is present";
|
|
361
|
+
var DID_NO_DIDDOC_ERROR = "A DID Document needs to be resolved when a DID is encountered";
|
|
362
|
+
var AUD_ERROR = "aud must be the URL of the credential issuer";
|
|
363
|
+
var IAT_ERROR = "iat must be the time at which the proof was issued";
|
|
364
|
+
var NONCE_ERROR = "nonce must be c_nonce provided by the credential issuer";
|
|
365
|
+
var JWT_VERIFY_CONFIG_ERROR = "JWT verify callback not configured correctly.";
|
|
366
|
+
var ISSUER_CONFIG_ERROR = "Issuer not configured correctly.";
|
|
367
|
+
var UNKNOWN_CLIENT_ERROR = "The client is not known by the issuer";
|
|
368
|
+
var NO_ISS_IN_AUTHORIZATION_CODE_CONTEXT = "iss missing in authorization-code context";
|
|
369
|
+
var ISS_PRESENT_IN_PRE_AUTHORIZED_CODE_CONTEXT = "iss should be omitted in pre-authorized-code context";
|
|
370
|
+
var ISS_MUST_BE_CLIENT_ID = "iss must be the client id";
|
|
371
|
+
var GRANTS_MUST_NOT_BE_UNDEFINED = "Grants must not be undefined";
|
|
372
|
+
var STATE_MISSING_ERROR = "issuer state or pre-authorized key not found";
|
|
373
|
+
var CREDENTIAL_MISSING_ERROR = "Credential must be present in response";
|
|
374
|
+
var UNSUPPORTED_GRANT_TYPE_ERROR = "unsupported grant_type";
|
|
375
|
+
var PRE_AUTHORIZED_CODE_REQUIRED_ERROR = "pre-authorized_code is required";
|
|
376
|
+
var USER_PIN_REQUIRED_ERROR = "User pin is required";
|
|
377
|
+
var USER_PIN_TX_CODE_SPEC_ERROR = "user_pin is mixed with tx_code, indicating a spec mismatch";
|
|
378
|
+
var USER_PIN_NOT_REQUIRED_ERROR = "User pin is not required";
|
|
379
|
+
var PIN_VALIDATION_ERROR = "PIN must consist the following amount of characters:";
|
|
380
|
+
var PIN_NOT_MATCH_ERROR = "PIN is invalid";
|
|
381
|
+
var INVALID_PRE_AUTHORIZED_CODE = "pre-authorized_code is invalid";
|
|
382
|
+
var EXPIRED_PRE_AUTHORIZED_CODE = "pre-authorized_code is expired";
|
|
383
|
+
var JWT_SIGNER_CALLBACK_REQUIRED_ERROR = "JWT signer callback function is required";
|
|
384
|
+
var STATE_MANAGER_REQUIRED_ERROR = "StateManager instance is required";
|
|
385
|
+
var NONCE_STATE_MANAGER_REQUIRED_ERROR = "NonceStateManager instance is required";
|
|
386
|
+
var ACCESS_TOKEN_ISSUER_REQUIRED_ERROR = "access token issuer is required";
|
|
387
|
+
var WRONG_METADATA_FORMAT = "Wrong metadata format";
|
|
388
|
+
|
|
389
|
+
// lib/types/OpenID4VCIVersions.types.ts
|
|
390
|
+
var OpenId4VCIVersion = /* @__PURE__ */ function(OpenId4VCIVersion2) {
|
|
391
|
+
OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0_08"] = 1008] = "VER_1_0_08";
|
|
392
|
+
OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0_09"] = 1009] = "VER_1_0_09";
|
|
393
|
+
OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0_11"] = 1011] = "VER_1_0_11";
|
|
394
|
+
OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0_12"] = 1012] = "VER_1_0_12";
|
|
395
|
+
OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0_13"] = 1013] = "VER_1_0_13";
|
|
396
|
+
OpenId4VCIVersion2[OpenId4VCIVersion2["VER_UNKNOWN"] = Number.MAX_VALUE] = "VER_UNKNOWN";
|
|
397
|
+
return OpenId4VCIVersion2;
|
|
398
|
+
}({});
|
|
399
|
+
var DefaultURISchemes = /* @__PURE__ */ function(DefaultURISchemes2) {
|
|
400
|
+
DefaultURISchemes2["INITIATE_ISSUANCE"] = "openid-initiate-issuance";
|
|
401
|
+
DefaultURISchemes2["CREDENTIAL_OFFER"] = "openid-credential-offer";
|
|
402
|
+
return DefaultURISchemes2;
|
|
403
|
+
}({});
|
|
404
|
+
|
|
405
|
+
// lib/types/StateManager.types.ts
|
|
406
|
+
var IssueStatus = /* @__PURE__ */ function(IssueStatus2) {
|
|
407
|
+
IssueStatus2["OFFER_CREATED"] = "OFFER_CREATED";
|
|
408
|
+
IssueStatus2["ACCESS_TOKEN_REQUESTED"] = "ACCESS_TOKEN_REQUESTED";
|
|
409
|
+
IssueStatus2["ACCESS_TOKEN_CREATED"] = "ACCESS_TOKEN_CREATED";
|
|
410
|
+
IssueStatus2["CREDENTIAL_REQUEST_RECEIVED"] = "CREDENTIAL_REQUEST_RECEIVED";
|
|
411
|
+
IssueStatus2["CREDENTIAL_ISSUED"] = "CREDENTIAL_ISSUED";
|
|
412
|
+
IssueStatus2["NOTIFICATION_CREDENTIAL_ACCEPTED"] = "NOTIFICATION_CREDENTIAL_ACCEPTED";
|
|
413
|
+
IssueStatus2["NOTIFICATION_CREDENTIAL_DELETED"] = "NOTIFICATION_CREDENTIAL_DELETED";
|
|
414
|
+
IssueStatus2["NOTIFICATION_CREDENTIAL_FAILURE"] = "NOTIFICATION_CREDENTIAL_FAILURE";
|
|
415
|
+
IssueStatus2["ERROR"] = "ERROR";
|
|
416
|
+
return IssueStatus2;
|
|
417
|
+
}({});
|
|
418
|
+
|
|
419
|
+
// lib/types/Token.types.ts
|
|
420
|
+
var TokenErrorResponse = /* @__PURE__ */ function(TokenErrorResponse2) {
|
|
421
|
+
TokenErrorResponse2["invalid_request"] = "invalid_request";
|
|
422
|
+
TokenErrorResponse2["invalid_grant"] = "invalid_grant";
|
|
423
|
+
TokenErrorResponse2["invalid_client"] = "invalid_client";
|
|
424
|
+
TokenErrorResponse2["invalid_scope"] = "invalid_scope";
|
|
425
|
+
TokenErrorResponse2["invalid_dpop_proof"] = "invalid_dpop_proof";
|
|
426
|
+
return TokenErrorResponse2;
|
|
427
|
+
}({});
|
|
428
|
+
var TokenError = class _TokenError extends Error {
|
|
429
|
+
static {
|
|
430
|
+
__name(this, "TokenError");
|
|
431
|
+
}
|
|
432
|
+
_statusCode;
|
|
433
|
+
_responseError;
|
|
434
|
+
constructor(statusCode, responseError, message) {
|
|
435
|
+
super(message);
|
|
436
|
+
this._statusCode = statusCode;
|
|
437
|
+
this._responseError = responseError;
|
|
438
|
+
Object.setPrototypeOf(this, _TokenError.prototype);
|
|
439
|
+
}
|
|
440
|
+
get statusCode() {
|
|
441
|
+
return this._statusCode;
|
|
442
|
+
}
|
|
443
|
+
get responseError() {
|
|
444
|
+
return this._responseError;
|
|
445
|
+
}
|
|
446
|
+
getDescription() {
|
|
447
|
+
return this.message;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// lib/functions/FormatUtils.ts
|
|
452
|
+
function isFormat(formatObject, format) {
|
|
453
|
+
return formatObject.format === format;
|
|
454
|
+
}
|
|
455
|
+
__name(isFormat, "isFormat");
|
|
456
|
+
function isNotFormat(formatObject, format) {
|
|
457
|
+
return formatObject.format !== format;
|
|
458
|
+
}
|
|
459
|
+
__name(isNotFormat, "isNotFormat");
|
|
460
|
+
var isUniformFormat = /* @__PURE__ */ __name((format) => {
|
|
461
|
+
return [
|
|
462
|
+
"jwt_vc_json",
|
|
463
|
+
"jwt_vc_json-ld",
|
|
464
|
+
"ldp_vc",
|
|
465
|
+
"vc+sd-jwt",
|
|
466
|
+
"mso_mdoc"
|
|
467
|
+
].includes(format);
|
|
468
|
+
}, "isUniformFormat");
|
|
469
|
+
function getUniformFormat(format) {
|
|
470
|
+
if (isUniformFormat(format)) {
|
|
471
|
+
return format;
|
|
472
|
+
}
|
|
473
|
+
if (format.toLocaleLowerCase() === "jwt_vc" || format.toLocaleLowerCase() === "jwt") {
|
|
474
|
+
return "jwt_vc";
|
|
475
|
+
}
|
|
476
|
+
if (format === "ldp_vc" || format === "ldp") {
|
|
477
|
+
return "ldp_vc";
|
|
478
|
+
}
|
|
479
|
+
throw new Error(`Invalid format: ${format}`);
|
|
480
|
+
}
|
|
481
|
+
__name(getUniformFormat, "getUniformFormat");
|
|
482
|
+
function getFormatForVersion(format, version) {
|
|
483
|
+
const uniformFormat = isUniformFormat(format) ? format : getUniformFormat(format);
|
|
484
|
+
if (version === OpenId4VCIVersion.VER_1_0_08) {
|
|
485
|
+
if (uniformFormat === "jwt_vc_json") {
|
|
486
|
+
return "jwt_vc";
|
|
487
|
+
} else if (uniformFormat === "ldp_vc" || uniformFormat === "jwt_vc_json-ld") {
|
|
488
|
+
return "ldp_vc";
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
return uniformFormat;
|
|
492
|
+
}
|
|
493
|
+
__name(getFormatForVersion, "getFormatForVersion");
|
|
494
|
+
|
|
495
|
+
// lib/functions/CredentialRequestUtil.ts
|
|
496
|
+
function getTypesFromRequest(credentialRequest, opts) {
|
|
497
|
+
let types = [];
|
|
498
|
+
if ("credential_identifier" in credentialRequest && credentialRequest.credential_identifier) {
|
|
499
|
+
throw Error(`Cannot get types from request when it contains a credential_identifier`);
|
|
500
|
+
} else if (credentialRequest.format === "jwt_vc_json-ld" || credentialRequest.format === "ldp_vc" || credentialRequest.format === "jwt_vc" || credentialRequest.format === "jwt_vc_json") {
|
|
501
|
+
if ("credential_definition" in credentialRequest && credentialRequest.credential_definition) {
|
|
502
|
+
types = "types" in credentialRequest.credential_definition ? credentialRequest.credential_definition.types : credentialRequest.credential_definition.type;
|
|
503
|
+
}
|
|
504
|
+
if ("type" in credentialRequest && Array.isArray(credentialRequest.type)) {
|
|
505
|
+
types = credentialRequest.type;
|
|
506
|
+
}
|
|
507
|
+
if ("types" in credentialRequest && Array.isArray(credentialRequest.types)) {
|
|
508
|
+
types = credentialRequest.types;
|
|
509
|
+
}
|
|
510
|
+
} else if (credentialRequest.format === "vc+sd-jwt" && "vct" in credentialRequest) {
|
|
511
|
+
types = [
|
|
512
|
+
credentialRequest.vct
|
|
513
|
+
];
|
|
514
|
+
} else if (credentialRequest.format === "mso_mdoc" && "doctype" in credentialRequest) {
|
|
515
|
+
types = [
|
|
516
|
+
credentialRequest.doctype
|
|
517
|
+
];
|
|
518
|
+
}
|
|
519
|
+
if (!types || types.length === 0) {
|
|
520
|
+
throw Error("Could not deduce types from credential request");
|
|
521
|
+
}
|
|
522
|
+
if (opts?.filterVerifiableCredential) {
|
|
523
|
+
return types.filter((type) => type !== "VerifiableCredential");
|
|
524
|
+
}
|
|
525
|
+
return types;
|
|
526
|
+
}
|
|
527
|
+
__name(getTypesFromRequest, "getTypesFromRequest");
|
|
528
|
+
function getCredentialRequestForVersion(credentialRequest, version) {
|
|
529
|
+
if (version === OpenId4VCIVersion.VER_1_0_08) {
|
|
530
|
+
const draft8Format = getFormatForVersion(credentialRequest.format, version);
|
|
531
|
+
const types = getTypesFromRequest(credentialRequest, {
|
|
532
|
+
filterVerifiableCredential: true
|
|
533
|
+
});
|
|
534
|
+
if (credentialRequest.credential_subject_issuance) {
|
|
535
|
+
throw Error("Experimental subject issuance is not supported for older versions of the spec");
|
|
536
|
+
}
|
|
537
|
+
return {
|
|
538
|
+
format: draft8Format,
|
|
539
|
+
proof: credentialRequest.proof,
|
|
540
|
+
type: types[0]
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
return credentialRequest;
|
|
544
|
+
}
|
|
545
|
+
__name(getCredentialRequestForVersion, "getCredentialRequestForVersion");
|
|
546
|
+
|
|
547
|
+
// lib/functions/HttpUtils.ts
|
|
548
|
+
var import_cross_fetch = require("cross-fetch");
|
|
549
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
550
|
+
var debug = (0, import_debug.default)("sphereon:openid4vci:http");
|
|
551
|
+
var getJson = /* @__PURE__ */ __name(async (URL1, opts) => {
|
|
552
|
+
return await openIdFetch(URL1, void 0, {
|
|
553
|
+
method: "GET",
|
|
554
|
+
...opts
|
|
555
|
+
});
|
|
556
|
+
}, "getJson");
|
|
557
|
+
var formPost = /* @__PURE__ */ __name(async (url, body, opts) => {
|
|
558
|
+
return await post(url, body, opts?.contentType ? {
|
|
559
|
+
...opts
|
|
560
|
+
} : {
|
|
561
|
+
contentType: Encoding.FORM_URL_ENCODED,
|
|
562
|
+
...opts
|
|
563
|
+
});
|
|
564
|
+
}, "formPost");
|
|
565
|
+
var post = /* @__PURE__ */ __name(async (url, body, opts) => {
|
|
566
|
+
return await openIdFetch(url, body, {
|
|
567
|
+
method: "POST",
|
|
568
|
+
...opts
|
|
569
|
+
});
|
|
570
|
+
}, "post");
|
|
571
|
+
var openIdFetch = /* @__PURE__ */ __name(async (url, body, opts) => {
|
|
572
|
+
const headers = opts?.customHeaders ?? {};
|
|
573
|
+
if (opts?.bearerToken) {
|
|
574
|
+
headers["Authorization"] = `${headers.dpop ? "DPoP" : "Bearer"} ${typeof opts.bearerToken === "function" ? await opts.bearerToken() : opts.bearerToken}`;
|
|
575
|
+
}
|
|
576
|
+
const method = opts?.method ? opts.method : body ? "POST" : "GET";
|
|
577
|
+
const accept = opts?.accept ? opts.accept : "application/json";
|
|
578
|
+
headers["Accept"] = accept;
|
|
579
|
+
if (headers["Content-Type"]) {
|
|
580
|
+
if (opts?.contentType && opts.contentType !== headers["Content-Type"]) {
|
|
581
|
+
throw Error(`Mismatch in content-types from custom headers (${headers["Content-Type"]}) and supplied content type option (${opts.contentType})`);
|
|
582
|
+
}
|
|
583
|
+
} else {
|
|
584
|
+
if (opts?.contentType) {
|
|
585
|
+
headers["Content-Type"] = opts.contentType;
|
|
586
|
+
} else if (method !== "GET") {
|
|
587
|
+
headers["Content-Type"] = "application/json";
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
const payload = {
|
|
591
|
+
method,
|
|
592
|
+
headers,
|
|
593
|
+
body
|
|
594
|
+
};
|
|
595
|
+
debug(`START fetching url: ${url}`);
|
|
596
|
+
if (body) {
|
|
597
|
+
debug(`Body:\r
|
|
598
|
+
${typeof body == "string" ? body : JSON.stringify(body)}`);
|
|
599
|
+
}
|
|
600
|
+
debug(`Headers:\r
|
|
601
|
+
${JSON.stringify(payload.headers)}`);
|
|
602
|
+
const origResponse = await (0, import_cross_fetch.fetch)(url, payload);
|
|
603
|
+
const isJSONResponse = accept === "application/json" || origResponse.headers.get("Content-Type") === "application/json";
|
|
604
|
+
const success = origResponse && origResponse.status >= 200 && origResponse.status < 400;
|
|
605
|
+
const responseText = await origResponse.text();
|
|
606
|
+
const responseBody = isJSONResponse && responseText.includes("{") ? JSON.parse(responseText) : responseText;
|
|
607
|
+
debug(`${success ? "success" : "error"} status: ${origResponse.status}, body:\r
|
|
608
|
+
${JSON.stringify(responseBody)}`);
|
|
609
|
+
if (!success && opts?.exceptionOnHttpErrorStatus) {
|
|
610
|
+
const error = JSON.stringify(responseBody);
|
|
611
|
+
throw new Error(error === "{}" ? '{"error": "not found"}' : error);
|
|
612
|
+
}
|
|
613
|
+
debug(`END fetching url: ${url}`);
|
|
614
|
+
return {
|
|
615
|
+
origResponse,
|
|
616
|
+
successBody: success ? responseBody : void 0,
|
|
617
|
+
errorBody: !success ? responseBody : void 0
|
|
618
|
+
};
|
|
619
|
+
}, "openIdFetch");
|
|
620
|
+
var isValidURL = /* @__PURE__ */ __name((url) => {
|
|
621
|
+
const urlPattern = new RegExp("^(https?:\\/\\/)((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((localhost))|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+:]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$", "i");
|
|
622
|
+
return urlPattern.test(url);
|
|
623
|
+
}, "isValidURL");
|
|
624
|
+
var trimBoth = /* @__PURE__ */ __name((value, trim) => {
|
|
625
|
+
return trimEnd(trimStart(value, trim), trim);
|
|
626
|
+
}, "trimBoth");
|
|
627
|
+
var trimEnd = /* @__PURE__ */ __name((value, trim) => {
|
|
628
|
+
return value.endsWith(trim) ? value.substring(0, value.length - trim.length) : value;
|
|
629
|
+
}, "trimEnd");
|
|
630
|
+
var trimStart = /* @__PURE__ */ __name((value, trim) => {
|
|
631
|
+
return value.startsWith(trim) ? value.substring(trim.length) : value;
|
|
632
|
+
}, "trimStart");
|
|
633
|
+
var adjustUrl = /* @__PURE__ */ __name((urlOrPath, opts) => {
|
|
634
|
+
let url = typeof urlOrPath === "object" ? urlOrPath.toString() : urlOrPath;
|
|
635
|
+
if (opts?.append) {
|
|
636
|
+
url = trimEnd(url, "/") + "/" + trimStart(opts.append, "/");
|
|
637
|
+
}
|
|
638
|
+
if (opts?.prepend) {
|
|
639
|
+
if (opts.prepend.includes("://")) {
|
|
640
|
+
if (!url.startsWith(opts.prepend)) {
|
|
641
|
+
url = trimEnd(opts.prepend, "/") + "/" + trimStart(url, "/");
|
|
642
|
+
}
|
|
643
|
+
} else {
|
|
644
|
+
let host = "";
|
|
645
|
+
let path = url;
|
|
646
|
+
if (url.includes("://")) {
|
|
647
|
+
host = new URL(url).host;
|
|
648
|
+
path = new URL(url).pathname;
|
|
649
|
+
}
|
|
650
|
+
if (!path.startsWith(opts.prepend)) {
|
|
651
|
+
if (host && host !== "") {
|
|
652
|
+
url = trimEnd(host, "/");
|
|
653
|
+
}
|
|
654
|
+
url += trimEnd(url, "/") + "/" + trimBoth(opts.prepend, "/") + "/" + trimStart(path, "/");
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
if (opts?.stripSlashStart) {
|
|
659
|
+
url = trimStart(url, "/");
|
|
660
|
+
}
|
|
661
|
+
if (opts?.stripSlashEnd) {
|
|
662
|
+
url = trimEnd(url, "/");
|
|
663
|
+
}
|
|
664
|
+
if (typeof urlOrPath === "string") {
|
|
665
|
+
return url;
|
|
666
|
+
}
|
|
667
|
+
return new URL(url);
|
|
668
|
+
}, "adjustUrl");
|
|
669
|
+
|
|
670
|
+
// lib/functions/CredentialResponseUtil.ts
|
|
671
|
+
function isDeferredCredentialResponse(credentialResponse) {
|
|
672
|
+
const orig = credentialResponse.successBody;
|
|
673
|
+
return credentialResponse.origResponse.status % 200 <= 2 && !!orig && !orig.credential && (!!orig.acceptance_token || !!orig.transaction_id);
|
|
674
|
+
}
|
|
675
|
+
__name(isDeferredCredentialResponse, "isDeferredCredentialResponse");
|
|
676
|
+
function assertNonFatalError(credentialResponse) {
|
|
677
|
+
if (credentialResponse.origResponse.status === 400 && credentialResponse.errorBody?.error) {
|
|
678
|
+
if (credentialResponse.errorBody.error === "invalid_transaction_id" || credentialResponse.errorBody.error.includes("acceptance_token")) {
|
|
679
|
+
throw Error("Invalid transaction id. Probably the deferred credential request expired");
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
__name(assertNonFatalError, "assertNonFatalError");
|
|
684
|
+
function isDeferredCredentialIssuancePending(credentialResponse) {
|
|
685
|
+
if (isDeferredCredentialResponse(credentialResponse)) {
|
|
686
|
+
return credentialResponse?.successBody?.transaction_id ?? !!credentialResponse?.successBody?.acceptance_token;
|
|
687
|
+
}
|
|
688
|
+
if (credentialResponse.origResponse.status === 400 && credentialResponse.errorBody?.error) {
|
|
689
|
+
if (credentialResponse.errorBody.error === "issuance_pending") {
|
|
690
|
+
return true;
|
|
691
|
+
} else if (credentialResponse.errorBody.error_description?.toLowerCase().includes("not available yet")) {
|
|
692
|
+
return true;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
__name(isDeferredCredentialIssuancePending, "isDeferredCredentialIssuancePending");
|
|
698
|
+
function sleep(ms) {
|
|
699
|
+
return new Promise((resolve) => {
|
|
700
|
+
setTimeout(resolve, ms);
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
__name(sleep, "sleep");
|
|
704
|
+
async function acquireDeferredCredential({ bearerToken, transactionId, deferredCredentialEndpoint, deferredCredentialIntervalInMS, deferredCredentialAwait }) {
|
|
705
|
+
let credentialResponse = await acquireDeferredCredentialImpl({
|
|
706
|
+
bearerToken,
|
|
707
|
+
transactionId,
|
|
708
|
+
deferredCredentialEndpoint
|
|
709
|
+
});
|
|
710
|
+
const DEFAULT_SLEEP_IN_MS = 5e3;
|
|
711
|
+
while (!credentialResponse.successBody?.credential && deferredCredentialAwait) {
|
|
712
|
+
assertNonFatalError(credentialResponse);
|
|
713
|
+
const pending = isDeferredCredentialIssuancePending(credentialResponse);
|
|
714
|
+
console.log(`Issuance still pending?: ${pending}`);
|
|
715
|
+
if (!pending) {
|
|
716
|
+
throw Error(`Issuance isn't pending anymore: ${credentialResponse}`);
|
|
717
|
+
}
|
|
718
|
+
await sleep(deferredCredentialIntervalInMS ?? DEFAULT_SLEEP_IN_MS);
|
|
719
|
+
credentialResponse = await acquireDeferredCredentialImpl({
|
|
720
|
+
bearerToken,
|
|
721
|
+
transactionId,
|
|
722
|
+
deferredCredentialEndpoint
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
return credentialResponse;
|
|
726
|
+
}
|
|
727
|
+
__name(acquireDeferredCredential, "acquireDeferredCredential");
|
|
728
|
+
async function acquireDeferredCredentialImpl({ bearerToken, transactionId, deferredCredentialEndpoint }) {
|
|
729
|
+
const response = await post(deferredCredentialEndpoint, JSON.stringify(transactionId ? {
|
|
730
|
+
transaction_id: transactionId
|
|
731
|
+
} : ""), {
|
|
732
|
+
bearerToken
|
|
733
|
+
});
|
|
734
|
+
console.log(JSON.stringify(response, null, 2));
|
|
735
|
+
assertNonFatalError(response);
|
|
736
|
+
return {
|
|
737
|
+
...response,
|
|
738
|
+
access_token: bearerToken
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
__name(acquireDeferredCredentialImpl, "acquireDeferredCredentialImpl");
|
|
742
|
+
|
|
743
|
+
// lib/functions/CredentialOfferUtil.ts
|
|
744
|
+
var import_debug2 = __toESM(require("debug"), 1);
|
|
745
|
+
var import_jwt_decode = require("jwt-decode");
|
|
746
|
+
var debug2 = (0, import_debug2.default)("sphereon:oid4vci:offer");
|
|
747
|
+
function determineSpecVersionFromURI(uri) {
|
|
748
|
+
let version = determineSpecVersionFromScheme(uri, OpenId4VCIVersion.VER_UNKNOWN) ?? OpenId4VCIVersion.VER_UNKNOWN;
|
|
749
|
+
version = getVersionFromURIParam(uri, version, [
|
|
750
|
+
OpenId4VCIVersion.VER_1_0_08
|
|
751
|
+
], "initiate_issuance");
|
|
752
|
+
version = getVersionFromURIParam(uri, version, [
|
|
753
|
+
OpenId4VCIVersion.VER_1_0_08
|
|
754
|
+
], "credential_type");
|
|
755
|
+
version = getVersionFromURIParam(uri, version, [
|
|
756
|
+
OpenId4VCIVersion.VER_1_0_08
|
|
757
|
+
], "op_state");
|
|
758
|
+
version = getVersionFromURIParam(uri, version, [
|
|
759
|
+
OpenId4VCIVersion.VER_1_0_11
|
|
760
|
+
], "credentials");
|
|
761
|
+
version = getVersionFromURIParam(uri, version, [
|
|
762
|
+
OpenId4VCIVersion.VER_1_0_11
|
|
763
|
+
], "grants.user_pin_required");
|
|
764
|
+
version = getVersionFromURIParam(uri, version, [
|
|
765
|
+
OpenId4VCIVersion.VER_1_0_13
|
|
766
|
+
], "credential_configuration_ids");
|
|
767
|
+
version = getVersionFromURIParam(uri, version, [
|
|
768
|
+
OpenId4VCIVersion.VER_1_0_13
|
|
769
|
+
], "tx_code");
|
|
770
|
+
if (version === OpenId4VCIVersion.VER_UNKNOWN) {
|
|
771
|
+
version = OpenId4VCIVersion.VER_1_0_13;
|
|
772
|
+
}
|
|
773
|
+
return version;
|
|
774
|
+
}
|
|
775
|
+
__name(determineSpecVersionFromURI, "determineSpecVersionFromURI");
|
|
776
|
+
function determineSpecVersionFromScheme(credentialOfferURI, openId4VCIVersion) {
|
|
777
|
+
const scheme = getScheme(credentialOfferURI);
|
|
778
|
+
if (credentialOfferURI.includes(DefaultURISchemes.INITIATE_ISSUANCE)) {
|
|
779
|
+
return recordVersion(openId4VCIVersion, [
|
|
780
|
+
OpenId4VCIVersion.VER_1_0_08
|
|
781
|
+
], scheme);
|
|
782
|
+
}
|
|
783
|
+
if (credentialOfferURI.includes("credential_offer_uri")) {
|
|
784
|
+
return void 0;
|
|
785
|
+
} else if (credentialOfferURI.includes(DefaultURISchemes.CREDENTIAL_OFFER)) {
|
|
786
|
+
if (credentialOfferURI.includes("credentials:") || credentialOfferURI.includes("credentials%22")) {
|
|
787
|
+
return recordVersion(openId4VCIVersion, [
|
|
788
|
+
OpenId4VCIVersion.VER_1_0_11
|
|
789
|
+
], scheme);
|
|
790
|
+
}
|
|
791
|
+
return recordVersion(openId4VCIVersion, [
|
|
792
|
+
OpenId4VCIVersion.VER_1_0_13
|
|
793
|
+
], scheme);
|
|
794
|
+
} else {
|
|
795
|
+
return recordVersion(openId4VCIVersion, [
|
|
796
|
+
OpenId4VCIVersion.VER_UNKNOWN
|
|
797
|
+
], scheme);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
__name(determineSpecVersionFromScheme, "determineSpecVersionFromScheme");
|
|
801
|
+
function getScheme(credentialOfferURI) {
|
|
802
|
+
if (!credentialOfferURI || !credentialOfferURI.includes("://")) {
|
|
803
|
+
throw Error("Invalid credential offer URI");
|
|
804
|
+
}
|
|
805
|
+
return credentialOfferURI.split("://")[0];
|
|
806
|
+
}
|
|
807
|
+
__name(getScheme, "getScheme");
|
|
808
|
+
function getIssuerFromCredentialOfferPayload(request) {
|
|
809
|
+
if (!request || !("issuer" in request) && !("credential_issuer" in request)) {
|
|
810
|
+
return void 0;
|
|
811
|
+
}
|
|
812
|
+
return "issuer" in request ? request.issuer : request["credential_issuer"];
|
|
813
|
+
}
|
|
814
|
+
__name(getIssuerFromCredentialOfferPayload, "getIssuerFromCredentialOfferPayload");
|
|
815
|
+
var getClientIdFromCredentialOfferPayload = /* @__PURE__ */ __name((credentialOffer) => {
|
|
816
|
+
if (!credentialOffer) {
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
if ("client_id" in credentialOffer) {
|
|
820
|
+
return credentialOffer.client_id;
|
|
821
|
+
}
|
|
822
|
+
const state = getStateFromCredentialOfferPayload(credentialOffer);
|
|
823
|
+
if (state && isJWT(state)) {
|
|
824
|
+
const decoded = (0, import_jwt_decode.jwtDecode)(state, {
|
|
825
|
+
header: false
|
|
826
|
+
});
|
|
827
|
+
if ("client_id" in decoded && typeof decoded.client_id === "string") {
|
|
828
|
+
return decoded.client_id;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return;
|
|
832
|
+
}, "getClientIdFromCredentialOfferPayload");
|
|
833
|
+
var isJWT = /* @__PURE__ */ __name((input) => {
|
|
834
|
+
if (!input) {
|
|
835
|
+
return false;
|
|
836
|
+
}
|
|
837
|
+
const noParts = input?.split(".").length;
|
|
838
|
+
return input?.startsWith("ey") && noParts === 3;
|
|
839
|
+
}, "isJWT");
|
|
840
|
+
var getStateFromCredentialOfferPayload = /* @__PURE__ */ __name((credentialOffer) => {
|
|
841
|
+
if ("grants" in credentialOffer) {
|
|
842
|
+
if (credentialOffer.grants?.authorization_code) {
|
|
843
|
+
return credentialOffer.grants.authorization_code.issuer_state;
|
|
844
|
+
} else if (credentialOffer.grants?.[PRE_AUTH_GRANT_LITERAL]) {
|
|
845
|
+
return credentialOffer.grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL];
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
if ("op_state" in credentialOffer) {
|
|
849
|
+
return credentialOffer.op_state;
|
|
850
|
+
} else if (PRE_AUTH_CODE_LITERAL in credentialOffer) {
|
|
851
|
+
return credentialOffer[PRE_AUTH_CODE_LITERAL];
|
|
852
|
+
}
|
|
853
|
+
return;
|
|
854
|
+
}, "getStateFromCredentialOfferPayload");
|
|
855
|
+
function determineSpecVersionFromOffer(offer) {
|
|
856
|
+
if (isCredentialOfferV1_0_13(offer)) {
|
|
857
|
+
return OpenId4VCIVersion.VER_1_0_13;
|
|
858
|
+
} else if (isCredentialOfferV1_0_11(offer)) {
|
|
859
|
+
return OpenId4VCIVersion.VER_1_0_11;
|
|
860
|
+
} else if (isCredentialOfferV1_0_09(offer)) {
|
|
861
|
+
return OpenId4VCIVersion.VER_1_0_09;
|
|
862
|
+
} else if (isCredentialOfferV1_0_08(offer)) {
|
|
863
|
+
return OpenId4VCIVersion.VER_1_0_08;
|
|
864
|
+
}
|
|
865
|
+
return OpenId4VCIVersion.VER_UNKNOWN;
|
|
866
|
+
}
|
|
867
|
+
__name(determineSpecVersionFromOffer, "determineSpecVersionFromOffer");
|
|
868
|
+
function isCredentialOfferVersion(offer, min, max) {
|
|
869
|
+
if (max && max.valueOf() < min.valueOf()) {
|
|
870
|
+
throw Error(`Cannot have a max ${max.valueOf()} version smaller than the min version ${min.valueOf()}`);
|
|
871
|
+
}
|
|
872
|
+
const version = determineSpecVersionFromOffer(offer);
|
|
873
|
+
if (version.valueOf() < min.valueOf()) {
|
|
874
|
+
debug2(`Credential offer version (${version.valueOf()}) is lower than minimum required version (${min.valueOf()})`);
|
|
875
|
+
return false;
|
|
876
|
+
} else if (max && version.valueOf() > max.valueOf()) {
|
|
877
|
+
debug2(`Credential offer version (${version.valueOf()}) is higher than maximum required version (${max.valueOf()})`);
|
|
878
|
+
return false;
|
|
879
|
+
}
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
882
|
+
__name(isCredentialOfferVersion, "isCredentialOfferVersion");
|
|
883
|
+
function isCredentialOfferV1_0_08(offer) {
|
|
884
|
+
if (!offer) {
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
887
|
+
if ("issuer" in offer && "credential_type" in offer) {
|
|
888
|
+
return true;
|
|
889
|
+
}
|
|
890
|
+
if ("credential_offer" in offer && offer["credential_offer"]) {
|
|
891
|
+
return isCredentialOfferV1_0_08(offer["credential_offer"]);
|
|
892
|
+
}
|
|
893
|
+
return false;
|
|
894
|
+
}
|
|
895
|
+
__name(isCredentialOfferV1_0_08, "isCredentialOfferV1_0_08");
|
|
896
|
+
function isCredentialOfferV1_0_09(offer) {
|
|
897
|
+
if (!offer) {
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
if ("issuer" in offer && "credentials" in offer) {
|
|
901
|
+
return true;
|
|
902
|
+
}
|
|
903
|
+
if ("credential_offer" in offer && offer["credential_offer"]) {
|
|
904
|
+
return isCredentialOfferV1_0_09(offer["credential_offer"]);
|
|
905
|
+
}
|
|
906
|
+
return false;
|
|
907
|
+
}
|
|
908
|
+
__name(isCredentialOfferV1_0_09, "isCredentialOfferV1_0_09");
|
|
909
|
+
function isCredentialOfferV1_0_11(offer) {
|
|
910
|
+
if (!offer) {
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
if ("credential_issuer" in offer && "credentials" in offer) {
|
|
914
|
+
return true;
|
|
915
|
+
}
|
|
916
|
+
if ("credential_offer" in offer && offer["credential_offer"]) {
|
|
917
|
+
return isCredentialOfferV1_0_11(offer["credential_offer"]);
|
|
918
|
+
}
|
|
919
|
+
return "credential_offer_uri" in offer;
|
|
920
|
+
}
|
|
921
|
+
__name(isCredentialOfferV1_0_11, "isCredentialOfferV1_0_11");
|
|
922
|
+
function isCredentialOfferV1_0_13(offer) {
|
|
923
|
+
if (!offer) {
|
|
924
|
+
return false;
|
|
925
|
+
} else if (typeof offer === "string" && offer.startsWith("{")) {
|
|
926
|
+
offer = JSON.parse(offer);
|
|
927
|
+
}
|
|
928
|
+
if ("credential_issuer" in offer && "credential_configuration_ids" in offer) {
|
|
929
|
+
return true;
|
|
930
|
+
}
|
|
931
|
+
if ("credential_offer" in offer && offer["credential_offer"]) {
|
|
932
|
+
return isCredentialOfferV1_0_13(offer["credential_offer"]);
|
|
933
|
+
}
|
|
934
|
+
return "credential_offer_uri" in offer;
|
|
935
|
+
}
|
|
936
|
+
__name(isCredentialOfferV1_0_13, "isCredentialOfferV1_0_13");
|
|
937
|
+
async function toUniformCredentialOfferRequest(offer, opts) {
|
|
938
|
+
let version = opts?.version ?? determineSpecVersionFromOffer(offer);
|
|
939
|
+
let originalCredentialOffer = offer.credential_offer;
|
|
940
|
+
let credentialOfferURI;
|
|
941
|
+
if ("credential_offer_uri" in offer && offer?.credential_offer_uri !== void 0) {
|
|
942
|
+
credentialOfferURI = offer.credential_offer_uri;
|
|
943
|
+
if (opts?.resolve || opts?.resolve === void 0) {
|
|
944
|
+
VCI_LOG_COMMON.log(`Credential offer contained a URI. Will use that to get the credential offer payload: ${credentialOfferURI}`);
|
|
945
|
+
originalCredentialOffer = await resolveCredentialOfferURI(credentialOfferURI);
|
|
946
|
+
} else if (!originalCredentialOffer) {
|
|
947
|
+
throw Error(`Credential offer uri (${credentialOfferURI}) found, but resolution was explicitly disabled and credential_offer was supplied`);
|
|
948
|
+
}
|
|
949
|
+
version = determineSpecVersionFromOffer(originalCredentialOffer);
|
|
950
|
+
VCI_LOG_COMMON.log(`Offer URI payload determined to be of version ${version}`);
|
|
951
|
+
}
|
|
952
|
+
if (!originalCredentialOffer) {
|
|
953
|
+
throw Error("No credential offer available");
|
|
954
|
+
}
|
|
955
|
+
const payload = toUniformCredentialOfferPayload(originalCredentialOffer, {
|
|
956
|
+
...opts,
|
|
957
|
+
version
|
|
958
|
+
});
|
|
959
|
+
const supportedFlows = determineFlowType(payload, version);
|
|
960
|
+
return {
|
|
961
|
+
credential_offer: payload,
|
|
962
|
+
original_credential_offer: originalCredentialOffer,
|
|
963
|
+
...credentialOfferURI && {
|
|
964
|
+
credential_offer_uri: credentialOfferURI
|
|
965
|
+
},
|
|
966
|
+
supportedFlows,
|
|
967
|
+
version
|
|
968
|
+
};
|
|
969
|
+
}
|
|
970
|
+
__name(toUniformCredentialOfferRequest, "toUniformCredentialOfferRequest");
|
|
971
|
+
function isPreAuthCode(request) {
|
|
972
|
+
const payload = "credential_offer" in request ? request.credential_offer : request;
|
|
973
|
+
return payload?.grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL] !== void 0;
|
|
974
|
+
}
|
|
975
|
+
__name(isPreAuthCode, "isPreAuthCode");
|
|
976
|
+
async function assertedUniformCredentialOffer(origCredentialOffer, opts) {
|
|
977
|
+
const credentialOffer = JSON.parse(JSON.stringify(origCredentialOffer));
|
|
978
|
+
if (credentialOffer.credential_offer_uri && !credentialOffer.credential_offer) {
|
|
979
|
+
if (opts?.resolve === void 0 || opts.resolve) {
|
|
980
|
+
credentialOffer.credential_offer = await resolveCredentialOfferURI(credentialOffer.credential_offer_uri);
|
|
981
|
+
} else {
|
|
982
|
+
throw Error(`No credential_offer present, but we did get a URI, but resolution was explicitly disabled`);
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
if (!credentialOffer.credential_offer) {
|
|
986
|
+
throw Error(`No credential_offer present`);
|
|
987
|
+
}
|
|
988
|
+
credentialOffer.credential_offer = await toUniformCredentialOfferPayload(credentialOffer.credential_offer, {
|
|
989
|
+
version: credentialOffer.version
|
|
990
|
+
});
|
|
991
|
+
return credentialOffer;
|
|
992
|
+
}
|
|
993
|
+
__name(assertedUniformCredentialOffer, "assertedUniformCredentialOffer");
|
|
994
|
+
async function resolveCredentialOfferURI(uri) {
|
|
995
|
+
if (!uri) {
|
|
996
|
+
return void 0;
|
|
997
|
+
}
|
|
998
|
+
const response = await getJson(uri);
|
|
999
|
+
if (!response || !response.successBody) {
|
|
1000
|
+
throw Error(`Could not get credential offer from uri: ${uri}: ${JSON.stringify(response?.errorBody)}`);
|
|
1001
|
+
}
|
|
1002
|
+
return response.successBody;
|
|
1003
|
+
}
|
|
1004
|
+
__name(resolveCredentialOfferURI, "resolveCredentialOfferURI");
|
|
1005
|
+
function toUniformCredentialOfferPayload(offer, opts) {
|
|
1006
|
+
const version = opts?.version ?? determineSpecVersionFromOffer(offer);
|
|
1007
|
+
if (version >= OpenId4VCIVersion.VER_1_0_11) {
|
|
1008
|
+
const orig = offer;
|
|
1009
|
+
return {
|
|
1010
|
+
...orig
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
const grants = "grants" in offer ? offer.grants : {};
|
|
1014
|
+
let offerPayloadAsV8V9 = offer;
|
|
1015
|
+
if (isCredentialOfferVersion(offer, OpenId4VCIVersion.VER_1_0_08, OpenId4VCIVersion.VER_1_0_09)) {
|
|
1016
|
+
if (offerPayloadAsV8V9.op_state) {
|
|
1017
|
+
grants.authorization_code = {
|
|
1018
|
+
...grants.authorization_code,
|
|
1019
|
+
issuer_state: offerPayloadAsV8V9.op_state
|
|
1020
|
+
};
|
|
1021
|
+
}
|
|
1022
|
+
let user_pin_required = false;
|
|
1023
|
+
if (typeof offerPayloadAsV8V9.user_pin_required === "string") {
|
|
1024
|
+
user_pin_required = offerPayloadAsV8V9.user_pin_required === "true" || offerPayloadAsV8V9.user_pin_required === "yes";
|
|
1025
|
+
} else if (offerPayloadAsV8V9.user_pin_required !== void 0) {
|
|
1026
|
+
user_pin_required = offerPayloadAsV8V9.user_pin_required;
|
|
1027
|
+
}
|
|
1028
|
+
if (offerPayloadAsV8V9[PRE_AUTH_CODE_LITERAL]) {
|
|
1029
|
+
grants[PRE_AUTH_GRANT_LITERAL] = {
|
|
1030
|
+
"pre-authorized_code": offerPayloadAsV8V9[PRE_AUTH_CODE_LITERAL],
|
|
1031
|
+
user_pin_required
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
const issuer = getIssuerFromCredentialOfferPayload(offer);
|
|
1036
|
+
if (version === OpenId4VCIVersion.VER_1_0_09) {
|
|
1037
|
+
offerPayloadAsV8V9 = offer;
|
|
1038
|
+
return {
|
|
1039
|
+
// credential_definition: getCredentialsSupported(never, offerPayloadAsV8V9.credentials).map(sup => {credentialSubject: sup.credentialSubject})[0],
|
|
1040
|
+
credential_issuer: issuer ?? offerPayloadAsV8V9.issuer,
|
|
1041
|
+
credentials: offerPayloadAsV8V9.credentials,
|
|
1042
|
+
grants
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
1045
|
+
if (version === OpenId4VCIVersion.VER_1_0_08) {
|
|
1046
|
+
offerPayloadAsV8V9 = offer;
|
|
1047
|
+
return {
|
|
1048
|
+
credential_issuer: issuer ?? offerPayloadAsV8V9.issuer,
|
|
1049
|
+
credentials: Array.isArray(offerPayloadAsV8V9.credential_type) ? offerPayloadAsV8V9.credential_type : [
|
|
1050
|
+
offerPayloadAsV8V9.credential_type
|
|
1051
|
+
],
|
|
1052
|
+
grants
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
throw Error(`Could not create uniform payload for version ${version}`);
|
|
1056
|
+
}
|
|
1057
|
+
__name(toUniformCredentialOfferPayload, "toUniformCredentialOfferPayload");
|
|
1058
|
+
function determineFlowType(suppliedOffer, version) {
|
|
1059
|
+
const payload = getCredentialOfferPayload(suppliedOffer);
|
|
1060
|
+
const supportedFlows = [];
|
|
1061
|
+
if (payload.grants?.authorization_code) {
|
|
1062
|
+
supportedFlows.push(AuthzFlowType.AUTHORIZATION_CODE_FLOW);
|
|
1063
|
+
}
|
|
1064
|
+
if (payload.grants?.[PRE_AUTH_GRANT_LITERAL]?.[PRE_AUTH_CODE_LITERAL]) {
|
|
1065
|
+
supportedFlows.push(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW);
|
|
1066
|
+
}
|
|
1067
|
+
if (supportedFlows.length === 0 && version < OpenId4VCIVersion.VER_1_0_09) {
|
|
1068
|
+
supportedFlows.push(AuthzFlowType.AUTHORIZATION_CODE_FLOW);
|
|
1069
|
+
}
|
|
1070
|
+
return supportedFlows;
|
|
1071
|
+
}
|
|
1072
|
+
__name(determineFlowType, "determineFlowType");
|
|
1073
|
+
function getCredentialOfferPayload(offer) {
|
|
1074
|
+
let payload;
|
|
1075
|
+
if ("credential_offer" in offer && offer["credential_offer"]) {
|
|
1076
|
+
payload = offer.credential_offer;
|
|
1077
|
+
} else {
|
|
1078
|
+
payload = offer;
|
|
1079
|
+
}
|
|
1080
|
+
return payload;
|
|
1081
|
+
}
|
|
1082
|
+
__name(getCredentialOfferPayload, "getCredentialOfferPayload");
|
|
1083
|
+
function determineGrantTypes(offer) {
|
|
1084
|
+
let grants;
|
|
1085
|
+
if ("grants" in offer && offer.grants) {
|
|
1086
|
+
grants = offer.grants;
|
|
1087
|
+
} else {
|
|
1088
|
+
grants = getCredentialOfferPayload(offer).grants;
|
|
1089
|
+
}
|
|
1090
|
+
const types = [];
|
|
1091
|
+
if (grants) {
|
|
1092
|
+
if ("authorization_code" in grants) {
|
|
1093
|
+
types.push(GrantTypes.AUTHORIZATION_CODE);
|
|
1094
|
+
}
|
|
1095
|
+
if (PRE_AUTH_GRANT_LITERAL in grants) {
|
|
1096
|
+
types.push(GrantTypes.PRE_AUTHORIZED_CODE);
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
return types;
|
|
1100
|
+
}
|
|
1101
|
+
__name(determineGrantTypes, "determineGrantTypes");
|
|
1102
|
+
function getVersionFromURIParam(credentialOfferURI, currentVersion, matchingVersion, param, allowUpgrade = true) {
|
|
1103
|
+
if (credentialOfferURI.includes(param)) {
|
|
1104
|
+
return recordVersion(currentVersion, matchingVersion, param, allowUpgrade);
|
|
1105
|
+
}
|
|
1106
|
+
return currentVersion;
|
|
1107
|
+
}
|
|
1108
|
+
__name(getVersionFromURIParam, "getVersionFromURIParam");
|
|
1109
|
+
function recordVersion(currentVersion, matchingVersion, key, allowUpgrade = true) {
|
|
1110
|
+
matchingVersion = matchingVersion.sort().reverse();
|
|
1111
|
+
if (currentVersion === OpenId4VCIVersion.VER_UNKNOWN) {
|
|
1112
|
+
return matchingVersion[0];
|
|
1113
|
+
} else if (matchingVersion.includes(currentVersion)) {
|
|
1114
|
+
if (!allowUpgrade) {
|
|
1115
|
+
return currentVersion;
|
|
1116
|
+
}
|
|
1117
|
+
return matchingVersion[0];
|
|
1118
|
+
}
|
|
1119
|
+
throw new Error(`Invalid param. Some keys have been used from version: ${currentVersion} version while '${key}' is used from version: ${JSON.stringify(matchingVersion)}`);
|
|
1120
|
+
}
|
|
1121
|
+
__name(recordVersion, "recordVersion");
|
|
1122
|
+
function getTypesFromOfferV1_0_11(credentialOffer, opts) {
|
|
1123
|
+
const types = credentialOffer.credentials.reduce((prev, curr) => {
|
|
1124
|
+
if (typeof curr === "string") {
|
|
1125
|
+
return [
|
|
1126
|
+
...prev,
|
|
1127
|
+
curr
|
|
1128
|
+
];
|
|
1129
|
+
} else if (curr.format === "jwt_vc_json-ld" || curr.format === "ldp_vc") {
|
|
1130
|
+
return [
|
|
1131
|
+
...prev,
|
|
1132
|
+
...curr.credential_definition.types
|
|
1133
|
+
];
|
|
1134
|
+
} else if (curr.format === "jwt_vc_json" || curr.format === "jwt_vc") {
|
|
1135
|
+
return [
|
|
1136
|
+
...prev,
|
|
1137
|
+
...curr.types
|
|
1138
|
+
];
|
|
1139
|
+
} else if (curr.format === "vc+sd-jwt") {
|
|
1140
|
+
return [
|
|
1141
|
+
...prev,
|
|
1142
|
+
curr.vct
|
|
1143
|
+
];
|
|
1144
|
+
}
|
|
1145
|
+
return prev;
|
|
1146
|
+
}, []);
|
|
1147
|
+
if (!types || types.length === 0) {
|
|
1148
|
+
throw Error("Could not deduce types from credential offer");
|
|
1149
|
+
}
|
|
1150
|
+
if (opts?.filterVerifiableCredential) {
|
|
1151
|
+
return types.filter((type) => type !== "VerifiableCredential");
|
|
1152
|
+
}
|
|
1153
|
+
return types;
|
|
1154
|
+
}
|
|
1155
|
+
__name(getTypesFromOfferV1_0_11, "getTypesFromOfferV1_0_11");
|
|
1156
|
+
|
|
1157
|
+
// lib/functions/Encoding.ts
|
|
1158
|
+
function convertJsonToURI(json, opts) {
|
|
1159
|
+
if (typeof json === "string") {
|
|
1160
|
+
return convertJsonToURI(JSON.parse(json), opts);
|
|
1161
|
+
}
|
|
1162
|
+
const results = [];
|
|
1163
|
+
function encodeAndStripWhitespace(key) {
|
|
1164
|
+
return encodeURIComponent(key.replace(" ", ""));
|
|
1165
|
+
}
|
|
1166
|
+
__name(encodeAndStripWhitespace, "encodeAndStripWhitespace");
|
|
1167
|
+
let components;
|
|
1168
|
+
if (opts?.version && opts.version > OpenId4VCIVersion.VER_1_0_08 && !opts.mode || opts?.mode === JsonURIMode.JSON_STRINGIFY) {
|
|
1169
|
+
components = encodeAndStripWhitespace(JSON.stringify(json));
|
|
1170
|
+
} else {
|
|
1171
|
+
for (const [key, value] of Object.entries(json)) {
|
|
1172
|
+
if (!value) {
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
if (!opts?.uriTypeProperties?.includes(key)) {
|
|
1176
|
+
results.push(`${key}=${value}`);
|
|
1177
|
+
continue;
|
|
1178
|
+
}
|
|
1179
|
+
if (opts?.arrayTypeProperties?.includes(key) && Array.isArray(value)) {
|
|
1180
|
+
results.push(value.map((v) => `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(v, /\./g)}`).join("&"));
|
|
1181
|
+
continue;
|
|
1182
|
+
}
|
|
1183
|
+
const isBool = typeof value == "boolean";
|
|
1184
|
+
const isNumber = typeof value == "number";
|
|
1185
|
+
const isString = typeof value == "string";
|
|
1186
|
+
let encoded;
|
|
1187
|
+
if (isBool || isNumber) {
|
|
1188
|
+
encoded = `${encodeAndStripWhitespace(key)}=${value}`;
|
|
1189
|
+
} else if (isString) {
|
|
1190
|
+
encoded = `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(value, /\./g)}`;
|
|
1191
|
+
} else {
|
|
1192
|
+
encoded = `${encodeAndStripWhitespace(key)}=${customEncodeURIComponent(JSON.stringify(value), /\./g)}`;
|
|
1193
|
+
}
|
|
1194
|
+
results.push(encoded);
|
|
1195
|
+
}
|
|
1196
|
+
components = results.join("&");
|
|
1197
|
+
}
|
|
1198
|
+
if (opts?.baseUrl) {
|
|
1199
|
+
if (opts.baseUrl.endsWith("=")) {
|
|
1200
|
+
if (opts.param) {
|
|
1201
|
+
throw Error("Cannot combine param with an url ending in =");
|
|
1202
|
+
}
|
|
1203
|
+
return `${opts.baseUrl}${components}`;
|
|
1204
|
+
} else if (!opts.baseUrl.includes("?")) {
|
|
1205
|
+
return `${opts.baseUrl}?${opts.param ? opts.param + "=" : ""}${components}`;
|
|
1206
|
+
} else if (opts.baseUrl.endsWith("?")) {
|
|
1207
|
+
return `${opts.baseUrl}${opts.param ? opts.param + "=" : ""}${components}`;
|
|
1208
|
+
} else {
|
|
1209
|
+
return `${opts.baseUrl}${opts.param ? "&" + opts.param : ""}=${components}`;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
return components;
|
|
1213
|
+
}
|
|
1214
|
+
__name(convertJsonToURI, "convertJsonToURI");
|
|
1215
|
+
function convertURIToJsonObject(uri, opts) {
|
|
1216
|
+
if (!uri || opts?.requiredProperties && !opts.requiredProperties?.every((p) => uri.includes(p))) {
|
|
1217
|
+
throw new Error(BAD_PARAMS);
|
|
1218
|
+
}
|
|
1219
|
+
const uriComponents = getURIComponentsAsArray(uri, opts?.arrayTypeProperties);
|
|
1220
|
+
return decodeJsonProperties(uriComponents);
|
|
1221
|
+
}
|
|
1222
|
+
__name(convertURIToJsonObject, "convertURIToJsonObject");
|
|
1223
|
+
function decodeJsonProperties(parts) {
|
|
1224
|
+
const result = {};
|
|
1225
|
+
for (const key in parts) {
|
|
1226
|
+
const value = parts[key];
|
|
1227
|
+
if (!value) {
|
|
1228
|
+
continue;
|
|
1229
|
+
}
|
|
1230
|
+
if (Array.isArray(value)) {
|
|
1231
|
+
result[decodeURIComponent(key)] = value.map((v) => decodeURIComponent(v));
|
|
1232
|
+
continue;
|
|
1233
|
+
}
|
|
1234
|
+
const isBool = typeof value == "boolean";
|
|
1235
|
+
const isNumber = typeof value == "number";
|
|
1236
|
+
const isString = typeof value == "string";
|
|
1237
|
+
const isObject = typeof value == "object";
|
|
1238
|
+
if (isBool || isNumber) {
|
|
1239
|
+
result[decodeURIComponent(key)] = value;
|
|
1240
|
+
} else if (isString) {
|
|
1241
|
+
const decoded = decodeURIComponent(value);
|
|
1242
|
+
if (decoded.startsWith("{") && decoded.endsWith("}")) {
|
|
1243
|
+
result[decodeURIComponent(key)] = JSON.parse(decoded);
|
|
1244
|
+
} else {
|
|
1245
|
+
result[decodeURIComponent(key)] = decoded;
|
|
1246
|
+
}
|
|
1247
|
+
} else if (isObject) {
|
|
1248
|
+
result[decodeURIComponent(key)] = decodeJsonProperties(value);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
return result;
|
|
1252
|
+
}
|
|
1253
|
+
__name(decodeJsonProperties, "decodeJsonProperties");
|
|
1254
|
+
function getURIComponentsAsArray(uri, arrayTypes) {
|
|
1255
|
+
const parts = uri.includes("?") ? uri.split("?")[1] : uri.includes("://") ? uri.split("://")[1] : uri;
|
|
1256
|
+
const json = [];
|
|
1257
|
+
const dict = parts.split("&");
|
|
1258
|
+
for (const entry of dict) {
|
|
1259
|
+
const pair = entry.split("=");
|
|
1260
|
+
const p0 = pair[0];
|
|
1261
|
+
const p1 = pair[1];
|
|
1262
|
+
if (arrayTypes?.includes(p0)) {
|
|
1263
|
+
const key = json[p0];
|
|
1264
|
+
if (Array.isArray(key)) {
|
|
1265
|
+
key.push(p1);
|
|
1266
|
+
} else {
|
|
1267
|
+
json[p0] = [
|
|
1268
|
+
p1
|
|
1269
|
+
];
|
|
1270
|
+
}
|
|
1271
|
+
continue;
|
|
1272
|
+
}
|
|
1273
|
+
json[p0] = p1;
|
|
1274
|
+
}
|
|
1275
|
+
return json;
|
|
1276
|
+
}
|
|
1277
|
+
__name(getURIComponentsAsArray, "getURIComponentsAsArray");
|
|
1278
|
+
function customEncodeURIComponent(uriComponent, searchValue) {
|
|
1279
|
+
return encodeURIComponent(uriComponent).replace(searchValue, (c) => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
1280
|
+
}
|
|
1281
|
+
__name(customEncodeURIComponent, "customEncodeURIComponent");
|
|
1282
|
+
|
|
1283
|
+
// lib/functions/TypeConversionUtils.ts
|
|
1284
|
+
function isW3cCredentialSupported(supported) {
|
|
1285
|
+
return [
|
|
1286
|
+
"jwt_vc_json",
|
|
1287
|
+
"jwt_vc_json-ld",
|
|
1288
|
+
"ldp_vc",
|
|
1289
|
+
"jwt_vc"
|
|
1290
|
+
].includes(supported.format);
|
|
1291
|
+
}
|
|
1292
|
+
__name(isW3cCredentialSupported, "isW3cCredentialSupported");
|
|
1293
|
+
var getNumberOrUndefined = /* @__PURE__ */ __name((input) => {
|
|
1294
|
+
return input && !isNaN(+input) ? +input : void 0;
|
|
1295
|
+
}, "getNumberOrUndefined");
|
|
1296
|
+
function getTypesFromObject(subject) {
|
|
1297
|
+
if (subject === void 0) {
|
|
1298
|
+
return void 0;
|
|
1299
|
+
} else if (typeof subject === "string") {
|
|
1300
|
+
return [
|
|
1301
|
+
subject
|
|
1302
|
+
];
|
|
1303
|
+
} else if ("credential_definition" in subject) {
|
|
1304
|
+
return getTypesFromObject(subject.credential_definition);
|
|
1305
|
+
} else if ("types" in subject && subject.types) {
|
|
1306
|
+
return Array.isArray(subject.types) ? subject.types : [
|
|
1307
|
+
subject.types
|
|
1308
|
+
];
|
|
1309
|
+
} else if ("type" in subject && subject.type) {
|
|
1310
|
+
return Array.isArray(subject.type) ? subject.type : [
|
|
1311
|
+
subject.type
|
|
1312
|
+
];
|
|
1313
|
+
} else if ("vct" in subject && subject.vct) {
|
|
1314
|
+
return [
|
|
1315
|
+
subject.vct
|
|
1316
|
+
];
|
|
1317
|
+
} else if ("doctype" in subject && subject.doctype) {
|
|
1318
|
+
return [
|
|
1319
|
+
subject.doctype
|
|
1320
|
+
];
|
|
1321
|
+
}
|
|
1322
|
+
VCI_LOG_COMMON.warning("Could not deduce credential types. Probably a failure down the line will happen!");
|
|
1323
|
+
return void 0;
|
|
1324
|
+
}
|
|
1325
|
+
__name(getTypesFromObject, "getTypesFromObject");
|
|
1326
|
+
function getTypesFromCredentialOffer(offer, opts) {
|
|
1327
|
+
const { configIdAsType = false } = {
|
|
1328
|
+
...opts
|
|
1329
|
+
};
|
|
1330
|
+
if ("credentials" in offer && Array.isArray(offer.credentials)) {
|
|
1331
|
+
return offer.credentials.map((cred) => getTypesFromObject(cred)).filter((cred) => cred !== void 0);
|
|
1332
|
+
} else if (configIdAsType && "credential_configuration_ids" in offer && Array.isArray(offer.credential_configuration_ids)) {
|
|
1333
|
+
return offer.credential_configuration_ids.map((id) => [
|
|
1334
|
+
id
|
|
1335
|
+
]);
|
|
1336
|
+
} else if ("credential_offer" in offer && offer.credential_offer) {
|
|
1337
|
+
return getTypesFromCredentialOffer(offer.credential_offer, opts);
|
|
1338
|
+
} else if ("credential_type" in offer && offer.credential_type) {
|
|
1339
|
+
if (typeof offer.credential_type === "string") {
|
|
1340
|
+
return [
|
|
1341
|
+
[
|
|
1342
|
+
offer.credential_type
|
|
1343
|
+
]
|
|
1344
|
+
];
|
|
1345
|
+
} else if (Array.isArray(offer.credential_type)) {
|
|
1346
|
+
return [
|
|
1347
|
+
offer.credential_type
|
|
1348
|
+
];
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
VCI_LOG_COMMON.warning("Could not deduce credential types from offer. Probably a failure down the line will happen!");
|
|
1352
|
+
return void 0;
|
|
1353
|
+
}
|
|
1354
|
+
__name(getTypesFromCredentialOffer, "getTypesFromCredentialOffer");
|
|
1355
|
+
function getTypesFromAuthorizationDetails(authDetails, opts) {
|
|
1356
|
+
const { configIdAsType = false } = {
|
|
1357
|
+
...opts
|
|
1358
|
+
};
|
|
1359
|
+
if (typeof authDetails === "string") {
|
|
1360
|
+
return [
|
|
1361
|
+
authDetails
|
|
1362
|
+
];
|
|
1363
|
+
} else if ("types" in authDetails && Array.isArray(authDetails.types)) {
|
|
1364
|
+
return authDetails.types;
|
|
1365
|
+
} else if (configIdAsType && authDetails.credential_configuration_id) {
|
|
1366
|
+
return [
|
|
1367
|
+
authDetails.credential_configuration_id
|
|
1368
|
+
];
|
|
1369
|
+
}
|
|
1370
|
+
return void 0;
|
|
1371
|
+
}
|
|
1372
|
+
__name(getTypesFromAuthorizationDetails, "getTypesFromAuthorizationDetails");
|
|
1373
|
+
function getTypesFromCredentialSupported(credentialSupported, opts) {
|
|
1374
|
+
let types = [];
|
|
1375
|
+
if (credentialSupported.format === "jwt_vc_json" || credentialSupported.format === "jwt_vc" || credentialSupported.format === "jwt_vc_json-ld" || credentialSupported.format === "ldp_vc") {
|
|
1376
|
+
types = getTypesFromObject(credentialSupported) ?? [];
|
|
1377
|
+
} else if (credentialSupported.format === "vc+sd-jwt") {
|
|
1378
|
+
types = [
|
|
1379
|
+
credentialSupported.vct
|
|
1380
|
+
];
|
|
1381
|
+
} else if (credentialSupported.format === "mso_mdoc") {
|
|
1382
|
+
types = [
|
|
1383
|
+
credentialSupported.doctype
|
|
1384
|
+
];
|
|
1385
|
+
}
|
|
1386
|
+
if (!types || types.length === 0) {
|
|
1387
|
+
throw Error("Could not deduce types from credential supported");
|
|
1388
|
+
}
|
|
1389
|
+
if (opts?.filterVerifiableCredential) {
|
|
1390
|
+
return types.filter((type) => type !== "VerifiableCredential");
|
|
1391
|
+
}
|
|
1392
|
+
return types;
|
|
1393
|
+
}
|
|
1394
|
+
__name(getTypesFromCredentialSupported, "getTypesFromCredentialSupported");
|
|
1395
|
+
|
|
1396
|
+
// lib/functions/IssuerMetadataUtils.ts
|
|
1397
|
+
function getSupportedCredentials(opts) {
|
|
1398
|
+
const { version = OpenId4VCIVersion.VER_1_0_13, types } = opts ?? {};
|
|
1399
|
+
if (types && Array.isArray(types)) {
|
|
1400
|
+
if (version < OpenId4VCIVersion.VER_1_0_13) {
|
|
1401
|
+
return types.flatMap((typeSet) => getSupportedCredential({
|
|
1402
|
+
...opts,
|
|
1403
|
+
version,
|
|
1404
|
+
types: typeSet
|
|
1405
|
+
}));
|
|
1406
|
+
} else {
|
|
1407
|
+
return types.map((typeSet) => {
|
|
1408
|
+
return getSupportedCredential({
|
|
1409
|
+
...opts,
|
|
1410
|
+
version,
|
|
1411
|
+
types: typeSet
|
|
1412
|
+
});
|
|
1413
|
+
}).reduce((acc, result) => {
|
|
1414
|
+
Object.assign(acc, result);
|
|
1415
|
+
return acc;
|
|
1416
|
+
}, {});
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
return getSupportedCredential(opts ? {
|
|
1420
|
+
...opts,
|
|
1421
|
+
types: void 0
|
|
1422
|
+
} : void 0);
|
|
1423
|
+
}
|
|
1424
|
+
__name(getSupportedCredentials, "getSupportedCredentials");
|
|
1425
|
+
function determineVersionsFromIssuerMetadata(issuerMetadata) {
|
|
1426
|
+
const versions = /* @__PURE__ */ new Set();
|
|
1427
|
+
if ("authorization_server" in issuerMetadata) {
|
|
1428
|
+
versions.add(OpenId4VCIVersion.VER_1_0_11);
|
|
1429
|
+
} else if ("authorization_servers" in issuerMetadata) {
|
|
1430
|
+
versions.add(OpenId4VCIVersion.VER_1_0_13);
|
|
1431
|
+
}
|
|
1432
|
+
if (versions.size === 0) {
|
|
1433
|
+
if ("credential_configurations_supported" in issuerMetadata) {
|
|
1434
|
+
versions.add(OpenId4VCIVersion.VER_1_0_13);
|
|
1435
|
+
} else if ("credentials_supported" in issuerMetadata) {
|
|
1436
|
+
if (typeof issuerMetadata.credentials_supported === "object") {
|
|
1437
|
+
versions.add(OpenId4VCIVersion.VER_1_0_08);
|
|
1438
|
+
} else {
|
|
1439
|
+
versions.add(OpenId4VCIVersion.VER_1_0_09).add(OpenId4VCIVersion.VER_1_0_11);
|
|
1440
|
+
}
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
if (versions.size === 0) {
|
|
1444
|
+
versions.add(OpenId4VCIVersion.VER_UNKNOWN);
|
|
1445
|
+
}
|
|
1446
|
+
return Array.from(versions).sort().reverse();
|
|
1447
|
+
}
|
|
1448
|
+
__name(determineVersionsFromIssuerMetadata, "determineVersionsFromIssuerMetadata");
|
|
1449
|
+
function getSupportedCredential(opts) {
|
|
1450
|
+
const { issuerMetadata, types, format, version = OpenId4VCIVersion.VER_1_0_13 } = opts ?? {};
|
|
1451
|
+
let credentialConfigurationsV11 = void 0;
|
|
1452
|
+
let credentialConfigurationsV13 = void 0;
|
|
1453
|
+
if (version < OpenId4VCIVersion.VER_1_0_12 || issuerMetadata?.credential_configurations_supported === void 0 && issuerMetadata?.credentials_supported) {
|
|
1454
|
+
if (issuerMetadata?.credentials_supported && !Array.isArray(issuerMetadata?.credentials_supported)) {
|
|
1455
|
+
credentialConfigurationsV11 = [];
|
|
1456
|
+
Object.entries(issuerMetadata.credentials_supported).forEach(([id, supported]) => {
|
|
1457
|
+
if (!supported.id) {
|
|
1458
|
+
supported.id = id;
|
|
1459
|
+
}
|
|
1460
|
+
credentialConfigurationsV11?.push(supported);
|
|
1461
|
+
});
|
|
1462
|
+
} else {
|
|
1463
|
+
credentialConfigurationsV11 = issuerMetadata?.credentials_supported ?? [];
|
|
1464
|
+
}
|
|
1465
|
+
} else {
|
|
1466
|
+
credentialConfigurationsV13 = issuerMetadata?.credential_configurations_supported ?? {};
|
|
1467
|
+
}
|
|
1468
|
+
if (!issuerMetadata || !issuerMetadata.credential_configurations_supported && !issuerMetadata.credentials_supported) {
|
|
1469
|
+
VCI_LOG_COMMON.warning(`No credential issuer metadata or supported credentials found for issuer}`);
|
|
1470
|
+
return version < OpenId4VCIVersion.VER_1_0_13 ? credentialConfigurationsV11 : credentialConfigurationsV13;
|
|
1471
|
+
}
|
|
1472
|
+
const normalizedTypes = Array.isArray(types) ? types : types ? [
|
|
1473
|
+
types
|
|
1474
|
+
] : [];
|
|
1475
|
+
const normalizedFormats = Array.isArray(format) ? format : format ? [
|
|
1476
|
+
format
|
|
1477
|
+
] : [];
|
|
1478
|
+
function filterMatchingConfig(config) {
|
|
1479
|
+
let isTypeMatch = normalizedTypes.length === 0;
|
|
1480
|
+
const types2 = getTypesFromObject(config);
|
|
1481
|
+
if (!isTypeMatch) {
|
|
1482
|
+
if (normalizedTypes.length === 1 && config.id === normalizedTypes[0]) {
|
|
1483
|
+
isTypeMatch = true;
|
|
1484
|
+
} else if (types2) {
|
|
1485
|
+
isTypeMatch = normalizedTypes.every((type) => types2.includes(type));
|
|
1486
|
+
} else {
|
|
1487
|
+
if (isW3cCredentialSupported(config) && "credential_definition" in config) {
|
|
1488
|
+
isTypeMatch = normalizedTypes.every((type) => config.credential_definition.type.includes(type));
|
|
1489
|
+
} else if (isW3cCredentialSupported(config) && "type" in config && Array.isArray(config.type)) {
|
|
1490
|
+
isTypeMatch = normalizedTypes.every((type) => config.type.includes(type));
|
|
1491
|
+
} else if (isW3cCredentialSupported(config) && "types" in config) {
|
|
1492
|
+
isTypeMatch = normalizedTypes.every((type) => config.types?.includes(type));
|
|
1493
|
+
}
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
const isFormatMatch = normalizedFormats.length === 0 || normalizedFormats.includes(config.format);
|
|
1497
|
+
return isTypeMatch && isFormatMatch ? config : void 0;
|
|
1498
|
+
}
|
|
1499
|
+
__name(filterMatchingConfig, "filterMatchingConfig");
|
|
1500
|
+
if (credentialConfigurationsV13) {
|
|
1501
|
+
return Object.entries(credentialConfigurationsV13).reduce((filteredConfigs, [id, config]) => {
|
|
1502
|
+
if (filterMatchingConfig(config)) {
|
|
1503
|
+
filteredConfigs[id] = config;
|
|
1504
|
+
if (!config.id) {
|
|
1505
|
+
config.id = id;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
return filteredConfigs;
|
|
1509
|
+
}, {});
|
|
1510
|
+
} else if (credentialConfigurationsV11) {
|
|
1511
|
+
return credentialConfigurationsV11.filter((config) => filterMatchingConfig(config));
|
|
1512
|
+
}
|
|
1513
|
+
throw Error(`Either < v11 configurations or V13 configurations should have been filtered at this point`);
|
|
1514
|
+
}
|
|
1515
|
+
__name(getSupportedCredential, "getSupportedCredential");
|
|
1516
|
+
function credentialsSupportedV8ToV13(supportedV8) {
|
|
1517
|
+
const credentialConfigsSupported = {};
|
|
1518
|
+
Object.entries(supportedV8).flatMap((entry) => {
|
|
1519
|
+
const type = entry[0];
|
|
1520
|
+
const supportedV82 = entry[1];
|
|
1521
|
+
Object.assign(credentialConfigsSupported, credentialSupportedV8ToV13(type, supportedV82));
|
|
1522
|
+
});
|
|
1523
|
+
return credentialConfigsSupported;
|
|
1524
|
+
}
|
|
1525
|
+
__name(credentialsSupportedV8ToV13, "credentialsSupportedV8ToV13");
|
|
1526
|
+
function credentialSupportedV8ToV13(key, supportedV8) {
|
|
1527
|
+
const credentialConfigsSupported = {};
|
|
1528
|
+
Object.entries(supportedV8.formats).map((entry) => {
|
|
1529
|
+
const format = entry[0];
|
|
1530
|
+
const credentialSupportBrief = entry[1];
|
|
1531
|
+
if (typeof format !== "string") {
|
|
1532
|
+
throw Error(`Unknown format received ${JSON.stringify(format)}`);
|
|
1533
|
+
}
|
|
1534
|
+
const credentialConfigSupported = {
|
|
1535
|
+
format,
|
|
1536
|
+
display: supportedV8.display,
|
|
1537
|
+
...credentialSupportBrief,
|
|
1538
|
+
credentialSubject: supportedV8.claims
|
|
1539
|
+
};
|
|
1540
|
+
credentialConfigsSupported[key] = credentialConfigSupported;
|
|
1541
|
+
});
|
|
1542
|
+
return credentialConfigsSupported;
|
|
1543
|
+
}
|
|
1544
|
+
__name(credentialSupportedV8ToV13, "credentialSupportedV8ToV13");
|
|
1545
|
+
function getIssuerDisplays(metadata, opts) {
|
|
1546
|
+
const matchedDisplays = metadata.display?.filter((item) => !opts?.prefLocales || opts.prefLocales.length === 0 || item.locale && opts.prefLocales.includes(item.locale) || !item.locale) ?? [];
|
|
1547
|
+
return matchedDisplays.sort((item) => item.locale ? opts?.prefLocales.indexOf(item.locale) ?? 1 : Number.MAX_VALUE);
|
|
1548
|
+
}
|
|
1549
|
+
__name(getIssuerDisplays, "getIssuerDisplays");
|
|
1550
|
+
function getIssuerName(url, credentialIssuerMetadata) {
|
|
1551
|
+
if (credentialIssuerMetadata) {
|
|
1552
|
+
const displays = credentialIssuerMetadata ? getIssuerDisplays(credentialIssuerMetadata) : [];
|
|
1553
|
+
for (const display of displays) {
|
|
1554
|
+
if (display.name) {
|
|
1555
|
+
return display.name;
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
return url;
|
|
1560
|
+
}
|
|
1561
|
+
__name(getIssuerName, "getIssuerName");
|
|
1562
|
+
|
|
1563
|
+
// lib/functions/ProofUtil.ts
|
|
1564
|
+
var import_debug3 = __toESM(require("debug"), 1);
|
|
1565
|
+
var import_jwt_decode2 = require("jwt-decode");
|
|
1566
|
+
var debug3 = (0, import_debug3.default)("sphereon:openid4vci:common");
|
|
1567
|
+
var createProofOfPossession = /* @__PURE__ */ __name(async (popMode, callbacks, jwtProps, existingJwt) => {
|
|
1568
|
+
if (!callbacks.signCallback) {
|
|
1569
|
+
debug3(`no jwt signer callback or arguments supplied!`);
|
|
1570
|
+
throw new Error(BAD_PARAMS);
|
|
1571
|
+
}
|
|
1572
|
+
const jwtPayload = createJWT(popMode, jwtProps, existingJwt);
|
|
1573
|
+
const jwt = await callbacks.signCallback(jwtPayload, jwtPayload.header.kid);
|
|
1574
|
+
const proof = {
|
|
1575
|
+
proof_type: "jwt",
|
|
1576
|
+
jwt
|
|
1577
|
+
};
|
|
1578
|
+
try {
|
|
1579
|
+
partiallyValidateJWS(jwt);
|
|
1580
|
+
if (callbacks.verifyCallback) {
|
|
1581
|
+
debug3(`Calling supplied verify callback....`);
|
|
1582
|
+
await callbacks.verifyCallback({
|
|
1583
|
+
jwt,
|
|
1584
|
+
kid: jwtPayload.header.kid
|
|
1585
|
+
});
|
|
1586
|
+
debug3(`Supplied verify callback return success result`);
|
|
1587
|
+
}
|
|
1588
|
+
} catch {
|
|
1589
|
+
debug3(`JWS was not valid`);
|
|
1590
|
+
throw new Error(JWS_NOT_VALID);
|
|
1591
|
+
}
|
|
1592
|
+
debug3(`Proof of Possession JWT:\r
|
|
1593
|
+
${jwt}`);
|
|
1594
|
+
return proof;
|
|
1595
|
+
}, "createProofOfPossession");
|
|
1596
|
+
var partiallyValidateJWS = /* @__PURE__ */ __name((jws) => {
|
|
1597
|
+
if (jws.split(".").length !== 3 || !jws.startsWith("ey")) {
|
|
1598
|
+
throw new Error(JWS_NOT_VALID);
|
|
1599
|
+
}
|
|
1600
|
+
}, "partiallyValidateJWS");
|
|
1601
|
+
var isJWS = /* @__PURE__ */ __name((token) => {
|
|
1602
|
+
try {
|
|
1603
|
+
partiallyValidateJWS(token);
|
|
1604
|
+
return true;
|
|
1605
|
+
} catch (e) {
|
|
1606
|
+
return false;
|
|
1607
|
+
}
|
|
1608
|
+
}, "isJWS");
|
|
1609
|
+
var extractBearerToken = /* @__PURE__ */ __name((authorizationHeader) => {
|
|
1610
|
+
return authorizationHeader ? /Bearer (.*)/i.exec(authorizationHeader)?.[1] : void 0;
|
|
1611
|
+
}, "extractBearerToken");
|
|
1612
|
+
var validateJWT = /* @__PURE__ */ __name(async (jwt, opts) => {
|
|
1613
|
+
if (!jwt) {
|
|
1614
|
+
throw Error("No JWT was supplied");
|
|
1615
|
+
}
|
|
1616
|
+
if (!opts?.accessTokenVerificationCallback) {
|
|
1617
|
+
VCI_LOG_COMMON.warning(`No access token verification callback supplied. Access tokens will not be verified, except for a very basic check`);
|
|
1618
|
+
partiallyValidateJWS(jwt);
|
|
1619
|
+
const header = (0, import_jwt_decode2.jwtDecode)(jwt, {
|
|
1620
|
+
header: true
|
|
1621
|
+
});
|
|
1622
|
+
const payload = (0, import_jwt_decode2.jwtDecode)(jwt, {
|
|
1623
|
+
header: false
|
|
1624
|
+
});
|
|
1625
|
+
return {
|
|
1626
|
+
jwt: {
|
|
1627
|
+
header,
|
|
1628
|
+
payload
|
|
1629
|
+
},
|
|
1630
|
+
...header,
|
|
1631
|
+
...payload
|
|
1632
|
+
};
|
|
1633
|
+
} else {
|
|
1634
|
+
return await opts.accessTokenVerificationCallback({
|
|
1635
|
+
jwt,
|
|
1636
|
+
kid: opts.kid
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
}, "validateJWT");
|
|
1640
|
+
var createJWT = /* @__PURE__ */ __name((mode, jwtProps, existingJwt) => {
|
|
1641
|
+
const aud = mode === "pop" ? getJwtProperty("aud", true, jwtProps?.issuer, existingJwt?.payload?.aud) : getJwtProperty("aud", false, jwtProps?.aud, existingJwt?.payload?.aud);
|
|
1642
|
+
const iss = mode === "pop" ? getJwtProperty("iss", false, jwtProps?.clientId, existingJwt?.payload?.iss) : getJwtProperty("iss", false, jwtProps?.issuer, existingJwt?.payload?.iss);
|
|
1643
|
+
const client_id = mode === "JWT" ? getJwtProperty("client_id", false, jwtProps?.clientId, existingJwt?.payload?.client_id) : void 0;
|
|
1644
|
+
const jti = getJwtProperty("jti", false, jwtProps?.jti, existingJwt?.payload?.jti);
|
|
1645
|
+
const typ = getJwtProperty("typ", true, jwtProps?.typ, existingJwt?.header?.typ, "openid4vci-proof+jwt");
|
|
1646
|
+
const nonce = getJwtProperty("nonce", false, jwtProps?.nonce, existingJwt?.payload?.nonce);
|
|
1647
|
+
const alg = getJwtProperty("alg", false, jwtProps?.alg, existingJwt?.header?.alg, "ES256");
|
|
1648
|
+
const kid = getJwtProperty("kid", false, jwtProps?.kid, existingJwt?.header?.kid);
|
|
1649
|
+
const jwk = getJwtProperty("jwk", false, jwtProps?.jwk, existingJwt?.header?.jwk);
|
|
1650
|
+
const x5c = getJwtProperty("x5c", false, jwtProps?.x5c, existingJwt?.header.x5c);
|
|
1651
|
+
const jwt = {
|
|
1652
|
+
...existingJwt
|
|
1653
|
+
};
|
|
1654
|
+
const now = +/* @__PURE__ */ new Date();
|
|
1655
|
+
const jwtPayload = {
|
|
1656
|
+
...aud && {
|
|
1657
|
+
aud
|
|
1658
|
+
},
|
|
1659
|
+
iat: jwt.payload?.iat ?? Math.floor(now / 1e3) - 60,
|
|
1660
|
+
exp: jwt.payload?.exp ?? Math.floor(now / 1e3) + 10 * 60,
|
|
1661
|
+
nonce,
|
|
1662
|
+
...client_id && {
|
|
1663
|
+
client_id
|
|
1664
|
+
},
|
|
1665
|
+
...iss && {
|
|
1666
|
+
iss
|
|
1667
|
+
},
|
|
1668
|
+
...jti && {
|
|
1669
|
+
jti
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
const jwtHeader = {
|
|
1673
|
+
typ,
|
|
1674
|
+
alg,
|
|
1675
|
+
...kid && {
|
|
1676
|
+
kid
|
|
1677
|
+
},
|
|
1678
|
+
...jwk && {
|
|
1679
|
+
jwk
|
|
1680
|
+
},
|
|
1681
|
+
...x5c && {
|
|
1682
|
+
x5c
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
return {
|
|
1686
|
+
payload: {
|
|
1687
|
+
...jwt.payload,
|
|
1688
|
+
...jwtPayload
|
|
1689
|
+
},
|
|
1690
|
+
header: {
|
|
1691
|
+
...jwt.header,
|
|
1692
|
+
...jwtHeader
|
|
1693
|
+
}
|
|
1694
|
+
};
|
|
1695
|
+
}, "createJWT");
|
|
1696
|
+
var getJwtProperty = /* @__PURE__ */ __name((propertyName, required, option, jwtProperty, defaultValue) => {
|
|
1697
|
+
if ((typeof option === "string" || Array.isArray(option)) && option && jwtProperty && option !== jwtProperty) {
|
|
1698
|
+
throw Error(`Cannot have a property '${propertyName}' with value '${option}' and different JWT value '${jwtProperty}' at the same time`);
|
|
1699
|
+
}
|
|
1700
|
+
let result = jwtProperty ? jwtProperty : option;
|
|
1701
|
+
if (!result) {
|
|
1702
|
+
if (required) {
|
|
1703
|
+
throw Error(`No ${propertyName} property provided either in a JWT or as option`);
|
|
1704
|
+
}
|
|
1705
|
+
result = defaultValue;
|
|
1706
|
+
}
|
|
1707
|
+
return result;
|
|
1708
|
+
}, "getJwtProperty");
|
|
1709
|
+
|
|
1710
|
+
// lib/functions/AuthorizationResponseUtil.ts
|
|
1711
|
+
var toAuthorizationResponsePayload = /* @__PURE__ */ __name((input) => {
|
|
1712
|
+
let response = input;
|
|
1713
|
+
if (typeof input === "string") {
|
|
1714
|
+
if (input.trim().startsWith("{") && input.trim().endsWith("}")) {
|
|
1715
|
+
response = JSON.parse(input);
|
|
1716
|
+
} else if (input.includes("?") && input.includes("code")) {
|
|
1717
|
+
response = convertURIToJsonObject(input);
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
if (response && typeof response !== "string") {
|
|
1721
|
+
return response;
|
|
1722
|
+
}
|
|
1723
|
+
throw Error(`Could not create authorization response from the input ${input}`);
|
|
1724
|
+
}, "toAuthorizationResponsePayload");
|
|
1725
|
+
|
|
1726
|
+
// lib/functions/RandomUtils.ts
|
|
1727
|
+
var import_oid4vc_common = require("@sphereon/oid4vc-common");
|
|
1728
|
+
var u8a = __toESM(require("uint8arrays"), 1);
|
|
1729
|
+
var CODE_VERIFIER_DEFAULT_LENGTH = 128;
|
|
1730
|
+
var NONCE_LENGTH = 32;
|
|
1731
|
+
var generateRandomString = /* @__PURE__ */ __name((length, encoding) => {
|
|
1732
|
+
return u8a.toString(randomBytes(length), encoding).slice(0, length);
|
|
1733
|
+
}, "generateRandomString");
|
|
1734
|
+
var generateNonce = /* @__PURE__ */ __name((length) => {
|
|
1735
|
+
return generateRandomString(length ?? NONCE_LENGTH);
|
|
1736
|
+
}, "generateNonce");
|
|
1737
|
+
var generateCodeVerifier = /* @__PURE__ */ __name((length) => {
|
|
1738
|
+
const codeVerifier = generateRandomString(length ?? CODE_VERIFIER_DEFAULT_LENGTH, "base64url");
|
|
1739
|
+
assertValidCodeVerifier(codeVerifier);
|
|
1740
|
+
return codeVerifier;
|
|
1741
|
+
}, "generateCodeVerifier");
|
|
1742
|
+
var createCodeChallenge = /* @__PURE__ */ __name((codeVerifier, codeChallengeMethod) => {
|
|
1743
|
+
if (codeChallengeMethod === CodeChallengeMethod.plain) {
|
|
1744
|
+
return codeVerifier;
|
|
1745
|
+
} else if (!codeChallengeMethod || codeChallengeMethod === CodeChallengeMethod.S256) {
|
|
1746
|
+
return u8a.toString((0, import_oid4vc_common.defaultHasher)(codeVerifier, "sha256"), "base64url");
|
|
1747
|
+
} else {
|
|
1748
|
+
throw Error(`code challenge method ${codeChallengeMethod} not implemented`);
|
|
1749
|
+
}
|
|
1750
|
+
}, "createCodeChallenge");
|
|
1751
|
+
var assertValidCodeVerifier = /* @__PURE__ */ __name((codeVerifier) => {
|
|
1752
|
+
const length = codeVerifier.length;
|
|
1753
|
+
if (length < 43) {
|
|
1754
|
+
throw Error(`code_verifier should have a minimum length of 43; see rfc7636`);
|
|
1755
|
+
} else if (length > 128) {
|
|
1756
|
+
throw Error(`code_verifier should have a maximum length of 128; see rfc7636`);
|
|
1757
|
+
}
|
|
1758
|
+
}, "assertValidCodeVerifier");
|
|
1759
|
+
|
|
1760
|
+
// lib/experimental/holder-vci.ts
|
|
1761
|
+
var EXPERIMENTAL_SUBJECT_PROOF_MODE_ENABLED = process.env.EXPERIMENTAL_SUBJECT_PROOF_MODE?.trim().toLowerCase() === "true";
|
|
1762
|
+
|
|
1763
|
+
// lib/events/index.ts
|
|
1764
|
+
var import_ssi_types = require("@sphereon/ssi-types");
|
|
1765
|
+
var CredentialOfferEventNames = /* @__PURE__ */ function(CredentialOfferEventNames2) {
|
|
1766
|
+
CredentialOfferEventNames2["OID4VCI_OFFER_CREATED"] = "OID4VCI_OFFER_CREATED";
|
|
1767
|
+
CredentialOfferEventNames2["OID4VCI_OFFER_EXPIRED"] = "OID4VCI_OFFER_EXPIRED";
|
|
1768
|
+
CredentialOfferEventNames2["OID4VCI_OFFER_DELETED"] = "OID4VCI_OFFER_DELETED";
|
|
1769
|
+
return CredentialOfferEventNames2;
|
|
1770
|
+
}({});
|
|
1771
|
+
var CredentialEventNames = /* @__PURE__ */ function(CredentialEventNames2) {
|
|
1772
|
+
CredentialEventNames2["OID4VCI_CREDENTIAL_ISSUED"] = "OID4VCI_CREDENTIAL_ISSUED";
|
|
1773
|
+
return CredentialEventNames2;
|
|
1774
|
+
}({});
|
|
1775
|
+
var NotificationStatusEventNames = /* @__PURE__ */ function(NotificationStatusEventNames2) {
|
|
1776
|
+
NotificationStatusEventNames2["OID4VCI_NOTIFICATION_RECEIVED"] = "OID4VCI_NOTIFICATION_RECEIVED";
|
|
1777
|
+
NotificationStatusEventNames2["OID4VCI_NOTIFICATION_PROCESSED"] = "OID4VCI_NOTIFICATION_PROCESSED";
|
|
1778
|
+
NotificationStatusEventNames2["OID4VCI_NOTIFICATION_ERROR"] = "OID4VCI_NOTIFICATION_ERROR";
|
|
1779
|
+
return NotificationStatusEventNames2;
|
|
1780
|
+
}({});
|
|
1781
|
+
var EVENTS = import_ssi_types.EventManager.instance();
|
|
1782
|
+
|
|
1783
|
+
// lib/index.ts
|
|
1784
|
+
var VCI_LOGGERS = import_ssi_types2.Loggers.DEFAULT;
|
|
1785
|
+
var VCI_LOG_COMMON = VCI_LOGGERS.get("sphereon:oid4vci:common");
|
|
1786
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1787
|
+
0 && (module.exports = {
|
|
1788
|
+
ACCESS_TOKEN_ISSUER_REQUIRED_ERROR,
|
|
1789
|
+
ALG_ERROR,
|
|
1790
|
+
AUD_ERROR,
|
|
1791
|
+
Alg,
|
|
1792
|
+
AuthorizationChallengeError,
|
|
1793
|
+
AuthzFlowType,
|
|
1794
|
+
BAD_PARAMS,
|
|
1795
|
+
CODE_VERIFIER_DEFAULT_LENGTH,
|
|
1796
|
+
CREDENTIAL_MISSING_ERROR,
|
|
1797
|
+
CodeChallengeMethod,
|
|
1798
|
+
CreateRequestObjectMode,
|
|
1799
|
+
CredentialEventNames,
|
|
1800
|
+
CredentialOfferEventNames,
|
|
1801
|
+
DID_NO_DIDDOC_ERROR,
|
|
1802
|
+
DefaultURISchemes,
|
|
1803
|
+
EVENTS,
|
|
1804
|
+
EXPERIMENTAL_SUBJECT_PROOF_MODE_ENABLED,
|
|
1805
|
+
EXPIRED_PRE_AUTHORIZED_CODE,
|
|
1806
|
+
Encoding,
|
|
1807
|
+
GRANTS_MUST_NOT_BE_UNDEFINED,
|
|
1808
|
+
GrantTypes,
|
|
1809
|
+
IAT_ERROR,
|
|
1810
|
+
INVALID_PRE_AUTHORIZED_CODE,
|
|
1811
|
+
ISSUER_CONFIG_ERROR,
|
|
1812
|
+
ISS_MUST_BE_CLIENT_ID,
|
|
1813
|
+
ISS_PRESENT_IN_PRE_AUTHORIZED_CODE_CONTEXT,
|
|
1814
|
+
IssueStatus,
|
|
1815
|
+
JWS_NOT_VALID,
|
|
1816
|
+
JWT_SIGNER_CALLBACK_REQUIRED_ERROR,
|
|
1817
|
+
JWT_VERIFY_CONFIG_ERROR,
|
|
1818
|
+
JsonURIMode,
|
|
1819
|
+
KID_DID_NO_DID_ERROR,
|
|
1820
|
+
KID_JWK_X5C_ERROR,
|
|
1821
|
+
NONCE_ERROR,
|
|
1822
|
+
NONCE_LENGTH,
|
|
1823
|
+
NONCE_STATE_MANAGER_REQUIRED_ERROR,
|
|
1824
|
+
NO_ISS_IN_AUTHORIZATION_CODE_CONTEXT,
|
|
1825
|
+
NO_JWT_PROVIDED,
|
|
1826
|
+
NotificationStatusEventNames,
|
|
1827
|
+
OpenId4VCIVersion,
|
|
1828
|
+
PARMode,
|
|
1829
|
+
PIN_NOT_MATCH_ERROR,
|
|
1830
|
+
PIN_VALIDATION_ERROR,
|
|
1831
|
+
PRE_AUTHORIZED_CODE_REQUIRED_ERROR,
|
|
1832
|
+
PRE_AUTH_CODE_LITERAL,
|
|
1833
|
+
PRE_AUTH_GRANT_LITERAL,
|
|
1834
|
+
PROOF_CANT_BE_CONSTRUCTED,
|
|
1835
|
+
ResponseType,
|
|
1836
|
+
STATE_MANAGER_REQUIRED_ERROR,
|
|
1837
|
+
STATE_MISSING_ERROR,
|
|
1838
|
+
TYP_ERROR,
|
|
1839
|
+
TokenError,
|
|
1840
|
+
TokenErrorResponse,
|
|
1841
|
+
UNKNOWN_CLIENT_ERROR,
|
|
1842
|
+
UNSUPPORTED_GRANT_TYPE_ERROR,
|
|
1843
|
+
URL_NOT_VALID,
|
|
1844
|
+
USER_PIN_NOT_REQUIRED_ERROR,
|
|
1845
|
+
USER_PIN_REQUIRED_ERROR,
|
|
1846
|
+
USER_PIN_TX_CODE_SPEC_ERROR,
|
|
1847
|
+
VCI_LOGGERS,
|
|
1848
|
+
VCI_LOG_COMMON,
|
|
1849
|
+
WRONG_METADATA_FORMAT,
|
|
1850
|
+
WellKnownEndpoints,
|
|
1851
|
+
acquireDeferredCredential,
|
|
1852
|
+
adjustUrl,
|
|
1853
|
+
assertValidCodeVerifier,
|
|
1854
|
+
assertedUniformCredentialOffer,
|
|
1855
|
+
authorizationServerMetadataFieldNames,
|
|
1856
|
+
convertJsonToURI,
|
|
1857
|
+
convertURIToJsonObject,
|
|
1858
|
+
createCodeChallenge,
|
|
1859
|
+
createProofOfPossession,
|
|
1860
|
+
credentialIssuerMetadataFieldNames,
|
|
1861
|
+
credentialSupportedV8ToV13,
|
|
1862
|
+
credentialsSupportedV8ToV13,
|
|
1863
|
+
decodeJsonProperties,
|
|
1864
|
+
determineFlowType,
|
|
1865
|
+
determineGrantTypes,
|
|
1866
|
+
determineSpecVersionFromOffer,
|
|
1867
|
+
determineSpecVersionFromScheme,
|
|
1868
|
+
determineSpecVersionFromURI,
|
|
1869
|
+
determineVersionsFromIssuerMetadata,
|
|
1870
|
+
extractBearerToken,
|
|
1871
|
+
formPost,
|
|
1872
|
+
generateCodeVerifier,
|
|
1873
|
+
generateNonce,
|
|
1874
|
+
generateRandomString,
|
|
1875
|
+
getClientIdFromCredentialOfferPayload,
|
|
1876
|
+
getCredentialOfferPayload,
|
|
1877
|
+
getCredentialRequestForVersion,
|
|
1878
|
+
getFormatForVersion,
|
|
1879
|
+
getIssuerDisplays,
|
|
1880
|
+
getIssuerFromCredentialOfferPayload,
|
|
1881
|
+
getIssuerName,
|
|
1882
|
+
getJson,
|
|
1883
|
+
getNumberOrUndefined,
|
|
1884
|
+
getScheme,
|
|
1885
|
+
getStateFromCredentialOfferPayload,
|
|
1886
|
+
getSupportedCredential,
|
|
1887
|
+
getSupportedCredentials,
|
|
1888
|
+
getTypesFromAuthorizationDetails,
|
|
1889
|
+
getTypesFromCredentialOffer,
|
|
1890
|
+
getTypesFromCredentialSupported,
|
|
1891
|
+
getTypesFromObject,
|
|
1892
|
+
getTypesFromOfferV1_0_11,
|
|
1893
|
+
getTypesFromRequest,
|
|
1894
|
+
getURIComponentsAsArray,
|
|
1895
|
+
getUniformFormat,
|
|
1896
|
+
isAuthorizationRequestV1_0_09,
|
|
1897
|
+
isAuthorizationRequestV1_0_11,
|
|
1898
|
+
isCredentialOfferVersion,
|
|
1899
|
+
isDeferredCredentialIssuancePending,
|
|
1900
|
+
isDeferredCredentialResponse,
|
|
1901
|
+
isFormat,
|
|
1902
|
+
isJWS,
|
|
1903
|
+
isNotFormat,
|
|
1904
|
+
isPreAuthCode,
|
|
1905
|
+
isValidURL,
|
|
1906
|
+
isW3cCredentialSupported,
|
|
1907
|
+
post,
|
|
1908
|
+
randomBytes,
|
|
1909
|
+
resolveCredentialOfferURI,
|
|
1910
|
+
toAuthorizationResponsePayload,
|
|
1911
|
+
toUniformCredentialOfferPayload,
|
|
1912
|
+
toUniformCredentialOfferRequest,
|
|
1913
|
+
trimBoth,
|
|
1914
|
+
trimEnd,
|
|
1915
|
+
trimStart,
|
|
1916
|
+
validateJWT
|
|
1917
|
+
});
|
|
1918
|
+
//# sourceMappingURL=index.cjs.map
|