172 Commits

Author SHA1 Message Date
dependabot[bot]
3d5abbfb33 Bump minimatch from 3.0.4 to 3.1.2 (#126)
Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2.
- [Release notes](https://github.com/isaacs/minimatch/releases)
- [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2)

---
updated-dependencies:
- dependency-name: minimatch
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-16 10:34:06 -03:30
dependabot[bot]
d8359ce078 Bump @metamask/auto-changelog from 3.0.0 to 3.1.0 (#125)
Bumps [@metamask/auto-changelog](https://github.com/MetaMask/auto-changelog) from 3.0.0 to 3.1.0.
- [Release notes](https://github.com/MetaMask/auto-changelog/releases)
- [Changelog](https://github.com/MetaMask/auto-changelog/blob/main/CHANGELOG.md)
- [Commits](https://github.com/MetaMask/auto-changelog/compare/v3.0.0...v3.1.0)

---
updated-dependencies:
- dependency-name: "@metamask/auto-changelog"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-16 10:30:34 -03:30
dependabot[bot]
82c6eef09a Bump @metamask/auto-changelog from 2.6.1 to 3.0.0 (#122)
Bumps [@metamask/auto-changelog](https://github.com/MetaMask/auto-changelog) from 2.6.1 to 3.0.0.
- [Release notes](https://github.com/MetaMask/auto-changelog/releases)
- [Changelog](https://github.com/MetaMask/auto-changelog/blob/main/CHANGELOG.md)
- [Commits](https://github.com/MetaMask/auto-changelog/compare/v2.6.1...v3.0.0)

---
updated-dependencies:
- dependency-name: "@metamask/auto-changelog"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-08 10:56:31 -03:30
Erik Marks
040a6ba85d Handle JSON-RPC notifications (#104)
This PR adds [JSON-RPC 2.0](https://www.jsonrpc.org/specification)-compliant notification handling for `JsonRpcEngine`.

- JSON-RPC notifications are defined as JSON-RPC request objects without an `id` property.
- A new constructor parameter, `notificationHandler`, is introduced. This parameter is a function that accepts JSON-RPC notification objects and returns `void | Promise<void>`.
- When `JsonRpcEngine.handle` is called, if a `notificationHandler` exists, any request objects duck-typed as notifications will be handled as such. This means that:
  - Validation errors that occur after duck-typing will be ignored. At the moment, this just means that no error will be thrown if the `method` field is not a string.
  - If basic validation succeeds, the notification object will be passed to the handler function without touching the middleware stack.
  - The response from `handle()` will be `undefined`.
  - No error will be returned or thrown, unless the notification handler itself throws or rejects.
    - Notification handlers should not throw or reject, and it is the implementer's responsibility to ensure that they do not.
- If `JsonRpcEngine.handle` is called and no `notificationHandler` exists, notifications will be treated just like requests. This is the current behavior.
2022-08-15 15:59:33 -07:00
dependabot[bot]
915920b0b6 Bump @metamask/utils from 2.0.0 to 2.1.0 (#113)
Bumps [@metamask/utils](https://github.com/MetaMask/utils) from 2.0.0 to 2.1.0.
- [Release notes](https://github.com/MetaMask/utils/releases)
- [Changelog](https://github.com/MetaMask/utils/blob/main/CHANGELOG.md)
- [Commits](https://github.com/MetaMask/utils/compare/v2.0.0...v2.1.0)

---
updated-dependencies:
- dependency-name: "@metamask/utils"
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
2022-08-12 00:05:13 -07:00
dependabot[bot]
5f52458e5a Bump @metamask/auto-changelog from 2.5.0 to 2.6.1 (#111)
Bumps [@metamask/auto-changelog](https://github.com/MetaMask/auto-changelog) from 2.5.0 to 2.6.1.
- [Release notes](https://github.com/MetaMask/auto-changelog/releases)
- [Changelog](https://github.com/MetaMask/auto-changelog/blob/main/CHANGELOG.md)
- [Commits](https://github.com/MetaMask/auto-changelog/compare/v2.5.0...v2.6.1)

---
updated-dependencies:
- dependency-name: "@metamask/auto-changelog"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-08-11 23:57:22 -07:00
Erik Marks
7892421230 Rename engine test file (#108)
Renames `engine.test.ts` to `JsonRpcEngine.test.ts`.
2022-05-18 15:46:08 -07:00
Erik Marks
993328577d Add destroy method (#106)
Adds a new method `JsonRpcEngine.destroy()`, based on this hack in the MetaMask extension: 851fce9a3b/app/scripts/metamask-controller.js (L2785)

The `JsonRpcMiddleware` type is altered to permit a `destroy` property. Calling `JsonRpcEngine.destroy()` clears the internal middleware array, calls the `destroy()` method of every middleware with such an own or inherited property, and renders the engine instance unusable.

Kudos to @daoauth for the original implementation in #98.

Co-authored-by: daoauth <57783762+daoauth@users.noreply.github.com>
2022-05-18 15:38:53 -07:00
Erik Marks
61e159f358 BREAKING: Use @metamask/utils (#105)
Replace various utility types and functions with implementations copied over to `@metamask/utils`. Functionality should be practically identical.

The one possible deviation is that two `in` checks have been replaced with `hasProperty`, which does not walk the prototype chain. This should not be breaking for our purposes.
2022-05-16 16:25:43 -07:00
Erik Marks
07f76045ff Migrate to Jest (#102)
Migrates all tests to Jest and TypeScript per the module template. Care was taken to modify the existing tests as little as possible. Therefore, the tests unfortunately make prodigious use of casts to `any`. Nevertheless, to minimize such casts, a pair of assertion type guards were added for successful and failed JSON-RPC responses. They use the existing boolean type guards under the hood, and are fully tested.

Assertion type guards are tremendously helpful in situations like this, where boolean type guards don't help since e.g. `expect(typeGuard(value)).toBe(true);` doesn't tell TypeScript anything, and we have lint rules preventing us from calling `expect` conditionally.
2022-05-15 18:06:36 -07:00
Erik Marks
75d2d37c7a Improve module template compliance (#100)
This PR updates various repository features for module template compliance. This repository should be fully compliant as of this PR, except for tests, which will be addressed in a follow-up. Notable changes include:

- Updates the ESLint config and related dependencies
- Adds `@lavamoat/allow-scripts` and the `setup` package script
- Migrates from CircleCI to GitHub Actions
- Bumps the minimum Node version to 14
2022-04-08 11:16:22 -07:00
dependabot[bot]
d38b71aaa8 Bump ajv from 6.10.2 to 6.12.6 (#101)
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.10.2 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](https://github.com/ajv-validator/ajv/compare/v6.10.2...v6.12.6)

---
updated-dependencies:
- dependency-name: ajv
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-08 10:38:39 -02:30
dependabot[bot]
e13c6b0f2b Bump minimist from 1.2.5 to 1.2.6 (#99)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-04-07 17:38:05 -07:00
dependabot[bot]
b3faa73e09 Bump path-parse from 1.0.6 to 1.0.7 (#95)
Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7.
- [Release notes](https://github.com/jbgutierrez/path-parse/releases)
- [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7)

---
updated-dependencies:
- dependency-name: path-parse
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-08-12 01:20:17 -02:30
dependabot[bot]
d7cba73f5b Bump glob-parent from 5.0.0 to 5.1.2 (#93)
Bumps [glob-parent](https://github.com/gulpjs/glob-parent) from 5.0.0 to 5.1.2.
- [Release notes](https://github.com/gulpjs/glob-parent/releases)
- [Changelog](https://github.com/gulpjs/glob-parent/blob/main/CHANGELOG.md)
- [Commits](https://github.com/gulpjs/glob-parent/compare/v5.0.0...v5.1.2)

---
updated-dependencies:
- dependency-name: glob-parent
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-11 01:52:05 -02:30
Erik Marks
0e57ecd678 Add type guard utilities (#91)
Adds some type guard utilities in a new file, `utils.ts`, and accompanying unit tests.

In addition to fixing #89, adds a function for validating JSON-RPC ID values. As part of implementing that, this also fixes a long-standing bug where we returned `undefined` instead of `null` for the ID when returning an error for a request without an `id` value.
2021-05-18 10:10:06 -07:00
Erik Marks
a49cc10e9a Update ESLint and TypeScript dependencies and config (#90)
* Update eslint dependencies and config

* Update CI config

* Add .prettierrc.yml
2021-05-17 17:26:44 -07:00
dependabot[bot]
0d29384c0c Bump hosted-git-info from 2.8.7 to 2.8.9 (#88)
Bumps [hosted-git-info](https://github.com/npm/hosted-git-info) from 2.8.7 to 2.8.9.
- [Release notes](https://github.com/npm/hosted-git-info/releases)
- [Changelog](https://github.com/npm/hosted-git-info/blob/v2.8.9/CHANGELOG.md)
- [Commits](https://github.com/npm/hosted-git-info/compare/v2.8.7...v2.8.9)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2021-05-11 11:33:53 -02:30
dependabot[bot]
7104f4d853 Bump lodash from 4.17.19 to 4.17.21 (#87)
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.19 to 4.17.21.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.19...4.17.21)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-05-11 11:31:58 -02:30
ryanml
2cdd922d10 Repo standardization (#86)
* Enforcing minimum node version 12 via .nvmrc, circleci, and the package file
* Adding a note about running tests to README.md
* Adding basic .gitattributes file
2021-04-08 07:49:42 -07:00
dependabot[bot]
3e8b71c9d6 Bump y18n from 4.0.0 to 4.0.1 (#85)
Bumps [y18n](https://github.com/yargs/y18n) from 4.0.0 to 4.0.1.
- [Release notes](https://github.com/yargs/y18n/releases)
- [Changelog](https://github.com/yargs/y18n/blob/master/CHANGELOG.md)
- [Commits](https://github.com/yargs/y18n/commits)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-03-31 09:21:03 -07:00
Niranjana Binoy
bece020a9d resolve() function argument was missing in Promise definition (#79) 2020-12-16 21:44:38 -05:00
Erik Marks
ec2e829d09 6.1.0 (#76)
* 6.1.0

* Update changelog
2020-11-20 09:03:09 -08:00
Erik Marks
20e58bc142 Add pending response type, use in middleware (#75) 2020-11-20 08:53:26 -08:00
Erik Marks
ebf0c55aef Use async/await and try/catch in place of Promise methods (#74)
* Remove use of .then/.catch in asMiddleware

* Use async/await in _handleBatch

* Use async/await in createAsyncMiddleware
2020-11-20 08:51:40 -08:00
Erik Marks
0e1006acf4 Add prepublishOnly script (#73) 2020-11-19 11:26:51 -08:00
Erik Marks
c3a774c7cc 6.0.0 (#72)
* 6.0.0

* Update changelog
2020-11-19 10:54:09 -08:00
Erik Marks
cf777cf502 Refactor internal error handling (#71)
* Refactor internal error handling

* Convert some methods to static

* Add docstrings
2020-11-19 09:46:11 -08:00
Erik Marks
f39f39d96f Add runtime typecheck for request objects and return handlers, refactor _handle (#70)
* Convert _handle to async function

* Add runtime typecheck for request object and request.method

* Add return handler typecheck
2020-11-19 08:58:36 -08:00
Erik Marks
9b04c79f4d Migrate to TypeScript (#69)
* Migrate to TypeScript

* Update CI config

* Update eth-rpc-errors, fix JsonRpcError stack type

* Add runtime typecheck for handle callback

* Use Maybe utility type for response.result
2020-11-18 12:56:38 -08:00
Erik Marks
cd832cefa8 5.4.0 (#68)
* 5.4.0

* Update changelog
2020-11-08 18:10:09 -08:00
Erik Marks
1e6f64751e Add missing types, fix remaining faulty ones (#67)
* Add missing types, fix faulty ones
2020-11-07 19:58:19 -08:00
Erik Marks
f938de657e Fix some type issues (#66)
* Fix some type errors

* More fixup

* fixup! More fixup

* Remove needlessly complicated XOR type

* fixup! Remove needlessly complicated XOR type
2020-10-25 19:10:48 -07:00
Whymarrh Whitby
82664565b5 Use yargs@15.4.1 (#65) 2020-09-07 11:16:52 -02:30
Erik Marks
06b8bc8ffc 5.3.0 (#64)
* 5.3.0

* update changelog
2020-07-30 13:01:28 -07:00
Erik Marks
a7307f7e25 eth-rpc-errors@3.0.0 (#63) 2020-07-30 12:43:03 -07:00
Erik Marks
39f03eec4d Correctly characterize async/await changes in changelog (#62)
* correctly characterize async/await changes in changelog
2020-07-29 12:06:18 -07:00
Erik Marks
65f60d9780 5.2.0 (#50)
* 5.2.0
* fix git URLs
* update changelog
* delete babel.config
2020-07-28 09:30:40 -07:00
Erik Marks
6509b94d6e Full test coverage (#52)
* 100% test coverage everywhere
* add nyc config, check coverage, use in CI
* add next handler test case
* add async handle tests
* add sinon; use stub
2020-07-28 09:16:37 -07:00
Erik Marks
2860ab914c Fix callback batch request handling (#61) 2020-07-27 15:17:58 -07:00
Mark Stacey
cb69d58b61 Update lockfile (#60)
The lockfile on `master` was out-of-date, and would change upon
installation.
2020-07-27 14:49:04 -07:00
Erik Marks
d564a23d6d Factor runMiddleware into static method (#58) 2020-07-27 14:12:39 -07:00
Erik Marks
9ffe19e4fd Add async handle signature (#55)
* add async handle signature

* add await example to readme

* encapsulate callback vs promise logic in handle
2020-07-27 14:10:36 -07:00
Erik Marks
b4b2b0636b _runMiddlewares -> _runAllMiddleware (#59) 2020-07-27 13:58:21 -07:00
Erik Marks
042e17e413 Remove promise-to-callback, reimplement createAsyncMiddleware (#46)
* remove promise-to-callback, reimplement createAsyncMiddleware

* fix middleware plural copy
2020-07-27 13:42:29 -07:00
Erik Marks
776a07db30 Rationalize _promiseHandle (#54) 2020-07-27 13:38:42 -07:00
Erik Marks
dfcc5e158b Fix asMiddleware implementation, add test cases (#51)
* fix asMiddleware implementation, add tests
2020-07-27 13:34:23 -07:00
Erik Marks
b910c1376b Update README (#49)
Co-authored-by: Mark Stacey <markjstacey@gmail.com>
2020-07-27 13:13:20 -07:00
Erik Marks
74f139236a Remove babel (#53)
* remove babel, build scripts; update lint parser

* use ecmaVersion 2017, disable spread rule
2020-07-27 11:39:52 -07:00
Erik Marks
4a6e08df8b Add CODEOWNERS (#48) 2020-07-24 09:23:15 -07:00