Use PQC WebCrypto in webcrypto.ts and a joint fallback API, webcrypto_with_fallback.ts - #46
Open
freybryce wants to merge 2 commits into
Open
Use PQC WebCrypto in webcrypto.ts and a joint fallback API, webcrypto_with_fallback.ts#46freybryce wants to merge 2 commits into
freybryce wants to merge 2 commits into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
webcrypto_with_fallback.tsthat 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.