mindoodb 0.0.96 → 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 (133) 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 +73 -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 +24 -1
  20. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -1
  21. package/dist/core/BaseMindooTenantDirectory.js +161 -90
  22. package/dist/core/BaseMindooTenantDirectory.js.map +1 -1
  23. package/dist/core/accesscontrol/directoryProjection.d.ts +7 -1
  24. package/dist/core/accesscontrol/directoryProjection.d.ts.map +1 -1
  25. package/dist/core/accesscontrol/directoryProjection.js +24 -0
  26. package/dist/core/accesscontrol/directoryProjection.js.map +1 -1
  27. package/dist/core/accesscontrol/types.d.ts +42 -2
  28. package/dist/core/accesscontrol/types.d.ts.map +1 -1
  29. package/dist/core/accesscontrol/types.js +77 -0
  30. package/dist/core/accesscontrol/types.js.map +1 -1
  31. package/dist/core/builtinDbInvariants.d.ts +26 -1
  32. package/dist/core/builtinDbInvariants.d.ts.map +1 -1
  33. package/dist/core/builtinDbInvariants.js +52 -2
  34. package/dist/core/builtinDbInvariants.js.map +1 -1
  35. package/dist/core/index.d.ts +3 -1
  36. package/dist/core/index.d.ts.map +1 -1
  37. package/dist/core/index.js +11 -5
  38. package/dist/core/index.js.map +1 -1
  39. package/dist/core/joinrequests/crypto.d.ts +110 -0
  40. package/dist/core/joinrequests/crypto.d.ts.map +1 -0
  41. package/dist/core/joinrequests/crypto.js +340 -0
  42. package/dist/core/joinrequests/crypto.js.map +1 -0
  43. package/dist/core/joinrequests/index.d.ts +4 -0
  44. package/dist/core/joinrequests/index.d.ts.map +1 -0
  45. package/dist/core/joinrequests/index.js +29 -0
  46. package/dist/core/joinrequests/index.js.map +1 -0
  47. package/dist/core/joinrequests/invitations.d.ts +257 -0
  48. package/dist/core/joinrequests/invitations.d.ts.map +1 -0
  49. package/dist/core/joinrequests/invitations.js +703 -0
  50. package/dist/core/joinrequests/invitations.js.map +1 -0
  51. package/dist/core/joinrequests/types.d.ts +208 -0
  52. package/dist/core/joinrequests/types.d.ts.map +1 -0
  53. package/dist/core/joinrequests/types.js +43 -0
  54. package/dist/core/joinrequests/types.js.map +1 -0
  55. package/dist/core/recovery/PaperRescueDevice.d.ts +92 -0
  56. package/dist/core/recovery/PaperRescueDevice.d.ts.map +1 -0
  57. package/dist/core/recovery/PaperRescueDevice.js +182 -0
  58. package/dist/core/recovery/PaperRescueDevice.js.map +1 -0
  59. package/dist/core/recovery/RecoveryContactsDocument.d.ts +91 -0
  60. package/dist/core/recovery/RecoveryContactsDocument.d.ts.map +1 -0
  61. package/dist/core/recovery/RecoveryContactsDocument.js +92 -0
  62. package/dist/core/recovery/RecoveryContactsDocument.js.map +1 -0
  63. package/dist/core/recovery/RecoveryContactsManager.d.ts +95 -0
  64. package/dist/core/recovery/RecoveryContactsManager.d.ts.map +1 -0
  65. package/dist/core/recovery/RecoveryContactsManager.js +322 -0
  66. package/dist/core/recovery/RecoveryContactsManager.js.map +1 -0
  67. package/dist/core/recovery/index.d.ts +8 -0
  68. package/dist/core/recovery/index.d.ts.map +1 -0
  69. package/dist/core/recovery/index.js +41 -0
  70. package/dist/core/recovery/index.js.map +1 -0
  71. package/dist/core/recovery/recoverWithContacts.d.ts +36 -0
  72. package/dist/core/recovery/recoverWithContacts.d.ts.map +1 -0
  73. package/dist/core/recovery/recoverWithContacts.js +103 -0
  74. package/dist/core/recovery/recoverWithContacts.js.map +1 -0
  75. package/dist/core/recovery/recoveryPackage.d.ts +72 -0
  76. package/dist/core/recovery/recoveryPackage.d.ts.map +1 -0
  77. package/dist/core/recovery/recoveryPackage.js +181 -0
  78. package/dist/core/recovery/recoveryPackage.js.map +1 -0
  79. package/dist/core/recovery/rescueDevice.d.ts +51 -0
  80. package/dist/core/recovery/rescueDevice.d.ts.map +1 -0
  81. package/dist/core/recovery/rescueDevice.js +201 -0
  82. package/dist/core/recovery/rescueDevice.js.map +1 -0
  83. package/dist/core/recovery/shamir.d.ts +30 -0
  84. package/dist/core/recovery/shamir.d.ts.map +1 -0
  85. package/dist/core/recovery/shamir.js +133 -0
  86. package/dist/core/recovery/shamir.js.map +1 -0
  87. package/dist/core/types.d.ts +80 -2
  88. package/dist/core/types.d.ts.map +1 -1
  89. package/dist/core/types.js.map +1 -1
  90. package/dist/core/userkeys/UserKeyManager.d.ts +29 -0
  91. package/dist/core/userkeys/UserKeyManager.d.ts.map +1 -1
  92. package/dist/core/userkeys/UserKeyManager.js +76 -8
  93. package/dist/core/userkeys/UserKeyManager.js.map +1 -1
  94. package/dist/core/userkeys/generationSignature.d.ts +6 -0
  95. package/dist/core/userkeys/generationSignature.d.ts.map +1 -1
  96. package/dist/core/userkeys/generationSignature.js +1 -0
  97. package/dist/core/userkeys/generationSignature.js.map +1 -1
  98. package/dist/core/userkeys/resolveUserKeyDocument.d.ts.map +1 -1
  99. package/dist/core/userkeys/resolveUserKeyDocument.js +6 -6
  100. package/dist/core/userkeys/resolveUserKeyDocument.js.map +1 -1
  101. package/dist/core/userkeys/validateUserKeyDocument.d.ts +11 -1
  102. package/dist/core/userkeys/validateUserKeyDocument.d.ts.map +1 -1
  103. package/dist/core/userkeys/validateUserKeyDocument.js +18 -5
  104. package/dist/core/userkeys/validateUserKeyDocument.js.map +1 -1
  105. package/dist/node/server/MindooDBServer.d.ts +2 -0
  106. package/dist/node/server/MindooDBServer.d.ts.map +1 -1
  107. package/dist/node/server/MindooDBServer.js +46 -0
  108. package/dist/node/server/MindooDBServer.js.map +1 -1
  109. package/dist/node/server/StoreFactory.d.ts.map +1 -1
  110. package/dist/node/server/StoreFactory.js +4 -1
  111. package/dist/node/server/StoreFactory.js.map +1 -1
  112. package/dist/node/server/server.js +2 -0
  113. package/dist/node/server/server.js.map +1 -1
  114. package/dist/server/JoinRequestService.d.ts +108 -0
  115. package/dist/server/JoinRequestService.d.ts.map +1 -0
  116. package/dist/server/JoinRequestService.js +454 -0
  117. package/dist/server/JoinRequestService.js.map +1 -0
  118. package/dist/server/TenantManager.d.ts +50 -0
  119. package/dist/server/TenantManager.d.ts.map +1 -1
  120. package/dist/server/TenantManager.js +271 -33
  121. package/dist/server/TenantManager.js.map +1 -1
  122. package/dist/server/http/MindooDBServerCore.d.ts +18 -0
  123. package/dist/server/http/MindooDBServerCore.d.ts.map +1 -1
  124. package/dist/server/http/MindooDBServerCore.js +229 -137
  125. package/dist/server/http/MindooDBServerCore.js.map +1 -1
  126. package/dist/server/serverConfig.d.ts.map +1 -1
  127. package/dist/server/serverConfig.js +17 -0
  128. package/dist/server/serverConfig.js.map +1 -1
  129. package/dist/server/types.d.ts +15 -0
  130. package/dist/server/types.d.ts.map +1 -1
  131. package/dist/server/types.js +6 -0
  132. package/dist/server/types.js.map +1 -1
  133. package/package.json +1 -1
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifyPaperRescueDoc = exports.openPaperRescueSecret = exports.PAPER_RESCUE_SCHEMA_VERSION = exports.PAPER_RESCUE_TYPE = exports.PAPER_RESCUE_DOC_ID_PREFIX = exports.certifyDeviceWithRescueDevice = exports.RecoveryError = exports.RecoveryContactsError = exports.combineRecoveryHelperPackages = exports.extractRecoveryPackageText = exports.decryptRecoveryHelperPackage = exports.encryptRecoveryHelperPackage = exports.normalizeRecoveryPackagePassword = exports.generateRecoveryPackagePassword = exports.RecoveryPackageError = exports.RECOVERY_PACKAGE_PREFIX = exports.personalDocBelongsTo = exports.verifyRecoveryContactsDoc = exports.asRecoveryContactsPayload = exports.isRecoveryContactsDocId = exports.RECOVERY_CONTACTS_MIN = exports.RECOVERY_CONTACTS_THRESHOLD = exports.RECOVERY_CONTACTS_SCHEMA_VERSION = exports.RECOVERY_CONTACTS_TYPE = exports.RECOVERY_CONTACTS_DOC_ID_PREFIX = exports.rescueDeviceUserId = exports.openRescueDevice = exports.generateRescueDevice = exports.combineShares = exports.splitSecret = void 0;
4
+ var shamir_1 = require("./shamir");
5
+ Object.defineProperty(exports, "splitSecret", { enumerable: true, get: function () { return shamir_1.splitSecret; } });
6
+ Object.defineProperty(exports, "combineShares", { enumerable: true, get: function () { return shamir_1.combineShares; } });
7
+ var rescueDevice_1 = require("./rescueDevice");
8
+ Object.defineProperty(exports, "generateRescueDevice", { enumerable: true, get: function () { return rescueDevice_1.generateRescueDevice; } });
9
+ Object.defineProperty(exports, "openRescueDevice", { enumerable: true, get: function () { return rescueDevice_1.openRescueDevice; } });
10
+ Object.defineProperty(exports, "rescueDeviceUserId", { enumerable: true, get: function () { return rescueDevice_1.rescueDeviceUserId; } });
11
+ var RecoveryContactsDocument_1 = require("./RecoveryContactsDocument");
12
+ Object.defineProperty(exports, "RECOVERY_CONTACTS_DOC_ID_PREFIX", { enumerable: true, get: function () { return RecoveryContactsDocument_1.RECOVERY_CONTACTS_DOC_ID_PREFIX; } });
13
+ Object.defineProperty(exports, "RECOVERY_CONTACTS_TYPE", { enumerable: true, get: function () { return RecoveryContactsDocument_1.RECOVERY_CONTACTS_TYPE; } });
14
+ Object.defineProperty(exports, "RECOVERY_CONTACTS_SCHEMA_VERSION", { enumerable: true, get: function () { return RecoveryContactsDocument_1.RECOVERY_CONTACTS_SCHEMA_VERSION; } });
15
+ Object.defineProperty(exports, "RECOVERY_CONTACTS_THRESHOLD", { enumerable: true, get: function () { return RecoveryContactsDocument_1.RECOVERY_CONTACTS_THRESHOLD; } });
16
+ Object.defineProperty(exports, "RECOVERY_CONTACTS_MIN", { enumerable: true, get: function () { return RecoveryContactsDocument_1.RECOVERY_CONTACTS_MIN; } });
17
+ Object.defineProperty(exports, "isRecoveryContactsDocId", { enumerable: true, get: function () { return RecoveryContactsDocument_1.isRecoveryContactsDocId; } });
18
+ Object.defineProperty(exports, "asRecoveryContactsPayload", { enumerable: true, get: function () { return RecoveryContactsDocument_1.asRecoveryContactsPayload; } });
19
+ Object.defineProperty(exports, "verifyRecoveryContactsDoc", { enumerable: true, get: function () { return RecoveryContactsDocument_1.verifyRecoveryContactsDoc; } });
20
+ Object.defineProperty(exports, "personalDocBelongsTo", { enumerable: true, get: function () { return RecoveryContactsDocument_1.personalDocBelongsTo; } });
21
+ var recoveryPackage_1 = require("./recoveryPackage");
22
+ Object.defineProperty(exports, "RECOVERY_PACKAGE_PREFIX", { enumerable: true, get: function () { return recoveryPackage_1.RECOVERY_PACKAGE_PREFIX; } });
23
+ Object.defineProperty(exports, "RecoveryPackageError", { enumerable: true, get: function () { return recoveryPackage_1.RecoveryPackageError; } });
24
+ Object.defineProperty(exports, "generateRecoveryPackagePassword", { enumerable: true, get: function () { return recoveryPackage_1.generateRecoveryPackagePassword; } });
25
+ Object.defineProperty(exports, "normalizeRecoveryPackagePassword", { enumerable: true, get: function () { return recoveryPackage_1.normalizeRecoveryPackagePassword; } });
26
+ Object.defineProperty(exports, "encryptRecoveryHelperPackage", { enumerable: true, get: function () { return recoveryPackage_1.encryptRecoveryHelperPackage; } });
27
+ Object.defineProperty(exports, "decryptRecoveryHelperPackage", { enumerable: true, get: function () { return recoveryPackage_1.decryptRecoveryHelperPackage; } });
28
+ Object.defineProperty(exports, "extractRecoveryPackageText", { enumerable: true, get: function () { return recoveryPackage_1.extractRecoveryPackageText; } });
29
+ Object.defineProperty(exports, "combineRecoveryHelperPackages", { enumerable: true, get: function () { return recoveryPackage_1.combineRecoveryHelperPackages; } });
30
+ var RecoveryContactsManager_1 = require("./RecoveryContactsManager");
31
+ Object.defineProperty(exports, "RecoveryContactsError", { enumerable: true, get: function () { return RecoveryContactsManager_1.RecoveryContactsError; } });
32
+ var recoverWithContacts_1 = require("./recoverWithContacts");
33
+ Object.defineProperty(exports, "RecoveryError", { enumerable: true, get: function () { return recoverWithContacts_1.RecoveryError; } });
34
+ Object.defineProperty(exports, "certifyDeviceWithRescueDevice", { enumerable: true, get: function () { return recoverWithContacts_1.certifyDeviceWithRescueDevice; } });
35
+ var PaperRescueDevice_1 = require("./PaperRescueDevice");
36
+ Object.defineProperty(exports, "PAPER_RESCUE_DOC_ID_PREFIX", { enumerable: true, get: function () { return PaperRescueDevice_1.PAPER_RESCUE_DOC_ID_PREFIX; } });
37
+ Object.defineProperty(exports, "PAPER_RESCUE_TYPE", { enumerable: true, get: function () { return PaperRescueDevice_1.PAPER_RESCUE_TYPE; } });
38
+ Object.defineProperty(exports, "PAPER_RESCUE_SCHEMA_VERSION", { enumerable: true, get: function () { return PaperRescueDevice_1.PAPER_RESCUE_SCHEMA_VERSION; } });
39
+ Object.defineProperty(exports, "openPaperRescueSecret", { enumerable: true, get: function () { return PaperRescueDevice_1.openPaperRescueSecret; } });
40
+ Object.defineProperty(exports, "verifyPaperRescueDoc", { enumerable: true, get: function () { return PaperRescueDevice_1.verifyPaperRescueDoc; } });
41
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/recovery/index.ts"],"names":[],"mappings":";;;AAAA,mCAAsD;AAA7C,qGAAA,WAAW,OAAA;AAAE,uGAAA,aAAa,OAAA;AACnC,+CAOwB;AANtB,oHAAA,oBAAoB,OAAA;AACpB,gHAAA,gBAAgB,OAAA;AAChB,kHAAA,kBAAkB,OAAA;AAKpB,uEAaoC;AAZlC,2IAAA,+BAA+B,OAAA;AAC/B,kIAAA,sBAAsB,OAAA;AACtB,4IAAA,gCAAgC,OAAA;AAChC,uIAAA,2BAA2B,OAAA;AAC3B,iIAAA,qBAAqB,OAAA;AACrB,mIAAA,uBAAuB,OAAA;AACvB,qIAAA,yBAAyB,OAAA;AACzB,qIAAA,yBAAyB,OAAA;AACzB,gIAAA,oBAAoB,OAAA;AAKtB,qDAW2B;AAVzB,0HAAA,uBAAuB,OAAA;AACvB,uHAAA,oBAAoB,OAAA;AACpB,kIAAA,+BAA+B,OAAA;AAC/B,mIAAA,gCAAgC,OAAA;AAChC,+HAAA,4BAA4B,OAAA;AAC5B,+HAAA,4BAA4B,OAAA;AAC5B,6HAAA,0BAA0B,OAAA;AAC1B,gIAAA,6BAA6B,OAAA;AAI/B,qEAKmC;AAJjC,gIAAA,qBAAqB,OAAA;AAKvB,6DAK+B;AAJ7B,oHAAA,aAAa,OAAA;AACb,oIAAA,6BAA6B,OAAA;AAI/B,yDAS6B;AAR3B,+HAAA,0BAA0B,OAAA;AAC1B,sHAAA,iBAAiB,OAAA;AACjB,gIAAA,2BAA2B,OAAA;AAC3B,0HAAA,qBAAqB,OAAA;AACrB,yHAAA,oBAAoB,OAAA"}
@@ -0,0 +1,36 @@
1
+ import type { CryptoAdapter } from "../crypto/CryptoAdapter";
2
+ import { type ContentAddressedStoreFactory } from "../types";
3
+ import type { CombinedRecoveryPackages } from "./recoveryPackage";
4
+ export declare class RecoveryError extends Error {
5
+ readonly code: "no-server" | "tenant-not-found" | "not-certified" | "sync-failed";
6
+ constructor(code: "no-server" | "tenant-not-found" | "not-certified" | "sync-failed", message: string);
7
+ }
8
+ export interface CertifyDeviceWithRescueDeviceInput {
9
+ cryptoAdapter: CryptoAdapter;
10
+ /** From the combined packages. */
11
+ recovery: CombinedRecoveryPackages;
12
+ /** Overrides `recovery.serverUrl` (the packages may not carry one). */
13
+ serverUrl?: string;
14
+ /** Public keys of the new device. */
15
+ device: {
16
+ signingPublicKey: string;
17
+ encryptionPublicKey: string;
18
+ };
19
+ label?: string;
20
+ /** Storage for the throwaway rescue session. Default: in memory. */
21
+ storeFactory?: ContentAddressedStoreFactory;
22
+ }
23
+ export interface CertifyDeviceWithRescueDeviceResult {
24
+ tenantId: string;
25
+ serverUrl: string;
26
+ username: string;
27
+ certificateDocId: string;
28
+ /** The rescue device that issued it, to withdraw once the new device is set up. */
29
+ rescueSigningKeyFingerprint: string;
30
+ }
31
+ /**
32
+ * Certify a new device of the person with the rescue device that the
33
+ * combined helper packages opened.
34
+ */
35
+ export declare function certifyDeviceWithRescueDevice(input: CertifyDeviceWithRescueDeviceInput): Promise<CertifyDeviceWithRescueDeviceResult>;
36
+ //# sourceMappingURL=recoverWithContacts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoverWithContacts.d.ts","sourceRoot":"","sources":["../../../src/core/recovery/recoverWithContacts.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAwB,KAAK,4BAA4B,EAAE,MAAM,UAAU,CAAC;AACnF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAGlE,qBAAa,aAAc,SAAQ,KAAK;IAEpC,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,eAAe,GAAG,aAAa;gBAAxE,IAAI,EAAE,WAAW,GAAG,kBAAkB,GAAG,eAAe,GAAG,aAAa,EACjF,OAAO,EAAE,MAAM;CAKlB;AAED,MAAM,WAAW,kCAAkC;IACjD,aAAa,EAAE,aAAa,CAAC;IAC7B,kCAAkC;IAClC,QAAQ,EAAE,wBAAwB,CAAC;IACnC,uEAAuE;IACvE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qCAAqC;IACrC,MAAM,EAAE;QAAE,gBAAgB,EAAE,MAAM,CAAC;QAAC,mBAAmB,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oEAAoE;IACpE,YAAY,CAAC,EAAE,4BAA4B,CAAC;CAC7C;AAED,MAAM,WAAW,mCAAmC;IAClD,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,gBAAgB,EAAE,MAAM,CAAC;IACzB,mFAAmF;IACnF,2BAA2B,EAAE,MAAM,CAAC;CACrC;AASD;;;GAGG;AACH,wBAAsB,6BAA6B,CACjD,KAAK,EAAE,kCAAkC,GACxC,OAAO,CAAC,mCAAmC,CAAC,CA0E9C"}
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RecoveryError = void 0;
4
+ exports.certifyDeviceWithRescueDevice = certifyDeviceWithRescueDevice;
5
+ /**
6
+ * Recovery on a new device (docs/userkeys.md §12.4): act as the rescue device
7
+ * for one session and certify the new device's keys with the person's
8
+ * self-grant key, which the rescue device receives as a wrap like any device.
9
+ *
10
+ * The rescue device runs in throwaway in-memory storage. It authenticates to
11
+ * the server with its own keys (the server knows it from its `dcert_`
12
+ * certificate), pulls `directory` and `userdirectory`, opens the User-Key and
13
+ * self-grant key wrapped to it, writes the new device's certificate plus its
14
+ * wraps and pushes `userdirectory`. From then on the new device is a device
15
+ * of the person in its own right and joins through ordinary device discovery
16
+ * (`discoverTenantsOnServer` + `bootstrapTenantFromDelivery`).
17
+ */
18
+ const BaseMindooTenantFactory_1 = require("../BaseMindooTenantFactory");
19
+ const InMemoryContentAddressedStore_1 = require("../appendonlystores/InMemoryContentAddressedStore");
20
+ const types_1 = require("../types");
21
+ const rescueDevice_1 = require("./rescueDevice");
22
+ class RecoveryError extends Error {
23
+ constructor(code, message) {
24
+ super(message);
25
+ this.code = code;
26
+ this.name = "RecoveryError";
27
+ }
28
+ }
29
+ exports.RecoveryError = RecoveryError;
30
+ function randomPassword(crypto) {
31
+ const bytes = crypto.getRandomValues(new Uint8Array(24));
32
+ let out = "";
33
+ for (const b of bytes)
34
+ out += b.toString(16).padStart(2, "0");
35
+ return out;
36
+ }
37
+ /**
38
+ * Certify a new device of the person with the rescue device that the
39
+ * combined helper packages opened.
40
+ */
41
+ async function certifyDeviceWithRescueDevice(input) {
42
+ const serverUrl = (input.serverUrl ?? input.recovery.serverUrl ?? "").trim().replace(/\/$/, "");
43
+ if (!serverUrl)
44
+ throw new RecoveryError("no-server", "No server address to recover from.");
45
+ const crypto = input.cryptoAdapter;
46
+ const password = randomPassword(crypto);
47
+ const rescueUser = await (0, rescueDevice_1.rescueDeviceUserId)(crypto, input.recovery.rescueDevice, input.recovery.username, password);
48
+ const factory = new BaseMindooTenantFactory_1.BaseMindooTenantFactory(input.storeFactory ?? new InMemoryContentAddressedStore_1.InMemoryContentAddressedStoreFactory(), crypto);
49
+ let deliveries;
50
+ try {
51
+ deliveries = await factory.discoverTenantsOnServer(serverUrl, { user: rescueUser, password });
52
+ }
53
+ catch (error) {
54
+ throw 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.`);
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
+ let joined;
61
+ try {
62
+ joined = await factory.bootstrapTenantFromDelivery(delivery, {
63
+ user: rescueUser,
64
+ password,
65
+ serverUrl,
66
+ });
67
+ }
68
+ catch (error) {
69
+ // A withdrawn rescue device still finds the tenant (discovery keeps naming
70
+ // revoked devices so they can learn about a wipe), but sync refuses it.
71
+ throw 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.`);
72
+ }
73
+ const tenant = joined.tenant;
74
+ try {
75
+ if (!tenant.issueDeviceCertificate) {
76
+ throw new RecoveryError("not-certified", "This tenant cannot certify devices.");
77
+ }
78
+ // bootstrap pulled both directories and reconciled; certify now.
79
+ const { docId } = await tenant.issueDeviceCertificate(input.device, input.label);
80
+ const local = await tenant.openDB(types_1.USER_DIRECTORY_DB_ID);
81
+ const remote = await tenant.connectToServer(serverUrl, types_1.USER_DIRECTORY_DB_ID);
82
+ const pushed = await local.pushChangesTo(remote);
83
+ if (pushed.cancelled) {
84
+ throw new RecoveryError("sync-failed", "Sending the new device certificate to the server was cancelled.");
85
+ }
86
+ return {
87
+ tenantId: input.recovery.tenantId,
88
+ serverUrl,
89
+ username: joined.user.username,
90
+ certificateDocId: docId,
91
+ rescueSigningKeyFingerprint: input.recovery.rescueDevice.signingKeyFingerprint,
92
+ };
93
+ }
94
+ finally {
95
+ try {
96
+ await tenant.close?.();
97
+ }
98
+ catch {
99
+ // throwaway session
100
+ }
101
+ }
102
+ }
103
+ //# sourceMappingURL=recoverWithContacts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoverWithContacts.js","sourceRoot":"","sources":["../../../src/core/recovery/recoverWithContacts.ts"],"names":[],"mappings":";;;AA+DA,sEA4EC;AA3ID;;;;;;;;;;;;GAYG;AACH,wEAAqE;AACrE,qGAAyG;AAEzG,oCAAmF;AAEnF,iDAAoD;AAEpD,MAAa,aAAc,SAAQ,KAAK;IACtC,YACW,IAAwE,EACjF,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,SAAI,GAAJ,IAAI,CAAoE;QAIjF,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AARD,sCAQC;AAwBD,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AAG,MAAM,MAAM,CAAC,MAAM,CAAC,4BAAoB,CAAC,CAAC;QACxD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,4BAAoB,CAAC,CAAC;QAC7E,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;YACrB,MAAM,IAAI,aAAa,CAAC,aAAa,EAAE,iEAAiE,CAAC,CAAC;QAC5G,CAAC;QACD,OAAO;YACL,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,QAAQ;YACjC,SAAS;YACT,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ;YAC9B,gBAAgB,EAAE,KAAK;YACvB,2BAA2B,EAAE,KAAK,CAAC,QAAQ,CAAC,YAAY,CAAC,qBAAqB;SAC/E,CAAC;IACJ,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAO,MAA0C,CAAC,KAAK,EAAE,EAAE,CAAC;QAC9D,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB;QACtB,CAAC;IACH,CAAC;AACH,CAAC"}
@@ -0,0 +1,72 @@
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
+ rescueBlob: string;
33
+ /** Base64 Shamir share. */
34
+ share: string;
35
+ /** Who helped (display only). */
36
+ helper: string;
37
+ createdAt: number;
38
+ }
39
+ /** The result of combining enough packages: the opened rescue device. */
40
+ export interface CombinedRecoveryPackages {
41
+ tenantId: string;
42
+ serverUrl?: string;
43
+ username: string;
44
+ setupDocId: string;
45
+ helpers: string[];
46
+ rescueDevice: OpenedRescueDevice;
47
+ }
48
+ export declare class RecoveryPackageError extends Error {
49
+ readonly code: "malformed" | "wrong-password" | "too-few" | "mismatch" | "duplicate" | "cannot-open";
50
+ constructor(code: "malformed" | "wrong-password" | "too-few" | "mismatch" | "duplicate" | "cannot-open", message: string);
51
+ }
52
+ /**
53
+ * A one-time password for a package: 12 characters from an alphabet without
54
+ * look-alikes (about 59 bits), shown in groups of four (`abcd-efgh-jkmn`).
55
+ */
56
+ export declare function generateRecoveryPackagePassword(crypto: CryptoAdapter): string;
57
+ /** Typed passwords: case, spaces and dashes do not matter. */
58
+ export declare function normalizeRecoveryPackagePassword(password: string): string;
59
+ /** Encrypt a package with its one-time password into the text form. */
60
+ export declare function encryptRecoveryHelperPackage(crypto: CryptoAdapter, pkg: RecoveryHelperPackage, password: string): Promise<string>;
61
+ /** Pull the package text out of whatever was pasted or scanned. */
62
+ export declare function extractRecoveryPackageText(input: string): string | null;
63
+ /** Decrypt a package; throws {@link RecoveryPackageError}. */
64
+ export declare function decryptRecoveryHelperPackage(crypto: CryptoAdapter, text: string, password: string): Promise<RecoveryHelperPackage>;
65
+ /**
66
+ * Combine decrypted packages from different contacts of the same setup and
67
+ * open the rescue device. Fails with `too-few` below the threshold, `mismatch`
68
+ * when the packages belong to different setups, `duplicate` for the same
69
+ * share twice, and `cannot-open` when the combination does not open the blob.
70
+ */
71
+ export declare function combineRecoveryHelperPackages(crypto: CryptoAdapter, packages: RecoveryHelperPackage[]): Promise<CombinedRecoveryPackages>;
72
+ //# 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,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,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,CA2CnC"}
@@ -0,0 +1,181 @@
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
+ rescueDevice,
179
+ };
180
+ }
181
+ //# sourceMappingURL=recoveryPackage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recoveryPackage.js","sourceRoot":"","sources":["../../../src/core/recovery/recoveryPackage.ts"],"names":[],"mappings":";;;AA2FA,0EAUC;AAGD,4EAEC;AA2BD,oEAwBC;AAGD,gEAGC;AAGD,oEAqDC;AAQD,sEA8CC;AAjQD,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;AAiC3B,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,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,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AC/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,YAAY;KACb,CAAC;AACJ,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"}