Merge pull request #257 from 0xProject/fix/ethereum-address
Remove ethereum-address dependency and add this logic to the repo
This commit is contained in:
commit
cb7188d473
@ -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"
|
||||
}
|
||||
|
4
packages/assert/src/globals.d.ts
vendored
4
packages/assert/src/globals.d.ts
vendored
@ -1,5 +1 @@
|
||||
declare module 'dirty-chai';
|
||||
|
||||
declare module 'ethereum-address' {
|
||||
const isAddress: (arg: any) => boolean;
|
||||
}
|
||||
|
@ -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`,
|
||||
);
|
||||
},
|
||||
|
@ -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",
|
||||
|
5
packages/subproviders/src/globals.d.ts
vendored
5
packages/subproviders/src/globals.d.ts
vendored
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"bignumber.js": "~4.1.0",
|
||||
"js-sha3": "^0.7.0",
|
||||
"lodash": "^4.17.4"
|
||||
}
|
||||
}
|
||||
|
34
packages/utils/src/address_utils.ts
Normal file
34
packages/utils/src/address_utils.ts
Normal file
@ -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;
|
||||
}
|
||||
},
|
||||
};
|
@ -1 +1,2 @@
|
||||
export {promisify} from './promisify';
|
||||
export {addressUtils} from './address_utils';
|
||||
|
@ -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",
|
||||
|
@ -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,
|
||||
|
5
packages/website/ts/globals.d.ts
vendored
5
packages/website/ts/globals.d.ts
vendored
@ -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 {
|
||||
|
14
yarn.lock
14
yarn.lock
@ -27,6 +27,16 @@
|
||||
uuid "^3.1.0"
|
||||
web3 "^0.20.0"
|
||||
|
||||
"@0xproject/assert@^0.0.6":
|
||||
version "0.0.6"
|
||||
resolved "https://registry.yarnpkg.com/@0xproject/assert/-/assert-0.0.6.tgz#773616620314f40ace11a9c4c65cc95398d2c178"
|
||||
dependencies:
|
||||
"@0xproject/json-schemas" "^0.6.9"
|
||||
bignumber.js "~4.1.0"
|
||||
ethereum-address "^0.0.4"
|
||||
lodash "^4.17.4"
|
||||
valid-url "^1.0.9"
|
||||
|
||||
"@types/accounting@^0.4.1":
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/accounting/-/accounting-0.4.1.tgz#865d9f5694fd7c438fba34eb4bc82eec6f34cdd5"
|
||||
@ -4518,6 +4528,10 @@ js-sha3@^0.6.1:
|
||||
version "0.6.1"
|
||||
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.6.1.tgz#5b89f77a7477679877f58c4a075240934b1f95c0"
|
||||
|
||||
js-sha3@^0.7.0:
|
||||
version "0.7.0"
|
||||
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.7.0.tgz#0a5c57b36f79882573b2d84051f8bb85dd1bd63a"
|
||||
|
||||
js-tokens@^3.0.0, js-tokens@^3.0.2:
|
||||
version "3.0.2"
|
||||
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b"
|
||||
|
Loading…
x
Reference in New Issue
Block a user