@gvnrdao/dh-lit-actions 0.0.3 โ 0.0.5
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/package.json +3 -3
- package/pkg-dist/utils/chunks/connection-helpers.d.ts +99 -0
- package/pkg-dist/utils/chunks/connection-helpers.d.ts.map +1 -0
- package/pkg-dist/utils/chunks/connection-helpers.js +362 -0
- package/pkg-dist/utils/chunks/connection-helpers.js.map +1 -0
- package/pkg-dist/utils/chunks/debug-logger.d.ts +93 -0
- package/pkg-dist/utils/chunks/debug-logger.d.ts.map +1 -0
- package/pkg-dist/utils/chunks/debug-logger.js +264 -0
- package/pkg-dist/utils/chunks/debug-logger.js.map +1 -0
- package/pkg-dist/utils/chunks/error-classification.d.ts +97 -0
- package/pkg-dist/utils/chunks/error-classification.d.ts.map +1 -0
- package/pkg-dist/utils/chunks/error-classification.js +385 -0
- package/pkg-dist/utils/chunks/error-classification.js.map +1 -0
- package/pkg-dist/utils/chunks/session-signature-cache.d.ts +84 -0
- package/pkg-dist/utils/chunks/session-signature-cache.d.ts.map +1 -0
- package/pkg-dist/utils/chunks/session-signature-cache.js +194 -0
- package/pkg-dist/utils/chunks/session-signature-cache.js.map +1 -0
- package/pkg-dist/utils/index.d.ts +4 -0
- package/pkg-dist/utils/index.d.ts.map +1 -1
- package/pkg-dist/utils/index.js +4 -0
- package/pkg-dist/utils/index.js.map +1 -1
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Enhanced Error Classification for LIT Protocol Operations
|
|
4
|
+
* Provides detailed error categorization and specific retry strategies
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.litProtocolErrors = exports.RetryStrategy = exports.ErrorCategory = void 0;
|
|
8
|
+
exports.classifyError = classifyError;
|
|
9
|
+
exports.getRetryConfigFromClassification = getRetryConfigFromClassification;
|
|
10
|
+
exports.analyzeError = analyzeError;
|
|
11
|
+
exports.createErrorReport = createErrorReport;
|
|
12
|
+
/**
|
|
13
|
+
* Error categories for different types of failures
|
|
14
|
+
*/
|
|
15
|
+
var ErrorCategory;
|
|
16
|
+
(function (ErrorCategory) {
|
|
17
|
+
ErrorCategory["NETWORK"] = "network";
|
|
18
|
+
ErrorCategory["PROTOCOL"] = "protocol";
|
|
19
|
+
ErrorCategory["AUTHENTICATION"] = "authentication";
|
|
20
|
+
ErrorCategory["RESOURCE"] = "resource";
|
|
21
|
+
ErrorCategory["VALIDATION"] = "validation";
|
|
22
|
+
ErrorCategory["TIMEOUT"] = "timeout";
|
|
23
|
+
ErrorCategory["RATE_LIMIT"] = "rate_limit";
|
|
24
|
+
ErrorCategory["CONFIGURATION"] = "configuration";
|
|
25
|
+
ErrorCategory["UNKNOWN"] = "unknown";
|
|
26
|
+
})(ErrorCategory || (exports.ErrorCategory = ErrorCategory = {}));
|
|
27
|
+
/**
|
|
28
|
+
* Retry strategy types
|
|
29
|
+
*/
|
|
30
|
+
var RetryStrategy;
|
|
31
|
+
(function (RetryStrategy) {
|
|
32
|
+
RetryStrategy["AGGRESSIVE"] = "aggressive";
|
|
33
|
+
RetryStrategy["CONSERVATIVE"] = "conservative";
|
|
34
|
+
RetryStrategy["EXPONENTIAL"] = "exponential";
|
|
35
|
+
RetryStrategy["LINEAR"] = "linear";
|
|
36
|
+
RetryStrategy["NONE"] = "none"; // No retries
|
|
37
|
+
})(RetryStrategy || (exports.RetryStrategy = RetryStrategy = {}));
|
|
38
|
+
/**
|
|
39
|
+
* LIT Protocol specific error patterns
|
|
40
|
+
*/
|
|
41
|
+
const LIT_ERROR_PATTERNS = {
|
|
42
|
+
// Network and connection errors
|
|
43
|
+
network: [
|
|
44
|
+
/network error/i,
|
|
45
|
+
/connection failed/i,
|
|
46
|
+
/connection refused/i,
|
|
47
|
+
/connection timeout/i,
|
|
48
|
+
/socket hang up/i,
|
|
49
|
+
/enotfound/i,
|
|
50
|
+
/econnrefused/i,
|
|
51
|
+
/etimedout/i,
|
|
52
|
+
/dns resolution failed/i,
|
|
53
|
+
/request failed/i
|
|
54
|
+
],
|
|
55
|
+
// Protocol specific errors
|
|
56
|
+
protocol: [
|
|
57
|
+
/lit protocol/i,
|
|
58
|
+
/lit node/i,
|
|
59
|
+
/signing shares/i,
|
|
60
|
+
/node communication/i,
|
|
61
|
+
/consensus/i,
|
|
62
|
+
/threshold/i,
|
|
63
|
+
/decryption/i,
|
|
64
|
+
/signature verification/i,
|
|
65
|
+
/There was an error getting the signing shares/i,
|
|
66
|
+
/Response from the nodes/i,
|
|
67
|
+
/NodeError/i,
|
|
68
|
+
/PKP validation/i,
|
|
69
|
+
/pkp validation failed/i
|
|
70
|
+
],
|
|
71
|
+
// Authentication and authorization errors
|
|
72
|
+
authentication: [
|
|
73
|
+
/authentication/i,
|
|
74
|
+
/authorization/i,
|
|
75
|
+
/session.*expired/i,
|
|
76
|
+
/invalid.*signature/i,
|
|
77
|
+
/unauthorized/i,
|
|
78
|
+
/access.*denied/i,
|
|
79
|
+
/permission/i,
|
|
80
|
+
/auth.*failed/i,
|
|
81
|
+
/siwe/i,
|
|
82
|
+
/session.*sig/i
|
|
83
|
+
],
|
|
84
|
+
// Resource and validation errors
|
|
85
|
+
resource: [
|
|
86
|
+
/resource.*not.*found/i,
|
|
87
|
+
/ipfs.*not.*found/i,
|
|
88
|
+
/cid.*invalid/i,
|
|
89
|
+
/pkp.*not.*found/i,
|
|
90
|
+
/pkp.*validation/i,
|
|
91
|
+
/resource.*validation/i,
|
|
92
|
+
/action.*not.*permitted/i,
|
|
93
|
+
/lit.*action.*not.*found/i
|
|
94
|
+
],
|
|
95
|
+
// Validation errors
|
|
96
|
+
validation: [
|
|
97
|
+
/validation.*failed/i,
|
|
98
|
+
/invalid.*input/i,
|
|
99
|
+
/invalid.*parameter/i,
|
|
100
|
+
/malformed/i,
|
|
101
|
+
/schema.*validation/i,
|
|
102
|
+
/type.*error/i,
|
|
103
|
+
/missing.*required/i
|
|
104
|
+
],
|
|
105
|
+
// Timeout specific errors
|
|
106
|
+
timeout: [
|
|
107
|
+
/timeout/i,
|
|
108
|
+
/request.*timed.*out/i,
|
|
109
|
+
/operation.*timed.*out/i,
|
|
110
|
+
/deadline.*exceeded/i,
|
|
111
|
+
/time.*limit.*exceeded/i
|
|
112
|
+
],
|
|
113
|
+
// Rate limiting errors
|
|
114
|
+
rateLimit: [
|
|
115
|
+
/rate.*limit/i,
|
|
116
|
+
/too.*many.*requests/i,
|
|
117
|
+
/quota.*exceeded/i,
|
|
118
|
+
/throttled/i,
|
|
119
|
+
/429/,
|
|
120
|
+
/rate.*exceeded/i
|
|
121
|
+
],
|
|
122
|
+
// Configuration errors
|
|
123
|
+
configuration: [
|
|
124
|
+
/configuration/i,
|
|
125
|
+
/config.*error/i,
|
|
126
|
+
/environment/i,
|
|
127
|
+
/missing.*env/i,
|
|
128
|
+
/invalid.*config/i,
|
|
129
|
+
/setup.*error/i
|
|
130
|
+
]
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* Predefined retry strategies
|
|
134
|
+
*/
|
|
135
|
+
const RETRY_STRATEGIES = {
|
|
136
|
+
[RetryStrategy.AGGRESSIVE]: {
|
|
137
|
+
maxAttempts: 5,
|
|
138
|
+
baseDelayMs: 500,
|
|
139
|
+
maxDelayMs: 5000,
|
|
140
|
+
multiplier: 1.5
|
|
141
|
+
},
|
|
142
|
+
[RetryStrategy.CONSERVATIVE]: {
|
|
143
|
+
maxAttempts: 3,
|
|
144
|
+
baseDelayMs: 3000,
|
|
145
|
+
maxDelayMs: 30000,
|
|
146
|
+
multiplier: 2.5
|
|
147
|
+
},
|
|
148
|
+
[RetryStrategy.EXPONENTIAL]: {
|
|
149
|
+
maxAttempts: 4,
|
|
150
|
+
baseDelayMs: 1000,
|
|
151
|
+
maxDelayMs: 15000,
|
|
152
|
+
multiplier: 2.0
|
|
153
|
+
},
|
|
154
|
+
[RetryStrategy.LINEAR]: {
|
|
155
|
+
maxAttempts: 3,
|
|
156
|
+
baseDelayMs: 2000,
|
|
157
|
+
maxDelayMs: 10000,
|
|
158
|
+
multiplier: 1.0
|
|
159
|
+
},
|
|
160
|
+
[RetryStrategy.NONE]: {
|
|
161
|
+
maxAttempts: 1,
|
|
162
|
+
baseDelayMs: 0,
|
|
163
|
+
maxDelayMs: 0,
|
|
164
|
+
multiplier: 1.0
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Error classification rules
|
|
169
|
+
*/
|
|
170
|
+
const CLASSIFICATION_RULES = {
|
|
171
|
+
[ErrorCategory.NETWORK]: {
|
|
172
|
+
category: ErrorCategory.NETWORK,
|
|
173
|
+
retryStrategy: RetryStrategy.AGGRESSIVE,
|
|
174
|
+
isRetryable: true,
|
|
175
|
+
...RETRY_STRATEGIES[RetryStrategy.AGGRESSIVE],
|
|
176
|
+
description: 'Network connectivity or communication error',
|
|
177
|
+
troubleshooting: [
|
|
178
|
+
'Check internet connection',
|
|
179
|
+
'Verify LIT Protocol network status',
|
|
180
|
+
'Check firewall and proxy settings',
|
|
181
|
+
'Try connecting to different node endpoints'
|
|
182
|
+
]
|
|
183
|
+
},
|
|
184
|
+
[ErrorCategory.PROTOCOL]: {
|
|
185
|
+
category: ErrorCategory.PROTOCOL,
|
|
186
|
+
retryStrategy: RetryStrategy.CONSERVATIVE,
|
|
187
|
+
isRetryable: true,
|
|
188
|
+
...RETRY_STRATEGIES[RetryStrategy.CONSERVATIVE],
|
|
189
|
+
description: 'LIT Protocol specific operational error',
|
|
190
|
+
troubleshooting: [
|
|
191
|
+
'Check LIT Protocol network status',
|
|
192
|
+
'Verify PKP configuration',
|
|
193
|
+
'Check signing shares availability',
|
|
194
|
+
'Wait for network consensus'
|
|
195
|
+
]
|
|
196
|
+
},
|
|
197
|
+
[ErrorCategory.AUTHENTICATION]: {
|
|
198
|
+
category: ErrorCategory.AUTHENTICATION,
|
|
199
|
+
retryStrategy: RetryStrategy.EXPONENTIAL,
|
|
200
|
+
isRetryable: true,
|
|
201
|
+
...RETRY_STRATEGIES[RetryStrategy.EXPONENTIAL],
|
|
202
|
+
maxAttempts: 2, // Override: limited retries for auth issues
|
|
203
|
+
description: 'Authentication or authorization error',
|
|
204
|
+
troubleshooting: [
|
|
205
|
+
'Check session signatures validity',
|
|
206
|
+
'Regenerate authentication tokens',
|
|
207
|
+
'Verify wallet permissions',
|
|
208
|
+
'Check PKP authorization status'
|
|
209
|
+
]
|
|
210
|
+
},
|
|
211
|
+
[ErrorCategory.RESOURCE]: {
|
|
212
|
+
category: ErrorCategory.RESOURCE,
|
|
213
|
+
retryStrategy: RetryStrategy.LINEAR,
|
|
214
|
+
isRetryable: true,
|
|
215
|
+
...RETRY_STRATEGIES[RetryStrategy.LINEAR],
|
|
216
|
+
maxAttempts: 2, // Override: limited retries for resource issues
|
|
217
|
+
description: 'Resource not found or validation error',
|
|
218
|
+
troubleshooting: [
|
|
219
|
+
'Verify resource CIDs are correct',
|
|
220
|
+
'Check IPFS availability',
|
|
221
|
+
'Confirm PKP exists and is accessible',
|
|
222
|
+
'Wait for resource propagation'
|
|
223
|
+
]
|
|
224
|
+
},
|
|
225
|
+
[ErrorCategory.VALIDATION]: {
|
|
226
|
+
category: ErrorCategory.VALIDATION,
|
|
227
|
+
retryStrategy: RetryStrategy.NONE,
|
|
228
|
+
isRetryable: false,
|
|
229
|
+
...RETRY_STRATEGIES[RetryStrategy.NONE],
|
|
230
|
+
description: 'Input validation or schema error',
|
|
231
|
+
troubleshooting: [
|
|
232
|
+
'Check input parameters format',
|
|
233
|
+
'Verify required fields are provided',
|
|
234
|
+
'Validate data types and ranges',
|
|
235
|
+
'Review API documentation'
|
|
236
|
+
]
|
|
237
|
+
},
|
|
238
|
+
[ErrorCategory.TIMEOUT]: {
|
|
239
|
+
category: ErrorCategory.TIMEOUT,
|
|
240
|
+
retryStrategy: RetryStrategy.CONSERVATIVE,
|
|
241
|
+
isRetryable: true,
|
|
242
|
+
...RETRY_STRATEGIES[RetryStrategy.CONSERVATIVE],
|
|
243
|
+
description: 'Operation timeout error',
|
|
244
|
+
troubleshooting: [
|
|
245
|
+
'Increase timeout values',
|
|
246
|
+
'Check network latency',
|
|
247
|
+
'Verify system resources',
|
|
248
|
+
'Split operations into smaller chunks'
|
|
249
|
+
]
|
|
250
|
+
},
|
|
251
|
+
[ErrorCategory.RATE_LIMIT]: {
|
|
252
|
+
category: ErrorCategory.RATE_LIMIT,
|
|
253
|
+
retryStrategy: RetryStrategy.CONSERVATIVE,
|
|
254
|
+
isRetryable: true,
|
|
255
|
+
...RETRY_STRATEGIES[RetryStrategy.CONSERVATIVE],
|
|
256
|
+
maxAttempts: 2, // Override: limited retries to avoid further rate limiting
|
|
257
|
+
baseDelayMs: 5000, // Override: longer delays for rate limits
|
|
258
|
+
description: 'Rate limit or quota exceeded',
|
|
259
|
+
troubleshooting: [
|
|
260
|
+
'Reduce request frequency',
|
|
261
|
+
'Implement request batching',
|
|
262
|
+
'Check rate limit headers',
|
|
263
|
+
'Wait for quota reset'
|
|
264
|
+
]
|
|
265
|
+
},
|
|
266
|
+
[ErrorCategory.CONFIGURATION]: {
|
|
267
|
+
category: ErrorCategory.CONFIGURATION,
|
|
268
|
+
retryStrategy: RetryStrategy.NONE,
|
|
269
|
+
isRetryable: false,
|
|
270
|
+
...RETRY_STRATEGIES[RetryStrategy.NONE],
|
|
271
|
+
description: 'Configuration or setup error',
|
|
272
|
+
troubleshooting: [
|
|
273
|
+
'Check environment variables',
|
|
274
|
+
'Verify configuration files',
|
|
275
|
+
'Review setup documentation',
|
|
276
|
+
'Check required dependencies'
|
|
277
|
+
]
|
|
278
|
+
},
|
|
279
|
+
[ErrorCategory.UNKNOWN]: {
|
|
280
|
+
category: ErrorCategory.UNKNOWN,
|
|
281
|
+
retryStrategy: RetryStrategy.EXPONENTIAL,
|
|
282
|
+
isRetryable: true,
|
|
283
|
+
...RETRY_STRATEGIES[RetryStrategy.EXPONENTIAL],
|
|
284
|
+
maxAttempts: 2, // Override: conservative retries for unknown errors
|
|
285
|
+
description: 'Unknown or unclassified error',
|
|
286
|
+
troubleshooting: [
|
|
287
|
+
'Check logs for more details',
|
|
288
|
+
'Verify system status',
|
|
289
|
+
'Try again with debug logging',
|
|
290
|
+
'Contact support if persists'
|
|
291
|
+
]
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Classify an error and determine retry strategy
|
|
296
|
+
*/
|
|
297
|
+
function classifyError(error) {
|
|
298
|
+
const errorMessage = error?.message || error?.toString() || '';
|
|
299
|
+
const errorLower = errorMessage.toLowerCase();
|
|
300
|
+
// Check each error category
|
|
301
|
+
for (const [category, patterns] of Object.entries(LIT_ERROR_PATTERNS)) {
|
|
302
|
+
for (const pattern of patterns) {
|
|
303
|
+
if (pattern.test(errorMessage) || pattern.test(errorLower)) {
|
|
304
|
+
const classification = CLASSIFICATION_RULES[category];
|
|
305
|
+
return {
|
|
306
|
+
...classification,
|
|
307
|
+
description: `${classification.description}: ${errorMessage.slice(0, 100)}`
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
// Default to unknown category
|
|
313
|
+
const unknownClassification = CLASSIFICATION_RULES[ErrorCategory.UNKNOWN];
|
|
314
|
+
return {
|
|
315
|
+
...unknownClassification,
|
|
316
|
+
description: `${unknownClassification.description}: ${errorMessage.slice(0, 100)}`
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get retry configuration from error classification
|
|
321
|
+
*/
|
|
322
|
+
function getRetryConfigFromClassification(classification) {
|
|
323
|
+
return {
|
|
324
|
+
maxAttempts: classification.maxAttempts,
|
|
325
|
+
initialDelayMs: classification.baseDelayMs,
|
|
326
|
+
maxDelayMs: classification.maxDelayMs,
|
|
327
|
+
backoffMultiplier: RETRY_STRATEGIES[classification.retryStrategy].multiplier,
|
|
328
|
+
retryableErrors: ['*'] // Classification already determined retryability
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Enhanced error analyzer for detailed error information
|
|
333
|
+
*/
|
|
334
|
+
function analyzeError(error) {
|
|
335
|
+
const classification = classifyError(error);
|
|
336
|
+
return {
|
|
337
|
+
...classification,
|
|
338
|
+
originalError: error,
|
|
339
|
+
errorMessage: error?.message || error?.toString() || 'Unknown error',
|
|
340
|
+
errorStack: error?.stack,
|
|
341
|
+
timestamp: new Date().toISOString(),
|
|
342
|
+
retryConfig: getRetryConfigFromClassification(classification)
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Create a human-readable error report
|
|
347
|
+
*/
|
|
348
|
+
function createErrorReport(error) {
|
|
349
|
+
const analysis = analyzeError(error);
|
|
350
|
+
const report = [
|
|
351
|
+
`๐ Error Analysis Report`,
|
|
352
|
+
`=====================================`,
|
|
353
|
+
`Category: ${analysis.category.toUpperCase()}`,
|
|
354
|
+
`Retryable: ${analysis.isRetryable ? 'โ
Yes' : 'โ No'}`,
|
|
355
|
+
`Strategy: ${analysis.retryStrategy}`,
|
|
356
|
+
`Max Attempts: ${analysis.maxAttempts}`,
|
|
357
|
+
`Description: ${analysis.description}`,
|
|
358
|
+
`Timestamp: ${analysis.timestamp}`,
|
|
359
|
+
``,
|
|
360
|
+
`Original Error: ${analysis.errorMessage}`,
|
|
361
|
+
``
|
|
362
|
+
];
|
|
363
|
+
if (analysis.troubleshooting && analysis.troubleshooting.length > 0) {
|
|
364
|
+
report.push(`๐ ๏ธ Troubleshooting Steps:`);
|
|
365
|
+
analysis.troubleshooting.forEach((step, index) => {
|
|
366
|
+
report.push(` ${index + 1}. ${step}`);
|
|
367
|
+
});
|
|
368
|
+
report.push('');
|
|
369
|
+
}
|
|
370
|
+
return report.join('\n');
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* LIT Protocol specific error matchers
|
|
374
|
+
*/
|
|
375
|
+
exports.litProtocolErrors = {
|
|
376
|
+
isNetworkError: (error) => classifyError(error).category === ErrorCategory.NETWORK,
|
|
377
|
+
isProtocolError: (error) => classifyError(error).category === ErrorCategory.PROTOCOL,
|
|
378
|
+
isAuthenticationError: (error) => classifyError(error).category === ErrorCategory.AUTHENTICATION,
|
|
379
|
+
isResourceError: (error) => classifyError(error).category === ErrorCategory.RESOURCE,
|
|
380
|
+
isTimeoutError: (error) => classifyError(error).category === ErrorCategory.TIMEOUT,
|
|
381
|
+
isRateLimitError: (error) => classifyError(error).category === ErrorCategory.RATE_LIMIT,
|
|
382
|
+
isConfigurationError: (error) => classifyError(error).category === ErrorCategory.CONFIGURATION,
|
|
383
|
+
isRetryable: (error) => classifyError(error).isRetryable
|
|
384
|
+
};
|
|
385
|
+
//# sourceMappingURL=error-classification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-classification.js","sourceRoot":"","sources":["../../../pkg-src/utils/chunks/error-classification.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA+TH,sCAuBC;AAKD,4EAQC;AAKD,oCAWC;AAKD,8CA0BC;AAhZD;;GAEG;AACH,IAAY,aAUX;AAVD,WAAY,aAAa;IACvB,oCAAmB,CAAA;IACnB,sCAAqB,CAAA;IACrB,kDAAiC,CAAA;IACjC,sCAAqB,CAAA;IACrB,0CAAyB,CAAA;IACzB,oCAAmB,CAAA;IACnB,0CAAyB,CAAA;IACzB,gDAA+B,CAAA;IAC/B,oCAAmB,CAAA;AACrB,CAAC,EAVW,aAAa,6BAAb,aAAa,QAUxB;AAED;;GAEG;AACH,IAAY,aAMX;AAND,WAAY,aAAa;IACvB,0CAAyB,CAAA;IACzB,8CAA6B,CAAA;IAC7B,4CAA2B,CAAA;IAC3B,kCAAiB,CAAA;IACjB,8BAAa,CAAA,CAAmB,aAAa;AAC/C,CAAC,EANW,aAAa,6BAAb,aAAa,QAMxB;AAgBD;;GAEG;AACH,MAAM,kBAAkB,GAAG;IACzB,gCAAgC;IAChC,OAAO,EAAE;QACP,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ache configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface SessionSignatureCacheConfig {
|
|
9
|
+
maxEntries: number;
|
|
10
|
+
bufferTimeMs: number;
|
|
11
|
+
enableLogging: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_CACHE_CONFIG: SessionSignatureCacheConfig;
|
|
14
|
+
/**
|
|
15
|
+
* In-memory session signature cache
|
|
16
|
+
*/
|
|
17
|
+
declare class SessionSignatureCache {
|
|
18
|
+
private cache;
|
|
19
|
+
private config;
|
|
20
|
+
constructor(config?: Partial<SessionSignatureCacheConfig>);
|
|
21
|
+
/**
|
|
22
|
+
* Generate cache key from PKP and context
|
|
23
|
+
*/
|
|
24
|
+
private generateCacheKey;
|
|
25
|
+
/**
|
|
26
|
+
* Check if cache entry is still valid
|
|
27
|
+
*/
|
|
28
|
+
private isEntryValid;
|
|
29
|
+
/**
|
|
30
|
+
* Clean expired entries from cache
|
|
31
|
+
*/
|
|
32
|
+
private cleanExpiredEntries;
|
|
33
|
+
/**
|
|
34
|
+
* Enforce cache size limits
|
|
35
|
+
*/
|
|
36
|
+
private enforceCacheSize;
|
|
37
|
+
/**
|
|
38
|
+
* Get cached session signatures if valid
|
|
39
|
+
*/
|
|
40
|
+
get(pkpTokenId: string, litActionCid: string, signerAddress: string, network: string): any | null;
|
|
41
|
+
/**
|
|
42
|
+
* Cache session signatures
|
|
43
|
+
*/
|
|
44
|
+
set(pkpTokenId: string, litActionCid: string, signerAddress: string, network: string, sessionSigs: any, expiration: Date): void;
|
|
45
|
+
/**
|
|
46
|
+
* Clear all cached session signatures
|
|
47
|
+
*/
|
|
48
|
+
clear(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get cache statistics
|
|
51
|
+
*/
|
|
52
|
+
getStats(): {
|
|
53
|
+
size: number;
|
|
54
|
+
maxEntries: number;
|
|
55
|
+
utilizationPercent: number;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Remove specific cache entry
|
|
59
|
+
*/
|
|
60
|
+
delete(pkpTokenId: string, litActionCid: string, signerAddress: string, network: string): boolean;
|
|
61
|
+
}
|
|
62
|
+
export declare const sessionSignatureCache: SessionSignatureCache;
|
|
63
|
+
/**
|
|
64
|
+
* Enhanced session signature generator with caching
|
|
65
|
+
*/
|
|
66
|
+
export declare function generateSessionSignaturesWithCache(litNodeClient: any, sessionConfig: any, pkpTokenId: string, litActionCid: string, signerAddress: string, network?: string): Promise<any>;
|
|
67
|
+
/**
|
|
68
|
+
* Configure the global session signature cache
|
|
69
|
+
*/
|
|
70
|
+
export declare function configureSessionSignatureCache(config: Partial<SessionSignatureCacheConfig>): void;
|
|
71
|
+
/**
|
|
72
|
+
* Clear the global session signature cache
|
|
73
|
+
*/
|
|
74
|
+
export declare function clearSessionSignatureCache(): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get session signature cache statistics
|
|
77
|
+
*/
|
|
78
|
+
export declare function getSessionSignatureCacheStats(): {
|
|
79
|
+
size: number;
|
|
80
|
+
maxEntries: number;
|
|
81
|
+
utilizationPercent: number;
|
|
82
|
+
};
|
|
83
|
+
export {};
|
|
84
|
+
//# sourceMappingURL=session-signature-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-signature-cache.d.ts","sourceRoot":"","sources":["../../../pkg-src/utils/chunks/session-signature-cache.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAiBH;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,eAAO,MAAM,oBAAoB,EAAE,2BAIlC,CAAC;AAEF;;GAEG;AACH,cAAM,qBAAqB;IACzB,OAAO,CAAC,KAAK,CAAiD;IAC9D,OAAO,CAAC,MAAM,CAA8B;gBAEhC,MAAM,GAAE,OAAO,CAAC,2BAA2B,CAAM;IAI7D;;OAEG;IACH,OAAO,CAAC,gBAAgB;IASxB;;OAEG;IACH,OAAO,CAAC,YAAY;IASpB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAgB3B;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAoBxB;;OAEG;IACH,GAAG,CACD,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,GAAG,GAAG,IAAI;IA6Bb;;OAEG;IACH,GAAG,CACD,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,GAAG,EAChB,UAAU,EAAE,IAAI,GACf,IAAI;IAuBP;;OAEG;IACH,KAAK,IAAI,IAAI;IASb;;OAEG;IACH,QAAQ;;;;;IAUR;;OAEG;IACH,MAAM,CACJ,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM,GACd,OAAO;CAUX;AAGD,eAAO,MAAM,qBAAqB,uBAA8B,CAAC;AAEjE;;GAEG;AACH,wBAAsB,kCAAkC,CACtD,aAAa,EAAE,GAAG,EAClB,aAAa,EAAE,GAAG,EAClB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,MAAgB,GACxB,OAAO,CAAC,GAAG,CAAC,CAqBd;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,OAAO,CAAC,2BAA2B,CAAC,GAAG,IAAI,CAEjG;AAED;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED;;GAEG;AACH,wBAAgB,6BAA6B;;;;EAE5C"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Session Signature Cache for PKP Operations
|
|
4
|
+
* Provides intelligent caching of session signatures to avoid regeneration
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.sessionSignatureCache = exports.DEFAULT_CACHE_CONFIG = void 0;
|
|
8
|
+
exports.generateSessionSignaturesWithCache = generateSessionSignaturesWithCache;
|
|
9
|
+
exports.configureSessionSignatureCache = configureSessionSignatureCache;
|
|
10
|
+
exports.clearSessionSignatureCache = clearSessionSignatureCache;
|
|
11
|
+
exports.getSessionSignatureCacheStats = getSessionSignatureCacheStats;
|
|
12
|
+
const debug_logger_1 = require("./debug-logger");
|
|
13
|
+
exports.DEFAULT_CACHE_CONFIG = {
|
|
14
|
+
maxEntries: 50,
|
|
15
|
+
bufferTimeMs: 60000, // 1 minute buffer before expiration
|
|
16
|
+
enableLogging: true
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* In-memory session signature cache
|
|
20
|
+
*/
|
|
21
|
+
class SessionSignatureCache {
|
|
22
|
+
constructor(config = {}) {
|
|
23
|
+
this.cache = new Map();
|
|
24
|
+
this.config = { ...exports.DEFAULT_CACHE_CONFIG, ...config };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Generate cache key from PKP and context
|
|
28
|
+
*/
|
|
29
|
+
generateCacheKey(pkpTokenId, litActionCid, signerAddress, network) {
|
|
30
|
+
return `${signerAddress}-${network}-${pkpTokenId}-${litActionCid}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if cache entry is still valid
|
|
34
|
+
*/
|
|
35
|
+
isEntryValid(entry) {
|
|
36
|
+
const now = new Date();
|
|
37
|
+
const expirationWithBuffer = new Date(entry.expiration.getTime() - this.config.bufferTimeMs);
|
|
38
|
+
return now < expirationWithBuffer;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Clean expired entries from cache
|
|
42
|
+
*/
|
|
43
|
+
cleanExpiredEntries() {
|
|
44
|
+
const now = new Date();
|
|
45
|
+
let cleanedCount = 0;
|
|
46
|
+
for (const [key, entry] of this.cache.entries()) {
|
|
47
|
+
if (now >= entry.expiration) {
|
|
48
|
+
this.cache.delete(key);
|
|
49
|
+
cleanedCount++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (cleanedCount > 0 && this.config.enableLogging) {
|
|
53
|
+
(0, debug_logger_1.debugInfo)('CACHE', `๐งน Cleaned ${cleanedCount} expired session signature entries`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Enforce cache size limits
|
|
58
|
+
*/
|
|
59
|
+
enforceCacheSize() {
|
|
60
|
+
if (this.cache.size <= this.config.maxEntries) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
// Sort entries by creation time and remove oldest
|
|
64
|
+
const entries = Array.from(this.cache.entries())
|
|
65
|
+
.sort(([, a], [, b]) => a.createdAt.getTime() - b.createdAt.getTime());
|
|
66
|
+
const toRemove = entries.slice(0, this.cache.size - this.config.maxEntries);
|
|
67
|
+
for (const [key] of toRemove) {
|
|
68
|
+
this.cache.delete(key);
|
|
69
|
+
}
|
|
70
|
+
if (this.config.enableLogging) {
|
|
71
|
+
(0, debug_logger_1.debugInfo)('CACHE', `๐ฆ Removed ${toRemove.length} oldest cache entries to maintain size limit`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get cached session signatures if valid
|
|
76
|
+
*/
|
|
77
|
+
get(pkpTokenId, litActionCid, signerAddress, network) {
|
|
78
|
+
this.cleanExpiredEntries();
|
|
79
|
+
const cacheKey = this.generateCacheKey(pkpTokenId, litActionCid, signerAddress, network);
|
|
80
|
+
const entry = this.cache.get(cacheKey);
|
|
81
|
+
if (!entry) {
|
|
82
|
+
if (this.config.enableLogging) {
|
|
83
|
+
(0, debug_logger_1.debugLog)('CACHE', `โ Session signatures cache miss: ${cacheKey}`);
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (!this.isEntryValid(entry)) {
|
|
88
|
+
this.cache.delete(cacheKey);
|
|
89
|
+
if (this.config.enableLogging) {
|
|
90
|
+
(0, debug_logger_1.debugWarn)('CACHE', `โฐ Session signatures expired: ${cacheKey}`);
|
|
91
|
+
}
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
if (this.config.enableLogging) {
|
|
95
|
+
const timeUntilExpiry = entry.expiration.getTime() - Date.now();
|
|
96
|
+
(0, debug_logger_1.debugInfo)('CACHE', `โ
Session signatures cache hit: ${cacheKey} (expires in ${Math.round(timeUntilExpiry / 1000)}s)`);
|
|
97
|
+
}
|
|
98
|
+
return entry.sessionSigs;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Cache session signatures
|
|
102
|
+
*/
|
|
103
|
+
set(pkpTokenId, litActionCid, signerAddress, network, sessionSigs, expiration) {
|
|
104
|
+
const cacheKey = this.generateCacheKey(pkpTokenId, litActionCid, signerAddress, network);
|
|
105
|
+
const entry = {
|
|
106
|
+
sessionSigs,
|
|
107
|
+
expiration,
|
|
108
|
+
pkpTokenId,
|
|
109
|
+
litActionCid,
|
|
110
|
+
signerAddress,
|
|
111
|
+
network,
|
|
112
|
+
createdAt: new Date()
|
|
113
|
+
};
|
|
114
|
+
this.cache.set(cacheKey, entry);
|
|
115
|
+
if (this.config.enableLogging) {
|
|
116
|
+
const timeUntilExpiry = expiration.getTime() - Date.now();
|
|
117
|
+
(0, debug_logger_1.debugInfo)('CACHE', `๐พ Cached session signatures: ${cacheKey} (expires in ${Math.round(timeUntilExpiry / 1000)}s)`);
|
|
118
|
+
}
|
|
119
|
+
this.enforceCacheSize();
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Clear all cached session signatures
|
|
123
|
+
*/
|
|
124
|
+
clear() {
|
|
125
|
+
const size = this.cache.size;
|
|
126
|
+
this.cache.clear();
|
|
127
|
+
if (this.config.enableLogging) {
|
|
128
|
+
(0, debug_logger_1.debugInfo)('CACHE', `๐๏ธ Cleared ${size} cached session signature entries`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get cache statistics
|
|
133
|
+
*/
|
|
134
|
+
getStats() {
|
|
135
|
+
this.cleanExpiredEntries();
|
|
136
|
+
return {
|
|
137
|
+
size: this.cache.size,
|
|
138
|
+
maxEntries: this.config.maxEntries,
|
|
139
|
+
utilizationPercent: Math.round((this.cache.size / this.config.maxEntries) * 100)
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Remove specific cache entry
|
|
144
|
+
*/
|
|
145
|
+
delete(pkpTokenId, litActionCid, signerAddress, network) {
|
|
146
|
+
const cacheKey = this.generateCacheKey(pkpTokenId, litActionCid, signerAddress, network);
|
|
147
|
+
const deleted = this.cache.delete(cacheKey);
|
|
148
|
+
if (deleted && this.config.enableLogging) {
|
|
149
|
+
(0, debug_logger_1.debugInfo)('CACHE', `๐๏ธ Removed session signatures from cache: ${cacheKey}`);
|
|
150
|
+
}
|
|
151
|
+
return deleted;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// Global session signature cache instance
|
|
155
|
+
exports.sessionSignatureCache = new SessionSignatureCache();
|
|
156
|
+
/**
|
|
157
|
+
* Enhanced session signature generator with caching
|
|
158
|
+
*/
|
|
159
|
+
async function generateSessionSignaturesWithCache(litNodeClient, sessionConfig, pkpTokenId, litActionCid, signerAddress, network = 'datil') {
|
|
160
|
+
// Check cache first
|
|
161
|
+
const cached = exports.sessionSignatureCache.get(pkpTokenId, litActionCid, signerAddress, network);
|
|
162
|
+
if (cached) {
|
|
163
|
+
return cached;
|
|
164
|
+
}
|
|
165
|
+
// Generate new session signatures
|
|
166
|
+
(0, debug_logger_1.debugInfo)('CACHE', '๐ Generating new session signatures (cache miss)...');
|
|
167
|
+
const sessionSigs = await litNodeClient.getSessionSigs(sessionConfig);
|
|
168
|
+
// Extract expiration from config
|
|
169
|
+
const expiration = new Date(sessionConfig.expiration);
|
|
170
|
+
// Cache the result
|
|
171
|
+
exports.sessionSignatureCache.set(pkpTokenId, litActionCid, signerAddress, network, sessionSigs, expiration);
|
|
172
|
+
const sigCount = Object.keys(sessionSigs).length;
|
|
173
|
+
(0, debug_logger_1.debugInfo)('CACHE', `โ
Generated and cached ${sigCount} session signatures`);
|
|
174
|
+
return sessionSigs;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Configure the global session signature cache
|
|
178
|
+
*/
|
|
179
|
+
function configureSessionSignatureCache(config) {
|
|
180
|
+
Object.assign(exports.sessionSignatureCache['config'], config);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Clear the global session signature cache
|
|
184
|
+
*/
|
|
185
|
+
function clearSessionSignatureCache() {
|
|
186
|
+
exports.sessionSignatureCache.clear();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get session signature cache statistics
|
|
190
|
+
*/
|
|
191
|
+
function getSessionSignatureCacheStats() {
|
|
192
|
+
return exports.sessionSignatureCache.getStats();
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=session-signature-cache.js.map
|