getGovernmentRsaPubKey static method

Future<CommercioRSAPublicKey> getGovernmentRsaPubKey(
  1. Uri lcdUrl, {
  2. Client? client,
})

encrypting the data that only it should see. Returns the RSA public key associated to the government that should be used when

Implementation

static Future<CommercioRSAPublicKey> getGovernmentRsaPubKey(
  Uri lcdUrl, {
  http.Client? client,
}) async {
  final tumblerResponse = await Network.query(
    Uri.parse('${lcdUrl.toString()}/government/tumbler'),
    client: client,
  );

  if (tumblerResponse == null) {
    throw const FormatException('Cannot get tumbler address');
  }

  final tumbler = TumblerResponse.fromJson(jsonDecode(tumblerResponse));
  final tumblerAddress = tumbler.result.tumblerAddress;
  final identityResponseRaw = await Network.query(
    Uri.parse('${lcdUrl.toString()}/identities/$tumblerAddress'),
    client: client,
  );

  if (identityResponseRaw == null) {
    throw const FormatException('Cannot get tumbler RSA public key');
  }

  final identityResponse =
      IdentityResponse.fromJson(jsonDecode(identityResponseRaw));

  final didPubKey = identityResponse.result.didDocument.publicKeys[1];

  if (didPubKey == null) {
    throw Exception('Could not find the governement public key');
  }

  final rsaPublicKey =
      RSAKeyParser.parseFromPem(didPubKey.publicKeyPem) as RSAPublicKey;

  return CommercioRSAPublicKey(
    rsaPublicKey,
    keyType: CommercioRSAKeyType.verification,
  );
}