importPublicKeys function

List<ImportedKey> importPublicKeys(
  1. Iterable<Object?> jwks
)

Imports the public Ed25519 JWKs of jwks; anything else (including private keys) is skipped.

Implementation

List<ImportedKey> importPublicKeys(Iterable<Object?> jwks) {
  final out = <ImportedKey>[];
  for (final jwk in jwks) {
    if (!isPublicEd25519Jwk(jwk)) continue;
    final m = jwk as Map;
    try {
      final x = base64UrlDecodeStrict(m['x'] as String);
      if (x.length != 32) continue;
      // Only the public member is used: kid/use/alg/key_ops never influence the key.
      out.add(ImportedKey(m['kid'] is String ? m['kid'] as String : null, SimplePublicKey(x, type: KeyPairType.ed25519)));
    } on FormatException {
      continue;
    }
  }
  return out;
}