signMessageRequest method

  1. @override
Future<String> signMessageRequest(
  1. String message, {
  2. required W3MSession session,
})
override

Implementation

@override
Future<String> signMessageRequest(
  String message, {
  required W3MSession session,
}) async {
  if (!enabled) throw Exception('siweConfig not enabled');
  //
  final chainId = AuthSignature.getChainIdFromMessage(message);
  final chain = W3MChainPresets.chains[chainId]!.namespace;
  final address = AuthSignature.getAddressFromMessage(message);
  final bytes = utf8.encode(message);
  final encoded = hex.encode(bytes);
  //
  if (session.sessionService.isMagic) {
    return await magicService.instance.request(
      chainId: chain,
      request: SessionRequestParams(
        method: 'personal_sign',
        params: ['0x$encoded', address],
      ),
    );
  }
  if (session.sessionService.isCoinbase) {
    return await coinbaseService.instance.request(
      chainId: chain,
      request: SessionRequestParams(
        method: 'personal_sign',
        params: ['0x$encoded', address],
      ),
    );
  }
  return await _web3app.request(
    topic: session.topic!,
    chainId: chain,
    request: SessionRequestParams(
      method: 'personal_sign',
      params: ['0x$encoded', address],
    ),
  );
}