Skip to content

Commit

Permalink
feat: add methods to support ERC-4337 accounts (#3602)
Browse files Browse the repository at this point in the history
## Description

**Depends on:**

- [x] <MetaMask/keyring-api#213>
- [x] <MetaMask/KeyringController#315>
- [x] <#3617>

This PR adds the following new methods available in the `EthKeyring`
interface:

- `prepareUserOperation`
- `patchUserOperation`
- `signUserOperation`

See the [PR](MetaMask/keyring-api#213) in the
`keyring-api` for more details.

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation for new or updated code as appropriate
(note: this will usually be JSDoc)
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
danroc authored Jan 22, 2024
1 parent 20011c4 commit 8a79dc5
Show file tree
Hide file tree
Showing 8 changed files with 508 additions and 286 deletions.
2 changes: 1 addition & 1 deletion jest.config.packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = {
coverageProvider: 'babel',

// A list of reporter names that Jest uses when writing coverage reports
coverageReporters: ['text', 'html', 'json-summary'],
coverageReporters: ['text', 'html', 'json-summary', 'lcov'],

// An object that configures minimum threshold enforcement for coverage results
// (Each package defines this separately)
Expand Down
4 changes: 2 additions & 2 deletions packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
},
"dependencies": {
"@metamask/base-controller": "^4.1.0",
"@metamask/eth-snap-keyring": "^2.0.0",
"@metamask/keyring-api": "^1.1.0",
"@metamask/eth-snap-keyring": "^2.1.1",
"@metamask/keyring-api": "^2.0.0",
"@metamask/snaps-sdk": "^1.3.1",
"@metamask/snaps-utils": "^5.1.1",
"@metamask/utils": "^8.3.0",
Expand Down
19 changes: 14 additions & 5 deletions packages/accounts-controller/src/AccountsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ const mockGetKeyringForAccount = jest.fn();
const mockGetKeyringByType = jest.fn();
const mockGetAccounts = jest.fn();

const EOA_METHODS = [
EthMethod.PersonalSign,
EthMethod.Sign,
EthMethod.SignTransaction,
EthMethod.SignTypedDataV1,
EthMethod.SignTypedDataV3,
EthMethod.SignTypedDataV4,
] as const;

const mockAccount: InternalAccount = {
id: 'mock-id',
address: '0x123',
options: {},
methods: [...Object.values(EthMethod)],
methods: [...EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: 'Account 1',
Expand All @@ -45,7 +54,7 @@ const mockAccount2: InternalAccount = {
id: 'mock-id2',
address: '0x1234',
options: {},
methods: [...Object.values(EthMethod)],
methods: [...EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: 'Account 2',
Expand All @@ -58,7 +67,7 @@ const mockAccount3: InternalAccount = {
id: 'mock-id3',
address: '0x3333',
options: {},
methods: [...Object.values(EthMethod)],
methods: [...EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: '',
Expand All @@ -76,7 +85,7 @@ const mockAccount4: InternalAccount = {
id: 'mock-id4',
address: '0x4444',
options: {},
methods: [...Object.values(EthMethod)],
methods: [...EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name: 'Custom Name',
Expand Down Expand Up @@ -121,7 +130,7 @@ function createExpectedInternalAccount({
id,
address,
options: {},
methods: [...Object.values(EthMethod)],
methods: [...EOA_METHODS],
type: EthAccountType.Eoa,
metadata: {
name,
Expand Down
12 changes: 10 additions & 2 deletions packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
"dependencies": {
"@keystonehq/metamask-airgapped-keyring": "^0.13.1",
"@metamask/base-controller": "^4.1.0",
"@metamask/eth-keyring-controller": "^15.1.0",
"@metamask/eth-keyring-controller": "^17.0.0",
"@metamask/keyring-api": "^2.0.0",
"@metamask/message-manager": "^7.3.7",
"@metamask/preferences-controller": "^6.0.0",
"@metamask/utils": "^8.3.0",
"async-mutex": "^0.2.6",
"ethereumjs-util": "^7.0.10",
Expand All @@ -45,9 +47,9 @@
"@ethereumjs/common": "^3.2.0",
"@ethereumjs/tx": "^4.2.0",
"@keystonehq/bc-ur-registry-eth": "^0.9.0",
"@lavamoat/allow-scripts": "^2.3.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/preferences-controller": "^6.0.0",
"@metamask/scure-bip39": "^2.1.1",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
Expand All @@ -69,5 +71,11 @@
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
},
"lavamoat": {
"allowScripts": {
"ethereumjs-util>ethereum-cryptography>keccak": false,
"ethereumjs-util>ethereum-cryptography>secp256k1": false
}
}
}
Loading

0 comments on commit 8a79dc5

Please sign in to comment.