@opendatalabs/vana-sdk 0.1.0-alpha.8eb4e46 → 0.1.0-alpha.a145c3c

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.
@@ -34131,6 +34131,8 @@ var PermissionsController = class {
34131
34131
  * Revokes a previously granted permission.
34132
34132
  *
34133
34133
  * @param params - Parameters for revoking the permission
34134
+ * @param params.permissionId - Permission identifier as bigint for contract compatibility.
34135
+ * Obtain from permission grants via `getUserPermissionGrantsOnChain()`.
34134
34136
  * @returns Promise resolving to transaction hash
34135
34137
  * @example
34136
34138
  * ```typescript
@@ -35272,8 +35274,7 @@ var DataController = class {
35272
35274
  schemaId,
35273
35275
  permissions = [],
35274
35276
  encrypt: encrypt2 = true,
35275
- providerName,
35276
- owner
35277
+ providerName
35277
35278
  } = params;
35278
35279
  try {
35279
35280
  let blob;
@@ -35351,7 +35352,7 @@ var DataController = class {
35351
35352
  filename,
35352
35353
  providerName
35353
35354
  );
35354
- const userAddress = owner || await this.getUserAddress();
35355
+ const userAddress = await this.getUserAddress();
35355
35356
  let encryptedPermissions = [];
35356
35357
  if (permissions.length > 0 && encrypt2) {
35357
35358
  const userEncryptionKey = await generateEncryptionKey(
@@ -35385,8 +35386,7 @@ var DataController = class {
35385
35386
  url: uploadResult.url,
35386
35387
  userAddress,
35387
35388
  permissions: encryptedPermissions,
35388
- schemaId: schemaId || 0,
35389
- ownerAddress: owner
35389
+ schemaId: schemaId || 0
35390
35390
  }
35391
35391
  );
35392
35392
  } else if (this.context.relayerCallbacks?.submitFileAddition) {
@@ -37647,6 +37647,39 @@ var ServerController = class {
37647
37647
  this.context = context;
37648
37648
  __publicField(this, "PERSONAL_SERVER_BASE_URL", process.env.NEXT_PUBLIC_PERSONAL_SERVER_BASE_URL);
37649
37649
  }
37650
+ /**
37651
+ * Retrieves the cryptographic identity of a personal server.
37652
+ *
37653
+ * @remarks
37654
+ * This method fetches the public key and metadata for a personal server,
37655
+ * which is required for encrypting data before sharing with the server.
37656
+ * The identity includes the server's public key, address, and operational
37657
+ * details needed for secure communication. This information is cached
37658
+ * by identity servers to enable offline key retrieval.
37659
+ *
37660
+ * @param request - Parameters containing the user address
37661
+ * @param request.userAddress - The wallet address associated with the personal server
37662
+ * @returns Promise resolving to the server's identity information
37663
+ * @throws {NetworkError} When the identity service is unavailable or returns invalid data
37664
+ * @throws {PersonalServerError} When server identity cannot be retrieved
37665
+ * @example
37666
+ * ```typescript
37667
+ * // Get server identity for data encryption
37668
+ * const identity = await vana.server.getIdentity({
37669
+ * userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
37670
+ * });
37671
+ *
37672
+ * console.log(`Server: ${identity.name}`);
37673
+ * console.log(`Address: ${identity.address}`);
37674
+ * console.log(`Public Key: ${identity.public_key}`);
37675
+ *
37676
+ * // Use the public key for encrypting data to share with this server
37677
+ * const encryptedData = await encryptWithWalletPublicKey(
37678
+ * userData,
37679
+ * identity.public_key
37680
+ * );
37681
+ * ```
37682
+ */
37650
37683
  async getIdentity(request) {
37651
37684
  try {
37652
37685
  const response = await fetch(
@@ -37689,10 +37722,13 @@ var ServerController = class {
37689
37722
  * This method submits a computation request to the personal server API.
37690
37723
  * The response includes the operation ID.
37691
37724
  * @param params - The request parameters object
37692
- * @param params.permissionId - The permission ID authorizing this operation
37725
+ * @param params.permissionId - The permission ID authorizing this operation.
37726
+ * Obtain from granted permissions via `vana.permissions.getUserPermissionGrantsOnChain()`.
37693
37727
  * @returns A Promise that resolves to an operation response with status and control URLs
37694
- * @throws {PersonalServerError} When server request fails or parameters are invalid
37695
- * @throws {NetworkError} When personal server API communication fails
37728
+ * @throws {PersonalServerError} When server request fails or parameters are invalid.
37729
+ * Verify permissionId exists and is active for the target server.
37730
+ * @throws {NetworkError} When personal server API communication fails.
37731
+ * Check server URL configuration and network connectivity.
37696
37732
  * @example
37697
37733
  * ```typescript
37698
37734
  * const response = await vana.server.createOperation({
@@ -37794,6 +37830,50 @@ var ServerController = class {
37794
37830
  );
37795
37831
  }
37796
37832
  }
37833
+ /**
37834
+ * Cancels a running operation on the personal server.
37835
+ *
37836
+ * @remarks
37837
+ * This method attempts to cancel an operation that is currently processing
37838
+ * on the personal server. The operation must be in a cancellable state
37839
+ * (typically `starting` or `processing`). Not all operations support
37840
+ * cancellation, and cancellation may not be immediate. The server will
37841
+ * attempt to stop the operation and update its status to `canceled`.
37842
+ *
37843
+ * **Cancellation Behavior:**
37844
+ * - Operations in `succeeded` or `failed` states cannot be canceled
37845
+ * - Some long-running operations may take time to respond to cancellation
37846
+ * - Always verify cancellation by polling the operation status afterward
37847
+ *
37848
+ * @param operationId - The unique identifier of the operation to cancel,
37849
+ * obtained from `createOperation()` response
37850
+ * @returns Promise that resolves when the cancellation request is accepted
37851
+ * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.
37852
+ * Check operation status - it may already be completed or failed.
37853
+ * @throws {NetworkError} When unable to reach the personal server API.
37854
+ * Verify server URL and network connectivity.
37855
+ * @example
37856
+ * ```typescript
37857
+ * // Start a long-running operation
37858
+ * const operation = await vana.server.createOperation({
37859
+ * permissionId: 123
37860
+ * });
37861
+ *
37862
+ * // Cancel if needed
37863
+ * try {
37864
+ * await vana.server.cancelOperation(operation.id);
37865
+ * console.log("Cancellation requested");
37866
+ *
37867
+ * // Verify cancellation
37868
+ * const status = await vana.server.getOperation(operation.id);
37869
+ * if (status.status === "canceled") {
37870
+ * console.log("Operation successfully canceled");
37871
+ * }
37872
+ * } catch (error) {
37873
+ * console.error("Failed to cancel:", error);
37874
+ * }
37875
+ * ```
37876
+ */
37797
37877
  async cancelOperation(operationId) {
37798
37878
  try {
37799
37879
  const response = await fetch(
@@ -38097,7 +38177,8 @@ var ProtocolController = class {
38097
38177
  * are actually deployed on the current network.
38098
38178
  * @param contractName - The name of the Vana contract to retrieve (use const assertion for full typing)
38099
38179
  * @returns An object containing the contract's address and fully typed ABI
38100
- * @throws {ContractNotFoundError} When the contract is not deployed on the current chain
38180
+ * @throws {ContractNotFoundError} When the contract is not deployed on the current chain.
38181
+ * Verify contract name spelling and check current network with `getChainId()`.
38101
38182
  * @example
38102
38183
  * ```typescript
38103
38184
  * // Get contract info with full type inference
@@ -39281,151 +39362,175 @@ var PinataStorage = class {
39281
39362
  }
39282
39363
  };
39283
39364
 
39284
- // src/storage/providers/callback-storage.ts
39285
- var CallbackStorage = class {
39286
- constructor(callbacks) {
39287
- this.callbacks = callbacks;
39288
- if (!callbacks.upload || !callbacks.download) {
39289
- throw new Error(
39290
- "CallbackStorage requires both upload and download callbacks"
39365
+ // src/storage/providers/server-proxy.ts
39366
+ var ServerProxyStorage = class {
39367
+ constructor(config) {
39368
+ this.config = config;
39369
+ if (!config.uploadUrl) {
39370
+ throw new StorageError(
39371
+ "Upload URL is required",
39372
+ "MISSING_UPLOAD_URL",
39373
+ "server-proxy"
39374
+ );
39375
+ }
39376
+ if (!config.downloadUrl) {
39377
+ throw new StorageError(
39378
+ "Download URL is required",
39379
+ "MISSING_DOWNLOAD_URL",
39380
+ "server-proxy"
39291
39381
  );
39292
39382
  }
39293
39383
  }
39294
39384
  /**
39295
- * Upload a file using the provided callback
39385
+ * Uploads a file through your server endpoint
39296
39386
  *
39297
- * @param file - The blob to upload
39298
- * @param filename - Optional filename for the upload
39299
- * @returns The upload result with URL and metadata
39387
+ * @remarks
39388
+ * This method sends the file to your configured upload endpoint via FormData.
39389
+ * Your server is responsible for handling the actual storage implementation
39390
+ * and must return a JSON response with `success: true` and an `identifier` field.
39391
+ *
39392
+ * @param file - The file to upload
39393
+ * @param filename - Optional custom filename
39394
+ * @returns Promise that resolves to the server-provided identifier
39395
+ * @throws {StorageError} When the upload fails or server returns an error
39396
+ *
39397
+ * @example
39398
+ * ```typescript
39399
+ * const identifier = await serverStorage.upload(fileBlob, { name: "report.pdf" });
39400
+ * console.log("File uploaded with identifier:", identifier);
39401
+ * ```
39300
39402
  */
39301
39403
  async upload(file, filename) {
39302
39404
  try {
39303
- const result = await this.callbacks.upload(file, filename);
39304
- if (!result.url || result.url.trim() === "") {
39405
+ const formData = new FormData();
39406
+ formData.append("file", file);
39407
+ if (filename) {
39408
+ formData.append("name", filename);
39409
+ }
39410
+ const response = await fetch(this.config.uploadUrl, {
39411
+ method: "POST",
39412
+ body: formData
39413
+ });
39414
+ if (!response.ok) {
39415
+ const _errorText = await response.text();
39305
39416
  throw new StorageError(
39306
- "Upload callback returned invalid result: missing or empty url",
39307
- "INVALID_UPLOAD_RESULT",
39308
- "callback-storage"
39417
+ `Server upload failed: ${response.status} ${response.statusText}`,
39418
+ "UPLOAD_FAILED",
39419
+ "server-proxy"
39309
39420
  );
39310
39421
  }
39311
- return result;
39422
+ const result = await response.json();
39423
+ if (!result.success) {
39424
+ throw new StorageError(
39425
+ `Upload failed: ${result.error || "Unknown server error"}`,
39426
+ "UPLOAD_FAILED",
39427
+ "server-proxy"
39428
+ );
39429
+ }
39430
+ if (!result.identifier) {
39431
+ throw new StorageError(
39432
+ "Server upload succeeded but no identifier returned",
39433
+ "NO_IDENTIFIER_RETURNED",
39434
+ "server-proxy"
39435
+ );
39436
+ }
39437
+ return {
39438
+ url: result.url || result.identifier,
39439
+ size: file.size,
39440
+ contentType: file.type || "application/octet-stream"
39441
+ };
39312
39442
  } catch (error) {
39313
39443
  if (error instanceof StorageError) {
39314
39444
  throw error;
39315
39445
  }
39316
39446
  throw new StorageError(
39317
- `Upload failed: ${error instanceof Error ? error.message : String(error)}`,
39447
+ `Server proxy upload error: ${error instanceof Error ? error.message : "Unknown error"}`,
39318
39448
  "UPLOAD_ERROR",
39319
- "callback-storage",
39320
- { cause: error instanceof Error ? error : void 0 }
39449
+ "server-proxy"
39321
39450
  );
39322
39451
  }
39323
39452
  }
39324
39453
  /**
39325
- * Download a file using the provided callback
39454
+ * Downloads a file through your server endpoint
39326
39455
  *
39327
- * @param url - The URL or identifier to download
39328
- * @returns The downloaded blob
39456
+ * @remarks
39457
+ * This method sends the identifier to your configured download endpoint via POST request.
39458
+ * Your server is responsible for retrieving the file from your storage backend
39459
+ * and returning the file content as a blob response.
39460
+ *
39461
+ * @param url - The server-provided URL or identifier from upload
39462
+ * @returns Promise that resolves to the downloaded file content
39463
+ * @throws {StorageError} When the download fails or file is not found
39464
+ *
39465
+ * @example
39466
+ * ```typescript
39467
+ * const fileBlob = await serverStorage.download("file-123");
39468
+ * const url = URL.createObjectURL(fileBlob);
39469
+ * ```
39329
39470
  */
39330
39471
  async download(url) {
39331
39472
  try {
39332
- const identifier = this.callbacks.extractIdentifier ? this.callbacks.extractIdentifier(url) : url;
39333
- const blob = await this.callbacks.download(identifier);
39334
- if (!(blob instanceof Blob)) {
39473
+ const identifier = this.extractIdentifierFromUrl(url);
39474
+ const response = await fetch(this.config.downloadUrl, {
39475
+ method: "POST",
39476
+ headers: {
39477
+ "Content-Type": "application/json"
39478
+ },
39479
+ body: JSON.stringify({ identifier })
39480
+ });
39481
+ if (!response.ok) {
39482
+ const _errorText = await response.text();
39335
39483
  throw new StorageError(
39336
- "Download callback returned invalid result: expected Blob",
39337
- "INVALID_DOWNLOAD_RESULT",
39338
- "callback-storage"
39484
+ `Server download failed: ${response.status} ${response.statusText}`,
39485
+ "DOWNLOAD_FAILED",
39486
+ "server-proxy"
39339
39487
  );
39340
39488
  }
39341
- return blob;
39489
+ return await response.blob();
39342
39490
  } catch (error) {
39343
39491
  if (error instanceof StorageError) {
39344
39492
  throw error;
39345
39493
  }
39346
39494
  throw new StorageError(
39347
- `Download failed: ${error instanceof Error ? error.message : String(error)}`,
39495
+ `Server proxy download error: ${error instanceof Error ? error.message : "Unknown error"}`,
39348
39496
  "DOWNLOAD_ERROR",
39349
- "callback-storage",
39350
- { cause: error instanceof Error ? error : void 0 }
39497
+ "server-proxy"
39351
39498
  );
39352
39499
  }
39353
39500
  }
39354
- /**
39355
- * List files using the provided callback (if available)
39356
- *
39357
- * @param options - Optional list options including filters and pagination
39358
- * @returns Array of storage files
39359
- */
39360
- async list(options) {
39361
- if (!this.callbacks.list) {
39362
- throw new StorageError(
39363
- "List operation not supported - no list callback provided",
39364
- "NOT_SUPPORTED",
39365
- "callback-storage"
39366
- );
39367
- }
39368
- try {
39369
- const result = await this.callbacks.list(options?.namePattern, options);
39370
- return result.items.map((item, index) => ({
39371
- id: item.identifier,
39372
- name: item.identifier.split("/").pop() || `file-${index}`,
39373
- url: item.identifier,
39374
- size: item.size || 0,
39375
- contentType: "application/octet-stream",
39376
- createdAt: item.lastModified || /* @__PURE__ */ new Date(),
39377
- metadata: item.metadata
39378
- }));
39379
- } catch (error) {
39380
- throw new StorageError(
39381
- `List failed: ${error instanceof Error ? error.message : String(error)}`,
39382
- "LIST_ERROR",
39383
- "callback-storage",
39384
- { cause: error instanceof Error ? error : void 0 }
39385
- );
39386
- }
39501
+ async list(_options) {
39502
+ throw new StorageError(
39503
+ "List operation is not supported by server proxy storage",
39504
+ "LIST_NOT_SUPPORTED",
39505
+ "server-proxy"
39506
+ );
39387
39507
  }
39388
- /**
39389
- * Delete a file using the provided callback (if available)
39390
- *
39391
- * @param url - The URL or identifier to delete
39392
- * @returns True if deletion succeeded
39393
- */
39394
- async delete(url) {
39395
- if (!this.callbacks.delete) {
39396
- throw new StorageError(
39397
- "Delete operation not supported - no delete callback provided",
39398
- "NOT_SUPPORTED",
39399
- "callback-storage"
39400
- );
39401
- }
39402
- try {
39403
- const identifier = this.callbacks.extractIdentifier ? this.callbacks.extractIdentifier(url) : url;
39404
- return await this.callbacks.delete(identifier);
39405
- } catch (error) {
39406
- throw new StorageError(
39407
- `Delete failed: ${error instanceof Error ? error.message : String(error)}`,
39408
- "DELETE_ERROR",
39409
- "callback-storage",
39410
- { cause: error instanceof Error ? error : void 0 }
39411
- );
39412
- }
39508
+ async delete(_url) {
39509
+ throw new StorageError(
39510
+ "Delete operation is not supported by server proxy storage",
39511
+ "DELETE_NOT_SUPPORTED",
39512
+ "server-proxy"
39513
+ );
39413
39514
  }
39414
39515
  /**
39415
- * Get provider configuration
39516
+ * Extract identifier from URL or return as-is
39416
39517
  *
39417
- * @returns Provider configuration metadata
39518
+ * @param url - URL or identifier string
39519
+ * @returns identifier string
39418
39520
  */
39521
+ extractIdentifierFromUrl(url) {
39522
+ return url;
39523
+ }
39419
39524
  getConfig() {
39420
39525
  return {
39421
- name: "callback-storage",
39422
- type: "callback",
39526
+ name: "Server Proxy",
39527
+ type: "server-proxy",
39423
39528
  requiresAuth: false,
39424
39529
  features: {
39425
39530
  upload: true,
39426
39531
  download: true,
39427
- list: !!this.callbacks.list,
39428
- delete: !!this.callbacks.delete
39532
+ list: false,
39533
+ delete: false
39429
39534
  }
39430
39535
  };
39431
39536
  }
@@ -40049,15 +40154,35 @@ var VanaCore = class {
40049
40154
  }
40050
40155
  /**
40051
40156
  * Encrypts data using the Vana protocol standard encryption.
40052
- * This method automatically uses the correct platform adapter for the current environment.
40157
+ *
40158
+ * @remarks
40159
+ * This method implements the Vana network's standard encryption protocol using
40160
+ * platform-appropriate cryptographic libraries. It automatically handles different
40161
+ * input types (string or Blob) and produces encrypted output suitable for secure
40162
+ * storage or transmission. The encryption is compatible with the network's
40163
+ * decryption protocols and can be decrypted by authorized parties.
40053
40164
  *
40054
- * @param data The data to encrypt (string or Blob)
40055
- * @param key The key to use as encryption key
40056
- * @returns The encrypted data as Blob
40165
+ * @param data - The data to encrypt (string or Blob)
40166
+ * @param key - The encryption key (typically generated via `generateEncryptionKey`)
40167
+ * @returns The encrypted data as a Blob
40168
+ * @throws {Error} When encryption fails due to invalid key or data format
40057
40169
  * @example
40058
40170
  * ```typescript
40059
- * const encryptionKey = await generateEncryptionKey(walletClient);
40060
- * const encrypted = await vana.encryptBlob("sensitive data", encryptionKey);
40171
+ * import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
40172
+ *
40173
+ * // Generate encryption key from wallet signature
40174
+ * const encryptionKey = await generateEncryptionKey(vana.walletClient);
40175
+ *
40176
+ * // Encrypt string data
40177
+ * const sensitiveData = "User's private information";
40178
+ * const encrypted = await vana.encryptBlob(sensitiveData, encryptionKey);
40179
+ *
40180
+ * // Encrypt file data
40181
+ * const fileBlob = new Blob([fileContent], { type: 'application/json' });
40182
+ * const encryptedFile = await vana.encryptBlob(fileBlob, encryptionKey);
40183
+ *
40184
+ * // Store encrypted data safely
40185
+ * await storageProvider.upload(encrypted, 'encrypted-data.bin');
40061
40186
  * ```
40062
40187
  */
40063
40188
  async encryptBlob(data, key) {
@@ -40065,16 +40190,52 @@ var VanaCore = class {
40065
40190
  }
40066
40191
  /**
40067
40192
  * Decrypts data that was encrypted using the Vana protocol.
40068
- * This method automatically uses the correct platform adapter for the current environment.
40193
+ *
40194
+ * @remarks
40195
+ * This method decrypts data that was previously encrypted using the Vana network's
40196
+ * standard encryption protocol. It requires the same wallet signature that was used
40197
+ * for encryption and automatically uses the appropriate platform adapter for
40198
+ * cryptographic operations. The decrypted output maintains the original data format.
40069
40199
  *
40070
- * @param encryptedData The encrypted data (string or Blob)
40071
- * @param walletSignature The wallet signature to use as decryption key
40072
- * @returns The decrypted data as Blob
40200
+ * @param encryptedData - The encrypted data (string or Blob)
40201
+ * @param walletSignature - The wallet signature used as decryption key
40202
+ * @returns The decrypted data as a Blob
40203
+ * @throws {Error} When decryption fails due to invalid signature or corrupted data
40073
40204
  * @example
40074
40205
  * ```typescript
40075
- * const encryptionKey = await generateEncryptionKey(walletClient);
40076
- * const decrypted = await vana.decryptBlob(encryptedData, encryptionKey);
40077
- * const text = await decrypted.text();
40206
+ * import { generateEncryptionKey } from '@opendatalabs/vana-sdk/node';
40207
+ *
40208
+ * // Retrieve encrypted data from storage
40209
+ * const encryptedBlob = await storageProvider.download('encrypted-data.bin');
40210
+ *
40211
+ * // Generate the same key used for encryption
40212
+ * const decryptionKey = await generateEncryptionKey(vana.walletClient);
40213
+ *
40214
+ * // Decrypt the data
40215
+ * const decrypted = await vana.decryptBlob(encryptedBlob, decryptionKey);
40216
+ *
40217
+ * // Convert back to original format
40218
+ * const originalText = await decrypted.text();
40219
+ * const originalJson = JSON.parse(originalText);
40220
+ *
40221
+ * console.log('Decrypted data:', originalJson);
40222
+ * ```
40223
+ *
40224
+ * @example
40225
+ * ```typescript
40226
+ * // Decrypt file downloaded from Vana network
40227
+ * const userFiles = await vana.data.getUserFiles();
40228
+ * const file = userFiles[0];
40229
+ *
40230
+ * // Download encrypted content
40231
+ * const encrypted = await fetch(file.url).then(r => r.blob());
40232
+ *
40233
+ * // Decrypt with user's key
40234
+ * const decryptionKey = await generateEncryptionKey(vana.walletClient);
40235
+ * const decrypted = await vana.decryptBlob(encrypted, decryptionKey);
40236
+ *
40237
+ * // Process original data
40238
+ * const fileContent = await decrypted.arrayBuffer();
40078
40239
  * ```
40079
40240
  */
40080
40241
  async decryptBlob(encryptedData, walletSignature) {
@@ -40885,7 +41046,6 @@ export {
40885
41046
  BaseController,
40886
41047
  BlockchainError,
40887
41048
  BrowserPlatformAdapter,
40888
- CallbackStorage,
40889
41049
  CircuitBreaker,
40890
41050
  ContractFactory,
40891
41051
  ContractNotFoundError,
@@ -40918,6 +41078,7 @@ export {
40918
41078
  SchemaValidator,
40919
41079
  SerializationError,
40920
41080
  ServerController,
41081
+ ServerProxyStorage,
40921
41082
  ServerUrlMismatchError,
40922
41083
  SignatureError,
40923
41084
  StorageError,