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 signMessageAsync(address: string, message: string): Promise {
assert.isETHAddressHex('address', address);
assert.isString('message', message); // TODO: Should this be stricter? Hex string?
const signData = await this.sendRawPayloadAsync({
method: 'eth_sign',
params: [address, message],
});
return signData;
}
/**
public async getBalanceInWeiAsync(owner: string, defaultBlock?: BlockParam): Promise {
assert.isETHAddressHex('owner', owner);
if (defaultBlock !== undefined) {
Web3Wrapper._assertBlockParam(defaultBlock);
}
const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
const encodedOwner = marshaller.marshalAddress(owner);
const balanceInWei = await this.sendRawPayloadAsync({
method: 'eth_getBalance',
params: [encodedOwner, marshalledDefaultBlock],
});
// Rewrap in a new BigNumber
return new BigNumber(balanceInWei);
}
/**
public async getContractCodeAsync(address: string, defaultBlock?: BlockParam): Promise {
assert.isETHAddressHex('address', address);
if (defaultBlock !== undefined) {
Web3Wrapper._assertBlockParam(defaultBlock);
}
const marshalledDefaultBlock = marshaller.marshalBlockParam(defaultBlock);
const encodedAddress = marshaller.marshalAddress(address);
const code = await this.sendRawPayloadAsync({
method: 'eth_getCode',
params: [encodedAddress, marshalledDefaultBlock],
});
return code;
}
/**
public async isSenderAddressAvailableAsync(senderAddress: string): Promise {
assert.isETHAddressHex('senderAddress', senderAddress);
const addresses = await this.getAvailableAddressesAsync();
const normalizedAddress = senderAddress.toLowerCase();
return _.includes(addresses, normalizedAddress);
}
/**
public async signPersonalMessageAsync(data: string, address: string): Promise {
if (data === undefined) {
throw new Error(WalletSubproviderErrors.DataMissingForSignPersonalMessage);
}
assert.isHexString('data', data);
assert.isETHAddressHex('address', address);
const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync();
const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, address);
this._ledgerClientIfExists = await this._createLedgerClientAsync();
try {
const fullDerivationPath = derivedKeyInfo.derivationPath;
const result = await this._ledgerClientIfExists.signPersonalMessage(
fullDerivationPath,
ethUtil.stripHexPrefix(data),
);
const lowestValidV = 27;
const v = result.v - lowestValidV;
const hexBase = 16;
let vHex = v.toString(hexBase);
if (vHex.length < 2) {
vHex = `0${v}`;
public async signPersonalMessageAsync(data: string, address: string): Promise {
if (_.isUndefined(data)) {
throw new Error(WalletSubproviderErrors.DataMissingForSignPersonalMessage)
}
assert.isHexString('data', data)
assert.isETHAddressHex('address', address)
const initialDerivedKeyInfo = await this._initialDerivedKeyInfoAsync()
const derivedKeyInfo = this._findDerivedKeyInfoForAddress(initialDerivedKeyInfo, address)
const fullDerivationPath = derivedKeyInfo.derivationPath
const response: TrezorConnectResponse = await this._trezorConnectClientApi.ethereumSignMessage({
path: fullDerivationPath,
message: data,
hex: false
})
if (response.success) {
const payload: TrezorSignMsgResponsePayload = response.payload
return `0x${payload.signature}`
} else {
const payload: TrezorResponseErrorPayload = response.payload
public async signTypedDataAsync(address: string, typedData: EIP712TypedData): Promise {
if (typedData === undefined) {
throw new Error(WalletSubproviderErrors.DataMissingForSignTypedData);
}
assert.isETHAddressHex('address', address);
if (address !== this._address) {
throw new Error(
`Requested to sign message with address: ${address}, instantiated with address: ${this._address}`,
);
}
const dataBuff = signTypedDataUtils.generateTypedDataHash(typedData);
const sig = ethUtil.ecsign(dataBuff, this._privateKeyBuffer);
const rpcSig = ethUtil.toRpcSig(sig.v, sig.r, sig.s);
return rpcSig;
}
}
public async signTypedDataAsync(address: string, typedData: EIP712TypedData): Promise {
if (typedData === undefined) {
throw new Error(WalletSubproviderErrors.DataMissingForSignPersonalMessage);
}
assert.isETHAddressHex('address', address);
const privateKeyWallet = this._privateKeyWalletForAddress(address);
const sig = await privateKeyWallet.signTypedDataAsync(address, typedData);
return sig;
}
private _privateKeyWalletForAddress(address: string): PrivateKeyWalletSubprovider {
async isSenderAddressAsync(
variableName: string,
senderAddressHex: string,
web3Wrapper: Web3Wrapper,
): Promise {
sharedAssert.isETHAddressHex(variableName, senderAddressHex);
const isSenderAddressAvailable = await web3Wrapper.isSenderAddressAvailableAsync(senderAddressHex);
sharedAssert.assert(
isSenderAddressAvailable,
`Specified ${variableName} ${senderAddressHex} isn't available through the supplied web3 provider`,
);
},
};
public async signTypedDataAsync(address: string, typedData: any): Promise {
assert.isETHAddressHex('address', address);
assert.doesConformToSchema('typedData', typedData, schemas.eip712TypedDataSchema);
const signData = await this.sendRawPayloadAsync({
method: 'eth_signTypedData',
params: [address, typedData],
});
return signData;
}
/**