@haex-space/vault-sdk 2.5.105 → 2.5.107
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/cli/index.js +31 -28
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/index.mjs +31 -28
- package/dist/cli/index.mjs.map +1 -1
- package/dist/{client-lIBgzxxo.d.mts → client-CBCjziWo.d.mts} +2 -2
- package/dist/{client-CvlnVzd_.d.ts → client-_FhZZse3.d.ts} +2 -2
- package/dist/index.d.mts +82 -7
- package/dist/index.d.ts +82 -7
- package/dist/index.js +199 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +185 -57
- package/dist/index.mjs.map +1 -1
- package/dist/node.d.mts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/node.js +2 -2
- package/dist/node.js.map +1 -1
- package/dist/node.mjs +2 -2
- package/dist/node.mjs.map +1 -1
- package/dist/nuxt.js +6 -6
- package/dist/nuxt.js.map +1 -1
- package/dist/nuxt.mjs +6 -6
- package/dist/nuxt.mjs.map +1 -1
- package/dist/react.d.mts +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/react.js +42 -56
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +42 -56
- package/dist/react.mjs.map +1 -1
- package/dist/runtime/nuxt.plugin.client.d.mts +2 -2
- package/dist/runtime/nuxt.plugin.client.d.ts +2 -2
- package/dist/runtime/nuxt.plugin.client.js +39 -52
- package/dist/runtime/nuxt.plugin.client.js.map +1 -1
- package/dist/runtime/nuxt.plugin.client.mjs +39 -52
- package/dist/runtime/nuxt.plugin.client.mjs.map +1 -1
- package/dist/svelte.d.mts +2 -2
- package/dist/svelte.d.ts +2 -2
- package/dist/svelte.js +42 -56
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +42 -56
- package/dist/svelte.mjs.map +1 -1
- package/dist/{types-D2qzgDja.d.mts → types-NWYbdRXr.d.mts} +44 -1
- package/dist/{types-D2qzgDja.d.ts → types-NWYbdRXr.d.ts} +44 -1
- package/dist/vite.js +4 -4
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +4 -4
- package/dist/vite.mjs.map +1 -1
- package/dist/vue.d.mts +2 -2
- package/dist/vue.d.ts +2 -2
- package/dist/vue.js +42 -56
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +42 -56
- package/dist/vue.mjs.map +1 -1
- package/package.json +21 -23
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ function installLocalStoragePolyfill() {
|
|
|
12
12
|
localStorage.setItem(testKey, testKey);
|
|
13
13
|
localStorage.removeItem(testKey);
|
|
14
14
|
localStorageWorks = true;
|
|
15
|
-
} catch
|
|
15
|
+
} catch {
|
|
16
16
|
console.warn("[HaexSpace] localStorage blocked \u2013 using in-memory fallback");
|
|
17
17
|
}
|
|
18
18
|
if (!localStorageWorks) {
|
|
@@ -43,7 +43,7 @@ function installLocalStoragePolyfill() {
|
|
|
43
43
|
writable: true,
|
|
44
44
|
configurable: true
|
|
45
45
|
});
|
|
46
|
-
} catch
|
|
46
|
+
} catch {
|
|
47
47
|
window.localStorage = localStoragePoly;
|
|
48
48
|
}
|
|
49
49
|
console.log("[HaexSpace] localStorage replaced with in-memory polyfill");
|
|
@@ -76,7 +76,7 @@ function installSessionStoragePolyfill() {
|
|
|
76
76
|
writable: true,
|
|
77
77
|
configurable: true
|
|
78
78
|
});
|
|
79
|
-
} catch
|
|
79
|
+
} catch {
|
|
80
80
|
window.sessionStorage = {
|
|
81
81
|
getItem: () => null,
|
|
82
82
|
setItem: () => {
|
|
@@ -103,7 +103,7 @@ function installCookiePolyfill() {
|
|
|
103
103
|
try {
|
|
104
104
|
document.cookie = "__cookie_test__=1";
|
|
105
105
|
cookiesWork = document.cookie.indexOf("__cookie_test__") !== -1;
|
|
106
|
-
} catch
|
|
106
|
+
} catch {
|
|
107
107
|
console.warn("[HaexSpace] Cookies blocked \u2013 using in-memory fallback");
|
|
108
108
|
}
|
|
109
109
|
if (!cookiesWork) {
|
|
@@ -361,7 +361,6 @@ function installPolyfills() {
|
|
|
361
361
|
installSessionStoragePolyfill();
|
|
362
362
|
installCookiePolyfill();
|
|
363
363
|
installHistoryPolyfill();
|
|
364
|
-
console.log("[HaexSpace] All polyfills loaded successfully");
|
|
365
364
|
installDebugDiagnostics();
|
|
366
365
|
}
|
|
367
366
|
if (typeof window !== "undefined") {
|
|
@@ -1827,15 +1826,14 @@ async function initNativeMode(ctx, log, onEvent, onContextChange) {
|
|
|
1827
1826
|
}
|
|
1828
1827
|
async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
1829
1828
|
const { listen } = getTauriEvent();
|
|
1830
|
-
|
|
1829
|
+
log("Setting up Tauri event listener for:", HAEXTENSION_EVENTS.CONTEXT_CHANGED);
|
|
1831
1830
|
try {
|
|
1832
1831
|
await listen(HAEXTENSION_EVENTS.CONTEXT_CHANGED, (event) => {
|
|
1833
|
-
|
|
1834
|
-
log("Received context change event:", event);
|
|
1832
|
+
log("Received Tauri event:", HAEXTENSION_EVENTS.CONTEXT_CHANGED, event);
|
|
1835
1833
|
const payload = event.payload;
|
|
1836
1834
|
if (payload?.context) {
|
|
1837
1835
|
ctx.state.context = payload.context;
|
|
1838
|
-
|
|
1836
|
+
log("Updated context to:", ctx.state.context);
|
|
1839
1837
|
onContextChange(payload.context);
|
|
1840
1838
|
onEvent({
|
|
1841
1839
|
type: HAEXTENSION_EVENTS.CONTEXT_CHANGED,
|
|
@@ -1843,19 +1841,17 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
|
1843
1841
|
timestamp: Date.now()
|
|
1844
1842
|
});
|
|
1845
1843
|
} else {
|
|
1846
|
-
|
|
1844
|
+
log("Event received but no context in payload:", event);
|
|
1847
1845
|
}
|
|
1848
1846
|
});
|
|
1849
|
-
|
|
1847
|
+
log("Context change listener registered successfully");
|
|
1850
1848
|
} catch (error) {
|
|
1851
|
-
console.error("[HaexVault SDK] Failed to setup context change listener:", error);
|
|
1852
1849
|
log("Failed to setup context change listener:", error);
|
|
1853
1850
|
}
|
|
1854
1851
|
try {
|
|
1855
1852
|
await listen(EXTERNAL_EVENTS.REQUEST, (event) => {
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
log("Received external request event:", event);
|
|
1853
|
+
log("====== EXTERNAL REQUEST RECEIVED ======");
|
|
1854
|
+
log("Event payload:", JSON.stringify(event.payload, null, 2));
|
|
1859
1855
|
if (event.payload) {
|
|
1860
1856
|
onEvent({
|
|
1861
1857
|
type: EXTERNAL_EVENTS.REQUEST,
|
|
@@ -1863,19 +1859,17 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
|
1863
1859
|
timestamp: Date.now()
|
|
1864
1860
|
});
|
|
1865
1861
|
} else {
|
|
1866
|
-
|
|
1862
|
+
log("External request event has no payload!");
|
|
1867
1863
|
}
|
|
1868
1864
|
});
|
|
1869
|
-
|
|
1865
|
+
log("External request listener registered successfully");
|
|
1870
1866
|
} catch (error) {
|
|
1871
|
-
console.error("[HaexVault SDK] Failed to setup external request listener:", error);
|
|
1872
1867
|
log("Failed to setup external request listener:", error);
|
|
1873
1868
|
}
|
|
1874
|
-
|
|
1869
|
+
log("Registering file change listener for:", HAEXTENSION_EVENTS.FILE_CHANGED);
|
|
1875
1870
|
try {
|
|
1876
1871
|
await listen(HAEXTENSION_EVENTS.FILE_CHANGED, (event) => {
|
|
1877
|
-
|
|
1878
|
-
log("Received file change event:", event);
|
|
1872
|
+
log("File change event received:", event.payload);
|
|
1879
1873
|
if (event.payload) {
|
|
1880
1874
|
const payload = event.payload;
|
|
1881
1875
|
onEvent({
|
|
@@ -1887,16 +1881,14 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
|
1887
1881
|
});
|
|
1888
1882
|
}
|
|
1889
1883
|
});
|
|
1890
|
-
|
|
1884
|
+
log("File change listener registered successfully");
|
|
1891
1885
|
} catch (error) {
|
|
1892
|
-
console.error("[HaexVault SDK] Failed to setup file change listener:", error);
|
|
1893
1886
|
log("Failed to setup file change listener:", error);
|
|
1894
1887
|
}
|
|
1895
|
-
|
|
1888
|
+
log("Registering sync tables updated listener for:", HAEXTENSION_EVENTS.SYNC_TABLES_UPDATED);
|
|
1896
1889
|
try {
|
|
1897
1890
|
await listen(HAEXTENSION_EVENTS.SYNC_TABLES_UPDATED, (event) => {
|
|
1898
|
-
|
|
1899
|
-
log("Received sync tables updated event:", event);
|
|
1891
|
+
log("Sync tables updated event received:", event.payload);
|
|
1900
1892
|
if (event.payload) {
|
|
1901
1893
|
const payload = event.payload;
|
|
1902
1894
|
onEvent({
|
|
@@ -1906,25 +1898,23 @@ async function setupTauriEventListeners(ctx, log, onEvent, onContextChange) {
|
|
|
1906
1898
|
});
|
|
1907
1899
|
}
|
|
1908
1900
|
});
|
|
1909
|
-
|
|
1901
|
+
log("Sync tables updated listener registered successfully");
|
|
1910
1902
|
} catch (error) {
|
|
1911
|
-
console.error("[HaexVault SDK] Failed to setup sync tables updated listener:", error);
|
|
1912
1903
|
log("Failed to setup sync tables updated listener:", error);
|
|
1913
1904
|
}
|
|
1914
|
-
|
|
1905
|
+
log("Setting up LocalSend event listeners");
|
|
1915
1906
|
try {
|
|
1916
1907
|
await setupLocalSendEventListeners(log, onEvent);
|
|
1917
|
-
|
|
1908
|
+
log("LocalSend event listeners setup complete");
|
|
1918
1909
|
} catch (error) {
|
|
1919
|
-
|
|
1910
|
+
log("Failed to setup LocalSend event listeners:", error);
|
|
1920
1911
|
}
|
|
1921
1912
|
}
|
|
1922
1913
|
async function setupLocalSendEventListeners(log, onEvent) {
|
|
1923
1914
|
const { listen } = getTauriEvent();
|
|
1924
1915
|
try {
|
|
1925
1916
|
await listen(LOCALSEND_EVENTS.deviceDiscovered, (event) => {
|
|
1926
|
-
|
|
1927
|
-
log("Received LocalSend device discovered event:", event);
|
|
1917
|
+
log("LocalSend device discovered:", event.payload);
|
|
1928
1918
|
if (event.payload) {
|
|
1929
1919
|
onEvent({
|
|
1930
1920
|
type: LOCALSEND_EVENTS.deviceDiscovered,
|
|
@@ -1933,14 +1923,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
|
|
|
1933
1923
|
});
|
|
1934
1924
|
}
|
|
1935
1925
|
});
|
|
1936
|
-
|
|
1926
|
+
log("LocalSend device discovered listener registered");
|
|
1937
1927
|
} catch (error) {
|
|
1938
|
-
|
|
1928
|
+
log("Failed to setup LocalSend device discovered listener:", error);
|
|
1939
1929
|
}
|
|
1940
1930
|
try {
|
|
1941
1931
|
await listen(LOCALSEND_EVENTS.deviceLost, (event) => {
|
|
1942
|
-
|
|
1943
|
-
log("Received LocalSend device lost event:", event);
|
|
1932
|
+
log("LocalSend device lost:", event.payload);
|
|
1944
1933
|
if (event.payload) {
|
|
1945
1934
|
onEvent({
|
|
1946
1935
|
type: LOCALSEND_EVENTS.deviceLost,
|
|
@@ -1949,14 +1938,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
|
|
|
1949
1938
|
});
|
|
1950
1939
|
}
|
|
1951
1940
|
});
|
|
1952
|
-
|
|
1941
|
+
log("LocalSend device lost listener registered");
|
|
1953
1942
|
} catch (error) {
|
|
1954
|
-
|
|
1943
|
+
log("Failed to setup LocalSend device lost listener:", error);
|
|
1955
1944
|
}
|
|
1956
1945
|
try {
|
|
1957
1946
|
await listen(LOCALSEND_EVENTS.transferRequest, (event) => {
|
|
1958
|
-
|
|
1959
|
-
log("Received LocalSend transfer request event:", event);
|
|
1947
|
+
log("LocalSend transfer request:", event.payload);
|
|
1960
1948
|
if (event.payload) {
|
|
1961
1949
|
onEvent({
|
|
1962
1950
|
type: LOCALSEND_EVENTS.transferRequest,
|
|
@@ -1965,13 +1953,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
|
|
|
1965
1953
|
});
|
|
1966
1954
|
}
|
|
1967
1955
|
});
|
|
1968
|
-
|
|
1956
|
+
log("LocalSend transfer request listener registered");
|
|
1969
1957
|
} catch (error) {
|
|
1970
|
-
|
|
1958
|
+
log("Failed to setup LocalSend transfer request listener:", error);
|
|
1971
1959
|
}
|
|
1972
1960
|
try {
|
|
1973
1961
|
await listen(LOCALSEND_EVENTS.transferProgress, (event) => {
|
|
1974
|
-
log("
|
|
1962
|
+
log("LocalSend transfer progress event:", event);
|
|
1975
1963
|
if (event.payload) {
|
|
1976
1964
|
onEvent({
|
|
1977
1965
|
type: LOCALSEND_EVENTS.transferProgress,
|
|
@@ -1980,14 +1968,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
|
|
|
1980
1968
|
});
|
|
1981
1969
|
}
|
|
1982
1970
|
});
|
|
1983
|
-
|
|
1971
|
+
log("LocalSend transfer progress listener registered");
|
|
1984
1972
|
} catch (error) {
|
|
1985
|
-
|
|
1973
|
+
log("Failed to setup LocalSend transfer progress listener:", error);
|
|
1986
1974
|
}
|
|
1987
1975
|
try {
|
|
1988
1976
|
await listen(LOCALSEND_EVENTS.transferComplete, (event) => {
|
|
1989
|
-
|
|
1990
|
-
log("Received LocalSend transfer complete event:", event);
|
|
1977
|
+
log("LocalSend transfer complete:", event.payload);
|
|
1991
1978
|
if (event.payload) {
|
|
1992
1979
|
onEvent({
|
|
1993
1980
|
type: LOCALSEND_EVENTS.transferComplete,
|
|
@@ -1996,14 +1983,13 @@ async function setupLocalSendEventListeners(log, onEvent) {
|
|
|
1996
1983
|
});
|
|
1997
1984
|
}
|
|
1998
1985
|
});
|
|
1999
|
-
|
|
1986
|
+
log("LocalSend transfer complete listener registered");
|
|
2000
1987
|
} catch (error) {
|
|
2001
|
-
|
|
1988
|
+
log("Failed to setup LocalSend transfer complete listener:", error);
|
|
2002
1989
|
}
|
|
2003
1990
|
try {
|
|
2004
1991
|
await listen(LOCALSEND_EVENTS.transferFailed, (event) => {
|
|
2005
|
-
|
|
2006
|
-
log("Received LocalSend transfer failed event:", event);
|
|
1992
|
+
log("LocalSend transfer failed:", event.payload);
|
|
2007
1993
|
if (event.payload) {
|
|
2008
1994
|
onEvent({
|
|
2009
1995
|
type: LOCALSEND_EVENTS.transferFailed,
|
|
@@ -2012,9 +1998,9 @@ async function setupLocalSendEventListeners(log, onEvent) {
|
|
|
2012
1998
|
});
|
|
2013
1999
|
}
|
|
2014
2000
|
});
|
|
2015
|
-
|
|
2001
|
+
log("LocalSend transfer failed listener registered");
|
|
2016
2002
|
} catch (error) {
|
|
2017
|
-
|
|
2003
|
+
log("Failed to setup LocalSend transfer failed listener:", error);
|
|
2018
2004
|
}
|
|
2019
2005
|
}
|
|
2020
2006
|
async function initIframeMode(ctx, log, messageHandler, request) {
|
|
@@ -2232,7 +2218,7 @@ function createDrizzleInstance(schema, extensionInfo, request, log) {
|
|
|
2232
2218
|
if (result2.rows && Array.isArray(result2.rows) && result2.rows.length > 0) {
|
|
2233
2219
|
return { rows: result2.rows };
|
|
2234
2220
|
}
|
|
2235
|
-
return
|
|
2221
|
+
return { rows: [] };
|
|
2236
2222
|
}
|
|
2237
2223
|
const result = await request(DATABASE_COMMANDS.query, {
|
|
2238
2224
|
sql,
|
|
@@ -2240,7 +2226,7 @@ function createDrizzleInstance(schema, extensionInfo, request, log) {
|
|
|
2240
2226
|
});
|
|
2241
2227
|
const rows = result.rows;
|
|
2242
2228
|
if (method === "get") {
|
|
2243
|
-
return { rows: rows.length > 0 ? rows
|
|
2229
|
+
return { rows: rows.length > 0 ? [rows[0]] : [] };
|
|
2244
2230
|
}
|
|
2245
2231
|
return { rows };
|
|
2246
2232
|
} catch (error) {
|
|
@@ -2756,6 +2742,148 @@ async function verifyExtensionSignature(files, manifest) {
|
|
|
2756
2742
|
}
|
|
2757
2743
|
}
|
|
2758
2744
|
|
|
2745
|
+
// src/crypto/userKeypair.ts
|
|
2746
|
+
var SIGNING_ALGO = { name: "ECDSA", namedCurve: "P-256" };
|
|
2747
|
+
var KEY_AGREEMENT_ALGO = { name: "ECDH", namedCurve: "P-256" };
|
|
2748
|
+
async function generateUserKeypairAsync() {
|
|
2749
|
+
const keypair = await crypto.subtle.generateKey(SIGNING_ALGO, true, ["sign", "verify"]);
|
|
2750
|
+
return { publicKey: keypair.publicKey, privateKey: keypair.privateKey };
|
|
2751
|
+
}
|
|
2752
|
+
async function exportUserKeypairAsync(keypair) {
|
|
2753
|
+
const pub = await crypto.subtle.exportKey("spki", keypair.publicKey);
|
|
2754
|
+
const priv = await crypto.subtle.exportKey("pkcs8", keypair.privateKey);
|
|
2755
|
+
return { publicKey: arrayBufferToBase64(pub), privateKey: arrayBufferToBase64(priv) };
|
|
2756
|
+
}
|
|
2757
|
+
async function importUserPublicKeyAsync(base64) {
|
|
2758
|
+
return crypto.subtle.importKey("spki", base64ToArrayBuffer(base64), SIGNING_ALGO, true, ["verify"]);
|
|
2759
|
+
}
|
|
2760
|
+
async function importUserPrivateKeyAsync(base64) {
|
|
2761
|
+
return crypto.subtle.importKey("pkcs8", base64ToArrayBuffer(base64), SIGNING_ALGO, true, ["sign"]);
|
|
2762
|
+
}
|
|
2763
|
+
async function importPublicKeyForKeyAgreementAsync(base64) {
|
|
2764
|
+
return crypto.subtle.importKey("spki", base64ToArrayBuffer(base64), KEY_AGREEMENT_ALGO, true, []);
|
|
2765
|
+
}
|
|
2766
|
+
async function importPrivateKeyForKeyAgreementAsync(base64) {
|
|
2767
|
+
return crypto.subtle.importKey("pkcs8", base64ToArrayBuffer(base64), KEY_AGREEMENT_ALGO, true, ["deriveBits"]);
|
|
2768
|
+
}
|
|
2769
|
+
async function encryptPrivateKeyAsync(privateKeyBase64, password) {
|
|
2770
|
+
const salt = crypto.getRandomValues(new Uint8Array(32));
|
|
2771
|
+
const derivedKey = await deriveKeyFromPassword(password, salt);
|
|
2772
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2773
|
+
const encrypted = await crypto.subtle.encrypt(
|
|
2774
|
+
{ name: "AES-GCM", iv: nonce },
|
|
2775
|
+
derivedKey,
|
|
2776
|
+
new TextEncoder().encode(privateKeyBase64)
|
|
2777
|
+
);
|
|
2778
|
+
return {
|
|
2779
|
+
encryptedPrivateKey: arrayBufferToBase64(encrypted),
|
|
2780
|
+
nonce: arrayBufferToBase64(nonce),
|
|
2781
|
+
salt: arrayBufferToBase64(salt)
|
|
2782
|
+
};
|
|
2783
|
+
}
|
|
2784
|
+
async function decryptPrivateKeyAsync(encryptedPrivateKey, nonce, salt, password) {
|
|
2785
|
+
const derivedKey = await deriveKeyFromPassword(password, base64ToArrayBuffer(salt));
|
|
2786
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
2787
|
+
{ name: "AES-GCM", iv: base64ToArrayBuffer(nonce) },
|
|
2788
|
+
derivedKey,
|
|
2789
|
+
base64ToArrayBuffer(encryptedPrivateKey)
|
|
2790
|
+
);
|
|
2791
|
+
return new TextDecoder().decode(decrypted);
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
// src/crypto/spaceKey.ts
|
|
2795
|
+
function generateSpaceKey() {
|
|
2796
|
+
return generateVaultKey();
|
|
2797
|
+
}
|
|
2798
|
+
async function encryptSpaceKeyForRecipientAsync(spaceKey, recipientPublicKeyBase64) {
|
|
2799
|
+
const ephemeral = await crypto.subtle.generateKey(KEY_AGREEMENT_ALGO, true, ["deriveBits"]);
|
|
2800
|
+
const recipientKey = await importPublicKeyForKeyAgreementAsync(recipientPublicKeyBase64);
|
|
2801
|
+
const sharedBits = await crypto.subtle.deriveBits(
|
|
2802
|
+
{ name: "ECDH", public: recipientKey },
|
|
2803
|
+
ephemeral.privateKey,
|
|
2804
|
+
256
|
|
2805
|
+
);
|
|
2806
|
+
const aesKey = await crypto.subtle.deriveKey(
|
|
2807
|
+
{
|
|
2808
|
+
name: "HKDF",
|
|
2809
|
+
hash: "SHA-256",
|
|
2810
|
+
salt: new Uint8Array(0),
|
|
2811
|
+
info: new TextEncoder().encode("haex-space-key")
|
|
2812
|
+
},
|
|
2813
|
+
await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveKey"]),
|
|
2814
|
+
{ name: "AES-GCM", length: 256 },
|
|
2815
|
+
false,
|
|
2816
|
+
["encrypt"]
|
|
2817
|
+
);
|
|
2818
|
+
const nonce = crypto.getRandomValues(new Uint8Array(12));
|
|
2819
|
+
const encrypted = await crypto.subtle.encrypt({ name: "AES-GCM", iv: nonce }, aesKey, spaceKey);
|
|
2820
|
+
const ephPub = await crypto.subtle.exportKey("spki", ephemeral.publicKey);
|
|
2821
|
+
return {
|
|
2822
|
+
encryptedSpaceKey: arrayBufferToBase64(encrypted),
|
|
2823
|
+
keyNonce: arrayBufferToBase64(nonce),
|
|
2824
|
+
ephemeralPublicKey: arrayBufferToBase64(ephPub)
|
|
2825
|
+
};
|
|
2826
|
+
}
|
|
2827
|
+
async function decryptSpaceKeyAsync(encrypted, ownPrivateKeyBase64) {
|
|
2828
|
+
const ephPubKey = await crypto.subtle.importKey(
|
|
2829
|
+
"spki",
|
|
2830
|
+
base64ToArrayBuffer(encrypted.ephemeralPublicKey),
|
|
2831
|
+
KEY_AGREEMENT_ALGO,
|
|
2832
|
+
true,
|
|
2833
|
+
[]
|
|
2834
|
+
);
|
|
2835
|
+
const ownPrivKey = await importPrivateKeyForKeyAgreementAsync(ownPrivateKeyBase64);
|
|
2836
|
+
const sharedBits = await crypto.subtle.deriveBits(
|
|
2837
|
+
{ name: "ECDH", public: ephPubKey },
|
|
2838
|
+
ownPrivKey,
|
|
2839
|
+
256
|
|
2840
|
+
);
|
|
2841
|
+
const aesKey = await crypto.subtle.deriveKey(
|
|
2842
|
+
{
|
|
2843
|
+
name: "HKDF",
|
|
2844
|
+
hash: "SHA-256",
|
|
2845
|
+
salt: new Uint8Array(0),
|
|
2846
|
+
info: new TextEncoder().encode("haex-space-key")
|
|
2847
|
+
},
|
|
2848
|
+
await crypto.subtle.importKey("raw", sharedBits, "HKDF", false, ["deriveKey"]),
|
|
2849
|
+
{ name: "AES-GCM", length: 256 },
|
|
2850
|
+
false,
|
|
2851
|
+
["decrypt"]
|
|
2852
|
+
);
|
|
2853
|
+
const decrypted = await crypto.subtle.decrypt(
|
|
2854
|
+
{ name: "AES-GCM", iv: base64ToArrayBuffer(encrypted.keyNonce) },
|
|
2855
|
+
aesKey,
|
|
2856
|
+
base64ToArrayBuffer(encrypted.encryptedSpaceKey)
|
|
2857
|
+
);
|
|
2858
|
+
return new Uint8Array(decrypted);
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
// src/crypto/recordSigning.ts
|
|
2862
|
+
function canonicalize(record) {
|
|
2863
|
+
const parts = [
|
|
2864
|
+
record.tableName,
|
|
2865
|
+
record.rowPks,
|
|
2866
|
+
record.columnName === null ? "NULL" : record.columnName,
|
|
2867
|
+
record.encryptedValue === null ? "NULL" : record.encryptedValue,
|
|
2868
|
+
record.hlcTimestamp
|
|
2869
|
+
].join("\0");
|
|
2870
|
+
return new TextEncoder().encode(parts);
|
|
2871
|
+
}
|
|
2872
|
+
async function signRecordAsync(record, privateKeyBase64) {
|
|
2873
|
+
const key = await importUserPrivateKeyAsync(privateKeyBase64);
|
|
2874
|
+
const sig = await crypto.subtle.sign({ name: "ECDSA", hash: "SHA-256" }, key, canonicalize(record));
|
|
2875
|
+
return arrayBufferToBase64(sig);
|
|
2876
|
+
}
|
|
2877
|
+
async function verifyRecordSignatureAsync(record, signatureBase64, publicKeyBase64) {
|
|
2878
|
+
const key = await importUserPublicKeyAsync(publicKeyBase64);
|
|
2879
|
+
return crypto.subtle.verify(
|
|
2880
|
+
{ name: "ECDSA", hash: "SHA-256" },
|
|
2881
|
+
key,
|
|
2882
|
+
base64ToArrayBuffer(signatureBase64),
|
|
2883
|
+
canonicalize(record)
|
|
2884
|
+
);
|
|
2885
|
+
}
|
|
2886
|
+
|
|
2759
2887
|
// src/crypto/passkey.ts
|
|
2760
2888
|
function toArrayBuffer(data) {
|
|
2761
2889
|
if (data instanceof ArrayBuffer) {
|
|
@@ -2926,6 +3054,6 @@ function createHaexVaultSdk(config = {}) {
|
|
|
2926
3054
|
return new HaexVaultSdk(config);
|
|
2927
3055
|
}
|
|
2928
3056
|
|
|
2929
|
-
export { COSE_ALGORITHM, DEFAULT_TIMEOUT, DatabaseAPI, EXTERNAL_EVENTS, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, LOCALSEND_EVENTS, LocalSendAPI, PermissionErrorCode, PermissionStatus, PermissionsAPI, RemoteStorageAPI, TABLE_SEPARATOR, TAURI_COMMANDS, WebAPI, arrayBufferToBase64, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptString, encryptVaultKey, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, generateCredentialId, generatePasskeyPairAsync, generateVaultKey, getTableName, hexToBytes, importPrivateKeyAsync, importPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, isPermissionDeniedError, isPermissionError, isPermissionPromptError, signWithPasskeyAsync, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, verifyWithPasskeyAsync, wrapKey };
|
|
3057
|
+
export { COSE_ALGORITHM, DEFAULT_TIMEOUT, DatabaseAPI, EXTERNAL_EVENTS, ErrorCode, ExternalConnectionErrorCode, ExternalConnectionState, FilesystemAPI, HAEXSPACE_MESSAGE_TYPES, HAEXTENSION_EVENTS, HaexVaultSdk, HaexVaultSdkError, KEY_AGREEMENT_ALGO, LOCALSEND_EVENTS, LocalSendAPI, PermissionErrorCode, PermissionStatus, PermissionsAPI, RemoteStorageAPI, SIGNING_ALGO, TABLE_SEPARATOR, TAURI_COMMANDS, WebAPI, arrayBufferToBase64, base64ToArrayBuffer, canExternalClientSendRequests, createHaexVaultSdk, decryptCrdtData, decryptPrivateKeyAsync, decryptSpaceKeyAsync, decryptString, decryptVaultKey, decryptVaultName, deriveKeyFromPassword, encryptCrdtData, encryptPrivateKeyAsync, encryptSpaceKeyForRecipientAsync, encryptString, encryptVaultKey, exportKeyPairAsync, exportPrivateKeyAsync, exportPublicKeyAsync, exportPublicKeyCoseAsync, exportUserKeypairAsync, generateCredentialId, generatePasskeyPairAsync, generateSpaceKey, generateUserKeypairAsync, generateVaultKey, getTableName, hexToBytes, importPrivateKeyAsync, importPrivateKeyForKeyAgreementAsync, importPublicKeyAsync, importPublicKeyForKeyAgreementAsync, importUserPrivateKeyAsync, importUserPublicKeyAsync, installBaseTag, installCookiePolyfill, installHistoryPolyfill, installLocalStoragePolyfill, installPolyfills, installSessionStoragePolyfill, isExternalClientConnected, isPermissionDeniedError, isPermissionError, isPermissionPromptError, signRecordAsync, signWithPasskeyAsync, sortObjectKeysRecursively, unwrapKey, verifyExtensionSignature, verifyRecordSignatureAsync, verifyWithPasskeyAsync, wrapKey };
|
|
2930
3058
|
//# sourceMappingURL=index.mjs.map
|
|
2931
3059
|
//# sourceMappingURL=index.mjs.map
|