@haex-space/vault-sdk 2.5.50 → 2.5.54

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.
@@ -230,6 +230,33 @@ var DatabaseAPI = class {
230
230
  }
231
231
  };
232
232
 
233
+ // src/crypto/vaultKey.ts
234
+ function arrayBufferToBase64(buffer) {
235
+ const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
236
+ if (typeof Buffer !== "undefined") {
237
+ return Buffer.from(bytes).toString("base64");
238
+ }
239
+ let binary = "";
240
+ for (let i = 0; i < bytes.length; i++) {
241
+ const byte = bytes[i];
242
+ if (byte !== void 0) {
243
+ binary += String.fromCharCode(byte);
244
+ }
245
+ }
246
+ return btoa(binary);
247
+ }
248
+ function base64ToArrayBuffer(base64) {
249
+ if (typeof Buffer !== "undefined") {
250
+ return new Uint8Array(Buffer.from(base64, "base64"));
251
+ }
252
+ const binary = atob(base64);
253
+ const bytes = new Uint8Array(binary.length);
254
+ for (let i = 0; i < binary.length; i++) {
255
+ bytes[i] = binary.charCodeAt(i);
256
+ }
257
+ return bytes;
258
+ }
259
+
233
260
  // src/api/filesystem.ts
234
261
  var FilesystemAPI = class {
235
262
  constructor(client) {
@@ -301,12 +328,7 @@ var FilesystemAPI = class {
301
328
  HAEXTENSION_METHODS.filesystem.readFile,
302
329
  { path }
303
330
  );
304
- const binary = atob(base64);
305
- const bytes = new Uint8Array(binary.length);
306
- for (let i = 0; i < binary.length; i++) {
307
- bytes[i] = binary.charCodeAt(i);
308
- }
309
- return bytes;
331
+ return base64ToArrayBuffer(base64);
310
332
  }
311
333
  /**
312
334
  * Write file contents
@@ -314,7 +336,7 @@ var FilesystemAPI = class {
314
336
  * @param data File contents as Uint8Array
315
337
  */
316
338
  async writeFile(path, data) {
317
- const base64 = btoa(String.fromCharCode(...data));
339
+ const base64 = arrayBufferToBase64(data);
318
340
  await this.client.request(
319
341
  HAEXTENSION_METHODS.filesystem.writeFile,
320
342
  { path, data: base64 }
@@ -600,7 +622,7 @@ var RemoteStorageAPI = class {
600
622
  * @param data - Data to upload
601
623
  */
602
624
  async upload(backendId, key, data) {
603
- const base64 = btoa(String.fromCharCode(...data));
625
+ const base64 = arrayBufferToBase64(data);
604
626
  await this.client.request(HAEXTENSION_METHODS.remoteStorage.upload, {
605
627
  backendId,
606
628
  key,
@@ -618,12 +640,7 @@ var RemoteStorageAPI = class {
618
640
  HAEXTENSION_METHODS.remoteStorage.download,
619
641
  { backendId, key }
620
642
  );
621
- const binary = atob(base64);
622
- const bytes = new Uint8Array(binary.length);
623
- for (let i = 0; i < binary.length; i++) {
624
- bytes[i] = binary.charCodeAt(i);
625
- }
626
- return bytes;
643
+ return base64ToArrayBuffer(base64);
627
644
  }
628
645
  /**
629
646
  * Delete an object from a storage backend