Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZK Deterministic Signature RPC method (Plume) #17482

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 41 additions & 42 deletions .storybook/initial-states/transactions.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/_locales/en/messages.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ browser.runtime.onConnectExternal.addListener(async (...args) => {
* @property {number} unapprovedEncryptionPublicKeyMsgCount - The number of messages in EncryptionPublicKeyMsgs.
* @property {object} unapprovedDecryptMsgs - An object of messages pending approval, mapping a unique ID to the options.
* @property {number} unapprovedDecryptMsgCount - The number of messages in unapprovedDecryptMsgs.
* @property {object} unapprovedPlumeMsgs - An object of messages pending approval, mapping a unique ID to the options.
* @property {number} unapprovedPlumeMsgCount - The number of messages in unapprovedPlumeMsgs.
* @property {object} unapprovedTypedMsgs - An object of messages pending approval, mapping a unique ID to the options.
* @property {number} unapprovedTypedMsgCount - The number of messages in unapprovedTypedMsgs.
* @property {number} pendingApprovalCount - The number of pending request in the approval controller.
Expand Down Expand Up @@ -672,6 +674,10 @@ export function setupController(initState, initLangCode, overrides) {
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
updateBadge,
);
controller.plumeSignatureManager.on(
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
updateBadge,
);
controller.typedMessageManager.on(
METAMASK_CONTROLLER_EVENTS.UPDATE_BADGE,
updateBadge,
Expand Down Expand Up @@ -713,6 +719,7 @@ export function setupController(initState, initLangCode, overrides) {
const { unapprovedDecryptMsgCount } = controller.decryptMessageManager;
const { unapprovedEncryptionPublicKeyMsgCount } =
controller.encryptionPublicKeyManager;
const { unapprovedPlumeMsgCount } = controller.plumeSignatureManager;
const { unapprovedTypedMessagesCount } = controller.typedMessageManager;
const pendingApprovalCount =
controller.approvalController.getTotalApprovalCount();
Expand All @@ -724,6 +731,7 @@ export function setupController(initState, initLangCode, overrides) {
unapprovedPersonalMsgCount +
unapprovedDecryptMsgCount +
unapprovedEncryptionPublicKeyMsgCount +
unapprovedPlumeMsgCount +
unapprovedTypedMessagesCount +
pendingApprovalCount +
waitingForUnlockCount
Expand Down Expand Up @@ -787,6 +795,14 @@ export function setupController(initState, initLangCode, overrides) {
REJECT_NOTFICIATION_CLOSE,
),
);
controller.plumeSignatureManager.messages
.filter((msg) => msg.status === 'unapproved')
.forEach((tx) =>
controller.plumeSignatureManager.rejectMsg(
tx.id,
REJECT_NOTFICIATION_CLOSE,
),
);

// Finally, resolve snap dialog approvals on Flask and reject all the others managed by the ApprovalController.
Object.values(controller.approvalController.state.pendingApprovals).forEach(
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/permissions/specifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export const unrestrictedMethods = Object.freeze([
'eth_getFilterChanges',
'eth_getFilterLogs',
'eth_getLogs',
'eth_getPlumeSignature',
'eth_getProof',
'eth_getStorageAt',
'eth_getTransactionByBlockHashAndIndex',
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/lib/createMetamaskMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createPendingNonceMiddleware,
createPendingTxMiddleware,
} from './middleware/pending';
import { createGetPlumeSignatureMiddleware } from './middleware/plume';

export default function createMetamaskMiddleware({
version,
Expand All @@ -16,6 +17,7 @@ export default function createMetamaskMiddleware({
processPersonalMessage,
processDecryptMessage,
processEncryptionPublicKey,
processGetPlumeSignature,
getPendingNonce,
getPendingTransactionByHash,
}) {
Expand All @@ -37,6 +39,7 @@ export default function createMetamaskMiddleware({
}),
createPendingNonceMiddleware({ getPendingNonce }),
createPendingTxMiddleware({ getPendingTransactionByHash }),
createGetPlumeSignatureMiddleware({ processGetPlumeSignature }),
]);
return metamaskMiddleware;
}
11 changes: 11 additions & 0 deletions app/scripts/lib/createRPCMethodTrackingMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const RATE_LIMIT_MAP = {
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V3]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V4]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_GET_PLUME_SIGNATURE]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.PERSONAL_SIGN]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_DECRYPT]: RATE_LIMIT_TYPES.NON_RATE_LIMITED,
[MESSAGE_TYPE.ETH_GET_ENCRYPTION_PUBLIC_KEY]:
Expand Down Expand Up @@ -59,6 +60,11 @@ const EVENT_NAME_MAP = {
REJECTED: EVENT_NAMES.SIGNATURE_REJECTED,
REQUESTED: EVENT_NAMES.SIGNATURE_REQUESTED,
},
[MESSAGE_TYPE.ETH_GET_PLUME_SIGNATURE]: {
APPROVED: EVENT_NAMES.SIGNATURE_APPROVED,
REJECTED: EVENT_NAMES.SIGNATURE_REJECTED,
REQUESTED: EVENT_NAMES.SIGNATURE_REQUESTED,
},
[MESSAGE_TYPE.ETH_SIGN_TYPED_DATA_V4]: {
APPROVED: EVENT_NAMES.SIGNATURE_APPROVED,
REJECTED: EVENT_NAMES.SIGNATURE_REJECTED,
Expand All @@ -79,6 +85,11 @@ const EVENT_NAME_MAP = {
REJECTED: EVENT_NAMES.ENCRYPTION_PUBLIC_KEY_REJECTED,
REQUESTED: EVENT_NAMES.ENCRYPTION_PUBLIC_KEY_REQUESTED,
},
[MESSAGE_TYPE.ETH_GET_PLUME_SIGNATURE]: {
APPROVED: EVENT_NAMES.PLUME_APPROVED,
REJECTED: EVENT_NAMES.PLUME_REJECTED,
REQUESTED: EVENT_NAMES.PLUME_REQUESTED,
},
[MESSAGE_TYPE.ETH_REQUEST_ACCOUNTS]: {
APPROVED: EVENT_NAMES.PERMISSIONS_APPROVED,
REJECTED: EVENT_NAMES.PERMISSIONS_REJECTED,
Expand Down
21 changes: 21 additions & 0 deletions app/scripts/lib/middleware/plume.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// TODO: Plan to deprecate this file once `processGetPlumeSignature` is added to eth-json-rpc-middleware
// https://github.com/MetaMask/eth-json-rpc-middleware/pull/198
import { ethErrors } from 'eth-rpc-errors';
import { createAsyncMiddleware } from 'json-rpc-engine';

export function createGetPlumeSignatureMiddleware({
processGetPlumeSignature,
}) {
return createAsyncMiddleware(async (req, res, next) => {
if (!processGetPlumeSignature) {
throw ethErrors.rpc.methodNotSupported();
}
const { method, params } = req;
if (method !== 'eth_getPlumeSignature') {
next();
return;
}
const [data, from] = params;
res.result = await processGetPlumeSignature({ data, from }, req);
});
}
Loading