Skip to content

Commit 9a27f0f

Browse files
committed
Fix base AtContext
1 parent e6213b1 commit 9a27f0f

11 files changed

Lines changed: 69 additions & 170 deletions

File tree

src/Codebooks/AtContextsEnum.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
enum AtContextsEnum: string
88
{
99
case W3Org2018CredentialsV1 = 'https://www.w3.org/2018/credentials/v1';
10+
11+
case W3OrgNsCredentialsV2 = 'https://www.w3.org/ns/credentials/v2';
1012
}

src/Factories/ClaimFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
use SimpleSAML\OpenID\ValueAbstracts\GenericClaim;
1212
use SimpleSAML\OpenID\ValueAbstracts\JwksClaim;
1313
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Factories\VcDataModelClaimFactory;
14+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Factories\VcDataModel2ClaimFactory;
1415

1516
class ClaimFactory
1617
{
1718
protected FederationClaimFactory $federationClaimFactory;
1819

1920
protected VcDataModelClaimFactory $vcDataModelClaimFactory;
2021

22+
protected VcDataModel2ClaimFactory $vcDataModel2ClaimFactory;
23+
2124

2225
public function __construct(
2326
protected readonly Helpers $helpers,
@@ -43,6 +46,15 @@ public function forVcDataModel(): VcDataModelClaimFactory
4346
}
4447

4548

49+
public function forVcDataModel2(): VcDataModel2ClaimFactory
50+
{
51+
return $this->vcDataModel2ClaimFactory ??= new VcDataModel2ClaimFactory(
52+
$this->helpers,
53+
$this,
54+
);
55+
}
56+
57+
4658
/**
4759
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
4860
*/

src/VerifiableCredentials/VcDataModel/Claims/VcAtContextClaimValue.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ class VcAtContextClaimValue implements ClaimInterface
1818
public function __construct(
1919
protected readonly string $baseContext,
2020
protected readonly array $otherContexts,
21+
AtContextsEnum $expectedBaseContext = AtContextsEnum::W3Org2018CredentialsV1,
2122
) {
22-
if ($this->baseContext !== AtContextsEnum::W3Org2018CredentialsV1->value) {
23+
if ($this->baseContext !== $expectedBaseContext->value) {
2324
throw new VcDataModelException(sprintf(
2425
'Invalid VC @context claim. Base context should be %s, %s given.',
25-
AtContextsEnum::W3Org2018CredentialsV1->value,
26+
$expectedBaseContext->value,
2627
$this->baseContext,
2728
));
2829
}
@@ -64,7 +65,7 @@ public function getName(): string
6465
*/
6566
public function getValue(): array
6667
{
67-
return[
68+
return [
6869
$this->baseContext,
6970
...$this->otherContexts,
7071
];

src/VerifiableCredentials/VcDataModel2/Claims/ValidFromClaimValue.php

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/VerifiableCredentials/VcDataModel2/Claims/ValidUntilClaimValue.php

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Factories;
6+
7+
use SimpleSAML\OpenID\Codebooks\AtContextsEnum;
8+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcAtContextClaimValue;
9+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Factories\VcDataModelClaimFactory;
10+
11+
class VcDataModel2ClaimFactory extends VcDataModelClaimFactory
12+
{
13+
/**
14+
* @param mixed[] $otherContexts
15+
* @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
16+
*/
17+
public function buildVcAtContextClaimValue(string $baseContext, array $otherContexts): VcAtContextClaimValue
18+
{
19+
return new VcAtContextClaimValue($baseContext, $otherContexts, AtContextsEnum::W3OrgNsCredentialsV2);
20+
}
21+
}

src/VerifiableCredentials/VcDataModel2/SdJwtVcJson.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function getVcAtContext(): VcAtContextClaimValue
9797
throw new VcDataModelException('Invalid @context claim.');
9898
}
9999

100-
return $this->vcAtContextClaimValue = $this->claimFactory->forVcDataModel()->buildVcAtContextClaimValue(
100+
return $this->vcAtContextClaimValue = $this->claimFactory->forVcDataModel2()->buildVcAtContextClaimValue(
101101
$baseContext,
102102
$vcContext,
103103
);
@@ -140,7 +140,7 @@ public function getVcType(): TypeClaimValue
140140
throw new VcDataModelException('Invalid Type claim.');
141141
}
142142

143-
return $this->vcTypeClaimValue = $this->claimFactory->forVcDataModel()->buildTypeClaimValue($vcType);
143+
return $this->vcTypeClaimValue = $this->claimFactory->forVcDataModel2()->buildTypeClaimValue($vcType);
144144
}
145145

146146

@@ -161,7 +161,7 @@ public function getVcCredentialSubject(): VcCredentialSubjectClaimBag
161161
throw new VcDataModelException('Invalid Credential Subject claim.');
162162
}
163163

164-
return $this->vcCredentialSubjectClaimBag = $this->claimFactory->forVcDataModel()
164+
return $this->vcCredentialSubjectClaimBag = $this->claimFactory->forVcDataModel2()
165165
->buildVcCredentialSubjectClaimBag(
166166
$vcCredentialSubject,
167167
$this->getSubject(),
@@ -192,13 +192,13 @@ public function getVcIssuer(): VcIssuerClaimValue
192192
}
193193

194194
if (is_string($vcIssuer)) {
195-
return $this->vcIssuerClaimValue = $this->claimFactory->forVcDataModel()->buildVcIssuerClaimValue(
195+
return $this->vcIssuerClaimValue = $this->claimFactory->forVcDataModel2()->buildVcIssuerClaimValue(
196196
[ClaimsEnum::Id->value => $vcIssuer],
197197
);
198198
}
199199

200200
if (is_array($vcIssuer)) {
201-
return $this->vcIssuerClaimValue = $this->claimFactory->forVcDataModel()->buildVcIssuerClaimValue(
201+
return $this->vcIssuerClaimValue = $this->claimFactory->forVcDataModel2()->buildVcIssuerClaimValue(
202202
$vcIssuer,
203203
);
204204
}
@@ -233,14 +233,15 @@ public function getValidFrom(): DateTimeImmutable
233233
throw new VcDataModelException('Invalid Not Before or Issued At claim.', $e->getCode(), $e);
234234
}
235235
}
236+
236237
throw new VcDataModelException('Valid From claim is missing.');
237238
}
238239

239240
try {
240241
$validFromStr = $this->helpers->type()->ensureNonEmptyString($validFrom, ClaimsEnum::ValidFrom->value);
241242
return $this->validFrom = $this->helpers->dateTime()->fromXsDateTime($validFromStr);
242-
} catch (Exception $e) {
243-
throw new VcDataModelException('Invalid Valid From claim.', (int) $e->getCode(), $e);
243+
} catch (Exception $exception) {
244+
throw new VcDataModelException('Invalid Valid From claim.', (int) $exception->getCode(), $exception);
244245
}
245246
}
246247

@@ -287,15 +288,16 @@ public function getValidUntil(): ?DateTimeImmutable
287288
throw new VcDataModelException('Invalid Expiration Time claim.', $e->getCode(), $e);
288289
}
289290
}
291+
290292
$this->validUntil = false;
291293
return null;
292294
}
293295

294296
try {
295297
$validUntilStr = $this->helpers->type()->ensureNonEmptyString($validUntil, ClaimsEnum::ValidUntil->value);
296298
return $this->validUntil = $this->helpers->dateTime()->fromXsDateTime($validUntilStr);
297-
} catch (Exception $e) {
298-
throw new VcDataModelException('Invalid Valid Until claim.', (int) $e->getCode(), $e);
299+
} catch (Exception $exception) {
300+
throw new VcDataModelException('Invalid Valid Until claim.', (int) $exception->getCode(), $exception);
299301
}
300302
}
301303

@@ -336,7 +338,7 @@ public function getVcProof(): ?VcProofClaimValue
336338
throw new VcDataModelException('Invalid Proof claim.');
337339
}
338340

339-
return $this->vcProofClaimValue = $this->claimFactory->forVcDataModel()->buildVcProofClaimValue($vcProof);
341+
return $this->vcProofClaimValue = $this->claimFactory->forVcDataModel2()->buildVcProofClaimValue($vcProof);
340342
}
341343

342344

@@ -364,7 +366,7 @@ public function getVcCredentialStatus(): ?VcCredentialStatusClaimValue
364366
throw new VcDataModelException('Invalid Credential Status claim.');
365367
}
366368

367-
return $this->vcCredentialStatusClaimValue = $this->claimFactory->forVcDataModel()
369+
return $this->vcCredentialStatusClaimValue = $this->claimFactory->forVcDataModel2()
368370
->buildVcCredentialStatusClaimValue($vcCredentialStatus);
369371
}
370372

@@ -393,7 +395,7 @@ public function getVcCredentialSchema(): ?VcCredentialSchemaClaimBag
393395
throw new VcDataModelException('Invalid Credential Schema claim.');
394396
}
395397

396-
return $this->vcCredentialSchemaClaimBag = $this->claimFactory->forVcDataModel()
398+
return $this->vcCredentialSchemaClaimBag = $this->claimFactory->forVcDataModel2()
397399
->buildVcCredentialSchemaClaimBag($vcCredentialSchema);
398400
}
399401

@@ -422,7 +424,7 @@ public function getVcRefreshService(): ?VcRefreshServiceClaimBag
422424
throw new VcDataModelException('Invalid Refresh Service claim.');
423425
}
424426

425-
return $this->vcRefreshServiceClaimBag = $this->claimFactory->forVcDataModel()
427+
return $this->vcRefreshServiceClaimBag = $this->claimFactory->forVcDataModel2()
426428
->buildVcRefreshServiceClaimBag($vcRefreshService);
427429
}
428430

@@ -451,7 +453,7 @@ public function getVcTermsOfUse(): ?VcTermsOfUseClaimBag
451453
throw new VcDataModelException('Invalid Terms Of Use claim.');
452454
}
453455

454-
return $this->vcTermsOfUseClaimBag = $this->claimFactory->forVcDataModel()
456+
return $this->vcTermsOfUseClaimBag = $this->claimFactory->forVcDataModel2()
455457
->buildVcTermsOfUseClaimBag($vcTermsOfUse);
456458
}
457459

@@ -480,7 +482,7 @@ public function getVcEvidence(): ?VcEvidenceClaimBag
480482
throw new VcDataModelException('Invalid Evidence claim.');
481483
}
482484

483-
return $this->vcEvidenceClaimBag = $this->claimFactory->forVcDataModel()
485+
return $this->vcEvidenceClaimBag = $this->claimFactory->forVcDataModel2()
484486
->buildVcEvidenceClaimBag($vcEvidence);
485487
}
486488
}

tests/src/VerifiableCredentials/VcDataModel/Claims/VcAtContextClaimValueTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@ final class VcAtContextClaimValueTest extends TestCase
1414
{
1515
protected string $baseContext = AtContextsEnum::W3Org2018CredentialsV1->value;
1616

17+
protected AtContextsEnum $expectedBaseContext = AtContextsEnum::W3Org2018CredentialsV1;
18+
1719
protected array $otherContexts = [];
1820

1921

2022
protected function sut(
2123
?string $baseContext = null,
2224
?array $otherContexts = null,
25+
?AtContextsEnum $expectedBaseContext = null,
2326
): VcAtContextClaimValue {
2427
$baseContext ??= $this->baseContext;
2528
$otherContexts ??= $this->otherContexts;
29+
$expectedBaseContext ??= $this->expectedBaseContext;
2630

27-
return new VcAtContextClaimValue($baseContext, $otherContexts);
31+
return new VcAtContextClaimValue($baseContext, $otherContexts, $expectedBaseContext);
2832
}
2933

3034

tests/src/VerifiableCredentials/VcDataModel2/Claims/ValidFromClaimValueTest.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

tests/src/VerifiableCredentials/VcDataModel2/Claims/ValidUntilClaimValueTest.php

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)