Skip to content

Replace node:crypto AES with @noble/ciphers - #10

Closed
mattgle wants to merge 1 commit into
devfrom
refactor/aes-noble-ciphers
Closed

mattgle wants to merge 1 commit into
devfrom
refactor/aes-noble-ciphers

Conversation

@mattgle

@mattgle mattgle commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Swaps the AES-256-GCM/CTR helpers in aes.ts from node:crypto (createCipheriv/createDecipheriv) to the pure-JS @noble/ciphers. This removes the package's only hard dependency on a Node builtin, so it runs natively in browsers and React Native without a node:crypto polyfill.

Behaviour is unchanged — same public API, error codes, IV/tag handling, and byte-for-byte output. AES-GCM/CTR are deterministic, so the existing Wycheproof (GCM) and NIST SP 800-38A (CTR) known-answer vectors and the multi-block roundtrip tests already pin output compatibility. Test-only randomBytes usages move to @noble/hashes/utils.

@noble/ciphers is pinned to ^1.x (dual CJS/ESM); v2 is ESM-only and would break this package's CommonJS consumers.

@mattgle mattgle self-assigned this Jun 17, 2026
@mattgle
mattgle requested a review from bhflm June 17, 2026 16:47
@mattgle
mattgle marked this pull request as ready for review June 17, 2026 16:48
Comment thread src/primitives/aes/aes.ts
@@ -1,5 +1,4 @@
import { createCipheriv, createDecipheriv } from 'node:crypto'

import { ctr, gcm } from '@noble/ciphers/aes'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this breaks with Chrome, throws ReferenceError: Buffer is not defined before it even reaches to load AES I think

Comment thread package-lock.json
"version": "0.2.16",
"resolved": "https://registry.npmjs.org/tinyglobby/-/tinyglobby-0.2.16.tgz",
"integrity": "sha512-pn99VhoACYR8nFHhxqix+uvsbXineAasWm5ojXoN8xEwK5Kd3/TrhNn1wByuD52UxWRLy8pu+kRMniEi6Eq9Zg==",
"version": "0.2.17",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to upgrade this ??

@mattgle
mattgle marked this pull request as draft June 18, 2026 16:19
@mattgle mattgle closed this Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants