diff --git a/packages/injected-script/main/utils.ts b/packages/injected-script/main/utils.ts index decb7c02fc3..1b3ca165514 100644 --- a/packages/injected-script/main/utils.ts +++ b/packages/injected-script/main/utils.ts @@ -93,13 +93,21 @@ export function constructXrayUnwrappedFilesFromUintLike( }) return file } + +function getError(message: any) { + try { + return { message: message.message } + } catch { + return { message: 'unknown error' } + } +} export async function handlePromise(id: number, promise: () => any) { try { const data = await promise() sendEvent('resolvePromise', id, data) } catch (error) { // TODO: - sendEvent('rejectPromise', id, {}) + sendEvent('rejectPromise', id, getError(error)) } } diff --git a/packages/mask/public/lockdown.js b/packages/mask/public/lockdown.js index 616ed46622e..9935c7d208d 100644 --- a/packages/mask/public/lockdown.js +++ b/packages/mask/public/lockdown.js @@ -1,4 +1,6 @@ /// +// https://github.com/endojs/endo/issues/1139 +Object.defineProperty(Array.prototype, 'at', { configurable: false, value: Array.prototype.at }) lockdown({ // In production, we have CSP enforced no eval @@ -15,7 +17,7 @@ try { delete globalThis.regeneratorRuntime /** * @param {string} name The global name to be protected - * @param {'accept' | 'ignore'} policy The global policy + * @param {'accept' | 'ignore' | 'accept-then-ignore'} policy The global policy * @param {boolean} freeze If the value should be frozen * @param {boolean} warn If should log a warning when accessed * @param {boolean} why If should trigger the debugger on set @@ -57,7 +59,10 @@ try { if (why) debugger if (policy === 'ignore') return - if (hasBeenSet) throw new TypeError(`globalThis.${name} is not writable.`) + if (hasBeenSet) { + if (policy === 'accept-then-ignore') return true + throw new TypeError(`globalThis.${name} is not writable.`) + } hasBeenSet = true value = val if (freeze) harden(val) @@ -69,7 +74,7 @@ try { // accepted globals global('Buffer') // by webpack global('elliptic') // required by secp256k1 polyfill - global('regeneratorRuntime') // require by generator/async transpiled by babel + global('regeneratorRuntime', 'accept-then-ignore') // require by generator/async transpiled by babel global('__EMOTION_REACT_11__', 'ignore') // by @emotion/react to avoid duplicate loading global('_', 'ignore') // by lodash, as UMD diff --git a/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts b/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts index df91b186756..4a3c2f36909 100644 --- a/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts +++ b/packages/mask/src/extension/background-script/EthereumServices/providers/MaskWallet.ts @@ -9,7 +9,7 @@ import { openPopupWindow } from '../../../../../background/services/helper' // #region providers const providerPool = new Map() -export function createProvider(url: string) { +export function createProvider(url: string): HttpProvider { const provider = providerPool.get(url) ?? new MaskWallet.providers.HttpProvider(url, { diff --git a/patches/web3-core-method+1.7.1.patch b/patches/web3-core-method+1.7.1.patch new file mode 100644 index 00000000000..74b54e8bbcc --- /dev/null +++ b/patches/web3-core-method+1.7.1.patch @@ -0,0 +1,50 @@ +# generated by patch-package 6.5.0 on 2022-04-04 16:12:32 +# +# command: +# npx patch-package web3-core-method +# +# declared package: +# web3-core-method: 1.7.1 +# +diff --git a/node_modules/web3-core-method/lib/index.js b/node_modules/web3-core-method/lib/index.js +index 6ff3114..d136df7 100644 +--- a/node_modules/web3-core-method/lib/index.js ++++ b/node_modules/web3-core-method/lib/index.js +@@ -63,13 +63,13 @@ Method.prototype.setRequestManager = function (requestManager, accounts) { + }; + Method.prototype.createFunction = function (requestManager, accounts) { + var func = this.buildCall(); +- func.call = this.call; ++ Object.defineProperty(func, 'call', { configurable: true, writable: true, value: this.call }); + this.setRequestManager(requestManager || this.requestManager, accounts || this.accounts); + return func; + }; + Method.prototype.attachToObject = function (obj) { + var func = this.buildCall(); +- func.call = this.call; ++ Object.defineProperty(func, 'call', { configurable: true, writable: true, value: this.call }); + var name = this.name.split('.'); + if (name.length > 1) { + obj[name[0]] = obj[name[0]] || {}; +diff --git a/node_modules/web3-core-method/src/index.js b/node_modules/web3-core-method/src/index.js +index e50a286..f50856c 100644 +--- a/node_modules/web3-core-method/src/index.js ++++ b/node_modules/web3-core-method/src/index.js +@@ -76,7 +76,7 @@ Method.prototype.setRequestManager = function (requestManager, accounts) { + + Method.prototype.createFunction = function (requestManager, accounts) { + var func = this.buildCall(); +- func.call = this.call; ++ Object.defineProperty(func, 'call', { configurable: true, writable: true, value: this.call }); + + this.setRequestManager(requestManager || this.requestManager, accounts || this.accounts); + +@@ -85,7 +85,7 @@ Method.prototype.createFunction = function (requestManager, accounts) { + + Method.prototype.attachToObject = function (obj) { + var func = this.buildCall(); +- func.call = this.call; ++ Object.defineProperty(func, 'call', { configurable: true, writable: true, value: this.call }); + var name = this.name.split('.'); + if (name.length > 1) { + obj[name[0]] = obj[name[0]] || {}; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89b17ad5cdd..ee942a661db 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -35,7 +35,7 @@ importers: '@types/react-dom': 17.0.14 '@types/web': ^0.0.60 '@typescript-eslint/experimental-utils': ^5.17.0 - '@uniswap/v3-sdk': ^3.3.2 + '@uniswap/v3-sdk': 3.3.2 cspell: ^5.19.3 eslint: 8.12.0 eslint-plugin-import: 2.25.4 @@ -28012,13 +28012,13 @@ packages: dev: false github.com/frozeman/bignumber.js-nolookahead/57692b3ecfc98bbdd6b3a516cb2353652ea49934: - resolution: {commit: 57692b3ecfc98bbdd6b3a516cb2353652ea49934, repo: git+ssh://git@github.com/frozeman/bignumber.js-nolookahead.git, type: git} + resolution: {tarball: https://codeload.github.com/frozeman/bignumber.js-nolookahead/tar.gz/57692b3ecfc98bbdd6b3a516cb2353652ea49934} name: bignumber.js version: 2.0.7 dev: false github.com/locize/html-parse-stringify2/d463109433b2c49c74a081044f54b2a6a1ccad7c: - resolution: {tarball: https://codeload.github.com/locize/html-parse-stringify2/tar.gz/d463109433b2c49c74a081044f54b2a6a1ccad7c} + resolution: {commit: d463109433b2c49c74a081044f54b2a6a1ccad7c, repo: git+ssh://git@github.com/locize/html-parse-stringify2.git, type: git} name: html-parse-stringify2 version: 2.0.1 dependencies: