@brightchain/brightchain-api-lib 0.24.1 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/package.json +4 -3
  2. package/src/lib/application.d.ts +3 -14
  3. package/src/lib/application.d.ts.map +1 -1
  4. package/src/lib/application.js +121 -44
  5. package/src/lib/application.js.map +1 -1
  6. package/src/lib/auth/aclDocumentStore.d.ts +90 -0
  7. package/src/lib/auth/aclDocumentStore.d.ts.map +1 -0
  8. package/src/lib/auth/aclDocumentStore.js +155 -0
  9. package/src/lib/auth/aclDocumentStore.js.map +1 -0
  10. package/src/lib/auth/index.d.ts +4 -0
  11. package/src/lib/auth/index.d.ts.map +1 -1
  12. package/src/lib/auth/index.js +4 -0
  13. package/src/lib/auth/index.js.map +1 -1
  14. package/src/lib/auth/writeAclApiRouter.d.ts +32 -0
  15. package/src/lib/auth/writeAclApiRouter.d.ts.map +1 -0
  16. package/src/lib/auth/writeAclApiRouter.js +348 -0
  17. package/src/lib/auth/writeAclApiRouter.js.map +1 -0
  18. package/src/lib/auth/writeAclAuditLogger.d.ts +94 -0
  19. package/src/lib/auth/writeAclAuditLogger.d.ts.map +1 -0
  20. package/src/lib/auth/writeAclAuditLogger.js +143 -0
  21. package/src/lib/auth/writeAclAuditLogger.js.map +1 -0
  22. package/src/lib/auth/writeProofMiddleware.d.ts +39 -0
  23. package/src/lib/auth/writeProofMiddleware.d.ts.map +1 -0
  24. package/src/lib/auth/writeProofMiddleware.js +56 -0
  25. package/src/lib/auth/writeProofMiddleware.js.map +1 -0
  26. package/src/lib/availability/aclDocumentSyncHandler.d.ts +39 -0
  27. package/src/lib/availability/aclDocumentSyncHandler.d.ts.map +1 -0
  28. package/src/lib/availability/aclDocumentSyncHandler.js +81 -0
  29. package/src/lib/availability/aclDocumentSyncHandler.js.map +1 -0
  30. package/src/lib/availability/gossipService.d.ts +4 -1
  31. package/src/lib/availability/gossipService.d.ts.map +1 -1
  32. package/src/lib/availability/gossipService.js +15 -1
  33. package/src/lib/availability/gossipService.js.map +1 -1
  34. package/src/lib/availability/headUpdateSyncHandler.d.ts +32 -0
  35. package/src/lib/availability/headUpdateSyncHandler.d.ts.map +1 -0
  36. package/src/lib/availability/headUpdateSyncHandler.js +78 -0
  37. package/src/lib/availability/headUpdateSyncHandler.js.map +1 -0
  38. package/src/lib/availability/index.d.ts +2 -0
  39. package/src/lib/availability/index.d.ts.map +1 -1
  40. package/src/lib/availability/index.js +2 -0
  41. package/src/lib/availability/index.js.map +1 -1
  42. package/src/lib/constants.d.ts.map +1 -1
  43. package/src/lib/constants.js +2 -0
  44. package/src/lib/constants.js.map +1 -1
  45. package/src/lib/controllers/api/brighthub/connectionController.d.ts +6 -0
  46. package/src/lib/controllers/api/brighthub/connectionController.d.ts.map +1 -1
  47. package/src/lib/controllers/api/brighthub/connectionController.js +158 -11
  48. package/src/lib/controllers/api/brighthub/connectionController.js.map +1 -1
  49. package/src/lib/controllers/api/brighthub/messagingController.d.ts +6 -0
  50. package/src/lib/controllers/api/brighthub/messagingController.d.ts.map +1 -1
  51. package/src/lib/controllers/api/brighthub/messagingController.js +190 -58
  52. package/src/lib/controllers/api/brighthub/messagingController.js.map +1 -1
  53. package/src/lib/controllers/api/brighthub/postController.d.ts +12 -3
  54. package/src/lib/controllers/api/brighthub/postController.d.ts.map +1 -1
  55. package/src/lib/controllers/api/brighthub/postController.js +60 -0
  56. package/src/lib/controllers/api/brighthub/postController.js.map +1 -1
  57. package/src/lib/controllers/api/brighthub/timelineController.d.ts +19 -0
  58. package/src/lib/controllers/api/brighthub/timelineController.d.ts.map +1 -1
  59. package/src/lib/controllers/api/brighthub/timelineController.js +133 -0
  60. package/src/lib/controllers/api/brighthub/timelineController.js.map +1 -1
  61. package/src/lib/controllers/api/emails.d.ts +4 -1
  62. package/src/lib/controllers/api/emails.d.ts.map +1 -1
  63. package/src/lib/controllers/api/emails.js +28 -1
  64. package/src/lib/controllers/api/emails.js.map +1 -1
  65. package/src/lib/controllers/api/user.d.ts.map +1 -1
  66. package/src/lib/controllers/api/user.js +10 -0
  67. package/src/lib/controllers/api/user.js.map +1 -1
  68. package/src/lib/databaseInit.d.ts +7 -11
  69. package/src/lib/databaseInit.d.ts.map +1 -1
  70. package/src/lib/databaseInit.js +41 -97
  71. package/src/lib/databaseInit.js.map +1 -1
  72. package/src/lib/datastore/block-document-store-factory.d.ts +3 -0
  73. package/src/lib/datastore/block-document-store-factory.d.ts.map +1 -1
  74. package/src/lib/datastore/block-document-store-factory.js +15 -18
  75. package/src/lib/datastore/block-document-store-factory.js.map +1 -1
  76. package/src/lib/datastore/block-document-store.d.ts +2 -191
  77. package/src/lib/datastore/block-document-store.d.ts.map +1 -1
  78. package/src/lib/datastore/block-document-store.js +4 -628
  79. package/src/lib/datastore/block-document-store.js.map +1 -1
  80. package/src/lib/datastore/document-store.d.ts +1 -62
  81. package/src/lib/datastore/document-store.d.ts.map +1 -1
  82. package/src/lib/datastore/memory-document-store.d.ts +1 -8
  83. package/src/lib/datastore/memory-document-store.d.ts.map +1 -1
  84. package/src/lib/datastore/memory-document-store.js +3 -214
  85. package/src/lib/datastore/memory-document-store.js.map +1 -1
  86. package/src/lib/environment.d.ts +3 -20
  87. package/src/lib/environment.d.ts.map +1 -1
  88. package/src/lib/environment.js +2 -45
  89. package/src/lib/environment.js.map +1 -1
  90. package/src/lib/factories/blockStoreFactory.d.ts.map +1 -1
  91. package/src/lib/factories/blockStoreFactory.js +4 -1
  92. package/src/lib/factories/blockStoreFactory.js.map +1 -1
  93. package/src/lib/interfaces/environment.d.ts +23 -2
  94. package/src/lib/interfaces/environment.d.ts.map +1 -1
  95. package/src/lib/interfaces/responses/brighthub/api-post-response.d.ts +8 -1
  96. package/src/lib/interfaces/responses/brighthub/api-post-response.d.ts.map +1 -1
  97. package/src/lib/middleware/index.d.ts +1 -1
  98. package/src/lib/middleware/index.d.ts.map +1 -1
  99. package/src/lib/middleware/index.js +3 -2
  100. package/src/lib/middleware/index.js.map +1 -1
  101. package/src/lib/middleware/validateBody.d.ts +1 -12
  102. package/src/lib/middleware/validateBody.d.ts.map +1 -1
  103. package/src/lib/middleware/validateBody.js +4 -32
  104. package/src/lib/middleware/validateBody.js.map +1 -1
  105. package/src/lib/middlewares.d.ts.map +1 -1
  106. package/src/lib/middlewares.js +7 -1
  107. package/src/lib/middlewares.js.map +1 -1
  108. package/src/lib/plugins/brightchain-database-plugin.d.ts +27 -79
  109. package/src/lib/plugins/brightchain-database-plugin.d.ts.map +1 -1
  110. package/src/lib/plugins/brightchain-database-plugin.js +27 -97
  111. package/src/lib/plugins/brightchain-database-plugin.js.map +1 -1
  112. package/src/lib/routers/api.d.ts +18 -1
  113. package/src/lib/routers/api.d.ts.map +1 -1
  114. package/src/lib/routers/api.js +24 -1
  115. package/src/lib/routers/api.js.map +1 -1
  116. package/src/lib/routers/app.d.ts.map +1 -1
  117. package/src/lib/routers/app.js +5 -2
  118. package/src/lib/routers/app.js.map +1 -1
  119. package/src/lib/services/auth.d.ts.map +1 -1
  120. package/src/lib/services/auth.js +37 -3
  121. package/src/lib/services/auth.js.map +1 -1
  122. package/src/lib/services/blockStore.d.ts +8 -1
  123. package/src/lib/services/blockStore.d.ts.map +1 -1
  124. package/src/lib/services/blockStore.js +19 -7
  125. package/src/lib/services/blockStore.js.map +1 -1
  126. package/src/lib/services/brightChainBackupCodeService.d.ts +42 -39
  127. package/src/lib/services/brightChainBackupCodeService.d.ts.map +1 -1
  128. package/src/lib/services/brightChainBackupCodeService.js +86 -61
  129. package/src/lib/services/brightChainBackupCodeService.js.map +1 -1
  130. package/src/lib/services/brighthub/collectionAdapter.d.ts +81 -0
  131. package/src/lib/services/brighthub/collectionAdapter.d.ts.map +1 -0
  132. package/src/lib/services/brighthub/collectionAdapter.js +127 -0
  133. package/src/lib/services/brighthub/collectionAdapter.js.map +1 -0
  134. package/src/lib/services/brighthub/connectionService.d.ts.map +1 -1
  135. package/src/lib/services/brighthub/connectionService.js +3 -0
  136. package/src/lib/services/brighthub/connectionService.js.map +1 -1
  137. package/src/lib/services/brighthub/messagingService.d.ts +4 -0
  138. package/src/lib/services/brighthub/messagingService.d.ts.map +1 -1
  139. package/src/lib/services/brighthub/messagingService.js +25 -4
  140. package/src/lib/services/brighthub/messagingService.js.map +1 -1
  141. package/src/lib/services/brighthub/notificationService.d.ts.map +1 -1
  142. package/src/lib/services/brighthub/notificationService.js +35 -20
  143. package/src/lib/services/brighthub/notificationService.js.map +1 -1
  144. package/src/lib/services/brighthub/postService.d.ts +7 -1
  145. package/src/lib/services/brighthub/postService.d.ts.map +1 -1
  146. package/src/lib/services/brighthub/postService.js +22 -1
  147. package/src/lib/services/brighthub/postService.js.map +1 -1
  148. package/src/lib/services/brighthub/userProfileService.d.ts +19 -1
  149. package/src/lib/services/brighthub/userProfileService.d.ts.map +1 -1
  150. package/src/lib/services/brighthub/userProfileService.js +74 -0
  151. package/src/lib/services/brighthub/userProfileService.js.map +1 -1
  152. package/src/lib/services/emailGateway/antiSpamFilter.d.ts +229 -0
  153. package/src/lib/services/emailGateway/antiSpamFilter.d.ts.map +1 -0
  154. package/src/lib/services/emailGateway/antiSpamFilter.js +325 -0
  155. package/src/lib/services/emailGateway/antiSpamFilter.js.map +1 -0
  156. package/src/lib/services/emailGateway/bounceProcessor.d.ts +171 -0
  157. package/src/lib/services/emailGateway/bounceProcessor.d.ts.map +1 -0
  158. package/src/lib/services/emailGateway/bounceProcessor.js +378 -0
  159. package/src/lib/services/emailGateway/bounceProcessor.js.map +1 -0
  160. package/src/lib/services/emailGateway/emailAuthVerifier.d.ts +99 -0
  161. package/src/lib/services/emailGateway/emailAuthVerifier.d.ts.map +1 -0
  162. package/src/lib/services/emailGateway/emailAuthVerifier.js +202 -0
  163. package/src/lib/services/emailGateway/emailAuthVerifier.js.map +1 -0
  164. package/src/lib/services/emailGateway/emailGatewayConfig.d.ts +73 -0
  165. package/src/lib/services/emailGateway/emailGatewayConfig.d.ts.map +1 -0
  166. package/src/lib/services/emailGateway/emailGatewayConfig.js +107 -0
  167. package/src/lib/services/emailGateway/emailGatewayConfig.js.map +1 -0
  168. package/src/lib/services/emailGateway/emailGatewayService.d.ts +152 -0
  169. package/src/lib/services/emailGateway/emailGatewayService.d.ts.map +1 -0
  170. package/src/lib/services/emailGateway/emailGatewayService.js +201 -0
  171. package/src/lib/services/emailGateway/emailGatewayService.js.map +1 -0
  172. package/src/lib/services/emailGateway/gatewayObservability.d.ts +123 -0
  173. package/src/lib/services/emailGateway/gatewayObservability.d.ts.map +1 -0
  174. package/src/lib/services/emailGateway/gatewayObservability.js +186 -0
  175. package/src/lib/services/emailGateway/gatewayObservability.js.map +1 -0
  176. package/src/lib/services/emailGateway/inboundProcessor.d.ts +113 -0
  177. package/src/lib/services/emailGateway/inboundProcessor.d.ts.map +1 -0
  178. package/src/lib/services/emailGateway/inboundProcessor.js +298 -0
  179. package/src/lib/services/emailGateway/inboundProcessor.js.map +1 -0
  180. package/src/lib/services/emailGateway/index.d.ts +23 -0
  181. package/src/lib/services/emailGateway/index.d.ts.map +1 -0
  182. package/src/lib/services/emailGateway/index.js +26 -0
  183. package/src/lib/services/emailGateway/index.js.map +1 -0
  184. package/src/lib/services/emailGateway/outboundDeliveryWorker.d.ts +111 -0
  185. package/src/lib/services/emailGateway/outboundDeliveryWorker.d.ts.map +1 -0
  186. package/src/lib/services/emailGateway/outboundDeliveryWorker.js +97 -0
  187. package/src/lib/services/emailGateway/outboundDeliveryWorker.js.map +1 -0
  188. package/src/lib/services/emailGateway/outboundQueue.d.ts +135 -0
  189. package/src/lib/services/emailGateway/outboundQueue.d.ts.map +1 -0
  190. package/src/lib/services/emailGateway/outboundQueue.js +227 -0
  191. package/src/lib/services/emailGateway/outboundQueue.js.map +1 -0
  192. package/src/lib/services/emailGateway/outboundQueueStore.d.ts +110 -0
  193. package/src/lib/services/emailGateway/outboundQueueStore.d.ts.map +1 -0
  194. package/src/lib/services/emailGateway/outboundQueueStore.js +131 -0
  195. package/src/lib/services/emailGateway/outboundQueueStore.js.map +1 -0
  196. package/src/lib/services/emailGateway/recipientLookupService.d.ts +135 -0
  197. package/src/lib/services/emailGateway/recipientLookupService.d.ts.map +1 -0
  198. package/src/lib/services/emailGateway/recipientLookupService.js +294 -0
  199. package/src/lib/services/emailGateway/recipientLookupService.js.map +1 -0
  200. package/src/lib/services/emailGateway/retryBackoff.d.ts +79 -0
  201. package/src/lib/services/emailGateway/retryBackoff.d.ts.map +1 -0
  202. package/src/lib/services/emailGateway/retryBackoff.js +77 -0
  203. package/src/lib/services/emailGateway/retryBackoff.js.map +1 -0
  204. package/src/lib/services/eventNotificationSystem.d.ts.map +1 -1
  205. package/src/lib/services/eventNotificationSystem.js.map +1 -1
  206. package/src/lib/services/index.d.ts +2 -1
  207. package/src/lib/services/index.d.ts.map +1 -1
  208. package/src/lib/services/index.js +2 -1
  209. package/src/lib/services/index.js.map +1 -1
  210. package/src/lib/services/quorumDatabaseAdapter.d.ts +7 -1
  211. package/src/lib/services/quorumDatabaseAdapter.d.ts.map +1 -1
  212. package/src/lib/services/quorumDatabaseAdapter.js +83 -0
  213. package/src/lib/services/quorumDatabaseAdapter.js.map +1 -1
  214. package/src/lib/services/sessionAdapter.d.ts +2 -61
  215. package/src/lib/services/sessionAdapter.d.ts.map +1 -1
  216. package/src/lib/services/sessionAdapter.js +2 -102
  217. package/src/lib/services/sessionAdapter.js.map +1 -1
  218. package/src/lib/shared-types.d.ts +7 -15
  219. package/src/lib/shared-types.d.ts.map +1 -1
  220. package/src/lib/stores/availabilityAwareBlockStore.d.ts +4 -3
  221. package/src/lib/stores/availabilityAwareBlockStore.d.ts.map +1 -1
  222. package/src/lib/stores/availabilityAwareBlockStore.js +5 -2
  223. package/src/lib/stores/availabilityAwareBlockStore.js.map +1 -1
  224. package/src/lib/stores/cloudBlockStoreBase.d.ts +2 -1
  225. package/src/lib/stores/cloudBlockStoreBase.d.ts.map +1 -1
  226. package/src/lib/stores/cloudBlockStoreBase.js +34 -13
  227. package/src/lib/stores/cloudBlockStoreBase.js.map +1 -1
  228. package/src/lib/stores/diskBlockAsyncStore.d.ts +21 -1
  229. package/src/lib/stores/diskBlockAsyncStore.d.ts.map +1 -1
  230. package/src/lib/stores/diskBlockAsyncStore.js +48 -17
  231. package/src/lib/stores/diskBlockAsyncStore.js.map +1 -1
  232. package/src/lib/stores/diskBlockStore.d.ts +10 -2
  233. package/src/lib/stores/diskBlockStore.d.ts.map +1 -1
  234. package/src/lib/stores/diskBlockStore.js +43 -19
  235. package/src/lib/stores/diskBlockStore.js.map +1 -1
  236. package/src/lib/types/backend-id.d.ts +1 -2
  237. package/src/lib/types/backend-id.d.ts.map +1 -1
  238. package/src/lib/utils/emailValidation.d.ts.map +1 -1
  239. package/src/lib/utils/emailValidation.js +2 -1
  240. package/src/lib/utils/emailValidation.js.map +1 -1
  241. package/src/lib/validation/userValidation.d.ts +2 -43
  242. package/src/lib/validation/userValidation.d.ts.map +1 -1
  243. package/src/lib/validation/userValidation.js +6 -144
  244. package/src/lib/validation/userValidation.js.map +1 -1
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /**
3
+ * ACL Document Store - stores and retrieves Write ACL documents as signed blocks.
4
+ *
5
+ * Follows the PoolACLStore pattern: each ACL document is serialized to JSON
6
+ * (without creatorSignature), signed with the admin's ECDSA key, and stored
7
+ * as a block. On retrieval, the signature is verified against the signer's
8
+ * public key before the document is returned.
9
+ *
10
+ * Version chaining: each update references the previous ACL block ID via
11
+ * `previousVersionBlockId`, forming an auditable linked list.
12
+ *
13
+ * @see Requirements 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.AclDocumentStore = void 0;
17
+ const tslib_1 = require("tslib");
18
+ const brightchain_lib_1 = require("@brightchain/brightchain-lib");
19
+ const crypto = tslib_1.__importStar(require("crypto"));
20
+ const ecdsaNodeAuthenticator_1 = require("./ecdsaNodeAuthenticator");
21
+ /**
22
+ * Stores and retrieves Write ACL documents as signed blocks.
23
+ *
24
+ * Uses an in-memory Map for block storage, following the PoolACLStore
25
+ * pattern. Block IDs are SHA-256 hashes of the stored content.
26
+ *
27
+ * @see Requirements 2.1, 2.2, 2.3, 2.4, 2.5, 2.6
28
+ */
29
+ class AclDocumentStore {
30
+ blocks = new Map();
31
+ authenticator;
32
+ constructor(authenticator) {
33
+ this.authenticator = authenticator ?? new ecdsaNodeAuthenticator_1.ECDSANodeAuthenticator();
34
+ }
35
+ /**
36
+ * Serialize an ACL document to JSON, sign it, and store as a block.
37
+ * Returns the block ID (SHA-256 hex of the stored content).
38
+ *
39
+ * The document is serialized using the shared serializeAclDocument helper
40
+ * (which handles Date → ISO string and Uint8Array → hex encoding).
41
+ * The creatorSignature field is excluded from the signed payload;
42
+ * the signature is stored separately in the SignedAclDocumentBlock envelope.
43
+ *
44
+ * @param doc - The ACL document to store (creatorSignature is ignored; a fresh signature is computed)
45
+ * @param signerPrivateKey - The admin's raw 32-byte secp256k1 private key
46
+ * @returns The block ID (SHA-256 hex digest)
47
+ * @see Requirements 2.1, 2.2, 2.3
48
+ */
49
+ async storeAclDocument(doc, signerPrivateKey) {
50
+ // Serialize the document (the serialization includes creatorSignature,
51
+ // but we strip it for signing to match the PoolACLStore pattern)
52
+ const docForSigning = {
53
+ ...doc,
54
+ creatorSignature: new Uint8Array(0), // zero-length placeholder for signing
55
+ };
56
+ const aclJson = (0, brightchain_lib_1.serializeAclDocument)(docForSigning);
57
+ const aclBytes = new TextEncoder().encode(aclJson);
58
+ // Sign the serialized JSON
59
+ const signature = await this.authenticator.signChallenge(aclBytes, signerPrivateKey);
60
+ // Derive the signer's public key
61
+ const ecdh = crypto.createECDH('secp256k1');
62
+ ecdh.setPrivateKey(Buffer.from(signerPrivateKey));
63
+ const publicKey = new Uint8Array(ecdh.getPublicKey());
64
+ const publicKeyHex = Buffer.from(publicKey).toString('hex');
65
+ const signedBlock = {
66
+ aclJson,
67
+ signatures: [
68
+ {
69
+ publicKeyHex,
70
+ signature: Buffer.from(signature).toString('hex'),
71
+ },
72
+ ],
73
+ };
74
+ const blockBytes = new TextEncoder().encode(JSON.stringify(signedBlock));
75
+ const blockId = this.computeBlockId(blockBytes);
76
+ this.blocks.set(blockId, blockBytes);
77
+ return blockId;
78
+ }
79
+ /**
80
+ * Load an ACL document from a stored block, verifying the signature.
81
+ * Throws if the block doesn't exist or the signature is invalid.
82
+ *
83
+ * @param blockId - The block ID to load
84
+ * @returns The deserialized and verified ACL document
85
+ * @throws AclSignatureVerificationError if signature verification fails
86
+ * @see Requirements 2.3, 2.4
87
+ */
88
+ async loadAclDocument(blockId) {
89
+ const blockBytes = this.blocks.get(blockId);
90
+ if (!blockBytes) {
91
+ throw new Error(`ACL document block not found: ${blockId}`);
92
+ }
93
+ const signedBlock = JSON.parse(new TextDecoder().decode(blockBytes));
94
+ if (signedBlock.signatures.length === 0) {
95
+ throw new brightchain_lib_1.AclSignatureVerificationError(blockId, 'ACL document block has no signatures');
96
+ }
97
+ // Verify the first signature
98
+ const firstSig = signedBlock.signatures[0];
99
+ const publicKey = new Uint8Array(Buffer.from(firstSig.publicKeyHex, 'hex'));
100
+ const signatureBytes = new Uint8Array(Buffer.from(firstSig.signature, 'hex'));
101
+ const aclBytes = new TextEncoder().encode(signedBlock.aclJson);
102
+ const isValid = await this.authenticator.verifySignature(aclBytes, signatureBytes, publicKey);
103
+ if (!isValid) {
104
+ throw new brightchain_lib_1.AclSignatureVerificationError(blockId, 'Signature verification failed');
105
+ }
106
+ // Deserialize the ACL document
107
+ const doc = (0, brightchain_lib_1.deserializeAclDocument)(signedBlock.aclJson);
108
+ // Attach the verified signature as the creatorSignature
109
+ doc.creatorSignature = signatureBytes;
110
+ return doc;
111
+ }
112
+ /**
113
+ * Update an ACL document: validates version increment, sets
114
+ * previousVersionBlockId to the current block ID, and stores
115
+ * the new version.
116
+ *
117
+ * @param currentBlockId - The block ID of the current ACL document
118
+ * @param updatedDoc - The updated ACL document
119
+ * @param signerPrivateKey - The admin's raw 32-byte secp256k1 private key
120
+ * @returns The new block ID
121
+ * @throws AclVersionConflictError if version is not strictly greater
122
+ * @see Requirements 2.5, 2.6
123
+ */
124
+ async updateAclDocument(currentBlockId, updatedDoc, signerPrivateKey) {
125
+ // Load and verify the current document
126
+ const currentDoc = await this.loadAclDocument(currentBlockId);
127
+ // Validate version increment (must be strictly greater)
128
+ if (updatedDoc.version <= currentDoc.version) {
129
+ throw new brightchain_lib_1.AclVersionConflictError(currentDoc.version, updatedDoc.version, updatedDoc.scope.dbName, updatedDoc.scope.collectionName);
130
+ }
131
+ // Set chain reference to the current block
132
+ const chainedDoc = {
133
+ ...updatedDoc,
134
+ previousVersionBlockId: currentBlockId,
135
+ };
136
+ return this.storeAclDocument(chainedDoc, signerPrivateKey);
137
+ }
138
+ /**
139
+ * Check whether a block exists in the store.
140
+ */
141
+ hasBlock(blockId) {
142
+ return this.blocks.has(blockId);
143
+ }
144
+ /**
145
+ * Compute a block ID as the SHA-256 hex digest of the content.
146
+ */
147
+ computeBlockId(content) {
148
+ return crypto
149
+ .createHash('sha256')
150
+ .update(Buffer.from(content))
151
+ .digest('hex');
152
+ }
153
+ }
154
+ exports.AclDocumentStore = AclDocumentStore;
155
+ //# sourceMappingURL=aclDocumentStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aclDocumentStore.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/aclDocumentStore.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;AAEH,kEAMsC;AACtC,uDAAiC;AAEjC,qEAAkE;AAelE;;;;;;;GAOG;AACH,MAAa,gBAAgB;IACR,MAAM,GAAG,IAAI,GAAG,EAAsB,CAAC;IACzC,aAAa,CAAyB;IAEvD,YAAY,aAAsC;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,IAAI,+CAAsB,EAAE,CAAC;IACrE,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,gB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wD;QACxD,GAAG,CAAC,gBAAgB,GAAG,cAAc,CAAC;QAEtC,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,iBAAiB,CACrB,cAAsB,EACtB,UAAwB,EACxB,gBAA4B;QAE5B,uCAAuC;QACvC,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;QAE9D,wDAAwD;QACxD,IAAI,UAAU,CAAC,OAAO,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YAC7C,MAAM,IAAI,yCAAuB,CAC/B,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,OAAO,EAClB,UAAU,CAAC,KAAK,CAAC,MAAM,EACvB,UAAU,CAAC,KAAK,CAAC,cAAc,CAChC,CAAC;QACJ,CAAC;QAED,2CAA2C;QAC3C,MAAM,UAAU,GAAiB;YAC/B,GAAG,UAAU;YACb,sBAAsB,EAAE,cAAc;SACvC,CAAC;QAEF,OAAO,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,OAAe;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,OAAmB;QACxC,OAAO,MAAM;aACV,UAAU,CAAC,QAAQ,CAAC;aACpB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aAC5B,MAAM,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC;CACF;AA/KD,4CA+KC"}
@@ -1,7 +1,11 @@
1
+ export * from './aclDocumentStore';
1
2
  export * from './aclEnforcedAvailability';
2
3
  export * from './aclEnforcedBlockStore';
3
4
  export * from './ecdsaNodeAuthenticator';
4
5
  export * from './poolAclBootstrap';
5
6
  export * from './poolAclStore';
6
7
  export { InsufficientQuorumError, PoolACLUpdater, type ACLUpdateProposal, } from './poolAclUpdater';
8
+ export * from './writeAclApiRouter';
9
+ export * from './writeAclAuditLogger';
10
+ export * from './writeProofMiddleware';
7
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,KAAK,iBAAiB,GACvB,MAAM,kBAAkB,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,wBAAwB,CAAC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PoolACLUpdater = exports.InsufficientQuorumError = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./aclDocumentStore"), exports);
5
6
  tslib_1.__exportStar(require("./aclEnforcedAvailability"), exports);
6
7
  tslib_1.__exportStar(require("./aclEnforcedBlockStore"), exports);
7
8
  tslib_1.__exportStar(require("./ecdsaNodeAuthenticator"), exports);
@@ -10,4 +11,7 @@ tslib_1.__exportStar(require("./poolAclStore"), exports);
10
11
  var poolAclUpdater_1 = require("./poolAclUpdater");
11
12
  Object.defineProperty(exports, "InsufficientQuorumError", { enumerable: true, get: function () { return poolAclUpdater_1.InsufficientQuorumError; } });
12
13
  Object.defineProperty(exports, "PoolACLUpdater", { enumerable: true, get: function () { return poolAclUpdater_1.PoolACLUpdater; } });
14
+ tslib_1.__exportStar(require("./writeAclApiRouter"), exports);
15
+ tslib_1.__exportStar(require("./writeAclAuditLogger"), exports);
16
+ tslib_1.__exportStar(require("./writeProofMiddleware"), exports);
13
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/index.ts"],"names":[],"mappings":";;;;AAAA,oEAA0C;AAC1C,kEAAwC;AACxC,mEAAyC;AACzC,6DAAmC;AACnC,yDAA+B;AAC/B,mDAI0B;AAHxB,yHAAA,uBAAuB,OAAA;AACvB,gHAAA,cAAc,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/index.ts"],"names":[],"mappings":";;;;AAAA,6DAAmC;AACnC,oEAA0C;AAC1C,kEAAwC;AACxC,mEAAyC;AACzC,6DAAmC;AACnC,yDAA+B;AAC/B,mDAI0B;AAHxB,yHAAA,uBAAuB,OAAA;AACvB,gHAAA,cAAc,OAAA;AAGhB,8DAAoC;AACpC,gEAAsC;AACtC,iEAAuC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @fileoverview WriteAclApiRouter - Express router for Write ACL management endpoints.
3
+ *
4
+ * Provides REST API endpoints for managing Write ACLs, mounted alongside
5
+ * the existing `createDbRouter`. All mutating endpoints require
6
+ * `X-Acl-Admin-Signature` (hex-encoded ECDSA signature) and
7
+ * `X-Acl-Admin-PublicKey` headers from an ACL administrator.
8
+ *
9
+ * @see BrightDB Write ACLs design, WriteAclApiRouter section
10
+ * @see Requirements 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
11
+ */
12
+ import type { IAclDocument, ICapabilityToken, IWriteAclAuditLogger, IWriteAclService } from '@brightchain/brightchain-lib';
13
+ import { Router } from 'express';
14
+ /**
15
+ * Interface for the ACL manager operations needed by the router.
16
+ * Extends IWriteAclService with mutation methods.
17
+ */
18
+ export interface IWriteAclApiManager extends IWriteAclService {
19
+ setAcl(aclDoc: IAclDocument, adminSignature: Uint8Array, adminPublicKey: Uint8Array): Promise<string>;
20
+ addWriter(dbName: string, collectionName: string | undefined, writerPublicKey: Uint8Array, adminSignature: Uint8Array, adminPublicKey: Uint8Array): Promise<string>;
21
+ removeWriter(dbName: string, collectionName: string | undefined, writerPublicKey: Uint8Array, adminSignature: Uint8Array, adminPublicKey: Uint8Array): Promise<string>;
22
+ issueCapabilityToken(token: ICapabilityToken, adminSignature: Uint8Array): Promise<ICapabilityToken>;
23
+ }
24
+ /**
25
+ * Factory function that creates an Express router for Write ACL management.
26
+ *
27
+ * @param aclManager - The WriteAclManager (or any IWriteAclApiManager) to delegate to
28
+ * @param auditLogger - Optional WriteAclAuditLogger for logging ACL events
29
+ * @returns An Express Router with ACL management endpoints
30
+ */
31
+ export declare function createWriteAclApiRouter(aclManager: IWriteAclApiManager, auditLogger?: IWriteAclAuditLogger): Router;
32
+ //# sourceMappingURL=writeAclApiRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeAclApiRouter.d.ts","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/writeAclApiRouter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAqB,MAAM,EAAE,MAAM,SAAS,CAAC;AAEpD;;;GAGG;AACH,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,MAAM,CACJ,MAAM,EAAE,YAAY,EACpB,cAAc,EAAE,UAAU,EAC1B,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,SAAS,CACP,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,eAAe,EAAE,UAAU,EAC3B,cAAc,EAAE,UAAU,EAC1B,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,YAAY,CACV,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,eAAe,EAAE,UAAU,EAC3B,cAAc,EAAE,UAAU,EAC1B,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,MAAM,CAAC,CAAC;IACnB,oBAAoB,CAClB,KAAK,EAAE,gBAAgB,EACvB,cAAc,EAAE,UAAU,GACzB,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9B;AAyCD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,mBAAmB,EAC/B,WAAW,CAAC,EAAE,oBAAoB,GACjC,MAAM,CA2WR"}
@@ -0,0 +1,348 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview WriteAclApiRouter - Express router for Write ACL management endpoints.
4
+ *
5
+ * Provides REST API endpoints for managing Write ACLs, mounted alongside
6
+ * the existing `createDbRouter`. All mutating endpoints require
7
+ * `X-Acl-Admin-Signature` (hex-encoded ECDSA signature) and
8
+ * `X-Acl-Admin-PublicKey` headers from an ACL administrator.
9
+ *
10
+ * @see BrightDB Write ACLs design, WriteAclApiRouter section
11
+ * @see Requirements 9.1, 9.2, 9.3, 9.4, 9.5, 9.6
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.createWriteAclApiRouter = createWriteAclApiRouter;
15
+ const express_1 = require("express");
16
+ /**
17
+ * Extract and validate admin credentials from request headers.
18
+ * Returns the admin signature and public key as Uint8Arrays, or
19
+ * sends HTTP 403 and returns undefined.
20
+ */
21
+ function extractAdminCredentials(req, res) {
22
+ const signatureHex = req.headers['x-acl-admin-signature'];
23
+ const publicKeyHex = req.headers['x-acl-admin-publickey'];
24
+ if (!signatureHex || !publicKeyHex) {
25
+ res.status(403).json({
26
+ error: 'Missing admin credentials',
27
+ message: 'X-Acl-Admin-Signature and X-Acl-Admin-PublicKey headers are required for this operation',
28
+ });
29
+ return undefined;
30
+ }
31
+ try {
32
+ const adminSignature = Uint8Array.from(Buffer.from(signatureHex, 'hex'));
33
+ const adminPublicKey = Uint8Array.from(Buffer.from(publicKeyHex, 'hex'));
34
+ return { adminSignature, adminPublicKey };
35
+ }
36
+ catch {
37
+ res.status(403).json({
38
+ error: 'Invalid admin credentials',
39
+ message: 'X-Acl-Admin-Signature and X-Acl-Admin-PublicKey must be valid hex-encoded values',
40
+ });
41
+ return undefined;
42
+ }
43
+ }
44
+ /**
45
+ * Factory function that creates an Express router for Write ACL management.
46
+ *
47
+ * @param aclManager - The WriteAclManager (or any IWriteAclApiManager) to delegate to
48
+ * @param auditLogger - Optional WriteAclAuditLogger for logging ACL events
49
+ * @returns An Express Router with ACL management endpoints
50
+ */
51
+ function createWriteAclApiRouter(aclManager, auditLogger) {
52
+ const router = (0, express_1.Router)();
53
+ // ─── GET endpoints: Retrieve current Write_ACL ──────────────────────
54
+ /** GET /acl/:dbName — Get database-level Write_ACL. @see Requirement 9.1 */
55
+ router.get('/acl/:dbName', (req, res) => {
56
+ try {
57
+ const dbName = req.params['dbName'];
58
+ const aclDoc = aclManager.getAclDocument(dbName);
59
+ if (!aclDoc) {
60
+ res.status(404).json({
61
+ error: 'ACL not found',
62
+ message: `No Write_ACL configured for database "${dbName}"`,
63
+ });
64
+ return;
65
+ }
66
+ res.json(serializeAclForResponse(aclDoc));
67
+ }
68
+ catch (error) {
69
+ res.status(500).json({ error: error.message });
70
+ }
71
+ });
72
+ /** GET /acl/:dbName/:collectionName — Get collection-level Write_ACL. @see Requirement 9.1 */
73
+ router.get('/acl/:dbName/:collectionName', (req, res) => {
74
+ try {
75
+ const dbName = req.params['dbName'];
76
+ const collectionName = req.params['collectionName'];
77
+ const aclDoc = aclManager.getAclDocument(dbName, collectionName);
78
+ if (!aclDoc) {
79
+ res.status(404).json({
80
+ error: 'ACL not found',
81
+ message: `No Write_ACL configured for "${dbName}/${collectionName}"`,
82
+ });
83
+ return;
84
+ }
85
+ res.json(serializeAclForResponse(aclDoc));
86
+ }
87
+ catch (error) {
88
+ res.status(500).json({ error: error.message });
89
+ }
90
+ });
91
+ // ─── PUT endpoints: Set/update Write_ACL ────────────────────────────
92
+ /** PUT /acl/:dbName — Set/update database-level Write_ACL. @see Requirements 9.2, 9.6 */
93
+ router.put('/acl/:dbName', async (req, res) => {
94
+ const credentials = extractAdminCredentials(req, res);
95
+ if (!credentials)
96
+ return;
97
+ try {
98
+ const dbName = req.params['dbName'];
99
+ const aclDoc = parseAclFromRequest(req.body, dbName);
100
+ const key = await aclManager.setAcl(aclDoc, credentials.adminSignature, credentials.adminPublicKey);
101
+ if (auditLogger) {
102
+ auditLogger.logAclModification(Buffer.from(credentials.adminPublicKey).toString('hex'), 'setAcl', 'database', dbName);
103
+ }
104
+ res.json({ success: true, key });
105
+ }
106
+ catch (error) {
107
+ handleAclError(error, res);
108
+ }
109
+ });
110
+ /** PUT /acl/:dbName/:collectionName — Set/update collection-level Write_ACL. @see Requirements 9.2, 9.6 */
111
+ router.put('/acl/:dbName/:collectionName', async (req, res) => {
112
+ const credentials = extractAdminCredentials(req, res);
113
+ if (!credentials)
114
+ return;
115
+ try {
116
+ const dbName = req.params['dbName'];
117
+ const collectionName = req.params['collectionName'];
118
+ const aclDoc = parseAclFromRequest(req.body, dbName, collectionName);
119
+ const key = await aclManager.setAcl(aclDoc, credentials.adminSignature, credentials.adminPublicKey);
120
+ if (auditLogger) {
121
+ auditLogger.logAclModification(Buffer.from(credentials.adminPublicKey).toString('hex'), 'setAcl', 'collection', dbName, collectionName);
122
+ }
123
+ res.json({ success: true, key });
124
+ }
125
+ catch (error) {
126
+ handleAclError(error, res);
127
+ }
128
+ });
129
+ // ─── POST endpoints: Add authorized writer ──────────────────────────
130
+ /** POST /acl/:dbName/writers — Add an Authorized_Writer (database). @see Requirements 9.3, 9.6 */
131
+ router.post('/acl/:dbName/writers', async (req, res) => {
132
+ const credentials = extractAdminCredentials(req, res);
133
+ if (!credentials)
134
+ return;
135
+ try {
136
+ const dbName = req.params['dbName'];
137
+ const writerPublicKeyHex = req.body?.publicKeyHex;
138
+ if (!writerPublicKeyHex) {
139
+ res
140
+ .status(400)
141
+ .json({ error: 'Missing publicKeyHex in request body' });
142
+ return;
143
+ }
144
+ const writerPublicKey = Uint8Array.from(Buffer.from(writerPublicKeyHex, 'hex'));
145
+ const key = await aclManager.addWriter(dbName, undefined, writerPublicKey, credentials.adminSignature, credentials.adminPublicKey);
146
+ if (auditLogger) {
147
+ auditLogger.logAclModification(Buffer.from(credentials.adminPublicKey).toString('hex'), 'addWriter', writerPublicKeyHex, dbName);
148
+ }
149
+ res.json({ success: true, key });
150
+ }
151
+ catch (error) {
152
+ handleAclError(error, res);
153
+ }
154
+ });
155
+ /** POST /acl/:dbName/:collectionName/writers — Add an Authorized_Writer (collection). @see Requirements 9.3, 9.6 */
156
+ router.post('/acl/:dbName/:collectionName/writers', async (req, res) => {
157
+ const credentials = extractAdminCredentials(req, res);
158
+ if (!credentials)
159
+ return;
160
+ try {
161
+ const dbName = req.params['dbName'];
162
+ const collectionName = req.params['collectionName'];
163
+ const writerPublicKeyHex = req.body?.publicKeyHex;
164
+ if (!writerPublicKeyHex) {
165
+ res
166
+ .status(400)
167
+ .json({ error: 'Missing publicKeyHex in request body' });
168
+ return;
169
+ }
170
+ const writerPublicKey = Uint8Array.from(Buffer.from(writerPublicKeyHex, 'hex'));
171
+ const key = await aclManager.addWriter(dbName, collectionName, writerPublicKey, credentials.adminSignature, credentials.adminPublicKey);
172
+ if (auditLogger) {
173
+ auditLogger.logAclModification(Buffer.from(credentials.adminPublicKey).toString('hex'), 'addWriter', writerPublicKeyHex, dbName, collectionName);
174
+ }
175
+ res.json({ success: true, key });
176
+ }
177
+ catch (error) {
178
+ handleAclError(error, res);
179
+ }
180
+ });
181
+ // ─── DELETE endpoints: Remove authorized writer ─────────────────────
182
+ /** DELETE /acl/:dbName/writers/:publicKeyHex — Remove an Authorized_Writer (database). @see Requirements 9.4, 9.6 */
183
+ router.delete('/acl/:dbName/writers/:publicKeyHex', async (req, res) => {
184
+ const credentials = extractAdminCredentials(req, res);
185
+ if (!credentials)
186
+ return;
187
+ try {
188
+ const dbName = req.params['dbName'];
189
+ const publicKeyHex = req.params['publicKeyHex'];
190
+ const writerPublicKey = Uint8Array.from(Buffer.from(publicKeyHex, 'hex'));
191
+ const key = await aclManager.removeWriter(dbName, undefined, writerPublicKey, credentials.adminSignature, credentials.adminPublicKey);
192
+ if (auditLogger) {
193
+ auditLogger.logAclModification(Buffer.from(credentials.adminPublicKey).toString('hex'), 'removeWriter', publicKeyHex, dbName);
194
+ }
195
+ res.json({ success: true, key });
196
+ }
197
+ catch (error) {
198
+ handleAclError(error, res);
199
+ }
200
+ });
201
+ /** DELETE /acl/:dbName/:collectionName/writers/:publicKeyHex — Remove an Authorized_Writer (collection). @see Requirements 9.4, 9.6 */
202
+ router.delete('/acl/:dbName/:collectionName/writers/:publicKeyHex', async (req, res) => {
203
+ const credentials = extractAdminCredentials(req, res);
204
+ if (!credentials)
205
+ return;
206
+ try {
207
+ const dbName = req.params['dbName'];
208
+ const collectionName = req.params['collectionName'];
209
+ const publicKeyHex = req.params['publicKeyHex'];
210
+ const writerPublicKey = Uint8Array.from(Buffer.from(publicKeyHex, 'hex'));
211
+ const key = await aclManager.removeWriter(dbName, collectionName, writerPublicKey, credentials.adminSignature, credentials.adminPublicKey);
212
+ if (auditLogger) {
213
+ auditLogger.logAclModification(Buffer.from(credentials.adminPublicKey).toString('hex'), 'removeWriter', publicKeyHex, dbName, collectionName);
214
+ }
215
+ res.json({ success: true, key });
216
+ }
217
+ catch (error) {
218
+ handleAclError(error, res);
219
+ }
220
+ });
221
+ // ─── POST endpoints: Issue capability token ─────────────────────────
222
+ /** POST /acl/:dbName/tokens — Issue a Capability_Token (database). @see Requirements 9.5, 9.6 */
223
+ router.post('/acl/:dbName/tokens', async (req, res) => {
224
+ const credentials = extractAdminCredentials(req, res);
225
+ if (!credentials)
226
+ return;
227
+ try {
228
+ const dbName = req.params['dbName'];
229
+ const token = parseCapabilityTokenFromRequest(req.body, dbName);
230
+ const issuedToken = await aclManager.issueCapabilityToken(token, credentials.adminSignature);
231
+ if (auditLogger) {
232
+ auditLogger.logCapabilityTokenIssued(Buffer.from(token.granteePublicKey).toString('hex'), token.scope, token.expiresAt, Buffer.from(credentials.adminPublicKey).toString('hex'));
233
+ }
234
+ res.json({
235
+ success: true,
236
+ token: serializeTokenForResponse(issuedToken),
237
+ });
238
+ }
239
+ catch (error) {
240
+ handleAclError(error, res);
241
+ }
242
+ });
243
+ /** POST /acl/:dbName/:collectionName/tokens — Issue a Capability_Token (collection). @see Requirements 9.5, 9.6 */
244
+ router.post('/acl/:dbName/:collectionName/tokens', async (req, res) => {
245
+ const credentials = extractAdminCredentials(req, res);
246
+ if (!credentials)
247
+ return;
248
+ try {
249
+ const dbName = req.params['dbName'];
250
+ const collectionName = req.params['collectionName'];
251
+ const token = parseCapabilityTokenFromRequest(req.body, dbName, collectionName);
252
+ const issuedToken = await aclManager.issueCapabilityToken(token, credentials.adminSignature);
253
+ if (auditLogger) {
254
+ auditLogger.logCapabilityTokenIssued(Buffer.from(token.granteePublicKey).toString('hex'), token.scope, token.expiresAt, Buffer.from(credentials.adminPublicKey).toString('hex'));
255
+ }
256
+ res.json({
257
+ success: true,
258
+ token: serializeTokenForResponse(issuedToken),
259
+ });
260
+ }
261
+ catch (error) {
262
+ handleAclError(error, res);
263
+ }
264
+ });
265
+ return router;
266
+ }
267
+ // ─── Helper functions ───────────────────────────────────────────────
268
+ /** Map known ACL error types to appropriate HTTP status codes. */
269
+ function handleAclError(error, res) {
270
+ const name = error.constructor.name;
271
+ if (name === 'AclAdminRequiredError' ||
272
+ name === 'CapabilityTokenInvalidError' ||
273
+ name === 'CapabilityTokenExpiredError' ||
274
+ name === 'AclSignatureVerificationError') {
275
+ res.status(403).json({ error: name, message: error.message });
276
+ return;
277
+ }
278
+ if (name === 'AclVersionConflictError') {
279
+ res.status(409).json({ error: name, message: error.message });
280
+ return;
281
+ }
282
+ if (name === 'LastAdministratorError' || name === 'WriterNotInPoolError') {
283
+ res.status(400).json({ error: name, message: error.message });
284
+ return;
285
+ }
286
+ res.status(500).json({ error: 'InternalError', message: error.message });
287
+ }
288
+ /** Parse an ACL document from a request body, injecting scope from URL params. */
289
+ function parseAclFromRequest(body, dbName, collectionName) {
290
+ return {
291
+ documentId: body['documentId'] ?? '',
292
+ writeMode: body['writeMode'],
293
+ authorizedWriters: (body['authorizedWriters'] ?? []).map((hex) => Uint8Array.from(Buffer.from(hex, 'hex'))),
294
+ aclAdministrators: (body['aclAdministrators'] ?? []).map((hex) => Uint8Array.from(Buffer.from(hex, 'hex'))),
295
+ scope: { dbName, collectionName },
296
+ version: body['version'] ?? 1,
297
+ createdAt: body['createdAt']
298
+ ? new Date(body['createdAt'])
299
+ : new Date(),
300
+ updatedAt: body['updatedAt']
301
+ ? new Date(body['updatedAt'])
302
+ : new Date(),
303
+ creatorPublicKey: body['creatorPublicKey']
304
+ ? Uint8Array.from(Buffer.from(body['creatorPublicKey'], 'hex'))
305
+ : new Uint8Array(0),
306
+ creatorSignature: body['creatorSignature']
307
+ ? Uint8Array.from(Buffer.from(body['creatorSignature'], 'hex'))
308
+ : new Uint8Array(0),
309
+ previousVersionBlockId: body['previousVersionBlockId'],
310
+ };
311
+ }
312
+ /** Parse a capability token from a request body, injecting scope from URL params. */
313
+ function parseCapabilityTokenFromRequest(body, dbName, collectionName) {
314
+ return {
315
+ granteePublicKey: Uint8Array.from(Buffer.from(body['granteePublicKey'] ?? '', 'hex')),
316
+ scope: { dbName, collectionName },
317
+ expiresAt: new Date(body['expiresAt'] ?? new Date().toISOString()),
318
+ grantorSignature: Uint8Array.from(Buffer.from(body['grantorSignature'] ?? '', 'hex')),
319
+ grantorPublicKey: Uint8Array.from(Buffer.from(body['grantorPublicKey'] ?? '', 'hex')),
320
+ };
321
+ }
322
+ /** Serialize an ACL document for JSON response (Uint8Array → hex strings). */
323
+ function serializeAclForResponse(aclDoc) {
324
+ return {
325
+ documentId: aclDoc.documentId,
326
+ writeMode: aclDoc.writeMode,
327
+ authorizedWriters: aclDoc.authorizedWriters.map((w) => Buffer.from(w).toString('hex')),
328
+ aclAdministrators: aclDoc.aclAdministrators.map((a) => Buffer.from(a).toString('hex')),
329
+ scope: aclDoc.scope,
330
+ version: aclDoc.version,
331
+ createdAt: aclDoc.createdAt.toISOString(),
332
+ updatedAt: aclDoc.updatedAt.toISOString(),
333
+ creatorPublicKey: Buffer.from(aclDoc.creatorPublicKey).toString('hex'),
334
+ creatorSignature: Buffer.from(aclDoc.creatorSignature).toString('hex'),
335
+ previousVersionBlockId: aclDoc.previousVersionBlockId,
336
+ };
337
+ }
338
+ /** Serialize a capability token for JSON response (Uint8Array → hex strings). */
339
+ function serializeTokenForResponse(token) {
340
+ return {
341
+ granteePublicKey: Buffer.from(token.granteePublicKey).toString('hex'),
342
+ scope: token.scope,
343
+ expiresAt: token.expiresAt.toISOString(),
344
+ grantorSignature: Buffer.from(token.grantorSignature).toString('hex'),
345
+ grantorPublicKey: Buffer.from(token.grantorPublicKey).toString('hex'),
346
+ };
347
+ }
348
+ //# sourceMappingURL=writeAclApiRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeAclApiRouter.js","sourceRoot":"","sources":["../../../../../brightchain-api-lib/src/lib/auth/writeAclApiRouter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAsFH,0DA8WC;AA5bD,qCAAoD;AAgCpD;;;;GAIG;AACH,SAAS,uBAAuB,CAC9B,GAAY,EACZ,GAAa;IAEb,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,uBAAuB,CAE3C,CAAC;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