agentic-payments 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/README.md +924 -0
- package/bin/cli.js +18 -0
- package/bin/mcp.js +10 -0
- package/completions/agentic-payments.bash +21 -0
- package/completions/agentic-payments.fish +9 -0
- package/completions/agentic-payments.zsh +17 -0
- package/completions/bash.sh +182 -0
- package/completions/fish.fish +110 -0
- package/completions/zsh.sh +175 -0
- package/dist/active-mandate/i18n.d.ts +27 -0
- package/dist/active-mandate/i18n.d.ts.map +1 -0
- package/dist/active-mandate/i18n.js +35 -0
- package/dist/active-mandate/i18n.js.map +1 -0
- package/dist/active-mandate/index.d.ts +26 -0
- package/dist/active-mandate/index.d.ts.map +1 -0
- package/dist/active-mandate/index.js +51 -0
- package/dist/active-mandate/index.js.map +1 -0
- package/dist/active-mandate/revocation.d.ts +11 -0
- package/dist/active-mandate/revocation.d.ts.map +1 -0
- package/dist/active-mandate/revocation.js +27 -0
- package/dist/active-mandate/revocation.js.map +1 -0
- package/dist/active-mandate/schema.d.ts +85 -0
- package/dist/active-mandate/schema.d.ts.map +1 -0
- package/dist/active-mandate/schema.js +36 -0
- package/dist/active-mandate/schema.js.map +1 -0
- package/dist/active-mandate/signing.d.ts +8 -0
- package/dist/active-mandate/signing.d.ts.map +1 -0
- package/dist/active-mandate/signing.js +64 -0
- package/dist/active-mandate/signing.js.map +1 -0
- package/dist/active-mandate/types.d.ts +59 -0
- package/dist/active-mandate/types.d.ts.map +1 -0
- package/dist/active-mandate/types.js +6 -0
- package/dist/active-mandate/types.js.map +1 -0
- package/dist/cli/commands/active-mandate.d.ts +4 -0
- package/dist/cli/commands/active-mandate.d.ts.map +1 -0
- package/dist/cli/commands/active-mandate.js +218 -0
- package/dist/cli/commands/active-mandate.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +3 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +59 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/mandate.d.ts +4 -0
- package/dist/cli/commands/mandate.d.ts.map +1 -0
- package/dist/cli/commands/mandate.js +223 -0
- package/dist/cli/commands/mandate.js.map +1 -0
- package/dist/cli/commands/system.d.ts +4 -0
- package/dist/cli/commands/system.d.ts.map +1 -0
- package/dist/cli/commands/system.js +101 -0
- package/dist/cli/commands/system.js.map +1 -0
- package/dist/cli/commands/verify.d.ts +3 -0
- package/dist/cli/commands/verify.d.ts.map +1 -0
- package/dist/cli/commands/verify.js +104 -0
- package/dist/cli/commands/verify.js.map +1 -0
- package/dist/cli/completion.d.ts +3 -0
- package/dist/cli/completion.d.ts.map +1 -0
- package/dist/cli/completion.js +245 -0
- package/dist/cli/completion.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +79 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +100 -0
- package/dist/errors.js.map +1 -0
- package/dist/identity.d.ts +78 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +204 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/mandate.d.ts +134 -0
- package/dist/mandate.d.ts.map +1 -0
- package/dist/mandate.js +342 -0
- package/dist/mandate.js.map +1 -0
- package/dist/mcp/index.d.ts +7 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +102 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/server.d.ts +38 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +126 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/agent.d.ts +9 -0
- package/dist/mcp/tools/agent.d.ts.map +1 -0
- package/dist/mcp/tools/agent.js +34 -0
- package/dist/mcp/tools/agent.js.map +1 -0
- package/dist/mcp/tools/consensus.d.ts +9 -0
- package/dist/mcp/tools/consensus.d.ts.map +1 -0
- package/dist/mcp/tools/consensus.js +38 -0
- package/dist/mcp/tools/consensus.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +45 -0
- package/dist/mcp/tools/index.d.ts.map +1 -0
- package/dist/mcp/tools/index.js +282 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/mandate.d.ts +31 -0
- package/dist/mcp/tools/mandate.d.ts.map +1 -0
- package/dist/mcp/tools/mandate.js +165 -0
- package/dist/mcp/tools/mandate.js.map +1 -0
- package/dist/mcp/tools/payment.d.ts +13 -0
- package/dist/mcp/tools/payment.d.ts.map +1 -0
- package/dist/mcp/tools/payment.js +66 -0
- package/dist/mcp/tools/payment.js.map +1 -0
- package/dist/mcp/tools/types.d.ts +63 -0
- package/dist/mcp/tools/types.d.ts.map +1 -0
- package/dist/mcp/tools/types.js +5 -0
- package/dist/mcp/tools/types.js.map +1 -0
- package/dist/mcp/transports/http.d.ts +52 -0
- package/dist/mcp/transports/http.d.ts.map +1 -0
- package/dist/mcp/transports/http.js +234 -0
- package/dist/mcp/transports/http.js.map +1 -0
- package/dist/types.d.ts +238 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/verification.d.ts +140 -0
- package/dist/verification.d.ts.map +1 -0
- package/dist/verification.js +285 -0
- package/dist/verification.js.map +1 -0
- package/package.json +175 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript type definitions for agentic-payments
|
|
3
|
+
* Native TypeScript implementation types
|
|
4
|
+
* @module types
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Cryptographic key pair for Ed25519 signatures
|
|
8
|
+
*/
|
|
9
|
+
export interface KeyPair {
|
|
10
|
+
/** Public key bytes (32 bytes) */
|
|
11
|
+
publicKey: Uint8Array;
|
|
12
|
+
/** Secret key bytes (32 bytes) */
|
|
13
|
+
secretKey: Uint8Array;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Agent identity with cryptographic keys and identifier
|
|
17
|
+
*/
|
|
18
|
+
export interface AgentIdentityData {
|
|
19
|
+
/** Unique agent identifier (DID format) */
|
|
20
|
+
id: string;
|
|
21
|
+
/** Ed25519 public key (32 bytes) */
|
|
22
|
+
publicKey: Uint8Array;
|
|
23
|
+
/** Ed25519 secret key (32 bytes) - SENSITIVE */
|
|
24
|
+
secretKey?: Uint8Array;
|
|
25
|
+
/** Agent metadata */
|
|
26
|
+
metadata?: Record<string, unknown>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Digital signature result
|
|
30
|
+
*/
|
|
31
|
+
export interface Signature {
|
|
32
|
+
/** Signature bytes (64 bytes for Ed25519) */
|
|
33
|
+
bytes: Uint8Array;
|
|
34
|
+
/** Signer's public key */
|
|
35
|
+
publicKey: Uint8Array;
|
|
36
|
+
/** Original message that was signed */
|
|
37
|
+
message: Uint8Array;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Verification result with consensus information
|
|
41
|
+
*/
|
|
42
|
+
export interface VerificationResult {
|
|
43
|
+
/** Whether verification succeeded */
|
|
44
|
+
isValid: boolean;
|
|
45
|
+
/** Consensus level reached (0.0 - 1.0) */
|
|
46
|
+
consensusPercentage: number;
|
|
47
|
+
/** Number of agents that participated */
|
|
48
|
+
totalVotes: number;
|
|
49
|
+
/** Votes for verification */
|
|
50
|
+
votesFor: number;
|
|
51
|
+
/** Votes against verification */
|
|
52
|
+
votesAgainst: number;
|
|
53
|
+
/** Individual agent verification results */
|
|
54
|
+
agentVotes: AgentVote[];
|
|
55
|
+
/** Whether consensus threshold was reached */
|
|
56
|
+
consensusReached: boolean;
|
|
57
|
+
/** Average latency across all agents */
|
|
58
|
+
avgLatencyMs: number;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Individual agent vote
|
|
62
|
+
*/
|
|
63
|
+
export interface AgentVote {
|
|
64
|
+
/** Agent identifier */
|
|
65
|
+
agentId: string;
|
|
66
|
+
/** Agent's vote */
|
|
67
|
+
vote: boolean;
|
|
68
|
+
/** Vote timestamp */
|
|
69
|
+
timestamp: number;
|
|
70
|
+
/** Verification latency for this agent */
|
|
71
|
+
latencyMs: number;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Verification system configuration
|
|
75
|
+
*/
|
|
76
|
+
export interface VerificationConfig {
|
|
77
|
+
/** Minimum consensus threshold (0.0 - 1.0) */
|
|
78
|
+
consensusThreshold: number;
|
|
79
|
+
/** Minimum number of agents required */
|
|
80
|
+
minAgents: number;
|
|
81
|
+
/** Maximum number of agents to use */
|
|
82
|
+
maxAgents: number;
|
|
83
|
+
/** Verification timeout in milliseconds */
|
|
84
|
+
timeoutMs?: number;
|
|
85
|
+
/** Enable parallel verification */
|
|
86
|
+
parallel?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* System performance metrics
|
|
90
|
+
*/
|
|
91
|
+
export interface SystemMetrics {
|
|
92
|
+
/** Total verifications performed */
|
|
93
|
+
totalVerifications: number;
|
|
94
|
+
/** Successful verifications */
|
|
95
|
+
successfulVerifications: number;
|
|
96
|
+
/** Failed verifications */
|
|
97
|
+
failedVerifications: number;
|
|
98
|
+
/** Average verification time (ms) */
|
|
99
|
+
avgVerificationTime: number;
|
|
100
|
+
/** Average consensus level */
|
|
101
|
+
avgConsensus: number;
|
|
102
|
+
/** System uptime (ms) */
|
|
103
|
+
uptimeMs: number;
|
|
104
|
+
/** Agent metrics */
|
|
105
|
+
agentMetrics: AgentMetrics[];
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Agent performance metrics
|
|
109
|
+
*/
|
|
110
|
+
export interface AgentMetrics {
|
|
111
|
+
/** Agent identifier */
|
|
112
|
+
agentId: string;
|
|
113
|
+
/** Total verifications by this agent */
|
|
114
|
+
totalVerifications: number;
|
|
115
|
+
/** Successful verifications */
|
|
116
|
+
successfulVerifications: number;
|
|
117
|
+
/** Failed verifications */
|
|
118
|
+
failedVerifications: number;
|
|
119
|
+
/** Average latency (ms) */
|
|
120
|
+
avgLatencyMs: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Intent mandate for payment authorization
|
|
124
|
+
*/
|
|
125
|
+
export interface IntentMandateData {
|
|
126
|
+
/** Unique mandate ID */
|
|
127
|
+
id: string;
|
|
128
|
+
/** Merchant identifier */
|
|
129
|
+
merchantId: string;
|
|
130
|
+
/** Customer identifier */
|
|
131
|
+
customerId: string;
|
|
132
|
+
/** Payment intent description */
|
|
133
|
+
intent: string;
|
|
134
|
+
/** Maximum amount authorized */
|
|
135
|
+
maxAmount: number;
|
|
136
|
+
/** Currency code (ISO 4217) */
|
|
137
|
+
currency: string;
|
|
138
|
+
/** Mandate creation timestamp */
|
|
139
|
+
createdAt: number;
|
|
140
|
+
/** Mandate expiry timestamp */
|
|
141
|
+
expiresAt: number;
|
|
142
|
+
/** Digital signature (hex string) */
|
|
143
|
+
signature?: string;
|
|
144
|
+
/** Signer DID */
|
|
145
|
+
signedBy?: string;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Cart mandate for shopping cart authorization
|
|
149
|
+
*/
|
|
150
|
+
export interface CartMandateData {
|
|
151
|
+
/** Unique mandate ID */
|
|
152
|
+
id: string;
|
|
153
|
+
/** Merchant identifier */
|
|
154
|
+
merchantId: string;
|
|
155
|
+
/** Customer identifier */
|
|
156
|
+
customerId: string;
|
|
157
|
+
/** Cart items */
|
|
158
|
+
items: CartItem[];
|
|
159
|
+
/** Total cart amount */
|
|
160
|
+
totalAmount: number;
|
|
161
|
+
/** Currency code (ISO 4217) */
|
|
162
|
+
currency: string;
|
|
163
|
+
/** Mandate creation timestamp */
|
|
164
|
+
createdAt: number;
|
|
165
|
+
/** Mandate expiry timestamp */
|
|
166
|
+
expiresAt: number;
|
|
167
|
+
/** Digital signature (hex string) */
|
|
168
|
+
signature?: string;
|
|
169
|
+
/** Signer DID */
|
|
170
|
+
signedBy?: string;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Shopping cart item
|
|
174
|
+
*/
|
|
175
|
+
export interface CartItem {
|
|
176
|
+
/** Item SKU or identifier */
|
|
177
|
+
id: string;
|
|
178
|
+
/** Item name */
|
|
179
|
+
name: string;
|
|
180
|
+
/** Item quantity */
|
|
181
|
+
quantity: number;
|
|
182
|
+
/** Unit price */
|
|
183
|
+
unitPrice: number;
|
|
184
|
+
/** Item metadata */
|
|
185
|
+
metadata?: Record<string, unknown>;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Payment mandate for transaction authorization
|
|
189
|
+
*/
|
|
190
|
+
export interface PaymentMandateData {
|
|
191
|
+
/** Unique mandate ID */
|
|
192
|
+
id: string;
|
|
193
|
+
/** Source mandate ID (intent or cart) */
|
|
194
|
+
sourceId: string;
|
|
195
|
+
/** Mandate type */
|
|
196
|
+
type: 'intent' | 'cart';
|
|
197
|
+
/** Payment amount */
|
|
198
|
+
amount: number;
|
|
199
|
+
/** Currency code (ISO 4217) */
|
|
200
|
+
currency: string;
|
|
201
|
+
/** Payment method */
|
|
202
|
+
paymentMethod: string;
|
|
203
|
+
/** Payment status */
|
|
204
|
+
status: PaymentStatus;
|
|
205
|
+
/** Mandate creation timestamp */
|
|
206
|
+
createdAt: number;
|
|
207
|
+
/** Payment processed timestamp */
|
|
208
|
+
processedAt?: number;
|
|
209
|
+
/** Digital signature (hex string) */
|
|
210
|
+
signature?: string;
|
|
211
|
+
/** Signer DID */
|
|
212
|
+
signedBy?: string;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Payment processing status
|
|
216
|
+
*/
|
|
217
|
+
export type PaymentStatus = 'pending' | 'authorized' | 'captured' | 'failed' | 'cancelled' | 'refunded';
|
|
218
|
+
/**
|
|
219
|
+
* Mandate validation result
|
|
220
|
+
*/
|
|
221
|
+
export interface ValidationResult {
|
|
222
|
+
/** Whether validation succeeded */
|
|
223
|
+
valid: boolean;
|
|
224
|
+
/** Validation errors if any */
|
|
225
|
+
errors: string[];
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Serialization options
|
|
229
|
+
*/
|
|
230
|
+
export interface SerializationOptions {
|
|
231
|
+
/** Include sensitive data (private keys) */
|
|
232
|
+
includeSensitive?: boolean;
|
|
233
|
+
/** Pretty print JSON */
|
|
234
|
+
pretty?: boolean;
|
|
235
|
+
/** Include metadata */
|
|
236
|
+
includeMetadata?: boolean;
|
|
237
|
+
}
|
|
238
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,kCAAkC;IAClC,SAAS,EAAE,UAAU,CAAC;IACtB,kCAAkC;IAClC,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,2CAA2C;IAC3C,EAAE,EAAE,MAAM,CAAC;IACX,oCAAoC;IACpC,SAAS,EAAE,UAAU,CAAC;IACtB,gDAAgD;IAChD,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,qBAAqB;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,6CAA6C;IAC7C,KAAK,EAAE,UAAU,CAAC;IAClB,0BAA0B;IAC1B,SAAS,EAAE,UAAU,CAAC;IACtB,uCAAuC;IACvC,OAAO,EAAE,UAAU,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,qCAAqC;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,0C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AC,EAAE,OAAO,CAAC;IAC3B,wBAAwB;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,uBAAuB;IACvB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-agent verification system - Pure TypeScript implementation
|
|
3
|
+
* No WASM dependencies - native implementation with @noble/ed25519
|
|
4
|
+
*/
|
|
5
|
+
import { AgentIdentity } from './identity.js';
|
|
6
|
+
export interface AgentVote {
|
|
7
|
+
agentId: string;
|
|
8
|
+
vote: boolean;
|
|
9
|
+
timestamp: number;
|
|
10
|
+
latencyMs: number;
|
|
11
|
+
}
|
|
12
|
+
export interface VerificationResult {
|
|
13
|
+
isValid: boolean;
|
|
14
|
+
votesFor: number;
|
|
15
|
+
votesAgainst: number;
|
|
16
|
+
totalVotes: number;
|
|
17
|
+
consensusReached: boolean;
|
|
18
|
+
consensusPercentage: number;
|
|
19
|
+
agentVotes: AgentVote[];
|
|
20
|
+
totalLatencyMs: number;
|
|
21
|
+
avgLatencyMs: number;
|
|
22
|
+
}
|
|
23
|
+
export interface VerificationConfig {
|
|
24
|
+
consensusThreshold: number;
|
|
25
|
+
minAgents: number;
|
|
26
|
+
maxAgents: number;
|
|
27
|
+
timeoutMs: number;
|
|
28
|
+
parallel: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface SystemMetrics {
|
|
31
|
+
totalVerifications: number;
|
|
32
|
+
successfulVerifications: number;
|
|
33
|
+
failedVerifications: number;
|
|
34
|
+
avgLatencyMs: number;
|
|
35
|
+
agentCount: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Verification agent - simulates Byzantine fault tolerant agent
|
|
39
|
+
*/
|
|
40
|
+
declare class VerificationAgent {
|
|
41
|
+
private identity;
|
|
42
|
+
private agentId;
|
|
43
|
+
private metrics;
|
|
44
|
+
constructor(identity: AgentIdentity);
|
|
45
|
+
/**
|
|
46
|
+
* Verify signature using this agent's cryptographic verification
|
|
47
|
+
*/
|
|
48
|
+
verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): Promise<AgentVote>;
|
|
49
|
+
getId(): string;
|
|
50
|
+
getIdentity(): AgentIdentity;
|
|
51
|
+
getMetrics(): {
|
|
52
|
+
avgLatency: number;
|
|
53
|
+
verifications: number;
|
|
54
|
+
successes: number;
|
|
55
|
+
failures: number;
|
|
56
|
+
totalLatency: number;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Multi-agent verification system with Byzantine fault tolerance
|
|
61
|
+
*/
|
|
62
|
+
export declare class VerificationSystem {
|
|
63
|
+
private config;
|
|
64
|
+
private agents;
|
|
65
|
+
private metrics;
|
|
66
|
+
private totalLatency;
|
|
67
|
+
constructor(config: VerificationConfig);
|
|
68
|
+
/**
|
|
69
|
+
* Add agent to verification pool
|
|
70
|
+
*/
|
|
71
|
+
addAgent(identity: AgentIdentity): void;
|
|
72
|
+
/**
|
|
73
|
+
* Verify message with multi-agent consensus
|
|
74
|
+
*/
|
|
75
|
+
verifyWithConsensus(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): Promise<VerificationResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Get system performance metrics
|
|
78
|
+
*/
|
|
79
|
+
getMetrics(): SystemMetrics;
|
|
80
|
+
/**
|
|
81
|
+
* Get current configuration
|
|
82
|
+
*/
|
|
83
|
+
getConfig(): VerificationConfig;
|
|
84
|
+
/**
|
|
85
|
+
* Get agent count
|
|
86
|
+
*/
|
|
87
|
+
getAgentCount(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Get all agent identities
|
|
90
|
+
*/
|
|
91
|
+
getAgents(): AgentIdentity[];
|
|
92
|
+
/**
|
|
93
|
+
* Get agent metrics
|
|
94
|
+
*/
|
|
95
|
+
getAgentMetrics(): Array<{
|
|
96
|
+
agentId: string;
|
|
97
|
+
metrics: ReturnType<VerificationAgent['getMetrics']>;
|
|
98
|
+
}>;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Builder for VerificationSystem with fluent API
|
|
102
|
+
*/
|
|
103
|
+
export declare class VerificationSystemBuilder {
|
|
104
|
+
private config;
|
|
105
|
+
private agents;
|
|
106
|
+
/**
|
|
107
|
+
* Set consensus threshold (0.0 - 1.0)
|
|
108
|
+
*/
|
|
109
|
+
consensusThreshold(threshold: number): this;
|
|
110
|
+
/**
|
|
111
|
+
* Set minimum number of agents
|
|
112
|
+
*/
|
|
113
|
+
minAgents(min: number): this;
|
|
114
|
+
/**
|
|
115
|
+
* Set maximum number of agents
|
|
116
|
+
*/
|
|
117
|
+
maxAgents(max: number): this;
|
|
118
|
+
/**
|
|
119
|
+
* Set verification timeout
|
|
120
|
+
*/
|
|
121
|
+
timeout(ms: number): this;
|
|
122
|
+
/**
|
|
123
|
+
* Enable/disable parallel verification
|
|
124
|
+
*/
|
|
125
|
+
parallel(enabled: boolean): this;
|
|
126
|
+
/**
|
|
127
|
+
* Add agent to verification pool
|
|
128
|
+
*/
|
|
129
|
+
addAgent(agent: AgentIdentity): this;
|
|
130
|
+
/**
|
|
131
|
+
* Add multiple agents
|
|
132
|
+
*/
|
|
133
|
+
addAgents(agents: AgentIdentity[]): this;
|
|
134
|
+
/**
|
|
135
|
+
* Build verification system
|
|
136
|
+
*/
|
|
137
|
+
build(): VerificationSystem;
|
|
138
|
+
}
|
|
139
|
+
export {};
|
|
140
|
+
//# sourceMappingURL=verification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../src/verification.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAM9C,MAAM,WAAW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|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multi-agent verification system - Pure TypeScript implementation
|
|
3
|
+
* No WASM dependencies - native implementation with @noble/ed25519
|
|
4
|
+
*/
|
|
5
|
+
import * as ed from '@noble/ed25519';
|
|
6
|
+
import { sha512 } from '@noble/hashes/sha512';
|
|
7
|
+
import { PaymentError, PaymentErrorCode } from './errors.js';
|
|
8
|
+
// Configure noble/ed25519 to use SHA-512
|
|
9
|
+
ed.etc.sha512Sync = (...m) => sha512(ed.etc.concatBytes(...m));
|
|
10
|
+
/**
|
|
11
|
+
* Verification agent - simulates Byzantine fault tolerant agent
|
|
12
|
+
*/
|
|
13
|
+
class VerificationAgent {
|
|
14
|
+
identity;
|
|
15
|
+
agentId;
|
|
16
|
+
metrics;
|
|
17
|
+
constructor(identity) {
|
|
18
|
+
this.identity = identity;
|
|
19
|
+
this.agentId = identity.did();
|
|
20
|
+
this.metrics = {
|
|
21
|
+
verifications: 0,
|
|
22
|
+
successes: 0,
|
|
23
|
+
failures: 0,
|
|
24
|
+
totalLatency: 0,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Verify signature using this agent's cryptographic verification
|
|
29
|
+
*/
|
|
30
|
+
async verify(signature, message, publicKey) {
|
|
31
|
+
const startTime = Date.now();
|
|
32
|
+
try {
|
|
33
|
+
const isValid = await ed.verifyAsync(signature, message, publicKey);
|
|
34
|
+
const latencyMs = Date.now() - startTime;
|
|
35
|
+
this.metrics.verifications++;
|
|
36
|
+
if (isValid) {
|
|
37
|
+
this.metrics.successes++;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
this.metrics.failures++;
|
|
41
|
+
}
|
|
42
|
+
this.metrics.totalLatency += latencyMs;
|
|
43
|
+
return {
|
|
44
|
+
agentId: this.agentId,
|
|
45
|
+
vote: isValid,
|
|
46
|
+
timestamp: Date.now(),
|
|
47
|
+
latencyMs,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const latencyMs = Date.now() - startTime;
|
|
52
|
+
this.metrics.verifications++;
|
|
53
|
+
this.metrics.failures++;
|
|
54
|
+
this.metrics.totalLatency += latencyMs;
|
|
55
|
+
return {
|
|
56
|
+
agentId: this.agentId,
|
|
57
|
+
vote: false,
|
|
58
|
+
timestamp: Date.now(),
|
|
59
|
+
latencyMs,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getId() {
|
|
64
|
+
return this.agentId;
|
|
65
|
+
}
|
|
66
|
+
getIdentity() {
|
|
67
|
+
return this.identity;
|
|
68
|
+
}
|
|
69
|
+
getMetrics() {
|
|
70
|
+
return {
|
|
71
|
+
...this.metrics,
|
|
72
|
+
avgLatency: this.metrics.verifications > 0 ? this.metrics.totalLatency / this.metrics.verifications : 0,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Multi-agent verification system with Byzantine fault tolerance
|
|
78
|
+
*/
|
|
79
|
+
export class VerificationSystem {
|
|
80
|
+
config;
|
|
81
|
+
agents = [];
|
|
82
|
+
metrics = {
|
|
83
|
+
totalVerifications: 0,
|
|
84
|
+
successfulVerifications: 0,
|
|
85
|
+
failedVerifications: 0,
|
|
86
|
+
avgLatencyMs: 0,
|
|
87
|
+
agentCount: 0,
|
|
88
|
+
};
|
|
89
|
+
totalLatency = 0;
|
|
90
|
+
constructor(config) {
|
|
91
|
+
this.config = config;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Add agent to verification pool
|
|
95
|
+
*/
|
|
96
|
+
addAgent(identity) {
|
|
97
|
+
if (this.agents.length >= this.config.maxAgents) {
|
|
98
|
+
throw new PaymentError(PaymentErrorCode.SYSTEM_ERROR, `Maximum agents reached: ${this.config.maxAgents}`);
|
|
99
|
+
}
|
|
100
|
+
const agent = new VerificationAgent(identity);
|
|
101
|
+
this.agents.push(agent);
|
|
102
|
+
this.metrics.agentCount = this.agents.length;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Verify message with multi-agent consensus
|
|
106
|
+
*/
|
|
107
|
+
async verifyWithConsensus(signature, message, publicKey) {
|
|
108
|
+
if (this.agents.length < this.config.minAgents) {
|
|
109
|
+
throw new PaymentError(PaymentErrorCode.CONSENSUS_ERROR, `Insufficient agents: ${this.agents.length} < ${this.config.minAgents}`);
|
|
110
|
+
}
|
|
111
|
+
const startTime = Date.now();
|
|
112
|
+
try {
|
|
113
|
+
// Run verification with all agents
|
|
114
|
+
let agentVotes;
|
|
115
|
+
if (this.config.parallel) {
|
|
116
|
+
// Parallel verification - all agents verify simultaneously
|
|
117
|
+
agentVotes = await Promise.all(this.agents.map(agent => agent.verify(signature, message, publicKey)));
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// Sequential verification - agents verify one by one
|
|
121
|
+
agentVotes = [];
|
|
122
|
+
for (const agent of this.agents) {
|
|
123
|
+
const vote = await agent.verify(signature, message, publicKey);
|
|
124
|
+
agentVotes.push(vote);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Calculate consensus
|
|
128
|
+
const votesFor = agentVotes.filter(v => v.vote === true).length;
|
|
129
|
+
const votesAgainst = agentVotes.filter(v => v.vote === false).length;
|
|
130
|
+
const totalVotes = agentVotes.length;
|
|
131
|
+
const consensusPercentage = votesFor / totalVotes;
|
|
132
|
+
const consensusReached = consensusPercentage >= this.config.consensusThreshold;
|
|
133
|
+
// Calculate latency metrics
|
|
134
|
+
const totalLatencyMs = Date.now() - startTime;
|
|
135
|
+
const avgLatencyMs = agentVotes.reduce((sum, v) => sum + v.latencyMs, 0) / totalVotes;
|
|
136
|
+
// Update system metrics
|
|
137
|
+
this.metrics.totalVerifications++;
|
|
138
|
+
if (consensusReached && votesFor > votesAgainst) {
|
|
139
|
+
this.metrics.successfulVerifications++;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.metrics.failedVerifications++;
|
|
143
|
+
}
|
|
144
|
+
this.totalLatency += totalLatencyMs;
|
|
145
|
+
this.metrics.avgLatencyMs = this.totalLatency / this.metrics.totalVerifications;
|
|
146
|
+
const result = {
|
|
147
|
+
isValid: consensusReached && votesFor > votesAgainst,
|
|
148
|
+
votesFor,
|
|
149
|
+
votesAgainst,
|
|
150
|
+
totalVotes,
|
|
151
|
+
consensusReached,
|
|
152
|
+
consensusPercentage,
|
|
153
|
+
agentVotes,
|
|
154
|
+
totalLatencyMs,
|
|
155
|
+
avgLatencyMs,
|
|
156
|
+
};
|
|
157
|
+
return result;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
this.metrics.totalVerifications++;
|
|
161
|
+
this.metrics.failedVerifications++;
|
|
162
|
+
throw new PaymentError(PaymentErrorCode.CONSENSUS_ERROR, `Verification failed: ${error instanceof Error ? error.message : 'unknown error'}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Get system performance metrics
|
|
167
|
+
*/
|
|
168
|
+
getMetrics() {
|
|
169
|
+
return { ...this.metrics };
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get current configuration
|
|
173
|
+
*/
|
|
174
|
+
getConfig() {
|
|
175
|
+
return { ...this.config };
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Get agent count
|
|
179
|
+
*/
|
|
180
|
+
getAgentCount() {
|
|
181
|
+
return this.agents.length;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Get all agent identities
|
|
185
|
+
*/
|
|
186
|
+
getAgents() {
|
|
187
|
+
return this.agents.map(a => a.getIdentity());
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Get agent metrics
|
|
191
|
+
*/
|
|
192
|
+
getAgentMetrics() {
|
|
193
|
+
return this.agents.map(agent => ({
|
|
194
|
+
agentId: agent.getId(),
|
|
195
|
+
metrics: agent.getMetrics(),
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Builder for VerificationSystem with fluent API
|
|
201
|
+
*/
|
|
202
|
+
export class VerificationSystemBuilder {
|
|
203
|
+
config = {
|
|
204
|
+
consensusThreshold: 0.67,
|
|
205
|
+
minAgents: 2,
|
|
206
|
+
maxAgents: 10,
|
|
207
|
+
timeoutMs: 5000,
|
|
208
|
+
parallel: true,
|
|
209
|
+
};
|
|
210
|
+
agents = [];
|
|
211
|
+
/**
|
|
212
|
+
* Set consensus threshold (0.0 - 1.0)
|
|
213
|
+
*/
|
|
214
|
+
consensusThreshold(threshold) {
|
|
215
|
+
if (threshold < 0 || threshold > 1) {
|
|
216
|
+
throw new Error('Consensus threshold must be between 0 and 1');
|
|
217
|
+
}
|
|
218
|
+
this.config.consensusThreshold = threshold;
|
|
219
|
+
return this;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Set minimum number of agents
|
|
223
|
+
*/
|
|
224
|
+
minAgents(min) {
|
|
225
|
+
if (min < 1) {
|
|
226
|
+
throw new Error('Minimum agents must be at least 1');
|
|
227
|
+
}
|
|
228
|
+
this.config.minAgents = min;
|
|
229
|
+
return this;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Set maximum number of agents
|
|
233
|
+
*/
|
|
234
|
+
maxAgents(max) {
|
|
235
|
+
if (max < this.config.minAgents) {
|
|
236
|
+
throw new Error('Maximum agents must be >= minimum agents');
|
|
237
|
+
}
|
|
238
|
+
this.config.maxAgents = max;
|
|
239
|
+
return this;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Set verification timeout
|
|
243
|
+
*/
|
|
244
|
+
timeout(ms) {
|
|
245
|
+
if (ms < 0) {
|
|
246
|
+
throw new Error('Timeout must be non-negative');
|
|
247
|
+
}
|
|
248
|
+
this.config.timeoutMs = ms;
|
|
249
|
+
return this;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Enable/disable parallel verification
|
|
253
|
+
*/
|
|
254
|
+
parallel(enabled) {
|
|
255
|
+
this.config.parallel = enabled;
|
|
256
|
+
return this;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Add agent to verification pool
|
|
260
|
+
*/
|
|
261
|
+
addAgent(agent) {
|
|
262
|
+
this.agents.push(agent);
|
|
263
|
+
return this;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Add multiple agents
|
|
267
|
+
*/
|
|
268
|
+
addAgents(agents) {
|
|
269
|
+
this.agents.push(...agents);
|
|
270
|
+
return this;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Build verification system
|
|
274
|
+
*/
|
|
275
|
+
build() {
|
|
276
|
+
if (this.agents.length < this.config.minAgents) {
|
|
277
|
+
throw new PaymentError(PaymentErrorCode.CONSENSUS_ERROR, `Insufficient agents: ${this.agents.length} < ${this.config.minAgents}`);
|
|
278
|
+
}
|
|
279
|
+
const system = new VerificationSystem(this.config);
|
|
280
|
+
// Add all agents
|
|
281
|
+
this.agents.forEach(agent => system.addAgent(agent));
|
|
282
|
+
return system;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
//# sourceMappingURL=verification.js.map
|