Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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();
},
};
marshalAddress(address: string): string {
if (addressUtils.isAddress(address)) {
return ethUtil.addHexPrefix(address);
}
throw new Error(`Invalid address encountered: ${address}`);
},
/**
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);
};
}
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(
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);
};
}
public static isAddress(address: string): boolean {
return addressUtils.isAddress(address);
}
/**
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);
}
}
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,
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,