@nexys/zk-store 0.1.12 → 0.1.14

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/shares.d.ts CHANGED
@@ -1,14 +1,21 @@
1
- import type { JoinedShare, ShareManifest, Tree } from "./types";
1
+ import type { JoinedShare, OwnedShare, ShareManifest, Tree } from "./types";
2
+ /** What a member may do: read the files, or also save new versions. */
3
+ export type MemberRole = "viewer" | "editor";
2
4
  export type ShareMember = {
3
5
  memberId: string;
4
6
  name: string;
5
7
  joinedAt: number;
8
+ role: MemberRole;
6
9
  };
7
10
  export type ShareInfo = {
8
11
  role: "owner" | "member";
9
12
  manifest: ShareManifest;
10
13
  members: ShareMember[];
11
14
  linkActive: boolean;
15
+ /** The role people get by joining through the link. */
16
+ linkRole: MemberRole;
17
+ /** Whether this vault may save new versions of the share's files. */
18
+ canEdit: boolean;
12
19
  };
13
20
  /** Thrown when the owner removed this vault or stopped sharing. */
14
21
  export declare class AccessRemovedError extends Error {
@@ -26,11 +33,21 @@ export declare function parseShareHash(hash: string): {
26
33
  } | null;
27
34
  /** The folder and everything under it, as ids. */
28
35
  export declare function folderSubtree(tree: Tree, root: string): Set<string>;
36
+ export declare function ownedShareKey(share: OwnedShare, userKey: CryptoKey): Promise<CryptoKey>;
37
+ /**
38
+ * The key of a share this vault owns or joined (null if neither), for
39
+ * example to open its live channels.
40
+ */
41
+ export declare function shareKeyFor(userKey: CryptoKey, tree: Tree, shareId: string): Promise<CryptoKey | null>;
29
42
  export declare function joinedShareKey(share: JoinedShare, userKey: CryptoKey): Promise<CryptoKey>;
30
43
  /** The share of this item, if the vault already made one. */
31
44
  export declare function findShare(tree: Tree, kind: "file" | "folder", target: string): string | null;
32
- /** Shares a file or folder and returns the share id and its link. */
33
- export declare function createShare(userKey: CryptoKey, kind: "file" | "folder", target: string): Promise<{
45
+ /**
46
+ * Shares a file or folder and returns the share id and its link. People who
47
+ * join through the link get `linkRole` (viewer unless you say editor). If
48
+ * the item is already shared, returns that share unchanged.
49
+ */
50
+ export declare function createShare(userKey: CryptoKey, kind: "file" | "folder", target: string, linkRole?: MemberRole): Promise<{
34
51
  shareId: string;
35
52
  url: string;
36
53
  }>;
@@ -40,8 +57,14 @@ export declare function getOwnedShare(userKey: CryptoKey, tree: Tree, shareId: s
40
57
  /** How many people have joined each of this vault's shares, by share id. */
41
58
  export declare function memberCounts(userKey: CryptoKey, tree: Tree): Promise<Record<string, number>>;
42
59
  export declare function removeMember(shareId: string, memberId: string): Promise<void>;
43
- /** Replaces the link: the old one stops working, members keep access. */
44
- export declare function resetLink(userKey: CryptoKey, shareId: string): Promise<string>;
60
+ /** Makes a member a viewer or an editor. Owner only. */
61
+ export declare function setMemberRole(shareId: string, memberId: string, role: MemberRole): Promise<void>;
62
+ /**
63
+ * Replaces the link: the old one stops working, members keep access and
64
+ * their roles. Pass `linkRole` to change what joining gives; left out, the
65
+ * new link gives what the old one did.
66
+ */
67
+ export declare function resetLink(userKey: CryptoKey, shareId: string, linkRole?: MemberRole): Promise<string>;
45
68
  /** Turns the link off: nobody new can join, members keep access. */
46
69
  export declare function disableLink(userKey: CryptoKey, shareId: string): Promise<void>;
47
70
  /** Stops sharing; everyone who joined loses access. */
@@ -57,16 +80,31 @@ export declare function previewLink(shareId: string, linkKeyRaw: Uint8Array): Pr
57
80
  manifest: ShareManifest;
58
81
  shareKeyRaw: Uint8Array;
59
82
  proof: string;
83
+ linkRole: MemberRole;
60
84
  }>;
61
85
  /** Joins a share as `name` and records it under "Shared with me". */
62
86
  export declare function joinShare(userKey: CryptoKey, shareId: string, linkKeyRaw: Uint8Array, name: string): Promise<void>;
63
87
  /** Opens a share this vault joined, with the latest manifest. */
64
88
  export declare function openJoinedShare(userKey: CryptoKey, share: JoinedShare, shareId: string): Promise<ShareInfo>;
65
89
  export declare function leaveShare(userKey: CryptoKey, shareId: string, share: JoinedShare): Promise<void>;
66
- /** Downloads and decrypts one file from a share. */
90
+ /**
91
+ * Downloads and decrypts one file from a share. `etag` names this version:
92
+ * pass it to `saveSharedFile` so a save never replaces a newer one unseen.
93
+ */
67
94
  export declare function downloadSharedFile(shareId: string, shareKey: CryptoKey, uuid: string, manifest: ShareManifest): Promise<{
68
95
  name: string;
69
96
  data: ArrayBuffer;
97
+ etag: string;
70
98
  }>;
99
+ /**
100
+ * Saves a new version of a shared file, as an editor or the owner, and
101
+ * returns the new version's ETag. `etag` is the version the edit started
102
+ * from; if someone saved since, this throws `ConflictError` and nothing is
103
+ * written: download theirs, merge or choose, and save again.
104
+ *
105
+ * The file keeps its key, name and size in the owner's file list: the
106
+ * owner sees the new contents the next time they download it.
107
+ */
108
+ export declare function saveSharedFile(shareId: string, shareKey: CryptoKey, uuid: string, manifest: ShareManifest, data: ArrayBuffer | Uint8Array, etag: string): Promise<string>;
71
109
  /** Re-wraps every share key in a tree for a new userKey (key rotation). */
72
110
  export declare function rewrapShareKeys(tree: Tree, oldKey: CryptoKey, newKey: CryptoKey): Promise<Pick<Tree, "shares" | "sharedWithMe">>;
package/dist/types.d.ts CHANGED
@@ -36,6 +36,8 @@ export type JoinedShare = {
36
36
  wrappedShareKey: string;
37
37
  memberId: string;
38
38
  joinedAt: number;
39
+ /** Shares joined before roles existed are viewers. */
40
+ role?: "viewer" | "editor";
39
41
  };
40
42
  export type Subscription = {
41
43
  tier: "free" | "pro";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexys/zk-store",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Browser client for zk-store: zero-knowledge encrypted file storage. Files are encrypted before they leave the device.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,7 +34,7 @@
34
34
  "prepack": "bun run build"
35
35
  },
36
36
  "dependencies": {
37
- "@nexys/zk-store-crypto": "0.1.12",
37
+ "@nexys/zk-store-crypto": "0.1.14",
38
38
  "openapi-fetch": "^0.17.0"
39
39
  },
40
40
  "devDependencies": {