From 22d3981a7419d088f2bef53da77bcfe6771ebd94 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 11 Jul 2018 12:34:13 +0200 Subject: Temporarily remove OrderWatcher from 0x.js --- packages/0x.js/src/0x.ts | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 001f336e7..3d2f23002 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -15,7 +15,6 @@ import { isValidSignature, signOrderHashAsync, } from '@0xproject/order-utils'; -import { OrderWatcher, OrderWatcherConfig } from '@0xproject/order-watcher'; import { ECSignature, Order, Provider, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -211,18 +210,4 @@ export class ZeroEx { ); return transactionReceiptWithDecodedLogs; } - /** - * Instantiates and returns a new OrderWatcher instance. - * Defaults to watching the pending state. - * @param config The configuration object. Look up the type for the description. - * @return An instance of the 0x.js OrderWatcher class. - */ - public async createOrderWatcherAsync(config?: OrderWatcherConfig): Promise { - // Hack: Get Web3Wrapper from ContractWrappers - const web3Wrapper: Web3Wrapper = (this._contractWrappers as any)._web3Wrapper; - const networkId = await web3Wrapper.getNetworkIdAsync(); - const provider = this._contractWrappers.getProvider(); - const orderWatcher = new OrderWatcher(provider, networkId, config); - return orderWatcher; - } } -- cgit v1.2.3 From 3824ea9079f3034fb34750c8b80125462f42c79c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 11 Jul 2018 18:46:12 +0200 Subject: Remove TokenRegistry from 0x.js --- packages/0x.js/src/0x.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 3d2f23002..c6315ac7a 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -2,11 +2,10 @@ import { assert } from '@0xproject/assert'; import { ContractWrappers, ContractWrappersConfig, + ERC20ProxyWrapper, + ERC20TokenWrapper, EtherTokenWrapper, ExchangeWrapper, - TokenRegistryWrapper, - TokenTransferProxyWrapper, - TokenWrapper, } from '@0xproject/contract-wrappers'; import { generatePseudoRandomSalt, @@ -37,10 +36,7 @@ export class ZeroEx { */ public exchange: ExchangeWrapper; /** - * An instance of the TokenRegistryWrapper class containing methods for interacting with the 0x - * TokenRegistry smart contract. */ - public tokenRegistry: TokenRegistryWrapper; /** * An instance of the TokenWrapper class containing methods for interacting with any ERC20 token smart contract. */ @@ -136,7 +132,6 @@ export class ZeroEx { this.proxy = this._contractWrappers.proxy; this.token = this._contractWrappers.token; this.exchange = this._contractWrappers.exchange; - this.tokenRegistry = this._contractWrappers.tokenRegistry; this.etherToken = this._contractWrappers.etherToken; } /** -- cgit v1.2.3 From b6ac132c789939414e2aba911246e6a931facea4 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 11 Jul 2018 18:53:50 +0200 Subject: Refactor 0x.js to V2 --- packages/0x.js/src/0x.ts | 82 +++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 33 deletions(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index c6315ac7a..597bc07a5 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -4,19 +4,22 @@ import { ContractWrappersConfig, ERC20ProxyWrapper, ERC20TokenWrapper, + ERC721ProxyWrapper, + ERC721TokenWrapper, EtherTokenWrapper, ExchangeWrapper, } from '@0xproject/contract-wrappers'; import { + ecSignOrderHashAsync, generatePseudoRandomSalt, - getOrderHashHex, - isValidOrderHash, - isValidSignature, - signOrderHashAsync, + isValidSignatureAsync, + MessagePrefixOpts, + orderHashUtils, } from '@0xproject/order-utils'; -import { ECSignature, Order, Provider, SignedOrder, TransactionReceiptWithDecodedLogs } from '@0xproject/types'; +import { ECSignature, Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; import { constants } from './utils/constants'; @@ -36,21 +39,28 @@ export class ZeroEx { */ public exchange: ExchangeWrapper; /** + * An instance of the ERC20TokenWrapper class containing methods for interacting with any ERC20 token smart contract. */ + public erc20Token: ERC20TokenWrapper; /** - * An instance of the TokenWrapper class containing methods for interacting with any ERC20 token smart contract. + * An instance of the ERC721TokenWrapper class containing methods for interacting with any ERC721 token smart contract. */ - public token: TokenWrapper; + public erc721Token: ERC721TokenWrapper; /** * An instance of the EtherTokenWrapper class containing methods for interacting with the * wrapped ETH ERC20 token smart contract. */ public etherToken: EtherTokenWrapper; /** - * An instance of the TokenTransferProxyWrapper class containing methods for interacting with the - * tokenTransferProxy smart contract. + * An instance of the ERC20ProxyWrapper class containing methods for interacting with the + * ERC20 proxy smart contract. */ - public proxy: TokenTransferProxyWrapper; + public erc20Proxy: ERC20ProxyWrapper; + /** + * An instance of the ERC721ProxyWrapper class containing methods for interacting with the + * ERC721 proxy smart contract. + */ + public erc721Proxy: ERC721ProxyWrapper; private _contractWrappers: ContractWrappers; /** * Generates a pseudo-random 256-bit salt. @@ -61,24 +71,13 @@ export class ZeroEx { public static generatePseudoRandomSalt(): BigNumber { return generatePseudoRandomSalt(); } - /** - * Verifies that the elliptic curve signature `signature` was generated - * by signing `data` with the private key corresponding to the `signerAddress` address. - * @param data The hex encoded data signed by the supplied signature. - * @param signature An object containing the elliptic curve signature parameters. - * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. - * @return Whether the signature is valid for the supplied signerAddress and data. - */ - public static isValidSignature(data: string, signature: ECSignature, signerAddress: string): boolean { - return isValidSignature(data, signature, signerAddress); - } /** * Computes the orderHash for a supplied order. * @param order An object that conforms to the Order or SignedOrder interface definitions. * @return The resulting orderHash from hashing the supplied order. */ public static getOrderHashHex(order: Order | SignedOrder): string { - return getOrderHashHex(order); + return orderHashUtils.getOrderHashHex(order); } /** * Checks if the supplied hex encoded order hash is valid. @@ -88,7 +87,7 @@ export class ZeroEx { * @return Whether the supplied orderHash has the expected format. */ public static isValidOrderHash(orderHash: string): boolean { - return isValidOrderHash(orderHash); + return orderHashUtils.isValidOrderHash(orderHash); } /** * A unit amount is defined as the amount of a token above the specified decimal places (integer part). @@ -129,11 +128,30 @@ export class ZeroEx { assert.isWeb3Provider('provider', provider); this._contractWrappers = new ContractWrappers(provider, config); - this.proxy = this._contractWrappers.proxy; - this.token = this._contractWrappers.token; + this.erc20Proxy = this._contractWrappers.erc20Proxy; + this.erc721Proxy = this._contractWrappers.erc721Proxy; + this.erc20Token = this._contractWrappers.erc20Token; + this.erc721Token = this._contractWrappers.erc721Token; this.exchange = this._contractWrappers.exchange; this.etherToken = this._contractWrappers.etherToken; } + /** + * Verifies that the provided signature is valid according to the 0x Protocol smart contracts + * @param provider The Web3Provider to use. Some signature types involve checking contract state. + * @param data The hex encoded data signed by the supplied signature. + * @param signature The hex encoded signature. + * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. + * @return Whether the signature is valid for the supplied signerAddress and data. + */ + public async isValidSignatureAsync(data: string, signature: string, signerAddress: string): Promise { + const isValid = await isValidSignatureAsync( + this._contractWrappers.getProvider(), + data, + signature, + signerAddress, + ); + return isValid; + } /** * Sets a new web3 provider for 0x.js. Updating the provider will stop all * subscriptions so you will need to re-subscribe to all events relevant to your app after this call. @@ -166,23 +184,21 @@ export class ZeroEx { * @param orderHash Hex encoded orderHash to sign. * @param signerAddress The hex encoded Ethereum address you wish to sign it with. This address * must be available via the Provider supplied to 0x.js. - * @param shouldAddPersonalMessagePrefix Some signers add the personal message prefix `\x19Ethereum Signed Message` - * themselves (e.g Parity Signer, Ledger, TestRPC) and others expect it to already be done by the client - * (e.g Metamask). Depending on which signer this request is going to, decide on whether to add the prefix - * before sending the request. + * @param MessagePrefixOpts Options regarding the desired prefix and whether to add it before calling `eth_sign` * @return An object containing the Elliptic curve signature parameters generated by signing the orderHash. */ - public async signOrderHashAsync( + public async ecSignOrderHashAsync( orderHash: string, signerAddress: string, - shouldAddPersonalMessagePrefix: boolean, + messagePrefixOpts: MessagePrefixOpts, ): Promise { - return signOrderHashAsync( + const signature = await ecSignOrderHashAsync( this._contractWrappers.getProvider(), orderHash, signerAddress, - shouldAddPersonalMessagePrefix, + messagePrefixOpts, ); + return signature; } /** * Waits for a transaction to be mined and returns the transaction receipt. -- cgit v1.2.3 From b0a57a50911e6ce669a12cefff16e5ed6749feb9 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 12 Jul 2018 15:25:25 +0200 Subject: remove non-existent param comment --- packages/0x.js/src/0x.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 597bc07a5..5d9a03719 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -137,7 +137,6 @@ export class ZeroEx { } /** * Verifies that the provided signature is valid according to the 0x Protocol smart contracts - * @param provider The Web3Provider to use. Some signature types involve checking contract state. * @param data The hex encoded data signed by the supplied signature. * @param signature The hex encoded signature. * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. -- cgit v1.2.3 From bf8ac3b9e6ee59f267f7850418febfe84dedceb8 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 17 Jul 2018 12:59:02 +0200 Subject: Fix tslint issues --- packages/0x.js/src/0x.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 5d9a03719..1d33eb7ca 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -61,7 +61,7 @@ export class ZeroEx { * ERC721 proxy smart contract. */ public erc721Proxy: ERC721ProxyWrapper; - private _contractWrappers: ContractWrappers; + private readonly _contractWrappers: ContractWrappers; /** * Generates a pseudo-random 256-bit salt. * The salt can be included in a 0x order, ensuring that the order generates a unique orderHash -- cgit v1.2.3 From 94ea7cc45104f9225bcb1d1905ffc4f2dbf27348 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 15:31:25 +0200 Subject: Export assetDataUtils from 0x.js --- packages/0x.js/src/0x.ts | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 5d9a03719..11ceb7c89 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -10,6 +10,7 @@ import { ExchangeWrapper, } from '@0xproject/contract-wrappers'; import { + assetDataUtils, ecSignOrderHashAsync, generatePseudoRandomSalt, isValidSignatureAsync, @@ -34,6 +35,10 @@ export class ZeroEx { * this constant for your convenience. */ public static NULL_ADDRESS = constants.NULL_ADDRESS; + /** + * A set of methods to easily decode/encode assetData fields found in 0x orders. + */ + public assetData = assetDataUtils; /** * An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract. */ -- cgit v1.2.3 From f2393de59bf77806281ebabfad9f4500dd183f4a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 17 Jul 2018 15:33:49 +0200 Subject: Make assetData a static property and add to CHANGELOG --- packages/0x.js/src/0x.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 11ceb7c89..e321b4020 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -38,7 +38,7 @@ export class ZeroEx { /** * A set of methods to easily decode/encode assetData fields found in 0x orders. */ - public assetData = assetDataUtils; + public static assetData = assetDataUtils; /** * An instance of the ExchangeWrapper class containing methods for interacting with the 0x Exchange smart contract. */ -- cgit v1.2.3 From 7c0775aa1b08de8c626e7b9aad0b3ca1a3d3c7b5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 18 Jul 2018 17:00:07 +0200 Subject: Fix 0x.js ts warnings --- packages/0x.js/src/0x.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packages/0x.js/src/0x.ts') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 385ba76b5..7c06a53af 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -17,7 +17,10 @@ import { MessagePrefixOpts, orderHashUtils, } from '@0xproject/order-utils'; -import { ECSignature, Order, SignedOrder } from '@0xproject/types'; +// HACK: Since we export assetDataUtils from ZeroEx and it has AssetProxyId, ERC20AssetData and ERC721AssetData +// in it's public interface, we need to import these types here. +// tslint:disable-next-line:no-unused-variable +import { AssetProxyId, ECSignature, ERC20AssetData, ERC721AssetData, Order, SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; -- cgit v1.2.3