Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for signing v4 typedData messages #145

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +1,6 @@
{
"name": "@portis/web3",
"version": "4.0.7",
"version": "4.0.8",
"description": "Portis Web3 SDK",
"main": "lib/index.js",
"module": "es/index.js",
Expand Down
51 changes: 0 additions & 51 deletions patches/web3-provider-engine+16.0.1.patch
Original file line number Diff line number Diff line change
@@ -1,54 +1,3 @@
diff --git a/node_modules/web3-provider-engine/dist/es5/subproviders/hooked-wallet.js b/node_modules/web3-provider-engine/dist/es5/subproviders/hooked-wallet.js
index 75576ec..2077f04 100644
--- a/node_modules/web3-provider-engine/dist/es5/subproviders/hooked-wallet.js
+++ b/node_modules/web3-provider-engine/dist/es5/subproviders/hooked-wallet.js
@@ -70,6 +70,7 @@ function HookedWalletSubprovider(opts) {
if (opts.processMessage) self.processMessage = opts.processMessage;
if (opts.processPersonalMessage) self.processPersonalMessage = opts.processPersonalMessage;
if (opts.processTypedMessage) self.processTypedMessage = opts.processTypedMessage; // approval hooks
+ if (opts.processTypedMessageV3) self.processTypedMessageV3 = opts.processTypedMessageV3; // approval hooks

self.approveTransaction = opts.approveTransaction || self.autoApprove;
self.approveMessage = opts.approveMessage || self.autoApprove;
@@ -84,6 +85,7 @@ function HookedWalletSubprovider(opts) {
if (opts.decryptMessage) self.decryptMessage = opts.decryptMessage || mustProvideInConstructor('decryptMessage');
if (opts.encryptionPublicKey) self.encryptionPublicKey = opts.encryptionPublicKey || mustProvideInConstructor('encryptionPublicKey');
if (opts.signTypedMessage) self.signTypedMessage = opts.signTypedMessage || mustProvideInConstructor('signTypedMessage');
+ if (opts.signTypedMessageV3) self.signTypedMessageV3 = opts.signTypedMessageV3 || mustProvideInConstructor('signTypedMessageV3');
if (opts.recoverPersonalSignature) self.recoverPersonalSignature = opts.recoverPersonalSignature; // publish to network

if (opts.publishTransaction) self.publishTransaction = opts.publishTransaction; // gas options
@@ -281,7 +283,9 @@ HookedWalletSubprovider.prototype.handleRequest = function (payload, next, end)
waterfall([function (cb) {
return self.validateTypedMessage(msgParams, cb);
}, function (cb) {
- return self.processTypedMessage(msgParams, cb);
+ return payload.method === 'eth_signTypedData'
+ ? self.processTypedMessage(msgParams, cb)
+ : self.processTypedMessageV3(msgParams, cb);
}], end);
}();

@@ -405,6 +409,19 @@ HookedWalletSubprovider.prototype.processTypedMessage = function (msgParams, cb)
// approval
//

+HookedWalletSubprovider.prototype.processTypedMessageV3 = function (msgParams, cb) {
+ var self = this;
+ waterfall([function (cb) {
+ return self.approveTypedMessage(msgParams, cb);
+ }, function (didApprove, cb) {
+ return self.checkApproval('message', didApprove, cb);
+ }, function (cb) {
+ return self.signTypedMessageV3(msgParams, cb);
+ }], cb);
+}; //
+// approval
+//
+

HookedWalletSubprovider.prototype.autoApprove = function (txParams, cb) {
cb(null, true);
diff --git a/node_modules/web3-provider-engine/index.js b/node_modules/web3-provider-engine/index.js
index 3a1b7d5..a4081c5 100644
--- a/node_modules/web3-provider-engine/index.js
Expand Down
6 changes: 0 additions & 6 deletions src/web3/web3Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,6 @@ export default class Web3Manager {
const { error, result } = await widgetCommunication.signMessage(params, this.config);
cb(error, result);
},
signTypedMessageV3: async (msgParams: any, cb: ProviderCallback) => {
const widgetCommunication = await this._getWidgetCommunication();
const params = { ...msgParams, messageStandard: 'signTypedMessageV3' };
const { error, result } = await widgetCommunication.signMessage(params, this.config);
cb(error, result);
},
estimateGas: async (txParams: any, cb: ProviderCallback) => {
const gas = await getTxGas(query, txParams);
cb(null, gas);
Expand Down