From c95c0b806b53203f85742c120f2537f158503484 Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Fri, 17 Jan 2025 19:57:14 +0100 Subject: [PATCH 1/8] Support attachments in the sdk --- src/iden3comm/constants.ts | 4 +- src/iden3comm/handlers/auth.ts | 6 +- src/iden3comm/handlers/credential-proposal.ts | 36 ++++- src/iden3comm/types/index.ts | 3 +- src/iden3comm/types/packer.ts | 8 +- src/iden3comm/types/protocol/attachment.ts | 13 ++ .../types/protocol/proposal-request.ts | 3 +- .../types/protocol/transparent-payment.ts | 32 ++++ tests/iden3comm/attachment.test.ts | 138 ++++++++++++++++++ 9 files changed, 232 insertions(+), 11 deletions(-) create mode 100644 src/iden3comm/types/protocol/attachment.ts create mode 100644 src/iden3comm/types/protocol/transparent-payment.ts create mode 100644 tests/iden3comm/attachment.test.ts diff --git a/src/iden3comm/constants.ts b/src/iden3comm/constants.ts index f061f6ab..6e04b902 100644 --- a/src/iden3comm/constants.ts +++ b/src/iden3comm/constants.ts @@ -55,7 +55,9 @@ export const PROTOCOL_MESSAGE_TYPE = Object.freeze({ `${DIDCOMM_PROTOCOL}discover-features/2.0/queries` as const, // DiscoveryProtocolDiscloseMessageType is type for didcomm discovery protocol disclose DISCOVERY_PROTOCOL_DISCLOSE_MESSAGE_TYPE: - `${DIDCOMM_PROTOCOL}discover-features/2.0/disclose` as const + `${DIDCOMM_PROTOCOL}discover-features/2.0/disclose` as const, + TRANSPARENT_PAYMENT_INSTRUCTION_MESSAGE_TYPE: + `${IDEN3_PROTOCOL}credentials/0.1/transparent-payment-instruction` as const }); /** diff --git a/src/iden3comm/handlers/auth.ts b/src/iden3comm/handlers/auth.ts index beb470e2..91f16da3 100644 --- a/src/iden3comm/handlers/auth.ts +++ b/src/iden3comm/handlers/auth.ts @@ -10,7 +10,8 @@ import { IPackageManager, JWSPackerParams, ZeroKnowledgeProofRequest, - JSONObject + JSONObject, + Attachment } from '../types'; import { DID, getUnixTimestamp } from '@iden3/js-iden3-core'; import { proving } from '@iden3/js-jwz'; @@ -35,6 +36,7 @@ export type AuthorizationRequestCreateOptions = { accept?: string[]; scope?: ZeroKnowledgeProofRequest[]; expires_time?: Date; + attachments?: Attachment[]; }; /** @@ -86,6 +88,8 @@ export function createAuthorizationRequestWithMessage( created_time: getUnixTimestamp(new Date()), expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined }; + + opts?.attachments && (request.attachments = opts.attachments); return request; } diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index 82336729..0de77437 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -1,12 +1,14 @@ import { PROTOCOL_MESSAGE_TYPE, MediaType } from '../constants'; import { + Attachment, BasicMessage, CredentialOffer, CredentialsOfferMessage, DIDDocument, IPackageManager, - JsonDocumentObject, - PackerParams + PackerParams, + TransparentPaymentData, + TransparentPaymentInstructionMessage } from '../types'; import { DID, getUnixTimestamp } from '@iden3/js-iden3-core'; @@ -27,13 +29,14 @@ import { IProtocolMessageHandler } from './message-handler'; import { verifyExpiresTime } from './common'; +import { PROTOCOL_CONSTANTS } from '..'; /** @beta ProposalRequestCreationOptions represents proposal-request creation options */ export type ProposalRequestCreationOptions = { credentials: ProposalRequestCredential[]; - metadata?: { type: string; data?: JsonDocumentObject }; did_doc?: DIDDocument; expires_time?: Date; + attachments?: Attachment[]; }; /** @beta ProposalCreationOptions represents proposal creation options */ @@ -66,6 +69,7 @@ export function createProposalRequest( created_time: getUnixTimestamp(new Date()), expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined }; + opts.attachments?.length && (request.attachments = opts.attachments); return request; } @@ -155,7 +159,11 @@ export type ProposalHandlerOptions = BasicHandlerOptions & { /** @beta CredentialProposalHandlerParams represents credential proposal handler params */ export type CredentialProposalHandlerParams = { agentUrl: string; - proposalResolverFn: (context: string, type: string) => Promise; + proposalResolverFn: ( + context: string, + type: string, + opts?: { paymentInfo?: TransparentPaymentData } + ) => Promise; packerParams: PackerParams; }; @@ -233,6 +241,19 @@ export class CredentialProposalHandler let credOfferMessage: CredentialsOfferMessage | undefined = undefined; let proposalMessage: ProposalMessage | undefined = undefined; + const paymentInstructionsMessages: TransparentPaymentInstructionMessage[] = ( + proposalRequest.attachments ?? [] + ) + .flatMap((a) => a.data.json as TransparentPaymentInstructionMessage) + .filter( + (m) => + m && + m.body?.goal_code === + PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE && + m.to === proposalRequest.to && // issuer + m.body.did === proposalRequest.from // user + ); + for (let i = 0; i < proposalRequest.body.credentials.length; i++) { const cred = proposalRequest.body.credentials[i]; @@ -282,8 +303,13 @@ export class CredentialProposalHandler continue; } + const paymentInfo = paymentInstructionsMessages.find((m) => + m.body.credentials.find((c) => c.type === cred.type && c.context === cred.context) + ); // credential not found in the wallet, prepare proposal protocol message - const proposal = await this._params.proposalResolverFn(cred.context, cred.type); + const proposal = await this._params.proposalResolverFn(cred.context, cred.type, { + paymentInfo: paymentInfo?.body?.paymentData + }); if (!proposal) { throw new Error(`can't resolve Proposal for type: ${cred.type}, context: ${cred.context}`); } diff --git a/src/iden3comm/types/index.ts b/src/iden3comm/types/index.ts index b72df0ae..827ad70e 100644 --- a/src/iden3comm/types/index.ts +++ b/src/iden3comm/types/index.ts @@ -8,7 +8,8 @@ export * from './protocol/proposal-request'; export * from './protocol/payment'; export * from './protocol/accept-profile'; export * from './protocol/discovery-protocol'; - +export * from './protocol/attachment'; +export * from './protocol/transparent-payment'; export * from './packer'; export * from './models'; export * from './packageManager'; diff --git a/src/iden3comm/types/packer.ts b/src/iden3comm/types/packer.ts index aed4cd92..0db9ecf3 100644 --- a/src/iden3comm/types/packer.ts +++ b/src/iden3comm/types/packer.ts @@ -5,6 +5,7 @@ import { CircuitId } from '../../circuits'; import { MediaType, PROTOCOL_MESSAGE_TYPE } from '../constants'; import { DIDDocument, VerificationMethod } from 'did-resolver'; import { StateVerificationOpts } from './models'; +import { Attachment } from './protocol/attachment'; /** * Protocol message type @@ -51,14 +52,19 @@ export type BasicMessage = { to?: string; created_time?: number; expires_time?: number; + attachments?: Attachment[]; }; /** * Basic message with all possible fields required */ -export type RequiredBasicMessage = Omit, 'created_time' | 'expires_time'> & { +export type RequiredBasicMessage = Omit< + Required, + 'created_time' | 'expires_time' | 'attachments' +> & { created_time?: number; expires_time?: number; + attachments?: Attachment[]; }; /** diff --git a/src/iden3comm/types/protocol/attachment.ts b/src/iden3comm/types/protocol/attachment.ts new file mode 100644 index 00000000..5b418974 --- /dev/null +++ b/src/iden3comm/types/protocol/attachment.ts @@ -0,0 +1,13 @@ +import { MediaType } from '../../constants'; + +export type Attachment = { + id: string; + description?: string; + media_type: MediaType; + data: AttachData; +}; + +export type AttachData = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + json: any; +}; diff --git a/src/iden3comm/types/protocol/proposal-request.ts b/src/iden3comm/types/protocol/proposal-request.ts index fef46747..f5f7097a 100644 --- a/src/iden3comm/types/protocol/proposal-request.ts +++ b/src/iden3comm/types/protocol/proposal-request.ts @@ -1,4 +1,4 @@ -import { BasicMessage, DIDDocument, JsonDocumentObject } from '../'; +import { BasicMessage, DIDDocument } from '../'; import { PROTOCOL_MESSAGE_TYPE } from '../../constants'; /** @beta ProposalRequestMessage is struct the represents proposal-request message */ @@ -10,7 +10,6 @@ export type ProposalRequestMessage = BasicMessage & { /** @beta ProposalRequestMessageBody is struct the represents body for proposal-request */ export type ProposalRequestMessageBody = { credentials: ProposalRequestCredential[]; - metadata?: { type: string; data?: JsonDocumentObject }; did_doc?: DIDDocument; }; diff --git a/src/iden3comm/types/protocol/transparent-payment.ts b/src/iden3comm/types/protocol/transparent-payment.ts new file mode 100644 index 00000000..83204a6d --- /dev/null +++ b/src/iden3comm/types/protocol/transparent-payment.ts @@ -0,0 +1,32 @@ +// package protocol + +import { PROTOCOL_MESSAGE_TYPE } from '../../constants'; +import { RequiredBasicMessage } from '../packer'; + +export type TransparentPaymentInstructionMessage = RequiredBasicMessage & { + body: TransparentPaymentInstructionMessageBody; + type: typeof PROTOCOL_MESSAGE_TYPE.TRANSPARENT_PAYMENT_INSTRUCTION_MESSAGE_TYPE; +}; + +export type TransparentPaymentInstructionMessageBody = { + goal_code: string; + did?: string; + credentials: TransparentCredential[]; + paymentData: TransparentPaymentData; +}; + +export type TransparentCredential = { + context: string; + type: string; +}; + +export type TransparentPaymentData = { + type: string; + signature: string; + recipient: string; + amount: string; + token?: string; + expiration: number; + nonce: number; + metadata?: string; +}; diff --git a/tests/iden3comm/attachment.test.ts b/tests/iden3comm/attachment.test.ts new file mode 100644 index 00000000..d6cbdcd2 --- /dev/null +++ b/tests/iden3comm/attachment.test.ts @@ -0,0 +1,138 @@ +import { + Attachment, + AuthorizationRequestMessage, + byteEncoder, + createAuthorizationRequest, + createProposalRequest, + CredentialProposalHandler, + ICredentialWallet, + IDataStorage, + IdentityWallet, + IPackageManager, + KMS, + Proposal, + ProposalRequestMessage, + TransparentPaymentData, + TransparentPaymentInstructionMessage +} from '../../src'; +import * as uuid from 'uuid'; +import { getRandomBytes } from '@iden3/js-crypto'; +import { Blockchain, buildDIDType, DID, DidMethod, Id, NetworkId } from '@iden3/js-iden3-core'; +import { MediaType, PROTOCOL_MESSAGE_TYPE } from '../../src/iden3comm/constants'; +import { expect } from 'chai'; + +describe('Attachments', () => { + const didType = buildDIDType(DidMethod.Iden3, Blockchain.Polygon, NetworkId.Amoy); + + const cred = { + context: 'https://schema.iden3.io/transparent-payment/1.0.0/schema.json', + type: 'TransparentCredential' + }; + + const paymentData = { + type: 'TransparentPaymentData', + signature: '0x0000000000000000000000000000000000000000000000000000000000000000', + recipient: '0x0000000000000000000000000000000000000000', + amount: '100', + token: 'USDT', + expiration: 1716153600, + nonce: 1, + metadata: '0x' + }; + + const [verifierDid, userDid, issuerDid] = [ + getRandomBytes(27), + getRandomBytes(27), + getRandomBytes(27) + ].map((seed) => DID.parseFromId(new Id(didType, seed)).string()); + + const verifierFlow = () => { + const id = uuid.v4(); + const transparentPaymentInstructionMessage: TransparentPaymentInstructionMessage = { + id, + thid: id, + from: verifierDid, + to: issuerDid, + typ: MediaType.PlainMessage, + type: PROTOCOL_MESSAGE_TYPE.TRANSPARENT_PAYMENT_INSTRUCTION_MESSAGE_TYPE, + body: { + goal_code: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE, + did: userDid, + credentials: [cred], + paymentData + } + }; + + const attachment: Attachment = { + id: id, + media_type: MediaType.PlainMessage, + data: { + json: transparentPaymentInstructionMessage + } + }; + // verifier creates auth request with attachment + const authRequest = createAuthorizationRequest( + 'transparent payment', + verifierDid, + 'http://verifier.com/callback', + { + attachments: [attachment] + } + ); + + return authRequest; + }; + + const userFlow = (authRequest: AuthorizationRequestMessage): ProposalRequestMessage => { + // checks no credential + // creates cred proposal request + return createProposalRequest(DID.parse(userDid), DID.parse(issuerDid), { + credentials: [cred], + attachments: authRequest.attachments + }); + }; + + const issuerFlow = async (proposalRequest: ProposalRequestMessage) => { + const credentialProposalHandler = new CredentialProposalHandler( + { + pack: () => null, + unpack: () => ({ unpackedMessage: proposalRequest }) + } as unknown as IPackageManager, + new IdentityWallet( + new KMS(), + { + states: { + getRpcProvider: () => null + } + } as unknown as IDataStorage, + { + findByQuery: () => Promise.reject(new Error('no credential satisfied query')) + } as unknown as ICredentialWallet + ), + { + agentUrl: 'http://issuer.com', + packerParams: {}, + proposalResolverFn: ( + context: string, + type: string, + opts: { paymentInfo?: TransparentPaymentData } | undefined + ) => { + expect(opts?.paymentInfo).to.be.deep.equal(paymentData); + + return Promise.resolve({} as Proposal); + } + } + ); + + return credentialProposalHandler.handleProposalRequest( + byteEncoder.encode(JSON.stringify(proposalRequest)), + {} + ); + }; + + it('verifier transparent payment instruction flow', async () => { + const authRequest = verifierFlow(); + const proposalRequest = userFlow(authRequest); + await issuerFlow(proposalRequest); + }); +}); From 325567cd0108ae3ee41a27e9c9c3b8dfd5d40be8 Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Fri, 17 Jan 2025 19:58:50 +0100 Subject: [PATCH 2/8] 1.28.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 921b326b..ef67dccc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.27.0", + "version": "1.28.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.27.0", + "version": "1.28.0", "license": "MIT or Apache-2.0", "dependencies": { "@iden3/onchain-non-merklized-issuer-base-abi": "^0.0.3", diff --git a/package.json b/package.json index 1bca6729..094a1d8e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.27.0", + "version": "1.28.0", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", From 765da648319a6a6d9db864da26ed0f764c3056d1 Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Fri, 17 Jan 2025 20:01:53 +0100 Subject: [PATCH 3/8] Fix import --- src/iden3comm/handlers/credential-proposal.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index 0de77437..58c877ce 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -29,8 +29,6 @@ import { IProtocolMessageHandler } from './message-handler'; import { verifyExpiresTime } from './common'; -import { PROTOCOL_CONSTANTS } from '..'; - /** @beta ProposalRequestCreationOptions represents proposal-request creation options */ export type ProposalRequestCreationOptions = { credentials: ProposalRequestCredential[]; @@ -248,8 +246,7 @@ export class CredentialProposalHandler .filter( (m) => m && - m.body?.goal_code === - PROTOCOL_CONSTANTS.PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE && + m.body?.goal_code === PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE && m.to === proposalRequest.to && // issuer m.body.did === proposalRequest.from // user ); From d54ee3c2db1cbd84282f62cbbddef4465460bb60 Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Thu, 23 Jan 2025 10:25:17 +0100 Subject: [PATCH 4/8] FIx comments --- src/iden3comm/handlers/auth.ts | 5 ++- src/iden3comm/handlers/credential-proposal.ts | 11 ++++--- src/iden3comm/types/index.ts | 1 + src/iden3comm/types/protocol/common.ts | 31 +++++++++++++++++++ src/iden3comm/types/protocol/payment.ts | 6 ++-- .../types/protocol/proposal-request.ts | 11 ++----- .../types/protocol/transparent-payment.ts | 12 +++---- tests/iden3comm/attachment.test.ts | 5 +-- 8 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 src/iden3comm/types/protocol/common.ts diff --git a/src/iden3comm/handlers/auth.ts b/src/iden3comm/handlers/auth.ts index 91f16da3..379ffe18 100644 --- a/src/iden3comm/handlers/auth.ts +++ b/src/iden3comm/handlers/auth.ts @@ -86,10 +86,9 @@ export function createAuthorizationRequestWithMessage( scope: opts?.scope ?? [] }, created_time: getUnixTimestamp(new Date()), - expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined + expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined, + attachments: opts?.attachments }; - - opts?.attachments && (request.attachments = opts.attachments); return request; } diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index 58c877ce..af329df2 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -16,7 +16,6 @@ import * as uuid from 'uuid'; import { proving } from '@iden3/js-jwz'; import { Proposal, - ProposalRequestCredential, ProposalRequestMessage, ProposalMessage } from '../types/protocol/proposal-request'; @@ -29,9 +28,11 @@ import { IProtocolMessageHandler } from './message-handler'; import { verifyExpiresTime } from './common'; +import { CredentialSchemaInfo, getProtocolMessageTypeByGoalCode } from '../types/protocol/common'; + /** @beta ProposalRequestCreationOptions represents proposal-request creation options */ export type ProposalRequestCreationOptions = { - credentials: ProposalRequestCredential[]; + credentials: CredentialSchemaInfo[]; did_doc?: DIDDocument; expires_time?: Date; attachments?: Attachment[]; @@ -246,9 +247,11 @@ export class CredentialProposalHandler .filter( (m) => m && - m.body?.goal_code === PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE && + m.body?.goal_code && + getProtocolMessageTypeByGoalCode(m.body.goal_code) === + PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE && m.to === proposalRequest.to && // issuer - m.body.did === proposalRequest.from // user + (!m.body.paymentReference || m.body.paymentReference === proposalRequest.from) // user ); for (let i = 0; i < proposalRequest.body.credentials.length; i++) { diff --git a/src/iden3comm/types/index.ts b/src/iden3comm/types/index.ts index 827ad70e..b1538348 100644 --- a/src/iden3comm/types/index.ts +++ b/src/iden3comm/types/index.ts @@ -10,6 +10,7 @@ export * from './protocol/accept-profile'; export * from './protocol/discovery-protocol'; export * from './protocol/attachment'; export * from './protocol/transparent-payment'; +export * from './protocol/common'; export * from './packer'; export * from './models'; export * from './packageManager'; diff --git a/src/iden3comm/types/protocol/common.ts b/src/iden3comm/types/protocol/common.ts new file mode 100644 index 00000000..20ef7f52 --- /dev/null +++ b/src/iden3comm/types/protocol/common.ts @@ -0,0 +1,31 @@ +import { PROTOCOL_MESSAGE_TYPE } from '../../constants'; + +/** + * Represents information about a credential schema. + * + * @property {string} type - The type of the credential schema. + * @property {string} context - The context in which the credential schema is used. + */ +export type CredentialSchemaInfo = { + type: string; + context: string; +}; + +/** + * Enum representing the goal codes used in the iden3 communication protocol. + * + * @enum {string} + * @property {string} ProposalRequest - Represents a proposal request in the iden3 communication protocol. + */ +export enum GoalCode { + ProposalRequest = 'iden3comm.credentials.v1-1.proposal-request' +} + +export const getProtocolMessageTypeByGoalCode = (goalCode: GoalCode) => { + switch (goalCode) { + case GoalCode.ProposalRequest: + return PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE; + default: + throw new Error(`Unknown goal code ${goalCode}`); + } +}; diff --git a/src/iden3comm/types/protocol/payment.ts b/src/iden3comm/types/protocol/payment.ts index 96adb5a1..7718c335 100644 --- a/src/iden3comm/types/protocol/payment.ts +++ b/src/iden3comm/types/protocol/payment.ts @@ -6,6 +6,7 @@ import { SupportedPaymentProofType } from '../../../verifiable'; import { PROTOCOL_MESSAGE_TYPE } from '../../constants'; +import { CredentialSchemaInfo } from './common'; /** @beta PaymentRequestMessage is struct the represents payment-request message */ export type PaymentRequestMessage = BasicMessage & { @@ -21,10 +22,7 @@ export type PaymentRequestMessageBody = { /** @beta PaymentRequestInfo is struct the represents payment info for payment-request */ export type PaymentRequestInfo = { - credentials: { - type: string; - context: string; - }[]; + credentials: CredentialSchemaInfo[]; data: | Iden3PaymentRequestCryptoV1 | ( diff --git a/src/iden3comm/types/protocol/proposal-request.ts b/src/iden3comm/types/protocol/proposal-request.ts index f5f7097a..2a8c72e7 100644 --- a/src/iden3comm/types/protocol/proposal-request.ts +++ b/src/iden3comm/types/protocol/proposal-request.ts @@ -1,5 +1,6 @@ import { BasicMessage, DIDDocument } from '../'; import { PROTOCOL_MESSAGE_TYPE } from '../../constants'; +import { CredentialSchemaInfo } from './common'; /** @beta ProposalRequestMessage is struct the represents proposal-request message */ export type ProposalRequestMessage = BasicMessage & { @@ -9,7 +10,7 @@ export type ProposalRequestMessage = BasicMessage & { /** @beta ProposalRequestMessageBody is struct the represents body for proposal-request */ export type ProposalRequestMessageBody = { - credentials: ProposalRequestCredential[]; + credentials: CredentialSchemaInfo[]; did_doc?: DIDDocument; }; @@ -24,15 +25,9 @@ export type ProposalMessageBody = { proposals: Proposal[]; }; -/** @beta ProposalRequestCredential is struct the represents proposal request credential */ -export type ProposalRequestCredential = { - type: string; - context: string; -}; - /** @beta Proposal is struct the represents proposal inside proposal protocol message */ export type Proposal = { - credentials: ProposalRequestCredential[]; + credentials: CredentialSchemaInfo[]; type: string; url?: string; expiration?: string; diff --git a/src/iden3comm/types/protocol/transparent-payment.ts b/src/iden3comm/types/protocol/transparent-payment.ts index 83204a6d..b8fb0af1 100644 --- a/src/iden3comm/types/protocol/transparent-payment.ts +++ b/src/iden3comm/types/protocol/transparent-payment.ts @@ -2,6 +2,7 @@ import { PROTOCOL_MESSAGE_TYPE } from '../../constants'; import { RequiredBasicMessage } from '../packer'; +import { CredentialSchemaInfo, GoalCode } from './common'; export type TransparentPaymentInstructionMessage = RequiredBasicMessage & { body: TransparentPaymentInstructionMessageBody; @@ -9,17 +10,12 @@ export type TransparentPaymentInstructionMessage = RequiredBasicMessage & { }; export type TransparentPaymentInstructionMessageBody = { - goal_code: string; - did?: string; - credentials: TransparentCredential[]; + goal_code: GoalCode; + paymentReference?: string; + credentials: CredentialSchemaInfo[]; paymentData: TransparentPaymentData; }; -export type TransparentCredential = { - context: string; - type: string; -}; - export type TransparentPaymentData = { type: string; signature: string; diff --git a/tests/iden3comm/attachment.test.ts b/tests/iden3comm/attachment.test.ts index d6cbdcd2..7e017f55 100644 --- a/tests/iden3comm/attachment.test.ts +++ b/tests/iden3comm/attachment.test.ts @@ -5,6 +5,7 @@ import { createAuthorizationRequest, createProposalRequest, CredentialProposalHandler, + GoalCode, ICredentialWallet, IDataStorage, IdentityWallet, @@ -56,8 +57,8 @@ describe('Attachments', () => { typ: MediaType.PlainMessage, type: PROTOCOL_MESSAGE_TYPE.TRANSPARENT_PAYMENT_INSTRUCTION_MESSAGE_TYPE, body: { - goal_code: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE, - did: userDid, + goal_code: GoalCode.ProposalRequest, + paymentReference: userDid, credentials: [cred], paymentData } From facc33b4737d2bd4079082d8503005a9fdb58fbd Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Thu, 23 Jan 2025 11:33:07 +0100 Subject: [PATCH 5/8] Fix prettier --- src/iden3comm/types/protocol/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iden3comm/types/protocol/common.ts b/src/iden3comm/types/protocol/common.ts index 20ef7f52..de2c1481 100644 --- a/src/iden3comm/types/protocol/common.ts +++ b/src/iden3comm/types/protocol/common.ts @@ -13,7 +13,7 @@ export type CredentialSchemaInfo = { /** * Enum representing the goal codes used in the iden3 communication protocol. - * + * * @enum {string} * @property {string} ProposalRequest - Represents a proposal request in the iden3 communication protocol. */ From c64d7bc956fa84db2e69b8d095ef359d1e47a810 Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Thu, 23 Jan 2025 13:05:16 +0100 Subject: [PATCH 6/8] Fix ProposalRequestCredential --- src/iden3comm/handlers/credential-proposal.ts | 7 ++++--- src/iden3comm/types/protocol/proposal-request.ts | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index af329df2..cd745c3f 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -17,7 +17,8 @@ import { proving } from '@iden3/js-jwz'; import { Proposal, ProposalRequestMessage, - ProposalMessage + ProposalMessage, + ProposalRequestCredential } from '../types/protocol/proposal-request'; import { IIdentityWallet } from '../../identity'; import { byteEncoder } from '../../utils'; @@ -28,11 +29,11 @@ import { IProtocolMessageHandler } from './message-handler'; import { verifyExpiresTime } from './common'; -import { CredentialSchemaInfo, getProtocolMessageTypeByGoalCode } from '../types/protocol/common'; +import { getProtocolMessageTypeByGoalCode } from '../types/protocol/common'; /** @beta ProposalRequestCreationOptions represents proposal-request creation options */ export type ProposalRequestCreationOptions = { - credentials: CredentialSchemaInfo[]; + credentials: ProposalRequestCredential[]; did_doc?: DIDDocument; expires_time?: Date; attachments?: Attachment[]; diff --git a/src/iden3comm/types/protocol/proposal-request.ts b/src/iden3comm/types/protocol/proposal-request.ts index 2a8c72e7..1a096d94 100644 --- a/src/iden3comm/types/protocol/proposal-request.ts +++ b/src/iden3comm/types/protocol/proposal-request.ts @@ -8,9 +8,12 @@ export type ProposalRequestMessage = BasicMessage & { type: typeof PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE; }; +/** @beta ProposalRequestCredential is struct the represents proposal request credential */ +export type ProposalRequestCredential = CredentialSchemaInfo; + /** @beta ProposalRequestMessageBody is struct the represents body for proposal-request */ export type ProposalRequestMessageBody = { - credentials: CredentialSchemaInfo[]; + credentials: ProposalRequestCredential[]; did_doc?: DIDDocument; }; @@ -27,7 +30,7 @@ export type ProposalMessageBody = { /** @beta Proposal is struct the represents proposal inside proposal protocol message */ export type Proposal = { - credentials: CredentialSchemaInfo[]; + credentials: ProposalRequestCredential[]; type: string; url?: string; expiration?: string; From f4c864fc0a2f203851b65cb7fcf5b2c166fabac3 Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Thu, 23 Jan 2025 13:22:13 +0100 Subject: [PATCH 7/8] Fix any --- src/iden3comm/types/protocol/attachment.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iden3comm/types/protocol/attachment.ts b/src/iden3comm/types/protocol/attachment.ts index 5b418974..4fb4dde4 100644 --- a/src/iden3comm/types/protocol/attachment.ts +++ b/src/iden3comm/types/protocol/attachment.ts @@ -1,4 +1,5 @@ import { MediaType } from '../../constants'; +import { JsonDocumentObject } from '../packer'; export type Attachment = { id: string; @@ -8,6 +9,5 @@ export type Attachment = { }; export type AttachData = { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - json: any; + json: JsonDocumentObject; }; From a95be40514be8b7586d4ff75abdddd33f4b5bd3b Mon Sep 17 00:00:00 2001 From: Kolezhniuk Date: Wed, 29 Jan 2025 15:15:32 +0100 Subject: [PATCH 8/8] Fix comment --- src/iden3comm/handlers/credential-proposal.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/iden3comm/handlers/credential-proposal.ts b/src/iden3comm/handlers/credential-proposal.ts index cd745c3f..6670190b 100644 --- a/src/iden3comm/handlers/credential-proposal.ts +++ b/src/iden3comm/handlers/credential-proposal.ts @@ -67,9 +67,9 @@ export function createProposalRequest( type: PROTOCOL_MESSAGE_TYPE.PROPOSAL_REQUEST_MESSAGE_TYPE, body: opts, created_time: getUnixTimestamp(new Date()), - expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined + expires_time: opts?.expires_time ? getUnixTimestamp(opts.expires_time) : undefined, + attachments: opts.attachments }; - opts.attachments?.length && (request.attachments = opts.attachments); return request; }