Skip to content

Commit 6af92a9

Browse files
committed
Move to refreshService v2
1 parent a6b967d commit 6af92a9

6 files changed

Lines changed: 160 additions & 38 deletions

File tree

src/VerifiableCredentials/VcDataModel/Factories/VcDataModelClaimFactory.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcClaimValue;
1919
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialSchemaClaimBag;
2020
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialSchemaClaimValue;
21-
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialStatusClaimBag;
2221
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialStatusClaimValue;
2322
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialSubjectClaimBag;
2423
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialSubjectClaimValue;
@@ -215,39 +214,6 @@ public function buildVcCredentialStatusClaimValue(array $data): VcCredentialStat
215214
}
216215

217216

218-
/**
219-
* @param mixed[] $data
220-
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
221-
* @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
222-
*/
223-
public function buildVcCredentialStatusClaimBag(array $data): VcCredentialStatusClaimBag
224-
{
225-
// If this is a single credential status claim, wrap it in a
226-
// CredentialStatusClaimBag.
227-
if ($this->helpers->arr()->isAssociative($data)) {
228-
return new VcCredentialStatusClaimBag(
229-
$this->buildVcCredentialStatusClaimValue($data),
230-
);
231-
}
232-
233-
// We have multiple credential status claims. Wrap them in a
234-
// CredentialStatusClaimBag.
235-
$data = $this->helpers->type()->enforceNonEmptyArrayOfNonEmptyArrays($data);
236-
237-
$vcCredentialStatusClaims = [];
238-
foreach ($data as $credentialStatusClaimValueData) {
239-
$vcCredentialStatusClaims[] = $this->buildVcCredentialStatusClaimValue($credentialStatusClaimValueData);
240-
}
241-
242-
$firstCredentialStatusClaim = array_shift($vcCredentialStatusClaims);
243-
244-
return new VcCredentialStatusClaimBag(
245-
$firstCredentialStatusClaim,
246-
...$vcCredentialStatusClaims,
247-
);
248-
}
249-
250-
251217
/**
252218
* @param non-empty-array<mixed> $data
253219
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException

src/VerifiableCredentials/VcDataModel/Claims/VcCredentialStatusClaimBag.php renamed to src/VerifiableCredentials/VcDataModel2/Claims/VcCredentialStatusClaimBag.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims;
5+
namespace SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims;
66

77
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
88
use SimpleSAML\OpenID\ValueAbstracts\ClaimInterface;
9+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialStatusClaimValue;
910

1011
class VcCredentialStatusClaimBag implements ClaimInterface
1112
{
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims;
6+
7+
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
8+
use SimpleSAML\OpenID\ValueAbstracts\ClaimInterface;
9+
10+
class VcRefreshServiceClaimBag implements ClaimInterface
11+
{
12+
/** @var \SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcRefreshServiceClaimValue[] */
13+
protected array $vcRefreshServiceClaimValueValues;
14+
15+
16+
public function __construct(
17+
VcRefreshServiceClaimValue $vcRefreshServiceClaimValue,
18+
VcRefreshServiceClaimValue ...$vcRefreshServiceClaimValueValues,
19+
) {
20+
$this->vcRefreshServiceClaimValueValues = [
21+
$vcRefreshServiceClaimValue,
22+
...$vcRefreshServiceClaimValueValues,
23+
];
24+
}
25+
26+
27+
/**
28+
* @return mixed[]
29+
*/
30+
public function jsonSerialize(): array
31+
{
32+
return array_map(
33+
fn(
34+
VcRefreshServiceClaimValue $vcRefreshServiceClaimValue,
35+
): array => $vcRefreshServiceClaimValue->jsonSerialize(),
36+
$this->getValue(),
37+
);
38+
}
39+
40+
41+
public function getName(): string
42+
{
43+
return ClaimsEnum::Refresh_Service->value;
44+
}
45+
46+
47+
/**
48+
* @return \SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcRefreshServiceClaimValue[]
49+
*/
50+
public function getValue(): array
51+
{
52+
return $this->vcRefreshServiceClaimValueValues;
53+
}
54+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims;
6+
7+
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
8+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\AbstractTypedClaimValue;
9+
10+
class VcRefreshServiceClaimValue extends AbstractTypedClaimValue
11+
{
12+
public function getName(): string
13+
{
14+
return ClaimsEnum::Refresh_Service->value;
15+
}
16+
}

src/VerifiableCredentials/VcDataModel2/Factories/VcDataModel2ClaimFactory.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
namespace SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Factories;
66

77
use SimpleSAML\OpenID\Codebooks\AtContextsEnum;
8+
use SimpleSAML\OpenID\Codebooks\ClaimsEnum;
9+
use SimpleSAML\OpenID\Exceptions\VcDataModelException;
810
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcAtContextClaimValue;
911
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Factories\VcDataModelClaimFactory;
12+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcCredentialStatusClaimBag;
13+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcRefreshServiceClaimBag;
14+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcRefreshServiceClaimValue;
1015

1116
class VcDataModel2ClaimFactory extends VcDataModelClaimFactory
1217
{
@@ -24,4 +29,82 @@ public function buildVcAtContextClaimValue(
2429
AtContextsEnum::W3OrgNsCredentialsV2,
2530
);
2631
}
32+
33+
34+
/**
35+
* @param mixed[] $data
36+
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
37+
* @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
38+
*/
39+
public function buildVcCredentialStatusClaimBag(array $data): VcCredentialStatusClaimBag
40+
{
41+
// If this is a single credential status claim, wrap it in a
42+
// CredentialStatusClaimBag.
43+
if ($this->helpers->arr()->isAssociative($data)) {
44+
return new VcCredentialStatusClaimBag(
45+
$this->buildVcCredentialStatusClaimValue($data),
46+
);
47+
}
48+
49+
// We have multiple credential status claims. Wrap them in a
50+
// CredentialStatusClaimBag.
51+
$data = $this->helpers->type()->enforceNonEmptyArrayOfNonEmptyArrays($data);
52+
53+
$vcCredentialStatusClaims = [];
54+
foreach ($data as $credentialStatusClaimValueData) {
55+
$vcCredentialStatusClaims[] = $this->buildVcCredentialStatusClaimValue($credentialStatusClaimValueData);
56+
}
57+
58+
$firstCredentialStatusClaim = array_shift($vcCredentialStatusClaims);
59+
60+
return new VcCredentialStatusClaimBag(
61+
$firstCredentialStatusClaim,
62+
...$vcCredentialStatusClaims,
63+
);
64+
}
65+
66+
67+
/**
68+
* @param non-empty-array<mixed> $data
69+
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
70+
* @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
71+
*/
72+
public function buildVcRefreshServiceClaimValue2(array $data): VcRefreshServiceClaimValue
73+
{
74+
$type = $data[ClaimsEnum::Type->value] ?? throw new VcDataModelException(
75+
'No Type claim value available.',
76+
);
77+
$typeClaimValue = $this->buildTypeClaimValue($type);
78+
79+
return new VcRefreshServiceClaimValue($typeClaimValue, $data);
80+
}
81+
82+
83+
/**
84+
* @param mixed[] $data
85+
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
86+
* @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
87+
*/
88+
public function buildVcRefreshServiceClaimBag2(array $data): VcRefreshServiceClaimBag
89+
{
90+
if ($this->helpers->arr()->isAssociative($data)) {
91+
$data = [$data];
92+
}
93+
94+
$data = $this->helpers->type()->enforceNonEmptyArrayOfNonEmptyArrays($data);
95+
96+
$vcRefreshServiceClaimValueData = array_shift($data);
97+
98+
$vcRefreshServiceClaimValue = $this->buildVcRefreshServiceClaimValue2($vcRefreshServiceClaimValueData);
99+
100+
$vcRefreshServiceClaimValues = array_map(
101+
$this->buildVcRefreshServiceClaimValue2(...),
102+
$data,
103+
);
104+
105+
return new VcRefreshServiceClaimBag(
106+
$vcRefreshServiceClaimValue,
107+
...$vcRefreshServiceClaimValues,
108+
);
109+
}
27110
}

src/VerifiableCredentials/VcDataModel2/VcSdJwt.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\TypeClaimValue;
1515
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcAtContextClaimValue;
1616
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialSchemaClaimBag;
17-
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialStatusClaimBag;
1817
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcCredentialSubjectClaimBag;
1918
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcEvidenceClaimBag;
2019
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcIssuerClaimValue;
2120
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcProofClaimValue;
22-
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcRefreshServiceClaimBag;
2321
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel\Claims\VcTermsOfUseClaimBag;
22+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcCredentialStatusClaimBag;
23+
use SimpleSAML\OpenID\VerifiableCredentials\VcDataModel2\Claims\VcRefreshServiceClaimBag;
2424
use SimpleSAML\OpenID\VerifiableCredentials\VerifiableCredentialInterface;
2525

2626
class VcSdJwt extends SdJwt implements VerifiableCredentialInterface
@@ -427,6 +427,8 @@ public function getVcCredentialSchema(): ?VcCredentialSchemaClaimBag
427427

428428
/**
429429
* @throws \SimpleSAML\OpenID\Exceptions\VcDataModelException
430+
* @throws \SimpleSAML\OpenID\Exceptions\InvalidValueException
431+
* @throws \SimpleSAML\OpenID\Exceptions\JwsException
430432
*/
431433
public function getVcRefreshService(): ?VcRefreshServiceClaimBag
432434
{
@@ -450,7 +452,7 @@ public function getVcRefreshService(): ?VcRefreshServiceClaimBag
450452
}
451453

452454
return $this->vcRefreshServiceClaimBag = $this->claimFactory->forVcDataModel2()
453-
->buildVcRefreshServiceClaimBag($vcRefreshService);
455+
->buildVcRefreshServiceClaimBag2($vcRefreshService);
454456
}
455457

456458

0 commit comments

Comments
 (0)