@metamask/ppom-validator
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -9,2 +9,8 @@ # Changelog | ||
## [0.6.0] | ||
### Changed | ||
- RPC payload fix ([#61](https://github.com/MetaMask/ppom-validator/pull/61)) | ||
- Using old data files for validation until new ones are fetched ([#51](https://github.com/MetaMask/ppom-validator/pull/51)) | ||
- Fix prefixing of hex value on chain id ([#50](https://github.com/MetaMask/ppom-validator/pull/50)) | ||
## [0.5.0] | ||
@@ -53,3 +59,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/ppom-validator/compare/v0.5.0...HEAD | ||
[Unreleased]: https://github.com/MetaMask/ppom-validator/compare/v0.6.0...HEAD | ||
[0.6.0]: https://github.com/MetaMask/ppom-validator/compare/v0.5.0...v0.6.0 | ||
[0.5.0]: https://github.com/MetaMask/ppom-validator/compare/v0.4.0...v0.5.0 | ||
@@ -56,0 +63,0 @@ [0.4.0]: https://github.com/MetaMask/ppom-validator/compare/v0.3.0...v0.4.0 |
@@ -22,2 +22,3 @@ import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller'; | ||
dataFetched: boolean; | ||
versionInfo: PPOMVersionResponse; | ||
}>; | ||
@@ -83,3 +84,3 @@ /** | ||
* @param options.state - Initial state of the controller. | ||
* @param options.blockaidPublicKey - Public key of blcokaid for verifying signatures of data files. | ||
* @param options.blockaidPublicKey - Public key of blockaid for verifying signatures of data files. | ||
* @returns The PPOMController instance. | ||
@@ -86,0 +87,0 @@ */ |
@@ -13,3 +13,3 @@ "use strict"; | ||
}; | ||
var _PPOMController_instances, _PPOMController_ppom, _PPOMController_provider, _PPOMController_storage, _PPOMController_refreshDataInterval, _PPOMController_fileScheduleInterval, _PPOMController_ppomMutex, _PPOMController_ppomProvider, _PPOMController_cdnBaseUrl, _PPOMController_providerRequestLimit, _PPOMController_providerRequests, _PPOMController_chainId, _PPOMController_dataUpdateDuration, _PPOMController_fileFetchScheduleDuration, _PPOMController_securityAlertsEnabled, _PPOMController_blockaidPublicKey, _PPOMController_includesEthereumMainnet, _PPOMController_resetDataFetchIntervals, _PPOMController_onNetworkChange, _PPOMController_onPreferenceChange, _PPOMController_registerMessageHandlers, _PPOMController_resetPPOM, _PPOMController_maybeUpdatePPOM, _PPOMController_isDataRequiredForCurrentChain, _PPOMController_updatePPOM, _PPOMController_updateVersionInfo, _PPOMController_checkFilePresentInStorage, _PPOMController_checkFilePath, _PPOMController_getFile, _PPOMController_setChainIdDataFetched, _PPOMController_getNewFilesForCurrentChain, _PPOMController_getListOfFilesToBeFetched, _PPOMController_deleteOldChainIds, _PPOMController_getNewFilesForAllChains, _PPOMController_getAPIResponse, _PPOMController_checkIfVersionInfoETagChanged, _PPOMController_fetchVersionInfo, _PPOMController_fetchBlob, _PPOMController_jsonRpcRequest, _PPOMController_getPPOM, _PPOMController_onDataUpdateDuration, _PPOMController_checkScheduleFileDownloadForAllChains; | ||
var _PPOMController_instances, _PPOMController_ppom, _PPOMController_provider, _PPOMController_storage, _PPOMController_refreshDataInterval, _PPOMController_fileScheduleInterval, _PPOMController_ppomMutex, _PPOMController_ppomProvider, _PPOMController_cdnBaseUrl, _PPOMController_providerRequestLimit, _PPOMController_providerRequests, _PPOMController_chainId, _PPOMController_dataUpdateDuration, _PPOMController_fileFetchScheduleDuration, _PPOMController_securityAlertsEnabled, _PPOMController_blockaidPublicKey, _PPOMController_chainStatusIncludeSupportedNetworks, _PPOMController_networkIsSupported, _PPOMController_resetDataFetchIntervals, _PPOMController_onNetworkChange, _PPOMController_onPreferenceChange, _PPOMController_registerMessageHandlers, _PPOMController_resetPPOM, _PPOMController_maybeUpdatePPOM, _PPOMController_isDataRequiredForCurrentChain, _PPOMController_updatePPOM, _PPOMController_updateVersionInfo, _PPOMController_checkFilePresentInStorage, _PPOMController_checkFilePath, _PPOMController_getFile, _PPOMController_setChainIdDataFetched, _PPOMController_getNewFilesForCurrentChain, _PPOMController_getListOfFilesToBeFetched, _PPOMController_deleteOldChainIds, _PPOMController_getNewFilesForAllChains, _PPOMController_getAPIResponse, _PPOMController_checkIfVersionInfoETagChanged, _PPOMController_fetchVersionInfo, _PPOMController_fetchBlob, _PPOMController_jsonRpcRequest, _PPOMController_getPPOM, _PPOMController_onDataUpdateDuration, _PPOMController_checkScheduleFileDownloadForAllChains; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -93,6 +93,7 @@ exports.PPOMController = exports.NETWORK_CACHE_DURATION = exports.REFRESH_TIME_INTERVAL = void 0; | ||
* @param options.state - Initial state of the controller. | ||
* @param options.blockaidPublicKey - Public key of blcokaid for verifying signatures of data files. | ||
* @param options.blockaidPublicKey - Public key of blockaid for verifying signatures of data files. | ||
* @returns The PPOMController instance. | ||
*/ | ||
constructor({ chainId, messenger, onNetworkChange, provider, storageBackend, securityAlertsEnabled, onPreferencesChange, ppomProvider, cdnBaseUrl, providerRequestLimit, dataUpdateDuration, fileFetchScheduleDuration, state, blockaidPublicKey, }) { | ||
const currentChainId = (0, util_1.addHexPrefix)(chainId); | ||
const initialState = { | ||
@@ -102,6 +103,7 @@ versionInfo: state?.versionInfo ?? [], | ||
chainStatus: state?.chainStatus ?? { | ||
[chainId]: { | ||
chainId, | ||
[currentChainId]: { | ||
chainId: currentChainId, | ||
lastVisited: new Date().getTime(), | ||
dataFetched: false, | ||
versionInfo: [], | ||
}, | ||
@@ -143,3 +145,3 @@ }, | ||
_PPOMController_blockaidPublicKey.set(this, void 0); | ||
__classPrivateFieldSet(this, _PPOMController_chainId, (0, util_1.addHexPrefix)(chainId), "f"); | ||
__classPrivateFieldSet(this, _PPOMController_chainId, currentChainId, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_provider, provider, "f"); | ||
@@ -184,3 +186,3 @@ __classPrivateFieldSet(this, _PPOMController_ppomProvider, ppomProvider, "f"); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_deleteOldChainIds).call(this); | ||
if (!__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_includesEthereumMainnet).call(this)) { | ||
if (!__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_chainStatusIncludeSupportedNetworks).call(this)) { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetDataFetchIntervals).call(this); | ||
@@ -204,3 +206,3 @@ return; | ||
} | ||
if (__classPrivateFieldGet(this, _PPOMController_chainId, "f") !== ETHEREUM_CHAIN_ID) { | ||
if (!__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_networkIsSupported).call(this, __classPrivateFieldGet(this, _PPOMController_chainId, "f"))) { | ||
throw Error('Blockaid validation is available only on ethereum mainnet'); | ||
@@ -218,5 +220,8 @@ } | ||
exports.PPOMController = PPOMController; | ||
_PPOMController_ppom = new WeakMap(), _PPOMController_provider = new WeakMap(), _PPOMController_storage = new WeakMap(), _PPOMController_refreshDataInterval = new WeakMap(), _PPOMController_fileScheduleInterval = new WeakMap(), _PPOMController_ppomMutex = new WeakMap(), _PPOMController_ppomProvider = new WeakMap(), _PPOMController_cdnBaseUrl = new WeakMap(), _PPOMController_providerRequestLimit = new WeakMap(), _PPOMController_providerRequests = new WeakMap(), _PPOMController_chainId = new WeakMap(), _PPOMController_dataUpdateDuration = new WeakMap(), _PPOMController_fileFetchScheduleDuration = new WeakMap(), _PPOMController_securityAlertsEnabled = new WeakMap(), _PPOMController_blockaidPublicKey = new WeakMap(), _PPOMController_instances = new WeakSet(), _PPOMController_includesEthereumMainnet = function _PPOMController_includesEthereumMainnet() { | ||
_PPOMController_ppom = new WeakMap(), _PPOMController_provider = new WeakMap(), _PPOMController_storage = new WeakMap(), _PPOMController_refreshDataInterval = new WeakMap(), _PPOMController_fileScheduleInterval = new WeakMap(), _PPOMController_ppomMutex = new WeakMap(), _PPOMController_ppomProvider = new WeakMap(), _PPOMController_cdnBaseUrl = new WeakMap(), _PPOMController_providerRequestLimit = new WeakMap(), _PPOMController_providerRequests = new WeakMap(), _PPOMController_chainId = new WeakMap(), _PPOMController_dataUpdateDuration = new WeakMap(), _PPOMController_fileFetchScheduleDuration = new WeakMap(), _PPOMController_securityAlertsEnabled = new WeakMap(), _PPOMController_blockaidPublicKey = new WeakMap(), _PPOMController_instances = new WeakSet(), _PPOMController_chainStatusIncludeSupportedNetworks = function _PPOMController_chainStatusIncludeSupportedNetworks() { | ||
const networkIsSupported = __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_networkIsSupported).bind(this); | ||
return (this.state?.chainStatus && | ||
Object.keys(this.state?.chainStatus)?.some((chainId) => chainId === ETHEREUM_CHAIN_ID)); | ||
Object.keys(this.state?.chainStatus)?.some(networkIsSupported)); | ||
}, _PPOMController_networkIsSupported = function _PPOMController_networkIsSupported(chainId) { | ||
return chainId === ETHEREUM_CHAIN_ID; | ||
}, _PPOMController_resetDataFetchIntervals = function _PPOMController_resetDataFetchIntervals() { | ||
@@ -227,5 +232,2 @@ clearInterval(__classPrivateFieldGet(this, _PPOMController_refreshDataInterval, "f")); | ||
const id = (0, util_1.addHexPrefix)(networkControllerState.providerConfig.chainId); | ||
if (id === __classPrivateFieldGet(this, _PPOMController_chainId, "f")) { | ||
return; | ||
} | ||
let chainStatus = { ...this.state.chainStatus }; | ||
@@ -240,2 +242,3 @@ const existingNetworkObject = chainStatus[id]; | ||
dataFetched: existingNetworkObject?.dataFetched ?? false, | ||
versionInfo: existingNetworkObject?.versionInfo ?? [], | ||
}, | ||
@@ -333,4 +336,5 @@ }; | ||
}, _PPOMController_setChainIdDataFetched = function _PPOMController_setChainIdDataFetched(chainId) { | ||
const { chainStatus } = this.state; | ||
const { chainStatus, versionInfo } = this.state; | ||
const chainIdObject = chainStatus[chainId]; | ||
const versionInfoForChain = versionInfo.filter(({ chainId: id }) => id === chainId); | ||
if (chainIdObject && !chainIdObject.dataFetched) { | ||
@@ -340,3 +344,7 @@ this.update((draftState) => { | ||
...chainStatus, | ||
[chainId]: { ...chainIdObject, dataFetched: true }, | ||
[chainId]: { | ||
...chainIdObject, | ||
dataFetched: true, | ||
versionInfo: versionInfoForChain, | ||
}, | ||
}; | ||
@@ -365,5 +373,8 @@ }); | ||
const { chainStatus, storageMetadata, versionInfo: stateVersionInfo, } = this.state; | ||
const networkIsSupported = __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_networkIsSupported).bind(this); | ||
// create a map of chainId and files belonging to that chainId | ||
// not include the files for which the version in storage is the latest one | ||
const chainIdsFileInfoList = Object.keys(chainStatus).map((chainId) => ({ | ||
const chainIdsFileInfoList = Object.keys(chainStatus) | ||
.filter(networkIsSupported) | ||
.map((chainId) => ({ | ||
chainId, | ||
@@ -551,8 +562,12 @@ versionInfo: stateVersionInfo.filter((versionInfo) => versionInfo.chainId === chainId && | ||
async function _PPOMController_getPPOM() { | ||
const { chainStatus } = this.state; | ||
const chainInfo = chainStatus[__classPrivateFieldGet(this, _PPOMController_chainId, "f")]; | ||
if (!chainInfo?.versionInfo?.length) { | ||
throw new Error(`Aborting validation as no files are found for the network with chainId: ${__classPrivateFieldGet(this, _PPOMController_chainId, "f")}`); | ||
} | ||
// Get all the files for the chainId | ||
let files = await Promise.all(this.state.versionInfo | ||
.filter((file) => file.chainId === __classPrivateFieldGet(this, _PPOMController_chainId, "f")) | ||
.map(async (file) => { | ||
let files = await Promise.all(chainInfo.versionInfo.map(async (file) => { | ||
let data; | ||
try { | ||
// First try to get file from storage | ||
data = await __classPrivateFieldGet(this, _PPOMController_storage, "f").readFile(file.name, file.chainId); | ||
@@ -562,2 +577,3 @@ } | ||
try { | ||
// Get the file from CDN if it is not found in storage | ||
data = await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getFile).call(this, file, true); | ||
@@ -590,3 +606,4 @@ } | ||
}, _PPOMController_checkScheduleFileDownloadForAllChains = function _PPOMController_checkScheduleFileDownloadForAllChains() { | ||
if (__classPrivateFieldGet(this, _PPOMController_securityAlertsEnabled, "f") && __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_includesEthereumMainnet).call(this)) { | ||
if (__classPrivateFieldGet(this, _PPOMController_securityAlertsEnabled, "f") && | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_chainStatusIncludeSupportedNetworks).call(this)) { | ||
if (!__classPrivateFieldGet(this, _PPOMController_refreshDataInterval, "f")) { | ||
@@ -593,0 +610,0 @@ __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_onDataUpdateDuration).call(this); |
@@ -16,3 +16,3 @@ "use strict"; | ||
method, | ||
params: params || {}, | ||
params: params || [], | ||
}); | ||
@@ -19,0 +19,0 @@ exports.createPayload = createPayload; |
{ | ||
"name": "@metamask/ppom-validator", | ||
"version": "0.5.0", | ||
"version": "0.6.0", | ||
"description": "This module has code to integrate Blockaid PPOM with MetaMask", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/MetaMask/ppom-validator#readme", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
125419
1078