Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thirdPartyAddress to the Attribute's shareInfo #282

Merged
merged 47 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
3104a0a
feat: add third party address to share info of an attribute
sebbi08 Sep 23, 2024
9bc036a
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Sep 23, 2024
145ba1f
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Sep 23, 2024
88ef386
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Sep 23, 2024
c0c0aad
fix: tests
sebbi08 Sep 24, 2024
c6ecf51
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Sep 25, 2024
f499978
Update packages/consumption/src/modules/attributes/local/CreateShared…
sebbi08 Sep 30, 2024
9bd016e
Update packages/consumption/src/modules/attributes/local/CreateShared…
sebbi08 Sep 30, 2024
057429a
Update packages/consumption/src/modules/attributes/local/LocalAttribu…
sebbi08 Sep 30, 2024
5cd0216
chore: improve third party check
sebbi08 Sep 30, 2024
590ad48
chore: improve third party check
sebbi08 Sep 30, 2024
886837b
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Sep 30, 2024
448e622
chore: revert local settings
sebbi08 Oct 1, 2024
56fdad7
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 1, 2024
6d6726e
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 1, 2024
ce470da
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 2, 2024
e092cc8
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 2, 2024
538f521
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 2, 2024
e9d1ab9
chore: improve error code
sebbi08 Oct 7, 2024
b02c13c
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 7, 2024
a1a6888
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 9, 2024
73217a5
chore: remove eslint ignores
sebbi08 Oct 9, 2024
6b7426d
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 10, 2024
6269a40
chore: rename test functions
sebbi08 Oct 10, 2024
bb88591
chore: rename test functions
sebbi08 Oct 10, 2024
1bc212a
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 11, 2024
75b03e8
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 11, 2024
0609061
feat: add third party address to DVO
sebbi08 Oct 14, 2024
9ddda95
chore: RelationshipAttribute in error text
sebbi08 Oct 14, 2024
d3757cc
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 14, 2024
017050f
chore: pr comments
sebbi08 Oct 15, 2024
edb583c
chore: test lower case
sebbi08 Oct 15, 2024
4881998
chore: change test name
sebbi08 Oct 15, 2024
c5dbb08
chore: remove debugger
sebbi08 Oct 15, 2024
cc9bada
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 16, 2024
cfd3f68
feat: automaticly set the thirdParty address when creating a local at…
sebbi08 Oct 16, 2024
b101240
feat: also forward thirdparty adress in the attribute succession
sebbi08 Oct 16, 2024
3566734
chore: improve js doc wording
sebbi08 Oct 16, 2024
08c4f81
chore: update DVOs
sebbi08 Oct 16, 2024
125a22b
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 17, 2024
89293d4
Merge branch 'main' into feature/add_third_party_adress_to_share_info
mergify[bot] Oct 17, 2024
448df83
chore: PR comments
sebbi08 Oct 17, 2024
5cb9778
chore: pr comments
sebbi08 Oct 21, 2024
983525c
Merge branch 'main' into feature/add_third_party_adress_to_share_info
sebbi08 Oct 21, 2024
43a781b
chore: pr comments
sebbi08 Oct 21, 2024
331bf5f
chore: fix tests
sebbi08 Oct 21, 2024
71836d7
chore: reword error
sebbi08 Oct 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ export class AttributesController extends ConsumptionBaseController {
const shareInfo = LocalAttributeShareInfo.from({
peer: parsedParams.peer,
requestReference: parsedParams.requestReference,
sourceAttribute: parsedParams.sourceAttributeId
sourceAttribute: parsedParams.sourceAttributeId,
thirdPartyAddress: sourceAttribute.shareInfo?.peer
});

const sharedLocalAttributeCopy = await LocalAttribute.fromAttribute(sourceAttribute.content, undefined, shareInfo, parsedParams.attributeId);
Expand All @@ -353,7 +354,8 @@ export class AttributesController extends ConsumptionBaseController {
public async createSharedLocalAttribute(params: ICreateSharedLocalAttributeParams): Promise<LocalAttribute> {
const shareInfo = LocalAttributeShareInfo.from({
peer: params.peer,
requestReference: params.requestReference
requestReference: params.requestReference,
thirdPartyAddress: params.thirdPartyAddress
});
const peerLocalAttribute = LocalAttribute.from({
id: params.id ?? (await ConsumptionIds.attribute.generate()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ export interface CreateSharedLocalAttributeParamsJSON {
content: IdentityAttributeJSON | RelationshipAttributeJSON;
requestReferece: string;
peer: string;
thirdPartyAddress?: string;
}

export interface ICreateSharedLocalAttributeParams extends ISerializable {
id?: ICoreId; // needs to be optional because sometimes (e.g. when accepting a CreateAttributeRequestItem) the id is not known yet
content: IIdentityAttribute | IRelationshipAttribute;
requestReference: ICoreId;
peer: ICoreAddress;
thirdPartyAddress?: ICoreAddress;
}

export class CreateSharedLocalAttributeParams extends Serializable implements ICreateSharedLocalAttributeParams {
Expand All @@ -33,6 +35,10 @@ export class CreateSharedLocalAttributeParams extends Serializable implements IC
@validate()
public peer: CoreAddress;

@serialize()
@validate({ nullable: true })
public thirdPartyAddress?: CoreAddress;

public static from(value: ICreateSharedLocalAttributeParams | CreateSharedLocalAttributeParamsJSON): CreateSharedLocalAttributeParams {
return this.fromAny(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ export type OwnSharedRelationshipAttribute = LocalAttribute & {
isDefault: undefined;
};

export type OwnSharedThirdPartyRelationshipAttribute = OwnSharedRelationshipAttribute & {
shareInfo: OwnSharedRelationshipAttribute["shareInfo"] & {
thirdPartyAddress: CoreAddress;
};
};

export type PeerSharedIdentityAttribute = LocalAttribute & {
content: IdentityAttribute;
shareInfo: LocalAttributeShareInfo & { sourceAttribute: undefined };
Expand All @@ -62,9 +68,17 @@ export type PeerSharedRelationshipAttribute = LocalAttribute & {
isDefault: undefined;
};

export type PeerSharedThirdPartyRelationshipAttribute = PeerSharedRelationshipAttribute & {
shareInfo: PeerSharedRelationshipAttribute["shareInfo"] & {
thirdPartyAddress: CoreAddress;
};
};

export type ThirdPartyOwnedRelationshipAttribute = LocalAttribute & {
content: RelationshipAttribute;
shareInfo: LocalAttributeShareInfo;
shareInfo: LocalAttribute["shareInfo"] & {
thirdPartyAddress: CoreAddress;
};
isDefault: undefined;
};

Expand Down Expand Up @@ -166,6 +180,18 @@ export class LocalAttribute extends CoreSynchronizable implements ILocalAttribut
return isPeerSharedAttribute;
}

public isOwnSharedThirdPartyRelationshipAttribute(ownAddress: CoreAddress): this is OwnSharedThirdPartyRelationshipAttribute {
const isThirdPartyAttribute = this.shareInfo?.thirdPartyAddress !== undefined;
const isOwnShared = this.isOwnedBy(ownAddress);
return isThirdPartyAttribute && isOwnShared;
}

public isPeerSharedThirdPartyRelationshipAttribute(peerAddress: CoreAddress): this is PeerSharedThirdPartyRelationshipAttribute {
const isThirdPartyAttribute = this.shareInfo?.thirdPartyAddress !== undefined;
const isPeerShared = this.isOwnedBy(peerAddress);
return isThirdPartyAttribute && isPeerShared;
}

public isThirdPartyOwnedAttribute(ownAddress: CoreAddress, thirdPartyAddress?: CoreAddress): this is ThirdPartyOwnedRelationshipAttribute {
let isThirdPartyOwnedAttribute = this.isShared() && !this.isOwnedBy(ownAddress) && !this.isOwnedBy(this.shareInfo.peer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ import { CoreAddress, CoreId, ICoreAddress, ICoreId } from "@nmshd/core-types";
import { nameof } from "ts-simple-nameof";
import { ConsumptionError } from "../../../consumption/ConsumptionError";

/* Either of requestReference or noticicationReference must be set, but not both. */
/* Either of requestReference or notificationReference must be set, but not both. */
export interface LocalAttributeShareInfoJSON {
requestReference?: string;
notificationReference?: string;

peer: string;
sourceAttribute?: string;
thirdPartyAddress?: string;
}

/* Either of requestReference or noticicationReference must be set, but not both. */
/* Either of requestReference or notificationReference must be set, but not both. */
export interface ILocalAttributeShareInfo extends ISerializable {
requestReference?: ICoreId;
notificationReference?: ICoreId;

peer: ICoreAddress;
sourceAttribute?: ICoreId;
thirdPartyAddress?: ICoreAddress;
}

export class LocalAttributeShareInfo extends Serializable implements ILocalAttributeShareInfo {
Expand All @@ -38,6 +38,10 @@ export class LocalAttributeShareInfo extends Serializable implements ILocalAttri
@validate({ nullable: true })
public sourceAttribute?: CoreId;

@serialize()
@validate({ nullable: true })
public thirdPartyAddress?: CoreAddress;

public static from(value: ILocalAttributeShareInfo | LocalAttributeShareInfoJSON): LocalAttributeShareInfo {
return super.fromAny(value) as LocalAttributeShareInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ export class ReadAttributeRequestItemProcessor extends GenericRequestItemProcess
return ReadAttributeAcceptResponseItem.from({
result: ResponseItemResult.Accepted,
attributeId: sharedLocalAttribute.id,
attribute: sharedLocalAttribute.content
attribute: sharedLocalAttribute.content,
thirdPartyAddress: sharedLocalAttribute.shareInfo?.thirdPartyAddress
});
}

Expand Down Expand Up @@ -306,25 +307,31 @@ export class ReadAttributeRequestItemProcessor extends GenericRequestItemProcess
}

private async performOwnSharedThirdPartyRelationshipAttributeSuccession(sharedPredecessorId: CoreId, sourceSuccessor: LocalAttribute, requestInfo: LocalRequestInfo) {
const predecessor = await this.consumptionController.attributes.getLocalAttribute(sharedPredecessorId);

const successorParams = {
content: sourceSuccessor.content,
shareInfo: LocalAttributeShareInfo.from({
peer: requestInfo.peer,
requestReference: requestInfo.id,
sourceAttribute: sourceSuccessor.id
sourceAttribute: sourceSuccessor.id,
thirdPartyAddress: predecessor?.shareInfo?.thirdPartyAddress
})
};
const { successor } = await this.consumptionController.attributes.succeedOwnSharedRelationshipAttribute(sharedPredecessorId, successorParams);
return successor;
}

private async performThirdPartyOwnedRelationshipAttributeSuccession(sharedPredecessorId: CoreId, sourceSuccessor: LocalAttribute, requestInfo: LocalRequestInfo) {
const predecessor = await this.consumptionController.attributes.getLocalAttribute(sharedPredecessorId);

const successorParams = {
content: sourceSuccessor.content,
shareInfo: LocalAttributeShareInfo.from({
peer: requestInfo.peer,
requestReference: requestInfo.id,
sourceAttribute: sourceSuccessor.id
sourceAttribute: sourceSuccessor.id,
thirdPartyAddress: predecessor?.shareInfo?.thirdPartyAddress
})
};
const { successor } = await this.consumptionController.attributes.succeedThirdPartyOwnedRelationshipAttribute(sharedPredecessorId, successorParams);
Expand Down Expand Up @@ -361,7 +368,8 @@ export class ReadAttributeRequestItemProcessor extends GenericRequestItemProcess
id: responseItem.attributeId,
content: responseItem.attribute,
peer: requestInfo.peer,
requestReference: requestInfo.id
requestReference: requestInfo.id,
thirdPartyAddress: responseItem.thirdPartyAddress
});
}

Expand All @@ -378,7 +386,13 @@ export class ReadAttributeRequestItemProcessor extends GenericRequestItemProcess
if (responseItem.successorContent instanceof IdentityAttribute) {
const { predecessor, successor } = await this.consumptionController.attributes.succeedPeerSharedIdentityAttribute(responseItem.predecessorId, successorParams);
return new PeerSharedAttributeSucceededEvent(this.currentIdentityAddress.toString(), predecessor, successor);
} else if (responseItem.successorContent.owner === requestInfo.peer) {
}
const predecessor = await this.consumptionController.attributes.getLocalAttribute(responseItem.predecessorId);

if (successorParams.shareInfo) {
successorParams.shareInfo.thirdPartyAddress = predecessor?.shareInfo?.thirdPartyAddress;
}
if (responseItem.successorContent.owner === requestInfo.peer) {
await this.consumptionController.attributes.succeedPeerSharedRelationshipAttribute(responseItem.predecessorId, successorParams);
} else {
await this.consumptionController.attributes.succeedThirdPartyOwnedRelationshipAttribute(responseItem.predecessorId, successorParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ export class ShareAttributeRequestItemProcessor extends GenericRequestItemProces
if (nonPendingRelationshipsToPeer.length === 0) {
return ValidationResult.error(ConsumptionCoreErrors.requests.cannotShareRelationshipAttributeOfPendingRelationship());
}

if (!requestItem.thirdPartyAddress) {
return ValidationResult.error(
ConsumptionCoreErrors.requests.invalidRequestItem(
"The source attribute provided is a RelationshipAttribute. You must provide a third party address that is the original peer when sharing with a third party."
)
);
}

if (!requestItem.thirdPartyAddress.equals(foundAttribute.shareInfo.peer)) {
return ValidationResult.error(ConsumptionCoreErrors.requests.invalidRequestItem("The third party address must be the peer of the RelationshipAttribute."));
}
}

if (requestItem.attribute instanceof IdentityAttribute) {
Expand Down Expand Up @@ -172,7 +184,8 @@ export class ShareAttributeRequestItemProcessor extends GenericRequestItemProces
const localAttribute = await this.consumptionController.attributes.createSharedLocalAttribute({
content: requestItem.attribute,
peer: requestInfo.peer,
requestReference: requestInfo.id
requestReference: requestInfo.id,
thirdPartyAddress: requestItem.thirdPartyAddress
});

return ShareAttributeAcceptResponseItem.from({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,38 @@ describe("AttributesController", function () {

mockEventBus.expectLastPublishedEvent(AttributeCreatedEvent);
});
});

test("should add a third party address when creating a shared copy of a relationship attribute", async function () {
const thirdPartyAddress = CoreAddress.from("thirdParty");
const peerAddress = CoreAddress.from("peerAddress");

const relationshipAttribute = await consumptionController.attributes.createAttributeUnsafe({
content: RelationshipAttribute.from({
key: "customerId",
value: {
"@type": "ProprietaryString",
value: "0815",
title: "Customer ID"
},
owner: CoreAddress.from("thirdPartyAddress"),
confidentiality: RelationshipAttributeConfidentiality.Public
}),
shareInfo: {
peer: thirdPartyAddress,
requestReference: CoreId.from("reqRefA")
}
});

const thirdPartyLocalAttributeCopy = await consumptionController.attributes.createSharedLocalAttributeCopy({
peer: peerAddress,
requestReference: CoreId.from("reqRefB"),
sourceAttributeId: relationshipAttribute.id,
attributeId: CoreId.from("ATTthirdParty")
});

expect(thirdPartyLocalAttributeCopy.shareInfo?.thirdPartyAddress?.toString()).toBe(thirdPartyAddress.toString());
});
});
describe("query Attributes", function () {
test("should allow to query relationship attributes with empty owner", async function () {
const relationshipAttributeParams: ICreateSharedLocalAttributeParams = {
Expand Down Expand Up @@ -2361,7 +2391,8 @@ describe("AttributesController", function () {
shareInfo: {
peer: CoreAddress.from("peerAddress"),
requestReference: CoreId.from("reqRefA"),
sourceAttribute: CoreId.from("ATT0")
sourceAttribute: CoreId.from("ATT0"),
thirdPartyAddress: CoreAddress.from("thirdPartyAddress")
}
});
const successorParams: IAttributeSuccessorParams = {
Expand All @@ -2378,7 +2409,8 @@ describe("AttributesController", function () {
shareInfo: {
peer: CoreAddress.from("peerAddress"),
requestReference: CoreId.from("reqRefB"),
sourceAttribute: CoreId.from("ATT1")
sourceAttribute: CoreId.from("ATT1"),
thirdPartyAddress: CoreAddress.from("thirdPartyAddress")
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ describe("LocalAttributeShareInfo", function () {
{
notificationReference: "notificationReferenceId",
peer: "peerAddress"
},
{
notificationReference: "notificationReferenceId",
peer: "peerAddress",
sourceAttribute: "sourceAttributeId",
thirdPartyAddress: "thirdPartyAddress"
},
{
requestReference: "requestReferenceId",
peer: "peerAddress",
sourceAttribute: "sourceAttributeId",
thirdPartyAddress: "thirdPartyAddress"
}
];
test.each(validShareInfoJsonParams)("should create objects from valid parameters using from()", function (shareInfoParams: LocalAttributeShareInfoJSON) {
Expand Down
Loading