personalSign method

Future<EthereumData?> personalSign(
  1. EthereumData? message,
  2. EthereumAddress? address, [
  3. String password = ''
])

The sign method calculates an Ethereum specific signature with: sign(keccack256('\x19Ethereum Signed Message:\n' + len(message) + message))). By adding a prefix to the message makes the calculated signature recognisable as an Ethereum specific signature. This prevents misuse where a malicious DApp can sign arbitrary data (e.g. transaction) and use the signature to impersonate the victim. See personalEcRecover to verify the signature.

Implementation

Future<EthereumData?> personalSign(
    EthereumData? message, EthereumAddress? address,
    [String password = '']) async {
  if (message == null) {
    throw ArgumentError.notNull('Ethereum::personalSign - message');
  }
  if (address == null) {
    throw ArgumentError.notNull('Ethereum::personalSign - address');
  }
  const method = EthereumRpcMethods.pSign;
  final params = <String?>[message.asString, address.asString, password];
  final dynamic res = await _client.rpcClient.request(method, params);
  if (res != null && res.containsKey(EthereumConstants.ethResultKey)) {
    return EthereumData.fromString(res[EthereumConstants.ethResultKey]);
  }
  _client.processError(method, res);
  return null;
}