eth_sign
Description
In compatProvider.ts
compatProvider.ts.catch(err => callback(err, {
id: payload.id,
jsonrpc: '2.0',
error: err
}));In provider.ts
provider.tsimport { hexToNumber, getErrMsg, toSubscription, toHex, hashEthMessage, bufferToHex } from './utils';this._methodMap['eth_sign'] = this._sign;private _sign = async (params: any) => {
if (!this.wallet || this.wallet.list.length === 0) {
throw new Error("no wallet specified");
}
const address = params[0];
const message = params[1];
const key = this.wallet.list.find((key) => key.address == address);
if (key === undefined) {
throw new Error(`key undefined for address ${address}`)
}
const hash = hashEthMessage(message);
if (hash === undefined) {
throw new Error("undefined hash");
}
const hashStriped = hash?.substring(2);
const buf = Buffer.from(hashStriped!, 'hex');
const signature = await key.sign(buf);
signature[64] += 27;
return bufferToHex(signature);
}In utils.ts
utils.tsIn getChainId.test.ts
getChainId.test.tsContracts Affected
Contract Name
Last updated
Was this helpful?