mindoodb 0.0.97 → 0.0.98

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 (125) hide show
  1. package/README.md +1 -0
  2. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +7 -0
  3. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -1
  4. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +17 -9
  5. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -1
  6. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +12 -0
  7. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -1
  8. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +19 -0
  9. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -1
  10. package/dist/browser/index.mjs +70 -0
  11. package/dist/core/BaseMindooDB.d.ts +2 -0
  12. package/dist/core/BaseMindooDB.d.ts.map +1 -1
  13. package/dist/core/BaseMindooDB.js +73 -53
  14. package/dist/core/BaseMindooDB.js.map +1 -1
  15. package/dist/core/BaseMindooTenant.d.ts +33 -1
  16. package/dist/core/BaseMindooTenant.d.ts.map +1 -1
  17. package/dist/core/BaseMindooTenant.js +141 -41
  18. package/dist/core/BaseMindooTenant.js.map +1 -1
  19. package/dist/core/BaseMindooTenantDirectory.d.ts +11 -0
  20. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  21. package/dist/core/BaseMindooTenantDirectory.js +137 -92
  22. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  23. package/dist/core/builtinDbInvariants.d.ts +26 -1
  24. package/dist/core/builtinDbInvariants.d.ts.map +1 -1
  25. package/dist/core/builtinDbInvariants.js +52 -2
  26. package/dist/core/builtinDbInvariants.js.map +1 -1
  27. package/dist/core/index.d.ts +2 -0
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/core/index.js +3 -0
  30. package/dist/core/index.js.map +1 -1
  31. package/dist/core/joinrequests/crypto.d.ts +110 -0
  32. package/dist/core/joinrequests/crypto.d.ts.map +1 -0
  33. package/dist/core/joinrequests/crypto.js +340 -0
  34. package/dist/core/joinrequests/crypto.js.map +1 -0
  35. package/dist/core/joinrequests/index.d.ts +4 -0
  36. package/dist/core/joinrequests/index.d.ts.map +1 -0
  37. package/dist/core/joinrequests/index.js +29 -0
  38. package/dist/core/joinrequests/index.js.map +1 -0
  39. package/dist/core/joinrequests/invitations.d.ts +257 -0
  40. package/dist/core/joinrequests/invitations.d.ts.map +1 -0
  41. package/dist/core/joinrequests/invitations.js +703 -0
  42. package/dist/core/joinrequests/invitations.js.map +1 -0
  43. package/dist/core/joinrequests/types.d.ts +208 -0
  44. package/dist/core/joinrequests/types.d.ts.map +1 -0
  45. package/dist/core/joinrequests/types.js +43 -0
  46. package/dist/core/joinrequests/types.js.map +1 -0
  47. package/dist/core/recovery/PaperRescueDevice.d.ts +92 -0
  48. package/dist/core/recovery/PaperRescueDevice.d.ts.map +1 -0
  49. package/dist/core/recovery/PaperRescueDevice.js +182 -0
  50. package/dist/core/recovery/PaperRescueDevice.js.map +1 -0
  51. package/dist/core/recovery/RecoveryContactsDocument.d.ts +91 -0
  52. package/dist/core/recovery/RecoveryContactsDocument.d.ts.map +1 -0
  53. package/dist/core/recovery/RecoveryContactsDocument.js +92 -0
  54. package/dist/core/recovery/RecoveryContactsDocument.js.map +1 -0
  55. package/dist/core/recovery/RecoveryContactsManager.d.ts +95 -0
  56. package/dist/core/recovery/RecoveryContactsManager.d.ts.map +1 -0
  57. package/dist/core/recovery/RecoveryContactsManager.js +322 -0
  58. package/dist/core/recovery/RecoveryContactsManager.js.map +1 -0
  59. package/dist/core/recovery/index.d.ts +8 -0
  60. package/dist/core/recovery/index.d.ts.map +1 -0
  61. package/dist/core/recovery/index.js +41 -0
  62. package/dist/core/recovery/index.js.map +1 -0
  63. package/dist/core/recovery/recoverWithContacts.d.ts +36 -0
  64. package/dist/core/recovery/recoverWithContacts.d.ts.map +1 -0
  65. package/dist/core/recovery/recoverWithContacts.js +103 -0
  66. package/dist/core/recovery/recoverWithContacts.js.map +1 -0
  67. package/dist/core/recovery/recoveryPackage.d.ts +72 -0
  68. package/dist/core/recovery/recoveryPackage.d.ts.map +1 -0
  69. package/dist/core/recovery/recoveryPackage.js +181 -0
  70. package/dist/core/recovery/recoveryPackage.js.map +1 -0
  71. package/dist/core/recovery/rescueDevice.d.ts +51 -0
  72. package/dist/core/recovery/rescueDevice.d.ts.map +1 -0
  73. package/dist/core/recovery/rescueDevice.js +201 -0
  74. package/dist/core/recovery/rescueDevice.js.map +1 -0
  75. package/dist/core/recovery/shamir.d.ts +30 -0
  76. package/dist/core/recovery/shamir.d.ts.map +1 -0
  77. package/dist/core/recovery/shamir.js +133 -0
  78. package/dist/core/recovery/shamir.js.map +1 -0
  79. package/dist/core/types.d.ts +64 -1
  80. package/dist/core/types.d.ts.map +1 -1
  81. package/dist/core/types.js.map +1 -1
  82. package/dist/core/userkeys/UserKeyManager.d.ts +29 -0
  83. package/dist/core/userkeys/UserKeyManager.d.ts.map +1 -1
  84. package/dist/core/userkeys/UserKeyManager.js +76 -8
  85. package/dist/core/userkeys/UserKeyManager.js.map +1 -1
  86. package/dist/core/userkeys/generationSignature.d.ts +6 -0
  87. package/dist/core/userkeys/generationSignature.d.ts.map +1 -1
  88. package/dist/core/userkeys/generationSignature.js +1 -0
  89. package/dist/core/userkeys/generationSignature.js.map +1 -1
  90. package/dist/core/userkeys/resolveUserKeyDocument.d.ts.map +1 -1
  91. package/dist/core/userkeys/resolveUserKeyDocument.js +6 -6
  92. package/dist/core/userkeys/resolveUserKeyDocument.js.map +1 -1
  93. package/dist/core/userkeys/validateUserKeyDocument.d.ts +11 -1
  94. package/dist/core/userkeys/validateUserKeyDocument.d.ts.map +1 -1
  95. package/dist/core/userkeys/validateUserKeyDocument.js +18 -5
  96. package/dist/core/userkeys/validateUserKeyDocument.js.map +1 -1
  97. package/dist/node/server/MindooDBServer.d.ts +2 -0
  98. package/dist/node/server/MindooDBServer.d.ts.map +1 -1
  99. package/dist/node/server/MindooDBServer.js +46 -0
  100. package/dist/node/server/MindooDBServer.js.map +1 -1
  101. package/dist/node/server/StoreFactory.d.ts.map +1 -1
  102. package/dist/node/server/StoreFactory.js +4 -1
  103. package/dist/node/server/StoreFactory.js.map +1 -1
  104. package/dist/node/server/server.js +2 -0
  105. package/dist/node/server/server.js.map +1 -1
  106. package/dist/server/JoinRequestService.d.ts +108 -0
  107. package/dist/server/JoinRequestService.d.ts.map +1 -0
  108. package/dist/server/JoinRequestService.js +454 -0
  109. package/dist/server/JoinRequestService.js.map +1 -0
  110. package/dist/server/TenantManager.d.ts +50 -0
  111. package/dist/server/TenantManager.d.ts.map +1 -1
  112. package/dist/server/TenantManager.js +271 -33
  113. package/dist/server/TenantManager.js.map +1 -1
  114. package/dist/server/http/MindooDBServerCore.d.ts +18 -0
  115. package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
  116. package/dist/server/http/MindooDBServerCore.js +229 -137
  117. package/dist/server/http/MindooDBServerCore.js.map +1 -1
  118. package/dist/server/serverConfig.d.ts.map +1 -1
  119. package/dist/server/serverConfig.js +17 -0
  120. package/dist/server/serverConfig.js.map +1 -1
  121. package/dist/server/types.d.ts +15 -0
  122. package/dist/server/types.d.ts.map +1 -1
  123. package/dist/server/types.js +6 -0
  124. package/dist/server/types.js.map +1 -1
  125. package/package.json +1 -1
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Recovery contacts document `rcv_` (docs/userkeys.md §12).
3
+ *
4
+ * One personal document per setup in `userdirectory`, written by the person
5
+ * whose devices it can replace. It holds the encrypted rescue device and one
6
+ * secret share per contact, each sealed to that contact's User-Key.
7
+ *
8
+ * **It uses the tenant `default` key.** Contacts must be able to read it to
9
+ * find their share, and the recovering device never needs to: everything it
10
+ * needs travels in the helper packages. `$publicinfos` would hand the hoster
11
+ * the list of who would vouch for whom, which is none of its business — the
12
+ * same reasoning as `dev_` and `qtn_` (§7.6).
13
+ *
14
+ * **Ids are generated** (`rcv_` plus an object id). A new contact list is a
15
+ * new setup with a new rescue device; the old document is deleted.
16
+ *
17
+ * **A document is a claim until it is verified.** Anyone may create an `rcv_`
18
+ * document naming anyone. {@link verifyRecoveryContactsDoc} accepts one only
19
+ * when its `doc_create` was signed by a device that resolves to the grant of
20
+ * the person the payload names (grant device or certified device), and the
21
+ * named username hashes to the same `username_hash`. The personal-document
22
+ * write rule then keeps everybody else from changing it.
23
+ */
24
+ import type { BaseMindooTenantDirectory } from "../BaseMindooTenantDirectory";
25
+ import type { MindooDB, MindooDoc } from "../types";
26
+ import { USERKEY_FORM } from "../userkeys/types";
27
+ export declare const RECOVERY_CONTACTS_DOC_ID_PREFIX = "rcv_";
28
+ export declare const RECOVERY_CONTACTS_TYPE = "recoverycontacts";
29
+ export declare const RECOVERY_CONTACTS_SCHEMA_VERSION = 1;
30
+ /** Any two contacts together can recover; one alone cannot. */
31
+ export declare const RECOVERY_CONTACTS_THRESHOLD = 2;
32
+ /** At least two contacts, so that one contact alone never suffices. */
33
+ export declare const RECOVERY_CONTACTS_MIN = 2;
34
+ export interface RecoveryContactEntry {
35
+ /** The contact's username, as the person picked it. Display and lookup. */
36
+ username: string;
37
+ /** Fingerprint of the contact's User-Key generation the share is sealed to. */
38
+ userKeyFingerprint: string;
39
+ /** Base64 RSA-OAEP ciphertext of the contact's share. */
40
+ sealedShare: string;
41
+ }
42
+ export interface RecoveryContactsPayload {
43
+ form: typeof USERKEY_FORM;
44
+ type: typeof RECOVERY_CONTACTS_TYPE;
45
+ schemaVersion: number;
46
+ /** The person, as on their grant. */
47
+ username: string;
48
+ username_hash: string;
49
+ threshold: number;
50
+ createdAt: number;
51
+ rescueDevice: {
52
+ signingPublicKey: string;
53
+ encryptionPublicKey: string;
54
+ signingKeyFingerprint: string;
55
+ /** The `dcert_` document that certifies it. */
56
+ certificateDocId: string;
57
+ };
58
+ /** The rescue device's private keys, AES-256-GCM under the recovery secret. */
59
+ rescueBlob: string;
60
+ contacts: RecoveryContactEntry[];
61
+ }
62
+ /** A setup that passed {@link verifyRecoveryContactsDoc}. */
63
+ export interface RecoveryContactsSetup {
64
+ docId: string;
65
+ payload: RecoveryContactsPayload;
66
+ }
67
+ export declare function isRecoveryContactsDocId(docId: string | null | undefined): boolean;
68
+ export declare function asRecoveryContactsPayload(data: unknown): RecoveryContactsPayload | null;
69
+ /**
70
+ * Verify an `rcv_` document: payload shape, creator bound to the person the
71
+ * payload names, username bound to that person's hash. Returns `null` for
72
+ * anything that fails — an unverifiable setup is litter, not an error.
73
+ */
74
+ export declare function verifyRecoveryContactsDoc(input: {
75
+ db: MindooDB;
76
+ doc: MindooDoc;
77
+ directory: BaseMindooTenantDirectory;
78
+ }): Promise<RecoveryContactsSetup | null>;
79
+ /**
80
+ * Whether a personal document was created by the person it names: its
81
+ * `doc_create` signer resolves (grant device or certified device) to the grant
82
+ * with `usernameHash`, and `username` hashes to that same value.
83
+ */
84
+ export declare function personalDocBelongsTo(input: {
85
+ db: MindooDB;
86
+ docId: string;
87
+ directory: BaseMindooTenantDirectory;
88
+ username: string;
89
+ usernameHash: string;
90
+ }): Promise<boolean>;
91
+ //# sourceMappingURL=RecoveryContactsDocument.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecoveryContactsDocument.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/RecoveryContactsDocument.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,+BAA+B,SAAS,CAAC;AACtD,eAAO,MAAM,sBAAsB,qBAAqB,CAAC;AACzD,eAAO,MAAM,gC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ACf,SAAS,EAAE,yBAAyB,CAAC;CACtC,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAUxC;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IAChD,EAAE,EAAE,QAAQ,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,yBAAyB,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;CACtB,GAAG,OAAO,CAAC,OAAO,CAAC,CAOnB"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RECOVERY_CONTACTS_MIN = exports.RECOVERY_CONTACTS_THRESHOLD = exports.RECOVERY_CONTACTS_SCHEMA_VERSION = exports.RECOVERY_CONTACTS_TYPE = exports.RECOVERY_CONTACTS_DOC_ID_PREFIX = void 0;
4
+ exports.isRecoveryContactsDocId = isRecoveryContactsDocId;
5
+ exports.asRecoveryContactsPayload = asRecoveryContactsPayload;
6
+ exports.verifyRecoveryContactsDoc = verifyRecoveryContactsDoc;
7
+ exports.personalDocBelongsTo = personalDocBelongsTo;
8
+ const types_1 = require("../userkeys/types");
9
+ exports.RECOVERY_CONTACTS_DOC_ID_PREFIX = "rcv_";
10
+ exports.RECOVERY_CONTACTS_TYPE = "recoverycontacts";
11
+ exports.RECOVERY_CONTACTS_SCHEMA_VERSION = 1;
12
+ /** Any two contacts together can recover; one alone cannot. */
13
+ exports.RECOVERY_CONTACTS_THRESHOLD = 2;
14
+ /** At least two contacts, so that one contact alone never suffices. */
15
+ exports.RECOVERY_CONTACTS_MIN = 2;
16
+ function isRecoveryContactsDocId(docId) {
17
+ return typeof docId === "string" && docId.startsWith(exports.RECOVERY_CONTACTS_DOC_ID_PREFIX);
18
+ }
19
+ function asRecoveryContactsPayload(data) {
20
+ if (!data || typeof data !== "object")
21
+ return null;
22
+ const d = data;
23
+ if (d.form !== types_1.USERKEY_FORM || d.type !== exports.RECOVERY_CONTACTS_TYPE)
24
+ return null;
25
+ for (const key of ["username", "username_hash", "rescueBlob"]) {
26
+ if (typeof d[key] !== "string" || !d[key])
27
+ return null;
28
+ }
29
+ if (typeof d.threshold !== "number" || typeof d.createdAt !== "number")
30
+ return null;
31
+ const rescue = d.rescueDevice;
32
+ if (!rescue || typeof rescue !== "object")
33
+ return null;
34
+ for (const key of ["signingPublicKey", "encryptionPublicKey", "signingKeyFingerprint", "certificateDocId"]) {
35
+ if (typeof rescue[key] !== "string" || !rescue[key])
36
+ return null;
37
+ }
38
+ if (!Array.isArray(d.contacts))
39
+ return null;
40
+ for (const entry of d.contacts) {
41
+ const c = entry;
42
+ if (!c || typeof c.username !== "string" || typeof c.userKeyFingerprint !== "string" || typeof c.sealedShare !== "string") {
43
+ return null;
44
+ }
45
+ }
46
+ return d;
47
+ }
48
+ async function resolveCreateSigner(db, docId) {
49
+ try {
50
+ // History is ordered causally, so `doc_create` is on the first page.
51
+ const page = await db.getDocumentHistoryPage(docId, { limit: 10 });
52
+ const create = page.entries.find((entry) => entry.entryType === "doc_create");
53
+ return create?.changeCreatedByPublicKey ?? null;
54
+ }
55
+ catch {
56
+ return null;
57
+ }
58
+ }
59
+ /**
60
+ * Verify an `rcv_` document: payload shape, creator bound to the person the
61
+ * payload names, username bound to that person's hash. Returns `null` for
62
+ * anything that fails — an unverifiable setup is litter, not an error.
63
+ */
64
+ async function verifyRecoveryContactsDoc(input) {
65
+ const { db, doc, directory } = input;
66
+ const docId = doc.getId();
67
+ if (!isRecoveryContactsDocId(docId) || doc.isDeleted())
68
+ return null;
69
+ const payload = asRecoveryContactsPayload(doc.getData());
70
+ if (!payload)
71
+ return null;
72
+ if (!(await personalDocBelongsTo({ db, docId, directory, username: payload.username, usernameHash: payload.username_hash }))) {
73
+ return null;
74
+ }
75
+ return { docId, payload: JSON.parse(JSON.stringify(payload)) };
76
+ }
77
+ /**
78
+ * Whether a personal document was created by the person it names: its
79
+ * `doc_create` signer resolves (grant device or certified device) to the grant
80
+ * with `usernameHash`, and `username` hashes to that same value.
81
+ */
82
+ async function personalDocBelongsTo(input) {
83
+ const creator = await resolveCreateSigner(input.db, input.docId);
84
+ if (!creator)
85
+ return false;
86
+ const resolved = await input.directory.resolveSignerToGrant(creator, Number.MAX_SAFE_INTEGER);
87
+ if (!resolved || resolved.grant.usernameHash !== input.usernameHash)
88
+ return false;
89
+ const candidates = await input.directory.getUsernameHashCandidates(input.username);
90
+ return candidates.includes(input.usernameHash);
91
+ }
92
+ //# sourceMappingURL=RecoveryContactsDocument.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecoveryContactsDocument.js","sourceRoot":"","sources":["../../../src/core/recovery/RecoveryContactsDocument.ts"],"names":[],"mappings":";;;AAuEA,0DAEC;AAED,8DAqBC;AAkBD,8DAcC;AAOD,oDAaC;AA3HD,6CAAiD;AAEpC,QAAA,+BAA+B,GAAG,MAAM,CAAC;AACzC,QAAA,sBAAsB,GAAG,kBAAkB,CAAC;AAC5C,QAAA,gCAAgC,GAAG,CAAC,CAAC;AAClD,+DAA+D;AAClD,QAAA,2BAA2B,GAAG,CAAC,CAAC;AAC7C,uEAAuE;AAC1D,QAAA,qBAAqB,GAAG,CAAC,CAAC;AAsCvC,SAAgB,uBAAuB,CAAC,KAAgC;IACtE,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,uCAA+B,CAAC,CAAC;AACxF,CAAC;AAED,SAAgB,yBAAyB,CAAC,IAAa;IACrD,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACnD,MAAM,CAAC,GAAG,IAA+B,CAAC;IAC1C,IAAI,CAAC,CAAC,IAAI,KAAK,oBAAY,IAAI,CAAC,CAAC,IAAI,KAAK,8BAAsB;QAAE,OAAO,IAAI,CAAC;IAC9E,KAAK,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,eAAe,EAAE,Y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,OAAO,KAAK,CAAC;IAC3B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC9F,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,KAAK,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY;QAAE,OAAO,KAAK,CAAC;IAClF,MAAM,UAAU,GAAG,MAAM,KAAK,CAAC,SAAS,CAAC,yBAAyB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACnF,OAAO,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Recovery contacts on the person's and on the contacts' devices
3
+ * (docs/userkeys.md §12). Reached through the tenant:
4
+ * `tenant.setupRecoveryContacts`, `getRecoveryContactsSetup`,
5
+ * `removeRecoveryContacts`, `listRecoveryContactRequests`,
6
+ * `createRecoveryHelperPackage`.
7
+ */
8
+ import type { BaseMindooTenant } from "../BaseMindooTenant";
9
+ import type { UserKeyManager } from "../userkeys/UserKeyManager";
10
+ import { type RecoveryContactsSetup } from "./RecoveryContactsDocument";
11
+ import type { RecoveryHelperPackage } from "./recoveryPackage";
12
+ export type RecoveryContactsErrorCode = "self-grant-required" | "too-few-contacts" | "contact-is-self" | "contact-without-key" | "no-user-key" | "no-default-key" | "not-a-contact" | "no-setup";
13
+ export declare class RecoveryContactsError extends Error {
14
+ readonly code: RecoveryContactsErrorCode;
15
+ /** Usernames the error is about (`contact-without-key`, `contact-is-self`). */
16
+ readonly usernames: string[];
17
+ constructor(code: RecoveryContactsErrorCode, message: string,
18
+ /** Usernames the error is about (`contact-without-key`, `contact-is-self`). */
19
+ usernames?: string[]);
20
+ }
21
+ /** A person who named this device's person as a recovery contact. */
22
+ export interface RecoveryContactRequest {
23
+ docId: string;
24
+ username: string;
25
+ createdAt: number;
26
+ threshold: number;
27
+ /** All contacts of that setup, this person included. */
28
+ contacts: string[];
29
+ }
30
+ export interface SetupRecoveryContactsOptions {
31
+ /** Label of the rescue device certificate. Default "Rescue device". */
32
+ rescueDeviceLabel?: string;
33
+ /**
34
+ * Signing-key fingerprints of further rescue devices to withdraw, such as
35
+ * the one a recovery just used, in case its setup is not in this replica.
36
+ */
37
+ withdrawRescueDevices?: string[];
38
+ }
39
+ export declare class RecoveryContactsManager {
40
+ private readonly tenant;
41
+ private readonly userKeys;
42
+ constructor(tenant: BaseMindooTenant, userKeys: UserKeyManager);
43
+ private userDirectory;
44
+ private directory;
45
+ /** Every `rcv_` document that verifies, newest first. */
46
+ private verifiedSetups;
47
+ private ownUsernameHash;
48
+ /** This person's current setups, newest first (normally one). */
49
+ private ownSetups;
50
+ /** This person's current recovery contacts, or `null` when none are set up. */
51
+ getSetup(): Promise<RecoveryContactsSetup | null>;
52
+ /**
53
+ * Name recovery contacts: make a new rescue device, certify it, split its
54
+ * secret among the contacts (any two recover) and publish the `rcv_`
55
+ * document. Replaces an earlier setup and withdraws its rescue device.
56
+ * Needs the person's device self-grant (the rescue device is certified with
57
+ * it) and a published User-Key for every contact.
58
+ */
59
+ setup(contactUsernames: string[], options?: SetupRecoveryContactsOptions): Promise<RecoveryContactsSetup>;
60
+ /** Delete a setup and withdraw its rescue device. */
61
+ private retire;
62
+ /** Withdraw rescue devices by fingerprint that no retired setup covered. */
63
+ private withdrawExtra;
64
+ /**
65
+ * Remove recovery contacts: delete every own setup and withdraw its rescue
66
+ * device (and `withdrawRescueDevices`). Returns how many setups were removed.
67
+ */
68
+ remove(options?: {
69
+ withdrawRescueDevices?: string[];
70
+ }): Promise<number>;
71
+ /**
72
+ * People who named this person as a recovery contact, one entry per person
73
+ * (their newest setup), newest first.
74
+ */
75
+ listRequests(): Promise<RecoveryContactRequest[]>;
76
+ /**
77
+ * Help a person recover: open this contact's share of their newest setup
78
+ * and build the package (plaintext — encrypt it with
79
+ * {@link encryptRecoveryHelperPackage} before handing it over).
80
+ * `person` is the person's username or the setup document id.
81
+ */
82
+ createHelperPackage(person: string, options?: {
83
+ serverUrl?: string;
84
+ }): Promise<RecoveryHelperPackage>;
85
+ /**
86
+ * Signing keys of the rescue devices of every verified setup in the local
87
+ * replica (deleted setups are not included). A certificate issued by one of
88
+ * them means a recovery took place (docs/userkeys.md §12.5).
89
+ */
90
+ rescueDeviceSigningKeys(): Promise<Array<{
91
+ username: string;
92
+ signingPublicKey: string;
93
+ }>>;
94
+ }
95
+ //# sourceMappingURL=RecoveryContactsManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecoveryContactsManager.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/RecoveryContactsManager.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAI5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,EAQL,KAAK,qBAAqB,EAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAI/D,MAAM,MAAM,yBAAyB,GACjC,qBAAqB,GACrB,kBAAkB,GAClB,iBAAiB,GACjB,qBAAqB,GACrB,aAAa,GACb,gBAAgB,GAChB,eAAe,GACf,UAAU,CAAC;AAEf,qBAAa,qBAAsB,SAAQ,KAAK;IAE5C,QAAQ,CAAC,IAAI,EAAE,yBAAyB;IAExC,+EAA+E;IAC/E,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE;gBAHnB,IAAI,EAAE,yBAAyB,EACxC,OAAO,EAAE,MAAM;IACf,+EAA+E;IACtE,SAAS,GAAE,MAAM,EAAO;CAKpC;AAED,qEAAqE;AACrE,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MA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322 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecoveryContactsManager = exports.RecoveryContactsError = void 0;
4
+ const RSAEncryption_1 = require("../crypto/RSAEncryption");
5
+ const types_1 = require("../types");
6
+ const fingerprint_1 = require("../userkeys/fingerprint");
7
+ const types_2 = require("../userkeys/types");
8
+ const RecoveryContactsDocument_1 = require("./RecoveryContactsDocument");
9
+ const rescueDevice_1 = require("./rescueDevice");
10
+ const shamir_1 = require("./shamir");
11
+ class RecoveryContactsError extends Error {
12
+ constructor(code, message,
13
+ /** Usernames the error is about (`contact-without-key`, `contact-is-self`). */
14
+ usernames = []) {
15
+ super(message);
16
+ this.code = code;
17
+ this.usernames = usernames;
18
+ this.name = "RecoveryContactsError";
19
+ }
20
+ }
21
+ exports.RecoveryContactsError = RecoveryContactsError;
22
+ class RecoveryContactsManager {
23
+ constructor(tenant, userKeys) {
24
+ this.tenant = tenant;
25
+ this.userKeys = userKeys;
26
+ }
27
+ async userDirectory() {
28
+ return this.tenant.openDB(types_1.USER_DIRECTORY_DB_ID);
29
+ }
30
+ async directory() {
31
+ return (await this.tenant.openDirectory());
32
+ }
33
+ /** Every `rcv_` document that verifies, newest first. */
34
+ async verifiedSetups() {
35
+ const db = await this.userDirectory();
36
+ const directory = await this.directory();
37
+ const out = [];
38
+ for (const id of await db.getAllDocumentIds()) {
39
+ if (!id.startsWith(RecoveryContactsDocument_1.RECOVERY_CONTACTS_DOC_ID_PREFIX))
40
+ continue;
41
+ try {
42
+ const doc = await db.getDocument(id);
43
+ const setup = await (0, RecoveryContactsDocument_1.verifyRecoveryContactsDoc)({ db, doc, directory });
44
+ if (setup)
45
+ out.push(setup);
46
+ }
47
+ catch {
48
+ // unreadable (no `default` yet) or damaged: not a setup
49
+ }
50
+ }
51
+ return out.sort((a, b) => b.payload.createdAt - a.payload.createdAt || (a.docId < b.docId ? 1 : -1));
52
+ }
53
+ async ownUsernameHash() {
54
+ const resolved = await this.userKeys.resolveOwnUserKeyDocument();
55
+ return resolved?.payload.username_hash ?? null;
56
+ }
57
+ /** This person's current setups, newest first (normally one). */
58
+ async ownSetups() {
59
+ const hash = await this.ownUsernameHash();
60
+ if (!hash)
61
+ return [];
62
+ return (await this.verifiedSetups()).filter((s) => s.payload.username_hash === hash);
63
+ }
64
+ /** This person's current recovery contacts, or `null` when none are set up. */
65
+ async getSetup() {
66
+ return (await this.ownSetups())[0] ?? null;
67
+ }
68
+ /**
69
+ * Name recovery contacts: make a new rescue device, certify it, split its
70
+ * secret among the contacts (any two recover) and publish the `rcv_`
71
+ * document. Replaces an earlier setup and withdraws its rescue device.
72
+ * Needs the person's device self-grant (the rescue device is certified with
73
+ * it) and a published User-Key for every contact.
74
+ */
75
+ async setup(contactUsernames, options) {
76
+ const me = await this.tenant.getCurrentUserId();
77
+ const directory = await this.directory();
78
+ const ownResolved = await this.userKeys.resolveOwnUserKeyDocument();
79
+ if (!ownResolved) {
80
+ throw new RecoveryContactsError("no-user-key", "This person has no published User-Key yet.");
81
+ }
82
+ const ownHash = ownResolved.payload.username_hash;
83
+ if (!(await this.tenant.hasDecryptionKey(types_1.DEFAULT_TENANT_KEY_ID))) {
84
+ throw new RecoveryContactsError("no-default-key", "This device does not hold the tenant key yet.");
85
+ }
86
+ const seen = new Set();
87
+ const contacts = [];
88
+ for (const raw of contactUsernames) {
89
+ const username = raw.trim();
90
+ if (!username)
91
+ continue;
92
+ const key = username.toLowerCase();
93
+ if (seen.has(key))
94
+ continue;
95
+ seen.add(key);
96
+ contacts.push(username);
97
+ }
98
+ const selfNamed = [];
99
+ for (const username of contacts) {
100
+ const hashes = await directory.getUsernameHashCandidates(username);
101
+ if (hashes.includes(ownHash))
102
+ selfNamed.push(username);
103
+ }
104
+ if (selfNamed.length > 0) {
105
+ throw new RecoveryContactsError("contact-is-self", "You cannot be your own recovery contact.", selfNamed);
106
+ }
107
+ if (contacts.length < RecoveryContactsDocument_1.RECOVERY_CONTACTS_MIN) {
108
+ throw new RecoveryContactsError("too-few-contacts", `Name at least ${RecoveryContactsDocument_1.RECOVERY_CONTACTS_MIN} recovery contacts.`);
109
+ }
110
+ if (!(await this.userKeys.canIssueDeviceCertificates())) {
111
+ throw new RecoveryContactsError("self-grant-required", "Recovery contacts need device self-grant: the administrator must allow this person to add own devices.");
112
+ }
113
+ const recipients = [];
114
+ const missing = [];
115
+ for (const username of contacts) {
116
+ const published = await this.userKeys.publishedUserKeyFor(username);
117
+ if (!published || published.pending) {
118
+ missing.push(username);
119
+ continue;
120
+ }
121
+ recipients.push({ username, publicKey: published.publicKey, fingerprint: published.fingerprint });
122
+ }
123
+ if (missing.length > 0) {
124
+ throw new RecoveryContactsError("contact-without-key", `These people cannot be recovery contacts yet (no published User-Key): ${missing.join(", ")}`, missing);
125
+ }
126
+ const previous = await this.ownSetups();
127
+ const crypto = this.tenant.getCryptoAdapter();
128
+ const rescue = await (0, rescueDevice_1.generateRescueDevice)(crypto);
129
+ const label = options?.rescueDeviceLabel?.trim() || "Rescue device";
130
+ const { docId: certificateDocId } = await this.userKeys.issueDeviceCertificate({ signingPublicKey: rescue.signingPublicKey, encryptionPublicKey: rescue.encryptionPublicKey }, label);
131
+ const shares = (0, shamir_1.splitSecret)(crypto, rescue.secret, recipients.length, RecoveryContactsDocument_1.RECOVERY_CONTACTS_THRESHOLD);
132
+ rescue.secret.fill(0);
133
+ const rsa = new RSAEncryption_1.RSAEncryption(crypto);
134
+ const payload = {
135
+ form: types_2.USERKEY_FORM,
136
+ type: RecoveryContactsDocument_1.RECOVERY_CONTACTS_TYPE,
137
+ schemaVersion: RecoveryContactsDocument_1.RECOVERY_CONTACTS_SCHEMA_VERSION,
138
+ username: me.username,
139
+ username_hash: ownHash,
140
+ threshold: RecoveryContactsDocument_1.RECOVERY_CONTACTS_THRESHOLD,
141
+ createdAt: Date.now(),
142
+ rescueDevice: {
143
+ signingPublicKey: rescue.signingPublicKey,
144
+ encryptionPublicKey: rescue.encryptionPublicKey,
145
+ signingKeyFingerprint: rescue.signingKeyFingerprint,
146
+ certificateDocId,
147
+ },
148
+ rescueBlob: rescue.blob,
149
+ contacts: [],
150
+ };
151
+ for (let i = 0; i < recipients.length; i++) {
152
+ const recipient = recipients[i];
153
+ payload.contacts.push({
154
+ username: recipient.username,
155
+ userKeyFingerprint: recipient.fingerprint,
156
+ sealedShare: (0, fingerprint_1.bytesToBase64)(await rsa.encrypt(shares[i], recipient.publicKey)),
157
+ });
158
+ shares[i].fill(0);
159
+ }
160
+ rescue.signingPkcs8.fill(0);
161
+ rescue.encryptionPkcs8.fill(0);
162
+ const db = await this.userDirectory();
163
+ const doc = await db.createDocument({
164
+ decryptionKeyId: types_1.DEFAULT_TENANT_KEY_ID,
165
+ idPrefix: RecoveryContactsDocument_1.RECOVERY_CONTACTS_DOC_ID_PREFIX.replace(/_$/, ""),
166
+ initialValues: payload,
167
+ });
168
+ // Only now retire what came before: a failure above leaves it working.
169
+ for (const old of previous) {
170
+ await this.retire(db, old);
171
+ }
172
+ await this.withdrawExtra(options?.withdrawRescueDevices, previous);
173
+ return { docId: doc.getId(), payload: JSON.parse(JSON.stringify(payload)) };
174
+ }
175
+ /** Delete a setup and withdraw its rescue device. */
176
+ async retire(db, setup) {
177
+ try {
178
+ await this.userKeys.revokeOwnDeviceCertificate(setup.payload.rescueDevice.signingKeyFingerprint);
179
+ }
180
+ catch {
181
+ // already withdrawn
182
+ }
183
+ try {
184
+ await db.deleteDocument(setup.docId);
185
+ }
186
+ catch {
187
+ // already deleted
188
+ }
189
+ }
190
+ /** Withdraw rescue devices by fingerprint that no retired setup covered. */
191
+ async withdrawExtra(fingerprints, retired) {
192
+ const covered = new Set(retired.map((s) => s.payload.rescueDevice.signingKeyFingerprint));
193
+ for (const fingerprint of fingerprints ?? []) {
194
+ if (covered.has(fingerprint))
195
+ continue;
196
+ try {
197
+ await this.userKeys.revokeOwnDeviceCertificate(fingerprint);
198
+ }
199
+ catch {
200
+ // not in this replica, or already withdrawn
201
+ }
202
+ }
203
+ }
204
+ /**
205
+ * Remove recovery contacts: delete every own setup and withdraw its rescue
206
+ * device (and `withdrawRescueDevices`). Returns how many setups were removed.
207
+ */
208
+ async remove(options) {
209
+ const db = await this.userDirectory();
210
+ const setups = await this.ownSetups();
211
+ for (const setup of setups)
212
+ await this.retire(db, setup);
213
+ await this.withdrawExtra(options?.withdrawRescueDevices, setups);
214
+ return setups.length;
215
+ }
216
+ /**
217
+ * People who named this person as a recovery contact, one entry per person
218
+ * (their newest setup), newest first.
219
+ */
220
+ async listRequests() {
221
+ const ownHash = await this.ownUsernameHash();
222
+ if (!ownHash)
223
+ return [];
224
+ const fingerprints = new Set((await this.userKeys.ownUserKeyGenerations()).map((g) => g.fingerprint));
225
+ if (fingerprints.size === 0)
226
+ return [];
227
+ const byPerson = new Map();
228
+ for (const setup of await this.verifiedSetups()) {
229
+ if (setup.payload.username_hash === ownHash)
230
+ continue;
231
+ if (byPerson.has(setup.payload.username_hash))
232
+ continue; // newest first
233
+ byPerson.set(setup.payload.username_hash, setup);
234
+ }
235
+ const out = [];
236
+ for (const setup of byPerson.values()) {
237
+ if (!setup.payload.contacts.some((c) => fingerprints.has(c.userKeyFingerprint)))
238
+ continue;
239
+ out.push({
240
+ docId: setup.docId,
241
+ username: setup.payload.username,
242
+ createdAt: setup.payload.createdAt,
243
+ threshold: setup.payload.threshold,
244
+ contacts: setup.payload.contacts.map((c) => c.username),
245
+ });
246
+ }
247
+ return out;
248
+ }
249
+ /**
250
+ * Help a person recover: open this contact's share of their newest setup
251
+ * and build the package (plaintext — encrypt it with
252
+ * {@link encryptRecoveryHelperPackage} before handing it over).
253
+ * `person` is the person's username or the setup document id.
254
+ */
255
+ async createHelperPackage(person, options) {
256
+ const ownHash = await this.ownUsernameHash();
257
+ const setups = (await this.verifiedSetups()).filter((s) => s.payload.username_hash !== ownHash);
258
+ let setup = setups.find((s) => s.docId === person);
259
+ if (!setup) {
260
+ const directory = await this.directory();
261
+ const hashes = new Set(await directory.getUsernameHashCandidates(person));
262
+ setup = setups.find((s) => hashes.has(s.payload.username_hash));
263
+ }
264
+ else {
265
+ // A setup id must still be the person's newest one.
266
+ const hash = setup.payload.username_hash;
267
+ setup = setups.find((s) => s.payload.username_hash === hash);
268
+ }
269
+ if (!setup) {
270
+ throw new RecoveryContactsError("no-setup", "This person has no recovery contacts set up.");
271
+ }
272
+ const generations = await this.userKeys.ownUserKeyGenerations();
273
+ const rsa = new RSAEncryption_1.RSAEncryption(this.tenant.getCryptoAdapter());
274
+ let share = null;
275
+ for (const entry of setup.payload.contacts) {
276
+ const matching = generations.filter((g) => g.fingerprint === entry.userKeyFingerprint);
277
+ for (const generation of matching) {
278
+ try {
279
+ share = await rsa.decrypt((0, fingerprint_1.base64ToBytes)(entry.sealedShare), generation.privateKey);
280
+ break;
281
+ }
282
+ catch {
283
+ // not this generation
284
+ }
285
+ }
286
+ if (share)
287
+ break;
288
+ }
289
+ if (!share) {
290
+ throw new RecoveryContactsError("not-a-contact", "You are not a recovery contact of this person.");
291
+ }
292
+ const me = await this.tenant.getCurrentUserId();
293
+ const serverUrl = options?.serverUrl?.trim().replace(/\/$/, "");
294
+ return {
295
+ v: 1,
296
+ kind: "mindoodb-recovery-share",
297
+ tenantId: this.tenant.getId(),
298
+ ...(serverUrl ? { serverUrl } : {}),
299
+ username: setup.payload.username,
300
+ setupDocId: setup.docId,
301
+ threshold: setup.payload.threshold,
302
+ rescueSigningKeyFingerprint: setup.payload.rescueDevice.signingKeyFingerprint,
303
+ rescueBlob: setup.payload.rescueBlob,
304
+ share: (0, fingerprint_1.bytesToBase64)(share),
305
+ helper: me.username,
306
+ createdAt: Date.now(),
307
+ };
308
+ }
309
+ /**
310
+ * Signing keys of the rescue devices of every verified setup in the local
311
+ * replica (deleted setups are not included). A certificate issued by one of
312
+ * them means a recovery took place (docs/userkeys.md §12.5).
313
+ */
314
+ async rescueDeviceSigningKeys() {
315
+ return (await this.verifiedSetups()).map((s) => ({
316
+ username: s.payload.username,
317
+ signingPublicKey: s.payload.rescueDevice.signingPublicKey,
318
+ }));
319
+ }
320
+ }
321
+ exports.RecoveryContactsManager = RecoveryContactsManager;
322
+ //# sourceMappingURL=RecoveryContactsManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecoveryContactsManager.js","sourceRoot":"","sources":["../../../src/core/recovery/RecoveryContactsManager.ts"],"names":[],"mappings":";;;AASA,2DAAwD;AACxD,oCAAsF;AAEtF,yDAAuE;AACvE,6CAAiD;AACjD,yEASoC;AAEpC,iDAAsD;AACtD,qCAAuC;AAYvC,MAAa,qBAAsB,SAAQ,KAAK;IAC9C,YACW,IAA+B,EACxC,OAAe;IACf,+EAA+E;IACtE,YAAsB,EAAE;QAEjC,KAAK,CAAC,OAAO,CAAC,CAAC;QALN,SAAI,GAAJ,IAAI,CAA2B;QAG/B,cAAS,GAAT,SAAS,CAAe;QAGjC,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF;AAVD,sDAUC;AAsBD,MAAa,uBAAuB;IAClC,YACmB,MAAwB,EACxB,QAAwB;QADxB,WAAM,GAAN,MAAM,CAAkB;QACxB,aAAQ,GAAR,QAAQ,CAAgB;IACxC,CAAC;IAEI,KAAK,CAAC,aAAa;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,4BAAoB,CAAC,CAAC;IAClD,CAAC;IAEO,KAAK,CAAC,SAAS;QACrB,OAAO,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAA8B,CAAC;IAC1E,CAAC;IAED,yDAAyD;IACjD,KAAK,CAAC,cAAc;QAC1B,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;QACtC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC;QACzC,MAAM,GAAG,GAA4B,EAAE,CAAC;QACxC,KAAK,MAAM,EAAE,IAAI,MAAM,EAAE,CAAC,iBAAiB,EAAE,EAAE,CAAC;YAC9C,IAAI,CA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B,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAChE,OAAO;YACL,CAAC,EAAE,CAAC;YACJ,IAAI,EAAE,yBAAyB;YAC/B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE;YAC7B,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACnC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ;YAChC,UAAU,EAAE,KAAK,CAAC,KAAK;YACvB,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,SAAS;YAClC,2BAA2B,EAAE,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,qBAAqB;YAC7E,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU;YACpC,KAAK,EAAE,IAAA,2BAAa,EAAC,KAAK,CAAC;YAC3B,MAAM,EAAE,EAAE,CAAC,QAAQ;YACnB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,uBAAuB;QAC3B,OAAO,CAAC,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YAC/C,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ;YAC5B,gBAAgB,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB;SAC1D,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AA5TD,0DA4TC"}
@@ -0,0 +1,8 @@
1
+ export { splitSecret, combineShares } from "./shamir";
2
+ export { generateRescueDevice, openRescueDevice, rescueDeviceUserId, type RescueDevicePublicKeys, type OpenedRescueDevice, type GeneratedRescueDevice, } from "./rescueDevice";
3
+ export { RECOVERY_CONTACTS_DOC_ID_PREFIX, RECOVERY_CONTACTS_TYPE, RECOVERY_CONTACTS_SCHEMA_VERSION, RECOVERY_CONTACTS_THRESHOLD, RECOVERY_CONTACTS_MIN, isRecoveryContactsDocId, asRecoveryContactsPayload, verifyRecoveryContactsDoc, personalDocBelongsTo, type RecoveryContactEntry, type RecoveryContactsPayload, type RecoveryContactsSetup, } from "./RecoveryContactsDocument";
4
+ export { RECOVERY_PACKAGE_PREFIX, RecoveryPackageError, generateRecoveryPackagePassword, normalizeRecoveryPackagePassword, encryptRecoveryHelperPackage, decryptRecoveryHelperPackage, extractRecoveryPackageText, combineRecoveryHelperPackages, type RecoveryHelperPackage, type CombinedRecoveryPackages, } from "./recoveryPackage";
5
+ export { RecoveryContactsError, type RecoveryContactsErrorCode, type RecoveryContactRequest, type SetupRecoveryContactsOptions, } from "./RecoveryContactsManager";
6
+ export { RecoveryError, certifyDeviceWithRescueDevice, type CertifyDeviceWithRescueDeviceInput, type CertifyDeviceWithRescueDeviceResult, } from "./recoverWithContacts";
7
+ export { PAPER_RESCUE_DOC_ID_PREFIX, PAPER_RESCUE_TYPE, PAPER_RESCUE_SCHEMA_VERSION, openPaperRescueSecret, verifyPaperRescueDoc, type PaperRescuePayload, type PaperRescueRecord, type PaperRescueSecret, } from "./PaperRescueDevice";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,+BAA+B,EAC/B,sBAAsB,EACtB,gCAAgC,EAChC,2BAA2B,EAC3B,qBAAqB,EACrB,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,GAC3B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,+BAA+B,EAC/B,gCAAgC,EAChC,4BAA4B,EAC5B,4BAA4B,EAC5B,0BAA0B,EAC1B,6BAA6B,EAC7B,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,qBAAqB,EACrB,KAAK,yBAAyB,EAC9B,KAAK,sBAAsB,EAC3B,KAAK,4BAA4B,GAClC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,aAAa,EACb,6BAA6B,EAC7B,KAAK,kCAAkC,EACvC,KAAK,mCAAmC,GACzC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,0BAA0B,EAC1B,iBAAiB,EACjB,2BAA2B,EAC3B,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,GACvB,MAAM,qBAAqB,CAAC"}