@sphereon/oid4vci-common 0.8.2-unstable.39 → 0.8.2-unstable.41
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/functions/CredentialOfferUtil.d.ts +27 -27
- package/dist/functions/CredentialOfferUtil.js +261 -261
- package/dist/functions/CredentialRequestUtil.d.ts +5 -5
- package/dist/functions/CredentialRequestUtil.js +27 -27
- package/dist/functions/Encoding.d.ts +19 -19
- package/dist/functions/Encoding.js +163 -163
- package/dist/functions/FormatUtils.d.ts +14 -14
- package/dist/functions/FormatUtils.js +33 -33
- package/dist/functions/HttpUtils.d.ts +32 -32
- package/dist/functions/HttpUtils.js +145 -145
- package/dist/functions/IssuerMetadataUtils.d.ts +19 -19
- package/dist/functions/IssuerMetadataUtils.js +115 -115
- package/dist/functions/TypeConversionUtils.d.ts +1 -1
- package/dist/functions/TypeConversionUtils.js +7 -7
- package/dist/functions/index.d.ts +6 -6
- package/dist/functions/index.js +22 -22
- package/dist/index.d.ts +2 -2
- package/dist/index.js +18 -18
- package/dist/types/Authorization.types.d.ts +214 -213
- package/dist/types/Authorization.types.d.ts.map +1 -1
- package/dist/types/Authorization.types.js +40 -40
- package/dist/types/Authorization.types.js.map +1 -1
- package/dist/types/CredentialIssuance.types.d.ts +150 -150
- package/dist/types/CredentialIssuance.types.js +14 -14
- package/dist/types/Generic.types.d.ts +229 -229
- package/dist/types/Generic.types.js +4 -4
- package/dist/types/OpenID4VCIErrors.d.ts +35 -35
- package/dist/types/OpenID4VCIErrors.js +39 -39
- package/dist/types/OpenID4VCIVersions.types.d.ts +9 -9
- package/dist/types/OpenID4VCIVersions.types.js +14 -14
- package/dist/types/QRCode.types.d.ts +204 -204
- package/dist/types/QRCode.types.js +2 -2
- package/dist/types/ServerMetadata.d.ts +60 -60
- package/dist/types/ServerMetadata.js +9 -9
- package/dist/types/StateManager.types.d.ts +53 -53
- package/dist/types/StateManager.types.js +13 -13
- package/dist/types/Token.types.d.ts +14 -14
- package/dist/types/Token.types.js +29 -29
- package/dist/types/index.d.ts +10 -10
- package/dist/types/index.js +26 -26
- package/dist/types/v1_0_12.types.d.ts +43 -43
- package/dist/types/v1_0_12.types.js +8 -8
- package/lib/__tests__/CredentialOfferUtil.spec.ts +1 -1
- package/lib/types/Authorization.types.ts +1 -0
- package/package.json +2 -2
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { AssertedUniformCredentialOffer, AuthzFlowType, CredentialOffer, CredentialOfferPayload, Grant, GrantTypes, OpenId4VCIVersion, UniformCredentialOffer, UniformCredentialOfferPayload, UniformCredentialOfferRequest } from '../types';
|
|
2
|
-
export declare function determineSpecVersionFromURI(uri: string): OpenId4VCIVersion;
|
|
3
|
-
export declare function determineSpecVersionFromScheme(credentialOfferURI: string, openId4VCIVersion: OpenId4VCIVersion): OpenId4VCIVersion;
|
|
4
|
-
export declare function getScheme(credentialOfferURI: string): string;
|
|
5
|
-
export declare function getIssuerFromCredentialOfferPayload(request: CredentialOfferPayload): string | undefined;
|
|
6
|
-
export declare function determineSpecVersionFromOffer(offer: CredentialOfferPayload | CredentialOffer): OpenId4VCIVersion;
|
|
7
|
-
export declare function isCredentialOfferVersion(offer: CredentialOfferPayload | CredentialOffer, min: OpenId4VCIVersion, max?: OpenId4VCIVersion): boolean;
|
|
8
|
-
export declare function toUniformCredentialOfferRequest(offer: CredentialOffer, opts?: {
|
|
9
|
-
resolve?: boolean;
|
|
10
|
-
version?: OpenId4VCIVersion;
|
|
11
|
-
}): Promise<UniformCredentialOfferRequest>;
|
|
12
|
-
export declare function isPreAuthCode(request: UniformCredentialOfferPayload | UniformCredentialOffer): boolean;
|
|
13
|
-
export declare function assertedUniformCredentialOffer(origCredentialOffer: UniformCredentialOffer, opts?: {
|
|
14
|
-
resolve?: boolean;
|
|
15
|
-
}): Promise<AssertedUniformCredentialOffer>;
|
|
16
|
-
export declare function resolveCredentialOfferURI(uri?: string): Promise<UniformCredentialOfferPayload | undefined>;
|
|
17
|
-
export declare function toUniformCredentialOfferPayload(offer: CredentialOfferPayload, opts?: {
|
|
18
|
-
version?: OpenId4VCIVersion;
|
|
19
|
-
}): UniformCredentialOfferPayload;
|
|
20
|
-
export declare function determineFlowType(suppliedOffer: AssertedUniformCredentialOffer | UniformCredentialOfferPayload, version: OpenId4VCIVersion): AuthzFlowType[];
|
|
21
|
-
export declare function getCredentialOfferPayload(offer: AssertedUniformCredentialOffer | UniformCredentialOfferPayload): UniformCredentialOfferPayload;
|
|
22
|
-
export declare function determineGrantTypes(offer: AssertedUniformCredentialOffer | UniformCredentialOfferPayload | ({
|
|
23
|
-
grants: Grant;
|
|
24
|
-
} & Record<never, never>)): GrantTypes[];
|
|
25
|
-
export declare function getTypesFromOffer(credentialOffer: UniformCredentialOfferPayload, opts?: {
|
|
26
|
-
filterVerifiableCredential: boolean;
|
|
27
|
-
}): string[];
|
|
1
|
+
import { AssertedUniformCredentialOffer, AuthzFlowType, CredentialOffer, CredentialOfferPayload, Grant, GrantTypes, OpenId4VCIVersion, UniformCredentialOffer, UniformCredentialOfferPayload, UniformCredentialOfferRequest } from '../types';
|
|
2
|
+
export declare function determineSpecVersionFromURI(uri: string): OpenId4VCIVersion;
|
|
3
|
+
export declare function determineSpecVersionFromScheme(credentialOfferURI: string, openId4VCIVersion: OpenId4VCIVersion): OpenId4VCIVersion;
|
|
4
|
+
export declare function getScheme(credentialOfferURI: string): string;
|
|
5
|
+
export declare function getIssuerFromCredentialOfferPayload(request: CredentialOfferPayload): string | undefined;
|
|
6
|
+
export declare function determineSpecVersionFromOffer(offer: CredentialOfferPayload | CredentialOffer): OpenId4VCIVersion;
|
|
7
|
+
export declare function isCredentialOfferVersion(offer: CredentialOfferPayload | CredentialOffer, min: OpenId4VCIVersion, max?: OpenId4VCIVersion): boolean;
|
|
8
|
+
export declare function toUniformCredentialOfferRequest(offer: CredentialOffer, opts?: {
|
|
9
|
+
resolve?: boolean;
|
|
10
|
+
version?: OpenId4VCIVersion;
|
|
11
|
+
}): Promise<UniformCredentialOfferRequest>;
|
|
12
|
+
export declare function isPreAuthCode(request: UniformCredentialOfferPayload | UniformCredentialOffer): boolean;
|
|
13
|
+
export declare function assertedUniformCredentialOffer(origCredentialOffer: UniformCredentialOffer, opts?: {
|
|
14
|
+
resolve?: boolean;
|
|
15
|
+
}): Promise<AssertedUniformCredentialOffer>;
|
|
16
|
+
export declare function resolveCredentialOfferURI(uri?: string): Promise<UniformCredentialOfferPayload | undefined>;
|
|
17
|
+
export declare function toUniformCredentialOfferPayload(offer: CredentialOfferPayload, opts?: {
|
|
18
|
+
version?: OpenId4VCIVersion;
|
|
19
|
+
}): UniformCredentialOfferPayload;
|
|
20
|
+
export declare function determineFlowType(suppliedOffer: AssertedUniformCredentialOffer | UniformCredentialOfferPayload, version: OpenId4VCIVersion): AuthzFlowType[];
|
|
21
|
+
export declare function getCredentialOfferPayload(offer: AssertedUniformCredentialOffer | UniformCredentialOfferPayload): UniformCredentialOfferPayload;
|
|
22
|
+
export declare function determineGrantTypes(offer: AssertedUniformCredentialOffer | UniformCredentialOfferPayload | ({
|
|
23
|
+
grants: Grant;
|
|
24
|
+
} & Record<never, never>)): GrantTypes[];
|
|
25
|
+
export declare function getTypesFromOffer(credentialOffer: UniformCredentialOfferPayload, opts?: {
|
|
26
|
+
filterVerifiableCredential: boolean;
|
|
27
|
+
}): string[];
|
|
28
28
|
//# sourceMappingURL=CredentialOfferUtil.d.ts.map
|
|
@@ -1,262 +1,262 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getTypesFromOffer = exports.determineGrantTypes = exports.getCredentialOfferPayload = exports.determineFlowType = exports.toUniformCredentialOfferPayload = exports.resolveCredentialOfferURI = exports.assertedUniformCredentialOffer = exports.isPreAuthCode = exports.toUniformCredentialOfferRequest = exports.isCredentialOfferVersion = exports.determineSpecVersionFromOffer = exports.getIssuerFromCredentialOfferPayload = exports.getScheme = exports.determineSpecVersionFromScheme = exports.determineSpecVersionFromURI = void 0;
|
|
16
|
-
const debug_1 = __importDefault(require("debug"));
|
|
17
|
-
const types_1 = require("../types");
|
|
18
|
-
const HttpUtils_1 = require("./HttpUtils");
|
|
19
|
-
const debug = (0, debug_1.default)('sphereon:oid4vci:offer');
|
|
20
|
-
function determineSpecVersionFromURI(uri) {
|
|
21
|
-
let version = types_1.OpenId4VCIVersion.VER_UNKNOWN;
|
|
22
|
-
version = determineSpecVersionFromScheme(uri, version);
|
|
23
|
-
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, 'initiate_issuance');
|
|
24
|
-
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, 'credential_type');
|
|
25
|
-
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, 'op_state');
|
|
26
|
-
// version = getVersionFromURIParam(uri, version, OpenId4VCIVersion.VER_1_0_09, 'credentials');
|
|
27
|
-
// version = getVersionFromURIParam(uri, version, OpenId4VCIVersion.VER_1_0_09, 'initiate_issuance_uri')
|
|
28
|
-
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_1_0_12, 'credential_offer_uri=');
|
|
29
|
-
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_1_0_12, 'credential_issuer');
|
|
30
|
-
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_1_0_12, 'grants');
|
|
31
|
-
/*
|
|
32
|
-
if (version === OpenId4VCIVersion.VER_UNKNOWN) { Why would we impose a version when required parameters are missing? If we need it for a specific case, please add a comment.
|
|
33
|
-
version = OpenId4VCIVersion.VER_1_0_12;
|
|
34
|
-
}
|
|
35
|
-
*/
|
|
36
|
-
return version;
|
|
37
|
-
}
|
|
38
|
-
exports.determineSpecVersionFromURI = determineSpecVersionFromURI;
|
|
39
|
-
function determineSpecVersionFromScheme(credentialOfferURI, openId4VCIVersion) {
|
|
40
|
-
const scheme = getScheme(credentialOfferURI);
|
|
41
|
-
if (credentialOfferURI.includes(types_1.DefaultURISchemes.INITIATE_ISSUANCE)) {
|
|
42
|
-
return recordVersion(openId4VCIVersion, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, scheme);
|
|
43
|
-
}
|
|
44
|
-
else if (credentialOfferURI.includes(types_1.DefaultURISchemes.CREDENTIAL_OFFER)) {
|
|
45
|
-
return recordVersion(openId4VCIVersion, types_1.OpenId4VCIVersion.VER_1_0_12, scheme);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
return recordVersion(openId4VCIVersion, types_1.OpenId4VCIVersion.VER_UNKNOWN, scheme);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.determineSpecVersionFromScheme = determineSpecVersionFromScheme;
|
|
52
|
-
function getScheme(credentialOfferURI) {
|
|
53
|
-
if (!credentialOfferURI || !credentialOfferURI.includes('://')) {
|
|
54
|
-
throw Error('Invalid credential offer URI');
|
|
55
|
-
}
|
|
56
|
-
return credentialOfferURI.split('://')[0];
|
|
57
|
-
}
|
|
58
|
-
exports.getScheme = getScheme;
|
|
59
|
-
function getIssuerFromCredentialOfferPayload(request) {
|
|
60
|
-
if (!request || (!('issuer' in request) && !('credential_issuer' in request))) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
return request['credential_issuer'];
|
|
64
|
-
}
|
|
65
|
-
exports.getIssuerFromCredentialOfferPayload = getIssuerFromCredentialOfferPayload;
|
|
66
|
-
function determineSpecVersionFromOffer(offer) {
|
|
67
|
-
if (isCredentialOfferV1_0_12(offer)) {
|
|
68
|
-
return types_1.OpenId4VCIVersion.VER_1_0_12;
|
|
69
|
-
}
|
|
70
|
-
return types_1.OpenId4VCIVersion.VER_UNKNOWN;
|
|
71
|
-
}
|
|
72
|
-
exports.determineSpecVersionFromOffer = determineSpecVersionFromOffer;
|
|
73
|
-
function isCredentialOfferVersion(offer, min, max) {
|
|
74
|
-
if (max && max.valueOf() < min.valueOf()) {
|
|
75
|
-
throw Error(`Cannot have a max ${max.valueOf()} version smaller than the min version ${min.valueOf()}`);
|
|
76
|
-
}
|
|
77
|
-
const version = determineSpecVersionFromOffer(offer);
|
|
78
|
-
if (version.valueOf() < min.valueOf()) {
|
|
79
|
-
debug(`Credential offer version (${version.valueOf()}) is lower than minimum required version (${min.valueOf()})`);
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
else if (max && version.valueOf() > max.valueOf()) {
|
|
83
|
-
debug(`Credential offer version (${version.valueOf()}) is higher than maximum required version (${max.valueOf()})`);
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
return true;
|
|
87
|
-
}
|
|
88
|
-
exports.isCredentialOfferVersion = isCredentialOfferVersion;
|
|
89
|
-
function isCredentialOfferV1_0_12(offer) {
|
|
90
|
-
if (!offer) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
if ('credential_issuer' in offer && 'credentials' in offer) {
|
|
94
|
-
// payload
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
if ('credential_offer' in offer && offer['credential_offer']) {
|
|
98
|
-
// offer, so check payload
|
|
99
|
-
return isCredentialOfferV1_0_12(offer['credential_offer']);
|
|
100
|
-
}
|
|
101
|
-
return 'credential_offer_uri' in offer;
|
|
102
|
-
}
|
|
103
|
-
function toUniformCredentialOfferRequest(offer, opts) {
|
|
104
|
-
var _a;
|
|
105
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : determineSpecVersionFromOffer(offer);
|
|
107
|
-
let originalCredentialOffer = offer.credential_offer;
|
|
108
|
-
let credentialOfferURI;
|
|
109
|
-
if ('credential_offer_uri' in offer && (offer === null || offer === void 0 ? void 0 : offer.credential_offer_uri) !== undefined) {
|
|
110
|
-
credentialOfferURI = offer.credential_offer_uri;
|
|
111
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.resolve) || (opts === null || opts === void 0 ? void 0 : opts.resolve) === undefined) {
|
|
112
|
-
originalCredentialOffer = (yield resolveCredentialOfferURI(credentialOfferURI));
|
|
113
|
-
}
|
|
114
|
-
else if (!originalCredentialOffer) {
|
|
115
|
-
throw Error(`Credential offer uri (${credentialOfferURI}) found, but resolution was explicitly disabled and credential_offer was supplied`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
if (!originalCredentialOffer) {
|
|
119
|
-
throw Error('No credential offer available');
|
|
120
|
-
}
|
|
121
|
-
const payload = toUniformCredentialOfferPayload(originalCredentialOffer, opts);
|
|
122
|
-
const supportedFlows = determineFlowType(payload, version);
|
|
123
|
-
return Object.assign(Object.assign({ credential_offer: payload, original_credential_offer: originalCredentialOffer }, (credentialOfferURI && { credential_offer_uri: credentialOfferURI })), { supportedFlows,
|
|
124
|
-
version });
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
exports.toUniformCredentialOfferRequest = toUniformCredentialOfferRequest;
|
|
128
|
-
function isPreAuthCode(request) {
|
|
129
|
-
var _a, _b;
|
|
130
|
-
const payload = 'credential_offer' in request ? request.credential_offer : request;
|
|
131
|
-
return ((_b = (_a = payload === null || payload === void 0 ? void 0 : payload.grants) === null || _a === void 0 ? void 0 : _a['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _b === void 0 ? void 0 : _b['pre-authorized_code']) !== undefined;
|
|
132
|
-
}
|
|
133
|
-
exports.isPreAuthCode = isPreAuthCode;
|
|
134
|
-
function assertedUniformCredentialOffer(origCredentialOffer, opts) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
const credentialOffer = JSON.parse(JSON.stringify(origCredentialOffer));
|
|
137
|
-
if (credentialOffer.credential_offer_uri && !credentialOffer.credential_offer) {
|
|
138
|
-
if ((opts === null || opts === void 0 ? void 0 : opts.resolve) === undefined || opts.resolve) {
|
|
139
|
-
credentialOffer.credential_offer = yield resolveCredentialOfferURI(credentialOffer.credential_offer_uri);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
throw Error(`No credential_offer present, but we did get a URI, but resolution was explicitly disabled`);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (!credentialOffer.credential_offer) {
|
|
146
|
-
throw Error(`No credential_offer present`);
|
|
147
|
-
}
|
|
148
|
-
credentialOffer.credential_offer = yield toUniformCredentialOfferPayload(credentialOffer.credential_offer, { version: credentialOffer.version });
|
|
149
|
-
return credentialOffer;
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
exports.assertedUniformCredentialOffer = assertedUniformCredentialOffer;
|
|
153
|
-
function resolveCredentialOfferURI(uri) {
|
|
154
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
if (!uri) {
|
|
156
|
-
return undefined;
|
|
157
|
-
}
|
|
158
|
-
const response = (yield (0, HttpUtils_1.getJson)(uri));
|
|
159
|
-
if (!response || !response.successBody) {
|
|
160
|
-
throw Error(`Could not get credential offer from uri: ${uri}: ${JSON.stringify(response === null || response === void 0 ? void 0 : response.errorBody)}`);
|
|
161
|
-
}
|
|
162
|
-
return response.successBody;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
exports.resolveCredentialOfferURI = resolveCredentialOfferURI;
|
|
166
|
-
function toUniformCredentialOfferPayload(offer, opts) {
|
|
167
|
-
var _a;
|
|
168
|
-
// todo: create test to check idempotence once a payload is already been made uniform.
|
|
169
|
-
const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : determineSpecVersionFromOffer(offer);
|
|
170
|
-
if (version >= types_1.OpenId4VCIVersion.VER_1_0_12) {
|
|
171
|
-
const orig = offer;
|
|
172
|
-
return Object.assign({}, orig);
|
|
173
|
-
}
|
|
174
|
-
throw Error(`Could not create uniform payload for version ${version}`);
|
|
175
|
-
}
|
|
176
|
-
exports.toUniformCredentialOfferPayload = toUniformCredentialOfferPayload;
|
|
177
|
-
function determineFlowType(suppliedOffer, version) {
|
|
178
|
-
var _a, _b, _c;
|
|
179
|
-
const payload = getCredentialOfferPayload(suppliedOffer);
|
|
180
|
-
const supportedFlows = [];
|
|
181
|
-
if ((_a = payload.grants) === null || _a === void 0 ? void 0 : _a.authorization_code) {
|
|
182
|
-
supportedFlows.push(types_1.AuthzFlowType.AUTHORIZATION_CODE_FLOW);
|
|
183
|
-
}
|
|
184
|
-
if ((_c = (_b = payload.grants) === null || _b === void 0 ? void 0 : _b['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _c === void 0 ? void 0 : _c['pre-authorized_code']) {
|
|
185
|
-
supportedFlows.push(types_1.AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW);
|
|
186
|
-
}
|
|
187
|
-
return supportedFlows;
|
|
188
|
-
}
|
|
189
|
-
exports.determineFlowType = determineFlowType;
|
|
190
|
-
function getCredentialOfferPayload(offer) {
|
|
191
|
-
let payload;
|
|
192
|
-
if ('credential_offer' in offer && offer['credential_offer']) {
|
|
193
|
-
payload = offer.credential_offer;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
payload = offer;
|
|
197
|
-
}
|
|
198
|
-
return payload;
|
|
199
|
-
}
|
|
200
|
-
exports.getCredentialOfferPayload = getCredentialOfferPayload;
|
|
201
|
-
function determineGrantTypes(offer) {
|
|
202
|
-
let grants;
|
|
203
|
-
if ('grants' in offer && offer.grants) {
|
|
204
|
-
grants = offer.grants;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
grants = getCredentialOfferPayload(offer).grants;
|
|
208
|
-
}
|
|
209
|
-
const types = [];
|
|
210
|
-
if (grants) {
|
|
211
|
-
if (grants.authorization_code) {
|
|
212
|
-
types.push(types_1.GrantTypes.AUTHORIZATION_CODE);
|
|
213
|
-
}
|
|
214
|
-
if (grants['urn:ietf:params:oauth:grant-type:pre-authorized_code'] &&
|
|
215
|
-
grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code']) {
|
|
216
|
-
types.push(types_1.GrantTypes.PRE_AUTHORIZED_CODE);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
return types;
|
|
220
|
-
}
|
|
221
|
-
exports.determineGrantTypes = determineGrantTypes;
|
|
222
|
-
function getVersionFromURIParam(credentialOfferURI, currentVersion, matchingVersion, param) {
|
|
223
|
-
if (credentialOfferURI.includes(param)) {
|
|
224
|
-
return recordVersion(currentVersion, matchingVersion, param);
|
|
225
|
-
}
|
|
226
|
-
return currentVersion;
|
|
227
|
-
}
|
|
228
|
-
function recordVersion(currentVersion, matchingVersion, key) {
|
|
229
|
-
if (currentVersion === types_1.OpenId4VCIVersion.VER_UNKNOWN || matchingVersion === currentVersion) {
|
|
230
|
-
return matchingVersion;
|
|
231
|
-
}
|
|
232
|
-
throw new Error(`Invalid param. Some keys have been used from version: ${currentVersion} version while '${key}' is used from version: ${matchingVersion}`);
|
|
233
|
-
}
|
|
234
|
-
function getTypesFromOffer(credentialOffer, opts) {
|
|
235
|
-
const types = credentialOffer.credentials.reduce((prev, curr) => {
|
|
236
|
-
// FIXME returning the string value is wrong (as it's an id), but just matching the current behavior of this library
|
|
237
|
-
// The credential_type (from draft 8) and the actual 'type' value in a VC (from draft 11) are mixed up
|
|
238
|
-
// Fix for this here: https://github.com/Sphereon-Opensource/OID4VCI/pull/54
|
|
239
|
-
if (typeof curr === 'string') {
|
|
240
|
-
return [...prev, curr];
|
|
241
|
-
}
|
|
242
|
-
else if (curr.format === 'jwt_vc_json-ld' || curr.format === 'ldp_vc') {
|
|
243
|
-
return [...prev, ...curr.credential_definition.type];
|
|
244
|
-
}
|
|
245
|
-
else if (curr.format === 'jwt_vc_json' || curr.format === 'jwt_vc') {
|
|
246
|
-
return [...prev, ...curr.types];
|
|
247
|
-
}
|
|
248
|
-
else if (curr.format === 'vc+sd-jwt') {
|
|
249
|
-
return [...prev, curr.vct];
|
|
250
|
-
}
|
|
251
|
-
return prev;
|
|
252
|
-
}, []);
|
|
253
|
-
if (!types || types.length === 0) {
|
|
254
|
-
throw Error('Could not deduce types from credential offer');
|
|
255
|
-
}
|
|
256
|
-
if (opts === null || opts === void 0 ? void 0 : opts.filterVerifiableCredential) {
|
|
257
|
-
return types.filter((type) => type !== 'VerifiableCredential');
|
|
258
|
-
}
|
|
259
|
-
return types;
|
|
260
|
-
}
|
|
261
|
-
exports.getTypesFromOffer = getTypesFromOffer;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getTypesFromOffer = exports.determineGrantTypes = exports.getCredentialOfferPayload = exports.determineFlowType = exports.toUniformCredentialOfferPayload = exports.resolveCredentialOfferURI = exports.assertedUniformCredentialOffer = exports.isPreAuthCode = exports.toUniformCredentialOfferRequest = exports.isCredentialOfferVersion = exports.determineSpecVersionFromOffer = exports.getIssuerFromCredentialOfferPayload = exports.getScheme = exports.determineSpecVersionFromScheme = exports.determineSpecVersionFromURI = void 0;
|
|
16
|
+
const debug_1 = __importDefault(require("debug"));
|
|
17
|
+
const types_1 = require("../types");
|
|
18
|
+
const HttpUtils_1 = require("./HttpUtils");
|
|
19
|
+
const debug = (0, debug_1.default)('sphereon:oid4vci:offer');
|
|
20
|
+
function determineSpecVersionFromURI(uri) {
|
|
21
|
+
let version = types_1.OpenId4VCIVersion.VER_UNKNOWN;
|
|
22
|
+
version = determineSpecVersionFromScheme(uri, version);
|
|
23
|
+
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, 'initiate_issuance');
|
|
24
|
+
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, 'credential_type');
|
|
25
|
+
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, 'op_state');
|
|
26
|
+
// version = getVersionFromURIParam(uri, version, OpenId4VCIVersion.VER_1_0_09, 'credentials');
|
|
27
|
+
// version = getVersionFromURIParam(uri, version, OpenId4VCIVersion.VER_1_0_09, 'initiate_issuance_uri')
|
|
28
|
+
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_1_0_12, 'credential_offer_uri=');
|
|
29
|
+
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_1_0_12, 'credential_issuer');
|
|
30
|
+
version = getVersionFromURIParam(uri, version, types_1.OpenId4VCIVersion.VER_1_0_12, 'grants');
|
|
31
|
+
/*
|
|
32
|
+
if (version === OpenId4VCIVersion.VER_UNKNOWN) { Why would we impose a version when required parameters are missing? If we need it for a specific case, please add a comment.
|
|
33
|
+
version = OpenId4VCIVersion.VER_1_0_12;
|
|
34
|
+
}
|
|
35
|
+
*/
|
|
36
|
+
return version;
|
|
37
|
+
}
|
|
38
|
+
exports.determineSpecVersionFromURI = determineSpecVersionFromURI;
|
|
39
|
+
function determineSpecVersionFromScheme(credentialOfferURI, openId4VCIVersion) {
|
|
40
|
+
const scheme = getScheme(credentialOfferURI);
|
|
41
|
+
if (credentialOfferURI.includes(types_1.DefaultURISchemes.INITIATE_ISSUANCE)) {
|
|
42
|
+
return recordVersion(openId4VCIVersion, types_1.OpenId4VCIVersion.VER_UNSUPPORTED, scheme);
|
|
43
|
+
}
|
|
44
|
+
else if (credentialOfferURI.includes(types_1.DefaultURISchemes.CREDENTIAL_OFFER)) {
|
|
45
|
+
return recordVersion(openId4VCIVersion, types_1.OpenId4VCIVersion.VER_1_0_12, scheme);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return recordVersion(openId4VCIVersion, types_1.OpenId4VCIVersion.VER_UNKNOWN, scheme);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.determineSpecVersionFromScheme = determineSpecVersionFromScheme;
|
|
52
|
+
function getScheme(credentialOfferURI) {
|
|
53
|
+
if (!credentialOfferURI || !credentialOfferURI.includes('://')) {
|
|
54
|
+
throw Error('Invalid credential offer URI');
|
|
55
|
+
}
|
|
56
|
+
return credentialOfferURI.split('://')[0];
|
|
57
|
+
}
|
|
58
|
+
exports.getScheme = getScheme;
|
|
59
|
+
function getIssuerFromCredentialOfferPayload(request) {
|
|
60
|
+
if (!request || (!('issuer' in request) && !('credential_issuer' in request))) {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
return request['credential_issuer'];
|
|
64
|
+
}
|
|
65
|
+
exports.getIssuerFromCredentialOfferPayload = getIssuerFromCredentialOfferPayload;
|
|
66
|
+
function determineSpecVersionFromOffer(offer) {
|
|
67
|
+
if (isCredentialOfferV1_0_12(offer)) {
|
|
68
|
+
return types_1.OpenId4VCIVersion.VER_1_0_12;
|
|
69
|
+
}
|
|
70
|
+
return types_1.OpenId4VCIVersion.VER_UNKNOWN;
|
|
71
|
+
}
|
|
72
|
+
exports.determineSpecVersionFromOffer = determineSpecVersionFromOffer;
|
|
73
|
+
function isCredentialOfferVersion(offer, min, max) {
|
|
74
|
+
if (max && max.valueOf() < min.valueOf()) {
|
|
75
|
+
throw Error(`Cannot have a max ${max.valueOf()} version smaller than the min version ${min.valueOf()}`);
|
|
76
|
+
}
|
|
77
|
+
const version = determineSpecVersionFromOffer(offer);
|
|
78
|
+
if (version.valueOf() < min.valueOf()) {
|
|
79
|
+
debug(`Credential offer version (${version.valueOf()}) is lower than minimum required version (${min.valueOf()})`);
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
else if (max && version.valueOf() > max.valueOf()) {
|
|
83
|
+
debug(`Credential offer version (${version.valueOf()}) is higher than maximum required version (${max.valueOf()})`);
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
exports.isCredentialOfferVersion = isCredentialOfferVersion;
|
|
89
|
+
function isCredentialOfferV1_0_12(offer) {
|
|
90
|
+
if (!offer) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
if ('credential_issuer' in offer && 'credentials' in offer) {
|
|
94
|
+
// payload
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if ('credential_offer' in offer && offer['credential_offer']) {
|
|
98
|
+
// offer, so check payload
|
|
99
|
+
return isCredentialOfferV1_0_12(offer['credential_offer']);
|
|
100
|
+
}
|
|
101
|
+
return 'credential_offer_uri' in offer;
|
|
102
|
+
}
|
|
103
|
+
function toUniformCredentialOfferRequest(offer, opts) {
|
|
104
|
+
var _a;
|
|
105
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : determineSpecVersionFromOffer(offer);
|
|
107
|
+
let originalCredentialOffer = offer.credential_offer;
|
|
108
|
+
let credentialOfferURI;
|
|
109
|
+
if ('credential_offer_uri' in offer && (offer === null || offer === void 0 ? void 0 : offer.credential_offer_uri) !== undefined) {
|
|
110
|
+
credentialOfferURI = offer.credential_offer_uri;
|
|
111
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.resolve) || (opts === null || opts === void 0 ? void 0 : opts.resolve) === undefined) {
|
|
112
|
+
originalCredentialOffer = (yield resolveCredentialOfferURI(credentialOfferURI));
|
|
113
|
+
}
|
|
114
|
+
else if (!originalCredentialOffer) {
|
|
115
|
+
throw Error(`Credential offer uri (${credentialOfferURI}) found, but resolution was explicitly disabled and credential_offer was supplied`);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (!originalCredentialOffer) {
|
|
119
|
+
throw Error('No credential offer available');
|
|
120
|
+
}
|
|
121
|
+
const payload = toUniformCredentialOfferPayload(originalCredentialOffer, opts);
|
|
122
|
+
const supportedFlows = determineFlowType(payload, version);
|
|
123
|
+
return Object.assign(Object.assign({ credential_offer: payload, original_credential_offer: originalCredentialOffer }, (credentialOfferURI && { credential_offer_uri: credentialOfferURI })), { supportedFlows,
|
|
124
|
+
version });
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
exports.toUniformCredentialOfferRequest = toUniformCredentialOfferRequest;
|
|
128
|
+
function isPreAuthCode(request) {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
const payload = 'credential_offer' in request ? request.credential_offer : request;
|
|
131
|
+
return ((_b = (_a = payload === null || payload === void 0 ? void 0 : payload.grants) === null || _a === void 0 ? void 0 : _a['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _b === void 0 ? void 0 : _b['pre-authorized_code']) !== undefined;
|
|
132
|
+
}
|
|
133
|
+
exports.isPreAuthCode = isPreAuthCode;
|
|
134
|
+
function assertedUniformCredentialOffer(origCredentialOffer, opts) {
|
|
135
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
+
const credentialOffer = JSON.parse(JSON.stringify(origCredentialOffer));
|
|
137
|
+
if (credentialOffer.credential_offer_uri && !credentialOffer.credential_offer) {
|
|
138
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.resolve) === undefined || opts.resolve) {
|
|
139
|
+
credentialOffer.credential_offer = yield resolveCredentialOfferURI(credentialOffer.credential_offer_uri);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
throw Error(`No credential_offer present, but we did get a URI, but resolution was explicitly disabled`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (!credentialOffer.credential_offer) {
|
|
146
|
+
throw Error(`No credential_offer present`);
|
|
147
|
+
}
|
|
148
|
+
credentialOffer.credential_offer = yield toUniformCredentialOfferPayload(credentialOffer.credential_offer, { version: credentialOffer.version });
|
|
149
|
+
return credentialOffer;
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
exports.assertedUniformCredentialOffer = assertedUniformCredentialOffer;
|
|
153
|
+
function resolveCredentialOfferURI(uri) {
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
if (!uri) {
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
const response = (yield (0, HttpUtils_1.getJson)(uri));
|
|
159
|
+
if (!response || !response.successBody) {
|
|
160
|
+
throw Error(`Could not get credential offer from uri: ${uri}: ${JSON.stringify(response === null || response === void 0 ? void 0 : response.errorBody)}`);
|
|
161
|
+
}
|
|
162
|
+
return response.successBody;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
exports.resolveCredentialOfferURI = resolveCredentialOfferURI;
|
|
166
|
+
function toUniformCredentialOfferPayload(offer, opts) {
|
|
167
|
+
var _a;
|
|
168
|
+
// todo: create test to check idempotence once a payload is already been made uniform.
|
|
169
|
+
const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : determineSpecVersionFromOffer(offer);
|
|
170
|
+
if (version >= types_1.OpenId4VCIVersion.VER_1_0_12) {
|
|
171
|
+
const orig = offer;
|
|
172
|
+
return Object.assign({}, orig);
|
|
173
|
+
}
|
|
174
|
+
throw Error(`Could not create uniform payload for version ${version}`);
|
|
175
|
+
}
|
|
176
|
+
exports.toUniformCredentialOfferPayload = toUniformCredentialOfferPayload;
|
|
177
|
+
function determineFlowType(suppliedOffer, version) {
|
|
178
|
+
var _a, _b, _c;
|
|
179
|
+
const payload = getCredentialOfferPayload(suppliedOffer);
|
|
180
|
+
const supportedFlows = [];
|
|
181
|
+
if ((_a = payload.grants) === null || _a === void 0 ? void 0 : _a.authorization_code) {
|
|
182
|
+
supportedFlows.push(types_1.AuthzFlowType.AUTHORIZATION_CODE_FLOW);
|
|
183
|
+
}
|
|
184
|
+
if ((_c = (_b = payload.grants) === null || _b === void 0 ? void 0 : _b['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _c === void 0 ? void 0 : _c['pre-authorized_code']) {
|
|
185
|
+
supportedFlows.push(types_1.AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW);
|
|
186
|
+
}
|
|
187
|
+
return supportedFlows;
|
|
188
|
+
}
|
|
189
|
+
exports.determineFlowType = determineFlowType;
|
|
190
|
+
function getCredentialOfferPayload(offer) {
|
|
191
|
+
let payload;
|
|
192
|
+
if ('credential_offer' in offer && offer['credential_offer']) {
|
|
193
|
+
payload = offer.credential_offer;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
payload = offer;
|
|
197
|
+
}
|
|
198
|
+
return payload;
|
|
199
|
+
}
|
|
200
|
+
exports.getCredentialOfferPayload = getCredentialOfferPayload;
|
|
201
|
+
function determineGrantTypes(offer) {
|
|
202
|
+
let grants;
|
|
203
|
+
if ('grants' in offer && offer.grants) {
|
|
204
|
+
grants = offer.grants;
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
grants = getCredentialOfferPayload(offer).grants;
|
|
208
|
+
}
|
|
209
|
+
const types = [];
|
|
210
|
+
if (grants) {
|
|
211
|
+
if (grants.authorization_code) {
|
|
212
|
+
types.push(types_1.GrantTypes.AUTHORIZATION_CODE);
|
|
213
|
+
}
|
|
214
|
+
if (grants['urn:ietf:params:oauth:grant-type:pre-authorized_code'] &&
|
|
215
|
+
grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code']) {
|
|
216
|
+
types.push(types_1.GrantTypes.PRE_AUTHORIZED_CODE);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return types;
|
|
220
|
+
}
|
|
221
|
+
exports.determineGrantTypes = determineGrantTypes;
|
|
222
|
+
function getVersionFromURIParam(credentialOfferURI, currentVersion, matchingVersion, param) {
|
|
223
|
+
if (credentialOfferURI.includes(param)) {
|
|
224
|
+
return recordVersion(currentVersion, matchingVersion, param);
|
|
225
|
+
}
|
|
226
|
+
return currentVersion;
|
|
227
|
+
}
|
|
228
|
+
function recordVersion(currentVersion, matchingVersion, key) {
|
|
229
|
+
if (currentVersion === types_1.OpenId4VCIVersion.VER_UNKNOWN || matchingVersion === currentVersion) {
|
|
230
|
+
return matchingVersion;
|
|
231
|
+
}
|
|
232
|
+
throw new Error(`Invalid param. Some keys have been used from version: ${currentVersion} version while '${key}' is used from version: ${matchingVersion}`);
|
|
233
|
+
}
|
|
234
|
+
function getTypesFromOffer(credentialOffer, opts) {
|
|
235
|
+
const types = credentialOffer.credentials.reduce((prev, curr) => {
|
|
236
|
+
// FIXME returning the string value is wrong (as it's an id), but just matching the current behavior of this library
|
|
237
|
+
// The credential_type (from draft 8) and the actual 'type' value in a VC (from draft 11) are mixed up
|
|
238
|
+
// Fix for this here: https://github.com/Sphereon-Opensource/OID4VCI/pull/54
|
|
239
|
+
if (typeof curr === 'string') {
|
|
240
|
+
return [...prev, curr];
|
|
241
|
+
}
|
|
242
|
+
else if (curr.format === 'jwt_vc_json-ld' || curr.format === 'ldp_vc') {
|
|
243
|
+
return [...prev, ...curr.credential_definition.type];
|
|
244
|
+
}
|
|
245
|
+
else if (curr.format === 'jwt_vc_json' || curr.format === 'jwt_vc') {
|
|
246
|
+
return [...prev, ...curr.types];
|
|
247
|
+
}
|
|
248
|
+
else if (curr.format === 'vc+sd-jwt') {
|
|
249
|
+
return [...prev, curr.vct];
|
|
250
|
+
}
|
|
251
|
+
return prev;
|
|
252
|
+
}, []);
|
|
253
|
+
if (!types || types.length === 0) {
|
|
254
|
+
throw Error('Could not deduce types from credential offer');
|
|
255
|
+
}
|
|
256
|
+
if (opts === null || opts === void 0 ? void 0 : opts.filterVerifiableCredential) {
|
|
257
|
+
return types.filter((type) => type !== 'VerifiableCredential');
|
|
258
|
+
}
|
|
259
|
+
return types;
|
|
260
|
+
}
|
|
261
|
+
exports.getTypesFromOffer = getTypesFromOffer;
|
|
262
262
|
//# sourceMappingURL=CredentialOfferUtil.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { OpenId4VCIVersion, UniformCredentialRequest } from '../types';
|
|
2
|
-
export declare function getTypesFromRequest(credentialRequest: UniformCredentialRequest, opts?: {
|
|
3
|
-
filterVerifiableCredential: boolean;
|
|
4
|
-
}): string[];
|
|
5
|
-
export declare function getCredentialRequestForVersion(credentialRequest: UniformCredentialRequest, version: OpenId4VCIVersion): UniformCredentialRequest;
|
|
1
|
+
import { OpenId4VCIVersion, UniformCredentialRequest } from '../types';
|
|
2
|
+
export declare function getTypesFromRequest(credentialRequest: UniformCredentialRequest, opts?: {
|
|
3
|
+
filterVerifiableCredential: boolean;
|
|
4
|
+
}): string[];
|
|
5
|
+
export declare function getCredentialRequestForVersion(credentialRequest: UniformCredentialRequest, version: OpenId4VCIVersion): UniformCredentialRequest;
|
|
6
6
|
//# sourceMappingURL=CredentialRequestUtil.d.ts.map
|