@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.
package/dist/react.mjs CHANGED
@@ -556,6 +556,33 @@ var DatabaseAPI = class {
556
556
  }
557
557
  };
558
558
 
559
+ // src/crypto/vaultKey.ts
560
+ function arrayBufferToBase64(buffer) {
561
+ const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
562
+ if (typeof Buffer !== "undefined") {
563
+ return Buffer.from(bytes).toString("base64");
564
+ }
565
+ let binary = "";
566
+ for (let i = 0; i < bytes.length; i++) {
567
+ const byte = bytes[i];
568
+ if (byte !== void 0) {
569
+ binary += String.fromCharCode(byte);
570
+ }
571
+ }
572
+ return btoa(binary);
573
+ }
574
+ function base64ToArrayBuffer(base64) {
575
+ if (typeof Buffer !== "undefined") {
576
+ return new Uint8Array(Buffer.from(base64, "base64"));
577
+ }
578
+ const binary = atob(base64);
579
+ const bytes = new Uint8Array(binary.length);
580
+ for (let i = 0; i < binary.length; i++) {
581
+ bytes[i] = binary.charCodeAt(i);
582
+ }
583
+ return bytes;
584
+ }
585
+
559
586
  // src/api/filesystem.ts
560
587
  var FilesystemAPI = class {
561
588
  constructor(client) {
@@ -627,12 +654,7 @@ var FilesystemAPI = class {
627
654
  HAEXTENSION_METHODS.filesystem.readFile,
628
655
  { path }
629
656
  );
630
- const binary = atob(base64);
631
- const bytes = new Uint8Array(binary.length);
632
- for (let i = 0; i < binary.length; i++) {
633
- bytes[i] = binary.charCodeAt(i);
634
- }
635
- return bytes;
657
+ return base64ToArrayBuffer(base64);
636
658
  }
637
659
  /**
638
660
  * Write file contents
@@ -640,7 +662,7 @@ var FilesystemAPI = class {
640
662
  * @param data File contents as Uint8Array
641
663
  */
642
664
  async writeFile(path, data) {
643
- const base64 = btoa(String.fromCharCode(...data));
665
+ const base64 = arrayBufferToBase64(data);
644
666
  await this.client.request(
645
667
  HAEXTENSION_METHODS.filesystem.writeFile,
646
668
  { path, data: base64 }
@@ -926,7 +948,7 @@ var RemoteStorageAPI = class {
926
948
  * @param data - Data to upload
927
949
  */
928
950
  async upload(backendId, key, data) {
929
- const base64 = btoa(String.fromCharCode(...data));
951
+ const base64 = arrayBufferToBase64(data);
930
952
  await this.client.request(HAEXTENSION_METHODS.remoteStorage.upload, {
931
953
  backendId,
932
954
  key,
@@ -944,12 +966,7 @@ var RemoteStorageAPI = class {
944
966
  HAEXTENSION_METHODS.remoteStorage.download,
945
967
  { backendId, key }
946
968
  );
947
- const binary = atob(base64);
948
- const bytes = new Uint8Array(binary.length);
949
- for (let i = 0; i < binary.length; i++) {
950
- bytes[i] = binary.charCodeAt(i);
951
- }
952
- return bytes;
969
+ return base64ToArrayBuffer(base64);
953
970
  }
954
971
  /**
955
972
  * Delete an object from a storage backend