Skip to content

Commit

Permalink
release v2.2.0-beta.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Aug 12, 2021
1 parent 12851cb commit ab351c4
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 104 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- ### Release 2.2.0-beta.3
- change eth_decrypt, eth_getEncryptionPublicKey, eth_sign, eth_signTypedData_v3, personal_sign adhere to the standard

- ### Release 2.2.0-beta.2
- Fix reference to css background class names in popUpCreator
- Fix typo with transaction receipt event
Expand Down
47 changes: 7 additions & 40 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ require('regenerator-runtime/runtime');

var name = "@myetherwallet/mewconnect-web-client";
var homepage = "https://github.com/myetherwallet/MEWconnect-web-client";
var version = "2.2.0-beta.1";
var version = "2.2.0-beta.2";
var main = "./dist/index.js";
var module$1 = "./src/index.js";
var scripts = {
Expand Down Expand Up @@ -6736,40 +6736,25 @@ const debugErrors$5 = debugLogger('MEWconnectError');
let state = {
wallet: null
};

const infuraUrlFormater = (name$$1, infuraId) => {
return `wss://${name$$1}.infura.io/ws/v3/${infuraId}`;
};
const eventHub = new EventEmitter();
let popUpCreator = {};

class Integration extends EventEmitter {
constructor(options = {}) {
super();
if (window.web3) {
if (window.web3.currentProvider) {
if (
window.web3.currentProvider.isMewConnect ||
window.web3.currentProvider.isTrust
) {
this.runningInApp = true;
state.web3Provider = window.web3.currentProvider;
} else {
this.runningInApp = false;
}
if (window.ethereum) {
if (window.ethereum.isMewConnect || window.ethereum.isTrust) {
this.runningInApp = true;
state.web3Provider = window.ethereum;
} else {
this.runningInApp = false;
}
} else {
this.runningInApp = false;
}

this.windowClosedError = options.windowClosedError || false;
this.subscriptionNotFoundNoThrow =
options.subscriptionNotFoundNoThrow || true;
// eslint-disable-next-line
this.infuraId = !!options.infuraId ? options.infuraId : false;

this.CHAIN_ID = options.chainId || 1;
this.RPC_URL = options.rpcUrl || false;
this.noUrlCheck = options.noUrlCheck || false;
Expand Down Expand Up @@ -6993,14 +6978,13 @@ class Integration extends EventEmitter {
RPC_URL = this.RPC_URL,
_noCheck = this.noUrlCheck
) {
let chainError = false;
let web3Provider;
try {
if (this.runningInApp) {
if (state.web3Provider) {
web3Provider = state.web3Provider;
} else {
web3Provider = window.web3.currentProvider;
web3Provider = window.ethereum;
}
} else {
let chain, defaultNetwork;
Expand All @@ -7013,10 +6997,6 @@ class Integration extends EventEmitter {
defaultNetwork = this.formatNewNetworks({ name: 'unknown' });
state.network = defaultNetwork;
}

if (this.infuraId && !this.RPC_URL) {
RPC_URL = infuraUrlFormater(chain.name, this.infuraId);
}
const hostUrl = url.parse(RPC_URL || defaultNetwork.url);
const options = {
subscriptionNotFoundNoThrow: this.subscriptionNotFoundNoThrow
Expand All @@ -7029,17 +7009,6 @@ class Integration extends EventEmitter {
'Invalid rpc endpoint supplied to MEWconnect during setup'
);
}
if (!_noCheck && !this.infuraId) {
if (
!hostUrl.hostname.includes(chain.name) &&
hostUrl.hostname.includes('infura.io')
) {
chainError = true;
throw Error(
`ChainId: ${CHAIN_ID} and infura endpoint ${hostUrl.hostname} don't match`
);
}
}
const parsedUrl = `${hostUrl.protocol}//${
hostUrl.hostname ? hostUrl.hostname : hostUrl.host
}${hostUrl.port ? ':' + hostUrl.port : ''}${
Expand Down Expand Up @@ -7073,9 +7042,7 @@ class Integration extends EventEmitter {
return web3Provider;
} catch (e) {
debugErrors$5('makeWeb3Provider ERROR');
if (chainError) {
throw e;
} else {
{
// eslint-disable-next-line
console.error(e);
}
Expand Down
40 changes: 27 additions & 13 deletions example/app/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -779,29 +779,43 @@ export default {
})
.then(pubkey => {
console.log(`User's public encryption key ${pubkey}`);
const encryptedMessage = ethUtil.bufferToHex(
Buffer.from(
JSON.stringify(
sigUtil.encrypt(
pubkey,
{ data: 'Hello world! ' + new Date().getTime() },
'x25519-xsalsa20-poly1305'
)
),
'utf8'
)
const encryptedMessage = Buffer.from(
JSON.stringify(
sigUtil.encrypt(
pubkey,
{ data: 'Hello world! ' + new Date().getTime() },
'x25519-xsalsa20-poly1305'
)
),
'utf8'
);
console.log('encrypted message', encryptedMessage);
const encryptedMessageHex = ethUtil.bufferToHex(encryptedMessage);
console.log('encrypted message', encryptedMessageHex);
setTimeout(() => {
this.ethereum
.request({
method: 'eth_decrypt',
params: [encryptedMessage, this.userAddress]
params: [encryptedMessageHex, this.userAddress]
})
.then(decryptedMessage =>
console.log('The decrypted message is:', decryptedMessage)
)
.catch(error => console.log(error.message));
}, 2000);
setTimeout(() => {
this.ethereum
.request({
method: 'eth_decrypt',
params: [encryptedMessage.toString('utf8'), this.userAddress]
})
.then(decryptedMessage =>
console.log(
'The decrypted struct message is:',
decryptedMessage
)
)
.catch(error => console.log(error.message));
}, 4000);
});
},
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@myetherwallet/mewconnect-web-client",
"homepage": "https://github.com/myetherwallet/MEWconnect-web-client",
"version": "2.2.0-beta.2",
"version": "2.2.0-beta.3",
"main": "./dist/index.js",
"module": "./src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/connectProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -622,14 +622,14 @@ export default class Integration extends EventEmitter {
}
});

eventHub.on(EventNames.GET_ENCRYPTED_PUBLIC_KEY, resolve => {
eventHub.on(EventNames.GET_ENCRYPTED_PUBLIC_KEY, (params, resolve) => {
if (!state.wallet) {
this.popUpHandler.showNoticePersistentEnter(
messageConstants.notConnected
);
} else {
const mewConnect = state.wallet.getConnection();
mewConnect.sendRtcMessage('eth_getEncryptionPublicKey', '');
mewConnect.sendRtcMessage('eth_getEncryptionPublicKey', params);
mewConnect.once('eth_getEncryptionPublicKey', data => {
resolve(data);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@
import { toError, toPayload } from '../jsonrpc';
import EventNames from '../events';
import debugLogger from 'debug';
import { isHexStrict } from 'web3-utils';
import { bufferToHex } from 'ethereumjs-util';
const debug = debugLogger('MEWconnectWeb3');
const debugErrors = debugLogger('MEWconnectError');

export default async ({ payload, eventHub }, res, next) => {
if (payload.method !== 'eth_decrypt') return next();
try {
debug(payload.params[0]); // todo remove dev item
eventHub.emit(EventNames.DECRYPT, payload.params, _response => {
if (_response.reject) {
debug('USER DECLINED SIGN TRANSACTION');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
let jsonObj = payload.params[0];
if (!isHexStrict(jsonObj)) {
jsonObj = JSON.parse(jsonObj);
jsonObj = bufferToHex(Buffer.from(JSON.stringify(jsonObj), 'utf8'));
}
eventHub.emit(
EventNames.DECRYPT,
[jsonObj, payload.params[1]],
_response => {
if (_response.reject) {
debug('USER DECLINED SIGN TRANSACTION');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
}
debug('decrypt response', payload.method, _response);
res(null, toPayload(payload.id, _response));
}
debug('decrypt response', payload.method, _response);
res(null, toPayload(payload.id, _response));
});
);
} catch (e) {
debugErrors(e);
debugErrors('Error: eth_decrypt', e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@ const debugErrors = debugLogger('MEWconnectError');
export default async ({ payload, eventHub }, res, next) => {
if (payload.method !== 'eth_getEncryptionPublicKey') return next();
try {
eventHub.emit(EventNames.GET_ENCRYPTED_PUBLIC_KEY, _response => {
if (_response.reject) {
debug('USER DECLINED SIGN TRANSACTION');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
eventHub.emit(
EventNames.GET_ENCRYPTED_PUBLIC_KEY,
payload.params,
_response => {
if (_response.reject) {
debug('USER DECLINED SIGN TRANSACTION');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
}
debug('eth_getEncryptionPublicKey response', payload.method, _response);
res(null, toPayload(payload.id, _response));
}
debug('eth_getEncryptionPublicKey response', payload.method, _response);
res(null, toPayload(payload.id, _response));
});
);
} catch (e) {
debugErrors(e);
debugErrors('Error: eth_getEncryptionPublicKey', e);
Expand Down
23 changes: 13 additions & 10 deletions src/connectProvider/web3Provider/web3-provider/methods/eth_sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ const debug = debugLogger('MEWconnectWeb3');

export default async ({ payload, eventHub }, res, next) => {
if (payload.method !== 'eth_sign') return next();
const msg = payload.params[1];
eventHub.emit(EventNames.SHOW_MSG_CONFIRM_MODAL, msg, _response => {
if (_response.reject) {
debug('USER DECLINED SIGN MESSAGE');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
eventHub.emit(
EventNames.SHOW_MSG_CONFIRM_MODAL,
payload.params,
_response => {
if (_response.reject) {
debug('USER DECLINED SIGN MESSAGE');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
}
_response = misc.sanitizeHex(_response.toString('hex'));
debug('sign result', _response);
res(null, toPayload(payload.id, _response));
}
_response = misc.sanitizeHex(_response.toString('hex'));
debug('sign result', _response);
res(null, toPayload(payload.id, _response));
});
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,15 @@ const debugErrors = debugLogger('MEWconnectError');
export default async ({ payload, eventHub }, res, next) => {
if (payload.method !== 'eth_signTypedData_v3') return next();
try {
eventHub.emit(
EventNames.SIGN_TYPE_DATA_V3,
payload.params[1],
_response => {
if (_response.reject) {
debug('USER DECLINED SIGN TYPED DATA');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
}
debug('eth_signTypedData_v3 response', payload.method, _response);
res(null, toPayload(payload.id, _response));
eventHub.emit(EventNames.SIGN_TYPE_DATA_V3, payload.params, _response => {
if (_response.reject) {
debug('USER DECLINED SIGN TYPED DATA');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
}
);
debug('eth_signTypedData_v3 response', payload.method, _response);
res(null, toPayload(payload.id, _response));
});
} catch (e) {
debugErrors(e);
debugErrors('Error: eth_signTypedData_v3', e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ const debug = debugLogger('MEWconnectWeb3');

export default async ({ payload, eventHub }, res, next) => {
if (payload.method !== 'personal_sign') return next();
const msg = payload.params[0];
eventHub.emit(EventNames.SHOW_MSG_CONFIRM_MODAL, msg, _response => {
if (_response.reject) {
debug('USER DECLINED PERSONAL SIGN');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
eventHub.emit(
EventNames.SHOW_MSG_CONFIRM_MODAL,
payload.params,
_response => {
if (_response.reject) {
debug('USER DECLINED PERSONAL SIGN');
res(toError(payload.id, 'User Rejected Request', 4001));
return;
}
_response = misc.sanitizeHex(_response.toString('hex'));
res(null, toPayload(payload.id, _response));
}
_response = misc.sanitizeHex(_response.toString('hex'));
res(null, toPayload(payload.id, _response));
});
);
};

0 comments on commit ab351c4

Please sign in to comment.