@emilia-protocol/gate 0.14.0 → 0.15.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 (62) hide show
  1. package/CHANGELOG.md +60 -1
  2. package/README.md +32 -1
  3. package/aeb-consumption-store.js +3 -0
  4. package/dist/aeb-consumption-store.d.ts +88 -0
  5. package/dist/aeb-consumption-store.d.ts.map +1 -0
  6. package/dist/aeb-consumption-store.js +471 -0
  7. package/dist/aeb-consumption-store.js.map +1 -0
  8. package/dist/capability-receipt.d.ts +8 -0
  9. package/dist/capability-receipt.d.ts.map +1 -1
  10. package/dist/capability-receipt.js +17 -0
  11. package/dist/capability-receipt.js.map +1 -1
  12. package/dist/index.d.ts +13 -3
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +16 -4
  15. package/dist/index.js.map +1 -1
  16. package/dist/proposal-to-effect-postgres.d.ts +144 -0
  17. package/dist/proposal-to-effect-postgres.d.ts.map +1 -0
  18. package/dist/proposal-to-effect-postgres.js +1578 -0
  19. package/dist/proposal-to-effect-postgres.js.map +1 -0
  20. package/dist/proposal-to-effect-status-head-store.d.ts +72 -0
  21. package/dist/proposal-to-effect-status-head-store.d.ts.map +1 -0
  22. package/dist/proposal-to-effect-status-head-store.js +355 -0
  23. package/dist/proposal-to-effect-status-head-store.js.map +1 -0
  24. package/dist/proposal-to-effect-status.d.ts +55 -0
  25. package/dist/proposal-to-effect-status.d.ts.map +1 -0
  26. package/dist/proposal-to-effect-status.js +294 -0
  27. package/dist/proposal-to-effect-status.js.map +1 -0
  28. package/dist/proposal-to-effect.d.ts +151 -3
  29. package/dist/proposal-to-effect.d.ts.map +1 -1
  30. package/dist/proposal-to-effect.js +589 -46
  31. package/dist/proposal-to-effect.js.map +1 -1
  32. package/dist/remedy-case-set-postgres.d.ts +73 -0
  33. package/dist/remedy-case-set-postgres.d.ts.map +1 -0
  34. package/dist/remedy-case-set-postgres.js +846 -0
  35. package/dist/remedy-case-set-postgres.js.map +1 -0
  36. package/dist/remedy-case-set.d.ts +53 -0
  37. package/dist/remedy-case-set.d.ts.map +1 -0
  38. package/dist/remedy-case-set.js +571 -0
  39. package/dist/remedy-case-set.js.map +1 -0
  40. package/dist/remedy-program-adapters.d.ts +137 -0
  41. package/dist/remedy-program-adapters.d.ts.map +1 -0
  42. package/dist/remedy-program-adapters.js +590 -0
  43. package/dist/remedy-program-adapters.js.map +1 -0
  44. package/dist/trust-program-revocation.js.map +1 -1
  45. package/package.json +283 -63
  46. package/proposal-to-effect-postgres.js +3 -0
  47. package/proposal-to-effect-status-head-store.js +2 -0
  48. package/proposal-to-effect-status.js +2 -0
  49. package/remedy-case-set-postgres.js +3 -0
  50. package/remedy-case-set.js +3 -0
  51. package/remedy-program-adapters.js +3 -0
  52. package/src/aeb-consumption-store.ts +568 -0
  53. package/src/capability-receipt.ts +17 -0
  54. package/src/index.ts +66 -3
  55. package/src/proposal-to-effect-postgres.ts +1833 -0
  56. package/src/proposal-to-effect-status-head-store.ts +449 -0
  57. package/src/proposal-to-effect-status.ts +388 -0
  58. package/src/proposal-to-effect.ts +755 -50
  59. package/src/remedy-case-set-postgres.ts +1008 -0
  60. package/src/remedy-case-set.ts +603 -0
  61. package/src/remedy-program-adapters.ts +657 -0
  62. package/src/trust-program-revocation.ts +1 -1
package/src/index.ts CHANGED
@@ -90,6 +90,7 @@ import {
90
90
  reconstructCapabilitySecret,
91
91
  createMemoryCapabilityStore,
92
92
  createPostgresCapabilityStore,
93
+ isSecureCapabilityStore,
93
94
  executeWithCapability,
94
95
  executeWithThreshold,
95
96
  reconcileCapabilityOperation,
@@ -224,6 +225,7 @@ export {
224
225
  reconstructCapabilitySecret,
225
226
  createMemoryCapabilityStore,
226
227
  createPostgresCapabilityStore,
228
+ isSecureCapabilityStore,
227
229
  executeWithCapability,
228
230
  executeWithThreshold,
229
231
  reconcileCapabilityOperation,
@@ -284,11 +286,62 @@ export {
284
286
  REMEDY_PROGRAM_POSTGRES_SQL,
285
287
  createRemedyProgramPostgresStore,
286
288
  } from './remedy-program-postgres.js';
289
+ export {
290
+ REMEDY_PROGRAM_EVIDENCE_VERSION,
291
+ REMEDY_PROGRAM_EVIDENCE_DOMAIN,
292
+ remedyProgramEvidenceDigest,
293
+ remedyProgramEvidenceSigningBytes,
294
+ createRemedyProgramAdapters,
295
+ } from './remedy-program-adapters.js';
296
+ export {
297
+ REMEDY_CASE_SET_VERSION,
298
+ createRemedyCaseSetCoordinator,
299
+ } from './remedy-case-set.js';
300
+ export {
301
+ REMEDY_CASE_SET_PG_STORE_VERSION,
302
+ REMEDY_CASE_SET_TABLE,
303
+ REMEDY_CASE_SET_EVENT_TABLE,
304
+ REMEDY_CASE_SET_MAX_STATE_BYTES,
305
+ REMEDY_CASE_SET_MAX_MANIFEST_BYTES,
306
+ REMEDY_CASE_SET_MAX_FORWARD_SKEW_MINUTES,
307
+ REMEDY_CASE_SET_POSTGRES_DDL,
308
+ REMEDY_CASE_SET_POSTGRES_SQL,
309
+ createRemedyCaseSetPostgresStore,
310
+ } from './remedy-case-set-postgres.js';
287
311
  export {
288
312
  PROPOSAL_TO_EFFECT_VERSION,
289
313
  proposalToEffectConsumptionNonce,
290
314
  createProposalToEffect,
291
315
  } from './proposal-to-effect.js';
316
+ export {
317
+ PROPOSAL_TO_EFFECT_STATUS_HEAD_STORE_VERSION,
318
+ PROPOSAL_TO_EFFECT_STATUS_HEAD_TABLE,
319
+ PROPOSAL_TO_EFFECT_STATUS_HEAD_SQL,
320
+ createProposalToEffectStatusVerifier,
321
+ createPostgresProposalToEffectStatusHeadStore,
322
+ } from './proposal-to-effect-status.js';
323
+ export type {
324
+ PostgresProposalToEffectStatusHeadStoreOptions,
325
+ ProposalToEffectStatusHeadAcceptance,
326
+ ProposalToEffectStatusHeadAcceptanceInput,
327
+ ProposalToEffectStatusHeadPgClient,
328
+ ProposalToEffectStatusHeadPgPool,
329
+ ProposalToEffectStatusHeadStore,
330
+ } from './proposal-to-effect-status.js';
331
+ export {
332
+ PROPOSAL_TO_EFFECT_POSTGRES_DDL,
333
+ PROPOSAL_TO_EFFECT_POSTGRES_SQL,
334
+ proposalToEffectAttemptDigest,
335
+ createProposalToEffectPostgresStore,
336
+ } from './proposal-to-effect-postgres.js';
337
+ export {
338
+ AEB_PG_CONSUMPTION_STORE_VERSION,
339
+ AEB_CONSUMPTION_OPERATION_TABLE,
340
+ AEB_CONSUMPTION_REPLAY_TABLE,
341
+ AEB_CONSUMPTION_DDL,
342
+ AEB_CONSUMPTION_SQL,
343
+ createPostgresAebDurableConsumptionStore,
344
+ } from './aeb-consumption-store.js';
292
345
  export const ASSURANCE_TIERS = ['software', 'class_a', 'quorum'];
293
346
  const TIER_RANK = { software: 0, class_a: 1, quorum: 2 };
294
347
  const CAPABILITY_FAILURE_STATUS = 409;
@@ -878,11 +931,13 @@ export function verifyBusinessAuthorization({ requirement, receipt, assurance, t
878
931
  * @param {object} [opts.store] durable, ownership-fenced, permanent consumption store
879
932
  * @param {object} [opts.capabilityStore] Marvel capability budget store. A
880
933
  * capability run reserves here before the effect and commits after it.
934
+ * Production stores must explicitly mark durable and reconciliation-capable
935
+ * custody and implement register/reserve/commit/reconcile operations.
881
936
  * @param {string[]} [opts.capabilityTrustedIssuerKeys] pinned capability
882
937
  * envelope issuer keys. Required when capabilityStore is configured.
883
938
  * @param {function|null} [opts.capabilityCaidResolver] relying-party-pinned resolver
884
939
  * for `urn:emilia:scope:caid-set-v1`. Missing resolver fails CAID scope closed.
885
- * @param {boolean} [opts.allowEphemeralStore=false] explicit test/demo opt-in for in-memory state
940
+ * @param {boolean} [opts.allowEphemeralStore=false] explicit test/demo opt-in for in-memory consumption or capability state
886
941
  * @param {object} [opts.log] evidence log (default in-memory, hash-chained)
887
942
  * @param {boolean} [opts.allowInlineKey=false] accept the receipt's own key (integrity, NOT trust)
888
943
  * @param {object} [opts.keyRegistry] a key registry (createKeyRegistry) for rotation + revocation;
@@ -960,8 +1015,15 @@ export function createGate({ manifest = null, trustedKeys = [], maxAgeSec = 900,
960
1015
  }
961
1016
  if (capabilityStore && (typeof capabilityStore.registerCapability !== 'function'
962
1017
  || typeof capabilityStore.reserveSpend !== 'function'
963
- || typeof capabilityStore.commitSpend !== 'function')) {
964
- throw new Error('EMILIA Gate capabilityStore must implement registerCapability(), reserveSpend(), and commitSpend()');
1018
+ || typeof capabilityStore.commitSpend !== 'function'
1019
+ || typeof capabilityStore.reconcileSpend !== 'function')) {
1020
+ throw new Error('EMILIA Gate capabilityStore must implement registerCapability(), reserveSpend(), commitSpend(), and reconcileSpend()');
1021
+ }
1022
+ if (capabilityStore && !allowEphemeralStore && !isSecureCapabilityStore(capabilityStore)) {
1023
+ throw new Error(
1024
+ 'EMILIA Gate capabilityStore must be durable and reconciliation-capable. '
1025
+ + 'Pass allowEphemeralStore:true only for an explicit test/demo gate.',
1026
+ );
965
1027
  }
966
1028
  if (capabilityStore && (!Array.isArray(capabilityTrustedIssuerKeys)
967
1029
  || capabilityTrustedIssuerKeys.length === 0
@@ -2114,6 +2176,7 @@ export default {
2114
2176
  reconstructCapabilitySecret,
2115
2177
  createMemoryCapabilityStore,
2116
2178
  createPostgresCapabilityStore,
2179
+ isSecureCapabilityStore,
2117
2180
  executeWithCapability,
2118
2181
  executeWithThreshold,
2119
2182
  reconcileCapabilityOperation,