Skip to content

Fix Sign-in With Ethereum (SIWE) metametric, add tests, and clean RPC method middleware event logic#18008

Merged
digiwand merged 16 commits intodevelopfrom
clean-createRPCMethodTrackingMiddleware
Mar 29, 2023
Merged

Fix Sign-in With Ethereum (SIWE) metametric, add tests, and clean RPC method middleware event logic#18008
digiwand merged 16 commits intodevelopfrom
clean-createRPCMethodTrackingMiddleware

Conversation

@digiwand
Copy link
Copy Markdown
Contributor

@digiwand digiwand commented Mar 6, 2023

Explanation

Fixes: #18474
See: #18007
Progresses #17974

Fix SIWE event and clean createRPCMethodTrackingMiddleware logic

Fix SIWE event that was introduced in #17688:
(while adding a test, I found a bug with the metametric event)

  • fix SIWE (sign-in with ethereum) event (returning number of array length instead of string)
  • add SIWE test

Clean:

  • condense tests
  • only need to build event properties once
  • no need to pass null event property (ui_customizations)
  • add ui_customizations event props to metametrics const
  • use errorCodes and TransactionStatus const

Screenshots/Screencaps

Before

After

Manual Testing Steps

  1. send RPC transaction through test Dapp
  2. with metametrics turned on, observe metametrics still send
  3. observe SIWE

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 6, 2023

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@digiwand digiwand marked this pull request as ready for review March 8, 2023 16:14
@digiwand digiwand requested a review from a team as a code owner March 8, 2023 16:14
@digiwand digiwand requested review from darkwing and removed request for a team March 8, 2023 16:14
jpuri
jpuri previously approved these changes Mar 8, 2023
Base automatically changed from fix-disabled-eth-sign-event to develop March 14, 2023 18:31
@digiwand digiwand force-pushed the clean-createRPCMethodTrackingMiddleware branch from 1a6bbd9 to 9dca36a Compare March 20, 2023 20:27
@digiwand digiwand requested review from filipsekulic and jpuri March 20, 2023 20:49
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [9dca36a]
Page Load Metrics (1632 ± 61 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint962491223216
domContentLoaded14681979160611957
load14682007163212761
domInteractive14681979160611957
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -294 bytes
  • ui: 0 bytes
  • common: 0 bytes

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 20, 2023

Codecov Report

Merging #18008 (726a9f7) into develop (79b2deb) will increase coverage by 0.00%.
The diff coverage is 70.59%.

@@           Coverage Diff            @@
##           develop   #18008   +/-   ##
========================================
  Coverage    64.55%   64.55%           
========================================
  Files          919      919           
  Lines        35444    35405   -39     
  Branches      9119     9099   -20     
========================================
- Hits         22880    22855   -25     
+ Misses       12564    12550   -14     
Impacted Files Coverage Δ
...p/scripts/lib/createRPCMethodTrackingMiddleware.js 80.20% <68.75%> (+8.77%) ⬆️
shared/constants/metametrics.js 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@digiwand digiwand force-pushed the clean-createRPCMethodTrackingMiddleware branch from 9dca36a to a2f9690 Compare March 24, 2023 02:21
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [a2f9690]
Page Load Metrics (1592 ± 41 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint94141116147
domContentLoaded1419175815748642
load1478175815928541
domInteractive1419175815748642
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -964 bytes
  • ui: 0 bytes
  • common: 0 bytes

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [91af4a8]
Page Load Metrics (1803 ± 55 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1002041452612
domContentLoaded15342003179811254
load15352021180311455
domInteractive15342003179811254
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -884 bytes
  • ui: 0 bytes
  • common: 85 bytes

@digiwand digiwand added the team-confirmations-secure-ux-PR PRs from the confirmations team label Mar 24, 2023
@digiwand
Copy link
Copy Markdown
Contributor Author

@jpuri thanks for the review! I updated the cleanup following the merge of #17688 (OpenSea security provider metrics). Looks like this PR introduced a bug to the tracked SIWE event, so I fixed it in this PR as well

@digiwand digiwand added the type-bug Something isn't working label Mar 24, 2023
@digiwand digiwand changed the title Clean RPC method middleware event logic Fix Sign-in With Ethereum (SIWE) metametric, add tests, and clean RPC method middleware event logic Mar 24, 2023
: properties.ui_customizations.push(
METAMETRIC_KEY_OPTIONS[METAMETRIC_KEY.UI_CUSTOMIZATIONS]
.SIWE,
);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turns out Array.push returns the length of the mutated array. this is a JS gotchya. fixed by using Array.concat

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [726a9f7]
Page Load Metrics (1423 ± 20 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint92134106126
domContentLoaded1323149614094622
load1343149714234120
domInteractive1323149614094622
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -882 bytes
  • ui: 0 bytes
  • common: 85 bytes

Copy link
Copy Markdown
Contributor

@jpuri jpuri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@seaona
Copy link
Copy Markdown
Member

seaona commented Mar 29, 2023

From QA looks good @digiwand ! Nice work! I've just discovered some other issue regarding metametrics and signatures, but this time related to Hardware Wallets. I've opened a separate issue, as I think it was already there before your changes. Just FYI
#18361

Comment on lines -264 to -320
let msgParams;

if (eventType.REQUESTED === EVENT_NAMES.SIGNATURE_REQUESTED) {
properties.signature_type = method;

const data = req?.params?.[0];
const from = req?.params?.[1];
const paramsExamplePassword = req?.params?.[2];

msgParams = {
...paramsExamplePassword,
from,
data,
origin,
};

const msgData = {
msgParams,
status: 'unapproved',
type: req.method,
};

try {
const securityProviderResponse = await securityProviderRequest(
msgData,
req.method,
);

if (securityProviderResponse?.flagAsDangerous === 1) {
properties.ui_customizations = ['flagged_as_malicious'];
} else if (securityProviderResponse?.flagAsDangerous === 2) {
properties.ui_customizations = ['flagged_as_safety_unknown'];
} else {
properties.ui_customizations = null;
}

if (method === MESSAGE_TYPE.PERSONAL_SIGN) {
const { isSIWEMessage } = detectSIWE({ data });
if (isSIWEMessage) {
properties.ui_customizations === null
? (properties.ui_customizations = [
METAMETRIC_KEY_OPTIONS[METAMETRIC_KEY.UI_CUSTOMIZATIONS]
.SIWE,
])
: properties.ui_customizations.push(
METAMETRIC_KEY_OPTIONS[METAMETRIC_KEY.UI_CUSTOMIZATIONS]
.SIWE,
);
}
}
} catch (e) {
console.warn(
`createRPCMethodTrackingMiddleware: Error calling securityProviderRequest - ${e}`,
);
}
} else {
properties.method = method;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not fully understanding why this was all removed, could you elaborate?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this turn out to be a wasteful duplication?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep! exactly. It's the same code verbatim from line 167. They live in the same scope of function rpcMethodTrackingMiddleware. no need to redefined :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@digiwand
Copy link
Copy Markdown
Contributor Author

Interesting. Good catch @seaona! I will write a comment in #18361 to start of the follow-up fix

@digiwand digiwand merged commit 058c571 into develop Mar 29, 2023
@digiwand digiwand deleted the clean-createRPCMethodTrackingMiddleware branch March 29, 2023 18:25
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-transactions team-confirmations-secure-ux-PR PRs from the confirmations team type-bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sign-in With Ethereum (SIWE) Cleanup [Bug]: When eth_sign is disabled we fire a Signature Approved event everytime we call the RPC method

7 participants