@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.
- package/LICENSE +202 -0
- package/README.md +39 -2
- package/build/PoeApi.d.mts +150 -0
- package/build/PoeApi.d.mts.map +1 -0
- package/build/PoeApi.mjs +262 -0
- package/build/PoeApi.mjs.map +1 -0
- package/build/PoeEvents.d.mts +187 -0
- package/build/PoeEvents.d.mts.map +1 -0
- package/build/PoeEvents.mjs +28 -0
- package/build/PoeEvents.mjs.map +1 -0
- package/build/PoeModule.d.mts +61 -0
- package/build/PoeModule.d.mts.map +1 -0
- package/build/PoeModule.mjs +139 -0
- package/build/PoeModule.mjs.map +1 -0
- package/build/PoeModuleConfig.d.mts +71 -0
- package/build/PoeModuleConfig.d.mts.map +1 -0
- package/build/PoeRole.d.mts +21 -0
- package/build/PoeRole.d.mts.map +1 -0
- package/build/PoeRole.mjs +23 -0
- package/build/PoeRole.mjs.map +1 -0
- package/build/PoeState.d.mts +76 -0
- package/build/PoeState.d.mts.map +1 -0
- package/build/PoeState.mjs +78 -0
- package/build/PoeState.mjs.map +1 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs +10 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs +7 -0
- package/build/_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs +9 -0
- package/build/_virtual/_rolldown/runtime.mjs +8 -0
- package/build/errors/PoeError.d.mts +173 -0
- package/build/errors/PoeError.d.mts.map +1 -0
- package/build/errors/PoeError.mjs +147 -0
- package/build/errors/PoeError.mjs.map +1 -0
- package/build/errors/index.d.mts +1 -0
- package/build/errors/index.mjs +1 -0
- package/build/executor/ProgramExecutor.d.mts +148 -0
- package/build/executor/ProgramExecutor.d.mts.map +1 -0
- package/build/executor/ProgramExecutorRegistry.d.mts +111 -0
- package/build/executor/ProgramExecutorRegistry.d.mts.map +1 -0
- package/build/executor/ProgramExecutorRegistry.mjs +145 -0
- package/build/executor/ProgramExecutorRegistry.mjs.map +1 -0
- package/build/executor/__mocks__/MockProgramExecutor.d.mts +118 -0
- package/build/executor/__mocks__/MockProgramExecutor.d.mts.map +1 -0
- package/build/executor/__mocks__/MockProgramExecutor.mjs +96 -0
- package/build/executor/__mocks__/MockProgramExecutor.mjs.map +1 -0
- package/build/executor/__mocks__/MockProofVerifier.d.mts +97 -0
- package/build/executor/__mocks__/MockProofVerifier.d.mts.map +1 -0
- package/build/executor/__mocks__/MockProofVerifier.mjs +79 -0
- package/build/executor/__mocks__/MockProofVerifier.mjs.map +1 -0
- package/build/executor/__mocks__/index.d.mts +2 -0
- package/build/executor/index.d.mts +5 -0
- package/build/executor/index.mjs +3 -0
- package/build/handlers/AcceptPoeMessageHandler.mjs +24 -0
- package/build/handlers/AcceptPoeMessageHandler.mjs.map +1 -0
- package/build/handlers/ChallengeMessageHandler.mjs +24 -0
- package/build/handlers/ChallengeMessageHandler.mjs.map +1 -0
- package/build/handlers/CompleteMessageHandler.mjs +24 -0
- package/build/handlers/CompleteMessageHandler.mjs.map +1 -0
- package/build/handlers/DeclinePoeMessageHandler.mjs +24 -0
- package/build/handlers/DeclinePoeMessageHandler.mjs.map +1 -0
- package/build/handlers/PoeProblemReportMessageHandler.mjs +18 -0
- package/build/handlers/PoeProblemReportMessageHandler.mjs.map +1 -0
- package/build/handlers/ProposePoeMessageHandler.mjs +18 -0
- package/build/handlers/ProposePoeMessageHandler.mjs.map +1 -0
- package/build/handlers/RequestPoeMessageHandler.mjs +18 -0
- package/build/handlers/RequestPoeMessageHandler.mjs.map +1 -0
- package/build/handlers/SubmitPoeMessageHandler.mjs +18 -0
- package/build/handlers/SubmitPoeMessageHandler.mjs.map +1 -0
- package/build/handlers/index.mjs +8 -0
- package/build/index.d.mts +38 -0
- package/build/index.mjs +33 -0
- package/build/messages/AcceptPoeMessage.d.mts +48 -0
- package/build/messages/AcceptPoeMessage.d.mts.map +1 -0
- package/build/messages/AcceptPoeMessage.mjs +61 -0
- package/build/messages/AcceptPoeMessage.mjs.map +1 -0
- package/build/messages/ChallengeMessage.d.mts +46 -0
- package/build/messages/ChallengeMessage.d.mts.map +1 -0
- package/build/messages/ChallengeMessage.mjs +57 -0
- package/build/messages/ChallengeMessage.mjs.map +1 -0
- package/build/messages/CompleteMessage.d.mts +56 -0
- package/build/messages/CompleteMessage.d.mts.map +1 -0
- package/build/messages/CompleteMessage.mjs +69 -0
- package/build/messages/CompleteMessage.mjs.map +1 -0
- package/build/messages/DeclinePoeMessage.d.mts +36 -0
- package/build/messages/DeclinePoeMessage.d.mts.map +1 -0
- package/build/messages/DeclinePoeMessage.mjs +45 -0
- package/build/messages/DeclinePoeMessage.mjs.map +1 -0
- package/build/messages/PoeProblemReportMessage.d.mts +51 -0
- package/build/messages/PoeProblemReportMessage.d.mts.map +1 -0
- package/build/messages/PoeProblemReportMessage.mjs +64 -0
- package/build/messages/PoeProblemReportMessage.mjs.map +1 -0
- package/build/messages/ProposePoeMessage.d.mts +51 -0
- package/build/messages/ProposePoeMessage.d.mts.map +1 -0
- package/build/messages/ProposePoeMessage.mjs +69 -0
- package/build/messages/ProposePoeMessage.mjs.map +1 -0
- package/build/messages/RequestPoeMessage.d.mts +64 -0
- package/build/messages/RequestPoeMessage.d.mts.map +1 -0
- package/build/messages/RequestPoeMessage.mjs +82 -0
- package/build/messages/RequestPoeMessage.mjs.map +1 -0
- package/build/messages/SubmitPoeMessage.d.mts +58 -0
- package/build/messages/SubmitPoeMessage.d.mts.map +1 -0
- package/build/messages/SubmitPoeMessage.mjs +75 -0
- package/build/messages/SubmitPoeMessage.mjs.map +1 -0
- package/build/messages/index.d.mts +9 -0
- package/build/messages/index.mjs +11 -0
- package/build/models/BindingContext.d.mts +36 -0
- package/build/models/BindingContext.d.mts.map +1 -0
- package/build/models/BindingContext.mjs +42 -0
- package/build/models/BindingContext.mjs.map +1 -0
- package/build/models/ProgramExecution.d.mts +142 -0
- package/build/models/ProgramExecution.d.mts.map +1 -0
- package/build/models/ProofArtifact.d.mts +260 -0
- package/build/models/ProofArtifact.d.mts.map +1 -0
- package/build/programs/AppAttestationProgram.d.mts +179 -0
- package/build/programs/AppAttestationProgram.d.mts.map +1 -0
- package/build/programs/AppAttestationProgram.mjs +296 -0
- package/build/programs/AppAttestationProgram.mjs.map +1 -0
- package/build/programs/PoeProgram.d.mts +204 -0
- package/build/programs/PoeProgram.d.mts.map +1 -0
- package/build/programs/PoeProgram.mjs +155 -0
- package/build/programs/PoeProgram.mjs.map +1 -0
- package/build/programs/examples/MockProgram.d.mts +98 -0
- package/build/programs/examples/MockProgram.d.mts.map +1 -0
- package/build/programs/examples/MockProgram.mjs +117 -0
- package/build/programs/examples/MockProgram.mjs.map +1 -0
- package/build/programs/examples/index.d.mts +1 -0
- package/build/programs/index.d.mts +4 -0
- package/build/programs/index.mjs +3 -0
- package/build/programs/vkeys/app_attestation_vkey.mjs +136 -0
- package/build/programs/vkeys/app_attestation_vkey.mjs.map +1 -0
- package/build/registry/ProgramRegistry.d.mts +108 -0
- package/build/registry/ProgramRegistry.d.mts.map +1 -0
- package/build/registry/ProgramRegistry.mjs +87 -0
- package/build/registry/ProgramRegistry.mjs.map +1 -0
- package/build/registry/ProofSystemRegistry.d.mts +111 -0
- package/build/registry/ProofSystemRegistry.d.mts.map +1 -0
- package/build/registry/ProofSystemRegistry.mjs +87 -0
- package/build/registry/ProofSystemRegistry.mjs.map +1 -0
- package/build/registry/index.d.mts +2 -0
- package/build/registry/index.mjs +2 -0
- package/build/repository/NonceRecord.d.mts +45 -0
- package/build/repository/NonceRecord.d.mts.map +1 -0
- package/build/repository/NonceRecord.mjs +34 -0
- package/build/repository/NonceRecord.mjs.map +1 -0
- package/build/repository/NonceRepository.d.mts +41 -0
- package/build/repository/NonceRepository.d.mts.map +1 -0
- package/build/repository/NonceRepository.mjs +63 -0
- package/build/repository/NonceRepository.mjs.map +1 -0
- package/build/repository/PoeSessionRecord.d.mts +107 -0
- package/build/repository/PoeSessionRecord.d.mts.map +1 -0
- package/build/repository/PoeSessionRecord.mjs +100 -0
- package/build/repository/PoeSessionRecord.mjs.map +1 -0
- package/build/repository/PoeSessionRepository.d.mts +29 -0
- package/build/repository/PoeSessionRepository.d.mts.map +1 -0
- package/build/repository/PoeSessionRepository.mjs +46 -0
- package/build/repository/PoeSessionRepository.mjs.map +1 -0
- package/build/repository/index.d.mts +4 -0
- package/build/repository/index.mjs +6 -0
- package/build/services/AutoProofExecutionService.d.mts +2 -0
- package/build/services/AutoProofExecutionService.mjs +144 -0
- package/build/services/AutoProofExecutionService.mjs.map +1 -0
- package/build/services/ContextBindingService.d.mts +51 -0
- package/build/services/ContextBindingService.d.mts.map +1 -0
- package/build/services/ContextBindingService.mjs +92 -0
- package/build/services/ContextBindingService.mjs.map +1 -0
- package/build/services/NonceService.d.mts +74 -0
- package/build/services/NonceService.d.mts.map +1 -0
- package/build/services/NonceService.mjs +126 -0
- package/build/services/NonceService.mjs.map +1 -0
- package/build/services/PoeService.d.mts +163 -0
- package/build/services/PoeService.d.mts.map +1 -0
- package/build/services/PoeService.mjs +487 -0
- package/build/services/PoeService.mjs.map +1 -0
- package/build/services/ProofVerificationService.d.mts +87 -0
- package/build/services/ProofVerificationService.d.mts.map +1 -0
- package/build/services/ProofVerificationService.mjs +164 -0
- package/build/services/ProofVerificationService.mjs.map +1 -0
- package/build/services/index.d.mts +5 -0
- package/build/services/index.mjs +5 -0
- package/build/workflow/PoeV1Actions.d.mts +149 -0
- package/build/workflow/PoeV1Actions.d.mts.map +1 -0
- package/build/workflow/PoeV1Actions.mjs +190 -0
- package/build/workflow/PoeV1Actions.mjs.map +1 -0
- package/package.json +44 -3
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { BindingContext } from "../models/BindingContext.mjs";
|
|
2
|
+
import { ProgramExecution } from "../models/ProgramExecution.mjs";
|
|
3
|
+
import { ProofArtifact } from "../models/ProofArtifact.mjs";
|
|
4
|
+
import { AgentContext } from "@credo-ts/core";
|
|
5
|
+
|
|
6
|
+
//#region src/executor/ProgramExecutor.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Interface that all ZK program executors must implement.
|
|
9
|
+
*
|
|
10
|
+
* Executors are responsible for:
|
|
11
|
+
* 1. Retrieving necessary data (from Askar DB, HTTP, files, etc.)
|
|
12
|
+
* 2. Generating the ZK proof
|
|
13
|
+
* 3. Returning a properly formatted ProofArtifact
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* export class MyExecutor implements ProgramExecutor {
|
|
18
|
+
* programId = 'my.program.v1'
|
|
19
|
+
*
|
|
20
|
+
* async execute(context, execution, bindingContext) {
|
|
21
|
+
* // 1. Get data
|
|
22
|
+
* const data = await getData(context, execution.inputs)
|
|
23
|
+
*
|
|
24
|
+
* // 2. Generate proof
|
|
25
|
+
* const proof = await generateProof(data, bindingContext)
|
|
26
|
+
*
|
|
27
|
+
* // 3. Return artifact
|
|
28
|
+
* return {
|
|
29
|
+
* program_id: this.programId,
|
|
30
|
+
* result: 'pass',
|
|
31
|
+
* public: { ... },
|
|
32
|
+
* zk: { ... }
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
interface ProgramExecutor {
|
|
39
|
+
/**
|
|
40
|
+
* Unique program identifier this executor handles
|
|
41
|
+
* Must match the program_id in ProgramMetadata
|
|
42
|
+
*/
|
|
43
|
+
readonly programId: string;
|
|
44
|
+
/**
|
|
45
|
+
* Execute the ZK program and generate proof
|
|
46
|
+
*
|
|
47
|
+
* This method is called automatically when a proof request is received
|
|
48
|
+
* if autoExecuteProofs is enabled in PoeModuleConfig.
|
|
49
|
+
*
|
|
50
|
+
* @param context - Agent context for accessing storage, DID resolver, etc.
|
|
51
|
+
* @param execution - Program execution parameters from requester
|
|
52
|
+
* @param bindingContext - Context binding for anti-replay protection
|
|
53
|
+
* @returns Complete proof artifact ready to submit
|
|
54
|
+
* @throws Error if execution fails (will result in problem report)
|
|
55
|
+
*/
|
|
56
|
+
execute(context: AgentContext, execution: ProgramExecution, bindingContext: BindingContext): Promise<ProofArtifact>;
|
|
57
|
+
/**
|
|
58
|
+
* Optional: Validate that this executor can handle the request
|
|
59
|
+
*
|
|
60
|
+
* Called before execute() to check if prerequisites are met.
|
|
61
|
+
* Useful for checking if required data exists, parameters are valid, etc.
|
|
62
|
+
*
|
|
63
|
+
* @param context - Agent context
|
|
64
|
+
* @param execution - Program execution parameters
|
|
65
|
+
* @returns Error message if cannot execute, undefined if can execute
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* async canExecute(context, execution) {
|
|
70
|
+
* const dataId = execution.inputs?.by_reference?.data_id
|
|
71
|
+
* if (!dataId) return 'Missing required data_id'
|
|
72
|
+
*
|
|
73
|
+
* const exists = await checkDataExists(context, dataId)
|
|
74
|
+
* if (!exists) return `Data not found: ${dataId}`
|
|
75
|
+
*
|
|
76
|
+
* return undefined // Can execute
|
|
77
|
+
* }
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
canExecute?(context: AgentContext, execution: ProgramExecution): Promise<string | undefined>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Interface for ZK proof verifiers.
|
|
84
|
+
*
|
|
85
|
+
* Verifiers provide custom verification logic beyond the generic
|
|
86
|
+
* verification performed by ProofVerificationService.
|
|
87
|
+
*
|
|
88
|
+
* If a custom verifier is registered, it takes precedence over
|
|
89
|
+
* the generic verification logic.
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* export class MyVerifier implements ProofVerifier {
|
|
94
|
+
* programId = 'my.program.v1'
|
|
95
|
+
*
|
|
96
|
+
* async verify(context, artifact, expectedContext) {
|
|
97
|
+
* // 1. Check binding context
|
|
98
|
+
* if (artifact.public.nonce !== expectedContext.nonce) {
|
|
99
|
+
* return { verified: false, errors: ['Nonce mismatch'] }
|
|
100
|
+
* }
|
|
101
|
+
*
|
|
102
|
+
* // 2. Custom verification logic
|
|
103
|
+
* const valid = await myCustomVerification(artifact)
|
|
104
|
+
*
|
|
105
|
+
* return { verified: valid }
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
interface ProofVerifier {
|
|
111
|
+
/**
|
|
112
|
+
* Unique program identifier this verifier handles
|
|
113
|
+
* Must match the program_id in ProgramMetadata
|
|
114
|
+
*/
|
|
115
|
+
readonly programId: string;
|
|
116
|
+
/**
|
|
117
|
+
* Verify a proof artifact with custom logic
|
|
118
|
+
*
|
|
119
|
+
* This method is called instead of generic verification if registered.
|
|
120
|
+
* Should perform all necessary verification including:
|
|
121
|
+
* - Binding context validation
|
|
122
|
+
* - ZK proof cryptographic verification
|
|
123
|
+
* - Program-specific constraints
|
|
124
|
+
*
|
|
125
|
+
* @param context - Agent context
|
|
126
|
+
* @param artifact - The proof artifact to verify
|
|
127
|
+
* @param expectedContext - The expected binding context
|
|
128
|
+
* @returns Verification result
|
|
129
|
+
*/
|
|
130
|
+
verify(context: AgentContext, artifact: ProofArtifact, expectedContext: BindingContext): Promise<{
|
|
131
|
+
verified: boolean;
|
|
132
|
+
errors?: string[];
|
|
133
|
+
warnings?: string[];
|
|
134
|
+
}>;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Factory function type for creating executors
|
|
138
|
+
* Useful when executors need agent-specific initialization
|
|
139
|
+
*/
|
|
140
|
+
type ExecutorFactory = (context: AgentContext) => ProgramExecutor | Promise<ProgramExecutor>;
|
|
141
|
+
/**
|
|
142
|
+
* Factory function type for creating verifiers
|
|
143
|
+
* Useful when verifiers need agent-specific initialization
|
|
144
|
+
*/
|
|
145
|
+
type VerifierFactory = (context: AgentContext) => ProofVerifier | Promise<ProofVerifier>;
|
|
146
|
+
//#endregion
|
|
147
|
+
export { ExecutorFactory, ProgramExecutor, ProofVerifier, VerifierFactory };
|
|
148
|
+
//# sourceMappingURL=ProgramExecutor.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgramExecutor.d.mts","names":[],"sources":["../../src/executor/ProgramExecutor.ts"],"mappings":";;;;;;;;;;AAkCA;;;;;;;;;;;;;;;;;;;;;;;;;;;UAAiB,eAAA;EAmDZ;;;AA+BL;EA/BK,SA9CM,SAAA;;;;;;;;;;;;;EAcT,OAAA,CACE,OAAA,EAAS,YAAA,EACT,SAAA,EAAW,gBAAA,EACX,cAAA,EAAgB,cAAA,GACf,OAAA,CAAQ,aAAA;EAmFQ;;;;;;;;AAYrB;;;;;;;;;;;;;;;EAtEE,UAAA,EACE,OAAA,EAAS,YAAA,EACT,SAAA,EAAW,gBAAA,GACV,OAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UA+BY,aAAA;;;;;WAKN,SAAA;;;;;;;;;;;;;;;EAgBT,MAAA,CACE,OAAA,EAAS,YAAA,EACT,QAAA,EAAU,aAAA,EACV,eAAA,EAAiB,cAAA,GAChB,OAAA;IACD,QAAA;IACA,MAAA;IACA,QAAA;EAAA;AAAA;;;;;KAQQ,eAAA,IAAmB,OAAA,EAAS,YAAA,KAAiB,eAAA,GAAkB,OAAA,CAAQ,eAAA;;;;;KAMvE,eAAA,IAAmB,OAAA,EAAS,YAAA,KAAiB,aAAA,GAAgB,OAAA,CAAQ,aAAA"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { ProgramExecutor, ProofVerifier } from "./ProgramExecutor.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/executor/ProgramExecutorRegistry.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Registry for managing program executors and verifiers.
|
|
6
|
+
*
|
|
7
|
+
* This is a core service in the PoE module that maintains mappings
|
|
8
|
+
* between program IDs and their executor/verifier implementations.
|
|
9
|
+
*
|
|
10
|
+
* Executors are registered during module initialization via PoeModuleConfig.
|
|
11
|
+
*/
|
|
12
|
+
declare class ProgramExecutorRegistry {
|
|
13
|
+
private executors;
|
|
14
|
+
private verifiers;
|
|
15
|
+
/**
|
|
16
|
+
* Register a program executor (prover side)
|
|
17
|
+
*
|
|
18
|
+
* @param executor - The executor implementation
|
|
19
|
+
* @throws PoeError if executor for this program already registered
|
|
20
|
+
*/
|
|
21
|
+
registerExecutor(executor: ProgramExecutor): void;
|
|
22
|
+
/**
|
|
23
|
+
* Register a proof verifier (verifier side)
|
|
24
|
+
*
|
|
25
|
+
* @param verifier - The verifier implementation
|
|
26
|
+
* @throws PoeError if verifier for this program already registered
|
|
27
|
+
*/
|
|
28
|
+
registerVerifier(verifier: ProofVerifier): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get executor for a program
|
|
31
|
+
*
|
|
32
|
+
* @param programId - The program identifier
|
|
33
|
+
* @returns Executor if registered, undefined otherwise
|
|
34
|
+
*/
|
|
35
|
+
getExecutor(programId: string): ProgramExecutor | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Get verifier for a program
|
|
38
|
+
*
|
|
39
|
+
* @param programId - The program identifier
|
|
40
|
+
* @returns Verifier if registered, undefined otherwise
|
|
41
|
+
*/
|
|
42
|
+
getVerifier(programId: string): ProofVerifier | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Check if executor is registered for a program
|
|
45
|
+
*
|
|
46
|
+
* @param programId - The program identifier
|
|
47
|
+
* @returns True if executor registered, false otherwise
|
|
48
|
+
*/
|
|
49
|
+
hasExecutor(programId: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Check if verifier is registered for a program
|
|
52
|
+
*
|
|
53
|
+
* @param programId - The program identifier
|
|
54
|
+
* @returns True if verifier registered, false otherwise
|
|
55
|
+
*/
|
|
56
|
+
hasVerifier(programId: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Get all registered executor program IDs
|
|
59
|
+
*
|
|
60
|
+
* @returns Array of program IDs with executors
|
|
61
|
+
*/
|
|
62
|
+
getAllExecutorIds(): string[];
|
|
63
|
+
/**
|
|
64
|
+
* Get all registered verifier program IDs
|
|
65
|
+
*
|
|
66
|
+
* @returns Array of program IDs with verifiers
|
|
67
|
+
*/
|
|
68
|
+
getAllVerifierIds(): string[];
|
|
69
|
+
/**
|
|
70
|
+
* Unregister an executor
|
|
71
|
+
*
|
|
72
|
+
* @param programId - The program identifier
|
|
73
|
+
* @returns True if executor was removed, false if not found
|
|
74
|
+
*/
|
|
75
|
+
unregisterExecutor(programId: string): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Unregister a verifier
|
|
78
|
+
*
|
|
79
|
+
* @param programId - The program identifier
|
|
80
|
+
* @returns True if verifier was removed, false if not found
|
|
81
|
+
*/
|
|
82
|
+
unregisterVerifier(programId: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Get all registered executors (for debugging/introspection)
|
|
85
|
+
*
|
|
86
|
+
* @returns Map of program IDs to executors
|
|
87
|
+
*/
|
|
88
|
+
getAllExecutors(): Map<string, ProgramExecutor>;
|
|
89
|
+
/**
|
|
90
|
+
* Get all registered verifiers (for debugging/introspection)
|
|
91
|
+
*
|
|
92
|
+
* @returns Map of program IDs to verifiers
|
|
93
|
+
*/
|
|
94
|
+
getAllVerifiers(): Map<string, ProofVerifier>;
|
|
95
|
+
/**
|
|
96
|
+
* Clear all registered executors and verifiers
|
|
97
|
+
* Useful for testing
|
|
98
|
+
*/
|
|
99
|
+
clear(): void;
|
|
100
|
+
/**
|
|
101
|
+
* Get count of registered executors
|
|
102
|
+
*/
|
|
103
|
+
get executorCount(): number;
|
|
104
|
+
/**
|
|
105
|
+
* Get count of registered verifiers
|
|
106
|
+
*/
|
|
107
|
+
get verifierCount(): number;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { ProgramExecutorRegistry };
|
|
111
|
+
//# sourceMappingURL=ProgramExecutorRegistry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgramExecutorRegistry.d.mts","names":[],"sources":["../../src/executor/ProgramExecutorRegistry.ts"],"mappings":";;;;;AAYA;;;;;;cACa,uBAAA;EAAA,QACH,SAAA;EAAA,QACA,SAAA;EAoI8B;;;;;;EA5H/B,gBAAA,CAAiB,QAAA,EAAU,eAAA;EAAA;;;;;;EAmB3B,gBAAA,CAAiB,QAAA,EAAU,aAAA;EAmBK;;;;;;EAAhC,WAAA,CAAY,SAAA,WAAoB,eAAA;EA8BpB;;;;;;EApBZ,WAAA,CAAY,SAAA,WAAoB,aAAA;EAmEhC;;;;;;EAzDA,WAAA,CAAY,SAAA;EAkFR;;;;;;EAxEJ,WAAA,CAAY,SAAA;;;;;;EASZ,iBAAA,CAAA;;;;;;EASA,iBAAA,CAAA;;;;;;;EAUA,kBAAA,CAAmB,SAAA;;;;;;;EAUnB,kBAAA,CAAmB,SAAA;;;;;;EASnB,eAAA,CAAA,GAAmB,GAAA,SAAY,eAAA;;;;;;EAS/B,eAAA,CAAA,GAAmB,GAAA,SAAY,aAAA;;;;;EAQ/B,KAAA,CAAA;;;;MAQI,aAAA,CAAA;;;;MAOA,aAAA,CAAA;AAAA"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { PoeError } from "../errors/PoeError.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
4
|
+
import { injectable } from "tsyringe";
|
|
5
|
+
|
|
6
|
+
//#region src/executor/ProgramExecutorRegistry.ts
|
|
7
|
+
let ProgramExecutorRegistry = class ProgramExecutorRegistry {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.executors = /* @__PURE__ */ new Map();
|
|
10
|
+
this.verifiers = /* @__PURE__ */ new Map();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Register a program executor (prover side)
|
|
14
|
+
*
|
|
15
|
+
* @param executor - The executor implementation
|
|
16
|
+
* @throws PoeError if executor for this program already registered
|
|
17
|
+
*/
|
|
18
|
+
registerExecutor(executor) {
|
|
19
|
+
const programId = executor.programId;
|
|
20
|
+
if (this.executors.has(programId)) throw new PoeError(`Executor for program ${programId} already registered. Use unregisterExecutor() first if you need to replace it.`);
|
|
21
|
+
this.executors.set(programId, executor);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Register a proof verifier (verifier side)
|
|
25
|
+
*
|
|
26
|
+
* @param verifier - The verifier implementation
|
|
27
|
+
* @throws PoeError if verifier for this program already registered
|
|
28
|
+
*/
|
|
29
|
+
registerVerifier(verifier) {
|
|
30
|
+
const programId = verifier.programId;
|
|
31
|
+
if (this.verifiers.has(programId)) throw new PoeError(`Verifier for program ${programId} already registered. Use unregisterVerifier() first if you need to replace it.`);
|
|
32
|
+
this.verifiers.set(programId, verifier);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get executor for a program
|
|
36
|
+
*
|
|
37
|
+
* @param programId - The program identifier
|
|
38
|
+
* @returns Executor if registered, undefined otherwise
|
|
39
|
+
*/
|
|
40
|
+
getExecutor(programId) {
|
|
41
|
+
return this.executors.get(programId);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get verifier for a program
|
|
45
|
+
*
|
|
46
|
+
* @param programId - The program identifier
|
|
47
|
+
* @returns Verifier if registered, undefined otherwise
|
|
48
|
+
*/
|
|
49
|
+
getVerifier(programId) {
|
|
50
|
+
return this.verifiers.get(programId);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if executor is registered for a program
|
|
54
|
+
*
|
|
55
|
+
* @param programId - The program identifier
|
|
56
|
+
* @returns True if executor registered, false otherwise
|
|
57
|
+
*/
|
|
58
|
+
hasExecutor(programId) {
|
|
59
|
+
return this.executors.has(programId);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Check if verifier is registered for a program
|
|
63
|
+
*
|
|
64
|
+
* @param programId - The program identifier
|
|
65
|
+
* @returns True if verifier registered, false otherwise
|
|
66
|
+
*/
|
|
67
|
+
hasVerifier(programId) {
|
|
68
|
+
return this.verifiers.has(programId);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get all registered executor program IDs
|
|
72
|
+
*
|
|
73
|
+
* @returns Array of program IDs with executors
|
|
74
|
+
*/
|
|
75
|
+
getAllExecutorIds() {
|
|
76
|
+
return Array.from(this.executors.keys());
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get all registered verifier program IDs
|
|
80
|
+
*
|
|
81
|
+
* @returns Array of program IDs with verifiers
|
|
82
|
+
*/
|
|
83
|
+
getAllVerifierIds() {
|
|
84
|
+
return Array.from(this.verifiers.keys());
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Unregister an executor
|
|
88
|
+
*
|
|
89
|
+
* @param programId - The program identifier
|
|
90
|
+
* @returns True if executor was removed, false if not found
|
|
91
|
+
*/
|
|
92
|
+
unregisterExecutor(programId) {
|
|
93
|
+
return this.executors.delete(programId);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Unregister a verifier
|
|
97
|
+
*
|
|
98
|
+
* @param programId - The program identifier
|
|
99
|
+
* @returns True if verifier was removed, false if not found
|
|
100
|
+
*/
|
|
101
|
+
unregisterVerifier(programId) {
|
|
102
|
+
return this.verifiers.delete(programId);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get all registered executors (for debugging/introspection)
|
|
106
|
+
*
|
|
107
|
+
* @returns Map of program IDs to executors
|
|
108
|
+
*/
|
|
109
|
+
getAllExecutors() {
|
|
110
|
+
return new Map(this.executors);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get all registered verifiers (for debugging/introspection)
|
|
114
|
+
*
|
|
115
|
+
* @returns Map of program IDs to verifiers
|
|
116
|
+
*/
|
|
117
|
+
getAllVerifiers() {
|
|
118
|
+
return new Map(this.verifiers);
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Clear all registered executors and verifiers
|
|
122
|
+
* Useful for testing
|
|
123
|
+
*/
|
|
124
|
+
clear() {
|
|
125
|
+
this.executors.clear();
|
|
126
|
+
this.verifiers.clear();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Get count of registered executors
|
|
130
|
+
*/
|
|
131
|
+
get executorCount() {
|
|
132
|
+
return this.executors.size;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Get count of registered verifiers
|
|
136
|
+
*/
|
|
137
|
+
get verifierCount() {
|
|
138
|
+
return this.verifiers.size;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
ProgramExecutorRegistry = __decorate([injectable()], ProgramExecutorRegistry);
|
|
142
|
+
|
|
143
|
+
//#endregion
|
|
144
|
+
export { ProgramExecutorRegistry };
|
|
145
|
+
//# sourceMappingURL=ProgramExecutorRegistry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgramExecutorRegistry.mjs","names":[],"sources":["../../src/executor/ProgramExecutorRegistry.ts"],"sourcesContent":["import { injectable } from 'tsyringe'\nimport type { ProgramExecutor, ProofVerifier } from './ProgramExecutor'\nimport { PoeError } from '../errors'\n\n/**\n * Registry for managing program executors and verifiers.\n *\n * This is a core service in the PoE module that maintains mappings\n * between program IDs and their executor/verifier implementations.\n *\n * Executors are registered during module initialization via PoeModuleConfig.\n */\n@injectable()\nexport class ProgramExecutorRegistry {\n private executors = new Map<string, ProgramExecutor>()\n private verifiers = new Map<string, ProofVerifier>()\n\n /**\n * Register a program executor (prover side)\n *\n * @param executor - The executor implementation\n * @throws PoeError if executor for this program already registered\n */\n public registerExecutor(executor: ProgramExecutor): void {\n const programId = executor.programId\n\n if (this.executors.has(programId)) {\n throw new PoeError(\n `Executor for program ${programId} already registered. ` +\n `Use unregisterExecutor() first if you need to replace it.`\n )\n }\n\n this.executors.set(programId, executor)\n }\n\n /**\n * Register a proof verifier (verifier side)\n *\n * @param verifier - The verifier implementation\n * @throws PoeError if verifier for this program already registered\n */\n public registerVerifier(verifier: ProofVerifier): void {\n const programId = verifier.programId\n\n if (this.verifiers.has(programId)) {\n throw new PoeError(\n `Verifier for program ${programId} already registered. ` +\n `Use unregisterVerifier() first if you need to replace it.`\n )\n }\n\n this.verifiers.set(programId, verifier)\n }\n\n /**\n * Get executor for a program\n *\n * @param programId - The program identifier\n * @returns Executor if registered, undefined otherwise\n */\n public getExecutor(programId: string): ProgramExecutor | undefined {\n return this.executors.get(programId)\n }\n\n /**\n * Get verifier for a program\n *\n * @param programId - The program identifier\n * @returns Verifier if registered, undefined otherwise\n */\n public getVerifier(programId: string): ProofVerifier | undefined {\n return this.verifiers.get(programId)\n }\n\n /**\n * Check if executor is registered for a program\n *\n * @param programId - The program identifier\n * @returns True if executor registered, false otherwise\n */\n public hasExecutor(programId: string): boolean {\n return this.executors.has(programId)\n }\n\n /**\n * Check if verifier is registered for a program\n *\n * @param programId - The program identifier\n * @returns True if verifier registered, false otherwise\n */\n public hasVerifier(programId: string): boolean {\n return this.verifiers.has(programId)\n }\n\n /**\n * Get all registered executor program IDs\n *\n * @returns Array of program IDs with executors\n */\n public getAllExecutorIds(): string[] {\n return Array.from(this.executors.keys())\n }\n\n /**\n * Get all registered verifier program IDs\n *\n * @returns Array of program IDs with verifiers\n */\n public getAllVerifierIds(): string[] {\n return Array.from(this.verifiers.keys())\n }\n\n /**\n * Unregister an executor\n *\n * @param programId - The program identifier\n * @returns True if executor was removed, false if not found\n */\n public unregisterExecutor(programId: string): boolean {\n return this.executors.delete(programId)\n }\n\n /**\n * Unregister a verifier\n *\n * @param programId - The program identifier\n * @returns True if verifier was removed, false if not found\n */\n public unregisterVerifier(programId: string): boolean {\n return this.verifiers.delete(programId)\n }\n\n /**\n * Get all registered executors (for debugging/introspection)\n *\n * @returns Map of program IDs to executors\n */\n public getAllExecutors(): Map<string, ProgramExecutor> {\n return new Map(this.executors)\n }\n\n /**\n * Get all registered verifiers (for debugging/introspection)\n *\n * @returns Map of program IDs to verifiers\n */\n public getAllVerifiers(): Map<string, ProofVerifier> {\n return new Map(this.verifiers)\n }\n\n /**\n * Clear all registered executors and verifiers\n * Useful for testing\n */\n public clear(): void {\n this.executors.clear()\n this.verifiers.clear()\n }\n\n /**\n * Get count of registered executors\n */\n public get executorCount(): number {\n return this.executors.size\n }\n\n /**\n * Get count of registered verifiers\n */\n public get verifierCount(): number {\n return this.verifiers.size\n }\n}\n"],"mappings":";;;;;;AAaO,oCAAM,wBAAwB;;OAC3B,4BAAY,IAAI,KAA8B;OAC9C,4BAAY,IAAI,KAA4B;;;;;;;;CAQpD,AAAO,iBAAiB,UAAiC;EACvD,MAAM,YAAY,SAAS;AAE3B,MAAI,KAAK,UAAU,IAAI,UAAU,CAC/B,OAAM,IAAI,SACR,wBAAwB,UAAU,gFAEnC;AAGH,OAAK,UAAU,IAAI,WAAW,SAAS;;;;;;;;CASzC,AAAO,iBAAiB,UAA+B;EACrD,MAAM,YAAY,SAAS;AAE3B,MAAI,KAAK,UAAU,IAAI,UAAU,CAC/B,OAAM,IAAI,SACR,wBAAwB,UAAU,gFAEnC;AAGH,OAAK,UAAU,IAAI,WAAW,SAAS;;;;;;;;CASzC,AAAO,YAAY,WAAgD;AACjE,SAAO,KAAK,UAAU,IAAI,UAAU;;;;;;;;CAStC,AAAO,YAAY,WAA8C;AAC/D,SAAO,KAAK,UAAU,IAAI,UAAU;;;;;;;;CAStC,AAAO,YAAY,WAA4B;AAC7C,SAAO,KAAK,UAAU,IAAI,UAAU;;;;;;;;CAStC,AAAO,YAAY,WAA4B;AAC7C,SAAO,KAAK,UAAU,IAAI,UAAU;;;;;;;CAQtC,AAAO,oBAA8B;AACnC,SAAO,MAAM,KAAK,KAAK,UAAU,MAAM,CAAC;;;;;;;CAQ1C,AAAO,oBAA8B;AACnC,SAAO,MAAM,KAAK,KAAK,UAAU,MAAM,CAAC;;;;;;;;CAS1C,AAAO,mBAAmB,WAA4B;AACpD,SAAO,KAAK,UAAU,OAAO,UAAU;;;;;;;;CASzC,AAAO,mBAAmB,WAA4B;AACpD,SAAO,KAAK,UAAU,OAAO,UAAU;;;;;;;CAQzC,AAAO,kBAAgD;AACrD,SAAO,IAAI,IAAI,KAAK,UAAU;;;;;;;CAQhC,AAAO,kBAA8C;AACnD,SAAO,IAAI,IAAI,KAAK,UAAU;;;;;;CAOhC,AAAO,QAAc;AACnB,OAAK,UAAU,OAAO;AACtB,OAAK,UAAU,OAAO;;;;;CAMxB,IAAW,gBAAwB;AACjC,SAAO,KAAK,UAAU;;;;;CAMxB,IAAW,gBAAwB;AACjC,SAAO,KAAK,UAAU;;;sCA/JzB,YAAY"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { BindingContext } from "../../models/BindingContext.mjs";
|
|
2
|
+
import { ProgramExecution } from "../../models/ProgramExecution.mjs";
|
|
3
|
+
import { ProofArtifact } from "../../models/ProofArtifact.mjs";
|
|
4
|
+
import { ProgramExecutor } from "../ProgramExecutor.mjs";
|
|
5
|
+
import { AgentContext } from "@credo-ts/core";
|
|
6
|
+
|
|
7
|
+
//#region src/executor/__mocks__/MockProgramExecutor.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* Mock ZK program executor for testing.
|
|
10
|
+
*
|
|
11
|
+
* Simulates proof generation without actual cryptographic computation.
|
|
12
|
+
* Useful for integration tests and development.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const mockExecutor = new MockProgramExecutor('mock-age-check', {
|
|
17
|
+
* executionDelayMs: 100, // Simulate processing time
|
|
18
|
+
* shouldFail: false,
|
|
19
|
+
* result: { age_over_18: true }
|
|
20
|
+
* })
|
|
21
|
+
*
|
|
22
|
+
* const agent = new Agent({
|
|
23
|
+
* modules: {
|
|
24
|
+
* poe: new PoeModule({
|
|
25
|
+
* executors: [mockExecutor],
|
|
26
|
+
* autoExecuteProofs: true
|
|
27
|
+
* })
|
|
28
|
+
* }
|
|
29
|
+
* })
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
declare class MockProgramExecutor implements ProgramExecutor {
|
|
33
|
+
readonly programId: string;
|
|
34
|
+
private options;
|
|
35
|
+
/**
|
|
36
|
+
* Create a new mock executor
|
|
37
|
+
*
|
|
38
|
+
* @param programId - Program identifier (e.g., 'mock-age-check')
|
|
39
|
+
* @param options - Mock behavior options
|
|
40
|
+
*/
|
|
41
|
+
constructor(programId: string, options?: MockExecutorOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Validate if this executor can handle the request
|
|
44
|
+
*
|
|
45
|
+
* Returns an error message if validation fails, undefined otherwise.
|
|
46
|
+
*/
|
|
47
|
+
canExecute(context: AgentContext, execution: ProgramExecution): Promise<string | undefined>;
|
|
48
|
+
/**
|
|
49
|
+
* Execute the mock proof generation
|
|
50
|
+
*
|
|
51
|
+
* Returns a simulated proof artifact with mock cryptographic data.
|
|
52
|
+
*/
|
|
53
|
+
execute(context: AgentContext, execution: ProgramExecution, bindingContext: BindingContext): Promise<ProofArtifact>;
|
|
54
|
+
/**
|
|
55
|
+
* Helper to introduce async delay
|
|
56
|
+
*/
|
|
57
|
+
private delay;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Configuration options for MockProgramExecutor
|
|
61
|
+
*/
|
|
62
|
+
interface MockExecutorOptions {
|
|
63
|
+
/**
|
|
64
|
+
* Delay in milliseconds to simulate proof generation time
|
|
65
|
+
* @default 0
|
|
66
|
+
*/
|
|
67
|
+
executionDelayMs?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Whether execution should fail with an error
|
|
70
|
+
* @default false
|
|
71
|
+
*/
|
|
72
|
+
shouldFail?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Error message if shouldFail is true
|
|
75
|
+
*/
|
|
76
|
+
errorMessage?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Whether validation (canExecute) should fail
|
|
79
|
+
* @default false
|
|
80
|
+
*/
|
|
81
|
+
shouldFailValidation?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Validation error message if shouldFailValidation is true
|
|
84
|
+
*/
|
|
85
|
+
validationError?: string;
|
|
86
|
+
/**
|
|
87
|
+
* Mock result (pass/fail/partial)
|
|
88
|
+
* @default 'pass'
|
|
89
|
+
*/
|
|
90
|
+
result?: 'pass' | 'fail' | 'partial';
|
|
91
|
+
/**
|
|
92
|
+
* Mock verifying key hash
|
|
93
|
+
* @default '0x' + '1'.repeat(64)
|
|
94
|
+
*/
|
|
95
|
+
mockVkHash?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Mock proof data (base64 encoded)
|
|
98
|
+
* @default Buffer.from('mock-proof-data').toString('base64')
|
|
99
|
+
*/
|
|
100
|
+
mockProofB64?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Mock proof scheme name
|
|
103
|
+
* @default 'mock-plonk'
|
|
104
|
+
*/
|
|
105
|
+
mockScheme?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Public schema identifier
|
|
108
|
+
* @default 'mock-schema-1.0'
|
|
109
|
+
*/
|
|
110
|
+
publicSchema?: string;
|
|
111
|
+
/**
|
|
112
|
+
* Additional public outputs to include in proof artifact
|
|
113
|
+
*/
|
|
114
|
+
publicOutputs?: Record<string, unknown>;
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
export { MockExecutorOptions, MockProgramExecutor };
|
|
118
|
+
//# sourceMappingURL=MockProgramExecutor.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockProgramExecutor.d.mts","names":[],"sources":["../../../src/executor/__mocks__/MockProgramExecutor.ts"],"mappings":";;;;;;;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;cAAa,mBAAA,YAA+B,eAAA;EAAA,SAC1B,SAAA;EAAA,QAER,OAAA;EA4BG;;;;;;cApBQ,SAAA,UAAmB,OAAA,GAAS,mBAAA;EAyC7C;;;;;EAtBW,UAAA,CACX,OAAA,EAAS,YAAA,EACT,SAAA,EAAW,gBAAA,GACV,OAAA;EAsBQ;;;;AAmDb;EAvDe,OAAA,CACX,OAAA,EAAS,YAAA,EACT,SAAA,EAAW,gBAAA,EACX,cAAA,EAAgB,cAAA,GACf,OAAA,CAAQ,aAAA;;;;UA2CH,KAAA;AAAA;;;;UAQO,mBAAA;EA6Cf;;;;EAxCA,gBAAA;EAyDsB;;;;EAnDtB,UAAA;;;;EAKA,YAAA;;;;;EAMA,oBAAA;;;;EAKA,eAAA;;;;;EAMA,MAAA;;;;;EAMA,UAAA;;;;;EAMA,YAAA;;;;;EAMA,UAAA;;;;;EAMA,YAAA;;;;EAKA,aAAA,GAAgB,MAAA;AAAA"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
//#region src/executor/__mocks__/MockProgramExecutor.ts
|
|
2
|
+
/**
|
|
3
|
+
* Mock ZK program executor for testing.
|
|
4
|
+
*
|
|
5
|
+
* Simulates proof generation without actual cryptographic computation.
|
|
6
|
+
* Useful for integration tests and development.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const mockExecutor = new MockProgramExecutor('mock-age-check', {
|
|
11
|
+
* executionDelayMs: 100, // Simulate processing time
|
|
12
|
+
* shouldFail: false,
|
|
13
|
+
* result: { age_over_18: true }
|
|
14
|
+
* })
|
|
15
|
+
*
|
|
16
|
+
* const agent = new Agent({
|
|
17
|
+
* modules: {
|
|
18
|
+
* poe: new PoeModule({
|
|
19
|
+
* executors: [mockExecutor],
|
|
20
|
+
* autoExecuteProofs: true
|
|
21
|
+
* })
|
|
22
|
+
* }
|
|
23
|
+
* })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
var MockProgramExecutor = class {
|
|
27
|
+
/**
|
|
28
|
+
* Create a new mock executor
|
|
29
|
+
*
|
|
30
|
+
* @param programId - Program identifier (e.g., 'mock-age-check')
|
|
31
|
+
* @param options - Mock behavior options
|
|
32
|
+
*/
|
|
33
|
+
constructor(programId, options = {}) {
|
|
34
|
+
this.programId = programId;
|
|
35
|
+
this.options = {
|
|
36
|
+
executionDelayMs: 0,
|
|
37
|
+
shouldFail: false,
|
|
38
|
+
shouldFailValidation: false,
|
|
39
|
+
validationError: "Mock validation failed",
|
|
40
|
+
mockVkHash: "0x" + "1".repeat(64),
|
|
41
|
+
mockProofB64: Buffer.from("mock-proof-data").toString("base64"),
|
|
42
|
+
publicSchema: "mock-schema-1.0",
|
|
43
|
+
...options
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validate if this executor can handle the request
|
|
48
|
+
*
|
|
49
|
+
* Returns an error message if validation fails, undefined otherwise.
|
|
50
|
+
*/
|
|
51
|
+
async canExecute(context, execution) {
|
|
52
|
+
if (this.options.shouldFailValidation) return this.options.validationError;
|
|
53
|
+
if (execution.program_id !== this.programId) return `Program ID mismatch: expected ${this.programId}, got ${execution.program_id}`;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Execute the mock proof generation
|
|
57
|
+
*
|
|
58
|
+
* Returns a simulated proof artifact with mock cryptographic data.
|
|
59
|
+
*/
|
|
60
|
+
async execute(context, execution, bindingContext) {
|
|
61
|
+
if (this.options.executionDelayMs && this.options.executionDelayMs > 0) await this.delay(this.options.executionDelayMs);
|
|
62
|
+
if (this.options.shouldFail) throw new Error(this.options.errorMessage || "Mock executor failed");
|
|
63
|
+
const result = this.options.result || "pass";
|
|
64
|
+
const vkHash = this.options.mockVkHash;
|
|
65
|
+
const proofB64 = this.options.mockProofB64;
|
|
66
|
+
return {
|
|
67
|
+
program_id: this.programId,
|
|
68
|
+
result,
|
|
69
|
+
zk: {
|
|
70
|
+
scheme: this.options.mockScheme || "mock-plonk",
|
|
71
|
+
circuit_id: execution.program_id,
|
|
72
|
+
vk_hash: vkHash,
|
|
73
|
+
proof_b64: proofB64
|
|
74
|
+
},
|
|
75
|
+
public: {
|
|
76
|
+
schema: this.options.publicSchema || "mock-schema-1.0",
|
|
77
|
+
nonce: bindingContext.nonce,
|
|
78
|
+
context_hash: bindingContext.context_hash,
|
|
79
|
+
session_id: bindingContext.session_id,
|
|
80
|
+
vk_hash: vkHash,
|
|
81
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
82
|
+
...this.options.publicOutputs
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Helper to introduce async delay
|
|
88
|
+
*/
|
|
89
|
+
delay(ms) {
|
|
90
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
export { MockProgramExecutor };
|
|
96
|
+
//# sourceMappingURL=MockProgramExecutor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockProgramExecutor.mjs","names":[],"sources":["../../../src/executor/__mocks__/MockProgramExecutor.ts"],"sourcesContent":["import type { AgentContext } from '@credo-ts/core'\nimport type { ProgramExecutor } from '../ProgramExecutor'\nimport type { ProgramExecution, BindingContext, ProofArtifact } from '../../models'\n\n/**\n * Mock ZK program executor for testing.\n *\n * Simulates proof generation without actual cryptographic computation.\n * Useful for integration tests and development.\n *\n * @example\n * ```typescript\n * const mockExecutor = new MockProgramExecutor('mock-age-check', {\n * executionDelayMs: 100, // Simulate processing time\n * shouldFail: false,\n * result: { age_over_18: true }\n * })\n *\n * const agent = new Agent({\n * modules: {\n * poe: new PoeModule({\n * executors: [mockExecutor],\n * autoExecuteProofs: true\n * })\n * }\n * })\n * ```\n */\nexport class MockProgramExecutor implements ProgramExecutor {\n public readonly programId: string\n\n private options: MockExecutorOptions\n\n /**\n * Create a new mock executor\n *\n * @param programId - Program identifier (e.g., 'mock-age-check')\n * @param options - Mock behavior options\n */\n public constructor(programId: string, options: MockExecutorOptions = {}) {\n this.programId = programId\n this.options = {\n executionDelayMs: 0,\n shouldFail: false,\n shouldFailValidation: false,\n validationError: 'Mock validation failed',\n mockVkHash: '0x' + '1'.repeat(64),\n mockProofB64: Buffer.from('mock-proof-data').toString('base64'),\n publicSchema: 'mock-schema-1.0',\n ...options,\n }\n }\n\n /**\n * Validate if this executor can handle the request\n *\n * Returns an error message if validation fails, undefined otherwise.\n */\n public async canExecute(\n context: AgentContext,\n execution: ProgramExecution\n ): Promise<string | undefined> {\n if (this.options.shouldFailValidation) {\n return this.options.validationError\n }\n\n // Validate program ID matches\n if (execution.program_id !== this.programId) {\n return `Program ID mismatch: expected ${this.programId}, got ${execution.program_id}`\n }\n\n return undefined\n }\n\n /**\n * Execute the mock proof generation\n *\n * Returns a simulated proof artifact with mock cryptographic data.\n */\n public async execute(\n context: AgentContext,\n execution: ProgramExecution,\n bindingContext: BindingContext\n ): Promise<ProofArtifact> {\n // Simulate processing delay\n if (this.options.executionDelayMs && this.options.executionDelayMs > 0) {\n await this.delay(this.options.executionDelayMs)\n }\n\n // Simulate execution failure\n if (this.options.shouldFail) {\n throw new Error(this.options.errorMessage || 'Mock executor failed')\n }\n\n // Generate mock proof artifact\n const result = this.options.result || 'pass'\n const vkHash = this.options.mockVkHash!\n const proofB64 = this.options.mockProofB64!\n\n const proofArtifact: ProofArtifact = {\n program_id: this.programId,\n result,\n zk: {\n scheme: this.options.mockScheme || 'mock-plonk',\n circuit_id: execution.program_id, // Use program_id as circuit_id\n vk_hash: vkHash,\n proof_b64: proofB64,\n },\n public: {\n schema: this.options.publicSchema || 'mock-schema-1.0',\n nonce: bindingContext.nonce,\n context_hash: bindingContext.context_hash,\n session_id: bindingContext.session_id,\n vk_hash: vkHash,\n timestamp: new Date().toISOString(),\n // Include any public outputs from execution\n ...this.options.publicOutputs,\n },\n }\n\n return proofArtifact\n }\n\n /**\n * Helper to introduce async delay\n */\n private delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n }\n}\n\n/**\n * Configuration options for MockProgramExecutor\n */\nexport interface MockExecutorOptions {\n /**\n * Delay in milliseconds to simulate proof generation time\n * @default 0\n */\n executionDelayMs?: number\n\n /**\n * Whether execution should fail with an error\n * @default false\n */\n shouldFail?: boolean\n\n /**\n * Error message if shouldFail is true\n */\n errorMessage?: string\n\n /**\n * Whether validation (canExecute) should fail\n * @default false\n */\n shouldFailValidation?: boolean\n\n /**\n * Validation error message if shouldFailValidation is true\n */\n validationError?: string\n\n /**\n * Mock result (pass/fail/partial)\n * @default 'pass'\n */\n result?: 'pass' | 'fail' | 'partial'\n\n /**\n * Mock verifying key hash\n * @default '0x' + '1'.repeat(64)\n */\n mockVkHash?: string\n\n /**\n * Mock proof data (base64 encoded)\n * @default Buffer.from('mock-proof-data').toString('base64')\n */\n mockProofB64?: string\n\n /**\n * Mock proof scheme name\n * @default 'mock-plonk'\n */\n mockScheme?: string\n\n /**\n * Public schema identifier\n * @default 'mock-schema-1.0'\n */\n publicSchema?: string\n\n /**\n * Additional public outputs to include in proof artifact\n */\n publicOutputs?: Record<string, unknown>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,IAAa,sBAAb,MAA4D;;;;;;;CAW1D,AAAO,YAAY,WAAmB,UAA+B,EAAE,EAAE;AACvE,OAAK,YAAY;AACjB,OAAK,UAAU;GACb,kBAAkB;GAClB,YAAY;GACZ,sBAAsB;GACtB,iBAAiB;GACjB,YAAY,OAAO,IAAI,OAAO,GAAG;GACjC,cAAc,OAAO,KAAK,kBAAkB,CAAC,SAAS,SAAS;GAC/D,cAAc;GACd,GAAG;GACJ;;;;;;;CAQH,MAAa,WACX,SACA,WAC6B;AAC7B,MAAI,KAAK,QAAQ,qBACf,QAAO,KAAK,QAAQ;AAItB,MAAI,UAAU,eAAe,KAAK,UAChC,QAAO,iCAAiC,KAAK,UAAU,QAAQ,UAAU;;;;;;;CAW7E,MAAa,QACX,SACA,WACA,gBACwB;AAExB,MAAI,KAAK,QAAQ,oBAAoB,KAAK,QAAQ,mBAAmB,EACnE,OAAM,KAAK,MAAM,KAAK,QAAQ,iBAAiB;AAIjD,MAAI,KAAK,QAAQ,WACf,OAAM,IAAI,MAAM,KAAK,QAAQ,gBAAgB,uBAAuB;EAItE,MAAM,SAAS,KAAK,QAAQ,UAAU;EACtC,MAAM,SAAS,KAAK,QAAQ;EAC5B,MAAM,WAAW,KAAK,QAAQ;AAuB9B,SArBqC;GACnC,YAAY,KAAK;GACjB;GACA,IAAI;IACF,QAAQ,KAAK,QAAQ,cAAc;IACnC,YAAY,UAAU;IACtB,SAAS;IACT,WAAW;IACZ;GACD,QAAQ;IACN,QAAQ,KAAK,QAAQ,gBAAgB;IACrC,OAAO,eAAe;IACtB,cAAc,eAAe;IAC7B,YAAY,eAAe;IAC3B,SAAS;IACT,4BAAW,IAAI,MAAM,EAAC,aAAa;IAEnC,GAAG,KAAK,QAAQ;IACjB;GACF;;;;;CAQH,AAAQ,MAAM,IAA2B;AACvC,SAAO,IAAI,SAAS,YAAY,WAAW,SAAS,GAAG,CAAC"}
|