From 0beab9eec45508fb6163bd6c0fd3970f0b61a91d Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 30 May 2018 17:55:33 -0700 Subject: Expose isValidPresignedSignatureAsync method --- packages/order-utils/src/signature_utils.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/order-utils/src/signature_utils.ts b/packages/order-utils/src/signature_utils.ts index 70637e2ac..f1466973c 100644 --- a/packages/order-utils/src/signature_utils.ts +++ b/packages/order-utils/src/signature_utils.ts @@ -66,9 +66,7 @@ export async function isValidSignatureAsync( } case SignatureType.PreSigned: { - const exchangeContract = new ExchangeContract(artifacts.Exchange.abi, signerAddress, provider); - const isValid = await exchangeContract.preSigned.callAsync(data, signerAddress); - return true; + return isValidPresignedSignatureAsync(provider, data, signature, signerAddress); } default: @@ -76,6 +74,24 @@ export async function isValidSignatureAsync( } } +/** + * Verifies that the provided presigned signature is valid according to the 0x Protocol smart contracts + * @param data The hex encoded data signed by the supplied signature. + * @param signature A hex encoded presigned 0x Protocol signature made up of: [SignatureType.Presigned] + * @param signerAddress The hex encoded address that signed the data, producing the supplied signature. + * @return Whether the data was preSigned by the supplied signerAddress. + */ +export async function isValidPresignedSignatureAsync( + provider: Provider, + data: string, + signature: string, + signerAddress: string, +): Promise { + const exchangeContract = new ExchangeContract(artifacts.Exchange.abi, signerAddress, provider); + const isValid = await exchangeContract.preSigned.callAsync(data, signerAddress); + return isValid; +} + /** * Checks if the supplied elliptic curve signature corresponds to signing `data` with * the private key corresponding to `signerAddress` -- cgit v1.2.3