@metamask/snap-networks-utils 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +63 -1
- package/README.md +4 -10
- package/dist/index.cjs +102 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +51 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +51 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +32 -1
- package/dist/index.mjs.map +1 -1
- package/dist/providers/assets/AssetsProvider.cjs +36 -18
- package/dist/providers/assets/AssetsProvider.cjs.map +1 -1
- package/dist/providers/assets/AssetsProvider.d.cts +30 -2
- package/dist/providers/assets/AssetsProvider.d.cts.map +1 -1
- package/dist/providers/assets/AssetsProvider.d.mts +30 -2
- package/dist/providers/assets/AssetsProvider.d.mts.map +1 -1
- package/dist/providers/assets/AssetsProvider.mjs +36 -18
- package/dist/providers/assets/AssetsProvider.mjs.map +1 -1
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs +4 -17
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.cjs.map +1 -1
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs +4 -17
- package/dist/providers/remote-feature-flags/RemoteFeatureFlagsProvider.mjs.map +1 -1
- package/dist/services/analytics/AnalyticsService.cjs +225 -0
- package/dist/services/analytics/AnalyticsService.cjs.map +1 -0
- package/dist/services/analytics/AnalyticsService.d.cts +175 -0
- package/dist/services/analytics/AnalyticsService.d.cts.map +1 -0
- package/dist/services/analytics/AnalyticsService.d.mts +175 -0
- package/dist/services/analytics/AnalyticsService.d.mts.map +1 -0
- package/dist/services/analytics/AnalyticsService.mjs +221 -0
- package/dist/services/analytics/AnalyticsService.mjs.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.cjs +23 -0
- package/dist/ui/ActionHeader/ActionHeader.cjs.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.d.cts +27 -0
- package/dist/ui/ActionHeader/ActionHeader.d.cts.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.d.mts +27 -0
- package/dist/ui/ActionHeader/ActionHeader.d.mts.map +1 -0
- package/dist/ui/ActionHeader/ActionHeader.mjs +19 -0
- package/dist/ui/ActionHeader/ActionHeader.mjs.map +1 -0
- package/dist/ui/Asset/Asset.cjs +68 -0
- package/dist/ui/Asset/Asset.cjs.map +1 -0
- package/dist/ui/Asset/Asset.d.cts +83 -0
- package/dist/ui/Asset/Asset.d.cts.map +1 -0
- package/dist/ui/Asset/Asset.d.mts +83 -0
- package/dist/ui/Asset/Asset.d.mts.map +1 -0
- package/dist/ui/Asset/Asset.mjs +60 -0
- package/dist/ui/Asset/Asset.mjs.map +1 -0
- package/dist/ui/Asset/question-mark.svg +3 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.cjs +57 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.cjs.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts +50 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.cts.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts +50 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.d.mts.map +1 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.mjs +53 -0
- package/dist/ui/EstimatedChanges/EstimatedChanges.mjs.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.cjs +72 -0
- package/dist/ui/TransactionAlert/TransactionAlert.cjs.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.cts +58 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.cts.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.mts +58 -0
- package/dist/ui/TransactionAlert/TransactionAlert.d.mts.map +1 -0
- package/dist/ui/TransactionAlert/TransactionAlert.mjs +68 -0
- package/dist/ui/TransactionAlert/TransactionAlert.mjs.map +1 -0
- package/dist/utils/async/async.cjs +95 -0
- package/dist/utils/async/async.cjs.map +1 -0
- package/dist/utils/async/async.d.cts +51 -0
- package/dist/utils/async/async.d.cts.map +1 -0
- package/dist/utils/async/async.d.mts +51 -0
- package/dist/utils/async/async.d.mts.map +1 -0
- package/dist/utils/async/async.mjs +88 -0
- package/dist/utils/async/async.mjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.cjs +54 -0
- package/dist/utils/buildUrl/buildUrl.cjs.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.cts +15 -0
- package/dist/utils/buildUrl/buildUrl.d.cts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.d.mts +15 -0
- package/dist/utils/buildUrl/buildUrl.d.mts.map +1 -0
- package/dist/utils/buildUrl/buildUrl.mjs +51 -0
- package/dist/utils/buildUrl/buildUrl.mjs.map +1 -0
- package/dist/utils/cache/InMemoryCache.cjs +134 -0
- package/dist/utils/cache/InMemoryCache.cjs.map +1 -0
- package/dist/utils/cache/InMemoryCache.d.cts +29 -0
- package/dist/utils/cache/InMemoryCache.d.cts.map +1 -0
- package/dist/utils/cache/InMemoryCache.d.mts +29 -0
- package/dist/utils/cache/InMemoryCache.d.mts.map +1 -0
- package/dist/utils/cache/InMemoryCache.mjs +130 -0
- package/dist/utils/cache/InMemoryCache.mjs.map +1 -0
- package/dist/utils/cache/StateCache.cjs +193 -0
- package/dist/utils/cache/StateCache.cjs.map +1 -0
- package/dist/utils/cache/StateCache.d.cts +96 -0
- package/dist/utils/cache/StateCache.d.cts.map +1 -0
- package/dist/utils/cache/StateCache.d.mts +96 -0
- package/dist/utils/cache/StateCache.d.mts.map +1 -0
- package/dist/utils/cache/StateCache.mjs +189 -0
- package/dist/utils/cache/StateCache.mjs.map +1 -0
- package/dist/utils/cache/types.cjs +3 -0
- package/dist/utils/cache/types.cjs.map +1 -0
- package/dist/utils/cache/types.d.cts +99 -0
- package/dist/utils/cache/types.d.cts.map +1 -0
- package/dist/utils/cache/types.d.mts +99 -0
- package/dist/utils/cache/types.d.mts.map +1 -0
- package/dist/utils/cache/types.mjs +2 -0
- package/dist/utils/cache/types.mjs.map +1 -0
- package/dist/utils/cache/useCache.cjs +82 -0
- package/dist/utils/cache/useCache.cjs.map +1 -0
- package/dist/utils/cache/useCache.d.cts +57 -0
- package/dist/utils/cache/useCache.d.cts.map +1 -0
- package/dist/utils/cache/useCache.d.mts +57 -0
- package/dist/utils/cache/useCache.d.mts.map +1 -0
- package/dist/utils/cache/useCache.mjs +78 -0
- package/dist/utils/cache/useCache.mjs.map +1 -0
- package/dist/utils/cache/useCacheUntil.cjs +80 -0
- package/dist/utils/cache/useCacheUntil.cjs.map +1 -0
- package/dist/utils/cache/useCacheUntil.d.cts +54 -0
- package/dist/utils/cache/useCacheUntil.d.cts.map +1 -0
- package/dist/utils/cache/useCacheUntil.d.mts +54 -0
- package/dist/utils/cache/useCacheUntil.d.mts.map +1 -0
- package/dist/utils/cache/useCacheUntil.mjs +76 -0
- package/dist/utils/cache/useCacheUntil.mjs.map +1 -0
- package/dist/utils/config/BaseConfigProvider.cjs +62 -0
- package/dist/utils/config/BaseConfigProvider.cjs.map +1 -0
- package/dist/utils/config/BaseConfigProvider.d.cts +54 -0
- package/dist/utils/config/BaseConfigProvider.d.cts.map +1 -0
- package/dist/utils/config/BaseConfigProvider.d.mts +54 -0
- package/dist/utils/config/BaseConfigProvider.d.mts.map +1 -0
- package/dist/utils/config/BaseConfigProvider.mjs +58 -0
- package/dist/utils/config/BaseConfigProvider.mjs.map +1 -0
- package/dist/utils/config/envStructs.cjs +69 -0
- package/dist/utils/config/envStructs.cjs.map +1 -0
- package/dist/utils/config/envStructs.d.cts +57 -0
- package/dist/utils/config/envStructs.d.cts.map +1 -0
- package/dist/utils/config/envStructs.d.mts +57 -0
- package/dist/utils/config/envStructs.d.mts.map +1 -0
- package/dist/utils/config/envStructs.mjs +61 -0
- package/dist/utils/config/envStructs.mjs.map +1 -0
- package/dist/utils/config/environmentStruct.cjs +19 -0
- package/dist/utils/config/environmentStruct.cjs.map +1 -0
- package/dist/utils/config/environmentStruct.d.cts +20 -0
- package/dist/utils/config/environmentStruct.d.cts.map +1 -0
- package/dist/utils/config/environmentStruct.d.mts +20 -0
- package/dist/utils/config/environmentStruct.d.mts.map +1 -0
- package/dist/utils/config/environmentStruct.mjs +16 -0
- package/dist/utils/config/environmentStruct.mjs.map +1 -0
- package/dist/utils/config/logLevelStruct.cjs +14 -0
- package/dist/utils/config/logLevelStruct.cjs.map +1 -0
- package/dist/utils/config/logLevelStruct.d.cts +17 -0
- package/dist/utils/config/logLevelStruct.d.cts.map +1 -0
- package/dist/utils/config/logLevelStruct.d.mts +17 -0
- package/dist/utils/config/logLevelStruct.d.mts.map +1 -0
- package/dist/utils/config/logLevelStruct.mjs +11 -0
- package/dist/utils/config/logLevelStruct.mjs.map +1 -0
- package/dist/utils/config/parseEnv.cjs +30 -0
- package/dist/utils/config/parseEnv.cjs.map +1 -0
- package/dist/utils/config/parseEnv.d.cts +19 -0
- package/dist/utils/config/parseEnv.d.cts.map +1 -0
- package/dist/utils/config/parseEnv.d.mts +19 -0
- package/dist/utils/config/parseEnv.d.mts.map +1 -0
- package/dist/utils/config/parseEnv.mjs +26 -0
- package/dist/utils/config/parseEnv.mjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs +28 -0
- package/dist/utils/dedupe/InFlightCoalescer.cjs.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts +12 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.cts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts +12 -0
- package/dist/utils/dedupe/InFlightCoalescer.d.mts.map +1 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs +24 -0
- package/dist/utils/dedupe/InFlightCoalescer.mjs.map +1 -0
- package/dist/utils/errors/errors.cjs +44 -0
- package/dist/utils/errors/errors.cjs.map +1 -0
- package/dist/utils/errors/errors.d.cts +37 -0
- package/dist/utils/errors/errors.d.cts.map +1 -0
- package/dist/utils/errors/errors.d.mts +37 -0
- package/dist/utils/errors/errors.d.mts.map +1 -0
- package/dist/utils/errors/errors.mjs +40 -0
- package/dist/utils/errors/errors.mjs.map +1 -0
- package/dist/utils/errors/index.cjs +18 -0
- package/dist/utils/errors/index.cjs.map +1 -0
- package/dist/utils/errors/index.d.cts +10 -0
- package/dist/utils/errors/index.d.cts.map +1 -0
- package/dist/utils/errors/index.d.mts +10 -0
- package/dist/utils/errors/index.d.mts.map +1 -0
- package/dist/utils/errors/index.mjs +6 -0
- package/dist/utils/errors/index.mjs.map +1 -0
- package/dist/utils/errors/snapRpcError.cjs +33 -0
- package/dist/utils/errors/snapRpcError.cjs.map +1 -0
- package/dist/utils/errors/snapRpcError.d.cts +11 -0
- package/dist/utils/errors/snapRpcError.d.cts.map +1 -0
- package/dist/utils/errors/snapRpcError.d.mts +11 -0
- package/dist/utils/errors/snapRpcError.d.mts.map +1 -0
- package/dist/utils/errors/snapRpcError.mjs +30 -0
- package/dist/utils/errors/snapRpcError.mjs.map +1 -0
- package/dist/utils/errors/stringifyReason.cjs +36 -0
- package/dist/utils/errors/stringifyReason.cjs.map +1 -0
- package/dist/utils/errors/stringifyReason.d.cts +15 -0
- package/dist/utils/errors/stringifyReason.d.cts.map +1 -0
- package/dist/utils/errors/stringifyReason.d.mts +15 -0
- package/dist/utils/errors/stringifyReason.d.mts.map +1 -0
- package/dist/utils/errors/stringifyReason.mjs +33 -0
- package/dist/utils/errors/stringifyReason.mjs.map +1 -0
- package/dist/utils/errors/syncError.cjs +98 -0
- package/dist/utils/errors/syncError.cjs.map +1 -0
- package/dist/utils/errors/syncError.d.cts +60 -0
- package/dist/utils/errors/syncError.d.cts.map +1 -0
- package/dist/utils/errors/syncError.d.mts +60 -0
- package/dist/utils/errors/syncError.d.mts.map +1 -0
- package/dist/utils/errors/syncError.mjs +92 -0
- package/dist/utils/errors/syncError.mjs.map +1 -0
- package/dist/utils/errors/trackError.cjs +76 -0
- package/dist/utils/errors/trackError.cjs.map +1 -0
- package/dist/utils/errors/trackError.d.cts +64 -0
- package/dist/utils/errors/trackError.d.cts.map +1 -0
- package/dist/utils/errors/trackError.d.mts +64 -0
- package/dist/utils/errors/trackError.d.mts.map +1 -0
- package/dist/utils/errors/trackError.mjs +72 -0
- package/dist/utils/errors/trackError.mjs.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.cjs +57 -0
- package/dist/utils/handlers/wrapSnapHandlers.cjs.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.cts +74 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.cts.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.mts +74 -0
- package/dist/utils/handlers/wrapSnapHandlers.d.mts.map +1 -0
- package/dist/utils/handlers/wrapSnapHandlers.mjs +53 -0
- package/dist/utils/handlers/wrapSnapHandlers.mjs.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.cjs +25 -0
- package/dist/utils/keyringAccount/keyringAccount.cjs.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.d.cts +29 -0
- package/dist/utils/keyringAccount/keyringAccount.d.cts.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.d.mts +29 -0
- package/dist/utils/keyringAccount/keyringAccount.d.mts.map +1 -0
- package/dist/utils/keyringAccount/keyringAccount.mjs +22 -0
- package/dist/utils/keyringAccount/keyringAccount.mjs.map +1 -0
- package/dist/utils/logger/Logger.cjs +140 -0
- package/dist/utils/logger/Logger.cjs.map +1 -0
- package/dist/utils/logger/Logger.d.cts +118 -0
- package/dist/utils/logger/Logger.d.cts.map +1 -0
- package/dist/utils/logger/Logger.d.mts +118 -0
- package/dist/utils/logger/Logger.d.mts.map +1 -0
- package/dist/utils/logger/Logger.mjs +136 -0
- package/dist/utils/logger/Logger.mjs.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.cjs +26 -0
- package/dist/utils/logger/__mocks__/Logger.cjs.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.d.cts +3 -0
- package/dist/utils/logger/__mocks__/Logger.d.cts.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.d.mts +3 -0
- package/dist/utils/logger/__mocks__/Logger.d.mts.map +1 -0
- package/dist/utils/logger/__mocks__/Logger.mjs +23 -0
- package/dist/utils/logger/__mocks__/Logger.mjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs +30 -0
- package/dist/utils/originPermissions/createOriginPermissions.cjs.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts +24 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.cts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts +24 -0
- package/dist/utils/originPermissions/createOriginPermissions.d.mts.map +1 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs +26 -0
- package/dist/utils/originPermissions/createOriginPermissions.mjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.cjs +23 -0
- package/dist/utils/originPermissions/validateOrigin.cjs.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts +10 -0
- package/dist/utils/originPermissions/validateOrigin.d.cts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts +10 -0
- package/dist/utils/originPermissions/validateOrigin.d.mts.map +1 -0
- package/dist/utils/originPermissions/validateOrigin.mjs +19 -0
- package/dist/utils/originPermissions/validateOrigin.mjs.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.cjs +89 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.cjs.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts +143 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.cts.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts +143 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.d.mts.map +1 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.mjs +85 -0
- package/dist/utils/proofOfOwnership/proofOfOwnership.mjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.cjs +26 -0
- package/dist/utils/safeMerge/safeMerge.cjs.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.cts +17 -0
- package/dist/utils/safeMerge/safeMerge.d.cts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.d.mts +17 -0
- package/dist/utils/safeMerge/safeMerge.d.mts.map +1 -0
- package/dist/utils/safeMerge/safeMerge.mjs +22 -0
- package/dist/utils/safeMerge/safeMerge.mjs.map +1 -0
- package/dist/utils/sanitize/sanitize.cjs +42 -0
- package/dist/utils/sanitize/sanitize.cjs.map +1 -0
- package/dist/utils/sanitize/sanitize.d.cts +15 -0
- package/dist/utils/sanitize/sanitize.d.cts.map +1 -0
- package/dist/utils/sanitize/sanitize.d.mts +15 -0
- package/dist/utils/sanitize/sanitize.d.mts.map +1 -0
- package/dist/utils/sanitize/sanitize.mjs +38 -0
- package/dist/utils/sanitize/sanitize.mjs.map +1 -0
- package/dist/utils/serialization/serialization.cjs +73 -0
- package/dist/utils/serialization/serialization.cjs.map +1 -0
- package/dist/utils/serialization/serialization.d.cts +19 -0
- package/dist/utils/serialization/serialization.d.cts.map +1 -0
- package/dist/utils/serialization/serialization.d.mts +19 -0
- package/dist/utils/serialization/serialization.d.mts.map +1 -0
- package/dist/utils/serialization/serialization.mjs +69 -0
- package/dist/utils/serialization/serialization.mjs.map +1 -0
- package/dist/utils/serialization/types.cjs +3 -0
- package/dist/utils/serialization/types.cjs.map +1 -0
- package/dist/utils/serialization/types.d.cts +8 -0
- package/dist/utils/serialization/types.d.cts.map +1 -0
- package/dist/utils/serialization/types.d.mts +8 -0
- package/dist/utils/serialization/types.d.mts.map +1 -0
- package/dist/utils/serialization/types.mjs +2 -0
- package/dist/utils/serialization/types.mjs.map +1 -0
- package/dist/utils/state/IStateManager.cjs +3 -0
- package/dist/utils/state/IStateManager.cjs.map +1 -0
- package/dist/utils/state/IStateManager.d.cts +69 -0
- package/dist/utils/state/IStateManager.d.cts.map +1 -0
- package/dist/utils/state/IStateManager.d.mts +69 -0
- package/dist/utils/state/IStateManager.d.mts.map +1 -0
- package/dist/utils/state/IStateManager.mjs +2 -0
- package/dist/utils/state/IStateManager.mjs.map +1 -0
- package/dist/utils/state/InMemoryState.cjs +41 -0
- package/dist/utils/state/InMemoryState.cjs.map +1 -0
- package/dist/utils/state/InMemoryState.d.cts +18 -0
- package/dist/utils/state/InMemoryState.d.cts.map +1 -0
- package/dist/utils/state/InMemoryState.d.mts +18 -0
- package/dist/utils/state/InMemoryState.d.mts.map +1 -0
- package/dist/utils/state/InMemoryState.mjs +38 -0
- package/dist/utils/state/InMemoryState.mjs.map +1 -0
- package/dist/utils/state/State.cjs +159 -0
- package/dist/utils/state/State.cjs.map +1 -0
- package/dist/utils/state/State.d.cts +25 -0
- package/dist/utils/state/State.d.cts.map +1 -0
- package/dist/utils/state/State.d.mts +25 -0
- package/dist/utils/state/State.d.mts.map +1 -0
- package/dist/utils/state/State.mjs +156 -0
- package/dist/utils/state/State.mjs.map +1 -0
- package/dist/utils/transactionType/transactionType.cjs +32 -0
- package/dist/utils/transactionType/transactionType.cjs.map +1 -0
- package/dist/utils/transactionType/transactionType.d.cts +17 -0
- package/dist/utils/transactionType/transactionType.d.cts.map +1 -0
- package/dist/utils/transactionType/transactionType.d.mts +17 -0
- package/dist/utils/transactionType/transactionType.d.mts.map +1 -0
- package/dist/utils/transactionType/transactionType.mjs +28 -0
- package/dist/utils/transactionType/transactionType.mjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.cjs +96 -0
- package/dist/utils/urlStruct/urlStruct.cjs.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.cts +25 -0
- package/dist/utils/urlStruct/urlStruct.d.cts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.d.mts +25 -0
- package/dist/utils/urlStruct/urlStruct.d.mts.map +1 -0
- package/dist/utils/urlStruct/urlStruct.mjs +93 -0
- package/dist/utils/urlStruct/urlStruct.mjs.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.cjs +12 -0
- package/dist/utils/uuidStruct/uuidStruct.cjs.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.d.cts +8 -0
- package/dist/utils/uuidStruct/uuidStruct.d.cts.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.d.mts +8 -0
- package/dist/utils/uuidStruct/uuidStruct.d.mts.map +1 -0
- package/dist/utils/uuidStruct/uuidStruct.mjs +9 -0
- package/dist/utils/uuidStruct/uuidStruct.mjs.map +1 -0
- package/package.json +33 -13
- package/dist/logger.cjs +0 -57
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -30
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -30
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -53
- package/dist/logger.mjs.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The severity levels supported by {@link Logger}.
|
|
3
|
+
*/
|
|
4
|
+
export declare const LogLevel: {
|
|
5
|
+
readonly SILENT: "silent";
|
|
6
|
+
readonly ERROR: "error";
|
|
7
|
+
readonly WARN: "warn";
|
|
8
|
+
readonly INFO: "info";
|
|
9
|
+
readonly DEBUG: "debug";
|
|
10
|
+
readonly TRACE: "trace";
|
|
11
|
+
};
|
|
12
|
+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
13
|
+
export type LoggerMethod = Exclude<LogLevel, typeof LogLevel.SILENT>;
|
|
14
|
+
export type LogMethod = (...args: unknown[]) => void;
|
|
15
|
+
/**
|
|
16
|
+
* A function that can add behavior around a logger method.
|
|
17
|
+
*
|
|
18
|
+
* Call `next` to forward a message through the logger's configured output.
|
|
19
|
+
*/
|
|
20
|
+
export type LogMethodDecorator = (next: LogMethod, ...args: unknown[]) => void;
|
|
21
|
+
export type LoggerDecorators = Partial<Record<LoggerMethod, LogMethodDecorator>>;
|
|
22
|
+
/**
|
|
23
|
+
* Configuration for a {@link Logger}.
|
|
24
|
+
*
|
|
25
|
+
* **Example: configure logging with `LOG_LEVEL`.**
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const logger = new Logger({
|
|
29
|
+
* level: process.env.LOG_LEVEL
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type LoggerOptions = {
|
|
34
|
+
/**
|
|
35
|
+
* The most verbose severity level that should be logged. Use
|
|
36
|
+
* {@link LogLevel.SILENT} to disable logging.
|
|
37
|
+
*/
|
|
38
|
+
level: LogLevel;
|
|
39
|
+
/**
|
|
40
|
+
* An optional prefix prepended to every message.
|
|
41
|
+
*
|
|
42
|
+
* Use {@link Logger.withPrefix} to add prefixes after construction.
|
|
43
|
+
*/
|
|
44
|
+
prefix?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Optional behavior to apply to individual log methods.
|
|
47
|
+
*
|
|
48
|
+
* Decorators receive `next`, which preserves this logger's configured level,
|
|
49
|
+
* prefix, and console output.
|
|
50
|
+
*/
|
|
51
|
+
decorators?: LoggerDecorators;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Logs network Snap messages to the console at configurable severity levels.
|
|
55
|
+
*
|
|
56
|
+
* Disable output with {@link LogLevel.SILENT}.
|
|
57
|
+
*
|
|
58
|
+
* **Example: create an enabled logger.**
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { Logger } from '@metamask/snap-networks-utils';
|
|
62
|
+
*
|
|
63
|
+
* const logger = new Logger({ level: LogLevel.TRACE });
|
|
64
|
+
* logger.info('Account synced');
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* **Example: add a Snap or component prefix.**
|
|
68
|
+
*
|
|
69
|
+
* ```ts
|
|
70
|
+
* const rootLogger = new Logger({ level: LogLevel.TRACE });
|
|
71
|
+
* const snapLogger = rootLogger.withPrefix('[tron-wallet-snap]');
|
|
72
|
+
* const accountsLogger = snapLogger.withPrefix('[accounts]');
|
|
73
|
+
*
|
|
74
|
+
* accountsLogger.debug('Refreshing account balances');
|
|
75
|
+
* ```
|
|
76
|
+
*
|
|
77
|
+
* **Example: decorate a method with Snap-specific behavior.**
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const logger = new Logger({
|
|
81
|
+
* level: LogLevel.TRACE,
|
|
82
|
+
* decorators: {
|
|
83
|
+
* error: (next, error) => {
|
|
84
|
+
* const details = getSolanaErrorDetails(error);
|
|
85
|
+
* next(details ?? error);
|
|
86
|
+
* },
|
|
87
|
+
* },
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare class Logger {
|
|
92
|
+
#private;
|
|
93
|
+
constructor({ level, prefix, decorators }: LoggerOptions);
|
|
94
|
+
/**
|
|
95
|
+
* Returns a logger with an additional prefix.
|
|
96
|
+
*
|
|
97
|
+
* The returned logger has the same log level and decorators as this one. Call
|
|
98
|
+
* this method as many times as needed; each derived logger appends its prefix
|
|
99
|
+
* to the existing prefix.
|
|
100
|
+
*
|
|
101
|
+
* @param prefix - The prefix to add to each message.
|
|
102
|
+
* @returns A derived logger.
|
|
103
|
+
*/
|
|
104
|
+
withPrefix(prefix: string): Logger;
|
|
105
|
+
error(...args: unknown[]): void;
|
|
106
|
+
warn(...args: unknown[]): void;
|
|
107
|
+
/**
|
|
108
|
+
* Logs an informational message.
|
|
109
|
+
*
|
|
110
|
+
* @param args - The values to write to the console.
|
|
111
|
+
* @deprecated Use {@link Logger.info} instead.
|
|
112
|
+
*/
|
|
113
|
+
log(...args: unknown[]): void;
|
|
114
|
+
info(...args: unknown[]): void;
|
|
115
|
+
debug(...args: unknown[]): void;
|
|
116
|
+
trace(...args: unknown[]): void;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=Logger.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.mts","sourceRoot":"","sources":["../../../src/utils/logger/Logger.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;;;;CAOX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAoBhE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,QAAQ,EAAE,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC;AAErE,MAAM,MAAM,SAAS,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAErD;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;AAE/E,MAAM,MAAM,gBAAgB,GAAG,OAAO,CACpC,MAAM,CAAC,YAAY,EAAE,kBAAkB,CAAC,CACzC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B;;;OAGG;IACH,KAAK,EAAE,QAAQ,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,qBAAa,MAAM;;gBAOL,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,aAAa;IAQxD;;;;;;;;;OASG;IACH,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAQlC,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI7B,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI9B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAI/B,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;CA+BhC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { assert, enums } from "@metamask/superstruct";
|
|
2
|
+
/**
|
|
3
|
+
* The severity levels supported by {@link Logger}.
|
|
4
|
+
*/
|
|
5
|
+
export const LogLevel = {
|
|
6
|
+
SILENT: 'silent',
|
|
7
|
+
ERROR: 'error',
|
|
8
|
+
WARN: 'warn',
|
|
9
|
+
INFO: 'info',
|
|
10
|
+
DEBUG: 'debug',
|
|
11
|
+
TRACE: 'trace',
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Defines the severity ordering used to filter log messages.
|
|
15
|
+
*
|
|
16
|
+
* Lower values are less verbose. Changing these numeric priorities changes
|
|
17
|
+
* which messages are emitted for each configured {@link LogLevel}, including
|
|
18
|
+
* in production.
|
|
19
|
+
*/
|
|
20
|
+
const logLevelPriority = {
|
|
21
|
+
[LogLevel.SILENT]: 0,
|
|
22
|
+
[LogLevel.ERROR]: 1,
|
|
23
|
+
[LogLevel.WARN]: 2,
|
|
24
|
+
[LogLevel.INFO]: 3,
|
|
25
|
+
[LogLevel.DEBUG]: 4,
|
|
26
|
+
[LogLevel.TRACE]: 5,
|
|
27
|
+
};
|
|
28
|
+
const LogLevelStruct = enums(Object.values(LogLevel));
|
|
29
|
+
/**
|
|
30
|
+
* Logs network Snap messages to the console at configurable severity levels.
|
|
31
|
+
*
|
|
32
|
+
* Disable output with {@link LogLevel.SILENT}.
|
|
33
|
+
*
|
|
34
|
+
* **Example: create an enabled logger.**
|
|
35
|
+
*
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { Logger } from '@metamask/snap-networks-utils';
|
|
38
|
+
*
|
|
39
|
+
* const logger = new Logger({ level: LogLevel.TRACE });
|
|
40
|
+
* logger.info('Account synced');
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* **Example: add a Snap or component prefix.**
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* const rootLogger = new Logger({ level: LogLevel.TRACE });
|
|
47
|
+
* const snapLogger = rootLogger.withPrefix('[tron-wallet-snap]');
|
|
48
|
+
* const accountsLogger = snapLogger.withPrefix('[accounts]');
|
|
49
|
+
*
|
|
50
|
+
* accountsLogger.debug('Refreshing account balances');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* **Example: decorate a method with Snap-specific behavior.**
|
|
54
|
+
*
|
|
55
|
+
* ```ts
|
|
56
|
+
* const logger = new Logger({
|
|
57
|
+
* level: LogLevel.TRACE,
|
|
58
|
+
* decorators: {
|
|
59
|
+
* error: (next, error) => {
|
|
60
|
+
* const details = getSolanaErrorDetails(error);
|
|
61
|
+
* next(details ?? error);
|
|
62
|
+
* },
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export class Logger {
|
|
68
|
+
#level;
|
|
69
|
+
#prefix;
|
|
70
|
+
#decorators;
|
|
71
|
+
constructor({ level, prefix, decorators }) {
|
|
72
|
+
assert(level, LogLevelStruct);
|
|
73
|
+
this.#level = level;
|
|
74
|
+
this.#prefix = prefix;
|
|
75
|
+
this.#decorators = decorators;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns a logger with an additional prefix.
|
|
79
|
+
*
|
|
80
|
+
* The returned logger has the same log level and decorators as this one. Call
|
|
81
|
+
* this method as many times as needed; each derived logger appends its prefix
|
|
82
|
+
* to the existing prefix.
|
|
83
|
+
*
|
|
84
|
+
* @param prefix - The prefix to add to each message.
|
|
85
|
+
* @returns A derived logger.
|
|
86
|
+
*/
|
|
87
|
+
withPrefix(prefix) {
|
|
88
|
+
return new Logger({
|
|
89
|
+
level: this.#level,
|
|
90
|
+
prefix: this.#prefix ? `${this.#prefix} ${prefix}` : prefix,
|
|
91
|
+
decorators: this.#decorators,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
error(...args) {
|
|
95
|
+
this.#write(LogLevel.ERROR, console.error, args);
|
|
96
|
+
}
|
|
97
|
+
warn(...args) {
|
|
98
|
+
this.#write(LogLevel.WARN, console.warn, args);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Logs an informational message.
|
|
102
|
+
*
|
|
103
|
+
* @param args - The values to write to the console.
|
|
104
|
+
* @deprecated Use {@link Logger.info} instead.
|
|
105
|
+
*/
|
|
106
|
+
log(...args) {
|
|
107
|
+
this.info(...args);
|
|
108
|
+
}
|
|
109
|
+
info(...args) {
|
|
110
|
+
this.#write(LogLevel.INFO, console.info, args);
|
|
111
|
+
}
|
|
112
|
+
debug(...args) {
|
|
113
|
+
this.#write(LogLevel.DEBUG, console.debug, args);
|
|
114
|
+
}
|
|
115
|
+
trace(...args) {
|
|
116
|
+
this.#write(LogLevel.TRACE, console.trace, args);
|
|
117
|
+
}
|
|
118
|
+
#isLevelDisabled(level) {
|
|
119
|
+
return logLevelPriority[level] > logLevelPriority[this.#level];
|
|
120
|
+
}
|
|
121
|
+
#write(level, writeToConsole, args) {
|
|
122
|
+
if (this.#isLevelDisabled(level)) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const next = this.#prefix
|
|
126
|
+
? (...nextArgs) => writeToConsole(this.#prefix, ...nextArgs)
|
|
127
|
+
: writeToConsole;
|
|
128
|
+
const decorator = this.#decorators?.[level];
|
|
129
|
+
if (decorator) {
|
|
130
|
+
decorator(next, ...args);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
next(...args);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=Logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.mjs","sourceRoot":"","sources":["../../../src/utils/logger/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,OAAO;CACN,CAAC;AAIX;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAG;IACvB,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;IACpB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;IAClB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;IACnB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;CACpB,CAAC;AAEF,MAAM,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AAiDtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,MAAM;IACR,MAAM,CAAW;IAEjB,OAAO,CAAU;IAEjB,WAAW,CAAoB;IAExC,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAiB;QACtD,MAAM,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;QAE9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAChC,CAAC;IAED;;;;;;;;;OASG;IACH,UAAU,CAAC,MAAc;QACvB,OAAO,IAAI,MAAM,CAAC;YAChB,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,IAAI,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM;YAC3D,UAAU,EAAE,IAAI,CAAC,WAAW;SAC7B,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,CAAC,GAAG,IAAe;QACrB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,GAAG,IAAe;QACpB,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IACrB,CAAC;IAED,IAAI,CAAC,GAAG,IAAe;QACrB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,KAAK,CAAC,GAAG,IAAe;QACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACnD,CAAC;IAED,gBAAgB,CAAC,KAAmB;QAClC,OAAO,gBAAgB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,CACJ,KAAmB,EACnB,cAA4C,EAC5C,IAAe;QAEf,IAAI,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QAED,MAAM,IAAI,GAAc,IAAI,CAAC,OAAO;YAClC,CAAC,CAAC,CAAC,GAAG,QAAmB,EAAQ,EAAE,CAC/B,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,QAAQ,CAAC;YAC7C,CAAC,CAAC,cAAc,CAAC;QAEnB,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC;QAE5C,IAAI,SAAS,EAAE,CAAC;YACd,SAAS,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;YACzB,OAAO;QACT,CAAC;QAED,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAChB,CAAC;CACF","sourcesContent":["import { assert, enums } from '@metamask/superstruct';\n\n/**\n * The severity levels supported by {@link Logger}.\n */\nexport const LogLevel = {\n SILENT: 'silent',\n ERROR: 'error',\n WARN: 'warn',\n INFO: 'info',\n DEBUG: 'debug',\n TRACE: 'trace',\n} as const;\n\nexport type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];\n\n/**\n * Defines the severity ordering used to filter log messages.\n *\n * Lower values are less verbose. Changing these numeric priorities changes\n * which messages are emitted for each configured {@link LogLevel}, including\n * in production.\n */\nconst logLevelPriority = {\n [LogLevel.SILENT]: 0,\n [LogLevel.ERROR]: 1,\n [LogLevel.WARN]: 2,\n [LogLevel.INFO]: 3,\n [LogLevel.DEBUG]: 4,\n [LogLevel.TRACE]: 5,\n};\n\nconst LogLevelStruct = enums(Object.values(LogLevel));\n\nexport type LoggerMethod = Exclude<LogLevel, typeof LogLevel.SILENT>;\n\nexport type LogMethod = (...args: unknown[]) => void;\n\n/**\n * A function that can add behavior around a logger method.\n *\n * Call `next` to forward a message through the logger's configured output.\n */\nexport type LogMethodDecorator = (next: LogMethod, ...args: unknown[]) => void;\n\nexport type LoggerDecorators = Partial<\n Record<LoggerMethod, LogMethodDecorator>\n>;\n\n/**\n * Configuration for a {@link Logger}.\n *\n * **Example: configure logging with `LOG_LEVEL`.**\n *\n * ```ts\n * const logger = new Logger({\n * level: process.env.LOG_LEVEL\n * });\n * ```\n */\nexport type LoggerOptions = {\n /**\n * The most verbose severity level that should be logged. Use\n * {@link LogLevel.SILENT} to disable logging.\n */\n level: LogLevel;\n /**\n * An optional prefix prepended to every message.\n *\n * Use {@link Logger.withPrefix} to add prefixes after construction.\n */\n prefix?: string;\n /**\n * Optional behavior to apply to individual log methods.\n *\n * Decorators receive `next`, which preserves this logger's configured level,\n * prefix, and console output.\n */\n decorators?: LoggerDecorators;\n};\n\n/**\n * Logs network Snap messages to the console at configurable severity levels.\n *\n * Disable output with {@link LogLevel.SILENT}.\n *\n * **Example: create an enabled logger.**\n *\n * ```ts\n * import { Logger } from '@metamask/snap-networks-utils';\n *\n * const logger = new Logger({ level: LogLevel.TRACE });\n * logger.info('Account synced');\n * ```\n *\n * **Example: add a Snap or component prefix.**\n *\n * ```ts\n * const rootLogger = new Logger({ level: LogLevel.TRACE });\n * const snapLogger = rootLogger.withPrefix('[tron-wallet-snap]');\n * const accountsLogger = snapLogger.withPrefix('[accounts]');\n *\n * accountsLogger.debug('Refreshing account balances');\n * ```\n *\n * **Example: decorate a method with Snap-specific behavior.**\n *\n * ```ts\n * const logger = new Logger({\n * level: LogLevel.TRACE,\n * decorators: {\n * error: (next, error) => {\n * const details = getSolanaErrorDetails(error);\n * next(details ?? error);\n * },\n * },\n * });\n * ```\n */\nexport class Logger {\n readonly #level: LogLevel;\n\n readonly #prefix?: string;\n\n readonly #decorators?: LoggerDecorators;\n\n constructor({ level, prefix, decorators }: LoggerOptions) {\n assert(level, LogLevelStruct);\n\n this.#level = level;\n this.#prefix = prefix;\n this.#decorators = decorators;\n }\n\n /**\n * Returns a logger with an additional prefix.\n *\n * The returned logger has the same log level and decorators as this one. Call\n * this method as many times as needed; each derived logger appends its prefix\n * to the existing prefix.\n *\n * @param prefix - The prefix to add to each message.\n * @returns A derived logger.\n */\n withPrefix(prefix: string): Logger {\n return new Logger({\n level: this.#level,\n prefix: this.#prefix ? `${this.#prefix} ${prefix}` : prefix,\n decorators: this.#decorators,\n });\n }\n\n error(...args: unknown[]): void {\n this.#write(LogLevel.ERROR, console.error, args);\n }\n\n warn(...args: unknown[]): void {\n this.#write(LogLevel.WARN, console.warn, args);\n }\n\n /**\n * Logs an informational message.\n *\n * @param args - The values to write to the console.\n * @deprecated Use {@link Logger.info} instead.\n */\n log(...args: unknown[]): void {\n this.info(...args);\n }\n\n info(...args: unknown[]): void {\n this.#write(LogLevel.INFO, console.info, args);\n }\n\n debug(...args: unknown[]): void {\n this.#write(LogLevel.DEBUG, console.debug, args);\n }\n\n trace(...args: unknown[]): void {\n this.#write(LogLevel.TRACE, console.trace, args);\n }\n\n #isLevelDisabled(level: LoggerMethod): boolean {\n return logLevelPriority[level] > logLevelPriority[this.#level];\n }\n\n #write(\n level: LoggerMethod,\n writeToConsole: (...args: unknown[]) => void,\n args: unknown[],\n ): void {\n if (this.#isLevelDisabled(level)) {\n return;\n }\n\n const next: LogMethod = this.#prefix\n ? (...nextArgs: unknown[]): void =>\n writeToConsole(this.#prefix, ...nextArgs)\n : writeToConsole;\n\n const decorator = this.#decorators?.[level];\n\n if (decorator) {\n decorator(next, ...args);\n return;\n }\n\n next(...args);\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockLogger = void 0;
|
|
4
|
+
exports.mockLogger = {
|
|
5
|
+
log: jest.fn(),
|
|
6
|
+
info: jest.fn(),
|
|
7
|
+
warn: jest.fn(),
|
|
8
|
+
error: jest.fn(),
|
|
9
|
+
debug: jest.fn(),
|
|
10
|
+
trace: jest.fn(),
|
|
11
|
+
withPrefix: (prefix) => createPrefixedLogger([prefix]),
|
|
12
|
+
};
|
|
13
|
+
function createPrefixedLogger(prefixes) {
|
|
14
|
+
return new Proxy(exports.mockLogger, {
|
|
15
|
+
get(target, property) {
|
|
16
|
+
if (property === 'withPrefix') {
|
|
17
|
+
return (prefix) => createPrefixedLogger([...prefixes, prefix]);
|
|
18
|
+
}
|
|
19
|
+
const method = target[property];
|
|
20
|
+
return typeof method === 'function'
|
|
21
|
+
? (...args) => method(...prefixes, ...args)
|
|
22
|
+
: method;
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=Logger.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.cjs","sourceRoot":"","sources":["../../../../src/utils/logger/__mocks__/Logger.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAG;IACxB,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;IACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;IACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,UAAU,EAAE,CAAC,MAAc,EAAU,EAAE,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;CACrC,CAAC;AAEpC,SAAS,oBAAoB,CAAC,QAAkB;IAC9C,OAAO,IAAI,KAAK,CAAC,kBAAU,EAAE;QAC3B,GAAG,CAAC,MAAM,EAAE,QAAsB;YAChC,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC9B,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;YACzE,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChC,OAAO,OAAO,MAAM,KAAK,UAAU;gBACjC,CAAC,CAAC,CAAC,GAAG,IAAe,EAAW,EAAE,CAAC,MAAM,CAAC,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC;gBAC/D,CAAC,CAAC,MAAM,CAAC;QACb,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Logger } from '../Logger';\n\nexport const mockLogger = {\n log: jest.fn(),\n info: jest.fn(),\n warn: jest.fn(),\n error: jest.fn(),\n debug: jest.fn(),\n trace: jest.fn(),\n withPrefix: (prefix: string): Logger => createPrefixedLogger([prefix]),\n} as unknown as jest.Mocked<Logger>;\n\nfunction createPrefixedLogger(prefixes: string[]): Logger {\n return new Proxy(mockLogger, {\n get(target, property: keyof Logger): unknown {\n if (property === 'withPrefix') {\n return (prefix: string) => createPrefixedLogger([...prefixes, prefix]);\n }\n\n const method = target[property];\n return typeof method === 'function'\n ? (...args: unknown[]): unknown => method(...prefixes, ...args)\n : method;\n },\n });\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.cts","sourceRoot":"","sources":["../../../../src/utils/logger/__mocks__/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,sBAAkB;AAExC,eAAO,MAAM,UAAU,EAQP,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.mts","sourceRoot":"","sources":["../../../../src/utils/logger/__mocks__/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,sBAAkB;AAExC,eAAO,MAAM,UAAU,EAQP,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const mockLogger = {
|
|
2
|
+
log: jest.fn(),
|
|
3
|
+
info: jest.fn(),
|
|
4
|
+
warn: jest.fn(),
|
|
5
|
+
error: jest.fn(),
|
|
6
|
+
debug: jest.fn(),
|
|
7
|
+
trace: jest.fn(),
|
|
8
|
+
withPrefix: (prefix) => createPrefixedLogger([prefix]),
|
|
9
|
+
};
|
|
10
|
+
function createPrefixedLogger(prefixes) {
|
|
11
|
+
return new Proxy(mockLogger, {
|
|
12
|
+
get(target, property) {
|
|
13
|
+
if (property === 'withPrefix') {
|
|
14
|
+
return (prefix) => createPrefixedLogger([...prefixes, prefix]);
|
|
15
|
+
}
|
|
16
|
+
const method = target[property];
|
|
17
|
+
return typeof method === 'function'
|
|
18
|
+
? (...args) => method(...prefixes, ...args)
|
|
19
|
+
: method;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=Logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.mjs","sourceRoot":"","sources":["../../../../src/utils/logger/__mocks__/Logger.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,IAAI,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;IACf,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE;IACf,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;IAChB,UAAU,EAAE,CAAC,MAAc,EAAU,EAAE,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;CACrC,CAAC;AAEpC,SAAS,oBAAoB,CAAC,QAAkB;IAC9C,OAAO,IAAI,KAAK,CAAC,UAAU,EAAE;QAC3B,GAAG,CAAC,MAAM,EAAE,QAAsB;YAChC,IAAI,QAAQ,KAAK,YAAY,EAAE,CAAC;gBAC9B,OAAO,CAAC,MAAc,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAAC,GAAG,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;YACzE,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;YAChC,OAAO,OAAO,MAAM,KAAK,UAAU;gBACjC,CAAC,CAAC,CAAC,GAAG,IAAe,EAAW,EAAE,CAAC,MAAM,CAAC,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC;gBAC/D,CAAC,CAAC,MAAM,CAAC;QACb,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Logger } from '../Logger';\n\nexport const mockLogger = {\n log: jest.fn(),\n info: jest.fn(),\n warn: jest.fn(),\n error: jest.fn(),\n debug: jest.fn(),\n trace: jest.fn(),\n withPrefix: (prefix: string): Logger => createPrefixedLogger([prefix]),\n} as unknown as jest.Mocked<Logger>;\n\nfunction createPrefixedLogger(prefixes: string[]): Logger {\n return new Proxy(mockLogger, {\n get(target, property: keyof Logger): unknown {\n if (property === 'withPrefix') {\n return (prefix: string) => createPrefixedLogger([...prefixes, prefix]);\n }\n\n const method = target[property];\n return typeof method === 'function'\n ? (...args: unknown[]): unknown => method(...prefixes, ...args)\n : method;\n },\n });\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOriginPermissions = exports.DEFAULT_METAMASK_ORIGIN = exports.DEFAULT_DEV_ORIGINS = exports.DEFAULT_PROD_ORIGINS = void 0;
|
|
4
|
+
exports.DEFAULT_PROD_ORIGINS = ['https://portfolio.metamask.io'];
|
|
5
|
+
exports.DEFAULT_DEV_ORIGINS = ['http://localhost:3000'];
|
|
6
|
+
exports.DEFAULT_METAMASK_ORIGIN = 'metamask';
|
|
7
|
+
/**
|
|
8
|
+
* Builds the origin-to-method permission map used by network snaps.
|
|
9
|
+
*
|
|
10
|
+
* Those origins receive `dappMethods` as provided (pass an empty list to deny
|
|
11
|
+
* dapp calls). The MetaMask origin always receives `metamaskMethods`.
|
|
12
|
+
*
|
|
13
|
+
* @param params - Origin and method lists for the snap.
|
|
14
|
+
* @param params.dappMethods - Methods allowed for connected dapps.
|
|
15
|
+
* @param params.metamaskMethods - Methods allowed for the MetaMask origin.
|
|
16
|
+
* @param params.origins - Dapp origins to register. Defaults to localhost.
|
|
17
|
+
* @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.
|
|
18
|
+
* @returns A map of origin to allowed RPC methods.
|
|
19
|
+
*/
|
|
20
|
+
const createOriginPermissions = ({ dappMethods, metamaskMethods, origins = exports.DEFAULT_DEV_ORIGINS, metamaskOrigin = exports.DEFAULT_METAMASK_ORIGIN, }) => {
|
|
21
|
+
const originPermissions = new Map();
|
|
22
|
+
const dappPermissions = new Set(dappMethods);
|
|
23
|
+
for (const origin of origins) {
|
|
24
|
+
originPermissions.set(origin, dappPermissions);
|
|
25
|
+
}
|
|
26
|
+
originPermissions.set(metamaskOrigin, new Set(metamaskMethods));
|
|
27
|
+
return originPermissions;
|
|
28
|
+
};
|
|
29
|
+
exports.createOriginPermissions = createOriginPermissions;
|
|
30
|
+
//# sourceMappingURL=createOriginPermissions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.cjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":";;;AAAa,QAAA,oBAAoB,GAAG,CAAC,+BAA+B,CAAU,CAAC;AAElE,QAAA,mBAAmB,GAAG,CAAC,uBAAuB,CAAU,CAAC;AAEzD,QAAA,uBAAuB,GAAG,UAAU,CAAC;AASlD;;;;;;;;;;;;GAYG;AACI,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,eAAe,EACf,OAAO,GAAG,2BAAmB,EAC7B,cAAc,GAAG,+BAAuB,GACV,EAA4B,EAAE;IAC5D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAE7C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC;AAfW,QAAA,uBAAuB,2BAelC","sourcesContent":["export const DEFAULT_PROD_ORIGINS = ['https://portfolio.metamask.io'] as const;\n\nexport const DEFAULT_DEV_ORIGINS = ['http://localhost:3000'] as const;\n\nexport const DEFAULT_METAMASK_ORIGIN = 'metamask';\n\nexport type CreateOriginPermissionsParams = {\n dappMethods: Iterable<string>;\n metamaskMethods: Iterable<string>;\n origins?: readonly string[];\n metamaskOrigin?: string;\n};\n\n/**\n * Builds the origin-to-method permission map used by network snaps.\n *\n * Those origins receive `dappMethods` as provided (pass an empty list to deny\n * dapp calls). The MetaMask origin always receives `metamaskMethods`.\n *\n * @param params - Origin and method lists for the snap.\n * @param params.dappMethods - Methods allowed for connected dapps.\n * @param params.metamaskMethods - Methods allowed for the MetaMask origin.\n * @param params.origins - Dapp origins to register. Defaults to localhost.\n * @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.\n * @returns A map of origin to allowed RPC methods.\n */\nexport const createOriginPermissions = ({\n dappMethods,\n metamaskMethods,\n origins = DEFAULT_DEV_ORIGINS,\n metamaskOrigin = DEFAULT_METAMASK_ORIGIN,\n}: CreateOriginPermissionsParams): Map<string, Set<string>> => {\n const originPermissions = new Map<string, Set<string>>();\n const dappPermissions = new Set(dappMethods);\n\n for (const origin of origins) {\n originPermissions.set(origin, dappPermissions);\n }\n originPermissions.set(metamaskOrigin, new Set(metamaskMethods));\n\n return originPermissions;\n};\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const DEFAULT_PROD_ORIGINS: readonly ["https://portfolio.metamask.io"];
|
|
2
|
+
export declare const DEFAULT_DEV_ORIGINS: readonly ["http://localhost:3000"];
|
|
3
|
+
export declare const DEFAULT_METAMASK_ORIGIN = "metamask";
|
|
4
|
+
export type CreateOriginPermissionsParams = {
|
|
5
|
+
dappMethods: Iterable<string>;
|
|
6
|
+
metamaskMethods: Iterable<string>;
|
|
7
|
+
origins?: readonly string[];
|
|
8
|
+
metamaskOrigin?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builds the origin-to-method permission map used by network snaps.
|
|
12
|
+
*
|
|
13
|
+
* Those origins receive `dappMethods` as provided (pass an empty list to deny
|
|
14
|
+
* dapp calls). The MetaMask origin always receives `metamaskMethods`.
|
|
15
|
+
*
|
|
16
|
+
* @param params - Origin and method lists for the snap.
|
|
17
|
+
* @param params.dappMethods - Methods allowed for connected dapps.
|
|
18
|
+
* @param params.metamaskMethods - Methods allowed for the MetaMask origin.
|
|
19
|
+
* @param params.origins - Dapp origins to register. Defaults to localhost.
|
|
20
|
+
* @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.
|
|
21
|
+
* @returns A map of origin to allowed RPC methods.
|
|
22
|
+
*/
|
|
23
|
+
export declare const createOriginPermissions: ({ dappMethods, metamaskMethods, origins, metamaskOrigin, }: CreateOriginPermissionsParams) => Map<string, Set<string>>;
|
|
24
|
+
//# sourceMappingURL=createOriginPermissions.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.d.cts","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,4CAA6C,CAAC;AAE/E,eAAO,MAAM,mBAAmB,oCAAqC,CAAC;AAEtE,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,4DAKrC,6BAA6B,KAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAUzD,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare const DEFAULT_PROD_ORIGINS: readonly ["https://portfolio.metamask.io"];
|
|
2
|
+
export declare const DEFAULT_DEV_ORIGINS: readonly ["http://localhost:3000"];
|
|
3
|
+
export declare const DEFAULT_METAMASK_ORIGIN = "metamask";
|
|
4
|
+
export type CreateOriginPermissionsParams = {
|
|
5
|
+
dappMethods: Iterable<string>;
|
|
6
|
+
metamaskMethods: Iterable<string>;
|
|
7
|
+
origins?: readonly string[];
|
|
8
|
+
metamaskOrigin?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Builds the origin-to-method permission map used by network snaps.
|
|
12
|
+
*
|
|
13
|
+
* Those origins receive `dappMethods` as provided (pass an empty list to deny
|
|
14
|
+
* dapp calls). The MetaMask origin always receives `metamaskMethods`.
|
|
15
|
+
*
|
|
16
|
+
* @param params - Origin and method lists for the snap.
|
|
17
|
+
* @param params.dappMethods - Methods allowed for connected dapps.
|
|
18
|
+
* @param params.metamaskMethods - Methods allowed for the MetaMask origin.
|
|
19
|
+
* @param params.origins - Dapp origins to register. Defaults to localhost.
|
|
20
|
+
* @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.
|
|
21
|
+
* @returns A map of origin to allowed RPC methods.
|
|
22
|
+
*/
|
|
23
|
+
export declare const createOriginPermissions: ({ dappMethods, metamaskMethods, origins, metamaskOrigin, }: CreateOriginPermissionsParams) => Map<string, Set<string>>;
|
|
24
|
+
//# sourceMappingURL=createOriginPermissions.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.d.mts","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,4CAA6C,CAAC;AAE/E,eAAO,MAAM,mBAAmB,oCAAqC,CAAC;AAEtE,eAAO,MAAM,uBAAuB,aAAa,CAAC;AAElD,MAAM,MAAM,6BAA6B,GAAG;IAC1C,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC9B,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,uBAAuB,GAAI,4DAKrC,6BAA6B,KAAG,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAUzD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const DEFAULT_PROD_ORIGINS = ['https://portfolio.metamask.io'];
|
|
2
|
+
export const DEFAULT_DEV_ORIGINS = ['http://localhost:3000'];
|
|
3
|
+
export const DEFAULT_METAMASK_ORIGIN = 'metamask';
|
|
4
|
+
/**
|
|
5
|
+
* Builds the origin-to-method permission map used by network snaps.
|
|
6
|
+
*
|
|
7
|
+
* Those origins receive `dappMethods` as provided (pass an empty list to deny
|
|
8
|
+
* dapp calls). The MetaMask origin always receives `metamaskMethods`.
|
|
9
|
+
*
|
|
10
|
+
* @param params - Origin and method lists for the snap.
|
|
11
|
+
* @param params.dappMethods - Methods allowed for connected dapps.
|
|
12
|
+
* @param params.metamaskMethods - Methods allowed for the MetaMask origin.
|
|
13
|
+
* @param params.origins - Dapp origins to register. Defaults to localhost.
|
|
14
|
+
* @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.
|
|
15
|
+
* @returns A map of origin to allowed RPC methods.
|
|
16
|
+
*/
|
|
17
|
+
export const createOriginPermissions = ({ dappMethods, metamaskMethods, origins = DEFAULT_DEV_ORIGINS, metamaskOrigin = DEFAULT_METAMASK_ORIGIN, }) => {
|
|
18
|
+
const originPermissions = new Map();
|
|
19
|
+
const dappPermissions = new Set(dappMethods);
|
|
20
|
+
for (const origin of origins) {
|
|
21
|
+
originPermissions.set(origin, dappPermissions);
|
|
22
|
+
}
|
|
23
|
+
originPermissions.set(metamaskOrigin, new Set(metamaskMethods));
|
|
24
|
+
return originPermissions;
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=createOriginPermissions.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOriginPermissions.mjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/createOriginPermissions.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,+BAA+B,CAAU,CAAC;AAE/E,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,uBAAuB,CAAU,CAAC;AAEtE,MAAM,CAAC,MAAM,uBAAuB,GAAG,UAAU,CAAC;AASlD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,EACtC,WAAW,EACX,eAAe,EACf,OAAO,GAAG,mBAAmB,EAC7B,cAAc,GAAG,uBAAuB,GACV,EAA4B,EAAE;IAC5D,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAuB,CAAC;IACzD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC;IAE7C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjD,CAAC;IACD,iBAAiB,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;IAEhE,OAAO,iBAAiB,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["export const DEFAULT_PROD_ORIGINS = ['https://portfolio.metamask.io'] as const;\n\nexport const DEFAULT_DEV_ORIGINS = ['http://localhost:3000'] as const;\n\nexport const DEFAULT_METAMASK_ORIGIN = 'metamask';\n\nexport type CreateOriginPermissionsParams = {\n dappMethods: Iterable<string>;\n metamaskMethods: Iterable<string>;\n origins?: readonly string[];\n metamaskOrigin?: string;\n};\n\n/**\n * Builds the origin-to-method permission map used by network snaps.\n *\n * Those origins receive `dappMethods` as provided (pass an empty list to deny\n * dapp calls). The MetaMask origin always receives `metamaskMethods`.\n *\n * @param params - Origin and method lists for the snap.\n * @param params.dappMethods - Methods allowed for connected dapps.\n * @param params.metamaskMethods - Methods allowed for the MetaMask origin.\n * @param params.origins - Dapp origins to register. Defaults to localhost.\n * @param params.metamaskOrigin - Origin key for MetaMask. Defaults to `metamask`.\n * @returns A map of origin to allowed RPC methods.\n */\nexport const createOriginPermissions = ({\n dappMethods,\n metamaskMethods,\n origins = DEFAULT_DEV_ORIGINS,\n metamaskOrigin = DEFAULT_METAMASK_ORIGIN,\n}: CreateOriginPermissionsParams): Map<string, Set<string>> => {\n const originPermissions = new Map<string, Set<string>>();\n const dappPermissions = new Set(dappMethods);\n\n for (const origin of origins) {\n originPermissions.set(origin, dappPermissions);\n }\n originPermissions.set(metamaskOrigin, new Set(metamaskMethods));\n\n return originPermissions;\n};\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateOrigin = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/only-throw-error -- UnauthorizedError is the JSON-RPC snap error surface */
|
|
5
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
6
|
+
/**
|
|
7
|
+
* Validates that the origin is allowed to call the given method.
|
|
8
|
+
*
|
|
9
|
+
* @param origin - The origin of the request.
|
|
10
|
+
* @param method - The RPC method of the request.
|
|
11
|
+
* @param originPermissions - Map of origin to allowed methods.
|
|
12
|
+
* @throws {UnauthorizedError} If the origin is missing or the method is not allowed.
|
|
13
|
+
*/
|
|
14
|
+
const validateOrigin = (origin, method, originPermissions) => {
|
|
15
|
+
if (!origin) {
|
|
16
|
+
throw new snaps_sdk_1.UnauthorizedError('Origin not found');
|
|
17
|
+
}
|
|
18
|
+
if (!originPermissions.get(origin)?.has(method)) {
|
|
19
|
+
throw new snaps_sdk_1.UnauthorizedError('Permission denied');
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.validateOrigin = validateOrigin;
|
|
23
|
+
//# sourceMappingURL=validateOrigin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.cjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":";;;AAAA,gHAAgH;AAChH,mDAAwD;AAExD;;;;;;;GAOG;AACI,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,MAAc,EACd,iBAA2C,EACrC,EAAE;IACR,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,6BAAiB,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,6BAAiB,CAAC,mBAAmB,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,cAAc,kBAWzB","sourcesContent":["/* eslint-disable @typescript-eslint/only-throw-error -- UnauthorizedError is the JSON-RPC snap error surface */\nimport { UnauthorizedError } from '@metamask/snaps-sdk';\n\n/**\n * Validates that the origin is allowed to call the given method.\n *\n * @param origin - The origin of the request.\n * @param method - The RPC method of the request.\n * @param originPermissions - Map of origin to allowed methods.\n * @throws {UnauthorizedError} If the origin is missing or the method is not allowed.\n */\nexport const validateOrigin = (\n origin: string,\n method: string,\n originPermissions: Map<string, Set<string>>,\n): void => {\n if (!origin) {\n throw new UnauthorizedError('Origin not found');\n }\n if (!originPermissions.get(origin)?.has(method)) {\n throw new UnauthorizedError('Permission denied');\n }\n};\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that the origin is allowed to call the given method.
|
|
3
|
+
*
|
|
4
|
+
* @param origin - The origin of the request.
|
|
5
|
+
* @param method - The RPC method of the request.
|
|
6
|
+
* @param originPermissions - Map of origin to allowed methods.
|
|
7
|
+
* @throws {UnauthorizedError} If the origin is missing or the method is not allowed.
|
|
8
|
+
*/
|
|
9
|
+
export declare const validateOrigin: (origin: string, method: string, originPermissions: Map<string, Set<string>>) => void;
|
|
10
|
+
//# sourceMappingURL=validateOrigin.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.d.cts","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,mBAAmB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,KAC1C,IAOF,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validates that the origin is allowed to call the given method.
|
|
3
|
+
*
|
|
4
|
+
* @param origin - The origin of the request.
|
|
5
|
+
* @param method - The RPC method of the request.
|
|
6
|
+
* @param originPermissions - Map of origin to allowed methods.
|
|
7
|
+
* @throws {UnauthorizedError} If the origin is missing or the method is not allowed.
|
|
8
|
+
*/
|
|
9
|
+
export declare const validateOrigin: (origin: string, method: string, originPermissions: Map<string, Set<string>>) => void;
|
|
10
|
+
//# sourceMappingURL=validateOrigin.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.d.mts","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,MAAM,EACd,QAAQ,MAAM,EACd,mBAAmB,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,KAC1C,IAOF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/only-throw-error -- UnauthorizedError is the JSON-RPC snap error surface */
|
|
2
|
+
import { UnauthorizedError } from "@metamask/snaps-sdk";
|
|
3
|
+
/**
|
|
4
|
+
* Validates that the origin is allowed to call the given method.
|
|
5
|
+
*
|
|
6
|
+
* @param origin - The origin of the request.
|
|
7
|
+
* @param method - The RPC method of the request.
|
|
8
|
+
* @param originPermissions - Map of origin to allowed methods.
|
|
9
|
+
* @throws {UnauthorizedError} If the origin is missing or the method is not allowed.
|
|
10
|
+
*/
|
|
11
|
+
export const validateOrigin = (origin, method, originPermissions) => {
|
|
12
|
+
if (!origin) {
|
|
13
|
+
throw new UnauthorizedError('Origin not found');
|
|
14
|
+
}
|
|
15
|
+
if (!originPermissions.get(origin)?.has(method)) {
|
|
16
|
+
throw new UnauthorizedError('Permission denied');
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=validateOrigin.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateOrigin.mjs","sourceRoot":"","sources":["../../../src/utils/originPermissions/validateOrigin.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,OAAO,EAAE,iBAAiB,EAAE,4BAA4B;AAExD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,MAAc,EACd,MAAc,EACd,iBAA2C,EACrC,EAAE;IACR,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,iBAAiB,CAAC,kBAAkB,CAAC,CAAC;IAClD,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IACnD,CAAC;AACH,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/only-throw-error -- UnauthorizedError is the JSON-RPC snap error surface */\nimport { UnauthorizedError } from '@metamask/snaps-sdk';\n\n/**\n * Validates that the origin is allowed to call the given method.\n *\n * @param origin - The origin of the request.\n * @param method - The RPC method of the request.\n * @param originPermissions - Map of origin to allowed methods.\n * @throws {UnauthorizedError} If the origin is missing or the method is not allowed.\n */\nexport const validateOrigin = (\n origin: string,\n method: string,\n originPermissions: Map<string, Set<string>>,\n): void => {\n if (!origin) {\n throw new UnauthorizedError('Origin not found');\n }\n if (!originPermissions.get(origin)?.has(method)) {\n throw new UnauthorizedError('Permission denied');\n }\n};\n"]}
|