@biolibs/bionet-client 0.1.0 → 0.2.1

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,7 +1,8 @@
1
1
  # @biolibs/bionet-client
2
2
 
3
3
  One device in one lab: its key, its copy of the lab's signed log, everything a member can do, and the
4
- connection to the lab's web peer. It works with no network and syncs when there is one.
4
+ connection to the lab's web peer. It works with no network and syncs when there is one. A member can
5
+ keep parts and tubes, say where each is, record a run at the bench, and back up the key and the lab.
5
6
 
6
7
  It is an application with the edges left open. Where entries are kept, where the key lives and what
7
8
  opens a socket are handed in, so the same `Lab` runs behind a desktop window, in a browser or in a test.
@@ -50,6 +51,61 @@ guards it; `memoryKeys()` is for tests.
50
51
  2. The keeper adds it, `lab.addMember({ key, person })`, and sends back `lab.invite`.
51
52
  3. The new member calls `lab.join(invite)`. The lab arrives once the keeper's change reaches the peer.
52
53
 
54
+ ## Where things are
55
+
56
+ ```ts
57
+ const freezer = await lab.addPlace({ kind: "freezer", name: "−80" });
58
+ const box = await lab.addPlace({ kind: "box", name: "Box 1", parent: freezer, grid: { rows: 9, columns: 9 } });
59
+ await lab.putItem({ item: tube, place: box, slot: { row: 0, column: 0 } });
60
+ lab.snapshot().lab?.places.length; // 2
61
+ ```
62
+
63
+ `movePlace`, `standPlace` (in metres, kept to the millimetre) and `retirePlace` do the rest. An
64
+ instrument can say which one it is: `addPlace({ kind: "instrument", name: "PCR", parent: bench, model: "thermocycler" })`.
65
+ `layoutFrom` in `@biolibs/bionet-space` turns the snapshot's lab into something that can be drawn.
66
+
67
+ ## Recording a run
68
+
69
+ ```ts
70
+ const done = await lab.recordRun({
71
+ kind: "pcr", instrument: thermocycler,
72
+ inputs: [{ item: template, amount: 1, role: "template" }],
73
+ outputs: [{ sequence: "GGATCACAGTCTACACTGCTCACTCC", name: "amplicon", amount: 50, unit: "µL" }],
74
+ });
75
+ done.items; // the IDs of the tubes it made
76
+ ```
77
+
78
+ `@biolibs/bionet-tools` works out what to pass for a PCR.
79
+
80
+ ## Backing up the key
81
+
82
+ A device's key never leaves it, with one exception: a lab with one member and one device ends when
83
+ the device does.
84
+
85
+ ```ts
86
+ const backup = await lab.backUp("several unrelated words"); // text to write to a file
87
+ // later, on a new device that is not in a lab yet:
88
+ await fresh.restore({ backup, passphrase: "several unrelated words" });
89
+ await fresh.join(invite); // and it carries on the same log
90
+ ```
91
+
92
+ The key is who you are; the lab itself is every signed change. `exportLab` writes all of them to a
93
+ file and `importLab` brings them back, so with both files a lab comes back on a new device with no
94
+ peer to ask:
95
+
96
+ ```ts
97
+ const copy = await lab.exportLab(); // every signed entry, as JSON
98
+ await fresh.restore({ backup, passphrase });
99
+ await fresh.importLab(copy); // the same lab, and it carries on the same log
100
+ ```
101
+
102
+ The copy is not sealed. Every entry in it is signed, so it cannot be altered without that showing,
103
+ but whoever reads the file reads the lab.
104
+
105
+ The key is sealed with AES-256-GCM under a key stretched from the passphrase by PBKDF2 (600,000
106
+ rounds of SHA-256). Nothing remembers the passphrase. `restore` is refused once a device is in a
107
+ lab: one key on two devices writes two histories the lab cannot tell apart.
108
+
53
109
  ## The window's side
54
110
 
55
111
  A window does not always share a process with the lab. It reaches one through a `LabSource`: the lab
@@ -0,0 +1,67 @@
1
+ /** The version of the sealed-key document. */
2
+ export declare const BACKUP_VERSION = 1;
3
+ /** How many rounds the passphrase is stretched by. */
4
+ export declare const BACKUP_ROUNDS = 600000;
5
+ /** The fewest characters a passphrase may have. */
6
+ export declare const SHORTEST_PASSPHRASE = 12;
7
+ /** A device's key, sealed under a passphrase. Every byte string is base64. */
8
+ export interface KeyBackup {
9
+ /** Which version of this document it is. */
10
+ bionet_key_backup: number;
11
+ /** The fingerprint of the key inside, so a person can tell which key a file holds without opening it. */
12
+ fingerprint: string;
13
+ /** How the passphrase becomes a key. */
14
+ kdf: {
15
+ name: "PBKDF2";
16
+ hash: "SHA-256";
17
+ iterations: number;
18
+ salt: string;
19
+ };
20
+ /** How the key was sealed. */
21
+ cipher: {
22
+ name: "AES-GCM";
23
+ iv: string;
24
+ };
25
+ /** The sealed key. */
26
+ sealed: string;
27
+ }
28
+ /**
29
+ * Seal a device's key under a passphrase.
30
+ *
31
+ * @param exported - The key, as `exportSigningKey` wrote it.
32
+ * @param passphrase - What it will take to open it again.
33
+ * @param options - `iterations` is only for tests, which cannot wait for the real number.
34
+ * @returns The sealed key, safe to write to a file.
35
+ * @throws If the passphrase is too short to be worth sealing anything with.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { exportSigningKey, generateSigningKey } from "@biolibs/opencloning";
40
+ * import { openKey, sealKey } from "@biolibs/bionet-client";
41
+ *
42
+ * const exported = await exportSigningKey(await generateSigningKey());
43
+ * const backup = await sealKey(exported, "correct horse battery staple");
44
+ * (await openKey(backup, "correct horse battery staple")) === exported; // true
45
+ * ```
46
+ */
47
+ export declare function sealKey(exported: string, passphrase: string, options?: {
48
+ iterations?: number;
49
+ }): Promise<KeyBackup>;
50
+ /**
51
+ * Read a sealed key, from the document or its text.
52
+ *
53
+ * @param value - What was in the file.
54
+ * @returns The sealed key.
55
+ * @throws If it is not one.
56
+ */
57
+ export declare function readBackup(value: unknown): KeyBackup;
58
+ /**
59
+ * Open a sealed key.
60
+ *
61
+ * @param backup - The sealed key, or the text of the file it was kept in.
62
+ * @param passphrase - What it was sealed under.
63
+ * @returns The key, as `exportSigningKey` wrote it.
64
+ * @throws If the passphrase is wrong, or the document has been changed.
65
+ */
66
+ export declare function openKey(backup: unknown, passphrase: string): Promise<string>;
67
+ //# sourceMappingURL=backup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backup.d.ts","sourceRoot":"","sources":["../src/backup.ts"],"names":[],"mappings":"AAYA,8CAA8C;AAC9C,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,sDAAsD;AACtD,eAAO,MAAM,aAAa,SAAU,CAAC;AAErC,mDAAmD;AACnD,eAAO,MAAM,mBAAmB,KAAK,CAAC;AAEtC,8EAA8E;AAC9E,MAAM,WAAW,SAAS;IACxB,4CAA4C;IAC5C,iBAAiB,EAAE,MAAM,CAAC;IAC1B,yGAAyG;IACzG,WAAW,EAAE,MAAM,CAAC;IACpB,wCAAwC;IACxC,GAAG,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,IAAI,EAAE,SAAS,CAAC;QAAC,UAAU,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3E,8BAA8B;IAC9B,MAAM,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACxC,sBAAsB;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB;AAWD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAgB7H;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAcpD;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAelF"}
package/dist/backup.js ADDED
@@ -0,0 +1,111 @@
1
+ /**
2
+ * A device's key, sealed so that it can be kept somewhere else.
3
+ *
4
+ * A device's key never leaves the device, with one exception: a lab with one member and one device
5
+ * is a lab that ends when the device does. So the key can be written out sealed under a passphrase,
6
+ * as a small document to keep somewhere that is not this machine, and opened again on a new one.
7
+ *
8
+ * What is sealed is useless without the passphrase, and nothing here remembers it. A sealed key
9
+ * whose passphrase is forgotten is a lost key.
10
+ */
11
+ import { importSigningKey, keyFingerprint } from "@biolibs/opencloning";
12
+ /** The version of the sealed-key document. */
13
+ export const BACKUP_VERSION = 1;
14
+ /** How many rounds the passphrase is stretched by. */
15
+ export const BACKUP_ROUNDS = 600_000;
16
+ /** The fewest characters a passphrase may have. */
17
+ export const SHORTEST_PASSPHRASE = 12;
18
+ const toBase64 = (bytes) => btoa(String.fromCharCode(...bytes));
19
+ const fromBase64 = (text) => Uint8Array.from(atob(text), (letter) => letter.charCodeAt(0));
20
+ async function stretch(passphrase, salt, iterations) {
21
+ const subtle = globalThis.crypto.subtle;
22
+ const material = await subtle.importKey("raw", new TextEncoder().encode(passphrase.normalize("NFKC")), "PBKDF2", false, ["deriveKey"]);
23
+ return subtle.deriveKey({ name: "PBKDF2", hash: "SHA-256", salt, iterations }, material, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
24
+ }
25
+ /**
26
+ * Seal a device's key under a passphrase.
27
+ *
28
+ * @param exported - The key, as `exportSigningKey` wrote it.
29
+ * @param passphrase - What it will take to open it again.
30
+ * @param options - `iterations` is only for tests, which cannot wait for the real number.
31
+ * @returns The sealed key, safe to write to a file.
32
+ * @throws If the passphrase is too short to be worth sealing anything with.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { exportSigningKey, generateSigningKey } from "@biolibs/opencloning";
37
+ * import { openKey, sealKey } from "@biolibs/bionet-client";
38
+ *
39
+ * const exported = await exportSigningKey(await generateSigningKey());
40
+ * const backup = await sealKey(exported, "correct horse battery staple");
41
+ * (await openKey(backup, "correct horse battery staple")) === exported; // true
42
+ * ```
43
+ */
44
+ export async function sealKey(exported, passphrase, options = {}) {
45
+ if (passphrase.length < SHORTEST_PASSPHRASE) {
46
+ throw new Error(`A passphrase of at least ${SHORTEST_PASSPHRASE} characters. Several unrelated words work well.`);
47
+ }
48
+ const iterations = options.iterations ?? BACKUP_ROUNDS;
49
+ const salt = globalThis.crypto.getRandomValues(new Uint8Array(16));
50
+ const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));
51
+ const fingerprint = await keyFingerprint((await importSigningKey(exported)).publicKey);
52
+ const sealed = await globalThis.crypto.subtle.encrypt({ name: "AES-GCM", iv }, await stretch(passphrase, salt, iterations), new TextEncoder().encode(exported));
53
+ return {
54
+ bionet_key_backup: BACKUP_VERSION, fingerprint,
55
+ kdf: { name: "PBKDF2", hash: "SHA-256", iterations, salt: toBase64(salt) },
56
+ cipher: { name: "AES-GCM", iv: toBase64(iv) },
57
+ sealed: toBase64(new Uint8Array(sealed)),
58
+ };
59
+ }
60
+ /**
61
+ * Read a sealed key, from the document or its text.
62
+ *
63
+ * @param value - What was in the file.
64
+ * @returns The sealed key.
65
+ * @throws If it is not one.
66
+ */
67
+ export function readBackup(value) {
68
+ let found = value;
69
+ if (typeof found === "string") {
70
+ try {
71
+ found = JSON.parse(found);
72
+ }
73
+ catch {
74
+ throw new Error("That is not a key backup.");
75
+ }
76
+ }
77
+ const one = found;
78
+ const short = (text, most) => typeof text === "string" && text.length > 0 && text.length <= most;
79
+ if (one === null || typeof one !== "object" || one.bionet_key_backup !== BACKUP_VERSION || !short(one.fingerprint, 100)
80
+ || one.kdf?.name !== "PBKDF2" || one.kdf.hash !== "SHA-256" || !Number.isSafeInteger(one.kdf.iterations)
81
+ || one.kdf.iterations < 1 || one.kdf.iterations > 10_000_000 || !short(one.kdf.salt, 200)
82
+ || one.cipher?.name !== "AES-GCM" || !short(one.cipher.iv, 200) || !short(one.sealed, 20_000)) {
83
+ throw new Error("That is not a key backup.");
84
+ }
85
+ return one;
86
+ }
87
+ /**
88
+ * Open a sealed key.
89
+ *
90
+ * @param backup - The sealed key, or the text of the file it was kept in.
91
+ * @param passphrase - What it was sealed under.
92
+ * @returns The key, as `exportSigningKey` wrote it.
93
+ * @throws If the passphrase is wrong, or the document has been changed.
94
+ */
95
+ export async function openKey(backup, passphrase) {
96
+ const one = readBackup(backup);
97
+ let exported;
98
+ try {
99
+ const opened = await globalThis.crypto.subtle.decrypt({ name: "AES-GCM", iv: fromBase64(one.cipher.iv) }, await stretch(passphrase, fromBase64(one.kdf.salt), one.kdf.iterations), fromBase64(one.sealed));
100
+ exported = new TextDecoder().decode(opened);
101
+ }
102
+ catch {
103
+ throw new Error("That passphrase does not open this backup.");
104
+ }
105
+ // The fingerprint on the outside is not sealed, so it is checked against what was inside.
106
+ if (await keyFingerprint((await importSigningKey(exported)).publicKey) !== one.fingerprint) {
107
+ throw new Error("This backup does not hold the key it says it does.");
108
+ }
109
+ return exported;
110
+ }
111
+ //# sourceMappingURL=backup.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"backup.js","sourceRoot":"","sources":["../src/backup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAExE,8CAA8C;AAC9C,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC,sDAAsD;AACtD,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC;AAErC,mDAAmD;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAgBtC,MAAM,QAAQ,GAAG,CAAC,KAAiB,EAAU,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC;AACpF,MAAM,UAAU,GAAG,CAAC,IAAY,EAA2B,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAE5H,KAAK,UAAU,OAAO,CAAC,UAAkB,EAAE,IAA6B,EAAE,UAAkB;IAC1F,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;IACxC,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE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W,EAAE,CAAC;QAC3F,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IACxE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  * - `lab.ts` — the device: `Lab`, and the plain-data snapshot a window draws
14
14
  * - `link.ts` — the connection to the web peer, which is allowed to fail
15
15
  * - `source.ts` — the narrow way a window reaches a lab, in this process or another
16
+ * - `backup.ts` — the device's key, sealed under a passphrase to keep somewhere else
16
17
  * - `store.ts` — the interfaces for storage and key keeping, with in-memory versions
17
18
  * - `sqlite.ts` — storage in a SQLite file, at `@biolibs/bionet-client/sqlite` because it needs Node
18
19
  */
@@ -20,4 +21,5 @@ export * from "./lab.js";
20
21
  export * from "./link.js";
21
22
  export * from "./store.js";
22
23
  export * from "./source.js";
24
+ export * from "./backup.js";
23
25
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@
13
13
  * - `lab.ts` — the device: `Lab`, and the plain-data snapshot a window draws
14
14
  * - `link.ts` — the connection to the web peer, which is allowed to fail
15
15
  * - `source.ts` — the narrow way a window reaches a lab, in this process or another
16
+ * - `backup.ts` — the device's key, sealed under a passphrase to keep somewhere else
16
17
  * - `store.ts` — the interfaces for storage and key keeping, with in-memory versions
17
18
  * - `sqlite.ts` — storage in a SQLite file, at `@biolibs/bionet-client/sqlite` because it needs Node
18
19
  */
@@ -20,4 +21,5 @@ export * from "./lab.js";
20
21
  export * from "./link.js";
21
22
  export * from "./store.js";
22
23
  export * from "./source.js";
24
+ export * from "./backup.js";
23
25
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC"}
package/dist/lab.d.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * holds is worked out from the entries each time they change, by `mergeLog`, which is why two devices
11
11
  * that have been apart agree the moment they have each other's entries.
12
12
  */
13
- import { type EntryStatus, type ItemState, type Operation, type Overlap, type PartState, type Role, type RosterKey } from "@biolibs/bionet";
13
+ import { type Crowded, type EntryStatus, type ItemState, type Operation, type Overlap, type PartState, type PlaceState, type RunInput, type RunState, type Role, type RosterKey } from "@biolibs/bionet";
14
14
  import { type LinkStatus } from "./link.js";
15
15
  import type { KeyKeeper, LabStore } from "./store.js";
16
16
  /** One key on the roster, as a window shows it. */
@@ -46,6 +46,12 @@ export interface LabView {
46
46
  roster: RosterView[];
47
47
  parts: PartState[];
48
48
  items: ItemState[];
49
+ /** Every place. */
50
+ places: PlaceState[];
51
+ /** Positions the log says hold more than one item. */
52
+ crowded: Crowded[];
53
+ /** Everything done at the bench that was recorded. */
54
+ runs: RunState[];
49
55
  overlaps: Overlap[];
50
56
  /** How many entries are waiting on others that have not arrived. */
51
57
  waiting: number;
@@ -87,6 +93,8 @@ export interface LabOptions {
87
93
  /** Something to open sockets with. Defaults to the runtime's own `WebSocket`. */
88
94
  WebSocket?: typeof globalThis.WebSocket;
89
95
  }
96
+ /** The version of the document `exportLab` writes. */
97
+ export declare const LAB_COPY_VERSION = 1;
90
98
  /** @param peer - The peer's socket address. @returns The web address it serves from. */
91
99
  export declare function originOf(peer: string): string;
92
100
  /**
@@ -178,6 +186,48 @@ export declare class Lab {
178
186
  setPeer(peer: string | null): Promise<void>;
179
187
  /** @param origin - The web address the lab publishes from, if it is not the peer's own. */
180
188
  setOrigin(origin: string | null): Promise<void>;
189
+ /**
190
+ * Seal this device's key under a passphrase, to keep somewhere that is not this device.
191
+ *
192
+ * @param passphrase - What it will take to open it again. Nothing here remembers it.
193
+ * @returns The sealed key as text, to be written to a file. It holds nothing readable without the passphrase.
194
+ */
195
+ backUp(passphrase: string): Promise<string>;
196
+ /**
197
+ * Take up a key from a backup, in place of the one this device made for itself.
198
+ *
199
+ * This is for a new device standing in for a lost one, so it is refused once the device is in a
200
+ * lab: a key in use on two devices at once writes two histories under one name, and the lab
201
+ * cannot tell which is true.
202
+ *
203
+ * @param from - The text of the backup file, and the passphrase it was sealed under.
204
+ */
205
+ restore(from: {
206
+ backup: string;
207
+ passphrase: string;
208
+ }): Promise<void>;
209
+ /**
210
+ * Everything this device holds of the lab, as text to keep in a file.
211
+ *
212
+ * It is every signed entry, so it is the whole lab: with it and a key on the roster, the lab can
213
+ * be brought back on a new device with no peer to ask. It is not sealed. Every entry is signed,
214
+ * so a copy cannot be altered without that showing, but anybody who reads it reads the lab.
215
+ *
216
+ * @returns The copy, as JSON.
217
+ */
218
+ exportLab(): Promise<string>;
219
+ /**
220
+ * Bring a lab in from a copy made by `exportLab`.
221
+ *
222
+ * On a device that is in no lab, this puts it in the copy's lab, with no peer. On a device already
223
+ * in that lab, it adds whatever the copy has that the device lacks. Entries are checked exactly as
224
+ * ones from a peer are: badly signed ones, and ones from keys the roster never knew, are dropped.
225
+ *
226
+ * @param text - The text of the file.
227
+ * @returns How many entries were new to this device.
228
+ * @throws If it is not a copy of a lab, is a copy of a different lab, or holds nothing of use.
229
+ */
230
+ importLab(text: string): Promise<number>;
181
231
  /** Stop talking to the peer, until `goOnline`. The device goes on working. */
182
232
  goOffline(): void;
183
233
  /** Start talking to the peer again. */
@@ -219,9 +269,85 @@ export declare class Lab {
219
269
  part: string;
220
270
  available: boolean;
221
271
  }): Promise<void>;
222
- /** Set one field on a part (by checksum) or an item (by ID). */
272
+ /**
273
+ * Add a place: a room, a freezer, a shelf, a box.
274
+ *
275
+ * @param place - What kind it is, what it is called, the place it is in if any, for a box how
276
+ * many rows and columns of positions it has, and for an instrument which one it is.
277
+ * @returns The new place's ID.
278
+ */
279
+ addPlace(place: {
280
+ kind: string;
281
+ name: string;
282
+ parent?: string | null;
283
+ grid?: {
284
+ rows: number;
285
+ columns: number;
286
+ } | null;
287
+ model?: string | null;
288
+ }): Promise<string>;
289
+ /** Put a place inside another, or with `null` inside nothing. */
290
+ movePlace(move: {
291
+ place: string;
292
+ parent: string | null;
293
+ }): Promise<void>;
294
+ /**
295
+ * Say where a place stands and how big it is, in metres, or with `null` that nobody has said.
296
+ * It is kept to the millimetre.
297
+ */
298
+ standPlace(stand: {
299
+ place: string;
300
+ standing: {
301
+ position: [number, number, number];
302
+ size: [number, number, number];
303
+ turn?: 0 | 90 | 180 | 270;
304
+ } | null;
305
+ }): Promise<void>;
306
+ /** Retire a place. It stays in the history. */
307
+ retirePlace(which: {
308
+ place: string;
309
+ }): Promise<void>;
310
+ /** Say where an item is: which place, and which position if the place is a box. `null` for nowhere recorded. */
311
+ putItem(put: {
312
+ item: string;
313
+ place: string | null;
314
+ slot?: {
315
+ row: number;
316
+ column: number;
317
+ } | null;
318
+ }): Promise<void>;
319
+ /**
320
+ * Record something done at the bench: what went in and how much of each, and what came out.
321
+ *
322
+ * It is one change. What was used is taken from each tube, each thing that came out becomes a
323
+ * tube (and a part, if the lab did not have it), and the run is kept so those tubes can say where
324
+ * they came from. A run that did not work is recorded with nothing coming out.
325
+ *
326
+ * @param run - What kind of run, where, what went in, what came out, how it was set up, whether it
327
+ * worked, and anything worth saying.
328
+ * @returns The run's ID, and the IDs of the tubes it made, in order.
329
+ */
330
+ recordRun(run: {
331
+ kind: string;
332
+ instrument?: string | null;
333
+ inputs: RunInput[];
334
+ outputs?: {
335
+ sequence: string;
336
+ circular?: boolean;
337
+ name: string;
338
+ amount: number;
339
+ unit?: string | null;
340
+ }[];
341
+ settings?: Record<string, string | number>;
342
+ outcome?: "worked" | "failed";
343
+ note?: string | null;
344
+ }): Promise<{
345
+ run: string;
346
+ items: string[];
347
+ }>;
348
+ /** Set one field on a part (by checksum), an item or a place (by ID). */
223
349
  setField(change: {
224
- on: "part" | "item";
350
+ on: "part" | "item" | "place";
225
351
  id: string;
226
352
  field: string;
227
353
  value: string | number | null;
package/dist/lab.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lab.d.ts","sourceRoot":"","sources":["../src/lab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAEe,KAAK,WAAW,EAAE,KAAK,SAAS,EAAiB,KAAK,SAAS,EAAE,KAAK,OAAO,EAC1F,KAAK,SAAS,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAG9F,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtD,mDAAmD;AACnD,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,GAAG,EAAE,OAAO,CAAC;CACd;AAED,uCAAuC;AACv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,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAsB/E,0DAA0D;IAC1D,KAAK,IAAI,IAAI;IAMb,OAAO,CAAC,OAAO;YAKD,OAAO;IASrB,OAAO,CAAC,OAAO;IAaf,OAAO,CAAC,MAAM;CAKf"}
package/dist/lab.js CHANGED
@@ -10,9 +10,12 @@
10
10
  * holds is worked out from the entries each time they change, by `mergeLog`, which is why two devices
11
11
  * that have been apart agree the moment they have each other's entries.
12
12
  */
13
- import { addItem, addPart, addToRoster, adjustItem, entryId, fetchInventory, foundLab, isMember, mergeLog, newItemId, nextEntry, offerPart, publicInventory, recountItem, retireItem, setField, signInventory, takeEntries } from "@biolibs/bionet";
13
+ import { addItem, addPart, addPlace, addToRoster, adjustItem, entryId, fetchInventory, foundLab, isMember, mergeLog, movePlace, newItemId, newPlaceId, newRunId, nextEntry, offerPart, publicInventory, putItem, recordRun, recountItem, retireItem, retirePlace, setField, signInventory, standPlace, takeEntries } from "@biolibs/bionet";
14
14
  import { exportSigningKey, generateSigningKey, importSigningKey, keyFingerprint } from "@biolibs/opencloning";
15
+ import { openKey, sealKey } from "./backup.js";
15
16
  import { PeerLink } from "./link.js";
17
+ /** The version of the document `exportLab` writes. */
18
+ export const LAB_COPY_VERSION = 1;
16
19
  /** @param peer - The peer's socket address. @returns The web address it serves from. */
17
20
  export function originOf(peer) {
18
21
  const url = new URL(peer);
@@ -127,6 +130,9 @@ export class Lab {
127
130
  roster: state.roster.map((one) => ({ ...one, fingerprint: this.fingerprints.get(one.key) ?? "", you: one.key === mine })),
128
131
  parts: state.parts,
129
132
  items: state.items,
133
+ places: state.places,
134
+ crowded: state.crowded,
135
+ runs: state.runs,
130
136
  overlaps: state.overlaps,
131
137
  waiting: state.waiting.length,
132
138
  entries: state.entries.map((one) => ({
@@ -217,6 +223,90 @@ export class Lab {
217
223
  this.store.set("origin", origin === null || origin.trim() === "" ? null : origin.trim());
218
224
  this.changed();
219
225
  }
226
+ /**
227
+ * Seal this device's key under a passphrase, to keep somewhere that is not this device.
228
+ *
229
+ * @param passphrase - What it will take to open it again. Nothing here remembers it.
230
+ * @returns The sealed key as text, to be written to a file. It holds nothing readable without the passphrase.
231
+ */
232
+ async backUp(passphrase) {
233
+ const exported = await this.options.keys.load();
234
+ if (exported === null)
235
+ throw new Error("This device has no key to back up.");
236
+ return JSON.stringify(await sealKey(exported, passphrase), null, 2);
237
+ }
238
+ /**
239
+ * Take up a key from a backup, in place of the one this device made for itself.
240
+ *
241
+ * This is for a new device standing in for a lost one, so it is refused once the device is in a
242
+ * lab: a key in use on two devices at once writes two histories under one name, and the lab
243
+ * cannot tell which is true.
244
+ *
245
+ * @param from - The text of the backup file, and the passphrase it was sealed under.
246
+ */
247
+ async restore(from) {
248
+ if (this.labId !== null)
249
+ throw new Error("This device is already in a lab, and keeps the key it has. A backup is restored on a new device, before it joins.");
250
+ const exported = await openKey(from.backup, from.passphrase);
251
+ await this.options.keys.save(exported);
252
+ this.key = await importSigningKey(exported);
253
+ this.fingerprint = await keyFingerprint(this.key.publicKey);
254
+ this.changed();
255
+ }
256
+ /**
257
+ * Everything this device holds of the lab, as text to keep in a file.
258
+ *
259
+ * It is every signed entry, so it is the whole lab: with it and a key on the roster, the lab can
260
+ * be brought back on a new device with no peer to ask. It is not sealed. Every entry is signed,
261
+ * so a copy cannot be altered without that showing, but anybody who reads it reads the lab.
262
+ *
263
+ * @returns The copy, as JSON.
264
+ */
265
+ async exportLab() {
266
+ const lab = this.labId;
267
+ if (lab === null || this.state === null)
268
+ throw new Error("This device is not in a lab yet.");
269
+ if (this.held.length === 0)
270
+ throw new Error("None of the lab has reached this device yet, so there is nothing to keep a copy of.");
271
+ return JSON.stringify({ bionet_lab_copy: LAB_COPY_VERSION, lab, name: this.state.name, copied_at: new Date().toISOString(), entries: this.held });
272
+ }
273
+ /**
274
+ * Bring a lab in from a copy made by `exportLab`.
275
+ *
276
+ * On a device that is in no lab, this puts it in the copy's lab, with no peer. On a device already
277
+ * in that lab, it adds whatever the copy has that the device lacks. Entries are checked exactly as
278
+ * ones from a peer are: badly signed ones, and ones from keys the roster never knew, are dropped.
279
+ *
280
+ * @param text - The text of the file.
281
+ * @returns How many entries were new to this device.
282
+ * @throws If it is not a copy of a lab, is a copy of a different lab, or holds nothing of use.
283
+ */
284
+ async importLab(text) {
285
+ let copy;
286
+ try {
287
+ copy = JSON.parse(text);
288
+ }
289
+ catch {
290
+ throw new Error("That is not a copy of a lab.");
291
+ }
292
+ if (typeof copy !== "object" || copy === null || copy.bionet_lab_copy !== LAB_COPY_VERSION || typeof copy.lab !== "string"
293
+ || !/^[0-9a-f]{64}$/.test(copy.lab) || !Array.isArray(copy.entries)) {
294
+ throw new Error("That is not a copy of a lab.");
295
+ }
296
+ const here = this.labId;
297
+ if (here !== null && here !== copy.lab)
298
+ throw new Error("That is a copy of a different lab from the one this device is in.");
299
+ if (here === null) {
300
+ // Nothing is believed about the copy until its entries have been checked against its own ID.
301
+ const { kept } = await takeEntries(copy.lab, [], copy.entries);
302
+ if (kept.length === 0)
303
+ throw new Error("Nothing in that copy belongs to the lab it says it is of.");
304
+ this.store.set("lab", copy.lab);
305
+ }
306
+ const added = await this.take(copy.entries);
307
+ this.connect();
308
+ return added;
309
+ }
220
310
  /** Stop talking to the peer, until `goOnline`. The device goes on working. */
221
311
  goOffline() { this.link?.stop(); }
222
312
  /** Start talking to the peer again. */
@@ -249,7 +339,63 @@ export class Lab {
249
339
  retire(which) { return this.write(retireItem(which.item)); }
250
340
  /** Say whether a part is on offer to other labs. */
251
341
  offer(offer) { return this.write(offerPart(offer.part, offer.available)); }
252
- /** Set one field on a part (by checksum) or an item (by ID). */
342
+ /**
343
+ * Add a place: a room, a freezer, a shelf, a box.
344
+ *
345
+ * @param place - What kind it is, what it is called, the place it is in if any, for a box how
346
+ * many rows and columns of positions it has, and for an instrument which one it is.
347
+ * @returns The new place's ID.
348
+ */
349
+ async addPlace(place) {
350
+ const id = newPlaceId();
351
+ await this.write(addPlace({ place: id, kind: place.kind.trim().toLowerCase(), name: place.name.trim(), parent: place.parent ?? null, grid: place.grid ?? null }));
352
+ // Which instrument it is is a field like any other, so a lab can correct it later.
353
+ if (typeof place.model === "string" && place.model.trim() !== "")
354
+ await this.write(setField("place", id, "model", place.model.trim()));
355
+ return id;
356
+ }
357
+ /** Put a place inside another, or with `null` inside nothing. */
358
+ movePlace(move) { return this.write(movePlace(move.place, move.parent)); }
359
+ /**
360
+ * Say where a place stands and how big it is, in metres, or with `null` that nobody has said.
361
+ * It is kept to the millimetre.
362
+ */
363
+ standPlace(stand) {
364
+ const mm = (list) => [Math.round(list[0] * 1000), Math.round(list[1] * 1000), Math.round(list[2] * 1000)];
365
+ return this.write(standPlace(stand.place, stand.standing === null ? null
366
+ : { at: mm(stand.standing.position), size: mm(stand.standing.size), turn: stand.standing.turn ?? 0 }));
367
+ }
368
+ /** Retire a place. It stays in the history. */
369
+ retirePlace(which) { return this.write(retirePlace(which.place)); }
370
+ /** Say where an item is: which place, and which position if the place is a box. `null` for nowhere recorded. */
371
+ putItem(put) {
372
+ return this.write(putItem(put.item, put.place, put.slot ?? null));
373
+ }
374
+ /**
375
+ * Record something done at the bench: what went in and how much of each, and what came out.
376
+ *
377
+ * It is one change. What was used is taken from each tube, each thing that came out becomes a
378
+ * tube (and a part, if the lab did not have it), and the run is kept so those tubes can say where
379
+ * they came from. A run that did not work is recorded with nothing coming out.
380
+ *
381
+ * @param run - What kind of run, where, what went in, what came out, how it was set up, whether it
382
+ * worked, and anything worth saying.
383
+ * @returns The run's ID, and the IDs of the tubes it made, in order.
384
+ */
385
+ async recordRun(run) {
386
+ const id = newRunId();
387
+ const outputs = (run.outputs ?? []).map((output) => ({
388
+ item: newItemId(), sequence: output.sequence.replace(/\s+/g, ""), circular: output.circular === true, name: output.name.trim(),
389
+ amount: output.amount, unit: output.unit === "" ? null : output.unit ?? null,
390
+ }));
391
+ const note = run.note === undefined || run.note === null || run.note.trim() === "" ? null : run.note.trim();
392
+ await this.write(recordRun({
393
+ run: id, kind: run.kind, instrument: run.instrument ?? null, inputs: run.inputs, outputs, settings: run.settings ?? {},
394
+ outcome: run.outcome ?? (outputs.length > 0 ? "worked" : "failed"), note,
395
+ }));
396
+ return { run: id, items: outputs.map((output) => output.item) };
397
+ }
398
+ /** Set one field on a part (by checksum), an item or a place (by ID). */
253
399
  setField(change) {
254
400
  return this.write(setField(change.on, change.id, change.field, change.value));
255
401
  }
package/dist/lab.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"lab.js","sourceRoot":"","sources":["../src/lab.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAChG,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAClG,WAAW,EACkD,MAAM,iBAAiB,CAAC;AAC9F,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,cAAc,EACrD,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAmB,MAAM,WAAW,CAAC;AA+EtD,wFAAwF;AACxF,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,OAAO,GAAG,GAAG,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,KAAK,GAAG,CAAC,IAAI,EAAE,CAAC;AACvE,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,IA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Q,CAAC;YACvB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE;YACrH,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;SACvF,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;IAEO,MAAM,CAAI,IAAsB;QACtC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACjC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
package/dist/source.d.ts CHANGED
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import type { Lab, LabSnapshot } from "./lab.js";
11
11
  /** Everything a window may ask a lab to do. Nothing outside this list can be asked for. */
12
- export declare const ACTIONS: readonly ["setPerson", "found", "join", "setPeer", "setOrigin", "addMember", "addPart", "addItem", "adjust", "recount", "retire", "offer", "setField", "publish"];
12
+ export declare const ACTIONS: readonly ["setPerson", "found", "join", "setPeer", "setOrigin", "addMember", "addPart", "addItem", "adjust", "recount", "retire", "offer", "setField", "publish", "backUp", "restore", "addPlace", "movePlace", "standPlace", "retirePlace", "putItem", "recordRun", "exportLab", "importLab"];
13
13
  /** One thing a window may ask for. */
14
14
  export type Action = (typeof ACTIONS)[number];
15
15
  /** How asking went: what came back, or why it could not be done, said for a person. */
@@ -1 +1 @@
1
- {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEjD,2FAA2F;AAC3F,eAAO,MAAM,OAAO,mKAC2E,CAAC;AAEhG,sCAAsC;AACtC,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9C,uFAAuF;AACvF,MAAM,MAAM,MAAM,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,qCAAqC;AACrC,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,wGAAwG;IACxG,QAAQ,IAAI,WAAW,GAAG,IAAI,CAAC;IAC/B,wFAAwF;IACxF,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1F;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAE5C"}
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEjD,2FAA2F;AAC3F,eAAO,MAAM,OAAO,gSAEoH,CAAC;AAEzI,sCAAsC;AACtC,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC;AAE9C,uFAAuF;AACvF,MAAM,MAAM,MAAM,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAElF,qCAAqC;AACrC,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,wGAAwG;IACxG,QAAQ,IAAI,WAAW,GAAG,IAAI,CAAC;IAC/B,wFAAwF;IACxF,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACzD;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1F;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,SAAS,CAE5C"}
package/dist/source.js CHANGED
@@ -1,6 +1,7 @@
1
1
  /** Everything a window may ask a lab to do. Nothing outside this list can be asked for. */
2
2
  export const ACTIONS = ["setPerson", "found", "join", "setPeer", "setOrigin", "addMember", "addPart", "addItem",
3
- "adjust", "recount", "retire", "offer", "setField", "publish"];
3
+ "adjust", "recount", "retire", "offer", "setField", "publish", "backUp", "restore",
4
+ "addPlace", "movePlace", "standPlace", "retirePlace", "putItem", "recordRun", "exportLab", "importLab"];
4
5
  /**
5
6
  * Do one of the things a window may ask for.
6
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":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E,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;AACvH,CAAC"}
package/package.json CHANGED
@@ -3,10 +3,10 @@
3
3
  "url": "https://github.com/matthewlovestocode/biolibs/issues"
4
4
  },
5
5
  "dependencies": {
6
- "@biolibs/bionet": "^1.2.0",
6
+ "@biolibs/bionet": "^1.3.1",
7
7
  "@biolibs/opencloning": "^2.0.0"
8
8
  },
9
- "description": "One device in one lab: its key, its copy of the lab's signed log, everything a member can do, and the connection to the lab's web peer. Works offline and syncs when it can. Storage and key keeping are plugged in, so it runs in Electron, Node or a browser",
9
+ "description": "One device in one lab: its key, its copy of the lab's signed log, everything a member can do, and the connection to the lab's web peer. Works offline and syncs when it can, and backs up the key and the lab. Storage and key keeping are plugged in",
10
10
  "engines": {
11
11
  "node": ">=20"
12
12
  },
@@ -46,5 +46,5 @@
46
46
  },
47
47
  "type": "module",
48
48
  "types": "dist/index.d.ts",
49
- "version": "0.1.0"
49
+ "version": "0.2.1"
50
50
  }
package/src/backup.ts ADDED
@@ -0,0 +1,128 @@
1
+ /**
2
+ * A device's key, sealed so that it can be kept somewhere else.
3
+ *
4
+ * A device's key never leaves the device, with one exception: a lab with one member and one device
5
+ * is a lab that ends when the device does. So the key can be written out sealed under a passphrase,
6
+ * as a small document to keep somewhere that is not this machine, and opened again on a new one.
7
+ *
8
+ * What is sealed is useless without the passphrase, and nothing here remembers it. A sealed key
9
+ * whose passphrase is forgotten is a lost key.
10
+ */
11
+ import { importSigningKey, keyFingerprint } from "@biolibs/opencloning";
12
+
13
+ /** The version of the sealed-key document. */
14
+ export const BACKUP_VERSION = 1;
15
+
16
+ /** How many rounds the passphrase is stretched by. */
17
+ export const BACKUP_ROUNDS = 600_000;
18
+
19
+ /** The fewest characters a passphrase may have. */
20
+ export const SHORTEST_PASSPHRASE = 12;
21
+
22
+ /** A device's key, sealed under a passphrase. Every byte string is base64. */
23
+ export interface KeyBackup {
24
+ /** Which version of this document it is. */
25
+ bionet_key_backup: number;
26
+ /** The fingerprint of the key inside, so a person can tell which key a file holds without opening it. */
27
+ fingerprint: string;
28
+ /** How the passphrase becomes a key. */
29
+ kdf: { name: "PBKDF2"; hash: "SHA-256"; iterations: number; salt: string };
30
+ /** How the key was sealed. */
31
+ cipher: { name: "AES-GCM"; iv: string };
32
+ /** The sealed key. */
33
+ sealed: string;
34
+ }
35
+
36
+ const toBase64 = (bytes: Uint8Array): string => btoa(String.fromCharCode(...bytes));
37
+ const fromBase64 = (text: string): Uint8Array<ArrayBuffer> => Uint8Array.from(atob(text), (letter) => letter.charCodeAt(0));
38
+
39
+ async function stretch(passphrase: string, salt: Uint8Array<ArrayBuffer>, iterations: number): Promise<CryptoKey> {
40
+ const subtle = globalThis.crypto.subtle;
41
+ const material = await subtle.importKey("raw", new TextEncoder().encode(passphrase.normalize("NFKC")), "PBKDF2", false, ["deriveKey"]);
42
+ return subtle.deriveKey({ name: "PBKDF2", hash: "SHA-256", salt, iterations }, material, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
43
+ }
44
+
45
+ /**
46
+ * Seal a device's key under a passphrase.
47
+ *
48
+ * @param exported - The key, as `exportSigningKey` wrote it.
49
+ * @param passphrase - What it will take to open it again.
50
+ * @param options - `iterations` is only for tests, which cannot wait for the real number.
51
+ * @returns The sealed key, safe to write to a file.
52
+ * @throws If the passphrase is too short to be worth sealing anything with.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { exportSigningKey, generateSigningKey } from "@biolibs/opencloning";
57
+ * import { openKey, sealKey } from "@biolibs/bionet-client";
58
+ *
59
+ * const exported = await exportSigningKey(await generateSigningKey());
60
+ * const backup = await sealKey(exported, "correct horse battery staple");
61
+ * (await openKey(backup, "correct horse battery staple")) === exported; // true
62
+ * ```
63
+ */
64
+ export async function sealKey(exported: string, passphrase: string, options: { iterations?: number } = {}): Promise<KeyBackup> {
65
+ if (passphrase.length < SHORTEST_PASSPHRASE) {
66
+ throw new Error(`A passphrase of at least ${SHORTEST_PASSPHRASE} characters. Several unrelated words work well.`);
67
+ }
68
+ const iterations = options.iterations ?? BACKUP_ROUNDS;
69
+ const salt = globalThis.crypto.getRandomValues(new Uint8Array(16));
70
+ const iv = globalThis.crypto.getRandomValues(new Uint8Array(12));
71
+ const fingerprint = await keyFingerprint((await importSigningKey(exported)).publicKey);
72
+ const sealed = await globalThis.crypto.subtle.encrypt({ name: "AES-GCM", iv }, await stretch(passphrase, salt, iterations),
73
+ new TextEncoder().encode(exported));
74
+ return {
75
+ bionet_key_backup: BACKUP_VERSION, fingerprint,
76
+ kdf: { name: "PBKDF2", hash: "SHA-256", iterations, salt: toBase64(salt) },
77
+ cipher: { name: "AES-GCM", iv: toBase64(iv) },
78
+ sealed: toBase64(new Uint8Array(sealed)),
79
+ };
80
+ }
81
+
82
+ /**
83
+ * Read a sealed key, from the document or its text.
84
+ *
85
+ * @param value - What was in the file.
86
+ * @returns The sealed key.
87
+ * @throws If it is not one.
88
+ */
89
+ export function readBackup(value: unknown): KeyBackup {
90
+ let found = value;
91
+ if (typeof found === "string") {
92
+ try { found = JSON.parse(found); } catch { throw new Error("That is not a key backup."); }
93
+ }
94
+ const one = found as Partial<KeyBackup> | null;
95
+ const short = (text: unknown, most: number): text is string => typeof text === "string" && text.length > 0 && text.length <= most;
96
+ if (one === null || typeof one !== "object" || one.bionet_key_backup !== BACKUP_VERSION || !short(one.fingerprint, 100)
97
+ || one.kdf?.name !== "PBKDF2" || one.kdf.hash !== "SHA-256" || !Number.isSafeInteger(one.kdf.iterations)
98
+ || one.kdf.iterations < 1 || one.kdf.iterations > 10_000_000 || !short(one.kdf.salt, 200)
99
+ || one.cipher?.name !== "AES-GCM" || !short(one.cipher.iv, 200) || !short(one.sealed, 20_000)) {
100
+ throw new Error("That is not a key backup.");
101
+ }
102
+ return one as KeyBackup;
103
+ }
104
+
105
+ /**
106
+ * Open a sealed key.
107
+ *
108
+ * @param backup - The sealed key, or the text of the file it was kept in.
109
+ * @param passphrase - What it was sealed under.
110
+ * @returns The key, as `exportSigningKey` wrote it.
111
+ * @throws If the passphrase is wrong, or the document has been changed.
112
+ */
113
+ export async function openKey(backup: unknown, passphrase: string): Promise<string> {
114
+ const one = readBackup(backup);
115
+ let exported: string;
116
+ try {
117
+ const opened = await globalThis.crypto.subtle.decrypt({ name: "AES-GCM", iv: fromBase64(one.cipher.iv) },
118
+ await stretch(passphrase, fromBase64(one.kdf.salt), one.kdf.iterations), fromBase64(one.sealed));
119
+ exported = new TextDecoder().decode(opened);
120
+ } catch {
121
+ throw new Error("That passphrase does not open this backup.");
122
+ }
123
+ // The fingerprint on the outside is not sealed, so it is checked against what was inside.
124
+ if (await keyFingerprint((await importSigningKey(exported)).publicKey) !== one.fingerprint) {
125
+ throw new Error("This backup does not hold the key it says it does.");
126
+ }
127
+ return exported;
128
+ }
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@
13
13
  * - `lab.ts` — the device: `Lab`, and the plain-data snapshot a window draws
14
14
  * - `link.ts` — the connection to the web peer, which is allowed to fail
15
15
  * - `source.ts` — the narrow way a window reaches a lab, in this process or another
16
+ * - `backup.ts` — the device's key, sealed under a passphrase to keep somewhere else
16
17
  * - `store.ts` — the interfaces for storage and key keeping, with in-memory versions
17
18
  * - `sqlite.ts` — storage in a SQLite file, at `@biolibs/bionet-client/sqlite` because it needs Node
18
19
  */
@@ -20,3 +21,4 @@ export * from "./lab.js";
20
21
  export * from "./link.js";
21
22
  export * from "./store.js";
22
23
  export * from "./source.js";
24
+ export * from "./backup.js";
package/src/lab.ts CHANGED
@@ -10,12 +10,14 @@
10
10
  * holds is worked out from the entries each time they change, by `mergeLog`, which is why two devices
11
11
  * that have been apart agree the moment they have each other's entries.
12
12
  */
13
- import { addItem, addPart, addToRoster, adjustItem, entryId, fetchInventory, foundLab, isMember, mergeLog,
14
- newItemId, nextEntry, offerPart, publicInventory, recountItem, retireItem, setField, signInventory,
15
- takeEntries, type EntryStatus, type ItemState, type LabState, type Operation, type Overlap,
16
- type PartState, type Role, type RosterKey, type SignedEntry } from "@biolibs/bionet";
13
+ import { addItem, addPart, addPlace, addToRoster, adjustItem, entryId, fetchInventory, foundLab, isMember, mergeLog,
14
+ movePlace, newItemId, newPlaceId, newRunId, nextEntry, offerPart, publicInventory, putItem, recordRun, recountItem, retireItem, retirePlace,
15
+ setField, signInventory, standPlace,
16
+ takeEntries, type Crowded, type EntryStatus, type ItemState, type LabState, type Operation, type Overlap,
17
+ type PartState, type PlaceState, type RunInput, type RunState, type Role, type RosterKey, type SignedEntry } from "@biolibs/bionet";
17
18
  import { exportSigningKey, generateSigningKey, importSigningKey, keyFingerprint,
18
19
  type SigningKey } from "@biolibs/opencloning";
20
+ import { openKey, sealKey } from "./backup.js";
19
21
  import { PeerLink, type LinkStatus } from "./link.js";
20
22
  import type { KeyKeeper, LabStore } from "./store.js";
21
23
 
@@ -54,6 +56,12 @@ export interface LabView {
54
56
  roster: RosterView[];
55
57
  parts: PartState[];
56
58
  items: ItemState[];
59
+ /** Every place. */
60
+ places: PlaceState[];
61
+ /** Positions the log says hold more than one item. */
62
+ crowded: Crowded[];
63
+ /** Everything done at the bench that was recorded. */
64
+ runs: RunState[];
57
65
  overlaps: Overlap[];
58
66
  /** How many entries are waiting on others that have not arrived. */
59
67
  waiting: number;
@@ -95,6 +103,9 @@ export interface LabOptions {
95
103
  WebSocket?: typeof globalThis.WebSocket;
96
104
  }
97
105
 
106
+ /** The version of the document `exportLab` writes. */
107
+ export const LAB_COPY_VERSION = 1;
108
+
98
109
  /** @param peer - The peer's socket address. @returns The web address it serves from. */
99
110
  export function originOf(peer: string): string {
100
111
  const url = new URL(peer);
@@ -210,6 +221,9 @@ export class Lab {
210
221
  roster: state.roster.map((one) => ({ ...one, fingerprint: this.fingerprints.get(one.key) ?? "", you: one.key === mine })),
211
222
  parts: state.parts,
212
223
  items: state.items,
224
+ places: state.places,
225
+ crowded: state.crowded,
226
+ runs: state.runs,
213
227
  overlaps: state.overlaps,
214
228
  waiting: state.waiting.length,
215
229
  entries: state.entries.map((one) => ({
@@ -304,6 +318,83 @@ export class Lab {
304
318
  this.changed();
305
319
  }
306
320
 
321
+ /**
322
+ * Seal this device's key under a passphrase, to keep somewhere that is not this device.
323
+ *
324
+ * @param passphrase - What it will take to open it again. Nothing here remembers it.
325
+ * @returns The sealed key as text, to be written to a file. It holds nothing readable without the passphrase.
326
+ */
327
+ async backUp(passphrase: string): Promise<string> {
328
+ const exported = await this.options.keys.load();
329
+ if (exported === null) throw new Error("This device has no key to back up.");
330
+ return JSON.stringify(await sealKey(exported, passphrase), null, 2);
331
+ }
332
+
333
+ /**
334
+ * Take up a key from a backup, in place of the one this device made for itself.
335
+ *
336
+ * This is for a new device standing in for a lost one, so it is refused once the device is in a
337
+ * lab: a key in use on two devices at once writes two histories under one name, and the lab
338
+ * cannot tell which is true.
339
+ *
340
+ * @param from - The text of the backup file, and the passphrase it was sealed under.
341
+ */
342
+ async restore(from: { backup: string; passphrase: string }): Promise<void> {
343
+ if (this.labId !== null) throw new Error("This device is already in a lab, and keeps the key it has. A backup is restored on a new device, before it joins.");
344
+ const exported = await openKey(from.backup, from.passphrase);
345
+ await this.options.keys.save(exported);
346
+ this.key = await importSigningKey(exported);
347
+ this.fingerprint = await keyFingerprint(this.key.publicKey);
348
+ this.changed();
349
+ }
350
+
351
+ /**
352
+ * Everything this device holds of the lab, as text to keep in a file.
353
+ *
354
+ * It is every signed entry, so it is the whole lab: with it and a key on the roster, the lab can
355
+ * be brought back on a new device with no peer to ask. It is not sealed. Every entry is signed,
356
+ * so a copy cannot be altered without that showing, but anybody who reads it reads the lab.
357
+ *
358
+ * @returns The copy, as JSON.
359
+ */
360
+ async exportLab(): Promise<string> {
361
+ const lab = this.labId;
362
+ if (lab === null || this.state === null) throw new Error("This device is not in a lab yet.");
363
+ if (this.held.length === 0) throw new Error("None of the lab has reached this device yet, so there is nothing to keep a copy of.");
364
+ return JSON.stringify({ bionet_lab_copy: LAB_COPY_VERSION, lab, name: this.state.name, copied_at: new Date().toISOString(), entries: this.held });
365
+ }
366
+
367
+ /**
368
+ * Bring a lab in from a copy made by `exportLab`.
369
+ *
370
+ * On a device that is in no lab, this puts it in the copy's lab, with no peer. On a device already
371
+ * in that lab, it adds whatever the copy has that the device lacks. Entries are checked exactly as
372
+ * ones from a peer are: badly signed ones, and ones from keys the roster never knew, are dropped.
373
+ *
374
+ * @param text - The text of the file.
375
+ * @returns How many entries were new to this device.
376
+ * @throws If it is not a copy of a lab, is a copy of a different lab, or holds nothing of use.
377
+ */
378
+ async importLab(text: string): Promise<number> {
379
+ let copy: { bionet_lab_copy?: unknown; lab?: unknown; entries?: unknown };
380
+ try { copy = JSON.parse(text) as typeof copy; } catch { throw new Error("That is not a copy of a lab."); }
381
+ if (typeof copy !== "object" || copy === null || copy.bionet_lab_copy !== LAB_COPY_VERSION || typeof copy.lab !== "string"
382
+ || !/^[0-9a-f]{64}$/.test(copy.lab) || !Array.isArray(copy.entries)) {
383
+ throw new Error("That is not a copy of a lab.");
384
+ }
385
+ const here = this.labId;
386
+ if (here !== null && here !== copy.lab) throw new Error("That is a copy of a different lab from the one this device is in.");
387
+ if (here === null) {
388
+ // Nothing is believed about the copy until its entries have been checked against its own ID.
389
+ const { kept } = await takeEntries(copy.lab, [], copy.entries);
390
+ if (kept.length === 0) throw new Error("Nothing in that copy belongs to the lab it says it is of.");
391
+ this.store.set("lab", copy.lab);
392
+ }
393
+ const added = await this.take(copy.entries);
394
+ this.connect();
395
+ return added;
396
+ }
397
+
307
398
  /** Stop talking to the peer, until `goOnline`. The device goes on working. */
308
399
  goOffline(): void { this.link?.stop(); }
309
400
 
@@ -345,8 +436,73 @@ export class Lab {
345
436
  /** Say whether a part is on offer to other labs. */
346
437
  offer(offer: { part: string; available: boolean }): Promise<void> { return this.write(offerPart(offer.part, offer.available)); }
347
438
 
348
- /** Set one field on a part (by checksum) or an item (by ID). */
349
- setField(change: { on: "part" | "item"; id: string; field: string; value: string | number | null }): Promise<void> {
439
+ /**
440
+ * Add a place: a room, a freezer, a shelf, a box.
441
+ *
442
+ * @param place - What kind it is, what it is called, the place it is in if any, for a box how
443
+ * many rows and columns of positions it has, and for an instrument which one it is.
444
+ * @returns The new place's ID.
445
+ */
446
+ async addPlace(place: { kind: string; name: string; parent?: string | null; grid?: { rows: number; columns: number } | null; model?: string | null }): Promise<string> {
447
+ const id = newPlaceId();
448
+ await this.write(addPlace({ place: id, kind: place.kind.trim().toLowerCase(), name: place.name.trim(), parent: place.parent ?? null, grid: place.grid ?? null }));
449
+ // Which instrument it is is a field like any other, so a lab can correct it later.
450
+ if (typeof place.model === "string" && place.model.trim() !== "") await this.write(setField("place", id, "model", place.model.trim()));
451
+ return id;
452
+ }
453
+
454
+ /** Put a place inside another, or with `null` inside nothing. */
455
+ movePlace(move: { place: string; parent: string | null }): Promise<void> { return this.write(movePlace(move.place, move.parent)); }
456
+
457
+ /**
458
+ * Say where a place stands and how big it is, in metres, or with `null` that nobody has said.
459
+ * It is kept to the millimetre.
460
+ */
461
+ standPlace(stand: { place: string; standing: { position: [number, number, number]; size: [number, number, number]; turn?: 0 | 90 | 180 | 270 } | null }): Promise<void> {
462
+ const mm = (list: [number, number, number]): [number, number, number] => [Math.round(list[0] * 1000), Math.round(list[1] * 1000), Math.round(list[2] * 1000)];
463
+ return this.write(standPlace(stand.place, stand.standing === null ? null
464
+ : { at: mm(stand.standing.position), size: mm(stand.standing.size), turn: stand.standing.turn ?? 0 }));
465
+ }
466
+
467
+ /** Retire a place. It stays in the history. */
468
+ retirePlace(which: { place: string }): Promise<void> { return this.write(retirePlace(which.place)); }
469
+
470
+ /** Say where an item is: which place, and which position if the place is a box. `null` for nowhere recorded. */
471
+ putItem(put: { item: string; place: string | null; slot?: { row: number; column: number } | null }): Promise<void> {
472
+ return this.write(putItem(put.item, put.place, put.slot ?? null));
473
+ }
474
+
475
+ /**
476
+ * Record something done at the bench: what went in and how much of each, and what came out.
477
+ *
478
+ * It is one change. What was used is taken from each tube, each thing that came out becomes a
479
+ * tube (and a part, if the lab did not have it), and the run is kept so those tubes can say where
480
+ * they came from. A run that did not work is recorded with nothing coming out.
481
+ *
482
+ * @param run - What kind of run, where, what went in, what came out, how it was set up, whether it
483
+ * worked, and anything worth saying.
484
+ * @returns The run's ID, and the IDs of the tubes it made, in order.
485
+ */
486
+ async recordRun(run: {
487
+ kind: string; instrument?: string | null; inputs: RunInput[];
488
+ outputs?: { sequence: string; circular?: boolean; name: string; amount: number; unit?: string | null }[];
489
+ settings?: Record<string, string | number>; outcome?: "worked" | "failed"; note?: string | null;
490
+ }): Promise<{ run: string; items: string[] }> {
491
+ const id = newRunId();
492
+ const outputs = (run.outputs ?? []).map((output) => ({
493
+ item: newItemId(), sequence: output.sequence.replace(/\s+/g, ""), circular: output.circular === true, name: output.name.trim(),
494
+ amount: output.amount, unit: output.unit === "" ? null : output.unit ?? null,
495
+ }));
496
+ const note = run.note === undefined || run.note === null || run.note.trim() === "" ? null : run.note.trim();
497
+ await this.write(recordRun({
498
+ run: id, kind: run.kind, instrument: run.instrument ?? null, inputs: run.inputs, outputs, settings: run.settings ?? {},
499
+ outcome: run.outcome ?? (outputs.length > 0 ? "worked" : "failed"), note,
500
+ }));
501
+ return { run: id, items: outputs.map((output) => output.item) };
502
+ }
503
+
504
+ /** Set one field on a part (by checksum), an item or a place (by ID). */
505
+ setField(change: { on: "part" | "item" | "place"; id: string; field: string; value: string | number | null }): Promise<void> {
350
506
  return this.write(setField(change.on, change.id, change.field, change.value));
351
507
  }
352
508
 
package/src/source.ts CHANGED
@@ -11,7 +11,8 @@ import type { Lab, LabSnapshot } from "./lab.js";
11
11
 
12
12
  /** Everything a window may ask a lab to do. Nothing outside this list can be asked for. */
13
13
  export const ACTIONS = ["setPerson", "found", "join", "setPeer", "setOrigin", "addMember", "addPart", "addItem",
14
- "adjust", "recount", "retire", "offer", "setField", "publish"] as const;
14
+ "adjust", "recount", "retire", "offer", "setField", "publish", "backUp", "restore",
15
+ "addPlace", "movePlace", "standPlace", "retirePlace", "putItem", "recordRun", "exportLab", "importLab"] as const;
15
16
 
16
17
  /** One thing a window may ask for. */
17
18
  export type Action = (typeof ACTIONS)[number];