@metamask/ppom-validator
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -9,2 +9,7 @@ # Changelog | ||
## [0.3.0] | ||
### Changed | ||
- Fix issue with fetching files the first time extension is installed ([#39](https://github.com/MetaMask/ppom-validator/pull/39)) | ||
- Fix url construction for fetching blockaid files from CDN ([#40](https://github.com/MetaMask/ppom-validator/pull/40)) | ||
## [0.2.0] | ||
@@ -39,3 +44,4 @@ ### Changed | ||
[Unreleased]: https://github.com/MetaMask/ppom-validator/compare/v0.2.0...HEAD | ||
[Unreleased]: https://github.com/MetaMask/ppom-validator/compare/v0.3.0...HEAD | ||
[0.3.0]: https://github.com/MetaMask/ppom-validator/compare/v0.2.0...v0.3.0 | ||
[0.2.0]: https://github.com/MetaMask/ppom-validator/compare/v0.1.2...v0.2.0 | ||
@@ -42,0 +48,0 @@ [0.1.2]: https://github.com/MetaMask/ppom-validator/compare/v0.1.1...v0.1.2 |
@@ -56,3 +56,2 @@ "use strict"; | ||
const PPOM_VERSION_FILE_NAME = 'ppom_version.json'; | ||
const URL_PREFIX = 'https://'; | ||
const controllerName = 'PPOMController'; | ||
@@ -238,2 +237,3 @@ const versionInfoFileHeaders = { | ||
} | ||
__classPrivateFieldSet(this, _PPOMController_securityAlertsEnabled, blockaidEnabled, "f"); | ||
if (blockaidEnabled) { | ||
@@ -246,3 +246,2 @@ __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_scheduleFileDownloadForAllChains).call(this); | ||
} | ||
__classPrivateFieldSet(this, _PPOMController_securityAlertsEnabled, blockaidEnabled, "f"); | ||
}, _PPOMController_registerMessageHandlers = function _PPOMController_registerMessageHandlers() { | ||
@@ -316,3 +315,3 @@ this.messagingSystem.registerActionHandler(`${controllerName}:usePPOM`, this.usePPOM.bind(this)); | ||
__classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkFilePath).call(this, fileVersionInfo.filePath); | ||
const fileUrl = `${URL_PREFIX}${__classPrivateFieldGet(this, _PPOMController_cdnBaseUrl, "f")}/${fileVersionInfo.filePath}`; | ||
const fileUrl = (0, util_1.constructURLHref)(__classPrivateFieldGet(this, _PPOMController_cdnBaseUrl, "f"), fileVersionInfo.filePath); | ||
const fileData = await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_fetchBlob).call(this, fileUrl); | ||
@@ -480,3 +479,3 @@ await (0, util_1.validateSignature)(fileData, fileVersionInfo.signature, __classPrivateFieldGet(this, _PPOMController_blockaidPublicKey, "f"), fileVersionInfo.filePath); | ||
async function _PPOMController_fetchVersionInfo() { | ||
const url = `${URL_PREFIX}${__classPrivateFieldGet(this, _PPOMController_cdnBaseUrl, "f")}/${PPOM_VERSION_FILE_NAME}`; | ||
const url = (0, util_1.constructURLHref)(__classPrivateFieldGet(this, _PPOMController_cdnBaseUrl, "f"), PPOM_VERSION_FILE_NAME); | ||
// If ETag is same it is not required to fetch data files again | ||
@@ -504,12 +503,12 @@ const eTagChanged = await __classPrivateFieldGet(this, _PPOMController_instances, "m", _PPOMController_checkIfVersionInfoETagChanged).call(this, url); | ||
async function _PPOMController_jsonRpcRequest(method, params) { | ||
return new Promise((resolve, reject) => { | ||
// Throw error if number of request to provider from PPOM exceed the limit for current transaction | ||
return new Promise((resolve) => { | ||
// Resolve with error if number of requests from PPOM to provider exceeds the limit for the current transaction | ||
if (__classPrivateFieldGet(this, _PPOMController_providerRequests, "f") > __classPrivateFieldGet(this, _PPOMController_providerRequestLimit, "f")) { | ||
reject(util_1.PROVIDER_ERRORS.limitExceeded()); | ||
resolve(util_1.PROVIDER_ERRORS.limitExceeded()); | ||
return; | ||
} | ||
__classPrivateFieldSet(this, _PPOMController_providerRequests, __classPrivateFieldGet(this, _PPOMController_providerRequests, "f") + 1, "f"); | ||
// Throw error if the method called on provider by PPOM is not allowed for PPOM | ||
// Resolve with error if the provider method called by PPOM is not allowed for PPOM | ||
if (!ALLOWED_PROVIDER_CALLS.includes(method)) { | ||
reject(util_1.PROVIDER_ERRORS.methodNotSupported()); | ||
resolve(util_1.PROVIDER_ERRORS.methodNotSupported()); | ||
return; | ||
@@ -520,3 +519,7 @@ } | ||
if (error) { | ||
reject(error); | ||
resolve({ | ||
jsonrpc: '2.0', | ||
id: (0, util_1.IdGenerator)(), | ||
error, | ||
}); | ||
} | ||
@@ -523,0 +526,0 @@ else { |
@@ -27,1 +27,2 @@ export declare const IdGenerator: () => number; | ||
export declare const validateSignature: (data: any, signature: string, key: string, filePath: string) => Promise<void>; | ||
export declare const constructURLHref: (base: string, path: string) => string; |
@@ -6,6 +6,7 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateSignature = exports.PROVIDER_ERRORS = exports.createPayload = exports.IdGenerator = void 0; | ||
exports.constructURLHref = exports.validateSignature = exports.PROVIDER_ERRORS = exports.createPayload = exports.IdGenerator = void 0; | ||
const elliptic_1 = __importDefault(require("elliptic")); | ||
const json_rpc_random_id_1 = __importDefault(require("json-rpc-random-id")); | ||
const EdDSA = elliptic_1.default.eddsa; | ||
const URL_PREFIX = 'https://'; | ||
exports.IdGenerator = (0, json_rpc_random_id_1.default)(); | ||
@@ -32,3 +33,3 @@ const createPayload = (method, params) => ({ | ||
error: { | ||
code: -32004, | ||
code: -32601, | ||
message: 'Method not supported', | ||
@@ -48,2 +49,6 @@ }, | ||
exports.validateSignature = validateSignature; | ||
const constructURLHref = (base, path) => new URL(`${URL_PREFIX}${base}/${path}` | ||
.replace(/https:\/\/https:\/\//gu, 'https://') | ||
.replace(/\/\//gu, '/')).href; | ||
exports.constructURLHref = constructURLHref; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "@metamask/ppom-validator", | ||
"version": "0.2.0", | ||
"version": "0.3.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
115848
1019