mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
[MMI] Added code fencing in libs folder (#17929)
This commit is contained in:
parent
4f8c4820d2
commit
9195057136
@ -7,6 +7,16 @@ import sendMetadata from './send-metadata';
|
||||
import switchEthereumChain from './switch-ethereum-chain';
|
||||
import watchAsset from './watch-asset';
|
||||
|
||||
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
||||
import mmiSupported from './institutional/mmi-supported';
|
||||
import mmiAuthenticate from './institutional/mmi-authenticate';
|
||||
import mmiPortfolio from './institutional/mmi-portfolio';
|
||||
import mmiOpenSwaps from './institutional/mmi-open-swaps';
|
||||
import mmiCheckIfTokenIsPresent from './institutional/mmi-check-if-token-is-present';
|
||||
import mmiSetAccountAndNetwork from './institutional/mmi-set-account-and-network';
|
||||
import mmiOpenAddHardwareWallet from './institutional/mmi-open-add-hardware-wallet';
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
|
||||
const handlers = [
|
||||
addEthereumChain,
|
||||
ethAccounts,
|
||||
@ -16,5 +26,14 @@ const handlers = [
|
||||
sendMetadata,
|
||||
switchEthereumChain,
|
||||
watchAsset,
|
||||
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
||||
mmiAuthenticate,
|
||||
mmiSupported,
|
||||
mmiPortfolio,
|
||||
mmiOpenSwaps,
|
||||
mmiCheckIfTokenIsPresent,
|
||||
mmiSetAccountAndNetwork,
|
||||
mmiOpenAddHardwareWallet,
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
];
|
||||
export default handlers;
|
||||
|
@ -0,0 +1,43 @@
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiAuthenticate = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_AUTHENTICATE, MESSAGE_TYPE.MMI_REAUTHENTICATE],
|
||||
implementation: mmiAuthenticateHandler,
|
||||
hookNames: {
|
||||
handleMmiAuthenticate: true,
|
||||
},
|
||||
};
|
||||
export default mmiAuthenticate;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiAuthenticateOptions
|
||||
* @property {Function} handleWatchAssetRequest - The wallet_watchAsset method implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiAuthenticateParam
|
||||
* @property {string} service - The service to which we are authenticating, e.g. 'codefi-compliance'
|
||||
* @property {object} token - The token used to authenticate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest<WatchAssetParam>} req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
* @param {WatchAssetOptions} options
|
||||
*/
|
||||
async function mmiAuthenticateHandler(
|
||||
req,
|
||||
res,
|
||||
_next,
|
||||
end,
|
||||
{ handleMmiAuthenticate },
|
||||
) {
|
||||
try {
|
||||
res.result = await handleMmiAuthenticate(req);
|
||||
return end();
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiAuthenticate = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_CHECK_IF_TOKEN_IS_PRESENT],
|
||||
implementation: mmiCheckIfTokenIsPresentHandler,
|
||||
hookNames: {
|
||||
handleMmiCheckIfTokenIsPresent: true,
|
||||
},
|
||||
};
|
||||
export default mmiAuthenticate;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiAuthenticateOptions
|
||||
* @property {Function} handleMmiCheckIfTokenIsPresent - The metamaskinstitutional_checkIfTokenIsPresent method implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiCheckIfTokenIsPresentParam
|
||||
* @property {string} service - The service to which we are authenticating, e.g. 'codefi-compliance'
|
||||
* @property {object} environment - The environment in which we are authenticating, e.g. 'saturn-dev'
|
||||
* @property {apiUrl} apiUrl - The API URL to which we are authenticating, e.g. 'https://saturn-custody.codefi.network/eth'
|
||||
* @property {object} token - The token used to authenticate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest<MmiCheckIfTokenIsPresentParam>} req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
* @param options0
|
||||
* @param options0.handleMmiCheckIfTokenIsPresent
|
||||
*/
|
||||
async function mmiCheckIfTokenIsPresentHandler(
|
||||
req,
|
||||
res,
|
||||
_next,
|
||||
end,
|
||||
{ handleMmiCheckIfTokenIsPresent },
|
||||
) {
|
||||
try {
|
||||
res.result = await handleMmiCheckIfTokenIsPresent(req);
|
||||
return end();
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
import { RPC_ALLOWED_ORIGINS } from '@metamask-institutional/rpc-allowlist';
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiOpenAddHardwareWallet = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_OPEN_ADD_HARDWARE_WALLET],
|
||||
implementation: mmiOpenAddHardwareWalletHandler,
|
||||
hookNames: {
|
||||
handleMmiOpenAddHardwareWallet: true,
|
||||
},
|
||||
};
|
||||
export default mmiOpenAddHardwareWallet;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiOpenAddHardwareWalletOptions
|
||||
* @property {Function} handleMmiOpenAddHardwareWallet - The metmaskinsititutional_openAddHardwareWallet method implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest} req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
* @param {WatchAssetOptions} options
|
||||
*/
|
||||
async function mmiOpenAddHardwareWalletHandler(
|
||||
req,
|
||||
res,
|
||||
_next,
|
||||
end,
|
||||
{ handleMmiOpenAddHardwareWallet },
|
||||
) {
|
||||
try {
|
||||
let validUrl = false;
|
||||
// if (!RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].includes(req.origin)) {
|
||||
RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].forEach((regexp) => {
|
||||
// eslint-disable-next-line require-unicode-regexp
|
||||
if (regexp.test(req.origin)) {
|
||||
validUrl = true;
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-negated-condition
|
||||
if (!validUrl) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
res.result = await handleMmiOpenAddHardwareWallet();
|
||||
return end();
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
import { ethErrors } from 'eth-rpc-errors';
|
||||
import { RPC_ALLOWED_ORIGINS } from '@metamask-institutional/rpc-allowlist';
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiOpenSwaps = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_OPEN_SWAPS],
|
||||
implementation: mmiOpenSwapsHandler,
|
||||
hookNames: {
|
||||
handleMmiOpenSwaps: true,
|
||||
},
|
||||
};
|
||||
export default mmiOpenSwaps;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiOpenSwapsOptions
|
||||
* @property {Function} handleMmiOpenSwaps - The metmaskinsititutional_open_swaps method implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiOpenSwapsParam
|
||||
* @property {string} service - The service to which we are authenticating, e.g. 'codefi-compliance'
|
||||
* @property {object} token - The token used to authenticate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest<MmiOpenSwapsParam>} req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
* @param {WatchAssetOptions} options
|
||||
*/
|
||||
async function mmiOpenSwapsHandler(
|
||||
req,
|
||||
res,
|
||||
_next,
|
||||
end,
|
||||
{ handleMmiOpenSwaps },
|
||||
) {
|
||||
try {
|
||||
let validUrl = false;
|
||||
// if (!RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].includes(req.origin)) {
|
||||
RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].forEach((regexp) => {
|
||||
// eslint-disable-next-line require-unicode-regexp
|
||||
if (regexp.test(req.origin)) {
|
||||
validUrl = true;
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-negated-condition
|
||||
if (!validUrl) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
if (!req.params?.[0] || typeof req.params[0] !== 'object') {
|
||||
return end(
|
||||
ethErrors.rpc.invalidParams({
|
||||
message: `Expected single, object parameter. Received:\n${JSON.stringify(
|
||||
req.params,
|
||||
)}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
const { address, network } = req.params[0];
|
||||
res.result = await handleMmiOpenSwaps(req.origin, address, network);
|
||||
return end();
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
import { RPC_ALLOWED_ORIGINS } from '@metamask-institutional/rpc-allowlist';
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiPortfolio = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_PORTFOLIO],
|
||||
implementation: mmiPortfolioHandler,
|
||||
hookNames: {
|
||||
handleMmiPortfolio: true,
|
||||
},
|
||||
};
|
||||
export default mmiPortfolio;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiPortfolioOptions
|
||||
* @property {Function} handleMmiportfolio - The metmaskinsititutional_portfolio method implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiPortfolioParam
|
||||
* @property {string} service - The service to which we are authenticating, e.g. 'codefi-compliance'
|
||||
* @property {object} token - The token used to authenticate
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest<MmiPortfolioParam>} req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
* @param {WatchAssetOptions} options
|
||||
*/
|
||||
async function mmiPortfolioHandler(
|
||||
req,
|
||||
res,
|
||||
_next,
|
||||
end,
|
||||
{ handleMmiPortfolio },
|
||||
) {
|
||||
try {
|
||||
let validUrl = false;
|
||||
RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].forEach((regexp) => {
|
||||
// eslint-disable-next-line require-unicode-regexp
|
||||
if (regexp.test(req.origin)) {
|
||||
validUrl = true;
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-negated-condition
|
||||
if (!validUrl) {
|
||||
throw new Error('Unauthorized');
|
||||
} else {
|
||||
res.result = await handleMmiPortfolio(req);
|
||||
return end();
|
||||
}
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
import { ethErrors } from 'eth-rpc-errors';
|
||||
import { RPC_ALLOWED_ORIGINS } from '@metamask-institutional/rpc-allowlist';
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiSetAccountAndNetwork = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_SET_ACCOUNT_AND_NETWORK],
|
||||
implementation: mmiSetAccountAndNetworkHandler,
|
||||
hookNames: {
|
||||
handleMmiSetAccountAndNetwork: true,
|
||||
},
|
||||
};
|
||||
export default mmiSetAccountAndNetwork;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiSetAccountAndNetworkOptions
|
||||
* @property {Function} handleMmiSetAccountAndNetwork - The metmaskinsititutional_set_account_and_network method implementation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiSetAccountAndNetworkParam
|
||||
* @property {string} account - Account address
|
||||
* @property {number} network - Chain Id
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest<MmiSetAccountAndNetworkParam>} req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
* @param {WatchAssetOptions} options
|
||||
*/
|
||||
async function mmiSetAccountAndNetworkHandler(
|
||||
req,
|
||||
res,
|
||||
_next,
|
||||
end,
|
||||
{ handleMmiSetAccountAndNetwork },
|
||||
) {
|
||||
try {
|
||||
let validUrl = false;
|
||||
RPC_ALLOWED_ORIGINS[MESSAGE_TYPE.MMI_PORTFOLIO].forEach((regexp) => {
|
||||
// eslint-disable-next-line require-unicode-regexp
|
||||
if (regexp.test(req.origin)) {
|
||||
validUrl = true;
|
||||
}
|
||||
});
|
||||
// eslint-disable-next-line no-negated-condition
|
||||
if (!validUrl) {
|
||||
throw new Error('Unauthorized');
|
||||
}
|
||||
|
||||
if (!req.params?.[0] || typeof req.params[0] !== 'object') {
|
||||
return end(
|
||||
ethErrors.rpc.invalidParams({
|
||||
message: `Expected single, object parameter. Received:\n${JSON.stringify(
|
||||
req.params,
|
||||
)}`,
|
||||
}),
|
||||
);
|
||||
}
|
||||
const { address, network } = req.params[0];
|
||||
res.result = await handleMmiSetAccountAndNetwork(
|
||||
req.origin,
|
||||
address,
|
||||
network,
|
||||
);
|
||||
return end();
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
import { MESSAGE_TYPE } from '../../../../../../shared/constants/app';
|
||||
|
||||
const mmiSupported = {
|
||||
methodNames: [MESSAGE_TYPE.MMI_SUPPORTED],
|
||||
implementation: mmiSupportedHandler,
|
||||
hookNames: {},
|
||||
};
|
||||
export default mmiSupported;
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiAuthenticateOptions
|
||||
* @property {Function} mmiSupportedHandler
|
||||
* This method simply returns true if this is Metamask Institutional
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} MmiSupportedParam
|
||||
* @property {string} mmiSupported No parameters
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {import('json-rpc-engine').JsonRpcRequest<WatchAssetParam>} _req - The JSON-RPC request object.
|
||||
* @param {import('json-rpc-engine').JsonRpcResponse<true>} res - The JSON-RPC response object.
|
||||
* @param {Function} _next - The json-rpc-engine 'next' callback.
|
||||
* @param {Function} end - The json-rpc-engine 'end' callback.
|
||||
*/
|
||||
async function mmiSupportedHandler(_req, res, _next, end) {
|
||||
try {
|
||||
res.result = true;
|
||||
return end();
|
||||
} catch (error) {
|
||||
return end(error);
|
||||
}
|
||||
}
|
@ -223,6 +223,7 @@
|
||||
"@metamask-institutional/extension": "^0.1.3",
|
||||
"@metamask-institutional/institutional-features": "^1.1.8",
|
||||
"@metamask-institutional/portfolio-dashboard": "^1.1.3",
|
||||
"@metamask-institutional/rpc-allowlist": "^1.0.0",
|
||||
"@metamask-institutional/sdk": "^0.1.17",
|
||||
"@metamask-institutional/transaction-update": "^0.1.21",
|
||||
"@metamask/address-book-controller": "^3.0.0",
|
||||
|
@ -209,7 +209,18 @@ export default class InfoTab extends PureComponent {
|
||||
ref={this.settingsRefs[0]}
|
||||
className="info-tab__version-header"
|
||||
>
|
||||
{isBeta() ? t('betaMetamaskVersion') : t('metamaskVersion')}
|
||||
{
|
||||
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-flask)
|
||||
isBeta() ? t('betaMetamaskVersion') : t('metamaskVersion')
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
}
|
||||
{
|
||||
///: BEGIN:ONLY_INCLUDE_IN(build-mmi)
|
||||
isBeta()
|
||||
? t('betaMetamaskInstitutionalVersion')
|
||||
: t('metamaskInstitutionalVersion')
|
||||
///: END:ONLY_INCLUDE_IN
|
||||
}
|
||||
</div>
|
||||
<div className="info-tab__version-number">
|
||||
{this.state.version}
|
||||
|
@ -3769,6 +3769,13 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@metamask-institutional/rpc-allowlist@npm:^1.0.0":
|
||||
version: 1.0.0
|
||||
resolution: "@metamask-institutional/rpc-allowlist@npm:1.0.0"
|
||||
checksum: c1c15822271b56fc5aeb2b86ed2bebd8a158cd3d3bbdda3c4beb2c6e5edf12df61e5e458e7b80482e41e28d93986b516124ee887529e3c311e8bc358fb577428
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"@metamask-institutional/sdk@npm:^0.1.14, @metamask-institutional/sdk@npm:^0.1.15, @metamask-institutional/sdk@npm:^0.1.16, @metamask-institutional/sdk@npm:^0.1.17":
|
||||
version: 0.1.17
|
||||
resolution: "@metamask-institutional/sdk@npm:0.1.17"
|
||||
@ -23922,6 +23929,7 @@ __metadata:
|
||||
"@metamask-institutional/extension": ^0.1.3
|
||||
"@metamask-institutional/institutional-features": ^1.1.8
|
||||
"@metamask-institutional/portfolio-dashboard": ^1.1.3
|
||||
"@metamask-institutional/rpc-allowlist": ^1.0.0
|
||||
"@metamask-institutional/sdk": ^0.1.17
|
||||
"@metamask-institutional/transaction-update": ^0.1.21
|
||||
"@metamask/address-book-controller": ^3.0.0
|
||||
|
Loading…
Reference in New Issue
Block a user