@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/{client-Bgu2k1yJ.d.ts → client-Dv3ysOWr.d.ts} +14 -1
- package/dist/{client-BDxVgihp.d.mts → client-Y3QEhTe2.d.mts} +14 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +222 -232
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +222 -232
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +31 -14
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +31 -14
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.d.mts +1 -1
- package/dist/runtime/nuxt.plugin.client.d.ts +1 -1
- package/dist/runtime/nuxt.plugin.client.js +31 -14
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +31 -14
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +1 -1
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.js +31 -14
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +31 -14
- package/dist/svelte.mjs.map +1 -1
- package/dist/vue.d.mts +1 -1
- package/dist/vue.d.ts +1 -1
- package/dist/vue.js +31 -14
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +31 -14
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -304,6 +304,17 @@ declare class PermissionsAPI {
|
|
|
304
304
|
checkFilesystemAsync(path: string, operation: "read" | "write"): Promise<boolean>;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* S3 config without secrets (for display purposes)
|
|
309
|
+
*/
|
|
310
|
+
interface S3PublicConfig {
|
|
311
|
+
/** Endpoint URL (optional) */
|
|
312
|
+
endpoint?: string;
|
|
313
|
+
/** Region */
|
|
314
|
+
region: string;
|
|
315
|
+
/** Bucket name */
|
|
316
|
+
bucket: string;
|
|
317
|
+
}
|
|
307
318
|
/**
|
|
308
319
|
* Storage backend info (public, without credentials)
|
|
309
320
|
*/
|
|
@@ -314,6 +325,8 @@ interface StorageBackendInfo {
|
|
|
314
325
|
name: string;
|
|
315
326
|
enabled: boolean;
|
|
316
327
|
createdAt: string;
|
|
328
|
+
/** Public config without secrets (endpoint, bucket, region) */
|
|
329
|
+
config?: S3PublicConfig;
|
|
317
330
|
}
|
|
318
331
|
/**
|
|
319
332
|
* S3-compatible backend configuration
|
|
@@ -507,4 +520,4 @@ declare class HaexVaultSdk {
|
|
|
507
520
|
private log;
|
|
508
521
|
}
|
|
509
522
|
|
|
510
|
-
export { type AddBackendRequest as A, DatabaseAPI as D, FilesystemAPI as F, HaexVaultSdk as H, PermissionsAPI as P, RemoteStorageAPI as R, StorageAPI as S, WebAPI as W, type FileStat as a, type DirEntry as b, type SelectFolderOptions as c, type SelectFileOptions as d, type StorageBackendInfo as e, type S3Config as f, type
|
|
523
|
+
export { type AddBackendRequest as A, DatabaseAPI as D, FilesystemAPI as F, HaexVaultSdk as H, PermissionsAPI as P, RemoteStorageAPI as R, StorageAPI as S, WebAPI as W, type FileStat as a, type DirEntry as b, type SelectFolderOptions as c, type SelectFileOptions as d, type StorageBackendInfo as e, type S3Config as f, type S3PublicConfig as g, type StorageObjectInfo as h };
|
|
@@ -304,6 +304,17 @@ declare class PermissionsAPI {
|
|
|
304
304
|
checkFilesystemAsync(path: string, operation: "read" | "write"): Promise<boolean>;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
/**
|
|
308
|
+
* S3 config without secrets (for display purposes)
|
|
309
|
+
*/
|
|
310
|
+
interface S3PublicConfig {
|
|
311
|
+
/** Endpoint URL (optional) */
|
|
312
|
+
endpoint?: string;
|
|
313
|
+
/** Region */
|
|
314
|
+
region: string;
|
|
315
|
+
/** Bucket name */
|
|
316
|
+
bucket: string;
|
|
317
|
+
}
|
|
307
318
|
/**
|
|
308
319
|
* Storage backend info (public, without credentials)
|
|
309
320
|
*/
|
|
@@ -314,6 +325,8 @@ interface StorageBackendInfo {
|
|
|
314
325
|
name: string;
|
|
315
326
|
enabled: boolean;
|
|
316
327
|
createdAt: string;
|
|
328
|
+
/** Public config without secrets (endpoint, bucket, region) */
|
|
329
|
+
config?: S3PublicConfig;
|
|
317
330
|
}
|
|
318
331
|
/**
|
|
319
332
|
* S3-compatible backend configuration
|
|
@@ -507,4 +520,4 @@ declare class HaexVaultSdk {
|
|
|
507
520
|
private log;
|
|
508
521
|
}
|
|
509
522
|
|
|
510
|
-
export { type AddBackendRequest as A, DatabaseAPI as D, FilesystemAPI as F, HaexVaultSdk as H, PermissionsAPI as P, RemoteStorageAPI as R, StorageAPI as S, WebAPI as W, type FileStat as a, type DirEntry as b, type SelectFolderOptions as c, type SelectFileOptions as d, type StorageBackendInfo as e, type S3Config as f, type
|
|
523
|
+
export { type AddBackendRequest as A, DatabaseAPI as D, FilesystemAPI as F, HaexVaultSdk as H, PermissionsAPI as P, RemoteStorageAPI as R, StorageAPI as S, WebAPI as W, type FileStat as a, type DirEntry as b, type SelectFolderOptions as c, type SelectFileOptions as d, type StorageBackendInfo as e, type S3Config as f, type S3PublicConfig as g, type StorageObjectInfo as h };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HaexVaultSdk } from './client-
|
|
2
|
-
export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, R as RemoteStorageAPI, e as RemoteStorageBackendInfo,
|
|
1
|
+
import { H as HaexVaultSdk } from './client-Y3QEhTe2.mjs';
|
|
2
|
+
export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, g as RemoteS3PublicConfig, R as RemoteStorageAPI, e as RemoteStorageBackendInfo, h as RemoteStorageObjectInfo, d as SelectFileOptions, c as SelectFolderOptions, W as WebAPI } from './client-Y3QEhTe2.mjs';
|
|
3
3
|
import { E as ExtensionManifest, H as HaexHubConfig } from './types-DiXJ5SF6.mjs';
|
|
4
4
|
export { A as ApplicationContext, t as AuthorizedClient, B as BlockedClient, C as ContextChangedEvent, F as DEFAULT_TIMEOUT, o as DatabaseColumnInfo, m as DatabaseExecuteParams, k as DatabasePermission, d as DatabasePermissionRequest, l as DatabaseQueryParams, D as DatabaseQueryResult, n as DatabaseTableInfo, U as EXTERNAL_EVENTS, z as ErrorCode, g as EventCallback, a as ExtensionInfo, v as ExternalAuthDecision, x as ExternalConnection, J as ExternalConnectionErrorCode, I as ExternalConnectionState, V as ExternalEvent, s as ExternalRequest, r as ExternalRequestEvent, e as ExternalRequestHandler, f as ExternalResponse, O as HAEXTENSION_EVENTS, j as HaexHubEvent, h as HaexHubRequest, i as HaexHubResponse, N as HaexVaultSdkError, Q as HaextensionEvent, u as PendingAuthorization, P as PermissionResponse, y as PermissionStatus, R as RequestedExtension, p as SearchQuery, q as SearchRequestEvent, S as SearchResult, w as SessionAuthorization, T as TABLE_SEPARATOR, W as WebRequestOptions, c as WebResponse, L as canExternalClientSendRequests, G as getTableName, K as isExternalClientConnected } from './types-DiXJ5SF6.mjs';
|
|
5
5
|
export { H as HaextensionConfig } from './config-D_HXjsEV.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { H as HaexVaultSdk } from './client-
|
|
2
|
-
export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, R as RemoteStorageAPI, e as RemoteStorageBackendInfo,
|
|
1
|
+
import { H as HaexVaultSdk } from './client-Dv3ysOWr.js';
|
|
2
|
+
export { D as DatabaseAPI, b as DirEntry, a as FileStat, F as FilesystemAPI, P as PermissionsAPI, A as RemoteAddBackendRequest, f as RemoteS3Config, g as RemoteS3PublicConfig, R as RemoteStorageAPI, e as RemoteStorageBackendInfo, h as RemoteStorageObjectInfo, d as SelectFileOptions, c as SelectFolderOptions, W as WebAPI } from './client-Dv3ysOWr.js';
|
|
3
3
|
import { E as ExtensionManifest, H as HaexHubConfig } from './types-DiXJ5SF6.js';
|
|
4
4
|
export { A as ApplicationContext, t as AuthorizedClient, B as BlockedClient, C as ContextChangedEvent, F as DEFAULT_TIMEOUT, o as DatabaseColumnInfo, m as DatabaseExecuteParams, k as DatabasePermission, d as DatabasePermissionRequest, l as DatabaseQueryParams, D as DatabaseQueryResult, n as DatabaseTableInfo, U as EXTERNAL_EVENTS, z as ErrorCode, g as EventCallback, a as ExtensionInfo, v as ExternalAuthDecision, x as ExternalConnection, J as ExternalConnectionErrorCode, I as ExternalConnectionState, V as ExternalEvent, s as ExternalRequest, r as ExternalRequestEvent, e as ExternalRequestHandler, f as ExternalResponse, O as HAEXTENSION_EVENTS, j as HaexHubEvent, h as HaexHubRequest, i as HaexHubResponse, N as HaexVaultSdkError, Q as HaextensionEvent, u as PendingAuthorization, P as PermissionResponse, y as PermissionStatus, R as RequestedExtension, p as SearchQuery, q as SearchRequestEvent, S as SearchResult, w as SessionAuthorization, T as TABLE_SEPARATOR, W as WebRequestOptions, c as WebResponse, L as canExternalClientSendRequests, G as getTableName, K as isExternalClientConnected } from './types-DiXJ5SF6.js';
|
|
5
5
|
export { H as HaextensionConfig } from './config-D_HXjsEV.js';
|
package/dist/index.js
CHANGED
|
@@ -645,6 +645,224 @@ var DatabaseAPI = class {
|
|
|
645
645
|
}
|
|
646
646
|
};
|
|
647
647
|
|
|
648
|
+
// src/crypto/vaultKey.ts
|
|
649
|
+
var PBKDF2_ITERATIONS = 6e5;
|
|
650
|
+
var KEY_LENGTH = 256;
|
|
651
|
+
var ALGORITHM = "AES-GCM";
|
|
652
|
+
async function deriveKeyFromPassword(password, salt) {
|
|
653
|
+
const encoder = new TextEncoder();
|
|
654
|
+
const passwordBuffer = encoder.encode(password);
|
|
655
|
+
const saltBuffer = new Uint8Array(salt);
|
|
656
|
+
const keyMaterial = await crypto.subtle.importKey(
|
|
657
|
+
"raw",
|
|
658
|
+
passwordBuffer,
|
|
659
|
+
"PBKDF2",
|
|
660
|
+
false,
|
|
661
|
+
["deriveKey"]
|
|
662
|
+
);
|
|
663
|
+
return await crypto.subtle.deriveKey(
|
|
664
|
+
{
|
|
665
|
+
name: "PBKDF2",
|
|
666
|
+
salt: saltBuffer,
|
|
667
|
+
iterations: PBKDF2_ITERATIONS,
|
|
668
|
+
hash: "SHA-256"
|
|
669
|
+
},
|
|
670
|
+
keyMaterial,
|
|
671
|
+
{ name: ALGORITHM, length: KEY_LENGTH },
|
|
672
|
+
false,
|
|
673
|
+
// not extractable
|
|
674
|
+
["encrypt", "decrypt"]
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
function generateVaultKey() {
|
|
678
|
+
return crypto.getRandomValues(new Uint8Array(32));
|
|
679
|
+
}
|
|
680
|
+
async function encryptString(data, derivedKey) {
|
|
681
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
682
|
+
const encoder = new TextEncoder();
|
|
683
|
+
const dataBuffer = encoder.encode(data);
|
|
684
|
+
const encryptedBuffer = await crypto.subtle.encrypt(
|
|
685
|
+
{
|
|
686
|
+
name: ALGORITHM,
|
|
687
|
+
iv: nonce
|
|
688
|
+
},
|
|
689
|
+
derivedKey,
|
|
690
|
+
dataBuffer
|
|
691
|
+
);
|
|
692
|
+
return {
|
|
693
|
+
encryptedData: arrayBufferToBase64(encryptedBuffer),
|
|
694
|
+
nonce: arrayBufferToBase64(nonce)
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
async function decryptString(encryptedData, nonce, derivedKey) {
|
|
698
|
+
const encryptedBuffer = base64ToArrayBuffer(encryptedData);
|
|
699
|
+
const nonceBuffer = base64ToArrayBuffer(nonce);
|
|
700
|
+
const encryptedDataBuffer = new Uint8Array(encryptedBuffer);
|
|
701
|
+
const iv = new Uint8Array(nonceBuffer);
|
|
702
|
+
const decryptedBuffer = await crypto.subtle.decrypt(
|
|
703
|
+
{
|
|
704
|
+
name: ALGORITHM,
|
|
705
|
+
iv
|
|
706
|
+
},
|
|
707
|
+
derivedKey,
|
|
708
|
+
encryptedDataBuffer
|
|
709
|
+
);
|
|
710
|
+
const decoder = new TextDecoder();
|
|
711
|
+
return decoder.decode(decryptedBuffer);
|
|
712
|
+
}
|
|
713
|
+
async function encryptVaultKey(vaultKey, password) {
|
|
714
|
+
const salt = crypto.getRandomValues(new Uint8Array(32));
|
|
715
|
+
const derivedKey = await deriveKeyFromPassword(password, salt);
|
|
716
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
717
|
+
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
718
|
+
const encryptedBuffer = await crypto.subtle.encrypt(
|
|
719
|
+
{
|
|
720
|
+
name: ALGORITHM,
|
|
721
|
+
iv: nonce
|
|
722
|
+
},
|
|
723
|
+
derivedKey,
|
|
724
|
+
vaultKeyBuffer
|
|
725
|
+
);
|
|
726
|
+
return {
|
|
727
|
+
encryptedVaultKey: arrayBufferToBase64(encryptedBuffer),
|
|
728
|
+
salt: arrayBufferToBase64(salt),
|
|
729
|
+
vaultKeyNonce: arrayBufferToBase64(nonce)
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
async function decryptVaultKey(encryptedVaultKey, salt, vaultKeyNonce, password) {
|
|
733
|
+
const encryptedBuffer = base64ToArrayBuffer(encryptedVaultKey);
|
|
734
|
+
const saltBuffer = base64ToArrayBuffer(salt);
|
|
735
|
+
const nonceBuffer = base64ToArrayBuffer(vaultKeyNonce);
|
|
736
|
+
const derivedKey = await deriveKeyFromPassword(password, saltBuffer);
|
|
737
|
+
const encryptedData = new Uint8Array(encryptedBuffer);
|
|
738
|
+
const iv = new Uint8Array(nonceBuffer);
|
|
739
|
+
const decryptedBuffer = await crypto.subtle.decrypt(
|
|
740
|
+
{
|
|
741
|
+
name: ALGORITHM,
|
|
742
|
+
iv
|
|
743
|
+
},
|
|
744
|
+
derivedKey,
|
|
745
|
+
encryptedData
|
|
746
|
+
);
|
|
747
|
+
return new Uint8Array(decryptedBuffer);
|
|
748
|
+
}
|
|
749
|
+
async function decryptVaultName(encryptedVaultName, vaultNameNonce, vaultNameSalt, password) {
|
|
750
|
+
const saltBuffer = base64ToArrayBuffer(vaultNameSalt);
|
|
751
|
+
const derivedKey = await deriveKeyFromPassword(password, saltBuffer);
|
|
752
|
+
return decryptString(encryptedVaultName, vaultNameNonce, derivedKey);
|
|
753
|
+
}
|
|
754
|
+
async function encryptCrdtData(data, vaultKey) {
|
|
755
|
+
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
756
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
757
|
+
"raw",
|
|
758
|
+
vaultKeyBuffer,
|
|
759
|
+
{ name: ALGORITHM },
|
|
760
|
+
false,
|
|
761
|
+
["encrypt"]
|
|
762
|
+
);
|
|
763
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
764
|
+
const encoder = new TextEncoder();
|
|
765
|
+
const dataBuffer = encoder.encode(JSON.stringify(data));
|
|
766
|
+
const encryptedBuffer = await crypto.subtle.encrypt(
|
|
767
|
+
{
|
|
768
|
+
name: ALGORITHM,
|
|
769
|
+
iv: nonce
|
|
770
|
+
},
|
|
771
|
+
cryptoKey,
|
|
772
|
+
dataBuffer
|
|
773
|
+
);
|
|
774
|
+
return {
|
|
775
|
+
encryptedData: arrayBufferToBase64(encryptedBuffer),
|
|
776
|
+
nonce: arrayBufferToBase64(nonce)
|
|
777
|
+
};
|
|
778
|
+
}
|
|
779
|
+
async function wrapKey(keyToWrap, wrappingKey) {
|
|
780
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
781
|
+
"raw",
|
|
782
|
+
new Uint8Array(wrappingKey),
|
|
783
|
+
{ name: ALGORITHM },
|
|
784
|
+
false,
|
|
785
|
+
["encrypt"]
|
|
786
|
+
);
|
|
787
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
788
|
+
const ciphertext = await crypto.subtle.encrypt(
|
|
789
|
+
{ name: ALGORITHM, iv: nonce },
|
|
790
|
+
cryptoKey,
|
|
791
|
+
new Uint8Array(keyToWrap)
|
|
792
|
+
);
|
|
793
|
+
const result = new Uint8Array(12 + ciphertext.byteLength);
|
|
794
|
+
result.set(nonce, 0);
|
|
795
|
+
result.set(new Uint8Array(ciphertext), 12);
|
|
796
|
+
return result;
|
|
797
|
+
}
|
|
798
|
+
async function unwrapKey(wrappedKey, wrappingKey) {
|
|
799
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
800
|
+
"raw",
|
|
801
|
+
new Uint8Array(wrappingKey),
|
|
802
|
+
{ name: ALGORITHM },
|
|
803
|
+
false,
|
|
804
|
+
["decrypt"]
|
|
805
|
+
);
|
|
806
|
+
const nonce = wrappedKey.slice(0, 12);
|
|
807
|
+
const ciphertext = wrappedKey.slice(12);
|
|
808
|
+
const plaintext = await crypto.subtle.decrypt(
|
|
809
|
+
{ name: ALGORITHM, iv: nonce },
|
|
810
|
+
cryptoKey,
|
|
811
|
+
ciphertext
|
|
812
|
+
);
|
|
813
|
+
return new Uint8Array(plaintext);
|
|
814
|
+
}
|
|
815
|
+
async function decryptCrdtData(encryptedData, nonce, vaultKey) {
|
|
816
|
+
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
817
|
+
const cryptoKey = await crypto.subtle.importKey(
|
|
818
|
+
"raw",
|
|
819
|
+
vaultKeyBuffer,
|
|
820
|
+
{ name: ALGORITHM },
|
|
821
|
+
false,
|
|
822
|
+
["decrypt"]
|
|
823
|
+
);
|
|
824
|
+
const encryptedBuffer = base64ToArrayBuffer(encryptedData);
|
|
825
|
+
const nonceBuffer = base64ToArrayBuffer(nonce);
|
|
826
|
+
const encryptedDataBuffer = new Uint8Array(encryptedBuffer);
|
|
827
|
+
const iv = new Uint8Array(nonceBuffer);
|
|
828
|
+
const decryptedBuffer = await crypto.subtle.decrypt(
|
|
829
|
+
{
|
|
830
|
+
name: ALGORITHM,
|
|
831
|
+
iv
|
|
832
|
+
},
|
|
833
|
+
cryptoKey,
|
|
834
|
+
encryptedDataBuffer
|
|
835
|
+
);
|
|
836
|
+
const decoder = new TextDecoder();
|
|
837
|
+
const jsonString = decoder.decode(decryptedBuffer);
|
|
838
|
+
return JSON.parse(jsonString);
|
|
839
|
+
}
|
|
840
|
+
function arrayBufferToBase64(buffer) {
|
|
841
|
+
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
842
|
+
if (typeof Buffer !== "undefined") {
|
|
843
|
+
return Buffer.from(bytes).toString("base64");
|
|
844
|
+
}
|
|
845
|
+
let binary = "";
|
|
846
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
847
|
+
const byte = bytes[i];
|
|
848
|
+
if (byte !== void 0) {
|
|
849
|
+
binary += String.fromCharCode(byte);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
return btoa(binary);
|
|
853
|
+
}
|
|
854
|
+
function base64ToArrayBuffer(base64) {
|
|
855
|
+
if (typeof Buffer !== "undefined") {
|
|
856
|
+
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
857
|
+
}
|
|
858
|
+
const binary = atob(base64);
|
|
859
|
+
const bytes = new Uint8Array(binary.length);
|
|
860
|
+
for (let i = 0; i < binary.length; i++) {
|
|
861
|
+
bytes[i] = binary.charCodeAt(i);
|
|
862
|
+
}
|
|
863
|
+
return bytes;
|
|
864
|
+
}
|
|
865
|
+
|
|
648
866
|
// src/api/filesystem.ts
|
|
649
867
|
var FilesystemAPI = class {
|
|
650
868
|
constructor(client) {
|
|
@@ -716,12 +934,7 @@ var FilesystemAPI = class {
|
|
|
716
934
|
HAEXTENSION_METHODS.filesystem.readFile,
|
|
717
935
|
{ path }
|
|
718
936
|
);
|
|
719
|
-
|
|
720
|
-
const bytes = new Uint8Array(binary.length);
|
|
721
|
-
for (let i = 0; i < binary.length; i++) {
|
|
722
|
-
bytes[i] = binary.charCodeAt(i);
|
|
723
|
-
}
|
|
724
|
-
return bytes;
|
|
937
|
+
return base64ToArrayBuffer(base64);
|
|
725
938
|
}
|
|
726
939
|
/**
|
|
727
940
|
* Write file contents
|
|
@@ -729,7 +942,7 @@ var FilesystemAPI = class {
|
|
|
729
942
|
* @param data File contents as Uint8Array
|
|
730
943
|
*/
|
|
731
944
|
async writeFile(path, data) {
|
|
732
|
-
const base64 =
|
|
945
|
+
const base64 = arrayBufferToBase64(data);
|
|
733
946
|
await this.client.request(
|
|
734
947
|
HAEXTENSION_METHODS.filesystem.writeFile,
|
|
735
948
|
{ path, data: base64 }
|
|
@@ -1015,7 +1228,7 @@ var RemoteStorageAPI = class {
|
|
|
1015
1228
|
* @param data - Data to upload
|
|
1016
1229
|
*/
|
|
1017
1230
|
async upload(backendId, key, data) {
|
|
1018
|
-
const base64 =
|
|
1231
|
+
const base64 = arrayBufferToBase64(data);
|
|
1019
1232
|
await this.client.request(HAEXTENSION_METHODS.remoteStorage.upload, {
|
|
1020
1233
|
backendId,
|
|
1021
1234
|
key,
|
|
@@ -1033,12 +1246,7 @@ var RemoteStorageAPI = class {
|
|
|
1033
1246
|
HAEXTENSION_METHODS.remoteStorage.download,
|
|
1034
1247
|
{ backendId, key }
|
|
1035
1248
|
);
|
|
1036
|
-
|
|
1037
|
-
const bytes = new Uint8Array(binary.length);
|
|
1038
|
-
for (let i = 0; i < binary.length; i++) {
|
|
1039
|
-
bytes[i] = binary.charCodeAt(i);
|
|
1040
|
-
}
|
|
1041
|
-
return bytes;
|
|
1249
|
+
return base64ToArrayBuffer(base64);
|
|
1042
1250
|
}
|
|
1043
1251
|
/**
|
|
1044
1252
|
* Delete an object from a storage backend
|
|
@@ -2329,224 +2537,6 @@ async function verifyExtensionSignature(files, manifest) {
|
|
|
2329
2537
|
}
|
|
2330
2538
|
}
|
|
2331
2539
|
|
|
2332
|
-
// src/crypto/vaultKey.ts
|
|
2333
|
-
var PBKDF2_ITERATIONS = 6e5;
|
|
2334
|
-
var KEY_LENGTH = 256;
|
|
2335
|
-
var ALGORITHM = "AES-GCM";
|
|
2336
|
-
async function deriveKeyFromPassword(password, salt) {
|
|
2337
|
-
const encoder = new TextEncoder();
|
|
2338
|
-
const passwordBuffer = encoder.encode(password);
|
|
2339
|
-
const saltBuffer = new Uint8Array(salt);
|
|
2340
|
-
const keyMaterial = await crypto.subtle.importKey(
|
|
2341
|
-
"raw",
|
|
2342
|
-
passwordBuffer,
|
|
2343
|
-
"PBKDF2",
|
|
2344
|
-
false,
|
|
2345
|
-
["deriveKey"]
|
|
2346
|
-
);
|
|
2347
|
-
return await crypto.subtle.deriveKey(
|
|
2348
|
-
{
|
|
2349
|
-
name: "PBKDF2",
|
|
2350
|
-
salt: saltBuffer,
|
|
2351
|
-
iterations: PBKDF2_ITERATIONS,
|
|
2352
|
-
hash: "SHA-256"
|
|
2353
|
-
},
|
|
2354
|
-
keyMaterial,
|
|
2355
|
-
{ name: ALGORITHM, length: KEY_LENGTH },
|
|
2356
|
-
false,
|
|
2357
|
-
// not extractable
|
|
2358
|
-
["encrypt", "decrypt"]
|
|
2359
|
-
);
|
|
2360
|
-
}
|
|
2361
|
-
function generateVaultKey() {
|
|
2362
|
-
return crypto.getRandomValues(new Uint8Array(32));
|
|
2363
|
-
}
|
|
2364
|
-
async function encryptString(data, derivedKey) {
|
|
2365
|
-
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2366
|
-
const encoder = new TextEncoder();
|
|
2367
|
-
const dataBuffer = encoder.encode(data);
|
|
2368
|
-
const encryptedBuffer = await crypto.subtle.encrypt(
|
|
2369
|
-
{
|
|
2370
|
-
name: ALGORITHM,
|
|
2371
|
-
iv: nonce
|
|
2372
|
-
},
|
|
2373
|
-
derivedKey,
|
|
2374
|
-
dataBuffer
|
|
2375
|
-
);
|
|
2376
|
-
return {
|
|
2377
|
-
encryptedData: arrayBufferToBase64(encryptedBuffer),
|
|
2378
|
-
nonce: arrayBufferToBase64(nonce)
|
|
2379
|
-
};
|
|
2380
|
-
}
|
|
2381
|
-
async function decryptString(encryptedData, nonce, derivedKey) {
|
|
2382
|
-
const encryptedBuffer = base64ToArrayBuffer(encryptedData);
|
|
2383
|
-
const nonceBuffer = base64ToArrayBuffer(nonce);
|
|
2384
|
-
const encryptedDataBuffer = new Uint8Array(encryptedBuffer);
|
|
2385
|
-
const iv = new Uint8Array(nonceBuffer);
|
|
2386
|
-
const decryptedBuffer = await crypto.subtle.decrypt(
|
|
2387
|
-
{
|
|
2388
|
-
name: ALGORITHM,
|
|
2389
|
-
iv
|
|
2390
|
-
},
|
|
2391
|
-
derivedKey,
|
|
2392
|
-
encryptedDataBuffer
|
|
2393
|
-
);
|
|
2394
|
-
const decoder = new TextDecoder();
|
|
2395
|
-
return decoder.decode(decryptedBuffer);
|
|
2396
|
-
}
|
|
2397
|
-
async function encryptVaultKey(vaultKey, password) {
|
|
2398
|
-
const salt = crypto.getRandomValues(new Uint8Array(32));
|
|
2399
|
-
const derivedKey = await deriveKeyFromPassword(password, salt);
|
|
2400
|
-
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2401
|
-
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
2402
|
-
const encryptedBuffer = await crypto.subtle.encrypt(
|
|
2403
|
-
{
|
|
2404
|
-
name: ALGORITHM,
|
|
2405
|
-
iv: nonce
|
|
2406
|
-
},
|
|
2407
|
-
derivedKey,
|
|
2408
|
-
vaultKeyBuffer
|
|
2409
|
-
);
|
|
2410
|
-
return {
|
|
2411
|
-
encryptedVaultKey: arrayBufferToBase64(encryptedBuffer),
|
|
2412
|
-
salt: arrayBufferToBase64(salt),
|
|
2413
|
-
vaultKeyNonce: arrayBufferToBase64(nonce)
|
|
2414
|
-
};
|
|
2415
|
-
}
|
|
2416
|
-
async function decryptVaultKey(encryptedVaultKey, salt, vaultKeyNonce, password) {
|
|
2417
|
-
const encryptedBuffer = base64ToArrayBuffer(encryptedVaultKey);
|
|
2418
|
-
const saltBuffer = base64ToArrayBuffer(salt);
|
|
2419
|
-
const nonceBuffer = base64ToArrayBuffer(vaultKeyNonce);
|
|
2420
|
-
const derivedKey = await deriveKeyFromPassword(password, saltBuffer);
|
|
2421
|
-
const encryptedData = new Uint8Array(encryptedBuffer);
|
|
2422
|
-
const iv = new Uint8Array(nonceBuffer);
|
|
2423
|
-
const decryptedBuffer = await crypto.subtle.decrypt(
|
|
2424
|
-
{
|
|
2425
|
-
name: ALGORITHM,
|
|
2426
|
-
iv
|
|
2427
|
-
},
|
|
2428
|
-
derivedKey,
|
|
2429
|
-
encryptedData
|
|
2430
|
-
);
|
|
2431
|
-
return new Uint8Array(decryptedBuffer);
|
|
2432
|
-
}
|
|
2433
|
-
async function decryptVaultName(encryptedVaultName, vaultNameNonce, vaultNameSalt, password) {
|
|
2434
|
-
const saltBuffer = base64ToArrayBuffer(vaultNameSalt);
|
|
2435
|
-
const derivedKey = await deriveKeyFromPassword(password, saltBuffer);
|
|
2436
|
-
return decryptString(encryptedVaultName, vaultNameNonce, derivedKey);
|
|
2437
|
-
}
|
|
2438
|
-
async function encryptCrdtData(data, vaultKey) {
|
|
2439
|
-
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
2440
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
2441
|
-
"raw",
|
|
2442
|
-
vaultKeyBuffer,
|
|
2443
|
-
{ name: ALGORITHM },
|
|
2444
|
-
false,
|
|
2445
|
-
["encrypt"]
|
|
2446
|
-
);
|
|
2447
|
-
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2448
|
-
const encoder = new TextEncoder();
|
|
2449
|
-
const dataBuffer = encoder.encode(JSON.stringify(data));
|
|
2450
|
-
const encryptedBuffer = await crypto.subtle.encrypt(
|
|
2451
|
-
{
|
|
2452
|
-
name: ALGORITHM,
|
|
2453
|
-
iv: nonce
|
|
2454
|
-
},
|
|
2455
|
-
cryptoKey,
|
|
2456
|
-
dataBuffer
|
|
2457
|
-
);
|
|
2458
|
-
return {
|
|
2459
|
-
encryptedData: arrayBufferToBase64(encryptedBuffer),
|
|
2460
|
-
nonce: arrayBufferToBase64(nonce)
|
|
2461
|
-
};
|
|
2462
|
-
}
|
|
2463
|
-
async function wrapKey(keyToWrap, wrappingKey) {
|
|
2464
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
2465
|
-
"raw",
|
|
2466
|
-
new Uint8Array(wrappingKey),
|
|
2467
|
-
{ name: ALGORITHM },
|
|
2468
|
-
false,
|
|
2469
|
-
["encrypt"]
|
|
2470
|
-
);
|
|
2471
|
-
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2472
|
-
const ciphertext = await crypto.subtle.encrypt(
|
|
2473
|
-
{ name: ALGORITHM, iv: nonce },
|
|
2474
|
-
cryptoKey,
|
|
2475
|
-
new Uint8Array(keyToWrap)
|
|
2476
|
-
);
|
|
2477
|
-
const result = new Uint8Array(12 + ciphertext.byteLength);
|
|
2478
|
-
result.set(nonce, 0);
|
|
2479
|
-
result.set(new Uint8Array(ciphertext), 12);
|
|
2480
|
-
return result;
|
|
2481
|
-
}
|
|
2482
|
-
async function unwrapKey(wrappedKey, wrappingKey) {
|
|
2483
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
2484
|
-
"raw",
|
|
2485
|
-
new Uint8Array(wrappingKey),
|
|
2486
|
-
{ name: ALGORITHM },
|
|
2487
|
-
false,
|
|
2488
|
-
["decrypt"]
|
|
2489
|
-
);
|
|
2490
|
-
const nonce = wrappedKey.slice(0, 12);
|
|
2491
|
-
const ciphertext = wrappedKey.slice(12);
|
|
2492
|
-
const plaintext = await crypto.subtle.decrypt(
|
|
2493
|
-
{ name: ALGORITHM, iv: nonce },
|
|
2494
|
-
cryptoKey,
|
|
2495
|
-
ciphertext
|
|
2496
|
-
);
|
|
2497
|
-
return new Uint8Array(plaintext);
|
|
2498
|
-
}
|
|
2499
|
-
async function decryptCrdtData(encryptedData, nonce, vaultKey) {
|
|
2500
|
-
const vaultKeyBuffer = new Uint8Array(vaultKey);
|
|
2501
|
-
const cryptoKey = await crypto.subtle.importKey(
|
|
2502
|
-
"raw",
|
|
2503
|
-
vaultKeyBuffer,
|
|
2504
|
-
{ name: ALGORITHM },
|
|
2505
|
-
false,
|
|
2506
|
-
["decrypt"]
|
|
2507
|
-
);
|
|
2508
|
-
const encryptedBuffer = base64ToArrayBuffer(encryptedData);
|
|
2509
|
-
const nonceBuffer = base64ToArrayBuffer(nonce);
|
|
2510
|
-
const encryptedDataBuffer = new Uint8Array(encryptedBuffer);
|
|
2511
|
-
const iv = new Uint8Array(nonceBuffer);
|
|
2512
|
-
const decryptedBuffer = await crypto.subtle.decrypt(
|
|
2513
|
-
{
|
|
2514
|
-
name: ALGORITHM,
|
|
2515
|
-
iv
|
|
2516
|
-
},
|
|
2517
|
-
cryptoKey,
|
|
2518
|
-
encryptedDataBuffer
|
|
2519
|
-
);
|
|
2520
|
-
const decoder = new TextDecoder();
|
|
2521
|
-
const jsonString = decoder.decode(decryptedBuffer);
|
|
2522
|
-
return JSON.parse(jsonString);
|
|
2523
|
-
}
|
|
2524
|
-
function arrayBufferToBase64(buffer) {
|
|
2525
|
-
const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
|
|
2526
|
-
if (typeof Buffer !== "undefined") {
|
|
2527
|
-
return Buffer.from(bytes).toString("base64");
|
|
2528
|
-
}
|
|
2529
|
-
let binary = "";
|
|
2530
|
-
for (let i = 0; i < bytes.length; i++) {
|
|
2531
|
-
const byte = bytes[i];
|
|
2532
|
-
if (byte !== void 0) {
|
|
2533
|
-
binary += String.fromCharCode(byte);
|
|
2534
|
-
}
|
|
2535
|
-
}
|
|
2536
|
-
return btoa(binary);
|
|
2537
|
-
}
|
|
2538
|
-
function base64ToArrayBuffer(base64) {
|
|
2539
|
-
if (typeof Buffer !== "undefined") {
|
|
2540
|
-
return new Uint8Array(Buffer.from(base64, "base64"));
|
|
2541
|
-
}
|
|
2542
|
-
const binary = atob(base64);
|
|
2543
|
-
const bytes = new Uint8Array(binary.length);
|
|
2544
|
-
for (let i = 0; i < binary.length; i++) {
|
|
2545
|
-
bytes[i] = binary.charCodeAt(i);
|
|
2546
|
-
}
|
|
2547
|
-
return bytes;
|
|
2548
|
-
}
|
|
2549
|
-
|
|
2550
2540
|
// src/index.ts
|
|
2551
2541
|
function createHaexVaultSdk(config = {}) {
|
|
2552
2542
|
return new HaexVaultSdk(config);
|