@metamask/ppom-validator
Advanced tools
Comparing version 0.8.0 to 0.9.0
@@ -9,2 +9,7 @@ # Changelog | ||
## [0.9.0] | ||
### Changed | ||
- Performance Improvement: async instantation of PPOM instance by passing data files ([#77](https://github.com/MetaMask/ppom-validator/pull/77)) | ||
- Performance Improvement: async initialization on ppom padding wasm file after PPOMController is constructed ([#73](https://github.com/MetaMask/ppom-validator/pull/73)) | ||
## [0.8.0] | ||
@@ -69,3 +74,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/ppom-validator/compare/v0.8.0...HEAD | ||
[Unreleased]: https://github.com/MetaMask/ppom-validator/compare/v0.9.0...HEAD | ||
[0.9.0]: https://github.com/MetaMask/ppom-validator/compare/v0.8.0...v0.9.0 | ||
[0.8.0]: https://github.com/MetaMask/ppom-validator/compare/v0.7.0...v0.8.0 | ||
@@ -72,0 +78,0 @@ [0.7.0]: https://github.com/MetaMask/ppom-validator/compare/v0.6.0...v0.7.0 |
@@ -18,3 +18,3 @@ import { BaseControllerV2, RestrictedControllerMessenger } from '@metamask/base-controller'; | ||
declare type PPOMVersionResponse = PPOMFileVersion[]; | ||
declare type ChainType = Record<string, { | ||
declare type ChainInfo = { | ||
chainId: string; | ||
@@ -24,3 +24,4 @@ lastVisited: number; | ||
versionInfo: PPOMVersionResponse; | ||
}>; | ||
}; | ||
declare type ChainType = Record<string, ChainInfo>; | ||
/** | ||
@@ -106,3 +107,2 @@ * @type PPOMState | ||
* Update the PPOM. | ||
* This function will acquire mutex lock and invoke internal method #updatePPOM. | ||
*/ | ||
@@ -113,3 +113,2 @@ updatePPOM(): Promise<void>; | ||
* This function receives a callback that will be called with the PPOM. | ||
* The callback will be called with the PPOM after it has been initialized. | ||
* | ||
@@ -116,0 +115,0 @@ * @param callback - Callback to be invoked with PPOM. |
@@ -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_providerRequestsCount, _PPOMController_blockaidPublicKey, _PPOMController_ppomInitialised, _PPOMController_chainStatusIncludeSupportedNetworks, _PPOMController_networkIsSupported, _PPOMController_resetDataFetchIntervals, _PPOMController_onNetworkChange, _PPOMController_onPreferenceChange, _PPOMController_registerMessageHandlers, _PPOMController_resetPPOM, _PPOMController_downloadNetworkFilesIfRequired, _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_ppomInitError, _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_providerRequestsCount, _PPOMController_blockaidPublicKey, _PPOMController_ppomInitialised, _PPOMController_initialisePPOM, _PPOMController_chainStatusIncludeSupportedNetworks, _PPOMController_networkIsSupported, _PPOMController_clearDataFetchIntervals, _PPOMController_resetToInactiveState, _PPOMController_onNetworkChange, _PPOMController_onPreferenceChange, _PPOMController_registerMessageHandlers, _PPOMController_resetPPOM, _PPOMController_reinitPPOM, _PPOMController_reinitPPOMForNetworkIfRequired, _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 }); | ||
@@ -118,2 +118,3 @@ exports.PPOMController = exports.NETWORK_CACHE_DURATION = exports.REFRESH_TIME_INTERVAL = void 0; | ||
_PPOMController_ppom.set(this, void 0); | ||
_PPOMController_ppomInitError.set(this, void 0); | ||
_PPOMController_provider.set(this, void 0); | ||
@@ -165,3 +166,5 @@ _PPOMController_storage.set(this, void 0); | ||
__classPrivateFieldSet(this, _PPOMController_dataUpdateDuration, dataUpdateDuration ?? exports.REFRESH_TIME_INTERVAL, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_fileFetchScheduleDuration, fileFetchScheduleDuration ?? FILE_FETCH_SCHEDULE_INTERVAL, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_fileFetchScheduleDuration, fileFetchScheduleDuration === undefined | ||
? FILE_FETCH_SCHEDULE_INTERVAL | ||
: fileFetchScheduleDuration, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_securityAlertsEnabled, securityAlertsEnabled, "f"); | ||
@@ -177,6 +180,8 @@ __classPrivateFieldSet(this, _PPOMController_blockaidPublicKey, blockaidPublicKey, "f"); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkScheduleFileDownloadForAllChains).call(this); | ||
// Async initialisation of PPOM as soon as controller is constructed and not when transactions are received | ||
// This helps to reduce the delay in validating transactions. | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_initialisePPOM).call(this); | ||
} | ||
/** | ||
* Update the PPOM. | ||
* This function will acquire mutex lock and invoke internal method #updatePPOM. | ||
*/ | ||
@@ -189,9 +194,9 @@ async updatePPOM() { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_deleteOldChainIds).call(this); | ||
// If none of the networks in chainStatus are supported we stop fetching data files | ||
// and inactivate functionality by reseting PPOM | ||
if (!__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_chainStatusIncludeSupportedNetworks).call(this)) { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetDataFetchIntervals).call(this); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetToInactiveState).call(this); | ||
return; | ||
} | ||
await __classPrivateFieldGet(this, _PPOMController_ppomMutex, "f").use(async () => { | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_updatePPOM).call(this); | ||
}); | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_updatePPOM).call(this); | ||
} | ||
@@ -201,3 +206,2 @@ /** | ||
* This function receives a callback that will be called with the PPOM. | ||
* The callback will be called with the PPOM after it has been initialized. | ||
* | ||
@@ -213,13 +217,9 @@ * @param callback - Callback to be invoked with PPOM. | ||
} | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_reinitPPOMForNetworkIfRequired).call(this); | ||
if (__classPrivateFieldGet(this, _PPOMController_ppomInitError, "f")) { | ||
throw new Error(__classPrivateFieldGet(this, _PPOMController_ppomInitError, "f")); | ||
} | ||
__classPrivateFieldSet(this, _PPOMController_providerRequests, 0, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_providerRequestsCount, {}, "f"); | ||
return await __classPrivateFieldGet(this, _PPOMController_ppomMutex, "f").use(async () => { | ||
if (!__classPrivateFieldGet(this, _PPOMController_ppomInitialised, "f")) { | ||
const { ppomInit } = __classPrivateFieldGet(this, _PPOMController_ppomProvider, "f"); | ||
await ppomInit('./ppom_bg.wasm'); | ||
__classPrivateFieldSet(this, _PPOMController_ppomInitialised, true, "f"); | ||
} | ||
if (!__classPrivateFieldGet(this, _PPOMController_ppom, "f")) { | ||
__classPrivateFieldSet(this, _PPOMController_ppom, await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getPPOM).call(this), "f"); | ||
} | ||
__classPrivateFieldSet(this, _PPOMController_providerRequests, 0, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_providerRequestsCount, {}, "f"); | ||
const result = await callback(__classPrivateFieldGet(this, _PPOMController_ppom, "f")); | ||
@@ -236,3 +236,15 @@ return { | ||
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_providerRequestsCount = new WeakMap(), _PPOMController_blockaidPublicKey = new WeakMap(), _PPOMController_ppomInitialised = new WeakMap(), _PPOMController_instances = new WeakSet(), _PPOMController_chainStatusIncludeSupportedNetworks = function _PPOMController_chainStatusIncludeSupportedNetworks() { | ||
_PPOMController_ppom = new WeakMap(), _PPOMController_ppomInitError = 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_providerRequestsCount = new WeakMap(), _PPOMController_blockaidPublicKey = new WeakMap(), _PPOMController_ppomInitialised = new WeakMap(), _PPOMController_instances = new WeakSet(), _PPOMController_initialisePPOM = function _PPOMController_initialisePPOM() { | ||
if (__classPrivateFieldGet(this, _PPOMController_securityAlertsEnabled, "f") && !__classPrivateFieldGet(this, _PPOMController_ppomInitialised, "f")) { | ||
__classPrivateFieldGet(this, _PPOMController_ppomMutex, "f") | ||
.use(async () => { | ||
const { ppomInit } = __classPrivateFieldGet(this, _PPOMController_ppomProvider, "f"); | ||
await ppomInit('./ppom_bg.wasm'); | ||
__classPrivateFieldSet(this, _PPOMController_ppomInitialised, true, "f"); | ||
}) | ||
.catch(() => { | ||
console.error('Error in trying to initialize PPOM'); | ||
}); | ||
} | ||
}, _PPOMController_chainStatusIncludeSupportedNetworks = function _PPOMController_chainStatusIncludeSupportedNetworks() { | ||
const networkIsSupported = __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_networkIsSupported).bind(this); | ||
@@ -243,5 +255,28 @@ return (this.state?.chainStatus && | ||
return chainId === ETHEREUM_CHAIN_ID; | ||
}, _PPOMController_resetDataFetchIntervals = function _PPOMController_resetDataFetchIntervals() { | ||
}, _PPOMController_clearDataFetchIntervals = function _PPOMController_clearDataFetchIntervals() { | ||
clearInterval(__classPrivateFieldGet(this, _PPOMController_refreshDataInterval, "f")); | ||
clearInterval(__classPrivateFieldGet(this, _PPOMController_fileScheduleInterval, "f")); | ||
__classPrivateFieldSet(this, _PPOMController_refreshDataInterval, undefined, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_fileScheduleInterval, undefined, "f"); | ||
}, _PPOMController_resetToInactiveState = function _PPOMController_resetToInactiveState() { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetPPOM).call(this); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_clearDataFetchIntervals).call(this); | ||
this.update((draftState) => { | ||
draftState.versionInfo = []; | ||
const newChainStatus = { ...this.state.chainStatus }; | ||
Object.keys(newChainStatus).forEach((chainId) => { | ||
if (newChainStatus[chainId]) { | ||
const chainInfo = { | ||
...newChainStatus[chainId], | ||
dataFetched: false, | ||
versionInfo: [], | ||
}; | ||
newChainStatus[chainId] = chainInfo; | ||
} | ||
}); | ||
draftState.chainStatus = newChainStatus; | ||
draftState.storageMetadata = []; | ||
draftState.versionFileETag = ''; | ||
}); | ||
// todo: as we move data files to controller storage we should also delete those here | ||
}, _PPOMController_onNetworkChange = function _PPOMController_onNetworkChange(networkControllerState) { | ||
@@ -251,2 +286,3 @@ const id = (0, util_1.addHexPrefix)(networkControllerState.providerConfig.chainId); | ||
const existingNetworkObject = chainStatus[id]; | ||
const oldChainId = __classPrivateFieldGet(this, _PPOMController_chainId, "f"); | ||
__classPrivateFieldSet(this, _PPOMController_chainId, id, "f"); | ||
@@ -267,3 +303,12 @@ chainStatus = { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkScheduleFileDownloadForAllChains).call(this); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetPPOM).call(this); | ||
if (oldChainId !== id) { | ||
if (chainStatus[id]?.dataFetched) { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_reinitPPOM).call(this).catch(() => { | ||
console.error('Error in re-init of PPOM'); | ||
}); | ||
} | ||
else { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetPPOM).call(this); | ||
} | ||
} | ||
}, _PPOMController_onPreferenceChange = function _PPOMController_onPreferenceChange(preferenceControllerState) { | ||
@@ -275,3 +320,9 @@ const blockaidEnabled = preferenceControllerState.securityAlertsEnabled; | ||
__classPrivateFieldSet(this, _PPOMController_securityAlertsEnabled, blockaidEnabled, "f"); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkScheduleFileDownloadForAllChains).call(this); | ||
if (blockaidEnabled) { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_initialisePPOM).call(this); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkScheduleFileDownloadForAllChains).call(this); | ||
} | ||
else { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetToInactiveState).call(this); | ||
} | ||
}, _PPOMController_registerMessageHandlers = function _PPOMController_registerMessageHandlers() { | ||
@@ -285,10 +336,17 @@ this.messagingSystem.registerActionHandler(`${controllerName}:usePPOM`, this.usePPOM.bind(this)); | ||
} | ||
}, _PPOMController_downloadNetworkFilesIfRequired = | ||
}, _PPOMController_reinitPPOM = | ||
/* | ||
* The function initialises PPOM. | ||
*/ | ||
async function _PPOMController_reinitPPOM() { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetPPOM).call(this); | ||
__classPrivateFieldSet(this, _PPOMController_ppom, await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getPPOM).call(this), "f"); | ||
}, _PPOMController_reinitPPOMForNetworkIfRequired = | ||
/** | ||
* Conditionally update the ppom configuration. | ||
* | ||
* If the ppom configuration is out of date, this function will call `updatePPOM` | ||
* to update the configuration. | ||
* The function will check if files are required to be downloaded and | ||
* if needed will re-initialise PPOM passing new network files to it. | ||
*/ | ||
async function _PPOMController_downloadNetworkFilesIfRequired() { | ||
async function _PPOMController_reinitPPOMForNetworkIfRequired() { | ||
if (__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_isDataRequiredForCurrentChain).call(this)) { | ||
@@ -303,2 +361,3 @@ await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getNewFilesForCurrentChain).call(this); | ||
* Update the PPOM configuration for all chainId. | ||
* If new version info file is available the function will update data files for all chains. | ||
*/ | ||
@@ -338,6 +397,6 @@ async function _PPOMController_updatePPOM() { | ||
*/ | ||
async function _PPOMController_getFile(fileVersionInfo, overrideStorage = false) { | ||
async function _PPOMController_getFile(fileVersionInfo, storageFoundCorrupted) { | ||
const { storageMetadata } = this.state; | ||
// do not fetch file if the storage version is latest | ||
if (!overrideStorage && | ||
if (!storageFoundCorrupted && | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkFilePresentInStorage).call(this, storageMetadata, fileVersionInfo)) { | ||
@@ -356,21 +415,23 @@ return undefined; | ||
return fileData; | ||
}, _PPOMController_setChainIdDataFetched = function _PPOMController_setChainIdDataFetched(chainId) { | ||
}, _PPOMController_setChainIdDataFetched = | ||
/* | ||
* As files for a chain are fetched this function set dataFetched | ||
* property for that chainId in chainStatus to true. | ||
*/ | ||
async function _PPOMController_setChainIdDataFetched(chainId) { | ||
const { chainStatus, versionInfo } = this.state; | ||
const chainIdObject = chainStatus[chainId]; | ||
const versionInfoForChain = versionInfo.filter(({ chainId: id }) => id === chainId); | ||
if (chainIdObject && !chainIdObject.dataFetched) { | ||
const oldVersionInfo = chainIdObject.versionInfo; | ||
this.update((draftState) => { | ||
draftState.chainStatus = { | ||
...chainStatus, | ||
[chainId]: { | ||
...chainIdObject, | ||
dataFetched: true, | ||
versionInfo: versionInfoForChain, | ||
}, | ||
}; | ||
}); | ||
if (chainId === __classPrivateFieldGet(this, _PPOMController_chainId, "f") && | ||
!(0, util_1.isDeepEqual)(oldVersionInfo, versionInfoForChain)) { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetPPOM).call(this); | ||
if (chainIdObject) { | ||
if (!chainIdObject.dataFetched) { | ||
this.update((draftState) => { | ||
draftState.chainStatus = { | ||
...chainStatus, | ||
[chainId]: { | ||
...chainIdObject, | ||
dataFetched: true, | ||
versionInfo: versionInfoForChain, | ||
}, | ||
}; | ||
}); | ||
} | ||
@@ -385,4 +446,3 @@ } | ||
async function _PPOMController_getNewFilesForCurrentChain() { | ||
const { versionInfo } = this.state; | ||
for (const fileVersionInfo of versionInfo) { | ||
for (const fileVersionInfo of this.state.versionInfo) { | ||
if (fileVersionInfo.chainId !== __classPrivateFieldGet(this, _PPOMController_chainId, "f")) { | ||
@@ -393,7 +453,11 @@ continue; | ||
console.error(`Error in getting file ${fileVersionInfo.filePath}: ${exp.message}`); | ||
throw exp; | ||
}); | ||
} | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_setChainIdDataFetched).call(this, __classPrivateFieldGet(this, _PPOMController_chainId, "f")); | ||
}, _PPOMController_getListOfFilesToBeFetched = function _PPOMController_getListOfFilesToBeFetched() { | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_setChainIdDataFetched).call(this, __classPrivateFieldGet(this, _PPOMController_chainId, "f")); | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_reinitPPOM).call(this); | ||
}, _PPOMController_getListOfFilesToBeFetched = | ||
/* | ||
* Function creates list of all files to be fetched for all chainIds in chainStatus. | ||
*/ | ||
async function _PPOMController_getListOfFilesToBeFetched() { | ||
const { chainStatus, storageMetadata, versionInfo: stateVersionInfo, } = this.state; | ||
@@ -403,2 +467,3 @@ const networkIsSupported = __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_networkIsSupported).bind(this); | ||
// not include the files for which the version in storage is the latest one | ||
// As we add support for multiple chains it will be useful to sort the chain in desc order of lastvisited | ||
const chainIdsFileInfoList = Object.keys(chainStatus) | ||
@@ -414,3 +479,3 @@ .filter(networkIsSupported) | ||
chainIdsFileInfoList.forEach((chainIdFileInfo) => { | ||
const { chainId, versionInfo } = chainIdFileInfo; | ||
const { versionInfo } = chainIdFileInfo; | ||
versionInfo.forEach((fileVersionInfo, index) => { | ||
@@ -422,6 +487,2 @@ fileToBeFetchedList.push({ | ||
}); | ||
if (versionInfo.length === 0) { | ||
// set dataFetched to true for chainId | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_setChainIdDataFetched).call(this, chainId); | ||
} | ||
}); | ||
@@ -463,3 +524,3 @@ return fileToBeFetchedList; | ||
// build a list of files to be fetched for all networks | ||
const fileToBeFetchedList = __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getListOfFilesToBeFetched).call(this); | ||
const fileToBeFetchedList = await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getListOfFilesToBeFetched).call(this); | ||
// Get scheduled interval, if schedule interval is large so that not all files can be fetched in | ||
@@ -484,6 +545,9 @@ // this.#dataUpdateDuration, reduce schedule interval | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_getFile).call(this, fileVersionInfo) | ||
.then(() => { | ||
.then(async () => { | ||
if (isLastFileOfNetwork) { | ||
// if this was last file for the chainId set dataFetched for chainId to true | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_setChainIdDataFetched).call(this, fileVersionInfo.chainId); | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_setChainIdDataFetched).call(this, fileVersionInfo.chainId); | ||
if (fileVersionInfo.chainId === __classPrivateFieldGet(this, _PPOMController_chainId, "f")) { | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_reinitPPOM).call(this); | ||
} | ||
} | ||
@@ -598,7 +662,11 @@ }) | ||
async function _PPOMController_getPPOM() { | ||
await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_downloadNetworkFilesIfRequired).call(this); | ||
// For some reason ppom initialisation in contrructor fails for react native | ||
// thus it is added here to prevent validation from failing. | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_initialisePPOM).call(this); | ||
__classPrivateFieldSet(this, _PPOMController_ppomInitError, undefined, "f"); | ||
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")}`); | ||
__classPrivateFieldSet(this, _PPOMController_ppomInitError, `Aborting validation as no files are found for the network with chainId: ${__classPrivateFieldGet(this, _PPOMController_chainId, "f")}`, "f"); | ||
return undefined; | ||
} | ||
@@ -631,7 +699,10 @@ // Get all the files for the chainId | ||
// this can be achieved by returning empty data from version file. | ||
if (!files.length) { | ||
throw new Error(`Aborting validation as no files are found for the network with chainId: ${__classPrivateFieldGet(this, _PPOMController_chainId, "f")}`); | ||
if (files.length !== chainInfo?.versionInfo?.length) { | ||
__classPrivateFieldSet(this, _PPOMController_ppomInitError, `Aborting validation as not all files could not be downloaded for the network with chainId: ${__classPrivateFieldGet(this, _PPOMController_chainId, "f")}`, "f"); | ||
return undefined; | ||
} | ||
const { PPOM } = __classPrivateFieldGet(this, _PPOMController_ppomProvider, "f"); | ||
return PPOM.new(__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_jsonRpcRequest).bind(this), files); | ||
return await __classPrivateFieldGet(this, _PPOMController_ppomMutex, "f").use(async () => { | ||
const { PPOM } = __classPrivateFieldGet(this, _PPOMController_ppomProvider, "f"); | ||
return PPOM.new(__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_jsonRpcRequest).bind(this), files); | ||
}); | ||
}, _PPOMController_onDataUpdateDuration = function _PPOMController_onDataUpdateDuration() { | ||
@@ -650,5 +721,5 @@ this.updatePPOM().catch((exp) => { | ||
else { | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetDataFetchIntervals).call(this); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_resetToInactiveState).call(this); | ||
} | ||
}; | ||
//# sourceMappingURL=ppom-controller.js.map |
@@ -29,2 +29,1 @@ export declare const IdGenerator: () => number; | ||
export declare const addHexPrefix: (str: string) => string; | ||
export declare const isDeepEqual: (a: any, b: any) => boolean; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isDeepEqual = exports.addHexPrefix = exports.constructURLHref = exports.validateSignature = exports.PROVIDER_ERRORS = exports.createPayload = exports.IdGenerator = void 0; | ||
exports.addHexPrefix = exports.constructURLHref = exports.validateSignature = exports.PROVIDER_ERRORS = exports.createPayload = exports.IdGenerator = void 0; | ||
const elliptic_1 = __importDefault(require("elliptic")); | ||
@@ -62,28 +62,2 @@ const json_rpc_random_id_1 = __importDefault(require("json-rpc-random-id")); | ||
exports.addHexPrefix = addHexPrefix; | ||
/* | ||
* Simplified implementation of deep equality check of objects in Javascript. | ||
*/ | ||
const isDeepEqual = (a, b) => { | ||
if (a === b) { | ||
return true; | ||
} | ||
if (typeof a !== 'object' || typeof b !== 'object' || !a || !b) { | ||
return false; | ||
} | ||
const keysA = Object.keys(a); | ||
const keysB = Object.keys(b); | ||
if (keysA.length !== keysB.length) { | ||
return false; | ||
} | ||
for (const key of keysA) { | ||
if (!keysB.includes(key)) { | ||
return false; | ||
} | ||
if (a[key].toString() !== b[key].toString()) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
}; | ||
exports.isDeepEqual = isDeepEqual; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "@metamask/ppom-validator", | ||
"version": "0.8.0", | ||
"version": "0.9.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
139172
1176