Rename EIP712Utils to eip712Utils since objectLiterals shouldn't start with caps
This commit is contained in:
parent
4d75689790
commit
7759e67a5a
@ -1,5 +1,5 @@
|
|||||||
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
import { BlockchainLifecycle } from '@0xproject/dev-utils';
|
||||||
import { assetDataUtils, EIP712Utils, orderHashUtils } from '@0xproject/order-utils';
|
import { assetDataUtils, eip712Utils, orderHashUtils } from '@0xproject/order-utils';
|
||||||
import { SignedOrder } from '@0xproject/types';
|
import { SignedOrder } from '@0xproject/types';
|
||||||
import { BigNumber } from '@0xproject/utils';
|
import { BigNumber } from '@0xproject/utils';
|
||||||
import * as chai from 'chai';
|
import * as chai from 'chai';
|
||||||
@ -109,7 +109,7 @@ describe('Exchange libs', () => {
|
|||||||
describe('getDomainSeparatorSchema', () => {
|
describe('getDomainSeparatorSchema', () => {
|
||||||
it('should output the correct domain separator schema hash', async () => {
|
it('should output the correct domain separator schema hash', async () => {
|
||||||
const domainSeparatorSchema = await libs.getDomainSeparatorSchemaHash.callAsync();
|
const domainSeparatorSchema = await libs.getDomainSeparatorSchemaHash.callAsync();
|
||||||
const domainSchemaBuffer = EIP712Utils._getDomainSeparatorSchemaBuffer();
|
const domainSchemaBuffer = eip712Utils._getDomainSeparatorSchemaBuffer();
|
||||||
const schemaHashHex = `0x${domainSchemaBuffer.toString('hex')}`;
|
const schemaHashHex = `0x${domainSchemaBuffer.toString('hex')}`;
|
||||||
expect(schemaHashHex).to.be.equal(domainSeparatorSchema);
|
expect(schemaHashHex).to.be.equal(domainSeparatorSchema);
|
||||||
});
|
});
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { EIP712Schema, EIP712Types, EIP712Utils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
import { EIP712Schema, EIP712Types, eip712Utils, generatePseudoRandomSalt } from '@0xproject/order-utils';
|
||||||
import { SignatureType } from '@0xproject/types';
|
import { SignatureType } from '@0xproject/types';
|
||||||
import * as ethUtil from 'ethereumjs-util';
|
import * as ethUtil from 'ethereumjs-util';
|
||||||
|
|
||||||
@ -31,11 +31,11 @@ export class TransactionFactory {
|
|||||||
signerAddress,
|
signerAddress,
|
||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
const executeTransactionHashBuff = EIP712Utils.structHash(
|
const executeTransactionHashBuff = eip712Utils.structHash(
|
||||||
EIP712_ZEROEX_TRANSACTION_SCHEMA,
|
EIP712_ZEROEX_TRANSACTION_SCHEMA,
|
||||||
executeTransactionData,
|
executeTransactionData,
|
||||||
);
|
);
|
||||||
const txHash = EIP712Utils.createEIP712Message(executeTransactionHashBuff, this._exchangeAddress);
|
const txHash = eip712Utils.createEIP712Message(executeTransactionHashBuff, this._exchangeAddress);
|
||||||
const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType);
|
const signature = signingUtils.signMessage(txHash, this._privateKey, signatureType);
|
||||||
const signedTx = {
|
const signedTx = {
|
||||||
exchangeAddress: this._exchangeAddress,
|
exchangeAddress: this._exchangeAddress,
|
||||||
|
@ -18,14 +18,14 @@ const EIP712_DOMAIN_SCHEMA: EIP712Schema = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const EIP712Utils = {
|
export const eip712Utils = {
|
||||||
/**
|
/**
|
||||||
* Compiles the EIP712Schema and returns the hash of the schema.
|
* Compiles the EIP712Schema and returns the hash of the schema.
|
||||||
* @param schema The EIP712 schema.
|
* @param schema The EIP712 schema.
|
||||||
* @return The hash of the compiled schema
|
* @return The hash of the compiled schema
|
||||||
*/
|
*/
|
||||||
compileSchema(schema: EIP712Schema): Buffer {
|
compileSchema(schema: EIP712Schema): Buffer {
|
||||||
const eip712Schema = EIP712Utils._encodeType(schema);
|
const eip712Schema = eip712Utils._encodeType(schema);
|
||||||
const eip712SchemaHashBuffer = crypto.solSHA3([eip712Schema]);
|
const eip712SchemaHashBuffer = crypto.solSHA3([eip712Schema]);
|
||||||
return eip712SchemaHashBuffer;
|
return eip712SchemaHashBuffer;
|
||||||
},
|
},
|
||||||
@ -36,7 +36,7 @@ export const EIP712Utils = {
|
|||||||
* @return The hash of an EIP712 message with domain separator prefixed
|
* @return The hash of an EIP712 message with domain separator prefixed
|
||||||
*/
|
*/
|
||||||
createEIP712Message(hashStruct: Buffer, contractAddress: string): Buffer {
|
createEIP712Message(hashStruct: Buffer, contractAddress: string): Buffer {
|
||||||
const domainSeparatorHashBuffer = EIP712Utils._getDomainSeparatorHashBuffer(contractAddress);
|
const domainSeparatorHashBuffer = eip712Utils._getDomainSeparatorHashBuffer(contractAddress);
|
||||||
const messageBuff = crypto.solSHA3([EIP191_PREFIX, domainSeparatorHashBuffer, hashStruct]);
|
const messageBuff = crypto.solSHA3([EIP191_PREFIX, domainSeparatorHashBuffer, hashStruct]);
|
||||||
return messageBuff;
|
return messageBuff;
|
||||||
},
|
},
|
||||||
@ -47,7 +47,7 @@ export const EIP712Utils = {
|
|||||||
*/
|
*/
|
||||||
pad32Address(address: string): Buffer {
|
pad32Address(address: string): Buffer {
|
||||||
const addressBuffer = ethUtil.toBuffer(address);
|
const addressBuffer = ethUtil.toBuffer(address);
|
||||||
const addressPadded = EIP712Utils.pad32Buffer(addressBuffer);
|
const addressPadded = eip712Utils.pad32Buffer(addressBuffer);
|
||||||
return addressPadded;
|
return addressPadded;
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -66,17 +66,17 @@ export const EIP712Utils = {
|
|||||||
* @return A buffer containing the SHA256 hash of the schema and encoded data
|
* @return A buffer containing the SHA256 hash of the schema and encoded data
|
||||||
*/
|
*/
|
||||||
structHash(schema: EIP712Schema, data: { [key: string]: any }): Buffer {
|
structHash(schema: EIP712Schema, data: { [key: string]: any }): Buffer {
|
||||||
const encodedData = EIP712Utils._encodeData(schema, data);
|
const encodedData = eip712Utils._encodeData(schema, data);
|
||||||
const schemaHash = EIP712Utils.compileSchema(schema);
|
const schemaHash = eip712Utils.compileSchema(schema);
|
||||||
const hashBuffer = crypto.solSHA3([schemaHash, ...encodedData]);
|
const hashBuffer = crypto.solSHA3([schemaHash, ...encodedData]);
|
||||||
return hashBuffer;
|
return hashBuffer;
|
||||||
},
|
},
|
||||||
_getDomainSeparatorSchemaBuffer(): Buffer {
|
_getDomainSeparatorSchemaBuffer(): Buffer {
|
||||||
return EIP712Utils.compileSchema(EIP712_DOMAIN_SCHEMA);
|
return eip712Utils.compileSchema(EIP712_DOMAIN_SCHEMA);
|
||||||
},
|
},
|
||||||
_getDomainSeparatorHashBuffer(exchangeAddress: string): Buffer {
|
_getDomainSeparatorHashBuffer(exchangeAddress: string): Buffer {
|
||||||
const domainSeparatorSchemaBuffer = EIP712Utils._getDomainSeparatorSchemaBuffer();
|
const domainSeparatorSchemaBuffer = eip712Utils._getDomainSeparatorSchemaBuffer();
|
||||||
const encodedData = EIP712Utils._encodeData(EIP712_DOMAIN_SCHEMA, {
|
const encodedData = eip712Utils._encodeData(EIP712_DOMAIN_SCHEMA, {
|
||||||
name: EIP712_DOMAIN_NAME,
|
name: EIP712_DOMAIN_NAME,
|
||||||
version: EIP712_DOMAIN_VERSION,
|
version: EIP712_DOMAIN_VERSION,
|
||||||
verifyingContract: exchangeAddress,
|
verifyingContract: exchangeAddress,
|
||||||
@ -99,7 +99,7 @@ export const EIP712Utils = {
|
|||||||
} else if (parameter.type === EIP712Types.Uint256) {
|
} else if (parameter.type === EIP712Types.Uint256) {
|
||||||
encodedValues.push(value);
|
encodedValues.push(value);
|
||||||
} else if (parameter.type === EIP712Types.Address) {
|
} else if (parameter.type === EIP712Types.Address) {
|
||||||
encodedValues.push(EIP712Utils.pad32Address(value));
|
encodedValues.push(eip712Utils.pad32Address(value));
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Unable to encode ${parameter.type}`);
|
throw new Error(`Unable to encode ${parameter.type}`);
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ export { orderHashUtils } from './order_hash';
|
|||||||
export { signatureUtils } from './signature_utils';
|
export { signatureUtils } from './signature_utils';
|
||||||
export { generatePseudoRandomSalt } from './salt';
|
export { generatePseudoRandomSalt } from './salt';
|
||||||
export { assetDataUtils } from './asset_data_utils';
|
export { assetDataUtils } from './asset_data_utils';
|
||||||
export { EIP712Utils } from './eip712_utils';
|
export { eip712Utils } from './eip712_utils';
|
||||||
|
|
||||||
export { OrderStateUtils } from './order_state_utils';
|
export { OrderStateUtils } from './order_state_utils';
|
||||||
export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher';
|
export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher';
|
||||||
|
@ -3,7 +3,7 @@ import { Order, SignedOrder } from '@0xproject/types';
|
|||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
import { assert } from './assert';
|
import { assert } from './assert';
|
||||||
import { EIP712Utils } from './eip712_utils';
|
import { eip712Utils } from './eip712_utils';
|
||||||
import { EIP712Schema, EIP712Types } from './types';
|
import { EIP712Schema, EIP712Types } from './types';
|
||||||
|
|
||||||
const INVALID_TAKER_FORMAT = 'instance.takerAddress is not of a type(s) string';
|
const INVALID_TAKER_FORMAT = 'instance.takerAddress is not of a type(s) string';
|
||||||
@ -69,11 +69,11 @@ export const orderHashUtils = {
|
|||||||
* @return The resulting orderHash from hashing the supplied order as a Buffer
|
* @return The resulting orderHash from hashing the supplied order as a Buffer
|
||||||
*/
|
*/
|
||||||
getOrderHashBuffer(order: SignedOrder | Order): Buffer {
|
getOrderHashBuffer(order: SignedOrder | Order): Buffer {
|
||||||
const orderParamsHashBuff = EIP712Utils.structHash(EIP712_ORDER_SCHEMA, order);
|
const orderParamsHashBuff = eip712Utils.structHash(EIP712_ORDER_SCHEMA, order);
|
||||||
const orderHashBuff = EIP712Utils.createEIP712Message(orderParamsHashBuff, order.exchangeAddress);
|
const orderHashBuff = eip712Utils.createEIP712Message(orderParamsHashBuff, order.exchangeAddress);
|
||||||
return orderHashBuff;
|
return orderHashBuff;
|
||||||
},
|
},
|
||||||
_getOrderSchemaBuffer(): Buffer {
|
_getOrderSchemaBuffer(): Buffer {
|
||||||
return EIP712Utils.compileSchema(EIP712_ORDER_SCHEMA);
|
return eip712Utils.compileSchema(EIP712_ORDER_SCHEMA);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user