Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

deps: Replace eth-sig-util@^2 with @metamask/eth-sig-util@^6 #157

Merged
merged 14 commits into from
Oct 19, 2023

Conversation

adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Dec 20, 2022

TODO:

  • Fix mocking with sandbox... not properly mocking recoverPersonalSignature with this update.

@socket-security
Copy link

socket-security bot commented Dec 20, 2022

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: [email protected], [email protected], [email protected], [email protected], [email protected], @lavamoat/[email protected], [email protected], [email protected], [email protected]

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore [email protected] bar@* or ignore all packages with @SocketSecurity ignore-all

@adonesky1
Copy link
Contributor Author

adonesky1 commented Dec 21, 2022

@SocketSecurity ignore @ethereumjs/[email protected] [email protected]

(these are both packages we use throughout are dependency graph that we trust)

@legobeat
Copy link
Contributor

legobeat commented May 1, 2023

@adonesky1 Are you still intending to pick this up? FYI v5.1.0 was recently released.

@legobeat legobeat changed the title update eth-sig-util version to latest deps: Replace eth-sig-util@^2 with @metamask/eth-sig-util@^5 Oct 3, 2023
@legobeat legobeat added the dependencies Pull requests that update a dependency file label Oct 3, 2023
@legobeat legobeat changed the title deps: Replace eth-sig-util@^2 with @metamask/eth-sig-util@^5 deps: Replace eth-sig-util@^2 with @metamask/eth-sig-util@^6 Oct 3, 2023
@socket-security
Copy link

socket-security bot commented Oct 3, 2023

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: @lavamoat/[email protected], @types/[email protected]

@legobeat
Copy link
Contributor

legobeat commented Oct 3, 2023

@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]

network access ok

@legobeat
Copy link
Contributor

legobeat commented Oct 3, 2023

SocketSecurity alerts addressed in:

@legobeat
Copy link
Contributor

legobeat commented Oct 3, 2023

@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]
@SocketSecurity ignore [email protected]
@SocketSecurity ignore @lavamoat/[email protected]
@SocketSecurity ignore [email protected]

@legobeat
Copy link
Contributor

legobeat commented Oct 3, 2023

@adonesky1 I bumped this to eth-sig-util v6 (v7 blocked by Node.js v14 support) and resolved the test mocking (borrowed from here

@legobeat legobeat marked this pull request as ready for review October 3, 2023 05:40
@legobeat legobeat requested a review from a team as a code owner October 3, 2023 05:40
Comment on lines +12 to +19
jest.mock('@metamask/eth-sig-util', () => {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
...jest.requireActual('@metamask/eth-sig-util'),
};
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@legobeat is this necessary. Don't understand what, if anything, this is doing?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is in order to mock the new version (see error this is addressing here:

FAIL src/ledger-keyring.test.ts (14.651 s)
  ● LedgerKeyring › signPersonalMessage › should call create a listener waiting for the iframe response

    Cannot spyOn on a primitive value; undefined given

      616 |
      617 |       jest
    > 618 |         .spyOn(sigUtil, 'recoverPersonalSignature')
          |          ^
      619 |         .mockReturnValue(fakeAccounts[0]);
      620 |
      621 |       await keyring.signPersonalMessage(fakeAccounts[0], 'some message');

      at ModuleMocker.spyOn (node_modules/jest-mock/build/index.js:774:13)
      at Object.<anonymous> (src/ledger-keyring.test.ts:618:10)

Copy link

Choose a reason for hiding this comment

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

Yes, this is a common approach when bundling all exports from an import into one variable and then spying on an individual export. Basically we're making a copy of sigUtil so that all properties are writable (jest.spyOn reassigns the property you spy on).

@adonesky1
Copy link
Contributor Author

@legobeat this looks good to me. I can't approve since I opened the PR

legobeat
legobeat previously approved these changes Oct 4, 2023
legobeat
legobeat previously approved these changes Oct 10, 2023
Comment on lines +12 to +19
jest.mock('@metamask/eth-sig-util', () => {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
__esModule: true,
...jest.requireActual('@metamask/eth-sig-util'),
};
});

Copy link

Choose a reason for hiding this comment

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

Yes, this is a common approach when bundling all exports from an import into one variable and then spying on an individual export. Basically we're making a copy of sigUtil so that all properties are writable (jest.spyOn reassigns the property you spy on).

"hdkey": "0.8.0"
},
"devDependencies": {
"@ethereumjs/common": "^3.1.1",
"@lavamoat/allow-scripts": "^2.3.0",
"@ledgerhq/hw-app-eth": "^6.32.0",
"@ledgerhq/types-cryptoassets": "^7.6.0",
Copy link

Choose a reason for hiding this comment

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

Why are these extra dependencies necessary? I don't see them being used in this PR.

Copy link
Contributor

@legobeat legobeat Oct 19, 2023

Choose a reason for hiding this comment

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

They're used by sibling modules: https://github.com/MetaMask/eth-ledger-bridge-keyring/actions/runs/6577714417/job/17869959528?pr=201

Error: node_modules/@ledgerhq/domain-service/lib/types.d.ts(1,26): error TS2307: Cannot find module '@ledgerhq/types-cryptoassets' or its corresponding type declarations.
Error: node_modules/@ledgerhq/types-live/lib/account.d.ts(2,58): error TS2307: Cannot find module '@ledgerhq/types-cryptoassets' or its corresponding type declarations.
Error: node_modules/@ledgerhq/types-live/lib/bridge.d.ts(3,37): error TS2307: Cannot find module '@ledgerhq/types-cryptoassets' or its corresponding type declarations.
Error: node_modules/@ledgerhq/types-live/lib/manager.d.ts(3,37): error TS2307: Cannot find module '@ledgerhq/types-cryptoassets' or its corresponding type declarations.
Error: node_modules/@ledgerhq/types-live/lib/portfolio.d.ts(2,52): error TS2307: Cannot find module '@ledgerhq/types-cryptoassets' or its corresponding type declarations.
Error: node_modules/@ledgerhq/types-live/lib/transaction.d.ts(2,27): error TS2307: Cannot find module '@ledgerhq/types-cryptoassets' or its corresponding type declarations.
Error: Process completed with exit code 2.

@legobeat legobeat requested a review from mcmire October 19, 2023 16:55
Copy link

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Looks good!

@legobeat legobeat merged commit 94caef9 into main Oct 19, 2023
19 checks passed
@legobeat legobeat deleted the update-eth-sig-util-version branch October 19, 2023 23:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests that update a dependency file
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants