mastra-ai/mastra · error

Unsupported JWS algorithm for A2A Agent Card signing: ${alg}

Error message

Unsupported JWS algorithm for A2A Agent Card signing: ${alg}

What it means

When signing an A2A Agent Card, getProtectedHeader() validates the JWS 'alg' from A2AAgentCardSigningConfig.protectedHeader against SUPPORTED_JWS_ALGORITHMS (ES256/384/512, RS256/384/512, PS256/384/512). Asymmetric algorithms only — HMAC (HS*) and others are rejected — so the error fires when an unsupported algorithm name is configured.

Source

Thrown at packages/server/src/server/a2a/agent-card-signing.ts:41

function importSigningKey(signing: A2AAgentCardSigningConfig) {
  const { privateKey } = signing;

  if (typeof privateKey === 'string') {
    return crypto.createPrivateKey(privateKey);
  }

  return crypto.createPrivateKey({
    key: privateKey,
    format: 'jwk',
  });
}

function getProtectedHeader(signing: A2AAgentCardSigningConfig): Record<string, unknown> {
  const { alg, ...rest } = signing.protectedHeader;

  if (!SUPPORTED_JWS_ALGORITHMS.has(alg)) {
    throw new Error(`Unsupported JWS algorithm for A2A Agent Card signing: ${alg}`);
  }

  return {
    ...rest,
    alg,
  };
}

type SignatureOptions = Pick<crypto.SignKeyObjectInput, 'dsaEncoding' | 'padding' | 'saltLength'>;

function getSignatureOptions(algorithm: string): SignatureOptions {
  if (algorithm.startsWith('ES')) {
    return { dsaEncoding: 'ieee-p1363' as const };
  }

  if (algorithm.startsWith('PS')) {
    return {
      padding: crypto.constants.RSA_PKCS1_PSS_PADDING,

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Change alg to a supported asymmetric algorithm: ES256/ES384/ES512, RS256/RS384/RS512, or PS256/PS384/PS512.
  2. Replace any HMAC/shared-secret key with an EC or RSA private key matching the chosen algorithm.
  3. Fix casing/typos — alg values are exact case-sensitive strings ('ES256', not 'es256').
  4. For Ed25519 keys, generate an EC P-256/384/521 or RSA key instead, since EdDSA is not supported.

Example fix

// before
signing: { privateKey, protectedHeader: { alg: 'HS256' } }
// after
signing: { privateKey, protectedHeader: { alg: 'ES256' } }
Defensive patterns

Strategy: validation

Validate before calling

const SUPPORTED = new Set(['ES256','ES384','ES512','RS256','RS384','RS512','PS256','PS384','PS512']);
if (!SUPPORTED.has(signing.protectedHeader.alg)) {
  throw new Error(`alg must be one of ${[...SUPPORTED].join(', ')}`);
}

Type guard

type SupportedJwsAlg = 'ES256'|'ES384'|'ES512'|'RS256'|'RS384'|'RS512'|'PS256'|'PS384'|'PS512';
const isSupportedAlg = (a: string): a is SupportedJwsAlg =>
  /^(ES|RS|PS)(256|384|512)$/.test(a);

Try / catch

try {
  const signed = await signAgentCard({ agentCard, signing });
} catch (e) {
  if (e.message.includes('Unsupported JWS algorithm')) {
    throw new ConfigError('A2A signing alg must be ES/RS/PS with 256/384/512');
  }
  throw e;
}

Prevention

When it happens

Trigger: Setting signing.protectedHeader.alg to e.g. 'HS256', 'ES256K', 'EdDSA', or any string not in the supported set when configuring A2A agent card signing.

Common situations: Copying a JWT config that uses HS256 with a shared secret; typo in the alg string; using an octet/Ed25519 key with EdDSA; assuming all RFC 7518 algorithms are supported.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/571b9aa97d7d96e4. Report an issue: GitHub.