From 45e9fbe8f93f68f3786629fff1861b1a66b90635 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 31 Jul 2018 17:24:19 +0800 Subject: Introduce SignerProviderType This allows the developer to indicate the nuanced signer provider. Some have different implementations (trezor, ledger) and others have different implementations (metamask). Breaking the abstraction of eth_sign. EthSign assumes a spec compliant implementation and can be used as a default --- packages/0x.js/src/0x.ts | 20 +++++++++++++------- packages/0x.js/src/index.ts | 2 +- 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'packages/0x.js/src') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 2a2b82f63..86859c368 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -14,13 +14,19 @@ import { ecSignOrderHashAsync, generatePseudoRandomSalt, isValidSignatureAsync, - MessagePrefixOpts, orderHashUtils, } from '@0xproject/order-utils'; // 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 { + AssetProxyId, + ERC20AssetData, + ERC721AssetData, + Order, + SignedOrder, + SignerProviderType, +} from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; @@ -238,19 +244,19 @@ 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 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. + * @param SignerProviderType The type of Signer Provider which implements `eth_sign`. E.g Metamask, Ledger, Trezor or EthSign. + * @return A hex encoded string of the Elliptic curve signature parameters generated by signing the orderHash and signature type. */ public async ecSignOrderHashAsync( orderHash: string, signerAddress: string, - messagePrefixOpts: MessagePrefixOpts, - ): Promise { + signerProviderType: SignerProviderType, + ): Promise { const signature = await ecSignOrderHashAsync( this._contractWrappers.getProvider(), orderHash, signerAddress, - messagePrefixOpts, + signerProviderType, ); return signature; } diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 95ca07eea..1e5c0c270 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -1,12 +1,12 @@ export { ZeroEx } from './0x'; -export { MessagePrefixType, MessagePrefixOpts } from '@0xproject/order-utils'; export { Web3ProviderEngine, RPCSubprovider } from '@0xproject/subproviders'; export { ExchangeContractErrs, Order, SignedOrder, + SignerProviderType, ECSignature, OrderStateValid, OrderStateInvalid, -- cgit v1.2.3 From ca4905c3436931684d113ec66882836a4d0b265b Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 9 Aug 2018 12:24:52 +1000 Subject: Rename from SignerProviderType.EthSign to SignerType.Default --- packages/0x.js/src/0x.ts | 17 ++++++----------- packages/0x.js/src/index.ts | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) (limited to 'packages/0x.js/src') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 86859c368..80d784552 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -19,14 +19,7 @@ import { // 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, - ERC20AssetData, - ERC721AssetData, - Order, - SignedOrder, - SignerProviderType, -} from '@0xproject/types'; +import { AssetProxyId, ERC20AssetData, ERC721AssetData, Order, SignedOrder, SignerType } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; @@ -244,19 +237,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 SignerProviderType The type of Signer Provider which implements `eth_sign`. E.g Metamask, Ledger, Trezor or EthSign. + * @param signerType the type signer that will perform the `eth_sign` operation. E.g Default, Metamask, Ledger or Trezor. + * Some implementations exhibit different behaviour. Default will assume a spec compliant eth_sign implementation. + * This parameter is defaulted to `SignerType.Default`. * @return A hex encoded string of the Elliptic curve signature parameters generated by signing the orderHash and signature type. */ public async ecSignOrderHashAsync( orderHash: string, signerAddress: string, - signerProviderType: SignerProviderType, + signerType: SignerType = SignerType.Default, ): Promise { const signature = await ecSignOrderHashAsync( this._contractWrappers.getProvider(), orderHash, signerAddress, - signerProviderType, + signerType, ); return signature; } diff --git a/packages/0x.js/src/index.ts b/packages/0x.js/src/index.ts index 1e5c0c270..2ba60e730 100644 --- a/packages/0x.js/src/index.ts +++ b/packages/0x.js/src/index.ts @@ -6,7 +6,7 @@ export { ExchangeContractErrs, Order, SignedOrder, - SignerProviderType, + SignerType, ECSignature, OrderStateValid, OrderStateInvalid, -- cgit v1.2.3 From a3517574936aa6a4911003dbff06302926b04cb4 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Tue, 14 Aug 2018 08:32:16 +1000 Subject: Update version numbers. Add source for Metamask future fix. Consolidate switch statement to one return --- packages/0x.js/src/0x.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/0x.js/src') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 80d784552..48d00c1ac 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -237,7 +237,7 @@ 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 signerType the type signer that will perform the `eth_sign` operation. E.g Default, Metamask, Ledger or Trezor. + * @param signerType the signer type that will perform the `eth_sign` operation. E.g Default, Metamask, Ledger or Trezor. * Some implementations exhibit different behaviour. Default will assume a spec compliant eth_sign implementation. * This parameter is defaulted to `SignerType.Default`. * @return A hex encoded string of the Elliptic curve signature parameters generated by signing the orderHash and signature type. -- cgit v1.2.3