@veridid/poe 0.0.0-stage → 1.0.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 (183) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +39 -2
  3. package/build/PoeApi.d.mts +150 -0
  4. package/build/PoeApi.d.mts.map +1 -0
  5. package/build/PoeApi.mjs +262 -0
  6. package/build/PoeApi.mjs.map +1 -0
  7. package/build/PoeEvents.d.mts +187 -0
  8. package/build/PoeEvents.d.mts.map +1 -0
  9. package/build/PoeEvents.mjs +28 -0
  10. package/build/PoeEvents.mjs.map +1 -0
  11. package/build/PoeModule.d.mts +61 -0
  12. package/build/PoeModule.d.mts.map +1 -0
  13. package/build/PoeModule.mjs +139 -0
  14. package/build/PoeModule.mjs.map +1 -0
  15. package/build/PoeModuleConfig.d.mts +71 -0
  16. package/build/PoeModuleConfig.d.mts.map +1 -0
  17. package/build/PoeRole.d.mts +21 -0
  18. package/build/PoeRole.d.mts.map +1 -0
  19. package/build/PoeRole.mjs +23 -0
  20. package/build/PoeRole.mjs.map +1 -0
  21. package/build/PoeState.d.mts +76 -0
  22. package/build/PoeState.d.mts.map +1 -0
  23. package/build/PoeState.mjs +78 -0
  24. package/build/PoeState.mjs.map +1 -0
  25. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs +10 -0
  26. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs +7 -0
  27. package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs +9 -0
  28. package/build/_virtual/_rolldown/runtime.mjs +8 -0
  29. package/build/errors/PoeError.d.mts +173 -0
  30. package/build/errors/PoeError.d.mts.map +1 -0
  31. package/build/errors/PoeError.mjs +147 -0
  32. package/build/errors/PoeError.mjs.map +1 -0
  33. package/build/errors/index.d.mts +1 -0
  34. package/build/errors/index.mjs +1 -0
  35. package/build/executor/ProgramExecutor.d.mts +148 -0
  36. package/build/executor/ProgramExecutor.d.mts.map +1 -0
  37. package/build/executor/ProgramExecutorRegistry.d.mts +111 -0
  38. package/build/executor/ProgramExecutorRegistry.d.mts.map +1 -0
  39. package/build/executor/ProgramExecutorRegistry.mjs +145 -0
  40. package/build/executor/ProgramExecutorRegistry.mjs.map +1 -0
  41. package/build/executor/__mocks__/MockProgramExecutor.d.mts +118 -0
  42. package/build/executor/__mocks__/MockProgramExecutor.d.mts.map +1 -0
  43. package/build/executor/__mocks__/MockProgramExecutor.mjs +96 -0
  44. package/build/executor/__mocks__/MockProgramExecutor.mjs.map +1 -0
  45. package/build/executor/__mocks__/MockProofVerifier.d.mts +97 -0
  46. package/build/executor/__mocks__/MockProofVerifier.d.mts.map +1 -0
  47. package/build/executor/__mocks__/MockProofVerifier.mjs +79 -0
  48. package/build/executor/__mocks__/MockProofVerifier.mjs.map +1 -0
  49. package/build/executor/__mocks__/index.d.mts +2 -0
  50. package/build/executor/index.d.mts +5 -0
  51. package/build/executor/index.mjs +3 -0
  52. package/build/handlers/AcceptPoeMessageHandler.mjs +24 -0
  53. package/build/handlers/AcceptPoeMessageHandler.mjs.map +1 -0
  54. package/build/handlers/ChallengeMessageHandler.mjs +24 -0
  55. package/build/handlers/ChallengeMessageHandler.mjs.map +1 -0
  56. package/build/handlers/CompleteMessageHandler.mjs +24 -0
  57. package/build/handlers/CompleteMessageHandler.mjs.map +1 -0
  58. package/build/handlers/DeclinePoeMessageHandler.mjs +24 -0
  59. package/build/handlers/DeclinePoeMessageHandler.mjs.map +1 -0
  60. package/build/handlers/PoeProblemReportMessageHandler.mjs +18 -0
  61. package/build/handlers/PoeProblemReportMessageHandler.mjs.map +1 -0
  62. package/build/handlers/ProposePoeMessageHandler.mjs +18 -0
  63. package/build/handlers/ProposePoeMessageHandler.mjs.map +1 -0
  64. package/build/handlers/RequestPoeMessageHandler.mjs +18 -0
  65. package/build/handlers/RequestPoeMessageHandler.mjs.map +1 -0
  66. package/build/handlers/SubmitPoeMessageHandler.mjs +18 -0
  67. package/build/handlers/SubmitPoeMessageHandler.mjs.map +1 -0
  68. package/build/handlers/index.mjs +8 -0
  69. package/build/index.d.mts +38 -0
  70. package/build/index.mjs +33 -0
  71. package/build/messages/AcceptPoeMessage.d.mts +48 -0
  72. package/build/messages/AcceptPoeMessage.d.mts.map +1 -0
  73. package/build/messages/AcceptPoeMessage.mjs +61 -0
  74. package/build/messages/AcceptPoeMessage.mjs.map +1 -0
  75. package/build/messages/ChallengeMessage.d.mts +46 -0
  76. package/build/messages/ChallengeMessage.d.mts.map +1 -0
  77. package/build/messages/ChallengeMessage.mjs +57 -0
  78. package/build/messages/ChallengeMessage.mjs.map +1 -0
  79. package/build/messages/CompleteMessage.d.mts +56 -0
  80. package/build/messages/CompleteMessage.d.mts.map +1 -0
  81. package/build/messages/CompleteMessage.mjs +69 -0
  82. package/build/messages/CompleteMessage.mjs.map +1 -0
  83. package/build/messages/DeclinePoeMessage.d.mts +36 -0
  84. package/build/messages/DeclinePoeMessage.d.mts.map +1 -0
  85. package/build/messages/DeclinePoeMessage.mjs +45 -0
  86. package/build/messages/DeclinePoeMessage.mjs.map +1 -0
  87. package/build/messages/PoeProblemReportMessage.d.mts +51 -0
  88. package/build/messages/PoeProblemReportMessage.d.mts.map +1 -0
  89. package/build/messages/PoeProblemReportMessage.mjs +64 -0
  90. package/build/messages/PoeProblemReportMessage.mjs.map +1 -0
  91. package/build/messages/ProposePoeMessage.d.mts +51 -0
  92. package/build/messages/ProposePoeMessage.d.mts.map +1 -0
  93. package/build/messages/ProposePoeMessage.mjs +69 -0
  94. package/build/messages/ProposePoeMessage.mjs.map +1 -0
  95. package/build/messages/RequestPoeMessage.d.mts +64 -0
  96. package/build/messages/RequestPoeMessage.d.mts.map +1 -0
  97. package/build/messages/RequestPoeMessage.mjs +82 -0
  98. package/build/messages/RequestPoeMessage.mjs.map +1 -0
  99. package/build/messages/SubmitPoeMessage.d.mts +58 -0
  100. package/build/messages/SubmitPoeMessage.d.mts.map +1 -0
  101. package/build/messages/SubmitPoeMessage.mjs +75 -0
  102. package/build/messages/SubmitPoeMessage.mjs.map +1 -0
  103. package/build/messages/index.d.mts +9 -0
  104. package/build/messages/index.mjs +11 -0
  105. package/build/models/BindingContext.d.mts +36 -0
  106. package/build/models/BindingContext.d.mts.map +1 -0
  107. package/build/models/BindingContext.mjs +42 -0
  108. package/build/models/BindingContext.mjs.map +1 -0
  109. package/build/models/ProgramExecution.d.mts +142 -0
  110. package/build/models/ProgramExecution.d.mts.map +1 -0
  111. package/build/models/ProofArtifact.d.mts +260 -0
  112. package/build/models/ProofArtifact.d.mts.map +1 -0
  113. package/build/programs/AppAttestationProgram.d.mts +179 -0
  114. package/build/programs/AppAttestationProgram.d.mts.map +1 -0
  115. package/build/programs/AppAttestationProgram.mjs +296 -0
  116. package/build/programs/AppAttestationProgram.mjs.map +1 -0
  117. package/build/programs/PoeProgram.d.mts +204 -0
  118. package/build/programs/PoeProgram.d.mts.map +1 -0
  119. package/build/programs/PoeProgram.mjs +155 -0
  120. package/build/programs/PoeProgram.mjs.map +1 -0
  121. package/build/programs/examples/MockProgram.d.mts +98 -0
  122. package/build/programs/examples/MockProgram.d.mts.map +1 -0
  123. package/build/programs/examples/MockProgram.mjs +117 -0
  124. package/build/programs/examples/MockProgram.mjs.map +1 -0
  125. package/build/programs/examples/index.d.mts +1 -0
  126. package/build/programs/index.d.mts +4 -0
  127. package/build/programs/index.mjs +3 -0
  128. package/build/programs/vkeys/app_attestation_vkey.mjs +136 -0
  129. package/build/programs/vkeys/app_attestation_vkey.mjs.map +1 -0
  130. package/build/registry/ProgramRegistry.d.mts +108 -0
  131. package/build/registry/ProgramRegistry.d.mts.map +1 -0
  132. package/build/registry/ProgramRegistry.mjs +87 -0
  133. package/build/registry/ProgramRegistry.mjs.map +1 -0
  134. package/build/registry/ProofSystemRegistry.d.mts +111 -0
  135. package/build/registry/ProofSystemRegistry.d.mts.map +1 -0
  136. package/build/registry/ProofSystemRegistry.mjs +87 -0
  137. package/build/registry/ProofSystemRegistry.mjs.map +1 -0
  138. package/build/registry/index.d.mts +2 -0
  139. package/build/registry/index.mjs +2 -0
  140. package/build/repository/NonceRecord.d.mts +45 -0
  141. package/build/repository/NonceRecord.d.mts.map +1 -0
  142. package/build/repository/NonceRecord.mjs +34 -0
  143. package/build/repository/NonceRecord.mjs.map +1 -0
  144. package/build/repository/NonceRepository.d.mts +41 -0
  145. package/build/repository/NonceRepository.d.mts.map +1 -0
  146. package/build/repository/NonceRepository.mjs +63 -0
  147. package/build/repository/NonceRepository.mjs.map +1 -0
  148. package/build/repository/PoeSessionRecord.d.mts +107 -0
  149. package/build/repository/PoeSessionRecord.d.mts.map +1 -0
  150. package/build/repository/PoeSessionRecord.mjs +100 -0
  151. package/build/repository/PoeSessionRecord.mjs.map +1 -0
  152. package/build/repository/PoeSessionRepository.d.mts +29 -0
  153. package/build/repository/PoeSessionRepository.d.mts.map +1 -0
  154. package/build/repository/PoeSessionRepository.mjs +46 -0
  155. package/build/repository/PoeSessionRepository.mjs.map +1 -0
  156. package/build/repository/index.d.mts +4 -0
  157. package/build/repository/index.mjs +6 -0
  158. package/build/services/AutoProofExecutionService.d.mts +2 -0
  159. package/build/services/AutoProofExecutionService.mjs +144 -0
  160. package/build/services/AutoProofExecutionService.mjs.map +1 -0
  161. package/build/services/ContextBindingService.d.mts +51 -0
  162. package/build/services/ContextBindingService.d.mts.map +1 -0
  163. package/build/services/ContextBindingService.mjs +92 -0
  164. package/build/services/ContextBindingService.mjs.map +1 -0
  165. package/build/services/NonceService.d.mts +74 -0
  166. package/build/services/NonceService.d.mts.map +1 -0
  167. package/build/services/NonceService.mjs +126 -0
  168. package/build/services/NonceService.mjs.map +1 -0
  169. package/build/services/PoeService.d.mts +163 -0
  170. package/build/services/PoeService.d.mts.map +1 -0
  171. package/build/services/PoeService.mjs +487 -0
  172. package/build/services/PoeService.mjs.map +1 -0
  173. package/build/services/ProofVerificationService.d.mts +87 -0
  174. package/build/services/ProofVerificationService.d.mts.map +1 -0
  175. package/build/services/ProofVerificationService.mjs +164 -0
  176. package/build/services/ProofVerificationService.mjs.map +1 -0
  177. package/build/services/index.d.mts +5 -0
  178. package/build/services/index.mjs +5 -0
  179. package/build/workflow/PoeV1Actions.d.mts +149 -0
  180. package/build/workflow/PoeV1Actions.d.mts.map +1 -0
  181. package/build/workflow/PoeV1Actions.mjs +190 -0
  182. package/build/workflow/PoeV1Actions.mjs.map +1 -0
  183. package/package.json +44 -3
@@ -0,0 +1,100 @@
1
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
2
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
3
+ import { BaseRecord, utils } from "@credo-ts/core";
4
+ import { Type } from "class-transformer";
5
+
6
+ //#region src/repository/PoeSessionRecord.ts
7
+ /**
8
+ * Record for tracking Proof of Execution (PoE) protocol sessions
9
+ */
10
+ var PoeSessionRecord = class PoeSessionRecord extends BaseRecord {
11
+ constructor(props) {
12
+ super();
13
+ this.type = PoeSessionRecord.type;
14
+ this.partialProofs = [];
15
+ if (props) {
16
+ this.id = props.id ?? utils.uuid();
17
+ this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
18
+ this.sessionId = props.sessionId;
19
+ this.connectionId = props.connectionId;
20
+ this.threadId = props.threadId;
21
+ this.parentThreadId = props.parentThreadId;
22
+ this.role = props.role;
23
+ this.state = props.state;
24
+ this.bindingContext = props.bindingContext;
25
+ this.programId = props.programId;
26
+ this.programVersion = props.programVersion;
27
+ this.executionPlan = props.executionPlan;
28
+ this.challengeSpec = props.challengeSpec;
29
+ this.partialProofs = props.partialProofs ?? [];
30
+ this.finalProof = props.finalProof;
31
+ this.verificationResult = props.verificationResult;
32
+ this.disclosure = props.disclosure;
33
+ this.idempotencyKey = props.idempotencyKey;
34
+ this.errorMessage = props.errorMessage;
35
+ this.expiry = props.expiry;
36
+ this._tags = props.tags ?? {};
37
+ }
38
+ }
39
+ getTags() {
40
+ return {
41
+ ...this._tags,
42
+ sessionId: this.sessionId,
43
+ threadId: this.threadId,
44
+ parentThreadId: this.parentThreadId,
45
+ connectionId: this.connectionId,
46
+ role: this.role,
47
+ state: this.state,
48
+ programId: this.programId
49
+ };
50
+ }
51
+ /**
52
+ * Assert that the record has the expected role
53
+ */
54
+ assertRole(expectedRole) {
55
+ if (this.role !== expectedRole) throw new Error(`PoE session has invalid role ${this.role}. Expected role ${expectedRole}.`);
56
+ }
57
+ /**
58
+ * Assert that the record is in one of the expected states
59
+ */
60
+ assertState(expectedStates) {
61
+ if (!Array.isArray(expectedStates)) expectedStates = [expectedStates];
62
+ if (!expectedStates.includes(this.state)) throw new Error(`PoE session is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
63
+ }
64
+ /**
65
+ * Add a partial proof to the collection
66
+ */
67
+ addPartialProof(proof) {
68
+ this.partialProofs.push(proof);
69
+ }
70
+ /**
71
+ * Set the final proof
72
+ */
73
+ setFinalProof(proof) {
74
+ this.finalProof = proof;
75
+ }
76
+ /**
77
+ * Check if the session has expired
78
+ */
79
+ isExpired() {
80
+ if (!this.expiry) return false;
81
+ return new Date(this.expiry) < /* @__PURE__ */ new Date();
82
+ }
83
+ /**
84
+ * Get a summary of the session for logging
85
+ */
86
+ getSummary() {
87
+ return `PoeSession(id=${this.id}, session=${this.sessionId}, role=${this.role}, state=${this.state}, program=${this.programId})`;
88
+ }
89
+ };
90
+ PoeSessionRecord.type = "PoeSessionRecord";
91
+ __decorate([Type(() => Object), __decorateMetadata("design:type", Object)], PoeSessionRecord.prototype, "bindingContext", void 0);
92
+ __decorate([Type(() => Object), __decorateMetadata("design:type", Object)], PoeSessionRecord.prototype, "executionPlan", void 0);
93
+ __decorate([Type(() => Object), __decorateMetadata("design:type", Object)], PoeSessionRecord.prototype, "challengeSpec", void 0);
94
+ __decorate([Type(() => Object), __decorateMetadata("design:type", Array)], PoeSessionRecord.prototype, "partialProofs", void 0);
95
+ __decorate([Type(() => Object), __decorateMetadata("design:type", Object)], PoeSessionRecord.prototype, "finalProof", void 0);
96
+ __decorate([Type(() => Object), __decorateMetadata("design:type", Object)], PoeSessionRecord.prototype, "verificationResult", void 0);
97
+
98
+ //#endregion
99
+ export { PoeSessionRecord };
100
+ //# sourceMappingURL=PoeSessionRecord.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoeSessionRecord.mjs","names":[],"sources":["../../src/repository/PoeSessionRecord.ts"],"sourcesContent":["import type { TagsBase, RecordTags } from '@credo-ts/core'\nimport type { PoeRole } from '../PoeRole'\nimport type { PoeState } from '../PoeState'\nimport type {\n BindingContext,\n ProgramExecution,\n ProofArtifact,\n VerificationResult,\n DisclosureLevel,\n ChallengeSpec,\n} from '../models'\n\nimport { BaseRecord, utils } from '@credo-ts/core'\nimport { Type } from 'class-transformer'\n\nexport type CustomPoeTags = TagsBase\n\nexport type DefaultPoeTags = {\n sessionId: string\n threadId: string\n parentThreadId?: string\n connectionId?: string\n role: PoeRole\n state: PoeState\n programId?: string\n}\n\nexport type PoeTags = RecordTags<PoeSessionRecord>\n\n/**\n * Storage properties for PoE session record\n */\nexport interface PoeSessionStorageProps {\n id?: string\n createdAt?: Date\n\n // Protocol metadata\n sessionId: string\n connectionId?: string\n threadId: string\n parentThreadId?: string\n\n role: PoeRole\n state: PoeState\n\n // Binding context (anti-replay)\n bindingContext: BindingContext\n\n // Program execution details\n programId?: string\n programVersion?: string\n executionPlan?: ProgramExecution\n\n // Challenge (for interactive programs)\n challengeSpec?: ChallengeSpec\n\n // Proof artifacts\n partialProofs?: ProofArtifact[]\n finalProof?: ProofArtifact\n\n // Verification\n verificationResult?: VerificationResult\n\n // Metadata\n disclosure?: DisclosureLevel\n idempotencyKey?: string\n errorMessage?: string\n expiry?: string\n\n tags?: CustomPoeTags\n}\n\n/**\n * Record for tracking Proof of Execution (PoE) protocol sessions\n */\nexport class PoeSessionRecord extends BaseRecord<DefaultPoeTags, CustomPoeTags> {\n public static readonly type = 'PoeSessionRecord'\n public readonly type = PoeSessionRecord.type\n\n // Protocol metadata\n public sessionId!: string\n public connectionId?: string\n public threadId!: string\n public parentThreadId?: string\n\n public role!: PoeRole\n public state!: PoeState\n\n // Binding context\n @Type(() => Object)\n public bindingContext!: BindingContext\n\n // Program execution\n public programId?: string\n public programVersion?: string\n\n @Type(() => Object)\n public executionPlan?: ProgramExecution\n\n // Challenge\n @Type(() => Object)\n public challengeSpec?: ChallengeSpec\n\n // Proof artifacts\n @Type(() => Object)\n public partialProofs: ProofArtifact[] = []\n\n @Type(() => Object)\n public finalProof?: ProofArtifact\n\n // Verification\n @Type(() => Object)\n public verificationResult?: VerificationResult\n\n // Metadata\n public disclosure?: DisclosureLevel\n public idempotencyKey?: string\n public errorMessage?: string\n public expiry?: string\n\n public constructor(props: PoeSessionStorageProps) {\n super()\n\n if (props) {\n this.id = props.id ?? utils.uuid()\n this.createdAt = props.createdAt ?? new Date()\n this.sessionId = props.sessionId\n this.connectionId = props.connectionId\n this.threadId = props.threadId\n this.parentThreadId = props.parentThreadId\n this.role = props.role\n this.state = props.state\n this.bindingContext = props.bindingContext\n this.programId = props.programId\n this.programVersion = props.programVersion\n this.executionPlan = props.executionPlan\n this.challengeSpec = props.challengeSpec\n this.partialProofs = props.partialProofs ?? []\n this.finalProof = props.finalProof\n this.verificationResult = props.verificationResult\n this.disclosure = props.disclosure\n this.idempotencyKey = props.idempotencyKey\n this.errorMessage = props.errorMessage\n this.expiry = props.expiry\n this._tags = props.tags ?? {}\n }\n }\n\n public getTags() {\n return {\n ...this._tags,\n sessionId: this.sessionId,\n threadId: this.threadId,\n parentThreadId: this.parentThreadId,\n connectionId: this.connectionId,\n role: this.role,\n state: this.state,\n programId: this.programId,\n }\n }\n\n /**\n * Assert that the record has the expected role\n */\n public assertRole(expectedRole: PoeRole) {\n if (this.role !== expectedRole) {\n throw new Error(`PoE session has invalid role ${this.role}. Expected role ${expectedRole}.`)\n }\n }\n\n /**\n * Assert that the record is in one of the expected states\n */\n public assertState(expectedStates: PoeState | PoeState[]) {\n if (!Array.isArray(expectedStates)) {\n expectedStates = [expectedStates]\n }\n\n if (!expectedStates.includes(this.state)) {\n throw new Error(\n `PoE session is in invalid state ${this.state}. Valid states are: ${expectedStates.join(', ')}.`\n )\n }\n }\n\n /**\n * Add a partial proof to the collection\n */\n public addPartialProof(proof: ProofArtifact): void {\n this.partialProofs.push(proof)\n }\n\n /**\n * Set the final proof\n */\n public setFinalProof(proof: ProofArtifact): void {\n this.finalProof = proof\n }\n\n /**\n * Check if the session has expired\n */\n public isExpired(): boolean {\n if (!this.expiry) return false\n\n const expiryDate = new Date(this.expiry)\n return expiryDate < new Date()\n }\n\n /**\n * Get a summary of the session for logging\n */\n public getSummary(): string {\n return `PoeSession(id=${this.id}, session=${this.sessionId}, role=${this.role}, state=${this.state}, program=${this.programId})`\n }\n}\n"],"mappings":";;;;;;;;;AA2EA,IAAa,mBAAb,MAAa,yBAAyB,WAA0C;CA6C9E,AAAO,YAAY,OAA+B;AAChD,SAAO;OA5CO,OAAO,iBAAiB;OA4BjC,gBAAiC,EAAE;AAkBxC,MAAI,OAAO;AACT,QAAK,KAAK,MAAM,MAAM,MAAM,MAAM;AAClC,QAAK,YAAY,MAAM,6BAAa,IAAI,MAAM;AAC9C,QAAK,YAAY,MAAM;AACvB,QAAK,eAAe,MAAM;AAC1B,QAAK,WAAW,MAAM;AACtB,QAAK,iBAAiB,MAAM;AAC5B,QAAK,OAAO,MAAM;AAClB,QAAK,QAAQ,MAAM;AACnB,QAAK,iBAAiB,MAAM;AAC5B,QAAK,YAAY,MAAM;AACvB,QAAK,iBAAiB,MAAM;AAC5B,QAAK,gBAAgB,MAAM;AAC3B,QAAK,gBAAgB,MAAM;AAC3B,QAAK,gBAAgB,MAAM,iBAAiB,EAAE;AAC9C,QAAK,aAAa,MAAM;AACxB,QAAK,qBAAqB,MAAM;AAChC,QAAK,aAAa,MAAM;AACxB,QAAK,iBAAiB,MAAM;AAC5B,QAAK,eAAe,MAAM;AAC1B,QAAK,SAAS,MAAM;AACpB,QAAK,QAAQ,MAAM,QAAQ,EAAE;;;CAIjC,AAAO,UAAU;AACf,SAAO;GACL,GAAG,KAAK;GACR,WAAW,KAAK;GAChB,UAAU,KAAK;GACf,gBAAgB,KAAK;GACrB,cAAc,KAAK;GACnB,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,WAAW,KAAK;GACjB;;;;;CAMH,AAAO,WAAW,cAAuB;AACvC,MAAI,KAAK,SAAS,aAChB,OAAM,IAAI,MAAM,gCAAgC,KAAK,KAAK,kBAAkB,aAAa,GAAG;;;;;CAOhG,AAAO,YAAY,gBAAuC;AACxD,MAAI,CAAC,MAAM,QAAQ,eAAe,CAChC,kBAAiB,CAAC,eAAe;AAGnC,MAAI,CAAC,eAAe,SAAS,KAAK,MAAM,CACtC,OAAM,IAAI,MACR,mCAAmC,KAAK,MAAM,sBAAsB,eAAe,KAAK,KAAK,CAAC,GAC/F;;;;;CAOL,AAAO,gBAAgB,OAA4B;AACjD,OAAK,cAAc,KAAK,MAAM;;;;;CAMhC,AAAO,cAAc,OAA4B;AAC/C,OAAK,aAAa;;;;;CAMpB,AAAO,YAAqB;AAC1B,MAAI,CAAC,KAAK,OAAQ,QAAO;AAGzB,SADmB,IAAI,KAAK,KAAK,OAAO,mBACpB,IAAI,MAAM;;;;;CAMhC,AAAO,aAAqB;AAC1B,SAAO,iBAAiB,KAAK,GAAG,YAAY,KAAK,UAAU,SAAS,KAAK,KAAK,UAAU,KAAK,MAAM,YAAY,KAAK,UAAU;;;iBAzIzG,OAAO;YAa7B,WAAW,OAAO;YAOlB,WAAW,OAAO;YAIlB,WAAW,OAAO;YAIlB,WAAW,OAAO;YAGlB,WAAW,OAAO;YAIlB,WAAW,OAAO"}
@@ -0,0 +1,29 @@
1
+ import { PoeSessionRecord } from "./PoeSessionRecord.mjs";
2
+ import { AgentContext, EventEmitter, Repository, StorageService } from "@credo-ts/core";
3
+
4
+ //#region src/repository/PoeSessionRepository.d.ts
5
+ /**
6
+ * Repository for managing Proof of Execution (PoE) session records
7
+ */
8
+ declare class PoeSessionRepository extends Repository<PoeSessionRecord> {
9
+ constructor(storageService: StorageService<PoeSessionRecord>, eventEmitter: EventEmitter);
10
+ /**
11
+ * Find a session by session ID
12
+ */
13
+ findBySessionId(agentContext: AgentContext, sessionId: string): Promise<PoeSessionRecord | null>;
14
+ /**
15
+ * Find a session by thread ID
16
+ */
17
+ findByThreadId(agentContext: AgentContext, threadId: string): Promise<PoeSessionRecord | null>;
18
+ /**
19
+ * Find sessions by connection ID
20
+ */
21
+ findByConnectionId(agentContext: AgentContext, connectionId: string): Promise<PoeSessionRecord[]>;
22
+ /**
23
+ * Find sessions by program ID
24
+ */
25
+ findByProgramId(agentContext: AgentContext, programId: string): Promise<PoeSessionRecord[]>;
26
+ }
27
+ //#endregion
28
+ export { PoeSessionRepository };
29
+ //# sourceMappingURL=PoeSessionRepository.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoeSessionRepository.d.mts","names":[],"sources":["../../src/repository/PoeSessionRepository.ts"],"mappings":";;;;;AASA;;cACa,oBAAA,SAA6B,UAAA,CAAW,gBAAA;cAER,cAAA,EAAgB,cAAA,CAAe,gBAAA,GACxE,YAAA,EAAc,YAAA;EAD0D;;;EAS7D,eAAA,CAAgB,YAAA,EAAc,YAAA,EAAc,SAAA,WAAiB,OAAA,CAAA,gBAAA;EAAA;;;EAO7D,cAAA,CAAe,YAAA,EAAc,YAAA,EAAc,QAAA,WAAgB,OAAA,CAAA,gBAAA;EAAA;;;EAO3D,kBAAA,CAAmB,YAAA,EAAc,YAAA,EAAc,YAAA,WAAoB,OAAA,CAAA,gBAAA;EAOrC;;;EAA9B,eAAA,CAAgB,YAAA,EAAc,YAAA,EAAc,SAAA,WAAiB,OAAA,CAAA,gBAAA;AAAA"}
@@ -0,0 +1,46 @@
1
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
2
+ import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs";
3
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
4
+ import { PoeSessionRecord } from "./PoeSessionRecord.mjs";
5
+ import { EventEmitter, InjectionSymbols, Repository, inject, injectable } from "@credo-ts/core";
6
+
7
+ //#region src/repository/PoeSessionRepository.ts
8
+ var _ref;
9
+ let PoeSessionRepository = class PoeSessionRepository extends Repository {
10
+ constructor(storageService, eventEmitter) {
11
+ super(PoeSessionRecord, storageService, eventEmitter);
12
+ }
13
+ /**
14
+ * Find a session by session ID
15
+ */
16
+ async findBySessionId(agentContext, sessionId) {
17
+ return this.findSingleByQuery(agentContext, { sessionId });
18
+ }
19
+ /**
20
+ * Find a session by thread ID
21
+ */
22
+ async findByThreadId(agentContext, threadId) {
23
+ return this.findSingleByQuery(agentContext, { threadId });
24
+ }
25
+ /**
26
+ * Find sessions by connection ID
27
+ */
28
+ async findByConnectionId(agentContext, connectionId) {
29
+ return this.findByQuery(agentContext, { connectionId });
30
+ }
31
+ /**
32
+ * Find sessions by program ID
33
+ */
34
+ async findByProgramId(agentContext, programId) {
35
+ return this.findByQuery(agentContext, { programId });
36
+ }
37
+ };
38
+ PoeSessionRepository = __decorate([
39
+ injectable(),
40
+ __decorateParam(0, inject(InjectionSymbols.StorageService)),
41
+ __decorateMetadata("design:paramtypes", [Object, EventEmitter])
42
+ ], PoeSessionRepository);
43
+
44
+ //#endregion
45
+ export { PoeSessionRepository };
46
+ //# sourceMappingURL=PoeSessionRepository.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PoeSessionRepository.mjs","names":[],"sources":["../../src/repository/PoeSessionRepository.ts"],"sourcesContent":["import type { AgentContext, StorageService } from '@credo-ts/core'\n\nimport { EventEmitter, inject, injectable, InjectionSymbols, Repository } from '@credo-ts/core'\n\nimport { PoeSessionRecord } from './PoeSessionRecord'\n\n/**\n * Repository for managing Proof of Execution (PoE) session records\n */\n@injectable()\nexport class PoeSessionRepository extends Repository<PoeSessionRecord> {\n public constructor(\n @inject(InjectionSymbols.StorageService) storageService: StorageService<PoeSessionRecord>,\n eventEmitter: EventEmitter\n ) {\n super(PoeSessionRecord, storageService, eventEmitter)\n }\n\n /**\n * Find a session by session ID\n */\n public async findBySessionId(agentContext: AgentContext, sessionId: string) {\n return this.findSingleByQuery(agentContext, { sessionId })\n }\n\n /**\n * Find a session by thread ID\n */\n public async findByThreadId(agentContext: AgentContext, threadId: string) {\n return this.findSingleByQuery(agentContext, { threadId })\n }\n\n /**\n * Find sessions by connection ID\n */\n public async findByConnectionId(agentContext: AgentContext, connectionId: string) {\n return this.findByQuery(agentContext, { connectionId })\n }\n\n /**\n * Find sessions by program ID\n */\n public async findByProgramId(agentContext: AgentContext, programId: string) {\n return this.findByQuery(agentContext, { programId })\n }\n}\n"],"mappings":";;;;;;;;AAUO,iCAAM,6BAA6B,WAA6B;CACrE,AAAO,YACL,AAAyC,gBACzC,cACA;AACA,QAAM,kBAAkB,gBAAgB,aAAa;;;;;CAMvD,MAAa,gBAAgB,cAA4B,WAAmB;AAC1E,SAAO,KAAK,kBAAkB,cAAc,EAAE,WAAW,CAAC;;;;;CAM5D,MAAa,eAAe,cAA4B,UAAkB;AACxE,SAAO,KAAK,kBAAkB,cAAc,EAAE,UAAU,CAAC;;;;;CAM3D,MAAa,mBAAmB,cAA4B,cAAsB;AAChF,SAAO,KAAK,YAAY,cAAc,EAAE,cAAc,CAAC;;;;;CAMzD,MAAa,gBAAgB,cAA4B,WAAmB;AAC1E,SAAO,KAAK,YAAY,cAAc,EAAE,WAAW,CAAC;;;;CAlCvD,YAAY;oBAGR,OAAO,iBAAiB,eAAe"}
@@ -0,0 +1,4 @@
1
+ import { CustomPoeTags, DefaultPoeTags, PoeSessionRecord, PoeSessionStorageProps, PoeTags } from "./PoeSessionRecord.mjs";
2
+ import { PoeSessionRepository } from "./PoeSessionRepository.mjs";
3
+ import { CustomNonceTags, DefaultNonceTags, NonceRecord, NonceRecordStorageProps } from "./NonceRecord.mjs";
4
+ import { NonceRepository } from "./NonceRepository.mjs";
@@ -0,0 +1,6 @@
1
+ import { NonceRecord } from "./NonceRecord.mjs";
2
+ import { NonceRepository } from "./NonceRepository.mjs";
3
+ import { PoeSessionRecord } from "./PoeSessionRecord.mjs";
4
+ import { PoeSessionRepository } from "./PoeSessionRepository.mjs";
5
+
6
+ export { PoeSessionRecord };
@@ -0,0 +1,2 @@
1
+ import "../executor/ProgramExecutorRegistry.mjs";
2
+ import { AgentContext, EventEmitter, Logger } from "@credo-ts/core";
@@ -0,0 +1,144 @@
1
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
2
+ import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs";
3
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
4
+ import { ProgramExecutorRegistry } from "../executor/ProgramExecutorRegistry.mjs";
5
+ import { PoeState } from "../PoeState.mjs";
6
+ import { PoeRole } from "../PoeRole.mjs";
7
+ import { PoeEventTypes } from "../PoeEvents.mjs";
8
+ import { AgentContext, EventEmitter, InjectionSymbols } from "@credo-ts/core";
9
+ import { inject as inject$1, injectable as injectable$1 } from "tsyringe";
10
+
11
+ //#region src/services/AutoProofExecutionService.ts
12
+ var _ref, _ref2;
13
+ let AutoProofExecutionService = class AutoProofExecutionService {
14
+ constructor(logger, eventEmitter, executorRegistry) {
15
+ this.eventEmitter = eventEmitter;
16
+ this.executorRegistry = executorRegistry;
17
+ this.enabled = true;
18
+ this.logger = logger;
19
+ }
20
+ /**
21
+ * Initialize with the agent context (called from PoeModule.initialize)
22
+ */
23
+ setAgentContext(agentContext) {
24
+ this.agentContext = agentContext;
25
+ this.setupEventListener();
26
+ this.logger.debug("AutoProofExecutionService initialized with agent context");
27
+ }
28
+ /**
29
+ * Cleanup - unsubscribe from events (called from PoeModule.shutdown)
30
+ */
31
+ shutdown() {
32
+ if (this.eventListener) {
33
+ this.eventEmitter.off(PoeEventTypes.PoeStateChanged, this.eventListener);
34
+ this.eventListener = void 0;
35
+ this.logger.debug("AutoProofExecutionService event listener removed");
36
+ }
37
+ this.agentContext = void 0;
38
+ }
39
+ /**
40
+ * Enable or disable automatic proof execution
41
+ *
42
+ * @param enabled - True to enable, false to disable
43
+ */
44
+ setEnabled(enabled) {
45
+ this.enabled = enabled;
46
+ this.logger.info(`Auto-proof execution ${enabled ? "enabled" : "disabled"}`);
47
+ }
48
+ /**
49
+ * Check if auto-execution is enabled
50
+ */
51
+ isEnabled() {
52
+ return this.enabled;
53
+ }
54
+ /**
55
+ * Set up event listener for PoeStateChanged events
56
+ */
57
+ setupEventListener() {
58
+ this.eventListener = async (data) => {
59
+ if (!this.enabled) return;
60
+ if (!this.agentContext) {
61
+ this.logger.warn("AutoProofExecutionService not initialized with agent context, skipping auto-execution");
62
+ return;
63
+ }
64
+ if (data.metadata.contextCorrelationId !== this.agentContext.contextCorrelationId) return;
65
+ const { poeRecord, previousState } = data.payload;
66
+ if (poeRecord.role === PoeRole.Prover && poeRecord.state === PoeState.RequestReceived && previousState !== PoeState.RequestReceived) await this.handleProofRequest(this.agentContext, poeRecord);
67
+ };
68
+ this.eventEmitter.on(PoeEventTypes.PoeStateChanged, this.eventListener);
69
+ this.logger.debug("AutoProofExecutionService event listener registered");
70
+ }
71
+ /**
72
+ * Handle incoming proof request by executing the program
73
+ */
74
+ async handleProofRequest(agentContext, poeRecord) {
75
+ const programId = poeRecord.programId;
76
+ if (!programId) {
77
+ this.logger.warn("No program ID in PoE record", { recordId: poeRecord.id });
78
+ return;
79
+ }
80
+ this.logger.info("Auto-executing proof generation", {
81
+ programId,
82
+ sessionId: poeRecord.sessionId,
83
+ recordId: poeRecord.id
84
+ });
85
+ try {
86
+ const executor = this.executorRegistry.getExecutor(programId);
87
+ if (!executor) {
88
+ this.logger.warn("No executor registered for program", { programId });
89
+ const { PoeApi } = await import("../PoeApi.mjs");
90
+ await agentContext.dependencyManager.resolve(PoeApi).sendProblemReport(poeRecord.id, "program_not_supported", `No executor registered for program ${programId}. Available executors: ${this.executorRegistry.getAllExecutorIds().join(", ")}`);
91
+ return;
92
+ }
93
+ if (executor.canExecute) {
94
+ const error = await executor.canExecute(agentContext, poeRecord.executionPlan);
95
+ if (error) {
96
+ this.logger.warn("Executor cannot handle request", { error });
97
+ const { PoeApi } = await import("../PoeApi.mjs");
98
+ await agentContext.dependencyManager.resolve(PoeApi).sendProblemReport(poeRecord.id, "execution_failed", error);
99
+ return;
100
+ }
101
+ }
102
+ this.logger.debug("Calling executor.execute()", { programId });
103
+ const startTime = Date.now();
104
+ const proofArtifact = await executor.execute(agentContext, poeRecord.executionPlan, poeRecord.bindingContext);
105
+ const duration = Date.now() - startTime;
106
+ this.logger.debug("Executor completed", {
107
+ programId,
108
+ durationMs: duration
109
+ });
110
+ const { PoeApi } = await import("../PoeApi.mjs");
111
+ await agentContext.dependencyManager.resolve(PoeApi).submitProof(poeRecord.id, proofArtifact);
112
+ this.logger.info("Proof auto-submitted successfully", {
113
+ recordId: poeRecord.id,
114
+ result: proofArtifact.result,
115
+ durationMs: duration
116
+ });
117
+ } catch (error) {
118
+ this.logger.error("Failed to auto-execute proof", {
119
+ programId,
120
+ error: error.message,
121
+ stack: error.stack
122
+ });
123
+ try {
124
+ const { PoeApi } = await import("../PoeApi.mjs");
125
+ await agentContext.dependencyManager.resolve(PoeApi).sendProblemReport(poeRecord.id, "proof_generation_failed", `Proof generation failed: ${error.message}`);
126
+ } catch (reportError) {
127
+ this.logger.error("Failed to send problem report", { error: reportError.message });
128
+ }
129
+ }
130
+ }
131
+ };
132
+ AutoProofExecutionService = __decorate([
133
+ injectable$1(),
134
+ __decorateParam(0, inject$1(InjectionSymbols.Logger)),
135
+ __decorateMetadata("design:paramtypes", [
136
+ Object,
137
+ EventEmitter,
138
+ ProgramExecutorRegistry
139
+ ])
140
+ ], AutoProofExecutionService);
141
+
142
+ //#endregion
143
+ export { AutoProofExecutionService };
144
+ //# sourceMappingURL=AutoProofExecutionService.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AutoProofExecutionService.mjs","names":["injectable","inject"],"sources":["../../src/services/AutoProofExecutionService.ts"],"sourcesContent":["import { injectable, inject } from 'tsyringe'\nimport type { Logger } from '@credo-ts/core'\nimport { EventEmitter, AgentContext, InjectionSymbols } from '@credo-ts/core'\n\nimport type { PoeStateChangedEvent } from '../PoeEvents'\nimport { PoeEventTypes } from '../PoeEvents'\nimport { PoeState } from '../PoeState'\nimport { PoeRole } from '../PoeRole'\nimport { ProgramExecutorRegistry } from '../executor/ProgramExecutorRegistry'\nimport type { PoeSessionRecord } from '../repository'\n\n/**\n * Service that automatically executes ZK programs when proof requests are received.\n *\n * This service listens for PoeStateChanged events and triggers automatic proof\n * generation when a request is received (state = RequestReceived, role = Prover).\n *\n * Benefits:\n * - Event-driven (no timeouts in tests)\n * - Automatic proof submission\n * - Error handling with problem reports\n * - Can be enabled/disabled at runtime\n *\n * @example\n * ```typescript\n * // Disable auto-execution for manual control\n * const autoExec = agent.dependencyManager.resolve(AutoProofExecutionService)\n * autoExec.setEnabled(false)\n * ```\n */\n@injectable()\nexport class AutoProofExecutionService {\n private enabled = true\n private logger: Logger\n private agentContext?: AgentContext\n private eventListener?: (data: PoeStateChangedEvent) => void | Promise<void>\n\n public constructor(\n @inject(InjectionSymbols.Logger) logger: Logger,\n private eventEmitter: EventEmitter,\n private executorRegistry: ProgramExecutorRegistry\n ) {\n this.logger = logger\n }\n\n /**\n * Initialize with the agent context (called from PoeModule.initialize)\n */\n public setAgentContext(agentContext: AgentContext): void {\n this.agentContext = agentContext\n this.setupEventListener()\n this.logger.debug('AutoProofExecutionService initialized with agent context')\n }\n\n /**\n * Cleanup - unsubscribe from events (called from PoeModule.shutdown)\n */\n public shutdown(): void {\n if (this.eventListener) {\n this.eventEmitter.off(PoeEventTypes.PoeStateChanged, this.eventListener)\n this.eventListener = undefined\n this.logger.debug('AutoProofExecutionService event listener removed')\n }\n this.agentContext = undefined\n }\n\n /**\n * Enable or disable automatic proof execution\n *\n * @param enabled - True to enable, false to disable\n */\n public setEnabled(enabled: boolean): void {\n this.enabled = enabled\n this.logger.info(`Auto-proof execution ${enabled ? 'enabled' : 'disabled'}`)\n }\n\n /**\n * Check if auto-execution is enabled\n */\n public isEnabled(): boolean {\n return this.enabled\n }\n\n /**\n * Set up event listener for PoeStateChanged events\n */\n private setupEventListener(): void {\n // Store listener reference for cleanup\n this.eventListener = async (data: PoeStateChangedEvent) => {\n if (!this.enabled) return\n\n // Use the stored agent context (set during module initialization)\n if (!this.agentContext) {\n this.logger.warn('AutoProofExecutionService not initialized with agent context, skipping auto-execution')\n return\n }\n\n // Verify the event is for our agent context\n if (data.metadata.contextCorrelationId !== this.agentContext.contextCorrelationId) {\n return // Event is for a different agent (multi-tenant scenario)\n }\n\n const { poeRecord, previousState } = data.payload\n\n // Only act on RequestReceived state for Prover role\n // Check previousState to avoid re-processing\n if (\n poeRecord.role === PoeRole.Prover &&\n poeRecord.state === PoeState.RequestReceived &&\n previousState !== PoeState.RequestReceived\n ) {\n await this.handleProofRequest(this.agentContext, poeRecord)\n }\n }\n\n this.eventEmitter.on<PoeStateChangedEvent>(PoeEventTypes.PoeStateChanged, this.eventListener)\n this.logger.debug('AutoProofExecutionService event listener registered')\n }\n\n /**\n * Handle incoming proof request by executing the program\n */\n private async handleProofRequest(\n agentContext: AgentContext,\n poeRecord: PoeSessionRecord\n ): Promise<void> {\n const programId = poeRecord.programId\n\n if (!programId) {\n this.logger.warn('No program ID in PoE record', { recordId: poeRecord.id })\n return\n }\n\n this.logger.info('Auto-executing proof generation', {\n programId,\n sessionId: poeRecord.sessionId,\n recordId: poeRecord.id,\n })\n\n try {\n // Get the executor for this program\n const executor = this.executorRegistry.getExecutor(programId)\n\n if (!executor) {\n this.logger.warn('No executor registered for program', { programId })\n\n // Send problem report\n const { PoeApi } = await import('../PoeApi')\n const poeApi = agentContext.dependencyManager.resolve(PoeApi)\n await poeApi.sendProblemReport(\n poeRecord.id,\n 'program_not_supported',\n `No executor registered for program ${programId}. ` +\n `Available executors: ${this.executorRegistry.getAllExecutorIds().join(', ')}`\n )\n return\n }\n\n // Validate executor can handle this request\n if (executor.canExecute) {\n const error = await executor.canExecute(agentContext, poeRecord.executionPlan!)\n if (error) {\n this.logger.warn('Executor cannot handle request', { error })\n\n const { PoeApi } = await import('../PoeApi')\n const poeApi = agentContext.dependencyManager.resolve(PoeApi)\n await poeApi.sendProblemReport(poeRecord.id, 'execution_failed', error)\n return\n }\n }\n\n // Execute the proof generation\n this.logger.debug('Calling executor.execute()', { programId })\n const startTime = Date.now()\n\n const proofArtifact = await executor.execute(\n agentContext,\n poeRecord.executionPlan!,\n poeRecord.bindingContext!\n )\n\n const duration = Date.now() - startTime\n this.logger.debug('Executor completed', { programId, durationMs: duration })\n\n // Auto-submit the proof\n const { PoeApi } = await import('../PoeApi')\n const poeApi = agentContext.dependencyManager.resolve(PoeApi)\n await poeApi.submitProof(poeRecord.id, proofArtifact)\n\n this.logger.info('Proof auto-submitted successfully', {\n recordId: poeRecord.id,\n result: proofArtifact.result,\n durationMs: duration,\n })\n } catch (error) {\n this.logger.error('Failed to auto-execute proof', {\n programId,\n error: error.message,\n stack: error.stack,\n })\n\n // Send problem report\n try {\n const { PoeApi } = await import('../PoeApi')\n const poeApi = agentContext.dependencyManager.resolve(PoeApi)\n await poeApi.sendProblemReport(\n poeRecord.id,\n 'proof_generation_failed',\n `Proof generation failed: ${error.message}`\n )\n } catch (reportError) {\n this.logger.error('Failed to send problem report', {\n error: reportError.message,\n })\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AA+BO,sCAAM,0BAA0B;CAMrC,AAAO,YACL,AAAiC,QACjC,AAAQ,cACR,AAAQ,kBACR;EAFQ;EACA;OARF,UAAU;AAUhB,OAAK,SAAS;;;;;CAMhB,AAAO,gBAAgB,cAAkC;AACvD,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AAiB,OAAO"}
@@ -0,0 +1,51 @@
1
+ import { BindingContext } from "../models/BindingContext.mjs";
2
+ import { AgentContext, Logger } from "@credo-ts/core";
3
+
4
+ //#region src/services/ContextBindingService.d.ts
5
+ /**
6
+ * Service for managing context binding and hash computation
7
+ */
8
+ declare class ContextBindingService {
9
+ private logger;
10
+ constructor(logger: Logger);
11
+ /**
12
+ * Compute a context hash from arbitrary context data
13
+ * Uses SHA-256 for hashing
14
+ */
15
+ computeContextHash(context: unknown): Promise<string>;
16
+ /**
17
+ * Canonicalize data for consistent hashing
18
+ * Sorts object keys and produces deterministic JSON
19
+ */
20
+ private canonicalize;
21
+ /**
22
+ * Validate a binding context format
23
+ */
24
+ validateBindingContext(context: BindingContext): {
25
+ valid: boolean;
26
+ error?: string;
27
+ };
28
+ /**
29
+ * Compare two binding contexts for equality
30
+ */
31
+ bindingContextsEqual(a: BindingContext, b: BindingContext): boolean;
32
+ /**
33
+ * Validate that received binding context matches expected
34
+ * @throws {ContextMismatchError} if contexts don't match
35
+ */
36
+ assertBindingMatch(expected: BindingContext, received: BindingContext): void;
37
+ /**
38
+ * Create a complete binding context with generated nonce and session ID
39
+ */
40
+ createBindingContext(agentContext: AgentContext, contextData: unknown, options?: {
41
+ nonce?: string;
42
+ sessionId?: string;
43
+ }): Promise<BindingContext>;
44
+ /**
45
+ * Verify context hash matches the provided context data
46
+ */
47
+ verifyContextHash(contextData: unknown, expectedHash: string): Promise<boolean>;
48
+ }
49
+ //#endregion
50
+ export { ContextBindingService };
51
+ //# sourceMappingURL=ContextBindingService.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextBindingService.d.mts","names":[],"sources":["../../src/services/ContextBindingService.ts"],"mappings":";;;;;AAaA;;cACa,qBAAA;EAAA,QACH,MAAA;cAE4C,MAAA,EAAQ,MAAA;EA2DrB;;;;EAnD1B,kBAAA,CAAmB,OAAA,YAAmB,OAAA;EAmFnC;;;;EAAA,QApER,YAAA;EA6F2E;;;EAzD5E,sBAAA,CAAuB,OAAA,EAAS,cAAA;IAAmB,KAAA;IAAgB,KAAA;EAAA;EAnDvB;;;EA0D5C,oBAAA,CAAqB,CAAA,EAAG,cAAA,EAAgB,CAAA,EAAG,cAAA;EAPpB;;;;EAevB,kBAAA,CAAmB,QAAA,EAAU,cAAA,EAAgB,QAAA,EAAU,cAAA;EARlC;;;EAwBf,oBAAA,CACX,YAAA,EAAc,YAAA,EACd,WAAA,WACA,OAAA;IACE,KAAA;IACA,SAAA;EAAA,IAED,OAAA,CAAQ,cAAA;EAvByC;;;EA0CvC,iBAAA,CAAkB,WAAA,WAAsB,YAAA,WAAuB,OAAA;AAAA"}
@@ -0,0 +1,92 @@
1
+ import { ContextMismatchError } from "../errors/PoeError.mjs";
2
+ import "../errors/index.mjs";
3
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
4
+ import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs";
5
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
6
+ import { bindingContextsEqual, validateBindingContext } from "../models/BindingContext.mjs";
7
+ import { Hasher, InjectionSymbols } from "@credo-ts/core";
8
+ import { inject as inject$1, injectable as injectable$1 } from "tsyringe";
9
+
10
+ //#region src/services/ContextBindingService.ts
11
+ let ContextBindingService = class ContextBindingService {
12
+ constructor(logger) {
13
+ this.logger = logger;
14
+ }
15
+ /**
16
+ * Compute a context hash from arbitrary context data
17
+ * Uses SHA-256 for hashing
18
+ */
19
+ async computeContextHash(context) {
20
+ const canonical = this.canonicalize(context);
21
+ const hash = Hasher.hash(canonical, "sha-256");
22
+ return "0x" + Buffer.from(hash).toString("hex");
23
+ }
24
+ /**
25
+ * Canonicalize data for consistent hashing
26
+ * Sorts object keys and produces deterministic JSON
27
+ */
28
+ canonicalize(data) {
29
+ if (data === null || data === void 0) return JSON.stringify(data);
30
+ if (typeof data !== "object") return JSON.stringify(data);
31
+ if (Array.isArray(data)) return "[" + data.map((item) => this.canonicalize(item)).join(",") + "]";
32
+ const sorted = Object.keys(data).sort().reduce((acc, key) => {
33
+ acc[key] = data[key];
34
+ return acc;
35
+ }, {});
36
+ return "{" + Object.keys(sorted).map((key) => `"${key}":${this.canonicalize(sorted[key])}`).join(",") + "}";
37
+ }
38
+ /**
39
+ * Validate a binding context format
40
+ */
41
+ validateBindingContext(context) {
42
+ return validateBindingContext(context);
43
+ }
44
+ /**
45
+ * Compare two binding contexts for equality
46
+ */
47
+ bindingContextsEqual(a, b) {
48
+ return bindingContextsEqual(a, b);
49
+ }
50
+ /**
51
+ * Validate that received binding context matches expected
52
+ * @throws {ContextMismatchError} if contexts don't match
53
+ */
54
+ assertBindingMatch(expected, received) {
55
+ if (!this.bindingContextsEqual(expected, received)) {
56
+ this.logger.error("Binding context mismatch", {
57
+ expected,
58
+ received
59
+ });
60
+ throw new ContextMismatchError(`Binding context does not match. Expected nonce=${expected.nonce}, received nonce=${received.nonce}`);
61
+ }
62
+ }
63
+ /**
64
+ * Create a complete binding context with generated nonce and session ID
65
+ */
66
+ async createBindingContext(agentContext, contextData, options) {
67
+ const { NonceService } = await import("./NonceService.mjs");
68
+ const nonceService = agentContext.dependencyManager.resolve(NonceService);
69
+ const nonce = options?.nonce ?? nonceService.generateNonce();
70
+ const sessionId = options?.sessionId ?? nonceService.generateSessionId();
71
+ return {
72
+ nonce,
73
+ context_hash: await this.computeContextHash(contextData),
74
+ session_id: sessionId
75
+ };
76
+ }
77
+ /**
78
+ * Verify context hash matches the provided context data
79
+ */
80
+ async verifyContextHash(contextData, expectedHash) {
81
+ return (await this.computeContextHash(contextData)).toLowerCase() === expectedHash.toLowerCase();
82
+ }
83
+ };
84
+ ContextBindingService = __decorate([
85
+ injectable$1(),
86
+ __decorateParam(0, inject$1(InjectionSymbols.Logger)),
87
+ __decorateMetadata("design:paramtypes", [Object])
88
+ ], ContextBindingService);
89
+
90
+ //#endregion
91
+ export { ContextBindingService };
92
+ //# sourceMappingURL=ContextBindingService.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ContextBindingService.mjs","names":["injectable","inject"],"sources":["../../src/services/ContextBindingService.ts"],"sourcesContent":["import type { AgentContext } from '@credo-ts/core'\nimport type { BindingContext } from '../models'\n\nimport { injectable, inject } from 'tsyringe'\nimport type { Logger } from '@credo-ts/core'\nimport { InjectionSymbols } from '@credo-ts/core'\nimport { Hasher } from '@credo-ts/core'\nimport { ContextMismatchError } from '../errors'\nimport { validateBindingContext, bindingContextsEqual } from '../models'\n\n/**\n * Service for managing context binding and hash computation\n */\n@injectable()\nexport class ContextBindingService {\n private logger: Logger\n\n public constructor(@inject(InjectionSymbols.Logger) logger: Logger) {\n this.logger = logger\n }\n\n /**\n * Compute a context hash from arbitrary context data\n * Uses SHA-256 for hashing\n */\n public async computeContextHash(context: unknown): Promise<string> {\n // Canonicalize the context (stable JSON serialization)\n const canonical = this.canonicalize(context)\n\n // Hash the canonical representation\n const hash = Hasher.hash(canonical, 'sha-256')\n\n // Convert Uint8Array to hex string\n return '0x' + Buffer.from(hash).toString('hex')\n }\n\n /**\n * Canonicalize data for consistent hashing\n * Sorts object keys and produces deterministic JSON\n */\n private canonicalize(data: unknown): string {\n if (data === null || data === undefined) {\n return JSON.stringify(data)\n }\n\n if (typeof data !== 'object') {\n return JSON.stringify(data)\n }\n\n if (Array.isArray(data)) {\n return '[' + data.map((item) => this.canonicalize(item)).join(',') + ']'\n }\n\n // Sort object keys for deterministic output\n const sorted = Object.keys(data as object)\n .sort()\n .reduce(\n (acc, key) => {\n acc[key] = (data as Record<string, unknown>)[key]\n return acc\n },\n {} as Record<string, unknown>\n )\n\n return (\n '{' +\n Object.keys(sorted)\n .map((key) => `\"${key}\":${this.canonicalize(sorted[key])}`)\n .join(',') +\n '}'\n )\n }\n\n /**\n * Validate a binding context format\n */\n public validateBindingContext(context: BindingContext): { valid: boolean; error?: string } {\n return validateBindingContext(context)\n }\n\n /**\n * Compare two binding contexts for equality\n */\n public bindingContextsEqual(a: BindingContext, b: BindingContext): boolean {\n return bindingContextsEqual(a, b)\n }\n\n /**\n * Validate that received binding context matches expected\n * @throws {ContextMismatchError} if contexts don't match\n */\n public assertBindingMatch(expected: BindingContext, received: BindingContext): void {\n if (!this.bindingContextsEqual(expected, received)) {\n this.logger.error('Binding context mismatch', {\n expected,\n received,\n })\n\n throw new ContextMismatchError(\n `Binding context does not match. Expected nonce=${expected.nonce}, received nonce=${received.nonce}`\n )\n }\n }\n\n /**\n * Create a complete binding context with generated nonce and session ID\n */\n public async createBindingContext(\n agentContext: AgentContext,\n contextData: unknown,\n options?: {\n nonce?: string\n sessionId?: string\n }\n ): Promise<BindingContext> {\n // Import NonceService to avoid circular dependency\n const { NonceService } = await import('./NonceService')\n const nonceService = agentContext.dependencyManager.resolve(NonceService)\n\n const nonce = options?.nonce ?? nonceService.generateNonce()\n const sessionId = options?.sessionId ?? nonceService.generateSessionId()\n const contextHash = await this.computeContextHash(contextData)\n\n return {\n nonce,\n context_hash: contextHash,\n session_id: sessionId,\n }\n }\n\n /**\n * Verify context hash matches the provided context data\n */\n public async verifyContextHash(contextData: unknown, expectedHash: string): Promise<boolean> {\n const computedHash = await this.computeContextHash(contextData)\n return computedHash.toLowerCase() === expectedHash.toLowerCase()\n }\n}\n"],"mappings":";;;;;;;;;;AAcO,kCAAM,sBAAsB;CAGjC,AAAO,YAAY,AAAiC,QAAgB;AAClE,OAAK,SAAS;;;;;;CAOhB,MAAa,mBAAmB,SAAmC;EAEjE,MAAM,YAAY,KAAK,aAAa,QAAQ;EAG5C,MAAM,OAAO,OAAO,KAAK,WAAW,UAAU;AAG9C,SAAO,OAAO,OAAO,KAAK,KAAK,CAAC,SAAS,MAAM;;;;;;CAOjD,AAAQ,aAAa,MAAuB;AAC1C,MAAI,SAAS,QAAQ,SAAS,OAC5B,QAAO,KAAK,UAAU,KAAK;AAG7B,MAAI,OAAO,SAAS,SAClB,QAAO,KAAK,UAAU,KAA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+ import { AgentContext } from "@credo-ts/core";
3
+
4
+ //#region src/services/NonceService.d.ts
5
+ /**
6
+ * Service for generating and validating nonces to prevent replay attacks.
7
+ *
8
+ * Uses persistent storage (Askar DB) with an in-memory cache for performance.
9
+ * Nonces persist across agent restarts to prevent replay attacks.
10
+ */
11
+ declare class NonceService {
12
+ private nonceRepository;
13
+ private nonceCache;
14
+ constructor(nonceRepository: NonceRepository);
15
+ /**
16
+ * Generate a cryptographically secure nonce
17
+ * @returns 32-byte hex string with 0x prefix
18
+ */
19
+ generateNonce(): string;
20
+ /**
21
+ * Generate a session ID (16 bytes)
22
+ * @returns 16-byte hex string with 0x prefix
23
+ */
24
+ generateSessionId(): string;
25
+ /**
26
+ * Check if a nonce has been used by a specific DID
27
+ *
28
+ * First checks in-memory cache, falls back to repository if not found.
29
+ * This provides fast lookups while maintaining persistence.
30
+ */
31
+ isNonceUsed(agentContext: AgentContext, proverDid: string, nonce: string): Promise<boolean>;
32
+ /**
33
+ * Mark a nonce as used by a specific DID
34
+ *
35
+ * Stores in both repository (persistent) and cache (fast access).
36
+ */
37
+ markNonceUsed(agentContext: AgentContext, proverDid: string, nonce: string): Promise<void>;
38
+ /**
39
+ * Helper to add nonce to in-memory cache
40
+ */
41
+ private addToCache;
42
+ /**
43
+ * Validate that a nonce hasn't been used and mark it as used
44
+ * @throws {NonceError} if nonce has already been used
45
+ */
46
+ validateAndMarkNonce(agentContext: AgentContext, proverDid: string, nonce: string): Promise<void>;
47
+ /**
48
+ * Validate nonce format
49
+ */
50
+ validateNonceFormat(nonce: string): boolean;
51
+ /**
52
+ * Validate session ID format
53
+ */
54
+ validateSessionIdFormat(sessionId: string): boolean;
55
+ /**
56
+ * Clear used nonces for a specific DID (useful for testing or cleanup)
57
+ */
58
+ clearNonces(agentContext: AgentContext, proverDid: string): Promise<void>;
59
+ /**
60
+ * Clear all used nonces (useful for testing)
61
+ */
62
+ clearAll(agentContext: AgentContext): Promise<void>;
63
+ /**
64
+ * Delete nonces older than specified time (for cleanup/maintenance)
65
+ *
66
+ * @param agentContext - Agent context
67
+ * @param olderThanMs - Delete nonces older than this many milliseconds
68
+ * @returns Number of nonces deleted
69
+ */
70
+ deleteOldNonces(agentContext: AgentContext, olderThanMs?: number): Promise<number>;
71
+ }
72
+ //#endregion
73
+ export { NonceService };
74
+ //# sourceMappingURL=NonceService.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NonceService.d.mts","names":[],"sources":["../../src/services/NonceService.ts"],"mappings":";;;;;;AAcA;;;;cACa,YAAA;EAAA,QAIgB,eAAA;EAAA,QAFnB,UAAA;cAEmB,eAAA,EAAiB,eAAA;EAgG5B;;;;EA1FT,aAAA,CAAA;EAsI4C;;;;EA7H5C,iBAAA,CAAA;EAfoB;;;;;;EA0Bd,WAAA,CACX,YAAA,EAAc,YAAA,EACd,SAAA,UACA,KAAA,WACC,OAAA;EAJU;;;;;EAkCA,aAAA,CACX,YAAA,EAAc,YAAA,EACd,SAAA,UACA,KAAA,WACC,OAAA;EAJU;;;EAAA,QAsBL,UAAA;EAnBN;;;;EAgCW,oBAAA,CACX,YAAA,EAAc,YAAA,EACd,SAAA,UACA,KAAA,WACC,OAAA;EAHD;;;EAcK,mBAAA,CAAoB,KAAA;EAApB;;;EAQA,uBAAA,CAAwB,SAAA;EAQlB;;;EAAA,WAAA,CAAY,YAAA,EAAc,YAAA,EAAc,SAAA,WAAoB,OAAA;EAAA;;;EAc5D,QAAA,CAAS,YAAA,EAAc,YAAA,GAAe,OAAA;EAAA;;;;;;;EAkBtC,eAAA,CACX,YAAA,EAAc,YAAA,EACd,WAAA,YACC,OAAA;AAAA"}