@metamask/snaps-jest 8.3.1 → 8.4.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 +16 -1
- package/dist/environment.cjs +2 -1
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.cts +1 -1
- package/dist/environment.d.cts.map +1 -1
- package/dist/environment.d.mts +1 -1
- package/dist/environment.d.mts.map +1 -1
- package/dist/environment.mjs +3 -2
- package/dist/environment.mjs.map +1 -1
- package/dist/helpers.cjs +13 -80
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +2 -44
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +2 -44
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +4 -64
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +8 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/internals/environment.d.cts +1 -1
- package/dist/internals/environment.d.mts +1 -1
- package/dist/internals/index.cjs +0 -3
- package/dist/internals/index.cjs.map +1 -1
- package/dist/internals/index.d.cts +0 -3
- package/dist/internals/index.d.cts.map +1 -1
- package/dist/internals/index.d.mts +0 -3
- package/dist/internals/index.d.mts.map +1 -1
- package/dist/internals/index.mjs +0 -3
- package/dist/internals/index.mjs.map +1 -1
- package/dist/matchers.cjs +3 -3
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.cts.map +1 -1
- package/dist/matchers.d.mts.map +1 -1
- package/dist/matchers.mjs +1 -1
- package/dist/matchers.mjs.map +1 -1
- package/dist/types/types.cjs.map +1 -1
- package/dist/types/types.d.cts +8 -1
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.mts +8 -1
- package/dist/types/types.d.mts.map +1 -1
- package/dist/types/types.mjs.map +1 -1
- package/package.json +7 -20
- package/dist/internals/request.cjs +0 -143
- package/dist/internals/request.cjs.map +0 -1
- package/dist/internals/request.d.cts +0 -56
- package/dist/internals/request.d.cts.map +0 -1
- package/dist/internals/request.d.mts +0 -56
- package/dist/internals/request.d.mts.map +0 -1
- package/dist/internals/request.mjs +0 -138
- package/dist/internals/request.mjs.map +0 -1
- package/dist/internals/simulation/constants.cjs +0 -21
- package/dist/internals/simulation/constants.cjs.map +0 -1
- package/dist/internals/simulation/constants.d.cts +0 -18
- package/dist/internals/simulation/constants.d.cts.map +0 -1
- package/dist/internals/simulation/constants.d.mts +0 -18
- package/dist/internals/simulation/constants.d.mts.map +0 -1
- package/dist/internals/simulation/constants.mjs +0 -18
- package/dist/internals/simulation/constants.mjs.map +0 -1
- package/dist/internals/simulation/controllers.cjs +0 -101
- package/dist/internals/simulation/controllers.cjs.map +0 -1
- package/dist/internals/simulation/controllers.d.cts +0 -41
- package/dist/internals/simulation/controllers.d.cts.map +0 -1
- package/dist/internals/simulation/controllers.d.mts +0 -41
- package/dist/internals/simulation/controllers.d.mts.map +0 -1
- package/dist/internals/simulation/controllers.mjs +0 -96
- package/dist/internals/simulation/controllers.mjs.map +0 -1
- package/dist/internals/simulation/files.cjs +0 -94
- package/dist/internals/simulation/files.cjs.map +0 -1
- package/dist/internals/simulation/files.d.cts +0 -49
- package/dist/internals/simulation/files.d.cts.map +0 -1
- package/dist/internals/simulation/files.d.mts +0 -49
- package/dist/internals/simulation/files.d.mts.map +0 -1
- package/dist/internals/simulation/files.mjs +0 -91
- package/dist/internals/simulation/files.mjs.map +0 -1
- package/dist/internals/simulation/index.cjs +0 -22
- package/dist/internals/simulation/index.cjs.map +0 -1
- package/dist/internals/simulation/index.d.cts +0 -6
- package/dist/internals/simulation/index.d.cts.map +0 -1
- package/dist/internals/simulation/index.d.mts +0 -6
- package/dist/internals/simulation/index.d.mts.map +0 -1
- package/dist/internals/simulation/index.mjs +0 -6
- package/dist/internals/simulation/index.mjs.map +0 -1
- package/dist/internals/simulation/interface.cjs +0 -527
- package/dist/internals/simulation/interface.cjs.map +0 -1
- package/dist/internals/simulation/interface.d.cts +0 -152
- package/dist/internals/simulation/interface.d.cts.map +0 -1
- package/dist/internals/simulation/interface.d.mts +0 -152
- package/dist/internals/simulation/interface.d.mts.map +0 -1
- package/dist/internals/simulation/interface.mjs +0 -513
- package/dist/internals/simulation/interface.mjs.map +0 -1
- package/dist/internals/simulation/methods/constants.cjs +0 -72
- package/dist/internals/simulation/methods/constants.cjs.map +0 -1
- package/dist/internals/simulation/methods/constants.d.cts +0 -11
- package/dist/internals/simulation/methods/constants.d.cts.map +0 -1
- package/dist/internals/simulation/methods/constants.d.mts +0 -11
- package/dist/internals/simulation/methods/constants.d.mts.map +0 -1
- package/dist/internals/simulation/methods/constants.mjs +0 -69
- package/dist/internals/simulation/methods/constants.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs +0 -18
- package/dist/internals/simulation/methods/hooks/get-preferences.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs +0 -14
- package/dist/internals/simulation/methods/hooks/get-preferences.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.cjs +0 -22
- package/dist/internals/simulation/methods/hooks/index.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.d.cts +0 -6
- package/dist/internals/simulation/methods/hooks/index.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.d.mts +0 -6
- package/dist/internals/simulation/methods/hooks/index.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/index.mjs +0 -6
- package/dist/internals/simulation/methods/hooks/index.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.cjs +0 -24
- package/dist/internals/simulation/methods/hooks/interface.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.d.cts +0 -17
- package/dist/internals/simulation/methods/hooks/interface.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.d.mts +0 -17
- package/dist/internals/simulation/methods/hooks/interface.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/interface.mjs +0 -19
- package/dist/internals/simulation/methods/hooks/interface.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.cjs +0 -58
- package/dist/internals/simulation/methods/hooks/notifications.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.d.cts +0 -17
- package/dist/internals/simulation/methods/hooks/notifications.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.d.mts +0 -17
- package/dist/internals/simulation/methods/hooks/notifications.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/notifications.mjs +0 -55
- package/dist/internals/simulation/methods/hooks/notifications.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs +0 -38
- package/dist/internals/simulation/methods/hooks/request-user-approval.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts +0 -16
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts +0 -16
- package/dist/internals/simulation/methods/hooks/request-user-approval.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +0 -35
- package/dist/internals/simulation/methods/hooks/request-user-approval.mjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.cjs +0 -84
- package/dist/internals/simulation/methods/hooks/state.cjs.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.d.cts +0 -24
- package/dist/internals/simulation/methods/hooks/state.d.cts.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.d.mts +0 -24
- package/dist/internals/simulation/methods/hooks/state.d.mts.map +0 -1
- package/dist/internals/simulation/methods/hooks/state.mjs +0 -79
- package/dist/internals/simulation/methods/hooks/state.mjs.map +0 -1
- package/dist/internals/simulation/methods/index.cjs +0 -18
- package/dist/internals/simulation/methods/index.cjs.map +0 -1
- package/dist/internals/simulation/methods/index.d.cts +0 -2
- package/dist/internals/simulation/methods/index.d.cts.map +0 -1
- package/dist/internals/simulation/methods/index.d.mts +0 -2
- package/dist/internals/simulation/methods/index.d.mts.map +0 -1
- package/dist/internals/simulation/methods/index.mjs +0 -2
- package/dist/internals/simulation/methods/index.mjs.map +0 -1
- package/dist/internals/simulation/methods/specifications.cjs +0 -85
- package/dist/internals/simulation/methods/specifications.cjs.map +0 -1
- package/dist/internals/simulation/methods/specifications.d.cts +0 -57
- package/dist/internals/simulation/methods/specifications.d.cts.map +0 -1
- package/dist/internals/simulation/methods/specifications.d.mts +0 -57
- package/dist/internals/simulation/methods/specifications.d.mts.map +0 -1
- package/dist/internals/simulation/methods/specifications.mjs +0 -78
- package/dist/internals/simulation/methods/specifications.mjs.map +0 -1
- package/dist/internals/simulation/middleware/engine.cjs +0 -37
- package/dist/internals/simulation/middleware/engine.cjs.map +0 -1
- package/dist/internals/simulation/middleware/engine.d.cts +0 -27
- package/dist/internals/simulation/middleware/engine.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/engine.d.mts +0 -27
- package/dist/internals/simulation/middleware/engine.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/engine.mjs +0 -34
- package/dist/internals/simulation/middleware/engine.mjs.map +0 -1
- package/dist/internals/simulation/middleware/index.cjs +0 -18
- package/dist/internals/simulation/middleware/index.cjs.map +0 -1
- package/dist/internals/simulation/middleware/index.d.cts +0 -2
- package/dist/internals/simulation/middleware/index.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/index.d.mts +0 -2
- package/dist/internals/simulation/middleware/index.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/index.mjs +0 -2
- package/dist/internals/simulation/middleware/index.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs +0 -34
- package/dist/internals/simulation/middleware/internal-methods/accounts.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts +0 -20
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts +0 -20
- package/dist/internals/simulation/middleware/internal-methods/accounts.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +0 -30
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.cjs +0 -18
- package/dist/internals/simulation/middleware/internal-methods/index.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/index.mjs +0 -2
- package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs +0 -44
- package/dist/internals/simulation/middleware/internal-methods/middleware.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts +0 -23
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts +0 -23
- package/dist/internals/simulation/middleware/internal-methods/middleware.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +0 -40
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs +0 -28
- package/dist/internals/simulation/middleware/internal-methods/provider-state.cjs.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts +0 -16
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts +0 -16
- package/dist/internals/simulation/middleware/internal-methods/provider-state.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +0 -24
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +0 -1
- package/dist/internals/simulation/middleware/mock.cjs +0 -22
- package/dist/internals/simulation/middleware/mock.cjs.map +0 -1
- package/dist/internals/simulation/middleware/mock.d.cts +0 -11
- package/dist/internals/simulation/middleware/mock.d.cts.map +0 -1
- package/dist/internals/simulation/middleware/mock.d.mts +0 -11
- package/dist/internals/simulation/middleware/mock.d.mts.map +0 -1
- package/dist/internals/simulation/middleware/mock.mjs +0 -18
- package/dist/internals/simulation/middleware/mock.mjs.map +0 -1
- package/dist/internals/simulation/options.cjs +0 -25
- package/dist/internals/simulation/options.cjs.map +0 -1
- package/dist/internals/simulation/options.d.cts +0 -40
- package/dist/internals/simulation/options.d.cts.map +0 -1
- package/dist/internals/simulation/options.d.mts +0 -40
- package/dist/internals/simulation/options.d.mts.map +0 -1
- package/dist/internals/simulation/options.mjs +0 -21
- package/dist/internals/simulation/options.mjs.map +0 -1
- package/dist/internals/simulation/simulation.cjs +0 -155
- package/dist/internals/simulation/simulation.cjs.map +0 -1
- package/dist/internals/simulation/simulation.d.cts +0 -103
- package/dist/internals/simulation/simulation.d.cts.map +0 -1
- package/dist/internals/simulation/simulation.d.mts +0 -103
- package/dist/internals/simulation/simulation.d.mts.map +0 -1
- package/dist/internals/simulation/simulation.mjs +0 -150
- package/dist/internals/simulation/simulation.mjs.map +0 -1
- package/dist/internals/simulation/store/index.cjs +0 -21
- package/dist/internals/simulation/store/index.cjs.map +0 -1
- package/dist/internals/simulation/store/index.d.cts +0 -5
- package/dist/internals/simulation/store/index.d.cts.map +0 -1
- package/dist/internals/simulation/store/index.d.mts +0 -5
- package/dist/internals/simulation/store/index.d.mts.map +0 -1
- package/dist/internals/simulation/store/index.mjs +0 -5
- package/dist/internals/simulation/store/index.mjs.map +0 -1
- package/dist/internals/simulation/store/mocks.cjs +0 -39
- package/dist/internals/simulation/store/mocks.cjs.map +0 -1
- package/dist/internals/simulation/store/mocks.d.cts +0 -36
- package/dist/internals/simulation/store/mocks.d.cts.map +0 -1
- package/dist/internals/simulation/store/mocks.d.mts +0 -36
- package/dist/internals/simulation/store/mocks.d.mts.map +0 -1
- package/dist/internals/simulation/store/mocks.mjs +0 -35
- package/dist/internals/simulation/store/mocks.mjs.map +0 -1
- package/dist/internals/simulation/store/notifications.cjs +0 -35
- package/dist/internals/simulation/store/notifications.cjs.map +0 -1
- package/dist/internals/simulation/store/notifications.d.cts +0 -45
- package/dist/internals/simulation/store/notifications.d.cts.map +0 -1
- package/dist/internals/simulation/store/notifications.d.mts +0 -45
- package/dist/internals/simulation/store/notifications.d.mts.map +0 -1
- package/dist/internals/simulation/store/notifications.mjs +0 -32
- package/dist/internals/simulation/store/notifications.mjs.map +0 -1
- package/dist/internals/simulation/store/state.cjs +0 -54
- package/dist/internals/simulation/store/state.cjs.map +0 -1
- package/dist/internals/simulation/store/state.d.cts +0 -56
- package/dist/internals/simulation/store/state.d.cts.map +0 -1
- package/dist/internals/simulation/store/state.d.mts +0 -56
- package/dist/internals/simulation/store/state.d.mts.map +0 -1
- package/dist/internals/simulation/store/state.mjs +0 -50
- package/dist/internals/simulation/store/state.mjs.map +0 -1
- package/dist/internals/simulation/store/store.cjs +0 -51
- package/dist/internals/simulation/store/store.cjs.map +0 -1
- package/dist/internals/simulation/store/store.d.cts +0 -22
- package/dist/internals/simulation/store/store.d.cts.map +0 -1
- package/dist/internals/simulation/store/store.d.mts +0 -22
- package/dist/internals/simulation/store/store.d.mts.map +0 -1
- package/dist/internals/simulation/store/store.mjs +0 -45
- package/dist/internals/simulation/store/store.mjs.map +0 -1
- package/dist/internals/simulation/store/ui.cjs +0 -24
- package/dist/internals/simulation/store/ui.cjs.map +0 -1
- package/dist/internals/simulation/store/ui.d.cts +0 -27
- package/dist/internals/simulation/store/ui.d.cts.map +0 -1
- package/dist/internals/simulation/store/ui.d.mts +0 -27
- package/dist/internals/simulation/store/ui.d.mts.map +0 -1
- package/dist/internals/simulation/store/ui.mjs +0 -21
- package/dist/internals/simulation/store/ui.mjs.map +0 -1
- package/dist/internals/structs.cjs +0 -157
- package/dist/internals/structs.cjs.map +0 -1
- package/dist/internals/structs.d.cts +0 -205
- package/dist/internals/structs.d.cts.map +0 -1
- package/dist/internals/structs.d.mts +0 -205
- package/dist/internals/structs.d.mts.map +0 -1
- package/dist/internals/structs.mjs +0 -154
- package/dist/internals/structs.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,4BAA4B;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB;AAEtE,
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,4BAA4B;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACzB,mCAAmC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AACnD,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,aAAa,EAAE,wBAAwB;AAEtE,MAAM,MAAM,cAAc,GAAG;IA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C,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,WAAW,CAAC;IAE1D;;;;;;;;;OASG;IACH,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,WAAW,CAAC;IAEjD;;;;OAIG;IACH,UAAU,IAAI,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAEjD;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG;QACrC;;WAEG;QACH,MAAM,IAAI,IAAI,CAAC;KAChB,CAAC;IAEF;;;;;;;OAOG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,UAAU,CAAC;CACrB,GAAG,oBAAoB,CAAC;AAEzB,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE;QAAE,MAAM,EAAE,IAAI,CAAA;KAAE,GAAG;QAAE,KAAK,EAAE,IAAI,CAAA;KAAE,CAAC;IAC7C,aAAa,EAAE;QACb,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAC;KACrC,EAAE,CAAC;IACJ,YAAY,IAAI,oBAAoB,CAAC;CACtC,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,yBAAyB,EACzB,cAAc,CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,4BAA4B,GAC5B,yBAAyB,CAAC;AAE9B,MAAM,MAAM,YAAY,GAAG,aAAa,CACtC,OAAO,kBAAkB,EACzB,gBAAgB,CACjB,CAAC"}
|
package/dist/types/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';\n\nimport type {\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from '../internals';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface =\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter;\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type {\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from '@metamask/snaps-simulation';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface =\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter;\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-jest",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.4.0",
|
|
4
4
|
"description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"exports": {
|
|
@@ -42,28 +42,15 @@
|
|
|
42
42
|
"@jest/environment": "^29.5.0",
|
|
43
43
|
"@jest/expect": "^29.5.0",
|
|
44
44
|
"@jest/globals": "^29.5.0",
|
|
45
|
-
"@metamask/
|
|
46
|
-
"@metamask/
|
|
47
|
-
"@metamask/
|
|
48
|
-
"@metamask/json-rpc-middleware-stream": "^8.0.2",
|
|
49
|
-
"@metamask/key-tree": "^9.1.2",
|
|
50
|
-
"@metamask/permission-controller": "^11.0.0",
|
|
51
|
-
"@metamask/phishing-controller": "^12.0.2",
|
|
52
|
-
"@metamask/snaps-controllers": "^9.6.0",
|
|
53
|
-
"@metamask/snaps-execution-environments": "^6.7.0",
|
|
54
|
-
"@metamask/snaps-rpc-methods": "^11.1.0",
|
|
55
|
-
"@metamask/snaps-sdk": "^6.4.0",
|
|
56
|
-
"@metamask/snaps-utils": "^8.1.0",
|
|
45
|
+
"@metamask/snaps-controllers": "^9.7.0",
|
|
46
|
+
"@metamask/snaps-sdk": "^6.5.0",
|
|
47
|
+
"@metamask/snaps-simulation": "^1.0.0",
|
|
57
48
|
"@metamask/superstruct": "^3.1.0",
|
|
58
49
|
"@metamask/utils": "^9.2.1",
|
|
59
|
-
"@reduxjs/toolkit": "^1.9.5",
|
|
60
50
|
"express": "^4.18.2",
|
|
61
51
|
"jest-environment-node": "^29.5.0",
|
|
62
52
|
"jest-matcher-utils": "^29.5.0",
|
|
63
|
-
"
|
|
64
|
-
"readable-stream": "^3.6.2",
|
|
65
|
-
"redux": "^4.2.1",
|
|
66
|
-
"redux-saga": "^1.2.3"
|
|
53
|
+
"redux": "^4.2.1"
|
|
67
54
|
},
|
|
68
55
|
"devDependencies": {
|
|
69
56
|
"@jest/types": "^29.6.3",
|
|
@@ -73,11 +60,11 @@
|
|
|
73
60
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
74
61
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
75
62
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
63
|
+
"@metamask/snaps-utils": "^8.1.1",
|
|
76
64
|
"@swc/core": "1.3.78",
|
|
77
65
|
"@swc/jest": "^0.2.26",
|
|
78
|
-
"@ts-bridge/cli": "^0.
|
|
66
|
+
"@ts-bridge/cli": "^0.5.1",
|
|
79
67
|
"@types/jest": "^27.5.1",
|
|
80
|
-
"@types/mime": "^3.0.0",
|
|
81
68
|
"@types/semver": "^7.5.0",
|
|
82
69
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
83
70
|
"@typescript-eslint/parser": "^6.21.0",
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getInterfaceApi = exports.getInterfaceFromResult = exports.handleRequest = void 0;
|
|
4
|
-
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
5
|
-
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
6
|
-
const superstruct_1 = require("@metamask/superstruct");
|
|
7
|
-
const utils_1 = require("@metamask/utils");
|
|
8
|
-
const toolkit_1 = require("@reduxjs/toolkit");
|
|
9
|
-
const simulation_1 = require("./simulation/index.cjs");
|
|
10
|
-
const structs_1 = require("./structs.cjs");
|
|
11
|
-
/**
|
|
12
|
-
* Send a JSON-RPC request to the Snap, and wrap the response in a
|
|
13
|
-
* {@link SnapResponse} object.
|
|
14
|
-
*
|
|
15
|
-
* @param options - The request options.
|
|
16
|
-
* @param options.snapId - The ID of the Snap to send the request to.
|
|
17
|
-
* @param options.store - The Redux store.
|
|
18
|
-
* @param options.executionService - The execution service to use to send the
|
|
19
|
-
* request.
|
|
20
|
-
* @param options.handler - The handler to use to send the request.
|
|
21
|
-
* @param options.controllerMessenger - The controller messenger used to call actions.
|
|
22
|
-
* @param options.runSaga - A function to run a saga outside the usual Redux
|
|
23
|
-
* flow.
|
|
24
|
-
* @param options.request - The request to send.
|
|
25
|
-
* @param options.request.id - The ID of the request. If not provided, a random
|
|
26
|
-
* ID will be generated.
|
|
27
|
-
* @param options.request.origin - The origin of the request. Defaults to
|
|
28
|
-
* `https://metamask.io`.
|
|
29
|
-
* @returns The response, wrapped in a {@link SnapResponse} object.
|
|
30
|
-
*/
|
|
31
|
-
function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id = (0, toolkit_1.nanoid)(), origin = 'https://metamask.io', ...options }, }) {
|
|
32
|
-
const getInterfaceError = () => {
|
|
33
|
-
throw new Error('Unable to get the interface from the Snap: The request to the Snap failed.');
|
|
34
|
-
};
|
|
35
|
-
const promise = executionService
|
|
36
|
-
.handleRpcRequest(snapId, {
|
|
37
|
-
origin,
|
|
38
|
-
handler,
|
|
39
|
-
request: {
|
|
40
|
-
jsonrpc: '2.0',
|
|
41
|
-
id: 1,
|
|
42
|
-
...options,
|
|
43
|
-
},
|
|
44
|
-
})
|
|
45
|
-
.then(async (result) => {
|
|
46
|
-
const notifications = (0, simulation_1.getNotifications)(store.getState());
|
|
47
|
-
store.dispatch((0, simulation_1.clearNotifications)());
|
|
48
|
-
try {
|
|
49
|
-
const getInterfaceFn = await getInterfaceApi(result, snapId, controllerMessenger);
|
|
50
|
-
return {
|
|
51
|
-
id: String(id),
|
|
52
|
-
response: {
|
|
53
|
-
result: (0, utils_1.getSafeJson)(result),
|
|
54
|
-
},
|
|
55
|
-
notifications,
|
|
56
|
-
...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
60
|
-
const [unwrappedError] = (0, snaps_utils_1.unwrapError)(error);
|
|
61
|
-
return {
|
|
62
|
-
id: String(id),
|
|
63
|
-
response: {
|
|
64
|
-
error: unwrappedError.serialize(),
|
|
65
|
-
},
|
|
66
|
-
notifications: [],
|
|
67
|
-
getInterface: getInterfaceError,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
})
|
|
71
|
-
.catch((error) => {
|
|
72
|
-
const [unwrappedError] = (0, snaps_utils_1.unwrapError)(error);
|
|
73
|
-
return {
|
|
74
|
-
id: String(id),
|
|
75
|
-
response: {
|
|
76
|
-
error: unwrappedError.serialize(),
|
|
77
|
-
},
|
|
78
|
-
notifications: [],
|
|
79
|
-
getInterface: getInterfaceError,
|
|
80
|
-
};
|
|
81
|
-
});
|
|
82
|
-
promise.getInterface = async () => {
|
|
83
|
-
const sagaPromise = runSaga(simulation_1.getInterface, runSaga, snapId, controllerMessenger).toPromise();
|
|
84
|
-
const result = await Promise.race([promise, sagaPromise]);
|
|
85
|
-
// If the request promise has resolved to an error, we should throw
|
|
86
|
-
// instead of waiting for an interface that likely will never be displayed
|
|
87
|
-
if ((0, superstruct_1.is)(result, structs_1.SnapResponseStruct) &&
|
|
88
|
-
(0, utils_1.hasProperty)(result.response, 'error')) {
|
|
89
|
-
throw new Error(`Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${result.response.error.message}`);
|
|
90
|
-
}
|
|
91
|
-
return await sagaPromise;
|
|
92
|
-
};
|
|
93
|
-
return promise;
|
|
94
|
-
}
|
|
95
|
-
exports.handleRequest = handleRequest;
|
|
96
|
-
/**
|
|
97
|
-
* Get the interface ID from the result if it's available or create a new interface if the result contains static components.
|
|
98
|
-
*
|
|
99
|
-
* @param result - The handler result object.
|
|
100
|
-
* @param snapId - The Snap ID.
|
|
101
|
-
* @param controllerMessenger - The controller messenger.
|
|
102
|
-
* @returns The interface ID or undefined if the result doesn't include content.
|
|
103
|
-
*/
|
|
104
|
-
async function getInterfaceFromResult(result, snapId, controllerMessenger) {
|
|
105
|
-
if ((0, utils_1.isPlainObject)(result) && (0, utils_1.hasProperty)(result, 'id')) {
|
|
106
|
-
return result.id;
|
|
107
|
-
}
|
|
108
|
-
if ((0, utils_1.isPlainObject)(result) && (0, utils_1.hasProperty)(result, 'content')) {
|
|
109
|
-
(0, utils_1.assert)((0, superstruct_1.is)(result.content, snaps_sdk_1.ComponentOrElementStruct), 'The Snap returned an invalid interface.');
|
|
110
|
-
const id = await controllerMessenger.call('SnapInterfaceController:createInterface', snapId, result.content);
|
|
111
|
-
return id;
|
|
112
|
-
}
|
|
113
|
-
return undefined;
|
|
114
|
-
}
|
|
115
|
-
exports.getInterfaceFromResult = getInterfaceFromResult;
|
|
116
|
-
/**
|
|
117
|
-
* Get the response content from the `SnapInterfaceController` and include the
|
|
118
|
-
* interaction methods.
|
|
119
|
-
*
|
|
120
|
-
* @param result - The handler result object.
|
|
121
|
-
* @param snapId - The Snap ID.
|
|
122
|
-
* @param controllerMessenger - The controller messenger.
|
|
123
|
-
* @returns The content components if any.
|
|
124
|
-
*/
|
|
125
|
-
async function getInterfaceApi(result, snapId, controllerMessenger) {
|
|
126
|
-
const interfaceId = await getInterfaceFromResult(result, snapId, controllerMessenger);
|
|
127
|
-
if (interfaceId) {
|
|
128
|
-
return () => {
|
|
129
|
-
const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, interfaceId);
|
|
130
|
-
const actions = (0, simulation_1.getInterfaceActions)(snapId, controllerMessenger, {
|
|
131
|
-
id: interfaceId,
|
|
132
|
-
content,
|
|
133
|
-
});
|
|
134
|
-
return {
|
|
135
|
-
content,
|
|
136
|
-
...actions,
|
|
137
|
-
};
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
return undefined;
|
|
141
|
-
}
|
|
142
|
-
exports.getInterfaceApi = getInterfaceApi;
|
|
143
|
-
//# sourceMappingURL=request.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.cjs","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":";;;AACA,mDAK6B;AAE7B,uDAAoD;AACpD,uDAA2C;AAC3C,2CAKyB;AACzB,8CAA0C;AAQ1C,uDAKsB;AAEtB,2CAA+C;AAY/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO,EAAE,EAAE,EAAE,GAAG,IAAA,gBAAM,GAAE,EAAE,MAAM,GAAG,qBAAqB,EAAE,GAAG,OAAO,EAAE,GACjD;IACrB,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,MAAM,IAAI,KAAK,CACb,4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AwB,CAAC,EAC5C,yCAAyC,CAC1C,CAAC;QACF,MAAM,EAAE,GAAG,MAAM,mBAAmB,CAAC,IAAI,CACvC,yCAAyC,EACzC,MAAM,EACN,MAAM,CAAC,OAA6B,CACrC,CAAC;QAEF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAxBD,wDAwBC;AAED;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,MAAe,EACf,MAAc,EACd,mBAA4C;IAE5C,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAC9C,MAAM,EACN,MAAM,EACN,mBAAmB,CACpB,CAAC;IAEF,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,OAAO,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAC1C,sCAAsC,EACtC,MAAM,EACN,WAAW,CACZ,CAAC;YAEF,MAAM,OAAO,GAAG,IAAA,gCAAmB,EAAC,MAAM,EAAE,mBAAmB,EAAE;gBAC/D,EAAE,EAAE,WAAW;gBACf,OAAO;aACR,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO;gBACP,GAAG,OAAO;aACX,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAhCD,0CAgCC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport type { RunSagaFunction, Store } from './simulation';\nimport {\n clearNotifications,\n getInterface,\n getInterfaceActions,\n getNotifications,\n} from './simulation';\nimport type { RootControllerMessenger } from './simulation/controllers';\nimport { SnapResponseStruct } from './structs';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const notifications = getNotifications(store.getState());\n store.dispatch(clearNotifications());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n const id = await controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the `SnapInterfaceController` and include the\n * interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n if (interfaceId) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n interfaceId,\n );\n\n const actions = getInterfaceActions(snapId, controllerMessenger, {\n id: interfaceId,\n content,\n });\n\n return {\n content,\n ...actions,\n };\n };\n }\n\n return undefined;\n}\n"]}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
|
-
import { type SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { HandlerType } from "@metamask/snaps-utils";
|
|
4
|
-
import type { RequestOptions, SnapHandlerInterface, SnapRequest } from "../types/index.cjs";
|
|
5
|
-
import type { RunSagaFunction, Store } from "./simulation/index.cjs";
|
|
6
|
-
import type { RootControllerMessenger } from "./simulation/controllers.cjs";
|
|
7
|
-
export type HandleRequestOptions = {
|
|
8
|
-
snapId: SnapId;
|
|
9
|
-
store: Store;
|
|
10
|
-
executionService: AbstractExecutionService<unknown>;
|
|
11
|
-
handler: HandlerType;
|
|
12
|
-
controllerMessenger: RootControllerMessenger;
|
|
13
|
-
runSaga: RunSagaFunction;
|
|
14
|
-
request: RequestOptions;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Send a JSON-RPC request to the Snap, and wrap the response in a
|
|
18
|
-
* {@link SnapResponse} object.
|
|
19
|
-
*
|
|
20
|
-
* @param options - The request options.
|
|
21
|
-
* @param options.snapId - The ID of the Snap to send the request to.
|
|
22
|
-
* @param options.store - The Redux store.
|
|
23
|
-
* @param options.executionService - The execution service to use to send the
|
|
24
|
-
* request.
|
|
25
|
-
* @param options.handler - The handler to use to send the request.
|
|
26
|
-
* @param options.controllerMessenger - The controller messenger used to call actions.
|
|
27
|
-
* @param options.runSaga - A function to run a saga outside the usual Redux
|
|
28
|
-
* flow.
|
|
29
|
-
* @param options.request - The request to send.
|
|
30
|
-
* @param options.request.id - The ID of the request. If not provided, a random
|
|
31
|
-
* ID will be generated.
|
|
32
|
-
* @param options.request.origin - The origin of the request. Defaults to
|
|
33
|
-
* `https://metamask.io`.
|
|
34
|
-
* @returns The response, wrapped in a {@link SnapResponse} object.
|
|
35
|
-
*/
|
|
36
|
-
export declare function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id, origin, ...options }, }: HandleRequestOptions): SnapRequest;
|
|
37
|
-
/**
|
|
38
|
-
* Get the interface ID from the result if it's available or create a new interface if the result contains static components.
|
|
39
|
-
*
|
|
40
|
-
* @param result - The handler result object.
|
|
41
|
-
* @param snapId - The Snap ID.
|
|
42
|
-
* @param controllerMessenger - The controller messenger.
|
|
43
|
-
* @returns The interface ID or undefined if the result doesn't include content.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
|
|
46
|
-
/**
|
|
47
|
-
* Get the response content from the `SnapInterfaceController` and include the
|
|
48
|
-
* interaction methods.
|
|
49
|
-
*
|
|
50
|
-
* @param result - The handler result object.
|
|
51
|
-
* @param snapId - The Snap ID.
|
|
52
|
-
* @param controllerMessenger - The controller messenger.
|
|
53
|
-
* @returns The content components if any.
|
|
54
|
-
*/
|
|
55
|
-
export declare function getInterfaceApi(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<(() => SnapHandlerInterface) | undefined>;
|
|
56
|
-
//# sourceMappingURL=request.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.cts","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,EAIL,KAAK,MAAM,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAWzD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,2BAAiB;AAClB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,+BAAqB;AAO3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qCAAiC;AAGxE,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO,EAAE,EAAE,EAAa,EAAE,MAA8B,EAAE,GAAG,OAAO,EAAE,GACvE,EAAE,oBAAoB,GAAG,WAAW,CAuFpC;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,+BAqB7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,GAC3C,OAAO,CAAC,CAAC,MAAM,oBAAoB,CAAC,GAAG,SAAS,CAAC,CA4BnD"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { AbstractExecutionService } from "@metamask/snaps-controllers";
|
|
2
|
-
import { type SnapId } from "@metamask/snaps-sdk";
|
|
3
|
-
import type { HandlerType } from "@metamask/snaps-utils";
|
|
4
|
-
import type { RequestOptions, SnapHandlerInterface, SnapRequest } from "../types/index.mjs";
|
|
5
|
-
import type { RunSagaFunction, Store } from "./simulation/index.mjs";
|
|
6
|
-
import type { RootControllerMessenger } from "./simulation/controllers.mjs";
|
|
7
|
-
export type HandleRequestOptions = {
|
|
8
|
-
snapId: SnapId;
|
|
9
|
-
store: Store;
|
|
10
|
-
executionService: AbstractExecutionService<unknown>;
|
|
11
|
-
handler: HandlerType;
|
|
12
|
-
controllerMessenger: RootControllerMessenger;
|
|
13
|
-
runSaga: RunSagaFunction;
|
|
14
|
-
request: RequestOptions;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* Send a JSON-RPC request to the Snap, and wrap the response in a
|
|
18
|
-
* {@link SnapResponse} object.
|
|
19
|
-
*
|
|
20
|
-
* @param options - The request options.
|
|
21
|
-
* @param options.snapId - The ID of the Snap to send the request to.
|
|
22
|
-
* @param options.store - The Redux store.
|
|
23
|
-
* @param options.executionService - The execution service to use to send the
|
|
24
|
-
* request.
|
|
25
|
-
* @param options.handler - The handler to use to send the request.
|
|
26
|
-
* @param options.controllerMessenger - The controller messenger used to call actions.
|
|
27
|
-
* @param options.runSaga - A function to run a saga outside the usual Redux
|
|
28
|
-
* flow.
|
|
29
|
-
* @param options.request - The request to send.
|
|
30
|
-
* @param options.request.id - The ID of the request. If not provided, a random
|
|
31
|
-
* ID will be generated.
|
|
32
|
-
* @param options.request.origin - The origin of the request. Defaults to
|
|
33
|
-
* `https://metamask.io`.
|
|
34
|
-
* @returns The response, wrapped in a {@link SnapResponse} object.
|
|
35
|
-
*/
|
|
36
|
-
export declare function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id, origin, ...options }, }: HandleRequestOptions): SnapRequest;
|
|
37
|
-
/**
|
|
38
|
-
* Get the interface ID from the result if it's available or create a new interface if the result contains static components.
|
|
39
|
-
*
|
|
40
|
-
* @param result - The handler result object.
|
|
41
|
-
* @param snapId - The Snap ID.
|
|
42
|
-
* @param controllerMessenger - The controller messenger.
|
|
43
|
-
* @returns The interface ID or undefined if the result doesn't include content.
|
|
44
|
-
*/
|
|
45
|
-
export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
|
|
46
|
-
/**
|
|
47
|
-
* Get the response content from the `SnapInterfaceController` and include the
|
|
48
|
-
* interaction methods.
|
|
49
|
-
*
|
|
50
|
-
* @param result - The handler result object.
|
|
51
|
-
* @param snapId - The Snap ID.
|
|
52
|
-
* @param controllerMessenger - The controller messenger.
|
|
53
|
-
* @returns The content components if any.
|
|
54
|
-
*/
|
|
55
|
-
export declare function getInterfaceApi(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<(() => SnapHandlerInterface) | undefined>;
|
|
56
|
-
//# sourceMappingURL=request.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.mts","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,EAIL,KAAK,MAAM,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAWzD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,2BAAiB;AAClB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,+BAAqB;AAO3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,qCAAiC;AAGxE,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO,EAAE,EAAE,EAAa,EAAE,MAA8B,EAAE,GAAG,OAAO,EAAE,GACvE,EAAE,oBAAoB,GAAG,WAAW,CAuFpC;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,+BAqB7C;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,GAC3C,OAAO,CAAC,CAAC,MAAM,oBAAoB,CAAC,GAAG,SAAS,CAAC,CA4BnD"}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { ComponentOrElementStruct } from "@metamask/snaps-sdk";
|
|
2
|
-
import { unwrapError } from "@metamask/snaps-utils";
|
|
3
|
-
import { is } from "@metamask/superstruct";
|
|
4
|
-
import { assert, getSafeJson, hasProperty, isPlainObject } from "@metamask/utils";
|
|
5
|
-
import $reduxjstoolkit from "@reduxjs/toolkit";
|
|
6
|
-
const { nanoid } = $reduxjstoolkit;
|
|
7
|
-
import { clearNotifications, getInterface, getInterfaceActions, getNotifications } from "./simulation/index.mjs";
|
|
8
|
-
import { SnapResponseStruct } from "./structs.mjs";
|
|
9
|
-
/**
|
|
10
|
-
* Send a JSON-RPC request to the Snap, and wrap the response in a
|
|
11
|
-
* {@link SnapResponse} object.
|
|
12
|
-
*
|
|
13
|
-
* @param options - The request options.
|
|
14
|
-
* @param options.snapId - The ID of the Snap to send the request to.
|
|
15
|
-
* @param options.store - The Redux store.
|
|
16
|
-
* @param options.executionService - The execution service to use to send the
|
|
17
|
-
* request.
|
|
18
|
-
* @param options.handler - The handler to use to send the request.
|
|
19
|
-
* @param options.controllerMessenger - The controller messenger used to call actions.
|
|
20
|
-
* @param options.runSaga - A function to run a saga outside the usual Redux
|
|
21
|
-
* flow.
|
|
22
|
-
* @param options.request - The request to send.
|
|
23
|
-
* @param options.request.id - The ID of the request. If not provided, a random
|
|
24
|
-
* ID will be generated.
|
|
25
|
-
* @param options.request.origin - The origin of the request. Defaults to
|
|
26
|
-
* `https://metamask.io`.
|
|
27
|
-
* @returns The response, wrapped in a {@link SnapResponse} object.
|
|
28
|
-
*/
|
|
29
|
-
export function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id = nanoid(), origin = 'https://metamask.io', ...options }, }) {
|
|
30
|
-
const getInterfaceError = () => {
|
|
31
|
-
throw new Error('Unable to get the interface from the Snap: The request to the Snap failed.');
|
|
32
|
-
};
|
|
33
|
-
const promise = executionService
|
|
34
|
-
.handleRpcRequest(snapId, {
|
|
35
|
-
origin,
|
|
36
|
-
handler,
|
|
37
|
-
request: {
|
|
38
|
-
jsonrpc: '2.0',
|
|
39
|
-
id: 1,
|
|
40
|
-
...options,
|
|
41
|
-
},
|
|
42
|
-
})
|
|
43
|
-
.then(async (result) => {
|
|
44
|
-
const notifications = getNotifications(store.getState());
|
|
45
|
-
store.dispatch(clearNotifications());
|
|
46
|
-
try {
|
|
47
|
-
const getInterfaceFn = await getInterfaceApi(result, snapId, controllerMessenger);
|
|
48
|
-
return {
|
|
49
|
-
id: String(id),
|
|
50
|
-
response: {
|
|
51
|
-
result: getSafeJson(result),
|
|
52
|
-
},
|
|
53
|
-
notifications,
|
|
54
|
-
...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
const [unwrappedError] = unwrapError(error);
|
|
59
|
-
return {
|
|
60
|
-
id: String(id),
|
|
61
|
-
response: {
|
|
62
|
-
error: unwrappedError.serialize(),
|
|
63
|
-
},
|
|
64
|
-
notifications: [],
|
|
65
|
-
getInterface: getInterfaceError,
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
.catch((error) => {
|
|
70
|
-
const [unwrappedError] = unwrapError(error);
|
|
71
|
-
return {
|
|
72
|
-
id: String(id),
|
|
73
|
-
response: {
|
|
74
|
-
error: unwrappedError.serialize(),
|
|
75
|
-
},
|
|
76
|
-
notifications: [],
|
|
77
|
-
getInterface: getInterfaceError,
|
|
78
|
-
};
|
|
79
|
-
});
|
|
80
|
-
promise.getInterface = async () => {
|
|
81
|
-
const sagaPromise = runSaga(getInterface, runSaga, snapId, controllerMessenger).toPromise();
|
|
82
|
-
const result = await Promise.race([promise, sagaPromise]);
|
|
83
|
-
// If the request promise has resolved to an error, we should throw
|
|
84
|
-
// instead of waiting for an interface that likely will never be displayed
|
|
85
|
-
if (is(result, SnapResponseStruct) &&
|
|
86
|
-
hasProperty(result.response, 'error')) {
|
|
87
|
-
throw new Error(`Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${result.response.error.message}`);
|
|
88
|
-
}
|
|
89
|
-
return await sagaPromise;
|
|
90
|
-
};
|
|
91
|
-
return promise;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get the interface ID from the result if it's available or create a new interface if the result contains static components.
|
|
95
|
-
*
|
|
96
|
-
* @param result - The handler result object.
|
|
97
|
-
* @param snapId - The Snap ID.
|
|
98
|
-
* @param controllerMessenger - The controller messenger.
|
|
99
|
-
* @returns The interface ID or undefined if the result doesn't include content.
|
|
100
|
-
*/
|
|
101
|
-
export async function getInterfaceFromResult(result, snapId, controllerMessenger) {
|
|
102
|
-
if (isPlainObject(result) && hasProperty(result, 'id')) {
|
|
103
|
-
return result.id;
|
|
104
|
-
}
|
|
105
|
-
if (isPlainObject(result) && hasProperty(result, 'content')) {
|
|
106
|
-
assert(is(result.content, ComponentOrElementStruct), 'The Snap returned an invalid interface.');
|
|
107
|
-
const id = await controllerMessenger.call('SnapInterfaceController:createInterface', snapId, result.content);
|
|
108
|
-
return id;
|
|
109
|
-
}
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Get the response content from the `SnapInterfaceController` and include the
|
|
114
|
-
* interaction methods.
|
|
115
|
-
*
|
|
116
|
-
* @param result - The handler result object.
|
|
117
|
-
* @param snapId - The Snap ID.
|
|
118
|
-
* @param controllerMessenger - The controller messenger.
|
|
119
|
-
* @returns The content components if any.
|
|
120
|
-
*/
|
|
121
|
-
export async function getInterfaceApi(result, snapId, controllerMessenger) {
|
|
122
|
-
const interfaceId = await getInterfaceFromResult(result, snapId, controllerMessenger);
|
|
123
|
-
if (interfaceId) {
|
|
124
|
-
return () => {
|
|
125
|
-
const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, interfaceId);
|
|
126
|
-
const actions = getInterfaceActions(snapId, controllerMessenger, {
|
|
127
|
-
id: interfaceId,
|
|
128
|
-
content,
|
|
129
|
-
});
|
|
130
|
-
return {
|
|
131
|
-
content,
|
|
132
|
-
...actions,
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
return undefined;
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=request.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request.mjs","sourceRoot":"","sources":["../../src/internals/request.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,wBAAwB,EAGzB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EAAE,EAAE,EAAE,8BAA8B;AAC3C,OAAO,EACL,MAAM,EACN,WAAW,EACX,WAAW,EACX,aAAa,EACd,wBAAwB;;;AASzB,OAAO,EACL,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACnB,gBAAgB,EACjB,+BAAqB;AAEtB,OAAO,EAAE,kBAAkB,EAAE,sBAAkB;AAY/C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,OAAO,EACP,OAAO,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,EAAE,MAAM,GAAG,qBAAqB,EAAE,GAAG,OAAO,EAAE,GACjD;IACrB,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,MAAM,IAA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C,IAAI,CACvC,yCAAyC,EACzC,MAAM,EACN,MAAM,CAAC,OAA6B,CACrC,CAAC;QAEF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,MAAe,EACf,MAAc,EACd,mBAA4C;IAE5C,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAC9C,MAAM,EACN,MAAM,EACN,mBAAmB,CACpB,CAAC;IAEF,IAAI,WAAW,EAAE,CAAC;QAChB,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,OAAO,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAC1C,sCAAsC,EACtC,MAAM,EACN,WAAW,CACZ,CAAC;YAEF,MAAM,OAAO,GAAG,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,EAAE;gBAC/D,EAAE,EAAE,WAAW;gBACf,OAAO;aACR,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO;gBACP,GAAG,OAAO;aACX,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport type { RunSagaFunction, Store } from './simulation';\nimport {\n clearNotifications,\n getInterface,\n getInterfaceActions,\n getNotifications,\n} from './simulation';\nimport type { RootControllerMessenger } from './simulation/controllers';\nimport { SnapResponseStruct } from './structs';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const notifications = getNotifications(store.getState());\n store.dispatch(clearNotifications());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n const id = await controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the `SnapInterfaceController` and include the\n * interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n if (interfaceId) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n interfaceId,\n );\n\n const actions = getInterfaceActions(snapId, controllerMessenger, {\n id: interfaceId,\n content,\n });\n\n return {\n content,\n ...actions,\n };\n };\n }\n\n return undefined;\n}\n"]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_JSON_RPC_ENDPOINT = exports.DEFAULT_CURRENCY = exports.DEFAULT_LOCALE = exports.DEFAULT_SRP = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* A secret recovery phrase that is used for testing purposes. Do not use this
|
|
6
|
-
* to store any real funds!
|
|
7
|
-
*/
|
|
8
|
-
exports.DEFAULT_SRP = 'test test test test test test test test test test test ball';
|
|
9
|
-
/**
|
|
10
|
-
* The default locale.
|
|
11
|
-
*/
|
|
12
|
-
exports.DEFAULT_LOCALE = 'en';
|
|
13
|
-
/**
|
|
14
|
-
* The default currency.
|
|
15
|
-
*/
|
|
16
|
-
exports.DEFAULT_CURRENCY = 'usd';
|
|
17
|
-
/**
|
|
18
|
-
* The default JSON-RPC endpoint for Ethereum requests.
|
|
19
|
-
*/
|
|
20
|
-
exports.DEFAULT_JSON_RPC_ENDPOINT = 'https://cloudflare-eth.com/';
|
|
21
|
-
//# sourceMappingURL=constants.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/internals/simulation/constants.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACU,QAAA,WAAW,GACtB,6DAA6D,CAAC;AAEhE;;GAEG;AACU,QAAA,cAAc,GAAG,IAAI,CAAC;AAEnC;;GAEG;AACU,QAAA,gBAAgB,GAAG,KAAK,CAAC;AAEtC;;GAEG;AACU,QAAA,yBAAyB,GAAG,6BAA6B,CAAC","sourcesContent":["/**\n * A secret recovery phrase that is used for testing purposes. Do not use this\n * to store any real funds!\n */\nexport const DEFAULT_SRP =\n 'test test test test test test test test test test test ball';\n\n/**\n * The default locale.\n */\nexport const DEFAULT_LOCALE = 'en';\n\n/**\n * The default currency.\n */\nexport const DEFAULT_CURRENCY = 'usd';\n\n/**\n * The default JSON-RPC endpoint for Ethereum requests.\n */\nexport const DEFAULT_JSON_RPC_ENDPOINT = 'https://cloudflare-eth.com/';\n"]}
|