@metamask/snaps-rpc-methods 11.0.0 → 11.1.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 +14 -1
- package/dist/__fixtures__/entropy.cjs +31 -0
- package/dist/__fixtures__/entropy.cjs.map +1 -0
- package/dist/{types/__fixtures__/entropy.d.ts → __fixtures__/entropy.d.cts} +1 -0
- package/dist/__fixtures__/entropy.d.cts.map +1 -0
- package/dist/__fixtures__/entropy.d.mts +15 -0
- package/dist/__fixtures__/entropy.d.mts.map +1 -0
- package/dist/__fixtures__/entropy.mjs +28 -0
- package/dist/__fixtures__/entropy.mjs.map +1 -0
- package/dist/__fixtures__/index.cjs +18 -0
- package/dist/__fixtures__/index.cjs.map +1 -0
- package/dist/__fixtures__/index.d.cts +2 -0
- package/dist/__fixtures__/index.d.cts.map +1 -0
- package/dist/__fixtures__/index.d.mts +2 -0
- package/dist/__fixtures__/index.d.mts.map +1 -0
- package/dist/__fixtures__/index.mjs +2 -0
- package/dist/__fixtures__/index.mjs.map +1 -0
- package/dist/endowments/caveats/generic.cjs +50 -0
- package/dist/endowments/caveats/generic.cjs.map +1 -0
- package/dist/{types/endowments/caveats/generic.d.ts → endowments/caveats/generic.d.cts} +3 -2
- package/dist/endowments/caveats/generic.d.cts.map +1 -0
- package/dist/endowments/caveats/generic.d.mts +20 -0
- package/dist/endowments/caveats/generic.d.mts.map +1 -0
- package/dist/endowments/caveats/generic.mjs +45 -6
- package/dist/endowments/caveats/generic.mjs.map +1 -1
- package/dist/endowments/caveats/index.cjs +19 -0
- package/dist/endowments/caveats/index.cjs.map +1 -0
- package/dist/endowments/caveats/index.d.cts +3 -0
- package/dist/endowments/caveats/index.d.cts.map +1 -0
- package/dist/endowments/caveats/index.d.mts +3 -0
- package/dist/endowments/caveats/index.d.mts.map +1 -0
- package/dist/endowments/caveats/index.mjs +2 -17
- package/dist/endowments/caveats/index.mjs.map +1 -1
- package/dist/endowments/caveats/requestTime.cjs +104 -0
- package/dist/{chunk-FCVWU5XH.js.map → endowments/caveats/requestTime.cjs.map} +1 -1
- package/dist/{types/endowments/caveats/requestTime.d.ts → endowments/caveats/requestTime.d.cts} +5 -4
- package/dist/endowments/caveats/requestTime.d.cts.map +1 -0
- package/dist/endowments/caveats/requestTime.d.mts +30 -0
- package/dist/endowments/caveats/requestTime.d.mts.map +1 -0
- package/dist/endowments/caveats/requestTime.mjs +96 -11
- package/dist/endowments/caveats/requestTime.mjs.map +1 -1
- package/dist/endowments/cronjob.cjs +105 -0
- package/dist/endowments/cronjob.cjs.map +1 -0
- package/dist/{types/endowments/cronjob.d.ts → endowments/cronjob.d.cts} +7 -6
- package/dist/endowments/cronjob.d.cts.map +1 -0
- package/dist/endowments/cronjob.d.mts +52 -0
- package/dist/endowments/cronjob.d.mts.map +1 -0
- package/dist/endowments/cronjob.mjs +97 -14
- package/dist/endowments/cronjob.mjs.map +1 -1
- package/dist/endowments/enum.cjs +18 -0
- package/dist/endowments/enum.cjs.map +1 -0
- package/dist/{types/endowments/enum.d.ts → endowments/enum.d.cts} +1 -0
- package/dist/endowments/enum.d.cts.map +1 -0
- package/dist/endowments/enum.d.mts +14 -0
- package/dist/endowments/enum.d.mts.map +1 -0
- package/dist/endowments/enum.mjs +14 -6
- package/dist/endowments/enum.mjs.map +1 -1
- package/dist/endowments/ethereum-provider.cjs +32 -0
- package/dist/endowments/ethereum-provider.cjs.map +1 -0
- package/dist/{types/endowments/ethereum-provider.d.ts → endowments/ethereum-provider.d.cts} +4 -3
- package/dist/endowments/ethereum-provider.d.cts.map +1 -0
- package/dist/endowments/ethereum-provider.d.mts +15 -0
- package/dist/endowments/ethereum-provider.d.mts.map +1 -0
- package/dist/endowments/ethereum-provider.mjs +27 -6
- package/dist/endowments/ethereum-provider.mjs.map +1 -1
- package/dist/endowments/home-page.cjs +28 -0
- package/dist/{chunk-2SFH57UV.js.map → endowments/home-page.cjs.map} +1 -1
- package/dist/{types/endowments/home-page.d.ts → endowments/home-page.d.cts} +5 -4
- package/dist/endowments/home-page.d.cts.map +1 -0
- package/dist/endowments/home-page.d.mts +16 -0
- package/dist/endowments/home-page.d.mts.map +1 -0
- package/dist/endowments/home-page.mjs +23 -6
- package/dist/endowments/home-page.mjs.map +1 -1
- package/dist/endowments/index.cjs +92 -0
- package/dist/endowments/index.cjs.map +1 -0
- package/dist/{types/endowments/index.d.ts → endowments/index.d.cts} +12 -11
- package/dist/endowments/index.d.cts.map +1 -0
- package/dist/endowments/index.d.mts +132 -0
- package/dist/endowments/index.d.mts.map +1 -0
- package/dist/endowments/index.mjs +65 -52
- package/dist/endowments/index.mjs.map +1 -1
- package/dist/endowments/keyring.cjs +96 -0
- package/dist/endowments/keyring.cjs.map +1 -0
- package/dist/{types/endowments/keyring.d.ts → endowments/keyring.d.cts} +7 -6
- package/dist/endowments/keyring.d.cts.map +1 -0
- package/dist/endowments/keyring.d.mts +40 -0
- package/dist/endowments/keyring.d.mts.map +1 -0
- package/dist/endowments/keyring.mjs +89 -15
- package/dist/endowments/keyring.mjs.map +1 -1
- package/dist/endowments/lifecycle-hooks.cjs +28 -0
- package/dist/endowments/lifecycle-hooks.cjs.map +1 -0
- package/dist/{types/endowments/lifecycle-hooks.d.ts → endowments/lifecycle-hooks.d.cts} +5 -4
- package/dist/endowments/lifecycle-hooks.d.cts.map +1 -0
- package/dist/endowments/lifecycle-hooks.d.mts +16 -0
- package/dist/endowments/lifecycle-hooks.d.mts.map +1 -0
- package/dist/endowments/lifecycle-hooks.mjs +23 -6
- package/dist/endowments/lifecycle-hooks.mjs.map +1 -1
- package/dist/endowments/name-lookup.cjs +141 -0
- package/dist/endowments/name-lookup.cjs.map +1 -0
- package/dist/{types/endowments/name-lookup.d.ts → endowments/name-lookup.d.cts} +6 -5
- package/dist/endowments/name-lookup.d.cts.map +1 -0
- package/dist/endowments/name-lookup.d.mts +50 -0
- package/dist/endowments/name-lookup.d.mts.map +1 -0
- package/dist/endowments/name-lookup.mjs +133 -17
- package/dist/endowments/name-lookup.mjs.map +1 -1
- package/dist/endowments/network-access.cjs +30 -0
- package/dist/endowments/network-access.cjs.map +1 -0
- package/dist/{types/endowments/network-access.d.ts → endowments/network-access.d.cts} +4 -3
- package/dist/endowments/network-access.d.cts.map +1 -0
- package/dist/endowments/network-access.d.mts +15 -0
- package/dist/endowments/network-access.d.mts.map +1 -0
- package/dist/endowments/network-access.mjs +25 -6
- package/dist/endowments/network-access.mjs.map +1 -1
- package/dist/endowments/rpc.cjs +90 -0
- package/dist/endowments/rpc.cjs.map +1 -0
- package/dist/{types/endowments/rpc.d.ts → endowments/rpc.d.cts} +7 -6
- package/dist/endowments/rpc.d.cts.map +1 -0
- package/dist/endowments/rpc.d.mts +39 -0
- package/dist/endowments/rpc.d.mts.map +1 -0
- package/dist/endowments/rpc.mjs +83 -15
- package/dist/endowments/rpc.mjs.map +1 -1
- package/dist/endowments/signature-insight.cjs +102 -0
- package/dist/endowments/signature-insight.cjs.map +1 -0
- package/dist/{types/endowments/signature-insight.d.ts → endowments/signature-insight.d.cts} +6 -5
- package/dist/endowments/signature-insight.d.cts.map +1 -0
- package/dist/endowments/signature-insight.d.mts +40 -0
- package/dist/endowments/signature-insight.d.mts.map +1 -0
- package/dist/endowments/signature-insight.mjs +95 -15
- package/dist/endowments/signature-insight.mjs.map +1 -1
- package/dist/endowments/transaction-insight.cjs +105 -0
- package/dist/endowments/transaction-insight.cjs.map +1 -0
- package/dist/{types/endowments/transaction-insight.d.ts → endowments/transaction-insight.d.cts} +6 -5
- package/dist/endowments/transaction-insight.d.cts.map +1 -0
- package/dist/endowments/transaction-insight.d.mts +40 -0
- package/dist/endowments/transaction-insight.d.mts.map +1 -0
- package/dist/endowments/transaction-insight.mjs +98 -15
- package/dist/endowments/transaction-insight.mjs.map +1 -1
- package/dist/endowments/web-assembly.cjs +31 -0
- package/dist/endowments/web-assembly.cjs.map +1 -0
- package/dist/{types/endowments/web-assembly.d.ts → endowments/web-assembly.d.cts} +4 -3
- package/dist/endowments/web-assembly.d.cts.map +1 -0
- package/dist/endowments/web-assembly.d.mts +15 -0
- package/dist/endowments/web-assembly.d.mts.map +1 -0
- package/dist/endowments/web-assembly.mjs +26 -6
- package/dist/endowments/web-assembly.mjs.map +1 -1
- package/dist/index.cjs +28 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -122
- package/dist/index.mjs.map +1 -1
- package/dist/permissions.cjs +55 -0
- package/dist/permissions.cjs.map +1 -0
- package/dist/{types/permissions.d.ts → permissions.d.cts} +3 -2
- package/dist/permissions.d.cts.map +1 -0
- package/dist/permissions.d.mts +17 -0
- package/dist/permissions.d.mts.map +1 -0
- package/dist/permissions.mjs +48 -43
- package/dist/permissions.mjs.map +1 -1
- package/dist/permitted/createInterface.cjs +64 -0
- package/dist/permitted/createInterface.cjs.map +1 -0
- package/dist/{types/permitted/createInterface.d.ts → permitted/createInterface.d.cts} +48 -47
- package/dist/permitted/createInterface.d.cts.map +1 -0
- package/dist/permitted/createInterface.d.mts +181 -0
- package/dist/permitted/createInterface.d.mts.map +1 -0
- package/dist/permitted/createInterface.mjs +59 -5
- package/dist/permitted/createInterface.mjs.map +1 -1
- package/dist/permitted/getAllSnaps.cjs +39 -0
- package/dist/permitted/getAllSnaps.cjs.map +1 -0
- package/dist/{types/permitted/getAllSnaps.d.ts → permitted/getAllSnaps.d.cts} +4 -3
- package/dist/permitted/getAllSnaps.d.cts.map +1 -0
- package/dist/permitted/getAllSnaps.d.mts +15 -0
- package/dist/permitted/getAllSnaps.d.mts.map +1 -0
- package/dist/permitted/getAllSnaps.mjs +34 -5
- package/dist/permitted/getAllSnaps.mjs.map +1 -1
- package/dist/permitted/getClientStatus.cjs +32 -0
- package/dist/permitted/getClientStatus.cjs.map +1 -0
- package/dist/{types/permitted/getClientStatus.d.ts → permitted/getClientStatus.d.cts} +4 -3
- package/dist/permitted/getClientStatus.d.cts.map +1 -0
- package/dist/permitted/getClientStatus.d.mts +14 -0
- package/dist/permitted/getClientStatus.d.mts.map +1 -0
- package/dist/permitted/getClientStatus.mjs +27 -5
- package/dist/permitted/getClientStatus.mjs.map +1 -1
- package/dist/permitted/getFile.cjs +47 -0
- package/dist/permitted/getFile.cjs.map +1 -0
- package/dist/{types/permitted/getFile.d.ts → permitted/getFile.d.cts} +4 -3
- package/dist/permitted/getFile.d.cts.map +1 -0
- package/dist/permitted/getFile.d.mts +16 -0
- package/dist/permitted/getFile.d.mts.map +1 -0
- package/dist/permitted/getFile.mjs +42 -7
- package/dist/permitted/getFile.mjs.map +1 -1
- package/dist/permitted/getInterfaceState.cjs +62 -0
- package/dist/permitted/getInterfaceState.cjs.map +1 -0
- package/dist/{types/permitted/getInterfaceState.d.ts → permitted/getInterfaceState.d.cts} +4 -3
- package/dist/permitted/getInterfaceState.d.cts.map +1 -0
- package/dist/permitted/getInterfaceState.d.mts +19 -0
- package/dist/permitted/getInterfaceState.d.mts.map +1 -0
- package/dist/permitted/getInterfaceState.mjs +57 -5
- package/dist/permitted/getInterfaceState.mjs.map +1 -1
- package/dist/permitted/getSnaps.cjs +33 -0
- package/dist/permitted/getSnaps.cjs.map +1 -0
- package/dist/{types/permitted/getSnaps.d.ts → permitted/getSnaps.d.cts} +4 -3
- package/dist/permitted/getSnaps.d.cts.map +1 -0
- package/dist/permitted/getSnaps.d.mts +14 -0
- package/dist/permitted/getSnaps.d.mts.map +1 -0
- package/dist/permitted/getSnaps.mjs +28 -5
- package/dist/permitted/getSnaps.mjs.map +1 -1
- package/dist/permitted/handlers.cjs +31 -0
- package/dist/permitted/handlers.cjs.map +1 -0
- package/dist/{types/permitted/handlers.d.ts → permitted/handlers.d.cts} +1 -0
- package/dist/permitted/handlers.d.cts.map +1 -0
- package/dist/permitted/handlers.d.mts +35 -0
- package/dist/permitted/handlers.d.mts.map +1 -0
- package/dist/permitted/handlers.mjs +26 -19
- package/dist/permitted/handlers.mjs.map +1 -1
- package/dist/permitted/index.cjs +19 -0
- package/dist/permitted/index.cjs.map +1 -0
- package/dist/permitted/index.d.cts +12 -0
- package/dist/permitted/index.d.cts.map +1 -0
- package/dist/permitted/index.d.mts +12 -0
- package/dist/permitted/index.d.mts.map +1 -0
- package/dist/permitted/index.mjs +2 -26
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/invokeKeyring.cjs +83 -0
- package/dist/permitted/invokeKeyring.cjs.map +1 -0
- package/dist/{types/permitted/invokeKeyring.d.ts → permitted/invokeKeyring.d.cts} +4 -3
- package/dist/permitted/invokeKeyring.d.cts.map +1 -0
- package/dist/permitted/invokeKeyring.d.mts +16 -0
- package/dist/permitted/invokeKeyring.d.mts.map +1 -0
- package/dist/permitted/invokeKeyring.mjs +78 -6
- package/dist/permitted/invokeKeyring.mjs.map +1 -1
- package/dist/permitted/invokeSnapSugar.cjs +68 -0
- package/dist/permitted/invokeSnapSugar.cjs.map +1 -0
- package/dist/{types/permitted/invokeSnapSugar.d.ts → permitted/invokeSnapSugar.d.cts} +5 -4
- package/dist/permitted/invokeSnapSugar.d.cts.map +1 -0
- package/dist/permitted/invokeSnapSugar.d.mts +35 -0
- package/dist/permitted/invokeSnapSugar.d.mts.map +1 -0
- package/dist/permitted/invokeSnapSugar.mjs +61 -9
- package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
- package/dist/permitted/middleware.cjs +40 -0
- package/dist/permitted/middleware.cjs.map +1 -0
- package/dist/{types/permitted/middleware.d.ts → permitted/middleware.d.cts} +3 -2
- package/dist/permitted/middleware.d.cts.map +1 -0
- package/dist/permitted/middleware.d.mts +11 -0
- package/dist/permitted/middleware.d.mts.map +1 -0
- package/dist/permitted/middleware.mjs +35 -20
- package/dist/permitted/middleware.mjs.map +1 -1
- package/dist/permitted/requestSnaps.cjs +121 -0
- package/dist/permitted/requestSnaps.cjs.map +1 -0
- package/dist/{types/permitted/requestSnaps.d.ts → permitted/requestSnaps.d.cts} +4 -3
- package/dist/permitted/requestSnaps.d.cts.map +1 -0
- package/dist/permitted/requestSnaps.d.mts +51 -0
- package/dist/permitted/requestSnaps.d.mts.map +1 -0
- package/dist/permitted/requestSnaps.mjs +114 -10
- package/dist/permitted/requestSnaps.mjs.map +1 -1
- package/dist/permitted/resolveInterface.cjs +65 -0
- package/dist/permitted/resolveInterface.cjs.map +1 -0
- package/dist/{types/permitted/resolveInterface.d.ts → permitted/resolveInterface.d.cts} +6 -5
- package/dist/permitted/resolveInterface.d.cts.map +1 -0
- package/dist/permitted/resolveInterface.d.mts +22 -0
- package/dist/permitted/resolveInterface.d.mts.map +1 -0
- package/dist/permitted/resolveInterface.mjs +60 -5
- package/dist/permitted/resolveInterface.mjs.map +1 -1
- package/dist/permitted/updateInterface.cjs +65 -0
- package/dist/permitted/updateInterface.cjs.map +1 -0
- package/dist/{types/permitted/updateInterface.d.ts → permitted/updateInterface.d.cts} +48 -47
- package/dist/permitted/updateInterface.d.cts.map +1 -0
- package/dist/permitted/updateInterface.d.mts +181 -0
- package/dist/permitted/updateInterface.d.mts.map +1 -0
- package/dist/permitted/updateInterface.mjs +60 -5
- package/dist/permitted/updateInterface.mjs.map +1 -1
- package/dist/restricted/caveats/index.cjs +22 -0
- package/dist/restricted/caveats/index.cjs.map +1 -0
- package/dist/{types/restricted/caveats/index.d.ts → restricted/caveats/index.d.cts} +3 -2
- package/dist/restricted/caveats/index.d.cts.map +1 -0
- package/dist/restricted/caveats/index.d.mts +9 -0
- package/dist/restricted/caveats/index.d.mts.map +1 -0
- package/dist/restricted/caveats/index.mjs +17 -15
- package/dist/restricted/caveats/index.mjs.map +1 -1
- package/dist/restricted/caveats/permittedCoinTypes.cjs +90 -0
- package/dist/restricted/caveats/permittedCoinTypes.cjs.map +1 -0
- package/dist/{types/restricted/caveats/permittedCoinTypes.d.ts → restricted/caveats/permittedCoinTypes.d.cts} +5 -4
- package/dist/restricted/caveats/permittedCoinTypes.d.cts.map +1 -0
- package/dist/restricted/caveats/permittedCoinTypes.d.mts +30 -0
- package/dist/restricted/caveats/permittedCoinTypes.d.mts.map +1 -0
- package/dist/restricted/caveats/permittedCoinTypes.mjs +82 -11
- package/dist/restricted/caveats/permittedCoinTypes.mjs.map +1 -1
- package/dist/restricted/caveats/permittedDerivationPaths.cjs +70 -0
- package/dist/restricted/caveats/permittedDerivationPaths.cjs.map +1 -0
- package/dist/{types/restricted/caveats/permittedDerivationPaths.d.ts → restricted/caveats/permittedDerivationPaths.d.cts} +5 -4
- package/dist/restricted/caveats/permittedDerivationPaths.d.cts.map +1 -0
- package/dist/restricted/caveats/permittedDerivationPaths.d.mts +33 -0
- package/dist/restricted/caveats/permittedDerivationPaths.d.mts.map +1 -0
- package/dist/restricted/caveats/permittedDerivationPaths.mjs +62 -11
- package/dist/restricted/caveats/permittedDerivationPaths.mjs.map +1 -1
- package/dist/restricted/caveats/snapIds.cjs +56 -0
- package/dist/restricted/caveats/snapIds.cjs.map +1 -0
- package/dist/{types/restricted/caveats/snapIds.d.ts → restricted/caveats/snapIds.d.cts} +5 -4
- package/dist/restricted/caveats/snapIds.d.cts.map +1 -0
- package/dist/restricted/caveats/snapIds.d.mts +22 -0
- package/dist/restricted/caveats/snapIds.d.mts.map +1 -0
- package/dist/restricted/caveats/snapIds.mjs +49 -9
- package/dist/restricted/caveats/snapIds.mjs.map +1 -1
- package/dist/restricted/dialog.cjs +222 -0
- package/dist/restricted/dialog.cjs.map +1 -0
- package/dist/restricted/dialog.d.cts +432 -0
- package/dist/restricted/dialog.d.cts.map +1 -0
- package/dist/restricted/dialog.d.mts +432 -0
- package/dist/restricted/dialog.d.mts.map +1 -0
- package/dist/restricted/dialog.mjs +216 -9
- package/dist/restricted/dialog.mjs.map +1 -1
- package/dist/restricted/getBip32Entropy.cjs +69 -0
- package/dist/restricted/getBip32Entropy.cjs.map +1 -0
- package/dist/{types/restricted/getBip32Entropy.d.ts → restricted/getBip32Entropy.d.cts} +6 -5
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -0
- package/dist/restricted/getBip32Entropy.d.mts +45 -0
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -0
- package/dist/restricted/getBip32Entropy.mjs +63 -8
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +78 -0
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -0
- package/dist/{types/restricted/getBip32PublicKey.d.ts → restricted/getBip32PublicKey.d.cts} +7 -6
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -0
- package/dist/restricted/getBip32PublicKey.d.mts +54 -0
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -0
- package/dist/restricted/getBip32PublicKey.mjs +72 -10
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +71 -0
- package/dist/restricted/getBip44Entropy.cjs.map +1 -0
- package/dist/{types/restricted/getBip44Entropy.d.ts → restricted/getBip44Entropy.d.cts} +6 -5
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -0
- package/dist/restricted/getBip44Entropy.d.mts +47 -0
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -0
- package/dist/restricted/getBip44Entropy.mjs +65 -7
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +59 -0
- package/dist/restricted/getEntropy.cjs.map +1 -0
- package/dist/{types/restricted/getEntropy.d.ts → restricted/getEntropy.d.cts} +7 -6
- package/dist/restricted/getEntropy.d.cts.map +1 -0
- package/dist/restricted/getEntropy.d.mts +62 -0
- package/dist/restricted/getEntropy.d.mts.map +1 -0
- package/dist/restricted/getEntropy.mjs +54 -8
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/restricted/getLocale.cjs +47 -0
- package/dist/restricted/getLocale.cjs.map +1 -0
- package/dist/{types/restricted/getLocale.d.ts → restricted/getLocale.d.cts} +6 -5
- package/dist/restricted/getLocale.d.cts.map +1 -0
- package/dist/restricted/getLocale.d.mts +50 -0
- package/dist/restricted/getLocale.d.mts.map +1 -0
- package/dist/restricted/getLocale.mjs +40 -9
- package/dist/restricted/getLocale.mjs.map +1 -1
- package/dist/restricted/getPreferences.cjs +46 -0
- package/dist/restricted/getPreferences.cjs.map +1 -0
- package/dist/{types/restricted/getPreferences.d.ts → restricted/getPreferences.d.cts} +6 -5
- package/dist/restricted/getPreferences.d.cts.map +1 -0
- package/dist/restricted/getPreferences.d.mts +49 -0
- package/dist/restricted/getPreferences.d.mts.map +1 -0
- package/dist/restricted/getPreferences.mjs +39 -9
- package/dist/restricted/getPreferences.mjs.map +1 -1
- package/dist/restricted/index.cjs +49 -0
- package/dist/restricted/index.cjs.map +1 -0
- package/dist/{types/restricted/index.d.ts → restricted/index.d.cts} +17 -16
- package/dist/restricted/index.d.cts.map +1 -0
- package/dist/restricted/index.d.mts +169 -0
- package/dist/restricted/index.d.mts.map +1 -0
- package/dist/restricted/index.mjs +27 -35
- package/dist/restricted/index.mjs.map +1 -1
- package/dist/restricted/invokeSnap.cjs +96 -0
- package/dist/restricted/invokeSnap.cjs.map +1 -0
- package/dist/{types/restricted/invokeSnap.d.ts → restricted/invokeSnap.d.cts} +8 -6
- package/dist/restricted/invokeSnap.d.cts.map +1 -0
- package/dist/restricted/invokeSnap.d.mts +65 -0
- package/dist/restricted/invokeSnap.d.mts.map +1 -0
- package/dist/restricted/invokeSnap.mjs +89 -11
- package/dist/restricted/invokeSnap.mjs.map +1 -1
- package/dist/restricted/manageAccounts.cjs +61 -0
- package/dist/restricted/manageAccounts.cjs.map +1 -0
- package/dist/{types/restricted/manageAccounts.d.ts → restricted/manageAccounts.d.cts} +6 -5
- package/dist/restricted/manageAccounts.d.cts.map +1 -0
- package/dist/restricted/manageAccounts.d.mts +65 -0
- package/dist/restricted/manageAccounts.d.mts.map +1 -0
- package/dist/restricted/manageAccounts.mjs +54 -11
- package/dist/restricted/manageAccounts.mjs.map +1 -1
- package/dist/restricted/manageState.cjs +175 -0
- package/dist/restricted/manageState.cjs.map +1 -0
- package/dist/{types/restricted/manageState.d.ts → restricted/manageState.d.cts} +6 -5
- package/dist/restricted/manageState.d.cts.map +1 -0
- package/dist/restricted/manageState.d.mts +111 -0
- package/dist/restricted/manageState.d.mts.map +1 -0
- package/dist/restricted/manageState.mjs +166 -18
- package/dist/restricted/manageState.mjs.map +1 -1
- package/dist/restricted/notify.cjs +108 -0
- package/dist/restricted/notify.cjs.map +1 -0
- package/dist/{types/restricted/notify.d.ts → restricted/notify.d.cts} +7 -6
- package/dist/restricted/notify.d.cts.map +1 -0
- package/dist/restricted/notify.d.mts +83 -0
- package/dist/restricted/notify.d.mts.map +1 -0
- package/dist/restricted/notify.mjs +100 -11
- package/dist/restricted/notify.mjs.map +1 -1
- package/dist/utils.cjs +140 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/{types/utils.d.ts → utils.d.cts} +6 -4
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +98 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +132 -12
- package/dist/utils.mjs.map +1 -1
- package/package.json +20 -19
- package/dist/chunk-23XDKQW2.mjs +0 -73
- package/dist/chunk-23XDKQW2.mjs.map +0 -1
- package/dist/chunk-2CTOCP34.mjs +0 -45
- package/dist/chunk-2CTOCP34.mjs.map +0 -1
- package/dist/chunk-2L2ATCIK.mjs +0 -78
- package/dist/chunk-2L2ATCIK.mjs.map +0 -1
- package/dist/chunk-2RDYC42U.mjs +0 -67
- package/dist/chunk-2RDYC42U.mjs.map +0 -1
- package/dist/chunk-2SFH57UV.js +0 -21
- package/dist/chunk-33LLA2MH.mjs +0 -75
- package/dist/chunk-33LLA2MH.mjs.map +0 -1
- package/dist/chunk-33MTKZ4H.js +0 -90
- package/dist/chunk-33MTKZ4H.js.map +0 -1
- package/dist/chunk-3UAWEHMF.js +0 -18
- package/dist/chunk-3UAWEHMF.js.map +0 -1
- package/dist/chunk-3WCLDJAS.mjs +0 -74
- package/dist/chunk-3WCLDJAS.mjs.map +0 -1
- package/dist/chunk-3WKIKYUH.js +0 -78
- package/dist/chunk-3WKIKYUH.js.map +0 -1
- package/dist/chunk-4D2B2UQ6.mjs +0 -23
- package/dist/chunk-4D2B2UQ6.mjs.map +0 -1
- package/dist/chunk-4LSOS7SM.js +0 -23
- package/dist/chunk-4LSOS7SM.js.map +0 -1
- package/dist/chunk-4PWFZPJC.js +0 -79
- package/dist/chunk-4PWFZPJC.js.map +0 -1
- package/dist/chunk-57BL7O2P.mjs +0 -69
- package/dist/chunk-57BL7O2P.mjs.map +0 -1
- package/dist/chunk-62URQ5VS.mjs +0 -18
- package/dist/chunk-62URQ5VS.mjs.map +0 -1
- package/dist/chunk-6XKVFSC2.js +0 -32
- package/dist/chunk-6XKVFSC2.js.map +0 -1
- package/dist/chunk-756OQVOC.js +0 -67
- package/dist/chunk-756OQVOC.js.map +0 -1
- package/dist/chunk-7CV677MM.js +0 -42
- package/dist/chunk-7CV677MM.js.map +0 -1
- package/dist/chunk-7HVABE5R.js +0 -74
- package/dist/chunk-7HVABE5R.js.map +0 -1
- package/dist/chunk-7P6TF6CE.mjs +0 -55
- package/dist/chunk-7P6TF6CE.mjs.map +0 -1
- package/dist/chunk-7TVJV425.js +0 -1
- package/dist/chunk-7TVJV425.js.map +0 -1
- package/dist/chunk-A6H6I4VH.js +0 -61
- package/dist/chunk-A6H6I4VH.js.map +0 -1
- package/dist/chunk-AMMJ744B.mjs +0 -32
- package/dist/chunk-AMMJ744B.mjs.map +0 -1
- package/dist/chunk-ATBKAX2S.js +0 -39
- package/dist/chunk-ATBKAX2S.js.map +0 -1
- package/dist/chunk-B3NIHNXW.js +0 -23
- package/dist/chunk-B3NIHNXW.js.map +0 -1
- package/dist/chunk-CD4OUHO5.mjs +0 -20
- package/dist/chunk-CD4OUHO5.mjs.map +0 -1
- package/dist/chunk-CDAVFOUS.js +0 -53
- package/dist/chunk-CDAVFOUS.js.map +0 -1
- package/dist/chunk-CH5O2YCX.mjs +0 -18
- package/dist/chunk-CH5O2YCX.mjs.map +0 -1
- package/dist/chunk-DLVPMPRZ.js +0 -45
- package/dist/chunk-DLVPMPRZ.js.map +0 -1
- package/dist/chunk-DTZF746A.mjs +0 -21
- package/dist/chunk-DTZF746A.mjs.map +0 -1
- package/dist/chunk-E27BGHCR.js +0 -78
- package/dist/chunk-E27BGHCR.js.map +0 -1
- package/dist/chunk-ELCOEVKA.js +0 -196
- package/dist/chunk-ELCOEVKA.js.map +0 -1
- package/dist/chunk-EOXTZF5U.js +0 -47
- package/dist/chunk-EOXTZF5U.js.map +0 -1
- package/dist/chunk-FCVWU5XH.js +0 -73
- package/dist/chunk-FFHVA6PP.js +0 -82
- package/dist/chunk-FFHVA6PP.js.map +0 -1
- package/dist/chunk-FJ7COFRJ.mjs +0 -54
- package/dist/chunk-FJ7COFRJ.mjs.map +0 -1
- package/dist/chunk-FM4LNQR7.mjs +0 -34
- package/dist/chunk-FM4LNQR7.mjs.map +0 -1
- package/dist/chunk-GE5XFDUE.js +0 -21
- package/dist/chunk-GE5XFDUE.js.map +0 -1
- package/dist/chunk-GEJDXRTL.mjs +0 -59
- package/dist/chunk-GEJDXRTL.mjs.map +0 -1
- package/dist/chunk-GPV4ETUH.mjs +0 -47
- package/dist/chunk-GPV4ETUH.mjs.map +0 -1
- package/dist/chunk-H6X3CWWQ.js +0 -54
- package/dist/chunk-H6X3CWWQ.js.map +0 -1
- package/dist/chunk-HOECEYMT.mjs +0 -70
- package/dist/chunk-HOECEYMT.mjs.map +0 -1
- package/dist/chunk-I2P65KBQ.mjs +0 -67
- package/dist/chunk-I2P65KBQ.mjs.map +0 -1
- package/dist/chunk-I3G6S6MJ.js +0 -68
- package/dist/chunk-I3G6S6MJ.js.map +0 -1
- package/dist/chunk-IE6EHYEG.js +0 -57
- package/dist/chunk-IE6EHYEG.js.map +0 -1
- package/dist/chunk-JWDQUKKU.mjs +0 -80
- package/dist/chunk-JWDQUKKU.mjs.map +0 -1
- package/dist/chunk-K3UL5RVN.mjs +0 -43
- package/dist/chunk-K3UL5RVN.mjs.map +0 -1
- package/dist/chunk-KRSIAVUJ.js +0 -115
- package/dist/chunk-KRSIAVUJ.js.map +0 -1
- package/dist/chunk-KSTF5JYB.mjs +0 -23
- package/dist/chunk-KSTF5JYB.mjs.map +0 -1
- package/dist/chunk-LP3RWEDJ.js +0 -43
- package/dist/chunk-LP3RWEDJ.js.map +0 -1
- package/dist/chunk-LR7UR4YU.mjs +0 -52
- package/dist/chunk-LR7UR4YU.mjs.map +0 -1
- package/dist/chunk-LXJBBRQ4.mjs +0 -57
- package/dist/chunk-LXJBBRQ4.mjs.map +0 -1
- package/dist/chunk-M2JQCKR7.js +0 -143
- package/dist/chunk-M2JQCKR7.js.map +0 -1
- package/dist/chunk-MC2Z4NF6.mjs +0 -45
- package/dist/chunk-MC2Z4NF6.mjs.map +0 -1
- package/dist/chunk-MXPVC2XP.mjs +0 -105
- package/dist/chunk-MXPVC2XP.mjs.map +0 -1
- package/dist/chunk-NU4NAAFG.js +0 -1
- package/dist/chunk-NU4NAAFG.js.map +0 -1
- package/dist/chunk-NWT2EXFD.js +0 -18
- package/dist/chunk-NWT2EXFD.js.map +0 -1
- package/dist/chunk-O66NZFSD.mjs +0 -23
- package/dist/chunk-O66NZFSD.mjs.map +0 -1
- package/dist/chunk-ODN35VOK.mjs +0 -119
- package/dist/chunk-ODN35VOK.mjs.map +0 -1
- package/dist/chunk-OI33OL7K.js +0 -47
- package/dist/chunk-OI33OL7K.js.map +0 -1
- package/dist/chunk-PIAWDTWO.mjs +0 -68
- package/dist/chunk-PIAWDTWO.mjs.map +0 -1
- package/dist/chunk-PIRQCNBJ.mjs +0 -78
- package/dist/chunk-PIRQCNBJ.mjs.map +0 -1
- package/dist/chunk-PK2RPAXI.js +0 -59
- package/dist/chunk-PK2RPAXI.js.map +0 -1
- package/dist/chunk-PS6OEQXL.js +0 -105
- package/dist/chunk-PS6OEQXL.js.map +0 -1
- package/dist/chunk-PXU6PORA.js +0 -119
- package/dist/chunk-PXU6PORA.js.map +0 -1
- package/dist/chunk-Q27K2I6Z.js +0 -23
- package/dist/chunk-Q27K2I6Z.js.map +0 -1
- package/dist/chunk-QDZAWH6F.js +0 -80
- package/dist/chunk-QDZAWH6F.js.map +0 -1
- package/dist/chunk-QMULJEYN.js +0 -35
- package/dist/chunk-QMULJEYN.js.map +0 -1
- package/dist/chunk-RHPSYX7X.js +0 -34
- package/dist/chunk-RHPSYX7X.js.map +0 -1
- package/dist/chunk-T56DKVFS.js +0 -70
- package/dist/chunk-T56DKVFS.js.map +0 -1
- package/dist/chunk-TAXLFFV4.mjs +0 -115
- package/dist/chunk-TAXLFFV4.mjs.map +0 -1
- package/dist/chunk-TE4W25CA.mjs +0 -143
- package/dist/chunk-TE4W25CA.mjs.map +0 -1
- package/dist/chunk-TG63GBK3.mjs +0 -1
- package/dist/chunk-TG63GBK3.mjs.map +0 -1
- package/dist/chunk-TNENASGX.mjs +0 -1
- package/dist/chunk-TNENASGX.mjs.map +0 -1
- package/dist/chunk-TQCUJQHY.mjs +0 -196
- package/dist/chunk-TQCUJQHY.mjs.map +0 -1
- package/dist/chunk-TT4DP2YW.mjs +0 -35
- package/dist/chunk-TT4DP2YW.mjs.map +0 -1
- package/dist/chunk-TVC3E5LI.mjs +0 -42
- package/dist/chunk-TVC3E5LI.mjs.map +0 -1
- package/dist/chunk-U6TJQLNV.js +0 -45
- package/dist/chunk-U6TJQLNV.js.map +0 -1
- package/dist/chunk-UB3733UY.mjs +0 -23
- package/dist/chunk-UB3733UY.mjs.map +0 -1
- package/dist/chunk-UCWANXBZ.js +0 -45
- package/dist/chunk-UCWANXBZ.js.map +0 -1
- package/dist/chunk-UF3UJTY3.js +0 -55
- package/dist/chunk-UF3UJTY3.js.map +0 -1
- package/dist/chunk-UY4DUF53.mjs +0 -45
- package/dist/chunk-UY4DUF53.mjs.map +0 -1
- package/dist/chunk-V3KRSCUK.mjs +0 -53
- package/dist/chunk-V3KRSCUK.mjs.map +0 -1
- package/dist/chunk-VUA6ICJO.js +0 -52
- package/dist/chunk-VUA6ICJO.js.map +0 -1
- package/dist/chunk-VVBTXSID.mjs +0 -82
- package/dist/chunk-VVBTXSID.mjs.map +0 -1
- package/dist/chunk-VYII7C3J.mjs +0 -79
- package/dist/chunk-VYII7C3J.mjs.map +0 -1
- package/dist/chunk-W33UWNA2.mjs +0 -90
- package/dist/chunk-W33UWNA2.mjs.map +0 -1
- package/dist/chunk-XGMYBPQR.mjs +0 -47
- package/dist/chunk-XGMYBPQR.mjs.map +0 -1
- package/dist/chunk-YGKFOOWI.js +0 -20
- package/dist/chunk-YGKFOOWI.js.map +0 -1
- package/dist/chunk-YOHE52XB.js +0 -23
- package/dist/chunk-YOHE52XB.js.map +0 -1
- package/dist/chunk-YT2Q3W5C.js +0 -69
- package/dist/chunk-YT2Q3W5C.js.map +0 -1
- package/dist/chunk-YZMFLB67.js +0 -75
- package/dist/chunk-YZMFLB67.js.map +0 -1
- package/dist/chunk-Z6YFGWHN.mjs +0 -61
- package/dist/chunk-Z6YFGWHN.mjs.map +0 -1
- package/dist/chunk-ZH3FC55E.mjs +0 -21
- package/dist/chunk-ZH3FC55E.mjs.map +0 -1
- package/dist/chunk-ZKISN6YP.js +0 -67
- package/dist/chunk-ZKISN6YP.js.map +0 -1
- package/dist/chunk-ZXDCQWMJ.mjs +0 -39
- package/dist/chunk-ZXDCQWMJ.mjs.map +0 -1
- package/dist/endowments/caveats/generic.js +0 -7
- package/dist/endowments/caveats/generic.js.map +0 -1
- package/dist/endowments/caveats/index.js +0 -18
- package/dist/endowments/caveats/index.js.map +0 -1
- package/dist/endowments/caveats/requestTime.js +0 -13
- package/dist/endowments/caveats/requestTime.js.map +0 -1
- package/dist/endowments/cronjob.js +0 -16
- package/dist/endowments/cronjob.js.map +0 -1
- package/dist/endowments/enum.js +0 -7
- package/dist/endowments/enum.js.map +0 -1
- package/dist/endowments/ethereum-provider.js +0 -8
- package/dist/endowments/ethereum-provider.js.map +0 -1
- package/dist/endowments/home-page.js +0 -8
- package/dist/endowments/home-page.js.map +0 -1
- package/dist/endowments/index.js +0 -54
- package/dist/endowments/index.js.map +0 -1
- package/dist/endowments/keyring.js +0 -17
- package/dist/endowments/keyring.js.map +0 -1
- package/dist/endowments/lifecycle-hooks.js +0 -8
- package/dist/endowments/lifecycle-hooks.js.map +0 -1
- package/dist/endowments/name-lookup.js +0 -19
- package/dist/endowments/name-lookup.js.map +0 -1
- package/dist/endowments/network-access.js +0 -8
- package/dist/endowments/network-access.js.map +0 -1
- package/dist/endowments/rpc.js +0 -17
- package/dist/endowments/rpc.js.map +0 -1
- package/dist/endowments/signature-insight.js +0 -17
- package/dist/endowments/signature-insight.js.map +0 -1
- package/dist/endowments/transaction-insight.js +0 -17
- package/dist/endowments/transaction-insight.js.map +0 -1
- package/dist/endowments/web-assembly.js +0 -8
- package/dist/endowments/web-assembly.js.map +0 -1
- package/dist/index.js +0 -123
- package/dist/index.js.map +0 -1
- package/dist/permissions.js +0 -44
- package/dist/permissions.js.map +0 -1
- package/dist/permitted/createInterface.js +0 -7
- package/dist/permitted/createInterface.js.map +0 -1
- package/dist/permitted/getAllSnaps.js +0 -7
- package/dist/permitted/getAllSnaps.js.map +0 -1
- package/dist/permitted/getClientStatus.js +0 -7
- package/dist/permitted/getClientStatus.js.map +0 -1
- package/dist/permitted/getFile.js +0 -9
- package/dist/permitted/getFile.js.map +0 -1
- package/dist/permitted/getInterfaceState.js +0 -7
- package/dist/permitted/getInterfaceState.js.map +0 -1
- package/dist/permitted/getSnaps.js +0 -7
- package/dist/permitted/getSnaps.js.map +0 -1
- package/dist/permitted/handlers.js +0 -21
- package/dist/permitted/handlers.js.map +0 -1
- package/dist/permitted/index.js +0 -27
- package/dist/permitted/index.js.map +0 -1
- package/dist/permitted/invokeKeyring.js +0 -8
- package/dist/permitted/invokeKeyring.js.map +0 -1
- package/dist/permitted/invokeSnapSugar.js +0 -11
- package/dist/permitted/invokeSnapSugar.js.map +0 -1
- package/dist/permitted/middleware.js +0 -21
- package/dist/permitted/middleware.js.map +0 -1
- package/dist/permitted/requestSnaps.js +0 -12
- package/dist/permitted/requestSnaps.js.map +0 -1
- package/dist/permitted/resolveInterface.js +0 -7
- package/dist/permitted/resolveInterface.js.map +0 -1
- package/dist/permitted/updateInterface.js +0 -7
- package/dist/permitted/updateInterface.js.map +0 -1
- package/dist/restricted/caveats/index.js +0 -17
- package/dist/restricted/caveats/index.js.map +0 -1
- package/dist/restricted/caveats/permittedCoinTypes.js +0 -13
- package/dist/restricted/caveats/permittedCoinTypes.js.map +0 -1
- package/dist/restricted/caveats/permittedDerivationPaths.js +0 -13
- package/dist/restricted/caveats/permittedDerivationPaths.js.map +0 -1
- package/dist/restricted/caveats/snapIds.js +0 -11
- package/dist/restricted/caveats/snapIds.js.map +0 -1
- package/dist/restricted/dialog.js +0 -11
- package/dist/restricted/dialog.js.map +0 -1
- package/dist/restricted/getBip32Entropy.js +0 -10
- package/dist/restricted/getBip32Entropy.js.map +0 -1
- package/dist/restricted/getBip32PublicKey.js +0 -12
- package/dist/restricted/getBip32PublicKey.js.map +0 -1
- package/dist/restricted/getBip44Entropy.js +0 -9
- package/dist/restricted/getBip44Entropy.js.map +0 -1
- package/dist/restricted/getEntropy.js +0 -10
- package/dist/restricted/getEntropy.js.map +0 -1
- package/dist/restricted/getLocale.js +0 -11
- package/dist/restricted/getLocale.js.map +0 -1
- package/dist/restricted/getPreferences.js +0 -11
- package/dist/restricted/getPreferences.js.map +0 -1
- package/dist/restricted/index.js +0 -37
- package/dist/restricted/index.js.map +0 -1
- package/dist/restricted/invokeSnap.js +0 -13
- package/dist/restricted/invokeSnap.js.map +0 -1
- package/dist/restricted/manageAccounts.js +0 -13
- package/dist/restricted/manageAccounts.js.map +0 -1
- package/dist/restricted/manageState.js +0 -20
- package/dist/restricted/manageState.js.map +0 -1
- package/dist/restricted/notify.js +0 -13
- package/dist/restricted/notify.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/__fixtures__/index.d.ts +0 -1
- package/dist/types/endowments/caveats/index.d.ts +0 -2
- package/dist/types/index.d.ts +0 -7
- package/dist/types/permitted/index.d.ts +0 -11
- package/dist/types/restricted/dialog.d.ts +0 -1463
- package/dist/utils.js +0 -13
- package/dist/utils.js.map +0 -1
|
@@ -1,20 +1,168 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
2
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
+
import { ManageStateOperation } from "@metamask/snaps-sdk";
|
|
4
|
+
import { STATE_ENCRYPTION_MAGIC_VALUE } from "@metamask/snaps-utils";
|
|
5
|
+
import { isObject, getJsonSize } from "@metamask/utils";
|
|
6
|
+
import { deriveEntropy } from "../utils.mjs";
|
|
7
|
+
// The salt used for SIP-6-based entropy derivation.
|
|
8
|
+
export const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';
|
|
9
|
+
const methodName = 'snap_manageState';
|
|
10
|
+
/**
|
|
11
|
+
* The specification builder for the `snap_manageState` permission.
|
|
12
|
+
* `snap_manageState` lets the Snap store and manage some of its state on
|
|
13
|
+
* your device.
|
|
14
|
+
*
|
|
15
|
+
* @param options - The specification builder options.
|
|
16
|
+
* @param options.allowedCaveats - The optional allowed caveats for the permission.
|
|
17
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
18
|
+
* @returns The specification for the `snap_manageState` permission.
|
|
19
|
+
*/
|
|
20
|
+
export const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
|
|
21
|
+
return {
|
|
22
|
+
permissionType: PermissionType.RestrictedMethod,
|
|
23
|
+
targetName: methodName,
|
|
24
|
+
allowedCaveats,
|
|
25
|
+
methodImplementation: getManageStateImplementation(methodHooks),
|
|
26
|
+
subjectTypes: [SubjectType.Snap],
|
|
27
|
+
};
|
|
19
28
|
};
|
|
29
|
+
const methodHooks = {
|
|
30
|
+
getUnlockPromise: true,
|
|
31
|
+
clearSnapState: true,
|
|
32
|
+
getSnapState: true,
|
|
33
|
+
updateSnapState: true,
|
|
34
|
+
};
|
|
35
|
+
export const manageStateBuilder = Object.freeze({
|
|
36
|
+
targetName: methodName,
|
|
37
|
+
specificationBuilder,
|
|
38
|
+
methodHooks,
|
|
39
|
+
});
|
|
40
|
+
export const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB)
|
|
41
|
+
/**
|
|
42
|
+
* Get a deterministic encryption key to use for encrypting and decrypting the
|
|
43
|
+
* state.
|
|
44
|
+
*
|
|
45
|
+
* This key should only be used for state encryption using `snap_manageState`.
|
|
46
|
+
* To get other encryption keys, a different salt can be used.
|
|
47
|
+
*
|
|
48
|
+
* @param args - The encryption key args.
|
|
49
|
+
* @param args.snapId - The ID of the snap to get the encryption key for.
|
|
50
|
+
* @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key
|
|
51
|
+
* from.
|
|
52
|
+
* @returns The state encryption key.
|
|
53
|
+
*/
|
|
54
|
+
export async function getEncryptionEntropy({ mnemonicPhrase, snapId, }) {
|
|
55
|
+
return await deriveEntropy({
|
|
56
|
+
mnemonicPhrase,
|
|
57
|
+
input: snapId,
|
|
58
|
+
salt: STATE_ENCRYPTION_SALT,
|
|
59
|
+
magic: STATE_ENCRYPTION_MAGIC_VALUE,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Builds the method implementation for `snap_manageState`.
|
|
64
|
+
*
|
|
65
|
+
* @param hooks - The RPC method hooks.
|
|
66
|
+
* @param hooks.clearSnapState - A function that clears the state stored for a
|
|
67
|
+
* snap.
|
|
68
|
+
* @param hooks.getSnapState - A function that fetches the persisted decrypted
|
|
69
|
+
* state for a snap.
|
|
70
|
+
* @param hooks.updateSnapState - A function that updates the state stored for a
|
|
71
|
+
* snap.
|
|
72
|
+
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask
|
|
73
|
+
* extension is unlocked and prompts the user to unlock their MetaMask if it is
|
|
74
|
+
* locked.
|
|
75
|
+
* @returns The method implementation which either returns `null` for a
|
|
76
|
+
* successful state update/deletion or returns the decrypted state.
|
|
77
|
+
* @throws If the params are invalid.
|
|
78
|
+
*/
|
|
79
|
+
export function getManageStateImplementation({ getUnlockPromise, clearSnapState, getSnapState, updateSnapState, }) {
|
|
80
|
+
return async function manageState(options) {
|
|
81
|
+
const { params = {}, method, context: { origin }, } = options;
|
|
82
|
+
const validatedParams = getValidatedParams(params, method);
|
|
83
|
+
// If the encrypted param is undefined or null we default to true.
|
|
84
|
+
const shouldEncrypt = validatedParams.encrypted ?? true;
|
|
85
|
+
// We only need to prompt the user when the mnemonic is needed
|
|
86
|
+
// which it isn't for the clear operation or unencrypted storage.
|
|
87
|
+
if (shouldEncrypt &&
|
|
88
|
+
validatedParams.operation !== ManageStateOperation.ClearState) {
|
|
89
|
+
await getUnlockPromise(true);
|
|
90
|
+
}
|
|
91
|
+
switch (validatedParams.operation) {
|
|
92
|
+
case ManageStateOperation.ClearState:
|
|
93
|
+
clearSnapState(origin, shouldEncrypt);
|
|
94
|
+
return null;
|
|
95
|
+
case ManageStateOperation.GetState: {
|
|
96
|
+
return await getSnapState(origin, shouldEncrypt);
|
|
97
|
+
}
|
|
98
|
+
case ManageStateOperation.UpdateState: {
|
|
99
|
+
await updateSnapState(origin, validatedParams.newState, shouldEncrypt);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
default:
|
|
103
|
+
throw rpcErrors.invalidParams(`Invalid ${method} operation: "${validatedParams.operation}"`);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Validates the manageState method `params` and returns them cast to the correct
|
|
109
|
+
* type. Throws if validation fails.
|
|
110
|
+
*
|
|
111
|
+
* @param params - The unvalidated params object from the method request.
|
|
112
|
+
* @param method - RPC method name used for debugging errors.
|
|
113
|
+
* @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.
|
|
114
|
+
* @returns The validated method parameter object.
|
|
115
|
+
*/
|
|
116
|
+
export function getValidatedParams(params, method, storageSizeLimit = STORAGE_SIZE_LIMIT) {
|
|
117
|
+
if (!isObject(params)) {
|
|
118
|
+
throw rpcErrors.invalidParams({
|
|
119
|
+
message: 'Expected params to be a single object.',
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const { operation, newState, encrypted } = params;
|
|
123
|
+
if (!operation ||
|
|
124
|
+
typeof operation !== 'string' ||
|
|
125
|
+
!Object.values(ManageStateOperation).includes(operation)) {
|
|
126
|
+
throw rpcErrors.invalidParams({
|
|
127
|
+
message: 'Must specify a valid manage state "operation".',
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (encrypted !== undefined && typeof encrypted !== 'boolean') {
|
|
131
|
+
throw rpcErrors.invalidParams({
|
|
132
|
+
message: '"encrypted" parameter must be a boolean if specified.',
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
if (operation === ManageStateOperation.UpdateState) {
|
|
136
|
+
if (!isObject(newState)) {
|
|
137
|
+
throw rpcErrors.invalidParams({
|
|
138
|
+
message: `Invalid ${method} "updateState" parameter: The new state must be a plain object.`,
|
|
139
|
+
data: {
|
|
140
|
+
receivedNewState: typeof newState === 'undefined' ? 'undefined' : newState,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
let size;
|
|
145
|
+
try {
|
|
146
|
+
// `getJsonSize` will throw if the state is not JSON serializable.
|
|
147
|
+
size = getJsonSize(newState);
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
throw rpcErrors.invalidParams({
|
|
151
|
+
message: `Invalid ${method} "updateState" parameter: The new state must be JSON serializable.`,
|
|
152
|
+
data: {
|
|
153
|
+
receivedNewState: typeof newState === 'undefined' ? 'undefined' : newState,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
if (size > storageSizeLimit) {
|
|
158
|
+
throw rpcErrors.invalidParams({
|
|
159
|
+
message: `Invalid ${method} "updateState" parameter: The new state must not exceed ${storageSizeLimit} bytes in size.`,
|
|
160
|
+
data: {
|
|
161
|
+
receivedNewState: typeof newState === 'undefined' ? 'undefined' : newState,
|
|
162
|
+
},
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return params;
|
|
167
|
+
}
|
|
20
168
|
//# sourceMappingURL=manageState.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"manageState.mjs","sourceRoot":"","sources":["../../src/restricted/manageState.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,oBAAoB,EAAE,4BAA4B;AAC3D,OAAO,EAAE,4BAA4B,EAAE,8BAA8B;AAErE,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,wBAAwB;AAGxD,OAAO,EAAE,aAAa,EAAE,qBAAiB;AAEzC,oDAAoD;AACpD,MAAM,CAAC,MAAM,qBAAqB,GAAG,6BAA6B,CAAC;AAEnE,MAAM,UAAU,GAAG,kBAAkB,CAAC;AAiDtC;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAI7B,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GAC4B,EAAE,EAAE;IAC3C,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,4BAA4B,CAAC,WAAW,CAA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CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,uDAAuD;SACjE,CAAC,CAAC;IACL,CAAC;IAED,IAAI,SAAS,KAAK,oBAAoB,CAAC,WAAW,EAAE,CAAC;QACnD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,iEAAiE;gBAC3F,IAAI,EAAE;oBACJ,gBAAgB,EACd,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;iBAC3D;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,CAAC;QACT,IAAI,CAAC;YACH,kEAAkE;YAClE,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;QAC/B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,oEAAoE;gBAC9F,IAAI,EAAE;oBACJ,gBAAgB,EACd,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;iBAC3D;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,IAAI,GAAG,gBAAgB,EAAE,CAAC;YAC5B,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,WAAW,MAAM,2DAA2D,gBAAgB,iBAAiB;gBACtH,IAAI,EAAE;oBACJ,gBAAgB,EACd,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ;iBAC3D;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,OAAO,MAA2B,CAAC;AACrC,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';\nimport { ManageStateOperation } from '@metamask/snaps-sdk';\nimport { STATE_ENCRYPTION_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { isObject, getJsonSize } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\n// The salt used for SIP-6-based entropy derivation.\nexport const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';\n\nconst methodName = 'snap_manageState';\n\nexport type ManageStateMethodHooks = {\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A function that clears the state of the requesting Snap.\n */\n clearSnapState: (snapId: string, encrypted: boolean) => void;\n\n /**\n * A function that gets the encrypted state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json>>;\n\n /**\n * A function that updates the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n */\n updateSnapState: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\ntype ManageStateSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageStateMethodHooks;\n};\n\ntype ManageStateSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getManageStateImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageState` permission.\n * `snap_manageState` lets the Snap store and manage some of its state on\n * your device.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageState` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageStateSpecificationBuilderOptions,\n ManageStateSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageStateSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getManageStateImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<ManageStateMethodHooks> = {\n getUnlockPromise: true,\n clearSnapState: true,\n getSnapState: true,\n updateSnapState: true,\n};\n\nexport const manageStateBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB)\n\ntype GetEncryptionKeyArgs = {\n snapId: string;\n mnemonicPhrase: Uint8Array;\n};\n\n/**\n * Get a deterministic encryption key to use for encrypting and decrypting the\n * state.\n *\n * This key should only be used for state encryption using `snap_manageState`.\n * To get other encryption keys, a different salt can be used.\n *\n * @param args - The encryption key args.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @returns The state encryption key.\n */\nexport async function getEncryptionEntropy({\n mnemonicPhrase,\n snapId,\n}: GetEncryptionKeyArgs) {\n return await deriveEntropy({\n mnemonicPhrase,\n input: snapId,\n salt: STATE_ENCRYPTION_SALT,\n magic: STATE_ENCRYPTION_MAGIC_VALUE,\n });\n}\n\n/**\n * Builds the method implementation for `snap_manageState`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.clearSnapState - A function that clears the state stored for a\n * snap.\n * @param hooks.getSnapState - A function that fetches the persisted decrypted\n * state for a snap.\n * @param hooks.updateSnapState - A function that updates the state stored for a\n * snap.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function getManageStateImplementation({\n getUnlockPromise,\n clearSnapState,\n getSnapState,\n updateSnapState,\n}: ManageStateMethodHooks) {\n return async function manageState(\n options: RestrictedMethodOptions<ManageStateParams>,\n ): Promise<ManageStateResult> {\n const {\n params = {},\n method,\n context: { origin },\n } = options;\n const validatedParams = getValidatedParams(params, method);\n\n // If the encrypted param is undefined or null we default to true.\n const shouldEncrypt = validatedParams.encrypted ?? true;\n\n // We only need to prompt the user when the mnemonic is needed\n // which it isn't for the clear operation or unencrypted storage.\n if (\n shouldEncrypt &&\n validatedParams.operation !== ManageStateOperation.ClearState\n ) {\n await getUnlockPromise(true);\n }\n\n switch (validatedParams.operation) {\n case ManageStateOperation.ClearState:\n clearSnapState(origin, shouldEncrypt);\n return null;\n\n case ManageStateOperation.GetState: {\n return await getSnapState(origin, shouldEncrypt);\n }\n\n case ManageStateOperation.UpdateState: {\n await updateSnapState(origin, validatedParams.newState, shouldEncrypt);\n return null;\n }\n\n default:\n throw rpcErrors.invalidParams(\n `Invalid ${method} operation: \"${\n validatedParams.operation as string\n }\"`,\n );\n }\n };\n}\n\n/**\n * Validates the manageState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @param method - RPC method name used for debugging errors.\n * @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(\n params: unknown,\n method: string,\n storageSizeLimit = STORAGE_SIZE_LIMIT,\n): ManageStateParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { operation, newState, encrypted } = params;\n\n if (\n !operation ||\n typeof operation !== 'string' ||\n !Object.values(ManageStateOperation).includes(\n operation as ManageStateOperation,\n )\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid manage state \"operation\".',\n });\n }\n\n if (encrypted !== undefined && typeof encrypted !== 'boolean') {\n throw rpcErrors.invalidParams({\n message: '\"encrypted\" parameter must be a boolean if specified.',\n });\n }\n\n if (operation === ManageStateOperation.UpdateState) {\n if (!isObject(newState)) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be a plain object.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n let size;\n try {\n // `getJsonSize` will throw if the state is not JSON serializable.\n size = getJsonSize(newState);\n } catch {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be JSON serializable.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n if (size > storageSizeLimit) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must not exceed ${storageSizeLimit} bytes in size.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n }\n\n return params as ManageStateParams;\n}\n"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValidatedParams = exports.getImplementation = exports.notifyBuilder = exports.specificationBuilder = void 0;
|
|
4
|
+
const permission_controller_1 = require("@metamask/permission-controller");
|
|
5
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
6
|
+
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
7
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
9
|
+
const methodName = 'snap_notify';
|
|
10
|
+
/**
|
|
11
|
+
* The specification builder for the `snap_notify` permission.
|
|
12
|
+
* `snap_notify` allows snaps to send multiple types of notifications to its users.
|
|
13
|
+
*
|
|
14
|
+
* @param options - The specification builder options.
|
|
15
|
+
* @param options.allowedCaveats - The optional allowed caveats for the permission.
|
|
16
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
17
|
+
* @returns The specification for the `snap_notify` permission.
|
|
18
|
+
*/
|
|
19
|
+
const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => {
|
|
20
|
+
return {
|
|
21
|
+
permissionType: permission_controller_1.PermissionType.RestrictedMethod,
|
|
22
|
+
targetName: methodName,
|
|
23
|
+
allowedCaveats,
|
|
24
|
+
methodImplementation: getImplementation(methodHooks),
|
|
25
|
+
subjectTypes: [permission_controller_1.SubjectType.Snap],
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.specificationBuilder = specificationBuilder;
|
|
29
|
+
const methodHooks = {
|
|
30
|
+
showNativeNotification: true,
|
|
31
|
+
showInAppNotification: true,
|
|
32
|
+
isOnPhishingList: true,
|
|
33
|
+
maybeUpdatePhishingList: true,
|
|
34
|
+
};
|
|
35
|
+
exports.notifyBuilder = Object.freeze({
|
|
36
|
+
targetName: methodName,
|
|
37
|
+
specificationBuilder: exports.specificationBuilder,
|
|
38
|
+
methodHooks,
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Builds the method implementation for `snap_notify`.
|
|
42
|
+
*
|
|
43
|
+
* @param hooks - The RPC method hooks.
|
|
44
|
+
* @param hooks.showNativeNotification - A function that shows a native browser notification.
|
|
45
|
+
* @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
|
|
46
|
+
* @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
|
|
47
|
+
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
48
|
+
* @returns The method implementation which returns `null` on success.
|
|
49
|
+
* @throws If the params are invalid.
|
|
50
|
+
*/
|
|
51
|
+
function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }) {
|
|
52
|
+
return async function implementation(args) {
|
|
53
|
+
const { params, context: { origin }, } = args;
|
|
54
|
+
const validatedParams = getValidatedParams(params);
|
|
55
|
+
await maybeUpdatePhishingList();
|
|
56
|
+
(0, snaps_utils_1.validateTextLinks)(validatedParams.message, isOnPhishingList);
|
|
57
|
+
switch (validatedParams.type) {
|
|
58
|
+
case snaps_sdk_1.NotificationType.Native:
|
|
59
|
+
return await showNativeNotification(origin, validatedParams);
|
|
60
|
+
case snaps_sdk_1.NotificationType.InApp:
|
|
61
|
+
return await showInAppNotification(origin, validatedParams);
|
|
62
|
+
default:
|
|
63
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
64
|
+
message: 'Must specify a valid notification "type".',
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
exports.getImplementation = getImplementation;
|
|
70
|
+
/**
|
|
71
|
+
* Validates the notify method `params` and returns them cast to the correct
|
|
72
|
+
* type. Throws if validation fails.
|
|
73
|
+
*
|
|
74
|
+
* @param params - The unvalidated params object from the method request.
|
|
75
|
+
* @returns The validated method parameter object.
|
|
76
|
+
*/
|
|
77
|
+
function getValidatedParams(params) {
|
|
78
|
+
if (!(0, utils_1.isObject)(params)) {
|
|
79
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
80
|
+
message: 'Expected params to be a single object.',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const { type, message } = params;
|
|
84
|
+
if (!type ||
|
|
85
|
+
typeof type !== 'string' ||
|
|
86
|
+
!Object.values(snaps_sdk_1.NotificationType).includes(type)) {
|
|
87
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
88
|
+
message: 'Must specify a valid notification "type".',
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
const isNotString = !message || typeof message !== 'string';
|
|
92
|
+
// Set to the max message length on a Mac notification for now.
|
|
93
|
+
if (type === snaps_sdk_1.NotificationType.Native &&
|
|
94
|
+
(isNotString || message.length >= 50)) {
|
|
95
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
96
|
+
message: 'Must specify a non-empty string "message" less than 50 characters long.',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (type === snaps_sdk_1.NotificationType.InApp &&
|
|
100
|
+
(isNotString || message.length >= 500)) {
|
|
101
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
102
|
+
message: 'Must specify a non-empty string "message" less than 500 characters long.',
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return params;
|
|
106
|
+
}
|
|
107
|
+
exports.getValidatedParams = getValidatedParams;
|
|
108
|
+
//# sourceMappingURL=notify.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify.cjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":";;;AAKA,2EAA8E;AAC9E,qDAAiD;AACjD,mDAAuD;AAMvD,uDAA0D;AAE1D,2CAA2C;AAI3C,MAAM,UAAU,GAAG,aAAa,CAAC;AAkDjC;;;;;;;;GAQG;AACI,MAAM,oBAAoB,GAI7B,CAAC,EAAE,cAAc,GAAG,IAAI,EAAE,WAAW,EAA+B,EAAE,EAAE;IAC1E,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,iBAAiB,CAAC,WAAW,CAAC;QACpD,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,oBAAoB,wBAY/B;AAEF,MAAM,WAAW,GAAyC;IACxD,sBAAsB,EAAE,IAAI;IAC5B,qBAAqB,EAAE,IAAI;IAC3B,gBAAgB,EAAE,IAAI;IACtB,uBAAuB,EAAE,IAAI;CAC9B,CAAC;AAEW,QAAA,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC;IACzC,UAAU,EAAE,UAAU;IACtB,oBAAoB,EAApB,4BAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;;;;GAUG;AACH,SAAgB,iBAAiB,CAAC,EAChC,sBAAsB,EACtB,qBAAqB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AW,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC5D,+DAA+D;IAC/D,IACE,IAAI,KAAK,4BAAgB,CAAC,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,4BAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAA0B,CAAC;AACpC,CAAC;AA1CD,gDA0CC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport type {\n NotifyParams,\n NotifyResult,\n EnumToUnion,\n} from '@metamask/snaps-sdk';\nimport { validateTextLinks } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nexport type NotificationArgs = {\n /**\n * Enum type to determine notification type.\n */\n type: EnumToUnion<NotificationType>;\n\n /**\n * A message to show on the notification.\n */\n message: string;\n};\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedParams = getValidatedParams(params);\n\n await maybeUpdatePhishingList();\n\n validateTextLinks(validatedParams.message, isOnPhishingList);\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n return params as NotificationArgs;\n}\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from
|
|
2
|
-
import { PermissionType } from
|
|
3
|
-
import { NotificationType } from
|
|
4
|
-
import type { NotifyParams, NotifyResult, EnumToUnion } from
|
|
5
|
-
import type { NonEmptyArray } from
|
|
6
|
-
import { type MethodHooksObject } from
|
|
1
|
+
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from "@metamask/permission-controller";
|
|
2
|
+
import { PermissionType } from "@metamask/permission-controller";
|
|
3
|
+
import { NotificationType } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { NotifyParams, NotifyResult, EnumToUnion } from "@metamask/snaps-sdk";
|
|
5
|
+
import type { NonEmptyArray } from "@metamask/utils";
|
|
6
|
+
import { type MethodHooksObject } from "../utils.cjs";
|
|
7
7
|
declare const methodName = "snap_notify";
|
|
8
8
|
export type NotificationArgs = {
|
|
9
9
|
/**
|
|
@@ -80,3 +80,4 @@ export declare function getImplementation({ showNativeNotification, showInAppNot
|
|
|
80
80
|
*/
|
|
81
81
|
export declare function getValidatedParams(params: unknown): NotifyParams;
|
|
82
82
|
export {};
|
|
83
|
+
//# sourceMappingURL=notify.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify.d.cts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,4BAA4B;AACvD,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACZ,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAEjC,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAEpC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH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AC1C,QAAQ,YAAY,CAAC,CAuBzB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CA0ChE"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder, RestrictedMethodOptions, ValidPermissionSpecification } from "@metamask/permission-controller";
|
|
2
|
+
import { PermissionType } from "@metamask/permission-controller";
|
|
3
|
+
import { NotificationType } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { NotifyParams, NotifyResult, EnumToUnion } from "@metamask/snaps-sdk";
|
|
5
|
+
import type { NonEmptyArray } from "@metamask/utils";
|
|
6
|
+
import { type MethodHooksObject } from "../utils.mjs";
|
|
7
|
+
declare const methodName = "snap_notify";
|
|
8
|
+
export type NotificationArgs = {
|
|
9
|
+
/**
|
|
10
|
+
* Enum type to determine notification type.
|
|
11
|
+
*/
|
|
12
|
+
type: EnumToUnion<NotificationType>;
|
|
13
|
+
/**
|
|
14
|
+
* A message to show on the notification.
|
|
15
|
+
*/
|
|
16
|
+
message: string;
|
|
17
|
+
};
|
|
18
|
+
export type NotifyMethodHooks = {
|
|
19
|
+
/**
|
|
20
|
+
* @param snapId - The ID of the Snap that created the notification.
|
|
21
|
+
* @param args - The notification arguments.
|
|
22
|
+
*/
|
|
23
|
+
showNativeNotification: (snapId: string, args: NotificationArgs) => Promise<null>;
|
|
24
|
+
/**
|
|
25
|
+
* @param snapId - The ID of the Snap that created the notification.
|
|
26
|
+
* @param args - The notification arguments.
|
|
27
|
+
*/
|
|
28
|
+
showInAppNotification: (snapId: string, args: NotificationArgs) => Promise<null>;
|
|
29
|
+
isOnPhishingList: (url: string) => boolean;
|
|
30
|
+
maybeUpdatePhishingList: () => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
type SpecificationBuilderOptions = {
|
|
33
|
+
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
|
|
34
|
+
methodHooks: NotifyMethodHooks;
|
|
35
|
+
};
|
|
36
|
+
type Specification = ValidPermissionSpecification<{
|
|
37
|
+
permissionType: PermissionType.RestrictedMethod;
|
|
38
|
+
targetName: typeof methodName;
|
|
39
|
+
methodImplementation: ReturnType<typeof getImplementation>;
|
|
40
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* The specification builder for the `snap_notify` permission.
|
|
44
|
+
* `snap_notify` allows snaps to send multiple types of notifications to its users.
|
|
45
|
+
*
|
|
46
|
+
* @param options - The specification builder options.
|
|
47
|
+
* @param options.allowedCaveats - The optional allowed caveats for the permission.
|
|
48
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
49
|
+
* @returns The specification for the `snap_notify` permission.
|
|
50
|
+
*/
|
|
51
|
+
export declare const specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, SpecificationBuilderOptions, Specification>;
|
|
52
|
+
export declare const notifyBuilder: Readonly<{
|
|
53
|
+
readonly targetName: "snap_notify";
|
|
54
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, SpecificationBuilderOptions, {
|
|
55
|
+
permissionType: PermissionType.RestrictedMethod;
|
|
56
|
+
targetName: typeof methodName;
|
|
57
|
+
methodImplementation: ReturnType<typeof getImplementation>;
|
|
58
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
59
|
+
}>;
|
|
60
|
+
readonly methodHooks: MethodHooksObject<NotifyMethodHooks>;
|
|
61
|
+
}>;
|
|
62
|
+
/**
|
|
63
|
+
* Builds the method implementation for `snap_notify`.
|
|
64
|
+
*
|
|
65
|
+
* @param hooks - The RPC method hooks.
|
|
66
|
+
* @param hooks.showNativeNotification - A function that shows a native browser notification.
|
|
67
|
+
* @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
|
|
68
|
+
* @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
|
|
69
|
+
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
70
|
+
* @returns The method implementation which returns `null` on success.
|
|
71
|
+
* @throws If the params are invalid.
|
|
72
|
+
*/
|
|
73
|
+
export declare function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }: NotifyMethodHooks): (args: RestrictedMethodOptions<NotifyParams>) => Promise<NotifyResult>;
|
|
74
|
+
/**
|
|
75
|
+
* Validates the notify method `params` and returns them cast to the correct
|
|
76
|
+
* type. Throws if validation fails.
|
|
77
|
+
*
|
|
78
|
+
* @param params - The unvalidated params object from the method request.
|
|
79
|
+
* @returns The validated method parameter object.
|
|
80
|
+
*/
|
|
81
|
+
export declare function getValidatedParams(params: unknown): NotifyParams;
|
|
82
|
+
export {};
|
|
83
|
+
//# sourceMappingURL=notify.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notify.d.mts","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EACvB,4BAA4B,EAC7B,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EAAE,gBAAgB,EAAE,4BAA4B;AACvD,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACZ,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAEjC,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAEpC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B;;;OAGG;IACH,sBAAsB,EAAE,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,gBAAgB,KACn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kB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,CA0ChE"}
|
|
@@ -1,13 +1,102 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
2
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
+
import { NotificationType } from "@metamask/snaps-sdk";
|
|
4
|
+
import { validateTextLinks } from "@metamask/snaps-utils";
|
|
5
|
+
import { isObject } from "@metamask/utils";
|
|
6
|
+
const methodName = 'snap_notify';
|
|
7
|
+
/**
|
|
8
|
+
* The specification builder for the `snap_notify` permission.
|
|
9
|
+
* `snap_notify` allows snaps to send multiple types of notifications to its users.
|
|
10
|
+
*
|
|
11
|
+
* @param options - The specification builder options.
|
|
12
|
+
* @param options.allowedCaveats - The optional allowed caveats for the permission.
|
|
13
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
14
|
+
* @returns The specification for the `snap_notify` permission.
|
|
15
|
+
*/
|
|
16
|
+
export const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => {
|
|
17
|
+
return {
|
|
18
|
+
permissionType: PermissionType.RestrictedMethod,
|
|
19
|
+
targetName: methodName,
|
|
20
|
+
allowedCaveats,
|
|
21
|
+
methodImplementation: getImplementation(methodHooks),
|
|
22
|
+
subjectTypes: [SubjectType.Snap],
|
|
23
|
+
};
|
|
12
24
|
};
|
|
25
|
+
const methodHooks = {
|
|
26
|
+
showNativeNotification: true,
|
|
27
|
+
showInAppNotification: true,
|
|
28
|
+
isOnPhishingList: true,
|
|
29
|
+
maybeUpdatePhishingList: true,
|
|
30
|
+
};
|
|
31
|
+
export const notifyBuilder = Object.freeze({
|
|
32
|
+
targetName: methodName,
|
|
33
|
+
specificationBuilder,
|
|
34
|
+
methodHooks,
|
|
35
|
+
});
|
|
36
|
+
/**
|
|
37
|
+
* Builds the method implementation for `snap_notify`.
|
|
38
|
+
*
|
|
39
|
+
* @param hooks - The RPC method hooks.
|
|
40
|
+
* @param hooks.showNativeNotification - A function that shows a native browser notification.
|
|
41
|
+
* @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.
|
|
42
|
+
* @param hooks.isOnPhishingList - A function that checks for links against the phishing list.
|
|
43
|
+
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
44
|
+
* @returns The method implementation which returns `null` on success.
|
|
45
|
+
* @throws If the params are invalid.
|
|
46
|
+
*/
|
|
47
|
+
export function getImplementation({ showNativeNotification, showInAppNotification, isOnPhishingList, maybeUpdatePhishingList, }) {
|
|
48
|
+
return async function implementation(args) {
|
|
49
|
+
const { params, context: { origin }, } = args;
|
|
50
|
+
const validatedParams = getValidatedParams(params);
|
|
51
|
+
await maybeUpdatePhishingList();
|
|
52
|
+
validateTextLinks(validatedParams.message, isOnPhishingList);
|
|
53
|
+
switch (validatedParams.type) {
|
|
54
|
+
case NotificationType.Native:
|
|
55
|
+
return await showNativeNotification(origin, validatedParams);
|
|
56
|
+
case NotificationType.InApp:
|
|
57
|
+
return await showInAppNotification(origin, validatedParams);
|
|
58
|
+
default:
|
|
59
|
+
throw rpcErrors.invalidParams({
|
|
60
|
+
message: 'Must specify a valid notification "type".',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Validates the notify method `params` and returns them cast to the correct
|
|
67
|
+
* type. Throws if validation fails.
|
|
68
|
+
*
|
|
69
|
+
* @param params - The unvalidated params object from the method request.
|
|
70
|
+
* @returns The validated method parameter object.
|
|
71
|
+
*/
|
|
72
|
+
export function getValidatedParams(params) {
|
|
73
|
+
if (!isObject(params)) {
|
|
74
|
+
throw rpcErrors.invalidParams({
|
|
75
|
+
message: 'Expected params to be a single object.',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const { type, message } = params;
|
|
79
|
+
if (!type ||
|
|
80
|
+
typeof type !== 'string' ||
|
|
81
|
+
!Object.values(NotificationType).includes(type)) {
|
|
82
|
+
throw rpcErrors.invalidParams({
|
|
83
|
+
message: 'Must specify a valid notification "type".',
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
const isNotString = !message || typeof message !== 'string';
|
|
87
|
+
// Set to the max message length on a Mac notification for now.
|
|
88
|
+
if (type === NotificationType.Native &&
|
|
89
|
+
(isNotString || message.length >= 50)) {
|
|
90
|
+
throw rpcErrors.invalidParams({
|
|
91
|
+
message: 'Must specify a non-empty string "message" less than 50 characters long.',
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (type === NotificationType.InApp &&
|
|
95
|
+
(isNotString || message.length >= 500)) {
|
|
96
|
+
throw rpcErrors.invalidParams({
|
|
97
|
+
message: 'Must specify a non-empty string "message" less than 500 characters long.',
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return params;
|
|
101
|
+
}
|
|
13
102
|
//# sourceMappingURL=notify.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EAAE,gBAAgB,EAAE,4BAA4B;AAMvD,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAE1D,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAI3C,MAAM,UAAU,GAAG,aAAa,CAAC;AAkDjC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAI7B,CAAC,EAAE,cAAc,GAAG,IAAI,EAAE,WAAW,EAA+B,EAAE,EAAE;IAC1E,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB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AAM,UAAU,kBAAkB,CAAC,MAAe;IAChD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,wCAAwC;SAClD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAEjC,IACE,CAAC,IAAI;QACL,OAAO,IAAI,KAAK,QAAQ;QACxB,CAAC,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,IAAwB,CAAC,EACnE,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,2CAA2C;SACrD,CAAC,CAAC;IACL,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC5D,+DAA+D;IAC/D,IACE,IAAI,KAAK,gBAAgB,CAAC,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,gBAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAA0B,CAAC;AACpC,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport type {\n NotifyParams,\n NotifyResult,\n EnumToUnion,\n} from '@metamask/snaps-sdk';\nimport { validateTextLinks } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nexport type NotificationArgs = {\n /**\n * Enum type to determine notification type.\n */\n type: EnumToUnion<NotificationType>;\n\n /**\n * A message to show on the notification.\n */\n message: string;\n};\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedParams = getValidatedParams(params);\n\n await maybeUpdatePhishingList();\n\n validateTextLinks(validatedParams.message, isOnPhishingList);\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n return params as NotificationArgs;\n}\n"]}
|