@msssystems/mss-link-sdk 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import type { DriveItemType, DriveWrappedItemKey } from './drive-sharing.contracts';
2
2
  export type DriveRecipientPublicKeyAlgorithm = 'X25519';
3
3
  export type DriveWrappedItemKeyAlgorithm = 'MSS-DRIVE-PUBLIC-KEY-WRAPPED-ITEM-KEY-v1';
4
+ export type DriveItemKeyMaterialKind = 'content-key' | 'folder-metadata-envelope';
4
5
  export interface DriveRecipientPublicKey {
5
6
  algorithm: DriveRecipientPublicKeyAlgorithm;
6
7
  keyId: string;
@@ -14,6 +15,7 @@ export interface DriveRecipientKeyTarget {
14
15
  }
15
16
  export interface DriveItemContentKeyEnvelope {
16
17
  algorithm?: 'AES-256-GCM' | string | null;
18
+ keyMaterialKind?: DriveItemKeyMaterialKind | string | null;
17
19
  keyId?: string | null;
18
20
  nonce?: string | null;
19
21
  wrappedKey: string;
@@ -39,10 +41,20 @@ export interface CreateDriveWrappedItemKeyForRecipientInput {
39
41
  recipient: DriveRecipientKeyTarget;
40
42
  wrappingAdapter: DrivePublicKeyWrappingAdapter;
41
43
  }
44
+ export interface CreateDriveWrappedFolderKeyForRecipientInput {
45
+ encryptedFolderMetadata: {
46
+ encryptedName: string;
47
+ schema?: 'mss.link.drive-folder-metadata.v1' | string;
48
+ };
49
+ folderId: string;
50
+ recipient: DriveRecipientKeyTarget;
51
+ wrappingAdapter: DrivePublicKeyWrappingAdapter;
52
+ }
42
53
  export interface DriveWrappedItemKeyPayload {
43
54
  contentAlgorithm: string;
44
55
  contentKey: string;
45
56
  contentKeyId?: string;
57
+ contentKeyMaterialKind: DriveItemKeyMaterialKind;
46
58
  contentNonce?: string;
47
59
  createdAt: string;
48
60
  itemId: string;
@@ -1,2 +1,3 @@
1
- import type { CreateDriveWrappedItemKeyForRecipientInput, DriveWrappedItemKeyForRecipientResult } from './drive-key-wrapping.contracts';
1
+ import type { CreateDriveWrappedFolderKeyForRecipientInput, CreateDriveWrappedItemKeyForRecipientInput, DriveWrappedItemKeyForRecipientResult } from './drive-key-wrapping.contracts';
2
2
  export declare function createDriveWrappedItemKeyForRecipient(input: CreateDriveWrappedItemKeyForRecipientInput): Promise<DriveWrappedItemKeyForRecipientResult>;
3
+ export declare function createDriveWrappedFolderKeyForRecipient(input: CreateDriveWrappedFolderKeyForRecipientInput): Promise<DriveWrappedItemKeyForRecipientResult>;
@@ -1,5 +1,7 @@
1
+ import { normalizeEncryptedDriveFolderMetadataInput } from './storage-metadata-crypto';
1
2
  const CONTENT_KEY_SCHEMA = 'mss.link.drive.item-key.v1';
2
3
  const WRAPPED_ITEM_KEY_ALGORITHM = 'MSS-DRIVE-PUBLIC-KEY-WRAPPED-ITEM-KEY-v1';
4
+ const FOLDER_METADATA_KEY_ID_PREFIX = 'drive-folder-metadata';
3
5
  export async function createDriveWrappedItemKeyForRecipient(input) {
4
6
  const itemId = normalizeRequiredText(input.itemId, 'Drive item id is required for key wrapping.');
5
7
  const itemType = input.itemType;
@@ -29,6 +31,24 @@ export async function createDriveWrappedItemKeyForRecipient(input) {
29
31
  }),
30
32
  };
31
33
  }
34
+ export function createDriveWrappedFolderKeyForRecipient(input) {
35
+ const folderId = normalizeRequiredText(input.folderId, 'Drive folder id is required for key wrapping.');
36
+ const metadata = normalizeEncryptedDriveFolderMetadataInput({
37
+ encryptedName: input.encryptedFolderMetadata.encryptedName,
38
+ });
39
+ return createDriveWrappedItemKeyForRecipient({
40
+ contentKey: {
41
+ algorithm: 'AES-256-GCM',
42
+ keyId: `${FOLDER_METADATA_KEY_ID_PREFIX}:${folderId}`,
43
+ keyMaterialKind: 'folder-metadata-envelope',
44
+ wrappedKey: metadata.encryptedName,
45
+ },
46
+ itemId: folderId,
47
+ itemType: 'folder',
48
+ recipient: input.recipient,
49
+ wrappingAdapter: input.wrappingAdapter,
50
+ });
51
+ }
32
52
  function buildWrappedItemKeyPayload({ contentKey, itemId, itemType, }) {
33
53
  return {
34
54
  schema: CONTENT_KEY_SCHEMA,
@@ -36,6 +56,7 @@ function buildWrappedItemKeyPayload({ contentKey, itemId, itemType, }) {
36
56
  itemType,
37
57
  contentAlgorithm: contentKey.algorithm,
38
58
  contentKey: contentKey.wrappedKey,
59
+ contentKeyMaterialKind: contentKey.keyMaterialKind,
39
60
  createdAt: new Date().toISOString(),
40
61
  ...(contentKey.keyId ? { contentKeyId: contentKey.keyId } : {}),
41
62
  ...(contentKey.nonce ? { contentNonce: contentKey.nonce } : {}),
@@ -74,10 +95,19 @@ function normalizeContentKey(contentKey) {
74
95
  return {
75
96
  algorithm,
76
97
  keyId: normalizeOptionalText(contentKey.keyId) ?? '',
98
+ keyMaterialKind: normalizeKeyMaterialKind(contentKey.keyMaterialKind),
77
99
  nonce: normalizeOptionalText(contentKey.nonce) ?? '',
78
100
  wrappedKey: normalizeRequiredText(contentKey.wrappedKey, 'Drive item content key is required.'),
79
101
  };
80
102
  }
103
+ function normalizeKeyMaterialKind(kind) {
104
+ const normalized = normalizeOptionalText(kind) ?? 'content-key';
105
+ if (normalized !== 'content-key' &&
106
+ normalized !== 'folder-metadata-envelope') {
107
+ throw new Error(`Unsupported Drive item key material kind: ${normalized}`);
108
+ }
109
+ return normalized;
110
+ }
81
111
  function normalizeWrappingAdapter(adapter) {
82
112
  if (!adapter || typeof adapter.wrapDriveItemKey !== 'function') {
83
113
  throw new Error('Drive public-key wrapping adapter is not configured.');
@@ -4,7 +4,7 @@ import type { DecryptMediaBlobInput, DecryptedMediaBlobResult, EncryptedMediaBlo
4
4
  import type { SendMediaMessageParams } from './media-message.contracts';
5
5
  import type { DecryptedMessage } from './message.contracts';
6
6
  import type { DecryptDriveFileMetadataInput, DecryptDriveFolderMetadataInput, DecryptedDriveFileMetadata, DecryptedDriveFolderMetadata, EncryptedDriveFileMetadata, EncryptedDriveFolderMetadata, EncryptDriveFileMetadataInput, EncryptDriveFolderMetadataInput } from './storage-metadata-crypto.contracts';
7
- import type { CreateDriveWrappedItemKeyForRecipientInput, DriveWrappedItemKeyForRecipientResult } from './drive-key-wrapping.contracts';
7
+ import type { CreateDriveWrappedFolderKeyForRecipientInput, CreateDriveWrappedItemKeyForRecipientInput, DriveWrappedItemKeyForRecipientResult } from './drive-key-wrapping.contracts';
8
8
  export declare class MssLinkBrowserClient {
9
9
  private readonly userId;
10
10
  private readonly apiBaseUrl;
@@ -36,6 +36,7 @@ export declare class MssLinkBrowserClient {
36
36
  encryptDriveFileMetadata(input: EncryptDriveFileMetadataInput): Promise<EncryptedDriveFileMetadata>;
37
37
  decryptDriveFileMetadata(input: DecryptDriveFileMetadataInput): Promise<DecryptedDriveFileMetadata>;
38
38
  createDriveWrappedItemKeyForRecipient(input: CreateDriveWrappedItemKeyForRecipientInput): Promise<DriveWrappedItemKeyForRecipientResult>;
39
+ createDriveWrappedFolderKeyForRecipient(input: CreateDriveWrappedFolderKeyForRecipientInput): Promise<DriveWrappedItemKeyForRecipientResult>;
39
40
  syncMessages(): Promise<void>;
40
41
  getLocalMessages(chatId: string): Promise<DecryptedMessage[]>;
41
42
  reset(): void;
@@ -4,7 +4,7 @@ import { checkLocalCryptoHealth } from './local-crypto-health';
4
4
  import { buildMediaMessageMetadataPayload, extractMediaAssetIds, serializeMediaMessageMetadata, } from './media-message-metadata';
5
5
  import { mapLocalSdkMessage } from './message.mapper';
6
6
  import { buildDecryptedDriveFileMetadata, buildDecryptedDriveFolderMetadata, buildEncryptedDriveFileMetadata, buildEncryptedDriveFolderMetadata, normalizeDriveFileMetadataInput, normalizeDriveFolderMetadataInput, normalizeEncryptedDriveFileMetadataInput, normalizeEncryptedDriveFolderMetadataInput, } from './storage-metadata-crypto';
7
- import { createDriveWrappedItemKeyForRecipient } from './drive-key-wrapping';
7
+ import { createDriveWrappedFolderKeyForRecipient, createDriveWrappedItemKeyForRecipient, } from './drive-key-wrapping';
8
8
  import { WasmCallQueue } from './wasm-call-queue';
9
9
  const DEFAULT_DEVICE_ID = 1;
10
10
  const DEFAULT_REGISTRATION_ID = 1;
@@ -213,6 +213,9 @@ export class MssLinkBrowserClient {
213
213
  createDriveWrappedItemKeyForRecipient(input) {
214
214
  return createDriveWrappedItemKeyForRecipient(input);
215
215
  }
216
+ createDriveWrappedFolderKeyForRecipient(input) {
217
+ return createDriveWrappedFolderKeyForRecipient(input);
218
+ }
216
219
  async syncMessages() {
217
220
  try {
218
221
  await this.runWithClient((client) => client.syncMessages());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@msssystems/mss-link-sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "Official managed application SDK for MSS ecosystem",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",