-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Bump version * Added delegation events * Updated event names * Revert update event names * Updated event names * Bump version * Updated changelog * Bump version * Fix version
- Loading branch information
1 parent
5a586c9
commit 8f0db8c
Showing
11 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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; | ||
DelegationStampsV2 stamps = 13; | ||
optional DelegationContractDocumentV2 activationContract = 14; | ||
optional DelegationContractDocumentV2 revocationContract = 15; | ||
} | ||
|
||
message DelegationContractDocumentV2 { | ||
string id = 1; | ||
string name = 2; | ||
string prettyName = 3; | ||
string contentType = 4; | ||
int64 createdAt = 5; | ||
} | ||
|
||
message DelegationStampV2 { | ||
int64 when = 1; | ||
} | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
|
||
package delegation.v2; | ||
|
||
import "v2/delegation/delegation.proto"; | ||
|
||
message ProducerDelegationSubmittedV2 { | ||
DelegationV2 delegation = 1; | ||
} | ||
|
||
message ProducerDelegationApprovedV2 { | ||
DelegationV2 delegation = 1; | ||
} | ||
|
||
message ProducerDelegationRejectedV2 { | ||
DelegationV2 delegation = 1; | ||
} | ||
|
||
message ProducerDelegationRevokedV2 { | ||
DelegationV2 delegation = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { z } from "zod"; | ||
import { match } from "ts-pattern"; | ||
import { | ||
ProducerDelegationSubmittedV2, | ||
ProducerDelegationApprovedV2, | ||
ProducerDelegationRejectedV2, | ||
ProducerDelegationRevokedV2, | ||
} from "../gen/v2/delegation/events.js"; | ||
import { protobufDecoder } from "../utils.js"; | ||
|
||
export function delegationEventToBinaryDataV2( | ||
event: DelegationEventV2 | ||
): Uint8Array { | ||
return match(event) | ||
.with({ type: "ProducerDelegationSubmitted" }, ({ data }) => | ||
ProducerDelegationSubmittedV2.toBinary(data) | ||
) | ||
.with({ type: "ProducerDelegationApproved" }, ({ data }) => | ||
ProducerDelegationApprovedV2.toBinary(data) | ||
) | ||
.with({ type: "ProducerDelegationRejected" }, ({ data }) => | ||
ProducerDelegationRejectedV2.toBinary(data) | ||
) | ||
.with({ type: "ProducerDelegationRevoked" }, ({ data }) => | ||
ProducerDelegationRevokedV2.toBinary(data) | ||
) | ||
.exhaustive(); | ||
} | ||
|
||
export const DelegationEventV2 = z.discriminatedUnion("type", [ | ||
z.object({ | ||
event_version: z.literal(2), | ||
type: z.literal("ProducerDelegationSubmitted"), | ||
data: protobufDecoder(ProducerDelegationSubmittedV2), | ||
stream_id: z.string(), | ||
version: z.number(), | ||
timestamp: z.coerce.date(), | ||
}), | ||
z.object({ | ||
event_version: z.literal(2), | ||
type: z.literal("ProducerDelegationApproved"), | ||
data: protobufDecoder(ProducerDelegationApprovedV2), | ||
stream_id: z.string(), | ||
version: z.number(), | ||
timestamp: z.coerce.date(), | ||
}), | ||
z.object({ | ||
event_version: z.literal(2), | ||
type: z.literal("ProducerDelegationRejected"), | ||
data: protobufDecoder(ProducerDelegationRejectedV2), | ||
stream_id: z.string(), | ||
version: z.number(), | ||
timestamp: z.coerce.date(), | ||
}), | ||
z.object({ | ||
event_version: z.literal(2), | ||
type: z.literal("ProducerDelegationRevoked"), | ||
data: protobufDecoder(ProducerDelegationRevokedV2), | ||
stream_id: z.string(), | ||
version: z.number(), | ||
timestamp: z.coerce.date(), | ||
}), | ||
]); | ||
|
||
export type DelegationEventV2 = z.infer<typeof DelegationEventV2>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { match } from "ts-pattern"; | ||
import { z } from "zod"; | ||
import { VersionedEvent } from "../utils.js"; | ||
import { | ||
DelegationEventV2, | ||
delegationEventToBinaryDataV2, | ||
} from "./eventsV2.js"; | ||
|
||
function delegationEventToBinaryData(event: DelegationEvent): Uint8Array { | ||
return match(event) | ||
.with({ event_version: 2 }, delegationEventToBinaryDataV2) | ||
.exhaustive(); | ||
} | ||
|
||
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 = match(obj) | ||
.with({ event_version: 1 }, () => { | ||
throw new Error("Unsupported event version"); | ||
}) | ||
.with({ event_version: 2 }, () => DelegationEventV2.safeParse(obj)) | ||
.exhaustive(); | ||
|
||
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<typeof DelegationEvent>; | ||
export { DelegationEventV2 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ describe("eservice", () => { | |
verified: [], | ||
declared: [], | ||
}, | ||
rejectionReasons: [], | ||
}, | ||
], | ||
}, | ||
|