@metamask/snaps-rpc-methods 11.0.0 → 11.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -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} +34 -33
- 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} +62 -49
- package/dist/permitted/createInterface.d.cts.map +1 -0
- package/dist/permitted/createInterface.d.mts +193 -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/permitted/handlers.d.cts +35 -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 +488 -0
- package/dist/restricted/dialog.d.cts.map +1 -0
- package/dist/restricted/dialog.d.mts +488 -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} +29 -28
- 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/handlers.d.ts +0 -34
- 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,11 +1,218 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
2
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
+
import { DialogType, enumValue, ComponentOrElementStruct, selectiveUnion } from "@metamask/snaps-sdk";
|
|
4
|
+
import { create, object, optional, size, string } from "@metamask/superstruct";
|
|
5
|
+
import { hasProperty, isObject, isPlainObject } from "@metamask/utils";
|
|
6
|
+
const methodName = 'snap_dialog';
|
|
7
|
+
export const DIALOG_APPROVAL_TYPES = {
|
|
8
|
+
[DialogType.Alert]: `${methodName}:alert`,
|
|
9
|
+
[DialogType.Confirmation]: `${methodName}:confirmation`,
|
|
10
|
+
[DialogType.Prompt]: `${methodName}:prompt`,
|
|
11
|
+
default: methodName,
|
|
10
12
|
};
|
|
13
|
+
const PlaceholderStruct = optional(size(string(), 1, 40));
|
|
14
|
+
/**
|
|
15
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
16
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
17
|
+
* - An alert, for displaying information.
|
|
18
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
19
|
+
* - A prompt, for inputting some information.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The specification builder options.
|
|
22
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
23
|
+
* permission.
|
|
24
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
25
|
+
* implementation.
|
|
26
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
27
|
+
*/
|
|
28
|
+
const specificationBuilder = ({ allowedCaveats = null, methodHooks, }) => {
|
|
29
|
+
return {
|
|
30
|
+
permissionType: PermissionType.RestrictedMethod,
|
|
31
|
+
targetName: methodName,
|
|
32
|
+
allowedCaveats,
|
|
33
|
+
methodImplementation: getDialogImplementation(methodHooks),
|
|
34
|
+
subjectTypes: [SubjectType.Snap],
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const methodHooks = {
|
|
38
|
+
requestUserApproval: true,
|
|
39
|
+
createInterface: true,
|
|
40
|
+
getInterface: true,
|
|
41
|
+
};
|
|
42
|
+
export const dialogBuilder = Object.freeze({
|
|
43
|
+
targetName: methodName,
|
|
44
|
+
specificationBuilder,
|
|
45
|
+
methodHooks,
|
|
46
|
+
});
|
|
47
|
+
const AlertParametersWithContentStruct = object({
|
|
48
|
+
type: enumValue(DialogType.Alert),
|
|
49
|
+
content: ComponentOrElementStruct,
|
|
50
|
+
});
|
|
51
|
+
const AlertParametersWithIdStruct = object({
|
|
52
|
+
type: enumValue(DialogType.Alert),
|
|
53
|
+
id: string(),
|
|
54
|
+
});
|
|
55
|
+
const AlertParametersStruct = selectiveUnion((value) => {
|
|
56
|
+
if (isPlainObject(value) && hasProperty(value, 'id')) {
|
|
57
|
+
return AlertParametersWithIdStruct;
|
|
58
|
+
}
|
|
59
|
+
return AlertParametersWithContentStruct;
|
|
60
|
+
});
|
|
61
|
+
const ConfirmationParametersWithContentStruct = object({
|
|
62
|
+
type: enumValue(DialogType.Confirmation),
|
|
63
|
+
content: ComponentOrElementStruct,
|
|
64
|
+
});
|
|
65
|
+
const ConfirmationParametersWithIdStruct = object({
|
|
66
|
+
type: enumValue(DialogType.Confirmation),
|
|
67
|
+
id: string(),
|
|
68
|
+
});
|
|
69
|
+
const ConfirmationParametersStruct = selectiveUnion((value) => {
|
|
70
|
+
if (isPlainObject(value) && hasProperty(value, 'id')) {
|
|
71
|
+
return ConfirmationParametersWithIdStruct;
|
|
72
|
+
}
|
|
73
|
+
return ConfirmationParametersWithContentStruct;
|
|
74
|
+
});
|
|
75
|
+
const PromptParametersWithContentStruct = object({
|
|
76
|
+
type: enumValue(DialogType.Prompt),
|
|
77
|
+
content: ComponentOrElementStruct,
|
|
78
|
+
placeholder: PlaceholderStruct,
|
|
79
|
+
});
|
|
80
|
+
const PromptParametersWithIdStruct = object({
|
|
81
|
+
type: enumValue(DialogType.Prompt),
|
|
82
|
+
id: string(),
|
|
83
|
+
placeholder: PlaceholderStruct,
|
|
84
|
+
});
|
|
85
|
+
const PromptParametersStruct = selectiveUnion((value) => {
|
|
86
|
+
if (isPlainObject(value) && hasProperty(value, 'id')) {
|
|
87
|
+
return PromptParametersWithIdStruct;
|
|
88
|
+
}
|
|
89
|
+
return PromptParametersWithContentStruct;
|
|
90
|
+
});
|
|
91
|
+
const DefaultParametersWithContentStruct = object({
|
|
92
|
+
content: ComponentOrElementStruct,
|
|
93
|
+
});
|
|
94
|
+
const DefaultParametersWithIdStruct = object({
|
|
95
|
+
id: string(),
|
|
96
|
+
});
|
|
97
|
+
const DefaultParametersStruct = selectiveUnion((value) => {
|
|
98
|
+
if (isPlainObject(value) && hasProperty(value, 'id')) {
|
|
99
|
+
return DefaultParametersWithIdStruct;
|
|
100
|
+
}
|
|
101
|
+
return DefaultParametersWithContentStruct;
|
|
102
|
+
});
|
|
103
|
+
const DialogParametersStruct = selectiveUnion((value) => {
|
|
104
|
+
if (isPlainObject(value) && hasProperty(value, 'type')) {
|
|
105
|
+
switch (value.type) {
|
|
106
|
+
// We cannot use typedUnion here unfortunately.
|
|
107
|
+
case DialogType.Alert:
|
|
108
|
+
return AlertParametersStruct;
|
|
109
|
+
case DialogType.Confirmation:
|
|
110
|
+
return ConfirmationParametersStruct;
|
|
111
|
+
case DialogType.Prompt:
|
|
112
|
+
return PromptParametersStruct;
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`The "type" property must be one of: ${Object.values(DialogType).join(', ')}.`);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return DefaultParametersStruct;
|
|
118
|
+
});
|
|
119
|
+
/**
|
|
120
|
+
* Builds the method implementation for `snap_dialog`.
|
|
121
|
+
*
|
|
122
|
+
* @param hooks - The RPC method hooks.
|
|
123
|
+
* @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.
|
|
124
|
+
* This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.
|
|
125
|
+
* @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
|
|
126
|
+
* @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.
|
|
127
|
+
* @returns The method implementation which return value depends on the dialog
|
|
128
|
+
* type, valid return types are: string, boolean, null.
|
|
129
|
+
*/
|
|
130
|
+
export function getDialogImplementation({ requestUserApproval, createInterface, getInterface, }) {
|
|
131
|
+
return async function dialogImplementation(args) {
|
|
132
|
+
const { params, context: { origin }, } = args;
|
|
133
|
+
if (!isObject(params)) {
|
|
134
|
+
throw rpcErrors.invalidParams({
|
|
135
|
+
message: 'Invalid params: Expected params to be a single object.',
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
const validatedParams = getValidatedParams(params);
|
|
139
|
+
const placeholder = isPromptDialog(validatedParams)
|
|
140
|
+
? validatedParams.placeholder
|
|
141
|
+
: undefined;
|
|
142
|
+
const validatedType = hasProperty(validatedParams, 'type')
|
|
143
|
+
? validatedParams.type
|
|
144
|
+
: 'default';
|
|
145
|
+
const approvalType = DIALOG_APPROVAL_TYPES[validatedType];
|
|
146
|
+
if (hasProperty(validatedParams, 'content')) {
|
|
147
|
+
const id = await createInterface(origin, validatedParams.content);
|
|
148
|
+
return requestUserApproval({
|
|
149
|
+
id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,
|
|
150
|
+
origin,
|
|
151
|
+
type: approvalType,
|
|
152
|
+
requestData: { id, placeholder },
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
validateInterface(origin, validatedParams.id, getInterface);
|
|
156
|
+
return requestUserApproval({
|
|
157
|
+
id: approvalType === DIALOG_APPROVAL_TYPES.default
|
|
158
|
+
? validatedParams.id
|
|
159
|
+
: undefined,
|
|
160
|
+
origin,
|
|
161
|
+
type: approvalType,
|
|
162
|
+
requestData: { id: validatedParams.id, placeholder },
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Validate that the interface ID is valid.
|
|
168
|
+
*
|
|
169
|
+
* @param origin - The origin of the request.
|
|
170
|
+
* @param id - The interface ID.
|
|
171
|
+
* @param getInterface - The function to get the interface.
|
|
172
|
+
*/
|
|
173
|
+
function validateInterface(origin, id, getInterface) {
|
|
174
|
+
try {
|
|
175
|
+
getInterface(origin, id);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
throw rpcErrors.invalidParams({
|
|
179
|
+
message: `Invalid params: ${error.message}`,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Gets the dialog type from the dialog parameters.
|
|
185
|
+
*
|
|
186
|
+
* @param params - The dialog parameters.
|
|
187
|
+
* @returns The dialog type.
|
|
188
|
+
*/
|
|
189
|
+
function getDialogType(params) {
|
|
190
|
+
return hasProperty(params, 'type') ? params.type : undefined;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Checks if the dialog parameters are for a prompt dialog.
|
|
194
|
+
*
|
|
195
|
+
* @param params - The dialog parameters.
|
|
196
|
+
* @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.
|
|
197
|
+
*/
|
|
198
|
+
function isPromptDialog(params) {
|
|
199
|
+
return getDialogType(params) === DialogType.Prompt;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Validates the confirm method `params` and returns them cast to the correct
|
|
203
|
+
* type. Throws if validation fails.
|
|
204
|
+
*
|
|
205
|
+
* @param params - The unvalidated params object from the method request.
|
|
206
|
+
* @returns The validated confirm method parameter object.
|
|
207
|
+
*/
|
|
208
|
+
function getValidatedParams(params) {
|
|
209
|
+
try {
|
|
210
|
+
return create(params, DialogParametersStruct);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
throw rpcErrors.invalidParams({
|
|
214
|
+
message: `Invalid params: ${error.message}`,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
11
218
|
//# sourceMappingURL=dialog.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"file":"dialog.mjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,cAAc,EACf,4BAA4B;AAW7B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,8BAA8B;AAE/E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAwB;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMjC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,eAAe;IACvD,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,SAAS;IAC3C,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAgE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GA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a,CAAC,MAAwB;IAC7C,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,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 {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm 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 confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBip32EntropyImplementation = exports.getBip32EntropyBuilder = void 0;
|
|
4
|
+
const permission_controller_1 = require("@metamask/permission-controller");
|
|
5
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
6
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
|
+
const utils_1 = require("@metamask/utils");
|
|
8
|
+
const utils_2 = require("../utils.cjs");
|
|
9
|
+
const targetName = 'snap_getBip32Entropy';
|
|
10
|
+
/**
|
|
11
|
+
* The specification builder for the `snap_getBip32Entropy` permission.
|
|
12
|
+
* `snap_getBip32Entropy` lets the Snap control private keys for a particular
|
|
13
|
+
* BIP-32 node.
|
|
14
|
+
*
|
|
15
|
+
* @param options - The specification builder options.
|
|
16
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
17
|
+
* @returns The specification for the `snap_getBip32Entropy` permission.
|
|
18
|
+
*/
|
|
19
|
+
const specificationBuilder = ({ methodHooks }) => {
|
|
20
|
+
return {
|
|
21
|
+
permissionType: permission_controller_1.PermissionType.RestrictedMethod,
|
|
22
|
+
targetName,
|
|
23
|
+
allowedCaveats: [snaps_utils_1.SnapCaveatType.PermittedDerivationPaths],
|
|
24
|
+
methodImplementation: getBip32EntropyImplementation(methodHooks),
|
|
25
|
+
validator: ({ caveats }) => {
|
|
26
|
+
if (caveats?.length !== 1 ||
|
|
27
|
+
caveats[0].type !== snaps_utils_1.SnapCaveatType.PermittedDerivationPaths) {
|
|
28
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
29
|
+
message: `Expected a single "${snaps_utils_1.SnapCaveatType.PermittedDerivationPaths}" caveat.`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
subjectTypes: [permission_controller_1.SubjectType.Snap],
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const methodHooks = {
|
|
37
|
+
getMnemonic: true,
|
|
38
|
+
getUnlockPromise: true,
|
|
39
|
+
};
|
|
40
|
+
exports.getBip32EntropyBuilder = Object.freeze({
|
|
41
|
+
targetName,
|
|
42
|
+
specificationBuilder,
|
|
43
|
+
methodHooks,
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* Builds the method implementation for `snap_getBip32Entropy`.
|
|
47
|
+
*
|
|
48
|
+
* @param hooks - The RPC method hooks.
|
|
49
|
+
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
50
|
+
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
51
|
+
* and prompts the user to unlock their MetaMask if it is locked.
|
|
52
|
+
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
53
|
+
* @throws If the params are invalid.
|
|
54
|
+
*/
|
|
55
|
+
function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
56
|
+
return async function getBip32Entropy(args) {
|
|
57
|
+
await getUnlockPromise(true);
|
|
58
|
+
const { params } = args;
|
|
59
|
+
(0, utils_1.assert)(params);
|
|
60
|
+
const node = await (0, utils_2.getNode)({
|
|
61
|
+
curve: params.curve,
|
|
62
|
+
path: params.path,
|
|
63
|
+
secretRecoveryPhrase: await getMnemonic(),
|
|
64
|
+
});
|
|
65
|
+
return node.toJSON();
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.getBip32EntropyImplementation = getBip32EntropyImplementation;
|
|
69
|
+
//# sourceMappingURL=getBip32Entropy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAAuD;AAEvD,2CAAyC;AAGzC,wCAAmC;AAEnC,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA4B1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE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AC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC;AApBD,sEAoBC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\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\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from
|
|
2
|
-
import { PermissionType } from
|
|
3
|
-
import type { GetBip32EntropyParams, GetBip32EntropyResult } from
|
|
4
|
-
import type { NonEmptyArray } from
|
|
5
|
-
import type { MethodHooksObject } from
|
|
1
|
+
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
|
+
import { PermissionType } from "@metamask/permission-controller";
|
|
3
|
+
import type { GetBip32EntropyParams, GetBip32EntropyResult } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { NonEmptyArray } from "@metamask/utils";
|
|
5
|
+
import type { MethodHooksObject } from "../utils.cjs";
|
|
6
6
|
declare const targetName = "snap_getBip32Entropy";
|
|
7
7
|
export type GetBip32EntropyMethodHooks = {
|
|
8
8
|
/**
|
|
@@ -42,3 +42,4 @@ export declare const getBip32EntropyBuilder: Readonly<{
|
|
|
42
42
|
*/
|
|
43
43
|
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
44
44
|
export {};
|
|
45
|
+
//# sourceMappingURL=getBip32Entropy.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAgDF,eAAO,MAAM,sBAAsB;;;wBA7CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA6C/B,CAAC;AAEZ;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,GACjB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAclC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
|
+
import { PermissionType } from "@metamask/permission-controller";
|
|
3
|
+
import type { GetBip32EntropyParams, GetBip32EntropyResult } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { NonEmptyArray } from "@metamask/utils";
|
|
5
|
+
import type { MethodHooksObject } from "../utils.mjs";
|
|
6
|
+
declare const targetName = "snap_getBip32Entropy";
|
|
7
|
+
export type GetBip32EntropyMethodHooks = {
|
|
8
|
+
/**
|
|
9
|
+
* @returns The mnemonic of the user's primary keyring.
|
|
10
|
+
*/
|
|
11
|
+
getMnemonic: () => Promise<Uint8Array>;
|
|
12
|
+
/**
|
|
13
|
+
* Waits for the extension to be unlocked.
|
|
14
|
+
*
|
|
15
|
+
* @returns A promise that resolves once the extension is unlocked.
|
|
16
|
+
*/
|
|
17
|
+
getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
type GetBip32EntropySpecificationBuilderOptions = {
|
|
20
|
+
methodHooks: GetBip32EntropyMethodHooks;
|
|
21
|
+
};
|
|
22
|
+
export declare const getBip32EntropyBuilder: Readonly<{
|
|
23
|
+
readonly targetName: "snap_getBip32Entropy";
|
|
24
|
+
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, GetBip32EntropySpecificationBuilderOptions, {
|
|
25
|
+
permissionType: PermissionType.RestrictedMethod;
|
|
26
|
+
targetName: typeof targetName;
|
|
27
|
+
methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;
|
|
28
|
+
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
|
|
29
|
+
validator: PermissionValidatorConstraint;
|
|
30
|
+
}>;
|
|
31
|
+
readonly methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks>;
|
|
32
|
+
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Builds the method implementation for `snap_getBip32Entropy`.
|
|
35
|
+
*
|
|
36
|
+
* @param hooks - The RPC method hooks.
|
|
37
|
+
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
38
|
+
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
39
|
+
* and prompts the user to unlock their MetaMask if it is locked.
|
|
40
|
+
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
41
|
+
* @throws If the params are invalid.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32EntropyMethodHooks): (args: RestrictedMethodOptions<GetBip32EntropyParams>) => Promise<GetBip32EntropyResult>;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=getBip32Entropy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.d.mts","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,yBAAyB,CAAC;AAE1C,MAAM,MAAM,0BAA0B,GAAG;IACvC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,KAAK,0CAA0C,GAAG;IAChD,WAAW,EAAE,0BAA0B,CAAC;CACzC,CAAC;AAgDF,eAAO,MAAM,sBAAsB;;;wBA7CjB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,oCAAoC,CAAC;wBACtD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EA6C/B,CAAC;AAEZ;;;;;;;;;GASG;AACH,wBAAgB,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,GACjB,EAAE,0BAA0B,UAEnB,wBAAwB,qBAAqB,CAAC,KACnD,QAAQ,qBAAqB,CAAC,CAclC"}
|
|
@@ -1,10 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "
|
|
5
|
-
import "../
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
2
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
+
import { SnapCaveatType } from "@metamask/snaps-utils";
|
|
4
|
+
import { assert } from "@metamask/utils";
|
|
5
|
+
import { getNode } from "../utils.mjs";
|
|
6
|
+
const targetName = 'snap_getBip32Entropy';
|
|
7
|
+
/**
|
|
8
|
+
* The specification builder for the `snap_getBip32Entropy` permission.
|
|
9
|
+
* `snap_getBip32Entropy` lets the Snap control private keys for a particular
|
|
10
|
+
* BIP-32 node.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The specification builder options.
|
|
13
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
14
|
+
* @returns The specification for the `snap_getBip32Entropy` permission.
|
|
15
|
+
*/
|
|
16
|
+
const specificationBuilder = ({ methodHooks }) => {
|
|
17
|
+
return {
|
|
18
|
+
permissionType: PermissionType.RestrictedMethod,
|
|
19
|
+
targetName,
|
|
20
|
+
allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],
|
|
21
|
+
methodImplementation: getBip32EntropyImplementation(methodHooks),
|
|
22
|
+
validator: ({ caveats }) => {
|
|
23
|
+
if (caveats?.length !== 1 ||
|
|
24
|
+
caveats[0].type !== SnapCaveatType.PermittedDerivationPaths) {
|
|
25
|
+
throw rpcErrors.invalidParams({
|
|
26
|
+
message: `Expected a single "${SnapCaveatType.PermittedDerivationPaths}" caveat.`,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
subjectTypes: [SubjectType.Snap],
|
|
31
|
+
};
|
|
9
32
|
};
|
|
33
|
+
const methodHooks = {
|
|
34
|
+
getMnemonic: true,
|
|
35
|
+
getUnlockPromise: true,
|
|
36
|
+
};
|
|
37
|
+
export const getBip32EntropyBuilder = Object.freeze({
|
|
38
|
+
targetName,
|
|
39
|
+
specificationBuilder,
|
|
40
|
+
methodHooks,
|
|
41
|
+
});
|
|
42
|
+
/**
|
|
43
|
+
* Builds the method implementation for `snap_getBip32Entropy`.
|
|
44
|
+
*
|
|
45
|
+
* @param hooks - The RPC method hooks.
|
|
46
|
+
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
47
|
+
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
48
|
+
* and prompts the user to unlock their MetaMask if it is locked.
|
|
49
|
+
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
50
|
+
* @throws If the params are invalid.
|
|
51
|
+
*/
|
|
52
|
+
export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
53
|
+
return async function getBip32Entropy(args) {
|
|
54
|
+
await getUnlockPromise(true);
|
|
55
|
+
const { params } = args;
|
|
56
|
+
assert(params);
|
|
57
|
+
const node = await getNode({
|
|
58
|
+
curve: params.curve,
|
|
59
|
+
path: params.path,
|
|
60
|
+
secretRecoveryPhrase: await getMnemonic(),
|
|
61
|
+
});
|
|
62
|
+
return node.toJSON();
|
|
63
|
+
};
|
|
64
|
+
}
|
|
10
65
|
//# sourceMappingURL=getBip32Entropy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"getBip32Entropy.mjs","sourceRoot":"","sources":["../../src/restricted/getBip32Entropy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAKjD,OAAO,EAAE,cAAc,EAAE,8BAA8B;AAEvD,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAGzC,OAAO,EAAE,OAAO,EAAE,qBAAiB;AAEnC,MAAM,UAAU,GAAG,sBAAsB,CAAC;AA4B1C;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,EAA8C,EAAE,EAAE;IAClE,OAAO;QACL,cAAc,EAAE,cAAc,CAAC,gBAAgB;QAC/C,UAAU;QACV,cAAc,EAAE,CAAC,cAAc,CAAC,wBAAwB,CAAC;QACzD,oBAAoB,EAAE,6BAA6B,CAAC,WAAW,CAAC;QAChE,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IACE,OAAO,EAAE,MAAM,KAAK,CAAC;gBACrB,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,wBAAwB,EAC3D,CAAC;gBACD,MAAM,SAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,cAAc,CAAC,wBAAwB,WAAW;iBAClF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,YAAY,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAkD;IACjE,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC,MAAM,CAAC;IAClD,UAAU;IACV,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAAC,EAC5C,WAAW,EACX,gBAAgB,GACW;IAC3B,OAAO,KAAK,UAAU,eAAe,CACnC,IAAoD;QAEpD,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;QAE7B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACxB,MAAM,CAAC,MAAM,CAAC,CAAC;QAEf,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC;YACzB,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,IAAI,EAAE,MAAM,CAAC,IAAI;YACjB,oBAAoB,EAAE,MAAM,WAAW,EAAE;SAC1C,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32EntropyParams,\n GetBip32EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32Entropy';\n\nexport type GetBip32EntropyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\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\ntype GetBip32EntropySpecificationBuilderOptions = {\n methodHooks: GetBip32EntropyMethodHooks;\n};\n\ntype GetBip32EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip32Entropy` permission.\n * `snap_getBip32Entropy` lets the Snap control private keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32EntropySpecificationBuilderOptions,\n GetBip32EntropySpecification\n> = ({ methodHooks }: GetBip32EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip32EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @returns The method implementation which returns a `JsonSLIP10Node`.\n * @throws If the params are invalid.\n */\nexport function getBip32EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip32EntropyMethodHooks) {\n return async function getBip32Entropy(\n args: RestrictedMethodOptions<GetBip32EntropyParams>,\n ): Promise<GetBip32EntropyResult> {\n await getUnlockPromise(true);\n\n const { params } = args;\n assert(params);\n\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n return node.toJSON();\n };\n}\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBip32PublicKeyImplementation = exports.getBip32PublicKeyBuilder = exports.Bip32PublicKeyArgsStruct = void 0;
|
|
4
|
+
const permission_controller_1 = require("@metamask/permission-controller");
|
|
5
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
6
|
+
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
9
|
+
const utils_2 = require("../utils.cjs");
|
|
10
|
+
const targetName = 'snap_getBip32PublicKey';
|
|
11
|
+
exports.Bip32PublicKeyArgsStruct = (0, snaps_utils_1.bip32entropy)((0, superstruct_1.object)({
|
|
12
|
+
path: snaps_utils_1.Bip32PathStruct,
|
|
13
|
+
curve: snaps_utils_1.CurveStruct,
|
|
14
|
+
compressed: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
15
|
+
}));
|
|
16
|
+
/**
|
|
17
|
+
* The specification builder for the `snap_getBip32PublicKey` permission.
|
|
18
|
+
* `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular
|
|
19
|
+
* BIP-32 node.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The specification builder options.
|
|
22
|
+
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
23
|
+
* @returns The specification for the `snap_getBip32PublicKey` permission.
|
|
24
|
+
*/
|
|
25
|
+
const specificationBuilder = ({ methodHooks }) => {
|
|
26
|
+
return {
|
|
27
|
+
permissionType: permission_controller_1.PermissionType.RestrictedMethod,
|
|
28
|
+
targetName,
|
|
29
|
+
allowedCaveats: [snaps_utils_1.SnapCaveatType.PermittedDerivationPaths],
|
|
30
|
+
methodImplementation: getBip32PublicKeyImplementation(methodHooks),
|
|
31
|
+
validator: ({ caveats }) => {
|
|
32
|
+
if (caveats?.length !== 1 ||
|
|
33
|
+
caveats[0].type !== snaps_utils_1.SnapCaveatType.PermittedDerivationPaths) {
|
|
34
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
35
|
+
message: `Expected a single "${snaps_utils_1.SnapCaveatType.PermittedDerivationPaths}" caveat.`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
subjectTypes: [permission_controller_1.SubjectType.Snap],
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
const methodHooks = {
|
|
43
|
+
getMnemonic: true,
|
|
44
|
+
getUnlockPromise: true,
|
|
45
|
+
};
|
|
46
|
+
exports.getBip32PublicKeyBuilder = Object.freeze({
|
|
47
|
+
targetName,
|
|
48
|
+
specificationBuilder,
|
|
49
|
+
methodHooks,
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Builds the method implementation for `snap_getBip32PublicKey`.
|
|
53
|
+
*
|
|
54
|
+
* @param hooks - The RPC method hooks.
|
|
55
|
+
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
56
|
+
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
57
|
+
* and prompts the user to unlock their MetaMask if it is locked.
|
|
58
|
+
* @returns The method implementation which returns a public key.
|
|
59
|
+
* @throws If the params are invalid.
|
|
60
|
+
*/
|
|
61
|
+
function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }) {
|
|
62
|
+
return async function getBip32PublicKey(args) {
|
|
63
|
+
await getUnlockPromise(true);
|
|
64
|
+
(0, utils_1.assertStruct)(args.params, exports.Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpc_errors_1.rpcErrors.invalidParams);
|
|
65
|
+
const { params } = args;
|
|
66
|
+
const node = await (0, utils_2.getNode)({
|
|
67
|
+
curve: params.curve,
|
|
68
|
+
path: params.path,
|
|
69
|
+
secretRecoveryPhrase: await getMnemonic(),
|
|
70
|
+
});
|
|
71
|
+
if (params.compressed) {
|
|
72
|
+
return node.compressedPublicKey;
|
|
73
|
+
}
|
|
74
|
+
return node.publicKey;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exports.getBip32PublicKeyImplementation = getBip32PublicKeyImplementation;
|
|
78
|
+
//# sourceMappingURL=getBip32PublicKey.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBip32PublicKey.cjs","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":";;;AAMA,2EAA8E;AAC9E,qDAAiD;AAKjD,uDAK+B;AAC/B,uDAAkE;AAElE,2CAA+C;AAG/C,wCAAmC;AAEnC,MAAM,UAAU,GAAG,wBAAwB,CAAC;AA4B/B,QAAA,wBAAwB,GAAG,IAAA,0BAAY,EAClD,IAAA,oBAAM,EAAC;IACL,IAAI,EAAE,6BAAe;IACrB,KAAK,EAAE,yBAAW;IAClB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;CAChC,CAAC,CACH,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAAE,WAAW,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E,MAAM,WAAW,EAAE;SAC1C,CAAC,CAAC;QAEH,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,mBAAmB,CAAC;QAClC,CAAC;QAED,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC,CAAC;AACJ,CAAC;AA7BD,0EA6BC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n PermissionValidatorConstraint,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetBip32PublicKeyParams,\n GetBip32PublicKeyResult,\n} from '@metamask/snaps-sdk';\nimport {\n bip32entropy,\n Bip32PathStruct,\n CurveStruct,\n SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport { boolean, object, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { getNode } from '../utils';\n\nconst targetName = 'snap_getBip32PublicKey';\n\nexport type GetBip32PublicKeyMethodHooks = {\n /**\n * @returns The mnemonic of the user's primary keyring.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\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\ntype GetBip32PublicKeySpecificationBuilderOptions = {\n methodHooks: GetBip32PublicKeyMethodHooks;\n};\n\ntype GetBip32PublicKeySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip32PublicKeyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\nexport const Bip32PublicKeyArgsStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: CurveStruct,\n compressed: optional(boolean()),\n }),\n);\n\n/**\n * The specification builder for the `snap_getBip32PublicKey` permission.\n * `snap_getBip32PublicKey` lets the Snap retrieve public keys for a particular\n * BIP-32 node.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_getBip32PublicKey` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip32PublicKeySpecificationBuilderOptions,\n GetBip32PublicKeySpecification\n> = ({ methodHooks }: GetBip32PublicKeySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedDerivationPaths],\n methodImplementation: getBip32PublicKeyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedDerivationPaths\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedDerivationPaths}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip32PublicKeyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip32PublicKeyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip32PublicKey`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked\n * and prompts the user to unlock their MetaMask if it is locked.\n * @returns The method implementation which returns a public key.\n * @throws If the params are invalid.\n */\nexport function getBip32PublicKeyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip32PublicKeyMethodHooks) {\n return async function getBip32PublicKey(\n args: RestrictedMethodOptions<GetBip32PublicKeyParams>,\n ): Promise<GetBip32PublicKeyResult> {\n await getUnlockPromise(true);\n\n assertStruct(\n args.params,\n Bip32PublicKeyArgsStruct,\n 'Invalid BIP-32 public key params',\n rpcErrors.invalidParams,\n );\n\n const { params } = args;\n const node = await getNode({\n curve: params.curve,\n path: params.path,\n secretRecoveryPhrase: await getMnemonic(),\n });\n\n if (params.compressed) {\n return node.compressedPublicKey;\n }\n\n return node.publicKey;\n };\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from
|
|
2
|
-
import { PermissionType } from
|
|
3
|
-
import type { GetBip32PublicKeyParams, GetBip32PublicKeyResult } from
|
|
4
|
-
import type { NonEmptyArray } from
|
|
5
|
-
import type { MethodHooksObject } from
|
|
1
|
+
import type { PermissionSpecificationBuilder, PermissionValidatorConstraint, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
|
+
import { PermissionType } from "@metamask/permission-controller";
|
|
3
|
+
import type { GetBip32PublicKeyParams, GetBip32PublicKeyResult } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { NonEmptyArray } from "@metamask/utils";
|
|
5
|
+
import type { MethodHooksObject } from "../utils.cjs";
|
|
6
6
|
declare const targetName = "snap_getBip32PublicKey";
|
|
7
7
|
export type GetBip32PublicKeyMethodHooks = {
|
|
8
8
|
/**
|
|
@@ -20,8 +20,8 @@ type GetBip32PublicKeySpecificationBuilderOptions = {
|
|
|
20
20
|
methodHooks: GetBip32PublicKeyMethodHooks;
|
|
21
21
|
};
|
|
22
22
|
export declare const Bip32PublicKeyArgsStruct: import("@metamask/superstruct").Struct<{
|
|
23
|
-
path: string[];
|
|
24
23
|
curve: "ed25519" | "ed25519Bip32" | "secp256k1";
|
|
24
|
+
path: string[];
|
|
25
25
|
compressed?: boolean | undefined;
|
|
26
26
|
}, {
|
|
27
27
|
path: import("@metamask/superstruct").Struct<string[], import("@metamask/superstruct").Struct<string, null>>;
|
|
@@ -51,3 +51,4 @@ export declare const getBip32PublicKeyBuilder: Readonly<{
|
|
|
51
51
|
*/
|
|
52
52
|
export declare function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise, }: GetBip32PublicKeyMethodHooks): (args: RestrictedMethodOptions<GetBip32PublicKeyParams>) => Promise<GetBip32PublicKeyResult>;
|
|
53
53
|
export {};
|
|
54
|
+
//# sourceMappingURL=getBip32PublicKey.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getBip32PublicKey.d.cts","sourceRoot":"","sources":["../../src/restricted/getBip32PublicKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,6BAA6B,EAC7B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,4BAA4B;AAQ7B,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAGlD,QAAA,MAAM,UAAU,2BAA2B,CAAC;AAE5C,MAAM,MAAM,4BAA4B,GAAG;IACzC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IAEvC;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,KAAK,4CAA4C,GAAG;IAClD,WAAW,EAAE,4BAA4B,CAAC;CAC3C,CAAC;AAUF,eAAO,MAAM,wBAAwB;;;;;;;;EAMpC,CAAC;AAwCF,eAAO,MAAM,wBAAwB;;;wBArDnB,eAAe,gBAAgB;oBACnC,iBAAiB;8BACP,WAAW,sCAAsC,CAAC;wBACxD,SAAS,cAAc,MAAM,CAAC,CAAC,GAAG,IAAI;mBAC3C,6BAA6B;;;EAqD/B,CAAC;AAEZ;;;;;;;;;GASG;AACH,wBAAgB,+BAA+B,CAAC,EAC9C,WAAW,EACX,gBAAgB,GACjB,EAAE,4BAA4B,UAErB,wBAAwB,uBAAuB,CAAC,KACrD,QAAQ,uBAAuB,CAAC,CAuBpC"}
|