@opendatalabs/vana-sdk 0.1.0-alpha.7ee7635 → 0.1.0-alpha.80df35f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__tests__/waitForTransactionEvents.test.d.ts +1 -0
- package/dist/browser.d.ts +4 -2
- package/dist/chains/definitions.cjs +9 -6
- package/dist/chains/definitions.cjs.map +1 -1
- package/dist/chains/definitions.d.ts +9 -11
- package/dist/chains/definitions.js +9 -6
- package/dist/chains/definitions.js.map +1 -1
- package/dist/chains/index.d.ts +5 -2
- package/dist/chains.browser.d.ts +8 -2
- package/dist/chains.d.ts +8 -2
- package/dist/chains.node.d.ts +8 -2
- package/dist/config/addresses.d.ts +8 -45
- package/dist/config/chains.d.ts +9 -13
- package/dist/config/default-services.cjs +60 -0
- package/dist/config/default-services.cjs.map +1 -0
- package/dist/config/default-services.d.ts +46 -0
- package/dist/config/default-services.js +33 -0
- package/dist/config/default-services.js.map +1 -0
- package/dist/config/default-services.test.d.ts +1 -0
- package/dist/config/features.d.ts +1 -3
- package/dist/config/tests/addresses.test.d.ts +1 -0
- package/dist/contracts/contractController.cjs +3 -3
- package/dist/contracts/contractController.cjs.map +1 -1
- package/dist/contracts/contractController.d.ts +11 -49
- package/dist/contracts/contractController.js +4 -7
- package/dist/contracts/contractController.js.map +1 -1
- package/dist/contracts/tests/contractController.test.d.ts +1 -0
- package/dist/controllers/__tests__/schemas-edge-cases.test.d.ts +1 -0
- package/dist/controllers/base.cjs +83 -0
- package/dist/controllers/base.cjs.map +1 -0
- package/dist/controllers/base.d.ts +84 -0
- package/dist/controllers/base.js +59 -0
- package/dist/controllers/base.js.map +1 -0
- package/dist/controllers/data-error-handling.test.d.ts +1 -0
- package/dist/controllers/data.cjs +338 -107
- package/dist/controllers/data.cjs.map +1 -1
- package/dist/controllers/data.d.ts +145 -46
- package/dist/controllers/data.js +338 -107
- package/dist/controllers/data.js.map +1 -1
- package/dist/controllers/permissions.cjs +162 -223
- package/dist/controllers/permissions.cjs.map +1 -1
- package/dist/controllers/permissions.d.ts +24 -78
- package/dist/controllers/permissions.js +162 -223
- package/dist/controllers/permissions.js.map +1 -1
- package/dist/controllers/protocol.cjs +15 -11
- package/dist/controllers/protocol.cjs.map +1 -1
- package/dist/controllers/protocol.d.ts +7 -56
- package/dist/controllers/protocol.js +15 -14
- package/dist/controllers/protocol.js.map +1 -1
- package/dist/controllers/schemas.cjs +29 -36
- package/dist/controllers/schemas.cjs.map +1 -1
- package/dist/controllers/schemas.d.ts +8 -23
- package/dist/controllers/schemas.js +29 -36
- package/dist/controllers/schemas.js.map +1 -1
- package/dist/controllers/server-additional.test.d.ts +1 -0
- package/dist/controllers/server.cjs +15 -10
- package/dist/controllers/server.cjs.map +1 -1
- package/dist/controllers/server.d.ts +7 -20
- package/dist/controllers/server.js +15 -10
- package/dist/controllers/server.js.map +1 -1
- package/dist/core/apiClient.cjs +15 -12
- package/dist/core/apiClient.cjs.map +1 -1
- package/dist/core/apiClient.d.ts +5 -9
- package/dist/core/apiClient.js +19 -19
- package/dist/core/apiClient.js.map +1 -1
- package/dist/core/client.cjs +7 -7
- package/dist/core/client.cjs.map +1 -1
- package/dist/core/client.d.ts +6 -9
- package/dist/core/client.js +7 -7
- package/dist/core/client.js.map +1 -1
- package/dist/core/core.test.d.ts +1 -0
- package/dist/core/generics.cjs +11 -9
- package/dist/core/generics.cjs.map +1 -1
- package/dist/core/generics.d.ts +9 -13
- package/dist/core/generics.js +22 -29
- package/dist/core/generics.js.map +1 -1
- package/dist/core/tests/apiClient.test.d.ts +1 -0
- package/dist/core/tests/client.test.d.ts +1 -0
- package/dist/core/tests/generics.test.d.ts +1 -0
- package/dist/core.cjs +82 -34
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +21 -73
- package/dist/core.js +105 -60
- package/dist/core.js.map +1 -1
- package/dist/crypto/ecies/__tests__/base.test.d.ts +4 -0
- package/dist/crypto/ecies/__tests__/compatibility.test.d.ts +8 -0
- package/dist/crypto/ecies/__tests__/constants.test.d.ts +4 -0
- package/dist/crypto/ecies/__tests__/native-parity.test.d.ts +7 -0
- package/dist/crypto/ecies/__tests__/normalization.test.d.ts +1 -0
- package/dist/crypto/ecies/__tests__/test-vectors.d.ts +2 -4
- package/dist/crypto/ecies/base.cjs +4 -3
- package/dist/crypto/ecies/base.cjs.map +1 -1
- package/dist/crypto/ecies/base.d.ts +2 -5
- package/dist/crypto/ecies/base.js +12 -15
- package/dist/crypto/ecies/base.js.map +1 -1
- package/dist/crypto/ecies/browser.cjs +2 -1
- package/dist/crypto/ecies/browser.cjs.map +1 -1
- package/dist/crypto/ecies/browser.d.ts +2 -7
- package/dist/crypto/ecies/browser.js +2 -1
- package/dist/crypto/ecies/browser.js.map +1 -1
- package/dist/crypto/ecies/constants.d.ts +7 -9
- package/dist/crypto/ecies/index.d.ts +8 -1
- package/dist/crypto/ecies/interface.cjs +4 -5
- package/dist/crypto/ecies/interface.cjs.map +1 -1
- package/dist/crypto/ecies/interface.d.ts +9 -11
- package/dist/crypto/ecies/interface.js +4 -5
- package/dist/crypto/ecies/interface.js.map +1 -1
- package/dist/crypto/ecies/node.cjs +3 -2
- package/dist/crypto/ecies/node.cjs.map +1 -1
- package/dist/crypto/ecies/node.d.ts +2 -7
- package/dist/crypto/ecies/node.js +11 -16
- package/dist/crypto/ecies/node.js.map +1 -1
- package/dist/crypto/ecies/utils.cjs +2 -41
- package/dist/crypto/ecies/utils.cjs.map +1 -1
- package/dist/crypto/ecies/utils.d.ts +3 -40
- package/dist/crypto/ecies/utils.js +1 -35
- package/dist/crypto/ecies/utils.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.cjs +2 -2
- package/dist/crypto/services/WalletKeyEncryptionService.cjs.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.d.ts +3 -7
- package/dist/crypto/services/WalletKeyEncryptionService.js +5 -9
- package/dist/crypto/services/WalletKeyEncryptionService.js.map +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.test.d.ts +1 -0
- package/dist/diagnostics.d.ts +1 -3
- package/dist/diagnostics.test.d.ts +1 -0
- package/dist/errors.cjs +16 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +53 -15
- package/dist/errors.js +18 -6
- package/dist/errors.js.map +1 -1
- package/dist/generated/abi/ComputeEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.cjs.map +1 -1
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.js.map +1 -1
- package/dist/generated/abi/DATFactoryImplementation.d.ts +2 -3
- package/dist/generated/abi/DATImplementation.d.ts +2 -3
- package/dist/generated/abi/DATPausableImplementation.d.ts +2 -3
- package/dist/generated/abi/DATVotesImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPPerformanceImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRewardSwapImplementation.d.ts +2 -3
- package/dist/generated/abi/DLPRootImplementation.d.ts +1 -3
- package/dist/generated/abi/DLPTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.ts +1 -3
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.js.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.cjs.map +1 -1
- package/dist/generated/abi/DataPortabilityServersImplementation.d.ts +2 -3
- package/dist/generated/abi/DataPortabilityServersImplementation.js.map +1 -1
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/DataRegistryImplementation.d.ts +2 -3
- package/dist/generated/abi/QueryEngineImplementation.d.ts +2 -3
- package/dist/generated/abi/SwapHelperImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.ts +2 -3
- package/dist/generated/abi/TeePoolPhalaImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaEpochImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolEntityImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolStakingImplementation.d.ts +2 -3
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.ts +2 -3
- package/dist/generated/abi/index.d.ts +37 -39
- package/dist/generated/event-types.d.ts +9 -10
- package/dist/generated/eventRegistry.d.ts +3 -7
- package/dist/generated/server/server-exports.d.ts +19 -21
- package/dist/generated/server/server.cjs.map +1 -1
- package/dist/generated/server/server.d.ts +113 -87
- package/dist/generated/subgraph.d.ts +329 -332
- package/dist/index.browser.d.ts +47 -96
- package/dist/index.browser.js +12 -0
- package/dist/index.browser.js.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/index.node.cjs +9 -0
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.d.ts +181 -87
- package/dist/index.node.js +10 -0
- package/dist/index.node.js.map +1 -1
- package/dist/node.d.ts +4 -2
- package/dist/platform/browser-only.d.ts +5 -8
- package/dist/platform/browser-only.test.d.ts +1 -0
- package/dist/platform/browser-safe.d.ts +6 -9
- package/dist/platform/browser-safe.test.d.ts +1 -0
- package/dist/platform/browser.cjs +7 -6
- package/dist/platform/browser.cjs.map +1 -1
- package/dist/platform/browser.d.ts +3 -6
- package/dist/platform/browser.js +19 -27
- package/dist/platform/browser.js.map +1 -1
- package/dist/platform/browser.test.d.ts +1 -0
- package/dist/platform/index.d.ts +11 -5
- package/dist/platform/interface.d.ts +6 -8
- package/dist/platform/node.d.ts +3 -7
- package/dist/platform/node.js +12 -19
- package/dist/platform/node.js.map +1 -1
- package/dist/platform/ports/openpgp-port.cjs +74 -0
- package/dist/platform/ports/openpgp-port.cjs.map +1 -0
- package/dist/platform/ports/openpgp-port.d.ts +13 -0
- package/dist/platform/ports/openpgp-port.js +59 -0
- package/dist/platform/ports/openpgp-port.js.map +1 -0
- package/dist/platform/ports/pgp-port.cjs +17 -0
- package/dist/platform/ports/pgp-port.cjs.map +1 -0
- package/dist/platform/ports/pgp-port.d.ts +35 -0
- package/dist/platform/ports/pgp-port.js +1 -0
- package/dist/platform/ports/pgp-port.js.map +1 -0
- package/dist/platform/shared/error-utils.d.ts +2 -4
- package/dist/platform/shared/pgp-utils.cjs +2 -2
- package/dist/platform/shared/pgp-utils.cjs.map +1 -1
- package/dist/platform/shared/pgp-utils.d.ts +3 -5
- package/dist/platform/shared/pgp-utils.js +2 -2
- package/dist/platform/shared/pgp-utils.js.map +1 -1
- package/dist/platform/shared/stream-utils.d.ts +1 -3
- package/dist/platform/utils.d.ts +6 -10
- package/dist/platform/utils.test.d.ts +1 -0
- package/dist/platform.browser.d.ts +9 -4
- package/dist/platform.d.ts +11 -5
- package/dist/platform.node.d.ts +10 -5
- package/dist/server/handler.cjs.map +1 -1
- package/dist/server/handler.d.ts +8 -227
- package/dist/server/handler.js.map +1 -1
- package/dist/storage/index.d.ts +56 -10
- package/dist/storage/manager.cjs +2 -2
- package/dist/storage/manager.cjs.map +1 -1
- package/dist/storage/manager.d.ts +2 -5
- package/dist/storage/manager.js +5 -12
- package/dist/storage/manager.js.map +1 -1
- package/dist/storage/providers/callback-storage.cjs +3 -3
- package/dist/storage/providers/callback-storage.cjs.map +1 -1
- package/dist/storage/providers/callback-storage.d.ts +3 -9
- package/dist/storage/providers/callback-storage.js +3 -3
- package/dist/storage/providers/callback-storage.js.map +1 -1
- package/dist/storage/providers/google-drive.cjs +2 -2
- package/dist/storage/providers/google-drive.cjs.map +1 -1
- package/dist/storage/providers/google-drive.d.ts +3 -7
- package/dist/storage/providers/google-drive.js +4 -7
- package/dist/storage/providers/google-drive.js.map +1 -1
- package/dist/storage/providers/google-drive.test.d.ts +1 -0
- package/dist/storage/providers/ipfs.cjs +5 -5
- package/dist/storage/providers/ipfs.cjs.map +1 -1
- package/dist/storage/providers/ipfs.d.ts +3 -6
- package/dist/storage/providers/ipfs.js +7 -10
- package/dist/storage/providers/ipfs.js.map +1 -1
- package/dist/storage/providers/pinata.cjs +6 -6
- package/dist/storage/providers/pinata.cjs.map +1 -1
- package/dist/storage/providers/pinata.d.ts +5 -8
- package/dist/storage/providers/pinata.js +8 -11
- package/dist/storage/providers/pinata.js.map +1 -1
- package/dist/storage/tests/callbackStorage.test.d.ts +1 -0
- package/dist/storage/tests/googleDriveStorage.test.d.ts +1 -0
- package/dist/storage/tests/ipfsStorage.test.d.ts +1 -0
- package/dist/storage/tests/pinataStorage.test.d.ts +1 -0
- package/dist/storage/tests/storageManager.test.d.ts +1 -0
- package/dist/tests/abi.test.d.ts +1 -0
- package/dist/tests/chains-definitions.test.d.ts +1 -0
- package/dist/tests/core-encryption.test.d.ts +1 -0
- package/dist/tests/core-extended.test.d.ts +1 -0
- package/dist/tests/core-generics-coverage.test.d.ts +1 -0
- package/dist/tests/coverage-boost.test.d.ts +1 -0
- package/dist/tests/crypto-cross-platform-compatibility.test.d.ts +1 -0
- package/dist/tests/data-addfile-permissions-schema.test.d.ts +1 -0
- package/dist/tests/data-additional-methods.test.d.ts +1 -0
- package/dist/tests/data-controller-edge-cases.test.d.ts +1 -0
- package/dist/tests/data-ipfs-gateways.test.d.ts +1 -0
- package/dist/tests/data-relayer.test.d.ts +1 -0
- package/dist/tests/data-schema-validation.test.d.ts +1 -0
- package/dist/tests/data-simple-methods.test.d.ts +1 -0
- package/dist/tests/data.test.d.ts +1 -0
- package/dist/tests/demo-integration.test.d.ts +1 -0
- package/dist/tests/demo-trusted-server-integration.test.d.ts +1 -0
- package/dist/tests/download-relayer.test.d.ts +1 -0
- package/dist/tests/dual-mode-permissions.test.d.ts +1 -0
- package/dist/tests/dual-mode-trusted-servers.test.d.ts +1 -0
- package/dist/tests/encryption-correct-implementation.test.d.ts +1 -0
- package/dist/tests/encryption-coverage.test.d.ts +1 -0
- package/dist/tests/encryption-edge-cases.test.d.ts +1 -0
- package/dist/tests/encryption-utils-updated.test.d.ts +1 -0
- package/dist/tests/errors-coverage.test.d.ts +1 -0
- package/dist/tests/errors.test.d.ts +1 -0
- package/dist/tests/factories/mockFactory.d.ts +316 -0
- package/dist/tests/fakes/FakeStorageManager.d.ts +200 -0
- package/dist/tests/fakes/FakeStorageManager.test.d.ts +1 -0
- package/dist/tests/fakes/FakeWaitForTransactionEvents.d.ts +170 -0
- package/dist/tests/fakes/FakeWaitForTransactionEvents.test.d.ts +1 -0
- package/dist/tests/fakes/fake-pgp-port.d.ts +13 -0
- package/dist/tests/grantValidation-edge-cases.test.d.ts +1 -0
- package/dist/tests/grantValidation-unreachable-branch.test.d.ts +1 -0
- package/dist/tests/helper-methods.test.d.ts +1 -0
- package/dist/tests/helpers/platformTestHelpers.d.ts +106 -0
- package/dist/tests/helpers/typedMocks.d.ts +64 -0
- package/dist/tests/index-browser.test.d.ts +1 -0
- package/dist/tests/index-node.test.d.ts +1 -0
- package/dist/tests/index.test.d.ts +1 -0
- package/dist/tests/mocks/platformAdapter.d.ts +12 -0
- package/dist/tests/new-permissions-methods.test.d.ts +1 -0
- package/dist/tests/no-buffer-browser.test.d.ts +1 -0
- package/dist/tests/permissions-grantee.test.d.ts +1 -0
- package/dist/tests/permissions-schema-validation.test.d.ts +1 -0
- package/dist/tests/permissions-server-files.test.d.ts +1 -0
- package/dist/tests/permissions-trust-servers.test.d.ts +1 -0
- package/dist/tests/permissions.test.d.ts +1 -0
- package/dist/tests/personal.test.d.ts +1 -0
- package/dist/tests/platform-browser.test.d.ts +1 -0
- package/dist/tests/platform-crypto-expanded.test.d.ts +1 -0
- package/dist/tests/platform-crypto.test.d.ts +1 -0
- package/dist/tests/platform-index.test.d.ts +1 -0
- package/dist/tests/platform-node.test.d.ts +1 -0
- package/dist/tests/platform-shared-utils.test.d.ts +1 -0
- package/dist/tests/platform-updated.test.d.ts +1 -0
- package/dist/tests/protocol-additional-methods.test.d.ts +1 -0
- package/dist/tests/protocol.test.d.ts +1 -0
- package/dist/tests/read-only-mode.test.d.ts +1 -0
- package/dist/tests/schemas.test.d.ts +1 -0
- package/dist/tests/server-handler.test.d.ts +1 -0
- package/dist/tests/setup.d.ts +7 -0
- package/dist/tests/signatureFormatter.test.d.ts +1 -0
- package/dist/tests/trusted-server-queries.test.d.ts +1 -0
- package/dist/tests/typedDataConverter.test.d.ts +1 -0
- package/dist/tests/types-contracts.test.d.ts +1 -0
- package/dist/tests/types-data.test.d.ts +1 -0
- package/dist/tests/types-external-apis.test.d.ts +1 -0
- package/dist/tests/types-generics.test.d.ts +1 -0
- package/dist/tests/types-permissions.test.d.ts +1 -0
- package/dist/tests/types-upload-params.test.d.ts +1 -0
- package/dist/tests/types.test.d.ts +1 -0
- package/dist/tests/utils-formatters.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles-edge-cases.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles-validation.test.d.ts +1 -0
- package/dist/tests/utils-grantFiles.test.d.ts +1 -0
- package/dist/tests/utils-grantValidation-consolidated.test.d.ts +1 -0
- package/dist/tests/utils-grants.test.d.ts +1 -0
- package/dist/tests/utils-ipfs-additional.test.d.ts +1 -0
- package/dist/tests/utils-ipfs.test.d.ts +4 -0
- package/dist/tests/utils-schemaValidation.test.d.ts +1 -0
- package/dist/tests/vana.test.d.ts +1 -0
- package/dist/tests/wallet-crypto-compatibility.test.d.ts +1 -0
- package/dist/types/blockchain.cjs.map +1 -1
- package/dist/types/blockchain.d.ts +13 -8
- package/dist/types/chains-additional.test.d.ts +1 -0
- package/dist/types/chains.d.ts +6 -9
- package/dist/types/config.cjs +10 -0
- package/dist/types/config.cjs.map +1 -1
- package/dist/types/config.d.ts +161 -54
- package/dist/types/config.js +8 -0
- package/dist/types/config.js.map +1 -1
- package/dist/types/contracts.cjs.map +1 -1
- package/dist/types/contracts.d.ts +8 -11
- package/dist/types/controller-context.cjs.map +1 -1
- package/dist/types/controller-context.d.ts +13 -20
- package/dist/types/data.cjs.map +1 -1
- package/dist/types/data.d.ts +107 -39
- package/dist/types/external-apis.d.ts +10 -12
- package/dist/types/generics.d.ts +35 -38
- package/dist/types/index.cjs +5 -4
- package/dist/types/index.cjs.map +1 -1
- package/dist/types/index.d.ts +20 -22
- package/dist/types/index.js +9 -2
- package/dist/types/index.js.map +1 -1
- package/dist/types/operations.cjs +2 -2
- package/dist/types/operations.cjs.map +1 -1
- package/dist/types/operations.d.ts +13 -17
- package/dist/types/operations.js +2 -2
- package/dist/types/operations.js.map +1 -1
- package/dist/types/permissions.d.ts +55 -58
- package/dist/types/personal.cjs.map +1 -1
- package/dist/types/personal.d.ts +6 -8
- package/dist/types/relayer.d.ts +15 -18
- package/dist/types/storage.d.ts +6 -8
- package/dist/types/storage.js +2 -5
- package/dist/types/storage.js.map +1 -1
- package/dist/types/transactionResults.d.ts +16 -18
- package/dist/types/utils.d.ts +21 -24
- package/dist/types.d.ts +4 -28
- package/dist/utils/__tests__/parseTransaction.test.d.ts +1 -0
- package/dist/utils/__tests__/pojo-serialization.test.d.ts +1 -0
- package/dist/utils/__tests__/signatureCache.test.d.ts +1 -0
- package/dist/utils/__tests__/transaction-edge-cases.test.d.ts +1 -0
- package/dist/utils/__tests__/transactionHelpers.test.d.ts +1 -0
- package/dist/utils/__tests__/urlResolver.test.d.ts +4 -0
- package/dist/utils/blockchain/registry.cjs +2 -2
- package/dist/utils/blockchain/registry.cjs.map +1 -1
- package/dist/utils/blockchain/registry.d.ts +6 -8
- package/dist/utils/blockchain/registry.js +2 -2
- package/dist/utils/blockchain/registry.js.map +1 -1
- package/dist/utils/blockchain/registry.test.d.ts +1 -0
- package/dist/utils/crypto-utils.cjs +0 -12
- package/dist/utils/crypto-utils.cjs.map +1 -1
- package/dist/utils/crypto-utils.d.ts +9 -27
- package/dist/utils/crypto-utils.js +0 -11
- package/dist/utils/crypto-utils.js.map +1 -1
- package/dist/utils/crypto-utils.test.d.ts +1 -0
- package/dist/utils/download.cjs +3 -3
- package/dist/utils/download.cjs.map +1 -1
- package/dist/utils/download.d.ts +13 -14
- package/dist/utils/download.js +2 -2
- package/dist/utils/download.js.map +1 -1
- package/dist/utils/encoding.cjs +1 -1
- package/dist/utils/encoding.cjs.map +1 -1
- package/dist/utils/encoding.d.ts +4 -6
- package/dist/utils/encoding.js +1 -1
- package/dist/utils/encoding.js.map +1 -1
- package/dist/utils/encoding.test.d.ts +1 -0
- package/dist/utils/encryption.cjs +16 -10
- package/dist/utils/encryption.cjs.map +1 -1
- package/dist/utils/encryption.d.ts +13 -17
- package/dist/utils/encryption.js +16 -10
- package/dist/utils/encryption.js.map +1 -1
- package/dist/utils/formatters.cjs +4 -2
- package/dist/utils/formatters.cjs.map +1 -1
- package/dist/utils/formatters.d.ts +4 -6
- package/dist/utils/formatters.js +4 -2
- package/dist/utils/formatters.js.map +1 -1
- package/dist/utils/grantFiles.cjs +7 -4
- package/dist/utils/grantFiles.cjs.map +1 -1
- package/dist/utils/grantFiles.d.ts +6 -10
- package/dist/utils/grantFiles.js +7 -4
- package/dist/utils/grantFiles.js.map +1 -1
- package/dist/utils/grantValidation.cjs +1 -1
- package/dist/utils/grantValidation.cjs.map +1 -1
- package/dist/utils/grantValidation.d.ts +14 -17
- package/dist/utils/grantValidation.js +1 -1
- package/dist/utils/grantValidation.js.map +1 -1
- package/dist/utils/grants.cjs +1 -1
- package/dist/utils/grants.cjs.map +1 -1
- package/dist/utils/grants.d.ts +10 -13
- package/dist/utils/grants.js +1 -1
- package/dist/utils/grants.js.map +1 -1
- package/dist/utils/ipfs.d.ts +8 -10
- package/dist/utils/lazy-import.cjs +4 -6
- package/dist/utils/lazy-import.cjs.map +1 -1
- package/dist/utils/lazy-import.d.ts +1 -3
- package/dist/utils/lazy-import.js +4 -6
- package/dist/utils/lazy-import.js.map +1 -1
- package/dist/utils/multicall.cjs +4 -2
- package/dist/utils/multicall.cjs.map +1 -1
- package/dist/utils/multicall.d.ts +5 -8
- package/dist/utils/multicall.js +4 -2
- package/dist/utils/multicall.js.map +1 -1
- package/dist/utils/parseTransactionPojo.cjs.map +1 -1
- package/dist/utils/parseTransactionPojo.d.ts +4 -10
- package/dist/utils/parseTransactionPojo.js.map +1 -1
- package/dist/utils/schemaValidation.cjs +5 -5
- package/dist/utils/schemaValidation.cjs.map +1 -1
- package/dist/utils/schemaValidation.d.ts +8 -12
- package/dist/utils/schemaValidation.js +7 -10
- package/dist/utils/schemaValidation.js.map +1 -1
- package/dist/utils/signatureCache.cjs +1 -2
- package/dist/utils/signatureCache.cjs.map +1 -1
- package/dist/utils/signatureCache.d.ts +4 -7
- package/dist/utils/signatureCache.js +4 -8
- package/dist/utils/signatureCache.js.map +1 -1
- package/dist/utils/signatureFormatter.cjs +6 -9
- package/dist/utils/signatureFormatter.cjs.map +1 -1
- package/dist/utils/signatureFormatter.d.ts +2 -5
- package/dist/utils/signatureFormatter.js +6 -9
- package/dist/utils/signatureFormatter.js.map +1 -1
- package/dist/utils/tests/multicall.test.d.ts +1 -0
- package/dist/utils/transactionHelpers.cjs.map +1 -1
- package/dist/utils/transactionHelpers.d.ts +5 -11
- package/dist/utils/transactionHelpers.js.map +1 -1
- package/dist/utils/typeGuards.cjs +109 -0
- package/dist/utils/typeGuards.cjs.map +1 -0
- package/dist/utils/typeGuards.d.ts +138 -0
- package/dist/utils/typeGuards.js +74 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/typedDataConverter.d.ts +3 -6
- package/dist/utils/urlResolver.cjs +1 -1
- package/dist/utils/urlResolver.cjs.map +1 -1
- package/dist/utils/urlResolver.d.ts +2 -4
- package/dist/utils/urlResolver.js +2 -2
- package/dist/utils/urlResolver.js.map +1 -1
- package/dist/utils/wallet.cjs +62 -0
- package/dist/utils/wallet.cjs.map +1 -0
- package/dist/utils/wallet.d.ts +32 -0
- package/dist/utils/wallet.js +36 -0
- package/dist/utils/wallet.js.map +1 -0
- package/dist/utils/withEvents.cjs.map +1 -1
- package/dist/utils/withEvents.d.ts +5 -12
- package/dist/utils/withEvents.js.map +1 -1
- package/package.json +22 -16
- package/dist/browser.d.cts +0 -2
- package/dist/chains/definitions.d.cts +0 -53
- package/dist/chains/index.d.cts +0 -2
- package/dist/chains.browser.cjs +0 -37
- package/dist/chains.browser.cjs.map +0 -1
- package/dist/chains.browser.d.cts +0 -2
- package/dist/chains.d.cts +0 -2
- package/dist/chains.node.d.cts +0 -2
- package/dist/config/addresses.d.cts +0 -401
- package/dist/config/chains.d.cts +0 -85
- package/dist/config/features.d.cts +0 -64
- package/dist/contracts/contractController.d.cts +0 -117
- package/dist/controllers/data.d.cts +0 -915
- package/dist/controllers/permissions.d.cts +0 -1383
- package/dist/controllers/protocol.d.cts +0 -188
- package/dist/controllers/schemas.d.cts +0 -260
- package/dist/controllers/server.d.cts +0 -230
- package/dist/core/apiClient.d.cts +0 -165
- package/dist/core/client.d.cts +0 -92
- package/dist/core/generics.d.cts +0 -120
- package/dist/core.d.cts +0 -493
- package/dist/crypto/ecies/__tests__/test-vectors.d.cts +0 -40
- package/dist/crypto/ecies/base.d.cts +0 -143
- package/dist/crypto/ecies/browser.d.cts +0 -48
- package/dist/crypto/ecies/constants.d.cts +0 -122
- package/dist/crypto/ecies/index.d.cts +0 -1
- package/dist/crypto/ecies/interface.d.cts +0 -176
- package/dist/crypto/ecies/node.d.cts +0 -50
- package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.cts +0 -76
- package/dist/crypto/ecies/test-vectors/eccrypto-vectors.d.ts +0 -76
- package/dist/crypto/ecies/utils.d.cts +0 -67
- package/dist/crypto/services/WalletKeyEncryptionService.d.cts +0 -92
- package/dist/diagnostics.d.cts +0 -26
- package/dist/errors.d.cts +0 -350
- package/dist/generated/abi/ComputeEngineImplementation.d.cts +0 -996
- package/dist/generated/abi/ComputeInstructionRegistryImplementation.d.cts +0 -545
- package/dist/generated/abi/DATFactoryImplementation.d.cts +0 -661
- package/dist/generated/abi/DATImplementation.d.cts +0 -693
- package/dist/generated/abi/DATPausableImplementation.d.cts +0 -1145
- package/dist/generated/abi/DATVotesImplementation.d.cts +0 -1095
- package/dist/generated/abi/DLPPerformanceImplementation.d.cts +0 -883
- package/dist/generated/abi/DLPRegistryImplementation.d.cts +0 -1123
- package/dist/generated/abi/DLPRegistryTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardDeployerImplementation.d.cts +0 -714
- package/dist/generated/abi/DLPRewardDeployerTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DLPRewardSwapImplementation.d.cts +0 -706
- package/dist/generated/abi/DLPRootImplementation.d.cts +0 -1248
- package/dist/generated/abi/DLPTreasuryImplementation.d.cts +0 -452
- package/dist/generated/abi/DataLiquidityPoolImplementation.d.cts +0 -737
- package/dist/generated/abi/DataPortabilityGranteesImplementation.d.cts +0 -661
- package/dist/generated/abi/DataPortabilityPermissionsImplementation.d.cts +0 -989
- package/dist/generated/abi/DataPortabilityServersImplementation.d.cts +0 -1086
- package/dist/generated/abi/DataRefinerRegistryImplementation.d.cts +0 -737
- package/dist/generated/abi/DataRegistryImplementation.d.cts +0 -1014
- package/dist/generated/abi/QueryEngineImplementation.d.cts +0 -1001
- package/dist/generated/abi/SwapHelperImplementation.d.cts +0 -764
- package/dist/generated/abi/TeePoolDedicatedGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolDedicatedStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolEphemeralStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolImplementation.d.cts +0 -993
- package/dist/generated/abi/TeePoolPersistentGpuImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPersistentStandardImplementation.d.cts +0 -701
- package/dist/generated/abi/TeePoolPhalaImplementation.d.cts +0 -993
- package/dist/generated/abi/VanaEpochImplementation.d.cts +0 -900
- package/dist/generated/abi/VanaPoolEntityImplementation.d.cts +0 -934
- package/dist/generated/abi/VanaPoolStakingImplementation.d.cts +0 -693
- package/dist/generated/abi/VanaPoolTreasuryImplementation.d.cts +0 -394
- package/dist/generated/abi/index.d.cts +0 -26547
- package/dist/generated/event-types.d.cts +0 -855
- package/dist/generated/eventRegistry.d.cts +0 -18
- package/dist/generated/server/server-exports.d.cts +0 -21
- package/dist/generated/server/server.d.cts +0 -512
- package/dist/generated/subgraph.d.cts +0 -5981
- package/dist/index.browser.cjs +0 -151
- package/dist/index.browser.cjs.map +0 -1
- package/dist/index.browser.d.cts +0 -201
- package/dist/index.d.cts +0 -2
- package/dist/index.node.d.cts +0 -87
- package/dist/node.d.cts +0 -2
- package/dist/platform/browser-only.d.cts +0 -25
- package/dist/platform/browser-safe.d.cts +0 -32
- package/dist/platform/browser.d.cts +0 -74
- package/dist/platform/index.d.cts +0 -5
- package/dist/platform/interface.d.cts +0 -218
- package/dist/platform/node.d.cts +0 -27
- package/dist/platform/shared/error-utils.d.cts +0 -25
- package/dist/platform/shared/pgp-utils.d.cts +0 -61
- package/dist/platform/shared/stream-utils.d.cts +0 -16
- package/dist/platform/utils.d.cts +0 -53
- package/dist/platform.browser.cjs +0 -41
- package/dist/platform.browser.cjs.map +0 -1
- package/dist/platform.browser.d.cts +0 -4
- package/dist/platform.d.cts +0 -5
- package/dist/platform.node.d.cts +0 -5
- package/dist/schemas/dataSchema.schema.d.cts +0 -88
- package/dist/schemas/dataSchema.schema.d.ts +0 -88
- package/dist/schemas/grantFile.schema.d.cts +0 -57
- package/dist/schemas/grantFile.schema.d.ts +0 -57
- package/dist/server/handler.d.cts +0 -306
- package/dist/storage/index.d.cts +0 -10
- package/dist/storage/manager.d.cts +0 -150
- package/dist/storage/providers/callback-storage.d.cts +0 -100
- package/dist/storage/providers/google-drive.d.cts +0 -156
- package/dist/storage/providers/ipfs.d.cts +0 -163
- package/dist/storage/providers/pinata.d.cts +0 -173
- package/dist/types/blockchain.d.cts +0 -52
- package/dist/types/chains.d.cts +0 -34
- package/dist/types/config.d.cts +0 -726
- package/dist/types/contracts.d.cts +0 -68
- package/dist/types/controller-context.d.cts +0 -71
- package/dist/types/data.d.cts +0 -694
- package/dist/types/eccrypto-js.d.d.cts +0 -13
- package/dist/types/eccrypto-js.d.d.ts +0 -13
- package/dist/types/external-apis.d.cts +0 -186
- package/dist/types/generics.d.cts +0 -450
- package/dist/types/index.d.cts +0 -22
- package/dist/types/operations.d.cts +0 -116
- package/dist/types/permissions.d.cts +0 -957
- package/dist/types/personal.d.cts +0 -40
- package/dist/types/relayer.d.cts +0 -284
- package/dist/types/storage.d.cts +0 -131
- package/dist/types/transactionResults.d.cts +0 -195
- package/dist/types/utils.d.cts +0 -819
- package/dist/types.d.cts +0 -54
- package/dist/utils/blockchain/registry.d.cts +0 -34
- package/dist/utils/crypto-utils.d.cts +0 -118
- package/dist/utils/download.d.cts +0 -41
- package/dist/utils/encoding.d.cts +0 -54
- package/dist/utils/encryption.d.cts +0 -275
- package/dist/utils/formatters.d.cts +0 -120
- package/dist/utils/grantFiles.d.cts +0 -186
- package/dist/utils/grantValidation.d.cts +0 -150
- package/dist/utils/grants.d.cts +0 -70
- package/dist/utils/ipfs.d.cts +0 -90
- package/dist/utils/lazy-import.d.cts +0 -20
- package/dist/utils/multicall.d.cts +0 -129
- package/dist/utils/parseTransactionPojo.d.cts +0 -37
- package/dist/utils/schemaValidation.d.cts +0 -172
- package/dist/utils/signatureCache.d.cts +0 -134
- package/dist/utils/signatureFormatter.d.cts +0 -39
- package/dist/utils/transactionHelpers.d.cts +0 -86
- package/dist/utils/typedDataConverter.d.cts +0 -13
- package/dist/utils/urlResolver.d.cts +0 -40
- package/dist/utils/withEvents.d.cts +0 -63
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/signatureFormatter.ts"],"sourcesContent":["import type
|
|
1
|
+
{"version":3,"sources":["../../src/utils/signatureFormatter.ts"],"sourcesContent":["import { type Hash, fromHex, toHex } from \"viem\";\n\nconst V_OFFSET_FOR_ETHEREUM = 27;\n\n/**\n * Formats a signature for Ethereum smart contract compatibility by adjusting the v-value.\n *\n * @remarks\n * This function ensures signature compatibility with Ethereum smart contracts by adjusting\n * the v-value component of ECDSA signatures. Some wallet implementations and signing methods\n * produce signatures with v-values in the range [0, 1], while Ethereum smart contracts\n * expect v-values in the range [27, 28] for proper signature verification.\n *\n * The function automatically detects signatures with low v-values and applies the standard\n * Ethereum offset (+27) to ensure compatibility. This is particularly important for gasless\n * transactions and EIP-712 signature verification in smart contracts.\n *\n * **Technical Details:**\n * - Ethereum signatures consist of r (32 bytes) + s (32 bytes) + v (1 byte) = 65 bytes total\n * - Valid v-values for Ethereum are 27 or 28 (or 0/1 + chain-specific offset for EIP-155)\n * - This function handles the common case where v ∈ [0, 1] needs adjustment to [27, 28]\n *\n * @param signature - The ECDSA signature hash to format (65 bytes as hex string)\n * @returns The formatted signature with correct v-value for Ethereum contract verification\n * @example\n * ```typescript\n * // Signature with v-value that needs adjustment\n * const rawSignature = \"0x1234...5600\"; // v = 0 (last byte)\n * const formatted = formatSignatureForContract(rawSignature);\n * // Result: \"0x1234...561b\" // v = 27 (0x1b)\n *\n * // Already properly formatted signature remains unchanged\n * const goodSignature = \"0x1234...561b\"; // v = 27\n * const unchanged = formatSignatureForContract(goodSignature);\n * // Result: \"0x1234...561b\" (no change needed)\n * ```\n * @category Cryptography\n */\nexport function formatSignatureForContract(signature: Hash): Hash {\n // Convert to bytes for safer manipulation\n const sigBytes = fromHex(signature, \"bytes\");\n\n if (sigBytes.length !== 65) {\n return signature;\n }\n\n // Extract v value (last byte)\n const v = sigBytes[64];\n\n if (v < 27) {\n // Adjust v value\n sigBytes[64] = v + V_OFFSET_FOR_ETHEREUM;\n // Convert back to hex\n return toHex(sigBytes);\n }\n\n return signature;\n}\n"],"mappings":"AAAA,SAAoB,SAAS,aAAa;AAE1C,MAAM,wBAAwB;AAoCvB,SAAS,2BAA2B,WAAuB;AAEhE,QAAM,WAAW,QAAQ,WAAW,OAAO;AAE3C,MAAI,SAAS,WAAW,IAAI;AAC1B,WAAO;AAAA,EACT;AAGA,QAAM,IAAI,SAAS,EAAE;AAErB,MAAI,IAAI,IAAI;AAEV,aAAS,EAAE,IAAI,IAAI;AAEnB,WAAO,MAAM,QAAQ;AAAA,EACvB;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from
|
|
1
|
+
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type { TransactionResult } from \"../types/operations\";\nimport type { Contract, Fn } from \"../generated/event-types\";\n\n/**\n * Creates a strongly-typed TransactionResult POJO.\n *\n * @remarks\n * This helper ensures all required fields are present and typed correctly,\n * reducing boilerplate and preventing mistakes.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name\n * @param input.fn - Function name\n * @param input.chainId - Optional chain ID\n * @param input.value - Optional transaction value\n * @param input.nonce - Optional nonce\n * @param input.to - Optional recipient address\n * @returns Typed TransactionResult\n *\n * @example\n * ```typescript\n * return tx({\n * hash,\n * from: account.address,\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\",\n * });\n * ```\n */\nexport function tx<C extends Contract, F extends Fn<C>>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n\n/**\n * Creates a transaction result with literal type inference.\n * Use this when you need TypeScript to preserve exact string literals.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name\n * @param input.fn - Function name\n * @param input.chainId - Optional chain ID\n * @param input.value - Optional transaction value\n * @param input.nonce - Optional nonce\n * @param input.to - Optional recipient address\n * @returns Typed TransactionResult\n *\n * @example\n * ```typescript\n * const transaction = txLiteral({\n * hash: '0x...',\n * from: '0x...',\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\",\n * });\n * // TypeScript knows exactly: DataPortabilityPermissions + revokePermission\n * ```\n */\nexport function txLiteral<\n const C extends Contract,\n const F extends Fn<C>,\n>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCO,SAAS,GAAwC,OAS5B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;AA4BO,SAAS,UAGd,OAS0B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { Hash, Address } from 'viem';
|
|
2
|
-
import { TransactionResult } from '../types/operations.js';
|
|
3
|
-
import { Contract, Fn } from '../generated/event-types.js';
|
|
4
|
-
import '../generated/server/server-exports.js';
|
|
5
|
-
import '../generated/server/server.js';
|
|
6
|
-
|
|
7
1
|
/**
|
|
8
2
|
* Helper functions for creating typed transaction POJOs
|
|
9
3
|
*/
|
|
10
|
-
|
|
4
|
+
import type { Hash, Address } from "viem";
|
|
5
|
+
import type { TransactionResult } from "../types/operations";
|
|
6
|
+
import type { Contract, Fn } from "../generated/event-types";
|
|
11
7
|
/**
|
|
12
8
|
* Creates a strongly-typed TransactionResult POJO.
|
|
13
9
|
*
|
|
@@ -36,7 +32,7 @@ import '../generated/server/server.js';
|
|
|
36
32
|
* });
|
|
37
33
|
* ```
|
|
38
34
|
*/
|
|
39
|
-
declare function tx<C extends Contract, F extends Fn<C>>(input: {
|
|
35
|
+
export declare function tx<C extends Contract, F extends Fn<C>>(input: {
|
|
40
36
|
hash: Hash;
|
|
41
37
|
from: Address;
|
|
42
38
|
contract: C;
|
|
@@ -72,7 +68,7 @@ declare function tx<C extends Contract, F extends Fn<C>>(input: {
|
|
|
72
68
|
* // TypeScript knows exactly: DataPortabilityPermissions + revokePermission
|
|
73
69
|
* ```
|
|
74
70
|
*/
|
|
75
|
-
declare function txLiteral<const C extends Contract, const F extends Fn<C>>(input: {
|
|
71
|
+
export declare function txLiteral<const C extends Contract, const F extends Fn<C>>(input: {
|
|
76
72
|
hash: Hash;
|
|
77
73
|
from: Address;
|
|
78
74
|
contract: C;
|
|
@@ -82,5 +78,3 @@ declare function txLiteral<const C extends Contract, const F extends Fn<C>>(inpu
|
|
|
82
78
|
nonce?: number;
|
|
83
79
|
to?: Address;
|
|
84
80
|
}): TransactionResult<C, F>;
|
|
85
|
-
|
|
86
|
-
export { tx, txLiteral };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from
|
|
1
|
+
{"version":3,"sources":["../../src/utils/transactionHelpers.ts"],"sourcesContent":["/**\n * Helper functions for creating typed transaction POJOs\n */\n\nimport type { Hash, Address } from \"viem\";\nimport type { TransactionResult } from \"../types/operations\";\nimport type { Contract, Fn } from \"../generated/event-types\";\n\n/**\n * Creates a strongly-typed TransactionResult POJO.\n *\n * @remarks\n * This helper ensures all required fields are present and typed correctly,\n * reducing boilerplate and preventing mistakes.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name\n * @param input.fn - Function name\n * @param input.chainId - Optional chain ID\n * @param input.value - Optional transaction value\n * @param input.nonce - Optional nonce\n * @param input.to - Optional recipient address\n * @returns Typed TransactionResult\n *\n * @example\n * ```typescript\n * return tx({\n * hash,\n * from: account.address,\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\",\n * });\n * ```\n */\nexport function tx<C extends Contract, F extends Fn<C>>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n\n/**\n * Creates a transaction result with literal type inference.\n * Use this when you need TypeScript to preserve exact string literals.\n *\n * @param input - Transaction details\n * @param input.hash - Transaction hash\n * @param input.from - Transaction sender address\n * @param input.contract - Contract name\n * @param input.fn - Function name\n * @param input.chainId - Optional chain ID\n * @param input.value - Optional transaction value\n * @param input.nonce - Optional nonce\n * @param input.to - Optional recipient address\n * @returns Typed TransactionResult\n *\n * @example\n * ```typescript\n * const transaction = txLiteral({\n * hash: '0x...',\n * from: '0x...',\n * contract: \"DataPortabilityPermissions\",\n * fn: \"revokePermission\",\n * });\n * // TypeScript knows exactly: DataPortabilityPermissions + revokePermission\n * ```\n */\nexport function txLiteral<\n const C extends Contract,\n const F extends Fn<C>,\n>(input: {\n hash: Hash;\n from: Address;\n contract: C;\n fn: F;\n chainId?: number;\n value?: bigint;\n nonce?: number;\n to?: Address;\n}): TransactionResult<C, F> {\n // Create a new plain object to ensure independence and true POJO behavior\n return {\n hash: input.hash,\n from: input.from,\n contract: input.contract,\n fn: input.fn,\n ...(input.chainId !== undefined && { chainId: input.chainId }),\n ...(input.value !== undefined && { value: input.value }),\n ...(input.nonce !== undefined && { nonce: input.nonce }),\n ...(input.to !== undefined && { to: input.to }),\n };\n}\n"],"mappings":"AAoCO,SAAS,GAAwC,OAS5B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;AA4BO,SAAS,UAGd,OAS0B;AAE1B,SAAO;AAAA,IACL,MAAM,MAAM;AAAA,IACZ,MAAM,MAAM;AAAA,IACZ,UAAU,MAAM;AAAA,IAChB,IAAI,MAAM;AAAA,IACV,GAAI,MAAM,YAAY,UAAa,EAAE,SAAS,MAAM,QAAQ;AAAA,IAC5D,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,UAAU,UAAa,EAAE,OAAO,MAAM,MAAM;AAAA,IACtD,GAAI,MAAM,OAAO,UAAa,EAAE,IAAI,MAAM,GAAG;AAAA,EAC/C;AACF;","names":[]}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 typeGuards_exports = {};
|
|
20
|
+
__export(typeGuards_exports, {
|
|
21
|
+
assertDefined: () => assertDefined,
|
|
22
|
+
assertHasProperties: () => assertHasProperties,
|
|
23
|
+
assertNonEmptyString: () => assertNonEmptyString,
|
|
24
|
+
ensureDefault: () => ensureDefault,
|
|
25
|
+
ensureError: () => ensureError,
|
|
26
|
+
hasProperty: () => hasProperty,
|
|
27
|
+
isArray: () => isArray,
|
|
28
|
+
isDefined: () => isDefined,
|
|
29
|
+
isNonEmptyString: () => isNonEmptyString,
|
|
30
|
+
isObject: () => isObject,
|
|
31
|
+
safeArrayAccess: () => safeArrayAccess,
|
|
32
|
+
safeGet: () => safeGet
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(typeGuards_exports);
|
|
35
|
+
function assertDefined(value, message) {
|
|
36
|
+
if (value === void 0 || value === null) {
|
|
37
|
+
throw new Error(message);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function isDefined(value) {
|
|
41
|
+
return value !== void 0 && value !== null;
|
|
42
|
+
}
|
|
43
|
+
function assertNonEmptyString(value, message) {
|
|
44
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
45
|
+
throw new Error(message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function isNonEmptyString(value) {
|
|
49
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
50
|
+
}
|
|
51
|
+
function safeGet(obj, key) {
|
|
52
|
+
return obj?.[key];
|
|
53
|
+
}
|
|
54
|
+
function ensureDefault(value, defaultValue) {
|
|
55
|
+
return isDefined(value) ? value : defaultValue;
|
|
56
|
+
}
|
|
57
|
+
function isObject(value) {
|
|
58
|
+
return typeof value === "object" && value !== null;
|
|
59
|
+
}
|
|
60
|
+
function isArray(value) {
|
|
61
|
+
return Array.isArray(value);
|
|
62
|
+
}
|
|
63
|
+
function safeArrayAccess(array, index) {
|
|
64
|
+
if (!array || index < 0 || index >= array.length) {
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
return array[index];
|
|
68
|
+
}
|
|
69
|
+
function hasProperty(obj, prop) {
|
|
70
|
+
return isObject(obj) && prop in obj;
|
|
71
|
+
}
|
|
72
|
+
function assertHasProperties(obj, properties, message) {
|
|
73
|
+
if (!isObject(obj)) {
|
|
74
|
+
throw new Error(`${message}: Value is not an object`);
|
|
75
|
+
}
|
|
76
|
+
for (const prop of properties) {
|
|
77
|
+
if (!(prop in obj)) {
|
|
78
|
+
throw new Error(`${message}: Missing required property '${prop}'`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function ensureError(error, fallbackMessage) {
|
|
83
|
+
if (error instanceof Error) {
|
|
84
|
+
return error;
|
|
85
|
+
}
|
|
86
|
+
if (typeof error === "string") {
|
|
87
|
+
return new Error(error);
|
|
88
|
+
}
|
|
89
|
+
if (isObject(error) && "message" in error && typeof error.message === "string") {
|
|
90
|
+
return new Error(error.message);
|
|
91
|
+
}
|
|
92
|
+
return new Error(fallbackMessage);
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
assertDefined,
|
|
97
|
+
assertHasProperties,
|
|
98
|
+
assertNonEmptyString,
|
|
99
|
+
ensureDefault,
|
|
100
|
+
ensureError,
|
|
101
|
+
hasProperty,
|
|
102
|
+
isArray,
|
|
103
|
+
isDefined,
|
|
104
|
+
isNonEmptyString,
|
|
105
|
+
isObject,
|
|
106
|
+
safeArrayAccess,
|
|
107
|
+
safeGet
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=typeGuards.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/typeGuards.ts"],"sourcesContent":["/**\n * Type guard utilities for runtime type checking and assertions.\n * These utilities provide type-safe alternatives to non-null assertions (!).\n *\n * @module typeGuards\n */\n\n/**\n * Asserts that a value is defined (not null or undefined).\n * Throws an error with a descriptive message if the assertion fails.\n *\n * @param value - The value to check\n * @param message - Error message to throw if value is not defined\n * @throws {Error} If value is null or undefined\n *\n * @example\n * ```typescript\n * const wallet = getWallet();\n * assertDefined(wallet, 'Wallet must be initialized before use');\n * // TypeScript now knows wallet is defined\n * console.log(wallet.address);\n * ```\n */\nexport function assertDefined<T>(\n value: T | undefined | null,\n message: string,\n): asserts value is T {\n if (value === undefined || value === null) {\n throw new Error(message);\n }\n}\n\n/**\n * Type guard to check if a value is defined (not null or undefined).\n *\n * @param value - The value to check\n * @returns True if the value is defined, false otherwise\n *\n * @example\n * ```typescript\n * const values = [1, undefined, 3, null, 5];\n * const defined = values.filter(isDefined); // [1, 3, 5]\n * ```\n */\nexport function isDefined<T>(value: T | undefined | null): value is T {\n return value !== undefined && value !== null;\n}\n\n/**\n * Asserts that a value is a non-empty string.\n *\n * @param value - The value to check\n * @param message - Error message if assertion fails\n * @throws {Error} If value is not a non-empty string\n */\nexport function assertNonEmptyString(\n value: unknown,\n message: string,\n): asserts value is string {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new Error(message);\n }\n}\n\n/**\n * Type guard to check if a value is a non-empty string.\n *\n * @param value - The value to check\n * @returns True if value is a non-empty string\n */\nexport function isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\n/**\n * Safely gets a property from an object, returning undefined if the property doesn't exist.\n *\n * @param obj - The object to get the property from\n * @param key - The property key\n * @returns The property value or undefined\n *\n * @example\n * ```typescript\n * const config = { wallet: { address: '0x123' } };\n * const address = safeGet(config, 'wallet')?.address;\n * ```\n */\nexport function safeGet<T, K extends keyof T>(\n obj: T | undefined | null,\n key: K,\n): T[K] | undefined {\n return obj?.[key];\n}\n\n/**\n * Ensures a value is defined or returns a default value.\n *\n * @param value - The value to check\n * @param defaultValue - The default value to use if undefined\n * @returns The value if defined, otherwise the default\n *\n * @example\n * ```typescript\n * const timeout = ensureDefault(config.timeout, 5000);\n * ```\n */\nexport function ensureDefault<T>(\n value: T | undefined | null,\n defaultValue: T,\n): T {\n return isDefined(value) ? value : defaultValue;\n}\n\n/**\n * Type guard for checking if a value is an object (and not null).\n *\n * @param value - The value to check\n * @returns True if value is an object\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Type guard for checking if a value is an array.\n *\n * @param value - The value to check\n * @returns True if value is an array\n */\nexport function isArray<T = unknown>(value: unknown): value is T[] {\n return Array.isArray(value);\n}\n\n/**\n * Safely accesses an array element, returning undefined if out of bounds.\n *\n * @param array - The array to access\n * @param index - The index to access\n * @returns The element at the index or undefined\n *\n * @example\n * ```typescript\n * const items = [1, 2, 3];\n * const item = safeArrayAccess(items, 5); // undefined\n * ```\n */\nexport function safeArrayAccess<T>(\n array: T[] | undefined | null,\n index: number,\n): T | undefined {\n if (!array || index < 0 || index >= array.length) {\n return undefined;\n }\n return array[index];\n}\n\n/**\n * Type guard to check if a value has a specific property.\n *\n * @param obj - The object to check\n * @param prop - The property name\n * @returns True if the object has the property\n *\n * @example\n * ```typescript\n * if (hasProperty(response, 'error')) {\n * console.error(response.error);\n * }\n * ```\n */\nexport function hasProperty<T extends string>(\n obj: unknown,\n prop: T,\n): obj is Record<T, unknown> {\n return isObject(obj) && prop in obj;\n}\n\n/**\n * Asserts that an object has required properties.\n *\n * @param obj - The object to check\n * @param properties - Array of required property names\n * @param message - Error message if assertion fails\n * @throws {Error} If any required property is missing\n */\nexport function assertHasProperties<T extends string>(\n obj: unknown,\n properties: T[],\n message: string,\n): asserts obj is Record<T, unknown> {\n if (!isObject(obj)) {\n throw new Error(`${message}: Value is not an object`);\n }\n\n for (const prop of properties) {\n if (!(prop in obj)) {\n throw new Error(`${message}: Missing required property '${prop}'`);\n }\n }\n}\n\n/**\n * Creates a type-safe error with a guaranteed message.\n *\n * @param error - The error or unknown value\n * @param fallbackMessage - Message to use if error doesn't have one\n * @returns An Error object with a message\n */\nexport function ensureError(error: unknown, fallbackMessage: string): Error {\n if (error instanceof Error) {\n return error;\n }\n if (typeof error === \"string\") {\n return new Error(error);\n }\n if (\n isObject(error) &&\n \"message\" in error &&\n typeof error.message === \"string\"\n ) {\n return new Error(error.message);\n }\n return new Error(fallbackMessage);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuBO,SAAS,cACd,OACA,SACoB;AACpB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;AAcO,SAAS,UAAa,OAAyC;AACpE,SAAO,UAAU,UAAa,UAAU;AAC1C;AASO,SAAS,qBACd,OACA,SACyB;AACzB,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,WAAW,GAAG;AAC1D,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;AAQO,SAAS,iBAAiB,OAAiC;AAChE,SAAO,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,SAAS;AAC5D;AAeO,SAAS,QACd,KACA,KACkB;AAClB,SAAO,MAAM,GAAG;AAClB;AAcO,SAAS,cACd,OACA,cACG;AACH,SAAO,UAAU,KAAK,IAAI,QAAQ;AACpC;AAQO,SAAS,SAAS,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAQO,SAAS,QAAqB,OAA8B;AACjE,SAAO,MAAM,QAAQ,KAAK;AAC5B;AAeO,SAAS,gBACd,OACA,OACe;AACf,MAAI,CAAC,SAAS,QAAQ,KAAK,SAAS,MAAM,QAAQ;AAChD,WAAO;AAAA,EACT;AACA,SAAO,MAAM,KAAK;AACpB;AAgBO,SAAS,YACd,KACA,MAC2B;AAC3B,SAAO,SAAS,GAAG,KAAK,QAAQ;AAClC;AAUO,SAAS,oBACd,KACA,YACA,SACmC;AACnC,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,UAAM,IAAI,MAAM,GAAG,OAAO,0BAA0B;AAAA,EACtD;AAEA,aAAW,QAAQ,YAAY;AAC7B,QAAI,EAAE,QAAQ,MAAM;AAClB,YAAM,IAAI,MAAM,GAAG,OAAO,gCAAgC,IAAI,GAAG;AAAA,IACnE;AAAA,EACF;AACF;AASO,SAAS,YAAY,OAAgB,iBAAgC;AAC1E,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,IAAI,MAAM,KAAK;AAAA,EACxB;AACA,MACE,SAAS,KAAK,KACd,aAAa,SACb,OAAO,MAAM,YAAY,UACzB;AACA,WAAO,IAAI,MAAM,MAAM,OAAO;AAAA,EAChC;AACA,SAAO,IAAI,MAAM,eAAe;AAClC;","names":[]}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type guard utilities for runtime type checking and assertions.
|
|
3
|
+
* These utilities provide type-safe alternatives to non-null assertions (!).
|
|
4
|
+
*
|
|
5
|
+
* @module typeGuards
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Asserts that a value is defined (not null or undefined).
|
|
9
|
+
* Throws an error with a descriptive message if the assertion fails.
|
|
10
|
+
*
|
|
11
|
+
* @param value - The value to check
|
|
12
|
+
* @param message - Error message to throw if value is not defined
|
|
13
|
+
* @throws {Error} If value is null or undefined
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* const wallet = getWallet();
|
|
18
|
+
* assertDefined(wallet, 'Wallet must be initialized before use');
|
|
19
|
+
* // TypeScript now knows wallet is defined
|
|
20
|
+
* console.log(wallet.address);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function assertDefined<T>(value: T | undefined | null, message: string): asserts value is T;
|
|
24
|
+
/**
|
|
25
|
+
* Type guard to check if a value is defined (not null or undefined).
|
|
26
|
+
*
|
|
27
|
+
* @param value - The value to check
|
|
28
|
+
* @returns True if the value is defined, false otherwise
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const values = [1, undefined, 3, null, 5];
|
|
33
|
+
* const defined = values.filter(isDefined); // [1, 3, 5]
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function isDefined<T>(value: T | undefined | null): value is T;
|
|
37
|
+
/**
|
|
38
|
+
* Asserts that a value is a non-empty string.
|
|
39
|
+
*
|
|
40
|
+
* @param value - The value to check
|
|
41
|
+
* @param message - Error message if assertion fails
|
|
42
|
+
* @throws {Error} If value is not a non-empty string
|
|
43
|
+
*/
|
|
44
|
+
export declare function assertNonEmptyString(value: unknown, message: string): asserts value is string;
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to check if a value is a non-empty string.
|
|
47
|
+
*
|
|
48
|
+
* @param value - The value to check
|
|
49
|
+
* @returns True if value is a non-empty string
|
|
50
|
+
*/
|
|
51
|
+
export declare function isNonEmptyString(value: unknown): value is string;
|
|
52
|
+
/**
|
|
53
|
+
* Safely gets a property from an object, returning undefined if the property doesn't exist.
|
|
54
|
+
*
|
|
55
|
+
* @param obj - The object to get the property from
|
|
56
|
+
* @param key - The property key
|
|
57
|
+
* @returns The property value or undefined
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const config = { wallet: { address: '0x123' } };
|
|
62
|
+
* const address = safeGet(config, 'wallet')?.address;
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare function safeGet<T, K extends keyof T>(obj: T | undefined | null, key: K): T[K] | undefined;
|
|
66
|
+
/**
|
|
67
|
+
* Ensures a value is defined or returns a default value.
|
|
68
|
+
*
|
|
69
|
+
* @param value - The value to check
|
|
70
|
+
* @param defaultValue - The default value to use if undefined
|
|
71
|
+
* @returns The value if defined, otherwise the default
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const timeout = ensureDefault(config.timeout, 5000);
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function ensureDefault<T>(value: T | undefined | null, defaultValue: T): T;
|
|
79
|
+
/**
|
|
80
|
+
* Type guard for checking if a value is an object (and not null).
|
|
81
|
+
*
|
|
82
|
+
* @param value - The value to check
|
|
83
|
+
* @returns True if value is an object
|
|
84
|
+
*/
|
|
85
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
86
|
+
/**
|
|
87
|
+
* Type guard for checking if a value is an array.
|
|
88
|
+
*
|
|
89
|
+
* @param value - The value to check
|
|
90
|
+
* @returns True if value is an array
|
|
91
|
+
*/
|
|
92
|
+
export declare function isArray<T = unknown>(value: unknown): value is T[];
|
|
93
|
+
/**
|
|
94
|
+
* Safely accesses an array element, returning undefined if out of bounds.
|
|
95
|
+
*
|
|
96
|
+
* @param array - The array to access
|
|
97
|
+
* @param index - The index to access
|
|
98
|
+
* @returns The element at the index or undefined
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const items = [1, 2, 3];
|
|
103
|
+
* const item = safeArrayAccess(items, 5); // undefined
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function safeArrayAccess<T>(array: T[] | undefined | null, index: number): T | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Type guard to check if a value has a specific property.
|
|
109
|
+
*
|
|
110
|
+
* @param obj - The object to check
|
|
111
|
+
* @param prop - The property name
|
|
112
|
+
* @returns True if the object has the property
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* if (hasProperty(response, 'error')) {
|
|
117
|
+
* console.error(response.error);
|
|
118
|
+
* }
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function hasProperty<T extends string>(obj: unknown, prop: T): obj is Record<T, unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* Asserts that an object has required properties.
|
|
124
|
+
*
|
|
125
|
+
* @param obj - The object to check
|
|
126
|
+
* @param properties - Array of required property names
|
|
127
|
+
* @param message - Error message if assertion fails
|
|
128
|
+
* @throws {Error} If any required property is missing
|
|
129
|
+
*/
|
|
130
|
+
export declare function assertHasProperties<T extends string>(obj: unknown, properties: T[], message: string): asserts obj is Record<T, unknown>;
|
|
131
|
+
/**
|
|
132
|
+
* Creates a type-safe error with a guaranteed message.
|
|
133
|
+
*
|
|
134
|
+
* @param error - The error or unknown value
|
|
135
|
+
* @param fallbackMessage - Message to use if error doesn't have one
|
|
136
|
+
* @returns An Error object with a message
|
|
137
|
+
*/
|
|
138
|
+
export declare function ensureError(error: unknown, fallbackMessage: string): Error;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
function assertDefined(value, message) {
|
|
2
|
+
if (value === void 0 || value === null) {
|
|
3
|
+
throw new Error(message);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
function isDefined(value) {
|
|
7
|
+
return value !== void 0 && value !== null;
|
|
8
|
+
}
|
|
9
|
+
function assertNonEmptyString(value, message) {
|
|
10
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
11
|
+
throw new Error(message);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function isNonEmptyString(value) {
|
|
15
|
+
return typeof value === "string" && value.trim().length > 0;
|
|
16
|
+
}
|
|
17
|
+
function safeGet(obj, key) {
|
|
18
|
+
return obj?.[key];
|
|
19
|
+
}
|
|
20
|
+
function ensureDefault(value, defaultValue) {
|
|
21
|
+
return isDefined(value) ? value : defaultValue;
|
|
22
|
+
}
|
|
23
|
+
function isObject(value) {
|
|
24
|
+
return typeof value === "object" && value !== null;
|
|
25
|
+
}
|
|
26
|
+
function isArray(value) {
|
|
27
|
+
return Array.isArray(value);
|
|
28
|
+
}
|
|
29
|
+
function safeArrayAccess(array, index) {
|
|
30
|
+
if (!array || index < 0 || index >= array.length) {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
return array[index];
|
|
34
|
+
}
|
|
35
|
+
function hasProperty(obj, prop) {
|
|
36
|
+
return isObject(obj) && prop in obj;
|
|
37
|
+
}
|
|
38
|
+
function assertHasProperties(obj, properties, message) {
|
|
39
|
+
if (!isObject(obj)) {
|
|
40
|
+
throw new Error(`${message}: Value is not an object`);
|
|
41
|
+
}
|
|
42
|
+
for (const prop of properties) {
|
|
43
|
+
if (!(prop in obj)) {
|
|
44
|
+
throw new Error(`${message}: Missing required property '${prop}'`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function ensureError(error, fallbackMessage) {
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
if (typeof error === "string") {
|
|
53
|
+
return new Error(error);
|
|
54
|
+
}
|
|
55
|
+
if (isObject(error) && "message" in error && typeof error.message === "string") {
|
|
56
|
+
return new Error(error.message);
|
|
57
|
+
}
|
|
58
|
+
return new Error(fallbackMessage);
|
|
59
|
+
}
|
|
60
|
+
export {
|
|
61
|
+
assertDefined,
|
|
62
|
+
assertHasProperties,
|
|
63
|
+
assertNonEmptyString,
|
|
64
|
+
ensureDefault,
|
|
65
|
+
ensureError,
|
|
66
|
+
hasProperty,
|
|
67
|
+
isArray,
|
|
68
|
+
isDefined,
|
|
69
|
+
isNonEmptyString,
|
|
70
|
+
isObject,
|
|
71
|
+
safeArrayAccess,
|
|
72
|
+
safeGet
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=typeGuards.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/typeGuards.ts"],"sourcesContent":["/**\n * Type guard utilities for runtime type checking and assertions.\n * These utilities provide type-safe alternatives to non-null assertions (!).\n *\n * @module typeGuards\n */\n\n/**\n * Asserts that a value is defined (not null or undefined).\n * Throws an error with a descriptive message if the assertion fails.\n *\n * @param value - The value to check\n * @param message - Error message to throw if value is not defined\n * @throws {Error} If value is null or undefined\n *\n * @example\n * ```typescript\n * const wallet = getWallet();\n * assertDefined(wallet, 'Wallet must be initialized before use');\n * // TypeScript now knows wallet is defined\n * console.log(wallet.address);\n * ```\n */\nexport function assertDefined<T>(\n value: T | undefined | null,\n message: string,\n): asserts value is T {\n if (value === undefined || value === null) {\n throw new Error(message);\n }\n}\n\n/**\n * Type guard to check if a value is defined (not null or undefined).\n *\n * @param value - The value to check\n * @returns True if the value is defined, false otherwise\n *\n * @example\n * ```typescript\n * const values = [1, undefined, 3, null, 5];\n * const defined = values.filter(isDefined); // [1, 3, 5]\n * ```\n */\nexport function isDefined<T>(value: T | undefined | null): value is T {\n return value !== undefined && value !== null;\n}\n\n/**\n * Asserts that a value is a non-empty string.\n *\n * @param value - The value to check\n * @param message - Error message if assertion fails\n * @throws {Error} If value is not a non-empty string\n */\nexport function assertNonEmptyString(\n value: unknown,\n message: string,\n): asserts value is string {\n if (typeof value !== \"string\" || value.trim().length === 0) {\n throw new Error(message);\n }\n}\n\n/**\n * Type guard to check if a value is a non-empty string.\n *\n * @param value - The value to check\n * @returns True if value is a non-empty string\n */\nexport function isNonEmptyString(value: unknown): value is string {\n return typeof value === \"string\" && value.trim().length > 0;\n}\n\n/**\n * Safely gets a property from an object, returning undefined if the property doesn't exist.\n *\n * @param obj - The object to get the property from\n * @param key - The property key\n * @returns The property value or undefined\n *\n * @example\n * ```typescript\n * const config = { wallet: { address: '0x123' } };\n * const address = safeGet(config, 'wallet')?.address;\n * ```\n */\nexport function safeGet<T, K extends keyof T>(\n obj: T | undefined | null,\n key: K,\n): T[K] | undefined {\n return obj?.[key];\n}\n\n/**\n * Ensures a value is defined or returns a default value.\n *\n * @param value - The value to check\n * @param defaultValue - The default value to use if undefined\n * @returns The value if defined, otherwise the default\n *\n * @example\n * ```typescript\n * const timeout = ensureDefault(config.timeout, 5000);\n * ```\n */\nexport function ensureDefault<T>(\n value: T | undefined | null,\n defaultValue: T,\n): T {\n return isDefined(value) ? value : defaultValue;\n}\n\n/**\n * Type guard for checking if a value is an object (and not null).\n *\n * @param value - The value to check\n * @returns True if value is an object\n */\nexport function isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\n/**\n * Type guard for checking if a value is an array.\n *\n * @param value - The value to check\n * @returns True if value is an array\n */\nexport function isArray<T = unknown>(value: unknown): value is T[] {\n return Array.isArray(value);\n}\n\n/**\n * Safely accesses an array element, returning undefined if out of bounds.\n *\n * @param array - The array to access\n * @param index - The index to access\n * @returns The element at the index or undefined\n *\n * @example\n * ```typescript\n * const items = [1, 2, 3];\n * const item = safeArrayAccess(items, 5); // undefined\n * ```\n */\nexport function safeArrayAccess<T>(\n array: T[] | undefined | null,\n index: number,\n): T | undefined {\n if (!array || index < 0 || index >= array.length) {\n return undefined;\n }\n return array[index];\n}\n\n/**\n * Type guard to check if a value has a specific property.\n *\n * @param obj - The object to check\n * @param prop - The property name\n * @returns True if the object has the property\n *\n * @example\n * ```typescript\n * if (hasProperty(response, 'error')) {\n * console.error(response.error);\n * }\n * ```\n */\nexport function hasProperty<T extends string>(\n obj: unknown,\n prop: T,\n): obj is Record<T, unknown> {\n return isObject(obj) && prop in obj;\n}\n\n/**\n * Asserts that an object has required properties.\n *\n * @param obj - The object to check\n * @param properties - Array of required property names\n * @param message - Error message if assertion fails\n * @throws {Error} If any required property is missing\n */\nexport function assertHasProperties<T extends string>(\n obj: unknown,\n properties: T[],\n message: string,\n): asserts obj is Record<T, unknown> {\n if (!isObject(obj)) {\n throw new Error(`${message}: Value is not an object`);\n }\n\n for (const prop of properties) {\n if (!(prop in obj)) {\n throw new Error(`${message}: Missing required property '${prop}'`);\n }\n }\n}\n\n/**\n * Creates a type-safe error with a guaranteed message.\n *\n * @param error - The error or unknown value\n * @param fallbackMessage - Message to use if error doesn't have one\n * @returns An Error object with a message\n */\nexport function ensureError(error: unknown, fallbackMessage: string): Error {\n if (error instanceof Error) {\n return error;\n }\n if (typeof error === \"string\") {\n return new Error(error);\n }\n if (\n isObject(error) &&\n \"message\" in error &&\n typeof error.message === \"string\"\n ) {\n return new Error(error.message);\n }\n return new Error(fallbackMessage);\n}\n"],"mappings":"AAuBO,SAAS,cACd,OACA,SACoB;AACpB,MAAI,UAAU,UAAa,UAAU,MAAM;AACzC,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;AAcO,SAAS,UAAa,OAAyC;AACpE,SAAO,UAAU,UAAa,UAAU;AAC1C;AASO,SAAS,qBACd,OACA,SACyB;AACzB,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,WAAW,GAAG;AAC1D,UAAM,IAAI,MAAM,OAAO;AAAA,EACzB;AACF;AAQO,SAAS,iBAAiB,OAAiC;AAChE,SAAO,OAAO,UAAU,YAAY,MAAM,KAAK,EAAE,SAAS;AAC5D;AAeO,SAAS,QACd,KACA,KACkB;AAClB,SAAO,MAAM,GAAG;AAClB;AAcO,SAAS,cACd,OACA,cACG;AACH,SAAO,UAAU,KAAK,IAAI,QAAQ;AACpC;AAQO,SAAS,SAAS,OAAkD;AACzE,SAAO,OAAO,UAAU,YAAY,UAAU;AAChD;AAQO,SAAS,QAAqB,OAA8B;AACjE,SAAO,MAAM,QAAQ,KAAK;AAC5B;AAeO,SAAS,gBACd,OACA,OACe;AACf,MAAI,CAAC,SAAS,QAAQ,KAAK,SAAS,MAAM,QAAQ;AAChD,WAAO;AAAA,EACT;AACA,SAAO,MAAM,KAAK;AACpB;AAgBO,SAAS,YACd,KACA,MAC2B;AAC3B,SAAO,SAAS,GAAG,KAAK,QAAQ;AAClC;AAUO,SAAS,oBACd,KACA,YACA,SACmC;AACnC,MAAI,CAAC,SAAS,GAAG,GAAG;AAClB,UAAM,IAAI,MAAM,GAAG,OAAO,0BAA0B;AAAA,EACtD;AAEA,aAAW,QAAQ,YAAY;AAC7B,QAAI,EAAE,QAAQ,MAAM;AAClB,YAAM,IAAI,MAAM,GAAG,OAAO,gCAAgC,IAAI,GAAG;AAAA,IACnE;AAAA,EACF;AACF;AASO,SAAS,YAAY,OAAgB,iBAAgC;AAC1E,MAAI,iBAAiB,OAAO;AAC1B,WAAO;AAAA,EACT;AACA,MAAI,OAAO,UAAU,UAAU;AAC7B,WAAO,IAAI,MAAM,KAAK;AAAA,EACxB;AACA,MACE,SAAS,KAAK,KACd,aAAa,SACb,OAAO,MAAM,YAAY,UACzB;AACA,WAAO,IAAI,MAAM,MAAM,OAAO;AAAA,EAChC;AACA,SAAO,IAAI,MAAM,eAAe;AAClC;","names":[]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { TypedDataDefinition } from
|
|
2
|
-
import { GenericTypedData } from
|
|
3
|
-
|
|
1
|
+
import type { TypedDataDefinition } from "viem";
|
|
2
|
+
import type { GenericTypedData } from "../types/permissions";
|
|
4
3
|
/**
|
|
5
4
|
* Converts a GenericTypedData object to a Viem-compatible TypedDataDefinition.
|
|
6
5
|
* This function ensures type safety when passing typed data to viem's signTypedData method.
|
|
@@ -8,6 +7,4 @@ import { GenericTypedData } from '../types/permissions.js';
|
|
|
8
7
|
* @param typedData - The typed data object to convert
|
|
9
8
|
* @returns A properly typed TypedDataDefinition for use with viem
|
|
10
9
|
*/
|
|
11
|
-
declare function toViemTypedDataDefinition(typedData: GenericTypedData): TypedDataDefinition;
|
|
12
|
-
|
|
13
|
-
export { toViemTypedDataDefinition };
|
|
10
|
+
export declare function toViemTypedDataDefinition(typedData: GenericTypedData): TypedDataDefinition;
|
|
@@ -33,7 +33,7 @@ class UrlResolutionError extends Error {
|
|
|
33
33
|
}
|
|
34
34
|
async function fetchFromUrl(url, downloadRelayer) {
|
|
35
35
|
try {
|
|
36
|
-
const response = await (0, import_download.
|
|
36
|
+
const response = await (0, import_download.universalFetch)(url, downloadRelayer);
|
|
37
37
|
if (!response.ok) {
|
|
38
38
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n * Universal URL resolver for the Vana SDK\n *\n * Handles fetching data from various protocols (IPFS, HTTP, Arweave, etc.)\n * in a consistent, reliable way.\n */\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n * Universal URL resolver for the Vana SDK\n *\n * Handles fetching data from various protocols (IPFS, HTTP, Arweave, etc.)\n * in a consistent, reliable way.\n */\n\nimport { universalFetch } from \"./download\";\n\n/**\n * Error thrown when URL resolution fails\n */\nexport class UrlResolutionError extends Error {\n constructor(\n message: string,\n public readonly url: string,\n public override readonly cause?: Error,\n ) {\n super(message);\n this.name = \"UrlResolutionError\";\n }\n}\n\n/**\n * Fetches and parses JSON data from any supported URL protocol\n *\n * @param url - The URL to fetch from (supports ipfs://, https://, http://, ar://)\n * @param downloadRelayer - Optional download relayer for CORS bypass\n * @param downloadRelayer.proxyDownload - Function to proxy downloads through application server\n * @returns Promise resolving to the parsed JSON data\n * @throws {UrlResolutionError} When the URL cannot be resolved or parsed\n *\n * @example\n * ```typescript\n * // Fetch from IPFS\n * const data = await fetchFromUrl(\"ipfs://QmXxx...\");\n *\n * // Fetch from HTTPS\n * const data = await fetchFromUrl(\"https://example.com/data.json\");\n *\n * // Handles protocol conversion internally\n * const schema = await fetchFromUrl(schemaDefinitionUrl);\n * ```\n */\nexport async function fetchFromUrl(\n url: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<unknown> {\n try {\n // Use unified download utility with automatic fallbacks\n const response = await universalFetch(url, downloadRelayer);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n // Parse JSON response\n const data = await response.json();\n return data;\n } catch (error) {\n throw new UrlResolutionError(\n `Failed to fetch from ${url}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n url,\n error instanceof Error ? error : undefined,\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,sBAA+B;AAKxB,MAAM,2BAA2B,MAAM;AAAA,EAC5C,YACE,SACgB,KACS,OACzB;AACA,UAAM,OAAO;AAHG;AACS;AAGzB,SAAK,OAAO;AAAA,EACd;AACF;AAuBA,eAAsB,aACpB,KACA,iBACkB;AAClB,MAAI;AAEF,UAAM,WAAW,UAAM,gCAAe,KAAK,eAAe;AAE1D,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,QAAQ,SAAS,MAAM,KAAK,SAAS,UAAU,EAAE;AAAA,IACnE;AAGA,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,wBAAwB,GAAG,KAAK,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACxF;AAAA,MACA,iBAAiB,QAAQ,QAAQ;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
/**
|
|
8
8
|
* Error thrown when URL resolution fails
|
|
9
9
|
*/
|
|
10
|
-
declare class UrlResolutionError extends Error {
|
|
10
|
+
export declare class UrlResolutionError extends Error {
|
|
11
11
|
readonly url: string;
|
|
12
12
|
readonly cause?: Error | undefined;
|
|
13
13
|
constructor(message: string, url: string, cause?: Error | undefined);
|
|
@@ -33,8 +33,6 @@ declare class UrlResolutionError extends Error {
|
|
|
33
33
|
* const schema = await fetchFromUrl(schemaDefinitionUrl);
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
|
-
declare function fetchFromUrl(url: string, downloadRelayer?: {
|
|
36
|
+
export declare function fetchFromUrl(url: string, downloadRelayer?: {
|
|
37
37
|
proxyDownload: (url: string) => Promise<Blob>;
|
|
38
38
|
}): Promise<unknown>;
|
|
39
|
-
|
|
40
|
-
export { UrlResolutionError, fetchFromUrl };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { universalFetch } from "./download";
|
|
2
2
|
class UrlResolutionError extends Error {
|
|
3
3
|
constructor(message, url, cause) {
|
|
4
4
|
super(message);
|
|
@@ -9,7 +9,7 @@ class UrlResolutionError extends Error {
|
|
|
9
9
|
}
|
|
10
10
|
async function fetchFromUrl(url, downloadRelayer) {
|
|
11
11
|
try {
|
|
12
|
-
const response = await
|
|
12
|
+
const response = await universalFetch(url, downloadRelayer);
|
|
13
13
|
if (!response.ok) {
|
|
14
14
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
15
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n * Universal URL resolver for the Vana SDK\n *\n * Handles fetching data from various protocols (IPFS, HTTP, Arweave, etc.)\n * in a consistent, reliable way.\n */\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/urlResolver.ts"],"sourcesContent":["/**\n * Universal URL resolver for the Vana SDK\n *\n * Handles fetching data from various protocols (IPFS, HTTP, Arweave, etc.)\n * in a consistent, reliable way.\n */\n\nimport { universalFetch } from \"./download\";\n\n/**\n * Error thrown when URL resolution fails\n */\nexport class UrlResolutionError extends Error {\n constructor(\n message: string,\n public readonly url: string,\n public override readonly cause?: Error,\n ) {\n super(message);\n this.name = \"UrlResolutionError\";\n }\n}\n\n/**\n * Fetches and parses JSON data from any supported URL protocol\n *\n * @param url - The URL to fetch from (supports ipfs://, https://, http://, ar://)\n * @param downloadRelayer - Optional download relayer for CORS bypass\n * @param downloadRelayer.proxyDownload - Function to proxy downloads through application server\n * @returns Promise resolving to the parsed JSON data\n * @throws {UrlResolutionError} When the URL cannot be resolved or parsed\n *\n * @example\n * ```typescript\n * // Fetch from IPFS\n * const data = await fetchFromUrl(\"ipfs://QmXxx...\");\n *\n * // Fetch from HTTPS\n * const data = await fetchFromUrl(\"https://example.com/data.json\");\n *\n * // Handles protocol conversion internally\n * const schema = await fetchFromUrl(schemaDefinitionUrl);\n * ```\n */\nexport async function fetchFromUrl(\n url: string,\n downloadRelayer?: { proxyDownload: (url: string) => Promise<Blob> },\n): Promise<unknown> {\n try {\n // Use unified download utility with automatic fallbacks\n const response = await universalFetch(url, downloadRelayer);\n\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}: ${response.statusText}`);\n }\n\n // Parse JSON response\n const data = await response.json();\n return data;\n } catch (error) {\n throw new UrlResolutionError(\n `Failed to fetch from ${url}: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n url,\n error instanceof Error ? error : undefined,\n );\n }\n}\n"],"mappings":"AAOA,SAAS,sBAAsB;AAKxB,MAAM,2BAA2B,MAAM;AAAA,EAC5C,YACE,SACgB,KACS,OACzB;AACA,UAAM,OAAO;AAHG;AACS;AAGzB,SAAK,OAAO;AAAA,EACd;AACF;AAuBA,eAAsB,aACpB,KACA,iBACkB;AAClB,MAAI;AAEF,UAAM,WAAW,MAAM,eAAe,KAAK,eAAe;AAE1D,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,QAAQ,SAAS,MAAM,KAAK,SAAS,UAAU,EAAE;AAAA,IACnE;AAGA,UAAM,OAAO,MAAM,SAAS,KAAK;AACjC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,wBAAwB,GAAG,KAAK,iBAAiB,QAAQ,MAAM,UAAU,eAAe;AAAA,MACxF;AAAA,MACA,iBAAiB,QAAQ,QAAQ;AAAA,IACnC;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 wallet_exports = {};
|
|
20
|
+
__export(wallet_exports, {
|
|
21
|
+
extractAddress: () => extractAddress,
|
|
22
|
+
extractAddressSafe: () => extractAddressSafe,
|
|
23
|
+
hasAddress: () => hasAddress
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(wallet_exports);
|
|
26
|
+
function extractAddress(account) {
|
|
27
|
+
if (!account) {
|
|
28
|
+
throw new Error("No account provided");
|
|
29
|
+
}
|
|
30
|
+
if (typeof account === "string") {
|
|
31
|
+
return account;
|
|
32
|
+
}
|
|
33
|
+
if (typeof account === "object" && "address" in account && account.address) {
|
|
34
|
+
return account.address;
|
|
35
|
+
}
|
|
36
|
+
throw new Error("Unable to determine wallet address from account");
|
|
37
|
+
}
|
|
38
|
+
function extractAddressSafe(account) {
|
|
39
|
+
try {
|
|
40
|
+
return extractAddress(account);
|
|
41
|
+
} catch {
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function hasAddress(account) {
|
|
46
|
+
if (!account) return false;
|
|
47
|
+
if (typeof account === "string") {
|
|
48
|
+
return /^0x[a-fA-F0-9]{40}$/.test(account);
|
|
49
|
+
}
|
|
50
|
+
if (typeof account === "object" && "address" in account) {
|
|
51
|
+
const addr = account.address;
|
|
52
|
+
return typeof addr === "string" && /^0x[a-fA-F0-9]{40}$/.test(addr);
|
|
53
|
+
}
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
extractAddress,
|
|
59
|
+
extractAddressSafe,
|
|
60
|
+
hasAddress
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=wallet.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/wallet.ts"],"sourcesContent":["import type { Account, Address } from \"viem\";\n\n/**\n * Extracts an Ethereum address from various account formats.\n *\n * Viem's Account type can be:\n * - A string address directly\n * - An object with an address property\n * - A LocalAccount with address property\n *\n * This utility provides a single source of truth for address extraction,\n * eliminating duplicate logic throughout the codebase.\n *\n * @param account - The account to extract address from\n * @returns The extracted Ethereum address\n * @throws Error if account is undefined or address cannot be determined\n */\nexport function extractAddress(\n account: Account | Address | undefined | null,\n): Address {\n if (!account) {\n throw new Error(\"No account provided\");\n }\n\n // Handle string address directly\n if (typeof account === \"string\") {\n return account as Address;\n }\n\n // Handle object with address property\n if (typeof account === \"object\" && \"address\" in account && account.address) {\n return account.address;\n }\n\n throw new Error(\"Unable to determine wallet address from account\");\n}\n\n/**\n * Safely extracts an address, returning undefined instead of throwing.\n * Useful for optional address resolution.\n *\n * @param account - The account to extract address from\n * @returns The extracted address or undefined\n */\nexport function extractAddressSafe(\n account: Account | Address | undefined | null,\n): Address | undefined {\n try {\n return extractAddress(account);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Type guard to check if an account has a valid address.\n *\n * @param account - The account to check\n * @returns True if account has a valid address\n */\nexport function hasAddress(account: unknown): account is Account | Address {\n if (!account) return false;\n\n if (typeof account === \"string\") {\n // Basic check for Ethereum address format\n return /^0x[a-fA-F0-9]{40}$/.test(account);\n }\n\n if (typeof account === \"object\" && \"address\" in account) {\n const addr = (account as any).address;\n return typeof addr === \"string\" && /^0x[a-fA-F0-9]{40}$/.test(addr);\n }\n\n return false;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,SAAS,eACd,SACS;AACT,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAGA,MAAI,OAAO,YAAY,UAAU;AAC/B,WAAO;AAAA,EACT;AAGA,MAAI,OAAO,YAAY,YAAY,aAAa,WAAW,QAAQ,SAAS;AAC1E,WAAO,QAAQ;AAAA,EACjB;AAEA,QAAM,IAAI,MAAM,iDAAiD;AACnE;AASO,SAAS,mBACd,SACqB;AACrB,MAAI;AACF,WAAO,eAAe,OAAO;AAAA,EAC/B,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAQO,SAAS,WAAW,SAAgD;AACzE,MAAI,CAAC,QAAS,QAAO;AAErB,MAAI,OAAO,YAAY,UAAU;AAE/B,WAAO,sBAAsB,KAAK,OAAO;AAAA,EAC3C;AAEA,MAAI,OAAO,YAAY,YAAY,aAAa,SAAS;AACvD,UAAM,OAAQ,QAAgB;AAC9B,WAAO,OAAO,SAAS,YAAY,sBAAsB,KAAK,IAAI;AAAA,EACpE;AAEA,SAAO;AACT;","names":[]}
|