@cmdoss/memwal-sdk 0.6.2 → 0.8.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/ARCHITECTURE.md +547 -547
- package/BENCHMARKS.md +238 -238
- package/README.md +310 -181
- package/dist/ai-sdk/tools.d.ts +2 -2
- package/dist/ai-sdk/tools.js +2 -2
- package/dist/client/ClientMemoryManager.js +2 -2
- package/dist/client/ClientMemoryManager.js.map +1 -1
- package/dist/client/PersonalDataWallet.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.d.ts +29 -1
- package/dist/client/SimplePDWClient.d.ts.map +1 -1
- package/dist/client/SimplePDWClient.js +45 -13
- package/dist/client/SimplePDWClient.js.map +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.d.ts +1 -1
- package/dist/client/namespaces/EmbeddingsNamespace.js +1 -1
- package/dist/client/namespaces/MemoryNamespace.d.ts +31 -0
- package/dist/client/namespaces/MemoryNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/MemoryNamespace.js +272 -39
- package/dist/client/namespaces/MemoryNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/AINamespace.d.ts +2 -2
- package/dist/client/namespaces/consolidated/AINamespace.js +2 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts +12 -2
- package/dist/client/namespaces/consolidated/BlockchainNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js +62 -4
- package/dist/client/namespaces/consolidated/BlockchainNamespace.js.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts +67 -2
- package/dist/client/namespaces/consolidated/StorageNamespace.d.ts.map +1 -1
- package/dist/client/namespaces/consolidated/StorageNamespace.js +549 -16
- package/dist/client/namespaces/consolidated/StorageNamespace.js.map +1 -1
- package/dist/config/ConfigurationHelper.js +61 -61
- package/dist/config/defaults.js +2 -2
- package/dist/config/defaults.js.map +1 -1
- package/dist/graph/GraphService.js +21 -21
- package/dist/graph/GraphService.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.d.ts +9 -5
- package/dist/infrastructure/seal/EncryptionService.d.ts.map +1 -1
- package/dist/infrastructure/seal/EncryptionService.js +37 -15
- package/dist/infrastructure/seal/EncryptionService.js.map +1 -1
- package/dist/infrastructure/seal/SealService.d.ts +13 -5
- package/dist/infrastructure/seal/SealService.d.ts.map +1 -1
- package/dist/infrastructure/seal/SealService.js +36 -34
- package/dist/infrastructure/seal/SealService.js.map +1 -1
- package/dist/langchain/createPDWRAG.js +30 -30
- package/dist/retrieval/MemoryDecryptionPipeline.d.ts.map +1 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js +2 -1
- package/dist/retrieval/MemoryDecryptionPipeline.js.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.d.ts +31 -0
- package/dist/retrieval/MemoryRetrievalService.d.ts.map +1 -1
- package/dist/retrieval/MemoryRetrievalService.js +44 -4
- package/dist/retrieval/MemoryRetrievalService.js.map +1 -1
- package/dist/services/CapabilityService.d.ts.map +1 -1
- package/dist/services/CapabilityService.js +30 -14
- package/dist/services/CapabilityService.js.map +1 -1
- package/dist/services/CrossContextPermissionService.d.ts.map +1 -1
- package/dist/services/CrossContextPermissionService.js +9 -7
- package/dist/services/CrossContextPermissionService.js.map +1 -1
- package/dist/services/EmbeddingService.d.ts +28 -1
- package/dist/services/EmbeddingService.d.ts.map +1 -1
- package/dist/services/EmbeddingService.js +54 -0
- package/dist/services/EmbeddingService.js.map +1 -1
- package/dist/services/EncryptionService.d.ts.map +1 -1
- package/dist/services/EncryptionService.js +6 -5
- package/dist/services/EncryptionService.js.map +1 -1
- package/dist/services/GeminiAIService.js +309 -309
- package/dist/services/IndexManager.d.ts +5 -1
- package/dist/services/IndexManager.d.ts.map +1 -1
- package/dist/services/IndexManager.js +17 -40
- package/dist/services/IndexManager.js.map +1 -1
- package/dist/services/QueryService.js +1 -1
- package/dist/services/QueryService.js.map +1 -1
- package/dist/services/StorageService.d.ts +11 -0
- package/dist/services/StorageService.d.ts.map +1 -1
- package/dist/services/StorageService.js +73 -10
- package/dist/services/StorageService.js.map +1 -1
- package/dist/services/TransactionService.d.ts +20 -0
- package/dist/services/TransactionService.d.ts.map +1 -1
- package/dist/services/TransactionService.js +43 -0
- package/dist/services/TransactionService.js.map +1 -1
- package/dist/services/ViewService.js +2 -2
- package/dist/services/ViewService.js.map +1 -1
- package/dist/services/storage/QuiltBatchManager.d.ts +101 -1
- package/dist/services/storage/QuiltBatchManager.d.ts.map +1 -1
- package/dist/services/storage/QuiltBatchManager.js +410 -20
- package/dist/services/storage/QuiltBatchManager.js.map +1 -1
- package/dist/services/storage/index.d.ts +1 -1
- package/dist/services/storage/index.d.ts.map +1 -1
- package/dist/services/storage/index.js.map +1 -1
- package/dist/utils/LRUCache.d.ts +106 -0
- package/dist/utils/LRUCache.d.ts.map +1 -0
- package/dist/utils/LRUCache.js +281 -0
- package/dist/utils/LRUCache.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/memoryIndexOnChain.d.ts +212 -0
- package/dist/utils/memoryIndexOnChain.d.ts.map +1 -0
- package/dist/utils/memoryIndexOnChain.js +312 -0
- package/dist/utils/memoryIndexOnChain.js.map +1 -0
- package/dist/utils/rebuildIndexNode.d.ts +29 -0
- package/dist/utils/rebuildIndexNode.d.ts.map +1 -1
- package/dist/utils/rebuildIndexNode.js +366 -98
- package/dist/utils/rebuildIndexNode.js.map +1 -1
- package/dist/vector/HnswWasmService.d.ts +20 -5
- package/dist/vector/HnswWasmService.d.ts.map +1 -1
- package/dist/vector/HnswWasmService.js +73 -40
- package/dist/vector/HnswWasmService.js.map +1 -1
- package/dist/vector/IHnswService.d.ts +10 -1
- package/dist/vector/IHnswService.d.ts.map +1 -1
- package/dist/vector/IHnswService.js.map +1 -1
- package/dist/vector/NodeHnswService.d.ts +16 -0
- package/dist/vector/NodeHnswService.d.ts.map +1 -1
- package/dist/vector/NodeHnswService.js +84 -5
- package/dist/vector/NodeHnswService.js.map +1 -1
- package/dist/vector/createHnswService.d.ts +1 -1
- package/dist/vector/createHnswService.js +1 -1
- package/dist/vector/index.d.ts +1 -1
- package/dist/vector/index.js +1 -1
- package/package.json +157 -157
- package/src/access/PermissionService.ts +635 -635
- package/src/aggregation/AggregationService.ts +389 -389
- package/src/ai-sdk/PDWVectorStore.ts +715 -715
- package/src/ai-sdk/index.ts +65 -65
- package/src/ai-sdk/tools.ts +460 -460
- package/src/ai-sdk/types.ts +404 -404
- package/src/batch/BatchManager.ts +597 -597
- package/src/batch/BatchingService.ts +429 -429
- package/src/batch/MemoryProcessingCache.ts +492 -492
- package/src/batch/index.ts +30 -30
- package/src/browser.ts +200 -200
- package/src/client/ClientMemoryManager.ts +987 -987
- package/src/client/PersonalDataWallet.ts +345 -345
- package/src/client/SimplePDWClient.ts +1289 -1222
- package/src/client/factory.ts +154 -154
- package/src/client/namespaces/AnalyticsNamespace.ts +377 -377
- package/src/client/namespaces/BatchNamespace.ts +356 -356
- package/src/client/namespaces/CacheNamespace.ts +123 -123
- package/src/client/namespaces/CapabilityNamespace.ts +217 -217
- package/src/client/namespaces/ClassifyNamespace.ts +169 -169
- package/src/client/namespaces/ContextNamespace.ts +297 -297
- package/src/client/namespaces/EmbeddingsNamespace.ts +99 -99
- package/src/client/namespaces/EncryptionNamespace.ts +221 -221
- package/src/client/namespaces/GraphNamespace.ts +468 -468
- package/src/client/namespaces/IndexNamespace.ts +361 -361
- package/src/client/namespaces/MemoryNamespace.ts +1422 -1135
- package/src/client/namespaces/PermissionsNamespace.ts +254 -254
- package/src/client/namespaces/PipelineNamespace.ts +220 -220
- package/src/client/namespaces/SearchNamespace.ts +1049 -1049
- package/src/client/namespaces/StorageNamespace.ts +458 -458
- package/src/client/namespaces/TxNamespace.ts +260 -260
- package/src/client/namespaces/WalletNamespace.ts +243 -243
- package/src/client/namespaces/consolidated/AINamespace.ts +449 -449
- package/src/client/namespaces/consolidated/BlockchainNamespace.ts +607 -546
- package/src/client/namespaces/consolidated/SecurityNamespace.ts +648 -648
- package/src/client/namespaces/consolidated/StorageNamespace.ts +1141 -497
- package/src/client/namespaces/consolidated/index.ts +39 -39
- package/src/client/signers/KeypairSigner.ts +108 -108
- package/src/client/signers/UnifiedSigner.ts +110 -110
- package/src/client/signers/WalletAdapterSigner.ts +159 -159
- package/src/client/signers/index.ts +26 -26
- package/src/config/ConfigurationHelper.ts +412 -412
- package/src/config/defaults.ts +51 -51
- package/src/config/index.ts +8 -8
- package/src/config/validation.ts +70 -70
- package/src/core/index.ts +14 -14
- package/src/core/interfaces/IService.ts +307 -307
- package/src/core/interfaces/index.ts +8 -8
- package/src/core/types/capability.ts +297 -297
- package/src/core/types/index.ts +870 -870
- package/src/core/types/wallet.ts +270 -270
- package/src/core/types.ts +9 -9
- package/src/core/wallet.ts +222 -222
- package/src/embedding/index.ts +19 -19
- package/src/embedding/types.ts +357 -357
- package/src/errors/index.ts +602 -602
- package/src/errors/recovery.ts +461 -461
- package/src/errors/validation.ts +567 -567
- package/src/generated/pdw/capability.ts +319 -319
- package/src/graph/GraphService.ts +887 -887
- package/src/graph/KnowledgeGraphManager.ts +728 -728
- package/src/graph/index.ts +25 -25
- package/src/index.ts +498 -474
- package/src/infrastructure/index.ts +22 -22
- package/src/infrastructure/seal/EncryptionService.ts +628 -603
- package/src/infrastructure/seal/SealService.ts +613 -615
- package/src/infrastructure/seal/index.ts +9 -9
- package/src/infrastructure/sui/BlockchainManager.ts +627 -627
- package/src/infrastructure/sui/SuiService.ts +888 -888
- package/src/infrastructure/sui/index.ts +9 -9
- package/src/infrastructure/walrus/StorageManager.ts +604 -604
- package/src/infrastructure/walrus/WalrusStorageService.ts +612 -612
- package/src/infrastructure/walrus/index.ts +9 -9
- package/src/langchain/PDWEmbeddings.ts +145 -145
- package/src/langchain/PDWVectorStore.ts +456 -456
- package/src/langchain/createPDWRAG.ts +303 -303
- package/src/langchain/index.ts +47 -47
- package/src/permissions/ConsentRepository.browser.ts +249 -249
- package/src/permissions/ConsentRepository.ts +364 -364
- package/src/pipeline/MemoryPipeline.ts +862 -862
- package/src/pipeline/PipelineManager.ts +683 -683
- package/src/pipeline/index.ts +26 -26
- package/src/retrieval/AdvancedSearchService.ts +629 -629
- package/src/retrieval/MemoryAnalyticsService.ts +711 -711
- package/src/retrieval/MemoryDecryptionPipeline.ts +825 -824
- package/src/retrieval/MemoryRetrievalService.ts +904 -830
- package/src/retrieval/index.ts +42 -42
- package/src/services/BatchService.ts +352 -352
- package/src/services/CapabilityService.ts +464 -448
- package/src/services/ClassifierService.ts +465 -465
- package/src/services/CrossContextPermissionService.ts +486 -484
- package/src/services/EmbeddingService.ts +771 -706
- package/src/services/EncryptionService.ts +712 -711
- package/src/services/GeminiAIService.ts +753 -753
- package/src/services/IndexManager.ts +977 -1004
- package/src/services/MemoryIndexService.ts +1003 -1003
- package/src/services/MemoryService.ts +369 -369
- package/src/services/QueryService.ts +890 -890
- package/src/services/StorageService.ts +1182 -1111
- package/src/services/TransactionService.ts +838 -790
- package/src/services/VectorService.ts +462 -462
- package/src/services/ViewService.ts +484 -484
- package/src/services/index.ts +25 -25
- package/src/services/storage/BlobAttributesManager.ts +333 -333
- package/src/services/storage/KnowledgeGraphManager.ts +425 -425
- package/src/services/storage/MemorySearchManager.ts +387 -387
- package/src/services/storage/QuiltBatchManager.ts +1130 -660
- package/src/services/storage/WalrusMetadataManager.ts +268 -268
- package/src/services/storage/WalrusStorageManager.ts +287 -287
- package/src/services/storage/index.ts +57 -52
- package/src/types/index.ts +13 -13
- package/src/utils/LRUCache.ts +378 -0
- package/src/utils/index.ts +76 -68
- package/src/utils/memoryIndexOnChain.ts +507 -0
- package/src/utils/rebuildIndex.ts +290 -290
- package/src/utils/rebuildIndexNode.ts +771 -424
- package/src/vector/BrowserHnswIndexService.ts +758 -758
- package/src/vector/HnswWasmService.ts +731 -679
- package/src/vector/IHnswService.ts +233 -224
- package/src/vector/NodeHnswService.ts +833 -735
- package/src/vector/VectorManager.ts +478 -478
- package/src/vector/createHnswService.ts +135 -135
- package/src/vector/index.ts +56 -56
- package/src/wallet/ContextWalletService.ts +656 -656
- package/src/wallet/MainWalletService.ts +317 -317
package/src/errors/index.ts
CHANGED
|
@@ -1,603 +1,603 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error Handling System for Personal Data Wallet SDK
|
|
3
|
-
*
|
|
4
|
-
* Provides structured error types, validation, and user-friendly messages
|
|
5
|
-
* for all SDK operations including blockchain, storage, and encryption errors.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// ==================== BASE ERROR CLASSES ====================
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Base error class for all Personal Data Wallet SDK errors
|
|
12
|
-
*/
|
|
13
|
-
export abstract class PDWError extends Error {
|
|
14
|
-
public readonly code: string;
|
|
15
|
-
public readonly category: ErrorCategory;
|
|
16
|
-
public readonly severity: ErrorSeverity;
|
|
17
|
-
public readonly context?: Record<string, any>;
|
|
18
|
-
public readonly timestamp: Date;
|
|
19
|
-
public readonly originalError?: Error;
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
22
|
-
message: string,
|
|
23
|
-
code: string,
|
|
24
|
-
category: ErrorCategory,
|
|
25
|
-
severity: ErrorSeverity = 'error',
|
|
26
|
-
context?: Record<string, any>,
|
|
27
|
-
originalError?: Error
|
|
28
|
-
) {
|
|
29
|
-
super(message);
|
|
30
|
-
this.name = this.constructor.name;
|
|
31
|
-
this.code = code;
|
|
32
|
-
this.category = category;
|
|
33
|
-
this.severity = severity;
|
|
34
|
-
this.context = context;
|
|
35
|
-
this.timestamp = new Date();
|
|
36
|
-
this.originalError = originalError;
|
|
37
|
-
|
|
38
|
-
// Maintain proper stack trace
|
|
39
|
-
if (Error.captureStackTrace) {
|
|
40
|
-
Error.captureStackTrace(this, this.constructor);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Convert error to a structured object for logging/reporting
|
|
46
|
-
*/
|
|
47
|
-
toObject(): ErrorObject {
|
|
48
|
-
return {
|
|
49
|
-
name: this.name,
|
|
50
|
-
message: this.message,
|
|
51
|
-
code: this.code,
|
|
52
|
-
category: this.category,
|
|
53
|
-
severity: this.severity,
|
|
54
|
-
context: this.context,
|
|
55
|
-
timestamp: this.timestamp.toISOString(),
|
|
56
|
-
stack: this.stack,
|
|
57
|
-
originalError: this.originalError ? {
|
|
58
|
-
name: this.originalError.name,
|
|
59
|
-
message: this.originalError.message,
|
|
60
|
-
stack: this.originalError.stack,
|
|
61
|
-
} : undefined,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Get user-friendly error message
|
|
67
|
-
*/
|
|
68
|
-
getUserMessage(): string {
|
|
69
|
-
return ERROR_MESSAGES[this.code] || this.message;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Check if error is retryable
|
|
74
|
-
*/
|
|
75
|
-
isRetryable(): boolean {
|
|
76
|
-
return RETRYABLE_ERROR_CODES.includes(this.code);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// ==================== ERROR TYPES ====================
|
|
81
|
-
|
|
82
|
-
export type ErrorCategory =
|
|
83
|
-
| 'validation'
|
|
84
|
-
| 'blockchain'
|
|
85
|
-
| 'storage'
|
|
86
|
-
| 'encryption'
|
|
87
|
-
| 'network'
|
|
88
|
-
| 'configuration'
|
|
89
|
-
| 'authentication'
|
|
90
|
-
| 'permission';
|
|
91
|
-
|
|
92
|
-
export type ErrorSeverity = 'info' | 'warning' | 'error' | 'critical';
|
|
93
|
-
|
|
94
|
-
export interface ErrorObject {
|
|
95
|
-
name: string;
|
|
96
|
-
message: string;
|
|
97
|
-
code: string;
|
|
98
|
-
category: ErrorCategory;
|
|
99
|
-
severity: ErrorSeverity;
|
|
100
|
-
context?: Record<string, any>;
|
|
101
|
-
timestamp: string;
|
|
102
|
-
stack?: string;
|
|
103
|
-
originalError?: {
|
|
104
|
-
name: string;
|
|
105
|
-
message: string;
|
|
106
|
-
stack?: string;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ==================== VALIDATION ERRORS ====================
|
|
111
|
-
|
|
112
|
-
export class ValidationError extends PDWError {
|
|
113
|
-
constructor(
|
|
114
|
-
message: string,
|
|
115
|
-
field?: string,
|
|
116
|
-
value?: any,
|
|
117
|
-
originalError?: Error
|
|
118
|
-
) {
|
|
119
|
-
super(
|
|
120
|
-
message,
|
|
121
|
-
'VALIDATION_ERROR',
|
|
122
|
-
'validation',
|
|
123
|
-
'error',
|
|
124
|
-
{ field, value },
|
|
125
|
-
originalError
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export class ConfigurationError extends PDWError {
|
|
131
|
-
constructor(
|
|
132
|
-
message: string,
|
|
133
|
-
configKey?: string,
|
|
134
|
-
originalError?: Error
|
|
135
|
-
) {
|
|
136
|
-
super(
|
|
137
|
-
message,
|
|
138
|
-
'CONFIGURATION_ERROR',
|
|
139
|
-
'configuration',
|
|
140
|
-
'error',
|
|
141
|
-
{ configKey },
|
|
142
|
-
originalError
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export class InvalidParameterError extends PDWError {
|
|
148
|
-
constructor(parameter: string, expected: string, received: any) {
|
|
149
|
-
super(
|
|
150
|
-
`Invalid parameter '${parameter}': expected ${expected}, received ${typeof received}`,
|
|
151
|
-
'INVALID_PARAMETER',
|
|
152
|
-
'validation',
|
|
153
|
-
'error',
|
|
154
|
-
{ field: parameter, value: received }
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export class MissingParameterError extends PDWError {
|
|
160
|
-
constructor(parameter: string) {
|
|
161
|
-
super(
|
|
162
|
-
`Missing required parameter: ${parameter}`,
|
|
163
|
-
'MISSING_PARAMETER',
|
|
164
|
-
'validation',
|
|
165
|
-
'error',
|
|
166
|
-
{ field: parameter }
|
|
167
|
-
);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// ==================== BLOCKCHAIN ERRORS ====================
|
|
172
|
-
|
|
173
|
-
export class BlockchainError extends PDWError {
|
|
174
|
-
constructor(
|
|
175
|
-
message: string,
|
|
176
|
-
code: string,
|
|
177
|
-
context?: Record<string, any>,
|
|
178
|
-
originalError?: Error
|
|
179
|
-
) {
|
|
180
|
-
super(message, code, 'blockchain', 'error', context, originalError);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export class TransactionError extends BlockchainError {
|
|
185
|
-
constructor(
|
|
186
|
-
message: string,
|
|
187
|
-
transactionId?: string,
|
|
188
|
-
originalError?: Error
|
|
189
|
-
) {
|
|
190
|
-
super(
|
|
191
|
-
message,
|
|
192
|
-
'TRANSACTION_ERROR',
|
|
193
|
-
{ transactionId },
|
|
194
|
-
originalError
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
export class InsufficientGasError extends BlockchainError {
|
|
200
|
-
constructor(required: number, available: number) {
|
|
201
|
-
super(
|
|
202
|
-
`Insufficient gas: required ${required}, available ${available}`,
|
|
203
|
-
'INSUFFICIENT_GAS',
|
|
204
|
-
{ required, available }
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export class ContractExecutionError extends BlockchainError {
|
|
210
|
-
constructor(
|
|
211
|
-
contractFunction: string,
|
|
212
|
-
reason: string,
|
|
213
|
-
originalError?: Error
|
|
214
|
-
) {
|
|
215
|
-
super(
|
|
216
|
-
`Contract execution failed: ${contractFunction} - ${reason}`,
|
|
217
|
-
'CONTRACT_EXECUTION_ERROR',
|
|
218
|
-
{ contractFunction, reason },
|
|
219
|
-
originalError
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
export class ObjectNotFoundError extends BlockchainError {
|
|
225
|
-
constructor(objectId: string, objectType?: string) {
|
|
226
|
-
super(
|
|
227
|
-
`Object not found: ${objectId}${objectType ? ` (${objectType})` : ''}`,
|
|
228
|
-
'OBJECT_NOT_FOUND',
|
|
229
|
-
{ objectId, objectType }
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// ==================== STORAGE ERRORS ====================
|
|
235
|
-
|
|
236
|
-
export class StorageError extends PDWError {
|
|
237
|
-
constructor(
|
|
238
|
-
message: string,
|
|
239
|
-
code: string,
|
|
240
|
-
context?: Record<string, any>,
|
|
241
|
-
originalError?: Error
|
|
242
|
-
) {
|
|
243
|
-
super(message, code, 'storage', 'error', context, originalError);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
export class WalrusError extends StorageError {
|
|
248
|
-
constructor(
|
|
249
|
-
message: string,
|
|
250
|
-
blobId?: string,
|
|
251
|
-
originalError?: Error
|
|
252
|
-
) {
|
|
253
|
-
super(
|
|
254
|
-
message,
|
|
255
|
-
'WALRUS_ERROR',
|
|
256
|
-
{ blobId },
|
|
257
|
-
originalError
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export class StorageUploadError extends StorageError {
|
|
263
|
-
constructor(
|
|
264
|
-
reason: string,
|
|
265
|
-
fileSize?: number,
|
|
266
|
-
originalError?: Error
|
|
267
|
-
) {
|
|
268
|
-
super(
|
|
269
|
-
`Storage upload failed: ${reason}`,
|
|
270
|
-
'STORAGE_UPLOAD_ERROR',
|
|
271
|
-
{ fileSize },
|
|
272
|
-
originalError
|
|
273
|
-
);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export class StorageRetrievalError extends StorageError {
|
|
278
|
-
constructor(
|
|
279
|
-
blobId: string,
|
|
280
|
-
reason: string,
|
|
281
|
-
originalError?: Error
|
|
282
|
-
) {
|
|
283
|
-
super(
|
|
284
|
-
`Storage retrieval failed for ${blobId}: ${reason}`,
|
|
285
|
-
'STORAGE_RETRIEVAL_ERROR',
|
|
286
|
-
{ blobId },
|
|
287
|
-
originalError
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
export class StorageQuotaExceededError extends StorageError {
|
|
293
|
-
constructor(currentUsage: number, limit: number) {
|
|
294
|
-
super(
|
|
295
|
-
`Storage quota exceeded: ${currentUsage}/${limit} bytes`,
|
|
296
|
-
'STORAGE_QUOTA_EXCEEDED',
|
|
297
|
-
{ currentUsage, limit }
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
// ==================== ENCRYPTION ERRORS ====================
|
|
303
|
-
|
|
304
|
-
export class EncryptionError extends PDWError {
|
|
305
|
-
constructor(
|
|
306
|
-
message: string,
|
|
307
|
-
code: string,
|
|
308
|
-
context?: Record<string, any>,
|
|
309
|
-
originalError?: Error
|
|
310
|
-
) {
|
|
311
|
-
super(message, code, 'encryption', 'error', context, originalError);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export class SealInitializationError extends EncryptionError {
|
|
316
|
-
constructor(reason: string, originalError?: Error) {
|
|
317
|
-
super(
|
|
318
|
-
`SEAL client initialization failed: ${reason}`,
|
|
319
|
-
'SEAL_INITIALIZATION_ERROR',
|
|
320
|
-
{ reason },
|
|
321
|
-
originalError
|
|
322
|
-
);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
export class EncryptionFailedError extends EncryptionError {
|
|
327
|
-
constructor(
|
|
328
|
-
userAddress: string,
|
|
329
|
-
reason: string,
|
|
330
|
-
originalError?: Error
|
|
331
|
-
) {
|
|
332
|
-
super(
|
|
333
|
-
`Encryption failed for ${userAddress}: ${reason}`,
|
|
334
|
-
'ENCRYPTION_FAILED',
|
|
335
|
-
{ userAddress, reason },
|
|
336
|
-
originalError
|
|
337
|
-
);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
export class DecryptionFailedError extends EncryptionError {
|
|
342
|
-
constructor(
|
|
343
|
-
reason: string,
|
|
344
|
-
contentId?: string,
|
|
345
|
-
originalError?: Error
|
|
346
|
-
) {
|
|
347
|
-
super(
|
|
348
|
-
`Decryption failed: ${reason}`,
|
|
349
|
-
'DECRYPTION_FAILED',
|
|
350
|
-
{ contentId, reason },
|
|
351
|
-
originalError
|
|
352
|
-
);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
export class AccessDeniedError extends EncryptionError {
|
|
357
|
-
constructor(
|
|
358
|
-
userAddress: string,
|
|
359
|
-
contentId: string,
|
|
360
|
-
reason?: string
|
|
361
|
-
) {
|
|
362
|
-
super(
|
|
363
|
-
`Access denied for user ${userAddress} to content ${contentId}${reason ? `: ${reason}` : ''}`,
|
|
364
|
-
'ACCESS_DENIED',
|
|
365
|
-
{ userAddress, contentId, reason }
|
|
366
|
-
);
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
export class SessionKeyError extends EncryptionError {
|
|
371
|
-
constructor(
|
|
372
|
-
operation: string,
|
|
373
|
-
reason: string,
|
|
374
|
-
originalError?: Error
|
|
375
|
-
) {
|
|
376
|
-
super(
|
|
377
|
-
`Session key ${operation} failed: ${reason}`,
|
|
378
|
-
'SESSION_KEY_ERROR',
|
|
379
|
-
{ operation, reason },
|
|
380
|
-
originalError
|
|
381
|
-
);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// ==================== NETWORK ERRORS ====================
|
|
386
|
-
|
|
387
|
-
export class NetworkError extends PDWError {
|
|
388
|
-
constructor(
|
|
389
|
-
message: string,
|
|
390
|
-
code: string,
|
|
391
|
-
context?: Record<string, any>,
|
|
392
|
-
originalError?: Error
|
|
393
|
-
) {
|
|
394
|
-
super(message, code, 'network', 'error', context, originalError);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export class ConnectionError extends NetworkError {
|
|
399
|
-
constructor(endpoint: string, originalError?: Error) {
|
|
400
|
-
super(
|
|
401
|
-
`Failed to connect to ${endpoint}`,
|
|
402
|
-
'CONNECTION_ERROR',
|
|
403
|
-
{ endpoint },
|
|
404
|
-
originalError
|
|
405
|
-
);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export class TimeoutError extends NetworkError {
|
|
410
|
-
constructor(operation: string, timeoutMs: number) {
|
|
411
|
-
super(
|
|
412
|
-
`Operation '${operation}' timed out after ${timeoutMs}ms`,
|
|
413
|
-
'TIMEOUT_ERROR',
|
|
414
|
-
{ operation, timeoutMs }
|
|
415
|
-
);
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
export class RateLimitError extends NetworkError {
|
|
420
|
-
constructor(service: string, retryAfter?: number) {
|
|
421
|
-
super(
|
|
422
|
-
`Rate limit exceeded for ${service}${retryAfter ? `, retry after ${retryAfter}s` : ''}`,
|
|
423
|
-
'RATE_LIMIT_ERROR',
|
|
424
|
-
{ service, retryAfter }
|
|
425
|
-
);
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// ==================== AUTHENTICATION ERRORS ====================
|
|
430
|
-
|
|
431
|
-
export class AuthenticationError extends PDWError {
|
|
432
|
-
constructor(
|
|
433
|
-
message: string,
|
|
434
|
-
code: string,
|
|
435
|
-
context?: Record<string, any>,
|
|
436
|
-
originalError?: Error
|
|
437
|
-
) {
|
|
438
|
-
super(message, code, 'authentication', 'error', context, originalError);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
export class InvalidSignatureError extends AuthenticationError {
|
|
443
|
-
constructor(expectedAddress: string, actualAddress?: string) {
|
|
444
|
-
super(
|
|
445
|
-
`Invalid signature: expected from ${expectedAddress}${actualAddress ? `, got from ${actualAddress}` : ''}`,
|
|
446
|
-
'INVALID_SIGNATURE',
|
|
447
|
-
{ expectedAddress, actualAddress }
|
|
448
|
-
);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
export class WalletNotConnectedError extends AuthenticationError {
|
|
453
|
-
constructor() {
|
|
454
|
-
super(
|
|
455
|
-
'Wallet not connected. Please connect your wallet to continue.',
|
|
456
|
-
'WALLET_NOT_CONNECTED'
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
// ==================== USER-FRIENDLY ERROR MESSAGES ====================
|
|
462
|
-
|
|
463
|
-
export const ERROR_MESSAGES: Record<string, string> = {
|
|
464
|
-
// Validation
|
|
465
|
-
'VALIDATION_ERROR': 'The provided information is invalid. Please check your input and try again.',
|
|
466
|
-
'CONFIGURATION_ERROR': 'There is an issue with the SDK configuration. Please check your settings.',
|
|
467
|
-
'INVALID_PARAMETER': 'One of the provided values is invalid. Please check your input.',
|
|
468
|
-
'MISSING_PARAMETER': 'Required information is missing. Please provide all necessary details.',
|
|
469
|
-
|
|
470
|
-
// Blockchain
|
|
471
|
-
'TRANSACTION_ERROR': 'The blockchain transaction failed. Please try again.',
|
|
472
|
-
'INSUFFICIENT_GAS': 'Not enough gas to complete the transaction. Please add more SUI to your wallet.',
|
|
473
|
-
'CONTRACT_EXECUTION_ERROR': 'The smart contract operation failed. Please try again later.',
|
|
474
|
-
'OBJECT_NOT_FOUND': 'The requested item could not be found on the blockchain.',
|
|
475
|
-
|
|
476
|
-
// Storage
|
|
477
|
-
'WALRUS_ERROR': 'There was an issue with decentralized storage. Please try again.',
|
|
478
|
-
'STORAGE_UPLOAD_ERROR': 'Failed to save your data. Please check your connection and try again.',
|
|
479
|
-
'STORAGE_RETRIEVAL_ERROR': 'Failed to retrieve your data. Please try again later.',
|
|
480
|
-
'STORAGE_QUOTA_EXCEEDED': 'You have reached your storage limit. Please free up space or upgrade your plan.',
|
|
481
|
-
|
|
482
|
-
// Encryption
|
|
483
|
-
'SEAL_INITIALIZATION_ERROR': 'Encryption service is currently unavailable. Please try again later.',
|
|
484
|
-
'ENCRYPTION_FAILED': 'Failed to encrypt your data. Please try again.',
|
|
485
|
-
'DECRYPTION_FAILED': 'Failed to decrypt the requested content. Please check your permissions.',
|
|
486
|
-
'ACCESS_DENIED': 'You do not have permission to access this content.',
|
|
487
|
-
'SESSION_KEY_ERROR': 'Authentication session expired. Please reconnect and try again.',
|
|
488
|
-
|
|
489
|
-
// Network
|
|
490
|
-
'CONNECTION_ERROR': 'Unable to connect to the service. Please check your internet connection.',
|
|
491
|
-
'TIMEOUT_ERROR': 'The operation took too long to complete. Please try again.',
|
|
492
|
-
'RATE_LIMIT_ERROR': 'Too many requests. Please wait a moment before trying again.',
|
|
493
|
-
|
|
494
|
-
// Authentication
|
|
495
|
-
'INVALID_SIGNATURE': 'The signature verification failed. Please sign the transaction again.',
|
|
496
|
-
'WALLET_NOT_CONNECTED': 'Please connect your wallet to use this feature.',
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
// ==================== RETRYABLE ERROR CODES ====================
|
|
500
|
-
|
|
501
|
-
export const RETRYABLE_ERROR_CODES = [
|
|
502
|
-
'CONNECTION_ERROR',
|
|
503
|
-
'TIMEOUT_ERROR',
|
|
504
|
-
'WALRUS_ERROR',
|
|
505
|
-
'STORAGE_RETRIEVAL_ERROR',
|
|
506
|
-
'NETWORK_ERROR',
|
|
507
|
-
'SEAL_INITIALIZATION_ERROR',
|
|
508
|
-
];
|
|
509
|
-
|
|
510
|
-
// ==================== ERROR UTILITIES ====================
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Check if an error is a PDW SDK error
|
|
514
|
-
*/
|
|
515
|
-
export function isPDWError(error: any): error is PDWError {
|
|
516
|
-
return error instanceof PDWError;
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
/**
|
|
520
|
-
* Wrap unknown errors in a PDWError
|
|
521
|
-
*/
|
|
522
|
-
export function wrapError(
|
|
523
|
-
error: unknown,
|
|
524
|
-
category: ErrorCategory = 'unknown' as ErrorCategory,
|
|
525
|
-
context?: Record<string, any>
|
|
526
|
-
): PDWError {
|
|
527
|
-
if (isPDWError(error)) {
|
|
528
|
-
return error;
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
if (error instanceof Error) {
|
|
532
|
-
return new ValidationError(
|
|
533
|
-
error.message,
|
|
534
|
-
undefined,
|
|
535
|
-
undefined,
|
|
536
|
-
error
|
|
537
|
-
);
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
return new ValidationError(
|
|
541
|
-
'An unknown error occurred',
|
|
542
|
-
undefined,
|
|
543
|
-
error
|
|
544
|
-
);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
/**
|
|
548
|
-
* Create error from Sui/blockchain errors
|
|
549
|
-
*/
|
|
550
|
-
export function createBlockchainError(error: any, context?: Record<string, any>): BlockchainError {
|
|
551
|
-
const message = error?.message || 'Unknown blockchain error';
|
|
552
|
-
|
|
553
|
-
// Check for specific Sui error patterns
|
|
554
|
-
if (message.includes('InsufficientGas')) {
|
|
555
|
-
const gasMatch = message.match(/required: (\d+), available: (\d+)/);
|
|
556
|
-
if (gasMatch) {
|
|
557
|
-
return new InsufficientGasError(parseInt(gasMatch[1]), parseInt(gasMatch[2]));
|
|
558
|
-
}
|
|
559
|
-
return new InsufficientGasError(0, 0);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
if (message.includes('ObjectNotExists') || message.includes('not found')) {
|
|
563
|
-
const objectId = context?.objectId || 'unknown';
|
|
564
|
-
return new ObjectNotFoundError(objectId);
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
if (message.includes('execution_failure') || message.includes('MoveAbort')) {
|
|
568
|
-
return new ContractExecutionError(
|
|
569
|
-
context?.function || 'unknown',
|
|
570
|
-
message,
|
|
571
|
-
error
|
|
572
|
-
);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
return new BlockchainError(message, 'BLOCKCHAIN_ERROR', context, error);
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Create error from network/HTTP errors
|
|
580
|
-
*/
|
|
581
|
-
export function createNetworkError(error: any, endpoint?: string): NetworkError {
|
|
582
|
-
const message = error?.message || 'Network error occurred';
|
|
583
|
-
|
|
584
|
-
if (error?.code === 'ECONNREFUSED' || error?.code === 'ENOTFOUND') {
|
|
585
|
-
return new ConnectionError(endpoint || 'unknown endpoint', error);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
if (error?.code === 'TIMEOUT' || message.includes('timeout')) {
|
|
589
|
-
return new TimeoutError('network request', error?.timeout || 30000);
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
if (error?.status === 429 || message.includes('rate limit')) {
|
|
593
|
-
return new RateLimitError(endpoint || 'unknown service', error?.retryAfter);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
return new NetworkError(message, 'NETWORK_ERROR', { endpoint }, error);
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
// Re-export validation utilities
|
|
600
|
-
export * from './validation';
|
|
601
|
-
|
|
602
|
-
// Re-export recovery utilities
|
|
1
|
+
/**
|
|
2
|
+
* Error Handling System for Personal Data Wallet SDK
|
|
3
|
+
*
|
|
4
|
+
* Provides structured error types, validation, and user-friendly messages
|
|
5
|
+
* for all SDK operations including blockchain, storage, and encryption errors.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ==================== BASE ERROR CLASSES ====================
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Base error class for all Personal Data Wallet SDK errors
|
|
12
|
+
*/
|
|
13
|
+
export abstract class PDWError extends Error {
|
|
14
|
+
public readonly code: string;
|
|
15
|
+
public readonly category: ErrorCategory;
|
|
16
|
+
public readonly severity: ErrorSeverity;
|
|
17
|
+
public readonly context?: Record<string, any>;
|
|
18
|
+
public readonly timestamp: Date;
|
|
19
|
+
public readonly originalError?: Error;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
message: string,
|
|
23
|
+
code: string,
|
|
24
|
+
category: ErrorCategory,
|
|
25
|
+
severity: ErrorSeverity = 'error',
|
|
26
|
+
context?: Record<string, any>,
|
|
27
|
+
originalError?: Error
|
|
28
|
+
) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = this.constructor.name;
|
|
31
|
+
this.code = code;
|
|
32
|
+
this.category = category;
|
|
33
|
+
this.severity = severity;
|
|
34
|
+
this.context = context;
|
|
35
|
+
this.timestamp = new Date();
|
|
36
|
+
this.originalError = originalError;
|
|
37
|
+
|
|
38
|
+
// Maintain proper stack trace
|
|
39
|
+
if (Error.captureStackTrace) {
|
|
40
|
+
Error.captureStackTrace(this, this.constructor);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Convert error to a structured object for logging/reporting
|
|
46
|
+
*/
|
|
47
|
+
toObject(): ErrorObject {
|
|
48
|
+
return {
|
|
49
|
+
name: this.name,
|
|
50
|
+
message: this.message,
|
|
51
|
+
code: this.code,
|
|
52
|
+
category: this.category,
|
|
53
|
+
severity: this.severity,
|
|
54
|
+
context: this.context,
|
|
55
|
+
timestamp: this.timestamp.toISOString(),
|
|
56
|
+
stack: this.stack,
|
|
57
|
+
originalError: this.originalError ? {
|
|
58
|
+
name: this.originalError.name,
|
|
59
|
+
message: this.originalError.message,
|
|
60
|
+
stack: this.originalError.stack,
|
|
61
|
+
} : undefined,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Get user-friendly error message
|
|
67
|
+
*/
|
|
68
|
+
getUserMessage(): string {
|
|
69
|
+
return ERROR_MESSAGES[this.code] || this.message;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Check if error is retryable
|
|
74
|
+
*/
|
|
75
|
+
isRetryable(): boolean {
|
|
76
|
+
return RETRYABLE_ERROR_CODES.includes(this.code);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ==================== ERROR TYPES ====================
|
|
81
|
+
|
|
82
|
+
export type ErrorCategory =
|
|
83
|
+
| 'validation'
|
|
84
|
+
| 'blockchain'
|
|
85
|
+
| 'storage'
|
|
86
|
+
| 'encryption'
|
|
87
|
+
| 'network'
|
|
88
|
+
| 'configuration'
|
|
89
|
+
| 'authentication'
|
|
90
|
+
| 'permission';
|
|
91
|
+
|
|
92
|
+
export type ErrorSeverity = 'info' | 'warning' | 'error' | 'critical';
|
|
93
|
+
|
|
94
|
+
export interface ErrorObject {
|
|
95
|
+
name: string;
|
|
96
|
+
message: string;
|
|
97
|
+
code: string;
|
|
98
|
+
category: ErrorCategory;
|
|
99
|
+
severity: ErrorSeverity;
|
|
100
|
+
context?: Record<string, any>;
|
|
101
|
+
timestamp: string;
|
|
102
|
+
stack?: string;
|
|
103
|
+
originalError?: {
|
|
104
|
+
name: string;
|
|
105
|
+
message: string;
|
|
106
|
+
stack?: string;
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ==================== VALIDATION ERRORS ====================
|
|
111
|
+
|
|
112
|
+
export class ValidationError extends PDWError {
|
|
113
|
+
constructor(
|
|
114
|
+
message: string,
|
|
115
|
+
field?: string,
|
|
116
|
+
value?: any,
|
|
117
|
+
originalError?: Error
|
|
118
|
+
) {
|
|
119
|
+
super(
|
|
120
|
+
message,
|
|
121
|
+
'VALIDATION_ERROR',
|
|
122
|
+
'validation',
|
|
123
|
+
'error',
|
|
124
|
+
{ field, value },
|
|
125
|
+
originalError
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export class ConfigurationError extends PDWError {
|
|
131
|
+
constructor(
|
|
132
|
+
message: string,
|
|
133
|
+
configKey?: string,
|
|
134
|
+
originalError?: Error
|
|
135
|
+
) {
|
|
136
|
+
super(
|
|
137
|
+
message,
|
|
138
|
+
'CONFIGURATION_ERROR',
|
|
139
|
+
'configuration',
|
|
140
|
+
'error',
|
|
141
|
+
{ configKey },
|
|
142
|
+
originalError
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export class InvalidParameterError extends PDWError {
|
|
148
|
+
constructor(parameter: string, expected: string, received: any) {
|
|
149
|
+
super(
|
|
150
|
+
`Invalid parameter '${parameter}': expected ${expected}, received ${typeof received}`,
|
|
151
|
+
'INVALID_PARAMETER',
|
|
152
|
+
'validation',
|
|
153
|
+
'error',
|
|
154
|
+
{ field: parameter, value: received }
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export class MissingParameterError extends PDWError {
|
|
160
|
+
constructor(parameter: string) {
|
|
161
|
+
super(
|
|
162
|
+
`Missing required parameter: ${parameter}`,
|
|
163
|
+
'MISSING_PARAMETER',
|
|
164
|
+
'validation',
|
|
165
|
+
'error',
|
|
166
|
+
{ field: parameter }
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ==================== BLOCKCHAIN ERRORS ====================
|
|
172
|
+
|
|
173
|
+
export class BlockchainError extends PDWError {
|
|
174
|
+
constructor(
|
|
175
|
+
message: string,
|
|
176
|
+
code: string,
|
|
177
|
+
context?: Record<string, any>,
|
|
178
|
+
originalError?: Error
|
|
179
|
+
) {
|
|
180
|
+
super(message, code, 'blockchain', 'error', context, originalError);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export class TransactionError extends BlockchainError {
|
|
185
|
+
constructor(
|
|
186
|
+
message: string,
|
|
187
|
+
transactionId?: string,
|
|
188
|
+
originalError?: Error
|
|
189
|
+
) {
|
|
190
|
+
super(
|
|
191
|
+
message,
|
|
192
|
+
'TRANSACTION_ERROR',
|
|
193
|
+
{ transactionId },
|
|
194
|
+
originalError
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export class InsufficientGasError extends BlockchainError {
|
|
200
|
+
constructor(required: number, available: number) {
|
|
201
|
+
super(
|
|
202
|
+
`Insufficient gas: required ${required}, available ${available}`,
|
|
203
|
+
'INSUFFICIENT_GAS',
|
|
204
|
+
{ required, available }
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export class ContractExecutionError extends BlockchainError {
|
|
210
|
+
constructor(
|
|
211
|
+
contractFunction: string,
|
|
212
|
+
reason: string,
|
|
213
|
+
originalError?: Error
|
|
214
|
+
) {
|
|
215
|
+
super(
|
|
216
|
+
`Contract execution failed: ${contractFunction} - ${reason}`,
|
|
217
|
+
'CONTRACT_EXECUTION_ERROR',
|
|
218
|
+
{ contractFunction, reason },
|
|
219
|
+
originalError
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export class ObjectNotFoundError extends BlockchainError {
|
|
225
|
+
constructor(objectId: string, objectType?: string) {
|
|
226
|
+
super(
|
|
227
|
+
`Object not found: ${objectId}${objectType ? ` (${objectType})` : ''}`,
|
|
228
|
+
'OBJECT_NOT_FOUND',
|
|
229
|
+
{ objectId, objectType }
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ==================== STORAGE ERRORS ====================
|
|
235
|
+
|
|
236
|
+
export class StorageError extends PDWError {
|
|
237
|
+
constructor(
|
|
238
|
+
message: string,
|
|
239
|
+
code: string,
|
|
240
|
+
context?: Record<string, any>,
|
|
241
|
+
originalError?: Error
|
|
242
|
+
) {
|
|
243
|
+
super(message, code, 'storage', 'error', context, originalError);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export class WalrusError extends StorageError {
|
|
248
|
+
constructor(
|
|
249
|
+
message: string,
|
|
250
|
+
blobId?: string,
|
|
251
|
+
originalError?: Error
|
|
252
|
+
) {
|
|
253
|
+
super(
|
|
254
|
+
message,
|
|
255
|
+
'WALRUS_ERROR',
|
|
256
|
+
{ blobId },
|
|
257
|
+
originalError
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export class StorageUploadError extends StorageError {
|
|
263
|
+
constructor(
|
|
264
|
+
reason: string,
|
|
265
|
+
fileSize?: number,
|
|
266
|
+
originalError?: Error
|
|
267
|
+
) {
|
|
268
|
+
super(
|
|
269
|
+
`Storage upload failed: ${reason}`,
|
|
270
|
+
'STORAGE_UPLOAD_ERROR',
|
|
271
|
+
{ fileSize },
|
|
272
|
+
originalError
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export class StorageRetrievalError extends StorageError {
|
|
278
|
+
constructor(
|
|
279
|
+
blobId: string,
|
|
280
|
+
reason: string,
|
|
281
|
+
originalError?: Error
|
|
282
|
+
) {
|
|
283
|
+
super(
|
|
284
|
+
`Storage retrieval failed for ${blobId}: ${reason}`,
|
|
285
|
+
'STORAGE_RETRIEVAL_ERROR',
|
|
286
|
+
{ blobId },
|
|
287
|
+
originalError
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export class StorageQuotaExceededError extends StorageError {
|
|
293
|
+
constructor(currentUsage: number, limit: number) {
|
|
294
|
+
super(
|
|
295
|
+
`Storage quota exceeded: ${currentUsage}/${limit} bytes`,
|
|
296
|
+
'STORAGE_QUOTA_EXCEEDED',
|
|
297
|
+
{ currentUsage, limit }
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// ==================== ENCRYPTION ERRORS ====================
|
|
303
|
+
|
|
304
|
+
export class EncryptionError extends PDWError {
|
|
305
|
+
constructor(
|
|
306
|
+
message: string,
|
|
307
|
+
code: string,
|
|
308
|
+
context?: Record<string, any>,
|
|
309
|
+
originalError?: Error
|
|
310
|
+
) {
|
|
311
|
+
super(message, code, 'encryption', 'error', context, originalError);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export class SealInitializationError extends EncryptionError {
|
|
316
|
+
constructor(reason: string, originalError?: Error) {
|
|
317
|
+
super(
|
|
318
|
+
`SEAL client initialization failed: ${reason}`,
|
|
319
|
+
'SEAL_INITIALIZATION_ERROR',
|
|
320
|
+
{ reason },
|
|
321
|
+
originalError
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export class EncryptionFailedError extends EncryptionError {
|
|
327
|
+
constructor(
|
|
328
|
+
userAddress: string,
|
|
329
|
+
reason: string,
|
|
330
|
+
originalError?: Error
|
|
331
|
+
) {
|
|
332
|
+
super(
|
|
333
|
+
`Encryption failed for ${userAddress}: ${reason}`,
|
|
334
|
+
'ENCRYPTION_FAILED',
|
|
335
|
+
{ userAddress, reason },
|
|
336
|
+
originalError
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export class DecryptionFailedError extends EncryptionError {
|
|
342
|
+
constructor(
|
|
343
|
+
reason: string,
|
|
344
|
+
contentId?: string,
|
|
345
|
+
originalError?: Error
|
|
346
|
+
) {
|
|
347
|
+
super(
|
|
348
|
+
`Decryption failed: ${reason}`,
|
|
349
|
+
'DECRYPTION_FAILED',
|
|
350
|
+
{ contentId, reason },
|
|
351
|
+
originalError
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export class AccessDeniedError extends EncryptionError {
|
|
357
|
+
constructor(
|
|
358
|
+
userAddress: string,
|
|
359
|
+
contentId: string,
|
|
360
|
+
reason?: string
|
|
361
|
+
) {
|
|
362
|
+
super(
|
|
363
|
+
`Access denied for user ${userAddress} to content ${contentId}${reason ? `: ${reason}` : ''}`,
|
|
364
|
+
'ACCESS_DENIED',
|
|
365
|
+
{ userAddress, contentId, reason }
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export class SessionKeyError extends EncryptionError {
|
|
371
|
+
constructor(
|
|
372
|
+
operation: string,
|
|
373
|
+
reason: string,
|
|
374
|
+
originalError?: Error
|
|
375
|
+
) {
|
|
376
|
+
super(
|
|
377
|
+
`Session key ${operation} failed: ${reason}`,
|
|
378
|
+
'SESSION_KEY_ERROR',
|
|
379
|
+
{ operation, reason },
|
|
380
|
+
originalError
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// ==================== NETWORK ERRORS ====================
|
|
386
|
+
|
|
387
|
+
export class NetworkError extends PDWError {
|
|
388
|
+
constructor(
|
|
389
|
+
message: string,
|
|
390
|
+
code: string,
|
|
391
|
+
context?: Record<string, any>,
|
|
392
|
+
originalError?: Error
|
|
393
|
+
) {
|
|
394
|
+
super(message, code, 'network', 'error', context, originalError);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export class ConnectionError extends NetworkError {
|
|
399
|
+
constructor(endpoint: string, originalError?: Error) {
|
|
400
|
+
super(
|
|
401
|
+
`Failed to connect to ${endpoint}`,
|
|
402
|
+
'CONNECTION_ERROR',
|
|
403
|
+
{ endpoint },
|
|
404
|
+
originalError
|
|
405
|
+
);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export class TimeoutError extends NetworkError {
|
|
410
|
+
constructor(operation: string, timeoutMs: number) {
|
|
411
|
+
super(
|
|
412
|
+
`Operation '${operation}' timed out after ${timeoutMs}ms`,
|
|
413
|
+
'TIMEOUT_ERROR',
|
|
414
|
+
{ operation, timeoutMs }
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
export class RateLimitError extends NetworkError {
|
|
420
|
+
constructor(service: string, retryAfter?: number) {
|
|
421
|
+
super(
|
|
422
|
+
`Rate limit exceeded for ${service}${retryAfter ? `, retry after ${retryAfter}s` : ''}`,
|
|
423
|
+
'RATE_LIMIT_ERROR',
|
|
424
|
+
{ service, retryAfter }
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// ==================== AUTHENTICATION ERRORS ====================
|
|
430
|
+
|
|
431
|
+
export class AuthenticationError extends PDWError {
|
|
432
|
+
constructor(
|
|
433
|
+
message: string,
|
|
434
|
+
code: string,
|
|
435
|
+
context?: Record<string, any>,
|
|
436
|
+
originalError?: Error
|
|
437
|
+
) {
|
|
438
|
+
super(message, code, 'authentication', 'error', context, originalError);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export class InvalidSignatureError extends AuthenticationError {
|
|
443
|
+
constructor(expectedAddress: string, actualAddress?: string) {
|
|
444
|
+
super(
|
|
445
|
+
`Invalid signature: expected from ${expectedAddress}${actualAddress ? `, got from ${actualAddress}` : ''}`,
|
|
446
|
+
'INVALID_SIGNATURE',
|
|
447
|
+
{ expectedAddress, actualAddress }
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export class WalletNotConnectedError extends AuthenticationError {
|
|
453
|
+
constructor() {
|
|
454
|
+
super(
|
|
455
|
+
'Wallet not connected. Please connect your wallet to continue.',
|
|
456
|
+
'WALLET_NOT_CONNECTED'
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// ==================== USER-FRIENDLY ERROR MESSAGES ====================
|
|
462
|
+
|
|
463
|
+
export const ERROR_MESSAGES: Record<string, string> = {
|
|
464
|
+
// Validation
|
|
465
|
+
'VALIDATION_ERROR': 'The provided information is invalid. Please check your input and try again.',
|
|
466
|
+
'CONFIGURATION_ERROR': 'There is an issue with the SDK configuration. Please check your settings.',
|
|
467
|
+
'INVALID_PARAMETER': 'One of the provided values is invalid. Please check your input.',
|
|
468
|
+
'MISSING_PARAMETER': 'Required information is missing. Please provide all necessary details.',
|
|
469
|
+
|
|
470
|
+
// Blockchain
|
|
471
|
+
'TRANSACTION_ERROR': 'The blockchain transaction failed. Please try again.',
|
|
472
|
+
'INSUFFICIENT_GAS': 'Not enough gas to complete the transaction. Please add more SUI to your wallet.',
|
|
473
|
+
'CONTRACT_EXECUTION_ERROR': 'The smart contract operation failed. Please try again later.',
|
|
474
|
+
'OBJECT_NOT_FOUND': 'The requested item could not be found on the blockchain.',
|
|
475
|
+
|
|
476
|
+
// Storage
|
|
477
|
+
'WALRUS_ERROR': 'There was an issue with decentralized storage. Please try again.',
|
|
478
|
+
'STORAGE_UPLOAD_ERROR': 'Failed to save your data. Please check your connection and try again.',
|
|
479
|
+
'STORAGE_RETRIEVAL_ERROR': 'Failed to retrieve your data. Please try again later.',
|
|
480
|
+
'STORAGE_QUOTA_EXCEEDED': 'You have reached your storage limit. Please free up space or upgrade your plan.',
|
|
481
|
+
|
|
482
|
+
// Encryption
|
|
483
|
+
'SEAL_INITIALIZATION_ERROR': 'Encryption service is currently unavailable. Please try again later.',
|
|
484
|
+
'ENCRYPTION_FAILED': 'Failed to encrypt your data. Please try again.',
|
|
485
|
+
'DECRYPTION_FAILED': 'Failed to decrypt the requested content. Please check your permissions.',
|
|
486
|
+
'ACCESS_DENIED': 'You do not have permission to access this content.',
|
|
487
|
+
'SESSION_KEY_ERROR': 'Authentication session expired. Please reconnect and try again.',
|
|
488
|
+
|
|
489
|
+
// Network
|
|
490
|
+
'CONNECTION_ERROR': 'Unable to connect to the service. Please check your internet connection.',
|
|
491
|
+
'TIMEOUT_ERROR': 'The operation took too long to complete. Please try again.',
|
|
492
|
+
'RATE_LIMIT_ERROR': 'Too many requests. Please wait a moment before trying again.',
|
|
493
|
+
|
|
494
|
+
// Authentication
|
|
495
|
+
'INVALID_SIGNATURE': 'The signature verification failed. Please sign the transaction again.',
|
|
496
|
+
'WALLET_NOT_CONNECTED': 'Please connect your wallet to use this feature.',
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
// ==================== RETRYABLE ERROR CODES ====================
|
|
500
|
+
|
|
501
|
+
export const RETRYABLE_ERROR_CODES = [
|
|
502
|
+
'CONNECTION_ERROR',
|
|
503
|
+
'TIMEOUT_ERROR',
|
|
504
|
+
'WALRUS_ERROR',
|
|
505
|
+
'STORAGE_RETRIEVAL_ERROR',
|
|
506
|
+
'NETWORK_ERROR',
|
|
507
|
+
'SEAL_INITIALIZATION_ERROR',
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
// ==================== ERROR UTILITIES ====================
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Check if an error is a PDW SDK error
|
|
514
|
+
*/
|
|
515
|
+
export function isPDWError(error: any): error is PDWError {
|
|
516
|
+
return error instanceof PDWError;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Wrap unknown errors in a PDWError
|
|
521
|
+
*/
|
|
522
|
+
export function wrapError(
|
|
523
|
+
error: unknown,
|
|
524
|
+
category: ErrorCategory = 'unknown' as ErrorCategory,
|
|
525
|
+
context?: Record<string, any>
|
|
526
|
+
): PDWError {
|
|
527
|
+
if (isPDWError(error)) {
|
|
528
|
+
return error;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
if (error instanceof Error) {
|
|
532
|
+
return new ValidationError(
|
|
533
|
+
error.message,
|
|
534
|
+
undefined,
|
|
535
|
+
undefined,
|
|
536
|
+
error
|
|
537
|
+
);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
return new ValidationError(
|
|
541
|
+
'An unknown error occurred',
|
|
542
|
+
undefined,
|
|
543
|
+
error
|
|
544
|
+
);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Create error from Sui/blockchain errors
|
|
549
|
+
*/
|
|
550
|
+
export function createBlockchainError(error: any, context?: Record<string, any>): BlockchainError {
|
|
551
|
+
const message = error?.message || 'Unknown blockchain error';
|
|
552
|
+
|
|
553
|
+
// Check for specific Sui error patterns
|
|
554
|
+
if (message.includes('InsufficientGas')) {
|
|
555
|
+
const gasMatch = message.match(/required: (\d+), available: (\d+)/);
|
|
556
|
+
if (gasMatch) {
|
|
557
|
+
return new InsufficientGasError(parseInt(gasMatch[1]), parseInt(gasMatch[2]));
|
|
558
|
+
}
|
|
559
|
+
return new InsufficientGasError(0, 0);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (message.includes('ObjectNotExists') || message.includes('not found')) {
|
|
563
|
+
const objectId = context?.objectId || 'unknown';
|
|
564
|
+
return new ObjectNotFoundError(objectId);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
if (message.includes('execution_failure') || message.includes('MoveAbort')) {
|
|
568
|
+
return new ContractExecutionError(
|
|
569
|
+
context?.function || 'unknown',
|
|
570
|
+
message,
|
|
571
|
+
error
|
|
572
|
+
);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
return new BlockchainError(message, 'BLOCKCHAIN_ERROR', context, error);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Create error from network/HTTP errors
|
|
580
|
+
*/
|
|
581
|
+
export function createNetworkError(error: any, endpoint?: string): NetworkError {
|
|
582
|
+
const message = error?.message || 'Network error occurred';
|
|
583
|
+
|
|
584
|
+
if (error?.code === 'ECONNREFUSED' || error?.code === 'ENOTFOUND') {
|
|
585
|
+
return new ConnectionError(endpoint || 'unknown endpoint', error);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
if (error?.code === 'TIMEOUT' || message.includes('timeout')) {
|
|
589
|
+
return new TimeoutError('network request', error?.timeout || 30000);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
if (error?.status === 429 || message.includes('rate limit')) {
|
|
593
|
+
return new RateLimitError(endpoint || 'unknown service', error?.retryAfter);
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
return new NetworkError(message, 'NETWORK_ERROR', { endpoint }, error);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// Re-export validation utilities
|
|
600
|
+
export * from './validation';
|
|
601
|
+
|
|
602
|
+
// Re-export recovery utilities
|
|
603
603
|
export * from './recovery';
|