Skip to content

Commit

Permalink
Improve eth_sign compatibility (#102)
Browse files Browse the repository at this point in the history
* eth_sign behaves like personal_sign
* add eth_sign test
  • Loading branch information
hewigovens authored Sep 27, 2020
1 parent 8f3c374 commit d75dfef
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 38 deletions.
4 changes: 2 additions & 2 deletions dist/trust-min.js
Git LFS file not shown
15 changes: 14 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import ProviderRpcError from "./error";
import Utils from "./utils";
import IdMapping from "./id_mapping";
import { EventEmitter } from "events";
import isUtf8 from 'isutf8';

class TrustWeb3Provider extends EventEmitter {
constructor(config) {
Expand Down Expand Up @@ -200,7 +201,19 @@ class TrustWeb3Provider extends EventEmitter {
}

eth_sign(payload) {
this.postMessage("signMessage", payload.id, {data: payload.params[1]});
const data = payload.params[1];
var buffer;
if ((typeof (data) === "string")) {
buffer = Utils.hexToBuffer(data);
} else {
buffer = Buffer.from(data);
}
const hex = buffer.toString('hex');
if (isUtf8(buffer)) {
this.postMessage("signPersonalMessage", payload.id, {data: hex});
} else {
this.postMessage("signMessage", payload.id, {data: hex});
}
}

personal_sign(payload) {
Expand Down
231 changes: 220 additions & 11 deletions src/package-lock.json

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

Loading

0 comments on commit d75dfef

Please sign in to comment.