Skip to content

Commit 9667567

Browse files
authored
Merge branch 'main' into release/openid4vc
2 parents 302dc42 + bbf812d commit 9667567

File tree

6 files changed

+133
-7
lines changed

6 files changed

+133
-7
lines changed

packages/consumption/src/modules/attributes/AttributesController.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,15 +1574,27 @@ export class AttributesController extends ConsumptionBaseController {
15741574
return docs.map((doc) => AttributeForwardingDetails.from(doc));
15751575
}
15761576

1577-
public async getAttributesExchangedWithPeer(peer: CoreAddress, query: any, hideTechnical = false, onlyLatestVersions = true): Promise<LocalAttribute[]> {
1578-
const attributesForwardedToPeer = await this.getAttributesForwardedToPeer(peer, query, hideTechnical, onlyLatestVersions);
1577+
public async getAttributesExchangedWithPeer(
1578+
peer: CoreAddress,
1579+
query: any,
1580+
attributeForwardingDetailsQuery?: any,
1581+
hideTechnical = false,
1582+
onlyLatestVersions = true
1583+
): Promise<LocalAttribute[]> {
1584+
const attributesForwardedToPeer = await this.getAttributesForwardedToPeer(peer, query, attributeForwardingDetailsQuery, hideTechnical, onlyLatestVersions);
15791585
const attributesWithPeer = await this.getAttributesWithPeer(peer, query, hideTechnical, onlyLatestVersions);
15801586

15811587
return [...attributesForwardedToPeer, ...attributesWithPeer];
15821588
}
15831589

1584-
public async getAttributesForwardedToPeer(peer: CoreAddress, query: any, hideTechnical = false, onlyLatestVersions = true): Promise<LocalAttribute[]> {
1585-
const forwardingDetailsDocs = await this.forwardingDetails.find({ peer: peer.toString() });
1590+
public async getAttributesForwardedToPeer(
1591+
peer: CoreAddress,
1592+
query: any,
1593+
attributeForwardingDetailsQuery?: any,
1594+
hideTechnical = false,
1595+
onlyLatestVersions = true
1596+
): Promise<LocalAttribute[]> {
1597+
const forwardingDetailsDocs = await this.forwardingDetails.find({ ...attributeForwardingDetailsQuery, peer: peer.toString() });
15861598
const forwardingDetails = forwardingDetailsDocs.map((doc) => AttributeForwardingDetails.from(doc));
15871599

15881600
const attributeIds = [...new Set(forwardingDetails.map((details) => details.attributeId.toString()))];

packages/runtime/src/useCases/common/Schemas.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14020,6 +14020,9 @@ export const GetOwnAttributesSharedWithPeerRequest: any = {
1402014020
"query": {
1402114021
"$ref": "#/definitions/GetOwnAttributesSharedWithPeerRequestQuery"
1402214022
},
14023+
"attributeForwardingDetailsQuery": {
14024+
"$ref": "#/definitions/GetOwnAttributesSharedWithPeerRequestAttributeForwardingDetailsQuery"
14025+
},
1402314026
"hideTechnical": {
1402414027
"type": "boolean"
1402514028
},
@@ -14194,6 +14197,77 @@ export const GetOwnAttributesSharedWithPeerRequest: any = {
1419414197
}
1419514198
},
1419614199
"additionalProperties": false
14200+
},
14201+
"GetOwnAttributesSharedWithPeerRequestAttributeForwardingDetailsQuery": {
14202+
"type": "object",
14203+
"properties": {
14204+
"sourceReference": {
14205+
"anyOf": [
14206+
{
14207+
"type": "string"
14208+
},
14209+
{
14210+
"type": "array",
14211+
"items": {
14212+
"type": "string"
14213+
}
14214+
}
14215+
]
14216+
},
14217+
"sharedAt": {
14218+
"anyOf": [
14219+
{
14220+
"type": "string"
14221+
},
14222+
{
14223+
"type": "array",
14224+
"items": {
14225+
"type": "string"
14226+
}
14227+
}
14228+
]
14229+
},
14230+
"deletionInfo": {
14231+
"anyOf": [
14232+
{
14233+
"type": "string"
14234+
},
14235+
{
14236+
"type": "array",
14237+
"items": {
14238+
"type": "string"
14239+
}
14240+
}
14241+
]
14242+
},
14243+
"deletionInfo.deletionStatus": {
14244+
"anyOf": [
14245+
{
14246+
"type": "string"
14247+
},
14248+
{
14249+
"type": "array",
14250+
"items": {
14251+
"type": "string"
14252+
}
14253+
}
14254+
]
14255+
},
14256+
"deletionInfo.deletionDate": {
14257+
"anyOf": [
14258+
{
14259+
"type": "string"
14260+
},
14261+
{
14262+
"type": "array",
14263+
"items": {
14264+
"type": "string"
14265+
}
14266+
}
14267+
]
14268+
}
14269+
},
14270+
"additionalProperties": false
1419714271
}
1419814272
}
1419914273
}

packages/runtime/src/useCases/consumption/attributes/DeleteSharedAttributesForRejectedOrRevokedRelationship.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class DeleteSharedAttributesForRejectedOrRevokedRelationshipUseCase exten
5151
const forwardedAttributes = (await this.attributesController.getAttributesForwardedToPeer(
5252
relationship.peer.address,
5353
{ "@type": { $in: ["OwnIdentityAttribute", "OwnRelationshipAttribute", "PeerRelationshipAttribute"] } },
54+
{},
5455
undefined,
5556
false
5657
)) as (OwnIdentityAttribute | OwnRelationshipAttribute | PeerRelationshipAttribute)[];

packages/runtime/src/useCases/consumption/attributes/GetOwnAttributesSharedWithPeer.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import { AddressString, SchemaRepository, SchemaValidator, UseCase } from "../..
77
import { flattenObject } from "../../common/flattenObject";
88
import { AttributeMapper } from "./AttributeMapper";
99
import { GetAttributesRequestQuery, GetAttributesUseCase } from "./GetAttributes";
10+
import { GetForwardingDetailsForAttributeUseCase } from "./GetForwardingDetailsForAttribute";
1011

1112
export interface GetOwnAttributesSharedWithPeerRequest {
1213
peer: AddressString;
1314
query?: GetOwnAttributesSharedWithPeerRequestQuery;
15+
attributeForwardingDetailsQuery?: GetOwnAttributesSharedWithPeerRequestAttributeForwardingDetailsQuery;
1416
hideTechnical?: boolean;
1517
/**
1618
* default: true
@@ -35,6 +37,14 @@ export interface GetOwnAttributesSharedWithPeerRequestQuery {
3537
"deletionInfo.deletionDate"?: string | string[];
3638
}
3739

40+
export interface GetOwnAttributesSharedWithPeerRequestAttributeForwardingDetailsQuery {
41+
sourceReference?: string | string[];
42+
sharedAt?: string | string[];
43+
deletionInfo?: string | string[];
44+
"deletionInfo.deletionStatus"?: string | string[];
45+
"deletionInfo.deletionDate"?: string | string[];
46+
}
47+
3848
class Validator extends SchemaValidator<GetOwnAttributesSharedWithPeerRequest> {
3949
public constructor(@Inject schemaRepository: SchemaRepository) {
4050
super(schemaRepository.getSchema("GetOwnAttributesSharedWithPeerRequest"));
@@ -51,15 +61,18 @@ export class GetOwnAttributesSharedWithPeerUseCase extends UseCase<GetOwnAttribu
5161

5262
protected async executeInternal(request: GetOwnAttributesSharedWithPeerRequest): Promise<Result<LocalAttributeDTO[]>> {
5363
const query: GetAttributesRequestQuery = request.query ?? {};
54-
5564
const flattenedQuery = flattenObject(query);
5665
const dbQuery = GetAttributesUseCase.queryTranslator.parse(flattenedQuery);
66+
dbQuery["@type"] = dbQuery["@type"] ?? { $in: ["OwnIdentityAttribute", "OwnRelationshipAttribute"] };
5767

58-
dbQuery["@type"] = { $in: ["OwnIdentityAttribute", "OwnRelationshipAttribute"] };
68+
const attributeForwardingDetailsQuery = request.attributeForwardingDetailsQuery ?? {};
69+
const flattenedAttributeForwardingDetailsQuery = flattenObject(attributeForwardingDetailsQuery);
70+
const dbAttributeForwardingDetailsQuery = GetForwardingDetailsForAttributeUseCase.queryTranslator.parse(flattenedAttributeForwardingDetailsQuery);
5971

6072
const attributes = await this.attributeController.getAttributesExchangedWithPeer(
6173
CoreAddress.from(request.peer),
6274
dbQuery,
75+
dbAttributeForwardingDetailsQuery,
6376
request.hideTechnical,
6477
request.onlyLatestVersions
6578
);

packages/runtime/src/useCases/transport/relationships/GetAttributesForRelationship.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class GetAttributesForRelationshipUseCase extends UseCase<GetAttributesFo
3939
return Result.fail(RuntimeErrors.general.recordNotFound(Relationship));
4040
}
4141

42-
const attributes = await this.attributesController.getAttributesExchangedWithPeer(relationship.peer.address, {}, request.hideTechnical, request.onlyLatestVersions);
42+
const attributes = await this.attributesController.getAttributesExchangedWithPeer(relationship.peer.address, {}, {}, request.hideTechnical, request.onlyLatestVersions);
4343

4444
return Result.ok(AttributeMapper.toAttributeDTOList(attributes));
4545
}

packages/runtime/test/consumption/attributes.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
ForwardedAttributeDeletedByPeerEvent,
3232
GetAttributeUseCase,
3333
GetAttributesUseCase,
34+
GetOwnAttributesSharedWithPeerRequest,
3435
GetOwnAttributesSharedWithPeerUseCase,
3536
GetOwnIdentityAttributesUseCase,
3637
GetPeerAttributesUseCase,
@@ -605,6 +606,31 @@ describe("get OwnIdentityAttributes, own Attributes shared with peer and peer At
605606
const ownAttributesSharedWithPeer = result.value;
606607
expect(ownAttributesSharedWithPeer).toStrictEqual([updatedServices1OwnGivenNameV1, services1OwnRelationshipAttributeV1, services1TechnicalOwnRelationshipAttribute]);
607608
});
609+
610+
test("should return an attribute if it matches the (AttributeForwardingDetails)Query", async function () {
611+
const forwardingDetails = (await services1.consumption.attributes.getForwardingDetailsForAttribute({ attributeId: services1OwnGivenNameV1.id })).value;
612+
const sharedAt = forwardingDetails[0].sharedAt;
613+
614+
const request: GetOwnAttributesSharedWithPeerRequest = {
615+
peer: services2.address,
616+
query: { "@type": "OwnIdentityAttribute" },
617+
attributeForwardingDetailsQuery: { sharedAt }
618+
};
619+
620+
const matchingAttributes = (await services1.consumption.attributes.getOwnAttributesSharedWithPeer(request)).value;
621+
expect(matchingAttributes).toStrictEqual([services1OwnGivenNameV1]);
622+
});
623+
624+
test("should not return an attribute if it doesn't match the (AttributeForwardingDetails)Query", async function () {
625+
const request: GetOwnAttributesSharedWithPeerRequest = {
626+
peer: services2.address,
627+
query: { "@type": "OwnIdentityAttribute" },
628+
attributeForwardingDetailsQuery: { sharedAt: "anotherTime" }
629+
};
630+
631+
const matchingAttributes = (await services1.consumption.attributes.getOwnAttributesSharedWithPeer(request)).value;
632+
expect(matchingAttributes).toHaveLength(0);
633+
});
608634
});
609635

610636
describe(GetPeerAttributesUseCase.name, () => {

0 commit comments

Comments
 (0)