@nexys/zk-store 0.0.0-stage → 0.1.0

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/README.md CHANGED
@@ -1,3 +1,86 @@
1
- # Temporary Holding Version
1
+ # @nexys/zk-store
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Browser client for [ZK Store](https://github.com/johnb8005/zk-store):
4
+ zero-knowledge encrypted file storage. Files are encrypted in the browser
5
+ before they leave it; the server only stores ciphertext and wrapped keys.
6
+
7
+ Use it to build a web app on a ZK Store server with no backend of your own.
8
+
9
+ ```bash
10
+ npm install @nexys/zk-store
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```ts
16
+ import {
17
+ configure,
18
+ ensureCryptoReady,
19
+ createVault,
20
+ unlockWithRecoveryPhrase,
21
+ } from "@nexys/zk-store";
22
+
23
+ configure({ baseUrl: "https://zk.example.com" }); // your ZK Store server
24
+ await ensureCryptoReady(); // loads the WASM crypto
25
+
26
+ // A new vault. Show the phrase to the user: it is the only way back in.
27
+ const { vault, recoveryPhrase } = await createVault();
28
+
29
+ const id = await vault.upload("notes.txt", new TextEncoder().encode("hello"));
30
+ console.log(await vault.listFiles()); // [{ uuid, name, size, uploaded }]
31
+
32
+ // Later, or on another device:
33
+ const again = await unlockWithRecoveryPhrase(recoveryPhrase);
34
+ const { name, data } = await again.download(id); // data: ArrayBuffer
35
+ await again.delete(id);
36
+ again.lock();
37
+ ```
38
+
39
+ `upload` takes an `ArrayBuffer`, a `Uint8Array` or a `Blob` (a `File` from an
40
+ `<input type="file">` works as is).
41
+
42
+ ## Server setup
43
+
44
+ The server must let your site call it from the browser. It allows any origin
45
+ by default; to restrict it, set `CORS_ORIGINS` to a comma-separated list
46
+ (e.g. `https://app.example.com`). Allowing any origin is safe: no auth is in
47
+ cookies, and every call needs a token that only a holder of the vault key
48
+ can get.
49
+
50
+ Passkeys are tied to the server's `WEBAUTHN_RP_ID`. To use them from a site
51
+ on another domain, add the site to `WEBAUTHN_ORIGIN`; the server lists those
52
+ origins at `/.well-known/webauthn` (WebAuthn Related Origin Requests, in
53
+ recent Chrome and Safari). The recovery-phrase flow above works anywhere.
54
+
55
+ ## Loading the WASM
56
+
57
+ `ensureCryptoReady()` with no argument fetches `zk_store_crypto_bg.wasm`
58
+ from next to `@nexys/zk-store-crypto`'s JS. Vite and webpack 5 copy that file
59
+ for you. With other bundlers, serve the file yourself (it is in
60
+ `node_modules/@nexys/zk-store-crypto/pkg/`) and pass its URL:
61
+
62
+ ```ts
63
+ await ensureCryptoReady("/zk_store_crypto_bg.wasm");
64
+ ```
65
+
66
+ On a server runtime (Bun, Node, Deno), pass the bytes instead.
67
+
68
+ ## Lower-level API
69
+
70
+ Everything the ZK Store web app uses is exported too:
71
+
72
+ - **Crypto**: `generateKey`, `wrapKey`/`unwrapKey`, `encrypt`/`decrypt`,
73
+ `deriveKey`, `deriveRecoveryKey`, `generateRecoveryPhrase`, …
74
+ - **API calls**: `openVault`, `getBlob`/`putBlob`/`deleteBlob`, invites,
75
+ passkey ceremonies, subscriptions, and `client`, the typed
76
+ [openapi-fetch](https://openapi-ts.dev/openapi-fetch/) client.
77
+ - **File list**: `loadTree`, `updateTree` (retries on conflicts with other
78
+ devices), `loadFileList`.
79
+ - **Sharing**: `createShare`, `joinShare`, `downloadSharedFile`, … for
80
+ file and folder links.
81
+
82
+ The server's API is documented at `/docs` on any ZK Store server.
83
+
84
+ ## License
85
+
86
+ MIT