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 sendCustomRequest (request: Partial) {
if (!this._connected) {
throw new Error(ERROR_SESSION_DISCONNECTED)
}
switch (request.method) {
case 'eth_accounts':
return this.accounts
case 'eth_chainId':
return convertNumberToHex(this.chainId)
case 'eth_sendTransaction':
case 'eth_signTransaction':
if (request.params) {
request.params[0] = parseTransactionData(request.params[0])
}
break
case 'personal_sign':
if (request.params) {
request.params = parsePersonalSign(request.params)
}
break
default:
break
}
const formattedRequest = this._formatRequest(request)
try {
const result = await this._sendCallRequest(formattedRequest)
return result
public async sendTransaction (tx: ITxData) {
if (!this._connected) {
throw new Error(ERROR_SESSION_DISCONNECTED)
}
const parsedTx = parseTransactionData(tx)
const request = this._formatRequest({
method: 'eth_sendTransaction',
params: [parsedTx]
})
try {
const result = await this._sendCallRequest(request)
return result
} catch (error) {
throw error
}
}
public async signTransaction (tx: ITxData) {
if (!this._connected) {
throw new Error(ERROR_SESSION_DISCONNECTED)
}
const parsedTx = parseTransactionData(tx)
const request = this._formatRequest({
method: 'eth_signTransaction',
params: [parsedTx]
})
try {
const result = await this._sendCallRequest(request)
return result
} catch (error) {
throw error
}
}