1. /* Sourced from 0x.js */
    2. import { assert as sharedAssert } from '@0xproject/assert';
    3. // 我们需要这两个未使用的导入,因为它们实际上被sharedAssert使用,它被注入到这里
    4. // tslint:disable-next-line:no-unused-variable
    5. import { Schema } from '@0xproject/json-schemas';
    6. // tslint:disable-next-line:no-unused-variable
    7. import { BigNumber } from '@0xproject/utils';
    8. import { Web3Wrapper } from '@0xproject/web3-wrapper';
    9. import * as _ from 'lodash';
    10. import { ECSignature } from '../types';
    11. import { signatureUtils } from '../utils/signature_utils';
    12. export const assert = {
    13. ...sharedAssert,
    14. isValidSignature(orderHash: string, ecSignature: ECSignature, signerAddress: string) {
    15. const isValidSignature = signatureUtils.isValidSignature(orderHash, ecSignature, signerAddress);
    16. this.assert(isValidSignature, `Expected order with hash '${orderHash}' to have a valid signature`);
    17. },
    18. async isSenderAddressAsync(
    19. variableName: string,
    20. senderAddressHex: string,
    21. web3Wrapper: Web3Wrapper,
    22. ): Promise<void> {
    23. sharedAssert.isETHAddressHex(variableName, senderAddressHex);
    24. const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
    25. sharedAssert.assert(
    26. isSenderAddressAvailable,
    27. `Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
    28. );
    29. },
    30. async isUserAddressAvailableAsync(web3Wrapper: Web3Wrapper): Promise<void> {
    31. const availableAddresses = await web3Wrapper.getAvailableAddressesAsync();
    32. this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 provider');
    33. },
    34. };