Skip to content

Commit ba1ec24

Browse files
support profiles in invitation
1 parent b6cd45c commit ba1ec24

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/iden3comm/handlers/invintation.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
parseAcceptProfile
1010
} from '../accept-profiles';
1111
import { PROTOCOL_MESSAGE_TYPE } from '../constants';
12+
import { IIdentityWallet } from '../../identity';
13+
import { DID } from '@iden3/js-iden3-core';
1214

1315
/**
1416
* @beta
@@ -57,7 +59,8 @@ export type InvitationHandlerParams = {
5759

5860
/** @beta InvitationHandlerOptions represents invitation handler options */
5961
export type InvitationHandlerOptions = {
60-
useProfile?: boolean;
62+
profileNonce?: number;
63+
senderDid: DID;
6164
};
6265

6366
/** @beta AcceptOptions represents invitation handler accept options */
@@ -101,6 +104,7 @@ export class InvitationHandler
101104
*
102105
*/
103106
constructor(
107+
private readonly _identityWallet: IIdentityWallet,
104108
private readonly _packerMgr: IPackageManager,
105109
private readonly _params: InvitationHandlerParams
106110
) {
@@ -129,7 +133,18 @@ export class InvitationHandler
129133
if (!this.isSupportAcceptProfile(invitationMessage.body.accept)) {
130134
throw new Error('accept profile not supported');
131135
}
132-
// TODO: support profile
136+
if (context.profileNonce) {
137+
const authProfile = (await this._identityWallet.getProfilesByDID(context.senderDid)).find(
138+
(i) => i.verifier === invitationMessage.from
139+
);
140+
context.senderDid = authProfile
141+
? DID.parse(authProfile.id)
142+
: await this._identityWallet.createProfile(
143+
context.senderDid,
144+
context.profileNonce,
145+
invitationMessage.from
146+
);
147+
}
133148
const iden3message = invitationMessage.attachments[0].data.json;
134149
return super.handle(iden3message, context as { [key: string]: unknown });
135150
}

src/iden3comm/handlers/message-handler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { PaymentHandlerOptions, PaymentRequestMessageHandlerOptions } from './pa
66
import { MediaType } from '../constants';
77
import { proving } from '@iden3/js-jwz';
88
import { DID } from '@iden3/js-iden3-core';
9+
import { InvitationHandlerOptions } from './invintation';
910
/**
1011
* iden3 Protocol message handler interface
1112
*/
@@ -123,6 +124,7 @@ export class MessageHandler {
123124
| RevocationStatusMessageHandlerOptions
124125
| PaymentRequestMessageHandlerOptions
125126
| PaymentHandlerOptions
127+
| InvitationHandlerOptions
126128
| { senderDid?: DID; [key: string]: unknown }
127129
): Promise<Uint8Array | null> {
128130
const { unpackedMediaType, unpackedMessage: message } =

0 commit comments

Comments
 (0)