1 import { PassCrypto } from '@proton/pass/lib/crypto';
2 import { getAllShareKeys, getShareLatestEventId } from '@proton/pass/lib/shares/share.requests';
3 import { decodeVaultContent } from '@proton/pass/lib/vaults/vault-proto.transformer';
4 import type { Maybe, Share, ShareGetResponse, ShareKeyResponse, ShareType } from '@proton/pass/types';
6 export const parseShareResponse = async (
7 encryptedShare: ShareGetResponse,
8 options?: { eventId?: string; shareKeys?: ShareKeyResponse[] }
9 ): Promise<Maybe<Share<ShareType.Vault>>> => {
10 const shareId = encryptedShare.ShareID;
11 const [shareKeys, eventId] = await Promise.all([
12 options?.shareKeys ?? getAllShareKeys(shareId),
13 options?.eventId ?? getShareLatestEventId(shareId),
16 const share = await PassCrypto.openShare<ShareType.Vault>({ encryptedShare, shareKeys });
20 content: decodeVaultContent(share.content),
21 createTime: share.createTime,
23 newUserInvitesReady: share.newUserInvitesReady,
26 shareId: share.shareId,
27 shareRoleId: share.shareRoleId,
28 targetId: share.targetId,
29 targetMembers: share.targetMembers,
30 targetMaxMembers: share.targetMaxMembers,
31 targetType: share.targetType,
32 vaultId: share.vaultId,