Code Monkey home page Code Monkey logo

core's Introduction

Core Monorepo

This monorepo is a collection of packages used across multiple MetaMask clients (e.g. metamask-extension, metamask-mobile).

Modules

This repository contains the following packages 1:

Or, in graph form 1:

%%{ init: { 'flowchart': { 'curve': 'bumpX' } } }%%
graph LR;
linkStyle default opacity:0.5
  accounts_controller(["@metamask/accounts-controller"]);
  address_book_controller(["@metamask/address-book-controller"]);
  announcement_controller(["@metamask/announcement-controller"]);
  approval_controller(["@metamask/approval-controller"]);
  assets_controllers(["@metamask/assets-controllers"]);
  base_controller(["@metamask/base-controller"]);
  build_utils(["@metamask/build-utils"]);
  chain_controller(["@metamask/chain-controller"]);
  composable_controller(["@metamask/composable-controller"]);
  controller_utils(["@metamask/controller-utils"]);
  ens_controller(["@metamask/ens-controller"]);
  eth_json_rpc_provider(["@metamask/eth-json-rpc-provider"]);
  gas_fee_controller(["@metamask/gas-fee-controller"]);
  json_rpc_engine(["@metamask/json-rpc-engine"]);
  json_rpc_middleware_stream(["@metamask/json-rpc-middleware-stream"]);
  keyring_controller(["@metamask/keyring-controller"]);
  logging_controller(["@metamask/logging-controller"]);
  message_manager(["@metamask/message-manager"]);
  name_controller(["@metamask/name-controller"]);
  network_controller(["@metamask/network-controller"]);
  notification_controller(["@metamask/notification-controller"]);
  notification_services_controller(["@metamask/notification-services-controller"]);
  permission_controller(["@metamask/permission-controller"]);
  permission_log_controller(["@metamask/permission-log-controller"]);
  phishing_controller(["@metamask/phishing-controller"]);
  polling_controller(["@metamask/polling-controller"]);
  preferences_controller(["@metamask/preferences-controller"]);
  profile_sync_controller(["@metamask/profile-sync-controller"]);
  queued_request_controller(["@metamask/queued-request-controller"]);
  rate_limit_controller(["@metamask/rate-limit-controller"]);
  selected_network_controller(["@metamask/selected-network-controller"]);
  signature_controller(["@metamask/signature-controller"]);
  transaction_controller(["@metamask/transaction-controller"]);
  user_operation_controller(["@metamask/user-operation-controller"]);
  accounts_controller --> base_controller;
  accounts_controller --> keyring_controller;
  address_book_controller --> base_controller;
  address_book_controller --> controller_utils;
  announcement_controller --> base_controller;
  approval_controller --> base_controller;
  assets_controllers --> accounts_controller;
  assets_controllers --> approval_controller;
  assets_controllers --> base_controller;
  assets_controllers --> controller_utils;
  assets_controllers --> keyring_controller;
  assets_controllers --> network_controller;
  assets_controllers --> polling_controller;
  assets_controllers --> preferences_controller;
  chain_controller --> base_controller;
  composable_controller --> base_controller;
  composable_controller --> json_rpc_engine;
  ens_controller --> base_controller;
  ens_controller --> controller_utils;
  ens_controller --> network_controller;
  eth_json_rpc_provider --> json_rpc_engine;
  gas_fee_controller --> base_controller;
  gas_fee_controller --> controller_utils;
  gas_fee_controller --> network_controller;
  gas_fee_controller --> polling_controller;
  json_rpc_middleware_stream --> json_rpc_engine;
  keyring_controller --> base_controller;
  keyring_controller --> message_manager;
  logging_controller --> base_controller;
  logging_controller --> controller_utils;
  message_manager --> base_controller;
  message_manager --> controller_utils;
  name_controller --> base_controller;
  name_controller --> controller_utils;
  network_controller --> base_controller;
  network_controller --> controller_utils;
  network_controller --> eth_json_rpc_provider;
  network_controller --> json_rpc_engine;
  notification_controller --> base_controller;
  notification_services_controller --> base_controller;
  notification_services_controller --> controller_utils;
  notification_services_controller --> keyring_controller;
  notification_services_controller --> profile_sync_controller;
  permission_controller --> base_controller;
  permission_controller --> controller_utils;
  permission_controller --> json_rpc_engine;
  permission_controller --> approval_controller;
  permission_log_controller --> base_controller;
  permission_log_controller --> json_rpc_engine;
  phishing_controller --> base_controller;
  phishing_controller --> controller_utils;
  polling_controller --> base_controller;
  polling_controller --> controller_utils;
  polling_controller --> network_controller;
  preferences_controller --> base_controller;
  preferences_controller --> controller_utils;
  preferences_controller --> keyring_controller;
  profile_sync_controller --> base_controller;
  queued_request_controller --> base_controller;
  queued_request_controller --> controller_utils;
  queued_request_controller --> json_rpc_engine;
  queued_request_controller --> network_controller;
  queued_request_controller --> selected_network_controller;
  rate_limit_controller --> base_controller;
  selected_network_controller --> base_controller;
  selected_network_controller --> json_rpc_engine;
  selected_network_controller --> network_controller;
  selected_network_controller --> permission_controller;
  signature_controller --> approval_controller;
  signature_controller --> base_controller;
  signature_controller --> controller_utils;
  signature_controller --> keyring_controller;
  signature_controller --> logging_controller;
  signature_controller --> message_manager;
  transaction_controller --> accounts_controller;
  transaction_controller --> approval_controller;
  transaction_controller --> base_controller;
  transaction_controller --> controller_utils;
  transaction_controller --> gas_fee_controller;
  transaction_controller --> network_controller;
  transaction_controller --> eth_json_rpc_provider;
  user_operation_controller --> approval_controller;
  user_operation_controller --> base_controller;
  user_operation_controller --> controller_utils;
  user_operation_controller --> gas_fee_controller;
  user_operation_controller --> keyring_controller;
  user_operation_controller --> network_controller;
  user_operation_controller --> polling_controller;
  user_operation_controller --> transaction_controller;
Loading

Refer to individual packages for usage instructions.

Learn more

For instructions on performing common development-related tasks, see contributing to the monorepo.

Footnotes

  1. The package list and dependency graph should be programmatically generated by running yarn update-readme-content. 2

core's People

Contributors

adonesky1 avatar belfordz avatar bergeron avatar bitpshr avatar cryptodev-2s avatar dbrans avatar dependabot[bot] avatar estebanmino avatar frederikbolding avatar github-actions[bot] avatar gudahtt avatar jiexi avatar jpuri avatar kanthesha avatar kumavis avatar legobeat avatar majorlift avatar matthewwalsh0 avatar mcmire avatar mikesposito avatar montelaidev avatar niranjanabinoy avatar ogpoyraz avatar prithpal-sooriya avatar rekmarks avatar rickycodes avatar sahar-fehri avatar shanejonas avatar vinistevam avatar whymarrh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core's Issues

Pass EthQuery instance into controllers

Many controllers accept a provider configuration property and internally create an EthQuery instance. We should make the NetworkControllers internal EthQuery instance public, and pass that into each controller instead of the provider.

This may be too restrictive, but it should be investigated.

Utils references undocumented stripHexPrefix from ethereumjs-util

stripHexPrefix isn't a documented function from ethereumjs-util v5.2.0,[1] but there are a few usages of it in src/utils.ts:

https://github.com/MetaMask/gaba/blob/7237cc605c0432f3a2298ec64a790bb3339aed59/src/util.ts#L70-L79

https://github.com/MetaMask/gaba/blob/7237cc605c0432f3a2298ec64a790bb3339aed59/src/util.ts#L81-L97

https://github.com/MetaMask/gaba/blob/7237cc605c0432f3a2298ec64a790bb3339aed59/src/util.ts#L172-L190

This code works in 5.x and in 6.x accidentally because all of ethjs-util is assigned to exports but we should either submit a patch upstream or rely on ethjs-util directly.[2][3]

Address book controller chainId potentially misleading

Address book entries are defined as:

interface AddressBookEntry {
  address: string;
  name: string;
  chainId: number;
  memo: string;
}

This leads us to believe that, perhaps, the user should be able to have entries with identical address fields and different chainId fields.

However, we store AddressBookEntrys by normalized addresses, and we normalize the address using toChecksumAddress(address), which returns the same address regardless of the chainId.

According to the ethereumjs-util documentation, we can add the chainId as an optional parameter to generate unique checksummed addresses by chainId. It appears they have yet to publish this version of the library, however, see: ethereumjs/ethereumjs-util#218

Question: if we compute checksummed addresses with chainId, can we still use those addresses directly for sending transactions? In other words, will they be different from what's currently displayed in the UI?

Add support for "mandatory" state updates

Currently the method BaseController.putState(state: object, forceUpdate: bool) is synchronous, and merely emits a state update, leaving persistence as an external concern, not coupled with controller logic.

I am working on a feature that will require guaranteed persistence to be coupled with some types of state updates, so I would like a way to update state that returns a promise and resolves once state has been persisted, so that it will be restored in the case of a system interruption.

Example use case

Let's say we add a login permission that enforces a rule like "This site may update my profile 5 times."

In order to enforce this rule, we need to ensure that portions of the state, namely:

  • update counter
  • outbound profile update messages

Are always persisted atomically, so that we never broadcast a profile update without also accounting for the site's limit.

This is about enforcing smart-contract-like guarantees within our own controllers, and if we want to decouple our security from constant user nagging, I believe this is a critical feature to pursue.

This will probably require gaba to become somewhat aware of its persistence strategy.

KeyringController state issues

There's something funky going on with the state of the KeyringController. Specifically with the property keyrings.

Once the property is updated via fullUpdate which internally calls update, the new value is not accessible via state (still has the default value) but it's fine if you access it via context.

How to reproduce from the app:
1 - Log in
2 - To verify that the value has been set, log Engine.context.KeyringController.state.keyrings => [{ type: 'HD Keyring', accounts: ['0x...']}]
3 - Now try to access it through state, logEngine.state.KeyringController.keyrings => []

Add test coverage for Keyring Controller

Test coverage is incorrectly reported at 100% due to the lack of importing and testing of the
KeyringController. The “heavy lifting” of this controller is handled in another package, but it’s still
important to test this controller to ensure proper usage.

Mock endpoints during tests

The current test suite doesn't mock any endpoints during unit testing. Instead, they either hit real endpoints or skip request entirely. We should be setting nock.disableNetConnect(); in the unit test setup to ensure that none of our tests will send real network requests, but first we'll have to migrate each test that relies upon the network to use mocks.

EDITED TO ADD:

Here are a list of controllers that have tests in which we need to mock network requests:

The safelyExecute​Function Swallows Exceptions

Gaba often makes use of a utility function called safelyExecute. The purpose of this function is to call a supplied function without handling any exceptions or errors that may occur.

The safelyExecute function accepts a function that returns a Promise and then calls it inside of a try...catch block. The catch block does not handle exceptions, provide a way for the caller to handle them, or even log the error. Because of this failures and critical issues can go unnoticed.

Tests fail with `npm ci` install

As of fcdf82f, npm ci && npm t fails with a lot of test files producing the following error:

> [email protected] test
> jest --coverage

[...]

    Cannot find module 'bignumber.js' from 'utils.js'
      
      at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:169:17)
      at Object.<anonymous> (node_modules/web3/lib/utils/utils.js:37:17)

Review all controllers for offline use

We should verify what happens to controllers when connectivity goes down and make sure they can resume peacefully. Is this something we handle higher up int he stack, like at the app level?

[DOCS] Clarify what GABA means

The GABA engine is a collection of platform-agnostic modules for creating secure data models for cryptocurrency wallets.

What does "GABA" mean?

TypeScript 3.9 compilation fails

Compilation with the latest 3.9 version results in the following errors:

src/user/PreferencesController.ts:186:5 - error TS2783: 'address' is specified more than once, so this usage will be overwritten.

186  			address,
     			~~~~~~~

  src/user/PreferencesController.ts:188:5
    188  			...(oldIdentities[address] || {})
         			~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This spread always overwrites this property.

src/user/PreferencesController.ts:187:5 - error TS2783: 'name' is specified more than once, so this usage will be overwritten.

187  			name: `Account ${index + 1}`,
     			~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  src/user/PreferencesController.ts:188:5
    188  			...(oldIdentities[address] || {})
         			~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This spread always overwrites this property.


Found 2 errors.

Replace Infura blacklist endpoint

The https://api.infura.io/v2/blacklist endpoint is just a proxy of https://raw.githubusercontent.com/409H/EtherAddressLookup/master/blacklists/domains.json and https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json. We should request these files from GitHub directly to reduce our Infura traffic.

Create EthereumAddress interface and class

By having an interface EthereumAddress we can forget about all the type related issues (string vs hex, etc).

If we have an EthereumAddress obj also we could call toChecksumAddress inside of the constructor and have some utility function like toShortString (which could return 0x1234...1234), etc.

cc: @danfinlay

Polling timers can exhaust file descriptors

Gaba contains a number of classes that initiate a polling mechanism for querying remote services for
various information. Due to the way in which these timers are written, certain network conditions could
lead to “stacking” connections, thus causing an exhaustion of sockets/file descriptors.

Add `justification` field

A requested permission should permit an optional justification field that is passed to the user confirmation function, to enhance the context of the prompt.

Should support text, but also be forward-extensible to other justification formats.

Migrate CI to CircleCI

This project should be using CircleCI, for consistency with the rest of the organization.

Make BaseController state immutable

The state member variable exposed by the BaseController is mutable and can be modified externally. Direct state modification shouldn't be allowed since it bypasses notification. The state variable should be made readonly so that it's immutable and can only be modified by calling update or an exposed API method that modifies state internally.

v2 Release

The current state of develop will be 2.0.0:

  • Remove web3 (#108)
  • Reuse collectible contract info (#165, optional)
  • Rename & scope package (#226)

Transaction validation is insufficient

The validateTransaction utility function in Gaba is not sufficient in preventing hostile input.

The value is converted to a string and then checked for “-” and “.” to determine if it is a negative or floating point number respectively. There are no other checks.

The current incarnation of this function allows the numerical values Infinity and NaN as well as unsafe
numbers like 10000000000000000 and even strings like “one million dollar$”. This can
potentially lead to a class of bugs like 9007199254740992 === 9007199254740993; // true

Instead of type casting and checking for substrings, the best approach here is to check
Number.isFinite(), !Number.isNaN(), and Number.isSafeInteger(). This will provide the
validation needed and perform better.

Triage BaseController member visibility

The notify method is exposed publicly on the BaseController, but it should be protected. It's an anti-pattern for notification to be triggered externally since it should already be triggered on every supported state change.

We should also triage all member visibility on the BaseController.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.