@opendatalabs/vana-sdk 2.3.0 → 3.0.1
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/README.md +76 -92
- package/dist/auth/errors.cjs +54 -0
- package/dist/auth/errors.cjs.map +1 -0
- package/dist/auth/errors.d.ts +26 -0
- package/dist/auth/errors.js +28 -0
- package/dist/auth/errors.js.map +1 -0
- package/dist/auth/pkce.cjs +100 -0
- package/dist/auth/pkce.cjs.map +1 -0
- package/dist/auth/pkce.d.ts +55 -0
- package/dist/auth/pkce.js +71 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/token-store.cjs +59 -0
- package/dist/auth/token-store.cjs.map +1 -0
- package/dist/auth/token-store.d.ts +61 -0
- package/dist/auth/token-store.js +35 -0
- package/dist/auth/token-store.js.map +1 -0
- package/dist/auth/web3-signed-builder.cjs +70 -0
- package/dist/auth/web3-signed-builder.cjs.map +1 -0
- package/dist/auth/web3-signed-builder.d.ts +47 -0
- package/dist/auth/web3-signed-builder.js +45 -0
- package/dist/auth/web3-signed-builder.js.map +1 -0
- package/dist/auth/web3-signed.cjs +150 -0
- package/dist/auth/web3-signed.cjs.map +1 -0
- package/dist/auth/web3-signed.d.ts +59 -0
- package/dist/auth/web3-signed.js +129 -0
- package/dist/auth/web3-signed.js.map +1 -0
- package/dist/chains/definitions.cjs +2 -6
- package/dist/chains/definitions.cjs.map +1 -1
- package/dist/chains/definitions.d.ts +1 -7
- package/dist/chains/definitions.js +2 -6
- package/dist/chains/definitions.js.map +1 -1
- package/dist/config/chains.d.ts +18 -0
- package/dist/config/contracts.config.cjs +7 -95
- package/dist/config/contracts.config.cjs.map +1 -1
- package/dist/config/contracts.config.d.ts +0 -54
- package/dist/config/contracts.config.js +6 -93
- package/dist/config/contracts.config.js.map +1 -1
- package/dist/config/default-services.cjs +0 -10
- package/dist/config/default-services.cjs.map +1 -1
- package/dist/config/default-services.d.ts +1 -20
- package/dist/config/default-services.js +0 -9
- package/dist/config/default-services.js.map +1 -1
- package/dist/crypto/ecies/interface.cjs +2 -0
- package/dist/crypto/ecies/interface.cjs.map +1 -1
- package/dist/crypto/ecies/interface.js +2 -0
- package/dist/crypto/ecies/interface.js.map +1 -1
- package/dist/crypto/envelope/openpgp.cjs +59 -0
- package/dist/crypto/envelope/openpgp.cjs.map +1 -0
- package/dist/crypto/envelope/openpgp.d.ts +28 -0
- package/dist/crypto/envelope/openpgp.js +24 -0
- package/dist/crypto/envelope/openpgp.js.map +1 -0
- package/dist/crypto/keys/derive.cjs +65 -0
- package/dist/crypto/keys/derive.cjs.map +1 -0
- package/dist/crypto/keys/derive.d.ts +45 -0
- package/dist/crypto/keys/derive.js +38 -0
- package/dist/crypto/keys/derive.js.map +1 -0
- package/dist/errors.cjs +10 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +10 -0
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/index.cjs +2 -37
- package/dist/generated/abi/index.cjs.map +1 -1
- package/dist/generated/abi/index.d.ts +2683 -9296
- package/dist/generated/abi/index.js +2 -29
- package/dist/generated/abi/index.js.map +1 -1
- package/dist/generated/addresses.cjs +5 -107
- package/dist/generated/addresses.cjs.map +1 -1
- package/dist/generated/addresses.d.ts +5 -99
- package/dist/generated/addresses.js +5 -105
- package/dist/generated/addresses.js.map +1 -1
- package/dist/index.browser.d.ts +24 -140
- package/dist/index.browser.js +32258 -114
- package/dist/index.browser.js.map +7 -1
- package/dist/index.node.cjs +32980 -160
- package/dist/index.node.cjs.map +7 -1
- package/dist/index.node.d.ts +23 -210
- package/dist/index.node.js +32884 -133
- package/dist/index.node.js.map +7 -1
- package/dist/protocol/data-file.cjs +56 -0
- package/dist/protocol/data-file.cjs.map +1 -0
- package/dist/protocol/data-file.d.ts +20 -0
- package/dist/protocol/data-file.js +30 -0
- package/dist/protocol/data-file.js.map +1 -0
- package/dist/protocol/eip712.cjs +123 -0
- package/dist/protocol/eip712.cjs.map +1 -0
- package/dist/protocol/eip712.d.ts +117 -0
- package/dist/protocol/eip712.js +90 -0
- package/dist/protocol/eip712.js.map +1 -0
- package/dist/protocol/gateway.cjs +226 -0
- package/dist/protocol/gateway.cjs.map +1 -0
- package/dist/protocol/gateway.d.ts +120 -0
- package/dist/protocol/gateway.js +202 -0
- package/dist/protocol/gateway.js.map +1 -0
- package/dist/protocol/grants.cjs +146 -0
- package/dist/protocol/grants.cjs.map +1 -0
- package/dist/protocol/grants.d.ts +31 -0
- package/dist/protocol/grants.js +123 -0
- package/dist/protocol/grants.js.map +1 -0
- package/dist/protocol/scopes.cjs +78 -0
- package/dist/protocol/scopes.cjs.map +1 -0
- package/dist/protocol/scopes.d.ts +13 -0
- package/dist/protocol/scopes.js +50 -0
- package/dist/protocol/scopes.js.map +1 -0
- package/dist/{types/atomicStore.cjs → storage/default.cjs} +9 -8
- package/dist/storage/default.cjs.map +1 -0
- package/dist/storage/default.d.ts +4 -0
- package/dist/storage/default.js +8 -0
- package/dist/storage/default.js.map +1 -0
- package/dist/storage/index.cjs +11 -2
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.js +7 -1
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +1 -0
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.js +1 -0
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/dropbox.cjs +1 -0
- package/dist/storage/providers/dropbox.cjs.map +1 -1
- package/dist/storage/providers/dropbox.js +1 -0
- package/dist/storage/providers/dropbox.js.map +1 -1
- package/dist/storage/providers/google-drive.cjs +1 -0
- package/dist/storage/providers/google-drive.cjs.map +1 -1
- package/dist/storage/providers/google-drive.js +1 -0
- package/dist/storage/providers/google-drive.js.map +1 -1
- package/dist/storage/providers/ipfs.cjs +1 -0
- package/dist/storage/providers/ipfs.cjs.map +1 -1
- package/dist/storage/providers/ipfs.js +1 -0
- package/dist/storage/providers/ipfs.js.map +1 -1
- package/dist/storage/providers/pinata.cjs +1 -0
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.js +1 -0
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/storage/providers/r2.cjs +376 -0
- package/dist/storage/providers/r2.cjs.map +1 -0
- package/dist/storage/providers/r2.d.ts +91 -0
- package/dist/storage/providers/r2.js +354 -0
- package/dist/storage/providers/r2.js.map +1 -0
- package/dist/storage/providers/vana-storage.cjs +251 -0
- package/dist/storage/providers/vana-storage.cjs.map +1 -0
- package/dist/storage/providers/vana-storage.d.ts +100 -0
- package/dist/storage/providers/vana-storage.js +231 -0
- package/dist/storage/providers/vana-storage.js.map +1 -0
- package/dist/types/config.cjs +0 -34
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +1 -607
- package/dist/types/config.js +0 -22
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +1 -1
- package/dist/types/index.cjs +2 -33
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +2 -33
- package/dist/types/index.js +1 -35
- package/dist/types/index.js.map +1 -1
- package/dist/types/ps-errors.cjs +91 -0
- package/dist/types/ps-errors.cjs.map +1 -0
- package/dist/types/ps-errors.d.ts +26 -0
- package/dist/types/ps-errors.js +66 -0
- package/dist/types/ps-errors.js.map +1 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +0 -29
- package/dist/types.js.map +1 -1
- package/package.json +7 -25
- package/dist/client/enhancedResponse.cjs +0 -164
- package/dist/client/enhancedResponse.cjs.map +0 -1
- package/dist/client/enhancedResponse.d.ts +0 -120
- package/dist/client/enhancedResponse.js +0 -138
- package/dist/client/enhancedResponse.js.map +0 -1
- package/dist/controllers/__tests__/data-consistency-integration.test.d.ts +0 -7
- package/dist/controllers/base.cjs +0 -116
- package/dist/controllers/base.cjs.map +0 -1
- package/dist/controllers/base.d.ts +0 -94
- package/dist/controllers/base.js +0 -92
- package/dist/controllers/base.js.map +0 -1
- package/dist/controllers/data.cjs +0 -2633
- package/dist/controllers/data.cjs.map +0 -1
- package/dist/controllers/data.d.ts +0 -1067
- package/dist/controllers/data.js +0 -2626
- package/dist/controllers/data.js.map +0 -1
- package/dist/controllers/operations.cjs +0 -430
- package/dist/controllers/operations.cjs.map +0 -1
- package/dist/controllers/operations.d.ts +0 -229
- package/dist/controllers/operations.js +0 -406
- package/dist/controllers/operations.js.map +0 -1
- package/dist/controllers/permissions.cjs +0 -4368
- package/dist/controllers/permissions.cjs.map +0 -1
- package/dist/controllers/permissions.d.ts +0 -1411
- package/dist/controllers/permissions.js +0 -4344
- package/dist/controllers/permissions.js.map +0 -1
- package/dist/controllers/protocol.cjs +0 -183
- package/dist/controllers/protocol.cjs.map +0 -1
- package/dist/controllers/protocol.d.ts +0 -138
- package/dist/controllers/protocol.js +0 -163
- package/dist/controllers/protocol.js.map +0 -1
- package/dist/controllers/schemas.cjs +0 -678
- package/dist/controllers/schemas.cjs.map +0 -1
- package/dist/controllers/schemas.d.ts +0 -293
- package/dist/controllers/schemas.js +0 -654
- package/dist/controllers/schemas.js.map +0 -1
- package/dist/controllers/server.cjs +0 -643
- package/dist/controllers/server.cjs.map +0 -1
- package/dist/controllers/server.d.ts +0 -322
- package/dist/controllers/server.js +0 -624
- package/dist/controllers/server.js.map +0 -1
- package/dist/controllers/staking.cjs +0 -626
- package/dist/controllers/staking.cjs.map +0 -1
- package/dist/controllers/staking.d.ts +0 -457
- package/dist/controllers/staking.js +0 -602
- package/dist/controllers/staking.js.map +0 -1
- package/dist/core/__tests__/pollingManager.test.d.ts +0 -4
- package/dist/core/apiClient.cjs +0 -378
- package/dist/core/apiClient.cjs.map +0 -1
- package/dist/core/apiClient.d.ts +0 -286
- package/dist/core/apiClient.js +0 -359
- package/dist/core/apiClient.js.map +0 -1
- package/dist/core/generics.cjs +0 -417
- package/dist/core/generics.cjs.map +0 -1
- package/dist/core/generics.d.ts +0 -205
- package/dist/core/generics.js +0 -386
- package/dist/core/generics.js.map +0 -1
- package/dist/core/health.cjs +0 -289
- package/dist/core/health.cjs.map +0 -1
- package/dist/core/health.d.ts +0 -143
- package/dist/core/health.js +0 -265
- package/dist/core/health.js.map +0 -1
- package/dist/core/inMemoryNonceManager.cjs +0 -138
- package/dist/core/inMemoryNonceManager.cjs.map +0 -1
- package/dist/core/inMemoryNonceManager.d.ts +0 -69
- package/dist/core/inMemoryNonceManager.js +0 -114
- package/dist/core/inMemoryNonceManager.js.map +0 -1
- package/dist/core/nonceManager.cjs +0 -304
- package/dist/core/nonceManager.cjs.map +0 -1
- package/dist/core/nonceManager.d.ts +0 -116
- package/dist/core/nonceManager.js +0 -280
- package/dist/core/nonceManager.js.map +0 -1
- package/dist/core/pollingManager.cjs +0 -292
- package/dist/core/pollingManager.cjs.map +0 -1
- package/dist/core/pollingManager.d.ts +0 -120
- package/dist/core/pollingManager.js +0 -268
- package/dist/core/pollingManager.js.map +0 -1
- package/dist/core.cjs +0 -781
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -496
- package/dist/core.js +0 -756
- package/dist/core.js.map +0 -1
- package/dist/diagnostics.cjs +0 -37
- package/dist/diagnostics.cjs.map +0 -1
- package/dist/diagnostics.d.ts +0 -24
- package/dist/diagnostics.js +0 -13
- package/dist/diagnostics.js.map +0 -1
- package/dist/generated/abi/DLPPerformanceImplementation.cjs +0 -1202
- package/dist/generated/abi/DLPPerformanceImplementation.cjs.map +0 -1
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +0 -914
- package/dist/generated/abi/DLPPerformanceImplementation.js +0 -1178
- package/dist/generated/abi/DLPPerformanceImplementation.js.map +0 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs +0 -1112
- package/dist/generated/abi/DLPRewardDeployerImplementation.cjs.map +0 -1
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +0 -840
- package/dist/generated/abi/DLPRewardDeployerImplementation.js +0 -1088
- package/dist/generated/abi/DLPRewardDeployerImplementation.js.map +0 -1
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.cjs +0 -612
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.cjs.map +0 -1
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +0 -451
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.js +0 -588
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.js.map +0 -1
- package/dist/generated/abi/DLPRewardSwapImplementation.cjs +0 -939
- package/dist/generated/abi/DLPRewardSwapImplementation.cjs.map +0 -1
- package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +0 -705
- package/dist/generated/abi/DLPRewardSwapImplementation.js +0 -915
- package/dist/generated/abi/DLPRewardSwapImplementation.js.map +0 -1
- package/dist/generated/abi/DLPRootImplementation.cjs +0 -1644
- package/dist/generated/abi/DLPRootImplementation.cjs.map +0 -1
- package/dist/generated/abi/DLPRootImplementation.d.ts +0 -1246
- package/dist/generated/abi/DLPRootImplementation.js +0 -1620
- package/dist/generated/abi/DLPRootImplementation.js.map +0 -1
- package/dist/generated/abi/DataLiquidityPoolImplementation.cjs +0 -985
- package/dist/generated/abi/DataLiquidityPoolImplementation.cjs.map +0 -1
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +0 -735
- package/dist/generated/abi/DataLiquidityPoolImplementation.js +0 -961
- package/dist/generated/abi/DataLiquidityPoolImplementation.js.map +0 -1
- package/dist/generated/abi/SwapHelperImplementation.cjs +0 -976
- package/dist/generated/abi/SwapHelperImplementation.cjs.map +0 -1
- package/dist/generated/abi/SwapHelperImplementation.d.ts +0 -728
- package/dist/generated/abi/SwapHelperImplementation.js +0 -952
- package/dist/generated/abi/SwapHelperImplementation.js.map +0 -1
- package/dist/generated/abi/TeePoolImplementation.cjs +0 -1313
- package/dist/generated/abi/TeePoolImplementation.cjs.map +0 -1
- package/dist/generated/abi/TeePoolImplementation.d.ts +0 -992
- package/dist/generated/abi/TeePoolImplementation.js +0 -1289
- package/dist/generated/abi/TeePoolImplementation.js.map +0 -1
- package/dist/generated/event-types.cjs +0 -17
- package/dist/generated/event-types.cjs.map +0 -1
- package/dist/generated/event-types.d.ts +0 -816
- package/dist/generated/event-types.js +0 -1
- package/dist/generated/event-types.js.map +0 -1
- package/dist/generated/eventRegistry.cjs +0 -4512
- package/dist/generated/eventRegistry.cjs.map +0 -1
- package/dist/generated/eventRegistry.d.ts +0 -14
- package/dist/generated/eventRegistry.js +0 -4487
- package/dist/generated/eventRegistry.js.map +0 -1
- package/dist/generated/server/server-exports.cjs +0 -45
- package/dist/generated/server/server-exports.cjs.map +0 -1
- package/dist/generated/server/server-exports.d.ts +0 -36
- package/dist/generated/server/server-exports.js +0 -19
- package/dist/generated/server/server-exports.js.map +0 -1
- package/dist/generated/server/server.cjs +0 -17
- package/dist/generated/server/server.cjs.map +0 -1
- package/dist/generated/server/server.d.ts +0 -907
- package/dist/generated/server/server.js +0 -1
- package/dist/generated/server/server.js.map +0 -1
- package/dist/generated/subgraph.cjs +0 -1440
- package/dist/generated/subgraph.cjs.map +0 -1
- package/dist/generated/subgraph.d.ts +0 -6113
- package/dist/generated/subgraph.js +0 -1404
- package/dist/generated/subgraph.js.map +0 -1
- package/dist/lib/__tests__/redisAtomicStore.test.d.ts +0 -1
- package/dist/lib/redisAtomicStore.cjs +0 -201
- package/dist/lib/redisAtomicStore.cjs.map +0 -1
- package/dist/lib/redisAtomicStore.d.ts +0 -120
- package/dist/lib/redisAtomicStore.js +0 -177
- package/dist/lib/redisAtomicStore.js.map +0 -1
- package/dist/server/relayerHandler.cjs +0 -452
- package/dist/server/relayerHandler.cjs.map +0 -1
- package/dist/server/relayerHandler.d.ts +0 -69
- package/dist/server/relayerHandler.js +0 -428
- package/dist/server/relayerHandler.js.map +0 -1
- package/dist/tests/abi.test.d.ts +0 -1
- package/dist/tests/chains-definitions.test.d.ts +0 -1
- package/dist/tests/core-encryption.test.d.ts +0 -1
- package/dist/tests/core-extended.test.d.ts +0 -1
- package/dist/tests/core-generics-coverage.test.d.ts +0 -1
- package/dist/tests/coverage-boost.test.d.ts +0 -1
- package/dist/tests/crypto-cross-platform-compatibility.test.d.ts +0 -1
- package/dist/tests/data-addfile-permissions-schema.test.d.ts +0 -1
- package/dist/tests/data-additional-methods.test.d.ts +0 -1
- package/dist/tests/data-controller-edge-cases.test.d.ts +0 -1
- package/dist/tests/data-ipfs-gateways.test.d.ts +0 -1
- package/dist/tests/data-relayer.test.d.ts +0 -1
- package/dist/tests/data-schema-validation.test.d.ts +0 -1
- package/dist/tests/data-simple-methods.test.d.ts +0 -1
- package/dist/tests/data-upload-owner-validation.test.d.ts +0 -1
- package/dist/tests/data.test.d.ts +0 -1
- package/dist/tests/demo-integration.test.d.ts +0 -1
- package/dist/tests/demo-trusted-server-integration.test.d.ts +0 -1
- package/dist/tests/download-relayer.test.d.ts +0 -1
- package/dist/tests/dual-mode-permissions.test.d.ts +0 -1
- package/dist/tests/dual-mode-trusted-servers.test.d.ts +0 -1
- package/dist/tests/encryption-correct-implementation.test.d.ts +0 -1
- package/dist/tests/encryption-coverage.test.d.ts +0 -1
- package/dist/tests/encryption-edge-cases.test.d.ts +0 -1
- package/dist/tests/encryption-utils-updated.test.d.ts +0 -1
- package/dist/tests/errors-coverage.test.d.ts +0 -1
- package/dist/tests/factories/mockFactory.d.ts +0 -316
- package/dist/tests/fakes/FakeStorageManager.d.ts +0 -200
- package/dist/tests/fakes/FakeStorageManager.test.d.ts +0 -1
- package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +0 -170
- package/dist/tests/fakes/FakeWaitForTransactionEvents.test.d.ts +0 -1
- package/dist/tests/fakes/fake-pgp-port.d.ts +0 -13
- package/dist/tests/grantValidation-edge-cases.test.d.ts +0 -1
- package/dist/tests/grantValidation-unreachable-branch.test.d.ts +0 -1
- package/dist/tests/helper-methods.test.d.ts +0 -1
- package/dist/tests/helpers/typedMocks.d.ts +0 -64
- package/dist/tests/index-browser.test.d.ts +0 -1
- package/dist/tests/index-node.test.d.ts +0 -1
- package/dist/tests/index.test.d.ts +0 -1
- package/dist/tests/mocks/platformAdapter.d.ts +0 -12
- package/dist/tests/new-permissions-methods.test.d.ts +0 -1
- package/dist/tests/no-buffer-browser.test.d.ts +0 -1
- package/dist/tests/permissions-grantee.test.d.ts +0 -1
- package/dist/tests/permissions-revoke-relayer.test.d.ts +0 -1
- package/dist/tests/permissions-schema-validation.test.d.ts +0 -1
- package/dist/tests/permissions-server-files.test.d.ts +0 -1
- package/dist/tests/permissions-transaction-options.test.d.ts +0 -1
- package/dist/tests/permissions-trust-servers.test.d.ts +0 -1
- package/dist/tests/permissions.test.d.ts +0 -1
- package/dist/tests/personal.test.d.ts +0 -1
- package/dist/tests/platform-browser.test.d.ts +0 -1
- package/dist/tests/platform-crypto-expanded.test.d.ts +0 -1
- package/dist/tests/platform-crypto.test.d.ts +0 -1
- package/dist/tests/platform-index.test.d.ts +0 -1
- package/dist/tests/platform-node.test.d.ts +0 -1
- package/dist/tests/platform-shared-utils.test.d.ts +0 -1
- package/dist/tests/platform-updated.test.d.ts +0 -1
- package/dist/tests/protocol-additional-methods.test.d.ts +0 -1
- package/dist/tests/protocol.test.d.ts +0 -1
- package/dist/tests/read-only-mode.test.d.ts +0 -1
- package/dist/tests/relayer-integration.test.d.ts +0 -1
- package/dist/tests/relayer-unified.test.d.ts +0 -1
- package/dist/tests/schemas.test.d.ts +0 -1
- package/dist/tests/server-relayer-handler.test.d.ts +0 -1
- package/dist/tests/signatureFormatter.test.d.ts +0 -1
- package/dist/tests/staking.test.d.ts +0 -1
- package/dist/tests/trusted-server-queries.test.d.ts +0 -1
- package/dist/tests/typedDataConverter.test.d.ts +0 -1
- package/dist/tests/types-contracts.test.d.ts +0 -1
- package/dist/tests/types-data.test.d.ts +0 -1
- package/dist/tests/types-external-apis.test.d.ts +0 -1
- package/dist/tests/types-generics.test.d.ts +0 -1
- package/dist/tests/types-permissions.test.d.ts +0 -1
- package/dist/tests/types-upload-params.test.d.ts +0 -1
- package/dist/tests/types.test.d.ts +0 -1
- package/dist/tests/utils-formatters.test.d.ts +0 -1
- package/dist/tests/utils-grantFiles-edge-cases.test.d.ts +0 -1
- package/dist/tests/utils-grantFiles-validation.test.d.ts +0 -1
- package/dist/tests/utils-grantFiles.test.d.ts +0 -1
- package/dist/tests/utils-grantValidation-consolidated.test.d.ts +0 -1
- package/dist/tests/utils-grants.test.d.ts +0 -1
- package/dist/tests/utils-ipfs-additional.test.d.ts +0 -1
- package/dist/tests/utils-ipfs.test.d.ts +0 -4
- package/dist/tests/utils-schemaValidation.test.d.ts +0 -1
- package/dist/tests/vana.test.d.ts +0 -1
- package/dist/tests/wallet-crypto-compatibility.test.d.ts +0 -1
- package/dist/types/atomicStore.cjs.map +0 -1
- package/dist/types/atomicStore.d.ts +0 -236
- package/dist/types/atomicStore.js +0 -7
- package/dist/types/atomicStore.js.map +0 -1
- package/dist/types/blockchain.cjs +0 -17
- package/dist/types/blockchain.cjs.map +0 -1
- package/dist/types/blockchain.d.ts +0 -85
- package/dist/types/blockchain.js +0 -1
- package/dist/types/blockchain.js.map +0 -1
- package/dist/types/controller-context.cjs +0 -17
- package/dist/types/controller-context.cjs.map +0 -1
- package/dist/types/controller-context.d.ts +0 -68
- package/dist/types/controller-context.js +0 -1
- package/dist/types/controller-context.js.map +0 -1
- package/dist/types/data.cjs +0 -17
- package/dist/types/data.cjs.map +0 -1
- package/dist/types/data.d.ts +0 -763
- package/dist/types/data.js +0 -1
- package/dist/types/data.js.map +0 -1
- package/dist/types/external-apis.cjs +0 -61
- package/dist/types/external-apis.cjs.map +0 -1
- package/dist/types/external-apis.d.ts +0 -184
- package/dist/types/external-apis.js +0 -34
- package/dist/types/external-apis.js.map +0 -1
- package/dist/types/generics.cjs +0 -17
- package/dist/types/generics.cjs.map +0 -1
- package/dist/types/generics.d.ts +0 -518
- package/dist/types/generics.js +0 -1
- package/dist/types/generics.js.map +0 -1
- package/dist/types/operationStore.cjs +0 -17
- package/dist/types/operationStore.cjs.map +0 -1
- package/dist/types/operationStore.d.ts +0 -171
- package/dist/types/operationStore.js +0 -1
- package/dist/types/operationStore.js.map +0 -1
- package/dist/types/operations.cjs +0 -53
- package/dist/types/operations.cjs.map +0 -1
- package/dist/types/operations.d.ts +0 -204
- package/dist/types/operations.js +0 -26
- package/dist/types/operations.js.map +0 -1
- package/dist/types/options.cjs +0 -17
- package/dist/types/options.cjs.map +0 -1
- package/dist/types/options.d.ts +0 -308
- package/dist/types/options.js +0 -1
- package/dist/types/options.js.map +0 -1
- package/dist/types/permissions.cjs +0 -17
- package/dist/types/permissions.cjs.map +0 -1
- package/dist/types/permissions.d.ts +0 -955
- package/dist/types/permissions.js +0 -1
- package/dist/types/permissions.js.map +0 -1
- package/dist/types/personal.cjs +0 -17
- package/dist/types/personal.cjs.map +0 -1
- package/dist/types/personal.d.ts +0 -174
- package/dist/types/personal.js +0 -1
- package/dist/types/personal.js.map +0 -1
- package/dist/types/relayer.cjs +0 -17
- package/dist/types/relayer.cjs.map +0 -1
- package/dist/types/relayer.d.ts +0 -552
- package/dist/types/relayer.js +0 -1
- package/dist/types/relayer.js.map +0 -1
- package/dist/types/transactionResults.cjs +0 -17
- package/dist/types/transactionResults.cjs.map +0 -1
- package/dist/types/transactionResults.d.ts +0 -193
- package/dist/types/transactionResults.js +0 -1
- package/dist/types/transactionResults.js.map +0 -1
- package/dist/types/utils.cjs +0 -17
- package/dist/types/utils.cjs.map +0 -1
- package/dist/types/utils.d.ts +0 -771
- package/dist/types/utils.js +0 -1
- package/dist/types/utils.js.map +0 -1
- package/dist/utils/__tests__/chainQuery.test.d.ts +0 -1
- package/dist/utils/__tests__/parseTransaction.test.d.ts +0 -1
- package/dist/utils/__tests__/pojo-serialization.test.d.ts +0 -1
- package/dist/utils/__tests__/signatureCache.test.d.ts +0 -1
- package/dist/utils/__tests__/subgraphConsistency.test.d.ts +0 -4
- package/dist/utils/__tests__/subgraphPagination.test.d.ts +0 -4
- package/dist/utils/__tests__/transaction-edge-cases.test.d.ts +0 -1
- package/dist/utils/__tests__/transactionHelpers.test.d.ts +0 -1
- package/dist/utils/__tests__/urlResolver.test.d.ts +0 -4
- package/dist/utils/blockchain/registry.cjs +0 -81
- package/dist/utils/blockchain/registry.cjs.map +0 -1
- package/dist/utils/blockchain/registry.d.ts +0 -32
- package/dist/utils/blockchain/registry.js +0 -56
- package/dist/utils/blockchain/registry.js.map +0 -1
- package/dist/utils/blockchain/registry.test.d.ts +0 -1
- package/dist/utils/chainQuery.cjs +0 -107
- package/dist/utils/chainQuery.cjs.map +0 -1
- package/dist/utils/chainQuery.d.ts +0 -31
- package/dist/utils/chainQuery.js +0 -82
- package/dist/utils/chainQuery.js.map +0 -1
- package/dist/utils/download.cjs +0 -69
- package/dist/utils/download.cjs.map +0 -1
- package/dist/utils/download.d.ts +0 -40
- package/dist/utils/download.js +0 -45
- package/dist/utils/download.js.map +0 -1
- package/dist/utils/encryption.cjs +0 -176
- package/dist/utils/encryption.cjs.map +0 -1
- package/dist/utils/encryption.d.ts +0 -271
- package/dist/utils/encryption.js +0 -142
- package/dist/utils/encryption.js.map +0 -1
- package/dist/utils/formatters.cjs +0 -55
- package/dist/utils/formatters.cjs.map +0 -1
- package/dist/utils/formatters.d.ts +0 -118
- package/dist/utils/formatters.js +0 -28
- package/dist/utils/formatters.js.map +0 -1
- package/dist/utils/grantFiles.cjs +0 -181
- package/dist/utils/grantFiles.cjs.map +0 -1
- package/dist/utils/grantFiles.d.ts +0 -172
- package/dist/utils/grantFiles.js +0 -143
- package/dist/utils/grantFiles.js.map +0 -1
- package/dist/utils/grantValidation.cjs +0 -243
- package/dist/utils/grantValidation.cjs.map +0 -1
- package/dist/utils/grantValidation.d.ts +0 -226
- package/dist/utils/grantValidation.js +0 -201
- package/dist/utils/grantValidation.js.map +0 -1
- package/dist/utils/grants.cjs +0 -108
- package/dist/utils/grants.cjs.map +0 -1
- package/dist/utils/grants.d.ts +0 -148
- package/dist/utils/grants.js +0 -82
- package/dist/utils/grants.js.map +0 -1
- package/dist/utils/ipfs.cjs +0 -128
- package/dist/utils/ipfs.cjs.map +0 -1
- package/dist/utils/ipfs.d.ts +0 -88
- package/dist/utils/ipfs.js +0 -97
- package/dist/utils/ipfs.js.map +0 -1
- package/dist/utils/multicall.cjs +0 -233
- package/dist/utils/multicall.cjs.map +0 -1
- package/dist/utils/multicall.d.ts +0 -126
- package/dist/utils/multicall.js +0 -208
- package/dist/utils/multicall.js.map +0 -1
- package/dist/utils/parseTransactionPojo.cjs +0 -87
- package/dist/utils/parseTransactionPojo.cjs.map +0 -1
- package/dist/utils/parseTransactionPojo.d.ts +0 -31
- package/dist/utils/parseTransactionPojo.js +0 -63
- package/dist/utils/parseTransactionPojo.js.map +0 -1
- package/dist/utils/schemaValidation.cjs +0 -258
- package/dist/utils/schemaValidation.cjs.map +0 -1
- package/dist/utils/schemaValidation.d.ts +0 -168
- package/dist/utils/schemaValidation.js +0 -219
- package/dist/utils/schemaValidation.js.map +0 -1
- package/dist/utils/signatureCache.cjs +0 -192
- package/dist/utils/signatureCache.cjs.map +0 -1
- package/dist/utils/signatureCache.d.ts +0 -172
- package/dist/utils/signatureCache.js +0 -167
- package/dist/utils/signatureCache.js.map +0 -1
- package/dist/utils/signatureFormatter.cjs +0 -42
- package/dist/utils/signatureFormatter.cjs.map +0 -1
- package/dist/utils/signatureFormatter.d.ts +0 -36
- package/dist/utils/signatureFormatter.js +0 -18
- package/dist/utils/signatureFormatter.js.map +0 -1
- package/dist/utils/subgraphConsistency.cjs +0 -184
- package/dist/utils/subgraphConsistency.cjs.map +0 -1
- package/dist/utils/subgraphConsistency.d.ts +0 -65
- package/dist/utils/subgraphConsistency.js +0 -155
- package/dist/utils/subgraphConsistency.js.map +0 -1
- package/dist/utils/subgraphMetaCache.cjs +0 -101
- package/dist/utils/subgraphMetaCache.cjs.map +0 -1
- package/dist/utils/subgraphMetaCache.d.ts +0 -56
- package/dist/utils/subgraphMetaCache.js +0 -76
- package/dist/utils/subgraphMetaCache.js.map +0 -1
- package/dist/utils/subgraphPagination.cjs +0 -104
- package/dist/utils/subgraphPagination.cjs.map +0 -1
- package/dist/utils/subgraphPagination.d.ts +0 -78
- package/dist/utils/subgraphPagination.js +0 -78
- package/dist/utils/subgraphPagination.js.map +0 -1
- package/dist/utils/tests/multicall.test.d.ts +0 -1
- package/dist/utils/transactionHelpers.cjs +0 -54
- package/dist/utils/transactionHelpers.cjs.map +0 -1
- package/dist/utils/transactionHelpers.d.ts +0 -80
- package/dist/utils/transactionHelpers.js +0 -29
- package/dist/utils/transactionHelpers.js.map +0 -1
- package/dist/utils/typeGuards.cjs +0 -109
- package/dist/utils/typeGuards.cjs.map +0 -1
- package/dist/utils/typeGuards.d.ts +0 -138
- package/dist/utils/typeGuards.js +0 -74
- package/dist/utils/typeGuards.js.map +0 -1
- package/dist/utils/typedDataConverter.cjs +0 -43
- package/dist/utils/typedDataConverter.cjs.map +0 -1
- package/dist/utils/typedDataConverter.d.ts +0 -46
- package/dist/utils/typedDataConverter.js +0 -19
- package/dist/utils/typedDataConverter.js.map +0 -1
- package/dist/utils/urlResolver.cjs +0 -62
- package/dist/utils/urlResolver.cjs.map +0 -1
- package/dist/utils/urlResolver.d.ts +0 -56
- package/dist/utils/urlResolver.js +0 -37
- package/dist/utils/urlResolver.js.map +0 -1
- package/dist/utils/wallet.cjs +0 -63
- package/dist/utils/wallet.cjs.map +0 -1
- package/dist/utils/wallet.d.ts +0 -94
- package/dist/utils/wallet.js +0 -37
- package/dist/utils/wallet.js.map +0 -1
- package/dist/utils/withEvents.cjs +0 -44
- package/dist/utils/withEvents.cjs.map +0 -1
- package/dist/utils/withEvents.d.ts +0 -56
- package/dist/utils/withEvents.js +0 -18
- package/dist/utils/withEvents.js.map +0 -1
- /package/dist/{__tests__/waitForTransactionEvents.test.d.ts → auth/pkce.test.d.ts} +0 -0
- /package/dist/{client/__tests__/enhancedResponse.test.d.ts → auth/token-store.test.d.ts} +0 -0
- /package/dist/{controllers/__tests__/operations.processQueue.test.d.ts → auth/web3-signed.test.d.ts} +0 -0
- /package/dist/{controllers/__tests__/schemas-edge-cases.test.d.ts → crypto/envelope/openpgp.test.d.ts} +0 -0
- /package/dist/{controllers/data-error-handling.test.d.ts → crypto/keys/derive.test.d.ts} +0 -0
- /package/dist/{tests/errors.test.d.ts → errors.test.d.ts} +0 -0
- /package/dist/{controllers/server-additional.test.d.ts → protocol/data-file.test.d.ts} +0 -0
- /package/dist/{core/__tests__/health.test.d.ts → protocol/eip712.test.d.ts} +0 -0
- /package/dist/{core/__tests__/inMemoryNonceManager.test.d.ts → protocol/gateway.test.d.ts} +0 -0
- /package/dist/{core/__tests__/nonceManager.test.d.ts → protocol/grants.test.d.ts} +0 -0
- /package/dist/{core/core.test.d.ts → protocol/scopes.test.d.ts} +0 -0
- /package/dist/{core/tests/apiClient.test.d.ts → storage/tests/defaultStorage.test.d.ts} +0 -0
- /package/dist/{core/tests/client.test.d.ts → storage/tests/r2Storage.test.d.ts} +0 -0
- /package/dist/{core/tests/generics.test.d.ts → storage/tests/vanaStorage.test.d.ts} +0 -0
- /package/dist/{diagnostics.test.d.ts → types/ps-errors.test.d.ts} +0 -0
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import type { GrantFile, GrantPermissionParams } from "../types/permissions";
|
|
2
|
-
/**
|
|
3
|
-
* Creates grant file structure for permission storage.
|
|
4
|
-
*
|
|
5
|
-
* @remarks
|
|
6
|
-
* Constructs JSON structure that represents a permission grant
|
|
7
|
-
* in the Vana protocol. The grant file contains all necessary information
|
|
8
|
-
* for a grantee to perform operations on behalf of the grantor.
|
|
9
|
-
*
|
|
10
|
-
* @param params - Permission parameters to create the grant file from
|
|
11
|
-
* @returns Grant file object for IPFS storage
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const grant = createGrantFile({
|
|
16
|
-
* grantee: '0x742d35Cc...',
|
|
17
|
-
* operation: 'llm_inference',
|
|
18
|
-
* parameters: { model: 'gpt-4' },
|
|
19
|
-
* expiresAt: Date.now() + 86400000 // 24 hours
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function createGrantFile(params: GrantPermissionParams): GrantFile;
|
|
24
|
-
/**
|
|
25
|
-
* Stores a grant file in IPFS via the relayer service.
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* This function uploads the grant file to IPFS through the relayer's upload endpoint.
|
|
29
|
-
* The returned URL can be stored on-chain as part of the permission grant, allowing
|
|
30
|
-
* anyone to retrieve the detailed permission parameters later.
|
|
31
|
-
*
|
|
32
|
-
* @param grantFile - The grant file to store
|
|
33
|
-
* @param relayerUrl - URL of the relayer service
|
|
34
|
-
* @returns Promise resolving to the IPFS URL
|
|
35
|
-
* @throws {NetworkError} When the upload fails or relayer is unavailable
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* const grantFile = createGrantFile(params);
|
|
39
|
-
*
|
|
40
|
-
* try {
|
|
41
|
-
* const ipfsUrl = await storeGrantFile(grantFile, 'https://relayer.vana.com');
|
|
42
|
-
* console.log(`Grant file stored at: ${ipfsUrl}`);
|
|
43
|
-
* // ipfsUrl: "ipfs://QmHash123..."
|
|
44
|
-
* } catch (error) {
|
|
45
|
-
* console.error('Failed to store grant file:', error);
|
|
46
|
-
* }
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
export declare function storeGrantFile(grantFile: GrantFile, relayerUrl: string): Promise<string>;
|
|
50
|
-
/**
|
|
51
|
-
* Retrieves detailed grant file data from IPFS or HTTP storage.
|
|
52
|
-
*
|
|
53
|
-
* @remarks
|
|
54
|
-
* **This is Step 2 of the performant two-step permission API.**
|
|
55
|
-
*
|
|
56
|
-
* Use this method to resolve detailed permission data (operation, parameters, etc.)
|
|
57
|
-
* for specific grants after first getting the fast on-chain data using
|
|
58
|
-
* `getUserPermissionGrantsOnChain()`. This design eliminates N+1 query problems
|
|
59
|
-
* by allowing selective lazy-loading of expensive off-chain data.
|
|
60
|
-
*
|
|
61
|
-
* **Performance**: Single network request per grant file (typically 100-500ms).
|
|
62
|
-
* **Reliability**: Tries multiple IPFS gateways as fallbacks if primary URL fails.
|
|
63
|
-
*
|
|
64
|
-
* @param grantUrl - The grant file URL from OnChainPermissionGrant.grantUrl
|
|
65
|
-
* @param _relayerUrl - URL of the relayer service (optional, unused)
|
|
66
|
-
* @param downloadRelayer - Optional download relayer for proxying CORS-restricted downloads
|
|
67
|
-
* @param downloadRelayer.proxyDownload - Function to proxy download requests through application server
|
|
68
|
-
* @returns Promise resolving to the complete grant file with operation details
|
|
69
|
-
* @throws {NetworkError} When all retrieval attempts fail
|
|
70
|
-
* @throws {SerializationError} When grant file format is invalid
|
|
71
|
-
* @example
|
|
72
|
-
* ```typescript
|
|
73
|
-
* // Step 1: Fast on-chain data (no N+1 queries)
|
|
74
|
-
* const grants = await vana.permissions.getUserPermissionGrantsOnChain();
|
|
75
|
-
*
|
|
76
|
-
* // Step 2: Lazy-load details for specific grant when needed
|
|
77
|
-
* const grantFile = await retrieveGrantFile(grants[0].grantUrl);
|
|
78
|
-
*
|
|
79
|
-
* console.log(`Operation: ${grantFile.operation}`);
|
|
80
|
-
* console.log(`Grantee: ${grantFile.grantee}`);
|
|
81
|
-
* console.log(`Parameters:`, grantFile.parameters);
|
|
82
|
-
*
|
|
83
|
-
* // Only fetch details for grants user actually wants to see
|
|
84
|
-
* for (const grant of selectedGrants) {
|
|
85
|
-
* const details = await retrieveGrantFile(grant.grantUrl);
|
|
86
|
-
* displayGrantDetails(details);
|
|
87
|
-
* }
|
|
88
|
-
* ```
|
|
89
|
-
*/
|
|
90
|
-
export declare function retrieveGrantFile(grantUrl: string, _relayerUrl?: string, downloadRelayer?: {
|
|
91
|
-
proxyDownload: (url: string) => Promise<Blob>;
|
|
92
|
-
}): Promise<GrantFile>;
|
|
93
|
-
/**
|
|
94
|
-
* Generates a content hash for a grant file.
|
|
95
|
-
* This can be used for integrity verification.
|
|
96
|
-
*
|
|
97
|
-
* @remarks
|
|
98
|
-
* Creates a deterministic keccak256 hash of the grant file by first sorting
|
|
99
|
-
* all object keys recursively to ensure consistent hashing regardless of
|
|
100
|
-
* property order. This hash can be used to verify grant file integrity
|
|
101
|
-
* or as a unique identifier.
|
|
102
|
-
*
|
|
103
|
-
* @param grantFile - The grant file to generate a hash for
|
|
104
|
-
* @returns The keccak256 hash of the grant file as a hex string
|
|
105
|
-
* @throws {SerializationError} When the grant file cannot be serialized
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const grantFile = {
|
|
109
|
-
* grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',
|
|
110
|
-
* operation: 'read',
|
|
111
|
-
* parameters: { version: '1.0', mode: 'full' }
|
|
112
|
-
* };
|
|
113
|
-
*
|
|
114
|
-
* const hash = getGrantFileHash(grantFile);
|
|
115
|
-
* console.log(`Grant file hash: ${hash}`);
|
|
116
|
-
* // "0x1234567890abcdef..."
|
|
117
|
-
*
|
|
118
|
-
* // Same grant file with different property order produces same hash
|
|
119
|
-
* const grantFile2 = {
|
|
120
|
-
* operation: 'read',
|
|
121
|
-
* parameters: { mode: 'full', version: '1.0' },
|
|
122
|
-
* grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36'
|
|
123
|
-
* };
|
|
124
|
-
*
|
|
125
|
-
* const hash2 = getGrantFileHash(grantFile2);
|
|
126
|
-
* console.log(hash === hash2); // true
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
export declare function getGrantFileHash(grantFile: GrantFile): string;
|
|
130
|
-
/**
|
|
131
|
-
* Validates that a grant file has the required structure.
|
|
132
|
-
*
|
|
133
|
-
* @remarks
|
|
134
|
-
* Performs runtime validation to ensure data conforms to the GrantFile interface.
|
|
135
|
-
* Checks for required fields (grantee, operation, parameters) and validates their
|
|
136
|
-
* types and formats. This is a type guard function that enables TypeScript to
|
|
137
|
-
* narrow the type when it returns true.
|
|
138
|
-
*
|
|
139
|
-
* @param data - The data to validate as a grant file
|
|
140
|
-
* @returns True if the data is a valid grant file, false otherwise
|
|
141
|
-
* @example
|
|
142
|
-
* ```typescript
|
|
143
|
-
* const unknownData = await fetch(url).then(r => r.json());
|
|
144
|
-
*
|
|
145
|
-
* if (validateGrantFile(unknownData)) {
|
|
146
|
-
* // TypeScript now knows unknownData is a GrantFile
|
|
147
|
-
* console.log(`Grant for operation: ${unknownData.operation}`);
|
|
148
|
-
* console.log(`Grantee: ${unknownData.grantee}`);
|
|
149
|
-
* } else {
|
|
150
|
-
* throw new Error('Invalid grant file format');
|
|
151
|
-
* }
|
|
152
|
-
*
|
|
153
|
-
* // Validation examples:
|
|
154
|
-
* validateGrantFile({
|
|
155
|
-
* grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',
|
|
156
|
-
* operation: 'read',
|
|
157
|
-
* parameters: {}
|
|
158
|
-
* }); // true
|
|
159
|
-
*
|
|
160
|
-
* validateGrantFile({
|
|
161
|
-
* grantee: 'invalid-address',
|
|
162
|
-
* operation: 'read',
|
|
163
|
-
* parameters: {}
|
|
164
|
-
* }); // false (invalid address format)
|
|
165
|
-
*
|
|
166
|
-
* validateGrantFile({
|
|
167
|
-
* operation: 'read',
|
|
168
|
-
* parameters: {}
|
|
169
|
-
* }); // false (missing grantee)
|
|
170
|
-
* ```
|
|
171
|
-
*/
|
|
172
|
-
export declare function validateGrantFile(data: unknown): data is GrantFile;
|
package/dist/utils/grantFiles.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { keccak256, toHex } from "viem";
|
|
2
|
-
import { SerializationError, NetworkError } from "../errors";
|
|
3
|
-
function createGrantFile(params) {
|
|
4
|
-
const grantFile = {
|
|
5
|
-
grantee: params.grantee,
|
|
6
|
-
operation: params.operation,
|
|
7
|
-
parameters: { ...params.parameters }
|
|
8
|
-
};
|
|
9
|
-
if (params.filters) {
|
|
10
|
-
grantFile.parameters.filters = params.filters;
|
|
11
|
-
}
|
|
12
|
-
if (params.expiresAt) {
|
|
13
|
-
grantFile.expires = params.expiresAt;
|
|
14
|
-
}
|
|
15
|
-
return grantFile;
|
|
16
|
-
}
|
|
17
|
-
async function storeGrantFile(grantFile, relayerUrl) {
|
|
18
|
-
try {
|
|
19
|
-
const grantFileBlob = new Blob([JSON.stringify(grantFile, null, 2)], {
|
|
20
|
-
type: "application/json"
|
|
21
|
-
});
|
|
22
|
-
const formData = new FormData();
|
|
23
|
-
formData.append("file", grantFileBlob, "grant-file.json");
|
|
24
|
-
const response = await fetch(`${relayerUrl}/api/ipfs/upload`, {
|
|
25
|
-
method: "POST",
|
|
26
|
-
body: formData
|
|
27
|
-
});
|
|
28
|
-
if (!response.ok) {
|
|
29
|
-
throw new NetworkError(
|
|
30
|
-
`Failed to store grant file: ${response.statusText}`,
|
|
31
|
-
new Error(`HTTP ${response.status}`)
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
const responseData = await response.json();
|
|
35
|
-
const data = responseData;
|
|
36
|
-
if (!data.success) {
|
|
37
|
-
throw new NetworkError(data.error ?? "Failed to store grant file");
|
|
38
|
-
}
|
|
39
|
-
if (!data.url) {
|
|
40
|
-
throw new NetworkError("Upload succeeded but no URL was returned");
|
|
41
|
-
}
|
|
42
|
-
return data.url;
|
|
43
|
-
} catch (error) {
|
|
44
|
-
if (error instanceof NetworkError) {
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
throw new NetworkError(
|
|
48
|
-
`Network error while storing grant file: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
49
|
-
error
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
async function retrieveGrantFile(grantUrl, _relayerUrl, downloadRelayer) {
|
|
54
|
-
try {
|
|
55
|
-
if (grantUrl.startsWith("http") && grantUrl.includes("/ipfs/")) {
|
|
56
|
-
console.warn(
|
|
57
|
-
`\u26A0\uFE0F Grant URL uses HTTP gateway format instead of ipfs:// protocol. Found: ${grantUrl}. Consider using ipfs:// format for better protocol-agnostic storage.`
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
const { universalFetch } = await import("./download");
|
|
61
|
-
const response = await universalFetch(grantUrl, downloadRelayer);
|
|
62
|
-
if (!response.ok) {
|
|
63
|
-
throw new NetworkError(
|
|
64
|
-
`Failed to retrieve grant file: HTTP ${response.status}`
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
const text = await response.text();
|
|
68
|
-
const grantFile = JSON.parse(text);
|
|
69
|
-
if (!validateGrantFile(grantFile)) {
|
|
70
|
-
throw new NetworkError(`Invalid grant file format from ${grantUrl}`);
|
|
71
|
-
}
|
|
72
|
-
return grantFile;
|
|
73
|
-
} catch (error) {
|
|
74
|
-
if (error instanceof NetworkError) {
|
|
75
|
-
throw error;
|
|
76
|
-
}
|
|
77
|
-
throw new NetworkError(
|
|
78
|
-
`Error retrieving grant file: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
79
|
-
error
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function getGrantFileHash(grantFile) {
|
|
84
|
-
try {
|
|
85
|
-
const sortedFile = {
|
|
86
|
-
grantee: grantFile.grantee,
|
|
87
|
-
operation: grantFile.operation,
|
|
88
|
-
parameters: sortObjectKeys(grantFile.parameters)
|
|
89
|
-
};
|
|
90
|
-
if (grantFile.expires !== void 0) {
|
|
91
|
-
sortedFile.expires = grantFile.expires;
|
|
92
|
-
}
|
|
93
|
-
const jsonString = JSON.stringify(sortedFile);
|
|
94
|
-
console.info(`Hash: ${keccak256(toHex(jsonString))}`);
|
|
95
|
-
return keccak256(toHex(jsonString));
|
|
96
|
-
} catch (error) {
|
|
97
|
-
throw new SerializationError(
|
|
98
|
-
`Failed to generate grant file hash: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function sortObjectKeys(obj) {
|
|
103
|
-
if (obj === null || typeof obj !== "object") {
|
|
104
|
-
return obj;
|
|
105
|
-
}
|
|
106
|
-
if (Array.isArray(obj)) {
|
|
107
|
-
return obj.map((item) => sortObjectKeys(item));
|
|
108
|
-
}
|
|
109
|
-
const sortedObj = {};
|
|
110
|
-
Object.keys(obj).sort().forEach((key) => {
|
|
111
|
-
sortedObj[key] = sortObjectKeys(obj[key]);
|
|
112
|
-
});
|
|
113
|
-
return sortedObj;
|
|
114
|
-
}
|
|
115
|
-
function validateGrantFile(data) {
|
|
116
|
-
if (!data || typeof data !== "object") {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
const obj = data;
|
|
120
|
-
if (typeof obj.grantee !== "string" || !obj.grantee.match(/^0x[a-fA-F0-9]{40}$/)) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
if (typeof obj.operation !== "string" || obj.operation.length === 0) {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
if (!obj.parameters || typeof obj.parameters !== "object") {
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
if (obj.expires !== void 0) {
|
|
130
|
-
if (typeof obj.expires !== "number" || obj.expires < 0 || !Number.isInteger(obj.expires)) {
|
|
131
|
-
return false;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
export {
|
|
137
|
-
createGrantFile,
|
|
138
|
-
getGrantFileHash,
|
|
139
|
-
retrieveGrantFile,
|
|
140
|
-
storeGrantFile,
|
|
141
|
-
validateGrantFile
|
|
142
|
-
};
|
|
143
|
-
//# sourceMappingURL=grantFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/grantFiles.ts"],"sourcesContent":["import { keccak256, toHex } from \"viem\";\nimport type { GrantFile, GrantPermissionParams } from \"../types/permissions\";\nimport { SerializationError, NetworkError } from \"../errors\";\n\ninterface GrantFileStorageResponse {\n success: boolean;\n error?: string;\n url?: string;\n}\n\n/**\n * Creates grant file structure for permission storage.\n *\n * @remarks\n * Constructs JSON structure that represents a permission grant\n * in the Vana protocol. The grant file contains all necessary information\n * for a grantee to perform operations on behalf of the grantor.\n *\n * @param params - Permission parameters to create the grant file from\n * @returns Grant file object for IPFS storage\n *\n * @example\n * ```typescript\n * const grant = createGrantFile({\n * grantee: '0x742d35Cc...',\n * operation: 'llm_inference',\n * parameters: { model: 'gpt-4' },\n * expiresAt: Date.now() + 86400000 // 24 hours\n * });\n * ```\n */\nexport function createGrantFile(params: GrantPermissionParams): GrantFile {\n const grantFile: GrantFile = {\n grantee: params.grantee,\n operation: params.operation,\n parameters: { ...params.parameters },\n };\n\n // Add filters to parameters if provided\n if (params.filters) {\n grantFile.parameters.filters = params.filters;\n }\n\n // Add expiration if provided\n if (params.expiresAt) {\n grantFile.expires = params.expiresAt;\n }\n\n return grantFile;\n}\n\n/**\n * Stores a grant file in IPFS via the relayer service.\n *\n * @remarks\n * This function uploads the grant file to IPFS through the relayer's upload endpoint.\n * The returned URL can be stored on-chain as part of the permission grant, allowing\n * anyone to retrieve the detailed permission parameters later.\n *\n * @param grantFile - The grant file to store\n * @param relayerUrl - URL of the relayer service\n * @returns Promise resolving to the IPFS URL\n * @throws {NetworkError} When the upload fails or relayer is unavailable\n * @example\n * ```typescript\n * const grantFile = createGrantFile(params);\n *\n * try {\n * const ipfsUrl = await storeGrantFile(grantFile, 'https://relayer.vana.com');\n * console.log(`Grant file stored at: ${ipfsUrl}`);\n * // ipfsUrl: \"ipfs://QmHash123...\"\n * } catch (error) {\n * console.error('Failed to store grant file:', error);\n * }\n * ```\n */\nexport async function storeGrantFile(\n grantFile: GrantFile,\n relayerUrl: string,\n): Promise<string> {\n try {\n // Convert grant file to blob and use IPFS upload endpoint\n const grantFileBlob = new Blob([JSON.stringify(grantFile, null, 2)], {\n type: \"application/json\",\n });\n\n const formData = new FormData();\n formData.append(\"file\", grantFileBlob, \"grant-file.json\");\n\n const response = await fetch(`${relayerUrl}/api/ipfs/upload`, {\n method: \"POST\",\n body: formData,\n });\n\n if (!response.ok) {\n throw new NetworkError(\n `Failed to store grant file: ${response.statusText}`,\n new Error(`HTTP ${response.status}`),\n );\n }\n\n const responseData: unknown = await response.json();\n const data = responseData as GrantFileStorageResponse;\n\n if (!data.success) {\n throw new NetworkError(data.error ?? \"Failed to store grant file\");\n }\n\n if (!data.url) {\n throw new NetworkError(\"Upload succeeded but no URL was returned\");\n }\n return data.url; // The IPFS URL from the upload response\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Network error while storing grant file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error as Error,\n );\n }\n}\n\n/**\n * Retrieves detailed grant file data from IPFS or HTTP storage.\n *\n * @remarks\n * **This is Step 2 of the performant two-step permission API.**\n *\n * Use this method to resolve detailed permission data (operation, parameters, etc.)\n * for specific grants after first getting the fast on-chain data using\n * `getUserPermissionGrantsOnChain()`. This design eliminates N+1 query problems\n * by allowing selective lazy-loading of expensive off-chain data.\n *\n * **Performance**: Single network request per grant file (typically 100-500ms).\n * **Reliability**: Tries multiple IPFS gateways as fallbacks if primary URL fails.\n *\n * @param grantUrl - The grant file URL from OnChainPermissionGrant.grantUrl\n * @param _relayerUrl - URL of the relayer service (optional, unused)\n * @param downloadRelayer - Optional download relayer for proxying CORS-restricted downloads\n * @param downloadRelayer.proxyDownload - Function to proxy download requests through application server\n * @returns Promise resolving to the complete grant file with operation details\n * @throws {NetworkError} When all retrieval attempts fail\n * @throws {SerializationError} When grant file format is invalid\n * @example\n * ```typescript\n * // Step 1: Fast on-chain data (no N+1 queries)\n * const grants = await vana.permissions.getUserPermissionGrantsOnChain();\n *\n * // Step 2: Lazy-load details for specific grant when needed\n * const grantFile = await retrieveGrantFile(grants[0].grantUrl);\n *\n * console.log(`Operation: ${grantFile.operation}`);\n * console.log(`Grantee: ${grantFile.grantee}`);\n * console.log(`Parameters:`, grantFile.parameters);\n *\n * // Only fetch details for grants user actually wants to see\n * for (const grant of selectedGrants) {\n * const details = await retrieveGrantFile(grant.grantUrl);\n * displayGrantDetails(details);\n * }\n * ```\n */\nexport async function retrieveGrantFile(\n grantUrl: string,\n _relayerUrl?: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<GrantFile> {\n try {\n // Check if the URL is a gateway URL instead of ipfs:// protocol\n if (grantUrl.startsWith(\"http\") && grantUrl.includes(\"/ipfs/\")) {\n console.warn(\n `⚠️ Grant URL uses HTTP gateway format instead of ipfs:// protocol. ` +\n `Found: ${grantUrl}. ` +\n `Consider using ipfs:// format for better protocol-agnostic storage.`,\n );\n }\n\n // Use the unified download utility\n const { universalFetch } = await import(\"./download\");\n const response = await universalFetch(grantUrl, downloadRelayer);\n\n if (!response.ok) {\n throw new NetworkError(\n `Failed to retrieve grant file: HTTP ${response.status}`,\n );\n }\n\n const text = await response.text();\n const grantFile = JSON.parse(text);\n\n if (!validateGrantFile(grantFile)) {\n throw new NetworkError(`Invalid grant file format from ${grantUrl}`);\n }\n\n return grantFile;\n } catch (error) {\n if (error instanceof NetworkError) {\n throw error;\n }\n throw new NetworkError(\n `Error retrieving grant file: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error as Error,\n );\n }\n}\n\n/**\n * Generates a content hash for a grant file.\n * This can be used for integrity verification.\n *\n * @remarks\n * Creates a deterministic keccak256 hash of the grant file by first sorting\n * all object keys recursively to ensure consistent hashing regardless of\n * property order. This hash can be used to verify grant file integrity\n * or as a unique identifier.\n *\n * @param grantFile - The grant file to generate a hash for\n * @returns The keccak256 hash of the grant file as a hex string\n * @throws {SerializationError} When the grant file cannot be serialized\n * @example\n * ```typescript\n * const grantFile = {\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'read',\n * parameters: { version: '1.0', mode: 'full' }\n * };\n *\n * const hash = getGrantFileHash(grantFile);\n * console.log(`Grant file hash: ${hash}`);\n * // \"0x1234567890abcdef...\"\n *\n * // Same grant file with different property order produces same hash\n * const grantFile2 = {\n * operation: 'read',\n * parameters: { mode: 'full', version: '1.0' },\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36'\n * };\n *\n * const hash2 = getGrantFileHash(grantFile2);\n * console.log(hash === hash2); // true\n * ```\n */\nexport function getGrantFileHash(grantFile: GrantFile): string {\n try {\n // Create a stable JSON representation\n const sortedFile: GrantFile = {\n grantee: grantFile.grantee,\n operation: grantFile.operation,\n parameters: sortObjectKeys(grantFile.parameters) as Record<\n string,\n unknown\n >,\n };\n\n // Add expires if present\n if (grantFile.expires !== undefined) {\n sortedFile.expires = grantFile.expires;\n }\n\n const jsonString = JSON.stringify(sortedFile);\n console.info(`Hash: ${keccak256(toHex(jsonString))}`);\n return keccak256(toHex(jsonString));\n } catch (error) {\n throw new SerializationError(\n `Failed to generate grant file hash: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n}\n\n/**\n * Recursively sorts object keys for stable serialization.\n *\n * @param obj - The object to sort keys recursively\n * @returns The object with all keys sorted recursively\n */\nfunction sortObjectKeys(obj: unknown): unknown {\n if (obj === null || typeof obj !== \"object\") {\n return obj;\n }\n\n if (Array.isArray(obj)) {\n return obj.map((item) => sortObjectKeys(item));\n }\n\n const sortedObj: Record<string, unknown> = {};\n Object.keys(obj as Record<string, unknown>)\n .sort()\n .forEach((key) => {\n sortedObj[key] = sortObjectKeys((obj as Record<string, unknown>)[key]);\n });\n\n return sortedObj;\n}\n\n/**\n * Validates that a grant file has the required structure.\n *\n * @remarks\n * Performs runtime validation to ensure data conforms to the GrantFile interface.\n * Checks for required fields (grantee, operation, parameters) and validates their\n * types and formats. This is a type guard function that enables TypeScript to\n * narrow the type when it returns true.\n *\n * @param data - The data to validate as a grant file\n * @returns True if the data is a valid grant file, false otherwise\n * @example\n * ```typescript\n * const unknownData = await fetch(url).then(r => r.json());\n *\n * if (validateGrantFile(unknownData)) {\n * // TypeScript now knows unknownData is a GrantFile\n * console.log(`Grant for operation: ${unknownData.operation}`);\n * console.log(`Grantee: ${unknownData.grantee}`);\n * } else {\n * throw new Error('Invalid grant file format');\n * }\n *\n * // Validation examples:\n * validateGrantFile({\n * grantee: '0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36',\n * operation: 'read',\n * parameters: {}\n * }); // true\n *\n * validateGrantFile({\n * grantee: 'invalid-address',\n * operation: 'read',\n * parameters: {}\n * }); // false (invalid address format)\n *\n * validateGrantFile({\n * operation: 'read',\n * parameters: {}\n * }); // false (missing grantee)\n * ```\n */\nexport function validateGrantFile(data: unknown): data is GrantFile {\n if (!data || typeof data !== \"object\") {\n return false;\n }\n\n const obj = data as Record<string, unknown>;\n\n // Validate required fields\n // Validate grantee address\n if (\n typeof obj.grantee !== \"string\" ||\n !obj.grantee.match(/^0x[a-fA-F0-9]{40}$/)\n ) {\n return false;\n }\n\n if (typeof obj.operation !== \"string\" || obj.operation.length === 0) {\n return false;\n }\n\n // Files are no longer stored in grant files - they're tracked in the contract\n\n if (!obj.parameters || typeof obj.parameters !== \"object\") {\n return false;\n }\n\n // Validate optional expires field\n if (obj.expires !== undefined) {\n if (\n typeof obj.expires !== \"number\" ||\n obj.expires < 0 ||\n !Number.isInteger(obj.expires)\n ) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":"AAAA,SAAS,WAAW,aAAa;AAEjC,SAAS,oBAAoB,oBAAoB;AA6B1C,SAAS,gBAAgB,QAA0C;AACxE,QAAM,YAAuB;AAAA,IAC3B,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,YAAY,EAAE,GAAG,OAAO,WAAW;AAAA,EACrC;AAGA,MAAI,OAAO,SAAS;AAClB,cAAU,WAAW,UAAU,OAAO;AAAA,EACxC;AAGA,MAAI,OAAO,WAAW;AACpB,cAAU,UAAU,OAAO;AAAA,EAC7B;AAEA,SAAO;AACT;AA2BA,eAAsB,eACpB,WACA,YACiB;AACjB,MA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,MAAkC;AAClE,MAAI,CAAC,QAAQ,OAAO,SAAS,UAAU;AACrC,WAAO;AAAA,EACT;AAEA,QAAM,MAAM;AAIZ,MACE,OAAO,IAAI,YAAY,YACvB,CAAC,IAAI,QAAQ,MAAM,qBAAqB,GACxC;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,IAAI,cAAc,YAAY,IAAI,UAAU,WAAW,GAAG;AACnE,WAAO;AAAA,EACT;AAIA,MAAI,CAAC,IAAI,cAAc,OAAO,IAAI,eAAe,UAAU;AACzD,WAAO;AAAA,EACT;AAGA,MAAI,IAAI,YAAY,QAAW;AAC7B,QACE,OAAO,IAAI,YAAY,YACvB,IAAI,UAAU,KACd,CAAC,OAAO,UAAU,IAAI,OAAO,GAC7B;AACA,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var grantValidation_exports = {};
|
|
30
|
-
__export(grantValidation_exports, {
|
|
31
|
-
GrantExpiredError: () => GrantExpiredError,
|
|
32
|
-
GrantSchemaError: () => GrantSchemaError,
|
|
33
|
-
GrantValidationError: () => GrantValidationError,
|
|
34
|
-
GranteeMismatchError: () => GranteeMismatchError,
|
|
35
|
-
OperationNotAllowedError: () => OperationNotAllowedError,
|
|
36
|
-
validateGrant: () => validateGrant,
|
|
37
|
-
validateGrantExpiry: () => validateGrantExpiry,
|
|
38
|
-
validateGranteeAccess: () => validateGranteeAccess,
|
|
39
|
-
validateOperationAccess: () => validateOperationAccess
|
|
40
|
-
});
|
|
41
|
-
module.exports = __toCommonJS(grantValidation_exports);
|
|
42
|
-
var import_viem = require("viem");
|
|
43
|
-
var import_ajv = __toESM(require("ajv"), 1);
|
|
44
|
-
var import_ajv_formats = __toESM(require("ajv-formats"), 1);
|
|
45
|
-
var import_grantFile_schema = __toESM(require("../schemas/grantFile.schema.json"), 1);
|
|
46
|
-
class GrantValidationError extends Error {
|
|
47
|
-
constructor(message, details) {
|
|
48
|
-
super(message);
|
|
49
|
-
this.details = details;
|
|
50
|
-
this.name = "GrantValidationError";
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
class GrantExpiredError extends GrantValidationError {
|
|
54
|
-
constructor(message, expires, currentTime) {
|
|
55
|
-
super(message, { expires, currentTime });
|
|
56
|
-
this.expires = expires;
|
|
57
|
-
this.currentTime = currentTime;
|
|
58
|
-
this.name = "GrantExpiredError";
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
class GranteeMismatchError extends GrantValidationError {
|
|
62
|
-
constructor(message, grantee, requestingAddress) {
|
|
63
|
-
super(message, { grantee, requestingAddress });
|
|
64
|
-
this.grantee = grantee;
|
|
65
|
-
this.requestingAddress = requestingAddress;
|
|
66
|
-
this.name = "GranteeMismatchError";
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
class OperationNotAllowedError extends GrantValidationError {
|
|
70
|
-
constructor(message, grantedOperation, requestedOperation) {
|
|
71
|
-
super(message, { grantedOperation, requestedOperation });
|
|
72
|
-
this.grantedOperation = grantedOperation;
|
|
73
|
-
this.requestedOperation = requestedOperation;
|
|
74
|
-
this.name = "OperationNotAllowedError";
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
class GrantSchemaError extends GrantValidationError {
|
|
78
|
-
constructor(message, schemaErrors, invalidData) {
|
|
79
|
-
super(message, { errors: schemaErrors, data: invalidData });
|
|
80
|
-
this.schemaErrors = schemaErrors;
|
|
81
|
-
this.invalidData = invalidData;
|
|
82
|
-
this.name = "GrantSchemaError";
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const ajv = new import_ajv.default({
|
|
86
|
-
strict: true,
|
|
87
|
-
removeAdditional: false,
|
|
88
|
-
useDefaults: false,
|
|
89
|
-
coerceTypes: false
|
|
90
|
-
});
|
|
91
|
-
(0, import_ajv_formats.default)(ajv);
|
|
92
|
-
const validateGrantFileSchema = ajv.compile(import_grantFile_schema.default);
|
|
93
|
-
function validateGrant(data, options = {}) {
|
|
94
|
-
const {
|
|
95
|
-
schema = true,
|
|
96
|
-
grantee,
|
|
97
|
-
operation,
|
|
98
|
-
currentTime,
|
|
99
|
-
throwOnError = true
|
|
100
|
-
} = options;
|
|
101
|
-
const errors = [];
|
|
102
|
-
let grant;
|
|
103
|
-
if (schema) {
|
|
104
|
-
try {
|
|
105
|
-
if (validateGrantFileSchema(data)) {
|
|
106
|
-
grant = data;
|
|
107
|
-
} else {
|
|
108
|
-
throw new GrantValidationError("Invalid grant file schema");
|
|
109
|
-
}
|
|
110
|
-
} catch (error) {
|
|
111
|
-
if (error instanceof GrantValidationError) {
|
|
112
|
-
const schemaError = new GrantSchemaError(
|
|
113
|
-
error.message,
|
|
114
|
-
Array.isArray(error.details?.errors) ? error.details.errors : [],
|
|
115
|
-
data
|
|
116
|
-
);
|
|
117
|
-
errors.push({
|
|
118
|
-
type: "schema",
|
|
119
|
-
message: error.message,
|
|
120
|
-
error: schemaError
|
|
121
|
-
});
|
|
122
|
-
} else {
|
|
123
|
-
errors.push({
|
|
124
|
-
type: "schema",
|
|
125
|
-
message: `Schema validation failed: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
126
|
-
error: error instanceof Error ? error : new Error("Unknown error")
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} else {
|
|
131
|
-
grant = data;
|
|
132
|
-
}
|
|
133
|
-
if (grant) {
|
|
134
|
-
if (grantee) {
|
|
135
|
-
try {
|
|
136
|
-
validateGranteeAccess(grant, grantee);
|
|
137
|
-
} catch (error) {
|
|
138
|
-
const field = extractFieldFromBusinessError(error);
|
|
139
|
-
errors.push({
|
|
140
|
-
type: "business",
|
|
141
|
-
field,
|
|
142
|
-
message: error instanceof Error ? error.message : "Unknown business rule error",
|
|
143
|
-
error: error instanceof Error ? error : new Error("Unknown error")
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
try {
|
|
148
|
-
validateGrantExpiry(grant, currentTime);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
const field = extractFieldFromBusinessError(error);
|
|
151
|
-
errors.push({
|
|
152
|
-
type: "business",
|
|
153
|
-
field,
|
|
154
|
-
message: error instanceof Error ? error.message : "Unknown business rule error",
|
|
155
|
-
error: error instanceof Error ? error : new Error("Unknown error")
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
if (operation) {
|
|
159
|
-
try {
|
|
160
|
-
validateOperationAccess(grant, operation);
|
|
161
|
-
} catch (error) {
|
|
162
|
-
const field = extractFieldFromBusinessError(error);
|
|
163
|
-
errors.push({
|
|
164
|
-
type: "business",
|
|
165
|
-
field,
|
|
166
|
-
message: error instanceof Error ? error.message : "Unknown business rule error",
|
|
167
|
-
error: error instanceof Error ? error : new Error("Unknown error")
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
if (errors.length > 0) {
|
|
173
|
-
if (throwOnError) {
|
|
174
|
-
const firstError = errors[0];
|
|
175
|
-
if (firstError.error) {
|
|
176
|
-
throw firstError.error;
|
|
177
|
-
} else {
|
|
178
|
-
const combinedMessage = errors.map((e) => e.message).join("; ");
|
|
179
|
-
throw new GrantValidationError(
|
|
180
|
-
`Grant validation failed: ${combinedMessage}`,
|
|
181
|
-
{ errors, data }
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return { valid: false, errors, grant };
|
|
186
|
-
}
|
|
187
|
-
if (throwOnError) {
|
|
188
|
-
return grant;
|
|
189
|
-
} else {
|
|
190
|
-
return { valid: true, errors: [], grant };
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
function extractFieldFromBusinessError(error) {
|
|
194
|
-
if (error instanceof GrantExpiredError) return "expires";
|
|
195
|
-
if (error instanceof GranteeMismatchError) return "grantee";
|
|
196
|
-
if (error instanceof OperationNotAllowedError) return "operation";
|
|
197
|
-
return void 0;
|
|
198
|
-
}
|
|
199
|
-
function validateGranteeAccess(grantFile, requestingAddress) {
|
|
200
|
-
const normalizedGrantee = (0, import_viem.getAddress)(grantFile.grantee);
|
|
201
|
-
const normalizedRequesting = (0, import_viem.getAddress)(requestingAddress);
|
|
202
|
-
if (normalizedGrantee !== normalizedRequesting) {
|
|
203
|
-
throw new GranteeMismatchError(
|
|
204
|
-
"Permission denied: requesting address does not match grantee",
|
|
205
|
-
grantFile.grantee,
|
|
206
|
-
requestingAddress
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function validateGrantExpiry(grantFile, currentTime) {
|
|
211
|
-
if (grantFile.expires) {
|
|
212
|
-
const now = currentTime !== void 0 ? currentTime : Math.floor(Date.now() / 1e3);
|
|
213
|
-
if (now > grantFile.expires) {
|
|
214
|
-
throw new GrantExpiredError(
|
|
215
|
-
"Permission denied: grant has expired",
|
|
216
|
-
grantFile.expires,
|
|
217
|
-
now
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
function validateOperationAccess(grantFile, requestedOperation) {
|
|
223
|
-
if (grantFile.operation !== requestedOperation) {
|
|
224
|
-
throw new OperationNotAllowedError(
|
|
225
|
-
"Permission denied: operation not allowed by grant",
|
|
226
|
-
grantFile.operation,
|
|
227
|
-
requestedOperation
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
232
|
-
0 && (module.exports = {
|
|
233
|
-
GrantExpiredError,
|
|
234
|
-
GrantSchemaError,
|
|
235
|
-
GrantValidationError,
|
|
236
|
-
GranteeMismatchError,
|
|
237
|
-
OperationNotAllowedError,
|
|
238
|
-
validateGrant,
|
|
239
|
-
validateGrantExpiry,
|
|
240
|
-
validateGranteeAccess,
|
|
241
|
-
validateOperationAccess
|
|
242
|
-
});
|
|
243
|
-
//# sourceMappingURL=grantValidation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/grantValidation.ts"],"sourcesContent":["/**\n * Provides comprehensive validation for permission grant files.\n *\n * @remarks\n * This module implements multi-layer validation for grant files including\n * JSON schema validation, business rule checking, expiration verification,\n * and access control validation. It provides both throwing and non-throwing\n * modes for flexible error handling.\n *\n * @category Permissions\n * @module utils/grantValidation\n */\n\nimport type { Address } from \"viem\";\nimport { getAddress } from \"viem\";\nimport Ajv, { type ValidateFunction } from \"ajv\";\nimport addFormats from \"ajv-formats\";\nimport type { GrantFile } from \"../types/permissions\";\nimport grantFileSchema from \"../schemas/grantFile.schema.json\";\n\n/**\n * Indicates a general grant validation failure.\n *\n * @remarks\n * Base class for all grant validation errors. Provides structured\n * error details for debugging and recovery.\n *\n * @category Permissions\n */\nexport class GrantValidationError extends Error {\n constructor(\n message: string,\n public details?: Record<string, unknown>,\n ) {\n super(message);\n this.name = \"GrantValidationError\";\n }\n}\n\n/**\n * Indicates that a grant has expired and is no longer valid.\n *\n * @remarks\n * Thrown when attempting to use a grant past its expiration timestamp.\n * Includes both the expiration time and current time for debugging.\n *\n * @category Permissions\n */\nexport class GrantExpiredError extends GrantValidationError {\n constructor(\n message: string,\n public expires: number,\n public currentTime: number,\n ) {\n super(message, { expires, currentTime });\n this.name = \"GrantExpiredError\";\n }\n}\n\n/**\n * Indicates that the requesting address doesn't match the grant's grantee.\n *\n * @remarks\n * Thrown when a user attempts to use a grant that was issued to a\n * different address. This prevents unauthorized use of permissions.\n *\n * @category Permissions\n */\nexport class GranteeMismatchError extends GrantValidationError {\n constructor(\n message: string,\n public grantee: Address,\n public requestingAddress: Address,\n ) {\n super(message, { grantee, requestingAddress });\n this.name = \"GranteeMismatchError\";\n }\n}\n\n/**\n * Indicates that the requested operation is not allowed by the grant.\n *\n * @remarks\n * Thrown when attempting an operation that differs from what the\n * grant authorizes. Includes both granted and requested operations.\n *\n * @category Permissions\n */\nexport class OperationNotAllowedError extends GrantValidationError {\n constructor(\n message: string,\n public grantedOperation: string,\n public requestedOperation: string,\n ) {\n super(message, { grantedOperation, requestedOperation });\n this.name = \"OperationNotAllowedError\";\n }\n}\n\n/**\n * Indicates that the grant file structure violates the JSON schema.\n *\n * @remarks\n * Thrown when a grant file doesn't conform to the expected schema.\n * Includes detailed schema validation errors and the invalid data.\n *\n * @category Permissions\n */\nexport class GrantSchemaError extends GrantValidationError {\n constructor(\n message: string,\n public schemaErrors: unknown[],\n public invalidData: unknown,\n ) {\n super(message, { errors: schemaErrors, data: invalidData });\n this.name = \"GrantSchemaError\";\n }\n}\n\n/**\n * Ajv instance configured for strict grant file validation.\n *\n * @internal\n */\nconst ajv = new Ajv({\n strict: true,\n removeAdditional: false,\n useDefaults: false,\n coerceTypes: false,\n});\n\n// Add format validators (email, date, etc.)\naddFormats(ajv);\n\n/**\n * Pre-compiled grant file schema validator for performance.\n *\n * @internal\n */\nconst validateGrantFileSchema: ValidateFunction = ajv.compile(grantFileSchema);\n\n/**\n * Configures grant validation behavior and scope.\n *\n * @remarks\n * Controls which validations to perform and how to handle errors.\n * Allows selective validation of specific aspects of a grant.\n *\n * @category Permissions\n */\nexport interface GrantValidationOptions {\n /** Enable JSON schema validation (default: true) */\n schema?: boolean;\n /** Grantee address to validate access for */\n grantee?: Address;\n /** Operation to validate permission for */\n operation?: string;\n /** Override current time for expiry checking (Unix timestamp) */\n currentTime?: number;\n /** Return detailed results instead of throwing (default: false) */\n throwOnError?: boolean;\n}\n\n/**\n * Represents the detailed result of grant validation.\n *\n * @remarks\n * Provides comprehensive validation results including all errors\n * encountered during validation. Used in non-throwing mode.\n *\n * @category Permissions\n */\nexport interface GrantValidationResult {\n /** Whether validation passed */\n valid: boolean;\n /** Validation errors encountered */\n errors: Array<{\n type: \"schema\" | \"business\";\n field?: string;\n message: string;\n error?: Error;\n }>;\n /** The validated grant file (if validation passed) */\n grant?: GrantFile;\n}\n\n/**\n * Validates a grant file with comprehensive schema and business rule checking.\n *\n * This function provides flexible validation with TypeScript overloads:\n * - When `throwOnError` is false (or `{ throwOnError: false }`), returns a detailed validation result\n * - When `throwOnError` is true (default), throws specific errors or returns the validated grant\n *\n * @param data - The grant file data to validate (unknown type for safety)\n * @param options - Validation options including grantee, operation, files, etc.\n * @returns Either a GrantFile (when throwing) or GrantValidationResult (when not throwing)\n * @throws {GrantSchemaError} When the grant file structure is invalid\n * @throws {GrantExpiredError} When the grant has expired\n * @throws {GranteeMismatchError} When the grantee doesn't match the requesting address\n * @throws {OperationNotAllowedError} When the requested operation is not allowed\n * @example\n * ```typescript\n * // Throwing mode (default) - returns GrantFile or throws\n * const grant = validateGrant(data, {\n * grantee: '0x123...',\n * operation: 'llm_inference',\n * });\n *\n * // Non-throwing mode - returns validation result\n * const result = validateGrant(data, {\n * grantee: '0x123...',\n * throwOnError: false\n * });\n * if (result.valid) {\n * console.log('Grant is valid:', result.grant);\n * } else {\n * console.log('Validation errors:', result.errors);\n * }\n * ```\n */\n\nexport function validateGrant(\n data: unknown,\n options: GrantValidationOptions & { throwOnError: false },\n): GrantValidationResult;\n\nexport function validateGrant(\n data: unknown,\n options?:\n | Omit<GrantValidationOptions, \"throwOnError\">\n | (GrantValidationOptions & { throwOnError?: true }),\n): GrantFile;\n\n/** @internal */\nexport function validateGrant(\n data: unknown,\n options: GrantValidationOptions = {},\n): GrantFile | GrantValidationResult {\n const {\n schema = true,\n grantee,\n operation,\n currentTime,\n throwOnError = true,\n } = options;\n\n const errors: GrantValidationResult[\"errors\"] = [];\n let grant: GrantFile | undefined;\n\n // 1. Schema Validation\n if (schema) {\n try {\n if (validateGrantFileSchema(data)) {\n grant = data as GrantFile;\n } else {\n throw new GrantValidationError(\"Invalid grant file schema\");\n }\n } catch (error) {\n if (error instanceof GrantValidationError) {\n const schemaError = new GrantSchemaError(\n error.message,\n Array.isArray(error.details?.errors) ? error.details.errors : [],\n data,\n );\n errors.push({\n type: \"schema\",\n message: error.message,\n error: schemaError,\n });\n } else {\n errors.push({\n type: \"schema\",\n message: `Schema validation failed: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n error: error instanceof Error ? error : new Error(\"Unknown error\"),\n });\n }\n }\n } else {\n // Minimal type assertion if schema validation is skipped\n grant = data as GrantFile;\n }\n\n // 2. Business Logic Validation (only if we have a valid grant)\n if (grant) {\n // Check grantee access\n if (grantee) {\n try {\n validateGranteeAccess(grant, grantee);\n } catch (error) {\n const field = extractFieldFromBusinessError(error);\n errors.push({\n type: \"business\",\n field,\n message:\n error instanceof Error\n ? error.message\n : \"Unknown business rule error\",\n error: error instanceof Error ? error : new Error(\"Unknown error\"),\n });\n }\n }\n\n // Check expiration\n try {\n validateGrantExpiry(grant, currentTime);\n } catch (error) {\n const field = extractFieldFromBusinessError(error);\n errors.push({\n type: \"business\",\n field,\n message:\n error instanceof Error\n ? error.message\n : \"Unknown business rule error\",\n error: error instanceof Error ? error : new Error(\"Unknown error\"),\n });\n }\n\n // Check operation access\n if (operation) {\n try {\n validateOperationAccess(grant, operation);\n } catch (error) {\n const field = extractFieldFromBusinessError(error);\n errors.push({\n type: \"business\",\n field,\n message:\n error instanceof Error\n ? error.message\n : \"Unknown business rule error\",\n error: error instanceof Error ? error : new Error(\"Unknown error\"),\n });\n }\n }\n }\n\n // 3. Return Results\n if (errors.length > 0) {\n if (throwOnError) {\n // Throw the most specific error we have\n const firstError = errors[0];\n if (firstError.error) {\n throw firstError.error;\n } else {\n const combinedMessage = errors.map((e) => e.message).join(\"; \");\n throw new GrantValidationError(\n `Grant validation failed: ${combinedMessage}`,\n { errors, data },\n );\n }\n }\n\n return { valid: false, errors, grant };\n }\n\n if (throwOnError) {\n return grant as GrantFile;\n } else {\n return { valid: true, errors: [], grant: grant as GrantFile };\n }\n}\n\n/**\n * Extracts the field name from business validation errors for reporting.\n *\n * @param error - The validation error to analyze\n * @returns The field name associated with the error, or undefined\n *\n * @internal\n */\nfunction extractFieldFromBusinessError(error: unknown): string | undefined {\n if (error instanceof GrantExpiredError) return \"expires\";\n if (error instanceof GranteeMismatchError) return \"grantee\";\n if (error instanceof OperationNotAllowedError) return \"operation\";\n return undefined;\n}\n\n/**\n * Validates that a grant allows access for the requesting address.\n *\n * @param grantFile - The grant file to validate.\n * Obtain from permission operations or server responses.\n * @param requestingAddress - The address requesting access.\n * Typically the current wallet address.\n *\n * @throws {GranteeMismatchError} If addresses don't match.\n * Ensure using the correct wallet that received the grant.\n *\n * @example\n * ```typescript\n * validateGranteeAccess(grantFile, walletAddress);\n * // Throws if walletAddress doesn't match grantFile.grantee\n * ```\n *\n * @category Permissions\n */\nexport function validateGranteeAccess(\n grantFile: GrantFile,\n requestingAddress: Address,\n): void {\n const normalizedGrantee = getAddress(grantFile.grantee);\n const normalizedRequesting = getAddress(requestingAddress);\n\n if (normalizedGrantee !== normalizedRequesting) {\n throw new GranteeMismatchError(\n \"Permission denied: requesting address does not match grantee\",\n grantFile.grantee,\n requestingAddress,\n );\n }\n}\n\n/**\n * Validates that a grant has not expired.\n *\n * @param grantFile - The grant file to check.\n * Must include expiry timestamp if time-limited.\n * @param currentTime - Optional time override for testing.\n * Unix timestamp in seconds. Defaults to current time.\n *\n * @throws {GrantExpiredError} If grant has expired.\n * Request a new grant from the data owner.\n *\n * @example\n * ```typescript\n * validateGrantExpiry(grantFile);\n * // Throws if current time > grantFile.expires\n * ```\n *\n * @category Permissions\n */\nexport function validateGrantExpiry(\n grantFile: GrantFile,\n currentTime?: number,\n): void {\n if (grantFile.expires) {\n const now =\n currentTime !== undefined ? currentTime : Math.floor(Date.now() / 1000); // Current Unix timestamp\n\n if (now > grantFile.expires) {\n throw new GrantExpiredError(\n \"Permission denied: grant has expired\",\n grantFile.expires,\n now,\n );\n }\n }\n}\n\n/**\n * Validates that a grant authorizes the requested operation.\n *\n * @param grantFile - The grant file to check.\n * Contains the authorized operation.\n * @param requestedOperation - The operation to validate.\n * Must match the grant's operation exactly.\n *\n * @throws {OperationNotAllowedError} If operations don't match.\n * Request a grant for the specific operation needed.\n *\n * @example\n * ```typescript\n * validateOperationAccess(grantFile, 'llm_inference');\n * // Throws if grantFile.operation !== 'llm_inference'\n * ```\n *\n * @category Permissions\n */\nexport function validateOperationAccess(\n grantFile: GrantFile,\n requestedOperation: string,\n): void {\n if (grantFile.operation !== requestedOperation) {\n throw new OperationNotAllowedError(\n \"Permission denied: operation not allowed by grant\",\n grantFile.operation,\n requestedOperation,\n );\n }\n}\n"],"mappings":";;;;;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