aboutsummaryrefslogtreecommitdiffstats
path: root/packages/web3-wrapper
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-10 08:04:54 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-10 08:04:54 +0800
commit8155d311af04339c105f1a29b74f1ddbced85197 (patch)
tree9b345f05561e806b6d89cec26b371aadafb109ed /packages/web3-wrapper
parentcd8e6d9cdf7d6aa1e811bb7d9d7017da342907ed (diff)
parentbd06ebde8d1a5caf138ad3b36f9a5c5f255f2312 (diff)
downloaddexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.tar
dexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.tar.gz
dexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.tar.bz2
dexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.tar.lz
dexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.tar.xz
dexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.tar.zst
dexon-sol-tools-8155d311af04339c105f1a29b74f1ddbced85197.zip
Merge branch 'development' into feature/asset-buyer/api-tweaks
* development: Define bundlewatch.ci.repoBranchBase Stop accesing ethers private methods Fix merge conflicts Fix ethers build issue Upgrade ethers.js version Fix branch name Add max sizes Use bundlewatch instead of bundlesize Move Metamask Error to OrderErrors Update the exported types for the packages which touch RPC providers Throw and handle errors from Providers. Clarifies use of schemas outside of Javascript/TypeScript. Detect MM on signature validation failure. Return SignedOrder from signing utils. Update 0x.js Changelog Add eth_signTypedData support to our wallet subproviders Move SignTypedData to utils package Introduce Metamask Subprovider. Expose eth_signTypedData functionality for order signing
Diffstat (limited to 'packages/web3-wrapper')
-rw-r--r--packages/web3-wrapper/CHANGELOG.json14
-rw-r--r--packages/web3-wrapper/package.json2
-rw-r--r--packages/web3-wrapper/src/index.ts1
-rw-r--r--packages/web3-wrapper/src/web3_wrapper.ts18
-rw-r--r--packages/web3-wrapper/test/web3_wrapper_test.ts15
5 files changed, 48 insertions, 2 deletions
diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json
index 47f054300..be5c1fef6 100644
--- a/packages/web3-wrapper/CHANGELOG.json
+++ b/packages/web3-wrapper/CHANGELOG.json
@@ -1,5 +1,19 @@
[
{
+ "version": "3.1.0",
+ "changes": [
+ {
+ "note": "Add `signTypedData` to perform EIP712 `eth_signTypedData`.",
+ "pr": 1102
+ },
+ {
+ "note":
+ "Web3Wrapper now throws when an RPC request contains an error field in the response. Previously errors could be swallowed and undefined returned.",
+ "pr": 1102
+ }
+ ]
+ },
+ {
"version": "3.0.3",
"changes": [
{
diff --git a/packages/web3-wrapper/package.json b/packages/web3-wrapper/package.json
index ef31a68dc..a3f82c87e 100644
--- a/packages/web3-wrapper/package.json
+++ b/packages/web3-wrapper/package.json
@@ -60,7 +60,7 @@
"@0xproject/utils": "^2.0.2",
"ethereum-types": "^1.0.11",
"ethereumjs-util": "^5.1.1",
- "ethers": "4.0.0-beta.14",
+ "ethers": "~4.0.4",
"lodash": "^4.17.5"
},
"publishConfig": {
diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts
index 7cdd25e55..9bef06fd4 100644
--- a/packages/web3-wrapper/src/index.ts
+++ b/packages/web3-wrapper/src/index.ts
@@ -30,6 +30,7 @@ export {
OpCode,
TxDataPayable,
JSONRPCResponsePayload,
+ JSONRPCResponseError,
RawLogEntry,
DecodedLogEntryEvent,
LogWithDecodedArgs,
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts
index d52c1cb6e..726246f1a 100644
--- a/packages/web3-wrapper/src/web3_wrapper.ts
+++ b/packages/web3-wrapper/src/web3_wrapper.ts
@@ -315,6 +315,21 @@ export class Web3Wrapper {
return signData;
}
/**
+ * Sign an EIP712 typed data message with a specific address's private key (`eth_signTypedData`)
+ * @param address Address of signer
+ * @param typedData Typed data message to sign
+ * @returns Signature string (as RSV)
+ */
+ public async signTypedDataAsync(address: string, typedData: any): Promise<string> {
+ assert.isETHAddressHex('address', address);
+ assert.doesConformToSchema('typedData', typedData, schemas.eip712TypedDataSchema);
+ const signData = await this.sendRawPayloadAsync<string>({
+ method: 'eth_signTypedData',
+ params: [address, typedData],
+ });
+ return signData;
+ }
+ /**
* Fetches the latest block number
* @returns Block number
*/
@@ -654,6 +669,9 @@ export class Web3Wrapper {
...payload,
};
const response = await promisify<JSONRPCResponsePayload>(sendAsync)(payloadWithDefaults);
+ if (response.error) {
+ throw new Error(response.error.message);
+ }
const result = response.result;
return result;
}
diff --git a/packages/web3-wrapper/test/web3_wrapper_test.ts b/packages/web3-wrapper/test/web3_wrapper_test.ts
index 385c469bf..164253777 100644
--- a/packages/web3-wrapper/test/web3_wrapper_test.ts
+++ b/packages/web3-wrapper/test/web3_wrapper_test.ts
@@ -1,5 +1,5 @@
import * as chai from 'chai';
-import { BlockParamLiteral } from 'ethereum-types';
+import { BlockParamLiteral, JSONRPCErrorCallback, JSONRPCRequestPayload } from 'ethereum-types';
import * as Ganache from 'ganache-core';
import * as _ from 'lodash';
import 'mocha';
@@ -78,6 +78,19 @@ describe('Web3Wrapper tests', () => {
const signatureLength = 132;
expect(signature.length).to.be.equal(signatureLength);
});
+ it('should throw if the provider returns an error', async () => {
+ const message = '0xdeadbeef';
+ const signer = addresses[1];
+ const fakeProvider = {
+ async sendAsync(payload: JSONRPCRequestPayload, callback: JSONRPCErrorCallback): Promise<void> {
+ callback(new Error('User denied message signature'));
+ },
+ };
+ const errorWeb3Wrapper = new Web3Wrapper(fakeProvider);
+ expect(errorWeb3Wrapper.signMessageAsync(signer, message)).to.be.rejectedWith(
+ 'User denied message signature',
+ );
+ });
});
describe('#getBlockNumberAsync', () => {
it('get block number', async () => {