@sphereon/oid4vci-client 0.12.1-unstable.4 → 0.12.1-unstable.7

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,28 +1,43 @@
1
- import { CredentialOfferRequestWithBaseUrl, EndpointMetadata, OpenId4VCIVersion, UniformCredentialOfferRequest } from '@sphereon/oid4vci-common';
2
- import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11';
3
- import { CredentialRequestClientBuilderV1_0_13 } from './CredentialRequestClientBuilderV1_0_13';
1
+ import { AccessTokenResponse, CredentialIssuerMetadata, CredentialIssuerMetadataV1_0_13, CredentialOfferRequestWithBaseUrl, EndpointMetadata, ExperimentalSubjectIssuance, OID4VCICredentialFormat, OpenId4VCIVersion, UniformCredentialOfferRequest } from '@sphereon/oid4vci-common';
2
+ import { CredentialFormat } from '@sphereon/ssi-types';
4
3
  export declare class CredentialRequestClientBuilder {
4
+ private _builder;
5
+ private constructor();
5
6
  static fromCredentialIssuer({ credentialIssuer, metadata, version, credentialIdentifier, credentialTypes, }: {
6
7
  credentialIssuer: string;
7
8
  metadata?: EndpointMetadata;
8
9
  version?: OpenId4VCIVersion;
9
10
  credentialIdentifier?: string;
10
11
  credentialTypes?: string | string[];
11
- }): CredentialRequestClientBuilderV1_0_13 | CredentialRequestClientBuilderV1_0_11;
12
- static fromURI({ uri, metadata, }: {
12
+ }): CredentialRequestClientBuilder;
13
+ static fromURI({ uri, metadata }: {
13
14
  uri: string;
14
15
  metadata?: EndpointMetadata;
15
- }): Promise<CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13>;
16
+ }): Promise<CredentialRequestClientBuilder>;
16
17
  static fromCredentialOfferRequest(opts: {
17
18
  request: UniformCredentialOfferRequest;
18
19
  scheme?: string;
19
20
  baseUrl?: string;
20
21
  version?: OpenId4VCIVersion;
21
22
  metadata?: EndpointMetadata;
22
- }): CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13;
23
+ }): CredentialRequestClientBuilder;
23
24
  static fromCredentialOffer({ credentialOffer, metadata, }: {
24
25
  credentialOffer: CredentialOfferRequestWithBaseUrl;
25
26
  metadata?: EndpointMetadata;
26
- }): CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13;
27
+ }): CredentialRequestClientBuilder;
28
+ getVersion(): OpenId4VCIVersion | undefined;
29
+ withCredentialEndpointFromMetadata(metadata: CredentialIssuerMetadata | CredentialIssuerMetadataV1_0_13): this;
30
+ withCredentialEndpoint(credentialEndpoint: string): this;
31
+ withDeferredCredentialEndpointFromMetadata(metadata: CredentialIssuerMetadata | CredentialIssuerMetadataV1_0_13): this;
32
+ withDeferredCredentialEndpoint(deferredCredentialEndpoint: string): this;
33
+ withDeferredCredentialAwait(deferredCredentialAwait: boolean, deferredCredentialIntervalInMS?: number): this;
34
+ withCredentialIdentifier(credentialIdentifier: string): this;
35
+ withCredentialType(credentialTypes: string | string[]): this;
36
+ withFormat(format: CredentialFormat | OID4VCICredentialFormat): this;
37
+ withSubjectIssuance(subjectIssuance: ExperimentalSubjectIssuance): this;
38
+ withToken(accessToken: string): this;
39
+ withTokenFromResponse(response: AccessTokenResponse): this;
40
+ withVersion(version: OpenId4VCIVersion): this;
41
+ build(): import("./CredentialRequestClientV1_0_11").CredentialRequestClientV1_0_11 | import("./CredentialRequestClient").CredentialRequestClient;
27
42
  }
28
43
  //# sourceMappingURL=CredentialRequestClientBuilder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"CredentialRequestClientBuilder.d.ts","sourceRoot":"","sources":["../lib/CredentialRequestClientBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAEjC,gBAAgB,EAChB,iBAAiB,EACjB,6BAA6B,EAC9B,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,qCAAqC,EAAE,MAAM,yCAAyC,CAAC;AAChG,OAAO,EAAE,qCAAqC,EAAE,MAA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+BAA+B,GAAG,IAAI;IAStH,8BAA8B,CAAC,0BAA0B,EAAE,MAAM,GAAG,IAAI;IAKxE,2BAA2B,CAAC,uBAAuB,EAAE,OAAO,EAAE,8BAA8B,CAAC,EAAE,MAAM,GAAG,IAAI;IAK5G,wBAAwB,CAAC,oBAAoB,EAAE,MAAM,GAAG,IAAI;IAQ5D,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAK5D,UAAU,CAAC,MAAM,EAAE,gBAAgB,GAAG,uBAAuB,GAAG,IAAI;IAKpE,mBAAmB,CAAC,eAAe,EAAE,2BAA2B,GAAG,IAAI;IAKvE,SAAS,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAKpC,qBAAqB,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI;IAK1D,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;IAK7C,KAAK;CAGb"}
@@ -14,11 +14,18 @@ const oid4vci_common_1 = require("@sphereon/oid4vci-common");
14
14
  const CredentialOfferClient_1 = require("./CredentialOfferClient");
15
15
  const CredentialRequestClientBuilderV1_0_11_1 = require("./CredentialRequestClientBuilderV1_0_11");
16
16
  const CredentialRequestClientBuilderV1_0_13_1 = require("./CredentialRequestClientBuilderV1_0_13");
17
+ function isV1_0_13(builder) {
18
+ return builder.withCredentialIdentifier !== undefined;
19
+ }
17
20
  class CredentialRequestClientBuilder {
21
+ constructor(builder) {
22
+ this._builder = builder;
23
+ }
18
24
  static fromCredentialIssuer({ credentialIssuer, metadata, version, credentialIdentifier, credentialTypes, }) {
19
- const specVersion = version ? version : oid4vci_common_1.OpenId4VCIVersion.VER_1_0_13;
25
+ const specVersion = version !== null && version !== void 0 ? version : oid4vci_common_1.OpenId4VCIVersion.VER_1_0_13;
26
+ let builder;
20
27
  if (specVersion >= oid4vci_common_1.OpenId4VCIVersion.VER_1_0_13) {
21
- return CredentialRequestClientBuilderV1_0_13_1.CredentialRequestClientBuilderV1_0_13.fromCredentialIssuer({
28
+ builder = CredentialRequestClientBuilderV1_0_13_1.CredentialRequestClientBuilderV1_0_13.fromCredentialIssuer({
22
29
  credentialIssuer,
23
30
  metadata,
24
31
  version,
@@ -30,10 +37,16 @@ class CredentialRequestClientBuilder {
30
37
  if (!credentialTypes || credentialTypes.length === 0) {
31
38
  throw new Error('CredentialTypes must be provided for v1_0_11');
32
39
  }
33
- return CredentialRequestClientBuilderV1_0_11_1.CredentialRequestClientBuilderV1_0_11.fromCredentialIssuer({ credentialIssuer, metadata, version, credentialTypes });
40
+ builder = CredentialRequestClientBuilderV1_0_11_1.CredentialRequestClientBuilderV1_0_11.fromCredentialIssuer({
41
+ credentialIssuer,
42
+ metadata,
43
+ version,
44
+ credentialTypes,
45
+ });
34
46
  }
47
+ return new CredentialRequestClientBuilder(builder);
35
48
  }
36
- static fromURI({ uri, metadata, }) {
49
+ static fromURI({ uri, metadata }) {
37
50
  return __awaiter(this, void 0, void 0, function* () {
38
51
  const offer = yield CredentialOfferClient_1.CredentialOfferClient.fromURI(uri);
39
52
  return CredentialRequestClientBuilder.fromCredentialOfferRequest(Object.assign(Object.assign({ request: offer }, offer), { metadata, version: offer.version }));
@@ -43,23 +56,98 @@ class CredentialRequestClientBuilder {
43
56
  var _a, _b;
44
57
  const { request } = opts;
45
58
  const version = (_b = (_a = opts.version) !== null && _a !== void 0 ? _a : request.version) !== null && _b !== void 0 ? _b : (0, oid4vci_common_1.determineSpecVersionFromOffer)(request.original_credential_offer);
59
+ let builder;
46
60
  if (version < oid4vci_common_1.OpenId4VCIVersion.VER_1_0_13) {
47
- return CredentialRequestClientBuilderV1_0_11_1.CredentialRequestClientBuilderV1_0_11.fromCredentialOfferRequest(opts);
61
+ builder = CredentialRequestClientBuilderV1_0_11_1.CredentialRequestClientBuilderV1_0_11.fromCredentialOfferRequest(opts);
62
+ }
63
+ else {
64
+ builder = CredentialRequestClientBuilderV1_0_13_1.CredentialRequestClientBuilderV1_0_13.fromCredentialOfferRequest(opts);
48
65
  }
49
- return CredentialRequestClientBuilderV1_0_13_1.CredentialRequestClientBuilderV1_0_13.fromCredentialOfferRequest(opts);
66
+ return new CredentialRequestClientBuilder(builder);
50
67
  }
51
68
  static fromCredentialOffer({ credentialOffer, metadata, }) {
52
69
  const version = (0, oid4vci_common_1.determineSpecVersionFromOffer)(credentialOffer.credential_offer);
70
+ let builder;
53
71
  if (version < oid4vci_common_1.OpenId4VCIVersion.VER_1_0_13) {
54
- return CredentialRequestClientBuilderV1_0_11_1.CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({
72
+ builder = CredentialRequestClientBuilderV1_0_11_1.CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({
55
73
  credentialOffer,
56
74
  metadata,
57
75
  });
58
76
  }
59
- return CredentialRequestClientBuilderV1_0_13_1.CredentialRequestClientBuilderV1_0_13.fromCredentialOffer({
60
- credentialOffer,
61
- metadata,
62
- });
77
+ else {
78
+ builder = CredentialRequestClientBuilderV1_0_13_1.CredentialRequestClientBuilderV1_0_13.fromCredentialOffer({
79
+ credentialOffer,
80
+ metadata,
81
+ });
82
+ }
83
+ return new CredentialRequestClientBuilder(builder);
84
+ }
85
+ getVersion() {
86
+ return this._builder.version;
87
+ }
88
+ withCredentialEndpointFromMetadata(metadata) {
89
+ if (isV1_0_13(this._builder)) {
90
+ this._builder.withCredentialEndpointFromMetadata(metadata);
91
+ }
92
+ else {
93
+ this._builder.withCredentialEndpointFromMetadata(metadata);
94
+ }
95
+ return this;
96
+ }
97
+ withCredentialEndpoint(credentialEndpoint) {
98
+ this._builder.withCredentialEndpoint(credentialEndpoint);
99
+ return this;
100
+ }
101
+ withDeferredCredentialEndpointFromMetadata(metadata) {
102
+ if (isV1_0_13(this._builder)) {
103
+ this._builder.withDeferredCredentialEndpointFromMetadata(metadata);
104
+ }
105
+ else {
106
+ this._builder.withDeferredCredentialEndpointFromMetadata(metadata);
107
+ }
108
+ return this;
109
+ }
110
+ withDeferredCredentialEndpoint(deferredCredentialEndpoint) {
111
+ this._builder.withDeferredCredentialEndpoint(deferredCredentialEndpoint);
112
+ return this;
113
+ }
114
+ withDeferredCredentialAwait(deferredCredentialAwait, deferredCredentialIntervalInMS) {
115
+ this._builder.withDeferredCredentialAwait(deferredCredentialAwait, deferredCredentialIntervalInMS);
116
+ return this;
117
+ }
118
+ withCredentialIdentifier(credentialIdentifier) {
119
+ if (this._builder.version === undefined || this._builder.version < oid4vci_common_1.OpenId4VCIVersion.VER_1_0_13) {
120
+ throw new Error('Version of spec should be equal or higher than v1_0_13');
121
+ }
122
+ this._builder.withCredentialIdentifier(credentialIdentifier);
123
+ return this;
124
+ }
125
+ withCredentialType(credentialTypes) {
126
+ this._builder.withCredentialType(credentialTypes);
127
+ return this;
128
+ }
129
+ withFormat(format) {
130
+ this._builder.withFormat(format);
131
+ return this;
132
+ }
133
+ withSubjectIssuance(subjectIssuance) {
134
+ this._builder.withSubjectIssuance(subjectIssuance);
135
+ return this;
136
+ }
137
+ withToken(accessToken) {
138
+ this._builder.withToken(accessToken);
139
+ return this;
140
+ }
141
+ withTokenFromResponse(response) {
142
+ this._builder.withTokenFromResponse(response);
143
+ return this;
144
+ }
145
+ withVersion(version) {
146
+ this._builder.withVersion(version);
147
+ return this;
148
+ }
149
+ build() {
150
+ return this._builder.build();
63
151
  }
64
152
  }
65
153
  exports.CredentialRequestClientBuilder = CredentialRequestClientBuilder;
@@ -1 +1 @@
1
- {"version":3,"file":"CredentialRequestClientBuilder.js","sourceRoot":"","sources":["../lib/CredentialRequestClientBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAMkC;AAElC,mEAAgE;AAChE,mGAAgG;AAChG,mGAAgG;AAEhG,MAAa,8BAA8B;IAClC,MAAM,CAAC,oBAAoB,CAAC,EACjC,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,oBAAoB,EACpB,eAAe,GAOhB;QACC,MAAM,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,C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,CAAC,mBAAmB,CAAC,EAChC,eAAe,EACf,QAAQ,GAIT;QACC,MAAM,OAAO,GAAG,IAAA,8CAA6B,EAAC,eAAe,CAAC,gBAAgB,CAAC,CAAC;QAChF,IAAI,OAAO,GAAG,kCAAiB,CAAC,UAAU,EAAE,CAAC;YAC3C,OAAO,6EAAqC,CAAC,mBAAmB,CAAC;gBAC/D,eAAe;gBACf,QAAQ;aACT,CAAC,CAAC;QACL,CAAC;QACD,OAAO,6EAAqC,CAAC,mBAAmB,CAAC;YAC/D,eAAe;YACf,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF;AA5ED,wEA4EC"}
1
+ {"version":3,"file":"CredentialRequestClientBuilder.js","sourceRoot":"","sources":["../lib/CredentialRequestClientBuilder.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAWiC;AAGjC,mEAAgE;AAChE,mGAAgG;AAChG,mGAAgG;AAIhG,SAAS,SAAS,CAAC,OAAsD;IACvE,OAAQ,OAAiD,CAAC,wBAAwB,KAAK,SAAS,CAAC;AACnG,CAAC;AAED,MAAa,8BAA8B;IAGzC,YAAoB,OAAsD;QACxE,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAC,EACE,gBAAgB,EAChB,QAAQ,EACR,OAAO,EACP,oBAAoB,EACpB,eAAe,GAOnD;QACC,MAAM,WAAW,GAAG,OAAO,aAAP,OAAO,cAAP,OAAO,GAAI,kCAAiB,CAAC,UAAU,CAAC;QAC5D,IAAI,OAAO,CAAC;QAEZ,IAAI,WAAW,IAAI,kCAAiB,CAAC,UAAU,EAAE,CAAC;YAChD,OAAO,GAAG,6EAAqC,CAAC,oBAAoB,CAAC;gBACnE,gBAAgB;gBAChB,QAAQ;gBACR,OAAO;gBACP,oBAAoB;gBACpB,eAAe;aAChB,CAAC,CAAC;QACL,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,MAAM,K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AAC,CAAC;QACnC,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK;QACV,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;IAC/B,CAAC;CACF;AAnLD,wEAmLC"}
@@ -1,32 +1,52 @@
1
1
  import {
2
+ AccessTokenResponse,
3
+ CredentialIssuerMetadata,
4
+ CredentialIssuerMetadataV1_0_13,
2
5
  CredentialOfferRequestWithBaseUrl,
3
6
  determineSpecVersionFromOffer,
4
7
  EndpointMetadata,
8
+ ExperimentalSubjectIssuance,
9
+ OID4VCICredentialFormat,
5
10
  OpenId4VCIVersion,
6
- UniformCredentialOfferRequest,
7
- } from '@sphereon/oid4vci-common';
11
+ UniformCredentialOfferRequest
12
+ } from '@sphereon/oid4vci-common'
13
+ import { CredentialFormat } from '@sphereon/ssi-types'
8
14
 
9
15
  import { CredentialOfferClient } from './CredentialOfferClient';
10
16
  import { CredentialRequestClientBuilderV1_0_11 } from './CredentialRequestClientBuilderV1_0_11';
11
17
  import { CredentialRequestClientBuilderV1_0_13 } from './CredentialRequestClientBuilderV1_0_13';
12
18
 
19
+ type CredentialRequestClientBuilderVersionSpecific = CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13;
20
+
21
+ function isV1_0_13(builder: CredentialRequestClientBuilderVersionSpecific): builder is CredentialRequestClientBuilderV1_0_13 {
22
+ return (builder as CredentialRequestClientBuilderV1_0_13).withCredentialIdentifier !== undefined;
23
+ }
24
+
13
25
  export class CredentialRequestClientBuilder {
26
+ private _builder: CredentialRequestClientBuilderVersionSpecific;
27
+
28
+ private constructor(builder: CredentialRequestClientBuilderVersionSpecific) {
29
+ this._builder = builder;
30
+ }
31
+
14
32
  public static fromCredentialIssuer({
15
- credentialIssuer,
16
- metadata,
17
- version,
18
- credentialIdentifier,
19
- credentialTypes,
20
- }: {
33
+ credentialIssuer,
34
+ metadata,
35
+ version,
36
+ credentialIdentifier,
37
+ credentialTypes,
38
+ }: {
21
39
  credentialIssuer: string;
22
40
  metadata?: EndpointMetadata;
23
41
  version?: OpenId4VCIVersion;
24
42
  credentialIdentifier?: string;
25
43
  credentialTypes?: string | string[];
26
- }): CredentialRequestClientBuilderV1_0_13 | CredentialRequestClientBuilderV1_0_11 {
27
- const specVersion = version ? version : OpenId4VCIVersion.VER_1_0_13;
44
+ }): CredentialRequestClientBuilder {
45
+ const specVersion = version ?? OpenId4VCIVersion.VER_1_0_13;
46
+ let builder;
47
+
28
48
  if (specVersion >= OpenId4VCIVersion.VER_1_0_13) {
29
- return CredentialRequestClientBuilderV1_0_13.fromCredentialIssuer({
49
+ builder = CredentialRequestClientBuilderV1_0_13.fromCredentialIssuer({
30
50
  credentialIssuer,
31
51
  metadata,
32
52
  version,
@@ -37,19 +57,25 @@ export class CredentialRequestClientBuilder {
37
57
  if (!credentialTypes || credentialTypes.length === 0) {
38
58
  throw new Error('CredentialTypes must be provided for v1_0_11');
39
59
  }
40
- return CredentialRequestClientBuilderV1_0_11.fromCredentialIssuer({ credentialIssuer, metadata, version, credentialTypes });
60
+ builder = CredentialRequestClientBuilderV1_0_11.fromCredentialIssuer({
61
+ credentialIssuer,
62
+ metadata,
63
+ version,
64
+ credentialTypes,
65
+ });
41
66
  }
67
+
68
+ return new CredentialRequestClientBuilder(builder);
42
69
  }
43
70
 
44
- public static async fromURI({
45
- uri,
46
- metadata,
47
- }: {
48
- uri: string;
49
- metadata?: EndpointMetadata;
50
- }): Promise<CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13> {
71
+ public static async fromURI({ uri, metadata }: { uri: string; metadata?: EndpointMetadata }): Promise<CredentialRequestClientBuilder> {
51
72
  const offer = await CredentialOfferClient.fromURI(uri);
52
- return CredentialRequestClientBuilder.fromCredentialOfferRequest({ request: offer, ...offer, metadata, version: offer.version });
73
+ return CredentialRequestClientBuilder.fromCredentialOfferRequest({
74
+ request: offer,
75
+ ...offer,
76
+ metadata,
77
+ version: offer.version,
78
+ });
53
79
  }
54
80
 
55
81
  public static fromCredentialOfferRequest(opts: {
@@ -58,32 +84,121 @@ export class CredentialRequestClientBuilder {
58
84
  baseUrl?: string;
59
85
  version?: OpenId4VCIVersion;
60
86
  metadata?: EndpointMetadata;
61
- }): CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13 {
87
+ }): CredentialRequestClientBuilder {
62
88
  const { request } = opts;
63
89
  const version = opts.version ?? request.version ?? determineSpecVersionFromOffer(request.original_credential_offer);
90
+ let builder;
91
+
64
92
  if (version < OpenId4VCIVersion.VER_1_0_13) {
65
- return CredentialRequestClientBuilderV1_0_11.fromCredentialOfferRequest(opts);
93
+ builder = CredentialRequestClientBuilderV1_0_11.fromCredentialOfferRequest(opts);
94
+ } else {
95
+ builder = CredentialRequestClientBuilderV1_0_13.fromCredentialOfferRequest(opts);
66
96
  }
67
- return CredentialRequestClientBuilderV1_0_13.fromCredentialOfferRequest(opts);
97
+
98
+ return new CredentialRequestClientBuilder(builder);
68
99
  }
69
100
 
70
101
  public static fromCredentialOffer({
71
- credentialOffer,
72
- metadata,
73
- }: {
102
+ credentialOffer,
103
+ metadata,
104
+ }: {
74
105
  credentialOffer: CredentialOfferRequestWithBaseUrl;
75
106
  metadata?: EndpointMetadata;
76
- }): CredentialRequestClientBuilderV1_0_11 | CredentialRequestClientBuilderV1_0_13 {
107
+ }): CredentialRequestClientBuilder {
77
108
  const version = determineSpecVersionFromOffer(credentialOffer.credential_offer);
109
+ let builder;
110
+
78
111
  if (version < OpenId4VCIVersion.VER_1_0_13) {
79
- return CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({
112
+ builder = CredentialRequestClientBuilderV1_0_11.fromCredentialOffer({
113
+ credentialOffer,
114
+ metadata,
115
+ });
116
+ } else {
117
+ builder = CredentialRequestClientBuilderV1_0_13.fromCredentialOffer({
80
118
  credentialOffer,
81
119
  metadata,
82
120
  });
83
121
  }
84
- return CredentialRequestClientBuilderV1_0_13.fromCredentialOffer({
85
- credentialOffer,
86
- metadata,
87
- });
122
+
123
+ return new CredentialRequestClientBuilder(builder);
124
+ }
125
+
126
+ public getVersion(): OpenId4VCIVersion | undefined {
127
+ return this._builder.version;
128
+ }
129
+
130
+ public withCredentialEndpointFromMetadata(metadata: CredentialIssuerMetadata | CredentialIssuerMetadataV1_0_13): this {
131
+ if (isV1_0_13(this._builder)) {
132
+ this._builder.withCredentialEndpointFromMetadata(metadata as CredentialIssuerMetadataV1_0_13)
133
+ } else {
134
+ this._builder.withCredentialEndpointFromMetadata(metadata as CredentialIssuerMetadata)
135
+ }
136
+ return this;
137
+ }
138
+
139
+ public withCredentialEndpoint(credentialEndpoint: string): this {
140
+ this._builder.withCredentialEndpoint(credentialEndpoint);
141
+ return this;
142
+ }
143
+
144
+ public withDeferredCredentialEndpointFromMetadata(metadata: CredentialIssuerMetadata | CredentialIssuerMetadataV1_0_13): this {
145
+ if (isV1_0_13(this._builder)) {
146
+ this._builder.withDeferredCredentialEndpointFromMetadata(metadata as CredentialIssuerMetadataV1_0_13);
147
+ } else {
148
+ this._builder.withDeferredCredentialEndpointFromMetadata(metadata as CredentialIssuerMetadata);
149
+ }
150
+ return this;
151
+ }
152
+
153
+ public withDeferredCredentialEndpoint(deferredCredentialEndpoint: string): this {
154
+ this._builder.withDeferredCredentialEndpoint(deferredCredentialEndpoint);
155
+ return this;
156
+ }
157
+
158
+ public withDeferredCredentialAwait(deferredCredentialAwait: boolean, deferredCredentialIntervalInMS?: number): this {
159
+ this._builder.withDeferredCredentialAwait(deferredCredentialAwait, deferredCredentialIntervalInMS);
160
+ return this;
161
+ }
162
+
163
+ public withCredentialIdentifier(credentialIdentifier: string): this {
164
+ if (this._builder.version === undefined || this._builder.version < OpenId4VCIVersion.VER_1_0_13) {
165
+ throw new Error('Version of spec should be equal or higher than v1_0_13');
166
+ }
167
+ (this._builder as CredentialRequestClientBuilderV1_0_13).withCredentialIdentifier(credentialIdentifier);
168
+ return this;
169
+ }
170
+
171
+ public withCredentialType(credentialTypes: string | string[]): this {
172
+ this._builder.withCredentialType(credentialTypes);
173
+ return this;
174
+ }
175
+
176
+ public withFormat(format: CredentialFormat | OID4VCICredentialFormat): this {
177
+ this._builder.withFormat(format);
178
+ return this;
179
+ }
180
+
181
+ public withSubjectIssuance(subjectIssuance: ExperimentalSubjectIssuance): this {
182
+ this._builder.withSubjectIssuance(subjectIssuance);
183
+ return this;
184
+ }
185
+
186
+ public withToken(accessToken: string): this {
187
+ this._builder.withToken(accessToken);
188
+ return this;
189
+ }
190
+
191
+ public withTokenFromResponse(response: AccessTokenResponse): this {
192
+ this._builder.withTokenFromResponse(response);
193
+ return this;
194
+ }
195
+
196
+ public withVersion(version: OpenId4VCIVersion): this {
197
+ this._builder.withVersion(version);
198
+ return this;
199
+ }
200
+
201
+ public build() {
202
+ return this._builder.build();
88
203
  }
89
204
  }
@@ -20,7 +20,7 @@ import * as jose from 'jose';
20
20
  // @ts-ignore
21
21
  import nock from 'nock';
22
22
 
23
- import { CredentialOfferClient, CredentialRequestClientBuilderV1_0_13, MetadataClient, ProofOfPossessionBuilder } from '..';
23
+ import { CredentialOfferClient, MetadataClient, ProofOfPossessionBuilder } from '..';
24
24
  import { CredentialRequestClientBuilder } from '../CredentialRequestClientBuilder';
25
25
 
26
26
  import { IDENTIPROOF_ISSUER_URL, IDENTIPROOF_OID4VCI_METADATA, INITIATION_TEST, WALT_OID4VCI_METADATA } from './MetadataMocks';
@@ -114,9 +114,7 @@ describe('Credential Request Client ', () => {
114
114
  });
115
115
 
116
116
  it('should fail with invalid url', async () => {
117
- const credReqClient = (
118
- CredentialRequestClientBuilder.fromCredentialOfferRequest({ request: INITIATION_TEST }) as CredentialRequestClientBuilderV1_0_13
119
- )
117
+ const credReqClient = CredentialRequestClientBuilder.fromCredentialOfferRequest({ request: INITIATION_TEST })
120
118
  .withCredentialEndpoint('httpsf://oidc4vci.demo.spruceid.com/credential')
121
119
  .withFormat('jwt_vc')
122
120
  .withCredentialIdentifier('https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential')
@@ -11,7 +11,7 @@ import {
11
11
  } from '@sphereon/oid4vci-common';
12
12
  import * as jose from 'jose';
13
13
 
14
- import { CredentialRequestClientBuilderV1_0_13, ProofOfPossessionBuilder } from '..';
14
+ import { CredentialRequestOpts, ProofOfPossessionBuilder } from '..';
15
15
  import { CredentialRequestClientBuilder } from '../CredentialRequestClientBuilder';
16
16
 
17
17
  import { IDENTIPROOF_ISSUER_URL, IDENTIPROOF_OID4VCI_METADATA, INITIATION_TEST_URI, WALT_ISSUER_URL, WALT_OID4VCI_METADATA } from './MetadataMocks';
@@ -82,7 +82,7 @@ async function proofOfPossessionVerifierCallbackFunction(args: { jwt: string; ki
82
82
 
83
83
  describe('Credential Request Client Builder', () => {
84
84
  it('should build correctly provided with correct params', async function () {
85
- const credReqClient = ((await CredentialRequestClientBuilder.fromURI({ uri: INITIATION_TEST_URI })) as CredentialRequestClientBuilderV1_0_13)
85
+ const credReqClient = (await CredentialRequestClientBuilder.fromURI({ uri: INITIATION_TEST_URI }))
86
86
  .withCredentialEndpoint('https://oidc4vci.demo.spruceid.com/credential')
87
87
  .withFormat('jwt_vc')
88
88
  .withCredentialIdentifier('credentialType')
@@ -90,12 +90,12 @@ describe('Credential Request Client Builder', () => {
90
90
  .build();
91
91
  expect(credReqClient.credentialRequestOpts.credentialEndpoint).toBe('https://oidc4vci.demo.spruceid.com/credential');
92
92
  expect(credReqClient.credentialRequestOpts.format).toBe('jwt_vc');
93
- expect(credReqClient.credentialRequestOpts.credentialIdentifier).toStrictEqual('credentialType');
93
+ expect((credReqClient.credentialRequestOpts as CredentialRequestOpts).credentialIdentifier).toStrictEqual('credentialType');
94
94
  expect(credReqClient.credentialRequestOpts.token).toBe('token');
95
95
  });
96
96
 
97
97
  it('should build credential request correctly', async () => {
98
- const credReqClient = ((await CredentialRequestClientBuilder.fromURI({ uri: INITIATION_TEST_URI })) as CredentialRequestClientBuilderV1_0_13)
98
+ const credReqClient = (await CredentialRequestClientBuilder.fromURI({ uri: INITIATION_TEST_URI }))
99
99
  .withCredentialEndpoint('https://oidc4vci.demo.spruceid.com/credential')
100
100
  .withFormat('jwt_vc')
101
101
  .withCredentialIdentifier('OpenBadgeCredential')
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  AccessTokenResponse,
3
- Alg,
3
+ Alg, CredentialOfferPayloadV1_0_13,
4
4
  CredentialOfferRequestWithBaseUrl,
5
5
  Jwt,
6
6
  OpenId4VCIVersion,
7
- ProofOfPossession,
8
- WellKnownEndpoints,
9
- } from '@sphereon/oid4vci-common';
7
+ ProofOfPossession, resolveCredentialOfferURI,
8
+ WellKnownEndpoints
9
+ } from '@sphereon/oid4vci-common'
10
10
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
11
11
  // @ts-ignore
12
12
  import nock from 'nock';
@@ -36,11 +36,27 @@ const jwtWithoutDid = {
36
36
  payload: { iss: 'test-clientId', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: ISSUER_URL },
37
37
  };
38
38
 
39
+ const mockedVC =
40
+ 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA';
41
+
42
+ // Access token mocks
43
+ const mockedAccessTokenResponse: AccessTokenResponse = {
44
+ access_token: 'ey6546.546654.64565',
45
+ authorization_pending: false,
46
+ c_nonce: 'c_nonce2022101300',
47
+ c_nonce_expires_in: 2025101300,
48
+ interval: 2025101300,
49
+ token_type: 'Bearer',
50
+ };
51
+
52
+ const INITIATE_QR_V1_0_13 =
53
+ 'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22:%22https://issuer.research.identiproof.io%22,%22credential_configuration_ids%22:%5B%22OpenBadgeCredentialUrl%22%5D,%22grants%22:%7B%22urn:ietf:params:oauth:grant-type:pre-authorized_code%22:%7B%22pre-authorized_code%22:%22oaKazRN8I0IbtZ0C7JuMn5%22,%22tx_code%22:%7B%22input_mode%22:%22text%22,%22length%22:22,%22description%22:%22Please%20enter%20the%20serial%20number%20of%20your%20physical%20drivers%20license%22%7D%7D%7D%7D';
54
+
55
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
56
+ async function proofOfPossessionCallbackFunction(_args: Jwt, _kid?: string): Promise<string> {
57
+ return 'ey.val.ue';
58
+ }
39
59
  describe('OID4VCI-Client should', () => {
40
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
41
- async function proofOfPossessionCallbackFunction(_args: Jwt, _kid?: string): Promise<string> {
42
- return 'ey.val.ue';
43
- }
44
60
  beforeEach(() => {
45
61
  nock.cleanAll();
46
62
  });
@@ -57,8 +73,6 @@ describe('OID4VCI-Client should', () => {
57
73
  interval: 2025101300,
58
74
  token_type: 'Bearer',
59
75
  };
60
- const mockedVC =
61
- 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA';
62
76
  const INITIATE_QR_V1_0_08 =
63
77
  'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true';
64
78
  const OFFER_QR_V1_0_08 =
@@ -72,9 +86,6 @@ describe('OID4VCI-Client should', () => {
72
86
  const HTTPS_OFFER_QR_PRE_AUTHORIZED_v13 =
73
87
  'https://issuer.research.identiproof.io?credential_offer=%7B%0A%20%20%20%20%22credential_issuer%22%3A%20%22https%3A%2F%2Fissuer.research.identiproof.io%22%2C%0A%20%20%20%20%22credential_configuration_ids%22%3A%20%5B%0A%20%20%20%20%20%20%20%20%22UniversityDegreeCredential%22%0A%20%20%20%20%5D%2C%0A%20%20%20%20%22grants%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22pre-authorized_code%22%3A%20%22adhjhdjajkdkhjhdj%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22tx_code%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22length%22%3A%204%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22input_mode%22%3A%20%22numeric%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22description%22%3A%20%22Please%20provide%20the%20one-time%20code%20that%20was%20sent%20via%20e-mail%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D';
74
88
 
75
- const INITIATE_QR_V1_0_13 =
76
- 'openid-credential-offer://?credential_offer=%7B%22credential_issuer%22:%22https://issuer.research.identiproof.io%22,%22credential_configuration_ids%22:%5B%22OpenBadgeCredentialUrl%22%5D,%22grants%22:%7B%22urn:ietf:params:oauth:grant-type:pre-authorized_code%22:%7B%22pre-authorized_code%22:%22oaKazRN8I0IbtZ0C7JuMn5%22,%22tx_code%22:%7B%22input_mode%22:%22text%22,%22length%22:22,%22description%22:%22Please%20enter%20the%20serial%20number%20of%20your%20physical%20drivers%20license%22%7D%7D%7D%7D';
77
-
78
89
  function succeedWithAFullFlowWithClientSetup() {
79
90
  nock(IDENTIPROOF_ISSUER_URL).get('/.well-known/openid-credential-issuer').reply(200, JSON.stringify(IDENTIPROOF_OID4VCI_METADATA));
80
91
  nock(IDENTIPROOF_AS_URL).get('/.well-known/oauth-authorization-server').reply(200, JSON.stringify(IDENTIPROOF_AS_METADATA));
@@ -225,7 +236,7 @@ describe('OID4VCI-Client should', () => {
225
236
  }
226
237
 
227
238
  it(
228
- 'succeed with a full flow without the client',
239
+ 'succeed with a full flow without the client v1_0_11',
229
240
  async () => {
230
241
  /* Convert the URI into an object */
231
242
  const credentialOffer: CredentialOfferRequestWithBaseUrl = await CredentialOfferClient.fromURI(INITIATE_QR_V1_0_08);
@@ -284,6 +295,125 @@ describe('OID4VCI-Client should', () => {
284
295
  UNIT_TEST_TIMEOUT,
285
296
  );
286
297
 
298
+ it(
299
+ 'succeed with a full flow without the client v1_0_13',
300
+ async () => {
301
+ /* Convert the URI into an object */
302
+ const credentialOffer: CredentialOfferRequestWithBaseUrl = await CredentialOfferClient.fromURI(INITIATE_QR_V1_0_13);
303
+ const preAuthorizedCode = 'oaKazRN8I0IbtZ0C7JuMn5';
304
+ expect(credentialOffer.baseUrl).toEqual('openid-credential-offer://');
305
+ expect((credentialOffer.credential_offer as CredentialOfferPayloadV1_0_13).credential_configuration_ids).toEqual(['OpenBadgeCredentialUrl']);
306
+ expect(credentialOffer.original_credential_offer.grants).toEqual({
307
+ 'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
308
+ 'pre-authorized_code': preAuthorizedCode,
309
+ tx_code: {
310
+ input_mode: 'text',
311
+ description: 'Please enter the serial number of your physical drivers license',
312
+ length: preAuthorizedCode.length,
313
+ },
314
+ },
315
+ });
316
+
317
+ nock(ISSUER_URL)
318
+ .post(/token.*/)
319
+ .reply(200, JSON.stringify(mockedAccessTokenResponse));
320
+
321
+ /* The actual access token calls */
322
+ const accessTokenClient: AccessTokenClient = new AccessTokenClient();
323
+ const accessTokenResponse = await accessTokenClient.acquireAccessToken({ credentialOffer: credentialOffer, pin: '1234' });
324
+ expect(accessTokenResponse.successBody).toEqual(mockedAccessTokenResponse);
325
+ // Get the credential
326
+ nock(ISSUER_URL)
327
+ .post(/credential/)
328
+ .reply(200, {
329
+ format: 'jwt-vc',
330
+ credential: mockedVC,
331
+ });
332
+ const credReqClient = CredentialRequestClientBuilder.fromCredentialOffer({ credentialOffer: credentialOffer })
333
+ .withFormat('jwt_vc')
334
+
335
+ .withTokenFromResponse(accessTokenResponse.successBody!)
336
+ .build();
337
+
338
+ //TS2322: Type '(args: ProofOfPossessionCallbackArgs) => Promise<string>'
339
+ // is not assignable to type 'ProofOfPossessionCallback'.
340
+ // Types of parameters 'args' and 'args' are incompatible.
341
+ // Property 'kid' is missing in type '{ header: unknown; payload: unknown; }' but required in type 'ProofOfPossessionCallbackArgs'.
342
+ const proof: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
343
+ jwt: jwtDid,
344
+ callbacks: {
345
+ signCallback: proofOfPossessionCallbackFunction,
346
+ },
347
+ version: OpenId4VCIVersion.VER_1_0_11,
348
+ })
349
+ .withEndpointMetadata({
350
+ issuer: 'https://issuer.research.identiproof.io',
351
+ credential_endpoint: 'https://issuer.research.identiproof.io/credential',
352
+ token_endpoint: 'https://issuer.research.identiproof.io/token',
353
+ })
354
+ .withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')
355
+ .build();
356
+ const credResponse = await credReqClient.acquireCredentialsUsingProof({
357
+ proofInput: proof,
358
+ credentialTypes: credentialOffer.original_credential_offer.credential_configuration_ids[0],
359
+ });
360
+ expect(credResponse.successBody?.credential).toEqual(mockedVC);
361
+ },
362
+ UNIT_TEST_TIMEOUT,
363
+ );
364
+ });
365
+
366
+ describe('OIDVCI-Client for v1_0_13 should', () => {
367
+ const mockedCredentialOffer = {
368
+ credential_issuer: 'https://mijnkvk.acc.credenco.com',
369
+ credential_configuration_ids: ['BevoegdheidUittreksel_jwt_vc_json'],
370
+ grants: {
371
+ authorization_code: {
372
+ issuer_state: '32fc4ebf-9e31-4149-9877-e3c0b602d559',
373
+ },
374
+ 'urn:ietf:params:oauth:grant-type:pre-authorized_code': {
375
+ 'pre-authorized_code':
376
+ 'eyJhbGciOiJFZERTQSJ9.eyJzdWIiOiIzMmZjNGViZi05ZTMxLTQxNDktOTg3Ny1lM2MwYjYwMmQ1NTkiLCJpc3MiOiJodHRwczovL21pam5rdmsuYWNjLmNyZWRlbmNvLmNvbSIsImF1ZCI6IlRPS0VOIn0.754aiQ87O0vHYSpRvPqAS9cLOgf-pewdeXbpLziRwsxEp9mENfaXpY62muYpzOaWcYmTOydkzhFul-NDYXJZCA',
377
+ },
378
+ },
379
+ };
380
+
381
+ beforeEach(() => {
382
+ // Mock the HTTP GET request to the credential offer URI
383
+ nock('https://mijnkvk.acc.credenco.com')
384
+ .get('/openid4vc/credentialOffer?id=32fc4ebf-9e31-4149-9877-e3c0b602d559')
385
+ .reply(200, mockedCredentialOffer)
386
+ .persist(); // Use .persist() if you want the mock to remain active for multiple tests
387
+ });
388
+
389
+ afterEach(() => {
390
+ // Clean up all mocks
391
+ nock.cleanAll();
392
+ });
393
+
394
+ /*function succeedWithAFullFlowWithClientSetup() {
395
+ nock(IDENTIPROOF_ISSUER_URL).get('/.well-known/openid-credential-issuer').reply(200, JSON.stringify(IDENTIPROOF_OID4VCI_METADATA));
396
+ nock(IDENTIPROOF_AS_URL).get('/.well-known/oauth-authorization-server').reply(200, JSON.stringify(IDENTIPROOF_AS_METADATA));
397
+ nock(IDENTIPROOF_AS_URL).get(WellKnownEndpoints.OPENID_CONFIGURATION).reply(404, {});
398
+ nock(IDENTIPROOF_AS_URL)
399
+ .post(/oauth2\/token.*!/)
400
+ .reply(200, JSON.stringify(mockedAccessTokenResponse));
401
+ nock(ISSUER_URL)
402
+ .post(/credential/)
403
+ .reply(200, {
404
+ format: 'jwt-vc',
405
+ credential: mockedVC,
406
+ });
407
+ }*/
408
+
409
+ it('should successfully resolve the credential offer URI', async () => {
410
+ const uri = 'https://mijnkvk.acc.credenco.com/openid4vc/credentialOffer?id=32fc4ebf-9e31-4149-9877-e3c0b602d559';
411
+
412
+ const credentialOffer = await resolveCredentialOfferURI(uri);
413
+
414
+ expect(credentialOffer).toEqual(mockedCredentialOffer);
415
+ });
416
+
287
417
  it(
288
418
  'succeed with a full flow without the client and without did',
289
419
  async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sphereon/oid4vci-client",
3
- "version": "0.12.1-unstable.4+30cddd3",
3
+ "version": "0.12.1-unstable.7+f655bf0",
4
4
  "description": "OpenID for Verifiable Credential Issuance (OpenID4VCI) client",
5
5
  "source": "lib/index.ts",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "build": "tsc"
16
16
  },
17
17
  "dependencies": {
18
- "@sphereon/oid4vci-common": "0.12.1-unstable.4+30cddd3",
18
+ "@sphereon/oid4vci-common": "0.12.1-unstable.7+f655bf0",
19
19
  "@sphereon/ssi-types": "0.25.1-unstable.87",
20
20
  "cross-fetch": "^3.1.8",
21
21
  "debug": "^4.3.4"
@@ -69,5 +69,5 @@
69
69
  "OIDC4VCI",
70
70
  "OID4VCI"
71
71
  ],
72
- "gitHead": "30cddd3af544e97047d27f48d1d76ce16f80a79b"
72
+ "gitHead": "f655bf063128e94e0f6e4b54a2437ea975bc0d34"
73
73
  }