@hauska-sdk/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,398 @@
1
+ # Troubleshooting
2
+
3
+ Common issues and solutions when using the CNS Protocol Core SDK.
4
+
5
+ ## Configuration Issues
6
+
7
+ ### "VDA configuration is required"
8
+
9
+ **Problem:** SDK initialization fails with configuration error.
10
+
11
+ **Solutions:**
12
+ 1. Ensure `vda` configuration is provided:
13
+ ```typescript
14
+ const sdk = new CNSSDK({
15
+ vda: {
16
+ storageAdapter: new PostgreSQLStorageAdapter({ /* ... */ }),
17
+ },
18
+ // ... other config
19
+ });
20
+ ```
21
+
22
+ 2. Check that `storageAdapter` is properly initialized.
23
+
24
+ ### "Pinata configuration is required"
25
+
26
+ **Problem:** Retrieval SDK requires Pinata configuration.
27
+
28
+ **Solutions:**
29
+ 1. Provide Pinata JWT token:
30
+ ```typescript
31
+ retrieval: {
32
+ pinata: {
33
+ pinataJwt: process.env.PINATA_JWT!,
34
+ pinataGateway: "https://gateway.pinata.cloud",
35
+ },
36
+ }
37
+ ```
38
+
39
+ 2. Verify your Pinata JWT token is valid.
40
+
41
+ ### "VDA storage adapter is required"
42
+
43
+ **Problem:** Storage adapter not configured.
44
+
45
+ **Solutions:**
46
+ 1. Install and configure a storage adapter:
47
+ ```bash
48
+ npm install @hauska-sdk/adapters-storage-postgres
49
+ ```
50
+
51
+ 2. Initialize the adapter:
52
+ ```typescript
53
+ import { PostgreSQLStorageAdapter } from "@hauska-sdk/adapters-storage-postgres";
54
+
55
+ const storageAdapter = new PostgreSQLStorageAdapter({
56
+ connectionString: process.env.DATABASE_URL!,
57
+ });
58
+ ```
59
+
60
+ ## Wallet Issues
61
+
62
+ ### "Wallet not found" or "Wallet creation failed"
63
+
64
+ **Problem:** Wallet operations fail.
65
+
66
+ **Solutions:**
67
+ 1. Ensure `userId` is provided and not empty:
68
+ ```typescript
69
+ await sdk.getOrCreateWallet({
70
+ userId: "user-123", // Must not be empty
71
+ password: "secure-password",
72
+ });
73
+ ```
74
+
75
+ 2. Check password is correct for existing wallets.
76
+
77
+ 3. Verify wallet manager is properly initialized.
78
+
79
+ ### "Wallet decryption failed"
80
+
81
+ **Problem:** Cannot decrypt wallet with provided password.
82
+
83
+ **Solutions:**
84
+ 1. Verify the password is correct.
85
+
86
+ 2. Check if wallet was created with a different password.
87
+
88
+ 3. Ensure wallet data hasn't been corrupted.
89
+
90
+ ## VDA Issues
91
+
92
+ ### "VDA not found"
93
+
94
+ **Problem:** Cannot find VDA by ID.
95
+
96
+ **Solutions:**
97
+ 1. Verify the VDA ID is correct.
98
+
99
+ 2. Check that the VDA exists in storage:
100
+ ```typescript
101
+ const vda = await sdk.getVDASDK().getVDA(vdaId);
102
+ if (!vda) {
103
+ console.log("VDA not found");
104
+ }
105
+ ```
106
+
107
+ 3. Ensure storage adapter is properly connected.
108
+
109
+ ### "VDA access denied"
110
+
111
+ **Problem:** Access denied when trying to access a VDA.
112
+
113
+ **Solutions:**
114
+ 1. Verify wallet owns the VDA:
115
+ ```typescript
116
+ const verification = await sdk.getVDASDK().verifyOwnership(
117
+ vdaId,
118
+ wallet.address,
119
+ ["view"]
120
+ );
121
+ ```
122
+
123
+ 2. Check if access pass exists and hasn't expired:
124
+ ```typescript
125
+ const accessPasses = await sdk.getVDASDK().listAccessPassesByOwner(wallet.address);
126
+ ```
127
+
128
+ 3. Verify access pass hasn't been revoked.
129
+
130
+ ### "Invalid VDA metadata"
131
+
132
+ **Problem:** VDA minting fails due to invalid metadata.
133
+
134
+ **Solutions:**
135
+ 1. Ensure at least one universal metadata key is provided:
136
+ - `address` (real estate)
137
+ - `legalDesc` (real estate)
138
+ - `patientId` (healthcare)
139
+ - `api14` (oil & gas)
140
+
141
+ 2. Verify `spoke` is a valid spoke type.
142
+
143
+ 3. Check that `assetType` is valid.
144
+
145
+ ## Document Retrieval Issues
146
+
147
+ ### "Document not found"
148
+
149
+ **Problem:** Cannot retrieve document from IPFS.
150
+
151
+ **Solutions:**
152
+ 1. Verify the CID is correct.
153
+
154
+ 2. Check that the document exists in Pinata:
155
+ ```typescript
156
+ const metadata = await sdk.getRetrievalSDK().getPinataClient().getFileMetadata(cid);
157
+ ```
158
+
159
+ 3. Ensure Pinata gateway is accessible.
160
+
161
+ ### "Access denied" to document
162
+
163
+ **Problem:** Cannot access document even though VDA exists.
164
+
165
+ **Solutions:**
166
+ 1. Verify wallet has access to the VDA:
167
+ ```typescript
168
+ const verification = await sdk.getRetrievalSDK().verifyAccess(
169
+ cid,
170
+ wallet.address,
171
+ ["view"]
172
+ );
173
+ ```
174
+
175
+ 2. Check that VDA has `ipfsCid` metadata set:
176
+ ```typescript
177
+ const vda = await sdk.getVDASDK().getVDA(vdaId);
178
+ console.log("IPFS CID:", vda.metadata.ipfsCid);
179
+ ```
180
+
181
+ 3. Provide `getVDAIdFromCID` function if VDA lookup fails:
182
+ ```typescript
183
+ retrieval: {
184
+ // ... config
185
+ getVDAIdFromCID: async (cid: string) => {
186
+ const vda = await storageAdapter.getVDAByCID(cid);
187
+ return vda?.id || null;
188
+ },
189
+ }
190
+ ```
191
+
192
+ ### "Encryption key required for decryption"
193
+
194
+ **Problem:** Document is encrypted but no encryption key provided.
195
+
196
+ **Solutions:**
197
+ 1. Provide encryption key in config:
198
+ ```typescript
199
+ retrieval: {
200
+ // ... config
201
+ getEncryptionKey: async (cid: string) => {
202
+ // Retrieve encryption key from secure storage
203
+ return await getKeyFromDatabase(cid);
204
+ },
205
+ }
206
+ ```
207
+
208
+ 2. Store encryption key when uploading:
209
+ ```typescript
210
+ const result = await sdk.getRetrievalSDK().uploadDocument(content, {
211
+ encrypt: true,
212
+ });
213
+
214
+ // Store encryption key securely
215
+ await storeEncryptionKey(result.cid, result.encryptionKey!);
216
+ ```
217
+
218
+ ### "VDA ID not found for CID"
219
+
220
+ **Problem:** Cannot resolve VDA ID from document CID.
221
+
222
+ **Solutions:**
223
+ 1. Ensure VDA has `ipfsCid` metadata:
224
+ ```typescript
225
+ const vda = await sdk.getVDASDK().mint({
226
+ // ... params
227
+ ipfsCid: documentCID, // Link VDA to document
228
+ });
229
+ ```
230
+
231
+ 2. Provide custom `getVDAIdFromCID` function:
232
+ ```typescript
233
+ retrieval: {
234
+ getVDAIdFromCID: async (cid: string) => {
235
+ // Query database or Pinata metadata
236
+ const vda = await db.query("SELECT id FROM vdas WHERE ipfs_cid = $1", [cid]);
237
+ return vda?.id || null;
238
+ },
239
+ }
240
+ ```
241
+
242
+ ## Payment Issues
243
+
244
+ ### "Payment verification failed"
245
+
246
+ **Problem:** Crypto payment verification fails.
247
+
248
+ **Solutions:**
249
+ 1. Verify transaction hash is correct.
250
+
251
+ 2. Check that transaction is confirmed on blockchain.
252
+
253
+ 3. Ensure facilitator wallet address is correct.
254
+
255
+ 4. Verify amount and currency match.
256
+
257
+ ### "Payment not found"
258
+
259
+ **Problem:** Cannot find payment record.
260
+
261
+ **Solutions:**
262
+ 1. Verify `resourceId` is correct.
263
+
264
+ 2. Check that payment was recorded:
265
+ ```typescript
266
+ const payment = await sdk.getPaymentSDK().getPayment(resourceId);
267
+ ```
268
+
269
+ 3. Ensure storage adapter is properly connected.
270
+
271
+ ## Network and Performance Issues
272
+
273
+ ### Slow document retrieval
274
+
275
+ **Problem:** Document retrieval is slow.
276
+
277
+ **Solutions:**
278
+ 1. Use Redis caching adapter:
279
+ ```typescript
280
+ import { RedisStorageAdapter } from "@hauska-sdk/adapters-storage-redis";
281
+
282
+ const redisAdapter = new RedisStorageAdapter({
283
+ redis: process.env.REDIS_URL!,
284
+ primaryStorageAdapter: postgresAdapter,
285
+ });
286
+ ```
287
+
288
+ 2. Check Pinata gateway performance.
289
+
290
+ 3. Consider using a CDN for frequently accessed documents.
291
+
292
+ ### Connection timeouts
293
+
294
+ **Problem:** Database or IPFS connection timeouts.
295
+
296
+ **Solutions:**
297
+ 1. Check database connection string.
298
+
299
+ 2. Verify network connectivity to Pinata.
300
+
301
+ 3. Increase timeout settings if needed.
302
+
303
+ 4. Check firewall rules.
304
+
305
+ ## Error Handling
306
+
307
+ ### Understanding Error Types
308
+
309
+ All SDK errors extend `SDKError` and include:
310
+ - `code` - Error code for programmatic handling
311
+ - `context` - Additional context about the error
312
+ - `statusCode` - HTTP status code (if applicable)
313
+ - `retryable` - Whether the error is retryable
314
+
315
+ ### Common Error Codes
316
+
317
+ - `PAYMENT_VERIFICATION_FAILED` - Payment verification failed
318
+ - `VDA_NOT_FOUND` - VDA not found
319
+ - `VDA_ACCESS_DENIED` - Access denied to VDA
320
+ - `RETRIEVAL_DOCUMENT_NOT_FOUND` - Document not found
321
+ - `RETRIEVAL_ACCESS_DENIED` - Access denied to document
322
+ - `WALLET_NOT_FOUND` - Wallet not found
323
+ - `CONFIG_MISSING_REQUIRED` - Required configuration missing
324
+
325
+ ### Error Handling Best Practices
326
+
327
+ ```typescript
328
+ import { isSDKError, isRetryableError } from "@hauska-sdk/core";
329
+
330
+ try {
331
+ await sdk.purchaseAndMintVDA({ /* ... */ });
332
+ } catch (error) {
333
+ if (isSDKError(error)) {
334
+ console.error(`Error code: ${error.code}`);
335
+ console.error(`Context:`, error.context);
336
+
337
+ if (isRetryableError(error)) {
338
+ // Implement retry logic
339
+ await retryOperation();
340
+ }
341
+ } else {
342
+ // Handle unexpected errors
343
+ console.error("Unexpected error:", error);
344
+ }
345
+ }
346
+ ```
347
+
348
+ ## Debugging
349
+
350
+ ### Enable Logging
351
+
352
+ ```typescript
353
+ const sdk = new CNSSDK({
354
+ // ... config
355
+ logHook: (level, message, data) => {
356
+ console.log(`[${level}] ${message}`, data);
357
+ },
358
+ });
359
+ ```
360
+
361
+ ### Enable Metrics
362
+
363
+ ```typescript
364
+ const sdk = new CNSSDK({
365
+ // ... config
366
+ metricsHook: (event, data) => {
367
+ console.log(`[METRICS] ${event}`, data);
368
+ },
369
+ });
370
+ ```
371
+
372
+ ### Check SDK State
373
+
374
+ ```typescript
375
+ // Verify SDK is initialized
376
+ console.log("Payment SDK:", sdk.getPaymentSDK());
377
+ console.log("VDA SDK:", sdk.getVDASDK());
378
+ console.log("Retrieval SDK:", sdk.getRetrievalSDK());
379
+ console.log("Wallet Manager:", sdk.getWalletManager());
380
+ ```
381
+
382
+ ## Getting Help
383
+
384
+ If you're still experiencing issues:
385
+
386
+ 1. Check the [API Reference](./api-reference.md) for detailed API documentation
387
+ 2. Review the [Examples](./examples.md) for usage patterns
388
+ 3. Open an issue on GitHub with:
389
+ - Error message and stack trace
390
+ - SDK configuration (without secrets)
391
+ - Steps to reproduce
392
+ - Expected vs actual behavior
393
+
394
+ ## Related Documentation
395
+
396
+ - [Getting Started Guide](./getting-started.md)
397
+ - [API Reference](./api-reference.md)
398
+ - [Examples](./examples.md)
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@hauska-sdk/core",
3
+ "version": "0.1.0",
4
+ "description": "CNS Protocol Core SDK - Unified SDK for Payment, VDA, and Document Retrieval",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md",
18
+ "CHANGELOG.md",
19
+ "docs"
20
+ ],
21
+ "scripts": {
22
+ "build": "tsc",
23
+ "clean": "rimraf dist",
24
+ "test": "vitest run",
25
+ "test:watch": "vitest",
26
+ "test:coverage": "vitest run --coverage",
27
+ "type-check": "tsc --noEmit",
28
+ "prepublishOnly": "npm run build"
29
+ },
30
+ "dependencies": {
31
+ "@hauska-sdk/payment": "^0.1.0",
32
+ "@hauska-sdk/retrieval": "^0.1.0",
33
+ "@hauska-sdk/vda": "^0.1.0",
34
+ "@hauska-sdk/wallet": "^0.1.0"
35
+ },
36
+ "devDependencies": {
37
+ "@hauska-sdk/adapters-storage-mock": "^0.1.0",
38
+ "rimraf": "^5.0.5",
39
+ "typescript": "^5.3.3",
40
+ "vitest": "^1.6.1"
41
+ },
42
+ "keywords": [
43
+ "cns-protocol",
44
+ "sdk",
45
+ "payment",
46
+ "vda",
47
+ "ipfs",
48
+ "blockchain",
49
+ "ethereum",
50
+ "base",
51
+ "verified-digital-assets",
52
+ "document-retrieval",
53
+ "access-control"
54
+ ],
55
+ "author": "Hauska SDK Team",
56
+ "license": "MIT",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "https://github.com/hauska-sdk/hauska-sdk.git",
60
+ "directory": "packages/core"
61
+ },
62
+ "bugs": {
63
+ "url": "https://github.com/hauska-sdk/hauska-sdk/issues"
64
+ },
65
+ "homepage": "https://github.com/hauska-sdk/hauska-sdk#readme",
66
+ "engines": {
67
+ "node": ">=18.0.0",
68
+ "npm": ">=9.0.0"
69
+ },
70
+ "publishConfig": {
71
+ "access": "public",
72
+ "registry": "https://registry.npmjs.org"
73
+ }
74
+ }