@opendatalabs/vana-sdk 0.1.0-alpha.5983460 → 0.1.0-alpha.5a59295

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.
@@ -285,6 +285,12 @@ class ServerController extends import_base.BaseController {
285
285
  * The download requires authentication using the application's signature.
286
286
  * This method returns the artifact as a Blob that can be saved or processed.
287
287
  *
288
+ * **Simplified Signature Scheme:**
289
+ * The signature is generated over the operation ID only, allowing a single signature
290
+ * to be reused for listing and downloading multiple artifacts from the same operation.
291
+ * This simplifies client implementation while maintaining security - access to the
292
+ * operation ID grants access to all artifacts.
293
+ *
288
294
  * @param params - The download parameters
289
295
  * @param params.operationId - The operation ID that generated the artifact
290
296
  * @param params.artifactPath - The path to the artifact file to download
@@ -315,14 +321,14 @@ class ServerController extends import_base.BaseController {
315
321
  async downloadArtifact(params) {
316
322
  this.assertWallet();
317
323
  try {
318
- const requestData = {
319
- operation_id: params.operationId,
320
- artifact_path: params.artifactPath
324
+ const signatureData = {
325
+ operation_id: params.operationId
321
326
  };
322
- const requestJson = JSON.stringify(requestData);
327
+ const requestJson = JSON.stringify(signatureData);
323
328
  const signature = await this.createSignature(requestJson);
324
329
  const requestBody = {
325
- ...requestData,
330
+ operation_id: params.operationId,
331
+ artifact_path: params.artifactPath,
326
332
  signature
327
333
  };
328
334
  const response = await fetch(
@@ -351,6 +357,79 @@ class ServerController extends import_base.BaseController {
351
357
  );
352
358
  }
353
359
  }
360
+ /**
361
+ * Lists all artifacts generated by a server operation.
362
+ *
363
+ * @remarks
364
+ * Retrieves metadata for all artifact files produced by an operation,
365
+ * including file paths, sizes, and content types. This provides visibility
366
+ * into available outputs without downloading them.
367
+ *
368
+ * **Simplified Signature Scheme:**
369
+ * Uses the same signature as downloadArtifact - signs only operation_id.
370
+ * This allows reusing the same signature for listing and downloading.
371
+ *
372
+ * @param operationId - The operation ID that generated the artifacts
373
+ * @returns Promise resolving to array of artifact metadata objects
374
+ * @throws {PersonalServerError} When artifacts cannot be listed
375
+ * @throws {NetworkError} When unable to reach the personal server API
376
+ * @throws {SignatureError} When unable to create the required signature
377
+ * @example
378
+ * ```typescript
379
+ * // List artifacts from a Gemini operation
380
+ * const artifacts = await vana.server.listArtifacts('op_123');
381
+ *
382
+ * console.log(`Found ${artifacts.length} artifacts:`);
383
+ * artifacts.forEach(artifact => {
384
+ * console.log(`- ${artifact.path} (${artifact.size} bytes)`);
385
+ * });
386
+ *
387
+ * // Download a specific artifact
388
+ * const blob = await vana.server.downloadArtifact({
389
+ * operationId: 'op_123',
390
+ * artifactPath: artifacts[0].path
391
+ * });
392
+ * ```
393
+ */
394
+ async listArtifacts(operationId) {
395
+ this.assertWallet();
396
+ try {
397
+ const signatureData = {
398
+ operation_id: operationId
399
+ };
400
+ const requestJson = JSON.stringify(signatureData);
401
+ const signature = await this.createSignature(requestJson);
402
+ const requestBody = {
403
+ operation_id: operationId,
404
+ signature
405
+ };
406
+ const response = await fetch(
407
+ `${this.personalServerBaseUrl}/artifacts/${operationId}/list`,
408
+ {
409
+ method: "POST",
410
+ headers: {
411
+ "Content-Type": "application/json"
412
+ },
413
+ body: JSON.stringify(requestBody)
414
+ }
415
+ );
416
+ if (!response.ok) {
417
+ const errorText = await response.text();
418
+ throw new import_errors.PersonalServerError(
419
+ `Failed to list artifacts: ${response.status} ${response.statusText} - ${errorText}`
420
+ );
421
+ }
422
+ const data = await response.json();
423
+ return data.artifacts ?? [];
424
+ } catch (error) {
425
+ if (error instanceof import_errors.NetworkError || error instanceof import_errors.PersonalServerError || error instanceof import_errors.SignatureError) {
426
+ throw error;
427
+ }
428
+ throw new import_errors.PersonalServerError(
429
+ `Failed to list artifacts: ${error instanceof Error ? error.message : "Unknown error"}`
430
+ );
431
+ }
432
+ }
354
433
  /**
355
434
  * Cancels a running operation on the personal server.
356
435
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/controllers/server.ts"],"sourcesContent":["import type {\n CreateOperationParams,\n InitPersonalServerParams,\n PersonalServerIdentity,\n DownloadArtifactParams,\n} from \"../types\";\nimport type {\n CreateOperationResponse,\n GetOperationResponse,\n IdentityResponseModel,\n} from \"../generated/server/server-exports\";\nimport {\n NetworkError,\n SerializationError,\n SignatureError,\n PersonalServerError,\n} from \"../errors\";\nimport type { ControllerContext } from \"./permissions\";\nimport type { Operation, PollingOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\n\n// Server types are now auto-imported from the generated exports\n\n/**\n * Manages personal server interactions for secure data processing.\n *\n * @remarks\n * Handles communication with personal servers for computation requests\n * and identity retrieval. Personal servers process user data with\n * cryptographic verification, ensuring privacy and permission compliance.\n *\n * **Architecture:**\n * Servers use deterministic key derivation from user addresses.\n * Identity cached for offline retrieval. Operations authenticated\n * via wallet signatures and permission verification.\n *\n * **Method Selection:**\n * - `getIdentity()` - Retrieve server public key for encryption\n * - `createOperation()` - Submit computation with permission ID\n * - `getOperation()` - Check status and retrieve results\n * - `waitForOperation()` - Poll until completion or timeout\n * - `cancelOperation()` - Stop running operations\n *\n * **Typical Workflow:**\n * 1. Get server identity for encryption key\n * 2. Create operation with permission ID\n * 3. Poll for completion\n * 4. Retrieve results\n *\n * @example\n * ```typescript\n * // Get server identity for encryption\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n * console.log(`Server key: ${identity.publicKey}`);\n *\n * // Submit computation request\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Wait for results\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Processing complete:\", result.result);\n * ```\n *\n * @category Server Management\n * @see For conceptual overview, visit {@link https://docs.vana.org/docs/personal-servers}\n */\nexport class ServerController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n private get personalServerBaseUrl(): string {\n if (!this.context.defaultPersonalServerUrl) {\n throw new PersonalServerError(\n \"Personal server URL is required for server operations. \" +\n \"Please configure defaultPersonalServerUrl in your VanaConfig.\",\n );\n }\n return this.context.defaultPersonalServerUrl;\n }\n\n /**\n * Retrieves cryptographic identity for a personal server.\n *\n * @remarks\n * Fetches public key and metadata required for data encryption.\n * Identity cached by infrastructure for offline retrieval.\n * Each user address maps to deterministic server identity.\n *\n * @param request - Identity request parameters\n * @param request.userAddress - Wallet address of server owner\n *\n * @returns Server identity with public key and metadata\n *\n * @throws {NetworkError} Identity service unavailable.\n * Check network connection and server URL configuration.\n * @throws {PersonalServerError} Identity retrieval failed.\n * Verify user address and server registration.\n *\n * @example\n * ```typescript\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * console.log(`Server: ${identity.name}`);\n * console.log(`Address: ${identity.address}`);\n * console.log(`Public Key: ${identity.publicKey}`);\n *\n * // Use for encryption before data sharing\n * const encrypted = await encryptWithPublicKey(\n * data,\n * identity.publicKey\n * );\n * ```\n */\n async getIdentity(\n request: InitPersonalServerParams,\n ): Promise<PersonalServerIdentity> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/identity?address=${request.userAddress}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n console.debug(\"🔍 Debug - getIdentity response\", response);\n if (!response.ok) {\n const errorText = await response.text();\n throw new NetworkError(\n `Local identity API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const serverResponse = (await response.json()) as IdentityResponseModel;\n\n return {\n kind: serverResponse.personal_server.kind,\n address: serverResponse.personal_server.address,\n publicKey: serverResponse.personal_server.public_key,\n baseUrl: this.personalServerBaseUrl,\n name: \"Hosted Vana Server\",\n };\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to get personal server identity: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a server operation and returns its details as a plain object.\n *\n * @remarks\n * This method submits a computation request to the personal server and returns\n * an Operation object that can be serialized and passed across API boundaries.\n * Use `waitForOperation()` to poll for completion.\n *\n * @param params - The operation request parameters\n * @param params.permissionId - The permission ID authorizing this operation.\n * Obtain via `vana.permissions.getUserPermissionGrantsOnChain()`.\n * @returns An Operation object containing the operation ID and status\n * @throws {PersonalServerError} When the server request fails or parameters are invalid\n * @throws {NetworkError} When personal server API communication fails\n * @example\n * ```typescript\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n * console.log(`Operation ID: ${operation.id}`);\n *\n * // Wait for completion\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Result:\", result.result);\n * ```\n */\n async createOperation<T = unknown>(\n params: CreateOperationParams,\n ): Promise<Operation<T>> {\n this.assertWallet();\n\n try {\n const requestData = {\n permission_id: params.permissionId,\n };\n\n const requestJson = JSON.stringify(requestData);\n\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n app_signature: signature,\n operation_request_json: requestJson,\n };\n\n // Step 5: Make request to personal server API\n console.debug(\"🔍 Debug - createOperation requestBody\", requestBody);\n const response = await this.makeRequest(requestBody);\n\n return {\n id: response.id,\n status: \"starting\",\n createdAt: Date.now(),\n } as Operation<T>;\n } catch (error) {\n if (error instanceof Error) {\n // Re-throw known Vana errors directly\n if (\n error instanceof NetworkError ||\n error instanceof SerializationError ||\n error instanceof SignatureError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n // Wrap unknown errors\n throw new PersonalServerError(\n `Personal server operation creation failed: ${error.message}`,\n error,\n );\n }\n throw new PersonalServerError(\n \"Personal server operation creation failed with unknown error\",\n );\n }\n }\n\n /**\n * Retrieves the current status and result of a server operation.\n *\n * @remarks\n * Common status values: `starting`, `running`, `succeeded`, `failed`, `canceled`.\n * When status is `succeeded`, the result field contains the operation output.\n *\n * @param operationId - The ID of the operation to query\n * @returns The operation as a plain object containing status, result, and metadata\n * @throws {NetworkError} When the API request fails or returns invalid data\n * @example\n * ```typescript\n * const operation = await vana.server.getOperation(operationId);\n * if (operation.status === 'succeeded') {\n * console.log('Result:', operation.result);\n * }\n * ```\n */\n async getOperation<T = unknown>(operationId: string): Promise<Operation<T>> {\n try {\n console.debug(\"Polling Operation Status:\", operationId);\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Polling Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Status polling failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as GetOperationResponse;\n\n console.debug(\"Polling Success Response:\", data);\n\n return {\n id: data.id,\n status: data.status as Operation[\"status\"],\n createdAt: Date.now(),\n updatedAt: Date.now(),\n result: data.status === \"succeeded\" ? (data.result as T) : undefined,\n error:\n data.status === \"failed\" ? (data.result ?? undefined) : undefined,\n };\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to poll status: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Waits for an operation to complete and returns the final result.\n *\n * @remarks\n * This method polls the operation status at regular intervals until it\n * reaches a terminal state (succeeded, failed, or canceled). Supports\n * ergonomic overloads to accept either an Operation object or just the ID.\n *\n * @param opOrId - Either an Operation object or operation ID string\n * @param options - Optional polling configuration\n * @returns The completed operation with result or error\n * @throws {PersonalServerError} When the operation fails or times out\n * @example\n * ```typescript\n * // Using operation object\n * const operation = await vana.server.createOperation({ permissionId: 123 });\n * const completed = await vana.server.waitForOperation(operation);\n *\n * // Using just the ID\n * const completed = await vana.server.waitForOperation(\"op_abc123\");\n *\n * // With custom timeout\n * const completed = await vana.server.waitForOperation(operation, {\n * timeout: 60000,\n * pollingInterval: 1000\n * });\n * ```\n */\n async waitForOperation<T = unknown>(\n opOrId: Operation<T> | string,\n options?: PollingOptions,\n ): Promise<Operation<T>> {\n const id = typeof opOrId === \"string\" ? opOrId : opOrId.id;\n const startTime = Date.now();\n const timeout = options?.timeout ?? 30000;\n const interval = options?.pollingInterval ?? 500;\n\n while (true) {\n const operation = await this.getOperation<T>(id);\n\n if (operation.status === \"succeeded\") {\n return operation;\n }\n\n if (operation.status === \"failed\") {\n throw new PersonalServerError(\n `Operation ${operation.status}: ${operation.error ?? \"Unknown error\"}`,\n );\n }\n\n if (operation.status === \"canceled\") {\n throw new PersonalServerError(`Operation was canceled`);\n }\n\n if (Date.now() - startTime > timeout) {\n throw new PersonalServerError(`Operation timed out after ${timeout}ms`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n }\n\n /**\n * Downloads an artifact generated by a server operation.\n *\n * @remarks\n * Artifacts are files generated during operations like Gemini agent analysis.\n * The download requires authentication using the application's signature.\n * This method returns the artifact as a Blob that can be saved or processed.\n *\n * @param params - The download parameters\n * @param params.operationId - The operation ID that generated the artifact\n * @param params.artifactPath - The path to the artifact file to download\n * @returns A Blob containing the artifact data\n * @throws {PersonalServerError} When the artifact cannot be downloaded or doesn't exist\n * @throws {NetworkError} When unable to reach the personal server API\n * @throws {SignatureError} When unable to create the required signature\n * @example\n * ```typescript\n * // Download an artifact after a Gemini operation\n * const blob = await vana.server.downloadArtifact({\n * operationId: 'op_123',\n * artifactPath: 'analysis_report.pdf'\n * });\n *\n * // Save to file in Node.js\n * const buffer = await blob.arrayBuffer();\n * fs.writeFileSync('report.pdf', Buffer.from(buffer));\n *\n * // Or create download link in browser\n * const url = URL.createObjectURL(blob);\n * const a = document.createElement('a');\n * a.href = url;\n * a.download = 'report.pdf';\n * a.click();\n * ```\n */\n async downloadArtifact(params: DownloadArtifactParams): Promise<Blob> {\n this.assertWallet();\n\n try {\n const requestData = {\n operation_id: params.operationId,\n artifact_path: params.artifactPath,\n };\n\n const requestJson = JSON.stringify(requestData);\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n ...requestData,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/artifacts/download`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Artifact download failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n return await response.blob();\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError ||\n error instanceof SignatureError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to download artifact: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Cancels a running operation on the personal server.\n *\n * @remarks\n * This method attempts to cancel an operation that is currently processing\n * on the personal server. The operation must be in a cancellable state\n * (typically `starting` or `processing`). Not all operations support\n * cancellation, and cancellation may not be immediate. The server will\n * attempt to stop the operation and update its status to `canceled`.\n *\n * **Cancellation Behavior:**\n * - Operations in `succeeded` or `failed` states cannot be canceled\n * - Some long-running operations may take time to respond to cancellation\n * - Always verify cancellation by polling the operation status afterward\n *\n * @param operationId - The unique identifier of the operation to cancel,\n * obtained from `createOperation()` response\n * @returns Promise that resolves when the cancellation request is accepted\n * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.\n * Check operation status - it may already be completed or failed.\n * @throws {NetworkError} When unable to reach the personal server API.\n * Verify server URL and network connectivity.\n * @example\n * ```typescript\n * // Start a long-running operation\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Cancel if needed\n * try {\n * await vana.server.cancelOperation(operation.id);\n * console.log(\"Cancellation requested\");\n *\n * // Verify cancellation\n * const status = await vana.server.getOperation(operation.id);\n * if (status.status === \"canceled\") {\n * console.log(\"Operation successfully canceled\");\n * }\n * } catch (error) {\n * console.error(\"Failed to cancel:\", error);\n * }\n * ```\n */\n async cancelOperation(operationId: string): Promise<void> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}/cancel`,\n {\n method: \"POST\",\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Failed to cancel operation: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to cancel operation: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Makes the request to the personal server API.\n *\n * @param requestBody - The post request parameters to serialize\n * @returns JSON string representation of the request data\n */\n private async makeRequest(\n requestBody: Record<string, unknown>,\n ): Promise<CreateOperationResponse> {\n try {\n console.debug(\"Personal Server Request:\", {\n url: `${this.personalServerBaseUrl}/operations`,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: requestBody,\n });\n\n const response = await fetch(`${this.personalServerBaseUrl}/operations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Personal Server Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Personal server API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as CreateOperationResponse;\n\n console.debug(\"Personal Server Success Response:\", data);\n\n return data;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to make personal server API request: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a signature for the request JSON.\n *\n * @param requestJson - The JSON string to sign\n * @returns Promise resolving to the cryptographic signature\n */\n private async createSignature(requestJson: string): Promise<string> {\n try {\n console.debug(\"🔍 Debug - createSignature\", requestJson);\n\n // Use applicationClient if available, fallback to walletClient\n const client =\n this.context.applicationClient ?? this.context.walletClient;\n\n if (!client) {\n throw new SignatureError(\"No client available for signing\");\n }\n\n // Get the account from the wallet client\n const { account } = client;\n if (!account) {\n throw new SignatureError(\"No account available for signing\");\n }\n\n // Only allow local accounts for signing\n if (account.type !== \"local\") {\n throw new SignatureError(\n \"Only local accounts are supported for signing\",\n );\n }\n\n console.debug(\"🔍 Debug - createSignature account\", account);\n // Sign locally using the account's signMessage method\n const signature = await account.signMessage({\n message: requestJson,\n });\n\n return signature;\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"User rejected\")) {\n throw new SignatureError(\"User rejected the signature request\");\n }\n throw new SignatureError(\n `Failed to create signature: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,oBAKO;AAGP,kBAA+B;AAmDxB,MAAM,yBAAyB,2BAAe;AAAA,EACnD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAY,wBAAgC;AAC1C,QAAI,CAAC,KAAK,QAAQ,0BAA0B;AAC1C,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,MAAM,YACJ,SACiC;AACjC,QAAI;AACF,YAAM,WAAW,MAAM;AAAA,QACrB,GAAG,KAAK,qBAAqB,qBAAqB,QAAQ,WAAW;AAAA,QACrE;AAAA,UACE,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MAAM,0CAAmC,QAAQ;AACzD,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,YAAY,MAAM,SAAS,KAAK;AACtC,cAAM,IAAI;AAAA,UACR,sCAAsC,SAAS,MAAM,IAAI,S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A,EAQA,MAAc,gBAAgB,aAAsC;AAClE,QAAI;AACF,cAAQ,MAAM,qCAA8B,WAAW;AAGvD,YAAM,SACJ,KAAK,QAAQ,qBAAqB,KAAK,QAAQ;AAEjD,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,6BAAe,iCAAiC;AAAA,MAC5D;AAGA,YAAM,EAAE,QAAQ,IAAI;AACpB,UAAI,CAAC,SAAS;AACZ,cAAM,IAAI,6BAAe,kCAAkC;AAAA,MAC7D;AAGA,UAAI,QAAQ,SAAS,SAAS;AAC5B,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MAAM,6CAAsC,OAAO;AAE3D,YAAM,YAAY,MAAM,QAAQ,YAAY;AAAA,QAC1C,SAAS;AAAA,MACX,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,eAAe,GAAG;AACrE,cAAM,IAAI,6BAAe,qCAAqC;AAAA,MAChE;AACA,YAAM,IAAI;AAAA,QACR,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACzF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/controllers/server.ts"],"sourcesContent":["import type {\n CreateOperationParams,\n InitPersonalServerParams,\n PersonalServerIdentity,\n DownloadArtifactParams,\n} from \"../types\";\nimport type {\n CreateOperationResponse,\n GetOperationResponse,\n IdentityResponseModel,\n} from \"../generated/server/server-exports\";\nimport {\n NetworkError,\n SerializationError,\n SignatureError,\n PersonalServerError,\n} from \"../errors\";\nimport type { ControllerContext } from \"./permissions\";\nimport type { Operation, PollingOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\n\n// Server types are now auto-imported from the generated exports\n\n/**\n * Manages personal server interactions for secure data processing.\n *\n * @remarks\n * Handles communication with personal servers for computation requests\n * and identity retrieval. Personal servers process user data with\n * cryptographic verification, ensuring privacy and permission compliance.\n *\n * **Architecture:**\n * Servers use deterministic key derivation from user addresses.\n * Identity cached for offline retrieval. Operations authenticated\n * via wallet signatures and permission verification.\n *\n * **Method Selection:**\n * - `getIdentity()` - Retrieve server public key for encryption\n * - `createOperation()` - Submit computation with permission ID\n * - `getOperation()` - Check status and retrieve results\n * - `waitForOperation()` - Poll until completion or timeout\n * - `cancelOperation()` - Stop running operations\n *\n * **Typical Workflow:**\n * 1. Get server identity for encryption key\n * 2. Create operation with permission ID\n * 3. Poll for completion\n * 4. Retrieve results\n *\n * @example\n * ```typescript\n * // Get server identity for encryption\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n * console.log(`Server key: ${identity.publicKey}`);\n *\n * // Submit computation request\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Wait for results\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Processing complete:\", result.result);\n * ```\n *\n * @category Server Management\n * @see For conceptual overview, visit {@link https://docs.vana.org/docs/personal-servers}\n */\nexport class ServerController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n private get personalServerBaseUrl(): string {\n if (!this.context.defaultPersonalServerUrl) {\n throw new PersonalServerError(\n \"Personal server URL is required for server operations. \" +\n \"Please configure defaultPersonalServerUrl in your VanaConfig.\",\n );\n }\n return this.context.defaultPersonalServerUrl;\n }\n\n /**\n * Retrieves cryptographic identity for a personal server.\n *\n * @remarks\n * Fetches public key and metadata required for data encryption.\n * Identity cached by infrastructure for offline retrieval.\n * Each user address maps to deterministic server identity.\n *\n * @param request - Identity request parameters\n * @param request.userAddress - Wallet address of server owner\n *\n * @returns Server identity with public key and metadata\n *\n * @throws {NetworkError} Identity service unavailable.\n * Check network connection and server URL configuration.\n * @throws {PersonalServerError} Identity retrieval failed.\n * Verify user address and server registration.\n *\n * @example\n * ```typescript\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * console.log(`Server: ${identity.name}`);\n * console.log(`Address: ${identity.address}`);\n * console.log(`Public Key: ${identity.publicKey}`);\n *\n * // Use for encryption before data sharing\n * const encrypted = await encryptWithPublicKey(\n * data,\n * identity.publicKey\n * );\n * ```\n */\n async getIdentity(\n request: InitPersonalServerParams,\n ): Promise<PersonalServerIdentity> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/identity?address=${request.userAddress}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n console.debug(\"🔍 Debug - getIdentity response\", response);\n if (!response.ok) {\n const errorText = await response.text();\n throw new NetworkError(\n `Local identity API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const serverResponse = (await response.json()) as IdentityResponseModel;\n\n return {\n kind: serverResponse.personal_server.kind,\n address: serverResponse.personal_server.address,\n publicKey: serverResponse.personal_server.public_key,\n baseUrl: this.personalServerBaseUrl,\n name: \"Hosted Vana Server\",\n };\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to get personal server identity: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a server operation and returns its details as a plain object.\n *\n * @remarks\n * This method submits a computation request to the personal server and returns\n * an Operation object that can be serialized and passed across API boundaries.\n * Use `waitForOperation()` to poll for completion.\n *\n * @param params - The operation request parameters\n * @param params.permissionId - The permission ID authorizing this operation.\n * Obtain via `vana.permissions.getUserPermissionGrantsOnChain()`.\n * @returns An Operation object containing the operation ID and status\n * @throws {PersonalServerError} When the server request fails or parameters are invalid\n * @throws {NetworkError} When personal server API communication fails\n * @example\n * ```typescript\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n * console.log(`Operation ID: ${operation.id}`);\n *\n * // Wait for completion\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Result:\", result.result);\n * ```\n */\n async createOperation<T = unknown>(\n params: CreateOperationParams,\n ): Promise<Operation<T>> {\n this.assertWallet();\n\n try {\n const requestData = {\n permission_id: params.permissionId,\n };\n\n const requestJson = JSON.stringify(requestData);\n\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n app_signature: signature,\n operation_request_json: requestJson,\n };\n\n // Step 5: Make request to personal server API\n console.debug(\"🔍 Debug - createOperation requestBody\", requestBody);\n const response = await this.makeRequest(requestBody);\n\n return {\n id: response.id,\n status: \"starting\",\n createdAt: Date.now(),\n } as Operation<T>;\n } catch (error) {\n if (error instanceof Error) {\n // Re-throw known Vana errors directly\n if (\n error instanceof NetworkError ||\n error instanceof SerializationError ||\n error instanceof SignatureError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n // Wrap unknown errors\n throw new PersonalServerError(\n `Personal server operation creation failed: ${error.message}`,\n error,\n );\n }\n throw new PersonalServerError(\n \"Personal server operation creation failed with unknown error\",\n );\n }\n }\n\n /**\n * Retrieves the current status and result of a server operation.\n *\n * @remarks\n * Common status values: `starting`, `running`, `succeeded`, `failed`, `canceled`.\n * When status is `succeeded`, the result field contains the operation output.\n *\n * @param operationId - The ID of the operation to query\n * @returns The operation as a plain object containing status, result, and metadata\n * @throws {NetworkError} When the API request fails or returns invalid data\n * @example\n * ```typescript\n * const operation = await vana.server.getOperation(operationId);\n * if (operation.status === 'succeeded') {\n * console.log('Result:', operation.result);\n * }\n * ```\n */\n async getOperation<T = unknown>(operationId: string): Promise<Operation<T>> {\n try {\n console.debug(\"Polling Operation Status:\", operationId);\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Polling Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Status polling failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as GetOperationResponse;\n\n console.debug(\"Polling Success Response:\", data);\n\n return {\n id: data.id,\n status: data.status as Operation[\"status\"],\n createdAt: Date.now(),\n updatedAt: Date.now(),\n result: data.status === \"succeeded\" ? (data.result as T) : undefined,\n error:\n data.status === \"failed\" ? (data.result ?? undefined) : undefined,\n };\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to poll status: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Waits for an operation to complete and returns the final result.\n *\n * @remarks\n * This method polls the operation status at regular intervals until it\n * reaches a terminal state (succeeded, failed, or canceled). Supports\n * ergonomic overloads to accept either an Operation object or just the ID.\n *\n * @param opOrId - Either an Operation object or operation ID string\n * @param options - Optional polling configuration\n * @returns The completed operation with result or error\n * @throws {PersonalServerError} When the operation fails or times out\n * @example\n * ```typescript\n * // Using operation object\n * const operation = await vana.server.createOperation({ permissionId: 123 });\n * const completed = await vana.server.waitForOperation(operation);\n *\n * // Using just the ID\n * const completed = await vana.server.waitForOperation(\"op_abc123\");\n *\n * // With custom timeout\n * const completed = await vana.server.waitForOperation(operation, {\n * timeout: 60000,\n * pollingInterval: 1000\n * });\n * ```\n */\n async waitForOperation<T = unknown>(\n opOrId: Operation<T> | string,\n options?: PollingOptions,\n ): Promise<Operation<T>> {\n const id = typeof opOrId === \"string\" ? opOrId : opOrId.id;\n const startTime = Date.now();\n const timeout = options?.timeout ?? 30000;\n const interval = options?.pollingInterval ?? 500;\n\n while (true) {\n const operation = await this.getOperation<T>(id);\n\n if (operation.status === \"succeeded\") {\n return operation;\n }\n\n if (operation.status === \"failed\") {\n throw new PersonalServerError(\n `Operation ${operation.status}: ${operation.error ?? \"Unknown error\"}`,\n );\n }\n\n if (operation.status === \"canceled\") {\n throw new PersonalServerError(`Operation was canceled`);\n }\n\n if (Date.now() - startTime > timeout) {\n throw new PersonalServerError(`Operation timed out after ${timeout}ms`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n }\n\n /**\n * Downloads an artifact generated by a server operation.\n *\n * @remarks\n * Artifacts are files generated during operations like Gemini agent analysis.\n * The download requires authentication using the application's signature.\n * This method returns the artifact as a Blob that can be saved or processed.\n *\n * **Simplified Signature Scheme:**\n * The signature is generated over the operation ID only, allowing a single signature\n * to be reused for listing and downloading multiple artifacts from the same operation.\n * This simplifies client implementation while maintaining security - access to the\n * operation ID grants access to all artifacts.\n *\n * @param params - The download parameters\n * @param params.operationId - The operation ID that generated the artifact\n * @param params.artifactPath - The path to the artifact file to download\n * @returns A Blob containing the artifact data\n * @throws {PersonalServerError} When the artifact cannot be downloaded or doesn't exist\n * @throws {NetworkError} When unable to reach the personal server API\n * @throws {SignatureError} When unable to create the required signature\n * @example\n * ```typescript\n * // Download an artifact after a Gemini operation\n * const blob = await vana.server.downloadArtifact({\n * operationId: 'op_123',\n * artifactPath: 'analysis_report.pdf'\n * });\n *\n * // Save to file in Node.js\n * const buffer = await blob.arrayBuffer();\n * fs.writeFileSync('report.pdf', Buffer.from(buffer));\n *\n * // Or create download link in browser\n * const url = URL.createObjectURL(blob);\n * const a = document.createElement('a');\n * a.href = url;\n * a.download = 'report.pdf';\n * a.click();\n * ```\n */\n async downloadArtifact(params: DownloadArtifactParams): Promise<Blob> {\n this.assertWallet();\n\n try {\n // Simplified signature scheme: sign only operation_id\n // This allows the same signature to be reused for all artifacts\n const signatureData = {\n operation_id: params.operationId,\n };\n\n const requestJson = JSON.stringify(signatureData);\n const signature = await this.createSignature(requestJson);\n\n // Request body still includes artifact_path for the API\n const requestBody = {\n operation_id: params.operationId,\n artifact_path: params.artifactPath,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/artifacts/download`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Artifact download failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n return await response.blob();\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError ||\n error instanceof SignatureError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to download artifact: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Lists all artifacts generated by a server operation.\n *\n * @remarks\n * Retrieves metadata for all artifact files produced by an operation,\n * including file paths, sizes, and content types. This provides visibility\n * into available outputs without downloading them.\n *\n * **Simplified Signature Scheme:**\n * Uses the same signature as downloadArtifact - signs only operation_id.\n * This allows reusing the same signature for listing and downloading.\n *\n * @param operationId - The operation ID that generated the artifacts\n * @returns Promise resolving to array of artifact metadata objects\n * @throws {PersonalServerError} When artifacts cannot be listed\n * @throws {NetworkError} When unable to reach the personal server API\n * @throws {SignatureError} When unable to create the required signature\n * @example\n * ```typescript\n * // List artifacts from a Gemini operation\n * const artifacts = await vana.server.listArtifacts('op_123');\n *\n * console.log(`Found ${artifacts.length} artifacts:`);\n * artifacts.forEach(artifact => {\n * console.log(`- ${artifact.path} (${artifact.size} bytes)`);\n * });\n *\n * // Download a specific artifact\n * const blob = await vana.server.downloadArtifact({\n * operationId: 'op_123',\n * artifactPath: artifacts[0].path\n * });\n * ```\n */\n async listArtifacts(operationId: string): Promise<\n Array<{\n path: string;\n size: number;\n content_type: string;\n }>\n > {\n this.assertWallet();\n\n try {\n // Use simplified signature scheme: sign only operation_id\n const signatureData = {\n operation_id: operationId,\n };\n\n const requestJson = JSON.stringify(signatureData);\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n operation_id: operationId,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/artifacts/${operationId}/list`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Failed to list artifacts: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = await response.json();\n return data.artifacts ?? [];\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError ||\n error instanceof SignatureError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to list artifacts: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Cancels a running operation on the personal server.\n *\n * @remarks\n * This method attempts to cancel an operation that is currently processing\n * on the personal server. The operation must be in a cancellable state\n * (typically `starting` or `processing`). Not all operations support\n * cancellation, and cancellation may not be immediate. The server will\n * attempt to stop the operation and update its status to `canceled`.\n *\n * **Cancellation Behavior:**\n * - Operations in `succeeded` or `failed` states cannot be canceled\n * - Some long-running operations may take time to respond to cancellation\n * - Always verify cancellation by polling the operation status afterward\n *\n * @param operationId - The unique identifier of the operation to cancel,\n * obtained from `createOperation()` response\n * @returns Promise that resolves when the cancellation request is accepted\n * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.\n * Check operation status - it may already be completed or failed.\n * @throws {NetworkError} When unable to reach the personal server API.\n * Verify server URL and network connectivity.\n * @example\n * ```typescript\n * // Start a long-running operation\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Cancel if needed\n * try {\n * await vana.server.cancelOperation(operation.id);\n * console.log(\"Cancellation requested\");\n *\n * // Verify cancellation\n * const status = await vana.server.getOperation(operation.id);\n * if (status.status === \"canceled\") {\n * console.log(\"Operation successfully canceled\");\n * }\n * } catch (error) {\n * console.error(\"Failed to cancel:\", error);\n * }\n * ```\n */\n async cancelOperation(operationId: string): Promise<void> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}/cancel`,\n {\n method: \"POST\",\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Failed to cancel operation: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to cancel operation: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Makes the request to the personal server API.\n *\n * @param requestBody - The post request parameters to serialize\n * @returns JSON string representation of the request data\n */\n private async makeRequest(\n requestBody: Record<string, unknown>,\n ): Promise<CreateOperationResponse> {\n try {\n console.debug(\"Personal Server Request:\", {\n url: `${this.personalServerBaseUrl}/operations`,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: requestBody,\n });\n\n const response = await fetch(`${this.personalServerBaseUrl}/operations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Personal Server Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Personal server API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as CreateOperationResponse;\n\n console.debug(\"Personal Server Success Response:\", data);\n\n return data;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to make personal server API request: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a signature for the request JSON.\n *\n * @param requestJson - The JSON string to sign\n * @returns Promise resolving to the cryptographic signature\n */\n private async createSignature(requestJson: string): Promise<string> {\n try {\n console.debug(\"🔍 Debug - createSignature\", requestJson);\n\n // Use applicationClient if available, fallback to walletClient\n const client =\n this.context.applicationClient ?? this.context.walletClient;\n\n if (!client) {\n throw new SignatureError(\"No client available for signing\");\n }\n\n // Get the account from the wallet client\n const { account } = client;\n if (!account) {\n throw new SignatureError(\"No account available for signing\");\n }\n\n // Only allow local accounts for signing\n if (account.type !== \"local\") {\n throw new SignatureError(\n \"Only local accounts are supported for signing\",\n );\n }\n\n console.debug(\"🔍 Debug - createSignature account\", account);\n // Sign locally using the account's signMessage method\n const signature = await account.signMessage({\n message: requestJson,\n });\n\n return signature;\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"User rejected\")) {\n throw new SignatureError(\"User rejected the signature request\");\n }\n throw new SignatureError(\n `Failed to create signature: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,oBAKO;AAGP,kBAA+B;AAmDxB,MAAM,yBAAyB,2BAAe;AAAA,EACnD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAY,wBAAgC;AAC1C,QAAI,CAAC,KAAK,QAAQ,0BAA0B;AAC1C,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,MAAM,YACJ,SACiC;AACjC,QAAI;AACF,YAAM,WAAW,MAAM;AAAA,QACrB,GAAG,KAAK,qBAAqB,qBAAqB,QAAQ,WAAW;AAAA,QACrE;AAAA,UACE,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MAAM,0CAAmC,QAAQ;AACzD,UAAI,CAAC,SAAS,IAAI;AAChB,cAAM,YAAY,MAAM,SAAS,KAAK;AACtC,cAAM,IAAI;AAAA,UACR,sCAAsC,SAAS,MAAM,IAAI,SAAS,UAAU,MAAM,SAAS;AAAA,QAC7F;AAAA,MACF;AAEA,YAAM,iBAAkB,MAAM,SAAS,KAAK;AAE5C,aAAO;AAAA,QACL,MAAM,eAAe,gBAAgB;AAAA,QACrC,SAAS,eAAe,gBAAgB;AAAA,QACxC,WAAW,eAAe,gBAAgB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Ae,kCAAkC;AAAA,MAC7D;AAGA,UAAI,QAAQ,SAAS,SAAS;AAC5B,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MAAM,6CAAsC,OAAO;AAE3D,YAAM,YAAY,MAAM,QAAQ,YAAY;AAAA,QAC1C,SAAS;AAAA,MACX,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,eAAe,GAAG;AACrE,cAAM,IAAI,6BAAe,qCAAqC;AAAA,MAChE;AACA,YAAM,IAAI;AAAA,QACR,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACzF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -171,6 +171,12 @@ export declare class ServerController extends BaseController {
171
171
  * The download requires authentication using the application's signature.
172
172
  * This method returns the artifact as a Blob that can be saved or processed.
173
173
  *
174
+ * **Simplified Signature Scheme:**
175
+ * The signature is generated over the operation ID only, allowing a single signature
176
+ * to be reused for listing and downloading multiple artifacts from the same operation.
177
+ * This simplifies client implementation while maintaining security - access to the
178
+ * operation ID grants access to all artifacts.
179
+ *
174
180
  * @param params - The download parameters
175
181
  * @param params.operationId - The operation ID that generated the artifact
176
182
  * @param params.artifactPath - The path to the artifact file to download
@@ -199,6 +205,45 @@ export declare class ServerController extends BaseController {
199
205
  * ```
200
206
  */
201
207
  downloadArtifact(params: DownloadArtifactParams): Promise<Blob>;
208
+ /**
209
+ * Lists all artifacts generated by a server operation.
210
+ *
211
+ * @remarks
212
+ * Retrieves metadata for all artifact files produced by an operation,
213
+ * including file paths, sizes, and content types. This provides visibility
214
+ * into available outputs without downloading them.
215
+ *
216
+ * **Simplified Signature Scheme:**
217
+ * Uses the same signature as downloadArtifact - signs only operation_id.
218
+ * This allows reusing the same signature for listing and downloading.
219
+ *
220
+ * @param operationId - The operation ID that generated the artifacts
221
+ * @returns Promise resolving to array of artifact metadata objects
222
+ * @throws {PersonalServerError} When artifacts cannot be listed
223
+ * @throws {NetworkError} When unable to reach the personal server API
224
+ * @throws {SignatureError} When unable to create the required signature
225
+ * @example
226
+ * ```typescript
227
+ * // List artifacts from a Gemini operation
228
+ * const artifacts = await vana.server.listArtifacts('op_123');
229
+ *
230
+ * console.log(`Found ${artifacts.length} artifacts:`);
231
+ * artifacts.forEach(artifact => {
232
+ * console.log(`- ${artifact.path} (${artifact.size} bytes)`);
233
+ * });
234
+ *
235
+ * // Download a specific artifact
236
+ * const blob = await vana.server.downloadArtifact({
237
+ * operationId: 'op_123',
238
+ * artifactPath: artifacts[0].path
239
+ * });
240
+ * ```
241
+ */
242
+ listArtifacts(operationId: string): Promise<Array<{
243
+ path: string;
244
+ size: number;
245
+ content_type: string;
246
+ }>>;
202
247
  /**
203
248
  * Cancels a running operation on the personal server.
204
249
  *
@@ -267,6 +267,12 @@ class ServerController extends BaseController {
267
267
  * The download requires authentication using the application's signature.
268
268
  * This method returns the artifact as a Blob that can be saved or processed.
269
269
  *
270
+ * **Simplified Signature Scheme:**
271
+ * The signature is generated over the operation ID only, allowing a single signature
272
+ * to be reused for listing and downloading multiple artifacts from the same operation.
273
+ * This simplifies client implementation while maintaining security - access to the
274
+ * operation ID grants access to all artifacts.
275
+ *
270
276
  * @param params - The download parameters
271
277
  * @param params.operationId - The operation ID that generated the artifact
272
278
  * @param params.artifactPath - The path to the artifact file to download
@@ -297,14 +303,14 @@ class ServerController extends BaseController {
297
303
  async downloadArtifact(params) {
298
304
  this.assertWallet();
299
305
  try {
300
- const requestData = {
301
- operation_id: params.operationId,
302
- artifact_path: params.artifactPath
306
+ const signatureData = {
307
+ operation_id: params.operationId
303
308
  };
304
- const requestJson = JSON.stringify(requestData);
309
+ const requestJson = JSON.stringify(signatureData);
305
310
  const signature = await this.createSignature(requestJson);
306
311
  const requestBody = {
307
- ...requestData,
312
+ operation_id: params.operationId,
313
+ artifact_path: params.artifactPath,
308
314
  signature
309
315
  };
310
316
  const response = await fetch(
@@ -333,6 +339,79 @@ class ServerController extends BaseController {
333
339
  );
334
340
  }
335
341
  }
342
+ /**
343
+ * Lists all artifacts generated by a server operation.
344
+ *
345
+ * @remarks
346
+ * Retrieves metadata for all artifact files produced by an operation,
347
+ * including file paths, sizes, and content types. This provides visibility
348
+ * into available outputs without downloading them.
349
+ *
350
+ * **Simplified Signature Scheme:**
351
+ * Uses the same signature as downloadArtifact - signs only operation_id.
352
+ * This allows reusing the same signature for listing and downloading.
353
+ *
354
+ * @param operationId - The operation ID that generated the artifacts
355
+ * @returns Promise resolving to array of artifact metadata objects
356
+ * @throws {PersonalServerError} When artifacts cannot be listed
357
+ * @throws {NetworkError} When unable to reach the personal server API
358
+ * @throws {SignatureError} When unable to create the required signature
359
+ * @example
360
+ * ```typescript
361
+ * // List artifacts from a Gemini operation
362
+ * const artifacts = await vana.server.listArtifacts('op_123');
363
+ *
364
+ * console.log(`Found ${artifacts.length} artifacts:`);
365
+ * artifacts.forEach(artifact => {
366
+ * console.log(`- ${artifact.path} (${artifact.size} bytes)`);
367
+ * });
368
+ *
369
+ * // Download a specific artifact
370
+ * const blob = await vana.server.downloadArtifact({
371
+ * operationId: 'op_123',
372
+ * artifactPath: artifacts[0].path
373
+ * });
374
+ * ```
375
+ */
376
+ async listArtifacts(operationId) {
377
+ this.assertWallet();
378
+ try {
379
+ const signatureData = {
380
+ operation_id: operationId
381
+ };
382
+ const requestJson = JSON.stringify(signatureData);
383
+ const signature = await this.createSignature(requestJson);
384
+ const requestBody = {
385
+ operation_id: operationId,
386
+ signature
387
+ };
388
+ const response = await fetch(
389
+ `${this.personalServerBaseUrl}/artifacts/${operationId}/list`,
390
+ {
391
+ method: "POST",
392
+ headers: {
393
+ "Content-Type": "application/json"
394
+ },
395
+ body: JSON.stringify(requestBody)
396
+ }
397
+ );
398
+ if (!response.ok) {
399
+ const errorText = await response.text();
400
+ throw new PersonalServerError(
401
+ `Failed to list artifacts: ${response.status} ${response.statusText} - ${errorText}`
402
+ );
403
+ }
404
+ const data = await response.json();
405
+ return data.artifacts ?? [];
406
+ } catch (error) {
407
+ if (error instanceof NetworkError || error instanceof PersonalServerError || error instanceof SignatureError) {
408
+ throw error;
409
+ }
410
+ throw new PersonalServerError(
411
+ `Failed to list artifacts: ${error instanceof Error ? error.message : "Unknown error"}`
412
+ );
413
+ }
414
+ }
336
415
  /**
337
416
  * Cancels a running operation on the personal server.
338
417
  *
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/controllers/server.ts"],"sourcesContent":["import type {\n CreateOperationParams,\n InitPersonalServerParams,\n PersonalServerIdentity,\n DownloadArtifactParams,\n} from \"../types\";\nimport type {\n CreateOperationResponse,\n GetOperationResponse,\n IdentityResponseModel,\n} from \"../generated/server/server-exports\";\nimport {\n NetworkError,\n SerializationError,\n SignatureError,\n PersonalServerError,\n} from \"../errors\";\nimport type { ControllerContext } from \"./permissions\";\nimport type { Operation, PollingOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\n\n// Server types are now auto-imported from the generated exports\n\n/**\n * Manages personal server interactions for secure data processing.\n *\n * @remarks\n * Handles communication with personal servers for computation requests\n * and identity retrieval. Personal servers process user data with\n * cryptographic verification, ensuring privacy and permission compliance.\n *\n * **Architecture:**\n * Servers use deterministic key derivation from user addresses.\n * Identity cached for offline retrieval. Operations authenticated\n * via wallet signatures and permission verification.\n *\n * **Method Selection:**\n * - `getIdentity()` - Retrieve server public key for encryption\n * - `createOperation()` - Submit computation with permission ID\n * - `getOperation()` - Check status and retrieve results\n * - `waitForOperation()` - Poll until completion or timeout\n * - `cancelOperation()` - Stop running operations\n *\n * **Typical Workflow:**\n * 1. Get server identity for encryption key\n * 2. Create operation with permission ID\n * 3. Poll for completion\n * 4. Retrieve results\n *\n * @example\n * ```typescript\n * // Get server identity for encryption\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n * console.log(`Server key: ${identity.publicKey}`);\n *\n * // Submit computation request\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Wait for results\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Processing complete:\", result.result);\n * ```\n *\n * @category Server Management\n * @see For conceptual overview, visit {@link https://docs.vana.org/docs/personal-servers}\n */\nexport class ServerController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n private get personalServerBaseUrl(): string {\n if (!this.context.defaultPersonalServerUrl) {\n throw new PersonalServerError(\n \"Personal server URL is required for server operations. \" +\n \"Please configure defaultPersonalServerUrl in your VanaConfig.\",\n );\n }\n return this.context.defaultPersonalServerUrl;\n }\n\n /**\n * Retrieves cryptographic identity for a personal server.\n *\n * @remarks\n * Fetches public key and metadata required for data encryption.\n * Identity cached by infrastructure for offline retrieval.\n * Each user address maps to deterministic server identity.\n *\n * @param request - Identity request parameters\n * @param request.userAddress - Wallet address of server owner\n *\n * @returns Server identity with public key and metadata\n *\n * @throws {NetworkError} Identity service unavailable.\n * Check network connection and server URL configuration.\n * @throws {PersonalServerError} Identity retrieval failed.\n * Verify user address and server registration.\n *\n * @example\n * ```typescript\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * console.log(`Server: ${identity.name}`);\n * console.log(`Address: ${identity.address}`);\n * console.log(`Public Key: ${identity.publicKey}`);\n *\n * // Use for encryption before data sharing\n * const encrypted = await encryptWithPublicKey(\n * data,\n * identity.publicKey\n * );\n * ```\n */\n async getIdentity(\n request: InitPersonalServerParams,\n ): Promise<PersonalServerIdentity> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/identity?address=${request.userAddress}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n console.debug(\"🔍 Debug - getIdentity response\", response);\n if (!response.ok) {\n const errorText = await response.text();\n throw new NetworkError(\n `Local identity API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const serverResponse = (await response.json()) as IdentityResponseModel;\n\n return {\n kind: serverResponse.personal_server.kind,\n address: serverResponse.personal_server.address,\n publicKey: serverResponse.personal_server.public_key,\n baseUrl: this.personalServerBaseUrl,\n name: \"Hosted Vana Server\",\n };\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to get personal server identity: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a server operation and returns its details as a plain object.\n *\n * @remarks\n * This method submits a computation request to the personal server and returns\n * an Operation object that can be serialized and passed across API boundaries.\n * Use `waitForOperation()` to poll for completion.\n *\n * @param params - The operation request parameters\n * @param params.permissionId - The permission ID authorizing this operation.\n * Obtain via `vana.permissions.getUserPermissionGrantsOnChain()`.\n * @returns An Operation object containing the operation ID and status\n * @throws {PersonalServerError} When the server request fails or parameters are invalid\n * @throws {NetworkError} When personal server API communication fails\n * @example\n * ```typescript\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n * console.log(`Operation ID: ${operation.id}`);\n *\n * // Wait for completion\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Result:\", result.result);\n * ```\n */\n async createOperation<T = unknown>(\n params: CreateOperationParams,\n ): Promise<Operation<T>> {\n this.assertWallet();\n\n try {\n const requestData = {\n permission_id: params.permissionId,\n };\n\n const requestJson = JSON.stringify(requestData);\n\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n app_signature: signature,\n operation_request_json: requestJson,\n };\n\n // Step 5: Make request to personal server API\n console.debug(\"🔍 Debug - createOperation requestBody\", requestBody);\n const response = await this.makeRequest(requestBody);\n\n return {\n id: response.id,\n status: \"starting\",\n createdAt: Date.now(),\n } as Operation<T>;\n } catch (error) {\n if (error instanceof Error) {\n // Re-throw known Vana errors directly\n if (\n error instanceof NetworkError ||\n error instanceof SerializationError ||\n error instanceof SignatureError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n // Wrap unknown errors\n throw new PersonalServerError(\n `Personal server operation creation failed: ${error.message}`,\n error,\n );\n }\n throw new PersonalServerError(\n \"Personal server operation creation failed with unknown error\",\n );\n }\n }\n\n /**\n * Retrieves the current status and result of a server operation.\n *\n * @remarks\n * Common status values: `starting`, `running`, `succeeded`, `failed`, `canceled`.\n * When status is `succeeded`, the result field contains the operation output.\n *\n * @param operationId - The ID of the operation to query\n * @returns The operation as a plain object containing status, result, and metadata\n * @throws {NetworkError} When the API request fails or returns invalid data\n * @example\n * ```typescript\n * const operation = await vana.server.getOperation(operationId);\n * if (operation.status === 'succeeded') {\n * console.log('Result:', operation.result);\n * }\n * ```\n */\n async getOperation<T = unknown>(operationId: string): Promise<Operation<T>> {\n try {\n console.debug(\"Polling Operation Status:\", operationId);\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Polling Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Status polling failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as GetOperationResponse;\n\n console.debug(\"Polling Success Response:\", data);\n\n return {\n id: data.id,\n status: data.status as Operation[\"status\"],\n createdAt: Date.now(),\n updatedAt: Date.now(),\n result: data.status === \"succeeded\" ? (data.result as T) : undefined,\n error:\n data.status === \"failed\" ? (data.result ?? undefined) : undefined,\n };\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to poll status: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Waits for an operation to complete and returns the final result.\n *\n * @remarks\n * This method polls the operation status at regular intervals until it\n * reaches a terminal state (succeeded, failed, or canceled). Supports\n * ergonomic overloads to accept either an Operation object or just the ID.\n *\n * @param opOrId - Either an Operation object or operation ID string\n * @param options - Optional polling configuration\n * @returns The completed operation with result or error\n * @throws {PersonalServerError} When the operation fails or times out\n * @example\n * ```typescript\n * // Using operation object\n * const operation = await vana.server.createOperation({ permissionId: 123 });\n * const completed = await vana.server.waitForOperation(operation);\n *\n * // Using just the ID\n * const completed = await vana.server.waitForOperation(\"op_abc123\");\n *\n * // With custom timeout\n * const completed = await vana.server.waitForOperation(operation, {\n * timeout: 60000,\n * pollingInterval: 1000\n * });\n * ```\n */\n async waitForOperation<T = unknown>(\n opOrId: Operation<T> | string,\n options?: PollingOptions,\n ): Promise<Operation<T>> {\n const id = typeof opOrId === \"string\" ? opOrId : opOrId.id;\n const startTime = Date.now();\n const timeout = options?.timeout ?? 30000;\n const interval = options?.pollingInterval ?? 500;\n\n while (true) {\n const operation = await this.getOperation<T>(id);\n\n if (operation.status === \"succeeded\") {\n return operation;\n }\n\n if (operation.status === \"failed\") {\n throw new PersonalServerError(\n `Operation ${operation.status}: ${operation.error ?? \"Unknown error\"}`,\n );\n }\n\n if (operation.status === \"canceled\") {\n throw new PersonalServerError(`Operation was canceled`);\n }\n\n if (Date.now() - startTime > timeout) {\n throw new PersonalServerError(`Operation timed out after ${timeout}ms`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n }\n\n /**\n * Downloads an artifact generated by a server operation.\n *\n * @remarks\n * Artifacts are files generated during operations like Gemini agent analysis.\n * The download requires authentication using the application's signature.\n * This method returns the artifact as a Blob that can be saved or processed.\n *\n * @param params - The download parameters\n * @param params.operationId - The operation ID that generated the artifact\n * @param params.artifactPath - The path to the artifact file to download\n * @returns A Blob containing the artifact data\n * @throws {PersonalServerError} When the artifact cannot be downloaded or doesn't exist\n * @throws {NetworkError} When unable to reach the personal server API\n * @throws {SignatureError} When unable to create the required signature\n * @example\n * ```typescript\n * // Download an artifact after a Gemini operation\n * const blob = await vana.server.downloadArtifact({\n * operationId: 'op_123',\n * artifactPath: 'analysis_report.pdf'\n * });\n *\n * // Save to file in Node.js\n * const buffer = await blob.arrayBuffer();\n * fs.writeFileSync('report.pdf', Buffer.from(buffer));\n *\n * // Or create download link in browser\n * const url = URL.createObjectURL(blob);\n * const a = document.createElement('a');\n * a.href = url;\n * a.download = 'report.pdf';\n * a.click();\n * ```\n */\n async downloadArtifact(params: DownloadArtifactParams): Promise<Blob> {\n this.assertWallet();\n\n try {\n const requestData = {\n operation_id: params.operationId,\n artifact_path: params.artifactPath,\n };\n\n const requestJson = JSON.stringify(requestData);\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n ...requestData,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/artifacts/download`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Artifact download failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n return await response.blob();\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError ||\n error instanceof SignatureError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to download artifact: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Cancels a running operation on the personal server.\n *\n * @remarks\n * This method attempts to cancel an operation that is currently processing\n * on the personal server. The operation must be in a cancellable state\n * (typically `starting` or `processing`). Not all operations support\n * cancellation, and cancellation may not be immediate. The server will\n * attempt to stop the operation and update its status to `canceled`.\n *\n * **Cancellation Behavior:**\n * - Operations in `succeeded` or `failed` states cannot be canceled\n * - Some long-running operations may take time to respond to cancellation\n * - Always verify cancellation by polling the operation status afterward\n *\n * @param operationId - The unique identifier of the operation to cancel,\n * obtained from `createOperation()` response\n * @returns Promise that resolves when the cancellation request is accepted\n * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.\n * Check operation status - it may already be completed or failed.\n * @throws {NetworkError} When unable to reach the personal server API.\n * Verify server URL and network connectivity.\n * @example\n * ```typescript\n * // Start a long-running operation\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Cancel if needed\n * try {\n * await vana.server.cancelOperation(operation.id);\n * console.log(\"Cancellation requested\");\n *\n * // Verify cancellation\n * const status = await vana.server.getOperation(operation.id);\n * if (status.status === \"canceled\") {\n * console.log(\"Operation successfully canceled\");\n * }\n * } catch (error) {\n * console.error(\"Failed to cancel:\", error);\n * }\n * ```\n */\n async cancelOperation(operationId: string): Promise<void> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}/cancel`,\n {\n method: \"POST\",\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Failed to cancel operation: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to cancel operation: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Makes the request to the personal server API.\n *\n * @param requestBody - The post request parameters to serialize\n * @returns JSON string representation of the request data\n */\n private async makeRequest(\n requestBody: Record<string, unknown>,\n ): Promise<CreateOperationResponse> {\n try {\n console.debug(\"Personal Server Request:\", {\n url: `${this.personalServerBaseUrl}/operations`,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: requestBody,\n });\n\n const response = await fetch(`${this.personalServerBaseUrl}/operations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Personal Server Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Personal server API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as CreateOperationResponse;\n\n console.debug(\"Personal Server Success Response:\", data);\n\n return data;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to make personal server API request: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a signature for the request JSON.\n *\n * @param requestJson - The JSON string to sign\n * @returns Promise resolving to the cryptographic signature\n */\n private async createSignature(requestJson: string): Promise<string> {\n try {\n console.debug(\"🔍 Debug - createSignature\", requestJson);\n\n // Use applicationClient if available, fallback to walletClient\n const client =\n this.context.applicationClient ?? this.context.walletClient;\n\n if (!client) {\n throw new SignatureError(\"No client available for signing\");\n }\n\n // Get the account from the wallet client\n const { account } = client;\n if (!account) {\n throw new SignatureError(\"No account available for signing\");\n }\n\n // Only allow local accounts for signing\n if (account.type !== \"local\") {\n throw new SignatureError(\n \"Only local accounts are supported for signing\",\n );\n }\n\n console.debug(\"🔍 Debug - createSignature account\", account);\n // Sign locally using the account's signMessage method\n const signature = await account.signMessage({\n message: requestJson,\n });\n\n return signature;\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"User rejected\")) {\n throw new SignatureError(\"User rejected the signature request\");\n }\n throw new SignatureError(\n `Failed to create signature: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n}\n"],"mappings":"AAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,sBAAsB;AAmDxB,MAAM,yBAAyB,eAAe;AAAA,EACnD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAY,wBAAgC;AAC1C,QAAI,CAAC,KAAK,QAAQ,0BAA0B;AAC1C,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,MAAM,YACJ,SACiC;AACjC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AU,MAAM,SAAS;AAAA,QAC9F;AAAA,MACF;AAEA,YAAM,OAAQ,MAAM,SAAS,KAAK;AAElC,cAAQ,MAAM,qCAAqC,IAAI;AAEvD,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,iBAAiB,cAAc;AACjC,cAAM;AAAA,MACR;AACA,YAAM,IAAI;AAAA,QACR,+CAA+C,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACzG;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAc,gBAAgB,aAAsC;AAClE,QAAI;AACF,cAAQ,MAAM,qCAA8B,WAAW;AAGvD,YAAM,SACJ,KAAK,QAAQ,qBAAqB,KAAK,QAAQ;AAEjD,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,eAAe,iCAAiC;AAAA,MAC5D;AAGA,YAAM,EAAE,QAAQ,IAAI;AACpB,UAAI,CAAC,SAAS;AACZ,cAAM,IAAI,eAAe,kCAAkC;AAAA,MAC7D;AAGA,UAAI,QAAQ,SAAS,SAAS;AAC5B,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MAAM,6CAAsC,OAAO;AAE3D,YAAM,YAAY,MAAM,QAAQ,YAAY;AAAA,QAC1C,SAAS;AAAA,MACX,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,eAAe,GAAG;AACrE,cAAM,IAAI,eAAe,qCAAqC;AAAA,MAChE;AACA,YAAM,IAAI;AAAA,QACR,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACzF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../src/controllers/server.ts"],"sourcesContent":["import type {\n CreateOperationParams,\n InitPersonalServerParams,\n PersonalServerIdentity,\n DownloadArtifactParams,\n} from \"../types\";\nimport type {\n CreateOperationResponse,\n GetOperationResponse,\n IdentityResponseModel,\n} from \"../generated/server/server-exports\";\nimport {\n NetworkError,\n SerializationError,\n SignatureError,\n PersonalServerError,\n} from \"../errors\";\nimport type { ControllerContext } from \"./permissions\";\nimport type { Operation, PollingOptions } from \"../types/operations\";\nimport { BaseController } from \"./base\";\n\n// Server types are now auto-imported from the generated exports\n\n/**\n * Manages personal server interactions for secure data processing.\n *\n * @remarks\n * Handles communication with personal servers for computation requests\n * and identity retrieval. Personal servers process user data with\n * cryptographic verification, ensuring privacy and permission compliance.\n *\n * **Architecture:**\n * Servers use deterministic key derivation from user addresses.\n * Identity cached for offline retrieval. Operations authenticated\n * via wallet signatures and permission verification.\n *\n * **Method Selection:**\n * - `getIdentity()` - Retrieve server public key for encryption\n * - `createOperation()` - Submit computation with permission ID\n * - `getOperation()` - Check status and retrieve results\n * - `waitForOperation()` - Poll until completion or timeout\n * - `cancelOperation()` - Stop running operations\n *\n * **Typical Workflow:**\n * 1. Get server identity for encryption key\n * 2. Create operation with permission ID\n * 3. Poll for completion\n * 4. Retrieve results\n *\n * @example\n * ```typescript\n * // Get server identity for encryption\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n * console.log(`Server key: ${identity.publicKey}`);\n *\n * // Submit computation request\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Wait for results\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Processing complete:\", result.result);\n * ```\n *\n * @category Server Management\n * @see For conceptual overview, visit {@link https://docs.vana.org/docs/personal-servers}\n */\nexport class ServerController extends BaseController {\n constructor(context: ControllerContext) {\n super(context);\n }\n\n private get personalServerBaseUrl(): string {\n if (!this.context.defaultPersonalServerUrl) {\n throw new PersonalServerError(\n \"Personal server URL is required for server operations. \" +\n \"Please configure defaultPersonalServerUrl in your VanaConfig.\",\n );\n }\n return this.context.defaultPersonalServerUrl;\n }\n\n /**\n * Retrieves cryptographic identity for a personal server.\n *\n * @remarks\n * Fetches public key and metadata required for data encryption.\n * Identity cached by infrastructure for offline retrieval.\n * Each user address maps to deterministic server identity.\n *\n * @param request - Identity request parameters\n * @param request.userAddress - Wallet address of server owner\n *\n * @returns Server identity with public key and metadata\n *\n * @throws {NetworkError} Identity service unavailable.\n * Check network connection and server URL configuration.\n * @throws {PersonalServerError} Identity retrieval failed.\n * Verify user address and server registration.\n *\n * @example\n * ```typescript\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * console.log(`Server: ${identity.name}`);\n * console.log(`Address: ${identity.address}`);\n * console.log(`Public Key: ${identity.publicKey}`);\n *\n * // Use for encryption before data sharing\n * const encrypted = await encryptWithPublicKey(\n * data,\n * identity.publicKey\n * );\n * ```\n */\n async getIdentity(\n request: InitPersonalServerParams,\n ): Promise<PersonalServerIdentity> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/identity?address=${request.userAddress}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n console.debug(\"🔍 Debug - getIdentity response\", response);\n if (!response.ok) {\n const errorText = await response.text();\n throw new NetworkError(\n `Local identity API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const serverResponse = (await response.json()) as IdentityResponseModel;\n\n return {\n kind: serverResponse.personal_server.kind,\n address: serverResponse.personal_server.address,\n publicKey: serverResponse.personal_server.public_key,\n baseUrl: this.personalServerBaseUrl,\n name: \"Hosted Vana Server\",\n };\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to get personal server identity: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a server operation and returns its details as a plain object.\n *\n * @remarks\n * This method submits a computation request to the personal server and returns\n * an Operation object that can be serialized and passed across API boundaries.\n * Use `waitForOperation()` to poll for completion.\n *\n * @param params - The operation request parameters\n * @param params.permissionId - The permission ID authorizing this operation.\n * Obtain via `vana.permissions.getUserPermissionGrantsOnChain()`.\n * @returns An Operation object containing the operation ID and status\n * @throws {PersonalServerError} When the server request fails or parameters are invalid\n * @throws {NetworkError} When personal server API communication fails\n * @example\n * ```typescript\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n * console.log(`Operation ID: ${operation.id}`);\n *\n * // Wait for completion\n * const result = await vana.server.waitForOperation(operation.id);\n * console.log(\"Result:\", result.result);\n * ```\n */\n async createOperation<T = unknown>(\n params: CreateOperationParams,\n ): Promise<Operation<T>> {\n this.assertWallet();\n\n try {\n const requestData = {\n permission_id: params.permissionId,\n };\n\n const requestJson = JSON.stringify(requestData);\n\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n app_signature: signature,\n operation_request_json: requestJson,\n };\n\n // Step 5: Make request to personal server API\n console.debug(\"🔍 Debug - createOperation requestBody\", requestBody);\n const response = await this.makeRequest(requestBody);\n\n return {\n id: response.id,\n status: \"starting\",\n createdAt: Date.now(),\n } as Operation<T>;\n } catch (error) {\n if (error instanceof Error) {\n // Re-throw known Vana errors directly\n if (\n error instanceof NetworkError ||\n error instanceof SerializationError ||\n error instanceof SignatureError ||\n error instanceof PersonalServerError\n ) {\n throw error;\n }\n // Wrap unknown errors\n throw new PersonalServerError(\n `Personal server operation creation failed: ${error.message}`,\n error,\n );\n }\n throw new PersonalServerError(\n \"Personal server operation creation failed with unknown error\",\n );\n }\n }\n\n /**\n * Retrieves the current status and result of a server operation.\n *\n * @remarks\n * Common status values: `starting`, `running`, `succeeded`, `failed`, `canceled`.\n * When status is `succeeded`, the result field contains the operation output.\n *\n * @param operationId - The ID of the operation to query\n * @returns The operation as a plain object containing status, result, and metadata\n * @throws {NetworkError} When the API request fails or returns invalid data\n * @example\n * ```typescript\n * const operation = await vana.server.getOperation(operationId);\n * if (operation.status === 'succeeded') {\n * console.log('Result:', operation.result);\n * }\n * ```\n */\n async getOperation<T = unknown>(operationId: string): Promise<Operation<T>> {\n try {\n console.debug(\"Polling Operation Status:\", operationId);\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}`,\n {\n method: \"GET\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Polling Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Status polling failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as GetOperationResponse;\n\n console.debug(\"Polling Success Response:\", data);\n\n return {\n id: data.id,\n status: data.status as Operation[\"status\"],\n createdAt: Date.now(),\n updatedAt: Date.now(),\n result: data.status === \"succeeded\" ? (data.result as T) : undefined,\n error:\n data.status === \"failed\" ? (data.result ?? undefined) : undefined,\n };\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to poll status: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Waits for an operation to complete and returns the final result.\n *\n * @remarks\n * This method polls the operation status at regular intervals until it\n * reaches a terminal state (succeeded, failed, or canceled). Supports\n * ergonomic overloads to accept either an Operation object or just the ID.\n *\n * @param opOrId - Either an Operation object or operation ID string\n * @param options - Optional polling configuration\n * @returns The completed operation with result or error\n * @throws {PersonalServerError} When the operation fails or times out\n * @example\n * ```typescript\n * // Using operation object\n * const operation = await vana.server.createOperation({ permissionId: 123 });\n * const completed = await vana.server.waitForOperation(operation);\n *\n * // Using just the ID\n * const completed = await vana.server.waitForOperation(\"op_abc123\");\n *\n * // With custom timeout\n * const completed = await vana.server.waitForOperation(operation, {\n * timeout: 60000,\n * pollingInterval: 1000\n * });\n * ```\n */\n async waitForOperation<T = unknown>(\n opOrId: Operation<T> | string,\n options?: PollingOptions,\n ): Promise<Operation<T>> {\n const id = typeof opOrId === \"string\" ? opOrId : opOrId.id;\n const startTime = Date.now();\n const timeout = options?.timeout ?? 30000;\n const interval = options?.pollingInterval ?? 500;\n\n while (true) {\n const operation = await this.getOperation<T>(id);\n\n if (operation.status === \"succeeded\") {\n return operation;\n }\n\n if (operation.status === \"failed\") {\n throw new PersonalServerError(\n `Operation ${operation.status}: ${operation.error ?? \"Unknown error\"}`,\n );\n }\n\n if (operation.status === \"canceled\") {\n throw new PersonalServerError(`Operation was canceled`);\n }\n\n if (Date.now() - startTime > timeout) {\n throw new PersonalServerError(`Operation timed out after ${timeout}ms`);\n }\n\n await new Promise((resolve) => setTimeout(resolve, interval));\n }\n }\n\n /**\n * Downloads an artifact generated by a server operation.\n *\n * @remarks\n * Artifacts are files generated during operations like Gemini agent analysis.\n * The download requires authentication using the application's signature.\n * This method returns the artifact as a Blob that can be saved or processed.\n *\n * **Simplified Signature Scheme:**\n * The signature is generated over the operation ID only, allowing a single signature\n * to be reused for listing and downloading multiple artifacts from the same operation.\n * This simplifies client implementation while maintaining security - access to the\n * operation ID grants access to all artifacts.\n *\n * @param params - The download parameters\n * @param params.operationId - The operation ID that generated the artifact\n * @param params.artifactPath - The path to the artifact file to download\n * @returns A Blob containing the artifact data\n * @throws {PersonalServerError} When the artifact cannot be downloaded or doesn't exist\n * @throws {NetworkError} When unable to reach the personal server API\n * @throws {SignatureError} When unable to create the required signature\n * @example\n * ```typescript\n * // Download an artifact after a Gemini operation\n * const blob = await vana.server.downloadArtifact({\n * operationId: 'op_123',\n * artifactPath: 'analysis_report.pdf'\n * });\n *\n * // Save to file in Node.js\n * const buffer = await blob.arrayBuffer();\n * fs.writeFileSync('report.pdf', Buffer.from(buffer));\n *\n * // Or create download link in browser\n * const url = URL.createObjectURL(blob);\n * const a = document.createElement('a');\n * a.href = url;\n * a.download = 'report.pdf';\n * a.click();\n * ```\n */\n async downloadArtifact(params: DownloadArtifactParams): Promise<Blob> {\n this.assertWallet();\n\n try {\n // Simplified signature scheme: sign only operation_id\n // This allows the same signature to be reused for all artifacts\n const signatureData = {\n operation_id: params.operationId,\n };\n\n const requestJson = JSON.stringify(signatureData);\n const signature = await this.createSignature(requestJson);\n\n // Request body still includes artifact_path for the API\n const requestBody = {\n operation_id: params.operationId,\n artifact_path: params.artifactPath,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/artifacts/download`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Artifact download failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n return await response.blob();\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError ||\n error instanceof SignatureError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to download artifact: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Lists all artifacts generated by a server operation.\n *\n * @remarks\n * Retrieves metadata for all artifact files produced by an operation,\n * including file paths, sizes, and content types. This provides visibility\n * into available outputs without downloading them.\n *\n * **Simplified Signature Scheme:**\n * Uses the same signature as downloadArtifact - signs only operation_id.\n * This allows reusing the same signature for listing and downloading.\n *\n * @param operationId - The operation ID that generated the artifacts\n * @returns Promise resolving to array of artifact metadata objects\n * @throws {PersonalServerError} When artifacts cannot be listed\n * @throws {NetworkError} When unable to reach the personal server API\n * @throws {SignatureError} When unable to create the required signature\n * @example\n * ```typescript\n * // List artifacts from a Gemini operation\n * const artifacts = await vana.server.listArtifacts('op_123');\n *\n * console.log(`Found ${artifacts.length} artifacts:`);\n * artifacts.forEach(artifact => {\n * console.log(`- ${artifact.path} (${artifact.size} bytes)`);\n * });\n *\n * // Download a specific artifact\n * const blob = await vana.server.downloadArtifact({\n * operationId: 'op_123',\n * artifactPath: artifacts[0].path\n * });\n * ```\n */\n async listArtifacts(operationId: string): Promise<\n Array<{\n path: string;\n size: number;\n content_type: string;\n }>\n > {\n this.assertWallet();\n\n try {\n // Use simplified signature scheme: sign only operation_id\n const signatureData = {\n operation_id: operationId,\n };\n\n const requestJson = JSON.stringify(signatureData);\n const signature = await this.createSignature(requestJson);\n\n const requestBody = {\n operation_id: operationId,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}/artifacts/${operationId}/list`,\n {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Failed to list artifacts: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = await response.json();\n return data.artifacts ?? [];\n } catch (error) {\n if (\n error instanceof NetworkError ||\n error instanceof PersonalServerError ||\n error instanceof SignatureError\n ) {\n throw error;\n }\n throw new PersonalServerError(\n `Failed to list artifacts: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Cancels a running operation on the personal server.\n *\n * @remarks\n * This method attempts to cancel an operation that is currently processing\n * on the personal server. The operation must be in a cancellable state\n * (typically `starting` or `processing`). Not all operations support\n * cancellation, and cancellation may not be immediate. The server will\n * attempt to stop the operation and update its status to `canceled`.\n *\n * **Cancellation Behavior:**\n * - Operations in `succeeded` or `failed` states cannot be canceled\n * - Some long-running operations may take time to respond to cancellation\n * - Always verify cancellation by polling the operation status afterward\n *\n * @param operationId - The unique identifier of the operation to cancel,\n * obtained from `createOperation()` response\n * @returns Promise that resolves when the cancellation request is accepted\n * @throws {PersonalServerError} When the operation cannot be canceled or doesn't exist.\n * Check operation status - it may already be completed or failed.\n * @throws {NetworkError} When unable to reach the personal server API.\n * Verify server URL and network connectivity.\n * @example\n * ```typescript\n * // Start a long-running operation\n * const operation = await vana.server.createOperation({\n * permissionId: 123\n * });\n *\n * // Cancel if needed\n * try {\n * await vana.server.cancelOperation(operation.id);\n * console.log(\"Cancellation requested\");\n *\n * // Verify cancellation\n * const status = await vana.server.getOperation(operation.id);\n * if (status.status === \"canceled\") {\n * console.log(\"Operation successfully canceled\");\n * }\n * } catch (error) {\n * console.error(\"Failed to cancel:\", error);\n * }\n * ```\n */\n async cancelOperation(operationId: string): Promise<void> {\n try {\n const response = await fetch(\n `${this.personalServerBaseUrl}/operations/${operationId}/cancel`,\n {\n method: \"POST\",\n },\n );\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new PersonalServerError(\n `Failed to cancel operation: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to cancel operation: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Makes the request to the personal server API.\n *\n * @param requestBody - The post request parameters to serialize\n * @returns JSON string representation of the request data\n */\n private async makeRequest(\n requestBody: Record<string, unknown>,\n ): Promise<CreateOperationResponse> {\n try {\n console.debug(\"Personal Server Request:\", {\n url: `${this.personalServerBaseUrl}/operations`,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: requestBody,\n });\n\n const response = await fetch(`${this.personalServerBaseUrl}/operations`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(requestBody),\n });\n\n if (!response.ok) {\n const errorText = await response.text();\n console.debug(\"Personal Server Error Response:\", {\n status: response.status,\n statusText: response.statusText,\n error: errorText,\n });\n throw new NetworkError(\n `Personal server API request failed: ${response.status} ${response.statusText} - ${errorText}`,\n );\n }\n\n const data = (await response.json()) as CreateOperationResponse;\n\n console.debug(\"Personal Server Success Response:\", data);\n\n return data;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Failed to make personal server API request: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n\n /**\n * Creates a signature for the request JSON.\n *\n * @param requestJson - The JSON string to sign\n * @returns Promise resolving to the cryptographic signature\n */\n private async createSignature(requestJson: string): Promise<string> {\n try {\n console.debug(\"🔍 Debug - createSignature\", requestJson);\n\n // Use applicationClient if available, fallback to walletClient\n const client =\n this.context.applicationClient ?? this.context.walletClient;\n\n if (!client) {\n throw new SignatureError(\"No client available for signing\");\n }\n\n // Get the account from the wallet client\n const { account } = client;\n if (!account) {\n throw new SignatureError(\"No account available for signing\");\n }\n\n // Only allow local accounts for signing\n if (account.type !== \"local\") {\n throw new SignatureError(\n \"Only local accounts are supported for signing\",\n );\n }\n\n console.debug(\"🔍 Debug - createSignature account\", account);\n // Sign locally using the account's signMessage method\n const signature = await account.signMessage({\n message: requestJson,\n });\n\n return signature;\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"User rejected\")) {\n throw new SignatureError(\"User rejected the signature request\");\n }\n throw new SignatureError(\n `Failed to create signature: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n }\n}\n"],"mappings":"AAWA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,sBAAsB;AAmDxB,MAAM,yBAAyB,eAAe;AAAA,EACnD,YAAY,SAA4B;AACtC,UAAM,OAAO;AAAA,EACf;AAAA,EAEA,IAAY,wBAAgC;AAC1C,QAAI,CAAC,KAAK,QAAQ,0BAA0B;AAC1C,YAAM,IAAI;AAAA,QACR;AAAA,MAEF;AAAA,IACF;AACA,WAAO,KAAK,QAAQ;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAqCA,MAAM,YACJ,SACiC;AACjC,QAAI;AACF,YAAM,WAAW,MAAM;AAAA,QACrB,GAAG,KAAK,qBAAqB,qBAAqB,QAAQ,WAAW;AAAA,QACrE;AAAA,UACE,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MA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ACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAc,gBAAgB,aAAsC;AAClE,QAAI;AACF,cAAQ,MAAM,qCAA8B,WAAW;AAGvD,YAAM,SACJ,KAAK,QAAQ,qBAAqB,KAAK,QAAQ;AAEjD,UAAI,CAAC,QAAQ;AACX,cAAM,IAAI,eAAe,iCAAiC;AAAA,MAC5D;AAGA,YAAM,EAAE,QAAQ,IAAI;AACpB,UAAI,CAAC,SAAS;AACZ,cAAM,IAAI,eAAe,kCAAkC;AAAA,MAC7D;AAGA,UAAI,QAAQ,SAAS,SAAS;AAC5B,cAAM,IAAI;AAAA,UACR;AAAA,QACF;AAAA,MACF;AAEA,cAAQ,MAAM,6CAAsC,OAAO;AAE3D,YAAM,YAAY,MAAM,QAAQ,YAAY;AAAA,QAC1C,SAAS;AAAA,MACX,CAAC;AAED,aAAO;AAAA,IACT,SAAS,OAAO;AACd,UAAI,iBAAiB,SAAS,MAAM,QAAQ,SAAS,eAAe,GAAG;AACrE,cAAM,IAAI,eAAe,qCAAqC;AAAA,MAChE;AACA,YAAM,IAAI;AAAA,QACR,+BAA+B,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACzF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendatalabs/vana-sdk",
3
- "version": "0.1.0-alpha.5983460",
3
+ "version": "0.1.0-alpha.5a59295",
4
4
  "description": "A TypeScript library for interacting with Vana Network smart contracts.",
5
5
  "publishConfig": {
6
6
  "access": "public"