@opendatalabs/vana-sdk 0.1.0-alpha.fd33fc9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.ts +33 -1
- package/dist/browser.js.map +1 -1
- package/dist/chains/index.cjs.map +1 -1
- package/dist/chains/index.d.ts +30 -1
- package/dist/chains/index.js.map +1 -1
- package/dist/client/__tests__/enhancedResponse.test.d.ts +1 -0
- package/dist/client/enhancedResponse.cjs +164 -0
- package/dist/client/enhancedResponse.cjs.map +1 -0
- package/dist/client/enhancedResponse.d.ts +120 -0
- package/dist/client/enhancedResponse.js +138 -0
- package/dist/client/enhancedResponse.js.map +1 -0
- package/dist/config/chains.cjs.map +1 -1
- package/dist/config/chains.d.ts +99 -0
- package/dist/config/chains.js.map +1 -1
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +66 -10
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +7 -0
- package/dist/controllers/__tests__/operations.processQueue.test.d.ts +1 -0
- package/dist/controllers/base.cjs +33 -0
- package/dist/controllers/base.cjs.map +1 -1
- package/dist/controllers/base.d.ts +10 -0
- package/dist/controllers/base.js +33 -0
- package/dist/controllers/base.js.map +1 -1
- package/dist/controllers/data.cjs +417 -276
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +246 -193
- package/dist/controllers/data.js +430 -279
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/operations.cjs +430 -0
- package/dist/controllers/operations.cjs.map +1 -0
- package/dist/controllers/operations.d.ts +229 -0
- package/dist/controllers/operations.js +406 -0
- package/dist/controllers/operations.js.map +1 -0
- package/dist/controllers/permissions.cjs +690 -209
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +196 -68
- package/dist/controllers/permissions.js +690 -209
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +27 -28
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +104 -25
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +88 -40
- package/dist/controllers/schemas.js +104 -25
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server.cjs +269 -58
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +157 -52
- package/dist/controllers/server.js +269 -58
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/__tests__/health.test.d.ts +1 -0
- package/dist/core/__tests__/inMemoryNonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/nonceManager.test.d.ts +1 -0
- package/dist/core/__tests__/pollingManager.test.d.ts +4 -0
- package/dist/core/apiClient.cjs +53 -3
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +132 -7
- package/dist/core/apiClient.js +53 -3
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/generics.cjs +30 -3
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +95 -6
- package/dist/core/generics.js +30 -3
- package/dist/core/generics.js.map +1 -1
- package/dist/core/health.cjs +289 -0
- package/dist/core/health.cjs.map +1 -0
- package/dist/core/health.d.ts +143 -0
- package/dist/core/health.js +265 -0
- package/dist/core/health.js.map +1 -0
- package/dist/core/inMemoryNonceManager.cjs +138 -0
- package/dist/core/inMemoryNonceManager.cjs.map +1 -0
- package/dist/core/inMemoryNonceManager.d.ts +69 -0
- package/dist/core/inMemoryNonceManager.js +114 -0
- package/dist/core/inMemoryNonceManager.js.map +1 -0
- package/dist/core/nonceManager.cjs +304 -0
- package/dist/core/nonceManager.cjs.map +1 -0
- package/dist/core/nonceManager.d.ts +116 -0
- package/dist/core/nonceManager.js +280 -0
- package/dist/core/nonceManager.js.map +1 -0
- package/dist/core/pollingManager.cjs +292 -0
- package/dist/core/pollingManager.cjs.map +1 -0
- package/dist/core/pollingManager.d.ts +120 -0
- package/dist/core/pollingManager.js +268 -0
- package/dist/core/pollingManager.js.map +1 -0
- package/dist/core.cjs +55 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +54 -3
- package/dist/core.js +55 -1
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/base.cjs +16 -3
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.js +16 -3
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/errors.cjs +29 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +64 -0
- package/dist/errors.js +28 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.cjs +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +32 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js +42 -0
- package/dist/generated/abi/DLPPerformanceImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.cjs +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +4 -4
- package/dist/generated/abi/DLPRegistryImplementation.js +5 -5
- package/dist/generated/abi/DLPRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +1 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +129 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js +166 -2
- package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +127 -14
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js +167 -19
- package/dist/generated/abi/DataPortabilityGranteesImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +0 -14
- package/dist/generated/abi/DataPortabilityServersImplementation.js +0 -19
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.cjs +0 -13
- package/dist/generated/abi/DataRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataRegistryImplementation.d.ts +0 -10
- package/dist/generated/abi/DataRegistryImplementation.js +0 -13
- package/dist/generated/abi/DataRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.cjs +0 -43
- package/dist/generated/abi/SwapHelperImplementation.cjs.map +1 -1
- package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -35
- package/dist/generated/abi/SwapHelperImplementation.js +0 -43
- package/dist/generated/abi/SwapHelperImplementation.js.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.cjs +195 -0
- package/dist/generated/abi/VanaEpochImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaEpochImplementation.d.ts +151 -0
- package/dist/generated/abi/VanaEpochImplementation.js +195 -0
- package/dist/generated/abi/VanaEpochImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +17 -51
- package/dist/generated/abi/VanaPoolEntityImplementation.js +22 -65
- package/dist/generated/abi/VanaPoolEntityImplementation.js.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.cjs.map +1 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +85 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js +113 -1
- package/dist/generated/abi/VanaPoolStakingImplementation.js.map +1 -1
- package/dist/generated/abi/index.d.ts +546 -146
- package/dist/generated/event-types.cjs.map +1 -1
- package/dist/generated/event-types.d.ts +14 -8
- package/dist/generated/eventRegistry.cjs +42 -18
- package/dist/generated/eventRegistry.cjs.map +1 -1
- package/dist/generated/eventRegistry.js +42 -18
- package/dist/generated/eventRegistry.js.map +1 -1
- package/dist/generated/server/server-exports.cjs +22 -0
- package/dist/generated/server/server-exports.cjs.map +1 -1
- package/dist/generated/server/server-exports.d.ts +27 -10
- package/dist/generated/server/server-exports.js +17 -0
- package/dist/generated/server/server-exports.js.map +1 -1
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +771 -402
- package/dist/generated/subgraph.cjs +797 -32
- package/dist/generated/subgraph.cjs.map +1 -1
- package/dist/generated/subgraph.d.ts +135 -0
- package/dist/generated/subgraph.js +792 -32
- package/dist/generated/subgraph.js.map +1 -1
- package/dist/index.browser.d.ts +2 -0
- package/dist/index.browser.js +10 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +26 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +49 -5
- package/dist/index.node.js +25 -1
- package/dist/index.node.js.map +1 -1
- package/dist/lib/__tests__/redisAtomicStore.test.d.ts +1 -0
- package/dist/lib/redisAtomicStore.cjs +201 -0
- package/dist/lib/redisAtomicStore.cjs.map +1 -0
- package/dist/lib/redisAtomicStore.d.ts +120 -0
- package/dist/lib/redisAtomicStore.js +177 -0
- package/dist/lib/redisAtomicStore.js.map +1 -0
- package/dist/node.cjs.map +1 -1
- package/dist/node.d.ts +39 -1
- package/dist/node.js.map +1 -1
- package/dist/platform/browser.cjs +160 -2
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +232 -12
- package/dist/platform/browser.js +160 -2
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/interface.cjs.map +1 -1
- package/dist/platform/interface.d.ts +283 -90
- package/dist/platform/node.cjs +163 -2
- package/dist/platform/node.cjs.map +1 -1
- package/dist/platform/node.d.ts +69 -6
- package/dist/platform/node.js +163 -2
- package/dist/platform/node.js.map +1 -1
- package/dist/server/relayerHandler.cjs +315 -81
- package/dist/server/relayerHandler.cjs.map +1 -1
- package/dist/server/relayerHandler.d.ts +35 -2
- package/dist/server/relayerHandler.js +315 -81
- package/dist/server/relayerHandler.js.map +1 -1
- package/dist/storage/index.cjs +3 -0
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/manager.cjs +108 -25
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +119 -25
- package/dist/storage/manager.js +108 -25
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +86 -15
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +109 -20
- package/dist/storage/providers/callback-storage.js +86 -15
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/dropbox.cjs +237 -0
- package/dist/storage/providers/dropbox.cjs.map +1 -0
- package/dist/storage/providers/dropbox.d.ts +39 -0
- package/dist/storage/providers/dropbox.js +215 -0
- package/dist/storage/providers/dropbox.js.map +1 -0
- package/dist/storage/providers/dropbox.test.d.ts +1 -0
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +12 -14
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/tests/data-upload-owner-validation.test.d.ts +1 -0
- package/dist/tests/permissions-transaction-options.test.d.ts +1 -0
- package/dist/types/atomicStore.cjs +31 -0
- package/dist/types/atomicStore.cjs.map +1 -0
- package/dist/types/atomicStore.d.ts +236 -0
- package/dist/types/atomicStore.js +7 -0
- package/dist/types/atomicStore.js.map +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +39 -11
- package/dist/types/chains.cjs.map +1 -1
- package/dist/types/chains.d.ts +74 -7
- package/dist/types/chains.js.map +1 -1
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +38 -4
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +71 -7
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +4 -1
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +11 -10
- package/dist/types/generics.cjs.map +1 -1
- package/dist/types/generics.d.ts +81 -10
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +31 -3
- package/dist/types/index.js.map +1 -1
- package/dist/types/operationStore.cjs +17 -0
- package/dist/types/operationStore.cjs.map +1 -0
- package/dist/types/operationStore.d.ts +171 -0
- package/dist/types/operationStore.js +1 -0
- package/dist/types/operationStore.js.map +1 -0
- package/dist/types/operations.cjs +3 -15
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +131 -39
- package/dist/types/operations.js +2 -13
- package/dist/types/operations.js.map +1 -1
- package/dist/types/options.cjs +17 -0
- package/dist/types/options.cjs.map +1 -0
- package/dist/types/options.d.ts +308 -0
- package/dist/types/options.js +1 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/permissions.cjs.map +1 -1
- package/dist/types/permissions.d.ts +19 -20
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +150 -14
- package/dist/types/relayer.cjs.map +1 -1
- package/dist/types/relayer.d.ts +145 -24
- package/dist/types/storage.cjs.map +1 -1
- package/dist/types/storage.d.ts +9 -21
- package/dist/types/storage.js.map +1 -1
- package/dist/types/utils.cjs.map +1 -1
- package/dist/types/utils.d.ts +0 -45
- package/dist/utils/__tests__/chainQuery.test.d.ts +1 -0
- package/dist/utils/__tests__/subgraphConsistency.test.d.ts +4 -0
- package/dist/utils/__tests__/subgraphPagination.test.d.ts +4 -0
- package/dist/utils/chainQuery.cjs +107 -0
- package/dist/utils/chainQuery.cjs.map +1 -0
- package/dist/utils/chainQuery.d.ts +31 -0
- package/dist/utils/chainQuery.js +82 -0
- package/dist/utils/chainQuery.js.map +1 -0
- package/dist/utils/grantFiles.cjs +4 -1
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +10 -20
- package/dist/utils/grantFiles.js +4 -1
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +95 -16
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +93 -12
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/ipfs.cjs +2 -4
- package/dist/utils/ipfs.cjs.map +1 -1
- package/dist/utils/ipfs.d.ts +1 -1
- package/dist/utils/ipfs.js +2 -4
- package/dist/utils/ipfs.js.map +1 -1
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +32 -7
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/signatureCache.cjs +8 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +49 -8
- package/dist/utils/signatureCache.js +8 -2
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/subgraphConsistency.cjs +184 -0
- package/dist/utils/subgraphConsistency.cjs.map +1 -0
- package/dist/utils/subgraphConsistency.d.ts +65 -0
- package/dist/utils/subgraphConsistency.js +155 -0
- package/dist/utils/subgraphConsistency.js.map +1 -0
- package/dist/utils/subgraphMetaCache.cjs +101 -0
- package/dist/utils/subgraphMetaCache.cjs.map +1 -0
- package/dist/utils/subgraphMetaCache.d.ts +56 -0
- package/dist/utils/subgraphMetaCache.js +76 -0
- package/dist/utils/subgraphMetaCache.js.map +1 -0
- package/dist/utils/subgraphPagination.cjs +104 -0
- package/dist/utils/subgraphPagination.cjs.map +1 -0
- package/dist/utils/subgraphPagination.d.ts +78 -0
- package/dist/utils/subgraphPagination.js +78 -0
- package/dist/utils/subgraphPagination.js.map +1 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +12 -12
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typedDataConverter.cjs.map +1 -1
- package/dist/utils/typedDataConverter.d.ts +39 -3
- package/dist/utils/typedDataConverter.js.map +1 -1
- package/dist/utils/urlResolver.cjs +7 -0
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +22 -4
- package/dist/utils/urlResolver.js +7 -0
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs.map +1 -1
- package/dist/utils/wallet.d.ts +78 -16
- package/dist/utils/wallet.js.map +1 -1
- package/package.json +3 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SERVER_PATHS } from "../generated/server/server-exports";
|
|
1
2
|
import {
|
|
2
3
|
NetworkError,
|
|
3
4
|
SerializationError,
|
|
@@ -5,6 +6,7 @@ import {
|
|
|
5
6
|
PersonalServerError
|
|
6
7
|
} from "../errors";
|
|
7
8
|
import { BaseController } from "./base";
|
|
9
|
+
import { SignatureCache } from "../utils/signatureCache";
|
|
8
10
|
class ServerController extends BaseController {
|
|
9
11
|
constructor(context) {
|
|
10
12
|
super(context);
|
|
@@ -15,26 +17,32 @@ class ServerController extends BaseController {
|
|
|
15
17
|
"Personal server URL is required for server operations. Please configure defaultPersonalServerUrl in your VanaConfig."
|
|
16
18
|
);
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
let url = this.context.defaultPersonalServerUrl;
|
|
21
|
+
if (url.endsWith("/api/v1")) {
|
|
22
|
+
url = url.slice(0, -7);
|
|
23
|
+
}
|
|
24
|
+
return url;
|
|
19
25
|
}
|
|
20
26
|
/**
|
|
21
|
-
* Retrieves
|
|
27
|
+
* Retrieves cryptographic identity for a personal server.
|
|
22
28
|
*
|
|
23
29
|
* @remarks
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
32
|
-
*
|
|
33
|
-
* @throws {NetworkError}
|
|
34
|
-
*
|
|
30
|
+
* Fetches public key and metadata required for data encryption.
|
|
31
|
+
* Identity cached by infrastructure for offline retrieval.
|
|
32
|
+
* Each user address maps to deterministic server identity.
|
|
33
|
+
*
|
|
34
|
+
* @param request - Identity request parameters
|
|
35
|
+
* @param request.userAddress - Wallet address of server owner
|
|
36
|
+
*
|
|
37
|
+
* @returns Server identity with public key and metadata
|
|
38
|
+
*
|
|
39
|
+
* @throws {NetworkError} Identity service unavailable.
|
|
40
|
+
* Check network connection and server URL configuration.
|
|
41
|
+
* @throws {PersonalServerError} Identity retrieval failed.
|
|
42
|
+
* Verify user address and server registration.
|
|
43
|
+
*
|
|
35
44
|
* @example
|
|
36
45
|
* ```typescript
|
|
37
|
-
* // Get server identity for data encryption
|
|
38
46
|
* const identity = await vana.server.getIdentity({
|
|
39
47
|
* userAddress: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36"
|
|
40
48
|
* });
|
|
@@ -43,9 +51,9 @@ class ServerController extends BaseController {
|
|
|
43
51
|
* console.log(`Address: ${identity.address}`);
|
|
44
52
|
* console.log(`Public Key: ${identity.publicKey}`);
|
|
45
53
|
*
|
|
46
|
-
* // Use
|
|
47
|
-
* const
|
|
48
|
-
*
|
|
54
|
+
* // Use for encryption before data sharing
|
|
55
|
+
* const encrypted = await encryptWithPublicKey(
|
|
56
|
+
* data,
|
|
49
57
|
* identity.publicKey
|
|
50
58
|
* );
|
|
51
59
|
* ```
|
|
@@ -53,7 +61,7 @@ class ServerController extends BaseController {
|
|
|
53
61
|
async getIdentity(request) {
|
|
54
62
|
try {
|
|
55
63
|
const response = await fetch(
|
|
56
|
-
`${this.personalServerBaseUrl}
|
|
64
|
+
`${this.personalServerBaseUrl}${SERVER_PATHS.identity}?address=${request.userAddress}`,
|
|
57
65
|
{
|
|
58
66
|
method: "GET",
|
|
59
67
|
headers: {
|
|
@@ -86,28 +94,28 @@ class ServerController extends BaseController {
|
|
|
86
94
|
}
|
|
87
95
|
}
|
|
88
96
|
/**
|
|
89
|
-
* Creates a server operation and returns its details
|
|
97
|
+
* Creates a server operation and returns its details from the OpenAPI schema.
|
|
90
98
|
*
|
|
91
99
|
* @remarks
|
|
92
100
|
* This method submits a computation request to the personal server and returns
|
|
93
|
-
*
|
|
94
|
-
*
|
|
101
|
+
* the server's CreateOperationResponse. The response contains the operation ID
|
|
102
|
+
* which can be used with `waitForOperation()` to poll for completion.
|
|
95
103
|
*
|
|
96
104
|
* @param params - The operation request parameters
|
|
97
105
|
* @param params.permissionId - The permission ID authorizing this operation.
|
|
98
106
|
* Obtain via `vana.permissions.getUserPermissionGrantsOnChain()`.
|
|
99
|
-
* @returns
|
|
107
|
+
* @returns Server response with operation ID
|
|
100
108
|
* @throws {PersonalServerError} When the server request fails or parameters are invalid
|
|
101
109
|
* @throws {NetworkError} When personal server API communication fails
|
|
102
110
|
* @example
|
|
103
111
|
* ```typescript
|
|
104
|
-
* const
|
|
112
|
+
* const response = await vana.server.createOperation({
|
|
105
113
|
* permissionId: 123
|
|
106
114
|
* });
|
|
107
|
-
* console.log(`Operation ID: ${
|
|
115
|
+
* console.log(`Operation ID: ${response.id}`);
|
|
108
116
|
*
|
|
109
117
|
* // Wait for completion
|
|
110
|
-
* const result = await vana.server.waitForOperation(
|
|
118
|
+
* const result = await vana.server.waitForOperation(response.id);
|
|
111
119
|
* console.log("Result:", result.result);
|
|
112
120
|
* ```
|
|
113
121
|
*/
|
|
@@ -125,11 +133,7 @@ class ServerController extends BaseController {
|
|
|
125
133
|
};
|
|
126
134
|
console.debug("\u{1F50D} Debug - createOperation requestBody", requestBody);
|
|
127
135
|
const response = await this.makeRequest(requestBody);
|
|
128
|
-
return
|
|
129
|
-
id: response.id,
|
|
130
|
-
status: "starting",
|
|
131
|
-
createdAt: Date.now()
|
|
132
|
-
};
|
|
136
|
+
return response;
|
|
133
137
|
} catch (error) {
|
|
134
138
|
if (error instanceof Error) {
|
|
135
139
|
if (error instanceof NetworkError || error instanceof SerializationError || error instanceof SignatureError || error instanceof PersonalServerError) {
|
|
@@ -149,17 +153,20 @@ class ServerController extends BaseController {
|
|
|
149
153
|
* Retrieves the current status and result of a server operation.
|
|
150
154
|
*
|
|
151
155
|
* @remarks
|
|
152
|
-
* Common status values: `starting`, `
|
|
156
|
+
* Common status values: `starting`, `processing`, `succeeded`, `failed`, `canceled`.
|
|
153
157
|
* When status is `succeeded`, the result field contains the operation output.
|
|
158
|
+
* Returns the server response directly from the OpenAPI schema.
|
|
154
159
|
*
|
|
155
160
|
* @param operationId - The ID of the operation to query
|
|
156
|
-
* @returns The operation
|
|
161
|
+
* @returns The operation status response from the server
|
|
157
162
|
* @throws {NetworkError} When the API request fails or returns invalid data
|
|
158
163
|
* @example
|
|
159
164
|
* ```typescript
|
|
160
165
|
* const operation = await vana.server.getOperation(operationId);
|
|
161
166
|
* if (operation.status === 'succeeded') {
|
|
162
167
|
* console.log('Result:', operation.result);
|
|
168
|
+
* console.log('Started at:', operation.started_at);
|
|
169
|
+
* console.log('Finished at:', operation.finished_at);
|
|
163
170
|
* }
|
|
164
171
|
* ```
|
|
165
172
|
*/
|
|
@@ -167,7 +174,7 @@ class ServerController extends BaseController {
|
|
|
167
174
|
try {
|
|
168
175
|
console.debug("Polling Operation Status:", operationId);
|
|
169
176
|
const response = await fetch(
|
|
170
|
-
`${this.personalServerBaseUrl}
|
|
177
|
+
`${this.personalServerBaseUrl}${SERVER_PATHS.getOperation(operationId)}`,
|
|
171
178
|
{
|
|
172
179
|
method: "GET",
|
|
173
180
|
headers: {
|
|
@@ -188,14 +195,7 @@ class ServerController extends BaseController {
|
|
|
188
195
|
}
|
|
189
196
|
const data = await response.json();
|
|
190
197
|
console.debug("Polling Success Response:", data);
|
|
191
|
-
return
|
|
192
|
-
id: data.id,
|
|
193
|
-
status: data.status,
|
|
194
|
-
createdAt: Date.now(),
|
|
195
|
-
updatedAt: Date.now(),
|
|
196
|
-
result: data.status === "succeeded" ? data.result : void 0,
|
|
197
|
-
error: data.status === "failed" ? data.result ?? void 0 : void 0
|
|
198
|
-
};
|
|
198
|
+
return data;
|
|
199
199
|
} catch (error) {
|
|
200
200
|
if (error instanceof NetworkError) {
|
|
201
201
|
throw error;
|
|
@@ -212,10 +212,11 @@ class ServerController extends BaseController {
|
|
|
212
212
|
* This method polls the operation status at regular intervals until it
|
|
213
213
|
* reaches a terminal state (succeeded, failed, or canceled). Supports
|
|
214
214
|
* ergonomic overloads to accept either an Operation object or just the ID.
|
|
215
|
+
* Returns the server response directly from the OpenAPI schema.
|
|
215
216
|
*
|
|
216
217
|
* @param opOrId - Either an Operation object or operation ID string
|
|
217
218
|
* @param options - Optional polling configuration
|
|
218
|
-
* @returns The completed operation with result
|
|
219
|
+
* @returns The completed operation with result and timestamp data
|
|
219
220
|
* @throws {PersonalServerError} When the operation fails or times out
|
|
220
221
|
* @example
|
|
221
222
|
* ```typescript
|
|
@@ -231,6 +232,10 @@ class ServerController extends BaseController {
|
|
|
231
232
|
* timeout: 60000,
|
|
232
233
|
* pollingInterval: 1000
|
|
233
234
|
* });
|
|
235
|
+
*
|
|
236
|
+
* // Access server-provided timestamps
|
|
237
|
+
* console.log('Started:', completed.started_at);
|
|
238
|
+
* console.log('Finished:', completed.finished_at);
|
|
234
239
|
* ```
|
|
235
240
|
*/
|
|
236
241
|
async waitForOperation(opOrId, options) {
|
|
@@ -244,8 +249,13 @@ class ServerController extends BaseController {
|
|
|
244
249
|
return operation;
|
|
245
250
|
}
|
|
246
251
|
if (operation.status === "failed") {
|
|
252
|
+
let errorMessage = "Unknown error";
|
|
253
|
+
if (operation.result) {
|
|
254
|
+
const resultObj = operation.result;
|
|
255
|
+
errorMessage = typeof resultObj.error === "string" ? resultObj.error : typeof resultObj.detail === "string" ? resultObj.detail : JSON.stringify(operation.result);
|
|
256
|
+
}
|
|
247
257
|
throw new PersonalServerError(
|
|
248
|
-
`Operation ${operation.status}: ${
|
|
258
|
+
`Operation ${operation.status}: ${errorMessage}`
|
|
249
259
|
);
|
|
250
260
|
}
|
|
251
261
|
if (operation.status === "canceled") {
|
|
@@ -257,6 +267,191 @@ class ServerController extends BaseController {
|
|
|
257
267
|
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
258
268
|
}
|
|
259
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Downloads an artifact generated by a server operation.
|
|
272
|
+
*
|
|
273
|
+
* @remarks
|
|
274
|
+
* Artifacts are files generated during operations like Gemini agent analysis.
|
|
275
|
+
* The download requires authentication using the application's signature.
|
|
276
|
+
* This method returns the artifact as a Blob that can be saved or processed.
|
|
277
|
+
*
|
|
278
|
+
* **Simplified Signature Scheme:**
|
|
279
|
+
* The signature is generated over the operation ID only, allowing a single signature
|
|
280
|
+
* to be reused for listing and downloading multiple artifacts from the same operation.
|
|
281
|
+
* This simplifies client implementation while maintaining security - access to the
|
|
282
|
+
* operation ID grants access to all artifacts.
|
|
283
|
+
*
|
|
284
|
+
* @param params - The download parameters
|
|
285
|
+
* @param params.operationId - The operation ID that generated the artifact
|
|
286
|
+
* @param params.artifactPath - The path to the artifact file to download
|
|
287
|
+
* @returns A Blob containing the artifact data
|
|
288
|
+
* @throws {PersonalServerError} When the artifact cannot be downloaded or doesn't exist
|
|
289
|
+
* @throws {NetworkError} When unable to reach the personal server API
|
|
290
|
+
* @throws {SignatureError} When unable to create the required signature
|
|
291
|
+
* @example
|
|
292
|
+
* ```typescript
|
|
293
|
+
* // Download an artifact after a Gemini operation
|
|
294
|
+
* const blob = await vana.server.downloadArtifact({
|
|
295
|
+
* operationId: 'op_123',
|
|
296
|
+
* artifactPath: 'analysis_report.pdf'
|
|
297
|
+
* });
|
|
298
|
+
*
|
|
299
|
+
* // Save to file in Node.js
|
|
300
|
+
* const buffer = await blob.arrayBuffer();
|
|
301
|
+
* fs.writeFileSync('report.pdf', Buffer.from(buffer));
|
|
302
|
+
*
|
|
303
|
+
* // Or create download link in browser
|
|
304
|
+
* const url = URL.createObjectURL(blob);
|
|
305
|
+
* const a = document.createElement('a');
|
|
306
|
+
* a.href = url;
|
|
307
|
+
* a.download = 'report.pdf';
|
|
308
|
+
* a.click();
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
async downloadArtifact(params) {
|
|
312
|
+
this.assertWallet();
|
|
313
|
+
try {
|
|
314
|
+
const signatureData = {
|
|
315
|
+
operation_id: params.operationId
|
|
316
|
+
};
|
|
317
|
+
const requestJson = JSON.stringify(signatureData);
|
|
318
|
+
const messageHash = SignatureCache.hashMessage(signatureData);
|
|
319
|
+
let signature = SignatureCache.get(
|
|
320
|
+
this.context.platform.cache,
|
|
321
|
+
this.getAccountAddress(),
|
|
322
|
+
messageHash
|
|
323
|
+
);
|
|
324
|
+
if (!signature) {
|
|
325
|
+
signature = await this.createSignature(requestJson);
|
|
326
|
+
SignatureCache.set(
|
|
327
|
+
this.context.platform.cache,
|
|
328
|
+
this.getAccountAddress(),
|
|
329
|
+
messageHash,
|
|
330
|
+
signature,
|
|
331
|
+
24
|
|
332
|
+
// Cache for 24 hours since operation_id doesn't change
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
const requestBody = {
|
|
336
|
+
operation_id: params.operationId,
|
|
337
|
+
artifact_path: params.artifactPath,
|
|
338
|
+
signature
|
|
339
|
+
};
|
|
340
|
+
const response = await fetch(
|
|
341
|
+
`${this.personalServerBaseUrl}${SERVER_PATHS.downloadArtifact}`,
|
|
342
|
+
{
|
|
343
|
+
method: "POST",
|
|
344
|
+
headers: {
|
|
345
|
+
"Content-Type": "application/json"
|
|
346
|
+
},
|
|
347
|
+
body: JSON.stringify(requestBody)
|
|
348
|
+
}
|
|
349
|
+
);
|
|
350
|
+
if (!response.ok) {
|
|
351
|
+
const errorText = await response.text();
|
|
352
|
+
throw new PersonalServerError(
|
|
353
|
+
`Artifact download failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
return await response.blob();
|
|
357
|
+
} catch (error) {
|
|
358
|
+
if (error instanceof NetworkError || error instanceof PersonalServerError || error instanceof SignatureError) {
|
|
359
|
+
throw error;
|
|
360
|
+
}
|
|
361
|
+
throw new PersonalServerError(
|
|
362
|
+
`Failed to download artifact: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Lists all artifacts generated by a server operation.
|
|
368
|
+
*
|
|
369
|
+
* @remarks
|
|
370
|
+
* Retrieves metadata for all artifact files produced by an operation,
|
|
371
|
+
* including file paths, sizes, and content types. This provides visibility
|
|
372
|
+
* into available outputs without downloading them.
|
|
373
|
+
*
|
|
374
|
+
* **Simplified Signature Scheme:**
|
|
375
|
+
* Uses the same signature as downloadArtifact - signs only operation_id.
|
|
376
|
+
* This allows reusing the same signature for listing and downloading.
|
|
377
|
+
*
|
|
378
|
+
* @param operationId - The operation ID that generated the artifacts
|
|
379
|
+
* @returns Promise resolving to array of artifact metadata objects
|
|
380
|
+
* @throws {PersonalServerError} When artifacts cannot be listed
|
|
381
|
+
* @throws {NetworkError} When unable to reach the personal server API
|
|
382
|
+
* @throws {SignatureError} When unable to create the required signature
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* // List artifacts from a Gemini operation
|
|
386
|
+
* const artifacts = await vana.server.listArtifacts('op_123');
|
|
387
|
+
*
|
|
388
|
+
* console.log(`Found ${artifacts.length} artifacts:`);
|
|
389
|
+
* artifacts.forEach(artifact => {
|
|
390
|
+
* console.log(`- ${artifact.path} (${artifact.size} bytes)`);
|
|
391
|
+
* });
|
|
392
|
+
*
|
|
393
|
+
* // Download a specific artifact
|
|
394
|
+
* const blob = await vana.server.downloadArtifact({
|
|
395
|
+
* operationId: 'op_123',
|
|
396
|
+
* artifactPath: artifacts[0].path
|
|
397
|
+
* });
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
async listArtifacts(operationId) {
|
|
401
|
+
this.assertWallet();
|
|
402
|
+
try {
|
|
403
|
+
const signatureData = {
|
|
404
|
+
operation_id: operationId
|
|
405
|
+
};
|
|
406
|
+
const requestJson = JSON.stringify(signatureData);
|
|
407
|
+
const messageHash = SignatureCache.hashMessage(signatureData);
|
|
408
|
+
let signature = SignatureCache.get(
|
|
409
|
+
this.context.platform.cache,
|
|
410
|
+
this.getAccountAddress(),
|
|
411
|
+
messageHash
|
|
412
|
+
);
|
|
413
|
+
if (!signature) {
|
|
414
|
+
signature = await this.createSignature(requestJson);
|
|
415
|
+
SignatureCache.set(
|
|
416
|
+
this.context.platform.cache,
|
|
417
|
+
this.getAccountAddress(),
|
|
418
|
+
messageHash,
|
|
419
|
+
signature,
|
|
420
|
+
24
|
|
421
|
+
// Cache for 24 hours since operation_id doesn't change
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
const requestBody = {
|
|
425
|
+
operation_id: operationId,
|
|
426
|
+
signature
|
|
427
|
+
};
|
|
428
|
+
const response = await fetch(
|
|
429
|
+
`${this.personalServerBaseUrl}${SERVER_PATHS.listArtifacts(operationId)}`,
|
|
430
|
+
{
|
|
431
|
+
method: "POST",
|
|
432
|
+
headers: {
|
|
433
|
+
"Content-Type": "application/json"
|
|
434
|
+
},
|
|
435
|
+
body: JSON.stringify(requestBody)
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
if (!response.ok) {
|
|
439
|
+
const errorText = await response.text();
|
|
440
|
+
throw new PersonalServerError(
|
|
441
|
+
`Failed to list artifacts: ${response.status} ${response.statusText} - ${errorText}`
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
const data = await response.json();
|
|
445
|
+
return data.artifacts ?? [];
|
|
446
|
+
} catch (error) {
|
|
447
|
+
if (error instanceof NetworkError || error instanceof PersonalServerError || error instanceof SignatureError) {
|
|
448
|
+
throw error;
|
|
449
|
+
}
|
|
450
|
+
throw new PersonalServerError(
|
|
451
|
+
`Failed to list artifacts: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
260
455
|
/**
|
|
261
456
|
* Cancels a running operation on the personal server.
|
|
262
457
|
*
|
|
@@ -304,7 +499,7 @@ class ServerController extends BaseController {
|
|
|
304
499
|
async cancelOperation(operationId) {
|
|
305
500
|
try {
|
|
306
501
|
const response = await fetch(
|
|
307
|
-
`${this.personalServerBaseUrl}
|
|
502
|
+
`${this.personalServerBaseUrl}${SERVER_PATHS.cancelOperation(operationId)}`,
|
|
308
503
|
{
|
|
309
504
|
method: "POST"
|
|
310
505
|
}
|
|
@@ -333,20 +528,23 @@ class ServerController extends BaseController {
|
|
|
333
528
|
async makeRequest(requestBody) {
|
|
334
529
|
try {
|
|
335
530
|
console.debug("Personal Server Request:", {
|
|
336
|
-
url: `${this.personalServerBaseUrl}
|
|
531
|
+
url: `${this.personalServerBaseUrl}${SERVER_PATHS.operations}`,
|
|
337
532
|
method: "POST",
|
|
338
533
|
headers: {
|
|
339
534
|
"Content-Type": "application/json"
|
|
340
535
|
},
|
|
341
536
|
body: requestBody
|
|
342
537
|
});
|
|
343
|
-
const response = await fetch(
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
538
|
+
const response = await fetch(
|
|
539
|
+
`${this.personalServerBaseUrl}${SERVER_PATHS.operations}`,
|
|
540
|
+
{
|
|
541
|
+
method: "POST",
|
|
542
|
+
headers: {
|
|
543
|
+
"Content-Type": "application/json"
|
|
544
|
+
},
|
|
545
|
+
body: JSON.stringify(requestBody)
|
|
546
|
+
}
|
|
547
|
+
);
|
|
350
548
|
if (!response.ok) {
|
|
351
549
|
const errorText = await response.text();
|
|
352
550
|
console.debug("Personal Server Error Response:", {
|
|
@@ -370,6 +568,23 @@ class ServerController extends BaseController {
|
|
|
370
568
|
);
|
|
371
569
|
}
|
|
372
570
|
}
|
|
571
|
+
/**
|
|
572
|
+
* Gets the account address from the wallet client.
|
|
573
|
+
*
|
|
574
|
+
* @returns The account address
|
|
575
|
+
* @throws {Error} When no account is available
|
|
576
|
+
*/
|
|
577
|
+
getAccountAddress() {
|
|
578
|
+
const client = this.context.applicationClient ?? this.context.walletClient;
|
|
579
|
+
if (!client) {
|
|
580
|
+
throw new Error("No client available for getting account address");
|
|
581
|
+
}
|
|
582
|
+
const { account } = client;
|
|
583
|
+
if (!account) {
|
|
584
|
+
throw new Error("No account available");
|
|
585
|
+
}
|
|
586
|
+
return typeof account === "string" ? account : account.address;
|
|
587
|
+
}
|
|
373
588
|
/**
|
|
374
589
|
* Creates a signature for the request JSON.
|
|
375
590
|
*
|
|
@@ -387,13 +602,9 @@ class ServerController extends BaseController {
|
|
|
387
602
|
if (!account) {
|
|
388
603
|
throw new SignatureError("No account available for signing");
|
|
389
604
|
}
|
|
390
|
-
if (account.type !== "local") {
|
|
391
|
-
throw new SignatureError(
|
|
392
|
-
"Only local accounts are supported for signing"
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
605
|
console.debug("\u{1F50D} Debug - createSignature account", account);
|
|
396
|
-
const signature = await
|
|
606
|
+
const signature = await client.signMessage({
|
|
607
|
+
account,
|
|
397
608
|
message: requestJson
|
|
398
609
|
});
|
|
399
610
|
return signature;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/controllers/server.ts"],"sourcesContent":["import type {\n CreateOperationParams,\n InitPersonalServerParams,\n PersonalServerIdentity,\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 interactions with Vana personal servers and identity infrastructure.\n *\n * @remarks\n * This controller handles communication with personal servers for data processing\n * and identity servers for public key derivation. It provides methods for posting\n * computation requests to personal servers, polling for results, and retrieving\n * cryptographic keys for secure data sharing. All server interactions use the\n * Replicate API infrastructure with proper authentication and error handling.\n *\n * **Server Identity System:**\n * Personal servers use deterministic key derivation: each user address maps to a specific server identity.\n * This enables secure communication without requiring servers to be online during key retrieval.\n *\n * **Method Selection:**\n * - `getIdentity()` retrieves server public keys and addresses for encryption setup\n * - `createOperation()` submits computation requests with signed permission verification\n * - `getOperation()` polls operation status and retrieves results when complete\n * - `cancelOperation()` stops running operations when cancellation is supported\n *\n * **Workflow Pattern:**\n * Typical flow: Get identity → Create operation → Poll status → Retrieve results\n *\n * @example\n * ```typescript\n * // Get a server's identity including public key for encryption\n * const identity = await vana.server.getIdentity({\n * userAddress: \"0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36\"\n * });\n *\n * // Create an operation using a granted permission\n * const response = await vana.server.createOperation({\n * permissionId: 123,\n * });\n *\n * // Poll for computation results\n * const result = await vana.server.getOperation(response.id);\n * ```\n * @category Server Management\n * @see {@link https://docs.vana.com/developer/personal-servers | Vana Personal Servers} for conceptual overview\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 the cryptographic identity of a personal server.\n *\n * @remarks\n * This method fetches the public key and metadata for a personal server,\n * which is required for encrypting data before sharing with the server.\n * The identity includes the server's public key, address, and operational\n * details needed for secure communication. This information is cached\n * by identity servers to enable offline key retrieval.\n *\n * @param request - Parameters containing the user address\n * @param request.userAddress - The wallet address associated with the personal server\n * @returns Promise resolving to the server's identity information\n * @throws {NetworkError} When the identity service is unavailable or returns invalid data\n * @throws {PersonalServerError} When server identity cannot be retrieved\n * @example\n * ```typescript\n * // Get server identity for data encryption\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 the public key for encrypting data to share with this server\n * const encryptedData = await encryptWithWalletPublicKey(\n * userData,\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 * 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":"AAUA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,sBAAsB;AA6CxB,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,EAmCA,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,g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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 { SERVER_PATHS } 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\";\nimport { SignatureCache } from \"../utils/signatureCache\";\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\n // Normalize the URL by removing /api/v1 suffix if present\n // This ensures backward compatibility with old configurations\n let url = this.context.defaultPersonalServerUrl;\n if (url.endsWith(\"/api/v1\")) {\n url = url.slice(0, -7); // Remove '/api/v1'\n }\n return url;\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}${SERVER_PATHS.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 from the OpenAPI schema.\n *\n * @remarks\n * This method submits a computation request to the personal server and returns\n * the server's CreateOperationResponse. The response contains the operation ID\n * which can be used with `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 Server response with operation ID\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 response = await vana.server.createOperation({\n * permissionId: 123\n * });\n * console.log(`Operation ID: ${response.id}`);\n *\n * // Wait for completion\n * const result = await vana.server.waitForOperation(response.id);\n * console.log(\"Result:\", result.result);\n * ```\n */\n async createOperation(\n params: CreateOperationParams,\n ): Promise<CreateOperationResponse> {\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 response;\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`, `processing`, `succeeded`, `failed`, `canceled`.\n * When status is `succeeded`, the result field contains the operation output.\n * Returns the server response directly from the OpenAPI schema.\n *\n * @param operationId - The ID of the operation to query\n * @returns The operation status response from the server\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 * console.log('Started at:', operation.started_at);\n * console.log('Finished at:', operation.finished_at);\n * }\n * ```\n */\n async getOperation(operationId: string): Promise<Operation> {\n try {\n console.debug(\"Polling Operation Status:\", operationId);\n\n const response = await fetch(\n `${this.personalServerBaseUrl}${SERVER_PATHS.getOperation(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 data;\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 * Returns the server response directly from the OpenAPI schema.\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 and timestamp data\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 * // Access server-provided timestamps\n * console.log('Started:', completed.started_at);\n * console.log('Finished:', completed.finished_at);\n * ```\n */\n async waitForOperation(\n opOrId: Operation | string,\n options?: PollingOptions,\n ): Promise<Operation> {\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(id);\n\n if (operation.status === \"succeeded\") {\n return operation;\n }\n\n if (operation.status === \"failed\") {\n // Extract error message from result object when failed\n let errorMessage = \"Unknown error\";\n if (operation.result) {\n const resultObj = operation.result as Record<string, unknown>;\n errorMessage =\n typeof resultObj.error === \"string\"\n ? resultObj.error\n : typeof resultObj.detail === \"string\"\n ? resultObj.detail\n : JSON.stringify(operation.result);\n }\n\n throw new PersonalServerError(\n `Operation ${operation.status}: ${errorMessage}`,\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 via caching\n const signatureData = {\n operation_id: params.operationId,\n };\n\n const requestJson = JSON.stringify(signatureData);\n\n // Use signature cache to avoid repeated wallet prompts for same operation\n const messageHash = SignatureCache.hashMessage(signatureData);\n let signature = SignatureCache.get(\n this.context.platform.cache,\n this.getAccountAddress(),\n messageHash,\n );\n\n if (!signature) {\n signature = await this.createSignature(requestJson);\n SignatureCache.set(\n this.context.platform.cache,\n this.getAccountAddress(),\n messageHash,\n signature,\n 24, // Cache for 24 hours since operation_id doesn't change\n );\n }\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}${SERVER_PATHS.downloadArtifact}`,\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 // Simplified signature scheme: sign only operation_id\n // This allows the same signature to be reused for all artifacts via caching\n const signatureData = {\n operation_id: operationId,\n };\n\n const requestJson = JSON.stringify(signatureData);\n\n // Use signature cache to avoid repeated wallet prompts for same operation\n const messageHash = SignatureCache.hashMessage(signatureData);\n let signature = SignatureCache.get(\n this.context.platform.cache,\n this.getAccountAddress(),\n messageHash,\n );\n\n if (!signature) {\n signature = await this.createSignature(requestJson);\n SignatureCache.set(\n this.context.platform.cache,\n this.getAccountAddress(),\n messageHash,\n signature,\n 24, // Cache for 24 hours since operation_id doesn't change\n );\n }\n\n const requestBody = {\n operation_id: operationId,\n signature,\n };\n\n const response = await fetch(\n `${this.personalServerBaseUrl}${SERVER_PATHS.listArtifacts(operationId)}`,\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}${SERVER_PATHS.cancelOperation(operationId)}`,\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}${SERVER_PATHS.operations}`,\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: requestBody,\n });\n\n const response = await fetch(\n `${this.personalServerBaseUrl}${SERVER_PATHS.operations}`,\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 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 * Gets the account address from the wallet client.\n *\n * @returns The account address\n * @throws {Error} When no account is available\n */\n private getAccountAddress(): `0x${string}` {\n const client = this.context.applicationClient ?? this.context.walletClient;\n if (!client) {\n throw new Error(\"No client available for getting account address\");\n }\n\n const { account } = client;\n if (!account) {\n throw new Error(\"No account available\");\n }\n\n // Account can be either a string address or an object with an address property\n return typeof account === \"string\" ? account : account.address;\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<`0x${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 console.debug(\"🔍 Debug - createSignature account\", account);\n // Sign message using the wallet client's signMessage method\n // This works with both local accounts (private key) and JSON-RPC accounts (MetaMask, WalletConnect)\n const signature = await client.signMessage({\n account,\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,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,sBAAsB;AAC/B,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;AAIA,QAAI,MAAM,KAAK,QAAQ;AACvB,QAAI,IAAI,SAAS,SAAS,GAAG;AAC3B,YAAM,IAAI,MAAM,GAAG,EAAE;AAAA,IACvB;AACA,WAAO;AAAA,EACT;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,GAAG,aAAa,QAAQ,YAAY,QAAQ,WAAW;AAAA,QACpF;AAAA,UACE,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,gB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