@sphereon/oid4vci-client 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.
@@ -1,88 +1,88 @@
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
- const credentialOffer = (0, functions_1.convertURIToJsonObject)(uri, {
33
- arrayTypeProperties: ['credentials'],
34
- requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['credential_offer'],
35
- });
36
- if ((credentialOffer === null || credentialOffer === void 0 ? void 0 : credentialOffer.credential_offer_uri) === undefined && !(credentialOffer === null || credentialOffer === void 0 ? void 0 : credentialOffer.credential_offer)) {
37
- throw Error('Either a credential_offer or credential_offer_uri should be present in ' + uri);
38
- }
39
- const request = yield (0, oid4vci_common_1.toUniformCredentialOfferRequest)(credentialOffer, Object.assign(Object.assign({}, opts), { version }));
40
- const grants = (_a = request.credential_offer) === null || _a === void 0 ? void 0 : _a.grants;
41
- return Object.assign(Object.assign(Object.assign(Object.assign({ scheme,
42
- 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']) && {
43
- preAuthorizedCode: grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code'],
44
- })), { 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 });
45
- });
46
- }
47
- static toURI(requestWithBaseUrl, opts) {
48
- var _a, _b;
49
- debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`);
50
- const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : requestWithBaseUrl.version;
51
- let baseUrl = requestWithBaseUrl.baseUrl.includes(requestWithBaseUrl.scheme)
52
- ? requestWithBaseUrl.baseUrl
53
- : `${requestWithBaseUrl.scheme.replace('://', '')}://${requestWithBaseUrl.baseUrl}`;
54
- let param;
55
- const isUri = requestWithBaseUrl.credential_offer_uri !== undefined;
56
- if (version.valueOf() >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_12.valueOf()) {
57
- // v11 changed from encoding every param to an encoded json object with a credential_offer param key
58
- if (!baseUrl.includes('?')) {
59
- param = isUri ? 'credential_offer_uri' : 'credential_offer';
60
- }
61
- else {
62
- const split = baseUrl.split('?');
63
- if (split.length > 1 && split[1] !== '') {
64
- if (baseUrl.endsWith('&')) {
65
- param = isUri ? 'credential_offer_uri' : 'credential_offer';
66
- }
67
- else if (!baseUrl.endsWith('=')) {
68
- baseUrl += `&`;
69
- param = isUri ? 'credential_offer_uri' : 'credential_offer';
70
- }
71
- }
72
- }
73
- }
74
- return (0, functions_1.convertJsonToURI)((_b = requestWithBaseUrl.credential_offer_uri) !== null && _b !== void 0 ? _b : requestWithBaseUrl.original_credential_offer, {
75
- baseUrl,
76
- arrayTypeProperties: isUri ? [] : ['credential_type'],
77
- uriTypeProperties: isUri
78
- ? ['credential_offer_uri']
79
- : version >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_12
80
- ? ['credential_issuer', 'credential_type']
81
- : ['issuer', 'credential_type'],
82
- param,
83
- version,
84
- });
85
- }
86
- }
87
- exports.CredentialOfferClient = CredentialOfferClient;
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
+ const credentialOffer = (0, functions_1.convertURIToJsonObject)(uri, {
33
+ arrayTypeProperties: ['credentials'],
34
+ requiredProperties: uri.includes('credential_offer_uri=') ? ['credential_offer_uri'] : ['credential_offer'],
35
+ });
36
+ if ((credentialOffer === null || credentialOffer === void 0 ? void 0 : credentialOffer.credential_offer_uri) === undefined && !(credentialOffer === null || credentialOffer === void 0 ? void 0 : credentialOffer.credential_offer)) {
37
+ throw Error('Either a credential_offer or credential_offer_uri should be present in ' + uri);
38
+ }
39
+ const request = yield (0, oid4vci_common_1.toUniformCredentialOfferRequest)(credentialOffer, Object.assign(Object.assign({}, opts), { version }));
40
+ const grants = (_a = request.credential_offer) === null || _a === void 0 ? void 0 : _a.grants;
41
+ return Object.assign(Object.assign(Object.assign(Object.assign({ scheme,
42
+ 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']) && {
43
+ preAuthorizedCode: grants['urn:ietf:params:oauth:grant-type:pre-authorized_code']['pre-authorized_code'],
44
+ })), { 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 });
45
+ });
46
+ }
47
+ static toURI(requestWithBaseUrl, opts) {
48
+ var _a, _b;
49
+ debug(`Credential Offer Request with base URL: ${JSON.stringify(requestWithBaseUrl)}`);
50
+ const version = (_a = opts === null || opts === void 0 ? void 0 : opts.version) !== null && _a !== void 0 ? _a : requestWithBaseUrl.version;
51
+ let baseUrl = requestWithBaseUrl.baseUrl.includes(requestWithBaseUrl.scheme)
52
+ ? requestWithBaseUrl.baseUrl
53
+ : `${requestWithBaseUrl.scheme.replace('://', '')}://${requestWithBaseUrl.baseUrl}`;
54
+ let param;
55
+ const isUri = requestWithBaseUrl.credential_offer_uri !== undefined;
56
+ if (version.valueOf() >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_12.valueOf()) {
57
+ // v11 changed from encoding every param to an encoded json object with a credential_offer param key
58
+ if (!baseUrl.includes('?')) {
59
+ param = isUri ? 'credential_offer_uri' : 'credential_offer';
60
+ }
61
+ else {
62
+ const split = baseUrl.split('?');
63
+ if (split.length > 1 && split[1] !== '') {
64
+ if (baseUrl.endsWith('&')) {
65
+ param = isUri ? 'credential_offer_uri' : 'credential_offer';
66
+ }
67
+ else if (!baseUrl.endsWith('=')) {
68
+ baseUrl += `&`;
69
+ param = isUri ? 'credential_offer_uri' : 'credential_offer';
70
+ }
71
+ }
72
+ }
73
+ }
74
+ return (0, functions_1.convertJsonToURI)((_b = requestWithBaseUrl.credential_offer_uri) !== null && _b !== void 0 ? _b : requestWithBaseUrl.original_credential_offer, {
75
+ baseUrl,
76
+ arrayTypeProperties: isUri ? [] : ['credential_type'],
77
+ uriTypeProperties: isUri
78
+ ? ['credential_offer_uri']
79
+ : version >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_12
80
+ ? ['credential_issuer', 'credential_type']
81
+ : ['issuer', 'credential_type'],
82
+ param,
83
+ version,
84
+ });
85
+ }
86
+ }
87
+ exports.CredentialOfferClient = CredentialOfferClient;
88
88
  //# sourceMappingURL=CredentialOfferClient.js.map
@@ -1,33 +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<DIDDoc>(opts: {
19
- proofInput: ProofOfPossessionBuilder<DIDDoc> | ProofOfPossession;
20
- credentialTypes?: string | string[];
21
- format?: CredentialFormat | OID4VCICredentialFormat;
22
- }): Promise<OpenIDResponse<CredentialResponse>>;
23
- acquireCredentialsUsingRequest(uniformRequest: UniformCredentialRequest): Promise<OpenIDResponse<CredentialResponse>>;
24
- createCredentialRequest<DIDDoc>(opts: {
25
- proofInput: ProofOfPossessionBuilder<DIDDoc> | ProofOfPossession;
26
- credentialTypes?: string | string[];
27
- format?: CredentialFormat | OID4VCICredentialFormat;
28
- version: OpenId4VCIVersion;
29
- }): Promise<UniformCredentialRequest>;
30
- private version;
31
- private isV11OrHigher;
32
- }
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<DIDDoc>(opts: {
19
+ proofInput: ProofOfPossessionBuilder<DIDDoc> | ProofOfPossession;
20
+ credentialTypes?: string | string[];
21
+ format?: CredentialFormat | OID4VCICredentialFormat;
22
+ }): Promise<OpenIDResponse<CredentialResponse>>;
23
+ acquireCredentialsUsingRequest(uniformRequest: UniformCredentialRequest): Promise<OpenIDResponse<CredentialResponse>>;
24
+ createCredentialRequest<DIDDoc>(opts: {
25
+ proofInput: ProofOfPossessionBuilder<DIDDoc> | ProofOfPossession;
26
+ credentialTypes?: string | string[];
27
+ format?: CredentialFormat | OID4VCICredentialFormat;
28
+ version: OpenId4VCIVersion;
29
+ }): Promise<UniformCredentialRequest>;
30
+ private version;
31
+ private isV12OrHigher;
32
+ }
33
33
  //# sourceMappingURL=CredentialRequestClient.d.ts.map
@@ -1,118 +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
- const request = (0, oid4vci_common_1.getCredentialRequestForVersion)(uniformRequest, this.version());
41
- const credentialEndpoint = this.credentialRequestOpts.credentialEndpoint;
42
- if (!(0, functions_1.isValidURL)(credentialEndpoint)) {
43
- debug(`Invalid credential endpoint: ${credentialEndpoint}`);
44
- throw new Error(oid4vci_common_1.URL_NOT_VALID);
45
- }
46
- debug(`Acquiring credential(s) from: ${credentialEndpoint}`);
47
- debug(`request\n: ${JSON.stringify(request, null, 2)}`);
48
- const requestToken = this.credentialRequestOpts.token;
49
- const response = yield (0, functions_1.post)(credentialEndpoint, JSON.stringify(request), { bearerToken: requestToken });
50
- debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`);
51
- return response;
52
- });
53
- }
54
- createCredentialRequest(opts) {
55
- var _a;
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const { proofInput } = opts;
58
- const formatSelection = (_a = opts.format) !== null && _a !== void 0 ? _a : this.credentialRequestOpts.format;
59
- if (!formatSelection) {
60
- throw Error(`Format of credential to be issued is missing`);
61
- }
62
- const format = (0, oid4vci_common_1.getUniformFormat)(formatSelection);
63
- const typesSelection = (opts === null || opts === void 0 ? void 0 : opts.credentialTypes) && (typeof opts.credentialTypes === 'string' || opts.credentialTypes.length > 0)
64
- ? opts.credentialTypes
65
- : this.credentialRequestOpts.credentialTypes;
66
- const types = Array.isArray(typesSelection) ? typesSelection : [typesSelection];
67
- if (types.length === 0) {
68
- throw Error(`Credential type(s) need to be provided`);
69
- }
70
- // FIXME: this is mixing up the type (as id) from v8/v9 and the types (from the vc.type) from v11
71
- else if (!this.isV11OrHigher() && types.length !== 1) {
72
- throw Error('Only a single credential type is supported for V8/V9');
73
- }
74
- const proof = 'proof_type' in proofInput
75
- ? yield ProofOfPossessionBuilder_1.ProofOfPossessionBuilder.fromProof(proofInput, opts.version).build()
76
- : yield proofInput.build();
77
- // TODO: we should move format specific logic
78
- if (format === 'jwt_vc_json' || format === 'jwt_vc') {
79
- return {
80
- types,
81
- format,
82
- proof, // TODO Don't we need credential_definition here as well?
83
- };
84
- }
85
- else if (format === 'jwt_vc_json-ld' || format === 'ldp_vc') {
86
- return {
87
- format,
88
- proof,
89
- credential_definition: {
90
- type: types,
91
- // FIXME: this was not included in the original code, but it is required
92
- '@context': [],
93
- },
94
- };
95
- }
96
- else if (format === 'vc+sd-jwt') {
97
- if (types.length > 1) {
98
- throw Error(`Only a single credential type is supported for ${format}`);
99
- }
100
- return {
101
- format,
102
- proof,
103
- vct: types[0],
104
- };
105
- }
106
- throw new Error(`Unsupported format: ${format}`);
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_12;
112
- }
113
- isV11OrHigher() {
114
- return this.version() >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_12;
115
- }
116
- }
117
- exports.CredentialRequestClient = CredentialRequestClient;
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
+ const request = (0, oid4vci_common_1.getCredentialRequestForVersion)(uniformRequest, this.version());
41
+ const credentialEndpoint = this.credentialRequestOpts.credentialEndpoint;
42
+ if (!(0, functions_1.isValidURL)(credentialEndpoint)) {
43
+ debug(`Invalid credential endpoint: ${credentialEndpoint}`);
44
+ throw new Error(oid4vci_common_1.URL_NOT_VALID);
45
+ }
46
+ debug(`Acquiring credential(s) from: ${credentialEndpoint}`);
47
+ debug(`request\n: ${JSON.stringify(request, null, 2)}`);
48
+ const requestToken = this.credentialRequestOpts.token;
49
+ const response = yield (0, functions_1.post)(credentialEndpoint, JSON.stringify(request), { bearerToken: requestToken });
50
+ debug(`Credential endpoint ${credentialEndpoint} response:\r\n${JSON.stringify(response, null, 2)}`);
51
+ return response;
52
+ });
53
+ }
54
+ createCredentialRequest(opts) {
55
+ var _a;
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ const { proofInput } = opts;
58
+ const formatSelection = (_a = opts.format) !== null && _a !== void 0 ? _a : this.credentialRequestOpts.format;
59
+ if (!formatSelection) {
60
+ throw Error(`Format of credential to be issued is missing`);
61
+ }
62
+ const format = (0, oid4vci_common_1.getUniformFormat)(formatSelection);
63
+ const typesSelection = (opts === null || opts === void 0 ? void 0 : opts.credentialTypes) && (typeof opts.credentialTypes === 'string' || opts.credentialTypes.length > 0)
64
+ ? opts.credentialTypes
65
+ : this.credentialRequestOpts.credentialTypes;
66
+ const types = Array.isArray(typesSelection) ? typesSelection : [typesSelection];
67
+ if (types.length === 0) {
68
+ throw Error(`Credential type(s) need to be provided`);
69
+ }
70
+ // FIXME: this is mixing up the type (as id) from v8/v9 and the types (from the vc.type) from v11
71
+ else if (!this.isV12OrHigher() && types.length !== 1) {
72
+ throw Error('Only a single credential type is supported for V8/V9');
73
+ }
74
+ const proof = 'proof_type' in proofInput
75
+ ? yield ProofOfPossessionBuilder_1.ProofOfPossessionBuilder.fromProof(proofInput, opts.version).build()
76
+ : yield proofInput.build();
77
+ // TODO: we should move format specific logic
78
+ if (format === 'jwt_vc_json' || format === 'jwt_vc') {
79
+ return {
80
+ types,
81
+ format,
82
+ proof, // TODO Don't we need credential_definition here as well?
83
+ };
84
+ }
85
+ else if (format === 'jwt_vc_json-ld' || format === 'ldp_vc') {
86
+ return {
87
+ format,
88
+ proof,
89
+ credential_definition: {
90
+ type: types,
91
+ // FIXME: this was not included in the original code, but it is required
92
+ '@context': [],
93
+ },
94
+ };
95
+ }
96
+ else if (format === 'vc+sd-jwt') {
97
+ if (types.length > 1) {
98
+ throw Error(`Only a single credential type is supported for ${format}`);
99
+ }
100
+ return {
101
+ format,
102
+ proof,
103
+ vct: types[0],
104
+ };
105
+ }
106
+ throw new Error(`Unsupported format: ${format}`);
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_12;
112
+ }
113
+ isV12OrHigher() {
114
+ return this.version() >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_12;
115
+ }
116
+ }
117
+ exports.CredentialRequestClient = CredentialRequestClient;
118
118
  //# sourceMappingURL=CredentialRequestClient.js.map
@@ -1,40 +1,40 @@
1
- import { AccessTokenResponse, CredentialIssuerMetadata, CredentialOfferRequestWithBaseUrl, EndpointMetadata, OID4VCICredentialFormat, OpenId4VCIVersion, UniformCredentialOfferRequest } from '@sphereon/oid4vci-common';
2
- import { CredentialFormat } from '@sphereon/ssi-types';
3
- import { CredentialRequestClient } from './CredentialRequestClient';
4
- export declare class CredentialRequestClientBuilder {
5
- credentialEndpoint?: string;
6
- credentialTypes: string[];
7
- format?: CredentialFormat | OID4VCICredentialFormat;
8
- token?: string;
9
- version?: OpenId4VCIVersion;
10
- static fromCredentialIssuer({ credentialIssuer, metadata, version, credentialTypes, }: {
11
- credentialIssuer: string;
12
- metadata?: EndpointMetadata;
13
- version?: OpenId4VCIVersion;
14
- credentialTypes: string | string[];
15
- }): CredentialRequestClientBuilder;
16
- static fromURI({ uri, metadata }: {
17
- uri: string;
18
- metadata?: EndpointMetadata;
19
- }): Promise<CredentialRequestClientBuilder>;
20
- static fromCredentialOfferRequest(opts: {
21
- request: UniformCredentialOfferRequest;
22
- scheme?: string;
23
- baseUrl?: string;
24
- version?: OpenId4VCIVersion;
25
- metadata?: EndpointMetadata;
26
- }): CredentialRequestClientBuilder;
27
- static fromCredentialOffer({ credentialOffer, metadata, }: {
28
- credentialOffer: CredentialOfferRequestWithBaseUrl;
29
- metadata?: EndpointMetadata;
30
- }): CredentialRequestClientBuilder;
31
- withCredentialEndpointFromMetadata(metadata: CredentialIssuerMetadata): CredentialRequestClientBuilder;
32
- withCredentialEndpoint(credentialEndpoint: string): CredentialRequestClientBuilder;
33
- withCredentialType(credentialTypes: string | string[]): CredentialRequestClientBuilder;
34
- withFormat(format: CredentialFormat | OID4VCICredentialFormat): CredentialRequestClientBuilder;
35
- withToken(accessToken: string): CredentialRequestClientBuilder;
36
- withTokenFromResponse(response: AccessTokenResponse): CredentialRequestClientBuilder;
37
- withVersion(version: OpenId4VCIVersion): CredentialRequestClientBuilder;
38
- build(): CredentialRequestClient;
39
- }
1
+ import { AccessTokenResponse, CredentialIssuerMetadata, CredentialOfferRequestWithBaseUrl, EndpointMetadata, OID4VCICredentialFormat, OpenId4VCIVersion, UniformCredentialOfferRequest } from '@sphereon/oid4vci-common';
2
+ import { CredentialFormat } from '@sphereon/ssi-types';
3
+ import { CredentialRequestClient } from './CredentialRequestClient';
4
+ export declare class CredentialRequestClientBuilder {
5
+ credentialEndpoint?: string;
6
+ credentialTypes: string[];
7
+ format?: CredentialFormat | OID4VCICredentialFormat;
8
+ token?: string;
9
+ version?: OpenId4VCIVersion;
10
+ static fromCredentialIssuer({ credentialIssuer, metadata, version, credentialTypes, }: {
11
+ credentialIssuer: string;
12
+ metadata?: EndpointMetadata;
13
+ version?: OpenId4VCIVersion;
14
+ credentialTypes: string | string[];
15
+ }): CredentialRequestClientBuilder;
16
+ static fromURI({ uri, metadata }: {
17
+ uri: string;
18
+ metadata?: EndpointMetadata;
19
+ }): Promise<CredentialRequestClientBuilder>;
20
+ static fromCredentialOfferRequest(opts: {
21
+ request: UniformCredentialOfferRequest;
22
+ scheme?: string;
23
+ baseUrl?: string;
24
+ version?: OpenId4VCIVersion;
25
+ metadata?: EndpointMetadata;
26
+ }): CredentialRequestClientBuilder;
27
+ static fromCredentialOffer({ credentialOffer, metadata, }: {
28
+ credentialOffer: CredentialOfferRequestWithBaseUrl;
29
+ metadata?: EndpointMetadata;
30
+ }): CredentialRequestClientBuilder;
31
+ withCredentialEndpointFromMetadata(metadata: CredentialIssuerMetadata): CredentialRequestClientBuilder;
32
+ withCredentialEndpoint(credentialEndpoint: string): CredentialRequestClientBuilder;
33
+ withCredentialType(credentialTypes: string | string[]): CredentialRequestClientBuilder;
34
+ withFormat(format: CredentialFormat | OID4VCICredentialFormat): CredentialRequestClientBuilder;
35
+ withToken(accessToken: string): CredentialRequestClientBuilder;
36
+ withTokenFromResponse(response: AccessTokenResponse): CredentialRequestClientBuilder;
37
+ withVersion(version: OpenId4VCIVersion): CredentialRequestClientBuilder;
38
+ build(): CredentialRequestClient;
39
+ }
40
40
  //# sourceMappingURL=CredentialRequestClientBuilder.d.ts.map