@internxt/sdk 1.17.7 → 1.17.9

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.
@@ -21,14 +21,15 @@ async function downloadFile(fileId, bucketId, mnemonic, network, crypto, toBinar
21
21
  throw new errors_1.DownloadInvalidMnemonicError();
22
22
  }
23
23
  }
24
- const { index, shards, version, size } = await network.getDownloadLinks(bucketId, fileId, opts?.token);
24
+ const fileInfo = await network.getDownloadLinks(bucketId, fileId, opts?.token);
25
+ const { index, shards, version, size } = fileInfo;
25
26
  if (!version || version === 1) {
26
27
  throw new FileVersionOneError();
27
28
  }
28
29
  iv = toBinaryData(index, types_1.BinaryDataEncoding.HEX).slice(0, 16);
29
30
  key = await crypto.generateFileKey(mnemonic, bucketId, toBinaryData(index, types_1.BinaryDataEncoding.HEX));
30
31
  const downloadables = shards.sort((sA, sB) => sA.index - sB.index);
31
- await downloadFile(downloadables, size);
32
+ await downloadFile(downloadables, fileInfo);
32
33
  await decryptFile(crypto.algorithm.type, key, iv, size);
33
34
  }
34
35
  catch (err) {
@@ -45,6 +45,10 @@ export interface GetDownloadLinksResponse {
45
45
  shards: DownloadableShard[];
46
46
  version?: number;
47
47
  size: number;
48
+ hmac?: {
49
+ value: string;
50
+ type: 'sha512';
51
+ };
48
52
  }
49
53
  export interface NetworkRequestConfig {
50
54
  client: HttpClient;
@@ -58,13 +62,19 @@ type UploadPayload = {
58
62
  export type StartUploadPayload = {
59
63
  uploads: UploadPayload[];
60
64
  };
65
+ export type HmacPayload = {
66
+ type: 'sha512';
67
+ value: string;
68
+ };
61
69
  export type FinishUploadPayload = {
62
70
  index: string;
63
71
  shards: Shard[];
72
+ hmac?: HmacPayload;
64
73
  };
65
74
  export type FinishMultipartUploadPayload = {
66
75
  index: string;
67
76
  shards: ShardForMultipart[];
77
+ hmac?: HmacPayload;
68
78
  };
69
79
  export type UploadFileFunction = (url: string) => Promise<Hash>;
70
80
  export type UploadFileMultipartFunction = (urls: string[]) => Promise<{
@@ -74,7 +84,7 @@ export type UploadFileMultipartFunction = (urls: string[]) => Promise<{
74
84
  ETag: string;
75
85
  }[];
76
86
  }>;
77
- export type DownloadFileFunction = (downloadables: DownloadableShard[], fileSize: number) => Promise<void>;
87
+ export type DownloadFileFunction = (downloadables: DownloadableShard[], fileInfo: GetDownloadLinksResponse) => Promise<void>;
78
88
  export type BinaryData = {
79
89
  slice: (from: number, to: number) => BinaryData;
80
90
  toString(encoding: 'hex'): string;
@@ -96,6 +106,7 @@ export type Crypto = {
96
106
  validateMnemonic: (mnemonic: string) => boolean;
97
107
  randomBytes: (bytesLength: number) => BinaryData;
98
108
  generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
109
+ computeHmac?: (key: BinaryData, shardHashes: string[]) => Promise<HmacPayload>;
99
110
  };
100
111
  export type EncryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData) => Promise<void>;
101
112
  export type DecryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData, fileSize: number) => Promise<void>;
@@ -22,9 +22,11 @@ async function uploadFile(network, crypto, bucketId, mnemonic, fileSize, encrypt
22
22
  }
23
23
  await encryptFile(crypto.algorithm.type, key, iv);
24
24
  const hash = await uploadFile(url);
25
+ const hmac = crypto.computeHmac ? await crypto.computeHmac(key, [hash]) : undefined;
25
26
  const finishUploadPayload = {
26
27
  index: index.toString('hex'),
27
28
  shards: [{ hash, uuid }],
29
+ hmac,
28
30
  };
29
31
  const finishUploadResponse = await network.finishUpload(bucketId, finishUploadPayload, signal);
30
32
  return finishUploadResponse.id;
@@ -60,9 +62,11 @@ async function uploadMultipartFile(network, crypto, bucketId, mnemonic, fileSize
60
62
  }
61
63
  await encryptFile(crypto.algorithm.type, key, iv);
62
64
  const { hash, parts: uploadedPartsReference } = await uploadMultiparts(urls);
65
+ const hmac = crypto.computeHmac ? await crypto.computeHmac(key, [hash]) : undefined;
63
66
  const finishUploadPayload = {
64
67
  index: index.toString('hex'),
65
68
  shards: [{ hash, uuid, UploadId, parts: uploadedPartsReference }],
69
+ hmac,
66
70
  };
67
71
  const finishUploadResponse = await network.finishMultipartUpload(bucketId, finishUploadPayload, signal);
68
72
  return finishUploadResponse.id;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@internxt/sdk",
3
3
  "author": "Internxt <hello@internxt.com>",
4
- "version": "1.17.7",
4
+ "version": "1.17.9",
5
5
  "description": "An sdk for interacting with Internxt's services",
6
6
  "repository": {
7
7
  "type": "git",