aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-12-12 22:30:04 +0800
committerGitHub <noreply@github.com>2017-12-12 22:30:04 +0800
commitcb7188d47390719b74d7e09c938068a9f201c1b0 (patch)
tree1b67b0b849550bea8b5ad20fe4d7a383ec49163d /packages
parent02f22d91555ea05fc52d342e9c91cd9477321da1 (diff)
parentd778378b37b0cbd77ecdf8d1cafc7720682064ec (diff)
downloaddexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.tar
dexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.tar.gz
dexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.tar.bz2
dexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.tar.lz
dexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.tar.xz
dexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.tar.zst
dexon-sol-tools-cb7188d47390719b74d7e09c938068a9f201c1b0.zip
Merge pull request #257 from 0xProject/fix/ethereum-address
Remove ethereum-address dependency and add this logic to the repo
Diffstat (limited to 'packages')
-rw-r--r--packages/assert/package.json2
-rw-r--r--packages/assert/src/globals.d.ts4
-rw-r--r--packages/assert/src/index.ts6
-rw-r--r--packages/subproviders/package.json1
-rw-r--r--packages/subproviders/src/globals.d.ts5
-rw-r--r--packages/subproviders/src/subproviders/ledger.ts4
-rw-r--r--packages/utils/package.json1
-rw-r--r--packages/utils/src/address_utils.ts34
-rw-r--r--packages/utils/src/index.ts1
-rw-r--r--packages/website/package.json1
-rw-r--r--packages/website/ts/components/inputs/address_input.tsx4
-rw-r--r--packages/website/ts/globals.d.ts5
12 files changed, 44 insertions, 24 deletions
diff --git a/packages/assert/package.json b/packages/assert/package.json
index 65b163c21..2fb7746a8 100644
--- a/packages/assert/package.json
+++ b/packages/assert/package.json
@@ -38,8 +38,8 @@
},
"dependencies": {
"@0xproject/json-schemas": "^0.6.10",
+ "@0xproject/utils": "^0.1.0",
"bignumber.js": "~4.1.0",
- "ethereum-address": "^0.0.4",
"lodash": "^4.17.4",
"valid-url": "^1.0.9"
}
diff --git a/packages/assert/src/globals.d.ts b/packages/assert/src/globals.d.ts
index cc47f3113..91ed2021e 100644
--- a/packages/assert/src/globals.d.ts
+++ b/packages/assert/src/globals.d.ts
@@ -1,5 +1 @@
declare module 'dirty-chai';
-
-declare module 'ethereum-address' {
- const isAddress: (arg: any) => boolean;
-}
diff --git a/packages/assert/src/index.ts b/packages/assert/src/index.ts
index 92bcf6f03..fadc31d09 100644
--- a/packages/assert/src/index.ts
+++ b/packages/assert/src/index.ts
@@ -2,8 +2,8 @@ import {
Schema,
SchemaValidator,
} from '@0xproject/json-schemas';
+import {addressUtils} from '@0xproject/utils';
import BigNumber from 'bignumber.js';
-import * as ethereum_address from 'ethereum-address';
import * as _ from 'lodash';
import * as validUrl from 'valid-url';
@@ -35,9 +35,9 @@ export const assert = {
this.typeAssertionMessage(variableName, 'HexString', value));
},
isETHAddressHex(variableName: string, value: string): void {
- this.assert(ethereum_address.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
+ this.assert(addressUtils.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
this.assert(
- ethereum_address.isAddress(value) && value.toLowerCase() === value,
+ addressUtils.isAddress(value) && value.toLowerCase() === value,
`Checksummed addresses are not supported. Convert ${variableName} to lower case before passing`,
);
},
diff --git a/packages/subproviders/package.json b/packages/subproviders/package.json
index 7ff0c5b09..b0c5686a6 100644
--- a/packages/subproviders/package.json
+++ b/packages/subproviders/package.json
@@ -21,7 +21,6 @@
"@0xproject/utils": "^0.1.0",
"bn.js": "^4.11.8",
"es6-promisify": "^5.0.0",
- "ethereum-address": "^0.0.4",
"ethereumjs-tx": "^1.3.3",
"ethereumjs-util": "^5.1.1",
"ledgerco": "0xProject/ledger-node-js-api",
diff --git a/packages/subproviders/src/globals.d.ts b/packages/subproviders/src/globals.d.ts
index 520ca9232..400bbef5b 100644
--- a/packages/subproviders/src/globals.d.ts
+++ b/packages/subproviders/src/globals.d.ts
@@ -54,11 +54,6 @@ declare module 'ledgerco' {
}
}
-// ethereum-address declarations
-declare module 'ethereum-address' {
- export const isAddress: (address: string) => boolean;
-}
-
// Semaphore-async-await declarations
declare module 'semaphore-async-await' {
class Semaphore {
diff --git a/packages/subproviders/src/subproviders/ledger.ts b/packages/subproviders/src/subproviders/ledger.ts
index e0a08f792..578f6ff6f 100644
--- a/packages/subproviders/src/subproviders/ledger.ts
+++ b/packages/subproviders/src/subproviders/ledger.ts
@@ -1,6 +1,6 @@
import {assert} from '@0xproject/assert';
+import {addressUtils} from '@0xproject/utils';
import promisify = require('es6-promisify');
-import {isAddress} from 'ethereum-address';
import EthereumTx = require('ethereumjs-tx');
import ethUtil = require('ethereumjs-util');
import * as ledger from 'ledgerco';
@@ -47,7 +47,7 @@ export class LedgerSubprovider extends Subprovider {
return isValid;
}
private static validateSender(sender: string) {
- if (_.isUndefined(sender) || !isAddress(sender)) {
+ if (_.isUndefined(sender) || !addressUtils.isAddress(sender)) {
throw new Error(LedgerSubproviderErrors.SenderInvalidOrNotSupplied);
}
}
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 1af8a7e11..8f856d0a0 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -28,6 +28,7 @@
},
"dependencies": {
"bignumber.js": "~4.1.0",
+ "js-sha3": "^0.7.0",
"lodash": "^4.17.4"
}
}
diff --git a/packages/utils/src/address_utils.ts b/packages/utils/src/address_utils.ts
new file mode 100644
index 000000000..bdbcd3a89
--- /dev/null
+++ b/packages/utils/src/address_utils.ts
@@ -0,0 +1,34 @@
+import * as jsSHA3 from 'js-sha3';
+
+const BASIC_ADDRESS_REGEX = /^(0x)?[0-9a-f]{40}$/i;
+const SAME_CASE_ADDRESS_REGEX = /^(0x)?([0-9a-f]{40}|[0-9A-F]{40})$/;
+
+export const addressUtils = {
+ isChecksumAddress(address: string): boolean {
+ // Check each case
+ const unprefixedAddress = address.replace('0x', '');
+ const addressHash = jsSHA3.keccak256(unprefixedAddress.toLowerCase());
+
+ for (let i = 0; i < 40; i++) {
+ // The nth letter should be uppercase if the nth digit of casemap is 1
+ if ((parseInt(addressHash[i], 16) > 7 && unprefixedAddress[i].toUpperCase() !== unprefixedAddress[i]) ||
+ (parseInt(addressHash[i], 16) <= 7 && unprefixedAddress[i].toLowerCase() !== unprefixedAddress[i])) {
+ return false;
+ }
+ }
+ return true;
+ },
+ isAddress(address: string): boolean {
+ if (!BASIC_ADDRESS_REGEX.test(address)) {
+ // Check if it has the basic requirements of an address
+ return false;
+ } else if (SAME_CASE_ADDRESS_REGEX.test(address)) {
+ // If it's all small caps or all all caps, return true
+ return true;
+ } else {
+ // Otherwise check each case
+ const isValidChecksummedAddress = addressUtils.isChecksumAddress(address);
+ return isValidChecksummedAddress;
+ }
+ },
+};
diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts
index a61f04ad2..edfd192b2 100644
--- a/packages/utils/src/index.ts
+++ b/packages/utils/src/index.ts
@@ -1 +1,2 @@
export {promisify} from './promisify';
+export {addressUtils} from './address_utils';
diff --git a/packages/website/package.json b/packages/website/package.json
index 5162a27ff..f005668f8 100644
--- a/packages/website/package.json
+++ b/packages/website/package.json
@@ -28,7 +28,6 @@
"dateformat": "^2.0.0",
"deep-equal": "^1.0.1",
"dharma-loan-frame": "^0.0.12",
- "ethereum-address": "^0.0.4",
"ethereumjs-tx": "^1.3.3",
"ethereumjs-util": "^5.1.1",
"find-versions": "^2.0.0",
diff --git a/packages/website/ts/components/inputs/address_input.tsx b/packages/website/ts/components/inputs/address_input.tsx
index 8b03b8d12..40ae722d9 100644
--- a/packages/website/ts/components/inputs/address_input.tsx
+++ b/packages/website/ts/components/inputs/address_input.tsx
@@ -1,4 +1,4 @@
-import {isAddress} from 'ethereum-address';
+import {addressUtils} from '@0xproject/utils';
import * as _ from 'lodash';
import {colors} from 'material-ui/styles';
import TextField from 'material-ui/TextField';
@@ -62,7 +62,7 @@ export class AddressInput extends React.Component<AddressInputProps, AddressInpu
}
private onOrderTakerAddressUpdated(e: any) {
const address = e.target.value.toLowerCase();
- const isValidAddress = isAddress(address) || address === '';
+ const isValidAddress = addressUtils.isAddress(address) || address === '';
const errMsg = isValidAddress ? '' : 'Invalid ethereum address';
this.setState({
address,
diff --git a/packages/website/ts/globals.d.ts b/packages/website/ts/globals.d.ts
index b4611f583..3144d7eb5 100644
--- a/packages/website/ts/globals.d.ts
+++ b/packages/website/ts/globals.d.ts
@@ -55,11 +55,6 @@ interface System {
}
declare var System: System;
-// ethereum-address declarations
-declare module 'ethereum-address' {
- export const isAddress: (address: string) => boolean;
-}
-
// jsonschema declarations
// Source: https://github.com/tdegrunt/jsonschema/blob/master/lib/index.d.ts
declare interface Schema {