|
9 | 9 | parseAcceptProfile
|
10 | 10 | } from '../accept-profiles';
|
11 | 11 | import { PROTOCOL_MESSAGE_TYPE } from '../constants';
|
| 12 | +import { IIdentityWallet } from '../../identity'; |
| 13 | +import { DID } from '@iden3/js-iden3-core'; |
12 | 14 |
|
13 | 15 | /**
|
14 | 16 | * @beta
|
@@ -57,7 +59,8 @@ export type InvitationHandlerParams = {
|
57 | 59 |
|
58 | 60 | /** @beta InvitationHandlerOptions represents invitation handler options */
|
59 | 61 | export type InvitationHandlerOptions = {
|
60 |
| - useProfile?: boolean; |
| 62 | + profileNonce?: number; |
| 63 | + senderDid: DID; |
61 | 64 | };
|
62 | 65 |
|
63 | 66 | /** @beta AcceptOptions represents invitation handler accept options */
|
@@ -101,6 +104,7 @@ export class InvitationHandler
|
101 | 104 | *
|
102 | 105 | */
|
103 | 106 | constructor(
|
| 107 | + private readonly _identityWallet: IIdentityWallet, |
104 | 108 | private readonly _packerMgr: IPackageManager,
|
105 | 109 | private readonly _params: InvitationHandlerParams
|
106 | 110 | ) {
|
@@ -129,7 +133,18 @@ export class InvitationHandler
|
129 | 133 | if (!this.isSupportAcceptProfile(invitationMessage.body.accept)) {
|
130 | 134 | throw new Error('accept profile not supported');
|
131 | 135 | }
|
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 | + } |
133 | 148 | const iden3message = invitationMessage.attachments[0].data.json;
|
134 | 149 | return super.handle(iden3message, context as { [key: string]: unknown });
|
135 | 150 | }
|
|
0 commit comments