@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
package/dist/controllers/data.js
CHANGED
|
@@ -68,9 +68,8 @@ class DataController extends BaseController {
|
|
|
68
68
|
} catch (error) {
|
|
69
69
|
isValid = false;
|
|
70
70
|
if (error instanceof Error) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
validationErrors = errorDetails;
|
|
71
|
+
if (typeof error === "object" && "errors" in error && Array.isArray(error.errors)) {
|
|
72
|
+
validationErrors = error.errors;
|
|
74
73
|
} else {
|
|
75
74
|
validationErrors = [error.message];
|
|
76
75
|
}
|
|
@@ -109,27 +108,26 @@ class DataController extends BaseController {
|
|
|
109
108
|
);
|
|
110
109
|
}
|
|
111
110
|
let result;
|
|
112
|
-
if (this.context.
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
if (this.context.relayer) {
|
|
112
|
+
const request = {
|
|
113
|
+
type: "direct",
|
|
114
|
+
operation: "submitFileAdditionComplete",
|
|
115
|
+
params: {
|
|
115
116
|
url: uploadResult.url,
|
|
116
117
|
userAddress,
|
|
117
118
|
permissions: encryptedPermissions,
|
|
118
119
|
schemaId: schemaId ?? 0,
|
|
119
120
|
ownerAddress: owner
|
|
120
121
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
throw new Error(
|
|
126
|
-
"The configured relay callback does not support schemas or permissions. Please update your relay server implementation to provide the `submitFileAdditionComplete` callback."
|
|
127
|
-
);
|
|
122
|
+
};
|
|
123
|
+
const response = await this.context.relayer(request);
|
|
124
|
+
if (response.type === "error") {
|
|
125
|
+
throw new Error(response.error);
|
|
128
126
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
127
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
128
|
+
throw new Error("Invalid response from relayer");
|
|
129
|
+
}
|
|
130
|
+
result = response.result;
|
|
133
131
|
} else {
|
|
134
132
|
const txResult = await this.addFileWithEncryptedPermissionsAndSchema(
|
|
135
133
|
uploadResult.url,
|
|
@@ -244,35 +242,33 @@ class DataController extends BaseController {
|
|
|
244
242
|
}
|
|
245
243
|
}
|
|
246
244
|
/**
|
|
247
|
-
* Decrypts a file
|
|
245
|
+
* Decrypts a file using wallet-derived decryption key.
|
|
248
246
|
*
|
|
249
247
|
* @remarks
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
248
|
+
* Counterpart to `upload()` for decrypting user files. Automatically
|
|
249
|
+
* generates decryption key from wallet, fetches encrypted content,
|
|
250
|
+
* and decrypts. Supports IPFS (with gateway fallback) and HTTP URLs.
|
|
251
|
+
*
|
|
252
|
+
* @param file - UserFile object from `getUserFiles()`
|
|
253
|
+
* @param options - Decryption options
|
|
254
|
+
* @param options.seed - Custom encryption seed.
|
|
255
|
+
* Defaults to standard Vana seed.
|
|
256
|
+
*
|
|
257
|
+
* @returns Decrypted content as Blob
|
|
258
|
+
*
|
|
259
|
+
* @throws {Error} No wallet connected.
|
|
260
|
+
* Connect wallet before decrypting.
|
|
261
|
+
* @throws {Error} Network error accessing file.
|
|
262
|
+
* Check CORS settings or server availability.
|
|
263
|
+
* @throws {Error} File not found (404).
|
|
264
|
+
* File no longer available at stored URL.
|
|
265
|
+
* @throws {Error} Access denied (403).
|
|
266
|
+
* No permission to access file.
|
|
267
|
+
* @throws {Error} Invalid file format.
|
|
268
|
+
* File not encrypted with Vana protocol.
|
|
269
|
+
* @throws {Error} Wrong encryption key.
|
|
270
|
+
* Verify seed matches upload or use default.
|
|
254
271
|
*
|
|
255
|
-
* The method automatically:
|
|
256
|
-
* - Generates the decryption key from the user's wallet signature
|
|
257
|
-
* - Determines the appropriate fetch method based on the file URL protocol
|
|
258
|
-
* - Fetches the encrypted content from IPFS or standard HTTP URLs
|
|
259
|
-
* - Decrypts the content using the generated key
|
|
260
|
-
*
|
|
261
|
-
* For IPFS URLs, the method uses gateway fallback for improved reliability. For
|
|
262
|
-
* standard HTTP URLs, it uses a simple fetch. If you need custom authentication
|
|
263
|
-
* headers or specific gateway configurations, use the low-level primitives directly.
|
|
264
|
-
*
|
|
265
|
-
* @param file - The user file to decrypt (typically from getUserFiles)
|
|
266
|
-
* @param encryptionSeed - Optional custom encryption seed (defaults to Vana standard)
|
|
267
|
-
* @returns Promise resolving to the decrypted file content as a Blob
|
|
268
|
-
* @throws {Error} "No addresses available in wallet client" - When wallet is not connected
|
|
269
|
-
* @throws {Error} "Network error: Cannot access the file URL" - When file URL is inaccessible (CORS, server down)
|
|
270
|
-
* @throws {Error} "File not found: The encrypted file is no longer available" - When file returns 404
|
|
271
|
-
* @throws {Error} "Access denied" - When file returns 403 (no permission)
|
|
272
|
-
* @throws {Error} "File is empty or could not be retrieved" - When file has no content
|
|
273
|
-
* @throws {Error} "Invalid file format: This file doesn't appear to be encrypted with the Vana protocol" - When file is not properly encrypted
|
|
274
|
-
* @throws {Error} "Wrong encryption key" - When decryption fails due to incorrect key/seed
|
|
275
|
-
* @throws {Error} "Failed to decrypt file: {error}" - General decryption failures
|
|
276
272
|
* @example
|
|
277
273
|
* ```typescript
|
|
278
274
|
* // Basic file decryption
|
|
@@ -388,35 +384,38 @@ class DataController extends BaseController {
|
|
|
388
384
|
}
|
|
389
385
|
}
|
|
390
386
|
/**
|
|
391
|
-
* Retrieves all
|
|
387
|
+
* Retrieves all files owned by a specific user address.
|
|
392
388
|
*
|
|
393
389
|
* @remarks
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* @
|
|
405
|
-
*
|
|
406
|
-
* @
|
|
407
|
-
*
|
|
408
|
-
* @throws {Error}
|
|
409
|
-
*
|
|
410
|
-
* @throws {Error}
|
|
390
|
+
* Queries the Vana subgraph for files owned by the specified address.
|
|
391
|
+
* Automatically deduplicates by file ID, keeping the latest version
|
|
392
|
+
* when duplicates exist from re-indexing or chain reorganizations.
|
|
393
|
+
* Enriches results with DLP proof data when available.
|
|
394
|
+
*
|
|
395
|
+
* @param params - Query configuration
|
|
396
|
+
* @param params.owner - Wallet address of the file owner
|
|
397
|
+
* @param params.subgraphUrl - Subgraph endpoint override.
|
|
398
|
+
* Defaults to context configuration.
|
|
399
|
+
*
|
|
400
|
+
* @returns Array of UserFile objects sorted by timestamp (newest first)
|
|
401
|
+
*
|
|
402
|
+
* @throws {Error} Subgraph URL not configured.
|
|
403
|
+
* Provide `subgraphUrl` parameter or configure in Vana constructor.
|
|
404
|
+
* @throws {Error} Subgraph request failed.
|
|
405
|
+
* Check network connectivity and subgraph availability.
|
|
406
|
+
* @throws {Error} Subgraph returned errors.
|
|
407
|
+
* Review query parameters and subgraph logs.
|
|
408
|
+
*
|
|
411
409
|
* @example
|
|
412
410
|
* ```typescript
|
|
413
|
-
* // Query files for a specific user
|
|
414
411
|
* const files = await vana.data.getUserFiles({
|
|
415
|
-
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
412
|
+
* owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
416
413
|
* });
|
|
417
414
|
*
|
|
418
415
|
* files.forEach(file => {
|
|
419
|
-
* console.log(`File ${file.id}: ${file.url}
|
|
416
|
+
* console.log(`File ${file.id}: ${file.url}`);
|
|
417
|
+
* console.log(` Schema: ${file.schemaId}`);
|
|
418
|
+
* console.log(` DLPs: ${file.dlpIds?.join(", ") || "none"}`);
|
|
420
419
|
* });
|
|
421
420
|
* ```
|
|
422
421
|
*/
|
|
@@ -1216,18 +1215,26 @@ class DataController extends BaseController {
|
|
|
1216
1215
|
}
|
|
1217
1216
|
}
|
|
1218
1217
|
/**
|
|
1219
|
-
*
|
|
1218
|
+
* Retrieves total file count from Data Registry.
|
|
1219
|
+
*
|
|
1220
|
+
* @remarks
|
|
1221
|
+
* Queries blockchain for complete file count across all users.
|
|
1222
|
+
* Useful for pagination and network statistics.
|
|
1223
|
+
*
|
|
1224
|
+
* @returns Total number of registered files
|
|
1225
|
+
*
|
|
1226
|
+
* @throws {Error} Chain ID not available.
|
|
1227
|
+
* Ensure network connection.
|
|
1228
|
+
* @throws {Error} Contract read failed.
|
|
1229
|
+
* Check RPC availability.
|
|
1220
1230
|
*
|
|
1221
|
-
* @returns Promise resolving to the total file count
|
|
1222
1231
|
* @example
|
|
1223
1232
|
* ```typescript
|
|
1224
|
-
* const
|
|
1225
|
-
* console.log(`Total files
|
|
1233
|
+
* const total = await vana.data.getTotalFilesCount();
|
|
1234
|
+
* console.log(`Total files: ${total}`);
|
|
1226
1235
|
*
|
|
1227
|
-
* //
|
|
1228
|
-
* const
|
|
1229
|
-
* const totalPages = Math.ceil(totalFiles / filesPerPage);
|
|
1230
|
-
* console.log(`Total pages: ${totalPages}`);
|
|
1236
|
+
* // Calculate pagination
|
|
1237
|
+
* const pages = Math.ceil(total / 20);
|
|
1231
1238
|
* ```
|
|
1232
1239
|
*/
|
|
1233
1240
|
async getTotalFilesCount() {
|
|
@@ -1254,32 +1261,32 @@ class DataController extends BaseController {
|
|
|
1254
1261
|
}
|
|
1255
1262
|
}
|
|
1256
1263
|
/**
|
|
1257
|
-
* Retrieves
|
|
1264
|
+
* Retrieves file metadata by ID from the blockchain.
|
|
1265
|
+
*
|
|
1266
|
+
* @remarks
|
|
1267
|
+
* Queries DataRegistry contract directly for file details.
|
|
1268
|
+
* Works for any file ID regardless of ownership, enabling
|
|
1269
|
+
* cross-user file discovery and verification.
|
|
1270
|
+
*
|
|
1271
|
+
* @param fileId - Numeric file ID to retrieve
|
|
1272
|
+
*
|
|
1273
|
+
* @returns UserFile object with metadata
|
|
1274
|
+
*
|
|
1275
|
+
* @throws {Error} Chain ID not available.
|
|
1276
|
+
* Ensure proper network connection.
|
|
1277
|
+
* @throws {Error} File not found.
|
|
1278
|
+
* Verify file ID exists on-chain.
|
|
1279
|
+
* @throws {Error} Contract call failed.
|
|
1280
|
+
* Check network and RPC availability.
|
|
1258
1281
|
*
|
|
1259
|
-
* @param fileId - The file ID to look up
|
|
1260
|
-
* @returns Promise resolving to UserFile object
|
|
1261
|
-
* @throws {Error} "Chain ID not available" - When wallet chain is not configured
|
|
1262
|
-
* @throws {Error} "File not found" - When file ID doesn't exist or returns empty data
|
|
1263
|
-
* @throws {Error} "Failed to fetch file {fileId}: {error}" - General contract read failures
|
|
1264
1282
|
* @example
|
|
1265
1283
|
* ```typescript
|
|
1266
|
-
*
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1269
|
-
*
|
|
1270
|
-
*
|
|
1271
|
-
* owner: file.ownerAddress,
|
|
1272
|
-
* addedAt: file.addedAtBlock
|
|
1273
|
-
* });
|
|
1274
|
-
* } catch (error) {
|
|
1275
|
-
* console.error('File not found or error retrieving file:', error);
|
|
1276
|
-
* }
|
|
1284
|
+
* const file = await vana.data.getFileById(123);
|
|
1285
|
+
* console.log(`File ${file.id}:`);
|
|
1286
|
+
* console.log(` URL: ${file.url}`);
|
|
1287
|
+
* console.log(` Owner: ${file.ownerAddress}`);
|
|
1288
|
+
* console.log(` Block: ${file.addedAtBlock}`);
|
|
1277
1289
|
* ```
|
|
1278
|
-
*
|
|
1279
|
-
* This method queries the DataRegistry contract directly
|
|
1280
|
-
* to get file details for any file ID, regardless of user ownership.
|
|
1281
|
-
* This is useful for file lookup functionality where users can search
|
|
1282
|
-
* for specific files by ID.
|
|
1283
1290
|
*/
|
|
1284
1291
|
async getFileById(fileId) {
|
|
1285
1292
|
try {
|
|
@@ -1594,31 +1601,35 @@ class DataController extends BaseController {
|
|
|
1594
1601
|
}
|
|
1595
1602
|
}
|
|
1596
1603
|
/**
|
|
1597
|
-
*
|
|
1604
|
+
* Registers a data refiner for processing templates.
|
|
1598
1605
|
*
|
|
1599
1606
|
* @remarks
|
|
1600
|
-
* Refiners
|
|
1601
|
-
*
|
|
1602
|
-
*
|
|
1603
|
-
*
|
|
1604
|
-
*
|
|
1605
|
-
* @param params - Refiner
|
|
1606
|
-
* @param params.
|
|
1607
|
-
*
|
|
1608
|
-
* @param params.
|
|
1609
|
-
*
|
|
1610
|
-
* @returns
|
|
1611
|
-
*
|
|
1612
|
-
* @throws {Error}
|
|
1607
|
+
* Refiners define data transformation rules for DLPs.
|
|
1608
|
+
* Associates schema, instructions, and processing logic.
|
|
1609
|
+
*
|
|
1610
|
+
* @param params - Refiner configuration
|
|
1611
|
+
* @param params.dlpId - Data Liquidity Pool ID
|
|
1612
|
+
* @param params.name - Refiner display name
|
|
1613
|
+
* @param params.schemaId - Output schema ID.
|
|
1614
|
+
* Obtain via `vana.schemas.list()`.
|
|
1615
|
+
* @param params.refinementInstructionUrl - Processing instructions URL
|
|
1616
|
+
*
|
|
1617
|
+
* @returns Refiner ID and transaction hash
|
|
1618
|
+
*
|
|
1619
|
+
* @throws {Error} Chain ID not available.
|
|
1620
|
+
* Ensure network connection.
|
|
1621
|
+
* @throws {Error} Transaction failed.
|
|
1622
|
+
* Check wallet balance and network status.
|
|
1623
|
+
*
|
|
1613
1624
|
* @example
|
|
1614
1625
|
* ```typescript
|
|
1615
1626
|
* const result = await vana.data.addRefiner({
|
|
1616
1627
|
* dlpId: 1,
|
|
1617
|
-
* name: "
|
|
1628
|
+
* name: "Sentiment Analyzer",
|
|
1618
1629
|
* schemaId: 42,
|
|
1619
1630
|
* refinementInstructionUrl: "ipfs://QmXxx..."
|
|
1620
1631
|
* });
|
|
1621
|
-
* console.log(`
|
|
1632
|
+
* console.log(`Refiner ${result.refinerId} created`);
|
|
1622
1633
|
* ```
|
|
1623
1634
|
*/
|
|
1624
1635
|
async addRefiner(params) {
|
|
@@ -1676,26 +1687,29 @@ class DataController extends BaseController {
|
|
|
1676
1687
|
}
|
|
1677
1688
|
}
|
|
1678
1689
|
/**
|
|
1679
|
-
* Retrieves
|
|
1690
|
+
* Retrieves refiner configuration by ID.
|
|
1680
1691
|
*
|
|
1681
1692
|
* @remarks
|
|
1682
|
-
* Queries
|
|
1683
|
-
*
|
|
1693
|
+
* Queries DataRefinerRegistry for refiner details.
|
|
1694
|
+
* Returns DLP association, schema, and processing instructions.
|
|
1695
|
+
*
|
|
1696
|
+
* @param refinerId - Numeric refiner ID
|
|
1697
|
+
*
|
|
1698
|
+
* @returns Refiner configuration object
|
|
1699
|
+
*
|
|
1700
|
+
* @throws {Error} Chain ID not available.
|
|
1701
|
+
* Ensure network connection.
|
|
1702
|
+
* @throws {Error} Refiner not found.
|
|
1703
|
+
* Verify refiner ID exists.
|
|
1704
|
+
* @throws {Error} Contract read failed.
|
|
1705
|
+
* Check network and RPC status.
|
|
1684
1706
|
*
|
|
1685
|
-
* @param refinerId - The numeric refiner ID to retrieve
|
|
1686
|
-
* @returns Promise resolving to the refiner information object
|
|
1687
|
-
* @throws {Error} When chain ID is not available - "Chain ID not available"
|
|
1688
|
-
* @throws {Error} When refiner doesn't exist - "Refiner with ID {refinerId} does not exist"
|
|
1689
|
-
* @throws {Error} When contract read fails - "Failed to fetch refiner: {error}"
|
|
1690
1707
|
* @example
|
|
1691
1708
|
* ```typescript
|
|
1692
1709
|
* const refiner = await vana.data.getRefiner(1);
|
|
1693
|
-
* console.log({
|
|
1694
|
-
*
|
|
1695
|
-
*
|
|
1696
|
-
* schema: refiner.schemaId,
|
|
1697
|
-
* instructions: refiner.refinementInstructionUrl
|
|
1698
|
-
* });
|
|
1710
|
+
* console.log(`Refiner: ${refiner.name}`);
|
|
1711
|
+
* console.log(`DLP: ${refiner.dlpId}`);
|
|
1712
|
+
* console.log(`Schema: ${refiner.schemaId}`);
|
|
1699
1713
|
* ```
|
|
1700
1714
|
*/
|
|
1701
1715
|
async getRefiner(refinerId) {
|
|
@@ -1736,21 +1750,27 @@ class DataController extends BaseController {
|
|
|
1736
1750
|
}
|
|
1737
1751
|
}
|
|
1738
1752
|
/**
|
|
1739
|
-
* Validates
|
|
1753
|
+
* Validates schema ID existence.
|
|
1740
1754
|
*
|
|
1741
1755
|
* @remarks
|
|
1742
|
-
*
|
|
1743
|
-
*
|
|
1756
|
+
* Verifies schema registration in DataRegistry.
|
|
1757
|
+
* Check before using schemas for uploads.
|
|
1758
|
+
*
|
|
1759
|
+
* @param schemaId - Numeric schema ID to validate
|
|
1760
|
+
*
|
|
1761
|
+
* @returns True if schema exists, false otherwise
|
|
1762
|
+
*
|
|
1763
|
+
* @throws {Error} Chain ID not available.
|
|
1764
|
+
* Ensure network connection.
|
|
1765
|
+
* @throws {Error} Contract read failed.
|
|
1766
|
+
* Check RPC availability.
|
|
1744
1767
|
*
|
|
1745
|
-
* @param schemaId - The numeric schema ID to validate
|
|
1746
|
-
* @returns Promise resolving to true if schema exists, false otherwise
|
|
1747
1768
|
* @example
|
|
1748
1769
|
* ```typescript
|
|
1749
|
-
* const
|
|
1750
|
-
* if (
|
|
1751
|
-
*
|
|
1752
|
-
*
|
|
1753
|
-
* console.log('Schema 42 does not exist');
|
|
1770
|
+
* const valid = await vana.data.isValidSchemaId(42);
|
|
1771
|
+
* if (valid) {
|
|
1772
|
+
* // Safe to use schema 42
|
|
1773
|
+
* await vana.data.upload({ schemaId: 42, ... });
|
|
1754
1774
|
* }
|
|
1755
1775
|
* ```
|
|
1756
1776
|
*/
|
|
@@ -1913,12 +1933,24 @@ class DataController extends BaseController {
|
|
|
1913
1933
|
};
|
|
1914
1934
|
})
|
|
1915
1935
|
);
|
|
1916
|
-
if (this.context.
|
|
1917
|
-
const
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1936
|
+
if (this.context.relayer) {
|
|
1937
|
+
const request = {
|
|
1938
|
+
type: "direct",
|
|
1939
|
+
operation: "submitFileAdditionWithPermissions",
|
|
1940
|
+
params: {
|
|
1941
|
+
url: uploadResult.url,
|
|
1942
|
+
userAddress,
|
|
1943
|
+
permissions: encryptedPermissions
|
|
1944
|
+
}
|
|
1945
|
+
};
|
|
1946
|
+
const response = await this.context.relayer(request);
|
|
1947
|
+
if (response.type === "error") {
|
|
1948
|
+
throw new Error(response.error);
|
|
1949
|
+
}
|
|
1950
|
+
if (response.type !== "direct" || !("fileId" in response.result)) {
|
|
1951
|
+
throw new Error("Invalid response from relayer");
|
|
1952
|
+
}
|
|
1953
|
+
const result = response.result;
|
|
1922
1954
|
return {
|
|
1923
1955
|
fileId: result.fileId,
|
|
1924
1956
|
url: uploadResult.url,
|
|
@@ -2007,7 +2039,7 @@ class DataController extends BaseController {
|
|
|
2007
2039
|
);
|
|
2008
2040
|
}
|
|
2009
2041
|
}
|
|
2010
|
-
const finalFilename = filename ?? `upload-${Date.now()}.dat`;
|
|
2042
|
+
const finalFilename = filename ?? encrypt ? `upload-${Date.now()}.enc` : `upload-${Date.now()}.dat`;
|
|
2011
2043
|
const uploadResult = await this.context.storageManager.upload(
|
|
2012
2044
|
finalBlob,
|
|
2013
2045
|
finalFilename,
|