Skip to content

Commit

Permalink
expires_time as an create option
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Nov 25, 2024
1 parent c0a0bbc commit 509f70a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/iden3comm/handlers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { parseAcceptProfile } from '../utils';
export type AuthorizationRequestCreateOptions = {
accept?: string[];
scope?: ZeroKnowledgeProofRequest[];
expires_time?: Date;
};

/**
Expand Down Expand Up @@ -78,7 +79,8 @@ export function createAuthorizationRequestWithMessage(
callbackUrl: callbackUrl,
scope: opts?.scope ?? []
},
created_time: Math.floor(Date.now() / 1000)
created_time: Math.floor(Date.now() / 1000),
expires_time: opts?.expires_time ? Math.floor(opts.expires_time.getTime() / 1000) : undefined
};
return request;
}
Expand Down
15 changes: 12 additions & 3 deletions src/iden3comm/handlers/credential-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export type ProposalRequestCreationOptions = {
credentials: ProposalRequestCredential[];
metadata?: { type: string; data?: JsonDocumentObject };
did_doc?: DIDDocument;
expires_time?: Date;
};

/** @beta ProposalCreationOptions represents proposal creation options */
export type ProposalCreationOptions = {
expires_time?: Date;
};

/**
Expand All @@ -53,7 +59,8 @@ export function createProposalRequest(
typ: MediaType.PlainMessage,
type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE,
body: opts,
created_time: Math.floor(Date.now() / 1000)
created_time: Math.floor(Date.now() / 1000),
expires_time: opts?.expires_time ? Math.floor(opts.expires_time.getTime() / 1000) : undefined
};
return request;
}
Expand All @@ -69,7 +76,8 @@ export function createProposalRequest(
export function createProposal(
sender: DID,
receiver: DID,
proposals?: Proposal[]
proposals?: Proposal[],
opts?: ProposalCreationOptions
): ProposalMessage {
const uuidv4 = uuid.v4();
const request: ProposalMessage = {
Expand All @@ -82,7 +90,8 @@ export function createProposal(
body: {
proposals: proposals || []
},
created_time: Math.floor(Date.now() / 1000)
created_time: Math.floor(Date.now() / 1000),
expires_time: opts?.expires_time ? Math.floor(opts.expires_time.getTime() / 1000) : undefined
};
return request;
}
Expand Down
22 changes: 18 additions & 4 deletions src/iden3comm/handlers/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ import { Signer, ethers } from 'ethers';
import { Resolvable } from 'did-resolver';
import { verifyExpiresTime } from './common';

/** @beta PaymentRequestCreationOptions represents payment-request creation options */
export type PaymentRequestCreationOptions = {
expires_time?: Date;
};

/** @beta PaymentCreationOptions represents proposal creation options */
export type PaymentCreationOptions = {
expires_time?: Date;
};

/**
* @beta
* createPaymentRequest is a function to create protocol payment-request message
Expand All @@ -46,7 +56,8 @@ export function createPaymentRequest(
sender: DID,
receiver: DID,
agent: string,
payments: PaymentRequestInfo[]
payments: PaymentRequestInfo[],
opts?: PaymentRequestCreationOptions
): PaymentRequestMessage {
const uuidv4 = uuid.v4();
const request: PaymentRequestMessage = {
Expand All @@ -60,7 +71,8 @@ export function createPaymentRequest(
agent,
payments
},
created_time: Math.floor(Date.now() / 1000)
created_time: Math.floor(Date.now() / 1000),
expires_time: opts?.expires_time ? Math.floor(opts.expires_time.getTime() / 1000) : undefined
};
return request;
}
Expand Down Expand Up @@ -154,7 +166,8 @@ export type PaymentRailsChainInfo = {
export function createPayment(
sender: DID,
receiver: DID,
payments: PaymentTypeUnion[]
payments: PaymentTypeUnion[],
opts?: PaymentCreationOptions
): PaymentMessage {
const uuidv4 = uuid.v4();
const request: PaymentMessage = {
Expand All @@ -167,7 +180,8 @@ export function createPayment(
body: {
payments
},
created_time: Math.floor(Date.now() / 1000)
created_time: Math.floor(Date.now() / 1000),
expires_time: opts?.expires_time ? Math.floor(opts.expires_time.getTime() / 1000) : undefined
};
return request;
}
Expand Down

0 comments on commit 509f70a

Please sign in to comment.