Skip to content

Commit

Permalink
-n -m chore: patch web3-core-method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack-Works committed Apr 4, 2022
1 parent b711008 commit a987985
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
10 changes: 9 additions & 1 deletion packages/injected-script/main/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
11 changes: 8 additions & 3 deletions packages/mask/public/lockdown.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="ses" />
// 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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { openPopupWindow } from '../../../../../background/services/helper'
// #region providers
const providerPool = new Map<string, HttpProvider>()

export function createProvider(url: string) {
export function createProvider(url: string): HttpProvider {
const provider =
providerPool.get(url) ??
new MaskWallet.providers.HttpProvider(url, {
Expand Down
50 changes: 50 additions & 0 deletions patches/web3-core-method+1.7.1.patch
Original file line number Diff line number Diff line change
@@ -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]] || {};
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a987985

Please sign in to comment.