Skip to content

Use PQC WebCrypto in webcrypto.ts and a joint fallback API, webcrypto_with_fallback.ts - #46

Open
freybryce wants to merge 2 commits into
paulmillr:mainfrom
freybryce:pr-part2
Open

Use PQC WebCrypto in webcrypto.ts and a joint fallback API, webcrypto_with_fallback.ts#46
freybryce wants to merge 2 commits into
paulmillr:mainfrom
freybryce:pr-part2

Conversation

@freybryce

Copy link
Copy Markdown

Note: This PR is stacked on top of #45 . Please review and merge that one first.

Fixes #43

Native WebCrypto PQC integration with separate TypeScript fallback API

This PR introduces native WebCrypto support for Post-Quantum Cryptography (PQC) algorithms (ML-KEM, ML-DSA, and X-Wing), while preserving the pure TypeScript implementation. An additional API enables TS as a reliable fallback, when explicitly used.

Key Changes

• Native WebCrypto Wrappers (src/webcrypto.ts): Implements standard wrappers around the browser's SubtleCrypto API to expose native PQC algorithms under the unified AsyncKEM and AsyncDSA interfaces.
• Opportunistic Fallback Mechanism (src/webcrypto_with_fallback.ts): Introduces a hybrid module that probes the environment for native WebCrypto support upon initialization. It delegates operations to the native
backend when supported, and falls back to the pure TypeScript implementation when native support is missing or when using deterministic inputs (e.g., keygen with a specific seed).
• SPKI Utilities (src/utils.ts): Adds unwrapSPKI and wrapSPKI ASN.1 DER encoding/decoding helpers. These are required to dynamically convert raw public keys into the SPKI formats expected by native WebCrypto APIs.
• Integration Testing (test/): Adds comprehensive Playwright integration tests to validate the hybrid fallback logic, verify that native WebCrypto SPKI formats map correctly to pure TS formats, and ensure
interoperability between the implementations.

Design Considerations

  • This change has kept to request in Incorporate using PQC WebCrypto first, when available #43 to keep the WebCrypto API usage in a separate, swappable API.
  • It also includes an API variant webcrypto_with_fallback.ts that allows the same one-line change for library consumers to use an API that prioritizes WebCrypto when available and falls back to the TS impl otherwise. This behavior is likely to be the most desired by library consumers (including my team at Google) in the near term until broad rollout of PQC WebCrypto in browsers, then consumers will likely migrate to pure the pure WebCrypto API for security.

Bryce Frey added 2 commits July 10, 2026 15:31
…tation.

What is the purpose of this change?
- Demonstrate the use of Playwright with Chrome Canary to use the flag controlled
  WebCrypto PQC feature, ahead of actual use.

Why doesn't this change affect any part of the larger noble-post-quantum project?
- This is specific commit is limited to the smoke test. It will be followed by a 
  stacked commit(s) that opportunistically uses the Chrome WebCrypto PQC APIs and
  tests that appropriately.
webcrypto_with_fallback.ts to fallback to TS impl.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorporate using PQC WebCrypto first, when available

1 participant