@internxt/sdk 1.17.8 → 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.
@@ -62,13 +62,19 @@ type UploadPayload = {
62
62
  export type StartUploadPayload = {
63
63
  uploads: UploadPayload[];
64
64
  };
65
+ export type HmacPayload = {
66
+ type: 'sha512';
67
+ value: string;
68
+ };
65
69
  export type FinishUploadPayload = {
66
70
  index: string;
67
71
  shards: Shard[];
72
+ hmac?: HmacPayload;
68
73
  };
69
74
  export type FinishMultipartUploadPayload = {
70
75
  index: string;
71
76
  shards: ShardForMultipart[];
77
+ hmac?: HmacPayload;
72
78
  };
73
79
  export type UploadFileFunction = (url: string) => Promise<Hash>;
74
80
  export type UploadFileMultipartFunction = (urls: string[]) => Promise<{
@@ -100,6 +106,7 @@ export type Crypto = {
100
106
  validateMnemonic: (mnemonic: string) => boolean;
101
107
  randomBytes: (bytesLength: number) => BinaryData;
102
108
  generateFileKey: (mnemonic: string, bucketId: string, index: BinaryData | string) => Promise<BinaryData>;
109
+ computeHmac?: (key: BinaryData, shardHashes: string[]) => Promise<HmacPayload>;
103
110
  };
104
111
  export type EncryptFileFunction = (algorithm: SymmetricCryptoAlgorithm, key: BinaryData, iv: BinaryData) => Promise<void>;
105
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.8",
4
+ "version": "1.17.9",
5
5
  "description": "An sdk for interacting with Internxt's services",
6
6
  "repository": {
7
7
  "type": "git",