Skip to content

update @noble/hashes - #1231

Merged
isamu merged 2 commits into
receptron:mainfrom
isamu:update@noble/hashes
Sep 22, 2025
Merged

isamu merged 2 commits into
receptron:mainfrom
isamu:update@noble/hashes

Conversation

@isamu

@isamu isamu commented Sep 21, 2025 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Chores

    • Replaced underlying cryptographic hashing dependency with an alternative implementation.
    • Updated dependency versioning; no UI or configuration changes expected.
  • Improvements

    • Broader handling of input types for internal caching logic to make operations more robust and reduce edge-case failures.
  • Impact

    • No user-facing behavioral changes anticipated; potential gains in reliability and performance.

@coderabbitai

coderabbitai Bot commented Sep 21, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Replaces the hashing implementation and dependency in the cache agent: @noble/hashes removed and js-sha256 added; cache key derivation now uses sha256.array(...) and base64 encoding; sortObjectKeys accepts number and boolean in addition to previous types.

Changes

Cohort / File(s) Summary of Changes
Dependency change
agent_filters/cache_agent_filter/package.json
Removed dependency @noble/hashes and added js-sha256 (^0.11.1).
Cache implementation
agent_filters/cache_agent_filter/src/cache.ts
Switched hash import from @noble/hashes/sha2 to js-sha256; changed cache key derivation to use sha256.array(...) and then base64-encode the byte array; expanded sortObjectKeys signature to accept number and boolean types.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant CacheModule as Cache Module
    participant Hasher as js-sha256

    Caller->>CacheModule: provide input (object/string/number/bool)
    CacheModule->>CacheModule: normalize and sort keys (sortObjectKeys)
    CacheModule->>Hasher: sha256.array(normalizedBytes)
    Hasher-->>CacheModule: byte[] hash
    CacheModule->>CacheModule: base64-encode byte[] -> cacheKey
    CacheModule-->>Caller: return cacheKey / lookup result
    Note right of CacheModule: Changed hashing lib and input types accepted
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Separate agent filter #1204 — Updates imports/usages to the revised @graphai/cache_agent_filter package which may be affected by the hashing/API changes.

Poem

I nibble data, fur aflutter,
Keys now hashed with a gentler stutter.
Bytes in a hop, base64 delight,
I tuck the cache and sleep tonight. 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title is short and clearly signals the change concerns the @noble/hashes dependency; it therefore relates to the main change in the diff. The actual change replaces @noble/hashes with js-sha256 and updates imports/usages, so the title is accurate but slightly less specific than ideal. Because it communicates the dependency-focused intent succinctly, it meets the pass criteria.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a43069 and 6f4731b.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • agent_filters/cache_agent_filter/package.json (1 hunks)
  • agent_filters/cache_agent_filter/src/cache.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • agent_filters/cache_agent_filter/package.json
🧰 Additional context used
🧬 Code graph analysis (1)
agent_filters/cache_agent_filter/src/cache.ts (1)
agent_filters/cache_agent_filter/lib/cache.js (1)
  • cacheKeySeed (25-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build (22.x)
  • GitHub Check: build (24.x)
🔇 Additional comments (2)
agent_filters/cache_agent_filter/src/cache.ts (2)

2-2: Library swap to js-sha256: verify parity and bundling.

Looks fine, but please confirm:

  • Output parity with @noble/hashes for representative inputs (digest bytes/base64 identical).
  • ESM/CJS interop in your bundlers (Node/Browser/Deno) for import { sha256 } from 'js-sha256'.

27-29: Replace btoa with a cross‑runtime base64 encoder (use Buffer in Node, fallback to btoa in browsers)

btoa is not available in Node and will throw; use Buffer when available and fallback to btoa for browsers.

File: agent_filters/cache_agent_filter/src/cache.ts Lines: 27-29

-  const cacheKeySeed = sha256.array(JSON.stringify(sortObjectKeys({ namedInputs, params, agentId })));
-  const cacheKey = btoa(String.fromCharCode(...cacheKeySeed));
+  const bytes = Uint8Array.from(sha256.array(JSON.stringify(sortObjectKeys({ namedInputs, params, agentId }))));
+  const cacheKey =
+    typeof (globalThis as any).Buffer !== "undefined"
+      ? (globalThis as any).Buffer.from(bytes).toString("base64")
+      : btoa(String.fromCharCode(...bytes));

Confirm the resulting base64 key only feeds stores tolerant of "+/="; if not, switch to URL‑safe base64.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3482ba9 and 3a43069.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (1)
  • agent_filters/cache_agent_filter/package.json (1 hunks)

@isamu
isamu merged commit f3164a9 into receptron:main Sep 22, 2025
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.

1 participant