@sphereon/oid4vci-client 0.2.0 → 0.4.1-next.285
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -201
- package/README.md +494 -371
- package/dist/AccessTokenClient.d.ts +30 -0
- package/dist/AccessTokenClient.d.ts.map +1 -0
- package/dist/AccessTokenClient.js +222 -0
- package/dist/AccessTokenClient.js.map +1 -0
- package/dist/AuthorizationDetailsBuilder.d.ts +11 -0
- package/dist/AuthorizationDetailsBuilder.d.ts.map +1 -0
- package/dist/AuthorizationDetailsBuilder.js +44 -0
- package/dist/AuthorizationDetailsBuilder.js.map +1 -0
- package/dist/CredentialOfferClient.d.ts +10 -0
- package/dist/CredentialOfferClient.d.ts.map +1 -0
- package/dist/CredentialOfferClient.js +101 -0
- package/dist/CredentialOfferClient.js.map +1 -0
- package/dist/CredentialRequestClient.d.ts +33 -0
- package/dist/CredentialRequestClient.d.ts.map +1 -0
- package/dist/CredentialRequestClient.js +118 -0
- package/dist/CredentialRequestClient.js.map +1 -0
- package/dist/CredentialRequestClientBuilder.d.ts +34 -0
- package/dist/CredentialRequestClientBuilder.d.ts.map +1 -0
- package/dist/CredentialRequestClientBuilder.js +87 -0
- package/dist/CredentialRequestClientBuilder.js.map +1 -0
- package/dist/{main/lib/MetadataClient.d.ts → MetadataClient.d.ts} +39 -38
- package/dist/MetadataClient.d.ts.map +1 -0
- package/dist/MetadataClient.js +148 -0
- package/dist/MetadataClient.js.map +1 -0
- package/dist/OpenID4VCIClient.d.ts +75 -0
- package/dist/OpenID4VCIClient.d.ts.map +1 -0
- package/dist/OpenID4VCIClient.js +403 -0
- package/dist/OpenID4VCIClient.js.map +1 -0
- package/dist/ProofOfPossessionBuilder.d.ts +38 -0
- package/dist/ProofOfPossessionBuilder.d.ts.map +1 -0
- package/dist/ProofOfPossessionBuilder.js +129 -0
- package/dist/ProofOfPossessionBuilder.js.map +1 -0
- package/dist/functions/ProofUtil.d.ts +29 -0
- package/dist/functions/ProofUtil.d.ts.map +1 -0
- package/dist/functions/ProofUtil.js +104 -0
- package/dist/functions/ProofUtil.js.map +1 -0
- package/dist/functions/index.d.ts +4 -0
- package/dist/functions/index.d.ts.map +1 -0
- package/dist/{main → functions}/index.js +20 -18
- package/dist/functions/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{main/lib/index.js → index.js} +25 -24
- package/dist/index.js.map +1 -0
- package/lib/AccessTokenClient.ts +249 -0
- package/lib/AuthorizationDetailsBuilder.ts +46 -0
- package/lib/CredentialOfferClient.ts +108 -0
- package/lib/CredentialRequestClient.ts +137 -0
- package/lib/CredentialRequestClientBuilder.ts +110 -0
- package/lib/MetadataClient.ts +147 -0
- package/lib/OpenID4VCIClient.ts +523 -0
- package/lib/ProofOfPossessionBuilder.ts +181 -0
- package/lib/__tests__/AccessTokenClient.spec.ts +225 -0
- package/lib/__tests__/AuthorizationDetailsBuilder.spec.ts +65 -0
- package/lib/__tests__/AuthzFlowType.spec.ts +39 -0
- package/lib/__tests__/CredentialRequestClient.spec.ts +291 -0
- package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +121 -0
- package/lib/__tests__/HttpUtils.spec.ts +37 -0
- package/lib/__tests__/IT.spec.ts +173 -0
- package/lib/__tests__/IssuanceInitiation.spec.ts +48 -0
- package/lib/__tests__/JsonURIConversions.spec.ts +146 -0
- package/lib/__tests__/MetadataClient.spec.ts +203 -0
- package/lib/__tests__/MetadataMocks.ts +444 -0
- package/lib/__tests__/OpenID4VCIClient.spec.ts +166 -0
- package/lib/__tests__/OpenID4VCIClientPAR.spec.ts +112 -0
- package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +110 -0
- package/lib/__tests__/data/VciDataFixtures.ts +744 -0
- package/lib/functions/ProofUtil.ts +120 -0
- package/lib/functions/index.ts +3 -0
- package/{dist/main/lib/index.d.ts → lib/index.ts} +8 -7
- package/package.json +68 -71
- package/CHANGELOG.md +0 -21
- package/dist/main/index.d.ts +0 -1
- package/dist/main/lib/AccessTokenClient.d.ts +0 -20
- package/dist/main/lib/AccessTokenClient.js +0 -141
- package/dist/main/lib/CredentialRequestClient.d.ts +0 -31
- package/dist/main/lib/CredentialRequestClient.js +0 -66
- package/dist/main/lib/CredentialRequestClientBuilder.d.ts +0 -21
- package/dist/main/lib/CredentialRequestClientBuilder.js +0 -56
- package/dist/main/lib/IssuanceInitiation.d.ts +0 -5
- package/dist/main/lib/IssuanceInitiation.js +0 -29
- package/dist/main/lib/MetadataClient.js +0 -127
- package/dist/main/lib/functions/Encoding.d.ts +0 -17
- package/dist/main/lib/functions/Encoding.js +0 -138
- package/dist/main/lib/functions/HttpUtils.d.ts +0 -17
- package/dist/main/lib/functions/HttpUtils.js +0 -133
- package/dist/main/lib/functions/ProofUtil.d.ts +0 -9
- package/dist/main/lib/functions/ProofUtil.js +0 -76
- package/dist/main/lib/functions/index.d.ts +0 -3
- package/dist/main/lib/functions/index.js +0 -20
- package/dist/main/lib/types/Authorization.types.d.ts +0 -66
- package/dist/main/lib/types/Authorization.types.js +0 -35
- package/dist/main/lib/types/CredentialIssuance.types.d.ts +0 -88
- package/dist/main/lib/types/CredentialIssuance.types.js +0 -8
- package/dist/main/lib/types/Generic.types.d.ts +0 -19
- package/dist/main/lib/types/Generic.types.js +0 -11
- package/dist/main/lib/types/OAuth2ASMetadata.d.ts +0 -37
- package/dist/main/lib/types/OAuth2ASMetadata.js +0 -3
- package/dist/main/lib/types/OID4VCIServerMetadata.d.ts +0 -65
- package/dist/main/lib/types/OID4VCIServerMetadata.js +0 -3
- package/dist/main/lib/types/Oidc4vciErrors.d.ts +0 -3
- package/dist/main/lib/types/Oidc4vciErrors.js +0 -7
- package/dist/main/lib/types/index.d.ts +0 -6
- package/dist/main/lib/types/index.js +0 -23
- package/dist/main/tsconfig.build.tsbuildinfo +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AccessTokenRequest, AccessTokenRequestOpts, AccessTokenResponse, AuthorizationServerOpts, EndpointMetadata, IssuerOpts, OpenIDResponse } from '@sphereon/oid4vci-common';
|
|
2
|
+
export declare class AccessTokenClient {
|
|
3
|
+
acquireAccessToken(opts: AccessTokenRequestOpts): Promise<OpenIDResponse<AccessTokenResponse>>;
|
|
4
|
+
acquireAccessTokenUsingRequest({ accessTokenRequest, isPinRequired, metadata, asOpts, issuerOpts, }: {
|
|
5
|
+
accessTokenRequest: AccessTokenRequest;
|
|
6
|
+
isPinRequired?: boolean;
|
|
7
|
+
metadata?: EndpointMetadata;
|
|
8
|
+
asOpts?: AuthorizationServerOpts;
|
|
9
|
+
issuerOpts?: IssuerOpts;
|
|
10
|
+
}): Promise<OpenIDResponse<AccessTokenResponse>>;
|
|
11
|
+
createAccessTokenRequest(opts: AccessTokenRequestOpts): Promise<AccessTokenRequest>;
|
|
12
|
+
private assertPreAuthorizedGrantType;
|
|
13
|
+
private assertAuthorizationGrantType;
|
|
14
|
+
private isPinRequiredValue;
|
|
15
|
+
private assertNumericPin;
|
|
16
|
+
private assertNonEmptyPreAuthorizedCode;
|
|
17
|
+
private assertNonEmptyCodeVerifier;
|
|
18
|
+
private assertNonEmptyCode;
|
|
19
|
+
private assertNonEmptyRedirectUri;
|
|
20
|
+
private validate;
|
|
21
|
+
private sendAuthCode;
|
|
22
|
+
static determineTokenURL({ asOpts, issuerOpts, metadata, }: {
|
|
23
|
+
asOpts?: AuthorizationServerOpts;
|
|
24
|
+
issuerOpts?: IssuerOpts;
|
|
25
|
+
metadata?: EndpointMetadata;
|
|
26
|
+
}): string;
|
|
27
|
+
private static creatTokenURLFromURL;
|
|
28
|
+
private throwNotSupportedFlow;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=AccessTokenClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessTokenClient.d.ts","sourceRoot":"","sources":["../lib/AccessTokenClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAA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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.AccessTokenClient = void 0;
|
|
16
|
+
const oid4vci_common_1 = require("@sphereon/oid4vci-common");
|
|
17
|
+
const ssi_types_1 = require("@sphereon/ssi-types");
|
|
18
|
+
const debug_1 = __importDefault(require("debug"));
|
|
19
|
+
const MetadataClient_1 = require("./MetadataClient");
|
|
20
|
+
const functions_1 = require("./functions");
|
|
21
|
+
const debug = (0, debug_1.default)('sphereon:oid4vci:token');
|
|
22
|
+
class AccessTokenClient {
|
|
23
|
+
acquireAccessToken(opts) {
|
|
24
|
+
var _a;
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const { asOpts, pin, codeVerifier, code, redirectUri, metadata } = opts;
|
|
27
|
+
const credentialOffer = yield (0, oid4vci_common_1.assertedUniformCredentialOffer)(opts.credentialOffer);
|
|
28
|
+
const isPinRequired = this.isPinRequiredValue(credentialOffer.credential_offer);
|
|
29
|
+
const issuer = (_a = (0, oid4vci_common_1.getIssuerFromCredentialOfferPayload)(credentialOffer.credential_offer)) !== null && _a !== void 0 ? _a : metadata === null || metadata === void 0 ? void 0 : metadata.issuer;
|
|
30
|
+
if (!issuer) {
|
|
31
|
+
throw Error('Issuer required at this point');
|
|
32
|
+
}
|
|
33
|
+
const issuerOpts = {
|
|
34
|
+
issuer,
|
|
35
|
+
};
|
|
36
|
+
return yield this.acquireAccessTokenUsingRequest({
|
|
37
|
+
accessTokenRequest: yield this.createAccessTokenRequest({
|
|
38
|
+
credentialOffer,
|
|
39
|
+
asOpts,
|
|
40
|
+
codeVerifier,
|
|
41
|
+
code,
|
|
42
|
+
redirectUri,
|
|
43
|
+
pin,
|
|
44
|
+
}),
|
|
45
|
+
isPinRequired,
|
|
46
|
+
metadata,
|
|
47
|
+
asOpts,
|
|
48
|
+
issuerOpts,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
acquireAccessTokenUsingRequest({ accessTokenRequest, isPinRequired, metadata, asOpts, issuerOpts, }) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
this.validate(accessTokenRequest, isPinRequired);
|
|
55
|
+
const requestTokenURL = AccessTokenClient.determineTokenURL({
|
|
56
|
+
asOpts,
|
|
57
|
+
issuerOpts,
|
|
58
|
+
metadata: metadata
|
|
59
|
+
? metadata
|
|
60
|
+
: (issuerOpts === null || issuerOpts === void 0 ? void 0 : issuerOpts.fetchMetadata)
|
|
61
|
+
? yield MetadataClient_1.MetadataClient.retrieveAllMetadata(issuerOpts.issuer, { errorOnNotFound: false })
|
|
62
|
+
: undefined,
|
|
63
|
+
});
|
|
64
|
+
return this.sendAuthCode(requestTokenURL, accessTokenRequest);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
createAccessTokenRequest(opts) {
|
|
68
|
+
var _a, _b, _c, _d;
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const { asOpts, pin, codeVerifier, code, redirectUri } = opts;
|
|
71
|
+
const credentialOfferRequest = yield (0, oid4vci_common_1.toUniformCredentialOfferRequest)(opts.credentialOffer);
|
|
72
|
+
const request = {};
|
|
73
|
+
if (asOpts === null || asOpts === void 0 ? void 0 : asOpts.clientId) {
|
|
74
|
+
request.client_id = asOpts.clientId;
|
|
75
|
+
}
|
|
76
|
+
this.assertNumericPin(this.isPinRequiredValue(credentialOfferRequest.credential_offer), pin);
|
|
77
|
+
request.user_pin = pin;
|
|
78
|
+
const isPreAuth = (0, oid4vci_common_1.isPreAuthCode)(credentialOfferRequest);
|
|
79
|
+
if (isPreAuth) {
|
|
80
|
+
if (codeVerifier) {
|
|
81
|
+
throw new Error('Cannot pass a code_verifier when flow type is pre-authorized');
|
|
82
|
+
}
|
|
83
|
+
request.grant_type = oid4vci_common_1.GrantTypes.PRE_AUTHORIZED_CODE;
|
|
84
|
+
// we actually know it is there because of the isPreAuthCode call
|
|
85
|
+
request[oid4vci_common_1.PRE_AUTH_CODE_LITERAL] =
|
|
86
|
+
(_b = (_a = credentialOfferRequest === null || credentialOfferRequest === void 0 ? void 0 : credentialOfferRequest.credential_offer.grants) === null || _a === void 0 ? void 0 : _a['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _b === void 0 ? void 0 : _b[oid4vci_common_1.PRE_AUTH_CODE_LITERAL];
|
|
87
|
+
}
|
|
88
|
+
if (!isPreAuth && ((_d = (_c = credentialOfferRequest.credential_offer.grants) === null || _c === void 0 ? void 0 : _c.authorization_code) === null || _d === void 0 ? void 0 : _d.issuer_state)) {
|
|
89
|
+
this.throwNotSupportedFlow(); // not supported yet
|
|
90
|
+
request.grant_type = oid4vci_common_1.GrantTypes.AUTHORIZATION_CODE;
|
|
91
|
+
}
|
|
92
|
+
if (codeVerifier) {
|
|
93
|
+
request.code_verifier = codeVerifier;
|
|
94
|
+
request.code = code;
|
|
95
|
+
request.redirect_uri = redirectUri;
|
|
96
|
+
request.grant_type = oid4vci_common_1.GrantTypes.AUTHORIZATION_CODE;
|
|
97
|
+
}
|
|
98
|
+
if (request.grant_type === oid4vci_common_1.GrantTypes.AUTHORIZATION_CODE && isPreAuth) {
|
|
99
|
+
throw Error('A pre_authorized_code flow cannot have an issuer state in the credential offer');
|
|
100
|
+
}
|
|
101
|
+
return request;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
assertPreAuthorizedGrantType(grantType) {
|
|
105
|
+
if (oid4vci_common_1.GrantTypes.PRE_AUTHORIZED_CODE !== grantType) {
|
|
106
|
+
throw new Error("grant type must be 'urn:ietf:params:oauth:grant-type:pre-authorized_code'");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
assertAuthorizationGrantType(grantType) {
|
|
110
|
+
if (oid4vci_common_1.GrantTypes.AUTHORIZATION_CODE !== grantType) {
|
|
111
|
+
throw new Error("grant type must be 'authorization_code'");
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
isPinRequiredValue(requestPayload) {
|
|
115
|
+
var _a, _b, _c;
|
|
116
|
+
let isPinRequired = false;
|
|
117
|
+
if (!requestPayload) {
|
|
118
|
+
throw new Error(oid4vci_common_1.TokenErrorResponse.invalid_request);
|
|
119
|
+
}
|
|
120
|
+
const issuer = (0, oid4vci_common_1.getIssuerFromCredentialOfferPayload)(requestPayload);
|
|
121
|
+
if ((_a = requestPayload.grants) === null || _a === void 0 ? void 0 : _a['urn:ietf:params:oauth:grant-type:pre-authorized_code']) {
|
|
122
|
+
isPinRequired = (_c = (_b = requestPayload.grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _b === void 0 ? void 0 : _b.user_pin_required) !== null && _c !== void 0 ? _c : false;
|
|
123
|
+
}
|
|
124
|
+
debug(`Pin required for issuer ${issuer}: ${isPinRequired}`);
|
|
125
|
+
return isPinRequired;
|
|
126
|
+
}
|
|
127
|
+
assertNumericPin(isPinRequired, pin) {
|
|
128
|
+
if (isPinRequired) {
|
|
129
|
+
if (!pin || !/^\d{1,8}$/.test(pin)) {
|
|
130
|
+
debug(`Pin is not 1 to 8 digits long`);
|
|
131
|
+
throw new Error('A valid pin consisting of maximal 8 numeric characters must be present.');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
else if (pin) {
|
|
135
|
+
debug(`Pin set, whilst not required`);
|
|
136
|
+
throw new Error('Cannot set a pin, when the pin is not required.');
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
assertNonEmptyPreAuthorizedCode(accessTokenRequest) {
|
|
140
|
+
if (!accessTokenRequest[oid4vci_common_1.PRE_AUTH_CODE_LITERAL]) {
|
|
141
|
+
debug(`No pre-authorized code present, whilst it is required`);
|
|
142
|
+
throw new Error('Pre-authorization must be proven by presenting the pre-authorized code. Code must be present.');
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
assertNonEmptyCodeVerifier(accessTokenRequest) {
|
|
146
|
+
if (!accessTokenRequest.code_verifier) {
|
|
147
|
+
debug('No code_verifier present, whilst it is required');
|
|
148
|
+
throw new Error('Authorization flow requires the code_verifier to be present');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
assertNonEmptyCode(accessTokenRequest) {
|
|
152
|
+
if (!accessTokenRequest.code) {
|
|
153
|
+
debug('No code present, whilst it is required');
|
|
154
|
+
throw new Error('Authorization flow requires the code to be present');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
assertNonEmptyRedirectUri(accessTokenRequest) {
|
|
158
|
+
if (!accessTokenRequest.redirect_uri) {
|
|
159
|
+
debug('No redirect_uri present, whilst it is required');
|
|
160
|
+
throw new Error('Authorization flow requires the redirect_uri to be present');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
validate(accessTokenRequest, isPinRequired) {
|
|
164
|
+
if (accessTokenRequest.grant_type === oid4vci_common_1.GrantTypes.PRE_AUTHORIZED_CODE) {
|
|
165
|
+
this.assertPreAuthorizedGrantType(accessTokenRequest.grant_type);
|
|
166
|
+
this.assertNonEmptyPreAuthorizedCode(accessTokenRequest);
|
|
167
|
+
this.assertNumericPin(isPinRequired, accessTokenRequest.user_pin);
|
|
168
|
+
}
|
|
169
|
+
else if (accessTokenRequest.grant_type === oid4vci_common_1.GrantTypes.AUTHORIZATION_CODE) {
|
|
170
|
+
this.assertAuthorizationGrantType(accessTokenRequest.grant_type);
|
|
171
|
+
this.assertNonEmptyCodeVerifier(accessTokenRequest);
|
|
172
|
+
this.assertNonEmptyCode(accessTokenRequest);
|
|
173
|
+
this.assertNonEmptyRedirectUri(accessTokenRequest);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
this.throwNotSupportedFlow;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
sendAuthCode(requestTokenURL, accessTokenRequest) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
return yield (0, functions_1.formPost)(requestTokenURL, (0, functions_1.convertJsonToURI)(accessTokenRequest));
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
static determineTokenURL({ asOpts, issuerOpts, metadata, }) {
|
|
185
|
+
if (!asOpts && !(metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) && !issuerOpts) {
|
|
186
|
+
throw new Error('Cannot determine token URL if no issuer, metadata and no Authorization Server values are present');
|
|
187
|
+
}
|
|
188
|
+
let url;
|
|
189
|
+
if (asOpts && asOpts.as) {
|
|
190
|
+
url = this.creatTokenURLFromURL(asOpts.as, asOpts === null || asOpts === void 0 ? void 0 : asOpts.allowInsecureEndpoints, asOpts.tokenEndpoint);
|
|
191
|
+
}
|
|
192
|
+
else if (metadata === null || metadata === void 0 ? void 0 : metadata.token_endpoint) {
|
|
193
|
+
url = metadata.token_endpoint;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
if (!(issuerOpts === null || issuerOpts === void 0 ? void 0 : issuerOpts.issuer)) {
|
|
197
|
+
throw Error('Either authorization server options, a token endpoint or issuer options are required at this point');
|
|
198
|
+
}
|
|
199
|
+
url = this.creatTokenURLFromURL(issuerOpts.issuer, asOpts === null || asOpts === void 0 ? void 0 : asOpts.allowInsecureEndpoints, issuerOpts.tokenEndpoint);
|
|
200
|
+
}
|
|
201
|
+
if (!url || !ssi_types_1.ObjectUtils.isString(url)) {
|
|
202
|
+
throw new Error('No authorization server token URL present. Cannot acquire access token');
|
|
203
|
+
}
|
|
204
|
+
debug(`Token endpoint determined to be ${url}`);
|
|
205
|
+
return url;
|
|
206
|
+
}
|
|
207
|
+
static creatTokenURLFromURL(url, allowInsecureEndpoints, tokenEndpoint) {
|
|
208
|
+
if (allowInsecureEndpoints !== true && url.startsWith('http:')) {
|
|
209
|
+
throw Error(`Unprotected token endpoints are not allowed ${url}. Adjust settings if you really need this (dev/test settings only!!)`);
|
|
210
|
+
}
|
|
211
|
+
const hostname = url.replace(/https?:\/\//, '').replace(/\/$/, '');
|
|
212
|
+
const endpoint = tokenEndpoint ? (tokenEndpoint.startsWith('/') ? tokenEndpoint : tokenEndpoint.substring(1)) : '/token';
|
|
213
|
+
const scheme = url.split('://')[0];
|
|
214
|
+
return `${scheme ? scheme + '://' : 'https://'}${hostname}${endpoint}`;
|
|
215
|
+
}
|
|
216
|
+
throwNotSupportedFlow() {
|
|
217
|
+
debug(`Only pre-authorized flow supported.`);
|
|
218
|
+
throw new Error('Only pre-authorized-code flow is supported');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.AccessTokenClient = AccessTokenClient;
|
|
222
|
+
//# sourceMappingURL=AccessTokenClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AccessTokenClient.js","sourceRoot":"","sources":["../lib/AccessTokenClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DAgBkC;AAClC,mDAAkD;AAClD,kDAA0B;AAE1B,qDAAkD;AAClD,2CAAyD;AAEzD,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,wBAAwB,CAAC,CAAC;AAE9C,MAAa,iBAAiB;IACf,kBAAkB,CAAC,IAA4B;;;YAC1D,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,GAAG,IA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,UAAU,GAAG,QAAQ,GAAG,QAAQ,EAAE,CAAC;IACzE,CAAC;IAEO,qBAAqB;QAC3B,KAAK,CAAC,qCAAqC,CAAC,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAChE,CAAC;CACF;AA/ND,8CA+NC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AuthorizationDetailsJwtVcJson, OID4VCICredentialFormat } from '@sphereon/oid4vci-common';
|
|
2
|
+
export declare class AuthorizationDetailsBuilder {
|
|
3
|
+
private readonly authorizationDetails;
|
|
4
|
+
constructor();
|
|
5
|
+
withType(type: string): AuthorizationDetailsBuilder;
|
|
6
|
+
withFormats(format: OID4VCICredentialFormat): AuthorizationDetailsBuilder;
|
|
7
|
+
withLocations(locations: string[]): AuthorizationDetailsBuilder;
|
|
8
|
+
addLocation(location: string): AuthorizationDetailsBuilder;
|
|
9
|
+
buildJwtVcJson(): AuthorizationDetailsJwtVcJson;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=AuthorizationDetailsBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthorizationDetailsBuilder.d.ts","sourceRoot":"","sources":["../lib/AuthorizationDetailsBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAGlG,qBAAa,2BAA2B;IACtC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAyC;;IAM9E,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,2BAA2B;IAKnD,WAAW,CAAC,MAAM,EAAE,uBAAuB,GAAG,2BAA2B;IAKzE,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,2BAA2B;IAS/D,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,2BAA2B;IAU1D,cAAc,IAAI,6BAA6B;CAMhD"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizationDetailsBuilder = void 0;
|
|
4
|
+
//todo: refactor this builder to be able to create ldp details as well
|
|
5
|
+
class AuthorizationDetailsBuilder {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.authorizationDetails = {};
|
|
8
|
+
}
|
|
9
|
+
withType(type) {
|
|
10
|
+
this.authorizationDetails.type = type;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
withFormats(format) {
|
|
14
|
+
this.authorizationDetails.format = format;
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
withLocations(locations) {
|
|
18
|
+
if (this.authorizationDetails.locations) {
|
|
19
|
+
this.authorizationDetails.locations.push(...locations);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.authorizationDetails.locations = locations;
|
|
23
|
+
}
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
addLocation(location) {
|
|
27
|
+
if (this.authorizationDetails.locations) {
|
|
28
|
+
this.authorizationDetails.locations.push(location);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.authorizationDetails.locations = [location];
|
|
32
|
+
}
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
//todo: we have to consider one thing, if this is a general purpose builder, we want to support ldp types here as well. and for that we need a few checks.
|
|
36
|
+
buildJwtVcJson() {
|
|
37
|
+
if (this.authorizationDetails.format && this.authorizationDetails.type) {
|
|
38
|
+
return this.authorizationDetails;
|
|
39
|
+
}
|
|
40
|
+
throw new Error('Type and format are required properties');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.AuthorizationDetailsBuilder = AuthorizationDetailsBuilder;
|
|
44
|
+
//# sourceMappingURL=AuthorizationDetailsBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AuthorizationDetailsBuilder.js","sourceRoot":"","sources":["../lib/AuthorizationDetail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-common';
|
|
2
|
+
export declare class CredentialOfferClient {
|
|
3
|
+
static fromURI(uri: string, opts?: {
|
|
4
|
+
resolve?: boolean;
|
|
5
|
+
}): Promise<CredentialOfferRequestWithBaseUrl>;
|
|
6
|
+
static toURI(requestWithBaseUrl: CredentialOfferRequestWithBaseUrl, opts?: {
|
|
7
|
+
version?: OpenId4VCIVersion;
|
|
8
|
+
}): string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=CredentialOfferClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialOfferClient.d.ts","sourceRoot":"","sources":["../lib/CredentialOfferClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,iCAAiC,EAGjC,iBAAiB,EAElB,MAAM,0BAA0B,CAAC;AAOlC,qBAAa,qBAAqB;WACZ,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,iCAAiC,CAAC;WA+CpG,KAAK,CACjB,kBAAkB,EAAE,iCAAiC,EACrD,IAAI,CAAC,EAAE;QACL,OAAO,CAAC,EAAE,iBAAiB,CAAC;KAC7B,GACA,MAAM;CAsCV"}
|
|
@@ -0,0 +1,101 @@
|
|
|
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.CredentialOfferClient = void 0;
|
|
16
|
+
const oid4vci_common_1 = require("@sphereon/oid4vci-common");
|
|
17
|
+
const debug_1 = __importDefault(require("debug"));
|
|
18
|
+
const functions_1 = require("./functions");
|
|
19
|
+
const debug = (0, debug_1.default)('sphereon:oid4vci:offer');
|
|
20
|
+
class CredentialOfferClient {
|
|
21
|
+
static fromURI(uri, opts) {
|
|
22
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
debug(`Credential Offer URI: ${uri}`);
|
|
25
|
+
if (!uri.includes('?') || !uri.includes('://')) {
|
|
26
|
+
debug(`Invalid Credential Offer URI: ${uri}`);
|
|
27
|
+
throw Error(`Invalid Credential Offer Request`);
|
|
28
|
+
}
|
|
29
|
+
const scheme = uri.split('://')[0];
|
|
30
|
+
const baseUrl = uri.split('?')[0];
|
|
31
|
+
const version = (0, oid4vci_common_1.determineSpecVersionFromURI)(uri);
|
|
32
|
+
let credentialOffer;
|
|
33
|
+
let credentialOfferPayload;
|
|
34
|
+
if (version < oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11) {
|
|
35
|
+
credentialOfferPayload = (0, functions_1.convertURIToJsonObject)(uri, {
|
|
36
|
+
arrayTypeProperties: ['credential_type'],
|
|
37
|
+
requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['issuer', 'credential_type'],
|
|
38
|
+
});
|
|
39
|
+
credentialOffer = {
|
|
40
|
+
credential_offer: credentialOfferPayload,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
credentialOffer = (0, functions_1.convertURIToJsonObject)(uri, {
|
|
45
|
+
arrayTypeProperties: ['credentials'],
|
|
46
|
+
requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['credential_offer'],
|
|
47
|
+
});
|
|
48
|
+
if ((credentialOffer === null || credentialOffer === void 0 ? void 0 : credentialOffer.credential_offer_uri) === undefined && !(credentialOffer === null || credentialOffer === void 0 ? void 0 : credentialOffer.credential_offer)) {
|
|
49
|
+
throw Error('Either a credential_offer or credential_offer_uri should be present in ' + uri);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const request = yield (0, oid4vci_common_1.toUniformCredentialOfferRequest)(credentialOffer, Object.assign(Object.assign({}, opts), { version }));
|
|
53
|
+
const grants = (_a = request.credential_offer) === null || _a === void 0 ? void 0 : _a.grants;
|
|
54
|
+
return Object.assign(Object.assign(Object.assign(Object.assign({ scheme,
|
|
55
|
+
baseUrl }, request), (((_b = grants === null || grants === void 0 ? void 0 : grants.authorization_code) === null || _b === void 0 ? void 0 : _b.issuer_state) && { issuerState: grants.authorization_code.issuer_state })), (((_c = grants === null || grants === void 0 ? void 0 : grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _c === void 0 ? void 0 : _c['pre-authorized_code']) && {
|
|
56
|
+
preAuthorizedCode: grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code'],
|
|
57
|
+
})), { userPinRequired: (_g = (_f = (_e = (_d = request.credential_offer) === null || _d === void 0 ? void 0 : _d.grants) === null || _e === void 0 ? void 0 : _e['urn:ietf:params:oauth:grant-type:pre-authorized_code']) === null || _f === void 0 ? void 0 : _f.user_pin_required) !== null && _g !== void 0 ? _g : false });
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
static toURI(requestWithBaseUrl, opts) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`);
|
|
63
|
+
const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : requestWithBaseUrl.version;
|
|
64
|
+
let baseUrl = requestWithBaseUrl.baseUrl.includes(requestWithBaseUrl.scheme)
|
|
65
|
+
? requestWithBaseUrl.baseUrl
|
|
66
|
+
: `${requestWithBaseUrl.scheme.replace('://', '')}://${requestWithBaseUrl.baseUrl}`;
|
|
67
|
+
let param;
|
|
68
|
+
const isUri = requestWithBaseUrl.credential_offer_uri !== undefined;
|
|
69
|
+
if (version.valueOf() >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11.valueOf()) {
|
|
70
|
+
// v11 changed from encoding every param to a encoded json object with a credential_offer param key
|
|
71
|
+
if (!baseUrl.includes('?')) {
|
|
72
|
+
param = isUri ? 'credential_offer_uri' : 'credential_offer';
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const split = baseUrl.split('?');
|
|
76
|
+
if (split.length > 1 && split[1] !== '') {
|
|
77
|
+
if (baseUrl.endsWith('&')) {
|
|
78
|
+
param = isUri ? 'credential_offer_uri' : 'credential_offer';
|
|
79
|
+
}
|
|
80
|
+
else if (!baseUrl.endsWith('=')) {
|
|
81
|
+
baseUrl += `&`;
|
|
82
|
+
param = isUri ? 'credential_offer_uri' : 'credential_offer';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return (0, functions_1.convertJsonToURI)((_b = requestWithBaseUrl.credential_offer_uri) !== null && _b !== void 0 ? _b : requestWithBaseUrl.original_credential_offer, {
|
|
88
|
+
baseUrl,
|
|
89
|
+
arrayTypeProperties: isUri ? [] : ['credential_type'],
|
|
90
|
+
uriTypeProperties: isUri
|
|
91
|
+
? ['credential_offer_uri']
|
|
92
|
+
: version >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11
|
|
93
|
+
? ['credential_issuer', 'credential_type']
|
|
94
|
+
: ['issuer', 'credential_type'],
|
|
95
|
+
param,
|
|
96
|
+
version,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.CredentialOfferClient = CredentialOfferClient;
|
|
101
|
+
//# sourceMappingURL=CredentialOfferClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialOfferClient.js","sourceRoot":"","sources":["../lib/CredentialOfferClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,6DASkC;AAClC,kDAA0B;AAE1B,2CAAuE;AAEvE,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,wBAAwB,CAAC,CAAC;AAE9C,MAAa,qBAAqB;IACzB,MAAM,CAAO,OAAO,CAAC,GAAW,EAAE,IAA4B;;;YACnE,KAAK,CAAC,yBAAyB,GAAG,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;gBAC9C,KAAK,CAAC,iCAAiC,GAAG,EAAE,CAAC,CAAC;gBAC9C,MAAM,KAAK,CAAC,kCAAkC,CAAC,CAAC;aACjD;YACD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACnC,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YAClC,MAAM,OAAO,GAAG,IAAA,4CAA2B,EAAC,GAAG,CAAC,CAAC;YACjD,IAAI,eAAgC,CAAC;YACrC,IAAI,sBAA8C,CAAC;YACnD,IAAI,OAAO,GAAG,kCAAiB,CAAC,UAAU,EAAE;gBAC1C,sBAAsB,GAAG,IAAA,kCAAsB,EAAC,GAAG,EAAE;oBACnD,mBAAmB,EAAE,CAAC,iBAAiB,CAAC;oBACxC,kBAAkB,EAAE,GAAG,CAAC,QAAQ,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,iBAAiB,CAAC;iBACrH,CAAkC,CAAC;gBACp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AAI,GAAG,CAAC;wBACf,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,kBAAkB,CAAC;qBAC7D;iBACF;aACF;SACF;QACD,OAAO,IAAA,4BAAgB,EAAC,MAAA,kBAAkB,CAAC,oBAAoB,mCAAI,kBAAkB,CAAC,yBAAyB,EAAE;YAC/G,OAAO;YACP,mBAAmB,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC;YACrD,iBAAiB,EAAE,KAAK;gBACtB,CAAC,CAAC,CAAC,sBAAsB,CAAC;gBAC1B,CAAC,CAAC,OAAO,IAAI,kCAAiB,CAAC,UAAU;oBACzC,CAAC,CAAC,CAAC,mBAAmB,EAAE,iBAAiB,CAAC;oBAC1C,CAAC,CAAC,CAAC,QAAQ,EAAE,iBAAiB,CAAC;YACjC,KAAK;YACL,OAAO;SACR,CAAC,CAAC;IACL,CAAC;CACF;AA3FD,sDA2FC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CredentialResponse, OID4VCICredentialFormat, OpenId4VCIVersion, OpenIDResponse, ProofOfPossession, UniformCredentialRequest } from '@sphereon/oid4vci-common';
|
|
2
|
+
import { CredentialFormat } from '@sphereon/ssi-types';
|
|
3
|
+
import { CredentialRequestClientBuilder } from './CredentialRequestClientBuilder';
|
|
4
|
+
import { ProofOfPossessionBuilder } from './ProofOfPossessionBuilder';
|
|
5
|
+
export interface CredentialRequestOpts {
|
|
6
|
+
credentialEndpoint: string;
|
|
7
|
+
credentialTypes: string[];
|
|
8
|
+
format?: CredentialFormat | OID4VCICredentialFormat;
|
|
9
|
+
proof: ProofOfPossession;
|
|
10
|
+
token: string;
|
|
11
|
+
version: OpenId4VCIVersion;
|
|
12
|
+
}
|
|
13
|
+
export declare class CredentialRequestClient {
|
|
14
|
+
private readonly _credentialRequestOpts;
|
|
15
|
+
get credentialRequestOpts(): CredentialRequestOpts;
|
|
16
|
+
getCredentialEndpoint(): string;
|
|
17
|
+
constructor(builder: CredentialRequestClientBuilder);
|
|
18
|
+
acquireCredentialsUsingProof(opts: {
|
|
19
|
+
proofInput: ProofOfPossessionBuilder | ProofOfPossession;
|
|
20
|
+
credentialTypes?: string | string[];
|
|
21
|
+
format?: CredentialFormat | OID4VCICredentialFormat;
|
|
22
|
+
}): Promise<OpenIDResponse<CredentialResponse>>;
|
|
23
|
+
acquireCredentialsUsingRequest(uniformRequest: UniformCredentialRequest): Promise<OpenIDResponse<CredentialResponse>>;
|
|
24
|
+
createCredentialRequest(opts: {
|
|
25
|
+
proofInput: ProofOfPossessionBuilder | ProofOfPossession;
|
|
26
|
+
credentialTypes?: string | string[];
|
|
27
|
+
format?: CredentialFormat | OID4VCICredentialFormat;
|
|
28
|
+
version: OpenId4VCIVersion;
|
|
29
|
+
}): Promise<UniformCredentialRequest>;
|
|
30
|
+
private version;
|
|
31
|
+
private isV11OrHigher;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=CredentialRequestClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CredentialRequestClient.d.ts","sourceRoot":"","sources":["../lib/CredentialRequestClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,uBAAuB,EACvB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,wBAAwB,EAEzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAKtE,MAAM,WAAW,qBAAqB;IACpC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAAC;IACpD,KAAK,EAAE,iBAAiB,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,iBAAiB,CAAC;CAC5B;AAED,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAiC;IAExE,IAAI,qBAAqB,IAAI,qBAAqB,CAEjD;IAEM,qBAAqB,IAAI,MAAM;gBAInB,OAAO,EAAE,8BAA8B;IAI7C,4BAA4B,CAAC,IAAI,EAAE;QAC9C,UAAU,EAAE,wBAAwB,GAAG,iBAAiB,CAAC;QACzD,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QACpC,MAAM,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAAC;KACrD,GAAG,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IAOlC,8BAA8B,CAAC,cAAc,EAAE,wBAAwB,GAAG,OAAO,CAAC,cAAc,CAAC,kBAAkB,CAAC,CAAC;IA+BrH,uBAAuB,CAAC,IAAI,EAAE;QACzC,UAAU,EAAE,wBAAwB,GAAG,iBAAiB,CAAC;QACzD,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QACpC,MAAM,CAAC,EAAE,gBAAgB,GAAG,uBAAuB,CAAC;QACpD,OAAO,EAAE,iBAAiB,CAAC;KAC5B,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAwCrC,OAAO,CAAC,OAAO;IAGf,OAAO,CAAC,aAAa;CAGtB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
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.CredentialRequestClient = void 0;
|
|
16
|
+
const oid4vci_common_1 = require("@sphereon/oid4vci-common");
|
|
17
|
+
const debug_1 = __importDefault(require("debug"));
|
|
18
|
+
const ProofOfPossessionBuilder_1 = require("./ProofOfPossessionBuilder");
|
|
19
|
+
const functions_1 = require("./functions");
|
|
20
|
+
const debug = (0, debug_1.default)('sphereon:oid4vci:credential');
|
|
21
|
+
class CredentialRequestClient {
|
|
22
|
+
get credentialRequestOpts() {
|
|
23
|
+
return this._credentialRequestOpts;
|
|
24
|
+
}
|
|
25
|
+
getCredentialEndpoint() {
|
|
26
|
+
return this.credentialRequestOpts.credentialEndpoint;
|
|
27
|
+
}
|
|
28
|
+
constructor(builder) {
|
|
29
|
+
this._credentialRequestOpts = Object.assign({}, builder);
|
|
30
|
+
}
|
|
31
|
+
acquireCredentialsUsingProof(opts) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const { credentialTypes, proofInput, format } = opts;
|
|
34
|
+
const request = yield this.createCredentialRequest({ proofInput, credentialTypes, format, version: this.version() });
|
|
35
|
+
return yield this.acquireCredentialsUsingRequest(request);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
acquireCredentialsUsingRequest(uniformRequest) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
let request = uniformRequest;
|
|
41
|
+
if (!this.isV11OrHigher()) {
|
|
42
|
+
let format = uniformRequest.format;
|
|
43
|
+
if (format === 'jwt_vc_json') {
|
|
44
|
+
format = 'jwt_vc';
|
|
45
|
+
}
|
|
46
|
+
else if (format === 'jwt_vc_json-ld') {
|
|
47
|
+
format = 'ldp_vc';
|
|
48
|
+
}
|
|
49
|
+
request = {
|
|
50
|
+
format,
|
|
51
|
+
proof: uniformRequest.proof,
|
|
52
|
+
type: 'types' in uniformRequest
|
|
53
|
+
? uniformRequest.types.filter((t) => t !== 'VerifiableCredential')[0]
|
|
54
|
+
: uniformRequest.credential_definition.types[0],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const credentialEndpoint = this.credentialRequestOpts.credentialEndpoint;
|
|
58
|
+
if (!(0, functions_1.isValidURL)(credentialEndpoint)) {
|
|
59
|
+
debug(`Invalid credential endpoint: ${credentialEndpoint}`);
|
|
60
|
+
throw new Error(oid4vci_common_1.URL_NOT_VALID);
|
|
61
|
+
}
|
|
62
|
+
debug(`Acquiring credential(s) from: ${credentialEndpoint}`);
|
|
63
|
+
const requestToken = this.credentialRequestOpts.token;
|
|
64
|
+
const response = yield (0, functions_1.post)(credentialEndpoint, JSON.stringify(request), { bearerToken: requestToken });
|
|
65
|
+
debug(`Credential endpoint ${credentialEndpoint} response:\r\n${response}`);
|
|
66
|
+
return response;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
createCredentialRequest(opts) {
|
|
70
|
+
var _a;
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const { proofInput } = opts;
|
|
73
|
+
const formatSelection = (_a = opts.format) !== null && _a !== void 0 ? _a : this.credentialRequestOpts.format;
|
|
74
|
+
let format = formatSelection;
|
|
75
|
+
if (opts.version < oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11) {
|
|
76
|
+
if (formatSelection === 'jwt_vc' || formatSelection === 'jwt') {
|
|
77
|
+
format = 'jwt_vc_json';
|
|
78
|
+
}
|
|
79
|
+
else if (formatSelection === 'ldp_vc' || formatSelection === 'ldp') {
|
|
80
|
+
format = 'jwt_vc_json-ld';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (!format) {
|
|
84
|
+
throw Error(`Format of credential to be issued is missing`);
|
|
85
|
+
}
|
|
86
|
+
else if (format !== 'jwt_vc_json-ld' && format !== 'jwt_vc_json' && format !== 'ldp_vc') {
|
|
87
|
+
throw Error(`Invalid format of credential to be issued: ${format}`);
|
|
88
|
+
}
|
|
89
|
+
const typesSelection = (opts === null || opts === void 0 ? void 0 : opts.credentialTypes) && (typeof opts.credentialTypes === 'string' || opts.credentialTypes.length > 0)
|
|
90
|
+
? opts.credentialTypes
|
|
91
|
+
: this.credentialRequestOpts.credentialTypes;
|
|
92
|
+
const types = Array.isArray(typesSelection) ? typesSelection : [typesSelection];
|
|
93
|
+
if (types.length === 0) {
|
|
94
|
+
throw Error(`Credential type(s) need to be provided`);
|
|
95
|
+
}
|
|
96
|
+
else if (!this.isV11OrHigher() && types.length !== 1) {
|
|
97
|
+
throw Error('Only a single credential type is supported for V8/V9');
|
|
98
|
+
}
|
|
99
|
+
const proof = 'proof_type' in proofInput
|
|
100
|
+
? yield ProofOfPossessionBuilder_1.ProofOfPossessionBuilder.fromProof(proofInput, opts.version).build()
|
|
101
|
+
: yield proofInput.build();
|
|
102
|
+
return {
|
|
103
|
+
types,
|
|
104
|
+
format,
|
|
105
|
+
proof,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
version() {
|
|
110
|
+
var _a, _b;
|
|
111
|
+
return (_b = (_a = this.credentialRequestOpts) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11;
|
|
112
|
+
}
|
|
113
|
+
isV11OrHigher() {
|
|
114
|
+
return this.version() >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_11;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.CredentialRequestClient = CredentialRequestClient;
|
|
118
|
+
//# sourceMappingURL=CredentialRequestClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,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