diff --git a/src/iden3comm/handlers/auth.ts b/src/iden3comm/handlers/auth.ts index d0939f4a..2d845e11 100644 --- a/src/iden3comm/handlers/auth.ts +++ b/src/iden3comm/handlers/auth.ts @@ -30,6 +30,7 @@ import { parseAcceptProfile } from '../utils'; export type AuthorizationRequestCreateOptions = { accept?: string[]; scope?: ZeroKnowledgeProofRequest[]; + expires_time?: Date; }; /** @@ -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; } diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index fb5d1898..4e914f66 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -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; }; /** @@ -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; } @@ -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 = { @@ -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; } diff --git a/src/iden3comm/handlers/payment.ts b/src/iden3comm/handlers/payment.ts index 35ef109f..df860b83 100644 --- a/src/iden3comm/handlers/payment.ts +++ b/src/iden3comm/handlers/payment.ts @@ -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 @@ -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 = { @@ -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; } @@ -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 = { @@ -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; }