mindoodb 0.0.97 → 0.0.99

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.
Files changed (166) hide show
  1. package/README-server.md +15 -0
  2. package/README.md +1 -0
  3. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +7 -0
  4. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
  5. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +17 -9
  6. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
  7. package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -1
  8. package/dist/appendonlystores/network/HttpTransport.js +1 -0
  9. package/dist/appendonlystores/network/HttpTransport.js.map +1 -1
  10. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +18 -0
  11. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
  12. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +41 -1
  13. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
  14. package/dist/browser/index.mjs +76 -0
  15. package/dist/core/BaseMindooDB.d.ts +2 -0
  16. package/dist/core/BaseMindooDB.d.ts.map +1 -1
  17. package/dist/core/BaseMindooDB.js +73 -53
  18. package/dist/core/BaseMindooDB.js.map +1 -1
  19. package/dist/core/BaseMindooTenant.d.ts +44 -1
  20. package/dist/core/BaseMindooTenant.d.ts.map +1 -1
  21. package/dist/core/BaseMindooTenant.js +176 -42
  22. package/dist/core/BaseMindooTenant.js.map +1 -1
  23. package/dist/core/BaseMindooTenantDirectory.d.ts +11 -0
  24. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  25. package/dist/core/BaseMindooTenantDirectory.js +137 -92
  26. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  27. package/dist/core/MindooDBServerAdmin.d.ts +1 -1
  28. package/dist/core/MindooDBServerAdmin.d.ts.map +1 -1
  29. package/dist/core/appendonlystores/migration/StoreMigration.d.ts +41 -1
  30. package/dist/core/appendonlystores/migration/StoreMigration.d.ts.map +1 -1
  31. package/dist/core/appendonlystores/migration/StoreMigration.js +126 -0
  32. package/dist/core/appendonlystores/migration/StoreMigration.js.map +1 -1
  33. package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.d.ts.map +1 -1
  34. package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js +29 -0
  35. package/dist/core/appendonlystores/sqlite/SqliteContentAddressedStore.js.map +1 -1
  36. package/dist/core/appendonlystores/syncStores.d.ts +6 -0
  37. package/dist/core/appendonlystores/syncStores.d.ts.map +1 -1
  38. package/dist/core/appendonlystores/syncStores.js +21 -0
  39. package/dist/core/appendonlystores/syncStores.js.map +1 -1
  40. package/dist/core/appendonlystores/types.d.ts +8 -0
  41. package/dist/core/appendonlystores/types.d.ts.map +1 -1
  42. package/dist/core/appendonlystores/types.js.map +1 -1
  43. package/dist/core/builtinDbInvariants.d.ts +26 -1
  44. package/dist/core/builtinDbInvariants.d.ts.map +1 -1
  45. package/dist/core/builtinDbInvariants.js +52 -2
  46. package/dist/core/builtinDbInvariants.js.map +1 -1
  47. package/dist/core/index.d.ts +2 -0
  48. package/dist/core/index.d.ts.map +1 -1
  49. package/dist/core/index.js +3 -0
  50. package/dist/core/index.js.map +1 -1
  51. package/dist/core/joinrequests/crypto.d.ts +110 -0
  52. package/dist/core/joinrequests/crypto.d.ts.map +1 -0
  53. package/dist/core/joinrequests/crypto.js +340 -0
  54. package/dist/core/joinrequests/crypto.js.map +1 -0
  55. package/dist/core/joinrequests/index.d.ts +4 -0
  56. package/dist/core/joinrequests/index.d.ts.map +1 -0
  57. package/dist/core/joinrequests/index.js +29 -0
  58. package/dist/core/joinrequests/index.js.map +1 -0
  59. package/dist/core/joinrequests/invitations.d.ts +257 -0
  60. package/dist/core/joinrequests/invitations.d.ts.map +1 -0
  61. package/dist/core/joinrequests/invitations.js +703 -0
  62. package/dist/core/joinrequests/invitations.js.map +1 -0
  63. package/dist/core/joinrequests/types.d.ts +208 -0
  64. package/dist/core/joinrequests/types.d.ts.map +1 -0
  65. package/dist/core/joinrequests/types.js +43 -0
  66. package/dist/core/joinrequests/types.js.map +1 -0
  67. package/dist/core/recovery/PaperRescueDevice.d.ts +101 -0
  68. package/dist/core/recovery/PaperRescueDevice.d.ts.map +1 -0
  69. package/dist/core/recovery/PaperRescueDevice.js +205 -0
  70. package/dist/core/recovery/PaperRescueDevice.js.map +1 -0
  71. package/dist/core/recovery/RecoveryContactsDocument.d.ts +86 -0
  72. package/dist/core/recovery/RecoveryContactsDocument.d.ts.map +1 -0
  73. package/dist/core/recovery/RecoveryContactsDocument.js +91 -0
  74. package/dist/core/recovery/RecoveryContactsDocument.js.map +1 -0
  75. package/dist/core/recovery/RecoveryContactsManager.d.ts +176 -0
  76. package/dist/core/recovery/RecoveryContactsManager.d.ts.map +1 -0
  77. package/dist/core/recovery/RecoveryContactsManager.js +455 -0
  78. package/dist/core/recovery/RecoveryContactsManager.js.map +1 -0
  79. package/dist/core/recovery/index.d.ts +9 -0
  80. package/dist/core/recovery/index.d.ts.map +1 -0
  81. package/dist/core/recovery/index.js +48 -0
  82. package/dist/core/recovery/index.js.map +1 -0
  83. package/dist/core/recovery/recoverWithContacts.d.ts +56 -0
  84. package/dist/core/recovery/recoverWithContacts.d.ts.map +1 -0
  85. package/dist/core/recovery/recoverWithContacts.js +142 -0
  86. package/dist/core/recovery/recoverWithContacts.js.map +1 -0
  87. package/dist/core/recovery/recoveryPackage.d.ts +80 -0
  88. package/dist/core/recovery/recoveryPackage.d.ts.map +1 -0
  89. package/dist/core/recovery/recoveryPackage.js +182 -0
  90. package/dist/core/recovery/recoveryPackage.js.map +1 -0
  91. package/dist/core/recovery/rescueApproval.d.ts +39 -0
  92. package/dist/core/recovery/rescueApproval.d.ts.map +1 -0
  93. package/dist/core/recovery/rescueApproval.js +52 -0
  94. package/dist/core/recovery/rescueApproval.js.map +1 -0
  95. package/dist/core/recovery/rescueDevice.d.ts +51 -0
  96. package/dist/core/recovery/rescueDevice.d.ts.map +1 -0
  97. package/dist/core/recovery/rescueDevice.js +201 -0
  98. package/dist/core/recovery/rescueDevice.js.map +1 -0
  99. package/dist/core/recovery/shamir.d.ts +30 -0
  100. package/dist/core/recovery/shamir.d.ts.map +1 -0
  101. package/dist/core/recovery/shamir.js +133 -0
  102. package/dist/core/recovery/shamir.js.map +1 -0
  103. package/dist/core/types.d.ts +73 -1
  104. package/dist/core/types.d.ts.map +1 -1
  105. package/dist/core/types.js.map +1 -1
  106. package/dist/core/userkeys/UserKeyManager.d.ts +45 -0
  107. package/dist/core/userkeys/UserKeyManager.d.ts.map +1 -1
  108. package/dist/core/userkeys/UserKeyManager.js +121 -8
  109. package/dist/core/userkeys/UserKeyManager.js.map +1 -1
  110. package/dist/core/userkeys/generationSignature.d.ts +6 -0
  111. package/dist/core/userkeys/generationSignature.d.ts.map +1 -1
  112. package/dist/core/userkeys/generationSignature.js +1 -0
  113. package/dist/core/userkeys/generationSignature.js.map +1 -1
  114. package/dist/core/userkeys/resolveUserKeyDocument.d.ts.map +1 -1
  115. package/dist/core/userkeys/resolveUserKeyDocument.js +6 -6
  116. package/dist/core/userkeys/resolveUserKeyDocument.js.map +1 -1
  117. package/dist/core/userkeys/validateUserKeyDocument.d.ts +11 -1
  118. package/dist/core/userkeys/validateUserKeyDocument.d.ts.map +1 -1
  119. package/dist/core/userkeys/validateUserKeyDocument.js +18 -5
  120. package/dist/core/userkeys/validateUserKeyDocument.js.map +1 -1
  121. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.d.ts +23 -0
  122. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.d.ts.map +1 -0
  123. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.js +119 -0
  124. package/dist/node/appendonlystores/sqlite/FsBlobContentStore.js.map +1 -0
  125. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.d.ts +43 -0
  126. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.d.ts.map +1 -0
  127. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.js +121 -0
  128. package/dist/node/appendonlystores/sqlite/NodeSqliteStore.js.map +1 -0
  129. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.d.ts +43 -0
  130. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.d.ts.map +1 -0
  131. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.js +279 -0
  132. package/dist/node/appendonlystores/sqlite/ServerSqliteStore.js.map +1 -0
  133. package/dist/node/server/MindooDBServer.d.ts +2 -0
  134. package/dist/node/server/MindooDBServer.d.ts.map +1 -1
  135. package/dist/node/server/MindooDBServer.js +46 -0
  136. package/dist/node/server/MindooDBServer.js.map +1 -1
  137. package/dist/node/server/StoreFactory.d.ts +5 -2
  138. package/dist/node/server/StoreFactory.d.ts.map +1 -1
  139. package/dist/node/server/StoreFactory.js +21 -4
  140. package/dist/node/server/StoreFactory.js.map +1 -1
  141. package/dist/node/server/TenantManager.d.ts +6 -0
  142. package/dist/node/server/TenantManager.d.ts.map +1 -1
  143. package/dist/node/server/TenantManager.js +17 -0
  144. package/dist/node/server/TenantManager.js.map +1 -1
  145. package/dist/node/server/server.js +2 -0
  146. package/dist/node/server/server.js.map +1 -1
  147. package/dist/server/JoinRequestService.d.ts +108 -0
  148. package/dist/server/JoinRequestService.d.ts.map +1 -0
  149. package/dist/server/JoinRequestService.js +454 -0
  150. package/dist/server/JoinRequestService.js.map +1 -0
  151. package/dist/server/TenantManager.d.ts +57 -1
  152. package/dist/server/TenantManager.d.ts.map +1 -1
  153. package/dist/server/TenantManager.js +273 -34
  154. package/dist/server/TenantManager.js.map +1 -1
  155. package/dist/server/http/MindooDBServerCore.d.ts +18 -0
  156. package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
  157. package/dist/server/http/MindooDBServerCore.js +230 -137
  158. package/dist/server/http/MindooDBServerCore.js.map +1 -1
  159. package/dist/server/serverConfig.d.ts.map +1 -1
  160. package/dist/server/serverConfig.js +17 -0
  161. package/dist/server/serverConfig.js.map +1 -1
  162. package/dist/server/types.d.ts +16 -1
  163. package/dist/server/types.d.ts.map +1 -1
  164. package/dist/server/types.js +6 -0
  165. package/dist/server/types.js.map +1 -1
  166. package/package.json +1 -1
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecoveryError = void 0;
4
+ exports.certifyDeviceWithRescueDevice = certifyDeviceWithRescueDevice;
5
+ exports.approveDeviceWithRescueDevice = approveDeviceWithRescueDevice;
6
+ /**
7
+ * Recovery on a new device (docs/userkeys.md §12.4): act as the rescue device
8
+ * for one session and certify the new device's keys with the person's
9
+ * self-grant key, which the rescue device receives as a wrap like any device.
10
+ *
11
+ * The rescue device runs in throwaway in-memory storage. It authenticates to
12
+ * the server with its own keys (the server knows it from its `dcert_`
13
+ * certificate), pulls `directory` and `userdirectory`, opens the User-Key and
14
+ * self-grant key wrapped to it, writes the new device's certificate plus its
15
+ * wraps and pushes `userdirectory`. From then on the new device is a device
16
+ * of the person in its own right and joins through ordinary device discovery
17
+ * (`discoverTenantsOnServer` + `bootstrapTenantFromDelivery`).
18
+ */
19
+ const BaseMindooTenantFactory_1 = require("../BaseMindooTenantFactory");
20
+ const InMemoryContentAddressedStore_1 = require("../appendonlystores/InMemoryContentAddressedStore");
21
+ const types_1 = require("../types");
22
+ const rescueDevice_1 = require("./rescueDevice");
23
+ const fingerprint_1 = require("../userkeys/fingerprint");
24
+ class RecoveryError extends Error {
25
+ constructor(code, message) {
26
+ super(message);
27
+ this.code = code;
28
+ this.name = "RecoveryError";
29
+ }
30
+ }
31
+ exports.RecoveryError = RecoveryError;
32
+ function randomPassword(crypto) {
33
+ const bytes = crypto.getRandomValues(new Uint8Array(24));
34
+ let out = "";
35
+ for (const b of bytes)
36
+ out += b.toString(16).padStart(2, "0");
37
+ return out;
38
+ }
39
+ /** Sign in to the server as the rescue device, in throwaway storage. */
40
+ async function openRescueSession(input) {
41
+ const serverUrl = (input.serverUrl ?? input.recovery.serverUrl ?? "").trim().replace(/\/$/, "");
42
+ if (!serverUrl)
43
+ throw new RecoveryError("no-server", "No server address to recover from.");
44
+ const crypto = input.cryptoAdapter;
45
+ const password = randomPassword(crypto);
46
+ const rescueUser = await (0, rescueDevice_1.rescueDeviceUserId)(crypto, input.recovery.rescueDevice, input.recovery.username, password);
47
+ const factory = new BaseMindooTenantFactory_1.BaseMindooTenantFactory(input.storeFactory ?? new InMemoryContentAddressedStore_1.InMemoryContentAddressedStoreFactory(), crypto);
48
+ const refused = (error) => new RecoveryError("not-certified", `The server does not accept the rescue device (${error instanceof Error ? error.message : String(error)}). It may have been replaced by a newer setup.`);
49
+ let deliveries;
50
+ try {
51
+ deliveries = await factory.discoverTenantsOnServer(serverUrl, { user: rescueUser, password });
52
+ }
53
+ catch (error) {
54
+ throw refused(error);
55
+ }
56
+ const delivery = deliveries.find((d) => d.tenantId === input.recovery.tenantId);
57
+ if (!delivery) {
58
+ throw new RecoveryError("tenant-not-found", `The rescue device has no access to tenant "${input.recovery.tenantId}" on ${serverUrl}.`);
59
+ }
60
+ try {
61
+ // A withdrawn rescue device still finds the tenant (discovery keeps naming
62
+ // revoked devices so they can learn about a wipe), but sync refuses it.
63
+ const joined = await factory.bootstrapTenantFromDelivery(delivery, { user: rescueUser, password, serverUrl });
64
+ return { tenant: joined.tenant, serverUrl, username: joined.user.username };
65
+ }
66
+ catch (error) {
67
+ throw refused(error);
68
+ }
69
+ }
70
+ async function pushUserDirectory(session, what) {
71
+ const local = await session.tenant.openDB(types_1.USER_DIRECTORY_DB_ID);
72
+ const remote = await session.tenant.connectToServer(session.serverUrl, types_1.USER_DIRECTORY_DB_ID);
73
+ const pushed = await local.pushChangesTo(remote);
74
+ if (pushed.cancelled)
75
+ throw new RecoveryError("sync-failed", `Sending ${what} to the server was cancelled.`);
76
+ }
77
+ async function closeSession(session) {
78
+ try {
79
+ await session.tenant.close?.();
80
+ }
81
+ catch {
82
+ // throwaway session
83
+ }
84
+ }
85
+ /**
86
+ * Certify a new device of the person with the rescue device that the
87
+ * combined helper packages opened.
88
+ */
89
+ async function certifyDeviceWithRescueDevice(input) {
90
+ const session = await openRescueSession(input);
91
+ try {
92
+ if (!session.tenant.issueDeviceCertificate) {
93
+ throw new RecoveryError("not-certified", "This tenant cannot certify devices.");
94
+ }
95
+ // bootstrap pulled both directories and reconciled; certify now.
96
+ const { docId } = await session.tenant.issueDeviceCertificate(input.device, input.label);
97
+ await pushUserDirectory(session, "the new device certificate");
98
+ return {
99
+ tenantId: input.recovery.tenantId,
100
+ serverUrl: session.serverUrl,
101
+ username: session.username,
102
+ certificateDocId: docId,
103
+ rescueSigningKeyFingerprint: input.recovery.rescueDevice.signingKeyFingerprint,
104
+ };
105
+ }
106
+ finally {
107
+ await closeSession(session);
108
+ }
109
+ }
110
+ /**
111
+ * Recovery with an admin-approved rescue device (docs/userkeys.md §12.9): the
112
+ * new device has joined with a normal join request and the administrator put
113
+ * it on the person's grant. The rescue device, which holds the User-Key, now
114
+ * wraps it to the new device. Fails with `device-not-on-grant` while the
115
+ * administrator has not approved the new device yet — call again later.
116
+ */
117
+ async function approveDeviceWithRescueDevice(input) {
118
+ const session = await openRescueSession(input);
119
+ try {
120
+ const crypto = input.cryptoAdapter;
121
+ const fingerprint = await (0, fingerprint_1.fingerprintPublicKeyPem)(input.deviceEncryptionPublicKey, crypto.getSubtle());
122
+ const rows = (await session.tenant.listUserKeyDevices?.()) ?? [];
123
+ const row = rows.find((r) => r.fingerprint === fingerprint);
124
+ if (!row) {
125
+ throw new RecoveryError("device-not-on-grant", "The administrator has not added this device to the person yet.");
126
+ }
127
+ if (row.status !== "approved") {
128
+ await session.tenant.approveUserKeyDevice(fingerprint);
129
+ await pushUserDirectory(session, "the User-Key for the new device");
130
+ }
131
+ return {
132
+ tenantId: input.recovery.tenantId,
133
+ serverUrl: session.serverUrl,
134
+ username: session.username,
135
+ rescueSigningKeyFingerprint: input.recovery.rescueDevice.signingKeyFingerprint,
136
+ };
137
+ }
138
+ finally {
139
+ await closeSession(session);
140
+ }
141
+ }
142
+ //# sourceMappingURL=recoverWithContacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoverWithContacts.js","sourceRoot":"","sources":["../../../src/core/recovery/recoverWithContacts.ts"],"names":[],"mappings":";;;AA8HA,sEAqBC;AASD,sEAiCC;AA7LD;;;;;;;;;;;;GAYG;AACH,wEAAqE;AACrE,qGAAyG;AAEzG,oCAAmF;AAEnF,iDAAoD;AACpD,yDAAkE;AAElE,MAAa,aAAc,SAAQ,KAAK;IACtC,YACW,IAAgG,EACzG,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAA4F;QAIzG,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AARD,sCAQC;AAwBD,SAAS,cAAc,CAAC,MAAqB;IAC3C,MAAM,KAAK,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;IACzD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,GAAG,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC9D,OAAO,GAAG,CAAC;AACb,CAAC;AAQD,wEAAwE;AACxE,KAAK,UAAU,iBAAiB,CAAC,KAKhC;IACC,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAChG,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,aAAa,CAAC,WAAW,EAAE,oCAAoC,CAAC,CAAC;IAC3F,MAAM,MAAM,GAAG,KAAK,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qB,CAAC,WAAW,CAAC,CAAC;YACxD,MAAM,iBAAiB,CAAC,OAAO,EAAE,iCAAiC,CAAC,CAAC;QACtE,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;YACjC,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,OAAO,CAAC,QAAQ;YAC1B,2BAA2B,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,qBAAqB;SAC/E,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC;AACH,CAAC"}
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Helper packages of recovery contacts (docs/userkeys.md §12).
3
+ *
4
+ * A contact who helps hands the person a package: their share of the
5
+ * recovery secret plus what the new device needs to find the tenant — server,
6
+ * tenant id, username and the encrypted rescue device. The package is
7
+ * encrypted with a one-time password the helper's app generates and shows
8
+ * separately, so a package that leaks on the way (chat, mail, a photo of the
9
+ * screen) is useless without its password, and even with it one share alone
10
+ * opens nothing.
11
+ *
12
+ * Text form: `mdbrescue1.` + base64url(salt(16) | iv(12) | iterations(u32) |
13
+ * AES-256-GCM ciphertext), key = PBKDF2-SHA-256(password, salt). The
14
+ * plaintext is JSON and stays well below what a QR code holds.
15
+ */
16
+ import type { CryptoAdapter } from "../crypto/CryptoAdapter";
17
+ import { type OpenedRescueDevice } from "./rescueDevice";
18
+ export declare const RECOVERY_PACKAGE_PREFIX = "mdbrescue1.";
19
+ /** What one contact hands over (plaintext; encrypted for transport). */
20
+ export interface RecoveryHelperPackage {
21
+ v: 1;
22
+ kind: "mindoodb-recovery-share";
23
+ tenantId: string;
24
+ /** Sync server of the tenant, as the helper's app knows it. */
25
+ serverUrl?: string;
26
+ /** The person being recovered. */
27
+ username: string;
28
+ /** The `rcv_` document the share belongs to. */
29
+ setupDocId: string;
30
+ threshold: number;
31
+ rescueSigningKeyFingerprint: string;
32
+ /**
33
+ * `admin` when the rescue device is on the person's grant instead of
34
+ * certified (docs/userkeys.md §12.9): the new device then needs the
35
+ * administrator's approval, and the rescue device wraps the User-Key to it.
36
+ */
37
+ rescueApproval?: "admin";
38
+ rescueBlob: string;
39
+ /** Base64 Shamir share. */
40
+ share: string;
41
+ /** Who helped (display only). */
42
+ helper: string;
43
+ createdAt: number;
44
+ }
45
+ /** The result of combining enough packages: the opened rescue device. */
46
+ export interface CombinedRecoveryPackages {
47
+ tenantId: string;
48
+ serverUrl?: string;
49
+ username: string;
50
+ setupDocId: string;
51
+ helpers: string[];
52
+ /** See {@link RecoveryHelperPackage.rescueApproval}. Default `certificate`. */
53
+ rescueApproval?: "admin";
54
+ rescueDevice: OpenedRescueDevice;
55
+ }
56
+ export declare class RecoveryPackageError extends Error {
57
+ readonly code: "malformed" | "wrong-password" | "too-few" | "mismatch" | "duplicate" | "cannot-open";
58
+ constructor(code: "malformed" | "wrong-password" | "too-few" | "mismatch" | "duplicate" | "cannot-open", message: string);
59
+ }
60
+ /**
61
+ * A one-time password for a package: 12 characters from an alphabet without
62
+ * look-alikes (about 59 bits), shown in groups of four (`abcd-efgh-jkmn`).
63
+ */
64
+ export declare function generateRecoveryPackagePassword(crypto: CryptoAdapter): string;
65
+ /** Typed passwords: case, spaces and dashes do not matter. */
66
+ export declare function normalizeRecoveryPackagePassword(password: string): string;
67
+ /** Encrypt a package with its one-time password into the text form. */
68
+ export declare function encryptRecoveryHelperPackage(crypto: CryptoAdapter, pkg: RecoveryHelperPackage, password: string): Promise<string>;
69
+ /** Pull the package text out of whatever was pasted or scanned. */
70
+ export declare function extractRecoveryPackageText(input: string): string | null;
71
+ /** Decrypt a package; throws {@link RecoveryPackageError}. */
72
+ export declare function decryptRecoveryHelperPackage(crypto: CryptoAdapter, text: string, password: string): Promise<RecoveryHelperPackage>;
73
+ /**
74
+ * Combine decrypted packages from different contacts of the same setup and
75
+ * open the rescue device. Fails with `too-few` below the threshold, `mismatch`
76
+ * when the packages belong to different setups, `duplicate` for the same
77
+ * share twice, and `cannot-open` when the combination does not open the blob.
78
+ */
79
+ export declare function combineRecoveryHelperPackages(crypto: CryptoAdapter, packages: RecoveryHelperPackage[]): Promise<CombinedRecoveryPackages>;
80
+ //# sourceMappingURL=recoveryPackage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoveryPackage.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/recoveryPackage.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI7D,OAAO,EAAoB,KAAK,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE3E,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAMrD,wEAAwE;AACxE,MAAM,WAAW,qBAAqB;IACpC,CAAC,EAAE,CAAC,CAAC;IACL,IAAI,EAAE,yBAAyB,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,+DAA+D;IAC/D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,gDAAgD;IAChD,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,2BAA2B,EAAE,MAAM,CAAC;IACpC;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,yEAAyE;AACzE,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,+EAA+E;IAC/E,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,YAAY,EAAE,kBAAkB,CAAC;CAClC;AAED,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,IAAI,EACT,WAAW,GACX,gBAAgB,GAChB,SAAS,GACT,UAAU,GACV,WAAW,GACX,aAAa;gBANR,IAAI,EACT,WAAW,GACX,gBAAgB,GAChB,SAAS,GACT,UAAU,GACV,WAAW,GACX,aAAa,EACjB,OAAO,EAAE,MAAM;CAKlB;AAeD;;;GAGG;AACH,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAU7E;AAED,8DAA8D;AAC9D,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzE;AA0BD,uEAAuE;AACvE,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,aAAa,EACrB,GAAG,EAAE,qBAAqB,EAC1B,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAED,mEAAmE;AACnE,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGvE;AAED,8DAA8D;AAC9D,wBAAsB,4BAA4B,CAChD,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,qBAAqB,CAAC,CAiDhC;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,qBAAqB,EAAE,GAChC,OAAO,CAAC,wBAAwB,CAAC,CA4CnC"}
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecoveryPackageError = exports.RECOVERY_PACKAGE_PREFIX = void 0;
4
+ exports.generateRecoveryPackagePassword = generateRecoveryPackagePassword;
5
+ exports.normalizeRecoveryPackagePassword = normalizeRecoveryPackagePassword;
6
+ exports.encryptRecoveryHelperPackage = encryptRecoveryHelperPackage;
7
+ exports.extractRecoveryPackageText = extractRecoveryPackageText;
8
+ exports.decryptRecoveryHelperPackage = decryptRecoveryHelperPackage;
9
+ exports.combineRecoveryHelperPackages = combineRecoveryHelperPackages;
10
+ const pbkdf2Iterations_1 = require("../crypto/pbkdf2Iterations");
11
+ const fingerprint_1 = require("../userkeys/fingerprint");
12
+ const shamir_1 = require("./shamir");
13
+ const rescueDevice_1 = require("./rescueDevice");
14
+ exports.RECOVERY_PACKAGE_PREFIX = "mdbrescue1.";
15
+ const PACKAGE_AAD = new TextEncoder().encode("mindoodb-recovery-package-v1");
16
+ /** Unambiguous lower-case letters and digits (no 0/o, 1/l/i). */
17
+ const PASSWORD_ALPHABET = "abcdefghjkmnpqrstuvwxyz23456789";
18
+ const PASSWORD_LENGTH = 12;
19
+ class RecoveryPackageError extends Error {
20
+ constructor(code, message) {
21
+ super(message);
22
+ this.code = code;
23
+ this.name = "RecoveryPackageError";
24
+ }
25
+ }
26
+ exports.RecoveryPackageError = RecoveryPackageError;
27
+ function toBuffer(bytes) {
28
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
29
+ }
30
+ function bytesToBase64Url(bytes) {
31
+ return (0, fingerprint_1.bytesToBase64)(bytes).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
32
+ }
33
+ function base64UrlToBytes(value) {
34
+ const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
35
+ return (0, fingerprint_1.base64ToBytes)(normalized + "=".repeat((4 - (normalized.length % 4)) % 4));
36
+ }
37
+ /**
38
+ * A one-time password for a package: 12 characters from an alphabet without
39
+ * look-alikes (about 59 bits), shown in groups of four (`abcd-efgh-jkmn`).
40
+ */
41
+ function generateRecoveryPackagePassword(crypto) {
42
+ const bound = 256 - (256 % PASSWORD_ALPHABET.length);
43
+ const chars = [];
44
+ const byte = new Uint8Array(1);
45
+ while (chars.length < PASSWORD_LENGTH) {
46
+ crypto.getRandomValues(byte);
47
+ if (byte[0] >= bound)
48
+ continue;
49
+ chars.push(PASSWORD_ALPHABET[byte[0] % PASSWORD_ALPHABET.length]);
50
+ }
51
+ return [chars.slice(0, 4), chars.slice(4, 8), chars.slice(8)].map((g) => g.join("")).join("-");
52
+ }
53
+ /** Typed passwords: case, spaces and dashes do not matter. */
54
+ function normalizeRecoveryPackagePassword(password) {
55
+ return password.toLowerCase().replace(/[^a-z0-9]/g, "");
56
+ }
57
+ async function packageKey(crypto, password, salt, iterations, usage) {
58
+ const subtle = crypto.getSubtle();
59
+ const base = await subtle.importKey("raw", toBuffer(new TextEncoder().encode(normalizeRecoveryPackagePassword(password))), "PBKDF2", false, ["deriveKey"]);
60
+ return subtle.deriveKey({ name: "PBKDF2", hash: "SHA-256", salt: toBuffer(salt), iterations }, base, { name: "AES-GCM", length: 256 }, false, [usage]);
61
+ }
62
+ /** Encrypt a package with its one-time password into the text form. */
63
+ async function encryptRecoveryHelperPackage(crypto, pkg, password) {
64
+ if (normalizeRecoveryPackagePassword(password).length < 8) {
65
+ throw new Error("The package password is too short.");
66
+ }
67
+ const salt = crypto.getRandomValues(new Uint8Array(16));
68
+ const iv = crypto.getRandomValues(new Uint8Array(12));
69
+ const iterations = (0, pbkdf2Iterations_1.resolvePbkdf2Iterations)(pbkdf2Iterations_1.DEFAULT_PBKDF2_ITERATIONS);
70
+ const ciphertext = new Uint8Array(await crypto.getSubtle().encrypt({ name: "AES-GCM", iv: toBuffer(iv), additionalData: toBuffer(PACKAGE_AAD), tagLength: 128 }, await packageKey(crypto, password, salt, iterations, "encrypt"), toBuffer(new TextEncoder().encode(JSON.stringify(pkg)))));
71
+ const out = new Uint8Array(16 + 12 + 4 + ciphertext.length);
72
+ out.set(salt, 0);
73
+ out.set(iv, 16);
74
+ new DataView(out.buffer).setUint32(28, iterations);
75
+ out.set(ciphertext, 32);
76
+ return exports.RECOVERY_PACKAGE_PREFIX + bytesToBase64Url(out);
77
+ }
78
+ /** Pull the package text out of whatever was pasted or scanned. */
79
+ function extractRecoveryPackageText(input) {
80
+ const match = input.match(/mdbrescue1\.[A-Za-z0-9_-]+/);
81
+ return match ? match[0] : null;
82
+ }
83
+ /** Decrypt a package; throws {@link RecoveryPackageError}. */
84
+ async function decryptRecoveryHelperPackage(crypto, text, password) {
85
+ const extracted = extractRecoveryPackageText(text);
86
+ if (!extracted)
87
+ throw new RecoveryPackageError("malformed", "This is not a recovery package.");
88
+ let bytes;
89
+ try {
90
+ bytes = base64UrlToBytes(extracted.slice(exports.RECOVERY_PACKAGE_PREFIX.length));
91
+ }
92
+ catch {
93
+ throw new RecoveryPackageError("malformed", "The recovery package is damaged.");
94
+ }
95
+ if (bytes.length < 32 + 16)
96
+ throw new RecoveryPackageError("malformed", "The recovery package is damaged.");
97
+ const iterations = new DataView(bytes.buffer, bytes.byteOffset).getUint32(28);
98
+ if (iterations < pbkdf2Iterations_1.MIN_PBKDF2_ITERATIONS || iterations > 10000000) {
99
+ throw new RecoveryPackageError("malformed", "The recovery package is damaged.");
100
+ }
101
+ let plain;
102
+ try {
103
+ plain = new Uint8Array(await crypto.getSubtle().decrypt({
104
+ name: "AES-GCM",
105
+ iv: toBuffer(bytes.slice(16, 28)),
106
+ additionalData: toBuffer(PACKAGE_AAD),
107
+ tagLength: 128,
108
+ }, await packageKey(crypto, password, bytes.slice(0, 16), iterations, "decrypt"), toBuffer(bytes.slice(32))));
109
+ }
110
+ catch {
111
+ throw new RecoveryPackageError("wrong-password", "The password does not open this package.");
112
+ }
113
+ let pkg;
114
+ try {
115
+ pkg = JSON.parse(new TextDecoder().decode(plain));
116
+ }
117
+ catch {
118
+ throw new RecoveryPackageError("malformed", "The recovery package is damaged.");
119
+ }
120
+ if (pkg?.v !== 1 ||
121
+ pkg.kind !== "mindoodb-recovery-share" ||
122
+ typeof pkg.tenantId !== "string" ||
123
+ typeof pkg.username !== "string" ||
124
+ typeof pkg.setupDocId !== "string" ||
125
+ typeof pkg.share !== "string" ||
126
+ typeof pkg.rescueBlob !== "string") {
127
+ throw new RecoveryPackageError("malformed", "The recovery package is damaged.");
128
+ }
129
+ return pkg;
130
+ }
131
+ /**
132
+ * Combine decrypted packages from different contacts of the same setup and
133
+ * open the rescue device. Fails with `too-few` below the threshold, `mismatch`
134
+ * when the packages belong to different setups, `duplicate` for the same
135
+ * share twice, and `cannot-open` when the combination does not open the blob.
136
+ */
137
+ async function combineRecoveryHelperPackages(crypto, packages) {
138
+ if (packages.length === 0)
139
+ throw new RecoveryPackageError("too-few", "No recovery packages.");
140
+ const first = packages[0];
141
+ for (const pkg of packages) {
142
+ if (pkg.setupDocId !== first.setupDocId ||
143
+ pkg.tenantId !== first.tenantId ||
144
+ pkg.username !== first.username ||
145
+ pkg.rescueBlob !== first.rescueBlob ||
146
+ pkg.rescueSigningKeyFingerprint !== first.rescueSigningKeyFingerprint) {
147
+ throw new RecoveryPackageError("mismatch", "The packages belong to different recovery setups.");
148
+ }
149
+ }
150
+ const shares = packages.map((pkg) => (0, fingerprint_1.base64ToBytes)(pkg.share));
151
+ const distinct = new Set(shares.map((s) => (0, fingerprint_1.bytesToBase64)(s)));
152
+ if (distinct.size !== shares.length) {
153
+ throw new RecoveryPackageError("duplicate", "The same package was used twice.");
154
+ }
155
+ const threshold = Math.max(2, first.threshold || 2);
156
+ if (shares.length < threshold) {
157
+ throw new RecoveryPackageError("too-few", `Packages from ${threshold} different contacts are needed.`);
158
+ }
159
+ let rescueDevice;
160
+ try {
161
+ const secret = (0, shamir_1.combineShares)(shares);
162
+ rescueDevice = await (0, rescueDevice_1.openRescueDevice)(crypto, secret, first.rescueBlob);
163
+ secret.fill(0);
164
+ }
165
+ catch {
166
+ throw new RecoveryPackageError("cannot-open", "The packages do not open the rescue device.");
167
+ }
168
+ if (rescueDevice.signingKeyFingerprint !== first.rescueSigningKeyFingerprint) {
169
+ throw new RecoveryPackageError("cannot-open", "The packages do not open the rescue device.");
170
+ }
171
+ const serverUrl = packages.map((pkg) => pkg.serverUrl).find((url) => typeof url === "string" && url);
172
+ return {
173
+ tenantId: first.tenantId,
174
+ ...(serverUrl ? { serverUrl } : {}),
175
+ username: first.username,
176
+ setupDocId: first.setupDocId,
177
+ helpers: packages.map((pkg) => pkg.helper),
178
+ ...(packages.some((pkg) => pkg.rescueApproval === "admin") ? { rescueApproval: "admin" } : {}),
179
+ rescueDevice,
180
+ };
181
+ }
182
+ //# sourceMappingURL=recoveryPackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoveryPackage.js","sourceRoot":"","sources":["../../../src/core/recovery/recoveryPackage.ts"],"names":[],"mappings":";;;AAmGA,0EAUC;AAGD,4EAEC;AA2BD,oEAwBC;AAGD,gEAGC;AAGD,oEAqDC;AAQD,sEA+CC;AA1QD,iEAAuH;AACvH,yDAAuE;AACvE,qCAAyC;AACzC,iDAA2E;AAE9D,QAAA,uBAAuB,GAAG,aAAa,CAAC;AACrD,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,8BAA8B,CAAC,CAAC;AAC7E,iEAAiE;AACjE,MAAM,iBAAiB,GAAG,iCAAiC,CAAC;AAC5D,MAAM,eAAe,GAAG,EAAE,CAAC;AAyC3B,MAAa,oBAAqB,SAAQ,KAAK;IAC7C,YACW,IAMQ,EACjB,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QATN,SAAI,GAAJ,IAAI,CAMI;QAIjB,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAdD,oDAcC;AAED,SAAS,QAAQ,CAAC,KAAiB;IACjC,OAAO,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,UAAU,CAAgB,CAAC;AAClG,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAiB;IACzC,OAAO,IAAA,2BAAa,EAAC,KAAK,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,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oBAAoB,CAAC,aAAa,EAAE,6CAA6C,CAAC,CAAC;IAC/F,CAAC;IACD,IAAI,YAAY,CAAC,qBAAqB,KAAK,KAAK,CAAC,2BAA2B,EAAE,CAAC;QAC7E,MAAM,IAAI,oBAAoB,CAAC,aAAa,EAAE,6CAA6C,CAAC,CAAC;IAC/F,CAAC;IACD,MAAM,SAAS,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,CAAC;IACrG,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,OAAO,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC;QAC1C,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,OAAgB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvG,YAAY;KACb,CAAC;AACJ,CAAC"}
@@ -0,0 +1,39 @@
1
+ /** How a rescue device was admitted. Absent in older documents: `certificate`. */
2
+ export type RescueDeviceApproval = "certificate" | "admin";
3
+ export interface RescueDeviceAttestation {
4
+ /** User-Key generation whose signing key made the signature. */
5
+ epoch: string;
6
+ /** Base64 Ed25519 signature over {@link rescueAttestationMessage}. */
7
+ signature: string;
8
+ }
9
+ export declare function rescueAttestationMessage(input: {
10
+ usernameHash: string;
11
+ signingPublicKey: string;
12
+ encryptionPublicKey: string;
13
+ }): Uint8Array;
14
+ /**
15
+ * The join request the person hands to the admin for a rescue device. It
16
+ * names no user (the admin picks the existing person, §6.5) and carries no
17
+ * User-Key: the rescue device gets the person's key by wrap.
18
+ */
19
+ export declare function rescueDeviceJoinRequestUri(device: {
20
+ signingPublicKey: string;
21
+ encryptionPublicKey: string;
22
+ label: string;
23
+ }): string;
24
+ /** The public half of a rescue device as `rcv_` and `rpp_` documents store it. */
25
+ export interface RescueDeviceRef {
26
+ signingPublicKey: string;
27
+ encryptionPublicKey: string;
28
+ signingKeyFingerprint: string;
29
+ /** The `dcert_` document that certifies it (`approval: "certificate"`). */
30
+ certificateDocId?: string;
31
+ /** Absent in documents written before admin approval existed: `certificate`. */
32
+ approval?: RescueDeviceApproval;
33
+ /** Required for `approval: "admin"` (see the module comment). */
34
+ attestation?: RescueDeviceAttestation;
35
+ }
36
+ /** Shape check of a stored {@link RescueDeviceRef}. */
37
+ export declare function isRescueDeviceRef(value: unknown): value is RescueDeviceRef;
38
+ export declare function rescueApprovalOf(ref: Pick<RescueDeviceRef, "approval">): RescueDeviceApproval;
39
+ //# sourceMappingURL=rescueApproval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rescueApproval.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/rescueApproval.ts"],"names":[],"mappings":"AA2BA,kFAAkF;AAClF,MAAM,MAAM,oBAAoB,GAAG,aAAa,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,uBAAuB;IACtC,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,wBAAgB,wBAAwB,CAAC,KAAK,EAAE;IAC9C,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;CAC7B,GAAG,UAAU,CASb;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,MAAM,EAAE;IACjD,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;CACf,GAAG,MAAM,CAQT;AAED,kFAAkF;AAClF,MAAM,WAAW,eAAe;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,2EAA2E;IAC3E,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,iEAAiE;IACjE,WAAW,CAAC,EAAE,uBAAuB,CAAC;CACvC;AAED,uDAAuD;AACvD,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,eAAe,CAY1E;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,oBAAoB,CAE7F"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rescueAttestationMessage = rescueAttestationMessage;
4
+ exports.rescueDeviceJoinRequestUri = rescueDeviceJoinRequestUri;
5
+ exports.isRescueDeviceRef = isRescueDeviceRef;
6
+ exports.rescueApprovalOf = rescueApprovalOf;
7
+ const joinRequestUri_1 = require("../uri/joinRequestUri");
8
+ const fingerprint_1 = require("../userkeys/fingerprint");
9
+ const ATTESTATION_TAG = "mindoodb-rescue-device-attestation-v1";
10
+ function rescueAttestationMessage(input) {
11
+ return new TextEncoder().encode(JSON.stringify([
12
+ ATTESTATION_TAG,
13
+ input.usernameHash,
14
+ (0, fingerprint_1.normalizePublicKeyPem)(input.signingPublicKey),
15
+ (0, fingerprint_1.normalizePublicKeyPem)(input.encryptionPublicKey),
16
+ ]));
17
+ }
18
+ /**
19
+ * The join request the person hands to the admin for a rescue device. It
20
+ * names no user (the admin picks the existing person, §6.5) and carries no
21
+ * User-Key: the rescue device gets the person's key by wrap.
22
+ */
23
+ function rescueDeviceJoinRequestUri(device) {
24
+ const request = {
25
+ v: 2,
26
+ signingPublicKey: device.signingPublicKey,
27
+ encryptionPublicKey: device.encryptionPublicKey,
28
+ label: device.label,
29
+ };
30
+ return (0, joinRequestUri_1.encodeJoinRequestUri)(request);
31
+ }
32
+ /** Shape check of a stored {@link RescueDeviceRef}. */
33
+ function isRescueDeviceRef(value) {
34
+ if (!value || typeof value !== "object")
35
+ return false;
36
+ const r = value;
37
+ for (const key of ["signingPublicKey", "encryptionPublicKey", "signingKeyFingerprint"]) {
38
+ if (typeof r[key] !== "string" || !r[key])
39
+ return false;
40
+ }
41
+ if (r.approval === "admin") {
42
+ const a = r.attestation;
43
+ return !!a && typeof a.epoch === "string" && typeof a.signature === "string";
44
+ }
45
+ if (r.approval !== undefined && r.approval !== "certificate")
46
+ return false;
47
+ return typeof r.certificateDocId === "string" && !!r.certificateDocId;
48
+ }
49
+ function rescueApprovalOf(ref) {
50
+ return ref.approval === "admin" ? "admin" : "certificate";
51
+ }
52
+ //# sourceMappingURL=rescueApproval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rescueApproval.js","sourceRoot":"","sources":["../../../src/core/recovery/rescueApproval.ts"],"names":[],"mappings":";;AAuCA,4DAaC;AAOD,gEAYC;AAgBD,8CAYC;AAED,4CAEC;AA/ED,0DAA6D;AAC7D,yDAAgE;AAYhE,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAEhE,SAAgB,wBAAwB,CAAC,KAIxC;IACC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAC7B,IAAI,CAAC,SAAS,CAAC;QACb,eAAe;QACf,KAAK,CAAC,YAAY;QAClB,IAAA,mCAAqB,EAAC,KAAK,CAAC,gBAAgB,CAAC;QAC7C,IAAA,mCAAqB,EAAC,KAAK,CAAC,mBAAmB,CAAC;KACjD,CAAC,CACH,CAAC;AACJ,CAAC;AAED;;;;GAI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CAAC,aAAa,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The rescue device of recovery contacts (docs/userkeys.md §12).
3
+ *
4
+ * A rescue device is an ordinary device of the person — an Ed25519 signing
5
+ * key and an RSA-OAEP 3072 encryption key — that no hardware holds. The
6
+ * person certifies it with their device self-grant key, so it receives the
7
+ * User-Key wraps and the self-grant key wrap like any device, and rotation
8
+ * keeps wrapping it. Its private keys exist only encrypted with the recovery
9
+ * secret `K`, which is split among the contacts.
10
+ *
11
+ * The encrypted keys ("rescue blob") are kept as small as possible because
12
+ * every helper package carries them and a package should fit a QR code: the
13
+ * Ed25519 seed (32 bytes) plus the two RSA primes (2 × 192 bytes). Everything
14
+ * else — modulus, private exponent, CRT values, public keys — is derived from
15
+ * them on recovery.
16
+ */
17
+ import type { CryptoAdapter } from "../crypto/CryptoAdapter";
18
+ import type { PrivateUserId } from "../types";
19
+ /** Public half of a rescue device, as certified and stored in `rcv_`. */
20
+ export interface RescueDevicePublicKeys {
21
+ signingPublicKey: string;
22
+ encryptionPublicKey: string;
23
+ /** Fingerprint of the signing key (colon-separated hex, as everywhere). */
24
+ signingKeyFingerprint: string;
25
+ }
26
+ /** A rescue device with its private keys opened. Memory only. */
27
+ export interface OpenedRescueDevice extends RescueDevicePublicKeys {
28
+ signingPkcs8: Uint8Array;
29
+ encryptionPkcs8: Uint8Array;
30
+ }
31
+ /** A freshly made rescue device: public keys, `K` and the encrypted blob. */
32
+ export interface GeneratedRescueDevice extends OpenedRescueDevice {
33
+ /** The 32-byte recovery secret the blob is encrypted with. */
34
+ secret: Uint8Array;
35
+ /** Base64 AES-256-GCM ciphertext of the private keys under {@link secret}. */
36
+ blob: string;
37
+ }
38
+ /** Make a new rescue device and encrypt its private keys with a new secret. */
39
+ export declare function generateRescueDevice(crypto: CryptoAdapter): Promise<GeneratedRescueDevice>;
40
+ /**
41
+ * Open a rescue blob with the recovery secret. Throws when the secret is wrong
42
+ * (AES-GCM authenticates it), which is how a bad share combination shows up.
43
+ */
44
+ export declare function openRescueDevice(crypto: CryptoAdapter, secret: Uint8Array, blob: string): Promise<OpenedRescueDevice>;
45
+ /**
46
+ * A {@link PrivateUserId} for the rescue device, its private keys encrypted
47
+ * with `password` exactly like {@link BaseMindooTenantFactory.createUserId}
48
+ * does, so the regular discovery and bootstrap calls can act as it.
49
+ */
50
+ export declare function rescueDeviceUserId(crypto: CryptoAdapter, device: OpenedRescueDevice, username: string, password: string): Promise<PrivateUserId>;
51
+ //# sourceMappingURL=rescueDevice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rescueDevice.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/rescueDevice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAI7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAM9C,yEAAyE;AACzE,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,MAAM,CAAC;IACzB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,2EAA2E;IAC3E,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED,iEAAiE;AACjE,MAAM,WAAW,kBAAmB,SAAQ,sBAAsB;IAChE,YAAY,EAAE,UAAU,CAAC;IACzB,eAAe,EAAE,UAAU,CAAC;CAC7B;AAED,6EAA6E;AAC7E,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,8DAA8D;IAC9D,MAAM,EAAE,UAAU,CAAC;IACnB,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;CACd;AAuHD,+EAA+E;AAC/E,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,qBAAqB,CAAC,CA2ChG;AAED;;;GAGG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,kBAAkB,CAAC,CA+B7B;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,aAAa,CAAC,CAYxB"}