@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,126 @@
|
|
|
1
|
+
import { NonceError } from "../errors/PoeError.mjs";
|
|
2
|
+
import "../errors/index.mjs";
|
|
3
|
+
import { NonceRecord } from "../repository/NonceRecord.mjs";
|
|
4
|
+
import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorateMetadata.mjs";
|
|
5
|
+
import { __decorate } from "../_virtual/_@oxc-project_runtime@0.112.0/helpers/decorate.mjs";
|
|
6
|
+
import { NonceRepository } from "../repository/NonceRepository.mjs";
|
|
7
|
+
import { randomBytes } from "crypto";
|
|
8
|
+
import { injectable } from "tsyringe";
|
|
9
|
+
|
|
10
|
+
//#region src/services/NonceService.ts
|
|
11
|
+
var _ref;
|
|
12
|
+
let NonceService = class NonceService {
|
|
13
|
+
constructor(nonceRepository) {
|
|
14
|
+
this.nonceRepository = nonceRepository;
|
|
15
|
+
this.nonceCache = /* @__PURE__ */ new Map();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a cryptographically secure nonce
|
|
19
|
+
* @returns 32-byte hex string with 0x prefix
|
|
20
|
+
*/
|
|
21
|
+
generateNonce() {
|
|
22
|
+
return "0x" + randomBytes(32).toString("hex");
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate a session ID (16 bytes)
|
|
26
|
+
* @returns 16-byte hex string with 0x prefix
|
|
27
|
+
*/
|
|
28
|
+
generateSessionId() {
|
|
29
|
+
return "0x" + randomBytes(16).toString("hex");
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if a nonce has been used by a specific DID
|
|
33
|
+
*
|
|
34
|
+
* First checks in-memory cache, falls back to repository if not found.
|
|
35
|
+
* This provides fast lookups while maintaining persistence.
|
|
36
|
+
*/
|
|
37
|
+
async isNonceUsed(agentContext, proverDid, nonce) {
|
|
38
|
+
const normalizedNonce = nonce.toLowerCase();
|
|
39
|
+
const cachedNonces = this.nonceCache.get(proverDid);
|
|
40
|
+
if (cachedNonces && cachedNonces.has(normalizedNonce)) return true;
|
|
41
|
+
if (await this.nonceRepository.findByProverAndNonce(agentContext, proverDid, normalizedNonce)) {
|
|
42
|
+
this.addToCache(proverDid, normalizedNonce);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Mark a nonce as used by a specific DID
|
|
49
|
+
*
|
|
50
|
+
* Stores in both repository (persistent) and cache (fast access).
|
|
51
|
+
*/
|
|
52
|
+
async markNonceUsed(agentContext, proverDid, nonce) {
|
|
53
|
+
const normalizedNonce = nonce.toLowerCase();
|
|
54
|
+
const record = new NonceRecord({
|
|
55
|
+
proverDid,
|
|
56
|
+
nonce: normalizedNonce,
|
|
57
|
+
usedAt: Date.now()
|
|
58
|
+
});
|
|
59
|
+
await this.nonceRepository.save(agentContext, record);
|
|
60
|
+
this.addToCache(proverDid, normalizedNonce);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Helper to add nonce to in-memory cache
|
|
64
|
+
*/
|
|
65
|
+
addToCache(proverDid, nonce) {
|
|
66
|
+
let didNonces = this.nonceCache.get(proverDid);
|
|
67
|
+
if (!didNonces) {
|
|
68
|
+
didNonces = /* @__PURE__ */ new Set();
|
|
69
|
+
this.nonceCache.set(proverDid, didNonces);
|
|
70
|
+
}
|
|
71
|
+
didNonces.add(nonce);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Validate that a nonce hasn't been used and mark it as used
|
|
75
|
+
* @throws {NonceError} if nonce has already been used
|
|
76
|
+
*/
|
|
77
|
+
async validateAndMarkNonce(agentContext, proverDid, nonce) {
|
|
78
|
+
if (await this.isNonceUsed(agentContext, proverDid, nonce)) throw new NonceError(`Nonce '${nonce}' has already been used by '${proverDid}'`);
|
|
79
|
+
await this.markNonceUsed(agentContext, proverDid, nonce);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validate nonce format
|
|
83
|
+
*/
|
|
84
|
+
validateNonceFormat(nonce) {
|
|
85
|
+
return /^0x[0-9a-fA-F]{64}$/.test(nonce);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Validate session ID format
|
|
89
|
+
*/
|
|
90
|
+
validateSessionIdFormat(sessionId) {
|
|
91
|
+
return /^0x[0-9a-fA-F]{32}$/.test(sessionId);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Clear used nonces for a specific DID (useful for testing or cleanup)
|
|
95
|
+
*/
|
|
96
|
+
async clearNonces(agentContext, proverDid) {
|
|
97
|
+
this.nonceCache.delete(proverDid);
|
|
98
|
+
const records = await this.nonceRepository.findByProverDid(agentContext, proverDid);
|
|
99
|
+
for (const record of records) await this.nonceRepository.delete(agentContext, record);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Clear all used nonces (useful for testing)
|
|
103
|
+
*/
|
|
104
|
+
async clearAll(agentContext) {
|
|
105
|
+
this.nonceCache.clear();
|
|
106
|
+
const allRecords = await this.nonceRepository.getAll(agentContext);
|
|
107
|
+
for (const record of allRecords) await this.nonceRepository.delete(agentContext, record);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Delete nonces older than specified time (for cleanup/maintenance)
|
|
111
|
+
*
|
|
112
|
+
* @param agentContext - Agent context
|
|
113
|
+
* @param olderThanMs - Delete nonces older than this many milliseconds
|
|
114
|
+
* @returns Number of nonces deleted
|
|
115
|
+
*/
|
|
116
|
+
async deleteOldNonces(agentContext, olderThanMs = 1440 * 60 * 1e3) {
|
|
117
|
+
const deletedCount = await this.nonceRepository.deleteOlderThan(agentContext, olderThanMs);
|
|
118
|
+
this.nonceCache.clear();
|
|
119
|
+
return deletedCount;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
NonceService = __decorate([injectable(), __decorateMetadata("design:paramtypes", [NonceRepository])], NonceService);
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
export { NonceService };
|
|
126
|
+
//# sourceMappingURL=NonceService.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceService.mjs","names":[],"sources":["../../src/services/NonceService.ts"],"sourcesContent":["import type { AgentContext } from '@credo-ts/core'\n\nimport { randomBytes } from 'crypto'\nimport { injectable } from 'tsyringe'\nimport { NonceError } from '../errors'\nimport { NonceRepository } from '../repository/NonceRepository'\nimport { NonceRecord } from '../repository/NonceRecord'\n\n/**\n * Service for generating and validating nonces to prevent replay attacks.\n *\n * Uses persistent storage (Askar DB) with an in-memory cache for performance.\n * Nonces persist across agent restarts to prevent replay attacks.\n */\n@injectable()\nexport class NonceService {\n // In-memory cache for fast lookups (key: proverDid, value: Set of nonces)\n private nonceCache: Map<string, Set<string>> = new Map()\n\n public constructor(private nonceRepository: NonceRepository) {}\n\n /**\n * Generate a cryptographically secure nonce\n * @returns 32-byte hex string with 0x prefix\n */\n public generateNonce(): string {\n const nonceBytes = randomBytes(32)\n return '0x' + nonceBytes.toString('hex')\n }\n\n /**\n * Generate a session ID (16 bytes)\n * @returns 16-byte hex string with 0x prefix\n */\n public generateSessionId(): string {\n const sessionBytes = randomBytes(16)\n return '0x' + sessionBytes.toString('hex')\n }\n\n /**\n * Check if a nonce has been used by a specific DID\n *\n * First checks in-memory cache, falls back to repository if not found.\n * This provides fast lookups while maintaining persistence.\n */\n public async isNonceUsed(\n agentContext: AgentContext,\n proverDid: string,\n nonce: string\n ): Promise<boolean> {\n const normalizedNonce = nonce.toLowerCase()\n\n // Check cache first\n const cachedNonces = this.nonceCache.get(proverDid)\n if (cachedNonces && cachedNonces.has(normalizedNonce)) {\n return true\n }\n\n // Check repository\n const record = await this.nonceRepository.findByProverAndNonce(\n agentContext,\n proverDid,\n normalizedNonce\n )\n\n if (record) {\n // Cache the result\n this.addToCache(proverDid, normalizedNonce)\n return true\n }\n\n return false\n }\n\n /**\n * Mark a nonce as used by a specific DID\n *\n * Stores in both repository (persistent) and cache (fast access).\n */\n public async markNonceUsed(\n agentContext: AgentContext,\n proverDid: string,\n nonce: string\n ): Promise<void> {\n const normalizedNonce = nonce.toLowerCase()\n\n // Save to repository (persistent storage)\n const record = new NonceRecord({\n proverDid,\n nonce: normalizedNonce,\n usedAt: Date.now(),\n })\n await this.nonceRepository.save(agentContext, record)\n\n // Add to cache\n this.addToCache(proverDid, normalizedNonce)\n }\n\n /**\n * Helper to add nonce to in-memory cache\n */\n private addToCache(proverDid: string, nonce: string): void {\n let didNonces = this.nonceCache.get(proverDid)\n if (!didNonces) {\n didNonces = new Set()\n this.nonceCache.set(proverDid, didNonces)\n }\n didNonces.add(nonce)\n }\n\n /**\n * Validate that a nonce hasn't been used and mark it as used\n * @throws {NonceError} if nonce has already been used\n */\n public async validateAndMarkNonce(\n agentContext: AgentContext,\n proverDid: string,\n nonce: string\n ): Promise<void> {\n const used = await this.isNonceUsed(agentContext, proverDid, nonce)\n if (used) {\n throw new NonceError(`Nonce '${nonce}' has already been used by '${proverDid}'`)\n }\n await this.markNonceUsed(agentContext, proverDid, nonce)\n }\n\n /**\n * Validate nonce format\n */\n public validateNonceFormat(nonce: string): boolean {\n const hexPattern = /^0x[0-9a-fA-F]{64}$/\n return hexPattern.test(nonce)\n }\n\n /**\n * Validate session ID format\n */\n public validateSessionIdFormat(sessionId: string): boolean {\n const hexPattern = /^0x[0-9a-fA-F]{32}$/\n return hexPattern.test(sessionId)\n }\n\n /**\n * Clear used nonces for a specific DID (useful for testing or cleanup)\n */\n public async clearNonces(agentContext: AgentContext, proverDid: string): Promise<void> {\n // Clear from cache\n this.nonceCache.delete(proverDid)\n\n // Clear from repository\n const records = await this.nonceRepository.findByProverDid(agentContext, proverDid)\n for (const record of records) {\n await this.nonceRepository.delete(agentContext, record)\n }\n }\n\n /**\n * Clear all used nonces (useful for testing)\n */\n public async clearAll(agentContext: AgentContext): Promise<void> {\n // Clear cache\n this.nonceCache.clear()\n\n // Clear repository\n const allRecords = await this.nonceRepository.getAll(agentContext)\n for (const record of allRecords) {\n await this.nonceRepository.delete(agentContext, record)\n }\n }\n\n /**\n * Delete nonces older than specified time (for cleanup/maintenance)\n *\n * @param agentContext - Agent context\n * @param olderThanMs - Delete nonces older than this many milliseconds\n * @returns Number of nonces deleted\n */\n public async deleteOldNonces(\n agentContext: AgentContext,\n olderThanMs: number = 24 * 60 * 60 * 1000 // Default: 24 hours\n ): Promise<number> {\n const deletedCount = await this.nonceRepository.deleteOlderThan(agentContext, olderThanMs)\n\n // Invalidate cache (simple approach - clear all)\n // Could be optimized to only remove specific entries\n this.nonceCache.clear()\n\n return deletedCount\n }\n}\n"],"mappings":";;;;;;;;;;;AAeO,yBAAM,aAAa;CAIxB,AAAO,YAAY,AAAQ,iBAAkC;EAAlC;OAFnB,6BAAuC,IAAI,KAAK;;;;;;CAQxD,AAAO,gBAAwB;AAE7B,SAAO,OADY,YAAY,GAAG,CACT,SAAS,MAAM;;;;;;CAO1C,AAAO,oBAA4B;AAEjC,SAAO,OADc,YAAY,GAAG,CACT,SAAS,MAAM;;;;;;;;CAS5C,MAAa,YACX,cACA,WACA,OACkB;EAClB,MAAM,kBAAkB,MAAM,aAAa;EAG3C,MAAM,eAAe,KAAK,WAAW,IAAI,UAAU;AACnD,MAAI,gBAAgB,aAAa,IAAI,gBAAgB,CACnD,QAAO;AAUT,MANe,MAAM,KAAK,gBAAgB,qBACxC,cACA,WACA,gBACD,EAEW;AAEV,QAAK,WAAW,WAAW,gBAAgB;AAC3C,UAAO;;AAGT,SAAO;;;;;;;CAQT,MAAa,cACX,cACA,WACA,OACe;EACf,MAAM,kBAAkB,MAAM,aAAa;EAG3C,MAAM,SAAS,IAAI,YAAY;GAC7B;GACA,OAAO;GACP,QAAQ,KAAK,KAAK;GACnB,CAAC;AACF,QAAM,KAAK,gBAAgB,KAAK,cAAc,OAAO;AAGrD,OAAK,WAAW,WAAW,gBAAgB;;;;;CAM7C,AAAQ,WAAW,WAAmB,OAAqB;EACzD,IAAI,YAAY,KAAK,WAAW,IAAI,UAAU;AAC9C,MAAI,CAAC,WAAW;AACd,+BAAY,IAAI,KAAK;AACrB,QAAK,WAAW,IAAI,WAAW,UAAU;;AAE3C,YAAU,IAAI,MAAM;;;;;;CAOtB,MAAa,qBACX,cACA,WACA,OACe;AAEf,MADa,MAAM,KAAK,YAAY,cAAc,WAAW,MAAM,CAEjE,OAAM,IAAI,WAAW,UAAU,MAAM,8BAA8B,UAAU,GAAG;AAElF,QAAM,KAAK,cAAc,cAAc,WAAW,MAAM;;;;;CAM1D,AAAO,oBAAoB,OAAwB;AAEjD,SADmB,sBACD,KAAK,MAAM;;;;;CAM/B,AAAO,wBAAwB,WAA4B;AAEzD,SADmB,sBACD,KAAK,UAAU;;;;;CAMnC,MAAa,YAAY,cAA4B,WAAkC;AAErF,OAAK,WAAW,OAAO,UAAU;EAGjC,MAAM,UAAU,MAAM,KAAK,gBAAgB,gBAAgB,cAAc,UAAU;AACnF,OAAK,MAAM,UAAU,QACnB,OAAM,KAAK,gBAAgB,OAAO,cAAc,OAAO;;;;;CAO3D,MAAa,SAAS,cAA2C;AAE/D,OAAK,WAAW,OAAO;EAGvB,MAAM,aAAa,MAAM,KAAK,gBAAgB,OAAO,aAAa;AAClE,OAAK,MAAM,UAAU,WACnB,OAAM,KAAK,gBAAgB,OAAO,cAAc,OAAO;;;;;;;;;CAW3D,MAAa,gBACX,cACA,cAAsB,OAAU,KAAK,KACpB;EACjB,MAAM,eAAe,MAAM,KAAK,gBAAgB,gBAAgB,cAAc,YAAY;AAI1F,OAAK,WAAW,OAAO;AAEvB,SAAO;;;2BA7KV,YAAY"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { BindingContext } from "../models/BindingContext.mjs";
|
|
2
|
+
import { ProgramExecution } from "../models/ProgramExecution.mjs";
|
|
3
|
+
import { ChallengeSpec, ProofArtifact } from "../models/ProofArtifact.mjs";
|
|
4
|
+
import { PoeSessionRecord } from "../repository/PoeSessionRecord.mjs";
|
|
5
|
+
import { PoeSessionRepository } from "../repository/PoeSessionRepository.mjs";
|
|
6
|
+
import "../repository/index.mjs";
|
|
7
|
+
import { ProgramRegistry } from "../registry/ProgramRegistry.mjs";
|
|
8
|
+
import "../registry/index.mjs";
|
|
9
|
+
import { NonceService } from "./NonceService.mjs";
|
|
10
|
+
import { ContextBindingService } from "./ContextBindingService.mjs";
|
|
11
|
+
import { ProofVerificationService } from "./ProofVerificationService.mjs";
|
|
12
|
+
import { RequestPoeMessage } from "../messages/RequestPoeMessage.mjs";
|
|
13
|
+
import { ProposePoeMessage } from "../messages/ProposePoeMessage.mjs";
|
|
14
|
+
import { AcceptPoeMessage } from "../messages/AcceptPoeMessage.mjs";
|
|
15
|
+
import { DeclinePoeMessage } from "../messages/DeclinePoeMessage.mjs";
|
|
16
|
+
import { ChallengeMessage } from "../messages/ChallengeMessage.mjs";
|
|
17
|
+
import { SubmitPoeMessage } from "../messages/SubmitPoeMessage.mjs";
|
|
18
|
+
import { CompleteMessage } from "../messages/CompleteMessage.mjs";
|
|
19
|
+
import { PoeProblemReportMessage } from "../messages/PoeProblemReportMessage.mjs";
|
|
20
|
+
import "../messages/index.mjs";
|
|
21
|
+
import "./index.mjs";
|
|
22
|
+
import { DidCommInboundMessageContext } from "@credo-ts/didcomm";
|
|
23
|
+
import { AgentContext, EventEmitter, Logger } from "@credo-ts/core";
|
|
24
|
+
|
|
25
|
+
//#region src/services/PoeService.d.ts
|
|
26
|
+
interface CreateRequestOptions {
|
|
27
|
+
connectionId: string;
|
|
28
|
+
programs: ProgramExecution[];
|
|
29
|
+
bindingContext: BindingContext;
|
|
30
|
+
expiry?: string;
|
|
31
|
+
transportHints?: Record<string, unknown>;
|
|
32
|
+
parentThreadId?: string;
|
|
33
|
+
}
|
|
34
|
+
interface CreateProposalOptions {
|
|
35
|
+
poeRecord: PoeSessionRecord;
|
|
36
|
+
program: Partial<ProgramExecution>;
|
|
37
|
+
disclosure?: string;
|
|
38
|
+
}
|
|
39
|
+
interface CreateSubmitOptions {
|
|
40
|
+
poeRecord: PoeSessionRecord;
|
|
41
|
+
proofArtifact: ProofArtifact;
|
|
42
|
+
attachments?: unknown[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Main service for orchestrating the PoE protocol
|
|
46
|
+
*/
|
|
47
|
+
declare class PoeService {
|
|
48
|
+
private sessionRepository;
|
|
49
|
+
private programRegistry;
|
|
50
|
+
private proofVerificationService;
|
|
51
|
+
private nonceService;
|
|
52
|
+
private contextBindingService;
|
|
53
|
+
private eventEmitter;
|
|
54
|
+
private logger;
|
|
55
|
+
constructor(logger: Logger, sessionRepository: PoeSessionRepository, programRegistry: ProgramRegistry, proofVerificationService: ProofVerificationService, nonceService: NonceService, contextBindingService: ContextBindingService, eventEmitter: EventEmitter);
|
|
56
|
+
/**
|
|
57
|
+
* Safely get threadId from a message, throwing if not present
|
|
58
|
+
*/
|
|
59
|
+
private getThreadId;
|
|
60
|
+
/**
|
|
61
|
+
* Create a proof execution request (Requester side)
|
|
62
|
+
*/
|
|
63
|
+
createRequest(agentContext: AgentContext, options: CreateRequestOptions): Promise<{
|
|
64
|
+
message: RequestPoeMessage;
|
|
65
|
+
record: PoeSessionRecord;
|
|
66
|
+
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Process incoming proof execution request (Prover side)
|
|
69
|
+
*/
|
|
70
|
+
processRequest(messageContext: DidCommInboundMessageContext<RequestPoeMessage>): Promise<PoeSessionRecord>;
|
|
71
|
+
/**
|
|
72
|
+
* Create a proposal (Prover side)
|
|
73
|
+
*/
|
|
74
|
+
createProposal(agentContext: AgentContext, options: CreateProposalOptions): Promise<{
|
|
75
|
+
message: ProposePoeMessage;
|
|
76
|
+
record: PoeSessionRecord;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Process incoming proposal (Requester side)
|
|
80
|
+
*/
|
|
81
|
+
processProposal(messageContext: DidCommInboundMessageContext<ProposePoeMessage>): Promise<PoeSessionRecord>;
|
|
82
|
+
/**
|
|
83
|
+
* Accept a proposal
|
|
84
|
+
*/
|
|
85
|
+
acceptProposal(agentContext: AgentContext, poeRecord: PoeSessionRecord): Promise<{
|
|
86
|
+
message: AcceptPoeMessage;
|
|
87
|
+
record: PoeSessionRecord;
|
|
88
|
+
}>;
|
|
89
|
+
/**
|
|
90
|
+
* Decline a proposal
|
|
91
|
+
*/
|
|
92
|
+
declineProposal(agentContext: AgentContext, poeRecord: PoeSessionRecord, reason?: string): Promise<{
|
|
93
|
+
message: DeclinePoeMessage;
|
|
94
|
+
record: PoeSessionRecord;
|
|
95
|
+
}>;
|
|
96
|
+
/**
|
|
97
|
+
* Process incoming accept message (Prover side)
|
|
98
|
+
*/
|
|
99
|
+
processAccept(messageContext: DidCommInboundMessageContext<AcceptPoeMessage>): Promise<PoeSessionRecord>;
|
|
100
|
+
/**
|
|
101
|
+
* Process incoming decline message (Prover side)
|
|
102
|
+
*/
|
|
103
|
+
processDecline(messageContext: DidCommInboundMessageContext<DeclinePoeMessage>): Promise<PoeSessionRecord>;
|
|
104
|
+
/**
|
|
105
|
+
* Create a challenge message (Requester side)
|
|
106
|
+
*/
|
|
107
|
+
createChallenge(agentContext: AgentContext, poeRecord: PoeSessionRecord, challengeSpec: ChallengeSpec, sequence?: number): Promise<{
|
|
108
|
+
message: ChallengeMessage;
|
|
109
|
+
record: PoeSessionRecord;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Process incoming challenge message (Prover side)
|
|
113
|
+
*/
|
|
114
|
+
processChallenge(messageContext: DidCommInboundMessageContext<ChallengeMessage>): Promise<PoeSessionRecord>;
|
|
115
|
+
/**
|
|
116
|
+
* Process incoming complete message (Prover side)
|
|
117
|
+
*/
|
|
118
|
+
processComplete(messageContext: DidCommInboundMessageContext<CompleteMessage>): Promise<PoeSessionRecord>;
|
|
119
|
+
/**
|
|
120
|
+
* Submit proof (Prover side)
|
|
121
|
+
*/
|
|
122
|
+
submitProof(agentContext: AgentContext, options: CreateSubmitOptions): Promise<{
|
|
123
|
+
message: SubmitPoeMessage;
|
|
124
|
+
record: PoeSessionRecord;
|
|
125
|
+
}>;
|
|
126
|
+
/**
|
|
127
|
+
* Process incoming proof submission (Requester side)
|
|
128
|
+
*/
|
|
129
|
+
processSubmit(messageContext: DidCommInboundMessageContext<SubmitPoeMessage>): Promise<PoeSessionRecord>;
|
|
130
|
+
/**
|
|
131
|
+
* Complete the protocol
|
|
132
|
+
*/
|
|
133
|
+
complete(agentContext: AgentContext, poeRecord: PoeSessionRecord, issueReceipt?: boolean): Promise<{
|
|
134
|
+
message: CompleteMessage;
|
|
135
|
+
record: PoeSessionRecord;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Send problem report
|
|
139
|
+
*/
|
|
140
|
+
createProblemReport(agentContext: AgentContext, poeRecord: PoeSessionRecord, code: string, explain?: string, details?: Record<string, unknown>): Promise<{
|
|
141
|
+
message: PoeProblemReportMessage;
|
|
142
|
+
record: PoeSessionRecord;
|
|
143
|
+
}>;
|
|
144
|
+
/**
|
|
145
|
+
* Process incoming problem report
|
|
146
|
+
*/
|
|
147
|
+
processProblemReport(messageContext: DidCommInboundMessageContext<PoeProblemReportMessage>): Promise<PoeSessionRecord>;
|
|
148
|
+
/**
|
|
149
|
+
* Get session by thread and connection ID
|
|
150
|
+
*/
|
|
151
|
+
private getByThreadAndConnectionId;
|
|
152
|
+
/**
|
|
153
|
+
* Update session state and emit event
|
|
154
|
+
*/
|
|
155
|
+
private updateState;
|
|
156
|
+
/**
|
|
157
|
+
* Emit state changed event
|
|
158
|
+
*/
|
|
159
|
+
private emitStateChangedEvent;
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
export { CreateProposalOptions, CreateRequestOptions, CreateSubmitOptions, PoeService };
|
|
163
|
+
//# sourceMappingURL=PoeService.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PoeService.d.mts","names":[],"sources":["../../src/services/PoeService.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;UA0BiB,oBAAA;EACf,YAAA;EACA,QAAA,EAAU,gBAAA;EACV,cAAA,EAAgB,cAAA;EAChB,MAAA;EACA,cAAA,GAAiB,MAAA;EACjB,cAAA;AAAA;AAAA,UAGe,qBAAA;EACf,SAAA,EAAW,gBAAA;EACX,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