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

DIDComm alignment: expires_time & created_time #288

Merged
merged 9 commits into from
Nov 25, 2024

Conversation

volodymyr-basiuk
Copy link
Collaborator

No description provided.

@volodymyr-basiuk volodymyr-basiuk marked this pull request as ready for review November 20, 2024 15:52
@@ -310,6 +312,12 @@ export class PaymentHandler
paymentRequest: PaymentRequestMessage,
ctx: PaymentRequestMessageHandlerOptions
): Promise<BasicMessage | null> {
if (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of code duplication. Can we do something like that:

package common
mustNotExpired = (obj: {expires_time?: number})) => {
 if paymentRequest?.expires_time && paymentRequest.expires_time < Math.floor(Date.now() / 1000)
     throw new Error
 }

Usage:

common.MustNotExpired(offer)
or
common.MustNotExpired(proposal)
...

My idea is have a utility function that consumes interface with optional field expires_time and does some logic

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@volodymyr-basiuk volodymyr-basiuk changed the title DIDComm alignement: expires_time & created_time DIDComm alignment: expires_time & created_time Nov 20, 2024
@@ -315,6 +316,7 @@ export class AuthHandler
ctx: AuthRespOptions
): Promise<BasicMessage | null> {
const request = ctx.request;
verifyExpiresTime(response);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to add option to the handler - allowExpiredMessages.

source:
However, protocols can nuance this in their formal spec. For example, an online auction protocol might specify that timed out bids must be ignored instead of triggering a cancellation of the whole auction

/**
* Basic message with all possible fields required
*/
export type RequiredBasicMessage = Omit<Required<BasicMessage>, 'created_time' | 'expires_time'> & {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required makes all optional fields required, and we need all required except created_time and expires_time

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

body is also can be optional. Why do we need this at all

src/iden3comm/handlers/payment.ts Outdated Show resolved Hide resolved
vmidyllic
vmidyllic previously approved these changes Nov 25, 2024
@volodymyr-basiuk volodymyr-basiuk merged commit cd001c6 into main Nov 25, 2024
2 checks passed
@volodymyr-basiuk volodymyr-basiuk deleted the feat/expires_time branch November 25, 2024 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants