@metamask/snaps-rpc-methods 6.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 +8 -2
- 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/{cjs/endowments/web-assembly.js.map → chunk-RZDRHJXI.js.map} +1 -1
- 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/{cjs/endowments/ethereum-provider.js.map → chunk-VZBSLVVA.js.map} +1 -1
- 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/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 +21 -18
- package/dist/cjs/endowments/caveats/generic.js +0 -40
- package/dist/cjs/endowments/caveats/generic.js.map +0 -1
- package/dist/cjs/endowments/caveats/index.js +0 -21
- package/dist/cjs/endowments/caveats/index.js.map +0 -1
- package/dist/cjs/endowments/caveats/requestTime.js +0 -99
- package/dist/cjs/endowments/caveats/requestTime.js.map +0 -1
- package/dist/cjs/endowments/cronjob.js +0 -100
- package/dist/cjs/endowments/cronjob.js.map +0 -1
- package/dist/cjs/endowments/enum.js +0 -26
- package/dist/cjs/endowments/enum.js.map +0 -1
- package/dist/cjs/endowments/ethereum-provider.js +0 -43
- package/dist/cjs/endowments/home-page.js +0 -37
- package/dist/cjs/endowments/home-page.js.map +0 -1
- package/dist/cjs/endowments/index.js +0 -121
- package/dist/cjs/endowments/index.js.map +0 -1
- package/dist/cjs/endowments/keyring.js +0 -104
- package/dist/cjs/endowments/keyring.js.map +0 -1
- package/dist/cjs/endowments/lifecycle-hooks.js +0 -37
- package/dist/cjs/endowments/lifecycle-hooks.js.map +0 -1
- package/dist/cjs/endowments/name-lookup.js +0 -148
- package/dist/cjs/endowments/name-lookup.js.map +0 -1
- package/dist/cjs/endowments/network-access.js +0 -44
- package/dist/cjs/endowments/network-access.js.map +0 -1
- package/dist/cjs/endowments/rpc.js +0 -103
- package/dist/cjs/endowments/rpc.js.map +0 -1
- package/dist/cjs/endowments/signature-insight.js +0 -110
- package/dist/cjs/endowments/signature-insight.js.map +0 -1
- package/dist/cjs/endowments/transaction-insight.js +0 -111
- package/dist/cjs/endowments/transaction-insight.js.map +0 -1
- package/dist/cjs/endowments/web-assembly.js +0 -42
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/permissions.js +0 -62
- package/dist/cjs/permissions.js.map +0 -1
- package/dist/cjs/permitted/createInterface.js +0 -68
- package/dist/cjs/permitted/createInterface.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/getInterfaceState.js +0 -67
- package/dist/cjs/permitted/getInterfaceState.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 -43
- 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/permitted/updateInterface.js +0 -70
- package/dist/cjs/permitted/updateInterface.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 -172
- 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/endowments/caveats/generic.js +0 -40
- package/dist/esm/endowments/caveats/generic.js.map +0 -1
- package/dist/esm/endowments/caveats/index.js +0 -4
- package/dist/esm/endowments/caveats/index.js.map +0 -1
- package/dist/esm/endowments/caveats/requestTime.js +0 -93
- package/dist/esm/endowments/caveats/requestTime.js.map +0 -1
- package/dist/esm/endowments/cronjob.js +0 -99
- package/dist/esm/endowments/cronjob.js.map +0 -1
- package/dist/esm/endowments/enum.js +0 -16
- package/dist/esm/endowments/enum.js.map +0 -1
- package/dist/esm/endowments/ethereum-provider.js +0 -33
- package/dist/esm/endowments/ethereum-provider.js.map +0 -1
- package/dist/esm/endowments/home-page.js +0 -27
- package/dist/esm/endowments/home-page.js.map +0 -1
- package/dist/esm/endowments/index.js +0 -68
- package/dist/esm/endowments/index.js.map +0 -1
- package/dist/esm/endowments/keyring.js +0 -95
- package/dist/esm/endowments/keyring.js.map +0 -1
- package/dist/esm/endowments/lifecycle-hooks.js +0 -27
- package/dist/esm/endowments/lifecycle-hooks.js.map +0 -1
- package/dist/esm/endowments/name-lookup.js +0 -146
- package/dist/esm/endowments/name-lookup.js.map +0 -1
- package/dist/esm/endowments/network-access.js +0 -34
- package/dist/esm/endowments/network-access.js.map +0 -1
- package/dist/esm/endowments/rpc.js +0 -92
- package/dist/esm/endowments/rpc.js.map +0 -1
- package/dist/esm/endowments/signature-insight.js +0 -103
- package/dist/esm/endowments/signature-insight.js.map +0 -1
- package/dist/esm/endowments/transaction-insight.js +0 -104
- package/dist/esm/endowments/transaction-insight.js.map +0 -1
- package/dist/esm/endowments/web-assembly.js +0 -32
- package/dist/esm/endowments/web-assembly.js.map +0 -1
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/permissions.js +0 -51
- package/dist/esm/permissions.js.map +0 -1
- package/dist/esm/permitted/createInterface.js +0 -58
- package/dist/esm/permitted/createInterface.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/getInterfaceState.js +0 -57
- package/dist/esm/permitted/getInterfaceState.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 -25
- 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/permitted/updateInterface.js +0 -60
- package/dist/esm/permitted/updateInterface.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 -164
- 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/invokeSnap.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionSideEffect,\n} from '@metamask/permission-controller';\nimport { PermissionType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n InvokeSnapResult,\n RequestSnapsParams,\n RequestSnapsResult,\n} from '@metamask/snaps-sdk';\nimport type { Snap, SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\n// Redeclare installSnaps action type to avoid circular dependencies\nexport type InstallSnaps = {\n type: `SnapController:install`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type GetPermittedSnaps = {\n type: `SnapController:getPermitted`;\n handler: (origin: string) => RequestSnapsResult;\n};\n\ntype AllowedActions = InstallSnaps | GetPermittedSnaps;\n\nexport type InvokeSnapMethodHooks = {\n getSnap: (snapId: string) => Snap | undefined;\n handleSnapRpcRequest: ({\n snapId,\n origin,\n handler,\n request,\n }: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\ntype InvokeSnapSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: InvokeSnapMethodHooks;\n};\n\ntype InvokeSnapSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof WALLET_SNAP_PERMISSION_KEY;\n methodImplementation: ReturnType<typeof getInvokeSnapImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n sideEffect: {\n onPermitted: PermissionSideEffect<AllowedActions, never>['onPermitted'];\n };\n}>;\n\nexport type InvokeSnapParams = {\n snapId: string;\n request: Record<string, Json>;\n};\n\n/**\n * The side-effect method to handle the snap install.\n *\n * @param params - The side-effect params.\n * @param params.requestData - The request data associated to the requested permission.\n * @param params.messagingSystem - The messenger to call an action.\n */\nexport const handleSnapInstall: PermissionSideEffect<\n AllowedActions,\n never\n>['onPermitted'] = async ({ requestData, messagingSystem }) => {\n const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0]\n .value as RequestSnapsParams;\n\n const permittedSnaps = messagingSystem.call(\n `SnapController:getPermitted`,\n requestData.metadata.origin,\n );\n\n const dedupedSnaps = Object.keys(snaps).reduce<RequestSnapsParams>(\n (filteredSnaps, snap) => {\n if (!permittedSnaps[snap]) {\n filteredSnaps[snap] = snaps[snap];\n }\n return filteredSnaps;\n },\n {},\n );\n\n return messagingSystem.call(\n `SnapController:install`,\n requestData.metadata.origin,\n dedupedSnaps,\n );\n};\n/**\n * The specification builder for the `wallet_snap_*` permission.\n *\n * `wallet_snap_*` attempts to invoke an RPC method of the specified Snap.\n *\n * Requesting its corresponding permission will attempt to connect to the Snap,\n * and install it if it's not available yet.\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 `wallet_snap_*` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n InvokeSnapSpecificationBuilderOptions,\n InvokeSnapSpecification\n> = ({ methodHooks }: InvokeSnapSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: WALLET_SNAP_PERMISSION_KEY,\n allowedCaveats: [SnapCaveatType.SnapIds],\n methodImplementation: getInvokeSnapImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.SnapIds) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.SnapIds}\" caveat.`,\n });\n }\n },\n sideEffect: {\n onPermitted: handleSnapInstall,\n },\n };\n};\n\nconst methodHooks: MethodHooksObject<InvokeSnapMethodHooks> = {\n getSnap: true,\n handleSnapRpcRequest: true,\n};\n\nexport const invokeSnapBuilder = Object.freeze({\n targetName: WALLET_SNAP_PERMISSION_KEY,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `wallet_snap_*`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.getSnap - A function that retrieves all information stored about a snap.\n * @param hooks.handleSnapRpcRequest - A function that sends an RPC request to a snap's RPC handler or throws if that fails.\n * @returns The method implementation which returns the result of `handleSnapRpcRequest`.\n * @throws If the params are invalid.\n */\nexport function getInvokeSnapImplementation({\n getSnap,\n handleSnapRpcRequest,\n}: InvokeSnapMethodHooks) {\n return async function invokeSnap(\n options: RestrictedMethodOptions<InvokeSnapParams>,\n ): Promise<InvokeSnapResult> {\n const { params = {}, context } = options;\n\n const { snapId, request } = params as InvokeSnapParams;\n\n if (!getSnap(snapId)) {\n throw rpcErrors.invalidRequest({\n message: `The snap \"${snapId}\" is not installed. Please install it first, before invoking the snap.`,\n });\n }\n\n const { origin } = context;\n\n return (await handleSnapRpcRequest({\n snapId,\n origin,\n request,\n handler: HandlerType.OnRpcRequest,\n })) as Json;\n };\n}\n"],"mappings":";AAOA,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAO1B,SAAS,aAAa,sBAAsB;AAKrC,IAAM,6BAA6B;AAwDnC,IAAM,oBAGM,OAAO,EAAE,aAAa,gBAAgB,MAAM;AAC7D,QAAM,QAAQ,YAAY,YAAY,0BAA0B,EAAE,UAAU,CAAC,EAC1E;AAEH,QAAM,iBAAiB,gBAAgB;AAAA,IACrC;AAAA,IACA,YAAY,SAAS;AAAA,EACvB;AAEA,QAAM,eAAe,OAAO,KAAK,KAAK,EAAE;AAAA,IACtC,CAAC,eAAe,SAAS;AACvB,UAAI,CAAC,eAAe,IAAI,GAAG;AACzB,sBAAc,IAAI,IAAI,MAAM,IAAI;AAAA,MAClC;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AAEA,SAAO,gBAAgB;AAAA,IACrB;AAAA,IACA,YAAY,SAAS;AAAA,IACrB;AAAA,EACF;AACF;AAaA,IAAM,uBAIF,CAAC,EAAE,aAAAA,aAAY,MAA6C;AAC9D,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ,gBAAgB,CAAC,eAAe,OAAO;AAAA,IACvC,sBAAsB,4BAA4BA,YAAW;AAAA,IAC7D,WAAW,CAAC,EAAE,QAAQ,MAAM;AAC1B,UAAI,SAAS,WAAW,KAAK,QAAQ,CAAC,EAAE,SAAS,eAAe,SAAS;AACvE,cAAM,UAAU,cAAc;AAAA,UAC5B,SAAS,sBAAsB,eAAe,OAAO;AAAA,QACvD,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,YAAY;AAAA,MACV,aAAa;AAAA,IACf;AAAA,EACF;AACF;AAEA,IAAM,cAAwD;AAAA,EAC5D,SAAS;AAAA,EACT,sBAAsB;AACxB;AAEO,IAAM,oBAAoB,OAAO,OAAO;AAAA,EAC7C,YAAY;AAAA,EACZ;AAAA,EACA;AACF,CAAU;AAWH,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AACF,GAA0B;AACxB,SAAO,eAAe,WACpB,SAC2B;AAC3B,UAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,IAAI;AAEjC,UAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,QAAI,CAAC,QAAQ,MAAM,GAAG;AACpB,YAAM,UAAU,eAAe;AAAA,QAC7B,SAAS,aAAa,MAAM;AAAA,MAC9B,CAAC;AAAA,IACH;AAEA,UAAM,EAAE,OAAO,IAAI;AAEnB,WAAQ,MAAM,qBAAqB;AAAA,MACjC;AAAA,MACA;AAAA,MACA;AAAA,MACA,SAAS,YAAY;AAAA,IACvB,CAAC;AAAA,EACH;AACF;","names":["methodHooks"]}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk632BZ6JYjs = require('./chunk-632BZ6JY.js');
|
|
4
|
+
|
|
5
|
+
// src/restricted/getEntropy.ts
|
|
6
|
+
var _permissioncontroller = require('@metamask/permission-controller');
|
|
7
|
+
var _rpcerrors = require('@metamask/rpc-errors');
|
|
8
|
+
var _snapsutils = require('@metamask/snaps-utils');
|
|
9
|
+
var _utils = require('@metamask/utils');
|
|
10
|
+
var _superstruct = require('superstruct');
|
|
11
|
+
var targetName = "snap_getEntropy";
|
|
12
|
+
var GetEntropyArgsStruct = _superstruct.object.call(void 0, {
|
|
13
|
+
version: _superstruct.literal.call(void 0, 1),
|
|
14
|
+
salt: _superstruct.optional.call(void 0, _superstruct.string.call(void 0, ))
|
|
15
|
+
});
|
|
16
|
+
var specificationBuilder = ({
|
|
17
|
+
allowedCaveats = null,
|
|
18
|
+
methodHooks: methodHooks2
|
|
19
|
+
}) => {
|
|
20
|
+
return {
|
|
21
|
+
permissionType: _permissioncontroller.PermissionType.RestrictedMethod,
|
|
22
|
+
targetName,
|
|
23
|
+
allowedCaveats,
|
|
24
|
+
methodImplementation: getEntropyImplementation(methodHooks2),
|
|
25
|
+
subjectTypes: [_permissioncontroller.SubjectType.Snap]
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
var methodHooks = {
|
|
29
|
+
getMnemonic: true,
|
|
30
|
+
getUnlockPromise: true
|
|
31
|
+
};
|
|
32
|
+
var getEntropyBuilder = Object.freeze({
|
|
33
|
+
targetName,
|
|
34
|
+
specificationBuilder,
|
|
35
|
+
methodHooks
|
|
36
|
+
});
|
|
37
|
+
function getEntropyImplementation({
|
|
38
|
+
getMnemonic,
|
|
39
|
+
getUnlockPromise
|
|
40
|
+
}) {
|
|
41
|
+
return async function getEntropy(options) {
|
|
42
|
+
const {
|
|
43
|
+
params,
|
|
44
|
+
context: { origin }
|
|
45
|
+
} = options;
|
|
46
|
+
_utils.assertStruct.call(void 0,
|
|
47
|
+
params,
|
|
48
|
+
GetEntropyArgsStruct,
|
|
49
|
+
'Invalid "snap_getEntropy" parameters',
|
|
50
|
+
_rpcerrors.rpcErrors.invalidParams
|
|
51
|
+
);
|
|
52
|
+
await getUnlockPromise(true);
|
|
53
|
+
const mnemonicPhrase = await getMnemonic();
|
|
54
|
+
return _chunk632BZ6JYjs.deriveEntropy.call(void 0, {
|
|
55
|
+
input: origin,
|
|
56
|
+
salt: params.salt,
|
|
57
|
+
mnemonicPhrase,
|
|
58
|
+
magic: _snapsutils.SIP_6_MAGIC_VALUE
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
exports.GetEntropyArgsStruct = GetEntropyArgsStruct; exports.getEntropyBuilder = getEntropyBuilder;
|
|
67
|
+
//# sourceMappingURL=chunk-6PXDUIXN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/getEntropy.ts"],"names":["methodHooks"],"mappings":";;;;;AAKA,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,iBAAiB;AAE1B,SAAS,yBAAyB;AAElC,SAAS,oBAAoB;AAE7B,SAAS,SAAS,QAAQ,UAAU,cAAc;AAKlD,IAAM,aAAa;AAcZ,IAAM,uBAAuB,OAAO;AAAA,EACzC,SAAS,QAAQ,CAAC;AAAA,EAClB,MAAM,SAAS,OAAO,CAAC;AACzB,CAAC;AAUD,IAAM,uBAIF,CAAC;AAAA,EACH,iBAAiB;AAAA,EACjB,aAAAA;AACF,MAA6C;AAC3C,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA;AAAA,IACA,sBAAsB,yBAAyBA,YAAW;AAAA,IAC1D,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEA,IAAM,cAAkD;AAAA,EACtD,aAAa;AAAA,EACb,kBAAkB;AACpB;AAEO,IAAM,oBAAoB,OAAO,OAAO;AAAA,EAC7C;AAAA,EACA;AAAA,EACA;AACF,CAAU;AA4BV,SAAS,yBAAyB;AAAA,EAChC;AAAA,EACA;AACF,GAAoB;AAClB,SAAO,eAAe,WACpB,SAC2B;AAC3B,UAAM;AAAA,MACJ;AAAA,MACA,SAAS,EAAE,OAAO;AAAA,IACpB,IAAI;AAEJ;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA,UAAU;AAAA,IACZ;AAEA,UAAM,iBAAiB,IAAI;AAC3B,UAAM,iBAAiB,MAAM,YAAY;AAEzC,WAAO,cAAc;AAAA,MACnB,OAAO;AAAA,MACP,MAAM,OAAO;AAAA,MACb;AAAA,MACA,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF","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"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// src/endowments/web-assembly.ts
|
|
2
|
+
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
3
|
+
var permissionName = "endowment:webassembly" /* WebAssemblyAccess */;
|
|
4
|
+
var specificationBuilder = (_builderOptions) => {
|
|
5
|
+
return {
|
|
6
|
+
permissionType: PermissionType.Endowment,
|
|
7
|
+
targetName: permissionName,
|
|
8
|
+
allowedCaveats: null,
|
|
9
|
+
endowmentGetter: (_getterOptions) => {
|
|
10
|
+
return ["WebAssembly"];
|
|
11
|
+
},
|
|
12
|
+
subjectTypes: [SubjectType.Snap]
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var webAssemblyEndowmentBuilder = Object.freeze({
|
|
16
|
+
targetName: permissionName,
|
|
17
|
+
specificationBuilder
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
webAssemblyEndowmentBuilder
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=chunk-72V4CPGO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endowments/web-assembly.ts"],"sourcesContent":["import type {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.WebAssemblyAccess;\n\ntype WebAssemblyEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (_options?: any) => ['WebAssembly'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:webassembly` returns the name of global browser API(s) that\n * enable access to the WebAssembly API.\n * This is intended to populate the endowments of the SES Compartment\n * in which a Snap executes.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the WebAssembly endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n WebAssemblyEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['WebAssembly'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const webAssemblyEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"],"mappings":";AAKA,SAAS,gBAAgB,mBAAmB;AAI5C,IAAM;AAkBN,IAAM,uBAIF,CAAC,oBAA0B;AAC7B,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,iBAAiB,CAAC,mBAA2C;AAC3D,aAAO,CAAC,aAAa;AAAA,IACvB;AAAA,IACA,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEO,IAAM,8BAA8B,OAAO,OAAO;AAAA,EACvD,YAAY;AAAA,EACZ;AACF,CAAU;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/permitted/getInterfaceState.ts
|
|
2
|
+
var _rpcerrors = require('@metamask/rpc-errors');
|
|
3
|
+
var _superstruct = require('superstruct');
|
|
4
|
+
var hookNames = {
|
|
5
|
+
getInterfaceState: true
|
|
6
|
+
};
|
|
7
|
+
var getInterfaceStateHandler = {
|
|
8
|
+
methodNames: ["snap_getInterfaceState"],
|
|
9
|
+
implementation: getGetInterfaceStateImplementation,
|
|
10
|
+
hookNames
|
|
11
|
+
};
|
|
12
|
+
var GetInterfaceStateParametersStruct = _superstruct.object.call(void 0, {
|
|
13
|
+
id: _superstruct.string.call(void 0, )
|
|
14
|
+
});
|
|
15
|
+
function getGetInterfaceStateImplementation(req, res, _next, end, { getInterfaceState }) {
|
|
16
|
+
const { params } = req;
|
|
17
|
+
try {
|
|
18
|
+
const validatedParams = getValidatedParams(params);
|
|
19
|
+
const { id } = validatedParams;
|
|
20
|
+
res.result = getInterfaceState(id);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
return end(error);
|
|
23
|
+
}
|
|
24
|
+
return end();
|
|
25
|
+
}
|
|
26
|
+
function getValidatedParams(params) {
|
|
27
|
+
try {
|
|
28
|
+
return _superstruct.create.call(void 0, params, GetInterfaceStateParametersStruct);
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error instanceof _superstruct.StructError) {
|
|
31
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
32
|
+
message: `Invalid params: ${error.message}.`
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
throw _rpcerrors.rpcErrors.internal();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
exports.getInterfaceStateHandler = getInterfaceStateHandler;
|
|
42
|
+
//# sourceMappingURL=chunk-7O63CIBT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAS1B,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA6D;AAAA,EACjE,mBAAmB;AACrB;AAUO,IAAM,2BAIT;AAAA,EACF,aAAa,CAAC,wBAAwB;AAAA,EACtC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,oCAAoC,OAAO;AAAA,EAC/C,IAAI,OAAO;AACb,CAAC;AAmBD,SAAS,mCACP,KACA,KACA,OACA,KACA,EAAE,kBAAkB,GACd;AACN,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,GAAG,IAAI;AAEf,QAAI,SAAS,kBAAkB,EAAE;AAAA,EACnC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA8C;AACxE,MAAI;AACF,WAAO,OAAO,QAAQ,iCAAiC;AAAA,EACzD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n InterfaceState,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceStateMethodHooks> = {\n getInterfaceState: true,\n};\n\nexport type GetInterfaceStateMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState: (id: string) => InterfaceState;\n};\n\nexport const getInterfaceStateHandler: PermittedHandlerExport<\n GetInterfaceStateMethodHooks,\n GetInterfaceStateParameters,\n GetInterfaceStateResult\n> = {\n methodNames: ['snap_getInterfaceState'],\n implementation: getGetInterfaceStateImplementation,\n hookNames,\n};\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceState - The function to get the interface state.\n * @returns Noting.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequest<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceState }: GetInterfaceStateMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceState(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState 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 getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/restricted/caveats/permittedCoinTypes.ts
|
|
2
|
+
var _rpcerrors = require('@metamask/rpc-errors');
|
|
3
|
+
var _snapsutils = require('@metamask/snaps-utils');
|
|
4
|
+
var _utils = require('@metamask/utils');
|
|
5
|
+
function permittedCoinTypesCaveatMapper(value) {
|
|
6
|
+
return {
|
|
7
|
+
caveats: [
|
|
8
|
+
{
|
|
9
|
+
type: _snapsutils.SnapCaveatType.PermittedCoinTypes,
|
|
10
|
+
value
|
|
11
|
+
}
|
|
12
|
+
]
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function validateBIP44Params(value) {
|
|
16
|
+
if (!_utils.isPlainObject.call(void 0, value) || !_utils.hasProperty.call(void 0, value, "coinType")) {
|
|
17
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
18
|
+
message: "Expected a plain object containing a coin type."
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (typeof value.coinType !== "number" || !Number.isInteger(value.coinType) || value.coinType < 0 || value.coinType > 2147483647) {
|
|
22
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
23
|
+
message: 'Invalid "coinType" parameter. Coin type must be a non-negative integer.'
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
if (_snapsutils.FORBIDDEN_COIN_TYPES.includes(value.coinType)) {
|
|
27
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
28
|
+
message: `Coin type ${value.coinType} is forbidden.`
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function validateBIP44Caveat(caveat) {
|
|
33
|
+
if (!_utils.hasProperty.call(void 0, caveat, "value") || !Array.isArray(caveat.value) || caveat.value.length === 0) {
|
|
34
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
35
|
+
message: "Expected non-empty array of coin types."
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
caveat.value.forEach(validateBIP44Params);
|
|
39
|
+
}
|
|
40
|
+
var PermittedCoinTypesCaveatSpecification = {
|
|
41
|
+
[_snapsutils.SnapCaveatType.PermittedCoinTypes]: Object.freeze({
|
|
42
|
+
type: _snapsutils.SnapCaveatType.PermittedCoinTypes,
|
|
43
|
+
decorator: (method, caveat) => {
|
|
44
|
+
return async (args) => {
|
|
45
|
+
const { params } = args;
|
|
46
|
+
validateBIP44Params(params);
|
|
47
|
+
const coinType = caveat.value.find(
|
|
48
|
+
(caveatValue) => caveatValue.coinType === params.coinType
|
|
49
|
+
);
|
|
50
|
+
if (!coinType) {
|
|
51
|
+
throw _rpcerrors.providerErrors.unauthorized({
|
|
52
|
+
message: "The requested coin type is not permitted. Allowed coin types must be specified in the snap manifest."
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return await method(args);
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
validator: (caveat) => validateBIP44Caveat(caveat)
|
|
59
|
+
})
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
exports.permittedCoinTypesCaveatMapper = permittedCoinTypesCaveatMapper; exports.validateBIP44Params = validateBIP44Params; exports.validateBIP44Caveat = validateBIP44Caveat; exports.PermittedCoinTypesCaveatSpecification = PermittedCoinTypesCaveatSpecification;
|
|
68
|
+
//# sourceMappingURL=chunk-ABFJRV6Q.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/caveats/permittedCoinTypes.ts"],"names":[],"mappings":";AAKA,SAAS,gBAAgB,iBAAiB;AAE1C,SAAS,sBAAsB,sBAAsB;AAErD,SAAS,aAAa,qBAAqB;AAUpC,SAAS,+BACd,OACuC;AACvC,SAAO;AAAA,IACL,SAAS;AAAA,MACP;AAAA,QACE,MAAM,eAAe;AAAA,QACrB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAQO,SAAS,oBACd,OACwC;AACxC,MAAI,CAAC,cAAc,KAAK,KAAK,CAAC,YAAY,OAAO,UAAU,GAAG;AAC5D,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,MACE,OAAO,MAAM,aAAa,YAC1B,CAAC,OAAO,UAAU,MAAM,QAAQ,KAChC,MAAM,WAAW,KACjB,MAAM,WAAW,YACjB;AACA,UAAM,UAAU,cAAc;AAAA,MAC5B,SACE;AAAA,IACJ,CAAC;AAAA,EACH;AAEA,MAAI,qBAAqB,SAAS,MAAM,QAAQ,GAAG;AACjD,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS,aAAa,MAAM,QAAQ;AAAA,IACtC,CAAC;AAAA,EACH;AACF;AASO,SAAS,oBAAoB,QAA6B;AAC/D,MACE,CAAC,YAAY,QAAQ,OAAO,KAC5B,CAAC,MAAM,QAAQ,OAAO,KAAK,KAC3B,OAAO,MAAM,WAAW,GACxB;AACA,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO,MAAM,QAAQ,mBAAmB;AAC1C;AAEO,IAAM,wCAGT;AAAA,EACF,CAAC,eAAe,kBAAkB,GAAG,OAAO,OAAO;AAAA,IACjD,MAAM,eAAe;AAAA,IACrB,WAAW,CACT,QACA,WAIG;AACH,aAAO,OAAO,SAAS;AACrB,cAAM,EAAE,OAAO,IAAI;AACnB,4BAAoB,MAAM;AAE1B,cAAM,WAAW,OAAO,MAAM;AAAA,UAC5B,CAAC,gBAAgB,YAAY,aAAa,OAAO;AAAA,QACnD;AAEA,YAAI,CAAC,UAAU;AACb,gBAAM,eAAe,aAAa;AAAA,YAChC,SACE;AAAA,UACJ,CAAC;AAAA,QACH;AAEA,eAAO,MAAM,OAAO,IAAI;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,WAAW,CAAC,WAAW,oBAAoB,MAAM;AAAA,EACnD,CAAC;AACH","sourcesContent":["import type {\n PermissionConstraint,\n RestrictedMethodCaveatSpecificationConstraint,\n Caveat,\n} from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetBip44EntropyParams } from '@metamask/snaps-sdk';\nimport { FORBIDDEN_COIN_TYPES, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty, isPlainObject } from '@metamask/utils';\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 permittedCoinTypesCaveatMapper(\n value: Json,\n): Pick<PermissionConstraint, 'caveats'> {\n return {\n caveats: [\n {\n type: SnapCaveatType.PermittedCoinTypes,\n value,\n },\n ],\n };\n}\n\n/**\n * Validate the params for `snap_getBip44Entropy`.\n *\n * @param value - The params to validate.\n * @throws If the params are invalid.\n */\nexport function validateBIP44Params(\n value: unknown,\n): asserts value is GetBip44EntropyParams {\n if (!isPlainObject(value) || !hasProperty(value, 'coinType')) {\n throw rpcErrors.invalidParams({\n message: 'Expected a plain object containing a coin type.',\n });\n }\n\n if (\n typeof value.coinType !== 'number' ||\n !Number.isInteger(value.coinType) ||\n value.coinType < 0 ||\n value.coinType > 0x7fffffff\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Invalid \"coinType\" parameter. Coin type must be a non-negative integer.',\n });\n }\n\n if (FORBIDDEN_COIN_TYPES.includes(value.coinType)) {\n throw rpcErrors.invalidParams({\n message: `Coin type ${value.coinType} is forbidden.`,\n });\n }\n}\n\n/**\n * Validate the coin types values associated with a caveat. This checks if the\n * values are non-negative integers (>= 0).\n *\n * @param caveat - The caveat to validate.\n * @throws If the caveat is invalid.\n */\nexport function validateBIP44Caveat(caveat: Caveat<string, any>) {\n if (\n !hasProperty(caveat, 'value') ||\n !Array.isArray(caveat.value) ||\n caveat.value.length === 0\n ) {\n throw rpcErrors.invalidParams({\n message: 'Expected non-empty array of coin types.',\n });\n }\n\n caveat.value.forEach(validateBIP44Params);\n}\n\nexport const PermittedCoinTypesCaveatSpecification: Record<\n SnapCaveatType.PermittedCoinTypes,\n RestrictedMethodCaveatSpecificationConstraint\n> = {\n [SnapCaveatType.PermittedCoinTypes]: Object.freeze({\n type: SnapCaveatType.PermittedCoinTypes,\n decorator: (\n method,\n caveat: Caveat<\n SnapCaveatType.PermittedCoinTypes,\n GetBip44EntropyParams[]\n >,\n ) => {\n return async (args) => {\n const { params } = args;\n validateBIP44Params(params);\n\n const coinType = caveat.value.find(\n (caveatValue) => caveatValue.coinType === params.coinType,\n );\n\n if (!coinType) {\n throw providerErrors.unauthorized({\n message:\n 'The requested coin type is not permitted. Allowed coin types must be specified in the snap manifest.',\n });\n }\n\n return await method(args);\n };\n },\n validator: (caveat) => validateBIP44Caveat(caveat),\n }),\n};\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
methodHandlers
|
|
3
|
+
} from "./chunk-YJ3ZFIA7.mjs";
|
|
4
|
+
import {
|
|
5
|
+
selectHooks
|
|
6
|
+
} from "./chunk-DR63Z4PV.mjs";
|
|
7
|
+
|
|
8
|
+
// src/permitted/middleware.ts
|
|
9
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
10
|
+
import { logError } from "@metamask/snaps-utils";
|
|
11
|
+
function createSnapsMethodMiddleware(isSnap, hooks) {
|
|
12
|
+
return async function methodMiddleware(request, response, next, end) {
|
|
13
|
+
const handler = methodHandlers[request.method];
|
|
14
|
+
if (handler) {
|
|
15
|
+
if (String.prototype.startsWith.call(request.method, "snap_") && !isSnap) {
|
|
16
|
+
return end(rpcErrors.methodNotFound());
|
|
17
|
+
}
|
|
18
|
+
const { implementation, hookNames } = handler;
|
|
19
|
+
try {
|
|
20
|
+
return await implementation(
|
|
21
|
+
request,
|
|
22
|
+
response,
|
|
23
|
+
next,
|
|
24
|
+
end,
|
|
25
|
+
selectHooks(hooks, hookNames)
|
|
26
|
+
);
|
|
27
|
+
} catch (error) {
|
|
28
|
+
logError(error);
|
|
29
|
+
return end(error);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return next();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
createSnapsMethodMiddleware
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-BZIPLSKM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { selectHooks } from '../utils';\nimport { methodHandlers } from './handlers';\n\n/**\n * Creates a middleware that handles permitted snap RPC methods.\n *\n * @param isSnap - A flag that should indicate whether the requesting origin is a snap or not.\n * @param hooks - An object containing the hooks made available to the permitted RPC methods.\n * @returns The middleware.\n */\nexport function createSnapsMethodMiddleware(\n isSnap: boolean,\n hooks: Record<string, unknown>,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This is not actually a misused promise, the type is just wrong\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n if (\n String.prototype.startsWith.call(request.method, 'snap_') &&\n !isSnap\n ) {\n return end(rpcErrors.methodNotFound());\n }\n\n // TODO: Once json-rpc-engine types are up to date, we should type this correctly\n const { implementation, hookNames } = handler as any;\n try {\n // Implementations may or may not be async, so we must await them.\n return await implementation(\n request,\n response,\n next,\n end,\n selectHooks(hooks, hookNames),\n );\n } catch (error) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"],"mappings":";;;;;;;;AACA,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AAalB,SAAS,4BACd,QACA,OACwC;AAGxC,SAAO,eAAe,iBAAiB,SAAS,UAAU,MAAM,KAAK;AACnE,UAAM,UACJ,eAAe,QAAQ,MAAqC;AAC9D,QAAI,SAAS;AACX,UACE,OAAO,UAAU,WAAW,KAAK,QAAQ,QAAQ,OAAO,KACxD,CAAC,QACD;AACA,eAAO,IAAI,UAAU,eAAe,CAAC;AAAA,MACvC;AAGA,YAAM,EAAE,gBAAgB,UAAU,IAAI;AACtC,UAAI;AAEF,eAAO,MAAM;AAAA,UACX;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,YAAY,OAAO,SAAS;AAAA,QAC9B;AAAA,MACF,SAAS,OAAO;AACd,iBAAS,KAAK;AACd,eAAO,IAAI,KAAK;AAAA,MAClB;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/permitted/invokeSnapSugar.ts
|
|
2
|
+
var _rpcerrors = require('@metamask/rpc-errors');
|
|
3
|
+
var _utils = require('@metamask/utils');
|
|
4
|
+
var invokeSnapSugarHandler = {
|
|
5
|
+
methodNames: ["wallet_invokeSnap"],
|
|
6
|
+
implementation: invokeSnapSugar,
|
|
7
|
+
hookNames: void 0
|
|
8
|
+
};
|
|
9
|
+
function invokeSnapSugar(req, _res, next, end) {
|
|
10
|
+
let params;
|
|
11
|
+
try {
|
|
12
|
+
params = getValidatedParams(req.params);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return end(error);
|
|
15
|
+
}
|
|
16
|
+
req.method = "wallet_snap";
|
|
17
|
+
req.params = params;
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
function getValidatedParams(params) {
|
|
21
|
+
if (!_utils.isObject.call(void 0, params)) {
|
|
22
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
23
|
+
message: "Expected params to be a single object."
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const { snapId, request } = params;
|
|
27
|
+
if (!snapId || typeof snapId !== "string" || snapId === "") {
|
|
28
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
29
|
+
message: "Must specify a valid snap ID."
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (!_utils.isObject.call(void 0, request)) {
|
|
33
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
34
|
+
message: "Expected request to be a single object."
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return params;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.invokeSnapSugarHandler = invokeSnapSugarHandler; exports.invokeSnapSugar = invokeSnapSugar; exports.getValidatedParams = getValidatedParams;
|
|
45
|
+
//# sourceMappingURL=chunk-CIIMO4C2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/invokeSnapSugar.ts"],"names":[],"mappings":";AAKA,SAAS,iBAAiB;AAG1B,SAAS,gBAAgB;AAKlB,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,mBAAmB;AAAA,EACjC,gBAAgB;AAAA,EAChB,WAAW;AACb;AAcO,SAAS,gBACd,KACA,MACA,MACA,KACM;AACN,MAAI;AACJ,MAAI;AACF,aAAS,mBAAmB,IAAI,MAAM;AAAA,EACxC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,MAAI,SAAS;AACb,MAAI,SAAS;AACb,SAAO,KAAK;AACd;AASO,SAAS,mBAAmB,QAAmC;AACpE,MAAI,CAAC,SAAS,MAAM,GAAG;AACrB,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,QAAM,EAAE,QAAQ,QAAQ,IAAI;AAE5B,MAAI,CAAC,UAAU,OAAO,WAAW,YAAY,WAAW,IAAI;AAC1D,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,MAAI,CAAC,SAAS,OAAO,GAAG;AACtB,UAAM,UAAU,cAAc;AAAA,MAC5B,SAAS;AAAA,IACX,CAAC;AAAA,EACH;AAEA,SAAO;AACT","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n} from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { InvokeSnapParams, InvokeSnapResult } from '@metamask/snaps-sdk';\nimport type { JsonRpcRequest } from '@metamask/utils';\nimport { isObject } from '@metamask/utils';\n\n/**\n * `wallet_invokeSnap` attempts to invoke an RPC method of the specified Snap.\n */\nexport const invokeSnapSugarHandler: PermittedHandlerExport<\n void,\n InvokeSnapParams,\n InvokeSnapResult\n> = {\n methodNames: ['wallet_invokeSnap'],\n implementation: invokeSnapSugar,\n hookNames: undefined,\n};\n\n/**\n * The `wallet_invokeSnap` method implementation.\n * Reroutes incoming JSON-RPC requests that are targeting snaps, by modifying the method and params.\n *\n * @param req - The JSON-RPC request object.\n * @param _res - The JSON-RPC response object. Not used by this\n * function.\n * @param next - The `json-rpc-engine` \"next\" callback.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @returns Nothing.\n * @throws If the params are invalid.\n */\nexport function invokeSnapSugar(\n req: JsonRpcRequest<InvokeSnapParams>,\n _res: unknown,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n): void {\n let params: InvokeSnapParams;\n try {\n params = getValidatedParams(req.params);\n } catch (error) {\n return end(error);\n }\n\n req.method = 'wallet_snap';\n req.params = params;\n return next();\n}\n\n/**\n * Validates the wallet_invokeSnap method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(params: unknown): InvokeSnapParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { snapId, request } = params;\n\n if (!snapId || typeof snapId !== 'string' || snapId === '') {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid snap ID.',\n });\n }\n\n if (!isObject(request)) {\n throw rpcErrors.invalidParams({\n message: 'Expected request to be a single object.',\n });\n }\n\n return params as InvokeSnapParams;\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/endowments/network-access.ts
|
|
2
|
+
var _permissioncontroller = require('@metamask/permission-controller');
|
|
3
|
+
var permissionName = "endowment:network-access" /* NetworkAccess */;
|
|
4
|
+
var specificationBuilder = (_builderOptions) => {
|
|
5
|
+
return {
|
|
6
|
+
permissionType: _permissioncontroller.PermissionType.Endowment,
|
|
7
|
+
targetName: permissionName,
|
|
8
|
+
allowedCaveats: null,
|
|
9
|
+
endowmentGetter: (_getterOptions) => {
|
|
10
|
+
return ["fetch", "Request", "Headers", "Response"];
|
|
11
|
+
},
|
|
12
|
+
subjectTypes: [_permissioncontroller.SubjectType.Snap]
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
var networkAccessEndowmentBuilder = Object.freeze({
|
|
16
|
+
targetName: permissionName,
|
|
17
|
+
specificationBuilder
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
exports.networkAccessEndowmentBuilder = networkAccessEndowmentBuilder;
|
|
23
|
+
//# sourceMappingURL=chunk-DBYI25UR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/endowments/network-access.ts"],"names":[],"mappings":";AAKA,SAAS,gBAAgB,mBAAmB;AAI5C,IAAM;AAmBN,IAAM,uBAIF,CAAC,oBAA0B;AAC7B,SAAO;AAAA,IACL,gBAAgB,eAAe;AAAA,IAC/B,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,iBAAiB,CAAC,mBAA2C;AAC3D,aAAO,CAAC,SAAS,WAAW,WAAW,UAAU;AAAA,IACnD;AAAA,IACA,cAAc,CAAC,YAAY,IAAI;AAAA,EACjC;AACF;AAEO,IAAM,gCAAgC,OAAO,OAAO;AAAA,EACzD,YAAY;AAAA,EACZ;AACF,CAAU","sourcesContent":["import type {\n EndowmentGetterParams,\n PermissionSpecificationBuilder,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\n\nimport { SnapEndowments } from './enum';\n\nconst permissionName = SnapEndowments.NetworkAccess;\n\ntype NetworkAccessEndowmentSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.Endowment;\n targetName: typeof permissionName;\n endowmentGetter: (\n _options?: any,\n ) => ['fetch', 'Request', 'Headers', 'Response'];\n allowedCaveats: null;\n}>;\n\n/**\n * `endowment:network-access` returns the name of global browser API(s) that\n * enable network access. This is intended to populate the endowments of the\n * SES Compartment in which a Snap executes.\n *\n * @param _builderOptions - Optional specification builder options.\n * @returns The specification for the network endowment.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.Endowment,\n any,\n NetworkAccessEndowmentSpecification\n> = (_builderOptions?: any) => {\n return {\n permissionType: PermissionType.Endowment,\n targetName: permissionName,\n allowedCaveats: null,\n endowmentGetter: (_getterOptions?: EndowmentGetterParams) => {\n return ['fetch', 'Request', 'Headers', 'Response'];\n },\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nexport const networkAccessEndowmentBuilder = Object.freeze({\n targetName: permissionName,\n specificationBuilder,\n} as const);\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/permitted/updateInterface.ts
|
|
2
|
+
var _rpcerrors = require('@metamask/rpc-errors');
|
|
3
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
4
|
+
var _superstruct = require('superstruct');
|
|
5
|
+
var hookNames = {
|
|
6
|
+
updateInterface: true
|
|
7
|
+
};
|
|
8
|
+
var updateInterfaceHandler = {
|
|
9
|
+
methodNames: ["snap_updateInterface"],
|
|
10
|
+
implementation: getUpdateInterfaceImplementation,
|
|
11
|
+
hookNames
|
|
12
|
+
};
|
|
13
|
+
var UpdateInterfaceParametersStruct = _superstruct.object.call(void 0, {
|
|
14
|
+
id: _superstruct.string.call(void 0, ),
|
|
15
|
+
ui: _snapssdk.ComponentStruct
|
|
16
|
+
});
|
|
17
|
+
async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
|
|
18
|
+
const { params } = req;
|
|
19
|
+
try {
|
|
20
|
+
const validatedParams = getValidatedParams(params);
|
|
21
|
+
const { id, ui } = validatedParams;
|
|
22
|
+
await updateInterface(id, ui);
|
|
23
|
+
res.result = null;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
return end(error);
|
|
26
|
+
}
|
|
27
|
+
return end();
|
|
28
|
+
}
|
|
29
|
+
function getValidatedParams(params) {
|
|
30
|
+
try {
|
|
31
|
+
return _superstruct.create.call(void 0, params, UpdateInterfaceParametersStruct);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
if (error instanceof _superstruct.StructError) {
|
|
34
|
+
throw _rpcerrors.rpcErrors.invalidParams({
|
|
35
|
+
message: `Invalid params: ${error.message}.`
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
throw _rpcerrors.rpcErrors.internal();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
exports.updateInterfaceHandler = updateInterfaceHandler;
|
|
45
|
+
//# sourceMappingURL=chunk-DDGDVWAW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/updateInterface.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,uBAAuB;AAGhC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n Component,\n UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { ComponentStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n */\n updateInterface: (id: string, ui: Component) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentStruct,\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui } = validatedParams;\n\n await updateInterface(id, ui);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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 updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
import { SLIP10Node } from "@metamask/key-tree";
|
|
3
|
+
import {
|
|
4
|
+
add0x,
|
|
5
|
+
assert,
|
|
6
|
+
concatBytes,
|
|
7
|
+
createDataView,
|
|
8
|
+
stringToBytes
|
|
9
|
+
} from "@metamask/utils";
|
|
10
|
+
import { keccak_256 as keccak256 } from "@noble/hashes/sha3";
|
|
11
|
+
var HARDENED_VALUE = 2147483648;
|
|
12
|
+
function selectHooks(hooks, hookNames) {
|
|
13
|
+
if (hookNames) {
|
|
14
|
+
return Object.keys(hookNames).reduce(
|
|
15
|
+
(hookSubset, _hookName) => {
|
|
16
|
+
const hookName = _hookName;
|
|
17
|
+
hookSubset[hookName] = hooks[hookName];
|
|
18
|
+
return hookSubset;
|
|
19
|
+
},
|
|
20
|
+
{}
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
function getDerivationPathArray(hash) {
|
|
26
|
+
const array = [];
|
|
27
|
+
const view = createDataView(hash);
|
|
28
|
+
for (let index = 0; index < 8; index++) {
|
|
29
|
+
const uint32 = view.getUint32(index * 4);
|
|
30
|
+
const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;
|
|
31
|
+
array.push(`bip32:${pathIndex - HARDENED_VALUE}'`);
|
|
32
|
+
}
|
|
33
|
+
return array;
|
|
34
|
+
}
|
|
35
|
+
async function deriveEntropy({
|
|
36
|
+
input,
|
|
37
|
+
salt = "",
|
|
38
|
+
mnemonicPhrase,
|
|
39
|
+
magic
|
|
40
|
+
}) {
|
|
41
|
+
const inputBytes = stringToBytes(input);
|
|
42
|
+
const saltBytes = stringToBytes(salt);
|
|
43
|
+
const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));
|
|
44
|
+
const computedDerivationPath = getDerivationPathArray(hash);
|
|
45
|
+
const { privateKey } = await SLIP10Node.fromDerivationPath({
|
|
46
|
+
derivationPath: [
|
|
47
|
+
mnemonicPhrase,
|
|
48
|
+
`bip32:${magic}`,
|
|
49
|
+
...computedDerivationPath
|
|
50
|
+
],
|
|
51
|
+
curve: "secp256k1"
|
|
52
|
+
});
|
|
53
|
+
assert(privateKey, "Failed to derive the entropy.");
|
|
54
|
+
return add0x(privateKey);
|
|
55
|
+
}
|
|
56
|
+
function getPathPrefix(curve) {
|
|
57
|
+
if (curve === "secp256k1") {
|
|
58
|
+
return "bip32";
|
|
59
|
+
}
|
|
60
|
+
return "slip10";
|
|
61
|
+
}
|
|
62
|
+
async function getNode({
|
|
63
|
+
curve,
|
|
64
|
+
secretRecoveryPhrase,
|
|
65
|
+
path
|
|
66
|
+
}) {
|
|
67
|
+
const prefix = getPathPrefix(curve);
|
|
68
|
+
return await SLIP10Node.fromDerivationPath({
|
|
69
|
+
curve,
|
|
70
|
+
derivationPath: [
|
|
71
|
+
secretRecoveryPhrase,
|
|
72
|
+
...path.slice(1).map((index) => `${prefix}:${index}`)
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
selectHooks,
|
|
79
|
+
deriveEntropy,
|
|
80
|
+
getPathPrefix,
|
|
81
|
+
getNode
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=chunk-DR63Z4PV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type {\n HardenedBIP32Node,\n BIP32Node,\n SLIP10PathNode,\n} from '@metamask/key-tree';\nimport { SLIP10Node } from '@metamask/key-tree';\nimport type { MagicValue } from '@metamask/snaps-utils';\nimport type { Hex } from '@metamask/utils';\nimport {\n add0x,\n assert,\n concatBytes,\n createDataView,\n stringToBytes,\n} from '@metamask/utils';\nimport { keccak_256 as keccak256 } from '@noble/hashes/sha3';\n\nconst HARDENED_VALUE = 0x80000000;\n\n/**\n * Maps an interface with method hooks to an object, using the keys of the\n * interface, and `true` as value. This ensures that the `methodHooks` object\n * has the same values as the interface.\n */\nexport type MethodHooksObject<HooksType extends Record<string, unknown>> = {\n [Key in keyof HooksType]: true;\n};\n\n/**\n * Returns the subset of the specified `hooks` that are included in the\n * `hookNames` object. This is a Principle of Least Authority (POLA) measure\n * to ensure that each RPC method implementation only has access to the\n * API \"hooks\" it needs to do its job.\n *\n * @param hooks - The hooks to select from.\n * @param hookNames - The names of the hooks to select.\n * @returns The selected hooks.\n * @template Hooks - The hooks to select from.\n * @template HookName - The names of the hooks to select.\n */\nexport function selectHooks<\n Hooks extends Record<string, unknown>,\n HookName extends keyof Hooks,\n>(\n hooks: Hooks,\n hookNames?: Record<HookName, boolean>,\n): Pick<Hooks, HookName> | undefined {\n if (hookNames) {\n return Object.keys(hookNames).reduce<Partial<Pick<Hooks, HookName>>>(\n (hookSubset, _hookName) => {\n const hookName = _hookName as HookName;\n hookSubset[hookName] = hooks[hookName];\n return hookSubset;\n },\n {},\n ) as Pick<Hooks, HookName>;\n }\n return undefined;\n}\n\n/**\n * Get a BIP-32 derivation path array from a hash, which is compatible with\n * `@metamask/key-tree`. The hash is assumed to be 32 bytes long.\n *\n * @param hash - The hash to derive indices from.\n * @returns The derived indices as a {@link HardenedBIP32Node} array.\n */\nfunction getDerivationPathArray(hash: Uint8Array): HardenedBIP32Node[] {\n const array: HardenedBIP32Node[] = [];\n const view = createDataView(hash);\n\n for (let index = 0; index < 8; index++) {\n const uint32 = view.getUint32(index * 4);\n\n // This is essentially `index | 0x80000000`. Because JavaScript numbers are\n // signed, we use the bitwise unsigned right shift operator to ensure that\n // the result is a positive number.\n // eslint-disable-next-line no-bitwise\n const pathIndex = (uint32 | HARDENED_VALUE) >>> 0;\n array.push(`bip32:${pathIndex - HARDENED_VALUE}'` as const);\n }\n\n return array;\n}\n\ntype DeriveEntropyOptions = {\n /**\n * The input value to derive entropy from.\n */\n input: string;\n\n /**\n * An optional salt to use when deriving entropy.\n */\n salt?: string;\n\n /**\n * The mnemonic phrase to use for entropy derivation.\n */\n mnemonicPhrase: Uint8Array;\n\n /**\n * A hardened BIP-32 index, which is used to derive the root key from the\n * mnemonic phrase.\n */\n magic: MagicValue;\n};\n\n/**\n * Derive entropy from the given mnemonic phrase and salt.\n *\n * This is based on the reference implementation of\n * [SIP-6](https://metamask.github.io/SIPs/SIPS/sip-6).\n *\n * @param options - The options for entropy derivation.\n * @param options.input - The input value to derive entropy from.\n * @param options.salt - An optional salt to use when deriving entropy.\n * @param options.mnemonicPhrase - The mnemonic phrase to use for entropy\n * derivation.\n * @param options.magic - A hardened BIP-32 index, which is used to derive the\n * root key from the mnemonic phrase.\n * @returns The derived entropy.\n */\nexport async function deriveEntropy({\n input,\n salt = '',\n mnemonicPhrase,\n magic,\n}: DeriveEntropyOptions): Promise<Hex> {\n const inputBytes = stringToBytes(input);\n const saltBytes = stringToBytes(salt);\n\n // Get the derivation path from the snap ID.\n const hash = keccak256(concatBytes([inputBytes, keccak256(saltBytes)]));\n const computedDerivationPath = getDerivationPathArray(hash);\n\n // Derive the private key using BIP-32.\n const { privateKey } = await SLIP10Node.fromDerivationPath({\n derivationPath: [\n mnemonicPhrase,\n `bip32:${magic}`,\n ...computedDerivationPath,\n ],\n curve: 'secp256k1',\n });\n\n // This should never happen, but this keeps TypeScript happy.\n assert(privateKey, 'Failed to derive the entropy.');\n\n return add0x(privateKey);\n}\n\n/**\n * Get the path prefix to use for key derivation in `key-tree`. This assumes the\n * following:\n *\n * - The Secp256k1 curve always use the BIP-32 specification.\n * - The Ed25519 curve always use the SLIP-10 specification.\n *\n * While this does not matter in most situations (no known case at the time of\n * writing), `key-tree` requires a specific specification to be used.\n *\n * @param curve - The curve to get the path prefix for. The curve is NOT\n * validated by this function.\n * @returns The path prefix, i.e., `secp256k1` or `ed25519`.\n */\nexport function getPathPrefix(\n curve: 'secp256k1' | 'ed25519',\n): 'bip32' | 'slip10' {\n if (curve === 'secp256k1') {\n return 'bip32';\n }\n\n return 'slip10';\n}\n\ntype GetNodeArgs = {\n curve: 'secp256k1' | 'ed25519';\n secretRecoveryPhrase: Uint8Array;\n path: string[];\n};\n\n/**\n * Get a `key-tree`-compatible node.\n *\n * Note: This function assumes that all the parameters have been validated\n * beforehand.\n *\n * @param options - The derivation options.\n * @param options.curve - The curve to use for derivation.\n * @param options.secretRecoveryPhrase - The secret recovery phrase to use for\n * derivation.\n * @param options.path - The derivation path to use as array, starting with an\n * \"m\" as the first item.\n */\nexport async function getNode({\n curve,\n secretRecoveryPhrase,\n path,\n}: GetNodeArgs) {\n const prefix = getPathPrefix(curve);\n return await SLIP10Node.fromDerivationPath({\n curve,\n derivationPath: [\n secretRecoveryPhrase,\n ...(path.slice(1).map((index) => `${prefix}:${index}`) as\n | BIP32Node[]\n | SLIP10PathNode[]),\n ],\n });\n}\n"],"mappings":";AAKA,SAAS,kBAAkB;AAG3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc,iBAAiB;AAExC,IAAM,iBAAiB;AAuBhB,SAAS,YAId,OACA,WACmC;AACnC,MAAI,WAAW;AACb,WAAO,OAAO,KAAK,SAAS,EAAE;AAAA,MAC5B,CAAC,YAAY,cAAc;AACzB,cAAM,WAAW;AACjB,mBAAW,QAAQ,IAAI,MAAM,QAAQ;AACrC,eAAO;AAAA,MACT;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACA,SAAO;AACT;AASA,SAAS,uBAAuB,MAAuC;AACrE,QAAM,QAA6B,CAAC;AACpC,QAAM,OAAO,eAAe,IAAI;AAEhC,WAAS,QAAQ,GAAG,QAAQ,GAAG,SAAS;AACtC,UAAM,SAAS,KAAK,UAAU,QAAQ,CAAC;AAMvC,UAAM,aAAa,SAAS,oBAAoB;AAChD,UAAM,KAAK,SAAS,YAAY,cAAc,GAAY;AAAA,EAC5D;AAEA,SAAO;AACT;AAwCA,eAAsB,cAAc;AAAA,EAClC;AAAA,EACA,OAAO;AAAA,EACP;AAAA,EACA;AACF,GAAuC;AACrC,QAAM,aAAa,cAAc,KAAK;AACtC,QAAM,YAAY,cAAc,IAAI;AAGpC,QAAM,OAAO,UAAU,YAAY,CAAC,YAAY,UAAU,SAAS,CAAC,CAAC,CAAC;AACtE,QAAM,yBAAyB,uBAAuB,IAAI;AAG1D,QAAM,EAAE,WAAW,IAAI,MAAM,WAAW,mBAAmB;AAAA,IACzD,gBAAgB;AAAA,MACd;AAAA,MACA,SAAS,KAAK;AAAA,MACd,GAAG;AAAA,IACL;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AAGD,SAAO,YAAY,+BAA+B;AAElD,SAAO,MAAM,UAAU;AACzB;AAgBO,SAAS,cACd,OACoB;AACpB,MAAI,UAAU,aAAa;AACzB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAqBA,eAAsB,QAAQ;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACF,GAAgB;AACd,QAAM,SAAS,cAAc,KAAK;AAClC,SAAO,MAAM,WAAW,mBAAmB;AAAA,IACzC;AAAA,IACA,gBAAgB;AAAA,MACd;AAAA,MACA,GAAI,KAAK,MAAM,CAAC,EAAE,IAAI,CAAC,UAAU,GAAG,MAAM,IAAI,KAAK,EAAE;AAAA,IAGvD;AAAA,EACF,CAAC;AACH;","names":[]}
|