@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,87 @@
|
|
|
1
|
+
import { ProgramNotSupportedError } 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/registry/ProgramRegistry.ts
|
|
7
|
+
let ProgramRegistry = class ProgramRegistry {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.programs = /* @__PURE__ */ new Map();
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register a new program
|
|
13
|
+
*/
|
|
14
|
+
register(metadata) {
|
|
15
|
+
this.programs.set(metadata.program_id, metadata);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Unregister a program
|
|
19
|
+
*/
|
|
20
|
+
unregister(programId) {
|
|
21
|
+
return this.programs.delete(programId);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get program metadata by ID
|
|
25
|
+
* @throws {ProgramNotSupportedError} if program not found
|
|
26
|
+
*/
|
|
27
|
+
getById(programId) {
|
|
28
|
+
const program = this.programs.get(programId);
|
|
29
|
+
if (!program) throw new ProgramNotSupportedError(programId);
|
|
30
|
+
return program;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Find program metadata by ID (returns undefined if not found)
|
|
34
|
+
*/
|
|
35
|
+
findById(programId) {
|
|
36
|
+
return this.programs.get(programId);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a program is supported
|
|
40
|
+
*/
|
|
41
|
+
isSupported(programId) {
|
|
42
|
+
return this.programs.has(programId);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get all registered programs
|
|
46
|
+
*/
|
|
47
|
+
getAllPrograms() {
|
|
48
|
+
return Array.from(this.programs.values());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check if a verifying key hash is allowed for a program
|
|
52
|
+
*/
|
|
53
|
+
isVkAllowed(programId, vkHash) {
|
|
54
|
+
return this.getById(programId).allowed_vk_hashes.includes(vkHash);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if program parameters hash is allowed
|
|
58
|
+
*/
|
|
59
|
+
isParamsAllowed(programId, paramsHash) {
|
|
60
|
+
const program = this.getById(programId);
|
|
61
|
+
if (!program.allowed_params_hashes || program.allowed_params_hashes.length === 0) return true;
|
|
62
|
+
return program.allowed_params_hashes.includes(paramsHash);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get programs that support interactive challenges
|
|
66
|
+
*/
|
|
67
|
+
getInteractivePrograms() {
|
|
68
|
+
return Array.from(this.programs.values()).filter((p) => p.supports_interactive);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clear all registered programs (useful for testing)
|
|
72
|
+
*/
|
|
73
|
+
clear() {
|
|
74
|
+
this.programs.clear();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the count of registered programs
|
|
78
|
+
*/
|
|
79
|
+
get count() {
|
|
80
|
+
return this.programs.size;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
ProgramRegistry = __decorate([injectable()], ProgramRegistry);
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { ProgramRegistry };
|
|
87
|
+
//# sourceMappingURL=ProgramRegistry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgramRegistry.mjs","names":[],"sources":["../../src/registry/ProgramRegistry.ts"],"sourcesContent":["import { injectable } from 'tsyringe'\nimport { ProgramNotSupportedError } from '../errors'\n\n/**\n * Metadata for a registered program\n */\nexport interface ProgramMetadata {\n /**\n * Unique program identifier (e.g., \"vendor.policy.eval.v1\")\n */\n program_id: string\n\n /**\n * Program version\n */\n version: string\n\n /**\n * Human-readable name\n */\n name: string\n\n /**\n * Description of what the program does\n */\n description?: string\n\n /**\n * List of allowed verifying key hashes\n */\n allowed_vk_hashes: string[]\n\n /**\n * List of allowed program parameter hashes (optional)\n */\n allowed_params_hashes?: string[]\n\n /**\n * JSON Schema for public outputs validation\n */\n public_schema: string\n\n /**\n * JSON Schema for inputs validation (optional)\n */\n inputs_schema?: string\n\n /**\n * Whether the program supports interactive challenges\n */\n supports_interactive: boolean\n\n /**\n * Maximum execution time in seconds\n */\n max_runtime_s?: number\n\n /**\n * Maximum artifact size in megabytes\n */\n max_artifact_mb?: number\n\n /**\n * Additional metadata\n */\n metadata?: Record<string, unknown>\n}\n\n/**\n * Registry for managing supported programs and their constraints\n */\n@injectable()\nexport class ProgramRegistry {\n private programs: Map<string, ProgramMetadata> = new Map()\n\n /**\n * Register a new program\n */\n public register(metadata: ProgramMetadata): void {\n this.programs.set(metadata.program_id, metadata)\n }\n\n /**\n * Unregister a program\n */\n public unregister(programId: string): boolean {\n return this.programs.delete(programId)\n }\n\n /**\n * Get program metadata by ID\n * @throws {ProgramNotSupportedError} if program not found\n */\n public getById(programId: string): ProgramMetadata {\n const program = this.programs.get(programId)\n if (!program) {\n throw new ProgramNotSupportedError(programId)\n }\n return program\n }\n\n /**\n * Find program metadata by ID (returns undefined if not found)\n */\n public findById(programId: string): ProgramMetadata | undefined {\n return this.programs.get(programId)\n }\n\n /**\n * Check if a program is supported\n */\n public isSupported(programId: string): boolean {\n return this.programs.has(programId)\n }\n\n /**\n * Get all registered programs\n */\n public getAllPrograms(): ProgramMetadata[] {\n return Array.from(this.programs.values())\n }\n\n /**\n * Check if a verifying key hash is allowed for a program\n */\n public isVkAllowed(programId: string, vkHash: string): boolean {\n const program = this.getById(programId)\n return program.allowed_vk_hashes.includes(vkHash)\n }\n\n /**\n * Check if program parameters hash is allowed\n */\n public isParamsAllowed(programId: string, paramsHash: string): boolean {\n const program = this.getById(programId)\n\n // If no params hashes are specified, all are allowed\n if (!program.allowed_params_hashes || program.allowed_params_hashes.length === 0) {\n return true\n }\n\n return program.allowed_params_hashes.includes(paramsHash)\n }\n\n /**\n * Get programs that support interactive challenges\n */\n public getInteractivePrograms(): ProgramMetadata[] {\n return Array.from(this.programs.values()).filter((p) => p.supports_interactive)\n }\n\n /**\n * Clear all registered programs (useful for testing)\n */\n public clear(): void {\n this.programs.clear()\n }\n\n /**\n * Get the count of registered programs\n */\n public get count(): number {\n return this.programs.size\n }\n}\n"],"mappings":";;;;;;AAwEO,4BAAM,gBAAgB;;OACnB,2BAAyC,IAAI,KAAK;;;;;CAK1D,AAAO,SAAS,UAAiC;AAC/C,OAAK,SAAS,IAAI,SAAS,YAAY,SAAS;;;;;CAMlD,AAAO,WAAW,WAA4B;AAC5C,SAAO,KAAK,SAAS,OAAO,UAAU;;;;;;CAOxC,AAAO,QAAQ,WAAoC;EACjD,MAAM,UAAU,KAAK,SAAS,IAAI,UAAU;AAC5C,MAAI,CAAC,QACH,OAAM,IAAI,yBAAyB,UAAU;AAE/C,SAAO;;;;;CAMT,AAAO,SAAS,WAAgD;AAC9D,SAAO,KAAK,SAAS,IAAI,UAAU;;;;;CAMrC,AAAO,YAAY,WAA4B;AAC7C,SAAO,KAAK,SAAS,IAAI,UAAU;;;;;CAMrC,AAAO,iBAAoC;AACzC,SAAO,MAAM,KAAK,KAAK,SAAS,QAAQ,CAAC;;;;;CAM3C,AAAO,YAAY,WAAmB,QAAyB;AAE7D,SADgB,KAAK,QAAQ,UAAU,CACxB,kBAAkB,SAAS,OAAO;;;;;CAMnD,AAAO,gBAAgB,WAAmB,YAA6B;EACrE,MAAM,UAAU,KAAK,QAAQ,UAAU;AAGvC,MAAI,CAAC,QAAQ,yBAAyB,QAAQ,sBAAsB,WAAW,EAC7E,QAAO;AAGT,SAAO,QAAQ,sBAAsB,SAAS,WAAW;;;;;CAM3D,AAAO,yBAA4C;AACjD,SAAO,MAAM,KAAK,KAAK,SAAS,QAAQ,CAAC,CAAC,QAAQ,MAAM,EAAE,qBAAqB;;;;;CAMjF,AAAO,QAAc;AACnB,OAAK,SAAS,OAAO;;;;;CAMvB,IAAW,QAAgB;AACzB,SAAO,KAAK,SAAS;;;8BA3FxB,YAAY"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { PublicOutputs, ZKProof } from "../models/ProofArtifact.mjs";
|
|
2
|
+
import { AgentContext } from "@credo-ts/core";
|
|
3
|
+
|
|
4
|
+
//#region src/registry/ProofSystemRegistry.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Verifying key with associated metadata
|
|
7
|
+
*/
|
|
8
|
+
interface VerifyingKey {
|
|
9
|
+
/**
|
|
10
|
+
* Hash of the verifying key
|
|
11
|
+
*/
|
|
12
|
+
vk_hash: string;
|
|
13
|
+
/**
|
|
14
|
+
* Verifying key data (bytes or string)
|
|
15
|
+
*/
|
|
16
|
+
vk_data: Uint8Array | string;
|
|
17
|
+
/**
|
|
18
|
+
* Cryptographic curve (e.g., 'bls12-381', 'bn254')
|
|
19
|
+
*/
|
|
20
|
+
curve?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Additional metadata
|
|
23
|
+
*/
|
|
24
|
+
metadata?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Interface for zero-knowledge proof system implementations
|
|
28
|
+
*/
|
|
29
|
+
interface ProofSystem {
|
|
30
|
+
/**
|
|
31
|
+
* Unique identifier (e.g., 'groth16@1', 'plonk@1')
|
|
32
|
+
*/
|
|
33
|
+
readonly id: string;
|
|
34
|
+
/**
|
|
35
|
+
* Version number
|
|
36
|
+
*/
|
|
37
|
+
readonly version: number;
|
|
38
|
+
/**
|
|
39
|
+
* Proof scheme name (e.g., 'groth16', 'plonk', 'stark')
|
|
40
|
+
*/
|
|
41
|
+
readonly scheme: string;
|
|
42
|
+
/**
|
|
43
|
+
* Supported cryptographic curves
|
|
44
|
+
*/
|
|
45
|
+
readonly supportedCurves: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Verify a zero-knowledge proof
|
|
48
|
+
*/
|
|
49
|
+
verify(agentContext: AgentContext, proof: ZKProof, publicOutputs: PublicOutputs, verifyingKey: VerifyingKey): Promise<boolean>;
|
|
50
|
+
/**
|
|
51
|
+
* Whether this proof system supports multi-round proofs
|
|
52
|
+
*/
|
|
53
|
+
supportsMultiRound?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Combine multiple proofs into one (for multi-round or aggregation)
|
|
56
|
+
*/
|
|
57
|
+
combineProofs?(proofs: ZKProof[]): Promise<ZKProof>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Registry for managing proof system implementations
|
|
61
|
+
*/
|
|
62
|
+
declare class ProofSystemRegistry {
|
|
63
|
+
private systems;
|
|
64
|
+
/**
|
|
65
|
+
* Register a proof system
|
|
66
|
+
*/
|
|
67
|
+
register(system: ProofSystem): void;
|
|
68
|
+
/**
|
|
69
|
+
* Unregister a proof system
|
|
70
|
+
*/
|
|
71
|
+
unregister(systemId: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get proof system by ID
|
|
74
|
+
*/
|
|
75
|
+
getById(systemId: string): ProofSystem;
|
|
76
|
+
/**
|
|
77
|
+
* Find proof system by scheme name
|
|
78
|
+
*/
|
|
79
|
+
getByScheme(scheme: string): ProofSystem | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Find all proof systems that support a given scheme
|
|
82
|
+
*/
|
|
83
|
+
getAllByScheme(scheme: string): ProofSystem[];
|
|
84
|
+
/**
|
|
85
|
+
* Check if a proof scheme is supported
|
|
86
|
+
*/
|
|
87
|
+
isSupported(scheme: string): boolean;
|
|
88
|
+
/**
|
|
89
|
+
* Get all registered proof systems
|
|
90
|
+
*/
|
|
91
|
+
getAllSystems(): ProofSystem[];
|
|
92
|
+
/**
|
|
93
|
+
* Get proof systems that support multi-round proofs
|
|
94
|
+
*/
|
|
95
|
+
getMultiRoundSystems(): ProofSystem[];
|
|
96
|
+
/**
|
|
97
|
+
* Verify a proof using the appropriate proof system
|
|
98
|
+
*/
|
|
99
|
+
verify(agentContext: AgentContext, proof: ZKProof, publicOutputs: PublicOutputs, verifyingKey: VerifyingKey): Promise<boolean>;
|
|
100
|
+
/**
|
|
101
|
+
* Clear all registered proof systems (useful for testing)
|
|
102
|
+
*/
|
|
103
|
+
clear(): void;
|
|
104
|
+
/**
|
|
105
|
+
* Get the count of registered proof systems
|
|
106
|
+
*/
|
|
107
|
+
get count(): number;
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { ProofSystem, ProofSystemRegistry, VerifyingKey };
|
|
111
|
+
//# sourceMappingURL=ProofSystemRegistry.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProofSystemRegistry.d.mts","names":[],"sources":["../../src/registry/ProofSystemRegistry.ts"],"mappings":";;;;;;AASA;UAAiB,YAAA;;;;EAIf,OAAA;EAKS;;;EAAT,OAAA,EAAS,UAAA;EAUQ;;AAMnB;EAXE,KAAA;;;;EAKA,QAAA,GAAW,MAAA;AAAA;;;;UAMI,WAAA;EAuC2B;;;EAAA,SAnCjC,EAAA;EAUA;;;EAAA,SALA,OAAA;EAgBP;;;EAAA,SAXO,MAAA;EAaP;;;EAAA,SARO,eAAA;EAeT;;;EAVA,MAAA,CACE,YAAA,EAAc,YAAA,EACd,KAAA,EAAO,OAAA,EACP,aAAA,EAAe,aAAA,EACf,YAAA,EAAc,YAAA,GACb,OAAA;EAUgC;;;EALnC,kBAAA;EAYW;;;EAPX,aAAA,EAAe,MAAA,EAAQ,OAAA,KAAY,OAAA,CAAQ,OAAA;AAAA;;;;cAOhC,mBAAA;EAAA,QACH,OAAA;EA8EC;;;EAzEF,QAAA,CAAS,MAAA,EAAQ,WAAA;EA4Ed;;;EArEH,UAAA,CAAW,QAAA;EAPM;;;EAcjB,OAAA,CAAQ,QAAA,WAAmB,WAAA;EAA3B;;;EAWA,WAAA,CAAY,MAAA,WAAiB,WAAA;EAAjB;;;EAYZ,cAAA,CAAe,MAAA,WAAiB,WAAA;EAAA;;;EAahC,WAAA,CAAY,MAAA;EAOK;;;EAAjB,aAAA,CAAA,GAAiB,WAAA;EAeR;;;EART,oBAAA,CAAA,GAAwB,WAAA;EAUd;;;EAHJ,MAAA,CACX,YAAA,EAAc,YAAA,EACd,KAAA,EAAO,OAAA,EACP,aAAA,EAAe,aAAA,EACf,YAAA,EAAc,YAAA,GACb,OAAA;EAAA;;;EAYI,KAAA,CAAA;EAOS;;;EAAA,IAAL,KAAA,CAAA;AAAA"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
2
|
+
import { CredoError } from "@credo-ts/core";
|
|
3
|
+
import { injectable as injectable$1 } from "tsyringe";
|
|
4
|
+
|
|
5
|
+
//#region src/registry/ProofSystemRegistry.ts
|
|
6
|
+
let ProofSystemRegistry = class ProofSystemRegistry {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.systems = /* @__PURE__ */ new Map();
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Register a proof system
|
|
12
|
+
*/
|
|
13
|
+
register(system) {
|
|
14
|
+
this.systems.set(system.id, system);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Unregister a proof system
|
|
18
|
+
*/
|
|
19
|
+
unregister(systemId) {
|
|
20
|
+
return this.systems.delete(systemId);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get proof system by ID
|
|
24
|
+
*/
|
|
25
|
+
getById(systemId) {
|
|
26
|
+
const system = this.systems.get(systemId);
|
|
27
|
+
if (!system) throw new CredoError(`Proof system '${systemId}' not found`);
|
|
28
|
+
return system;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Find proof system by scheme name
|
|
32
|
+
*/
|
|
33
|
+
getByScheme(scheme) {
|
|
34
|
+
for (const system of this.systems.values()) if (system.scheme.toLowerCase() === scheme.toLowerCase()) return system;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Find all proof systems that support a given scheme
|
|
38
|
+
*/
|
|
39
|
+
getAllByScheme(scheme) {
|
|
40
|
+
const results = [];
|
|
41
|
+
for (const system of this.systems.values()) if (system.scheme.toLowerCase() === scheme.toLowerCase()) results.push(system);
|
|
42
|
+
return results;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Check if a proof scheme is supported
|
|
46
|
+
*/
|
|
47
|
+
isSupported(scheme) {
|
|
48
|
+
return this.getByScheme(scheme) !== void 0;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get all registered proof systems
|
|
52
|
+
*/
|
|
53
|
+
getAllSystems() {
|
|
54
|
+
return Array.from(this.systems.values());
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get proof systems that support multi-round proofs
|
|
58
|
+
*/
|
|
59
|
+
getMultiRoundSystems() {
|
|
60
|
+
return Array.from(this.systems.values()).filter((s) => s.supportsMultiRound);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Verify a proof using the appropriate proof system
|
|
64
|
+
*/
|
|
65
|
+
async verify(agentContext, proof, publicOutputs, verifyingKey) {
|
|
66
|
+
const system = this.getByScheme(proof.scheme);
|
|
67
|
+
if (!system) throw new CredoError(`Proof system for scheme '${proof.scheme}' not found`);
|
|
68
|
+
return system.verify(agentContext, proof, publicOutputs, verifyingKey);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clear all registered proof systems (useful for testing)
|
|
72
|
+
*/
|
|
73
|
+
clear() {
|
|
74
|
+
this.systems.clear();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the count of registered proof systems
|
|
78
|
+
*/
|
|
79
|
+
get count() {
|
|
80
|
+
return this.systems.size;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
ProofSystemRegistry = __decorate([injectable$1()], ProofSystemRegistry);
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
export { ProofSystemRegistry };
|
|
87
|
+
//# sourceMappingURL=ProofSystemRegistry.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProofSystemRegistry.mjs","names":["injectable"],"sources":["../../src/registry/ProofSystemRegistry.ts"],"sourcesContent":["import type { AgentContext } from '@credo-ts/core'\nimport type { PublicOutputs, ZKProof } from '../models'\n\nimport { injectable } from 'tsyringe'\nimport { CredoError } from '@credo-ts/core'\n\n/**\n * Verifying key with associated metadata\n */\nexport interface VerifyingKey {\n /**\n * Hash of the verifying key\n */\n vk_hash: string\n\n /**\n * Verifying key data (bytes or string)\n */\n vk_data: Uint8Array | string\n\n /**\n * Cryptographic curve (e.g., 'bls12-381', 'bn254')\n */\n curve?: string\n\n /**\n * Additional metadata\n */\n metadata?: Record<string, unknown>\n}\n\n/**\n * Interface for zero-knowledge proof system implementations\n */\nexport interface ProofSystem {\n /**\n * Unique identifier (e.g., 'groth16@1', 'plonk@1')\n */\n readonly id: string\n\n /**\n * Version number\n */\n readonly version: number\n\n /**\n * Proof scheme name (e.g., 'groth16', 'plonk', 'stark')\n */\n readonly scheme: string\n\n /**\n * Supported cryptographic curves\n */\n readonly supportedCurves: string[]\n\n /**\n * Verify a zero-knowledge proof\n */\n verify(\n agentContext: AgentContext,\n proof: ZKProof,\n publicOutputs: PublicOutputs,\n verifyingKey: VerifyingKey\n ): Promise<boolean>\n\n /**\n * Whether this proof system supports multi-round proofs\n */\n supportsMultiRound?: boolean\n\n /**\n * Combine multiple proofs into one (for multi-round or aggregation)\n */\n combineProofs?(proofs: ZKProof[]): Promise<ZKProof>\n}\n\n/**\n * Registry for managing proof system implementations\n */\n@injectable()\nexport class ProofSystemRegistry {\n private systems: Map<string, ProofSystem> = new Map()\n\n /**\n * Register a proof system\n */\n public register(system: ProofSystem): void {\n this.systems.set(system.id, system)\n }\n\n /**\n * Unregister a proof system\n */\n public unregister(systemId: string): boolean {\n return this.systems.delete(systemId)\n }\n\n /**\n * Get proof system by ID\n */\n public getById(systemId: string): ProofSystem {\n const system = this.systems.get(systemId)\n if (!system) {\n throw new CredoError(`Proof system '${systemId}' not found`)\n }\n return system\n }\n\n /**\n * Find proof system by scheme name\n */\n public getByScheme(scheme: string): ProofSystem | undefined {\n for (const system of this.systems.values()) {\n if (system.scheme.toLowerCase() === scheme.toLowerCase()) {\n return system\n }\n }\n return undefined\n }\n\n /**\n * Find all proof systems that support a given scheme\n */\n public getAllByScheme(scheme: string): ProofSystem[] {\n const results: ProofSystem[] = []\n for (const system of this.systems.values()) {\n if (system.scheme.toLowerCase() === scheme.toLowerCase()) {\n results.push(system)\n }\n }\n return results\n }\n\n /**\n * Check if a proof scheme is supported\n */\n public isSupported(scheme: string): boolean {\n return this.getByScheme(scheme) !== undefined\n }\n\n /**\n * Get all registered proof systems\n */\n public getAllSystems(): ProofSystem[] {\n return Array.from(this.systems.values())\n }\n\n /**\n * Get proof systems that support multi-round proofs\n */\n public getMultiRoundSystems(): ProofSystem[] {\n return Array.from(this.systems.values()).filter((s) => s.supportsMultiRound)\n }\n\n /**\n * Verify a proof using the appropriate proof system\n */\n public async verify(\n agentContext: AgentContext,\n proof: ZKProof,\n publicOutputs: PublicOutputs,\n verifyingKey: VerifyingKey\n ): Promise<boolean> {\n const system = this.getByScheme(proof.scheme)\n if (!system) {\n throw new CredoError(`Proof system for scheme '${proof.scheme}' not found`)\n }\n\n return system.verify(agentContext, proof, publicOutputs, verifyingKey)\n }\n\n /**\n * Clear all registered proof systems (useful for testing)\n */\n public clear(): void {\n this.systems.clear()\n }\n\n /**\n * Get the count of registered proof systems\n */\n public get count(): number {\n return this.systems.size\n }\n}\n"],"mappings":";;;;;AAgFO,gCAAM,oBAAoB;;OACvB,0BAAoC,IAAI,KAAK;;;;;CAKrD,AAAO,SAAS,QAA2B;AACzC,OAAK,QAAQ,IAAI,OAAO,IAAI,OAAO;;;;;CAMrC,AAAO,WAAW,UAA2B;AAC3C,SAAO,KAAK,QAAQ,OAAO,SAAS;;;;;CAMtC,AAAO,QAAQ,UAA+B;EAC5C,MAAM,SAAS,KAAK,QAAQ,IAAI,SAAS;AACzC,MAAI,CAAC,OACH,OAAM,IAAI,WAAW,iBAAiB,SAAS,aAAa;AAE9D,SAAO;;;;;CAMT,AAAO,YAAY,QAAyC;AAC1D,OAAK,MAAM,UAAU,KAAK,QAAQ,QAAQ,CACxC,KAAI,OAAO,OAAO,aAAa,KAAK,OAAO,aAAa,CACtD,QAAO;;;;;CASb,AAAO,eAAe,QAA+B;EACnD,MAAM,UAAyB,EAAE;AACjC,OAAK,MAAM,UAAU,KAAK,QAAQ,QAAQ,CACxC,KAAI,OAAO,OAAO,aAAa,KAAK,OAAO,aAAa,CACtD,SAAQ,KAAK,OAAO;AAGxB,SAAO;;;;;CAMT,AAAO,YAAY,QAAyB;AAC1C,SAAO,KAAK,YAAY,OAAO,KAAK;;;;;CAMtC,AAAO,gBAA+B;AACpC,SAAO,MAAM,KAAK,KAAK,QAAQ,QAAQ,CAAC;;;;;CAM1C,AAAO,uBAAsC;AAC3C,SAAO,MAAM,KAAK,KAAK,QAAQ,QAAQ,CAAC,CAAC,QAAQ,MAAM,EAAE,mBAAmB;;;;;CAM9E,MAAa,OACX,cACA,OACA,eACA,cACkB;EAClB,MAAM,SAAS,KAAK,YAAY,MAAM,OAAO;AAC7C,MAAI,CAAC,OACH,OAAM,IAAI,WAAW,4BAA4B,MAAM,OAAO,aAAa;AAG7E,SAAO,OAAO,OAAO,cAAc,OAAO,eAAe,aAAa;;;;;CAMxE,AAAO,QAAc;AACnB,OAAK,QAAQ,OAAO;;;;;CAMtB,IAAW,QAAgB;AACzB,SAAO,KAAK,QAAQ;;;kCAvGvBA,cAAY"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { BaseRecord, TagsBase } from "@credo-ts/core";
|
|
2
|
+
|
|
3
|
+
//#region src/repository/NonceRecord.d.ts
|
|
4
|
+
type DefaultNonceTags = {
|
|
5
|
+
proverDid: string;
|
|
6
|
+
nonce: string;
|
|
7
|
+
};
|
|
8
|
+
type CustomNonceTags = TagsBase;
|
|
9
|
+
interface NonceRecordStorageProps {
|
|
10
|
+
id?: string;
|
|
11
|
+
proverDid: string;
|
|
12
|
+
nonce: string;
|
|
13
|
+
usedAt: number;
|
|
14
|
+
tags?: CustomNonceTags;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Record for storing used nonces to prevent replay attacks.
|
|
18
|
+
*
|
|
19
|
+
* Nonces are stored persistently in Askar DB to survive agent restarts.
|
|
20
|
+
* Each nonce is tied to a prover DID and can only be used once.
|
|
21
|
+
*/
|
|
22
|
+
declare class NonceRecord extends BaseRecord<DefaultNonceTags, CustomNonceTags> {
|
|
23
|
+
static readonly type = "NonceRecord";
|
|
24
|
+
readonly type = "NonceRecord";
|
|
25
|
+
/**
|
|
26
|
+
* Prover DID that used this nonce
|
|
27
|
+
*/
|
|
28
|
+
proverDid: string;
|
|
29
|
+
/**
|
|
30
|
+
* The nonce value (32-byte hex string with 0x prefix)
|
|
31
|
+
*/
|
|
32
|
+
nonce: string;
|
|
33
|
+
/**
|
|
34
|
+
* Timestamp when nonce was used (milliseconds since epoch)
|
|
35
|
+
*/
|
|
36
|
+
usedAt: number;
|
|
37
|
+
constructor(props: NonceRecordStorageProps);
|
|
38
|
+
getTags(): {
|
|
39
|
+
proverDid: string;
|
|
40
|
+
nonce: string;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { CustomNonceTags, DefaultNonceTags, NonceRecord, NonceRecordStorageProps };
|
|
45
|
+
//# sourceMappingURL=NonceRecord.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceRecord.d.mts","names":[],"sources":["../../src/repository/NonceRecord.ts"],"mappings":";;;KAIY,gBAAA;EACV,SAAA;EACA,KAAA;AAAA;AAAA,KAGU,eAAA,GAAkB,QAAA;AAAA,UAEb,uBAAA;EACf,EAAA;EACA,SAAA;EACA,KAAA;EACA,MAAA;EACA,IAAA,GAAO,eAAA;AAAA;;;;;;;cASI,WAAA,SAAoB,UAAA,CAAW,gBAAA,EAAkB,eAAA;EAAA,gBACrC,IAAA;EAAA,SACP,IAAA;EAXM;;AASxB;EAOS,SAAA;;;;EAKA,KAAA;EAZwB;;;EAiBxB,MAAA;cAEY,KAAA,EAAO,uBAAA;EAYnB,OAAA,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { BaseRecord, utils } from "@credo-ts/core";
|
|
2
|
+
|
|
3
|
+
//#region src/repository/NonceRecord.ts
|
|
4
|
+
/**
|
|
5
|
+
* Record for storing used nonces to prevent replay attacks.
|
|
6
|
+
*
|
|
7
|
+
* Nonces are stored persistently in Askar DB to survive agent restarts.
|
|
8
|
+
* Each nonce is tied to a prover DID and can only be used once.
|
|
9
|
+
*/
|
|
10
|
+
var NonceRecord = class NonceRecord extends BaseRecord {
|
|
11
|
+
constructor(props) {
|
|
12
|
+
super();
|
|
13
|
+
this.type = NonceRecord.type;
|
|
14
|
+
if (props) {
|
|
15
|
+
this.id = props.id ?? utils.uuid();
|
|
16
|
+
this.proverDid = props.proverDid;
|
|
17
|
+
this.nonce = props.nonce;
|
|
18
|
+
this.usedAt = props.usedAt;
|
|
19
|
+
this._tags = props.tags ?? {};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getTags() {
|
|
23
|
+
return {
|
|
24
|
+
...this._tags,
|
|
25
|
+
proverDid: this.proverDid,
|
|
26
|
+
nonce: this.nonce
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
NonceRecord.type = "NonceRecord";
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { NonceRecord };
|
|
34
|
+
//# sourceMappingURL=NonceRecord.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceRecord.mjs","names":[],"sources":["../../src/repository/NonceRecord.ts"],"sourcesContent":["import type { TagsBase } from '@credo-ts/core'\n\nimport { BaseRecord, utils } from '@credo-ts/core'\n\nexport type DefaultNonceTags = {\n proverDid: string\n nonce: string\n}\n\nexport type CustomNonceTags = TagsBase\n\nexport interface NonceRecordStorageProps {\n id?: string\n proverDid: string\n nonce: string\n usedAt: number\n tags?: CustomNonceTags\n}\n\n/**\n * Record for storing used nonces to prevent replay attacks.\n *\n * Nonces are stored persistently in Askar DB to survive agent restarts.\n * Each nonce is tied to a prover DID and can only be used once.\n */\nexport class NonceRecord extends BaseRecord<DefaultNonceTags, CustomNonceTags> {\n public static readonly type = 'NonceRecord'\n public readonly type = NonceRecord.type\n\n /**\n * Prover DID that used this nonce\n */\n public proverDid!: string\n\n /**\n * The nonce value (32-byte hex string with 0x prefix)\n */\n public nonce!: string\n\n /**\n * Timestamp when nonce was used (milliseconds since epoch)\n */\n public usedAt!: number\n\n public constructor(props: NonceRecordStorageProps) {\n super()\n\n if (props) {\n this.id = props.id ?? utils.uuid()\n this.proverDid = props.proverDid\n this.nonce = props.nonce\n this.usedAt = props.usedAt\n this._tags = props.tags ?? {}\n }\n }\n\n public getTags() {\n return {\n ...this._tags,\n proverDid: this.proverDid,\n nonce: this.nonce,\n }\n }\n}\n"],"mappings":";;;;;;;;;AAyBA,IAAa,cAAb,MAAa,oBAAoB,WAA8C;CAmB7E,AAAO,YAAY,OAAgC;AACjD,SAAO;OAlBO,OAAO,YAAY;AAoBjC,MAAI,OAAO;AACT,QAAK,KAAK,MAAM,MAAM,MAAM,MAAM;AAClC,QAAK,YAAY,MAAM;AACvB,QAAK,QAAQ,MAAM;AACnB,QAAK,SAAS,MAAM;AACpB,QAAK,QAAQ,MAAM,QAAQ,EAAE;;;CAIjC,AAAO,UAAU;AACf,SAAO;GACL,GAAG,KAAK;GACR,WAAW,KAAK;GAChB,OAAO,KAAK;GACb;;;YAnCoB,OAAO"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { NonceRecord } from "./NonceRecord.mjs";
|
|
2
|
+
import { AgentContext, EventEmitter, Repository, StorageService } from "@credo-ts/core";
|
|
3
|
+
|
|
4
|
+
//#region src/repository/NonceRepository.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Repository for managing nonce records.
|
|
7
|
+
*
|
|
8
|
+
* Provides persistent storage for used nonces to prevent replay attacks
|
|
9
|
+
* across agent restarts.
|
|
10
|
+
*/
|
|
11
|
+
declare class NonceRepository extends Repository<NonceRecord> {
|
|
12
|
+
constructor(storageService: StorageService<NonceRecord>, eventEmitter: EventEmitter);
|
|
13
|
+
/**
|
|
14
|
+
* Find a nonce record by prover DID and nonce value
|
|
15
|
+
*
|
|
16
|
+
* @param agentContext - Agent context
|
|
17
|
+
* @param proverDid - Prover DID
|
|
18
|
+
* @param nonce - Nonce value
|
|
19
|
+
* @returns Nonce record if found, null otherwise
|
|
20
|
+
*/
|
|
21
|
+
findByProverAndNonce(agentContext: AgentContext, proverDid: string, nonce: string): Promise<NonceRecord | null>;
|
|
22
|
+
/**
|
|
23
|
+
* Find all nonces for a prover DID
|
|
24
|
+
*
|
|
25
|
+
* @param agentContext - Agent context
|
|
26
|
+
* @param proverDid - Prover DID
|
|
27
|
+
* @returns Array of nonce records
|
|
28
|
+
*/
|
|
29
|
+
findByProverDid(agentContext: AgentContext, proverDid: string): Promise<NonceRecord[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Delete old nonces (cleanup)
|
|
32
|
+
*
|
|
33
|
+
* @param agentContext - Agent context
|
|
34
|
+
* @param olderThanMs - Delete nonces older than this many milliseconds
|
|
35
|
+
* @returns Number of records deleted
|
|
36
|
+
*/
|
|
37
|
+
deleteOlderThan(agentContext: AgentContext, olderThanMs: number): Promise<number>;
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { NonceRepository };
|
|
41
|
+
//# sourceMappingURL=NonceRepository.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceRepository.d.mts","names":[],"sources":["../../src/repository/NonceRepository.ts"],"mappings":";;;;;AAYA;;;;;cACa,eAAA,SAAwB,UAAA,CAAW,WAAA;cAEH,cAAA,EAAgB,cAAA,CAAe,WAAA,GACxE,YAAA,EAAc,YAAA;EAcA;;;;;;;;EADH,oBAAA,CACX,YAAA,EAAc,YAAA,EACd,SAAA,UACA,KAAA,WACC,OAAA,CAAQ,WAAA;EApBkC;;;;;;;EAkChC,eAAA,CAAgB,YAAA,EAAc,YAAA,EAAc,SAAA,WAAoB,OAAA,CAAQ,WAAA;EA/BrE;;;;;;;EA0CH,eAAA,CAAgB,YAAA,EAAc,YAAA,EAAc,WAAA,WAAsB,OAAA;AAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { NonceRecord } from "./NonceRecord.mjs";
|
|
2
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
3
|
+
import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateParam.mjs";
|
|
4
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
5
|
+
import { EventEmitter, InjectionSymbols, Repository, inject, injectable } from "@credo-ts/core";
|
|
6
|
+
|
|
7
|
+
//#region src/repository/NonceRepository.ts
|
|
8
|
+
var _ref;
|
|
9
|
+
let NonceRepository = class NonceRepository extends Repository {
|
|
10
|
+
constructor(storageService, eventEmitter) {
|
|
11
|
+
super(NonceRecord, storageService, eventEmitter);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Find a nonce record by prover DID and nonce value
|
|
15
|
+
*
|
|
16
|
+
* @param agentContext - Agent context
|
|
17
|
+
* @param proverDid - Prover DID
|
|
18
|
+
* @param nonce - Nonce value
|
|
19
|
+
* @returns Nonce record if found, null otherwise
|
|
20
|
+
*/
|
|
21
|
+
async findByProverAndNonce(agentContext, proverDid, nonce) {
|
|
22
|
+
return this.findSingleByQuery(agentContext, {
|
|
23
|
+
proverDid,
|
|
24
|
+
nonce
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Find all nonces for a prover DID
|
|
29
|
+
*
|
|
30
|
+
* @param agentContext - Agent context
|
|
31
|
+
* @param proverDid - Prover DID
|
|
32
|
+
* @returns Array of nonce records
|
|
33
|
+
*/
|
|
34
|
+
async findByProverDid(agentContext, proverDid) {
|
|
35
|
+
return this.findByQuery(agentContext, { proverDid });
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Delete old nonces (cleanup)
|
|
39
|
+
*
|
|
40
|
+
* @param agentContext - Agent context
|
|
41
|
+
* @param olderThanMs - Delete nonces older than this many milliseconds
|
|
42
|
+
* @returns Number of records deleted
|
|
43
|
+
*/
|
|
44
|
+
async deleteOlderThan(agentContext, olderThanMs) {
|
|
45
|
+
const cutoffTime = Date.now() - olderThanMs;
|
|
46
|
+
const allRecords = await this.getAll(agentContext);
|
|
47
|
+
let deletedCount = 0;
|
|
48
|
+
for (const record of allRecords) if (record.usedAt < cutoffTime) {
|
|
49
|
+
await this.delete(agentContext, record);
|
|
50
|
+
deletedCount++;
|
|
51
|
+
}
|
|
52
|
+
return deletedCount;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
NonceRepository = __decorate([
|
|
56
|
+
injectable(),
|
|
57
|
+
__decorateParam(0, inject(InjectionSymbols.StorageService)),
|
|
58
|
+
__decorateMetadata("design:paramtypes", [Object, EventEmitter])
|
|
59
|
+
], NonceRepository);
|
|
60
|
+
|
|
61
|
+
//#endregion
|
|
62
|
+
export { NonceRepository };
|
|
63
|
+
//# sourceMappingURL=NonceRepository.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceRepository.mjs","names":[],"sources":["../../src/repository/NonceRepository.ts"],"sourcesContent":["import type { AgentContext, StorageService } from '@credo-ts/core'\n\nimport { EventEmitter, inject, injectable, InjectionSymbols, Repository } from '@credo-ts/core'\n\nimport { NonceRecord } from './NonceRecord'\n\n/**\n * Repository for managing nonce records.\n *\n * Provides persistent storage for used nonces to prevent replay attacks\n * across agent restarts.\n */\n@injectable()\nexport class NonceRepository extends Repository<NonceRecord> {\n public constructor(\n @inject(InjectionSymbols.StorageService) storageService: StorageService<NonceRecord>,\n eventEmitter: EventEmitter\n ) {\n super(NonceRecord, storageService, eventEmitter)\n }\n\n /**\n * Find a nonce record by prover DID and nonce value\n *\n * @param agentContext - Agent context\n * @param proverDid - Prover DID\n * @param nonce - Nonce value\n * @returns Nonce record if found, null otherwise\n */\n public async findByProverAndNonce(\n agentContext: AgentContext,\n proverDid: string,\n nonce: string\n ): Promise<NonceRecord | null> {\n return this.findSingleByQuery(agentContext, {\n proverDid,\n nonce,\n })\n }\n\n /**\n * Find all nonces for a prover DID\n *\n * @param agentContext - Agent context\n * @param proverDid - Prover DID\n * @returns Array of nonce records\n */\n public async findByProverDid(agentContext: AgentContext, proverDid: string): Promise<NonceRecord[]> {\n return this.findByQuery(agentContext, { proverDid })\n }\n\n /**\n * Delete old nonces (cleanup)\n *\n * @param agentContext - Agent context\n * @param olderThanMs - Delete nonces older than this many milliseconds\n * @returns Number of records deleted\n */\n public async deleteOlderThan(agentContext: AgentContext, olderThanMs: number): Promise<number> {\n const cutoffTime = Date.now() - olderThanMs\n const allRecords = await this.getAll(agentContext)\n\n let deletedCount = 0\n for (const record of allRecords) {\n if (record.usedAt < cutoffTime) {\n await this.delete(agentContext, record)\n deletedCount++\n }\n }\n\n return deletedCount\n }\n}\n"],"mappings":";;;;;;;;AAaO,4BAAM,wBAAwB,WAAwB;CAC3D,AAAO,YACL,AAAyC,gBACzC,cACA;AACA,QAAM,aAAa,gBAAgB,aAAa;;;;;;;;;;CAWlD,MAAa,qBACX,cACA,WACA,OAC6B;AAC7B,SAAO,KAAK,kBAAkB,cAAc;GAC1C;GACA;GACD,CAAC;;;;;;;;;CAUJ,MAAa,gBAAgB,cAA4B,WAA2C;AAClG,SAAO,KAAK,YAAY,cAAc,EAAE,WAAW,CAAC;;;;;;;;;CAUtD,MAAa,gBAAgB,cAA4B,aAAsC;EAC7F,MAAM,aAAa,KAAK,KAAK,GAAG;EAChC,MAAM,aAAa,MAAM,KAAK,OAAO,aAAa;EAElD,IAAI,eAAe;AACnB,OAAK,MAAM,UAAU,WACnB,KAAI,OAAO,SAAS,YAAY;AAC9B,SAAM,KAAK,OAAO,cAAc,OAAO;AACvC;;AAIJ,SAAO;;;;CA1DV,YAAY;oBAGR,OAAO,iBAAiB,eAAe"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { PoeRole } from "../PoeRole.mjs";
|
|
2
|
+
import { PoeState } from "../PoeState.mjs";
|
|
3
|
+
import { BindingContext } from "../models/BindingContext.mjs";
|
|
4
|
+
import { DisclosureLevel, ProgramExecution } from "../models/ProgramExecution.mjs";
|
|
5
|
+
import { ChallengeSpec, ProofArtifact, VerificationResult } from "../models/ProofArtifact.mjs";
|
|
6
|
+
import { BaseRecord, RecordTags, TagsBase } from "@credo-ts/core";
|
|
7
|
+
|
|
8
|
+
//#region src/repository/PoeSessionRecord.d.ts
|
|
9
|
+
type CustomPoeTags = TagsBase;
|
|
10
|
+
type DefaultPoeTags = {
|
|
11
|
+
sessionId: string;
|
|
12
|
+
threadId: string;
|
|
13
|
+
parentThreadId?: string;
|
|
14
|
+
connectionId?: string;
|
|
15
|
+
role: PoeRole;
|
|
16
|
+
state: PoeState;
|
|
17
|
+
programId?: string;
|
|
18
|
+
};
|
|
19
|
+
type PoeTags = RecordTags<PoeSessionRecord>;
|
|
20
|
+
/**
|
|
21
|
+
* Storage properties for PoE session record
|
|
22
|
+
*/
|
|
23
|
+
interface PoeSessionStorageProps {
|
|
24
|
+
id?: string;
|
|
25
|
+
createdAt?: Date;
|
|
26
|
+
sessionId: string;
|
|
27
|
+
connectionId?: string;
|
|
28
|
+
threadId: string;
|
|
29
|
+
parentThreadId?: string;
|
|
30
|
+
role: PoeRole;
|
|
31
|
+
state: PoeState;
|
|
32
|
+
bindingContext: BindingContext;
|
|
33
|
+
programId?: string;
|
|
34
|
+
programVersion?: string;
|
|
35
|
+
executionPlan?: ProgramExecution;
|
|
36
|
+
challengeSpec?: ChallengeSpec;
|
|
37
|
+
partialProofs?: ProofArtifact[];
|
|
38
|
+
finalProof?: ProofArtifact;
|
|
39
|
+
verificationResult?: VerificationResult;
|
|
40
|
+
disclosure?: DisclosureLevel;
|
|
41
|
+
idempotencyKey?: string;
|
|
42
|
+
errorMessage?: string;
|
|
43
|
+
expiry?: string;
|
|
44
|
+
tags?: CustomPoeTags;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Record for tracking Proof of Execution (PoE) protocol sessions
|
|
48
|
+
*/
|
|
49
|
+
declare class PoeSessionRecord extends BaseRecord<DefaultPoeTags, CustomPoeTags> {
|
|
50
|
+
static readonly type = "PoeSessionRecord";
|
|
51
|
+
readonly type = "PoeSessionRecord";
|
|
52
|
+
sessionId: string;
|
|
53
|
+
connectionId?: string;
|
|
54
|
+
threadId: string;
|
|
55
|
+
parentThreadId?: string;
|
|
56
|
+
role: PoeRole;
|
|
57
|
+
state: PoeState;
|
|
58
|
+
bindingContext: BindingContext;
|
|
59
|
+
programId?: string;
|
|
60
|
+
programVersion?: string;
|
|
61
|
+
executionPlan?: ProgramExecution;
|
|
62
|
+
challengeSpec?: ChallengeSpec;
|
|
63
|
+
partialProofs: ProofArtifact[];
|
|
64
|
+
finalProof?: ProofArtifact;
|
|
65
|
+
verificationResult?: VerificationResult;
|
|
66
|
+
disclosure?: DisclosureLevel;
|
|
67
|
+
idempotencyKey?: string;
|
|
68
|
+
errorMessage?: string;
|
|
69
|
+
expiry?: string;
|
|
70
|
+
constructor(props: PoeSessionStorageProps);
|
|
71
|
+
getTags(): {
|
|
72
|
+
sessionId: string;
|
|
73
|
+
threadId: string;
|
|
74
|
+
parentThreadId: string | undefined;
|
|
75
|
+
connectionId: string | undefined;
|
|
76
|
+
role: PoeRole;
|
|
77
|
+
state: PoeState;
|
|
78
|
+
programId: string | undefined;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Assert that the record has the expected role
|
|
82
|
+
*/
|
|
83
|
+
assertRole(expectedRole: PoeRole): void;
|
|
84
|
+
/**
|
|
85
|
+
* Assert that the record is in one of the expected states
|
|
86
|
+
*/
|
|
87
|
+
assertState(expectedStates: PoeState | PoeState[]): void;
|
|
88
|
+
/**
|
|
89
|
+
* Add a partial proof to the collection
|
|
90
|
+
*/
|
|
91
|
+
addPartialProof(proof: ProofArtifact): void;
|
|
92
|
+
/**
|
|
93
|
+
* Set the final proof
|
|
94
|
+
*/
|
|
95
|
+
setFinalProof(proof: ProofArtifact): void;
|
|
96
|
+
/**
|
|
97
|
+
* Check if the session has expired
|
|
98
|
+
*/
|
|
99
|
+
isExpired(): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Get a summary of the session for logging
|
|
102
|
+
*/
|
|
103
|
+
getSummary(): string;
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export { CustomPoeTags, DefaultPoeTags, PoeSessionRecord, PoeSessionStorageProps, PoeTags };
|
|
107
|
+
//# sourceMappingURL=PoeSessionRecord.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PoeSessionRecord.d.mts","names":[],"sources":["../../src/repository/PoeSessionRecord.ts"],"mappings":";;;;;;;;KAeY,aAAA,GAAgB,QAAA;AAAA,KAEhB,cAAA;EACV,SAAA;EACA,QAAA;EACA,cAAA;EACA,YAAA;EACA,IAAA,EAAM,OAAA;EACN,KAAA,EAAO,QAAA;EACP,SAAA;AAAA;AAAA,KAGU,OAAA,GAAU,UAAA,CAAW,gBAAA;;;;UAKhB,sBAAA;EACf,EAAA;EACA,SAAA,GAAY,IAAA;EAGZ,SAAA;EACA,YAAA;EACA,QAAA;EACA,cAAA;EAEA,IAAA,EAAM,OAAA;EACN,KAAA,EAAO,QAAA;EAGP,cAAA,EAAgB,cAAA;EAGhB,SAAA;EACA,cAAA;EACA,aAAA,GAAgB,gBAAA;EAGhB,aAAA,GAAgB,aAAA;EAGhB,aAAA,GAAgB,aAAA;EAChB,UAAA,GAAa,aAAA;EAGb,kBAAA,GAAqB,kBAAA;EAGrB,UAAA,GAAa,eAAA;EACb,cAAA;EACA,YAAA;EACA,MAAA;EAEA,IAAA,GAAO,aAAA;AAAA;;;;cAMI,gBAAA,SAAyB,UAAA,CAAW,cAAA,EAAgB,aAAA;EAAA,gBACxC,IAAA;EAAA,SACP,IAAA;EAGT,SAAA;EACA,YAAA;EACA,QAAA;EACA,cAAA;EAEA,IAAA,EAAO,OAAA;EACP,KAAA,EAAQ,QAAA;EAIR,cAAA,EAAiB,cAAA;EAGjB,SAAA;EACA,cAAA;EAGA,aAAA,GAAgB,gBAAA;EAIhB,aAAA,GAAgB,aAAA;EAIhB,aAAA,EAAe,aAAA;EAGf,UAAA,GAAa,aAAA;EAIb,kBAAA,GAAqB,kBAAA;EAGrB,UAAA,GAAa,eAAA;EACb,cAAA;EACA,YAAA;EACA,MAAA;cAEY,KAAA,EAAO,sBAAA;EA4BnB,OAAA,CAAA;;;;;;;;;EAnFP;;;EAmGO,UAAA,CAAW,YAAA,EAAc,OAAA;EA/FzB;;;EAwGA,WAAA,CAAY,cAAA,EAAgB,QAAA,GAAW,QAAA;EAlGlB;;;EAiHrB,eAAA,CAAgB,KAAA,EAAO,aAAA;EAvGhB;;;EA8GP,aAAA,CAAc,KAAA,EAAO,aAAA;EA9FL;;;EAqGhB,SAAA,CAAA;EAvFa;;;EAiGb,UAAA,CAAA;AAAA"}
|