grafana/k6 · error

unsupported algorithm {alg}

Error message

unsupported algorithm {alg}

What it means

extractPublicKeyBytes (internal/js/modules/k6/webcrypto/elliptic_curve.go:467) serializes an elliptic-curve public key to raw bytes and handles exactly two algorithm names: ECDH (via ecdh.PublicKey.Bytes()) and ECDSA (via elliptic.Marshal). Any other algorithm name on an EC key when exporting in raw format returns "unsupported algorithm <alg>". It is called from exportECKey (elliptic_curve.go:432) during crypto.subtle.exportKey('raw', key).

Source

Thrown at internal/js/modules/k6/webcrypto/elliptic_curve.go:486

	if alg == ECDH {
		k, ok := handle.(*ecdh.PublicKey)
		if !ok {
			return nil, NewError(OperationError, "key data isn't a valid elliptic curve public key")
		}

		return k.Bytes(), nil
	}

	if alg == ECDSA {
		k, ok := handle.(*ecdsa.PublicKey)
		if !ok {
			return nil, NewError(OperationError, "key data isn't a valid elliptic curve public key")
		}

		return elliptic.Marshal(k.Curve, k.X, k.Y), nil //nolint:staticcheck // we need to use the Marshal function
	}

	return nil, errors.New("unsupported algorithm " + alg)
}

// ECDHKeyDeriveParams represents the object that should be passed as the algorithm parameter
// into `SubtleCrypto.DeriveBits` or `SubtleCrypto.DeriveKey` when generating any elliptic-curve-based
// key: that is, when the algorithm is identified as ECDH.
type ECDHKeyDeriveParams struct {
	Algorithm
	Public *CryptoKey
}

var _ BitsDeriver = &ECDHKeyDeriveParams{}

func newECDHKeyDeriveParams(rt *sobek.Runtime, normalized Algorithm, params sobek.Value) (*ECDHKeyDeriveParams, error) {
	var publicKey *CryptoKey

	pcValue, err := traverseObject(rt, params, "public")
	if err != nil {
		return nil, NewError(TypeError, "algorithm does not contain a public key")

View on GitHub (pinned to 93accf6570)

Solutions

  1. Verify the key was generated/imported with name 'ECDH' or 'ECDSA' and re-import it if unsure
  2. Reproduce with a fresh generateKey/importKey call to rule out state corruption
  3. If it persists on stock k6, report it at https://github.com/grafana/k6/issues with the script
Defensive patterns

Strategy: validation

Validate before calling

const name = key.algorithm.name;
if (name !== 'ECDH' && name !== 'ECDSA') {
  throw new Error(`cannot raw-export an EC key with algorithm ${name}`);
}

Try / catch

try {
  raw = await crypto.subtle.exportKey('raw', key);
} catch (e) {
  if (String(e.message).includes('unsupported algorithm')) throw new Error(`key algorithm ${key.algorithm?.name} cannot be raw-exported as an EC key`);
  throw e;
}

Prevention

When it happens

Trigger: `crypto.subtle.exportKey('raw', ecKey)` where the key's algorithm normalized name is neither 'ECDH' nor 'ECDSA' — in practice only reachable with non-standard algorithm names on a key that still carries an EcKeyAlgorithm, since k6's normalization otherwise routes keys correctly.

Common situations: Rare/defensive: custom forks adding new EC algorithms, corrupted internal key state, or bugs in algorithm normalization. Stock k6 generates EC keys only as ECDH or ECDSA, so users essentially do not hit this.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/486d1188b4acd711. Report an issue: GitHub.