diff --git a/proto/v2/delegation/delegation.proto b/proto/v2/delegation/delegation.proto deleted file mode 100644 index 5a79b17..0000000 --- a/proto/v2/delegation/delegation.proto +++ /dev/null @@ -1,52 +0,0 @@ -syntax = "proto3"; - -package delegation.v2; - -message DelegationV2 { - string id = 1; - string delegatorId = 2; - string delegateId = 3; - string eserviceId = 4; - int64 createdAt = 5; - int64 submittedAt = 6; - optional int64 approvedAt = 7; - optional int64 rejectedAt = 8; - optional string rejectionReason = 9; - optional int64 revokedAt = 10; - DelegationStateV2 state = 11; - DelegationKindV2 kind = 12; - optional DelegationContractDocumentV2 contract = 14; - optional DelegationStampsV2 stamps = 13; -} - -message DelegationContractDocumentV2 { - string id = 1; - string name = 2; - string prettyName = 3; - string contentType = 4; - int64 createdAt = 5; -} - -message DelegationStampV2 { - string who = 1; - int64 when = 2; -} - -message DelegationStampsV2 { - DelegationStampV2 submission = 1; - optional DelegationStampV2 activation = 2; - optional DelegationStampV2 rejection = 3; - optional DelegationStampV2 revocation = 4; -} - -enum DelegationStateV2 { - WAITING_FOR_APPROVAL= 0; - ACTIVE= 1; - REJECTED= 2; - REVOKED= 3; -} - -enum DelegationKindV2 { - DELEGATED_PRODUCER = 0; - DELEGATED_CONSUMER = 1; -} \ No newline at end of file diff --git a/proto/v2/delegation/events.proto b/proto/v2/delegation/events.proto deleted file mode 100644 index 171f5c1..0000000 --- a/proto/v2/delegation/events.proto +++ /dev/null @@ -1,21 +0,0 @@ -syntax = "proto3"; - -package delegation.v2; - -import "v2/delegation/delegation.proto"; - -message DelegationSubmittedV2 { - DelegationV2 delegation = 1; -} - -message DelegationApprovedV2 { - DelegationV2 delegation = 1; -} - -message DelegationRejectedV2 { - DelegationV2 delegation = 1; -} - -message DelegationRevokedV2 { - DelegationV2 delegation = 1; -} \ No newline at end of file diff --git a/proto/v2/eservice/eservice.proto b/proto/v2/eservice/eservice.proto index 1d5377d..1f20184 100644 --- a/proto/v2/eservice/eservice.proto +++ b/proto/v2/eservice/eservice.proto @@ -11,7 +11,6 @@ message EServiceV2 { repeated EServiceDescriptorV2 descriptors = 6; int64 createdAt = 7; EServiceModeV2 mode = 8; - optional string delegationId = 9; } message EServiceAttributeValueV2 { diff --git a/proto/v2/eservice/events.proto b/proto/v2/eservice/events.proto index 4cc4d6e..0b7c97a 100644 --- a/proto/v2/eservice/events.proto +++ b/proto/v2/eservice/events.proto @@ -102,13 +102,3 @@ message EServiceDescriptorDocumentDeletedV2 { message EServiceDescriptionUpdatedV2 { EServiceV2 eservice = 1; } - -message EServiceDelegationAssignedV2 { - string delegationId = 1; - EServiceV2 eservice = 2; -} - -message EServiceDelegationRevokedV2 { - string delegationId = 1; - EServiceV2 eservice = 2; -} diff --git a/src/delegation/eventsV2.ts b/src/delegation/eventsV2.ts deleted file mode 100644 index 2e0a13c..0000000 --- a/src/delegation/eventsV2.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { match } from "ts-pattern"; -import { z } from "zod"; -import { protobufDecoder } from "../utils.js"; -import { - DelegationApprovedV2, - DelegationRejectedV2, - DelegationRevokedV2, - DelegationSubmittedV2, -} from "../gen/v2/delegation/events.js"; - -export function delegationEventToBinaryDataV2( - event: DelegationEventV2 -): Uint8Array { - return match(event) - .with({ type: "DelegationSubmitted" }, ({ data }) => - DelegationSubmittedV2.toBinary(data) - ) - .with({ type: "DelegationApproved" }, ({ data }) => - DelegationApprovedV2.toBinary(data) - ) - .with({ type: "DelegationRejected" }, ({ data }) => - DelegationRejectedV2.toBinary(data) - ) - .with({ type: "DelegationRevoked" }, ({ data }) => - DelegationRevokedV2.toBinary(data) - ) - .exhaustive(); -} - -export const DelegationEventV2 = z.discriminatedUnion("type", [ - z.object({ - event_version: z.literal(2), - type: z.literal("DelegationSubmitted"), - data: protobufDecoder(DelegationSubmittedV2), - stream_id: z.string(), - version: z.number(), - timestamp: z.coerce.date(), - }), - z.object({ - event_version: z.literal(2), - type: z.literal("DelegationApproved"), - data: protobufDecoder(DelegationApprovedV2), - stream_id: z.string(), - version: z.number(), - timestamp: z.coerce.date(), - }), - z.object({ - event_version: z.literal(2), - type: z.literal("DelegationRejected"), - data: protobufDecoder(DelegationRejectedV2), - stream_id: z.string(), - version: z.number(), - timestamp: z.coerce.date(), - }), - z.object({ - event_version: z.literal(2), - type: z.literal("DelegationRevoked"), - data: protobufDecoder(DelegationRevokedV2), - stream_id: z.string(), - version: z.number(), - timestamp: z.coerce.date(), - }), -]); -export type DelegationEventV2 = z.infer; diff --git a/src/delegation/index.ts b/src/delegation/index.ts deleted file mode 100644 index 41d27b4..0000000 --- a/src/delegation/index.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { z } from "zod"; -import { VersionedEvent } from "../utils.js"; -import { - delegationEventToBinaryDataV2, - DelegationEventV2, -} from "./eventsV2.js"; - -function DelegationEventToBinaryData(event: DelegationEvent): Uint8Array { - return delegationEventToBinaryDataV2(event); -} - -export function encodeOutboundDelegationEvent(event: DelegationEvent): string { - return JSON.stringify({ - event_version: event.event_version, - type: event.type, - data: Buffer.from(DelegationEventToBinaryData(event)).toString("hex"), - stream_id: event.stream_id, - version: event.version, - timestamp: event.timestamp, - }); -} - -export function decodeOutboundDelegationEvent( - encodedEvent: string -): DelegationEvent { - return DelegationEvent.parse(JSON.parse(encodedEvent)); -} - -export const DelegationEvent = VersionedEvent.transform((obj, ctx) => { - const res = DelegationEventV2.safeParse(obj); - - if (!res.success) { - res.error.issues.forEach(ctx.addIssue); - return z.NEVER; - } - return res.data; -}); - -export type DelegationEventType = DelegationEvent["type"]; -export type DelegationEvent = z.infer; -export { DelegationEventV2 }; diff --git a/src/eservice/eventsV2.ts b/src/eservice/eventsV2.ts index bf9b5a3..b21e571 100644 --- a/src/eservice/eventsV2.ts +++ b/src/eservice/eventsV2.ts @@ -21,8 +21,6 @@ import { EServiceDraftDescriptorUpdatedV2, EServiceDescriptorQuotasUpdatedV2, EServiceDescriptionUpdatedV2, - EServiceDelegationAssignedV2, - EServiceDelegationRevokedV2, } from "../gen/v2/eservice/events.js"; export function eServiceEventToBinaryDataV2( @@ -86,12 +84,6 @@ export function eServiceEventToBinaryDataV2( .with({ type: "EServiceDescriptionUpdated" }, ({ data }) => EServiceDescriptionUpdatedV2.toBinary(data) ) - .with({ type: "EServiceDelegationAssigned" }, ({ data }) => - EServiceDescriptionUpdatedV2.toBinary(data) - ) - .with({ type: "EServiceDelegationRevoked" }, ({ data }) => - EServiceDescriptionUpdatedV2.toBinary(data) - ) .exhaustive(); } @@ -248,22 +240,6 @@ export const EServiceEventV2 = z.discriminatedUnion("type", [ version: z.number(), timestamp: z.coerce.date(), }), - z.object({ - event_version: z.literal(2), - type: z.literal("EServiceDelegationAssigned"), - data: protobufDecoder(EServiceDelegationAssignedV2), - stream_id: z.string(), - version: z.number(), - timestamp: z.coerce.date(), - }), - z.object({ - event_version: z.literal(2), - type: z.literal("EServiceDelegationRevoked"), - data: protobufDecoder(EServiceDelegationRevokedV2), - stream_id: z.string(), - version: z.number(), - timestamp: z.coerce.date(), - }), ]); export type EServiceEventV2 = z.infer; diff --git a/src/index.ts b/src/index.ts index 34bb00a..e70a9d0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,6 @@ export * from "./eservice/index.js"; export * from "./agreement/index.js"; export * from "./purpose/index.js"; export * from "./tenant/index.js"; -export * from "./delegation/index.js"; export * from "./gen/v1/agreement/agreement.js"; export * from "./gen/v1/agreement/events.js"; @@ -21,5 +20,3 @@ export * from "./gen/v2/purpose/purpose.js"; export * from "./gen/v2/purpose/events.js"; export * from "./gen/v2/tenant/tenant.js"; export * from "./gen/v2/tenant/events.js"; -export * from "./gen/v2/delegation/delegation.js"; -export * from "./gen/v2/delegation/events.js"; diff --git a/tests/delegation.test.ts b/tests/delegation.test.ts deleted file mode 100644 index 899337b..0000000 --- a/tests/delegation.test.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { describe, it, expect } from "vitest"; -import { - encodeOutboundDelegationEvent, - decodeOutboundDelegationEvent, - DelegationEvent, -} from "../src/index.js"; - -describe("delegation", () => { - it("should correctly encode and decode DelegationApproved event", () => { - const event: DelegationEvent = { - event_version: 2, - type: "DelegationApproved", - data: { - delegation: undefined, - }, - stream_id: "123", - timestamp: new Date(), - version: 1, - }; - - const encoded = encodeOutboundDelegationEvent(event); - const decoded = decodeOutboundDelegationEvent(encoded); - - expect(decoded).toEqual(event); - }); -});