@biolibs/bionet-client 0.1.0 → 0.2.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 +28 -0
- package/dist/backup.d.ts +67 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +111 -0
- package/dist/backup.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lab.d.ts +73 -3
- package/dist/lab.d.ts.map +1 -1
- package/dist/lab.js +64 -2
- package/dist/lab.js.map +1 -1
- package/dist/source.d.ts +1 -1
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +2 -1
- package/dist/source.js.map +1 -1
- package/package.json +2 -2
- package/src/backup.ts +128 -0
- package/src/index.ts +2 -0
- package/src/lab.ts +78 -6
- package/src/source.ts +2 -1
package/README.md
CHANGED
|
@@ -50,6 +50,34 @@ guards it; `memoryKeys()` is for tests.
|
|
|
50
50
|
2. The keeper adds it, `lab.addMember({ key, person })`, and sends back `lab.invite`.
|
|
51
51
|
3. The new member calls `lab.join(invite)`. The lab arrives once the keeper's change reaches the peer.
|
|
52
52
|
|
|
53
|
+
## Where things are
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const freezer = await lab.addPlace({ kind: "freezer", name: "−80" });
|
|
57
|
+
const box = await lab.addPlace({ kind: "box", name: "Box 1", parent: freezer, grid: { rows: 9, columns: 9 } });
|
|
58
|
+
await lab.putItem({ item: tube, place: box, slot: { row: 0, column: 0 } });
|
|
59
|
+
lab.snapshot().lab?.places.length; // 2
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`movePlace`, `standPlace` (in metres, kept to the millimetre) and `retirePlace` do the rest.
|
|
63
|
+
`layoutFrom` in `@biolibs/bionet-space` turns the snapshot's lab into something that can be drawn.
|
|
64
|
+
|
|
65
|
+
## Backing up the key
|
|
66
|
+
|
|
67
|
+
A device's key never leaves it, with one exception: a lab with one member and one device ends when
|
|
68
|
+
the device does.
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
const backup = await lab.backUp("several unrelated words"); // text to write to a file
|
|
72
|
+
// later, on a new device that is not in a lab yet:
|
|
73
|
+
await fresh.restore({ backup, passphrase: "several unrelated words" });
|
|
74
|
+
await fresh.join(invite); // and it carries on the same log
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The key is sealed with AES-256-GCM under a key stretched from the passphrase by PBKDF2 (600,000
|
|
78
|
+
rounds of SHA-256). Nothing remembers the passphrase. `restore` is refused once a device is in a
|
|
79
|
+
lab: one key on two devices writes two histories the lab cannot tell apart.
|
|
80
|
+
|
|
53
81
|
## The window's side
|
|
54
82
|
|
|
55
83
|
A window does not always share a process with the lab. It reaches one through a `LabSource`: the lab
|
package/dist/backup.d.ts
ADDED
|
@@ -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,KAAK,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IACvI,OAAO,MAAM,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,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HANGED
|
@@ -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
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
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
|
|
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 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,10 @@ 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[];
|
|
49
53
|
overlaps: Overlap[];
|
|
50
54
|
/** How many entries are waiting on others that have not arrived. */
|
|
51
55
|
waiting: number;
|
|
@@ -178,6 +182,26 @@ export declare class Lab {
|
|
|
178
182
|
setPeer(peer: string | null): Promise<void>;
|
|
179
183
|
/** @param origin - The web address the lab publishes from, if it is not the peer's own. */
|
|
180
184
|
setOrigin(origin: string | null): Promise<void>;
|
|
185
|
+
/**
|
|
186
|
+
* Seal this device's key under a passphrase, to keep somewhere that is not this device.
|
|
187
|
+
*
|
|
188
|
+
* @param passphrase - What it will take to open it again. Nothing here remembers it.
|
|
189
|
+
* @returns The sealed key as text, to be written to a file. It holds nothing readable without the passphrase.
|
|
190
|
+
*/
|
|
191
|
+
backUp(passphrase: string): Promise<string>;
|
|
192
|
+
/**
|
|
193
|
+
* Take up a key from a backup, in place of the one this device made for itself.
|
|
194
|
+
*
|
|
195
|
+
* This is for a new device standing in for a lost one, so it is refused once the device is in a
|
|
196
|
+
* lab: a key in use on two devices at once writes two histories under one name, and the lab
|
|
197
|
+
* cannot tell which is true.
|
|
198
|
+
*
|
|
199
|
+
* @param from - The text of the backup file, and the passphrase it was sealed under.
|
|
200
|
+
*/
|
|
201
|
+
restore(from: {
|
|
202
|
+
backup: string;
|
|
203
|
+
passphrase: string;
|
|
204
|
+
}): Promise<void>;
|
|
181
205
|
/** Stop talking to the peer, until `goOnline`. The device goes on working. */
|
|
182
206
|
goOffline(): void;
|
|
183
207
|
/** Start talking to the peer again. */
|
|
@@ -219,9 +243,55 @@ export declare class Lab {
|
|
|
219
243
|
part: string;
|
|
220
244
|
available: boolean;
|
|
221
245
|
}): Promise<void>;
|
|
222
|
-
/**
|
|
246
|
+
/**
|
|
247
|
+
* Add a place: a room, a freezer, a shelf, a box.
|
|
248
|
+
*
|
|
249
|
+
* @param place - What kind it is, what it is called, the place it is in if any, and for a box how
|
|
250
|
+
* many rows and columns of positions it has.
|
|
251
|
+
* @returns The new place's ID.
|
|
252
|
+
*/
|
|
253
|
+
addPlace(place: {
|
|
254
|
+
kind: string;
|
|
255
|
+
name: string;
|
|
256
|
+
parent?: string | null;
|
|
257
|
+
grid?: {
|
|
258
|
+
rows: number;
|
|
259
|
+
columns: number;
|
|
260
|
+
} | null;
|
|
261
|
+
}): Promise<string>;
|
|
262
|
+
/** Put a place inside another, or with `null` inside nothing. */
|
|
263
|
+
movePlace(move: {
|
|
264
|
+
place: string;
|
|
265
|
+
parent: string | null;
|
|
266
|
+
}): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Say where a place stands and how big it is, in metres, or with `null` that nobody has said.
|
|
269
|
+
* It is kept to the millimetre.
|
|
270
|
+
*/
|
|
271
|
+
standPlace(stand: {
|
|
272
|
+
place: string;
|
|
273
|
+
standing: {
|
|
274
|
+
position: [number, number, number];
|
|
275
|
+
size: [number, number, number];
|
|
276
|
+
turn?: 0 | 90 | 180 | 270;
|
|
277
|
+
} | null;
|
|
278
|
+
}): Promise<void>;
|
|
279
|
+
/** Retire a place. It stays in the history. */
|
|
280
|
+
retirePlace(which: {
|
|
281
|
+
place: string;
|
|
282
|
+
}): Promise<void>;
|
|
283
|
+
/** Say where an item is: which place, and which position if the place is a box. `null` for nowhere recorded. */
|
|
284
|
+
putItem(put: {
|
|
285
|
+
item: string;
|
|
286
|
+
place: string | null;
|
|
287
|
+
slot?: {
|
|
288
|
+
row: number;
|
|
289
|
+
column: number;
|
|
290
|
+
} | null;
|
|
291
|
+
}): Promise<void>;
|
|
292
|
+
/** Set one field on a part (by checksum), an item or a place (by ID). */
|
|
223
293
|
setField(change: {
|
|
224
|
-
on: "part" | "item";
|
|
294
|
+
on: "part" | "item" | "place";
|
|
225
295
|
id: string;
|
|
226
296
|
field: string;
|
|
227
297
|
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,
|
|
1
|
+
{"version":3,"file":"lab.d.ts","s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
package/dist/lab.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
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, nextEntry, offerPart, publicInventory, putItem, 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";
|
|
16
17
|
/** @param peer - The peer's socket address. @returns The web address it serves from. */
|
|
17
18
|
export function originOf(peer) {
|
|
@@ -127,6 +128,8 @@ export class Lab {
|
|
|
127
128
|
roster: state.roster.map((one) => ({ ...one, fingerprint: this.fingerprints.get(one.key) ?? "", you: one.key === mine })),
|
|
128
129
|
parts: state.parts,
|
|
129
130
|
items: state.items,
|
|
131
|
+
places: state.places,
|
|
132
|
+
crowded: state.crowded,
|
|
130
133
|
overlaps: state.overlaps,
|
|
131
134
|
waiting: state.waiting.length,
|
|
132
135
|
entries: state.entries.map((one) => ({
|
|
@@ -217,6 +220,36 @@ export class Lab {
|
|
|
217
220
|
this.store.set("origin", origin === null || origin.trim() === "" ? null : origin.trim());
|
|
218
221
|
this.changed();
|
|
219
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Seal this device's key under a passphrase, to keep somewhere that is not this device.
|
|
225
|
+
*
|
|
226
|
+
* @param passphrase - What it will take to open it again. Nothing here remembers it.
|
|
227
|
+
* @returns The sealed key as text, to be written to a file. It holds nothing readable without the passphrase.
|
|
228
|
+
*/
|
|
229
|
+
async backUp(passphrase) {
|
|
230
|
+
const exported = await this.options.keys.load();
|
|
231
|
+
if (exported === null)
|
|
232
|
+
throw new Error("This device has no key to back up.");
|
|
233
|
+
return JSON.stringify(await sealKey(exported, passphrase), null, 2);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Take up a key from a backup, in place of the one this device made for itself.
|
|
237
|
+
*
|
|
238
|
+
* This is for a new device standing in for a lost one, so it is refused once the device is in a
|
|
239
|
+
* lab: a key in use on two devices at once writes two histories under one name, and the lab
|
|
240
|
+
* cannot tell which is true.
|
|
241
|
+
*
|
|
242
|
+
* @param from - The text of the backup file, and the passphrase it was sealed under.
|
|
243
|
+
*/
|
|
244
|
+
async restore(from) {
|
|
245
|
+
if (this.labId !== null)
|
|
246
|
+
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.");
|
|
247
|
+
const exported = await openKey(from.backup, from.passphrase);
|
|
248
|
+
await this.options.keys.save(exported);
|
|
249
|
+
this.key = await importSigningKey(exported);
|
|
250
|
+
this.fingerprint = await keyFingerprint(this.key.publicKey);
|
|
251
|
+
this.changed();
|
|
252
|
+
}
|
|
220
253
|
/** Stop talking to the peer, until `goOnline`. The device goes on working. */
|
|
221
254
|
goOffline() { this.link?.stop(); }
|
|
222
255
|
/** Start talking to the peer again. */
|
|
@@ -249,7 +282,36 @@ export class Lab {
|
|
|
249
282
|
retire(which) { return this.write(retireItem(which.item)); }
|
|
250
283
|
/** Say whether a part is on offer to other labs. */
|
|
251
284
|
offer(offer) { return this.write(offerPart(offer.part, offer.available)); }
|
|
252
|
-
/**
|
|
285
|
+
/**
|
|
286
|
+
* Add a place: a room, a freezer, a shelf, a box.
|
|
287
|
+
*
|
|
288
|
+
* @param place - What kind it is, what it is called, the place it is in if any, and for a box how
|
|
289
|
+
* many rows and columns of positions it has.
|
|
290
|
+
* @returns The new place's ID.
|
|
291
|
+
*/
|
|
292
|
+
async addPlace(place) {
|
|
293
|
+
const id = newPlaceId();
|
|
294
|
+
await this.write(addPlace({ place: id, kind: place.kind.trim().toLowerCase(), name: place.name.trim(), parent: place.parent ?? null, grid: place.grid ?? null }));
|
|
295
|
+
return id;
|
|
296
|
+
}
|
|
297
|
+
/** Put a place inside another, or with `null` inside nothing. */
|
|
298
|
+
movePlace(move) { return this.write(movePlace(move.place, move.parent)); }
|
|
299
|
+
/**
|
|
300
|
+
* Say where a place stands and how big it is, in metres, or with `null` that nobody has said.
|
|
301
|
+
* It is kept to the millimetre.
|
|
302
|
+
*/
|
|
303
|
+
standPlace(stand) {
|
|
304
|
+
const mm = (list) => [Math.round(list[0] * 1000), Math.round(list[1] * 1000), Math.round(list[2] * 1000)];
|
|
305
|
+
return this.write(standPlace(stand.place, stand.standing === null ? null
|
|
306
|
+
: { at: mm(stand.standing.position), size: mm(stand.standing.size), turn: stand.standing.turn ?? 0 }));
|
|
307
|
+
}
|
|
308
|
+
/** Retire a place. It stays in the history. */
|
|
309
|
+
retirePlace(which) { return this.write(retirePlace(which.place)); }
|
|
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
|
+
return this.write(putItem(put.item, put.place, put.slot ?? null));
|
|
313
|
+
}
|
|
314
|
+
/** Set one field on a part (by checksum), an item or a place (by ID). */
|
|
253
315
|
setField(change) {
|
|
254
316
|
return this.write(setField(change.on, change.id, change.field, change.value));
|
|
255
317
|
}
|
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,S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ACpB,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"];
|
|
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. */
|
package/dist/source.d.ts.map
CHANGED
|
@@ -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,
|
|
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,yPAE6E,CAAC;AAElG,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"];
|
|
4
5
|
/**
|
|
5
6
|
* Do one of the things a window may ask for.
|
|
6
7
|
*
|
package/dist/source.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAWA,2FAA2F;AAC3F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS;IACvF,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"source.js","sourceRoot":"","sources":["../src/source.ts"],"names":[],"mappings":"AAWA,2FAA2F;AAC3F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS;IACvF,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS;IAClF,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,CAAU,CAAC;AAkBlG;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAQ,EAAE,MAAc,EAAE,OAAiB;IACvE,IAAI,CAAE,OAA6B,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,sCAAsC,EAAE,CAAC;IAC1H,IAAI,CAAC;QACH,MAAM,MAAM,GAAI,GAAwE,CAAC,MAAM,CAAE,CAAC;QAClG,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;IAC/D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;IACtF,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAQ;IAC/B,OAAO,EAAE,SAAS,EAAE,GAAG,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;AACvH,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"url": "https://github.com/matthewlovestocode/biolibs/issues"
|
|
4
4
|
},
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@biolibs/bionet": "^1.
|
|
6
|
+
"@biolibs/bionet": "^1.3.0",
|
|
7
7
|
"@biolibs/opencloning": "^2.0.0"
|
|
8
8
|
},
|
|
9
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",
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
},
|
|
47
47
|
"type": "module",
|
|
48
48
|
"types": "dist/index.d.ts",
|
|
49
|
-
"version": "0.
|
|
49
|
+
"version": "0.2.0"
|
|
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,
|
|
15
|
-
|
|
16
|
-
type
|
|
13
|
+
import { addItem, addPart, addPlace, addToRoster, adjustItem, entryId, fetchInventory, foundLab, isMember, mergeLog,
|
|
14
|
+
movePlace, newItemId, newPlaceId, nextEntry, offerPart, publicInventory, putItem, 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 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,10 @@ 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[];
|
|
57
63
|
overlaps: Overlap[];
|
|
58
64
|
/** How many entries are waiting on others that have not arrived. */
|
|
59
65
|
waiting: number;
|
|
@@ -210,6 +216,8 @@ export class Lab {
|
|
|
210
216
|
roster: state.roster.map((one) => ({ ...one, fingerprint: this.fingerprints.get(one.key) ?? "", you: one.key === mine })),
|
|
211
217
|
parts: state.parts,
|
|
212
218
|
items: state.items,
|
|
219
|
+
places: state.places,
|
|
220
|
+
crowded: state.crowded,
|
|
213
221
|
overlaps: state.overlaps,
|
|
214
222
|
waiting: state.waiting.length,
|
|
215
223
|
entries: state.entries.map((one) => ({
|
|
@@ -304,6 +312,36 @@ export class Lab {
|
|
|
304
312
|
this.changed();
|
|
305
313
|
}
|
|
306
314
|
|
|
315
|
+
/**
|
|
316
|
+
* Seal this device's key under a passphrase, to keep somewhere that is not this device.
|
|
317
|
+
*
|
|
318
|
+
* @param passphrase - What it will take to open it again. Nothing here remembers it.
|
|
319
|
+
* @returns The sealed key as text, to be written to a file. It holds nothing readable without the passphrase.
|
|
320
|
+
*/
|
|
321
|
+
async backUp(passphrase: string): Promise<string> {
|
|
322
|
+
const exported = await this.options.keys.load();
|
|
323
|
+
if (exported === null) throw new Error("This device has no key to back up.");
|
|
324
|
+
return JSON.stringify(await sealKey(exported, passphrase), null, 2);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Take up a key from a backup, in place of the one this device made for itself.
|
|
329
|
+
*
|
|
330
|
+
* This is for a new device standing in for a lost one, so it is refused once the device is in a
|
|
331
|
+
* lab: a key in use on two devices at once writes two histories under one name, and the lab
|
|
332
|
+
* cannot tell which is true.
|
|
333
|
+
*
|
|
334
|
+
* @param from - The text of the backup file, and the passphrase it was sealed under.
|
|
335
|
+
*/
|
|
336
|
+
async restore(from: { backup: string; passphrase: string }): Promise<void> {
|
|
337
|
+
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.");
|
|
338
|
+
const exported = await openKey(from.backup, from.passphrase);
|
|
339
|
+
await this.options.keys.save(exported);
|
|
340
|
+
this.key = await importSigningKey(exported);
|
|
341
|
+
this.fingerprint = await keyFingerprint(this.key.publicKey);
|
|
342
|
+
this.changed();
|
|
343
|
+
}
|
|
344
|
+
|
|
307
345
|
/** Stop talking to the peer, until `goOnline`. The device goes on working. */
|
|
308
346
|
goOffline(): void { this.link?.stop(); }
|
|
309
347
|
|
|
@@ -345,8 +383,42 @@ export class Lab {
|
|
|
345
383
|
/** Say whether a part is on offer to other labs. */
|
|
346
384
|
offer(offer: { part: string; available: boolean }): Promise<void> { return this.write(offerPart(offer.part, offer.available)); }
|
|
347
385
|
|
|
348
|
-
/**
|
|
349
|
-
|
|
386
|
+
/**
|
|
387
|
+
* Add a place: a room, a freezer, a shelf, a box.
|
|
388
|
+
*
|
|
389
|
+
* @param place - What kind it is, what it is called, the place it is in if any, and for a box how
|
|
390
|
+
* many rows and columns of positions it has.
|
|
391
|
+
* @returns The new place's ID.
|
|
392
|
+
*/
|
|
393
|
+
async addPlace(place: { kind: string; name: string; parent?: string | null; grid?: { rows: number; columns: number } | null }): Promise<string> {
|
|
394
|
+
const id = newPlaceId();
|
|
395
|
+
await this.write(addPlace({ place: id, kind: place.kind.trim().toLowerCase(), name: place.name.trim(), parent: place.parent ?? null, grid: place.grid ?? null }));
|
|
396
|
+
return id;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Put a place inside another, or with `null` inside nothing. */
|
|
400
|
+
movePlace(move: { place: string; parent: string | null }): Promise<void> { return this.write(movePlace(move.place, move.parent)); }
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Say where a place stands and how big it is, in metres, or with `null` that nobody has said.
|
|
404
|
+
* It is kept to the millimetre.
|
|
405
|
+
*/
|
|
406
|
+
standPlace(stand: { place: string; standing: { position: [number, number, number]; size: [number, number, number]; turn?: 0 | 90 | 180 | 270 } | null }): Promise<void> {
|
|
407
|
+
const mm = (list: [number, number, number]): [number, number, number] => [Math.round(list[0] * 1000), Math.round(list[1] * 1000), Math.round(list[2] * 1000)];
|
|
408
|
+
return this.write(standPlace(stand.place, stand.standing === null ? null
|
|
409
|
+
: { at: mm(stand.standing.position), size: mm(stand.standing.size), turn: stand.standing.turn ?? 0 }));
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** Retire a place. It stays in the history. */
|
|
413
|
+
retirePlace(which: { place: string }): Promise<void> { return this.write(retirePlace(which.place)); }
|
|
414
|
+
|
|
415
|
+
/** Say where an item is: which place, and which position if the place is a box. `null` for nowhere recorded. */
|
|
416
|
+
putItem(put: { item: string; place: string | null; slot?: { row: number; column: number } | null }): Promise<void> {
|
|
417
|
+
return this.write(putItem(put.item, put.place, put.slot ?? null));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
/** Set one field on a part (by checksum), an item or a place (by ID). */
|
|
421
|
+
setField(change: { on: "part" | "item" | "place"; id: string; field: string; value: string | number | null }): Promise<void> {
|
|
350
422
|
return this.write(setField(change.on, change.id, change.field, change.value));
|
|
351
423
|
}
|
|
352
424
|
|
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"
|
|
14
|
+
"adjust", "recount", "retire", "offer", "setField", "publish", "backUp", "restore",
|
|
15
|
+
"addPlace", "movePlace", "standPlace", "retirePlace", "putItem"] as const;
|
|
15
16
|
|
|
16
17
|
/** One thing a window may ask for. */
|
|
17
18
|
export type Action = (typeof ACTIONS)[number];
|