@opendatalabs/vana-sdk 0.1.0-alpha.f2de4f7 → 0.1.0-alpha.f35bb9c
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/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +33 -1
- package/dist/browser.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +30 -1
- package/dist/chains/index.js.map +1 -1
- package/dist/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +99 -0
- package/dist/config/chains.js.map +1 -1
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +66 -10
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/controllers/data.cjs +173 -141
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +213 -175
- package/dist/controllers/data.js +173 -141
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +185 -191
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +29 -73
- package/dist/controllers/permissions.js +185 -191
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +27 -28
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +23 -21
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +47 -40
- package/dist/controllers/schemas.js +23 -21
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +17 -15
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +46 -38
- package/dist/controllers/server.js +17 -15
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/apiClient.cjs +53 -3
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +132 -7
- package/dist/core/apiClient.js +53 -3
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/generics.cjs +30 -3
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +95 -6
- package/dist/core/generics.js +30 -3
- package/dist/core/generics.js.map +1 -1
- package/dist/core.cjs +29 -12
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +2 -1
- package/dist/core.js +29 -12
- package/dist/core.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +3 -3
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +8 -9
- package/dist/index.node.js +2 -2
- package/dist/index.node.js.map +1 -1
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -1
- package/dist/node.js.map +1 -1
- package/dist/platform/browser.cjs +160 -2
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +232 -12
- package/dist/platform/browser.js +160 -2
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +283 -90
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +69 -6
- package/dist/platform/node.js +163 -2
- package/dist/platform/node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +214 -0
- package/dist/server/relayerHandler.cjs.map +1 -0
- package/dist/server/relayerHandler.d.ts +36 -0
- package/dist/server/relayerHandler.js +190 -0
- package/dist/server/relayerHandler.js.map +1 -0
- package/dist/storage/manager.cjs +108 -25
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +119 -25
- package/dist/storage/manager.js +108 -25
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +86 -15
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +109 -20
- package/dist/storage/providers/callback-storage.js +86 -15
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +12 -14
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/tests/factories/mockFactory.d.ts +2 -2
- package/dist/tests/relayer-integration.test.d.ts +1 -0
- package/dist/tests/relayer-unified.test.d.ts +1 -0
- package/dist/tests/server-relayer-handler.test.d.ts +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +39 -11
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +74 -7
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +46 -191
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +71 -7
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +3 -2
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +4 -6
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +80 -9
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +27 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +132 -15
- package/dist/types/operations.js.map +1 -1
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +15 -20
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +131 -14
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +262 -35
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +9 -21
- package/dist/types/storage.js.map +1 -1
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +10 -20
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +95 -16
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +93 -12
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +32 -7
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/signatureCache.cjs +8 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +49 -8
- package/dist/utils/signatureCache.js +8 -2
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +12 -12
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +39 -3
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +7 -0
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +22 -4
- package/dist/utils/urlResolver.js +7 -0
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs +2 -1
- package/dist/utils/wallet.cjs.map +1 -1
- package/dist/utils/wallet.d.ts +78 -16
- package/dist/utils/wallet.js +2 -1
- package/dist/utils/wallet.js.map +1 -1
- package/package.json +1 -1
- package/dist/server/handler.cjs +0 -101
- package/dist/server/handler.cjs.map +0 -1
- package/dist/server/handler.d.ts +0 -87
- package/dist/server/handler.js +0 -77
- package/dist/server/handler.js.map +0 -1
- /package/dist/tests/{server-handler.test.d.ts → permissions-revoke-relayer.test.d.ts} +0 -0
|
@@ -84,9 +84,8 @@ class DataController extends import_base.BaseController {
|
|
|
84
84
|
} catch (error) {
|
|
85
85
|
isValid = false;
|
|
86
86
|
if (error instanceof Error) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
validationErrors = errorDetails;
|
|
87
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
88
|
+
validationErrors = error.errors;
|
|
90
89
|
} else {
|
|
91
90
|
validationErrors = [error.message];
|
|
92
91
|
}
|
|
@@ -125,27 +124,26 @@ class DataController extends import_base.BaseController {
|
|
|
125
124
|
);
|
|
126
125
|
}
|
|
127
126
|
let result;
|
|
128
|
-
if (this.context.
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
if (this.context.relayer) {
|
|
128
|
+
const request = {
|
|
129
|
+
type: "direct",
|
|
130
|
+
operation: "submitFileAdditionComplete",
|
|
131
|
+
params: {
|
|
131
132
|
url: uploadResult.url,
|
|
132
133
|
userAddress,
|
|
133
134
|
permissions: encryptedPermissions,
|
|
134
135
|
schemaId: schemaId ?? 0,
|
|
135
136
|
ownerAddress: owner
|
|
136
137
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
throw new Error(
|
|
142
|
-
"The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
|
|
143
|
-
);
|
|
138
|
+
};
|
|
139
|
+
const response = await this.context.relayer(request);
|
|
140
|
+
if (response.type === "error") {
|
|
141
|
+
throw new Error(response.error);
|
|
144
142
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
144
|
+
throw new Error("Invalid response from relayer");
|
|
145
|
+
}
|
|
146
|
+
result = response.result;
|
|
149
147
|
} else {
|
|
150
148
|
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
151
149
|
uploadResult.url,
|
|
@@ -260,35 +258,33 @@ class DataController extends import_base.BaseController {
|
|
|
260
258
|
}
|
|
261
259
|
}
|
|
262
260
|
/**
|
|
263
|
-
* Decrypts a file
|
|
261
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
264
262
|
*
|
|
265
263
|
* @remarks
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
264
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
265
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
266
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
267
|
+
*
|
|
268
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
269
|
+
* @param options - Decryption options
|
|
270
|
+
* @param options.seed - Custom encryption seed.
|
|
271
|
+
* Defaults to standard Vana seed.
|
|
272
|
+
*
|
|
273
|
+
* @returns Decrypted content as Blob
|
|
274
|
+
*
|
|
275
|
+
* @throws {Error} No wallet connected.
|
|
276
|
+
* Connect wallet before decrypting.
|
|
277
|
+
* @throws {Error} Network error accessing file.
|
|
278
|
+
* Check CORS settings or server availability.
|
|
279
|
+
* @throws {Error} File not found (404).
|
|
280
|
+
* File no longer available at stored URL.
|
|
281
|
+
* @throws {Error} Access denied (403).
|
|
282
|
+
* No permission to access file.
|
|
283
|
+
* @throws {Error} Invalid file format.
|
|
284
|
+
* File not encrypted with Vana protocol.
|
|
285
|
+
* @throws {Error} Wrong encryption key.
|
|
286
|
+
* Verify seed matches upload or use default.
|
|
270
287
|
*
|
|
271
|
-
* The method automatically:
|
|
272
|
-
* - Generates the decryption key from the user's wallet signature
|
|
273
|
-
* - Determines the appropriate fetch method based on the file URL protocol
|
|
274
|
-
* - Fetches the encrypted content from IPFS or standard HTTP URLs
|
|
275
|
-
* - Decrypts the content using the generated key
|
|
276
|
-
*
|
|
277
|
-
* For IPFS URLs, the method uses gateway fallback for improved reliability. For
|
|
278
|
-
* standard HTTP URLs, it uses a simple fetch. If you need custom authentication
|
|
279
|
-
* headers or specific gateway configurations, use the low-level primitives directly.
|
|
280
|
-
*
|
|
281
|
-
* @param file - The user file to decrypt (typically from getUserFiles)
|
|
282
|
-
* @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
|
|
283
|
-
* @returns Promise resolving to the decrypted file content as a Blob
|
|
284
|
-
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
285
|
-
* @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
|
|
286
|
-
* @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
|
|
287
|
-
* @throws {Error} "Access denied" - When file returns 403 (no permission)
|
|
288
|
-
* @throws {Error} "File is empty or could not be retrieved" - When file has no content
|
|
289
|
-
* @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
|
|
290
|
-
* @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
|
|
291
|
-
* @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
|
|
292
288
|
* @example
|
|
293
289
|
* ```typescript
|
|
294
290
|
* // Basic file decryption
|
|
@@ -404,35 +400,38 @@ class DataController extends import_base.BaseController {
|
|
|
404
400
|
}
|
|
405
401
|
}
|
|
406
402
|
/**
|
|
407
|
-
* Retrieves all
|
|
403
|
+
* Retrieves all files owned by a specific user address.
|
|
408
404
|
*
|
|
409
405
|
* @remarks
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* @
|
|
421
|
-
*
|
|
422
|
-
* @
|
|
423
|
-
*
|
|
424
|
-
* @throws {Error}
|
|
425
|
-
*
|
|
426
|
-
* @throws {Error}
|
|
406
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
407
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
408
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
409
|
+
* Enriches results with DLP proof data when available.
|
|
410
|
+
*
|
|
411
|
+
* @param params - Query configuration
|
|
412
|
+
* @param params.owner - Wallet address of the file owner
|
|
413
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
414
|
+
* Defaults to context configuration.
|
|
415
|
+
*
|
|
416
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
417
|
+
*
|
|
418
|
+
* @throws {Error} Subgraph URL not configured.
|
|
419
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
420
|
+
* @throws {Error} Subgraph request failed.
|
|
421
|
+
* Check network connectivity and subgraph availability.
|
|
422
|
+
* @throws {Error} Subgraph returned errors.
|
|
423
|
+
* Review query parameters and subgraph logs.
|
|
424
|
+
*
|
|
427
425
|
* @example
|
|
428
426
|
* ```typescript
|
|
429
|
-
* // Query files for a specific user
|
|
430
427
|
* const files = await vana.data.getUserFiles({
|
|
431
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
428
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
432
429
|
* });
|
|
433
430
|
*
|
|
434
431
|
* files.forEach(file => {
|
|
435
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
432
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
433
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
434
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
436
435
|
* });
|
|
437
436
|
* ```
|
|
438
437
|
*/
|
|
@@ -1232,18 +1231,26 @@ class DataController extends import_base.BaseController {
|
|
|
1232
1231
|
}
|
|
1233
1232
|
}
|
|
1234
1233
|
/**
|
|
1235
|
-
*
|
|
1234
|
+
* Retrieves total file count from Data Registry.
|
|
1235
|
+
*
|
|
1236
|
+
* @remarks
|
|
1237
|
+
* Queries blockchain for complete file count across all users.
|
|
1238
|
+
* Useful for pagination and network statistics.
|
|
1239
|
+
*
|
|
1240
|
+
* @returns Total number of registered files
|
|
1241
|
+
*
|
|
1242
|
+
* @throws {Error} Chain ID not available.
|
|
1243
|
+
* Ensure network connection.
|
|
1244
|
+
* @throws {Error} Contract read failed.
|
|
1245
|
+
* Check RPC availability.
|
|
1236
1246
|
*
|
|
1237
|
-
* @returns Promise resolving to the total file count
|
|
1238
1247
|
* @example
|
|
1239
1248
|
* ```typescript
|
|
1240
|
-
* const
|
|
1241
|
-
* console.log(`Total files
|
|
1249
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1250
|
+
* console.log(`Total files: ${total}`);
|
|
1242
1251
|
*
|
|
1243
|
-
* //
|
|
1244
|
-
* const
|
|
1245
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1246
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1252
|
+
* // Calculate pagination
|
|
1253
|
+
* const pages = Math.ceil(total / 20);
|
|
1247
1254
|
* ```
|
|
1248
1255
|
*/
|
|
1249
1256
|
async getTotalFilesCount() {
|
|
@@ -1270,32 +1277,32 @@ class DataController extends import_base.BaseController {
|
|
|
1270
1277
|
}
|
|
1271
1278
|
}
|
|
1272
1279
|
/**
|
|
1273
|
-
* Retrieves
|
|
1280
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1281
|
+
*
|
|
1282
|
+
* @remarks
|
|
1283
|
+
* Queries DataRegistry contract directly for file details.
|
|
1284
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1285
|
+
* cross-user file discovery and verification.
|
|
1286
|
+
*
|
|
1287
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1288
|
+
*
|
|
1289
|
+
* @returns UserFile object with metadata
|
|
1290
|
+
*
|
|
1291
|
+
* @throws {Error} Chain ID not available.
|
|
1292
|
+
* Ensure proper network connection.
|
|
1293
|
+
* @throws {Error} File not found.
|
|
1294
|
+
* Verify file ID exists on-chain.
|
|
1295
|
+
* @throws {Error} Contract call failed.
|
|
1296
|
+
* Check network and RPC availability.
|
|
1274
1297
|
*
|
|
1275
|
-
* @param fileId - The file ID to look up
|
|
1276
|
-
* @returns Promise resolving to UserFile object
|
|
1277
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1278
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1279
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1280
1298
|
* @example
|
|
1281
1299
|
* ```typescript
|
|
1282
|
-
*
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1286
|
-
*
|
|
1287
|
-
* owner: file.ownerAddress,
|
|
1288
|
-
* addedAt: file.addedAtBlock
|
|
1289
|
-
* });
|
|
1290
|
-
* } catch (error) {
|
|
1291
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1292
|
-
* }
|
|
1300
|
+
* const file = await vana.data.getFileById(123);
|
|
1301
|
+
* console.log(`File ${file.id}:`);
|
|
1302
|
+
* console.log(` URL: ${file.url}`);
|
|
1303
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1304
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1293
1305
|
* ```
|
|
1294
|
-
*
|
|
1295
|
-
* This method queries the DataRegistry contract directly
|
|
1296
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1297
|
-
* This is useful for file lookup functionality where users can search
|
|
1298
|
-
* for specific files by ID.
|
|
1299
1306
|
*/
|
|
1300
1307
|
async getFileById(fileId) {
|
|
1301
1308
|
try {
|
|
@@ -1610,31 +1617,35 @@ class DataController extends import_base.BaseController {
|
|
|
1610
1617
|
}
|
|
1611
1618
|
}
|
|
1612
1619
|
/**
|
|
1613
|
-
*
|
|
1620
|
+
* Registers a data refiner for processing templates.
|
|
1614
1621
|
*
|
|
1615
1622
|
* @remarks
|
|
1616
|
-
* Refiners
|
|
1617
|
-
*
|
|
1618
|
-
*
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
1621
|
-
* @param params - Refiner
|
|
1622
|
-
* @param params.
|
|
1623
|
-
*
|
|
1624
|
-
* @param params.
|
|
1625
|
-
*
|
|
1626
|
-
* @returns
|
|
1627
|
-
*
|
|
1628
|
-
* @throws {Error}
|
|
1623
|
+
* Refiners define data transformation rules for DLPs.
|
|
1624
|
+
* Associates schema, instructions, and processing logic.
|
|
1625
|
+
*
|
|
1626
|
+
* @param params - Refiner configuration
|
|
1627
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1628
|
+
* @param params.name - Refiner display name
|
|
1629
|
+
* @param params.schemaId - Output schema ID.
|
|
1630
|
+
* Obtain via `vana.schemas.list()`.
|
|
1631
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1632
|
+
*
|
|
1633
|
+
* @returns Refiner ID and transaction hash
|
|
1634
|
+
*
|
|
1635
|
+
* @throws {Error} Chain ID not available.
|
|
1636
|
+
* Ensure network connection.
|
|
1637
|
+
* @throws {Error} Transaction failed.
|
|
1638
|
+
* Check wallet balance and network status.
|
|
1639
|
+
*
|
|
1629
1640
|
* @example
|
|
1630
1641
|
* ```typescript
|
|
1631
1642
|
* const result = await vana.data.addRefiner({
|
|
1632
1643
|
* dlpId: 1,
|
|
1633
|
-
* name: "
|
|
1644
|
+
* name: "Sentiment Analyzer",
|
|
1634
1645
|
* schemaId: 42,
|
|
1635
1646
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1636
1647
|
* });
|
|
1637
|
-
* console.log(`
|
|
1648
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1638
1649
|
* ```
|
|
1639
1650
|
*/
|
|
1640
1651
|
async addRefiner(params) {
|
|
@@ -1692,26 +1703,29 @@ class DataController extends import_base.BaseController {
|
|
|
1692
1703
|
}
|
|
1693
1704
|
}
|
|
1694
1705
|
/**
|
|
1695
|
-
* Retrieves
|
|
1706
|
+
* Retrieves refiner configuration by ID.
|
|
1696
1707
|
*
|
|
1697
1708
|
* @remarks
|
|
1698
|
-
* Queries
|
|
1699
|
-
*
|
|
1709
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1710
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1711
|
+
*
|
|
1712
|
+
* @param refinerId - Numeric refiner ID
|
|
1713
|
+
*
|
|
1714
|
+
* @returns Refiner configuration object
|
|
1715
|
+
*
|
|
1716
|
+
* @throws {Error} Chain ID not available.
|
|
1717
|
+
* Ensure network connection.
|
|
1718
|
+
* @throws {Error} Refiner not found.
|
|
1719
|
+
* Verify refiner ID exists.
|
|
1720
|
+
* @throws {Error} Contract read failed.
|
|
1721
|
+
* Check network and RPC status.
|
|
1700
1722
|
*
|
|
1701
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1702
|
-
* @returns Promise resolving to the refiner information object
|
|
1703
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1704
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1705
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1706
1723
|
* @example
|
|
1707
1724
|
* ```typescript
|
|
1708
1725
|
* const refiner = await vana.data.getRefiner(1);
|
|
1709
|
-
* console.log({
|
|
1710
|
-
*
|
|
1711
|
-
*
|
|
1712
|
-
* schema: refiner.schemaId,
|
|
1713
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1714
|
-
* });
|
|
1726
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1727
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1728
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1715
1729
|
* ```
|
|
1716
1730
|
*/
|
|
1717
1731
|
async getRefiner(refinerId) {
|
|
@@ -1752,21 +1766,27 @@ class DataController extends import_base.BaseController {
|
|
|
1752
1766
|
}
|
|
1753
1767
|
}
|
|
1754
1768
|
/**
|
|
1755
|
-
* Validates
|
|
1769
|
+
* Validates schema ID existence.
|
|
1756
1770
|
*
|
|
1757
1771
|
* @remarks
|
|
1758
|
-
*
|
|
1759
|
-
*
|
|
1772
|
+
* Verifies schema registration in DataRegistry.
|
|
1773
|
+
* Check before using schemas for uploads.
|
|
1774
|
+
*
|
|
1775
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1776
|
+
*
|
|
1777
|
+
* @returns True if schema exists, false otherwise
|
|
1778
|
+
*
|
|
1779
|
+
* @throws {Error} Chain ID not available.
|
|
1780
|
+
* Ensure network connection.
|
|
1781
|
+
* @throws {Error} Contract read failed.
|
|
1782
|
+
* Check RPC availability.
|
|
1760
1783
|
*
|
|
1761
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1762
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1763
1784
|
* @example
|
|
1764
1785
|
* ```typescript
|
|
1765
|
-
* const
|
|
1766
|
-
* if (
|
|
1767
|
-
*
|
|
1768
|
-
*
|
|
1769
|
-
* console.log('Schema 42 does not exist');
|
|
1786
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1787
|
+
* if (valid) {
|
|
1788
|
+
* // Safe to use schema 42
|
|
1789
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1770
1790
|
* }
|
|
1771
1791
|
* ```
|
|
1772
1792
|
*/
|
|
@@ -1929,12 +1949,24 @@ class DataController extends import_base.BaseController {
|
|
|
1929
1949
|
};
|
|
1930
1950
|
})
|
|
1931
1951
|
);
|
|
1932
|
-
if (this.context.
|
|
1933
|
-
const
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1952
|
+
if (this.context.relayer) {
|
|
1953
|
+
const request = {
|
|
1954
|
+
type: "direct",
|
|
1955
|
+
operation: "submitFileAdditionWithPermissions",
|
|
1956
|
+
params: {
|
|
1957
|
+
url: uploadResult.url,
|
|
1958
|
+
userAddress,
|
|
1959
|
+
permissions: encryptedPermissions
|
|
1960
|
+
}
|
|
1961
|
+
};
|
|
1962
|
+
const response = await this.context.relayer(request);
|
|
1963
|
+
if (response.type === "error") {
|
|
1964
|
+
throw new Error(response.error);
|
|
1965
|
+
}
|
|
1966
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
1967
|
+
throw new Error("Invalid response from relayer");
|
|
1968
|
+
}
|
|
1969
|
+
const result = response.result;
|
|
1938
1970
|
return {
|
|
1939
1971
|
fileId: result.fileId,
|
|
1940
1972
|
url: uploadResult.url,
|
|
@@ -2023,7 +2055,7 @@ class DataController extends import_base.BaseController {
|
|
|
2023
2055
|
);
|
|
2024
2056
|
}
|
|
2025
2057
|
}
|
|
2026
|
-
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
2058
|
+
const finalFilename = filename ?? encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2027
2059
|
const uploadResult = await this.context.storageManager.upload(
|
|
2028
2060
|
finalBlob,
|
|
2029
2061
|
finalFilename,
|