formatAuthMessage method

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

format payload to message string

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);
  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 resources = cacaoPayload.resources != null &&
          cacaoPayload.resources!.isNotEmpty
      ? 'Resources:\n${cacaoPayload.resources!.map((resource) => '- $resource').join('\n')}'
      : null;

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

  return message;
}