formatAuthMessage method

  1. @override
String formatAuthMessage({
  1. required String iss,
  2. required CacaoRequestPayload cacaoPayload,
})
override

Implementation

@override
String formatAuthMessage({
  required String iss,
  required CacaoRequestPayload cacaoPayload,
}) {
  final header =
      '${cacaoPayload.domain} wants you to sign in with your Ethereum account:';
  final walletAddress = AddressUtils.getDidAddress(iss);

  if (cacaoPayload.aud.isEmpty) {
    throw WalletConnectError(code: -1, message: 'aud is required');
  }

  String statement = cacaoPayload.statement ?? '';
  final uri = 'URI: ${cacaoPayload.aud}';
  final version = 'Version: ${cacaoPayload.version}';
  final chainId = 'Chain ID: ${AddressUtils.getDidChainId(iss)}';
  final nonce = 'Nonce: ${cacaoPayload.nonce}';
  final issuedAt = 'Issued At: ${cacaoPayload.iat}';
  final expirationTime = (cacaoPayload.exp != null)
      ? 'Expiration Time: ${cacaoPayload.exp}'
      : null;
  final notBefore =
      (cacaoPayload.nbf != null) ? 'Not Before: ${cacaoPayload.nbf}' : null;
  final requestId = (cacaoPayload.requestId != null)
      ? 'Request ID: ${cacaoPayload.requestId}'
      : null;
  final resources = cacaoPayload.resources != null &&
          cacaoPayload.resources!.isNotEmpty
      ? 'Resources:\n${cacaoPayload.resources!.map((resource) => '- $resource').join('\n')}'
      : null;
  final recap = ReCapsUtils.getRecapFromResources(
    resources: cacaoPayload.resources,
  );
  if (recap != null) {
    final decoded = ReCapsUtils.decodeRecap(recap);
    statement = ReCapsUtils.formatStatementFromRecap(
      statement: statement,
      recap: decoded,
    );
  }

  final message = [
    header,
    walletAddress.toEIP55(),
    '',
    statement,
    '',
    uri,
    version,
    chainId,
    nonce,
    issuedAt,
    expirationTime,
    notBefore,
    requestId,
    resources,
  ].where((element) => element != null).join('\n');

  return message;
}