@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
package/README.md
CHANGED
|
@@ -1,122 +1,106 @@
|
|
|
1
1
|
# Vana SDK
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
TypeScript primitives for building on Vana — smart-contract bindings, ECIES
|
|
4
|
+
encryption, storage providers, and a shared isomorphic platform layer.
|
|
4
5
|
|
|
5
6
|
[](https://www.npmjs.com/package/@opendatalabs/vana-sdk)
|
|
6
7
|
[](https://www.npmjs.com/package/@opendatalabs/vana-sdk)
|
|
7
8
|
[](https://opensource.org/licenses/ISC)
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
> **Heads up — minimal scaffold.** As of `3.x` the SDK has been pared down
|
|
11
|
+
> to the primitives the new Vana protocol architecture builds on. The
|
|
12
|
+
> previous high-level API (`Vana(...)` factory, `vana.permissions`,
|
|
13
|
+
> `vana.data`, subgraph queries, personal-server client, DLP rewards) is
|
|
14
|
+
> **not part of this release.** If you need that surface, pin to
|
|
15
|
+
> [`@opendatalabs/vana-sdk@^2.3.0`](https://www.npmjs.com/package/@opendatalabs/vana-sdk/v/2.3.0)
|
|
16
|
+
> or check out the [`legacy-pre-unification`](https://github.com/vana-com/vana-sdk/tree/legacy-pre-unification)
|
|
17
|
+
> tag.
|
|
18
|
+
|
|
19
|
+
## What's in the box
|
|
20
|
+
|
|
21
|
+
- **Smart-contract bindings** — `getContractController`, `getContractInfo`,
|
|
22
|
+
`getAbi`, `getContractAddress`, plus the `CONTRACTS` and `VanaContract`
|
|
23
|
+
registries auto-generated from on-chain discovery.
|
|
24
|
+
- **Chain configurations** — `vanaMainnet`, `mokshaTestnet` (alias `moksha`),
|
|
25
|
+
`getChainConfig`, `getAllChains`, plus the lower-level viem `chains` map.
|
|
26
|
+
- **ECIES crypto** — audited (HashCloak, 2025) ECIES implementation with
|
|
27
|
+
matched browser and Node providers, byte-identical across platforms and
|
|
28
|
+
with strict KDF/MAC validation.
|
|
29
|
+
- **Storage providers** — `StorageManager`, `IpfsStorage`, `PinataStorage`,
|
|
30
|
+
`GoogleDriveStorage`, `DropboxStorage`, `CallbackStorage`.
|
|
31
|
+
- **Platform adapters** — `NodePlatformAdapter` and `BrowserPlatformAdapter`
|
|
32
|
+
with a shared `VanaPlatformAdapter` interface, plus detection helpers
|
|
33
|
+
(`detectPlatform`, `isPlatformSupported`, `createPlatformAdapter`,
|
|
34
|
+
`createPlatformAdapterSafe`).
|
|
35
|
+
- **JSON protocol schemas** — `dataSchema.schema.json` and
|
|
36
|
+
`grantFile.schema.json`, shipped under `dist/schemas/`.
|
|
37
|
+
|
|
38
|
+
## Install
|
|
14
39
|
|
|
15
40
|
```bash
|
|
16
41
|
npm install @opendatalabs/vana-sdk viem
|
|
17
42
|
```
|
|
18
43
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Choose the build for your environment:
|
|
22
|
-
|
|
23
|
-
**Browser:**
|
|
44
|
+
The SDK ships separate browser and Node bundles. Pick the entry point that
|
|
45
|
+
matches your runtime:
|
|
24
46
|
|
|
25
47
|
```typescript
|
|
26
|
-
|
|
27
|
-
import {
|
|
48
|
+
// Browser / web app
|
|
49
|
+
import { BrowserPlatformAdapter } from "@opendatalabs/vana-sdk/browser";
|
|
28
50
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
transport: custom(window.ethereum),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const vana = Vana({ walletClient });
|
|
51
|
+
// Node.js / server
|
|
52
|
+
import { NodePlatformAdapter } from "@opendatalabs/vana-sdk/node";
|
|
35
53
|
```
|
|
36
54
|
|
|
37
|
-
|
|
55
|
+
The bare `@opendatalabs/vana-sdk` import intentionally throws — it forces a
|
|
56
|
+
deliberate platform choice instead of accidentally pulling Node-only code
|
|
57
|
+
into a browser bundle (or vice versa).
|
|
38
58
|
|
|
39
|
-
|
|
40
|
-
import { Vana, mokshaTestnet } from "@opendatalabs/vana-sdk/node";
|
|
41
|
-
import { createWalletClient, http } from "viem";
|
|
42
|
-
import { privateKeyToAccount } from "viem/accounts";
|
|
43
|
-
|
|
44
|
-
const account = privateKeyToAccount("0x...");
|
|
45
|
-
const vana = Vana({
|
|
46
|
-
walletClient: createWalletClient({
|
|
47
|
-
account,
|
|
48
|
-
chain: mokshaTestnet,
|
|
49
|
-
transport: http("https://rpc.moksha.vana.org"),
|
|
50
|
-
}),
|
|
51
|
-
relayerUrl: "https://relayer.moksha.vana.org",
|
|
52
|
-
});
|
|
53
|
-
```
|
|
59
|
+
## Quick examples
|
|
54
60
|
|
|
55
|
-
###
|
|
61
|
+
### Read a Vana contract
|
|
56
62
|
|
|
57
63
|
```typescript
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
operation: "llm_inference",
|
|
62
|
-
parameters: {
|
|
63
|
-
prompt: "Analyze my data for insights",
|
|
64
|
-
maxTokens: 1000,
|
|
65
|
-
},
|
|
66
|
-
expiresAt: Math.floor(Date.now() / 1000) + 86400,
|
|
67
|
-
});
|
|
64
|
+
import { getContractController } from "@opendatalabs/vana-sdk/node";
|
|
65
|
+
import { createPublicClient, http } from "viem";
|
|
66
|
+
import { mokshaTestnet } from "@opendatalabs/vana-sdk/node";
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
filename: "data.json",
|
|
73
|
-
schemaId: 123,
|
|
74
|
-
permissions: [
|
|
75
|
-
{
|
|
76
|
-
account: "0xServerAddress...",
|
|
77
|
-
publicKey: "0x04ServerKey...",
|
|
78
|
-
},
|
|
79
|
-
],
|
|
68
|
+
const client = createPublicClient({
|
|
69
|
+
chain: mokshaTestnet,
|
|
70
|
+
transport: http(),
|
|
80
71
|
});
|
|
81
72
|
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
owner: "0x742d35Cc6558Fd4D9e9E0E888F0462ef6919Bd36",
|
|
85
|
-
});
|
|
73
|
+
const dataRegistry = getContractController("DataRegistry" as const, client);
|
|
74
|
+
const fileCount = await dataRegistry.read.filesCount();
|
|
86
75
|
```
|
|
87
76
|
|
|
88
|
-
|
|
77
|
+
### Encrypt with ECIES (Node)
|
|
89
78
|
|
|
90
|
-
|
|
79
|
+
```typescript
|
|
80
|
+
import { NodeECIESProvider } from "@opendatalabs/vana-sdk/node";
|
|
91
81
|
|
|
92
|
-
|
|
93
|
-
| ------------- | -------------------------------------------- |
|
|
94
|
-
| `permissions` | Grant and revoke gasless data access |
|
|
95
|
-
| `data` | Upload, query, and decrypt encrypted files |
|
|
96
|
-
| `schemas` | Validate data against schemas |
|
|
97
|
-
| `server` | Interact with trusted servers |
|
|
98
|
-
| `protocol` | Direct smart contract access |
|
|
99
|
-
| `operations` | Track and poll transaction status |
|
|
82
|
+
const ecies = new NodeECIESProvider();
|
|
100
83
|
|
|
101
|
-
|
|
84
|
+
const encrypted = await ecies.encrypt(recipientPublicKey, payload);
|
|
85
|
+
const decrypted = await ecies.decrypt(recipientPrivateKey, encrypted);
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The browser entry exposes the same surface as `BrowserECIESProvider`.
|
|
102
89
|
|
|
103
|
-
|
|
90
|
+
### Upload a file via the storage manager
|
|
104
91
|
|
|
105
92
|
```typescript
|
|
106
93
|
import { StorageManager, PinataStorage } from "@opendatalabs/vana-sdk/node";
|
|
107
94
|
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
),
|
|
118
|
-
subgraphUrl: "https://api.thegraph.com/subgraphs/name/vana/moksha",
|
|
119
|
-
});
|
|
95
|
+
const storage = new StorageManager();
|
|
96
|
+
storage.register(
|
|
97
|
+
"pinata",
|
|
98
|
+
new PinataStorage({ jwt: process.env.PINATA_JWT! }),
|
|
99
|
+
true, // mark as default
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const result = await storage.upload(myBlob, "report.json");
|
|
103
|
+
console.log(result.url);
|
|
120
104
|
```
|
|
121
105
|
|
|
122
106
|
## Networks
|
|
@@ -126,16 +110,16 @@ const vana = Vana({
|
|
|
126
110
|
| Vana Mainnet | 1480 | https://rpc.vana.org |
|
|
127
111
|
| Moksha Testnet | 14800 | https://rpc.moksha.vana.org |
|
|
128
112
|
|
|
129
|
-
##
|
|
113
|
+
## Audit
|
|
130
114
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
- [Examples](https://github.com/vana-com/vana-sdk/tree/main/examples) - Full demo applications
|
|
134
|
-
- [Discord](https://discord.gg/vanabuilders) - Community support
|
|
115
|
+
The ECIES implementation under `src/crypto/ecies/` was audited by HashCloak
|
|
116
|
+
in October 2025; the report is in [`audits/`](https://github.com/vana-com/vana-sdk/tree/main/packages/vana-sdk/audits).
|
|
135
117
|
|
|
136
|
-
##
|
|
118
|
+
## Learn more
|
|
137
119
|
|
|
138
|
-
|
|
120
|
+
- [Documentation](https://docs.vana.org/docs/sdk)
|
|
121
|
+
- [API reference](https://vana-com.github.io/vana-sdk)
|
|
122
|
+
- [Discord](https://discord.gg/vanabuilders)
|
|
139
123
|
|
|
140
124
|
## License
|
|
141
125
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
ExpiredTokenError: () => ExpiredTokenError,
|
|
22
|
+
InvalidSignatureError: () => InvalidSignatureError,
|
|
23
|
+
MissingAuthError: () => MissingAuthError
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(errors_exports);
|
|
26
|
+
var import_errors = require("../errors");
|
|
27
|
+
class MissingAuthError extends import_errors.VanaError {
|
|
28
|
+
constructor(message = "Missing authentication", details) {
|
|
29
|
+
super(message, "MISSING_AUTH");
|
|
30
|
+
this.details = details;
|
|
31
|
+
}
|
|
32
|
+
details;
|
|
33
|
+
}
|
|
34
|
+
class InvalidSignatureError extends import_errors.VanaError {
|
|
35
|
+
constructor(details, message = "Invalid signature") {
|
|
36
|
+
super(message, "INVALID_SIGNATURE");
|
|
37
|
+
this.details = details;
|
|
38
|
+
}
|
|
39
|
+
details;
|
|
40
|
+
}
|
|
41
|
+
class ExpiredTokenError extends import_errors.VanaError {
|
|
42
|
+
constructor(details, message = "Token has expired") {
|
|
43
|
+
super(message, "EXPIRED_TOKEN");
|
|
44
|
+
this.details = details;
|
|
45
|
+
}
|
|
46
|
+
details;
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
ExpiredTokenError,
|
|
51
|
+
InvalidSignatureError,
|
|
52
|
+
MissingAuthError
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=errors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/errors.ts"],"sourcesContent":["/**\n * Auth-specific error classes for Web3Signed verification.\n *\n * @remarks\n * Mirrors the relevant subset of `personal-server-ts` `ProtocolError` so server\n * code that consumes Web3Signed primitives can branch on typed errors. They\n * extend {@link VanaError} so they fit the SDK error hierarchy.\n *\n * @category Error Handling\n */\n\nimport { VanaError } from \"../errors\";\n\n/** Thrown when an Authorization header is missing or empty. */\nexport class MissingAuthError extends VanaError {\n constructor(\n message = \"Missing authentication\",\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"MISSING_AUTH\");\n }\n}\n\n/** Thrown when a Web3Signed header is malformed or its signature does not verify. */\nexport class InvalidSignatureError extends VanaError {\n constructor(\n public readonly details?: Record<string, unknown>,\n message = \"Invalid signature\",\n ) {\n super(message, \"INVALID_SIGNATURE\");\n }\n}\n\n/** Thrown when a Web3Signed token is expired or issued too far in the future. */\nexport class ExpiredTokenError extends VanaError {\n constructor(\n public readonly details?: Record<string, unknown>,\n message = \"Token has expired\",\n ) {\n super(message, \"EXPIRED_TOKEN\");\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,oBAA0B;AAGnB,MAAM,yBAAyB,wBAAU;AAAA,EAC9C,YACE,UAAU,0BACM,SAChB;AACA,UAAM,SAAS,cAAc;AAFb;AAAA,EAGlB;AAAA,EAHkB;AAIpB;AAGO,MAAM,8BAA8B,wBAAU;AAAA,EACnD,YACkB,SAChB,UAAU,qBACV;AACA,UAAM,SAAS,mBAAmB;AAHlB;AAAA,EAIlB;AAAA,EAJkB;AAKpB;AAGO,MAAM,0BAA0B,wBAAU;AAAA,EAC/C,YACkB,SAChB,UAAU,qBACV;AACA,UAAM,SAAS,eAAe;AAHd;AAAA,EAIlB;AAAA,EAJkB;AAKpB;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auth-specific error classes for Web3Signed verification.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Mirrors the relevant subset of `personal-server-ts` `ProtocolError` so server
|
|
6
|
+
* code that consumes Web3Signed primitives can branch on typed errors. They
|
|
7
|
+
* extend {@link VanaError} so they fit the SDK error hierarchy.
|
|
8
|
+
*
|
|
9
|
+
* @category Error Handling
|
|
10
|
+
*/
|
|
11
|
+
import { VanaError } from "../errors";
|
|
12
|
+
/** Thrown when an Authorization header is missing or empty. */
|
|
13
|
+
export declare class MissingAuthError extends VanaError {
|
|
14
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
15
|
+
constructor(message?: string, details?: Record<string, unknown> | undefined);
|
|
16
|
+
}
|
|
17
|
+
/** Thrown when a Web3Signed header is malformed or its signature does not verify. */
|
|
18
|
+
export declare class InvalidSignatureError extends VanaError {
|
|
19
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
20
|
+
constructor(details?: Record<string, unknown> | undefined, message?: string);
|
|
21
|
+
}
|
|
22
|
+
/** Thrown when a Web3Signed token is expired or issued too far in the future. */
|
|
23
|
+
export declare class ExpiredTokenError extends VanaError {
|
|
24
|
+
readonly details?: Record<string, unknown> | undefined;
|
|
25
|
+
constructor(details?: Record<string, unknown> | undefined, message?: string);
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { VanaError } from "../errors";
|
|
2
|
+
class MissingAuthError extends VanaError {
|
|
3
|
+
constructor(message = "Missing authentication", details) {
|
|
4
|
+
super(message, "MISSING_AUTH");
|
|
5
|
+
this.details = details;
|
|
6
|
+
}
|
|
7
|
+
details;
|
|
8
|
+
}
|
|
9
|
+
class InvalidSignatureError extends VanaError {
|
|
10
|
+
constructor(details, message = "Invalid signature") {
|
|
11
|
+
super(message, "INVALID_SIGNATURE");
|
|
12
|
+
this.details = details;
|
|
13
|
+
}
|
|
14
|
+
details;
|
|
15
|
+
}
|
|
16
|
+
class ExpiredTokenError extends VanaError {
|
|
17
|
+
constructor(details, message = "Token has expired") {
|
|
18
|
+
super(message, "EXPIRED_TOKEN");
|
|
19
|
+
this.details = details;
|
|
20
|
+
}
|
|
21
|
+
details;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
ExpiredTokenError,
|
|
25
|
+
InvalidSignatureError,
|
|
26
|
+
MissingAuthError
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/errors.ts"],"sourcesContent":["/**\n * Auth-specific error classes for Web3Signed verification.\n *\n * @remarks\n * Mirrors the relevant subset of `personal-server-ts` `ProtocolError` so server\n * code that consumes Web3Signed primitives can branch on typed errors. They\n * extend {@link VanaError} so they fit the SDK error hierarchy.\n *\n * @category Error Handling\n */\n\nimport { VanaError } from \"../errors\";\n\n/** Thrown when an Authorization header is missing or empty. */\nexport class MissingAuthError extends VanaError {\n constructor(\n message = \"Missing authentication\",\n public readonly details?: Record<string, unknown>,\n ) {\n super(message, \"MISSING_AUTH\");\n }\n}\n\n/** Thrown when a Web3Signed header is malformed or its signature does not verify. */\nexport class InvalidSignatureError extends VanaError {\n constructor(\n public readonly details?: Record<string, unknown>,\n message = \"Invalid signature\",\n ) {\n super(message, \"INVALID_SIGNATURE\");\n }\n}\n\n/** Thrown when a Web3Signed token is expired or issued too far in the future. */\nexport class ExpiredTokenError extends VanaError {\n constructor(\n public readonly details?: Record<string, unknown>,\n message = \"Token has expired\",\n ) {\n super(message, \"EXPIRED_TOKEN\");\n }\n}\n"],"mappings":"AAWA,SAAS,iBAAiB;AAGnB,MAAM,yBAAyB,UAAU;AAAA,EAC9C,YACE,UAAU,0BACM,SAChB;AACA,UAAM,SAAS,cAAc;AAFb;AAAA,EAGlB;AAAA,EAHkB;AAIpB;AAGO,MAAM,8BAA8B,UAAU;AAAA,EACnD,YACkB,SAChB,UAAU,qBACV;AACA,UAAM,SAAS,mBAAmB;AAHlB;AAAA,EAIlB;AAAA,EAJkB;AAKpB;AAGO,MAAM,0BAA0B,UAAU;AAAA,EAC/C,YACkB,SAChB,UAAU,qBACV;AACA,UAAM,SAAS,eAAe;AAHd;AAAA,EAIlB;AAAA,EAJkB;AAKpB;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var pkce_exports = {};
|
|
20
|
+
__export(pkce_exports, {
|
|
21
|
+
PKCE_CHALLENGE_PATTERN: () => PKCE_CHALLENGE_PATTERN,
|
|
22
|
+
PKCE_VERIFIER_PATTERN: () => PKCE_VERIFIER_PATTERN,
|
|
23
|
+
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
24
|
+
computePkceChallenge: () => computePkceChallenge,
|
|
25
|
+
generatePkceVerifier: () => generatePkceVerifier,
|
|
26
|
+
verifyPkceChallenge: () => verifyPkceChallenge
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(pkce_exports);
|
|
29
|
+
const PKCE_VERIFIER_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
30
|
+
const PKCE_VERIFIER_MIN_LENGTH = 43;
|
|
31
|
+
const PKCE_VERIFIER_MAX_LENGTH = 128;
|
|
32
|
+
const PKCE_VERIFIER_DEFAULT_LENGTH = 64;
|
|
33
|
+
const PKCE_VERIFIER_PATTERN = /^[A-Za-z0-9._~-]{43,128}$/;
|
|
34
|
+
const PKCE_CHALLENGE_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
35
|
+
function assertValidPkceVerifier(verifier) {
|
|
36
|
+
if (!PKCE_VERIFIER_PATTERN.test(verifier)) {
|
|
37
|
+
throw new RangeError(
|
|
38
|
+
`PKCE verifier must match RFC 7636 \xA74.1: ${PKCE_VERIFIER_MIN_LENGTH}-${PKCE_VERIFIER_MAX_LENGTH} unreserved chars [A-Za-z0-9._~-]`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function generatePkceVerifier(length = PKCE_VERIFIER_DEFAULT_LENGTH) {
|
|
43
|
+
if (!Number.isInteger(length) || length < PKCE_VERIFIER_MIN_LENGTH || length > PKCE_VERIFIER_MAX_LENGTH) {
|
|
44
|
+
throw new RangeError(
|
|
45
|
+
`PKCE verifier length must be an integer between ${PKCE_VERIFIER_MIN_LENGTH} and ${PKCE_VERIFIER_MAX_LENGTH}`
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const alphabetLen = PKCE_VERIFIER_ALPHABET.length;
|
|
49
|
+
const acceptCutoff = Math.floor(256 / alphabetLen) * alphabetLen;
|
|
50
|
+
const out = new Array(length);
|
|
51
|
+
let filled = 0;
|
|
52
|
+
const buffer = new Uint8Array(length * 2);
|
|
53
|
+
while (filled < length) {
|
|
54
|
+
crypto.getRandomValues(buffer);
|
|
55
|
+
for (let i = 0; i < buffer.length && filled < length; i++) {
|
|
56
|
+
const byte = buffer[i];
|
|
57
|
+
if (byte < acceptCutoff) {
|
|
58
|
+
out[filled++] = PKCE_VERIFIER_ALPHABET[byte % alphabetLen];
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return out.join("");
|
|
63
|
+
}
|
|
64
|
+
async function computePkceChallenge(verifier) {
|
|
65
|
+
assertValidPkceVerifier(verifier);
|
|
66
|
+
const bytes = new TextEncoder().encode(verifier);
|
|
67
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
68
|
+
return base64UrlEncode(new Uint8Array(digest));
|
|
69
|
+
}
|
|
70
|
+
async function verifyPkceChallenge(verifier, challenge) {
|
|
71
|
+
if (!PKCE_VERIFIER_PATTERN.test(verifier)) return false;
|
|
72
|
+
if (!PKCE_CHALLENGE_PATTERN.test(challenge)) return false;
|
|
73
|
+
const computed = await computePkceChallenge(verifier);
|
|
74
|
+
return constantTimeEqualString(computed, challenge);
|
|
75
|
+
}
|
|
76
|
+
function base64UrlEncode(bytes) {
|
|
77
|
+
let binary = "";
|
|
78
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
79
|
+
binary += String.fromCharCode(bytes[i]);
|
|
80
|
+
}
|
|
81
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
82
|
+
}
|
|
83
|
+
function constantTimeEqualString(a, b) {
|
|
84
|
+
if (a.length !== b.length) return false;
|
|
85
|
+
let result = 0;
|
|
86
|
+
for (let i = 0; i < a.length; i++) {
|
|
87
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
88
|
+
}
|
|
89
|
+
return result === 0;
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
PKCE_CHALLENGE_PATTERN,
|
|
94
|
+
PKCE_VERIFIER_PATTERN,
|
|
95
|
+
assertValidPkceVerifier,
|
|
96
|
+
computePkceChallenge,
|
|
97
|
+
generatePkceVerifier,
|
|
98
|
+
verifyPkceChallenge
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=pkce.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/pkce.ts"],"sourcesContent":["/**\n * PKCE (Proof Key for Code Exchange) primitives per RFC 7636.\n *\n * @remarks\n * Implements the S256 challenge method only. All functions are pure and\n * isomorphic — they rely on the `crypto.getRandomValues` and\n * `crypto.subtle` Web Crypto APIs available as globals in browsers and\n * Node.js (>= 20).\n *\n * @category Auth\n * @module auth/pkce\n */\n\n// RFC 7636 §4.1 unreserved characters: ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\"\nconst PKCE_VERIFIER_ALPHABET =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~\";\n\nconst PKCE_VERIFIER_MIN_LENGTH = 43;\nconst PKCE_VERIFIER_MAX_LENGTH = 128;\nconst PKCE_VERIFIER_DEFAULT_LENGTH = 64;\n\n/**\n * RFC 7636 §4.1 verifier shape: 43-128 unreserved chars.\n *\n * @category Auth\n */\nexport const PKCE_VERIFIER_PATTERN = /^[A-Za-z0-9._~-]{43,128}$/;\n\n/**\n * S256 challenge shape: 43-char base64url (SHA-256 = 32 bytes → 43 chars\n * after base64url-no-padding encoding).\n *\n * @category Auth\n */\nexport const PKCE_CHALLENGE_PATTERN = /^[A-Za-z0-9_-]{43}$/;\n\n/**\n * Throws {@link RangeError} unless `verifier` matches RFC 7636 §4.1.\n *\n * @category Auth\n */\nexport function assertValidPkceVerifier(verifier: string): void {\n if (!PKCE_VERIFIER_PATTERN.test(verifier)) {\n throw new RangeError(\n `PKCE verifier must match RFC 7636 §4.1: ${PKCE_VERIFIER_MIN_LENGTH}-${PKCE_VERIFIER_MAX_LENGTH} unreserved chars [A-Za-z0-9._~-]`,\n );\n }\n}\n\n/**\n * Generates a cryptographically random PKCE code verifier.\n *\n * @param length - Verifier length in characters. Must be between 43 and 128\n * (RFC 7636 §4.1). Defaults to 64.\n * @returns A string of the requested length using only the RFC-allowed\n * unreserved alphabet.\n */\nexport function generatePkceVerifier(\n length: number = PKCE_VERIFIER_DEFAULT_LENGTH,\n): string {\n if (\n !Number.isInteger(length) ||\n length < PKCE_VERIFIER_MIN_LENGTH ||\n length > PKCE_VERIFIER_MAX_LENGTH\n ) {\n throw new RangeError(\n `PKCE verifier length must be an integer between ${PKCE_VERIFIER_MIN_LENGTH} and ${PKCE_VERIFIER_MAX_LENGTH}`,\n );\n }\n\n const alphabetLen = PKCE_VERIFIER_ALPHABET.length;\n // Reject-sample to avoid modulo bias from a non-power-of-two alphabet (66).\n const acceptCutoff = Math.floor(256 / alphabetLen) * alphabetLen;\n\n const out = new Array<string>(length);\n let filled = 0;\n const buffer = new Uint8Array(length * 2);\n\n while (filled < length) {\n crypto.getRandomValues(buffer);\n for (let i = 0; i < buffer.length && filled < length; i++) {\n const byte = buffer[i] as number;\n if (byte < acceptCutoff) {\n out[filled++] = PKCE_VERIFIER_ALPHABET[byte % alphabetLen] as string;\n }\n }\n }\n\n return out.join(\"\");\n}\n\n/**\n * Computes the S256 PKCE code challenge for a verifier.\n *\n * @param verifier - The PKCE code verifier.\n * @returns The base64url-encoded SHA-256 hash of the verifier (no padding).\n */\nexport async function computePkceChallenge(verifier: string): Promise<string> {\n assertValidPkceVerifier(verifier);\n const bytes = new TextEncoder().encode(verifier);\n const digest = await crypto.subtle.digest(\"SHA-256\", bytes);\n return base64UrlEncode(new Uint8Array(digest));\n}\n\n/**\n * Verifies that a verifier hashes to the given S256 challenge.\n *\n * @param verifier - The PKCE code verifier presented by the client.\n * @param challenge - The previously stored S256 challenge.\n * @returns `true` when the verifier matches; `false` otherwise.\n */\nexport async function verifyPkceChallenge(\n verifier: string,\n challenge: string,\n): Promise<boolean> {\n if (!PKCE_VERIFIER_PATTERN.test(verifier)) return false;\n if (!PKCE_CHALLENGE_PATTERN.test(challenge)) return false;\n const computed = await computePkceChallenge(verifier);\n return constantTimeEqualString(computed, challenge);\n}\n\nfunction base64UrlEncode(bytes: Uint8Array): string {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i] as number);\n }\n // btoa is available in Node 16+ and all browsers.\n return btoa(binary)\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/, \"\");\n}\n\nfunction constantTimeEqualString(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAcA,MAAM,yBACJ;AAEF,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,+BAA+B;AAO9B,MAAM,wBAAwB;AAQ9B,MAAM,yBAAyB;AAO/B,SAAS,wBAAwB,UAAwB;AAC9D,MAAI,CAAC,sBAAsB,KAAK,QAAQ,GAAG;AACzC,UAAM,IAAI;AAAA,MACR,8CAA2C,wBAAwB,IAAI,wBAAwB;AAAA,IACjG;AAAA,EACF;AACF;AAUO,SAAS,qBACd,SAAiB,8BACT;AACR,MACE,CAAC,OAAO,UAAU,MAAM,KACxB,SAAS,4BACT,SAAS,0BACT;AACA,UAAM,IAAI;AAAA,MACR,mDAAmD,wBAAwB,QAAQ,wBAAwB;AAAA,IAC7G;AAAA,EACF;AAEA,QAAM,cAAc,uBAAuB;AAE3C,QAAM,eAAe,KAAK,MAAM,MAAM,WAAW,IAAI;AAErD,QAAM,MAAM,IAAI,MAAc,MAAM;AACpC,MAAI,SAAS;AACb,QAAM,SAAS,IAAI,WAAW,SAAS,CAAC;AAExC,SAAO,SAAS,QAAQ;AACtB,WAAO,gBAAgB,MAAM;AAC7B,aAAS,IAAI,GAAG,IAAI,OAAO,UAAU,SAAS,QAAQ,KAAK;AACzD,YAAM,OAAO,OAAO,CAAC;AACrB,UAAI,OAAO,cAAc;AACvB,YAAI,QAAQ,IAAI,uBAAuB,OAAO,WAAW;AAAA,MAC3D;AAAA,IACF;AAAA,EACF;AAEA,SAAO,IAAI,KAAK,EAAE;AACpB;AAQA,eAAsB,qBAAqB,UAAmC;AAC5E,0BAAwB,QAAQ;AAChC,QAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,QAAQ;AAC/C,QAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AAC1D,SAAO,gBAAgB,IAAI,WAAW,MAAM,CAAC;AAC/C;AASA,eAAsB,oBACpB,UACA,WACkB;AAClB,MAAI,CAAC,sBAAsB,KAAK,QAAQ,EAAG,QAAO;AAClD,MAAI,CAAC,uBAAuB,KAAK,SAAS,EAAG,QAAO;AACpD,QAAM,WAAW,MAAM,qBAAqB,QAAQ;AACpD,SAAO,wBAAwB,UAAU,SAAS;AACpD;AAEA,SAAS,gBAAgB,OAA2B;AAClD,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAW;AAAA,EAClD;AAEA,SAAO,KAAK,MAAM,EACf,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,EAAE;AACtB;AAEA,SAAS,wBAAwB,GAAW,GAAoB;AAC9D,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,cAAU,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC5C;AACA,SAAO,WAAW;AACpB;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PKCE (Proof Key for Code Exchange) primitives per RFC 7636.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* Implements the S256 challenge method only. All functions are pure and
|
|
6
|
+
* isomorphic — they rely on the `crypto.getRandomValues` and
|
|
7
|
+
* `crypto.subtle` Web Crypto APIs available as globals in browsers and
|
|
8
|
+
* Node.js (>= 20).
|
|
9
|
+
*
|
|
10
|
+
* @category Auth
|
|
11
|
+
* @module auth/pkce
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* RFC 7636 §4.1 verifier shape: 43-128 unreserved chars.
|
|
15
|
+
*
|
|
16
|
+
* @category Auth
|
|
17
|
+
*/
|
|
18
|
+
export declare const PKCE_VERIFIER_PATTERN: RegExp;
|
|
19
|
+
/**
|
|
20
|
+
* S256 challenge shape: 43-char base64url (SHA-256 = 32 bytes → 43 chars
|
|
21
|
+
* after base64url-no-padding encoding).
|
|
22
|
+
*
|
|
23
|
+
* @category Auth
|
|
24
|
+
*/
|
|
25
|
+
export declare const PKCE_CHALLENGE_PATTERN: RegExp;
|
|
26
|
+
/**
|
|
27
|
+
* Throws {@link RangeError} unless `verifier` matches RFC 7636 §4.1.
|
|
28
|
+
*
|
|
29
|
+
* @category Auth
|
|
30
|
+
*/
|
|
31
|
+
export declare function assertValidPkceVerifier(verifier: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Generates a cryptographically random PKCE code verifier.
|
|
34
|
+
*
|
|
35
|
+
* @param length - Verifier length in characters. Must be between 43 and 128
|
|
36
|
+
* (RFC 7636 §4.1). Defaults to 64.
|
|
37
|
+
* @returns A string of the requested length using only the RFC-allowed
|
|
38
|
+
* unreserved alphabet.
|
|
39
|
+
*/
|
|
40
|
+
export declare function generatePkceVerifier(length?: number): string;
|
|
41
|
+
/**
|
|
42
|
+
* Computes the S256 PKCE code challenge for a verifier.
|
|
43
|
+
*
|
|
44
|
+
* @param verifier - The PKCE code verifier.
|
|
45
|
+
* @returns The base64url-encoded SHA-256 hash of the verifier (no padding).
|
|
46
|
+
*/
|
|
47
|
+
export declare function computePkceChallenge(verifier: string): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
* Verifies that a verifier hashes to the given S256 challenge.
|
|
50
|
+
*
|
|
51
|
+
* @param verifier - The PKCE code verifier presented by the client.
|
|
52
|
+
* @param challenge - The previously stored S256 challenge.
|
|
53
|
+
* @returns `true` when the verifier matches; `false` otherwise.
|
|
54
|
+
*/
|
|
55
|
+
export declare function verifyPkceChallenge(verifier: string, challenge: string): Promise<boolean>;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
const PKCE_VERIFIER_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~";
|
|
2
|
+
const PKCE_VERIFIER_MIN_LENGTH = 43;
|
|
3
|
+
const PKCE_VERIFIER_MAX_LENGTH = 128;
|
|
4
|
+
const PKCE_VERIFIER_DEFAULT_LENGTH = 64;
|
|
5
|
+
const PKCE_VERIFIER_PATTERN = /^[A-Za-z0-9._~-]{43,128}$/;
|
|
6
|
+
const PKCE_CHALLENGE_PATTERN = /^[A-Za-z0-9_-]{43}$/;
|
|
7
|
+
function assertValidPkceVerifier(verifier) {
|
|
8
|
+
if (!PKCE_VERIFIER_PATTERN.test(verifier)) {
|
|
9
|
+
throw new RangeError(
|
|
10
|
+
`PKCE verifier must match RFC 7636 \xA74.1: ${PKCE_VERIFIER_MIN_LENGTH}-${PKCE_VERIFIER_MAX_LENGTH} unreserved chars [A-Za-z0-9._~-]`
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function generatePkceVerifier(length = PKCE_VERIFIER_DEFAULT_LENGTH) {
|
|
15
|
+
if (!Number.isInteger(length) || length < PKCE_VERIFIER_MIN_LENGTH || length > PKCE_VERIFIER_MAX_LENGTH) {
|
|
16
|
+
throw new RangeError(
|
|
17
|
+
`PKCE verifier length must be an integer between ${PKCE_VERIFIER_MIN_LENGTH} and ${PKCE_VERIFIER_MAX_LENGTH}`
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
const alphabetLen = PKCE_VERIFIER_ALPHABET.length;
|
|
21
|
+
const acceptCutoff = Math.floor(256 / alphabetLen) * alphabetLen;
|
|
22
|
+
const out = new Array(length);
|
|
23
|
+
let filled = 0;
|
|
24
|
+
const buffer = new Uint8Array(length * 2);
|
|
25
|
+
while (filled < length) {
|
|
26
|
+
crypto.getRandomValues(buffer);
|
|
27
|
+
for (let i = 0; i < buffer.length && filled < length; i++) {
|
|
28
|
+
const byte = buffer[i];
|
|
29
|
+
if (byte < acceptCutoff) {
|
|
30
|
+
out[filled++] = PKCE_VERIFIER_ALPHABET[byte % alphabetLen];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return out.join("");
|
|
35
|
+
}
|
|
36
|
+
async function computePkceChallenge(verifier) {
|
|
37
|
+
assertValidPkceVerifier(verifier);
|
|
38
|
+
const bytes = new TextEncoder().encode(verifier);
|
|
39
|
+
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
40
|
+
return base64UrlEncode(new Uint8Array(digest));
|
|
41
|
+
}
|
|
42
|
+
async function verifyPkceChallenge(verifier, challenge) {
|
|
43
|
+
if (!PKCE_VERIFIER_PATTERN.test(verifier)) return false;
|
|
44
|
+
if (!PKCE_CHALLENGE_PATTERN.test(challenge)) return false;
|
|
45
|
+
const computed = await computePkceChallenge(verifier);
|
|
46
|
+
return constantTimeEqualString(computed, challenge);
|
|
47
|
+
}
|
|
48
|
+
function base64UrlEncode(bytes) {
|
|
49
|
+
let binary = "";
|
|
50
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
51
|
+
binary += String.fromCharCode(bytes[i]);
|
|
52
|
+
}
|
|
53
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
54
|
+
}
|
|
55
|
+
function constantTimeEqualString(a, b) {
|
|
56
|
+
if (a.length !== b.length) return false;
|
|
57
|
+
let result = 0;
|
|
58
|
+
for (let i = 0; i < a.length; i++) {
|
|
59
|
+
result |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
60
|
+
}
|
|
61
|
+
return result === 0;
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
PKCE_CHALLENGE_PATTERN,
|
|
65
|
+
PKCE_VERIFIER_PATTERN,
|
|
66
|
+
assertValidPkceVerifier,
|
|
67
|
+
computePkceChallenge,
|
|
68
|
+
generatePkceVerifier,
|
|
69
|
+
verifyPkceChallenge
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=pkce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/pkce.ts"],"sourcesContent":["/**\n * PKCE (Proof Key for Code Exchange) primitives per RFC 7636.\n *\n * @remarks\n * Implements the S256 challenge method only. All functions are pure and\n * isomorphic — they rely on the `crypto.getRandomValues` and\n * `crypto.subtle` Web Crypto APIs available as globals in browsers and\n * Node.js (>= 20).\n *\n * @category Auth\n * @module auth/pkce\n */\n\n// RFC 7636 §4.1 unreserved characters: ALPHA / DIGIT / \"-\" / \".\" / \"_\" / \"~\"\nconst PKCE_VERIFIER_ALPHABET =\n \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~\";\n\nconst PKCE_VERIFIER_MIN_LENGTH = 43;\nconst PKCE_VERIFIER_MAX_LENGTH = 128;\nconst PKCE_VERIFIER_DEFAULT_LENGTH = 64;\n\n/**\n * RFC 7636 §4.1 verifier shape: 43-128 unreserved chars.\n *\n * @category Auth\n */\nexport const PKCE_VERIFIER_PATTERN = /^[A-Za-z0-9._~-]{43,128}$/;\n\n/**\n * S256 challenge shape: 43-char base64url (SHA-256 = 32 bytes → 43 chars\n * after base64url-no-padding encoding).\n *\n * @category Auth\n */\nexport const PKCE_CHALLENGE_PATTERN = /^[A-Za-z0-9_-]{43}$/;\n\n/**\n * Throws {@link RangeError} unless `verifier` matches RFC 7636 §4.1.\n *\n * @category Auth\n */\nexport function assertValidPkceVerifier(verifier: string): void {\n if (!PKCE_VERIFIER_PATTERN.test(verifier)) {\n throw new RangeError(\n `PKCE verifier must match RFC 7636 §4.1: ${PKCE_VERIFIER_MIN_LENGTH}-${PKCE_VERIFIER_MAX_LENGTH} unreserved chars [A-Za-z0-9._~-]`,\n );\n }\n}\n\n/**\n * Generates a cryptographically random PKCE code verifier.\n *\n * @param length - Verifier length in characters. Must be between 43 and 128\n * (RFC 7636 §4.1). Defaults to 64.\n * @returns A string of the requested length using only the RFC-allowed\n * unreserved alphabet.\n */\nexport function generatePkceVerifier(\n length: number = PKCE_VERIFIER_DEFAULT_LENGTH,\n): string {\n if (\n !Number.isInteger(length) ||\n length < PKCE_VERIFIER_MIN_LENGTH ||\n length > PKCE_VERIFIER_MAX_LENGTH\n ) {\n throw new RangeError(\n `PKCE verifier length must be an integer between ${PKCE_VERIFIER_MIN_LENGTH} and ${PKCE_VERIFIER_MAX_LENGTH}`,\n );\n }\n\n const alphabetLen = PKCE_VERIFIER_ALPHABET.length;\n // Reject-sample to avoid modulo bias from a non-power-of-two alphabet (66).\n const acceptCutoff = Math.floor(256 / alphabetLen) * alphabetLen;\n\n const out = new Array<string>(length);\n let filled = 0;\n const buffer = new Uint8Array(length * 2);\n\n while (filled < length) {\n crypto.getRandomValues(buffer);\n for (let i = 0; i < buffer.length && filled < length; i++) {\n const byte = buffer[i] as number;\n if (byte < acceptCutoff) {\n out[filled++] = PKCE_VERIFIER_ALPHABET[byte % alphabetLen] as string;\n }\n }\n }\n\n return out.join(\"\");\n}\n\n/**\n * Computes the S256 PKCE code challenge for a verifier.\n *\n * @param verifier - The PKCE code verifier.\n * @returns The base64url-encoded SHA-256 hash of the verifier (no padding).\n */\nexport async function computePkceChallenge(verifier: string): Promise<string> {\n assertValidPkceVerifier(verifier);\n const bytes = new TextEncoder().encode(verifier);\n const digest = await crypto.subtle.digest(\"SHA-256\", bytes);\n return base64UrlEncode(new Uint8Array(digest));\n}\n\n/**\n * Verifies that a verifier hashes to the given S256 challenge.\n *\n * @param verifier - The PKCE code verifier presented by the client.\n * @param challenge - The previously stored S256 challenge.\n * @returns `true` when the verifier matches; `false` otherwise.\n */\nexport async function verifyPkceChallenge(\n verifier: string,\n challenge: string,\n): Promise<boolean> {\n if (!PKCE_VERIFIER_PATTERN.test(verifier)) return false;\n if (!PKCE_CHALLENGE_PATTERN.test(challenge)) return false;\n const computed = await computePkceChallenge(verifier);\n return constantTimeEqualString(computed, challenge);\n}\n\nfunction base64UrlEncode(bytes: Uint8Array): string {\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i] as number);\n }\n // btoa is available in Node 16+ and all browsers.\n return btoa(binary)\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/, \"\");\n}\n\nfunction constantTimeEqualString(a: string, b: string): boolean {\n if (a.length !== b.length) return false;\n let result = 0;\n for (let i = 0; i < a.length; i++) {\n result |= a.charCodeAt(i) ^ b.charCodeAt(i);\n }\n return result === 0;\n}\n"],"mappings":"AAcA,MAAM,yBACJ;AAEF,MAAM,2BAA2B;AACjC,MAAM,2BAA2B;AACjC,MAAM,+BAA+B;AAO9B,MAAM,wBAAwB;AAQ9B,MAAM,yBAAyB;AAO/B,SAAS,wBAAwB,UAAwB;AAC9D,MAAI,CAAC,sBAAsB,KAAK,QAAQ,GAAG;AACzC,UAAM,IAAI;AAAA,MACR,8CAA2C,wBAAwB,IAAI,wBAAwB;AAAA,IACjG;AAAA,EACF;AACF;AAUO,SAAS,qBACd,SAAiB,8BACT;AACR,MACE,CAAC,OAAO,UAAU,MAAM,KACxB,SAAS,4BACT,SAAS,0BACT;AACA,UAAM,IAAI;AAAA,MACR,mDAAmD,wBAAwB,QAAQ,wBAAwB;AAAA,IAC7G;AAAA,EACF;AAEA,QAAM,cAAc,uBAAuB;AAE3C,QAAM,eAAe,KAAK,MAAM,MAAM,WAAW,IAAI;AAErD,QAAM,MAAM,IAAI,MAAc,MAAM;AACpC,MAAI,SAAS;AACb,QAAM,SAAS,IAAI,WAAW,SAAS,CAAC;AAExC,SAAO,SAAS,QAAQ;AACtB,WAAO,gBAAgB,MAAM;AAC7B,aAAS,IAAI,GAAG,IAAI,OAAO,UAAU,SAAS,QAAQ,KAAK;AACzD,YAAM,OAAO,OAAO,CAAC;AACrB,UAAI,OAAO,cAAc;AACvB,YAAI,QAAQ,IAAI,uBAAuB,OAAO,WAAW;AAAA,MAC3D;AAAA,IACF;AAAA,EACF;AAEA,SAAO,IAAI,KAAK,EAAE;AACpB;AAQA,eAAsB,qBAAqB,UAAmC;AAC5E,0BAAwB,QAAQ;AAChC,QAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,QAAQ;AAC/C,QAAM,SAAS,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK;AAC1D,SAAO,gBAAgB,IAAI,WAAW,MAAM,CAAC;AAC/C;AASA,eAAsB,oBACpB,UACA,WACkB;AAClB,MAAI,CAAC,sBAAsB,KAAK,QAAQ,EAAG,QAAO;AAClD,MAAI,CAAC,uBAAuB,KAAK,SAAS,EAAG,QAAO;AACpD,QAAM,WAAW,MAAM,qBAAqB,QAAQ;AACpD,SAAO,wBAAwB,UAAU,SAAS;AACpD;AAEA,SAAS,gBAAgB,OAA2B;AAClD,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAW;AAAA,EAClD;AAEA,SAAO,KAAK,MAAM,EACf,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,EAAE;AACtB;AAEA,SAAS,wBAAwB,GAAW,GAAoB;AAC9D,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,cAAU,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC5C;AACA,SAAO,WAAW;AACpB;","names":[]}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var token_store_exports = {};
|
|
20
|
+
__export(token_store_exports, {
|
|
21
|
+
InMemoryTokenStore: () => InMemoryTokenStore
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(token_store_exports);
|
|
24
|
+
class InMemoryTokenStore {
|
|
25
|
+
#records = /* @__PURE__ */ new Map();
|
|
26
|
+
get(key) {
|
|
27
|
+
const record = this.#records.get(key);
|
|
28
|
+
if (record === void 0) return Promise.resolve(null);
|
|
29
|
+
if (record.expiresAt !== void 0 && record.expiresAt <= Math.floor(Date.now() / 1e3)) {
|
|
30
|
+
this.#records.delete(key);
|
|
31
|
+
return Promise.resolve(null);
|
|
32
|
+
}
|
|
33
|
+
return Promise.resolve({ ...record });
|
|
34
|
+
}
|
|
35
|
+
set(key, record) {
|
|
36
|
+
this.#records.set(key, { ...record });
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}
|
|
39
|
+
delete(key) {
|
|
40
|
+
this.#records.delete(key);
|
|
41
|
+
return Promise.resolve();
|
|
42
|
+
}
|
|
43
|
+
clear() {
|
|
44
|
+
this.#records.clear();
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the number of stored entries (including any not yet
|
|
49
|
+
* lazily evicted). Intended for tests and diagnostics.
|
|
50
|
+
*/
|
|
51
|
+
get size() {
|
|
52
|
+
return this.#records.size;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
InMemoryTokenStore
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=token-store.cjs.map
|