Reject checksummed addresses
This commit is contained in:
@@ -87,7 +87,7 @@
|
||||
"types-ethereumjs-util": "^0.0.5",
|
||||
"typescript": "^2.4.1",
|
||||
"web3-provider-engine": "^13.0.1",
|
||||
"web3-typescript-typings": "^0.3.0",
|
||||
"web3-typescript-typings": "^0.3.2",
|
||||
"webpack": "^3.1.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export const addressSchema = {
|
||||
id: '/addressSchema',
|
||||
type: 'string',
|
||||
pattern: '^0[xX][0-9A-Fa-f]{40}$',
|
||||
pattern: '^0x[0-9a-f]{40}$',
|
||||
};
|
||||
|
||||
export const numberSchema = {
|
||||
|
||||
@@ -24,6 +24,10 @@ export const assert = {
|
||||
isETHAddressHex(variableName: string, value: string): void {
|
||||
const web3 = new Web3();
|
||||
this.assert(web3.isAddress(value), this.typeAssertionMessage(variableName, 'ETHAddressHex', value));
|
||||
this.assert(
|
||||
web3.isAddress(value) && !web3.isChecksumAddress(value),
|
||||
'Checksummed addresses are not supported. Convert to lower case before passing',
|
||||
);
|
||||
},
|
||||
doesBelongToStringEnum(variableName: string, value: string,
|
||||
stringEnum: any /* There is no base type for every string enum */): void {
|
||||
|
||||
@@ -57,7 +57,7 @@ describe('ZeroEx library', () => {
|
||||
).to.become(false);
|
||||
});
|
||||
it('should return false if the address doesn\'t pertain to the signature & data', async () => {
|
||||
const validUnrelatedAddress = '0x8b0292B11a196601eD2ce54B665CaFEca0347D42';
|
||||
const validUnrelatedAddress = '0x8b0292b11a196601ed2ce54b665cafeca0347d42';
|
||||
expect(ZeroEx.isValidSignature(dataHex, signature, validUnrelatedAddress)).to.be.false();
|
||||
return expect(
|
||||
(zeroEx.exchange as any)._isValidSignatureUsingContractCallAsync(dataHex, signature,
|
||||
|
||||
@@ -42,11 +42,15 @@ describe('Schema', () => {
|
||||
});
|
||||
describe('#addressSchema', () => {
|
||||
it('should validate valid addresses', () => {
|
||||
const testCases = ['0x8b0292B11a196601eD2ce54B665CaFEca0347D42', constants.NULL_ADDRESS];
|
||||
const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', constants.NULL_ADDRESS];
|
||||
validateAgainstSchema(testCases, addressSchema);
|
||||
});
|
||||
it('should fail for invalid addresses', () => {
|
||||
const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42'];
|
||||
const testCases = [
|
||||
'0x',
|
||||
'0',
|
||||
'0x00',
|
||||
'0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42', '0x8b0292B11a196601eD2ce54B665CaFEca0347D42'];
|
||||
const shouldFail = true;
|
||||
validateAgainstSchema(testCases, addressSchema, shouldFail);
|
||||
});
|
||||
@@ -159,7 +163,7 @@ describe('Schema', () => {
|
||||
name: 'Zero Ex',
|
||||
symbol: 'ZRX',
|
||||
decimals: 100500,
|
||||
address: '0x8b0292B11a196601eD2ce54B665CaFEca0347D42',
|
||||
address: '0x8b0292b11a196601ed2ce54b665cafeca0347d42',
|
||||
url: 'https://0xproject.com',
|
||||
};
|
||||
it('should validate valid token', () => {
|
||||
|
||||
@@ -5047,9 +5047,9 @@ web3-provider-engine@^8.4.0:
|
||||
xhr "^2.2.0"
|
||||
xtend "^4.0.1"
|
||||
|
||||
web3-typescript-typings@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.3.0.tgz#1df583d8d9012059802dee90f72144576e0ab4fe"
|
||||
web3-typescript-typings@^0.3.2:
|
||||
version "0.3.2"
|
||||
resolved "https://registry.yarnpkg.com/web3-typescript-typings/-/web3-typescript-typings-0.3.2.tgz#75f65fe452e35e2b96192908199dbb7a9ab5bcc3"
|
||||
dependencies:
|
||||
bignumber.js "^4.0.2"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user