@mcp-i/core 0.1.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 +21 -0
- package/README.md +390 -0
- package/dist/auth/handshake.d.ts +104 -0
- package/dist/auth/handshake.d.ts.map +1 -0
- package/dist/auth/handshake.js +230 -0
- package/dist/auth/handshake.js.map +1 -0
- package/dist/auth/index.d.ts +3 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +2 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/types.d.ts +31 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +7 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/delegation/audience-validator.d.ts +9 -0
- package/dist/delegation/audience-validator.d.ts.map +1 -0
- package/dist/delegation/audience-validator.js +17 -0
- package/dist/delegation/audience-validator.js.map +1 -0
- package/dist/delegation/bitstring.d.ts +37 -0
- package/dist/delegation/bitstring.d.ts.map +1 -0
- package/dist/delegation/bitstring.js +117 -0
- package/dist/delegation/bitstring.js.map +1 -0
- package/dist/delegation/cascading-revocation.d.ts +45 -0
- package/dist/delegation/cascading-revocation.d.ts.map +1 -0
- package/dist/delegation/cascading-revocation.js +148 -0
- package/dist/delegation/cascading-revocation.js.map +1 -0
- package/dist/delegation/delegation-graph.d.ts +49 -0
- package/dist/delegation/delegation-graph.d.ts.map +1 -0
- package/dist/delegation/delegation-graph.js +99 -0
- package/dist/delegation/delegation-graph.js.map +1 -0
- package/dist/delegation/did-key-resolver.d.ts +64 -0
- package/dist/delegation/did-key-resolver.d.ts.map +1 -0
- package/dist/delegation/did-key-resolver.js +154 -0
- package/dist/delegation/did-key-resolver.js.map +1 -0
- package/dist/delegation/did-web-resolver.d.ts +83 -0
- package/dist/delegation/did-web-resolver.d.ts.map +1 -0
- package/dist/delegation/did-web-resolver.js +218 -0
- package/dist/delegation/did-web-resolver.js.map +1 -0
- package/dist/delegation/index.d.ts +21 -0
- package/dist/delegation/index.d.ts.map +1 -0
- package/dist/delegation/index.js +21 -0
- package/dist/delegation/index.js.map +1 -0
- package/dist/delegation/outbound-headers.d.ts +81 -0
- package/dist/delegation/outbound-headers.d.ts.map +1 -0
- package/dist/delegation/outbound-headers.js +139 -0
- package/dist/delegation/outbound-headers.js.map +1 -0
- package/dist/delegation/outbound-proof.d.ts +43 -0
- package/dist/delegation/outbound-proof.d.ts.map +1 -0
- package/dist/delegation/outbound-proof.js +52 -0
- package/dist/delegation/outbound-proof.js.map +1 -0
- package/dist/delegation/statuslist-manager.d.ts +44 -0
- package/dist/delegation/statuslist-manager.d.ts.map +1 -0
- package/dist/delegation/statuslist-manager.js +126 -0
- package/dist/delegation/statuslist-manager.js.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts +70 -0
- package/dist/delegation/storage/memory-graph-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-graph-storage.js +145 -0
- package/dist/delegation/storage/memory-graph-storage.js.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts +19 -0
- package/dist/delegation/storage/memory-statuslist-storage.d.ts.map +1 -0
- package/dist/delegation/storage/memory-statuslist-storage.js +33 -0
- package/dist/delegation/storage/memory-statuslist-storage.js.map +1 -0
- package/dist/delegation/utils.d.ts +49 -0
- package/dist/delegation/utils.d.ts.map +1 -0
- package/dist/delegation/utils.js +131 -0
- package/dist/delegation/utils.js.map +1 -0
- package/dist/delegation/vc-issuer.d.ts +56 -0
- package/dist/delegation/vc-issuer.d.ts.map +1 -0
- package/dist/delegation/vc-issuer.js +80 -0
- package/dist/delegation/vc-issuer.js.map +1 -0
- package/dist/delegation/vc-verifier.d.ts +112 -0
- package/dist/delegation/vc-verifier.d.ts.map +1 -0
- package/dist/delegation/vc-verifier.js +280 -0
- package/dist/delegation/vc-verifier.js.map +1 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/index.d.ts +2 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +2 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +23 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +82 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/middleware/index.d.ts +7 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/middleware/index.js +7 -0
- package/dist/middleware/index.js.map +1 -0
- package/dist/middleware/with-mcpi.d.ts +152 -0
- package/dist/middleware/with-mcpi.d.ts.map +1 -0
- package/dist/middleware/with-mcpi.js +472 -0
- package/dist/middleware/with-mcpi.js.map +1 -0
- package/dist/proof/errors.d.ts +49 -0
- package/dist/proof/errors.d.ts.map +1 -0
- package/dist/proof/errors.js +61 -0
- package/dist/proof/errors.js.map +1 -0
- package/dist/proof/generator.d.ts +65 -0
- package/dist/proof/generator.d.ts.map +1 -0
- package/dist/proof/generator.js +163 -0
- package/dist/proof/generator.js.map +1 -0
- package/dist/proof/index.d.ts +4 -0
- package/dist/proof/index.d.ts.map +1 -0
- package/dist/proof/index.js +4 -0
- package/dist/proof/index.js.map +1 -0
- package/dist/proof/verifier.d.ts +108 -0
- package/dist/proof/verifier.d.ts.map +1 -0
- package/dist/proof/verifier.js +299 -0
- package/dist/proof/verifier.js.map +1 -0
- package/dist/providers/base.d.ts +64 -0
- package/dist/providers/base.d.ts.map +1 -0
- package/dist/providers/base.js +19 -0
- package/dist/providers/base.js.map +1 -0
- package/dist/providers/index.d.ts +3 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +3 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/memory.d.ts +33 -0
- package/dist/providers/memory.d.ts.map +1 -0
- package/dist/providers/memory.js +102 -0
- package/dist/providers/memory.js.map +1 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +2 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/manager.d.ts +77 -0
- package/dist/session/manager.d.ts.map +1 -0
- package/dist/session/manager.js +251 -0
- package/dist/session/manager.js.map +1 -0
- package/dist/types/protocol.d.ts +320 -0
- package/dist/types/protocol.d.ts.map +1 -0
- package/dist/types/protocol.js +229 -0
- package/dist/types/protocol.js.map +1 -0
- package/dist/utils/base58.d.ts +31 -0
- package/dist/utils/base58.d.ts.map +1 -0
- package/dist/utils/base58.js +104 -0
- package/dist/utils/base58.js.map +1 -0
- package/dist/utils/base64.d.ts +13 -0
- package/dist/utils/base64.d.ts.map +1 -0
- package/dist/utils/base64.js +99 -0
- package/dist/utils/base64.js.map +1 -0
- package/dist/utils/crypto-service.d.ts +37 -0
- package/dist/utils/crypto-service.d.ts.map +1 -0
- package/dist/utils/crypto-service.js +153 -0
- package/dist/utils/crypto-service.js.map +1 -0
- package/dist/utils/did-helpers.d.ts +156 -0
- package/dist/utils/did-helpers.d.ts.map +1 -0
- package/dist/utils/did-helpers.js +193 -0
- package/dist/utils/did-helpers.js.map +1 -0
- package/dist/utils/ed25519-constants.d.ts +18 -0
- package/dist/utils/ed25519-constants.d.ts.map +1 -0
- package/dist/utils/ed25519-constants.js +21 -0
- package/dist/utils/ed25519-constants.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +5 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +105 -0
- package/src/__tests__/integration/full-flow.test.ts +362 -0
- package/src/__tests__/providers/base.test.ts +173 -0
- package/src/__tests__/providers/memory.test.ts +332 -0
- package/src/__tests__/utils/mock-providers.ts +319 -0
- package/src/__tests__/utils/node-crypto-provider.ts +93 -0
- package/src/auth/handshake.ts +411 -0
- package/src/auth/index.ts +11 -0
- package/src/auth/types.ts +40 -0
- package/src/delegation/__tests__/audience-validator.test.ts +110 -0
- package/src/delegation/__tests__/bitstring.test.ts +346 -0
- package/src/delegation/__tests__/cascading-revocation.test.ts +624 -0
- package/src/delegation/__tests__/delegation-graph.test.ts +623 -0
- package/src/delegation/__tests__/did-key-resolver.test.ts +265 -0
- package/src/delegation/__tests__/did-web-resolver.test.ts +467 -0
- package/src/delegation/__tests__/outbound-headers.test.ts +230 -0
- package/src/delegation/__tests__/outbound-proof.test.ts +179 -0
- package/src/delegation/__tests__/statuslist-manager.test.ts +515 -0
- package/src/delegation/__tests__/utils.test.ts +185 -0
- package/src/delegation/__tests__/vc-issuer.test.ts +487 -0
- package/src/delegation/__tests__/vc-verifier.test.ts +1029 -0
- package/src/delegation/audience-validator.ts +24 -0
- package/src/delegation/bitstring.ts +160 -0
- package/src/delegation/cascading-revocation.ts +224 -0
- package/src/delegation/delegation-graph.ts +143 -0
- package/src/delegation/did-key-resolver.ts +181 -0
- package/src/delegation/did-web-resolver.ts +270 -0
- package/src/delegation/index.ts +33 -0
- package/src/delegation/outbound-headers.ts +193 -0
- package/src/delegation/outbound-proof.ts +90 -0
- package/src/delegation/statuslist-manager.ts +219 -0
- package/src/delegation/storage/__tests__/memory-graph-storage.test.ts +366 -0
- package/src/delegation/storage/__tests__/memory-statuslist-storage.test.ts +228 -0
- package/src/delegation/storage/memory-graph-storage.ts +178 -0
- package/src/delegation/storage/memory-statuslist-storage.ts +42 -0
- package/src/delegation/utils.ts +189 -0
- package/src/delegation/vc-issuer.ts +137 -0
- package/src/delegation/vc-verifier.ts +440 -0
- package/src/index.ts +264 -0
- package/src/logging/__tests__/logger.test.ts +366 -0
- package/src/logging/index.ts +6 -0
- package/src/logging/logger.ts +91 -0
- package/src/middleware/__tests__/with-mcpi.test.ts +504 -0
- package/src/middleware/index.ts +16 -0
- package/src/middleware/with-mcpi.ts +766 -0
- package/src/proof/__tests__/proof-generator.test.ts +483 -0
- package/src/proof/__tests__/verifier.test.ts +488 -0
- package/src/proof/errors.ts +75 -0
- package/src/proof/generator.ts +255 -0
- package/src/proof/index.ts +22 -0
- package/src/proof/verifier.ts +449 -0
- package/src/providers/base.ts +68 -0
- package/src/providers/index.ts +15 -0
- package/src/providers/memory.ts +130 -0
- package/src/session/__tests__/session-manager.test.ts +342 -0
- package/src/session/index.ts +7 -0
- package/src/session/manager.ts +332 -0
- package/src/types/protocol.ts +596 -0
- package/src/utils/__tests__/base58.test.ts +281 -0
- package/src/utils/__tests__/base64.test.ts +239 -0
- package/src/utils/__tests__/crypto-service.test.ts +530 -0
- package/src/utils/__tests__/did-helpers.test.ts +156 -0
- package/src/utils/base58.ts +115 -0
- package/src/utils/base64.ts +116 -0
- package/src/utils/crypto-service.ts +209 -0
- package/src/utils/did-helpers.ts +210 -0
- package/src/utils/ed25519-constants.ts +23 -0
- package/src/utils/index.ts +9 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proof Generation — Platform-agnostic Protocol Reference
|
|
3
|
+
*
|
|
4
|
+
* Handles JCS canonicalization, SHA-256 digest generation, and Ed25519 JWS
|
|
5
|
+
* signing (compact format) according to MCP-I requirements 5.1, 5.2, 5.3, 5.6.
|
|
6
|
+
*
|
|
7
|
+
* This module is the authoritative proof implementation. All platform adapters
|
|
8
|
+
* (Node.js, Cloudflare Workers) inject a CryptoProvider and delegate here.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { CompactSign, importPKCS8 } from 'jose';
|
|
12
|
+
import { canonicalize } from 'json-canonicalize';
|
|
13
|
+
import type {
|
|
14
|
+
DetachedProof,
|
|
15
|
+
ProofMeta,
|
|
16
|
+
CanonicalHashes,
|
|
17
|
+
SessionContext,
|
|
18
|
+
} from '../types/protocol.js';
|
|
19
|
+
import type { CryptoProvider } from '../providers/base.js';
|
|
20
|
+
import { CryptoService, type Ed25519JWK } from '../utils/crypto-service.js';
|
|
21
|
+
import { base64ToBytes, base64urlEncodeFromBytes, bytesToBase64 } from '../utils/base64.js';
|
|
22
|
+
import { ED25519_PKCS8_DER_HEADER, ED25519_KEY_SIZE } from '../utils/ed25519-constants.js';
|
|
23
|
+
|
|
24
|
+
export interface ProofAgentIdentity {
|
|
25
|
+
did: string;
|
|
26
|
+
kid: string;
|
|
27
|
+
privateKey: string;
|
|
28
|
+
publicKey: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ToolRequest {
|
|
32
|
+
method: string;
|
|
33
|
+
params?: unknown;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface ToolResponse {
|
|
37
|
+
data: unknown;
|
|
38
|
+
meta?: {
|
|
39
|
+
proof?: DetachedProof;
|
|
40
|
+
[key: string]: unknown;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface ProofOptions {
|
|
45
|
+
scopeId?: string;
|
|
46
|
+
delegationRef?: string;
|
|
47
|
+
clientDid?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export class ProofGenerator {
|
|
51
|
+
private identity: ProofAgentIdentity;
|
|
52
|
+
private cryptoProvider: CryptoProvider;
|
|
53
|
+
|
|
54
|
+
constructor(identity: ProofAgentIdentity, cryptoProvider: CryptoProvider) {
|
|
55
|
+
this.identity = identity;
|
|
56
|
+
this.cryptoProvider = cryptoProvider;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Generate a detached proof for an MCP tool call.
|
|
61
|
+
*
|
|
62
|
+
* Creates a JWS (JSON Web Signature) that binds the tool request and response
|
|
63
|
+
* to the agent's identity and current session context.
|
|
64
|
+
*
|
|
65
|
+
* @param request - The MCP tool request (method + params)
|
|
66
|
+
* @param response - The tool response data
|
|
67
|
+
* @param session - The current session context from handshake
|
|
68
|
+
* @param options - Optional proof metadata (scopeId, delegationRef, clientDid)
|
|
69
|
+
* @returns Detached proof containing JWS and proof metadata
|
|
70
|
+
* @throws {Error} If JWS generation fails (invalid key, crypto error)
|
|
71
|
+
*/
|
|
72
|
+
async generateProof(
|
|
73
|
+
request: ToolRequest,
|
|
74
|
+
response: ToolResponse,
|
|
75
|
+
session: SessionContext,
|
|
76
|
+
options: ProofOptions = {}
|
|
77
|
+
): Promise<DetachedProof> {
|
|
78
|
+
const hashes = await this.generateCanonicalHashes(request, response);
|
|
79
|
+
|
|
80
|
+
const meta: ProofMeta = {
|
|
81
|
+
did: this.identity.did,
|
|
82
|
+
kid: this.identity.kid,
|
|
83
|
+
ts: Math.floor(Date.now() / 1000),
|
|
84
|
+
nonce: session.nonce,
|
|
85
|
+
audience: session.audience,
|
|
86
|
+
sessionId: session.sessionId,
|
|
87
|
+
requestHash: hashes.requestHash,
|
|
88
|
+
responseHash: hashes.responseHash,
|
|
89
|
+
...options,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const jws = await this.generateJWS(meta);
|
|
93
|
+
|
|
94
|
+
return { jws, meta };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private async generateCanonicalHashes(
|
|
98
|
+
request: ToolRequest,
|
|
99
|
+
response: ToolResponse
|
|
100
|
+
): Promise<CanonicalHashes> {
|
|
101
|
+
const canonicalRequest = {
|
|
102
|
+
method: request.method,
|
|
103
|
+
...(request.params ? { params: request.params } : {}),
|
|
104
|
+
};
|
|
105
|
+
const canonicalResponse = response.data;
|
|
106
|
+
|
|
107
|
+
const requestHash = await this.generateSHA256Hash(canonicalRequest);
|
|
108
|
+
const responseHash = await this.generateSHA256Hash(canonicalResponse);
|
|
109
|
+
|
|
110
|
+
return { requestHash, responseHash };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private async generateSHA256Hash(data: unknown): Promise<string> {
|
|
114
|
+
const canonicalJson = this.canonicalizeJSON(data);
|
|
115
|
+
const encoded = new TextEncoder().encode(canonicalJson);
|
|
116
|
+
return this.cryptoProvider.hash(encoded);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
private canonicalizeJSON(obj: unknown): string {
|
|
120
|
+
return canonicalize(obj as Parameters<typeof canonicalize>[0]);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
private async generateJWS(meta: ProofMeta): Promise<string> {
|
|
124
|
+
try {
|
|
125
|
+
const privateKeyPem = this.formatPrivateKeyAsPEM(this.identity.privateKey);
|
|
126
|
+
const privateKey = await importPKCS8(privateKeyPem, 'EdDSA');
|
|
127
|
+
|
|
128
|
+
const payload = {
|
|
129
|
+
aud: meta.audience,
|
|
130
|
+
sub: meta.did,
|
|
131
|
+
iss: meta.did,
|
|
132
|
+
requestHash: meta.requestHash,
|
|
133
|
+
responseHash: meta.responseHash,
|
|
134
|
+
ts: meta.ts,
|
|
135
|
+
nonce: meta.nonce,
|
|
136
|
+
sessionId: meta.sessionId,
|
|
137
|
+
...(meta.scopeId && { scopeId: meta.scopeId }),
|
|
138
|
+
...(meta.delegationRef && { delegationRef: meta.delegationRef }),
|
|
139
|
+
...(meta.clientDid && { clientDid: meta.clientDid }),
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// Use canonicalized JSON (RFC 8785) for deterministic payload serialization.
|
|
143
|
+
// This ensures signature verification succeeds regardless of JSON key ordering.
|
|
144
|
+
const canonicalPayload = canonicalize(payload as Parameters<typeof canonicalize>[0]);
|
|
145
|
+
const payloadBytes = new TextEncoder().encode(canonicalPayload);
|
|
146
|
+
|
|
147
|
+
const jws = await new CompactSign(payloadBytes)
|
|
148
|
+
.setProtectedHeader({
|
|
149
|
+
alg: 'EdDSA',
|
|
150
|
+
kid: this.identity.kid,
|
|
151
|
+
})
|
|
152
|
+
.sign(privateKey);
|
|
153
|
+
|
|
154
|
+
return jws;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw new Error(
|
|
157
|
+
`Failed to generate JWS: ${error instanceof Error ? error.message : 'Unknown error'}`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private formatPrivateKeyAsPEM(base64PrivateKey: string): string {
|
|
163
|
+
const keyData = base64ToBytes(base64PrivateKey);
|
|
164
|
+
|
|
165
|
+
// Extract raw 32-byte seed
|
|
166
|
+
const rawKey = keyData.subarray(0, ED25519_KEY_SIZE);
|
|
167
|
+
|
|
168
|
+
// Build full PKCS#8 key: header + raw key
|
|
169
|
+
const fullKey = new Uint8Array(ED25519_PKCS8_DER_HEADER.length + rawKey.length);
|
|
170
|
+
fullKey.set(ED25519_PKCS8_DER_HEADER);
|
|
171
|
+
fullKey.set(rawKey, ED25519_PKCS8_DER_HEADER.length);
|
|
172
|
+
|
|
173
|
+
const base64Key = bytesToBase64(fullKey);
|
|
174
|
+
const formattedKey = base64Key.match(/.{1,64}/g)?.join('\n') ?? base64Key;
|
|
175
|
+
|
|
176
|
+
return (
|
|
177
|
+
'-----BEGIN PRIVATE KEY-----\n' +
|
|
178
|
+
formattedKey +
|
|
179
|
+
'\n-----END PRIVATE KEY-----'
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async verifyProof(
|
|
184
|
+
proof: DetachedProof,
|
|
185
|
+
request: ToolRequest,
|
|
186
|
+
response: ToolResponse
|
|
187
|
+
): Promise<boolean> {
|
|
188
|
+
try {
|
|
189
|
+
const expectedHashes = await this.generateCanonicalHashes(request, response);
|
|
190
|
+
|
|
191
|
+
if (
|
|
192
|
+
proof.meta.requestHash !== expectedHashes.requestHash ||
|
|
193
|
+
proof.meta.responseHash !== expectedHashes.responseHash
|
|
194
|
+
) {
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const publicKeyJwk = this.base64PublicKeyToJWK(this.identity.publicKey);
|
|
199
|
+
const cryptoService = new CryptoService(this.cryptoProvider);
|
|
200
|
+
|
|
201
|
+
return cryptoService.verifyJWS(proof.jws, publicKeyJwk, {
|
|
202
|
+
expectedKid: this.identity.kid,
|
|
203
|
+
alg: 'EdDSA',
|
|
204
|
+
});
|
|
205
|
+
} catch {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private base64PublicKeyToJWK(publicKeyBase64: string): Ed25519JWK {
|
|
211
|
+
const publicKeyBytes = base64ToBytes(publicKeyBase64);
|
|
212
|
+
|
|
213
|
+
if (publicKeyBytes.length !== ED25519_KEY_SIZE) {
|
|
214
|
+
throw new Error(`Invalid Ed25519 public key length: ${publicKeyBytes.length}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return {
|
|
218
|
+
kty: 'OKP',
|
|
219
|
+
crv: 'Ed25519',
|
|
220
|
+
x: base64urlEncodeFromBytes(publicKeyBytes),
|
|
221
|
+
kid: this.identity.kid,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export async function createProofResponse(
|
|
227
|
+
request: ToolRequest,
|
|
228
|
+
data: unknown,
|
|
229
|
+
identity: ProofAgentIdentity,
|
|
230
|
+
session: SessionContext,
|
|
231
|
+
cryptoProvider: CryptoProvider,
|
|
232
|
+
options: ProofOptions = {}
|
|
233
|
+
): Promise<ToolResponse> {
|
|
234
|
+
const response: ToolResponse = { data };
|
|
235
|
+
const proofGenerator = new ProofGenerator(identity, cryptoProvider);
|
|
236
|
+
const proof = await proofGenerator.generateProof(request, response, session, options);
|
|
237
|
+
response.meta = { proof };
|
|
238
|
+
return response;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
export function extractCanonicalData(
|
|
242
|
+
request: ToolRequest,
|
|
243
|
+
response: ToolResponse
|
|
244
|
+
): {
|
|
245
|
+
request: unknown;
|
|
246
|
+
response: unknown;
|
|
247
|
+
} {
|
|
248
|
+
return {
|
|
249
|
+
request: {
|
|
250
|
+
method: request.method,
|
|
251
|
+
...(request.params ? { params: request.params } : {}),
|
|
252
|
+
},
|
|
253
|
+
response: response.data,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export {
|
|
2
|
+
ProofGenerator,
|
|
3
|
+
createProofResponse,
|
|
4
|
+
extractCanonicalData,
|
|
5
|
+
type ProofAgentIdentity,
|
|
6
|
+
type ToolRequest,
|
|
7
|
+
type ToolResponse,
|
|
8
|
+
type ProofOptions,
|
|
9
|
+
} from './generator.js';
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
ProofVerifier,
|
|
13
|
+
type ProofVerifierConfig,
|
|
14
|
+
type ProofVerificationResult,
|
|
15
|
+
} from './verifier.js';
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
ProofVerificationError,
|
|
19
|
+
PROOF_VERIFICATION_ERROR_CODES,
|
|
20
|
+
createProofVerificationError,
|
|
21
|
+
type ProofVerificationErrorCode,
|
|
22
|
+
} from './errors.js';
|