mindoodb 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/README.md +263 -0
  2. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts +5 -0
  3. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.d.ts.map +1 -0
  4. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js +17 -0
  5. package/dist/appendonlystores/InMemoryContentAddressedStoreFactory.js.map +1 -0
  6. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts +111 -0
  7. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.d.ts.map +1 -0
  8. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js +237 -0
  9. package/dist/appendonlystores/network/ClientNetworkContentAddressedStore.js.map +1 -0
  10. package/dist/appendonlystores/network/HttpTransport.d.ts +78 -0
  11. package/dist/appendonlystores/network/HttpTransport.d.ts.map +1 -0
  12. package/dist/appendonlystores/network/HttpTransport.js +356 -0
  13. package/dist/appendonlystores/network/HttpTransport.js.map +1 -0
  14. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts +131 -0
  15. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.d.ts.map +1 -0
  16. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js +248 -0
  17. package/dist/appendonlystores/network/ServerNetworkContentAddressedStore.js.map +1 -0
  18. package/dist/appendonlystores/network/index.d.ts +8 -0
  19. package/dist/appendonlystores/network/index.d.ts.map +1 -0
  20. package/dist/appendonlystores/network/index.js +21 -0
  21. package/dist/appendonlystores/network/index.js.map +1 -0
  22. package/dist/browser/crypto/BrowserCryptoAdapter.d.ts +14 -0
  23. package/dist/browser/crypto/BrowserCryptoAdapter.d.ts.map +1 -0
  24. package/dist/browser/crypto/BrowserCryptoAdapter.js +30 -0
  25. package/dist/browser/crypto/BrowserCryptoAdapter.js.map +1 -0
  26. package/dist/browser/index.d.ts +3 -0
  27. package/dist/browser/index.d.ts.map +1 -0
  28. package/dist/browser/index.js +26 -0
  29. package/dist/browser/index.js.map +1 -0
  30. package/dist/core/BaseMindooDB.d.ts +182 -0
  31. package/dist/core/BaseMindooDB.d.ts.map +1 -0
  32. package/dist/core/BaseMindooDB.js +1701 -0
  33. package/dist/core/BaseMindooDB.js.map +1 -0
  34. package/dist/core/BaseMindooTenant.d.ts +155 -0
  35. package/dist/core/BaseMindooTenant.d.ts.map +1 -0
  36. package/dist/core/BaseMindooTenant.js +673 -0
  37. package/dist/core/BaseMindooTenant.js.map +1 -0
  38. package/dist/core/BaseMindooTenantDirectory.d.ts +99 -0
  39. package/dist/core/BaseMindooTenantDirectory.d.ts.map +1 -0
  40. package/dist/core/BaseMindooTenantDirectory.js +776 -0
  41. package/dist/core/BaseMindooTenantDirectory.js.map +1 -0
  42. package/dist/core/BaseMindooTenantFactory.d.ts +91 -0
  43. package/dist/core/BaseMindooTenantFactory.d.ts.map +1 -0
  44. package/dist/core/BaseMindooTenantFactory.js +297 -0
  45. package/dist/core/BaseMindooTenantFactory.js.map +1 -0
  46. package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts +111 -0
  47. package/dist/core/appendonlystores/InMemoryContentAddressedStore.d.ts.map +1 -0
  48. package/dist/core/appendonlystores/InMemoryContentAddressedStore.js +293 -0
  49. package/dist/core/appendonlystores/InMemoryContentAddressedStore.js.map +1 -0
  50. package/dist/core/appendonlystores/network/AuthenticationService.d.ts +78 -0
  51. package/dist/core/appendonlystores/network/AuthenticationService.d.ts.map +1 -0
  52. package/dist/core/appendonlystores/network/AuthenticationService.js +297 -0
  53. package/dist/core/appendonlystores/network/AuthenticationService.js.map +1 -0
  54. package/dist/core/appendonlystores/network/NetworkTransport.d.ts +174 -0
  55. package/dist/core/appendonlystores/network/NetworkTransport.d.ts.map +1 -0
  56. package/dist/core/appendonlystores/network/NetworkTransport.js +3 -0
  57. package/dist/core/appendonlystores/network/NetworkTransport.js.map +1 -0
  58. package/dist/core/appendonlystores/network/types.d.ts +135 -0
  59. package/dist/core/appendonlystores/network/types.d.ts.map +1 -0
  60. package/dist/core/appendonlystores/network/types.js +35 -0
  61. package/dist/core/appendonlystores/network/types.js.map +1 -0
  62. package/dist/core/appendonlystores/types.d.ts +157 -0
  63. package/dist/core/appendonlystores/types.d.ts.map +1 -0
  64. package/dist/core/appendonlystores/types.js +3 -0
  65. package/dist/core/appendonlystores/types.js.map +1 -0
  66. package/dist/core/crypto/CryptoAdapter.d.ts +19 -0
  67. package/dist/core/crypto/CryptoAdapter.d.ts.map +1 -0
  68. package/dist/core/crypto/CryptoAdapter.js +3 -0
  69. package/dist/core/crypto/CryptoAdapter.js.map +1 -0
  70. package/dist/core/crypto/MindooDocSigner.d.ts +106 -0
  71. package/dist/core/crypto/MindooDocSigner.d.ts.map +1 -0
  72. package/dist/core/crypto/MindooDocSigner.js +192 -0
  73. package/dist/core/crypto/MindooDocSigner.js.map +1 -0
  74. package/dist/core/crypto/RSAEncryption.d.ts +62 -0
  75. package/dist/core/crypto/RSAEncryption.d.ts.map +1 -0
  76. package/dist/core/crypto/RSAEncryption.js +167 -0
  77. package/dist/core/crypto/RSAEncryption.js.map +1 -0
  78. package/dist/core/errors.d.ts +10 -0
  79. package/dist/core/errors.d.ts.map +1 -0
  80. package/dist/core/errors.js +17 -0
  81. package/dist/core/errors.js.map +1 -0
  82. package/dist/core/index.d.ts +14 -0
  83. package/dist/core/index.d.ts.map +1 -0
  84. package/dist/core/index.js +53 -0
  85. package/dist/core/index.js.map +1 -0
  86. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts +33 -0
  87. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.d.ts.map +1 -0
  88. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js +27 -0
  89. package/dist/core/indexing/virtualviews/IViewEntryAccessCheck.js.map +1 -0
  90. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts +31 -0
  91. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.d.ts.map +1 -0
  92. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js +3 -0
  93. package/dist/core/indexing/virtualviews/IVirtualViewDataProvider.js.map +1 -0
  94. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts +52 -0
  95. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.d.ts.map +1 -0
  96. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js +106 -0
  97. package/dist/core/indexing/virtualviews/MindooDBVirtualViewDataProvider.js.map +1 -0
  98. package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts +44 -0
  99. package/dist/core/indexing/virtualviews/ViewEntrySortKey.d.ts.map +1 -0
  100. package/dist/core/indexing/virtualviews/ViewEntrySortKey.js +107 -0
  101. package/dist/core/indexing/virtualviews/ViewEntrySortKey.js.map +1 -0
  102. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts +28 -0
  103. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.d.ts.map +1 -0
  104. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js +133 -0
  105. package/dist/core/indexing/virtualviews/ViewEntrySortKeyComparator.js.map +1 -0
  106. package/dist/core/indexing/virtualviews/VirtualView.d.ts +109 -0
  107. package/dist/core/indexing/virtualviews/VirtualView.d.ts.map +1 -0
  108. package/dist/core/indexing/virtualviews/VirtualView.js +504 -0
  109. package/dist/core/indexing/virtualviews/VirtualView.js.map +1 -0
  110. package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts +59 -0
  111. package/dist/core/indexing/virtualviews/VirtualViewColumn.d.ts.map +1 -0
  112. package/dist/core/indexing/virtualviews/VirtualViewColumn.js +70 -0
  113. package/dist/core/indexing/virtualviews/VirtualViewColumn.js.map +1 -0
  114. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts +49 -0
  115. package/dist/core/indexing/virtualviews/VirtualViewDataChange.d.ts.map +1 -0
  116. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js +69 -0
  117. package/dist/core/indexing/virtualviews/VirtualViewDataChange.js.map +1 -0
  118. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts +121 -0
  119. package/dist/core/indexing/virtualviews/VirtualViewEntryData.d.ts.map +1 -0
  120. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js +365 -0
  121. package/dist/core/indexing/virtualviews/VirtualViewEntryData.js.map +1 -0
  122. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts +131 -0
  123. package/dist/core/indexing/virtualviews/VirtualViewFactory.d.ts.map +1 -0
  124. package/dist/core/indexing/virtualviews/VirtualViewFactory.js +236 -0
  125. package/dist/core/indexing/virtualviews/VirtualViewFactory.js.map +1 -0
  126. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts +330 -0
  127. package/dist/core/indexing/virtualviews/VirtualViewNavigator.d.ts.map +1 -0
  128. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js +1010 -0
  129. package/dist/core/indexing/virtualviews/VirtualViewNavigator.js.map +1 -0
  130. package/dist/core/indexing/virtualviews/index.d.ts +53 -0
  131. package/dist/core/indexing/virtualviews/index.d.ts.map +1 -0
  132. package/dist/core/indexing/virtualviews/index.js +89 -0
  133. package/dist/core/indexing/virtualviews/index.js.map +1 -0
  134. package/dist/core/indexing/virtualviews/types.d.ts +115 -0
  135. package/dist/core/indexing/virtualviews/types.d.ts.map +1 -0
  136. package/dist/core/indexing/virtualviews/types.js +175 -0
  137. package/dist/core/indexing/virtualviews/types.js.map +1 -0
  138. package/dist/core/keys/KeyBag.d.ts +122 -0
  139. package/dist/core/keys/KeyBag.d.ts.map +1 -0
  140. package/dist/core/keys/KeyBag.js +401 -0
  141. package/dist/core/keys/KeyBag.js.map +1 -0
  142. package/dist/core/types.d.ts +1004 -0
  143. package/dist/core/types.d.ts.map +1 -0
  144. package/dist/core/types.js +10 -0
  145. package/dist/core/types.js.map +1 -0
  146. package/dist/core/userid/index.d.ts +53 -0
  147. package/dist/core/userid/index.d.ts.map +1 -0
  148. package/dist/core/userid/index.js +3 -0
  149. package/dist/core/userid/index.js.map +1 -0
  150. package/dist/core/utils/idGeneration.d.ts +109 -0
  151. package/dist/core/utils/idGeneration.d.ts.map +1 -0
  152. package/dist/core/utils/idGeneration.js +182 -0
  153. package/dist/core/utils/idGeneration.js.map +1 -0
  154. package/dist/core/utils/index.d.ts +5 -0
  155. package/dist/core/utils/index.d.ts.map +1 -0
  156. package/dist/core/utils/index.js +19 -0
  157. package/dist/core/utils/index.js.map +1 -0
  158. package/dist/index.d.ts +7 -0
  159. package/dist/index.d.ts.map +1 -0
  160. package/dist/index.js +40 -0
  161. package/dist/index.js.map +1 -0
  162. package/dist/node/crypto/NodeCryptoAdapter.d.ts +16 -0
  163. package/dist/node/crypto/NodeCryptoAdapter.d.ts.map +1 -0
  164. package/dist/node/crypto/NodeCryptoAdapter.js +53 -0
  165. package/dist/node/crypto/NodeCryptoAdapter.js.map +1 -0
  166. package/dist/node/index.d.ts +3 -0
  167. package/dist/node/index.d.ts.map +1 -0
  168. package/dist/node/index.js +26 -0
  169. package/dist/node/index.js.map +1 -0
  170. package/package.json +58 -0
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NetworkError = exports.NetworkErrorType = void 0;
4
+ /**
5
+ * Network transport error types for error handling.
6
+ */
7
+ var NetworkErrorType;
8
+ (function (NetworkErrorType) {
9
+ /** Token is invalid or expired */
10
+ NetworkErrorType["INVALID_TOKEN"] = "INVALID_TOKEN";
11
+ /** User has been revoked */
12
+ NetworkErrorType["USER_REVOKED"] = "USER_REVOKED";
13
+ /** Signature verification failed */
14
+ NetworkErrorType["INVALID_SIGNATURE"] = "INVALID_SIGNATURE";
15
+ /** Challenge expired or already used */
16
+ NetworkErrorType["CHALLENGE_EXPIRED"] = "CHALLENGE_EXPIRED";
17
+ /** Network communication error */
18
+ NetworkErrorType["NETWORK_ERROR"] = "NETWORK_ERROR";
19
+ /** Server-side error */
20
+ NetworkErrorType["SERVER_ERROR"] = "SERVER_ERROR";
21
+ /** User not found in directory */
22
+ NetworkErrorType["USER_NOT_FOUND"] = "USER_NOT_FOUND";
23
+ })(NetworkErrorType || (exports.NetworkErrorType = NetworkErrorType = {}));
24
+ /**
25
+ * Network transport error with type for structured error handling.
26
+ */
27
+ class NetworkError extends Error {
28
+ constructor(type, message) {
29
+ super(message);
30
+ this.type = type;
31
+ this.name = "NetworkError";
32
+ }
33
+ }
34
+ exports.NetworkError = NetworkError;
35
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/appendonlystores/network/types.ts"],"names":[],"mappings":";;;AA6HA;;GAEG;AACH,IAAY,gBAeX;AAfD,WAAY,gBAAgB;IAC1B,kCAAkC;IAClC,mDAA+B,CAAA;IAC/B,4BAA4B;IAC5B,iDAA6B,CAAA;IAC7B,oCAAoC;IACpC,2DAAuC,CAAA;IACvC,wCAAwC;IACxC,2DAAuC,CAAA;IACvC,kCAAkC;IAClC,mDAA+B,CAAA;IAC/B,wBAAwB;IACxB,iDAA6B,CAAA;IAC7B,kCAAkC;IAClC,qDAAiC,CAAA;AACnC,CAAC,EAfW,gBAAgB,gCAAhB,gBAAgB,QAe3B;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,KAAK;IACrC,YACkB,IAAsB,EACtC,OAAe;QAEf,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAkB;QAItC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AARD,oCAQC"}
@@ -0,0 +1,157 @@
1
+ import type { StoreEntry, StoreEntryMetadata } from "../types";
2
+ /**
3
+ * Options for opening/creating a database store.
4
+ * Factory implementations can use these to customize store behavior.
5
+ *
6
+ * This is an open interface that allows any implementation-specific options.
7
+ * Examples of options that implementations might support:
8
+ * - preferLocal: boolean - Prefer local storage over remote
9
+ * - cacheSize: number - Maximum cache size
10
+ * - syncMode: "eager" | "lazy" - Synchronization strategy
11
+ */
12
+ export interface OpenStoreOptions {
13
+ [key: string]: unknown;
14
+ }
15
+ /**
16
+ * Result of creating stores for a database.
17
+ * Contains the document store and an optional separate attachment store.
18
+ */
19
+ export interface CreateStoreResult {
20
+ /**
21
+ * The store for document changes (doc_create, doc_change, doc_snapshot, doc_delete).
22
+ * This is required.
23
+ */
24
+ docStore: ContentAddressedStore;
25
+ /**
26
+ * Optional separate store for attachment chunks (attachment_chunk).
27
+ * If not provided, attachments are stored in the docStore.
28
+ * Having a separate store enables:
29
+ * - Different storage backends (e.g., local docs, cloud attachments)
30
+ * - Different caching/eviction policies
31
+ * - Cost optimization (cheaper storage for large attachments)
32
+ */
33
+ attachmentStore?: ContentAddressedStore;
34
+ }
35
+ /**
36
+ * ContentAddressedStoreFactory creates ContentAddressedStore instances for a given database ID.
37
+ * This allows different implementations to provide different storage backends
38
+ * (e.g., in-memory, file-based, database-backed, cloud storage) while maintaining a consistent interface.
39
+ */
40
+ export interface ContentAddressedStoreFactory {
41
+ /**
42
+ * Create stores for the given database ID.
43
+ * Returns a document store and optionally a separate attachment store.
44
+ *
45
+ * @param dbId The ID of the database (e.g., "directory" for the tenant directory database)
46
+ * @param options Optional configuration for store creation (e.g., preferLocal, custom settings)
47
+ * @return An object containing the document store and optional attachment store
48
+ */
49
+ createStore(dbId: string, options?: OpenStoreOptions): CreateStoreResult;
50
+ }
51
+ /**
52
+ * A ContentAddressedStore is a store that stores signed and optionally encrypted
53
+ * binary entries. Each entry has:
54
+ * - A unique `id` (primary key for lookups)
55
+ * - A `contentHash` (SHA-256 of encrypted data, for deduplication)
56
+ *
57
+ * The store supports both Automerge document changes and attachment chunks through
58
+ * a unified interface, with storage-level deduplication based on contentHash.
59
+ *
60
+ * The store is responsible for:
61
+ * - Storing entries with metadata indexed by id
62
+ * - Deduplicating encrypted bytes by contentHash (same content stored once)
63
+ * - Providing methods to retrieve entries by id
64
+ * - Finding new entries for synchronization
65
+ * - Resolving dependency chains (for traversing DAG structures)
66
+ *
67
+ * The append-only structure makes synchronization easy between peers (client-client,
68
+ * client-server, server-server). Store implementations can optimize storage based on
69
+ * entry type (e.g., inline small doc changes, external storage for large attachment chunks).
70
+ */
71
+ export interface ContentAddressedStore {
72
+ /**
73
+ * Get the ID of the store
74
+ *
75
+ * @return The ID of the store
76
+ */
77
+ getId(): string;
78
+ /**
79
+ * Store one or more entries.
80
+ * - Metadata is stored by entry id (always unique)
81
+ * - Encrypted bytes are deduplicated by contentHash (same bytes stored once)
82
+ *
83
+ * @param entries The entries to store
84
+ * @return A promise that resolves when all entries are stored
85
+ */
86
+ putEntries(entries: StoreEntry[]): Promise<void>;
87
+ /**
88
+ * Get entries by their IDs.
89
+ * Returns only entries that exist in this store.
90
+ *
91
+ * @param ids The IDs of the entries to fetch
92
+ * @return A list of entries (may be shorter than input if some don't exist)
93
+ */
94
+ getEntries(ids: string[]): Promise<StoreEntry[]>;
95
+ /**
96
+ * Check which IDs from the provided list exist in this store.
97
+ *
98
+ * @param ids The IDs to check
99
+ * @return A list of IDs that exist in this store
100
+ */
101
+ hasEntries(ids: string[]): Promise<string[]>;
102
+ /**
103
+ * Find entries in the store that are not listed in the given list of IDs.
104
+ * Used for synchronization to identify which entries we have that the peer doesn't.
105
+ *
106
+ * @param knownIds The list of entry IDs we already have
107
+ * @return A list of entry metadata for entries we have that aren't in knownIds
108
+ */
109
+ findNewEntries(knownIds: string[]): Promise<StoreEntryMetadata[]>;
110
+ /**
111
+ * Find entries in the store for a specific document that are not listed in the given list of IDs.
112
+ *
113
+ * @param knownIds The list of entry IDs we already have
114
+ * @param docId The ID of the document
115
+ * @return A list of entry metadata for entries we have that aren't in knownIds
116
+ */
117
+ findNewEntriesForDoc(knownIds: string[], docId: string): Promise<StoreEntryMetadata[]>;
118
+ /**
119
+ * Get all entry IDs in the store.
120
+ * Used for synchronization to identify which entries we have.
121
+ *
122
+ * @return A list of all entry IDs in the store
123
+ */
124
+ getAllIds(): Promise<string[]>;
125
+ /**
126
+ * Resolve the dependency chain starting from an entry ID.
127
+ * Returns IDs in dependency order, traversing backward through dependencyIds.
128
+ *
129
+ * This is useful for:
130
+ * - Loading all chunks of an attachment (traverse from last to first chunk)
131
+ * - Finding all changes needed to reconstruct a document state
132
+ * - Stopping at snapshots when loading documents (use options.stopAtEntryType)
133
+ *
134
+ * @param startId The entry ID to start traversal from
135
+ * @param options Optional traversal options:
136
+ * - stopAtEntryType: Stop when encountering an entry of this type (e.g., "doc_snapshot")
137
+ * - maxDepth: Maximum number of hops to traverse
138
+ * - includeStart: Whether to include startId in the result (default: true)
139
+ * @return A list of entry IDs in dependency order (oldest first by default)
140
+ */
141
+ resolveDependencies(startId: string, options?: Record<string, unknown>): Promise<string[]>;
142
+ /**
143
+ * Purge all entries for a specific document from the store.
144
+ * This breaks append-only semantics but is required for GDPR compliance
145
+ * (right to be forgotten).
146
+ *
147
+ * After purging, all entries for the specified document will be removed
148
+ * from the store. Content bytes that are no longer referenced by any
149
+ * entry should also be cleaned up.
150
+ *
151
+ * @param docId The document ID whose entries should be purged
152
+ * @return A promise that resolves when the purge is complete
153
+ * @throws Error if the store implementation does not support purging
154
+ */
155
+ purgeDocHistory(docId: string): Promise<void>;
156
+ }
157
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/appendonlystores/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE/D;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,EAAE,qBAAqB,CAAC;IAEhC;;;;;;;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ineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/appendonlystores/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * CryptoAdapter provides a platform-agnostic interface to the Web Crypto API.
3
+ * This allows BaseMindooTenant to work in both browser and Node.js environments.
4
+ */
5
+ export interface CryptoAdapter {
6
+ /**
7
+ * Get the SubtleCrypto interface for cryptographic operations.
8
+ * In browsers: window.crypto.subtle
9
+ * In Node.js: crypto.webcrypto.subtle
10
+ */
11
+ getSubtle(): SubtleCrypto;
12
+ /**
13
+ * Get random values for key generation and IVs.
14
+ * In browsers: window.crypto.getRandomValues
15
+ * In Node.js: crypto.webcrypto.getRandomValues
16
+ */
17
+ getRandomValues(array: Uint8Array): Uint8Array;
18
+ }
19
+ //# sourceMappingURL=CryptoAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CryptoAdapter.d.ts","sourceRoot":"","sources":["../../../src/core/crypto/CryptoAdapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,SAAS,IAAI,YAAY,CAAC;IAE1B;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC;CAChD"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=CryptoAdapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CryptoAdapter.js","sourceRoot":"","sources":["../../../src/core/crypto/CryptoAdapter.ts"],"names":[],"mappings":""}
@@ -0,0 +1,106 @@
1
+ import { MindooDoc, SigningKeyPair } from "../types";
2
+ import { BaseMindooTenant } from "../BaseMindooTenant";
3
+ /**
4
+ * MindooDocSigner provides functionality to create and verify combined signatures
5
+ * for multiple document items in a MindooDoc.
6
+ *
7
+ * This class addresses the security requirement of preventing selective tampering
8
+ * with document fields. By signing multiple document items together in a single
9
+ * signature operation, any modification to any signed field will invalidate the
10
+ * entire signature.
11
+ *
12
+ * ## Key Features
13
+ *
14
+ * - **Combined Signatures**: All specified document items are signed together in
15
+ * one operation, preventing attackers from selectively modifying individual fields
16
+ * (e.g., changing a "type" field while keeping other fields intact).
17
+ *
18
+ * - **Canonical JSON Serialization**: Uses deterministic JSON serialization that
19
+ * handles JavaScript's non-deterministic object key ordering. Object keys are
20
+ * sorted alphabetically, and nested objects are processed recursively to ensure
21
+ * the same data always produces the same signature.
22
+ *
23
+ * - **Ed25519 Signatures**: Uses Ed25519 digital signatures for cryptographic
24
+ * security and verification.
25
+ *
26
+ * ## Usage Example
27
+ *
28
+ * ```typescript
29
+ * const signer = new MindooDocSigner(tenant, signingKeyPair);
30
+ *
31
+ * // Sign multiple document items together
32
+ * const signature = await signer.signItems(
33
+ * doc,
34
+ * ["type", "status", "metadata"],
35
+ * password
36
+ * );
37
+ *
38
+ * // Verify the signature
39
+ * const isValid = await signer.verifyItems(
40
+ * doc,
41
+ * ["type", "status", "metadata"],
42
+ * signature,
43
+ * publicKey
44
+ * );
45
+ * ```
46
+ *
47
+ * ## Security Considerations
48
+ *
49
+ * - The signature covers all specified items as a single unit. Changing any
50
+ * signed field will invalidate the signature.
51
+ * - Missing fields are included as `null` in the canonical representation to
52
+ * ensure deterministic signatures regardless of field presence.
53
+ * - The signing key is decrypted using the tenant's key decryption infrastructure,
54
+ * ensuring consistent security practices across the codebase.
55
+ *
56
+ * ## Dependencies
57
+ *
58
+ * - Requires a `BaseMindooTenant` instance for cryptographic operations
59
+ * (key decryption, crypto adapter access)
60
+ * - Uses Ed25519 signing algorithm (Ed25519 signatures)
61
+ * - Uses canonical JSON serialization for deterministic signatures
62
+ *
63
+ * @see BaseMindooTenant For the tenant infrastructure used for key management
64
+ */
65
+ export declare class MindooDocSigner {
66
+ private tenant;
67
+ private signKey;
68
+ constructor(tenant: BaseMindooTenant, signKey: SigningKeyPair);
69
+ /**
70
+ * Creates a canonical JSON representation of the selected document items.
71
+ * This ensures deterministic serialization regardless of object key order.
72
+ *
73
+ * The canonical format:
74
+ * - Object keys are sorted alphabetically
75
+ * - Nested objects are processed recursively
76
+ * - Arrays preserve order
77
+ * - Primitives (string, number, boolean, null) are serialized as-is
78
+ * - undefined values are omitted (not included in the signature)
79
+ *
80
+ * @param payload The document payload
81
+ * @param items The item keys to include in the signature
82
+ * @returns A canonical JSON string representation
83
+ */
84
+ private createCanonicalJSON;
85
+ /**
86
+ * Signs the specified document items with a combined signature.
87
+ * This prevents selective tampering by signing all items together in one operation.
88
+ *
89
+ * @param doc The document to sign items from
90
+ * @param items The item keys to include in the signature
91
+ * @param signPassword The password to decrypt the signing private key
92
+ * @returns The signature as a Uint8Array
93
+ */
94
+ signItems(doc: MindooDoc, items: string[], signPassword: string): Promise<Uint8Array>;
95
+ /**
96
+ * Verifies the signature for the specified document items.
97
+ *
98
+ * @param doc The document to verify items from
99
+ * @param items The item keys that were included in the signature
100
+ * @param signature The signature to verify
101
+ * @param publicKey The public key to verify the signature with (Ed25519, PEM format)
102
+ * @returns True if the signature is valid, false otherwise
103
+ */
104
+ verifyItems(doc: MindooDoc, items: string[], signature: Uint8Array, publicKey: string): Promise<boolean>;
105
+ }
106
+ //# sourceMappingURL=MindooDocSigner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MindooDocSigner.d.ts","sourceRoot":"","sources":["../../../src/core/crypto/MindooDocSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,cAAc,EAAoB,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,OAAO,CAAiB;gBAEpB,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,cAAc;IAK7D;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,mBAAmB;IA6C3B;;;;;;;;OAQG;IACG,SAAS,CAAC,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IA4C3F;;;;;;;;OAQG;IACG,WAAW,CACf,GAAG,EAAE,SAAS,EACd,KAAK,EAAE,MAAM,EAAE,EACf,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,OAAO,CAAC;CAyCpB"}
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MindooDocSigner = void 0;
4
+ /**
5
+ * MindooDocSigner provides functionality to create and verify combined signatures
6
+ * for multiple document items in a MindooDoc.
7
+ *
8
+ * This class addresses the security requirement of preventing selective tampering
9
+ * with document fields. By signing multiple document items together in a single
10
+ * signature operation, any modification to any signed field will invalidate the
11
+ * entire signature.
12
+ *
13
+ * ## Key Features
14
+ *
15
+ * - **Combined Signatures**: All specified document items are signed together in
16
+ * one operation, preventing attackers from selectively modifying individual fields
17
+ * (e.g., changing a "type" field while keeping other fields intact).
18
+ *
19
+ * - **Canonical JSON Serialization**: Uses deterministic JSON serialization that
20
+ * handles JavaScript's non-deterministic object key ordering. Object keys are
21
+ * sorted alphabetically, and nested objects are processed recursively to ensure
22
+ * the same data always produces the same signature.
23
+ *
24
+ * - **Ed25519 Signatures**: Uses Ed25519 digital signatures for cryptographic
25
+ * security and verification.
26
+ *
27
+ * ## Usage Example
28
+ *
29
+ * ```typescript
30
+ * const signer = new MindooDocSigner(tenant, signingKeyPair);
31
+ *
32
+ * // Sign multiple document items together
33
+ * const signature = await signer.signItems(
34
+ * doc,
35
+ * ["type", "status", "metadata"],
36
+ * password
37
+ * );
38
+ *
39
+ * // Verify the signature
40
+ * const isValid = await signer.verifyItems(
41
+ * doc,
42
+ * ["type", "status", "metadata"],
43
+ * signature,
44
+ * publicKey
45
+ * );
46
+ * ```
47
+ *
48
+ * ## Security Considerations
49
+ *
50
+ * - The signature covers all specified items as a single unit. Changing any
51
+ * signed field will invalidate the signature.
52
+ * - Missing fields are included as `null` in the canonical representation to
53
+ * ensure deterministic signatures regardless of field presence.
54
+ * - The signing key is decrypted using the tenant's key decryption infrastructure,
55
+ * ensuring consistent security practices across the codebase.
56
+ *
57
+ * ## Dependencies
58
+ *
59
+ * - Requires a `BaseMindooTenant` instance for cryptographic operations
60
+ * (key decryption, crypto adapter access)
61
+ * - Uses Ed25519 signing algorithm (Ed25519 signatures)
62
+ * - Uses canonical JSON serialization for deterministic signatures
63
+ *
64
+ * @see BaseMindooTenant For the tenant infrastructure used for key management
65
+ */
66
+ class MindooDocSigner {
67
+ constructor(tenant, signKey) {
68
+ this.tenant = tenant;
69
+ this.signKey = signKey;
70
+ }
71
+ /**
72
+ * Creates a canonical JSON representation of the selected document items.
73
+ * This ensures deterministic serialization regardless of object key order.
74
+ *
75
+ * The canonical format:
76
+ * - Object keys are sorted alphabetically
77
+ * - Nested objects are processed recursively
78
+ * - Arrays preserve order
79
+ * - Primitives (string, number, boolean, null) are serialized as-is
80
+ * - undefined values are omitted (not included in the signature)
81
+ *
82
+ * @param payload The document payload
83
+ * @param items The item keys to include in the signature
84
+ * @returns A canonical JSON string representation
85
+ */
86
+ createCanonicalJSON(payload, items) {
87
+ // Extract only the specified items
88
+ // Include all specified items, even if they don't exist (will be null)
89
+ // This ensures deterministic signatures regardless of field presence
90
+ const selectedItems = {};
91
+ for (const itemKey of items) {
92
+ if (itemKey in payload) {
93
+ selectedItems[itemKey] = payload[itemKey];
94
+ }
95
+ else {
96
+ // Field doesn't exist - include as null for deterministic signature
97
+ selectedItems[itemKey] = null;
98
+ }
99
+ }
100
+ // Recursively canonicalize the object
101
+ const canonicalize = (value) => {
102
+ if (value === null || value === undefined) {
103
+ return null; // Treat undefined as null for consistency
104
+ }
105
+ if (Array.isArray(value)) {
106
+ return value.map(item => canonicalize(item));
107
+ }
108
+ if (typeof value === "object") {
109
+ // Sort keys alphabetically and recursively process values
110
+ const sortedKeys = Object.keys(value).sort();
111
+ const canonicalized = {};
112
+ for (const key of sortedKeys) {
113
+ const itemValue = value[key];
114
+ if (itemValue !== undefined) {
115
+ canonicalized[key] = canonicalize(itemValue);
116
+ }
117
+ }
118
+ return canonicalized;
119
+ }
120
+ // Primitives: string, number, boolean
121
+ return value;
122
+ };
123
+ const canonicalized = canonicalize(selectedItems);
124
+ return JSON.stringify(canonicalized);
125
+ }
126
+ /**
127
+ * Signs the specified document items with a combined signature.
128
+ * This prevents selective tampering by signing all items together in one operation.
129
+ *
130
+ * @param doc The document to sign items from
131
+ * @param items The item keys to include in the signature
132
+ * @param signPassword The password to decrypt the signing private key
133
+ * @returns The signature as a Uint8Array
134
+ */
135
+ async signItems(doc, items, signPassword) {
136
+ const docPayload = doc.getData();
137
+ // Create canonical JSON representation
138
+ const canonicalJSON = this.createCanonicalJSON(docPayload, items);
139
+ console.log(`[MindooDocSigner] Canonical JSON for signing: ${canonicalJSON}`);
140
+ // Convert to bytes (UTF-8 encoding)
141
+ const encoder = new TextEncoder();
142
+ const payloadBytes = encoder.encode(canonicalJSON);
143
+ // Decrypt the signing private key using the tenant's decryptPrivateKey method
144
+ const decryptedKeyBuffer = await this.tenant.decryptPrivateKey(this.signKey.privateKey, signPassword, "signing");
145
+ const subtle = this.tenant.getCryptoAdapter().getSubtle();
146
+ // Import the decrypted key as an Ed25519 private key
147
+ const signingKey = await subtle.importKey("pkcs8", decryptedKeyBuffer, {
148
+ name: "Ed25519",
149
+ }, false, // not extractable
150
+ ["sign"]);
151
+ // Sign the payload
152
+ const signature = await subtle.sign({
153
+ name: "Ed25519",
154
+ }, signingKey, payloadBytes.buffer);
155
+ console.log(`[MindooDocSigner] Signed ${items.length} items (signature: ${signature.byteLength} bytes)`);
156
+ return new Uint8Array(signature);
157
+ }
158
+ /**
159
+ * Verifies the signature for the specified document items.
160
+ *
161
+ * @param doc The document to verify items from
162
+ * @param items The item keys that were included in the signature
163
+ * @param signature The signature to verify
164
+ * @param publicKey The public key to verify the signature with (Ed25519, PEM format)
165
+ * @returns True if the signature is valid, false otherwise
166
+ */
167
+ async verifyItems(doc, items, signature, publicKey) {
168
+ const docPayload = doc.getData();
169
+ // Create the same canonical JSON representation
170
+ const canonicalJSON = this.createCanonicalJSON(docPayload, items);
171
+ console.log(`[MindooDocSigner] Canonical JSON for verification: ${canonicalJSON}`);
172
+ // Convert to bytes (UTF-8 encoding)
173
+ const encoder = new TextEncoder();
174
+ const payloadBytes = encoder.encode(canonicalJSON);
175
+ const subtle = this.tenant.getCryptoAdapter().getSubtle();
176
+ // Convert PEM format to ArrayBuffer using tenant's public method
177
+ const publicKeyBuffer = this.tenant.pemToArrayBuffer(publicKey);
178
+ // Import the public key from SPKI format
179
+ const cryptoKey = await subtle.importKey("spki", publicKeyBuffer, {
180
+ name: "Ed25519",
181
+ }, false, // not extractable
182
+ ["verify"]);
183
+ // Verify the signature
184
+ const isValid = await subtle.verify({
185
+ name: "Ed25519",
186
+ }, cryptoKey, signature.buffer, payloadBytes.buffer);
187
+ console.log(`[MindooDocSigner] Signature verification: ${isValid ? "valid" : "invalid"}`);
188
+ return isValid;
189
+ }
190
+ }
191
+ exports.MindooDocSigner = MindooDocSigner;
192
+ //# sourceMappingURL=MindooDocSigner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MindooDocSigner.js","sourceRoot":"","sources":["../../../src/core/crypto/MindooDocSigner.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AACH,MAAa,eAAe;IAI1B,YAAY,MAAwB,EAAE,OAAuB;QAC3D,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC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OAAO,OAAO,CAAC;IACjB,CAAC;CAEF;AAjLD,0CAiLC"}
@@ -0,0 +1,62 @@
1
+ import type { CryptoAdapter } from "./CryptoAdapter";
2
+ /**
3
+ * RSA Encryption utilities for network transport security.
4
+ *
5
+ * Uses RSA-OAEP for encrypting change payloads during network transport.
6
+ * The encrypted data can only be decrypted by the recipient who has
7
+ * the corresponding private key.
8
+ *
9
+ * This provides an additional layer of security on top of the existing
10
+ * symmetric encryption (AES-256-GCM) used for storage.
11
+ */
12
+ export declare class RSAEncryption {
13
+ private cryptoAdapter;
14
+ constructor(cryptoAdapter: CryptoAdapter);
15
+ /**
16
+ * Import an RSA public key from PEM format.
17
+ *
18
+ * @param pemKey The public key in PEM format (SPKI)
19
+ * @returns The imported CryptoKey for encryption
20
+ */
21
+ importPublicKey(pemKey: string): Promise<CryptoKey>;
22
+ /**
23
+ * Import an RSA private key from PEM format.
24
+ *
25
+ * @param pemKey The private key in PEM format (PKCS#8)
26
+ * @returns The imported CryptoKey for decryption
27
+ */
28
+ importPrivateKey(pemKey: string): Promise<CryptoKey>;
29
+ /**
30
+ * Encrypt data with an RSA public key.
31
+ *
32
+ * Note: RSA-OAEP with 3072-bit keys and SHA-256 can only encrypt
33
+ * up to 318 bytes directly. For larger payloads, this method uses
34
+ * hybrid encryption: generates a random AES key, encrypts the data
35
+ * with AES-GCM, then encrypts the AES key with RSA.
36
+ *
37
+ * @param data The data to encrypt
38
+ * @param publicKey The RSA public key (CryptoKey or PEM string)
39
+ * @returns The encrypted data
40
+ */
41
+ encrypt(data: Uint8Array, publicKey: CryptoKey | string): Promise<Uint8Array>;
42
+ /**
43
+ * Decrypt data with an RSA private key.
44
+ *
45
+ * Handles hybrid encryption: extracts the RSA-encrypted AES key,
46
+ * decrypts it with RSA, then uses AES-GCM to decrypt the payload.
47
+ *
48
+ * @param encryptedData The encrypted data
49
+ * @param privateKey The RSA private key (CryptoKey or PEM string)
50
+ * @returns The decrypted data
51
+ */
52
+ decrypt(encryptedData: Uint8Array, privateKey: CryptoKey | string): Promise<Uint8Array>;
53
+ /**
54
+ * Convert a base64 string to Uint8Array.
55
+ */
56
+ private base64ToUint8Array;
57
+ /**
58
+ * Convert a Uint8Array to base64 string.
59
+ */
60
+ private uint8ArrayToBase64;
61
+ }
62
+ //# sourceMappingURL=RSAEncryption.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RSAEncryption.d.ts","sourceRoot":"","sources":["../../../src/core/crypto/RSAEncryption.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAErD;;;;;;;;;GASG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,aAAa,CAAgB;gBAEzB,aAAa,EAAE,aAAa;IAIxC;;;;;OAKG;IACG,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA4BzD;;;;;OAKG;IACG,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA4B1D;;;;;;;;;;;OAWG;IACG,OAAO,CACX,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,SAAS,GAAG,MAAM,GAC5B,OAAO,CAAC,UAAU,CAAC;IAoEtB;;;;;;;;;OASG;IACG,OAAO,CACX,aAAa,EAAE,UAAU,EACzB,UAAU,EAAE,SAAS,GAAG,MAAM,GAC7B,OAAO,CAAC,UAAU,CAAC;IAgDtB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAS1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAO3B"}