How to use the @0x/utils.addressUtils.isAddress function in @0x/utils

To help you get started, we’ve selected a few @0x/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / ledger.ts View on Github external
public async signTransactionAsync(txParams: PartialTxParams): Promise {
        LedgerSubprovider._validateTxParams(txParams);
        if (txParams.from === undefined || !addressUtils.isAddress(txParams.from)) {
            throw new Error(WalletSubproviderErrors.FromAddressMissingOrInvalid);
        }
        const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync();
        const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, txParams.from);

        this._ledgerClientIfExists = await this._createLedgerClientAsync();

        const tx = new EthereumTx(txParams);

        // Set the EIP155 bits
        const vIndex = 6;
        tx.raw[vIndex] = Buffer.from([this._networkId]); // v
        const rIndex = 7;
        tx.raw[rIndex] = Buffer.from([]); // r
        const sIndex = 8;
        tx.raw[sIndex] = Buffer.from([]); // s
github 0xProject / 0x-monorepo / packages / testnet-faucets / src / ts / parameter_transformer.ts View on Github external
transform(req: Request, res: Response, next: NextFunction): void {
        const recipientAddress = req.params.recipient;
        if (recipientAddress === undefined || !addressUtils.isAddress(recipientAddress)) {
            res.status(constants.BAD_REQUEST_STATUS).send('INVALID_RECIPIENT_ADDRESS');
            return;
        }
        const lowerCaseRecipientAddress = recipientAddress.toLowerCase();
        req.params.recipient = lowerCaseRecipientAddress;
        const chainId = _.get(req.query, 'chainId', DEFAULT_CHAIN_ID);
        const rpcUrlIfExists = _.get(rpcUrls, chainId);
        if (rpcUrlIfExists === undefined) {
            res.status(constants.BAD_REQUEST_STATUS).send('UNSUPPORTED_CHAIN_ID');
            return;
        }
        req.params.chainId = chainId;
        next();
    },
};
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / marshaller.ts View on Github external
marshalAddress(address: string): string {
        if (addressUtils.isAddress(address)) {
            return ethUtil.addHexPrefix(address);
        }
        throw new Error(`Invalid address encountered: ${address}`);
    },
    /**
github 0xProject / 0x-monorepo / packages / website / ts / pages / instant / config_generator_address_input.tsx View on Github external
private readonly _handleChange = (event: React.ChangeEvent): void => {
        const address = event.target.value;
        const isValidAddress = addressUtils.isAddress(address.toLowerCase()) || address === '';
        const errMsg = isValidAddress ? '' : 'Please enter a valid Ethereum address';
        this.setState({
            errMsg,
        });
        this.props.onChange(address, isValidAddress);
    };
}
github 0xProject / 0x-monorepo / packages / assert / src / index.ts View on Github external
isETHAddressHex(variableName: string, value: string): void {
        assert.assert(_.isString(value), assert.typeAssertionMessage(variableName, 'string', value));
        assert.assert(addressUtils.isAddress(value), assert.typeAssertionMessage(variableName, 'ETHAddressHex', value));
    },
    doesBelongToStringEnum(
github 0xProject / 0x-monorepo / packages / website / ts / @next / pages / instant / config_generator_address_input.tsx View on Github external
private readonly _handleChange = (event: React.ChangeEvent): void => {
        const address = event.target.value;
        const isValidAddress = addressUtils.isAddress(address.toLowerCase()) || address === '';
        const errMsg = isValidAddress ? '' : 'Please enter a valid Ethereum address';
        this.setState({
            errMsg,
        });
        this.props.onChange(address, isValidAddress);
    };
}
github 0xProject / 0x-monorepo / packages / web3-wrapper / src / web3_wrapper.ts View on Github external
public static isAddress(address: string): boolean {
        return addressUtils.isAddress(address);
    }
    /**
github 0xProject / 0x-monorepo / packages / website / ts / components / inputs / address_input.tsx View on Github external
private _onOrderTakerAddressUpdated(e: any): void {
        const address = e.target.value.toLowerCase();
        const isValidAddress = addressUtils.isAddress(address) || address === '';
        const errMsg = isValidAddress ? '' : 'Invalid ethereum address';
        this.setState({
            address,
            errMsg,
        });
        const addressIfValid = isValidAddress ? address : undefined;
        this.props.updateAddress(addressIfValid);
    }
}
github 0xProject / 0x-monorepo / packages / subproviders / src / subproviders / trezor.ts View on Github external
public async signTransactionAsync(txData: PartialTxParams): Promise {
        if (txData.from === undefined || !addressUtils.isAddress(txData.from)) {
            throw new Error(WalletSubproviderErrors.FromAddressMissingOrInvalid);
        }
        txData.value = txData.value ? txData.value : '0x0';
        txData.data = txData.data ? txData.data : '0x';
        txData.gas = txData.gas ? txData.gas : '0x0';
        txData.gasPrice = txData.gasPrice ? txData.gasPrice : '0x0';

        const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync();
        const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, txData.from);
        const fullDerivationPath = derivedKeyInfo.derivationPath;

        const response: TrezorConnectResponse = await this._trezorConnectClientApi.ethereumSignTransaction({
            path: fullDerivationPath,
            transaction: {
                to: txData.to,
                value: txData.value,
github NoahZinsmeister / web3-react / src / connectors / trezor / subprovider.ts View on Github external
public async signTransactionAsync(txData: PartialTxParams): Promise {
    if (_.isUndefined(txData.from) || !addressUtils.isAddress(txData.from)) {
      throw new Error(WalletSubproviderErrors.FromAddressMissingOrInvalid)
    }
    txData.value = txData.value ? txData.value : '0x0'
    txData.data = txData.data ? txData.data : '0x'
    txData.gas = txData.gas ? txData.gas : '0x0'
    txData.gasPrice = txData.gasPrice ? txData.gasPrice : '0x0'

    const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync()
    const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, txData.from)
    const fullDerivationPath = derivedKeyInfo.derivationPath

    const response: TrezorConnectResponse = await this._trezorConnectClientApi.ethereumSignTransaction({
      path: fullDerivationPath,
      transaction: {
        to: txData.to,
        value: txData.value,