From d27ce8137bf54688f49702a5d9bf1ae6ed3893c7 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 8 May 2025 12:40:04 +0200 Subject: [PATCH 1/9] Bump Snaps packages --- package.json | 10 +++--- yarn.lock | 87 ++++++++++++++++++++++++++++------------------------ 2 files changed, 52 insertions(+), 45 deletions(-) diff --git a/package.json b/package.json index 2506eb225740..24c6e1066145 100644 --- a/package.json +++ b/package.json @@ -219,11 +219,11 @@ "@metamask/signature-controller": "^28.0.0", "@metamask/slip44": "^4.1.0", "@metamask/smart-transactions-controller": "^16.3.1", - "@metamask/snaps-controllers": "^11.2.3", - "@metamask/snaps-execution-environments": "^7.2.2", - "@metamask/snaps-rpc-methods": "^12.1.0", - "@metamask/snaps-sdk": "^6.22.1", - "@metamask/snaps-utils": "^9.2.1", + "@metamask/snaps-controllers": "^12.0.0", + "@metamask/snaps-execution-environments": "^8.0.0", + "@metamask/snaps-rpc-methods": "^12.2.0", + "@metamask/snaps-sdk": "^6.23.0", + "@metamask/snaps-utils": "^9.2.2", "@metamask/solana-wallet-snap": "^1.27.0", "@metamask/stake-sdk": "^1.0.0", "@metamask/swappable-obj-proxy": "^2.1.0", diff --git a/yarn.lock b/yarn.lock index 3acd958d21a1..2c2aee533cf9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5512,6 +5512,14 @@ fast-json-stable-stringify "^2.1.0" uuid "^8.3.2" +"@metamask/post-message-stream@^10.0.0": + version "10.0.0" + resolved "https://registry.yarnpkg.com/@metamask/post-message-stream/-/post-message-stream-10.0.0.tgz#ee0ea11092931df3b9f79a33c083340168f5706b" + integrity sha512-nFepq24aGQw81hkSgCIEBYFpNocnLZpIArCEICdT74pLTMXLgm4G8aHSszF+sOOvnMKW8zV56og9ImZSondIjA== + dependencies: + "@metamask/utils" "^11.4.0" + readable-stream "3.6.2" + "@metamask/post-message-stream@^9.0.0": version "9.0.0" resolved "https://registry.yarnpkg.com/@metamask/post-message-stream/-/post-message-stream-9.0.0.tgz#1b1249eb7d378cc1eda8abe6b2f882f6dd923c46" @@ -5574,10 +5582,10 @@ is-stream "^2.0.0" readable-stream "^3.6.2" -"@metamask/providers@^22.0.1": - version "22.0.1" - resolved "https://registry.yarnpkg.com/@metamask/providers/-/providers-22.0.1.tgz#eedb84ac13dd771d5d86e7a89968e3280f655be6" - integrity sha512-RWB32NLL2DIgUII17UY7R3n2eU5fTrXXA0Z137VIO7pQeLcL9xiVqfqhtCDKfMW9K7Pw68U4Qme4lhLrhJcZBQ== +"@metamask/providers@^22.1.0": + version "22.1.0" + resolved "https://registry.yarnpkg.com/@metamask/providers/-/providers-22.1.0.tgz#13efe37debcdf4d2b3ef68daddbc35794453118a" + integrity sha512-lu639mkH78GLSLVUGW+XI6viHI5NAOwoJe+B9OmQm/rVmLuvy2ZSQVrsrT3n00Pt1WLeq1J6Ee/gML3RxVc4Aw== dependencies: "@metamask/json-rpc-engine" "^10.0.2" "@metamask/json-rpc-middleware-stream" "^8.0.6" @@ -5713,25 +5721,25 @@ fast-json-patch "^3.1.0" lodash "^4.17.21" -"@metamask/snaps-controllers@^11.2.3": - version "11.2.3" - resolved "https://registry.yarnpkg.com/@metamask/snaps-controllers/-/snaps-controllers-11.2.3.tgz#b5ddcc2d8cec092b0a0cc3098c5b02a6950b0c7d" - integrity sha512-zNLA3JdRkcpiCRivo7qiwNpv79WSTYtVR29wy3Rp0oCs7WwsxRvicl8IlMp+AjWjfQ7jUXiSiMo0nwzvrgloFw== +"@metamask/snaps-controllers@^12.0.0": + version "12.0.0" + resolved "https://registry.yarnpkg.com/@metamask/snaps-controllers/-/snaps-controllers-12.0.0.tgz#aff6da4800662e53e2b3150a10e0ee51e914cf47" + integrity sha512-5edP8xp25tZthI9AJN1R2efCuK9c3XCj3o8q9fQFzfjvnj143q2ivBiqMCVIP6xV3ppwmJNf/cKgIJMm5Oc/vw== dependencies: "@metamask/approval-controller" "^7.1.3" - "@metamask/base-controller" "^8.0.0" + "@metamask/base-controller" "^8.0.1" "@metamask/json-rpc-engine" "^10.0.2" "@metamask/json-rpc-middleware-stream" "^8.0.7" "@metamask/key-tree" "^10.1.1" "@metamask/object-multiplex" "^2.1.0" "@metamask/permission-controller" "^11.0.6" "@metamask/phishing-controller" "^12.5.0" - "@metamask/post-message-stream" "^9.0.0" + "@metamask/post-message-stream" "^10.0.0" "@metamask/rpc-errors" "^7.0.2" "@metamask/snaps-registry" "^3.2.3" - "@metamask/snaps-rpc-methods" "^12.1.0" - "@metamask/snaps-sdk" "^6.22.1" - "@metamask/snaps-utils" "^9.2.1" + "@metamask/snaps-rpc-methods" "^12.2.0" + "@metamask/snaps-sdk" "^6.23.0" + "@metamask/snaps-utils" "^9.2.2" "@metamask/utils" "^11.4.0" "@xstate/fsm" "^2.0.0" async-mutex "^0.5.0" @@ -5747,21 +5755,20 @@ semver "^7.5.4" tar-stream "^3.1.7" -"@metamask/snaps-execution-environments@^7.2.2": - version "7.2.2" - resolved "https://registry.yarnpkg.com/@metamask/snaps-execution-environments/-/snaps-execution-environments-7.2.2.tgz#872747ccbcb5bc79c395b434fe088e0daeca343a" - integrity sha512-AmyaHhOijmchcx29o1v9q5SpKLQPtJU+lEKwgGv0CzZscvE/UZATea32LtnAAJJumSvKRNioKWAF65ikeXG8yg== +"@metamask/snaps-execution-environments@^8.0.0": + version "8.0.0" + resolved "https://registry.yarnpkg.com/@metamask/snaps-execution-environments/-/snaps-execution-environments-8.0.0.tgz#1e3dccd57cfb0fca65f65012889ef30dad78ff42" + integrity sha512-Xrcwwujr067vxQHb/EeH4NeD13OU/rKiaPhkenez8XM8KkvX/XCVZY+1xYWKh5A9J9+5BPigfdUToN4rvxT84g== dependencies: "@metamask/json-rpc-engine" "^10.0.2" "@metamask/object-multiplex" "^2.1.0" - "@metamask/post-message-stream" "^9.0.0" - "@metamask/providers" "^22.0.1" + "@metamask/post-message-stream" "^10.0.0" + "@metamask/providers" "^22.1.0" "@metamask/rpc-errors" "^7.0.2" - "@metamask/snaps-sdk" "^6.22.1" - "@metamask/snaps-utils" "^9.2.1" + "@metamask/snaps-sdk" "^6.23.0" + "@metamask/snaps-utils" "^9.2.2" "@metamask/superstruct" "^3.2.1" "@metamask/utils" "^11.4.0" - nanoid "^3.3.10" readable-stream "^3.6.2" "@metamask/snaps-registry@^3.2.3": @@ -5774,46 +5781,46 @@ "@noble/curves" "^1.2.0" "@noble/hashes" "^1.3.2" -"@metamask/snaps-rpc-methods@^12.1.0": - version "12.1.0" - resolved "https://registry.yarnpkg.com/@metamask/snaps-rpc-methods/-/snaps-rpc-methods-12.1.0.tgz#ccaceb6c278a9ee30e094e830bc8cd945e12d712" - integrity sha512-cTjYwTQjXRWQgo9eji6cXrmkLYFHSLyUrw/s+VEjfWhyaiNEq8Os3Pm7sHF2JwpAN/Zg8W+UzyK9XxSoynLVDg== +"@metamask/snaps-rpc-methods@^12.2.0": + version "12.2.0" + resolved "https://registry.yarnpkg.com/@metamask/snaps-rpc-methods/-/snaps-rpc-methods-12.2.0.tgz#7ba24f86fb19f01b9f0b3fe2fad04c59d40cd8e4" + integrity sha512-EjE0aBGDZBmlzLrI9CGvXU1dZPkyDsgJGovUBWxYFnD/CPizrbPmo+KCS7QBnN85uYRTUTS53oBovWB/MdI9wA== dependencies: "@metamask/key-tree" "^10.1.1" "@metamask/permission-controller" "^11.0.6" "@metamask/rpc-errors" "^7.0.2" - "@metamask/snaps-sdk" "^6.22.0" - "@metamask/snaps-utils" "^9.2.0" + "@metamask/snaps-sdk" "^6.23.0" + "@metamask/snaps-utils" "^9.2.2" "@metamask/superstruct" "^3.2.1" - "@metamask/utils" "^11.2.0" + "@metamask/utils" "^11.4.0" "@noble/hashes" "^1.7.1" luxon "^3.5.0" -"@metamask/snaps-sdk@^6.22.0", "@metamask/snaps-sdk@^6.22.1": - version "6.22.1" - resolved "https://registry.yarnpkg.com/@metamask/snaps-sdk/-/snaps-sdk-6.22.1.tgz#740b52dde4182b1851d507d8032f6e3e355b91c9" - integrity sha512-fnm7rdqC+VfAAntWm/xP8PW+ySEkUdJY3UU7/b74I3Qaujd5TlBqJSxp9K+DQIyR+aZZWITFZxxqpMq4JTaBQA== +"@metamask/snaps-sdk@^6.22.0", "@metamask/snaps-sdk@^6.23.0": + version "6.23.0" + resolved "https://registry.yarnpkg.com/@metamask/snaps-sdk/-/snaps-sdk-6.23.0.tgz#d61d4cbfda2c2e0aa66ee1c82e38f56d24b6b68f" + integrity sha512-V0uuomD5zfwsME3mklQezFWIttZwd843t39IBqcSbQqbsX08QJA6//wU54keh07pCyVvrdRtIR8w1Zqv8GqzUQ== dependencies: "@metamask/key-tree" "^10.1.1" - "@metamask/providers" "^22.0.1" + "@metamask/providers" "^22.1.0" "@metamask/rpc-errors" "^7.0.2" "@metamask/superstruct" "^3.2.1" "@metamask/utils" "^11.4.0" -"@metamask/snaps-utils@^9.2.0", "@metamask/snaps-utils@^9.2.1": - version "9.2.1" - resolved "https://registry.yarnpkg.com/@metamask/snaps-utils/-/snaps-utils-9.2.1.tgz#3c5bff8a7b5c486227133d0176929beb893d98b2" - integrity sha512-Nt901AUu7KU5o/bo2giCvvrcflzWWXIc3xMoRE66ZKVlOYB/4DicTqcnSqK15VCeFgqYVrIRpfnNcEmfmA0uUA== +"@metamask/snaps-utils@^9.2.0", "@metamask/snaps-utils@^9.2.2": + version "9.2.2" + resolved "https://registry.yarnpkg.com/@metamask/snaps-utils/-/snaps-utils-9.2.2.tgz#ba78625bd4ff249f16cada74aae3841eac376ddc" + integrity sha512-j3las/qt3NMOrmaH8qN498JxzccIADhfDjZx2r1RERRsxT8mJL4vnWa+skvwWgp4FKVuwYNSgzLoHdWDXVIwaQ== dependencies: "@babel/core" "^7.23.2" "@babel/types" "^7.23.0" - "@metamask/base-controller" "^8.0.0" + "@metamask/base-controller" "^8.0.1" "@metamask/key-tree" "^10.1.1" "@metamask/permission-controller" "^11.0.6" "@metamask/rpc-errors" "^7.0.2" "@metamask/slip44" "^4.1.0" "@metamask/snaps-registry" "^3.2.3" - "@metamask/snaps-sdk" "^6.22.1" + "@metamask/snaps-sdk" "^6.23.0" "@metamask/superstruct" "^3.2.1" "@metamask/utils" "^11.4.0" "@noble/hashes" "^1.7.1" From 9a5075699dde7eba6bcb1383c979cc965756b26d Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 8 May 2025 12:47:53 +0200 Subject: [PATCH 2/9] Deduplicate `@metamask/post-message-stream` --- package.json | 2 +- yarn.lock | 8 -------- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/package.json b/package.json index 24c6e1066145..af8e8b55fc84 100644 --- a/package.json +++ b/package.json @@ -202,7 +202,7 @@ "@metamask/notification-services-controller": "^7.0.0", "@metamask/permission-controller": "^11.0.6", "@metamask/phishing-controller": "^12.4.1", - "@metamask/post-message-stream": "^9.0.0", + "@metamask/post-message-stream": "^10.0.0", "@metamask/ppom-validator": "0.36.0", "@metamask/preferences-controller": "^17.0.0", "@metamask/profile-sync-controller": "^13.0.0", diff --git a/yarn.lock b/yarn.lock index 2c2aee533cf9..09a060eacaf3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5520,14 +5520,6 @@ "@metamask/utils" "^11.4.0" readable-stream "3.6.2" -"@metamask/post-message-stream@^9.0.0": - version "9.0.0" - resolved "https://registry.yarnpkg.com/@metamask/post-message-stream/-/post-message-stream-9.0.0.tgz#1b1249eb7d378cc1eda8abe6b2f882f6dd923c46" - integrity sha512-JQVu+aENg8r4LiZPPEsmaa+N9j3ecBcumtAEWZ+N5tB6qX/WcLLwCsfNidCx7zQCR0ritgx3lLbZ/sVqkNZ2OQ== - dependencies: - "@metamask/utils" "^11.0.1" - readable-stream "3.6.2" - "@metamask/ppom-validator@0.36.0": version "0.36.0" resolved "https://registry.yarnpkg.com/@metamask/ppom-validator/-/ppom-validator-0.36.0.tgz#cc8ace84ead3521c1b079650fa4169d1020bc070" From d19e959b9a61c2d95603d19f6f8b1aacc542230a Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 8 May 2025 12:54:01 +0200 Subject: [PATCH 3/9] Update `post-message-stream` patch --- ...@metamask+post-message-stream+10.0.0.patch | 67 +++++++++++++++++++ .../@metamask+post-message-stream+9.0.0.patch | 30 --------- 2 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 patches/@metamask+post-message-stream+10.0.0.patch delete mode 100644 patches/@metamask+post-message-stream+9.0.0.patch diff --git a/patches/@metamask+post-message-stream+10.0.0.patch b/patches/@metamask+post-message-stream+10.0.0.patch new file mode 100644 index 000000000000..f04137ffb73c --- /dev/null +++ b/patches/@metamask+post-message-stream+10.0.0.patch @@ -0,0 +1,67 @@ +diff --git a/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.cjs b/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.cjs +index 0aaba03..e6eb9ea 100644 +--- a/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.cjs ++++ b/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.cjs +@@ -1,4 +1,11 @@ + "use strict"; ++/** ++ * ============================== PATCH INFORMATION ============================== ++ * This patch was added for Snaps controller integration. The MessageEvent is not ++ * available in react native so we can simply return undefined here and handle the ++ * origin and source elsewhere. ++ * =============================================================================== ++ */ + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@ -17,11 +24,13 @@ const utils_1 = require("@metamask/utils"); + const BasePostMessageStream_1 = require("../BasePostMessageStream.cjs"); + const utils_2 = require("../utils.cjs"); + /* istanbul ignore next */ +-const getSource = (_a = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'source')) === null || _a === void 0 ? void 0 : _a.get; +-(0, utils_1.assert)(getSource, 'MessageEvent.prototype.source getter is not defined.'); ++// const getSource = (_a = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'source')) === null || _a === void 0 ? void 0 : _a.get; ++// (0, utils_1.assert)(getSource, 'MessageEvent.prototype.source getter is not defined.'); ++const getSource = () => undefined; + /* istanbul ignore next */ +-const getOrigin = (_b = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'origin')) === null || _b === void 0 ? void 0 : _b.get; +-(0, utils_1.assert)(getOrigin, 'MessageEvent.prototype.origin getter is not defined.'); ++// const getOrigin = (_b = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'origin')) === null || _b === void 0 ? void 0 : _b.get; ++// (0, utils_1.assert)(getOrigin, 'MessageEvent.prototype.origin getter is not defined.'); ++const getOrigin = () => undefined; + /** + * A {@link Window.postMessage} stream. + */ +diff --git a/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.mjs b/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.mjs +index db60ec4..ff6d786 100644 +--- a/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.mjs ++++ b/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.mjs +@@ -1,3 +1,10 @@ ++/** ++ * ============================== PATCH INFORMATION ============================== ++ * This patch was added for Snaps controller integration. The MessageEvent is not ++ * available in react native so we can simply return undefined here and handle the ++ * origin and source elsewhere. ++ * =============================================================================== ++ */ + var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) +@@ -14,11 +21,13 @@ import { assert } from "@metamask/utils"; + import { BasePostMessageStream } from "../BasePostMessageStream.mjs"; + import { isValidStreamMessage } from "../utils.mjs"; + /* istanbul ignore next */ +-const getSource = (_a = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'source')) === null || _a === void 0 ? void 0 : _a.get; +-assert(getSource, 'MessageEvent.prototype.source getter is not defined.'); ++// const getSource = (_a = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'source')) === null || _a === void 0 ? void 0 : _a.get; ++// assert(getSource, 'MessageEvent.prototype.source getter is not defined.'); ++const getSource = () => undefined; + /* istanbul ignore next */ +-const getOrigin = (_b = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'origin')) === null || _b === void 0 ? void 0 : _b.get; +-assert(getOrigin, 'MessageEvent.prototype.origin getter is not defined.'); ++// const getOrigin = (_b = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'origin')) === null || _b === void 0 ? void 0 : _b.get; ++// assert(getOrigin, 'MessageEvent.prototype.origin getter is not defined.'); ++const getOrigin = () => undefined; + /** + * A {@link Window.postMessage} stream. + */ diff --git a/patches/@metamask+post-message-stream+9.0.0.patch b/patches/@metamask+post-message-stream+9.0.0.patch deleted file mode 100644 index 1f320420ffba..000000000000 --- a/patches/@metamask+post-message-stream+9.0.0.patch +++ /dev/null @@ -1,30 +0,0 @@ -diff --git a/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.js b/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.js -index f2e42ef..27807bb 100644 ---- a/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.js -+++ b/node_modules/@metamask/post-message-stream/dist/window/WindowPostMessageStream.js -@@ -17,11 +17,21 @@ const utils_1 = require("@metamask/utils"); - const BasePostMessageStream_1 = require("../BasePostMessageStream"); - const utils_2 = require("../utils"); - /* istanbul ignore next */ --const getSource = (_a = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'source')) === null || _a === void 0 ? void 0 : _a.get; --(0, utils_1.assert)(getSource, 'MessageEvent.prototype.source getter is not defined.'); -+/** -++ * ============================== PATCH INFORMATION ============================== -++ * This patch was added for snaps controller integration. The MessageEvent is not -++ * available in react native so we can simply return undefined here and handle the -++ * origin and source elsewhere. -++ * =============================================================================== -++ */ -+/** -+// const getSource = (_a = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'source')) === null || _a === void 0 ? void 0 : _a.get; -+// (0, utils_1.assert)(getSource, 'MessageEvent.prototype.source getter is not defined.'); -+const getSource = () => undefined; - /* istanbul ignore next */ --const getOrigin = (_b = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'origin')) === null || _b === void 0 ? void 0 : _b.get; --(0, utils_1.assert)(getOrigin, 'MessageEvent.prototype.origin getter is not defined.'); -+// const getOrigin = (_b = Object.getOwnPropertyDescriptor(MessageEvent.prototype, 'origin')) === null || _b === void 0 ? void 0 : _b.get; -+// (0, utils_1.assert)(getOrigin, 'MessageEvent.prototype.origin getter is not defined.'); -+const getOrigin = () => undefined; - /** - * A {@link Window.postMessage} stream. - */ From 06efb503d5d5b4622ddc974ec54fa7e6a156380c Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 8 May 2025 13:10:07 +0200 Subject: [PATCH 4/9] Update webview execution environment path --- app/__mocks__/htmlMock.ts | 2 +- app/lib/snaps/SnapsExecutionWebView.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/__mocks__/htmlMock.ts b/app/__mocks__/htmlMock.ts index de49880d8199..d17d8815499f 100644 --- a/app/__mocks__/htmlMock.ts +++ b/app/__mocks__/htmlMock.ts @@ -1,3 +1,3 @@ //@ts-expect-error TS issue: Cannot find module '../../node_modules/@metamask/... -export { default as html } from '../../node_modules/@metamask/snaps-execution-environments/dist/browserify/webview/index.html'; +export { default as html } from '../../node_modules/@metamask/snaps-execution-environments/dist/webpack/webview/index.html'; diff --git a/app/lib/snaps/SnapsExecutionWebView.tsx b/app/lib/snaps/SnapsExecutionWebView.tsx index 2aa12f15c100..efb8e12d6d6e 100644 --- a/app/lib/snaps/SnapsExecutionWebView.tsx +++ b/app/lib/snaps/SnapsExecutionWebView.tsx @@ -7,7 +7,7 @@ import { WebViewInterface } from '@metamask/snaps-controllers/react-native'; import { WebViewError } from '@metamask/react-native-webview/lib/WebViewTypes'; import { PostMessageEvent } from '@metamask/post-message-stream'; // @ts-expect-error Types are currently broken for this. -import WebViewHTML from '@metamask/snaps-execution-environments/dist/browserify/webview/index.html'; +import WebViewHTML from '@metamask/snaps-execution-environments/dist/webpack/webview/index.html'; import { EmptyObject } from '@metamask/snaps-sdk'; const styles = createStyles(); From d95abf68f1f71cb345ee744017bf4e184f97c0d0 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 8 May 2025 13:59:44 +0200 Subject: [PATCH 5/9] Bump `snaps-execution-environments` again --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index af8e8b55fc84..ba96db20b803 100644 --- a/package.json +++ b/package.json @@ -220,7 +220,7 @@ "@metamask/slip44": "^4.1.0", "@metamask/smart-transactions-controller": "^16.3.1", "@metamask/snaps-controllers": "^12.0.0", - "@metamask/snaps-execution-environments": "^8.0.0", + "@metamask/snaps-execution-environments": "^8.0.1", "@metamask/snaps-rpc-methods": "^12.2.0", "@metamask/snaps-sdk": "^6.23.0", "@metamask/snaps-utils": "^9.2.2", diff --git a/yarn.lock b/yarn.lock index 09a060eacaf3..3bfdbc6a4bc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5747,10 +5747,10 @@ semver "^7.5.4" tar-stream "^3.1.7" -"@metamask/snaps-execution-environments@^8.0.0": - version "8.0.0" - resolved "https://registry.yarnpkg.com/@metamask/snaps-execution-environments/-/snaps-execution-environments-8.0.0.tgz#1e3dccd57cfb0fca65f65012889ef30dad78ff42" - integrity sha512-Xrcwwujr067vxQHb/EeH4NeD13OU/rKiaPhkenez8XM8KkvX/XCVZY+1xYWKh5A9J9+5BPigfdUToN4rvxT84g== +"@metamask/snaps-execution-environments@^8.0.1": + version "8.0.1" + resolved "https://registry.yarnpkg.com/@metamask/snaps-execution-environments/-/snaps-execution-environments-8.0.1.tgz#e1f6b2f82ce78eacc560264b497f061fccbb83ae" + integrity sha512-mixUO02zvt45SvSZev1IH4HRy7hwHK/gb/aq6yO72ev8gTHFDUBoVRnfzBTriDQFCgkM6tTfS+DVt9+CFCs1Ug== dependencies: "@metamask/json-rpc-engine" "^10.0.2" "@metamask/object-multiplex" "^2.1.0" From 18977e836556066841a988507e6699d5c49cd16c Mon Sep 17 00:00:00 2001 From: David Drazic Date: Tue, 13 May 2025 09:56:51 +0200 Subject: [PATCH 6/9] feat(snaps): Add Snap export tracking hook to Snap controller init (#14428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** This PR adds MetaMetrics tracking hook to Snap controller init. This way we delegate Snap export tracking to Snap controller. ## **Related issues** Related PR: https://github.com/MetaMask/snaps/pull/3281 https://github.com/MetaMask/metamask-extension/pull/31553 ## **Notes** - Requires Snaps release. - Snaps PR: https://github.com/MetaMask/snaps/pull/3281 - Targets Snaps release when ready. ## **Manual testing steps** 1. TBD ## **Screenshots/Recordings** ### **Before** n/a ### **After** n/a ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- .../controllers/snaps/snap-controller-init.test.ts | 1 + .../Engine/controllers/snaps/snap-controller-init.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/app/core/Engine/controllers/snaps/snap-controller-init.test.ts b/app/core/Engine/controllers/snaps/snap-controller-init.test.ts index 07883880aaeb..98e01c836990 100644 --- a/app/core/Engine/controllers/snaps/snap-controller-init.test.ts +++ b/app/core/Engine/controllers/snaps/snap-controller-init.test.ts @@ -68,6 +68,7 @@ describe('SnapControllerInit', () => { getMnemonicSeed: expect.any(Function), maxIdleTime: expect.any(Number), preinstalledSnaps: expect.any(Array), + trackEvent: expect.any(Function), }); }); diff --git a/app/core/Engine/controllers/snaps/snap-controller-init.ts b/app/core/Engine/controllers/snaps/snap-controller-init.ts index dd1420d201eb..5078ef7da902 100644 --- a/app/core/Engine/controllers/snaps/snap-controller-init.ts +++ b/app/core/Engine/controllers/snaps/snap-controller-init.ts @@ -21,6 +21,8 @@ import { selectBasicFunctionalityEnabled } from '../../../../selectors/settings' import { store } from '../../../../store'; import PREINSTALLED_SNAPS from '../../../../lib/snaps/preinstalled-snaps'; import { Caip25EndowmentPermissionName } from '@metamask/chain-agnostic-permission'; +import { MetaMetrics } from '../../../Analytics'; +import { MetricsEventBuilder } from '../../../Analytics/MetricsEventBuilder'; /** * Initialize the Snap controller. @@ -119,6 +121,16 @@ export const snapControllerInit: ControllerInitFunction< clientCryptography: { pbkdf2Sha512: pbkdf2, }, + trackEvent: (params: { + event: string; + properties?: Record; + }) => + MetaMetrics.getInstance().trackEvent( + MetricsEventBuilder.createEventBuilder({ + category: params.event, + properties: params.properties, + }).build(), + ), }); return { From e90e1d48ec7c2bd5c4683d8f0d2810ee222ed3b0 Mon Sep 17 00:00:00 2001 From: David Drazic Date: Tue, 13 May 2025 10:04:38 +0200 Subject: [PATCH 7/9] feat(snaps): Add integration for new RPC method snap_trackEvent (#15209) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## **Description** Add integration for new RPC method: `snap_trackEvent` SIP-32: https://metamask.github.io/SIPs/SIPS/sip-32 Related PRs: - Snaps: https://github.com/MetaMask/snaps/pull/3375 - Extension: https://github.com/MetaMask/metamask-extension/pull/32554 ## **Related issues** https://github.com/MetaMask/snaps/issues/3274 ## **Manual testing steps** 1. Within some of the preinstalled Snaps use `snap_trackEvent` RPC method and send some tracking data in format specified in [SIP-32](https://metamask.github.io/SIPs/SIPS/sip-32). 2. Find a way and verify that the event is sent (intercept MetaMetrics track event method or check with other e2e metrics testing utilities) Example Snap code used for testing the method: ```typescript await snap.request({ method: 'snap_trackEvent', params: { event: { event: 'SnapExportUsed', properties: { export: 'onRpcRequest', origin: 'https://metamask.io', snap_category: null, snap_id: 'npm:@metamask/example-snap', success: true, }, sensitiveProperties: { transaction_hash: 'transaction-hash', }, }, }, }); ``` ## **Screenshots/Recordings** ### **Before** n/a ### **After** n/a ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --- app/core/Permissions/specifications.js | 1 + app/core/Snaps/SnapsMethodMiddleware.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/app/core/Permissions/specifications.js b/app/core/Permissions/specifications.js index 3cd4aa0bdfe4..cb53923ca757 100644 --- a/app/core/Permissions/specifications.js +++ b/app/core/Permissions/specifications.js @@ -172,6 +172,7 @@ export const unrestrictedMethods = Object.freeze([ 'snap_resolveInterface', 'snap_setState', 'snap_scheduleBackgroundEvent', + 'snap_trackEvent', 'snap_cancelBackgroundEvent', 'snap_getBackgroundEvents', 'snap_experimentalProviderRequest', diff --git a/app/core/Snaps/SnapsMethodMiddleware.ts b/app/core/Snaps/SnapsMethodMiddleware.ts index 1fa850bcf0d4..148dc88148bb 100644 --- a/app/core/Snaps/SnapsMethodMiddleware.ts +++ b/app/core/Snaps/SnapsMethodMiddleware.ts @@ -26,6 +26,9 @@ import { SnapInterfaceControllerUpdateInterfaceStateAction, } from '../Engine/controllers/snaps'; import { KeyringTypes } from '@metamask/keyring-controller'; +import { MetaMetrics } from '../../../app/core/Analytics'; +import { MetricsEventBuilder } from '../Analytics/MetricsEventBuilder'; +import { Json } from '@metamask/utils'; export function getSnapIdFromRequest( request: Record, @@ -121,6 +124,19 @@ const snapMethodMiddlewareBuilder = ( controllerMessenger, SnapControllerGetSnapAction, ), + trackEvent: (eventPayload: { + event: string; + properties: Record; + sensitiveProperties: Record; + }) => { + MetaMetrics.getInstance().trackEvent( + MetricsEventBuilder.createEventBuilder({ + category: eventPayload.event, + properties: eventPayload.properties, + sensitiveProperties: eventPayload.sensitiveProperties, + }).build(), + ); + }, updateInterfaceState: controllerMessenger.call.bind( controllerMessenger, SnapInterfaceControllerUpdateInterfaceStateAction, From 0cb25319ace987b56c926fbe255f889f50f49a2c Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 13 May 2025 10:55:31 +0200 Subject: [PATCH 8/9] Add test --- .../snaps/snap-controller-init.test.ts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/app/core/Engine/controllers/snaps/snap-controller-init.test.ts b/app/core/Engine/controllers/snaps/snap-controller-init.test.ts index 98e01c836990..56be3d29852c 100644 --- a/app/core/Engine/controllers/snaps/snap-controller-init.test.ts +++ b/app/core/Engine/controllers/snaps/snap-controller-init.test.ts @@ -11,6 +11,7 @@ import { buildControllerInitRequestMock } from '../../utils/test-utils'; import { ExtendedControllerMessenger } from '../../../ExtendedControllerMessenger'; import { KeyringControllerGetKeyringsByTypeAction } from '@metamask/keyring-controller'; import { store } from '../../../../store'; +import { MetaMetrics } from '../../../Analytics'; jest.mock('@metamask/snaps-controllers'); @@ -139,4 +140,33 @@ describe('SnapControllerInit', () => { }); }); }); + + describe('trackEvent', () => { + it('calls the MetaMetrics `trackEvent` function', () => { + snapControllerInit(getInitRequestMock()); + + const controllerMock = jest.mocked(SnapController); + const trackEvent = controllerMock.mock.calls[0][0].trackEvent; + + const instance = MetaMetrics.getInstance(); + const spy = jest.spyOn(instance, 'trackEvent'); + + trackEvent({ + event: 'test-event', + category: 'test-category', + properties: { + testProperty: 'test-value', + }, + }); + + expect(spy).toHaveBeenCalledWith( + expect.objectContaining({ + name: 'test-event', + properties: { + testProperty: 'test-value', + }, + }), + ); + }); + }); }); From 6faab39d3d7b31acc2cd63289e6436e66be7f1b1 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Tue, 13 May 2025 11:43:18 +0200 Subject: [PATCH 9/9] Add missing await --- app/core/Engine/Engine.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/core/Engine/Engine.ts b/app/core/Engine/Engine.ts index a8505a8bdeda..8a15456664ec 100644 --- a/app/core/Engine/Engine.ts +++ b/app/core/Engine/Engine.ts @@ -1438,7 +1438,7 @@ export class Engine { (state: NetworkState) => { if ( state.networksMetadata[state.selectedNetworkClientId].status === - NetworkStatus.Available && + NetworkStatus.Available && getGlobalChainId(networkController) !== currentChainId ) { // We should add a state or event emitter saying the provider changed @@ -1611,7 +1611,7 @@ export class Engine { const chainIdHex = toHexadecimal(chainId); const tokens = TokensController.state.allTokens?.[chainIdHex]?.[ - selectedInternalAccount.address + selectedInternalAccount.address ] || []; const { marketData } = TokenRatesController.state; const tokenExchangeRates = marketData?.[toHexadecimal(chainId)]; @@ -1624,7 +1624,7 @@ export class Engine { const decimalsToShow = (currentCurrency === 'usd' && 2) || undefined; if ( accountsByChainId?.[toHexadecimal(chainId)]?.[ - selectedInternalAccountFormattedAddress + selectedInternalAccountFormattedAddress ] ) { const balanceHex = @@ -1665,7 +1665,7 @@ export class Engine { const tokenBalances = allTokenBalances?.[selectedInternalAccount.address as Hex]?.[ - chainId + chainId ] ?? {}; tokens.forEach( (item: { address: string; balance?: string; decimals: number }) => { @@ -1676,9 +1676,9 @@ export class Engine { item.balance || (item.address in tokenBalances ? renderFromTokenMinimalUnit( - tokenBalances[item.address as Hex], - item.decimals, - ) + tokenBalances[item.address as Hex], + item.decimals, + ) : undefined); const tokenBalanceFiat = balanceToFiatNumber( // TODO: Fix this by handling or eliminating the undefined case @@ -1834,7 +1834,7 @@ export class Engine { // Remove all permissions. PermissionController?.clearState?.(); ///: BEGIN:ONLY_INCLUDE_IF(preinstalled-snaps,external-snaps) - SnapController.clearState(); + await SnapController.clearState(); ///: END:ONLY_INCLUDE_IF // Clear selected network