@metamask/snaps-rpc-methods 5.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -3
- package/dist/chunk-2A5M65V3.js +21 -0
- package/dist/chunk-2A5M65V3.js.map +1 -0
- package/dist/chunk-2IL6T3EX.js +18 -0
- package/dist/chunk-2IL6T3EX.js.map +1 -0
- package/dist/chunk-2N2PZJDJ.mjs +105 -0
- package/dist/chunk-2N2PZJDJ.mjs.map +1 -0
- package/dist/chunk-2QEA2YZM.mjs +23 -0
- package/dist/chunk-2QEA2YZM.mjs.map +1 -0
- package/dist/chunk-2TYDIMR6.js +78 -0
- package/dist/chunk-2TYDIMR6.js.map +1 -0
- package/dist/chunk-2WCLK3LN.mjs +115 -0
- package/dist/chunk-2WCLK3LN.mjs.map +1 -0
- package/dist/chunk-3CSLIOIY.mjs +43 -0
- package/dist/chunk-3CSLIOIY.mjs.map +1 -0
- package/dist/chunk-3DWRS3YG.mjs +49 -0
- package/dist/chunk-3DWRS3YG.mjs.map +1 -0
- package/dist/chunk-3FKD2O7M.js +151 -0
- package/dist/chunk-3FKD2O7M.js.map +1 -0
- package/dist/chunk-4ALFLY5D.js +105 -0
- package/dist/chunk-4ALFLY5D.js.map +1 -0
- package/dist/chunk-4Z4X6EJP.mjs +67 -0
- package/dist/chunk-4Z4X6EJP.mjs.map +1 -0
- package/dist/chunk-5HIIIAIS.mjs +57 -0
- package/dist/chunk-5HIIIAIS.mjs.map +1 -0
- package/dist/chunk-632BZ6JY.js +83 -0
- package/dist/{cjs/utils.js.map → chunk-632BZ6JY.js.map} +1 -1
- package/dist/chunk-6DUTJBD2.mjs +82 -0
- package/dist/chunk-6DUTJBD2.mjs.map +1 -0
- package/dist/chunk-6PXDUIXN.js +67 -0
- package/dist/chunk-6PXDUIXN.js.map +1 -0
- package/dist/chunk-72V4CPGO.mjs +23 -0
- package/dist/chunk-72V4CPGO.mjs.map +1 -0
- package/dist/chunk-7O63CIBT.js +42 -0
- package/dist/chunk-7O63CIBT.js.map +1 -0
- package/dist/chunk-ABFJRV6Q.js +68 -0
- package/dist/chunk-ABFJRV6Q.js.map +1 -0
- package/dist/chunk-BZIPLSKM.mjs +39 -0
- package/dist/chunk-BZIPLSKM.mjs.map +1 -0
- package/dist/chunk-CIIMO4C2.js +45 -0
- package/dist/chunk-CIIMO4C2.js.map +1 -0
- package/dist/chunk-DBYI25UR.js +23 -0
- package/dist/chunk-DBYI25UR.js.map +1 -0
- package/dist/chunk-DDGDVWAW.js +45 -0
- package/dist/chunk-DDGDVWAW.js.map +1 -0
- package/dist/chunk-DR63Z4PV.mjs +83 -0
- package/dist/chunk-DR63Z4PV.mjs.map +1 -0
- package/dist/chunk-E2G25QVG.js +119 -0
- package/dist/chunk-E2G25QVG.js.map +1 -0
- package/dist/chunk-E4HGQWSS.js +43 -0
- package/dist/chunk-E4HGQWSS.js.map +1 -0
- package/dist/chunk-EAL6AH74.js +67 -0
- package/dist/chunk-EAL6AH74.js.map +1 -0
- package/dist/chunk-EB6OXVFN.mjs +52 -0
- package/dist/chunk-EB6OXVFN.mjs.map +1 -0
- package/dist/chunk-EKB7QNFO.mjs +54 -0
- package/dist/chunk-EKB7QNFO.mjs.map +1 -0
- package/dist/chunk-EPNGNDRH.mjs +80 -0
- package/dist/chunk-EPNGNDRH.mjs.map +1 -0
- package/dist/chunk-F5BEVZOB.js +47 -0
- package/dist/chunk-F5BEVZOB.js.map +1 -0
- package/dist/chunk-FMUQOZIO.js +57 -0
- package/dist/chunk-FMUQOZIO.js.map +1 -0
- package/dist/chunk-H45CGE4Z.js +23 -0
- package/dist/chunk-H45CGE4Z.js.map +1 -0
- package/dist/chunk-HIYXSQ6K.mjs +188 -0
- package/dist/chunk-HIYXSQ6K.mjs.map +1 -0
- package/dist/chunk-HLF4WCE4.mjs +20 -0
- package/dist/chunk-HLF4WCE4.mjs.map +1 -0
- package/dist/chunk-HODDBRLQ.js +75 -0
- package/dist/chunk-HODDBRLQ.js.map +1 -0
- package/dist/chunk-HOXOD5RL.mjs +68 -0
- package/dist/chunk-HOXOD5RL.mjs.map +1 -0
- package/dist/chunk-I5H5ZZRC.js +80 -0
- package/dist/chunk-I5H5ZZRC.js.map +1 -0
- package/dist/chunk-IDRDPYAN.js +70 -0
- package/dist/chunk-IDRDPYAN.js.map +1 -0
- package/dist/chunk-JEEKFTAL.mjs +59 -0
- package/dist/chunk-JEEKFTAL.mjs.map +1 -0
- package/dist/chunk-JPUJWFBS.js +115 -0
- package/dist/chunk-JPUJWFBS.js.map +1 -0
- package/dist/chunk-JURJUHQB.mjs +70 -0
- package/dist/chunk-JURJUHQB.mjs.map +1 -0
- package/dist/chunk-JV26U22G.js +52 -0
- package/dist/chunk-JV26U22G.js.map +1 -0
- package/dist/chunk-K73RKHXA.js +20 -0
- package/dist/chunk-K73RKHXA.js.map +1 -0
- package/dist/chunk-KDLWQGV3.js +74 -0
- package/dist/chunk-KDLWQGV3.js.map +1 -0
- package/dist/chunk-KE74K2JM.js +59 -0
- package/dist/chunk-KE74K2JM.js.map +1 -0
- package/dist/chunk-KVHYDTGR.js +1 -0
- package/dist/chunk-KVHYDTGR.js.map +1 -0
- package/dist/chunk-L7MGGL7Q.mjs +43 -0
- package/dist/chunk-L7MGGL7Q.mjs.map +1 -0
- package/dist/chunk-LITIVHN4.js +73 -0
- package/dist/chunk-LITIVHN4.js.map +1 -0
- package/dist/chunk-LU3J2EYE.js +51 -0
- package/dist/chunk-LU3J2EYE.js.map +1 -0
- package/dist/chunk-LX37AMSK.mjs +78 -0
- package/dist/chunk-LX37AMSK.mjs.map +1 -0
- package/dist/chunk-LYOKCYHO.mjs +1 -0
- package/dist/chunk-LYOKCYHO.mjs.map +1 -0
- package/dist/chunk-MDJZ4K3U.mjs +45 -0
- package/dist/chunk-MDJZ4K3U.mjs.map +1 -0
- package/dist/chunk-MVPKNRLA.mjs +21 -0
- package/dist/chunk-MVPKNRLA.mjs.map +1 -0
- package/dist/chunk-MYMH4S2N.mjs +23 -0
- package/dist/chunk-MYMH4S2N.mjs.map +1 -0
- package/dist/chunk-NE2GDZGZ.mjs +67 -0
- package/dist/chunk-NE2GDZGZ.mjs.map +1 -0
- package/dist/chunk-NTDD6M3B.mjs +32 -0
- package/dist/chunk-NTDD6M3B.mjs.map +1 -0
- package/dist/chunk-NUKEBOOL.js +78 -0
- package/dist/chunk-NUKEBOOL.js.map +1 -0
- package/dist/chunk-OMP4SFLK.js +1 -0
- package/dist/chunk-OMP4SFLK.js.map +1 -0
- package/dist/chunk-OU3QPU6E.mjs +45 -0
- package/dist/chunk-OU3QPU6E.mjs.map +1 -0
- package/dist/chunk-OUD66G6O.mjs +74 -0
- package/dist/chunk-OUD66G6O.mjs.map +1 -0
- package/dist/chunk-PEMZWIHQ.js +39 -0
- package/dist/chunk-PEMZWIHQ.js.map +1 -0
- package/dist/chunk-PSAM7MJM.mjs +78 -0
- package/dist/chunk-PSAM7MJM.mjs.map +1 -0
- package/dist/chunk-RC7LBS3H.js +35 -0
- package/dist/chunk-RC7LBS3H.js.map +1 -0
- package/dist/chunk-RHGOSBUT.js +21 -0
- package/dist/chunk-RHGOSBUT.js.map +1 -0
- package/dist/chunk-RKCEAMYH.mjs +18 -0
- package/dist/chunk-RKCEAMYH.mjs.map +1 -0
- package/dist/chunk-RWLBQVYX.mjs +73 -0
- package/dist/chunk-RWLBQVYX.mjs.map +1 -0
- package/dist/chunk-RZDRHJXI.js +23 -0
- package/dist/chunk-RZDRHJXI.js.map +1 -0
- package/dist/chunk-SCXW3FQO.js +49 -0
- package/dist/chunk-SCXW3FQO.js.map +1 -0
- package/dist/chunk-SMWKMPHG.mjs +35 -0
- package/dist/chunk-SMWKMPHG.mjs.map +1 -0
- package/dist/chunk-SXSNJEE7.js +18 -0
- package/dist/chunk-SXSNJEE7.js.map +1 -0
- package/dist/chunk-TNIGT6KN.js +32 -0
- package/dist/chunk-TNIGT6KN.js.map +1 -0
- package/dist/chunk-TRB2LS4N.js +54 -0
- package/dist/chunk-TRB2LS4N.js.map +1 -0
- package/dist/chunk-TZRCALSV.mjs +54 -0
- package/dist/chunk-TZRCALSV.mjs.map +1 -0
- package/dist/chunk-UJZ3HNXS.mjs +23 -0
- package/dist/chunk-UJZ3HNXS.mjs.map +1 -0
- package/dist/chunk-UXVJ7HYO.js +78 -0
- package/dist/{cjs/restricted/getBip32PublicKey.js.map → chunk-UXVJ7HYO.js.map} +1 -1
- package/dist/chunk-UYSXSKML.js +82 -0
- package/dist/chunk-UYSXSKML.js.map +1 -0
- package/dist/chunk-VFI5FR5U.mjs +119 -0
- package/dist/chunk-VFI5FR5U.mjs.map +1 -0
- package/dist/chunk-VRDGSBXX.mjs +78 -0
- package/dist/chunk-VRDGSBXX.mjs.map +1 -0
- package/dist/chunk-VSVVWO3W.mjs +42 -0
- package/dist/chunk-VSVVWO3W.mjs.map +1 -0
- package/dist/chunk-VZBSLVVA.js +23 -0
- package/dist/chunk-VZBSLVVA.js.map +1 -0
- package/dist/chunk-W2VJ5TWL.js +54 -0
- package/dist/chunk-W2VJ5TWL.js.map +1 -0
- package/dist/chunk-WHWFVRFH.js +69 -0
- package/dist/chunk-WHWFVRFH.js.map +1 -0
- package/dist/chunk-WI23VKOX.mjs +21 -0
- package/dist/chunk-WI23VKOX.mjs.map +1 -0
- package/dist/chunk-XAQ2P3BY.js +188 -0
- package/dist/chunk-XAQ2P3BY.js.map +1 -0
- package/dist/chunk-Y5ENHOIY.mjs +47 -0
- package/dist/chunk-Y5ENHOIY.mjs.map +1 -0
- package/dist/chunk-Y6EL5DBH.mjs +75 -0
- package/dist/chunk-Y6EL5DBH.mjs.map +1 -0
- package/dist/chunk-Y7DF3ZHO.mjs +1 -0
- package/dist/chunk-Y7DF3ZHO.mjs.map +1 -0
- package/dist/chunk-YJ3ZFIA7.mjs +51 -0
- package/dist/chunk-YJ3ZFIA7.mjs.map +1 -0
- package/dist/chunk-YK6IFDRN.mjs +151 -0
- package/dist/chunk-YK6IFDRN.mjs.map +1 -0
- package/dist/chunk-YN3OMGA5.mjs +69 -0
- package/dist/chunk-YN3OMGA5.mjs.map +1 -0
- package/dist/chunk-ZLLV3F4G.js +43 -0
- package/dist/chunk-ZLLV3F4G.js.map +1 -0
- package/dist/chunk-ZP3L7LAQ.mjs +18 -0
- package/dist/chunk-ZP3L7LAQ.mjs.map +1 -0
- package/dist/endowments/caveats/generic.js +7 -0
- package/dist/endowments/caveats/generic.js.map +1 -0
- package/dist/endowments/caveats/generic.mjs +7 -0
- package/dist/endowments/caveats/generic.mjs.map +1 -0
- package/dist/endowments/caveats/index.js +18 -0
- package/dist/endowments/caveats/index.js.map +1 -0
- package/dist/endowments/caveats/index.mjs +18 -0
- package/dist/endowments/caveats/index.mjs.map +1 -0
- package/dist/endowments/caveats/requestTime.js +13 -0
- package/dist/endowments/caveats/requestTime.js.map +1 -0
- package/dist/endowments/caveats/requestTime.mjs +13 -0
- package/dist/endowments/caveats/requestTime.mjs.map +1 -0
- package/dist/endowments/cronjob.js +16 -0
- package/dist/endowments/cronjob.js.map +1 -0
- package/dist/endowments/cronjob.mjs +16 -0
- package/dist/endowments/cronjob.mjs.map +1 -0
- package/dist/endowments/enum.js +7 -0
- package/dist/endowments/enum.js.map +1 -0
- package/dist/endowments/enum.mjs +7 -0
- package/dist/endowments/enum.mjs.map +1 -0
- package/dist/endowments/ethereum-provider.js +8 -0
- package/dist/endowments/ethereum-provider.js.map +1 -0
- package/dist/endowments/ethereum-provider.mjs +8 -0
- package/dist/endowments/ethereum-provider.mjs.map +1 -0
- package/dist/endowments/home-page.js +8 -0
- package/dist/endowments/home-page.js.map +1 -0
- package/dist/endowments/home-page.mjs +8 -0
- package/dist/endowments/home-page.mjs.map +1 -0
- package/dist/endowments/index.js +54 -0
- package/dist/endowments/index.js.map +1 -0
- package/dist/endowments/index.mjs +54 -0
- package/dist/endowments/index.mjs.map +1 -0
- package/dist/endowments/keyring.js +17 -0
- package/dist/endowments/keyring.js.map +1 -0
- package/dist/endowments/keyring.mjs +17 -0
- package/dist/endowments/keyring.mjs.map +1 -0
- package/dist/endowments/lifecycle-hooks.js +8 -0
- package/dist/endowments/lifecycle-hooks.js.map +1 -0
- package/dist/endowments/lifecycle-hooks.mjs +8 -0
- package/dist/endowments/lifecycle-hooks.mjs.map +1 -0
- package/dist/endowments/name-lookup.js +19 -0
- package/dist/endowments/name-lookup.js.map +1 -0
- package/dist/endowments/name-lookup.mjs +19 -0
- package/dist/endowments/name-lookup.mjs.map +1 -0
- package/dist/endowments/network-access.js +8 -0
- package/dist/endowments/network-access.js.map +1 -0
- package/dist/endowments/network-access.mjs +8 -0
- package/dist/endowments/network-access.mjs.map +1 -0
- package/dist/endowments/rpc.js +17 -0
- package/dist/endowments/rpc.js.map +1 -0
- package/dist/endowments/rpc.mjs +17 -0
- package/dist/endowments/rpc.mjs.map +1 -0
- package/dist/endowments/signature-insight.js +17 -0
- package/dist/endowments/signature-insight.js.map +1 -0
- package/dist/endowments/signature-insight.mjs +17 -0
- package/dist/endowments/signature-insight.mjs.map +1 -0
- package/dist/endowments/transaction-insight.js +17 -0
- package/dist/endowments/transaction-insight.js.map +1 -0
- package/dist/endowments/transaction-insight.mjs +17 -0
- package/dist/endowments/transaction-insight.mjs.map +1 -0
- package/dist/endowments/web-assembly.js +8 -0
- package/dist/endowments/web-assembly.js.map +1 -0
- package/dist/endowments/web-assembly.mjs +8 -0
- package/dist/endowments/web-assembly.mjs.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +118 -0
- package/dist/index.mjs.map +1 -0
- package/dist/permissions.js +43 -0
- package/dist/permissions.js.map +1 -0
- package/dist/permissions.mjs +43 -0
- package/dist/permissions.mjs.map +1 -0
- package/dist/permitted/createInterface.js +7 -0
- package/dist/permitted/createInterface.js.map +1 -0
- package/dist/permitted/createInterface.mjs +7 -0
- package/dist/permitted/createInterface.mjs.map +1 -0
- package/dist/permitted/getAllSnaps.js +7 -0
- package/dist/permitted/getAllSnaps.js.map +1 -0
- package/dist/permitted/getAllSnaps.mjs +7 -0
- package/dist/permitted/getAllSnaps.mjs.map +1 -0
- package/dist/permitted/getClientStatus.js +7 -0
- package/dist/permitted/getClientStatus.js.map +1 -0
- package/dist/permitted/getClientStatus.mjs +7 -0
- package/dist/permitted/getClientStatus.mjs.map +1 -0
- package/dist/permitted/getFile.js +9 -0
- package/dist/permitted/getFile.js.map +1 -0
- package/dist/permitted/getFile.mjs +9 -0
- package/dist/permitted/getFile.mjs.map +1 -0
- package/dist/permitted/getInterfaceState.js +7 -0
- package/dist/permitted/getInterfaceState.js.map +1 -0
- package/dist/permitted/getInterfaceState.mjs +7 -0
- package/dist/permitted/getInterfaceState.mjs.map +1 -0
- package/dist/permitted/getSnaps.js +7 -0
- package/dist/permitted/getSnaps.js.map +1 -0
- package/dist/permitted/getSnaps.mjs +7 -0
- package/dist/permitted/getSnaps.mjs.map +1 -0
- package/dist/permitted/handlers.js +20 -0
- package/dist/permitted/handlers.js.map +1 -0
- package/dist/permitted/handlers.mjs +20 -0
- package/dist/permitted/handlers.mjs.map +1 -0
- package/dist/permitted/index.js +26 -0
- package/dist/permitted/index.js.map +1 -0
- package/dist/permitted/index.mjs +26 -0
- package/dist/permitted/index.mjs.map +1 -0
- package/dist/permitted/invokeKeyring.js +8 -0
- package/dist/permitted/invokeKeyring.js.map +1 -0
- package/dist/permitted/invokeKeyring.mjs +8 -0
- package/dist/permitted/invokeKeyring.mjs.map +1 -0
- package/dist/permitted/invokeSnapSugar.js +11 -0
- package/dist/permitted/invokeSnapSugar.js.map +1 -0
- package/dist/permitted/invokeSnapSugar.mjs +11 -0
- package/dist/permitted/invokeSnapSugar.mjs.map +1 -0
- package/dist/permitted/middleware.js +20 -0
- package/dist/permitted/middleware.js.map +1 -0
- package/dist/permitted/middleware.mjs +20 -0
- package/dist/permitted/middleware.mjs.map +1 -0
- package/dist/permitted/requestSnaps.js +12 -0
- package/dist/permitted/requestSnaps.js.map +1 -0
- package/dist/permitted/requestSnaps.mjs +12 -0
- package/dist/permitted/requestSnaps.mjs.map +1 -0
- package/dist/permitted/updateInterface.js +7 -0
- package/dist/permitted/updateInterface.js.map +1 -0
- package/dist/permitted/updateInterface.mjs +7 -0
- package/dist/permitted/updateInterface.mjs.map +1 -0
- package/dist/restricted/caveats/index.js +17 -0
- package/dist/restricted/caveats/index.js.map +1 -0
- package/dist/restricted/caveats/index.mjs +17 -0
- package/dist/restricted/caveats/index.mjs.map +1 -0
- package/dist/restricted/caveats/permittedCoinTypes.js +13 -0
- package/dist/restricted/caveats/permittedCoinTypes.js.map +1 -0
- package/dist/restricted/caveats/permittedCoinTypes.mjs +13 -0
- package/dist/restricted/caveats/permittedCoinTypes.mjs.map +1 -0
- package/dist/restricted/caveats/permittedDerivationPaths.js +13 -0
- package/dist/restricted/caveats/permittedDerivationPaths.js.map +1 -0
- package/dist/restricted/caveats/permittedDerivationPaths.mjs +13 -0
- package/dist/restricted/caveats/permittedDerivationPaths.mjs.map +1 -0
- package/dist/restricted/caveats/snapIds.js +11 -0
- package/dist/restricted/caveats/snapIds.js.map +1 -0
- package/dist/restricted/caveats/snapIds.mjs +11 -0
- package/dist/restricted/caveats/snapIds.mjs.map +1 -0
- package/dist/restricted/dialog.js +9 -0
- package/dist/restricted/dialog.js.map +1 -0
- package/dist/restricted/dialog.mjs +9 -0
- package/dist/restricted/dialog.mjs.map +1 -0
- package/dist/restricted/getBip32Entropy.js +10 -0
- package/dist/restricted/getBip32Entropy.js.map +1 -0
- package/dist/restricted/getBip32Entropy.mjs +10 -0
- package/dist/restricted/getBip32Entropy.mjs.map +1 -0
- package/dist/restricted/getBip32PublicKey.js +12 -0
- package/dist/restricted/getBip32PublicKey.js.map +1 -0
- package/dist/restricted/getBip32PublicKey.mjs +12 -0
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -0
- package/dist/restricted/getBip44Entropy.js +9 -0
- package/dist/restricted/getBip44Entropy.js.map +1 -0
- package/dist/restricted/getBip44Entropy.mjs +9 -0
- package/dist/restricted/getBip44Entropy.mjs.map +1 -0
- package/dist/restricted/getEntropy.js +10 -0
- package/dist/restricted/getEntropy.js.map +1 -0
- package/dist/restricted/getEntropy.mjs +10 -0
- package/dist/restricted/getEntropy.mjs.map +1 -0
- package/dist/restricted/getLocale.js +11 -0
- package/dist/restricted/getLocale.js.map +1 -0
- package/dist/restricted/getLocale.mjs +11 -0
- package/dist/restricted/getLocale.mjs.map +1 -0
- package/dist/restricted/index.js +33 -0
- package/dist/restricted/index.js.map +1 -0
- package/dist/restricted/index.mjs +33 -0
- package/dist/restricted/index.mjs.map +1 -0
- package/dist/restricted/invokeSnap.js +13 -0
- package/dist/restricted/invokeSnap.js.map +1 -0
- package/dist/restricted/invokeSnap.mjs +13 -0
- package/dist/restricted/invokeSnap.mjs.map +1 -0
- package/dist/restricted/manageAccounts.js +13 -0
- package/dist/restricted/manageAccounts.js.map +1 -0
- package/dist/restricted/manageAccounts.mjs +13 -0
- package/dist/restricted/manageAccounts.mjs.map +1 -0
- package/dist/restricted/manageState.js +20 -0
- package/dist/restricted/manageState.js.map +1 -0
- package/dist/restricted/manageState.mjs +20 -0
- package/dist/restricted/manageState.mjs.map +1 -0
- package/dist/restricted/notify.js +13 -0
- package/dist/restricted/notify.js.map +1 -0
- package/dist/restricted/notify.mjs +13 -0
- package/dist/restricted/notify.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/endowments/caveats/generic.d.ts +19 -0
- package/dist/types/endowments/caveats/index.d.ts +2 -0
- package/dist/types/endowments/caveats/requestTime.d.ts +29 -0
- package/dist/types/endowments/cronjob.d.ts +51 -0
- package/dist/types/endowments/enum.d.ts +13 -0
- package/dist/types/endowments/ethereum-provider.d.ts +14 -0
- package/dist/types/endowments/home-page.d.ts +15 -0
- package/dist/types/endowments/index.d.ts +131 -0
- package/dist/types/endowments/keyring.d.ts +39 -0
- package/dist/types/endowments/lifecycle-hooks.d.ts +15 -0
- package/dist/types/endowments/name-lookup.d.ts +49 -0
- package/dist/types/endowments/network-access.d.ts +14 -0
- package/dist/types/endowments/rpc.d.ts +38 -0
- package/dist/types/endowments/signature-insight.d.ts +39 -0
- package/dist/types/endowments/transaction-insight.d.ts +39 -0
- package/dist/types/endowments/web-assembly.d.ts +14 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/permissions.d.ts +16 -0
- package/dist/types/permitted/createInterface.d.ts +150 -0
- package/dist/types/permitted/getInterfaceState.d.ts +18 -0
- package/dist/types/permitted/handlers.d.ts +4 -1
- package/dist/types/permitted/index.d.ts +4 -1
- package/dist/types/permitted/updateInterface.d.ts +152 -0
- package/dist/types/restricted/dialog.d.ts +776 -14
- package/dist/utils.js +13 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.mjs +13 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +22 -19
- package/dist/cjs/index.js +0 -43
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/permitted/getAllSnaps.js +0 -44
- package/dist/cjs/permitted/getAllSnaps.js.map +0 -1
- package/dist/cjs/permitted/getClientStatus.js +0 -40
- package/dist/cjs/permitted/getClientStatus.js.map +0 -1
- package/dist/cjs/permitted/getFile.js +0 -63
- package/dist/cjs/permitted/getFile.js.map +0 -1
- package/dist/cjs/permitted/getSnaps.js +0 -39
- package/dist/cjs/permitted/getSnaps.js.map +0 -1
- package/dist/cjs/permitted/handlers.js +0 -37
- package/dist/cjs/permitted/handlers.js.map +0 -1
- package/dist/cjs/permitted/index.js +0 -21
- package/dist/cjs/permitted/index.js.map +0 -1
- package/dist/cjs/permitted/invokeKeyring.js +0 -87
- package/dist/cjs/permitted/invokeKeyring.js.map +0 -1
- package/dist/cjs/permitted/invokeSnapSugar.js +0 -62
- package/dist/cjs/permitted/invokeSnapSugar.js.map +0 -1
- package/dist/cjs/permitted/middleware.js +0 -38
- package/dist/cjs/permitted/middleware.js.map +0 -1
- package/dist/cjs/permitted/requestSnaps.js +0 -123
- package/dist/cjs/permitted/requestSnaps.js.map +0 -1
- package/dist/cjs/restricted/caveats/index.js +0 -38
- package/dist/cjs/restricted/caveats/index.js.map +0 -1
- package/dist/cjs/restricted/caveats/permittedCoinTypes.js +0 -83
- package/dist/cjs/restricted/caveats/permittedCoinTypes.js.map +0 -1
- package/dist/cjs/restricted/caveats/permittedDerivationPaths.js +0 -67
- package/dist/cjs/restricted/caveats/permittedDerivationPaths.js.map +0 -1
- package/dist/cjs/restricted/caveats/snapIds.js +0 -59
- package/dist/cjs/restricted/caveats/snapIds.js.map +0 -1
- package/dist/cjs/restricted/dialog.js +0 -145
- package/dist/cjs/restricted/dialog.js.map +0 -1
- package/dist/cjs/restricted/getBip32Entropy.js +0 -76
- package/dist/cjs/restricted/getBip32Entropy.js.map +0 -1
- package/dist/cjs/restricted/getBip32PublicKey.js +0 -91
- package/dist/cjs/restricted/getBip44Entropy.js +0 -76
- package/dist/cjs/restricted/getBip44Entropy.js.map +0 -1
- package/dist/cjs/restricted/getEntropy.js +0 -76
- package/dist/cjs/restricted/getEntropy.js.map +0 -1
- package/dist/cjs/restricted/getLocale.js +0 -49
- package/dist/cjs/restricted/getLocale.js.map +0 -1
- package/dist/cjs/restricted/index.js +0 -59
- package/dist/cjs/restricted/index.js.map +0 -1
- package/dist/cjs/restricted/invokeSnap.js +0 -99
- package/dist/cjs/restricted/invokeSnap.js.map +0 -1
- package/dist/cjs/restricted/manageAccounts.js +0 -68
- package/dist/cjs/restricted/manageAccounts.js.map +0 -1
- package/dist/cjs/restricted/manageState.js +0 -208
- package/dist/cjs/restricted/manageState.js.map +0 -1
- package/dist/cjs/restricted/notify.js +0 -92
- package/dist/cjs/restricted/notify.js.map +0 -1
- package/dist/cjs/utils.js +0 -98
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/permitted/getAllSnaps.js +0 -37
- package/dist/esm/permitted/getAllSnaps.js.map +0 -1
- package/dist/esm/permitted/getClientStatus.js +0 -32
- package/dist/esm/permitted/getClientStatus.js.map +0 -1
- package/dist/esm/permitted/getFile.js +0 -45
- package/dist/esm/permitted/getFile.js.map +0 -1
- package/dist/esm/permitted/getSnaps.js +0 -31
- package/dist/esm/permitted/getSnaps.js.map +0 -1
- package/dist/esm/permitted/handlers.js +0 -19
- package/dist/esm/permitted/handlers.js.map +0 -1
- package/dist/esm/permitted/index.js +0 -4
- package/dist/esm/permitted/index.js.map +0 -1
- package/dist/esm/permitted/invokeKeyring.js +0 -79
- package/dist/esm/permitted/invokeKeyring.js.map +0 -1
- package/dist/esm/permitted/invokeSnapSugar.js +0 -60
- package/dist/esm/permitted/invokeSnapSugar.js.map +0 -1
- package/dist/esm/permitted/middleware.js +0 -34
- package/dist/esm/permitted/middleware.js.map +0 -1
- package/dist/esm/permitted/requestSnaps.js +0 -118
- package/dist/esm/permitted/requestSnaps.js.map +0 -1
- package/dist/esm/restricted/caveats/index.js +0 -20
- package/dist/esm/restricted/caveats/index.js.map +0 -1
- package/dist/esm/restricted/caveats/permittedCoinTypes.js +0 -77
- package/dist/esm/restricted/caveats/permittedCoinTypes.js.map +0 -1
- package/dist/esm/restricted/caveats/permittedDerivationPaths.js +0 -64
- package/dist/esm/restricted/caveats/permittedDerivationPaths.js.map +0 -1
- package/dist/esm/restricted/caveats/snapIds.js +0 -50
- package/dist/esm/restricted/caveats/snapIds.js.map +0 -1
- package/dist/esm/restricted/dialog.js +0 -138
- package/dist/esm/restricted/dialog.js.map +0 -1
- package/dist/esm/restricted/getBip32Entropy.js +0 -67
- package/dist/esm/restricted/getBip32Entropy.js.map +0 -1
- package/dist/esm/restricted/getBip32PublicKey.js +0 -79
- package/dist/esm/restricted/getBip32PublicKey.js.map +0 -1
- package/dist/esm/restricted/getBip44Entropy.js +0 -69
- package/dist/esm/restricted/getBip44Entropy.js.map +0 -1
- package/dist/esm/restricted/getEntropy.js +0 -58
- package/dist/esm/restricted/getEntropy.js.map +0 -1
- package/dist/esm/restricted/getLocale.js +0 -42
- package/dist/esm/restricted/getLocale.js.map +0 -1
- package/dist/esm/restricted/index.js +0 -27
- package/dist/esm/restricted/index.js.map +0 -1
- package/dist/esm/restricted/invokeSnap.js +0 -89
- package/dist/esm/restricted/invokeSnap.js.map +0 -1
- package/dist/esm/restricted/manageAccounts.js +0 -60
- package/dist/esm/restricted/manageAccounts.js.map +0 -1
- package/dist/esm/restricted/manageState.js +0 -225
- package/dist/esm/restricted/manageState.js.map +0 -1
- package/dist/esm/restricted/notify.js +0 -92
- package/dist/esm/restricted/notify.js.map +0 -1
- package/dist/esm/utils.js +0 -124
- package/dist/esm/utils.js.map +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { providerErrors, rpcErrors } from '@metamask/rpc-errors';
|
|
2
|
-
import { SnapCaveatType, Bip32EntropyStruct, isEqual } from '@metamask/snaps-utils';
|
|
3
|
-
import { assertStruct } from '@metamask/utils';
|
|
4
|
-
import { array, size, type } from 'superstruct';
|
|
5
|
-
/**
|
|
6
|
-
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
7
|
-
* Note that this function does not do any validation, that's handled by the
|
|
8
|
-
* PermissionsController when the permission is requested.
|
|
9
|
-
*
|
|
10
|
-
* @param value - The raw value from the `initialPermissions`.
|
|
11
|
-
* @returns The caveat specification.
|
|
12
|
-
*/ export function permittedDerivationPathsCaveatMapper(value) {
|
|
13
|
-
return {
|
|
14
|
-
caveats: [
|
|
15
|
-
{
|
|
16
|
-
type: SnapCaveatType.PermittedDerivationPaths,
|
|
17
|
-
value
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Validate a caveat path object. The object must consist of a `path` array and
|
|
24
|
-
* a `curve` string. Paths must start with `m`, and must contain at
|
|
25
|
-
* least two indices. If `ed25519` is used, this checks if all the path indices
|
|
26
|
-
* are hardened.
|
|
27
|
-
*
|
|
28
|
-
* @param value - The value to validate.
|
|
29
|
-
* @throws If the value is invalid.
|
|
30
|
-
*/ export function validateBIP32Path(value) {
|
|
31
|
-
assertStruct(value, Bip32EntropyStruct, 'Invalid BIP-32 entropy path definition', rpcErrors.invalidParams);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Validate the path values associated with a caveat. This validates that the
|
|
35
|
-
* value is a non-empty array with valid derivation paths and curves.
|
|
36
|
-
*
|
|
37
|
-
* @param caveat - The caveat to validate.
|
|
38
|
-
* @throws If the value is invalid.
|
|
39
|
-
*/ export function validateBIP32CaveatPaths(caveat) {
|
|
40
|
-
assertStruct(caveat, type({
|
|
41
|
-
value: size(array(Bip32EntropyStruct), 1, Infinity)
|
|
42
|
-
}), 'Invalid BIP-32 entropy caveat', rpcErrors.internal);
|
|
43
|
-
}
|
|
44
|
-
export const PermittedDerivationPathsCaveatSpecification = {
|
|
45
|
-
[SnapCaveatType.PermittedDerivationPaths]: Object.freeze({
|
|
46
|
-
type: SnapCaveatType.PermittedDerivationPaths,
|
|
47
|
-
decorator: (method, caveat)=>{
|
|
48
|
-
return async (args)=>{
|
|
49
|
-
const { params } = args;
|
|
50
|
-
validateBIP32Path(params);
|
|
51
|
-
const path = caveat.value.find((caveatPath)=>isEqual(params.path.slice(0, caveatPath.path.length), caveatPath.path) && caveatPath.curve === params.curve);
|
|
52
|
-
if (!path) {
|
|
53
|
-
throw providerErrors.unauthorized({
|
|
54
|
-
message: 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.'
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
return await method(args);
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
validator: (caveat)=>validateBIP32CaveatPaths(caveat)
|
|
61
|
-
})
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=permittedDerivationPaths.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/restricted/caveats/permittedDerivationPaths.ts"],"sourcesContent":["import type {\n Caveat,\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Bip32Entropy } from '@metamask/snaps-utils';\nimport {\n SnapCaveatType,\n Bip32EntropyStruct,\n isEqual,\n} from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { array, size, type } from 'superstruct';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function permittedDerivationPathsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedDerivationPaths,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate a caveat path object. The object must consist of a `path` array and\n * a `curve` string. Paths must start with `m`, and must contain at\n * least two indices. If `ed25519` is used, this checks if all the path indices\n * are hardened.\n *\n * @param value - The value to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32Path(\n value: unknown,\n): asserts value is Bip32Entropy {\n assertStruct(\n value,\n Bip32EntropyStruct,\n 'Invalid BIP-32 entropy path definition',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Validate the path values associated with a caveat. This validates that the\n * value is a non-empty array with valid derivation paths and curves.\n *\n * @param caveat - The caveat to validate.\n * @throws If the value is invalid.\n */\nexport function validateBIP32CaveatPaths(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, Bip32Entropy[]> {\n assertStruct(\n caveat,\n type({ value: size(array(Bip32EntropyStruct), 1, Infinity) }),\n 'Invalid BIP-32 entropy caveat',\n rpcErrors.internal,\n );\n}\n\nexport const PermittedDerivationPathsCaveatSpecification: Record<\n SnapCaveatType.PermittedDerivationPaths,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedDerivationPaths]: Object.freeze({\n type: SnapCaveatType.PermittedDerivationPaths,\n decorator: (\n method,\n caveat: Caveat<SnapCaveatType.PermittedDerivationPaths, Bip32Entropy[]>,\n ) => {\n return async (args) => {\n const { params } = args;\n validateBIP32Path(params);\n\n const path = caveat.value.find(\n (caveatPath) =>\n isEqual(\n params.path.slice(0, caveatPath.path.length),\n caveatPath.path,\n ) && caveatPath.curve === params.curve,\n );\n\n if (!path) {\n throw providerErrors.unauthorized({\n message:\n 'The requested path is not permitted. Allowed paths must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP32CaveatPaths(caveat),\n }),\n};\n"],"names":["providerErrors","rpcErrors","SnapCaveatType","Bip32EntropyStruct","isEqual","assertStruct","array","size","type","permittedDerivationPathsCaveatMapper","value","caveats","PermittedDerivationPaths","validateBIP32Path","invalidParams","validateBIP32CaveatPaths","caveat","Infinity","internal","PermittedDerivationPathsCaveatSpecification","Object","freeze","decorator","method","args","params","path","find","caveatPath","slice","length","curve","unauthorized","message","validator"],"mappings":"AAKA,SAASA,cAAc,EAAEC,SAAS,QAAQ,uBAAuB;AAEjE,SACEC,cAAc,EACdC,kBAAkB,EAClBC,OAAO,QACF,wBAAwB;AAE/B,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,KAAK,EAAEC,IAAI,EAAEC,IAAI,QAAQ,cAAc;AAEhD;;;;;;;CAOC,GACD,OAAO,SAASC,qCACdC,KAAW;IAEX,OAAO;QACLC,SAAS;YACP;gBACEH,MAAMN,eAAeU,wBAAwB;gBAC7CF;YACF;SACD;IACH;AACF;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASG,kBACdH,KAAc;IAEdL,aACEK,OACAP,oBACA,0CACAF,UAAUa,aAAa;AAE3B;AAEA;;;;;;CAMC,GACD,OAAO,SAASC,yBACdC,MAA2B;IAE3BX,aACEW,QACAR,KAAK;QAAEE,OAAOH,KAAKD,MAAMH,qBAAqB,GAAGc;IAAU,IAC3D,iCACAhB,UAAUiB,QAAQ;AAEtB;AAEA,OAAO,MAAMC,8CAGT;IACF,CAACjB,eAAeU,wBAAwB,CAAC,EAAEQ,OAAOC,MAAM,CAAC;QACvDb,MAAMN,eAAeU,wBAAwB;QAC7CU,WAAW,CACTC,QACAP;YAEA,OAAO,OAAOQ;gBACZ,MAAM,EAAEC,MAAM,EAAE,GAAGD;gBACnBX,kBAAkBY;gBAElB,MAAMC,OAAOV,OAAON,KAAK,CAACiB,IAAI,CAC5B,CAACC,aACCxB,QACEqB,OAAOC,IAAI,CAACG,KAAK,CAAC,GAAGD,WAAWF,IAAI,CAACI,MAAM,GAC3CF,WAAWF,IAAI,KACZE,WAAWG,KAAK,KAAKN,OAAOM,KAAK;gBAG1C,IAAI,CAACL,MAAM;oBACT,MAAM1B,eAAegC,YAAY,CAAC;wBAChCC,SACE;oBACJ;gBACF;gBAEA,OAAO,MAAMV,OAAOC;YACtB;QACF;QACAU,WAAW,CAAClB,SAAWD,yBAAyBC;IAClD;AACF,EAAE"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { rpcErrors } from '@metamask/rpc-errors';
|
|
2
|
-
import { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils';
|
|
3
|
-
import { hasProperty, assertStruct } from '@metamask/utils';
|
|
4
|
-
import { type } from 'superstruct';
|
|
5
|
-
/**
|
|
6
|
-
* Map a raw value from the `initialPermissions` to a caveat specification.
|
|
7
|
-
* Note that this function does not do any validation, that's handled by the
|
|
8
|
-
* PermissionsController when the permission is requested.
|
|
9
|
-
*
|
|
10
|
-
* @param value - The raw value from the `initialPermissions`.
|
|
11
|
-
* @returns The caveat specification.
|
|
12
|
-
*/ export function snapIdsCaveatMapper(value) {
|
|
13
|
-
return {
|
|
14
|
-
caveats: [
|
|
15
|
-
{
|
|
16
|
-
type: SnapCaveatType.SnapIds,
|
|
17
|
-
value
|
|
18
|
-
}
|
|
19
|
-
]
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Validates that the caveat value exists and is a non-empty object.
|
|
24
|
-
*
|
|
25
|
-
* @param caveat - The caveat to validate.
|
|
26
|
-
* @throws If the caveat is invalid.
|
|
27
|
-
*/ export function validateSnapIdsCaveat(caveat) {
|
|
28
|
-
assertStruct(caveat, type({
|
|
29
|
-
value: SnapIdsStruct
|
|
30
|
-
}), 'Expected caveat to have a value property of a non-empty object of snap IDs.', rpcErrors.invalidParams);
|
|
31
|
-
}
|
|
32
|
-
export const SnapIdsCaveatSpecification = {
|
|
33
|
-
[SnapCaveatType.SnapIds]: Object.freeze({
|
|
34
|
-
type: SnapCaveatType.SnapIds,
|
|
35
|
-
validator: (caveat)=>validateSnapIdsCaveat(caveat),
|
|
36
|
-
decorator: (method, caveat)=>{
|
|
37
|
-
return async (args)=>{
|
|
38
|
-
const { params, context: { origin } } = args;
|
|
39
|
-
const snapIds = caveat.value;
|
|
40
|
-
const { snapId } = params;
|
|
41
|
-
if (!hasProperty(snapIds, snapId)) {
|
|
42
|
-
throw new Error(`${origin} does not have permission to invoke ${snapId} snap.`);
|
|
43
|
-
}
|
|
44
|
-
return await method(args);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=snapIds.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/restricted/caveats/snapIds.ts"],"sourcesContent":["import type {\n Caveat,\n RestrictedMethodOptions,\n RestrictedMethodParameters,\n RestrictedMethodCaveatSpecificationConstraint,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { SnapIds } from '@metamask/snaps-utils';\nimport { SnapCaveatType, SnapIdsStruct } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, assertStruct } from '@metamask/utils';\nimport { type } from 'superstruct';\n\nimport type { InvokeSnapParams } from '../invokeSnap';\n\n/**\n * Map a raw value from the `initialPermissions` to a caveat specification.\n * Note that this function does not do any validation, that's handled by the\n * PermissionsController when the permission is requested.\n *\n * @param value - The raw value from the `initialPermissions`.\n * @returns The caveat specification.\n */\nexport function snapIdsCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.SnapIds,\n value,\n },\n ],\n };\n}\n\n/**\n * Validates that the caveat value exists and is a non-empty object.\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat is invalid.\n */\nexport function validateSnapIdsCaveat(\n caveat: Caveat<string, any>,\n): asserts caveat is Caveat<string, SnapIds> {\n assertStruct(\n caveat,\n type({\n value: SnapIdsStruct,\n }),\n 'Expected caveat to have a value property of a non-empty object of snap IDs.',\n rpcErrors.invalidParams,\n );\n}\n\nexport const SnapIdsCaveatSpecification: Record<\n SnapCaveatType.SnapIds,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.SnapIds]: Object.freeze({\n type: SnapCaveatType.SnapIds,\n validator: (caveat) => validateSnapIdsCaveat(caveat),\n decorator: (method, caveat) => {\n return async (args) => {\n const {\n params,\n context: { origin },\n }: RestrictedMethodOptions<RestrictedMethodParameters> = args;\n const snapIds = caveat.value;\n const { snapId } = params as InvokeSnapParams;\n if (!hasProperty(snapIds, snapId)) {\n throw new Error(\n `${origin} does not have permission to invoke ${snapId} snap.`,\n );\n }\n return await method(args);\n };\n },\n }),\n};\n"],"names":["rpcErrors","SnapCaveatType","SnapIdsStruct","hasProperty","assertStruct","type","snapIdsCaveatMapper","value","caveats","SnapIds","validateSnapIdsCaveat","caveat","invalidParams","SnapIdsCaveatSpecification","Object","freeze","validator","decorator","method","args","params","context","origin","snapIds","snapId","Error"],"mappings":"AAOA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,cAAc,EAAEC,aAAa,QAAQ,wBAAwB;AAEtE,SAASC,WAAW,EAAEC,YAAY,QAAQ,kBAAkB;AAC5D,SAASC,IAAI,QAAQ,cAAc;AAInC;;;;;;;CAOC,GACD,OAAO,SAASC,oBACdC,KAAW;IAEX,OAAO;QACLC,SAAS;YACP;gBACEH,MAAMJ,eAAeQ,OAAO;gBAC5BF;YACF;SACD;IACH;AACF;AAEA;;;;;CAKC,GACD,OAAO,SAASG,sBACdC,MAA2B;IAE3BP,aACEO,QACAN,KAAK;QACHE,OAAOL;IACT,IACA,+EACAF,UAAUY,aAAa;AAE3B;AAEA,OAAO,MAAMC,6BAGT;IACF,CAACZ,eAAeQ,OAAO,CAAC,EAAEK,OAAOC,MAAM,CAAC;QACtCV,MAAMJ,eAAeQ,OAAO;QAC5BO,WAAW,CAACL,SAAWD,sBAAsBC;QAC7CM,WAAW,CAACC,QAAQP;YAClB,OAAO,OAAOQ;gBACZ,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAwDH;gBACzD,MAAMI,UAAUZ,OAAOJ,KAAK;gBAC5B,MAAM,EAAEiB,MAAM,EAAE,GAAGJ;gBACnB,IAAI,CAACjB,YAAYoB,SAASC,SAAS;oBACjC,MAAM,IAAIC,MACR,CAAC,EAAEH,OAAO,oCAAoC,EAAEE,OAAO,MAAM,CAAC;gBAElE;gBACA,OAAO,MAAMN,OAAOC;YACtB;QACF;IACF;AACF,EAAE"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
2
|
-
import { rpcErrors } from '@metamask/rpc-errors';
|
|
3
|
-
import { DialogType, ComponentStruct, enumValue } from '@metamask/snaps-sdk';
|
|
4
|
-
import { validateComponentLinks } from '@metamask/snaps-utils';
|
|
5
|
-
import { create, enums, object, optional, size, string, StructError, type, union } from 'superstruct';
|
|
6
|
-
const methodName = 'snap_dialog';
|
|
7
|
-
const PlaceholderStruct = optional(size(string(), 1, 40));
|
|
8
|
-
/**
|
|
9
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
10
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
11
|
-
* - An alert, for displaying information.
|
|
12
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
13
|
-
* - A prompt, for inputting some information.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The specification builder options.
|
|
16
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
17
|
-
* permission.
|
|
18
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
19
|
-
* implementation.
|
|
20
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
21
|
-
*/ const specificationBuilder = ({ allowedCaveats = null, methodHooks })=>{
|
|
22
|
-
return {
|
|
23
|
-
permissionType: PermissionType.RestrictedMethod,
|
|
24
|
-
targetName: methodName,
|
|
25
|
-
allowedCaveats,
|
|
26
|
-
methodImplementation: getDialogImplementation(methodHooks),
|
|
27
|
-
subjectTypes: [
|
|
28
|
-
SubjectType.Snap
|
|
29
|
-
]
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
const methodHooks = {
|
|
33
|
-
showDialog: true,
|
|
34
|
-
isOnPhishingList: true,
|
|
35
|
-
maybeUpdatePhishingList: true
|
|
36
|
-
};
|
|
37
|
-
export const dialogBuilder = Object.freeze({
|
|
38
|
-
targetName: methodName,
|
|
39
|
-
specificationBuilder,
|
|
40
|
-
methodHooks
|
|
41
|
-
});
|
|
42
|
-
// Note: We use `type` here instead of `object` because `type` does not validate
|
|
43
|
-
// the keys of the object, which is what we want.
|
|
44
|
-
const BaseParamsStruct = type({
|
|
45
|
-
type: enums([
|
|
46
|
-
DialogType.Alert,
|
|
47
|
-
DialogType.Confirmation,
|
|
48
|
-
DialogType.Prompt
|
|
49
|
-
])
|
|
50
|
-
});
|
|
51
|
-
const AlertParametersStruct = object({
|
|
52
|
-
type: enumValue(DialogType.Alert),
|
|
53
|
-
content: ComponentStruct
|
|
54
|
-
});
|
|
55
|
-
const ConfirmationParametersStruct = object({
|
|
56
|
-
type: enumValue(DialogType.Confirmation),
|
|
57
|
-
content: ComponentStruct
|
|
58
|
-
});
|
|
59
|
-
const PromptParametersStruct = object({
|
|
60
|
-
type: enumValue(DialogType.Prompt),
|
|
61
|
-
content: ComponentStruct,
|
|
62
|
-
placeholder: PlaceholderStruct
|
|
63
|
-
});
|
|
64
|
-
const DialogParametersStruct = union([
|
|
65
|
-
AlertParametersStruct,
|
|
66
|
-
ConfirmationParametersStruct,
|
|
67
|
-
PromptParametersStruct
|
|
68
|
-
]);
|
|
69
|
-
const structs = {
|
|
70
|
-
[DialogType.Alert]: AlertParametersStruct,
|
|
71
|
-
[DialogType.Confirmation]: ConfirmationParametersStruct,
|
|
72
|
-
[DialogType.Prompt]: PromptParametersStruct
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Builds the method implementation for `snap_dialog`.
|
|
76
|
-
*
|
|
77
|
-
* @param hooks - The RPC method hooks.
|
|
78
|
-
* @param hooks.showDialog - A function that shows the specified dialog in the
|
|
79
|
-
* MetaMask UI and returns the appropriate value for the dialog type.
|
|
80
|
-
* @param hooks.isOnPhishingList - A function that checks a link against the
|
|
81
|
-
* phishing list and return true if it's in, otherwise false.
|
|
82
|
-
* @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
83
|
-
* @returns The method implementation which return value depends on the dialog
|
|
84
|
-
* type, valid return types are: string, boolean, null.
|
|
85
|
-
*/ export function getDialogImplementation({ showDialog, isOnPhishingList, maybeUpdatePhishingList }) {
|
|
86
|
-
return async function dialogImplementation(args) {
|
|
87
|
-
const { params, context: { origin } } = args;
|
|
88
|
-
const validatedType = getValidatedType(params);
|
|
89
|
-
const validatedParams = getValidatedParams(params, structs[validatedType]);
|
|
90
|
-
const { content } = validatedParams;
|
|
91
|
-
await maybeUpdatePhishingList();
|
|
92
|
-
validateComponentLinks(content, isOnPhishingList);
|
|
93
|
-
const placeholder = validatedParams.type === DialogType.Prompt ? validatedParams.placeholder : undefined;
|
|
94
|
-
return showDialog(origin, validatedType, content, placeholder);
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get the validated type of the dialog parameters. Throws an error if the type
|
|
99
|
-
* is invalid.
|
|
100
|
-
*
|
|
101
|
-
* @param params - The parameters to validate.
|
|
102
|
-
* @returns The validated type of the dialog parameters.
|
|
103
|
-
*/ function getValidatedType(params) {
|
|
104
|
-
try {
|
|
105
|
-
return create(params, BaseParamsStruct).type;
|
|
106
|
-
} catch (error) {
|
|
107
|
-
throw rpcErrors.invalidParams({
|
|
108
|
-
message: `The "type" property must be one of: ${Object.values(DialogType).join(', ')}.`
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Validates the confirm method `params` and returns them cast to the correct
|
|
114
|
-
* type. Throws if validation fails.
|
|
115
|
-
*
|
|
116
|
-
* @param params - The unvalidated params object from the method request.
|
|
117
|
-
* @param struct - The struct to validate the params against.
|
|
118
|
-
* @returns The validated confirm method parameter object.
|
|
119
|
-
*/ function getValidatedParams(params, struct) {
|
|
120
|
-
try {
|
|
121
|
-
return create(params, struct);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
if (error instanceof StructError) {
|
|
124
|
-
const { key, type: errorType } = error;
|
|
125
|
-
if (key === 'placeholder' && errorType === 'never') {
|
|
126
|
-
throw rpcErrors.invalidParams({
|
|
127
|
-
message: 'Invalid params: Alerts or confirmations may not specify a "placeholder" field.'
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
throw rpcErrors.invalidParams({
|
|
131
|
-
message: `Invalid params: ${error.message}.`
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
/* istanbul ignore next */ throw rpcErrors.internal();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
//# sourceMappingURL=dialog.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/restricted/dialog.ts"],"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 { DialogType, ComponentStruct, enumValue } from '@metamask/snaps-sdk';\nimport type { DialogParams, EnumToUnion, Component } from '@metamask/snaps-sdk';\nimport { validateComponentLinks } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n StructError,\n type,\n union,\n} from 'superstruct';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype ShowDialog = (\n snapId: string,\n type: EnumToUnion<DialogType>,\n content: Component,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\n\ntype MaybeUpdatePhisingList = () => Promise<void>;\ntype IsOnPhishingList = (url: string) => boolean;\n\nexport type DialogMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the alert.\n * @param type - The dialog type.\n * @param content - The dialog custom UI.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\n\n maybeUpdatePhishingList: MaybeUpdatePhisingList;\n\n /**\n * @param url - The URL to check against the phishing list.\n */\n isOnPhishingList: IsOnPhishingList;\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 showDialog: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n// Note: We use `type` here instead of `object` because `type` does not validate\n// the keys of the object, which is what we want.\nconst BaseParamsStruct = type({\n type: enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\n});\n\nconst AlertParametersStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentStruct,\n});\n\nconst ConfirmationParametersStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentStruct,\n});\n\nconst PromptParametersStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs = {\n [DialogType.Alert]: AlertParametersStruct,\n [DialogType.Confirmation]: ConfirmationParametersStruct,\n [DialogType.Prompt]: PromptParametersStruct,\n};\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showDialog - A function that shows the specified dialog in the\n * MetaMask UI and returns the appropriate value for the dialog type.\n * @param hooks.isOnPhishingList - A function that checks a link against the\n * phishing list and return true if it's in, otherwise false.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\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 showDialog,\n isOnPhishingList,\n maybeUpdatePhishingList,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedType = getValidatedType(params);\n const validatedParams = getValidatedParams(params, structs[validatedType]);\n\n const { content } = validatedParams;\n\n await maybeUpdatePhishingList();\n\n validateComponentLinks(content, isOnPhishingList);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\n ? validatedParams.placeholder\n : undefined;\n\n return showDialog(origin, validatedType, content, placeholder);\n };\n}\n\n/**\n * Get the validated type of the dialog parameters. Throws an error if the type\n * is invalid.\n *\n * @param params - The parameters to validate.\n * @returns The validated type of the dialog parameters.\n */\nfunction getValidatedType(params: unknown): DialogType {\n try {\n return create(params, BaseParamsStruct).type;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `The \"type\" property must be one of: ${Object.values(\n DialogType,\n ).join(', ')}.`,\n });\n }\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 * @param struct - The struct to validate the params against.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n struct: Struct<any>,\n): DialogParameters {\n try {\n return create(params, struct);\n } catch (error) {\n if (error instanceof StructError) {\n const { key, type: errorType } = error;\n\n if (key === 'placeholder' && errorType === 'never') {\n throw rpcErrors.invalidParams({\n message:\n 'Invalid params: Alerts or confirmations may not specify a \"placeholder\" field.',\n });\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","DialogType","ComponentStruct","enumValue","validateComponentLinks","create","enums","object","optional","size","string","StructError","type","union","methodName","PlaceholderStruct","specificationBuilder","allowedCaveats","methodHooks","permissionType","RestrictedMethod","targetName","methodImplementation","getDialogImplementation","subjectTypes","Snap","showDialog","isOnPhishingList","maybeUpdatePhishingList","dialogBuilder","Object","freeze","BaseParamsStruct","Alert","Confirmation","Prompt","AlertParametersStruct","content","ConfirmationParametersStruct","PromptParametersStruct","placeholder","DialogParametersStruct","structs","dialogImplementation","args","params","context","origin","validatedType","getValidatedType","validatedParams","getValidatedParams","undefined","error","invalidParams","message","values","join","struct","key","errorType","internal"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AACjD,SAASC,UAAU,EAAEC,eAAe,EAAEC,SAAS,QAAQ,sBAAsB;AAE7E,SAASC,sBAAsB,QAAQ,wBAAwB;AAI/D,SACEC,MAAM,EACNC,KAAK,EACLC,MAAM,EACNC,QAAQ,EACRC,IAAI,EACJC,MAAM,EACNC,WAAW,EACXC,IAAI,EACJC,KAAK,QACA,cAAc;AAIrB,MAAMC,aAAa;AAEnB,MAAMC,oBAAoBP,SAASC,KAAKC,UAAU,GAAG;AA2CrD;;;;;;;;;;;;;CAaC,GACD,MAAMM,uBAIF,CAAC,EACHC,iBAAiB,IAAI,EACrBC,WAAW,EACuB;IAClC,OAAO;QACLC,gBAAgBrB,eAAesB,gBAAgB;QAC/CC,YAAYP;QACZG;QACAK,sBAAsBC,wBAAwBL;QAC9CM,cAAc;YAACzB,YAAY0B,IAAI;SAAC;IAClC;AACF;AAEA,MAAMP,cAAoD;IACxDQ,YAAY;IACZC,kBAAkB;IAClBC,yBAAyB;AAC3B;AAEA,OAAO,MAAMC,gBAAgBC,OAAOC,MAAM,CAAC;IACzCV,YAAYP;IACZE;IACAE;AACF,GAAY;AAEZ,gFAAgF;AAChF,iDAAiD;AACjD,MAAMc,mBAAmBpB,KAAK;IAC5BA,MAAMN,MAAM;QAACL,WAAWgC,KAAK;QAAEhC,WAAWiC,YAAY;QAAEjC,WAAWkC,MAAM;KAAC;AAC5E;AAEA,MAAMC,wBAAwB7B,OAAO;IACnCK,MAAMT,UAAUF,WAAWgC,KAAK;IAChCI,SAASnC;AACX;AAEA,MAAMoC,+BAA+B/B,OAAO;IAC1CK,MAAMT,UAAUF,WAAWiC,YAAY;IACvCG,SAASnC;AACX;AAEA,MAAMqC,yBAAyBhC,OAAO;IACpCK,MAAMT,UAAUF,WAAWkC,MAAM;IACjCE,SAASnC;IACTsC,aAAazB;AACf;AAEA,MAAM0B,yBAAyB5B,MAAM;IACnCuB;IACAE;IACAC;CACD;AAOD,MAAMG,UAAU;IACd,CAACzC,WAAWgC,KAAK,CAAC,EAAEG;IACpB,CAACnC,WAAWiC,YAAY,CAAC,EAAEI;IAC3B,CAACrC,WAAWkC,MAAM,CAAC,EAAEI;AACvB;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAAShB,wBAAwB,EACtCG,UAAU,EACVC,gBAAgB,EAChBC,uBAAuB,EACL;IAClB,OAAO,eAAee,qBACpBC,IAA+C;QAE/C,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAGH;QAEJ,MAAMI,gBAAgBC,iBAAiBJ;QACvC,MAAMK,kBAAkBC,mBAAmBN,QAAQH,OAAO,CAACM,cAAc;QAEzE,MAAM,EAAEX,OAAO,EAAE,GAAGa;QAEpB,MAAMtB;QAENxB,uBAAuBiC,SAASV;QAEhC,MAAMa,cACJU,gBAAgBtC,IAAI,KAAKX,WAAWkC,MAAM,GACtCe,gBAAgBV,WAAW,GAC3BY;QAEN,OAAO1B,WAAWqB,QAAQC,eAAeX,SAASG;IACpD;AACF;AAEA;;;;;;CAMC,GACD,SAASS,iBAAiBJ,MAAe;IACvC,IAAI;QACF,OAAOxC,OAAOwC,QAAQb,kBAAkBpB,IAAI;IAC9C,EAAE,OAAOyC,OAAO;QACd,MAAMrD,UAAUsD,aAAa,CAAC;YAC5BC,SAAS,CAAC,oCAAoC,EAAEzB,OAAO0B,MAAM,CAC3DvD,YACAwD,IAAI,CAAC,MAAM,CAAC,CAAC;QACjB;IACF;AACF;AAEA;;;;;;;CAOC,GACD,SAASN,mBACPN,MAAe,EACfa,MAAmB;IAEnB,IAAI;QACF,OAAOrD,OAAOwC,QAAQa;IACxB,EAAE,OAAOL,OAAO;QACd,IAAIA,iBAAiB1C,aAAa;YAChC,MAAM,EAAEgD,GAAG,EAAE/C,MAAMgD,SAAS,EAAE,GAAGP;YAEjC,IAAIM,QAAQ,iBAAiBC,cAAc,SAAS;gBAClD,MAAM5D,UAAUsD,aAAa,CAAC;oBAC5BC,SACE;gBACJ;YACF;YAEA,MAAMvD,UAAUsD,aAAa,CAAC;gBAC5BC,SAAS,CAAC,gBAAgB,EAAEF,MAAME,OAAO,CAAC,CAAC,CAAC;YAC9C;QACF;QAEA,wBAAwB,GACxB,MAAMvD,UAAU6D,QAAQ;IAC1B;AACF"}
|
|
@@ -1,67 +0,0 @@
|
|
|
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';
|
|
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
|
-
*/ const specificationBuilder = ({ methodHooks })=>{
|
|
16
|
-
return {
|
|
17
|
-
permissionType: PermissionType.RestrictedMethod,
|
|
18
|
-
targetName,
|
|
19
|
-
allowedCaveats: [
|
|
20
|
-
SnapCaveatType.PermittedDerivationPaths
|
|
21
|
-
],
|
|
22
|
-
methodImplementation: getBip32EntropyImplementation(methodHooks),
|
|
23
|
-
validator: ({ caveats })=>{
|
|
24
|
-
if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedDerivationPaths) {
|
|
25
|
-
throw rpcErrors.invalidParams({
|
|
26
|
-
message: `Expected a single "${SnapCaveatType.PermittedDerivationPaths}" caveat.`
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
subjectTypes: [
|
|
31
|
-
SubjectType.Snap
|
|
32
|
-
]
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const methodHooks = {
|
|
36
|
-
getMnemonic: true,
|
|
37
|
-
getUnlockPromise: true
|
|
38
|
-
};
|
|
39
|
-
export const getBip32EntropyBuilder = Object.freeze({
|
|
40
|
-
targetName,
|
|
41
|
-
specificationBuilder,
|
|
42
|
-
methodHooks
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* Builds the method implementation for `snap_getBip32Entropy`.
|
|
46
|
-
*
|
|
47
|
-
* @param hooks - The RPC method hooks.
|
|
48
|
-
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
49
|
-
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
50
|
-
* and prompts the user to unlock their MetaMask if it is locked.
|
|
51
|
-
* @returns The method implementation which returns a `JsonSLIP10Node`.
|
|
52
|
-
* @throws If the params are invalid.
|
|
53
|
-
*/ export function getBip32EntropyImplementation({ getMnemonic, getUnlockPromise }) {
|
|
54
|
-
return async function getBip32Entropy(args) {
|
|
55
|
-
await getUnlockPromise(true);
|
|
56
|
-
const { params } = args;
|
|
57
|
-
assert(params);
|
|
58
|
-
const node = await getNode({
|
|
59
|
-
curve: params.curve,
|
|
60
|
-
path: params.path,
|
|
61
|
-
secretRecoveryPhrase: await getMnemonic()
|
|
62
|
-
});
|
|
63
|
-
return node.toJSON();
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
//# sourceMappingURL=getBip32Entropy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/restricted/getBip32Entropy.ts"],"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"],"names":["PermissionType","SubjectType","rpcErrors","SnapCaveatType","assert","getNode","targetName","specificationBuilder","methodHooks","permissionType","RestrictedMethod","allowedCaveats","PermittedDerivationPaths","methodImplementation","getBip32EntropyImplementation","validator","caveats","length","type","invalidParams","message","subjectTypes","Snap","getMnemonic","getUnlockPromise","getBip32EntropyBuilder","Object","freeze","getBip32Entropy","args","params","node","curve","path","secretRecoveryPhrase","toJSON"],"mappings":"AAMA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,SAASC,cAAc,QAAQ,wBAAwB;AAEvD,SAASC,MAAM,QAAQ,kBAAkB;AAGzC,SAASC,OAAO,QAAQ,WAAW;AAEnC,MAAMC,aAAa;AA4BnB;;;;;;;;CAQC,GACD,MAAMC,uBAIF,CAAC,EAAEC,WAAW,EAA8C;IAC9D,OAAO;QACLC,gBAAgBT,eAAeU,gBAAgB;QAC/CJ;QACAK,gBAAgB;YAACR,eAAeS,wBAAwB;SAAC;QACzDC,sBAAsBC,8BAA8BN;QACpDO,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKf,eAAeS,wBAAwB,EAC3D;gBACA,MAAMV,UAAUiB,aAAa,CAAC;oBAC5BC,SAAS,CAAC,mBAAmB,EAAEjB,eAAeS,wBAAwB,CAAC,SAAS,CAAC;gBACnF;YACF;QACF;QACAS,cAAc;YAACpB,YAAYqB,IAAI;SAAC;IAClC;AACF;AAEA,MAAMd,cAA6D;IACjEe,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,yBAAyBC,OAAOC,MAAM,CAAC;IAClDrB;IACAC;IACAC;AACF,GAAY;AAEZ;;;;;;;;;CASC,GACD,OAAO,SAASM,8BAA8B,EAC5CS,WAAW,EACXC,gBAAgB,EACW;IAC3B,OAAO,eAAeI,gBACpBC,IAAoD;QAEpD,MAAML,iBAAiB;QAEvB,MAAM,EAAEM,MAAM,EAAE,GAAGD;QACnBzB,OAAO0B;QAEP,MAAMC,OAAO,MAAM1B,QAAQ;YACzB2B,OAAOF,OAAOE,KAAK;YACnBC,MAAMH,OAAOG,IAAI;YACjBC,sBAAsB,MAAMX;QAC9B;QAEA,OAAOQ,KAAKI,MAAM;IACpB;AACF"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
2
|
-
import { rpcErrors } from '@metamask/rpc-errors';
|
|
3
|
-
import { bip32entropy, Bip32PathStruct, SnapCaveatType } from '@metamask/snaps-utils';
|
|
4
|
-
import { assertStruct } from '@metamask/utils';
|
|
5
|
-
import { boolean, enums, object, optional } from 'superstruct';
|
|
6
|
-
import { getNode } from '../utils';
|
|
7
|
-
const targetName = 'snap_getBip32PublicKey';
|
|
8
|
-
export const Bip32PublicKeyArgsStruct = bip32entropy(object({
|
|
9
|
-
path: Bip32PathStruct,
|
|
10
|
-
curve: enums([
|
|
11
|
-
'ed25519',
|
|
12
|
-
'secp256k1'
|
|
13
|
-
]),
|
|
14
|
-
compressed: optional(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
|
-
*/ const specificationBuilder = ({ methodHooks })=>{
|
|
25
|
-
return {
|
|
26
|
-
permissionType: PermissionType.RestrictedMethod,
|
|
27
|
-
targetName,
|
|
28
|
-
allowedCaveats: [
|
|
29
|
-
SnapCaveatType.PermittedDerivationPaths
|
|
30
|
-
],
|
|
31
|
-
methodImplementation: getBip32PublicKeyImplementation(methodHooks),
|
|
32
|
-
validator: ({ caveats })=>{
|
|
33
|
-
if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedDerivationPaths) {
|
|
34
|
-
throw rpcErrors.invalidParams({
|
|
35
|
-
message: `Expected a single "${SnapCaveatType.PermittedDerivationPaths}" caveat.`
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
subjectTypes: [
|
|
40
|
-
SubjectType.Snap
|
|
41
|
-
]
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
const methodHooks = {
|
|
45
|
-
getMnemonic: true,
|
|
46
|
-
getUnlockPromise: true
|
|
47
|
-
};
|
|
48
|
-
export const getBip32PublicKeyBuilder = Object.freeze({
|
|
49
|
-
targetName,
|
|
50
|
-
specificationBuilder,
|
|
51
|
-
methodHooks
|
|
52
|
-
});
|
|
53
|
-
/**
|
|
54
|
-
* Builds the method implementation for `snap_getBip32PublicKey`.
|
|
55
|
-
*
|
|
56
|
-
* @param hooks - The RPC method hooks.
|
|
57
|
-
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase of the user.
|
|
58
|
-
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask extension is unlocked
|
|
59
|
-
* and prompts the user to unlock their MetaMask if it is locked.
|
|
60
|
-
* @returns The method implementation which returns a public key.
|
|
61
|
-
* @throws If the params are invalid.
|
|
62
|
-
*/ export function getBip32PublicKeyImplementation({ getMnemonic, getUnlockPromise }) {
|
|
63
|
-
return async function getBip32PublicKey(args) {
|
|
64
|
-
await getUnlockPromise(true);
|
|
65
|
-
assertStruct(args.params, Bip32PublicKeyArgsStruct, 'Invalid BIP-32 public key params', rpcErrors.invalidParams);
|
|
66
|
-
const { params } = args;
|
|
67
|
-
const node = await getNode({
|
|
68
|
-
curve: params.curve,
|
|
69
|
-
path: params.path,
|
|
70
|
-
secretRecoveryPhrase: await getMnemonic()
|
|
71
|
-
});
|
|
72
|
-
if (params.compressed) {
|
|
73
|
-
return node.compressedPublicKey;
|
|
74
|
-
}
|
|
75
|
-
return node.publicKey;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
//# sourceMappingURL=getBip32PublicKey.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/restricted/getBip32PublicKey.ts"],"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 SnapCaveatType,\n} from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport { boolean, enums, object, optional } from 'superstruct';\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: enums(['ed25519', 'secp256k1']),\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"],"names":["PermissionType","SubjectType","rpcErrors","bip32entropy","Bip32PathStruct","SnapCaveatType","assertStruct","boolean","enums","object","optional","getNode","targetName","Bip32PublicKeyArgsStruct","path","curve","compressed","specificationBuilder","methodHooks","permissionType","RestrictedMethod","allowedCaveats","PermittedDerivationPaths","methodImplementation","getBip32PublicKeyImplementation","validator","caveats","length","type","invalidParams","message","subjectTypes","Snap","getMnemonic","getUnlockPromise","getBip32PublicKeyBuilder","Object","freeze","getBip32PublicKey","args","params","node","secretRecoveryPhrase","compressedPublicKey","publicKey"],"mappings":"AAMA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,SACEC,YAAY,EACZC,eAAe,EACfC,cAAc,QACT,wBAAwB;AAE/B,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,OAAO,EAAEC,KAAK,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,cAAc;AAG/D,SAASC,OAAO,QAAQ,WAAW;AAEnC,MAAMC,aAAa;AA4BnB,OAAO,MAAMC,2BAA2BV,aACtCM,OAAO;IACLK,MAAMV;IACNW,OAAOP,MAAM;QAAC;QAAW;KAAY;IACrCQ,YAAYN,SAASH;AACvB,IACA;AAEF;;;;;;;;CAQC,GACD,MAAMU,uBAIF,CAAC,EAAEC,WAAW,EAAgD;IAChE,OAAO;QACLC,gBAAgBnB,eAAeoB,gBAAgB;QAC/CR;QACAS,gBAAgB;YAAChB,eAAeiB,wBAAwB;SAAC;QACzDC,sBAAsBC,gCAAgCN;QACtDO,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKvB,eAAeiB,wBAAwB,EAC3D;gBACA,MAAMpB,UAAU2B,aAAa,CAAC;oBAC5BC,SAAS,CAAC,mBAAmB,EAAEzB,eAAeiB,wBAAwB,CAAC,SAAS,CAAC;gBACnF;YACF;QACF;QACAS,cAAc;YAAC9B,YAAY+B,IAAI;SAAC;IAClC;AACF;AAEA,MAAMd,cAA+D;IACnEe,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,2BAA2BC,OAAOC,MAAM,CAAC;IACpDzB;IACAK;IACAC;AACF,GAAY;AAEZ;;;;;;;;;CASC,GACD,OAAO,SAASM,gCAAgC,EAC9CS,WAAW,EACXC,gBAAgB,EACa;IAC7B,OAAO,eAAeI,kBACpBC,IAAsD;QAEtD,MAAML,iBAAiB;QAEvB5B,aACEiC,KAAKC,MAAM,EACX3B,0BACA,oCACAX,UAAU2B,aAAa;QAGzB,MAAM,EAAEW,MAAM,EAAE,GAAGD;QACnB,MAAME,OAAO,MAAM9B,QAAQ;YACzBI,OAAOyB,OAAOzB,KAAK;YACnBD,MAAM0B,OAAO1B,IAAI;YACjB4B,sBAAsB,MAAMT;QAC9B;QAEA,IAAIO,OAAOxB,UAAU,EAAE;YACrB,OAAOyB,KAAKE,mBAAmB;QACjC;QAEA,OAAOF,KAAKG,SAAS;IACvB;AACF"}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { BIP44CoinTypeNode } from '@metamask/key-tree';
|
|
2
|
-
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
3
|
-
import { rpcErrors } from '@metamask/rpc-errors';
|
|
4
|
-
import { SnapCaveatType } from '@metamask/snaps-utils';
|
|
5
|
-
const targetName = 'snap_getBip44Entropy';
|
|
6
|
-
/**
|
|
7
|
-
* The specification builder for the `snap_getBip44Entropy` permission.
|
|
8
|
-
* `snap_getBip44Entropy_*` lets the Snap control private keys for a particular
|
|
9
|
-
* BIP-32 coin type.
|
|
10
|
-
*
|
|
11
|
-
* @param options - The specification builder options.
|
|
12
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
13
|
-
* implementation.
|
|
14
|
-
* @returns The specification for the `snap_getBip44Entropy` permission.
|
|
15
|
-
*/ const specificationBuilder = ({ methodHooks })=>{
|
|
16
|
-
return {
|
|
17
|
-
permissionType: PermissionType.RestrictedMethod,
|
|
18
|
-
targetName,
|
|
19
|
-
allowedCaveats: [
|
|
20
|
-
SnapCaveatType.PermittedCoinTypes
|
|
21
|
-
],
|
|
22
|
-
methodImplementation: getBip44EntropyImplementation(methodHooks),
|
|
23
|
-
validator: ({ caveats })=>{
|
|
24
|
-
if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.PermittedCoinTypes) {
|
|
25
|
-
throw rpcErrors.invalidParams({
|
|
26
|
-
message: `Expected a single "${SnapCaveatType.PermittedCoinTypes}" caveat.`
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
subjectTypes: [
|
|
31
|
-
SubjectType.Snap
|
|
32
|
-
]
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const methodHooks = {
|
|
36
|
-
getMnemonic: true,
|
|
37
|
-
getUnlockPromise: true
|
|
38
|
-
};
|
|
39
|
-
export const getBip44EntropyBuilder = Object.freeze({
|
|
40
|
-
targetName,
|
|
41
|
-
specificationBuilder,
|
|
42
|
-
methodHooks
|
|
43
|
-
});
|
|
44
|
-
/**
|
|
45
|
-
* Builds the method implementation for `snap_getBip44Entropy`.
|
|
46
|
-
*
|
|
47
|
-
* @param hooks - The RPC method hooks.
|
|
48
|
-
* @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase
|
|
49
|
-
* of the user.
|
|
50
|
-
* @param hooks.getUnlockPromise - A function that resolves once the MetaMask
|
|
51
|
-
* extension is unlocked and prompts the user to unlock their MetaMask if it is
|
|
52
|
-
* locked.
|
|
53
|
-
* @returns The method implementation which returns a `BIP44CoinTypeNode`.
|
|
54
|
-
* @throws If the params are invalid.
|
|
55
|
-
*/ export function getBip44EntropyImplementation({ getMnemonic, getUnlockPromise }) {
|
|
56
|
-
return async function getBip44Entropy(args) {
|
|
57
|
-
await getUnlockPromise(true);
|
|
58
|
-
// `args.params` is validated by the decorator, so it's safe to assert here.
|
|
59
|
-
const params = args.params;
|
|
60
|
-
const node = await BIP44CoinTypeNode.fromDerivationPath([
|
|
61
|
-
await getMnemonic(),
|
|
62
|
-
`bip32:44'`,
|
|
63
|
-
`bip32:${params.coinType}'`
|
|
64
|
-
]);
|
|
65
|
-
return node.toJSON();
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
//# sourceMappingURL=getBip44Entropy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/restricted/getBip44Entropy.ts"],"sourcesContent":["import { BIP44CoinTypeNode } from '@metamask/key-tree';\nimport 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 GetBip44EntropyParams,\n GetBip44EntropyResult,\n} from '@metamask/snaps-sdk';\nimport { SnapCaveatType } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst targetName = 'snap_getBip44Entropy';\n\nexport type GetBip44EntropyMethodHooks = {\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 GetBip44EntropySpecificationBuilderOptions = {\n methodHooks: GetBip44EntropyMethodHooks;\n};\n\ntype GetBip44EntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getBip44EntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n}>;\n\n/**\n * The specification builder for the `snap_getBip44Entropy` permission.\n * `snap_getBip44Entropy_*` lets the Snap control private keys for a particular\n * BIP-32 coin type.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_getBip44Entropy` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetBip44EntropySpecificationBuilderOptions,\n GetBip44EntropySpecification\n> = ({ methodHooks }: GetBip44EntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats: [SnapCaveatType.PermittedCoinTypes],\n methodImplementation: getBip44EntropyImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (\n caveats?.length !== 1 ||\n caveats[0].type !== SnapCaveatType.PermittedCoinTypes\n ) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.PermittedCoinTypes}\" caveat.`,\n });\n }\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetBip44EntropyMethodHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getBip44EntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_getBip44Entropy`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - A function to retrieve the Secret Recovery Phrase\n * of the user.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @returns The method implementation which returns a `BIP44CoinTypeNode`.\n * @throws If the params are invalid.\n */\nexport function getBip44EntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetBip44EntropyMethodHooks) {\n return async function getBip44Entropy(\n args: RestrictedMethodOptions<GetBip44EntropyParams>,\n ): Promise<GetBip44EntropyResult> {\n await getUnlockPromise(true);\n\n // `args.params` is validated by the decorator, so it's safe to assert here.\n const params = args.params as GetBip44EntropyParams;\n\n const node = await BIP44CoinTypeNode.fromDerivationPath([\n await getMnemonic(),\n `bip32:44'`,\n `bip32:${params.coinType}'`,\n ]);\n\n return node.toJSON();\n };\n}\n"],"names":["BIP44CoinTypeNode","PermissionType","SubjectType","rpcErrors","SnapCaveatType","targetName","specificationBuilder","methodHooks","permissionType","RestrictedMethod","allowedCaveats","PermittedCoinTypes","methodImplementation","getBip44EntropyImplementation","validator","caveats","length","type","invalidParams","message","subjectTypes","Snap","getMnemonic","getUnlockPromise","getBip44EntropyBuilder","Object","freeze","getBip44Entropy","args","params","node","fromDerivationPath","coinType","toJSON"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,qBAAqB;AAOvD,SAASC,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAKjD,SAASC,cAAc,QAAQ,wBAAwB;AAKvD,MAAMC,aAAa;AA4BnB;;;;;;;;;CASC,GACD,MAAMC,uBAIF,CAAC,EAAEC,WAAW,EAA8C;IAC9D,OAAO;QACLC,gBAAgBP,eAAeQ,gBAAgB;QAC/CJ;QACAK,gBAAgB;YAACN,eAAeO,kBAAkB;SAAC;QACnDC,sBAAsBC,8BAA8BN;QACpDO,WAAW,CAAC,EAAEC,OAAO,EAAE;YACrB,IACEA,SAASC,WAAW,KACpBD,OAAO,CAAC,EAAE,CAACE,IAAI,KAAKb,eAAeO,kBAAkB,EACrD;gBACA,MAAMR,UAAUe,aAAa,CAAC;oBAC5BC,SAAS,CAAC,mBAAmB,EAAEf,eAAeO,kBAAkB,CAAC,SAAS,CAAC;gBAC7E;YACF;QACF;QACAS,cAAc;YAAClB,YAAYmB,IAAI;SAAC;IAClC;AACF;AAEA,MAAMd,cAA6D;IACjEe,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,yBAAyBC,OAAOC,MAAM,CAAC;IAClDrB;IACAC;IACAC;AACF,GAAY;AAEZ;;;;;;;;;;;CAWC,GACD,OAAO,SAASM,8BAA8B,EAC5CS,WAAW,EACXC,gBAAgB,EACW;IAC3B,OAAO,eAAeI,gBACpBC,IAAoD;QAEpD,MAAML,iBAAiB;QAEvB,4EAA4E;QAC5E,MAAMM,SAASD,KAAKC,MAAM;QAE1B,MAAMC,OAAO,MAAM9B,kBAAkB+B,kBAAkB,CAAC;YACtD,MAAMT;YACN,CAAC,SAAS,CAAC;YACX,CAAC,MAAM,EAAEO,OAAOG,QAAQ,CAAC,CAAC,CAAC;SAC5B;QAED,OAAOF,KAAKG,MAAM;IACpB;AACF"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { PermissionType, SubjectType } from '@metamask/permission-controller';
|
|
2
|
-
import { rpcErrors } from '@metamask/rpc-errors';
|
|
3
|
-
import { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';
|
|
4
|
-
import { assertStruct } from '@metamask/utils';
|
|
5
|
-
import { literal, object, optional, string } from 'superstruct';
|
|
6
|
-
import { deriveEntropy } from '../utils';
|
|
7
|
-
const targetName = 'snap_getEntropy';
|
|
8
|
-
export const GetEntropyArgsStruct = object({
|
|
9
|
-
version: literal(1),
|
|
10
|
-
salt: optional(string())
|
|
11
|
-
});
|
|
12
|
-
const specificationBuilder = ({ allowedCaveats = null, methodHooks })=>{
|
|
13
|
-
return {
|
|
14
|
-
permissionType: PermissionType.RestrictedMethod,
|
|
15
|
-
targetName,
|
|
16
|
-
allowedCaveats,
|
|
17
|
-
methodImplementation: getEntropyImplementation(methodHooks),
|
|
18
|
-
subjectTypes: [
|
|
19
|
-
SubjectType.Snap
|
|
20
|
-
]
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
const methodHooks = {
|
|
24
|
-
getMnemonic: true,
|
|
25
|
-
getUnlockPromise: true
|
|
26
|
-
};
|
|
27
|
-
export const getEntropyBuilder = Object.freeze({
|
|
28
|
-
targetName,
|
|
29
|
-
specificationBuilder,
|
|
30
|
-
methodHooks
|
|
31
|
-
});
|
|
32
|
-
/**
|
|
33
|
-
* Builds the method implementation for `snap_getEntropy`. The implementation
|
|
34
|
-
* is based on the reference implementation of
|
|
35
|
-
* [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).
|
|
36
|
-
*
|
|
37
|
-
* @param hooks - The RPC method hooks.
|
|
38
|
-
* @param hooks.getMnemonic - The method to get the mnemonic of the user's
|
|
39
|
-
* primary keyring.
|
|
40
|
-
* @param hooks.getUnlockPromise - The method to get a promise that resolves
|
|
41
|
-
* once the extension is unlocked.
|
|
42
|
-
* @returns The method implementation.
|
|
43
|
-
*/ function getEntropyImplementation({ getMnemonic, getUnlockPromise }) {
|
|
44
|
-
return async function getEntropy(options) {
|
|
45
|
-
const { params, context: { origin } } = options;
|
|
46
|
-
assertStruct(params, GetEntropyArgsStruct, 'Invalid "snap_getEntropy" parameters', rpcErrors.invalidParams);
|
|
47
|
-
await getUnlockPromise(true);
|
|
48
|
-
const mnemonicPhrase = await getMnemonic();
|
|
49
|
-
return deriveEntropy({
|
|
50
|
-
input: origin,
|
|
51
|
-
salt: params.salt,
|
|
52
|
-
mnemonicPhrase,
|
|
53
|
-
magic: SIP_6_MAGIC_VALUE
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
//# sourceMappingURL=getEntropy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/restricted/getEntropy.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetEntropyParams, GetEntropyResult } from '@metamask/snaps-sdk';\nimport { SIP_6_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { literal, object, optional, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\nconst targetName = 'snap_getEntropy';\n\ntype GetEntropySpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: GetEntropyHooks;\n};\n\ntype GetEntropySpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof targetName;\n methodImplementation: ReturnType<typeof getEntropyImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\nexport const GetEntropyArgsStruct = object({\n version: literal(1),\n salt: optional(string()),\n});\n\n/**\n * @property version - The version of the `snap_getEntropy` method. This must be\n * the numeric literal `1`.\n * @property salt - A string to use as the salt when deriving the entropy. If\n * omitted, the salt will be an empty string.\n */\nexport type GetEntropyArgs = Infer<typeof GetEntropyArgsStruct>;\n\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n GetEntropySpecificationBuilderOptions,\n GetEntropySpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: GetEntropySpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName,\n allowedCaveats,\n methodImplementation: getEntropyImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<GetEntropyHooks> = {\n getMnemonic: true,\n getUnlockPromise: true,\n};\n\nexport const getEntropyBuilder = Object.freeze({\n targetName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport type GetEntropyHooks = {\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\n/**\n * Builds the method implementation for `snap_getEntropy`. The implementation\n * is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getMnemonic - The method to get the mnemonic of the user's\n * primary keyring.\n * @param hooks.getUnlockPromise - The method to get a promise that resolves\n * once the extension is unlocked.\n * @returns The method implementation.\n */\nfunction getEntropyImplementation({\n getMnemonic,\n getUnlockPromise,\n}: GetEntropyHooks) {\n return async function getEntropy(\n options: RestrictedMethodOptions<GetEntropyParams>,\n ): Promise<GetEntropyResult> {\n const {\n params,\n context: { origin },\n } = options;\n\n assertStruct(\n params,\n GetEntropyArgsStruct,\n 'Invalid \"snap_getEntropy\" parameters',\n rpcErrors.invalidParams,\n );\n\n await getUnlockPromise(true);\n const mnemonicPhrase = await getMnemonic();\n\n return deriveEntropy({\n input: origin,\n salt: params.salt,\n mnemonicPhrase,\n magic: SIP_6_MAGIC_VALUE,\n });\n };\n}\n"],"names":["PermissionType","SubjectType","rpcErrors","SIP_6_MAGIC_VALUE","assertStruct","literal","object","optional","string","deriveEntropy","targetName","GetEntropyArgsStruct","version","salt","specificationBuilder","allowedCaveats","methodHooks","permissionType","RestrictedMethod","methodImplementation","getEntropyImplementation","subjectTypes","Snap","getMnemonic","getUnlockPromise","getEntropyBuilder","Object","freeze","getEntropy","options","params","context","origin","invalidParams","mnemonicPhrase","input","magic"],"mappings":"AAKA,SAASA,cAAc,EAAEC,WAAW,QAAQ,kCAAkC;AAC9E,SAASC,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,iBAAiB,QAAQ,wBAAwB;AAE1D,SAASC,YAAY,QAAQ,kBAAkB;AAE/C,SAASC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,QAAQ,cAAc;AAGhE,SAASC,aAAa,QAAQ,WAAW;AAEzC,MAAMC,aAAa;AAcnB,OAAO,MAAMC,uBAAuBL,OAAO;IACzCM,SAASP,QAAQ;IACjBQ,MAAMN,SAASC;AACjB,GAAG;AAUH,MAAMM,uBAIF,CAAC,EACHC,iBAAiB,IAAI,EACrBC,WAAW,EAC2B;IACtC,OAAO;QACLC,gBAAgBjB,eAAekB,gBAAgB;QAC/CR;QACAK;QACAI,sBAAsBC,yBAAyBJ;QAC/CK,cAAc;YAACpB,YAAYqB,IAAI;SAAC;IAClC;AACF;AAEA,MAAMN,cAAkD;IACtDO,aAAa;IACbC,kBAAkB;AACpB;AAEA,OAAO,MAAMC,oBAAoBC,OAAOC,MAAM,CAAC;IAC7CjB;IACAI;IACAE;AACF,GAAY;AAgBZ;;;;;;;;;;;CAWC,GACD,SAASI,yBAAyB,EAChCG,WAAW,EACXC,gBAAgB,EACA;IAChB,OAAO,eAAeI,WACpBC,OAAkD;QAElD,MAAM,EACJC,MAAM,EACNC,SAAS,EAAEC,MAAM,EAAE,EACpB,GAAGH;QAEJzB,aACE0B,QACAnB,sBACA,wCACAT,UAAU+B,aAAa;QAGzB,MAAMT,iBAAiB;QACvB,MAAMU,iBAAiB,MAAMX;QAE7B,OAAOd,cAAc;YACnB0B,OAAOH;YACPnB,MAAMiB,OAAOjB,IAAI;YACjBqB;YACAE,OAAOjC;QACT;IACF;AACF"}
|