Skip to content

Commit

Permalink
Merge branch 'main' into caip-multichain
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Oct 22, 2024
2 parents 046133a + 24d257a commit eea9f46
Show file tree
Hide file tree
Showing 12 changed files with 204 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/core-monorepo",
"version": "223.0.0",
"version": "225.0.0",
"private": true,
"description": "Monorepo for packages shared between MetaMask clients",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@metamask/base-controller": "^7.0.1",
"@metamask/browser-passworder": "^4.3.0",
"@metamask/eth-hd-keyring": "^7.0.4",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/eth-sig-util": "^8.0.0",
"@metamask/eth-simple-keyring": "^6.0.5",
"@metamask/keyring-api": "^8.1.3",
"@metamask/message-manager": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/message-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/controller-utils": "^11.3.0",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/eth-sig-util": "^8.0.0",
"@metamask/utils": "^9.1.0",
"@types/uuid": "^8.3.0",
"jsonschema": "^1.2.4",
Expand Down
23 changes: 22 additions & 1 deletion packages/notification-services-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.11.0]

### Added

- Added support for an optional FCM token parameter for push notifications on mobile platforms, allowing native handling of FCM token creation through the Firebase SDK ([#4823](https://github.com/MetaMask/core/pull/4823))

### Changed

- update the types described in `types/on-chain-notification/schema` and `types/on-chain-notification/on-chain-notification` ([#4818](https://github.com/MetaMask/core/pull/4818))

- adds new notifications: aave_v3_health_factor; ens_expiration; lido_staking_rewards; notional_loan_expiration; rocketpool_staking_rewards; spark_fi_health_factor
- splits Wallet Notifications from Web 3 Notifications

- updated and added new notification mocks ([#4818](https://github.com/MetaMask/core/pull/4818))
- can be accessed through `@metamask/notification-services-controller/notification-services/mocks`

### Fixed

- made `updateMetamaskNotificationsList` function work correctly by making the message handler async and moving the publish call outside of the update function. This ensures the `NotificationServicesController:notificationsListUpdated` event is received by the extension ([#4826](https://github.com/MetaMask/core/pull/4826))

## [0.10.0]

### Added
Expand Down Expand Up @@ -200,7 +220,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.10.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.11.0...HEAD
[0.11.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.10.0...@metamask/notification-services-controller@0.11.0
[0.10.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.9.0...@metamask/notification-services-controller@0.10.0
[0.9.0]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.8.2...@metamask/notification-services-controller@0.9.0
[0.8.2]: https://github.com/MetaMask/core/compare/@metamask/notification-services-controller@0.8.1...@metamask/notification-services-controller@0.8.2
Expand Down
2 changes: 1 addition & 1 deletion packages/notification-services-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/notification-services-controller",
"version": "0.10.0",
"version": "0.11.0",
"description": "Manages New MetaMask decentralized Notification system",
"keywords": [
"MetaMask",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ export default class NotificationServicesController extends BaseController<
#registerMessageHandlers(): void {
this.messagingSystem.registerActionHandler(
`${controllerName}:updateMetamaskNotificationsList`,
this.updateMetamaskNotificationsList.bind(this),
async (...args) => this.updateMetamaskNotificationsList(...args),
);

this.messagingSystem.registerActionHandler(
Expand Down Expand Up @@ -1375,12 +1375,13 @@ export default class NotificationServicesController extends BaseController<
processedNotification,
...state.metamaskNotificationsList,
];
this.messagingSystem.publish(
`${controllerName}:notificationsListUpdated`,
state.metamaskNotificationsList,
);
}
});

this.messagingSystem.publish(
`${controllerName}:notificationsListUpdated`,
this.state.metamaskNotificationsList,
);
}
}
}
19 changes: 18 additions & 1 deletion packages/signature-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [20.1.0]

### Added

- Add additional properties to message parameter types ([#4822](https://github.com/MetaMask/core/pull/4822))
- Add `metamaskId` to `MessageParams`.
- Add `version` to `MessageParamsTyped`.

### Changed

- Update required arguments in methods ([#4822](https://github.com/MetaMask/core/pull/4822))
- Make `request` argument optional in `newUnsignedPersonalMessage` and `newUnsignedTypedMessage`.
- Make `signingOptions` argument optional in `newUnsignedTypedMessage`.
- Bump `eth-sig-util` from `^7.0.1` to `^8.0.0` ([#4830](https://github.com/MetaMask/core/pull/4830))
- Bump `@metamask/keyring-controller` from `^17.2.2` to `^17.3.0` ([#4643](https://github.com/MetaMask/core/pull/4643))

## [20.0.0]

### Added
Expand Down Expand Up @@ -363,7 +379,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Initial release ([#1214](https://github.com/MetaMask/core/pull/1214))

[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/signature-controller@20.0.0...HEAD
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/signature-controller@20.1.0...HEAD
[20.1.0]: https://github.com/MetaMask/core/compare/@metamask/signature-controller@20.0.0...@metamask/signature-controller@20.1.0
[20.0.0]: https://github.com/MetaMask/core/compare/@metamask/signature-controller@19.1.0...@metamask/signature-controller@20.0.0
[19.1.0]: https://github.com/MetaMask/core/compare/@metamask/signature-controller@19.0.0...@metamask/signature-controller@19.1.0
[19.0.0]: https://github.com/MetaMask/core/compare/@metamask/signature-controller@18.1.0...@metamask/signature-controller@19.0.0
Expand Down
4 changes: 2 additions & 2 deletions packages/signature-controller/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@metamask/signature-controller",
"version": "20.0.0",
"version": "20.1.0",
"description": "Processes signing requests in order to sign arbitrary and typed data",
"keywords": [
"MetaMask",
Expand Down Expand Up @@ -49,7 +49,7 @@
"dependencies": {
"@metamask/base-controller": "^7.0.1",
"@metamask/controller-utils": "^11.3.0",
"@metamask/eth-sig-util": "^7.0.1",
"@metamask/eth-sig-util": "^8.0.0",
"@metamask/utils": "^9.1.0",
"jsonschema": "^1.2.4",
"lodash": "^4.17.21",
Expand Down
123 changes: 113 additions & 10 deletions packages/signature-controller/src/SignatureController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SIWEMessage } from '@metamask/controller-utils';
import { detectSIWE } from '@metamask/controller-utils';
import { detectSIWE, ORIGIN_METAMASK } from '@metamask/controller-utils';
import { SignTypedDataVersion } from '@metamask/keyring-controller';
import { LogType, SigningStage } from '@metamask/logging-controller';
import { v1 } from 'uuid';
Expand All @@ -11,7 +11,12 @@ import type {
SignatureControllerState,
} from './SignatureController';
import { SignatureController } from './SignatureController';
import type { MessageParamsPersonal, SignatureRequest } from './types';
import type {
MessageParamsPersonal,
MessageParamsTyped,
OriginalRequest,
SignatureRequest,
} from './types';
import { SignatureRequestStatus, SignatureRequestType } from './types';
import {
normalizePersonalMessageParams,
Expand All @@ -34,10 +39,14 @@ const DATA_MOCK = '0xABC123';
const SIGNATURE_HASH_MOCK = '0x123ABC';
const ERROR_MESSAGE_MOCK = 'Test Error Message';
const ERROR_CODE_MOCK = 1234;
const ORIGIN_MOCK = 'testOrigin';

const PARAMS_MOCK = {
from: FROM_MOCK,
data: DATA_MOCK,
from: FROM_MOCK,
metamaskId: ID_MOCK,
origin: ORIGIN_MOCK,
version: SignTypedDataVersion.V1,
};

const SIGNATURE_REQUEST_MOCK: SignatureRequest = {
Expand Down Expand Up @@ -327,15 +336,26 @@ describe('SignatureController', () => {
describe.each([
[
'newUnsignedPersonalMessage',
(controller: SignatureController, request = {}) =>
controller.newUnsignedPersonalMessage({ ...PARAMS_MOCK }, request),
(
controller: SignatureController,
request?: OriginalRequest,
params?: Partial<MessageParamsPersonal>,
) =>
controller.newUnsignedPersonalMessage(
{ ...PARAMS_MOCK, ...params },
request,
),
SignatureRequestType.PersonalSign,
],
[
'newUnsignedTypedMessage',
(controller: SignatureController, request = {}) =>
(
controller: SignatureController,
request?: OriginalRequest,
params?: Partial<MessageParamsTyped>,
) =>
controller.newUnsignedTypedMessage(
PARAMS_MOCK,
{ ...PARAMS_MOCK, ...params },
request,
SignTypedDataVersion.V1,
{ parseJsonData: false },
Expand Down Expand Up @@ -488,7 +508,7 @@ describe('SignatureController', () => {
});
});

it('populates origin from request', async () => {
it('populates origin from request if present', async () => {
const { controller } = createController();

await fn(controller, { origin: 'test' });
Expand All @@ -498,14 +518,34 @@ describe('SignatureController', () => {
).toBe('test');
});

it('populates origin from message params if no request', async () => {
const { controller } = createController();

await fn(controller);

expect(
controller.state.signatureRequests[ID_MOCK].messageParams.origin,
).toBe(ORIGIN_MOCK);
});

it('populates request ID from request', async () => {
const { controller } = createController();

await fn(controller, { id: 'test' });
await fn(controller, { id: 123 });

expect(
controller.state.signatureRequests[ID_MOCK].messageParams.requestId,
).toBe('test');
).toBe(123);
});

it('populates metamask ID using ID', async () => {
const { controller } = createController();

await fn(controller);

expect(
controller.state.signatureRequests[ID_MOCK].messageParams.metamaskId,
).toBe(ID_MOCK);
});

it('emits unapproved message event', async () => {
Expand Down Expand Up @@ -604,6 +644,50 @@ describe('SignatureController', () => {
expect(resultCallbackErrorMock).toHaveBeenCalledTimes(1);
expect(resultCallbackErrorMock).toHaveBeenCalledWith(errorMock);
});

it('requests approval', async () => {
const { controller, approvalControllerAddRequestMock } =
createController();

await fn(controller);

expect(approvalControllerAddRequestMock).toHaveBeenCalledTimes(1);
expect(approvalControllerAddRequestMock).toHaveBeenCalledWith(
{
expectsResult: true,
id: ID_MOCK,
origin: ORIGIN_MOCK,
requestData: expect.objectContaining({
data: PARAMS_MOCK.data,
from: PARAMS_MOCK.from,
}),
type,
},
true,
);
});

it('requests approval with internal origin if no origin provided', async () => {
const { controller, approvalControllerAddRequestMock } =
createController();

await fn(controller, undefined, { origin: undefined });

expect(approvalControllerAddRequestMock).toHaveBeenCalledTimes(1);
expect(approvalControllerAddRequestMock).toHaveBeenCalledWith(
{
expectsResult: true,
id: ID_MOCK,
origin: ORIGIN_METAMASK,
requestData: expect.objectContaining({
data: PARAMS_MOCK.data,
from: PARAMS_MOCK.from,
}),
type,
},
true,
);
});
});

describe('newUnsignedPersonalMessage', () => {
Expand Down Expand Up @@ -685,6 +769,7 @@ describe('SignatureController', () => {
{
...PARAMS_MOCK,
data: { test: 123 },
version,
},
version,
);
Expand Down Expand Up @@ -746,6 +831,24 @@ describe('SignatureController', () => {
ERROR_MESSAGE_MOCK,
);
});

it('populates version in params', async () => {
const { controller } = createController();

await controller.newUnsignedTypedMessage(
PARAMS_MOCK,
{},
SignTypedDataVersion.V3,
{ parseJsonData: false },
);

expect(
(
controller.state.signatureRequests[ID_MOCK]
.messageParams as MessageParamsTyped
).version,
).toBe(SignTypedDataVersion.V3);
});
});

describe('setDeferredSignSuccess', () => {
Expand Down
Loading

0 comments on commit eea9f46

Please sign in to comment.