Skip to content

fix: add obfucation check for w3c documents#25

Merged
rongquan1 merged 4 commits into
masterfrom
fix/w3c-obfuscate-check
Jul 25, 2025
Merged

fix: add obfucation check for w3c documents#25
rongquan1 merged 4 commits into
masterfrom
fix/w3c-obfuscate-check

Conversation

@RishabhS7

@RishabhS7 RishabhS7 commented Jul 25, 2025

Copy link
Copy Markdown

Summary

add obfuscation check for w3c documents

Issues

Jira Ticket

Summary by CodeRabbit

  • New Features

    • Added support for handling signed W3C Verifiable Credentials, including detection of obfuscated data within these credentials.
  • Tests

    • Introduced new test cases to verify obfuscation detection for W3C Verifiable Credentials.
    • Added comprehensive test fixtures for both signed and redacted W3C Verifiable Credentials.

@coderabbitai

coderabbitai Bot commented Jul 25, 2025

Copy link
Copy Markdown

Walkthrough

The changes add support for handling signed W3C Verifiable Credentials using the @trustvc/w3c-vc package. The utility function isObfuscated is updated to recognize and process these credentials. New test fixtures and corresponding tests are introduced to verify the handling of both obfuscated and non-obfuscated W3C credentials.

Changes

File(s) Change Summary
package.json Added @trustvc/w3c-vc dependency version ^1.2.17.
src/shared/utils/utils.ts Updated isObfuscated to support SignedVerifiableCredential and handle BBS+ proofs.
test/fixtures/w3c/w3c-redacted.json,
test/fixtures/w3c/w3c-signed.json
Added new W3C Verifiable Credential JSON fixtures for obfuscated and signed cases.
src/shared/utils/tests/utils.test.ts Added tests for isObfuscated using new W3C credential fixtures.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Utils as isObfuscated()
    participant VC as W3C Verifiable Credential

    Test->>Utils: Call isObfuscated(VC)
    Utils->>VC: Check if VC is signed (isSignedDocument)
    alt VC is signed and proof.type == "BbsBlsSignatureProof2020"
        Utils-->>Test: return true
    else VC is not obfuscated
        Utils-->>Test: return false
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

In the warren of code, a new friend appears,
W3C credentials—bring the rabbits cheers!
Now signed and obfuscated, they hop through the test,
With BBS+ proofs, they pass every quest.
The fixtures are many, the changes are neat—
More carrots for coders, a CodeRabbit treat! 🥕

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

npm error Exit handler never called!
npm error This is an error with npm itself. Please report this error at:
npm error https://github.com/npm/cli/issues
npm error A complete log of this run can be found in: /.npm/_logs/2025-07-25T05_58_21_782Z-debug-0.log

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/w3c-obfuscate-check

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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 5509bf1 and 331a01d.

📒 Files selected for processing (1)
  • src/shared/utils/__tests__/utils.test.ts (2 hunks)
🔇 Additional comments (1)
src/shared/utils/__tests__/utils.test.ts (1)

15-17: LGTM! Import structure follows existing patterns.

The new imports for W3C test fixtures and the SignedVerifiableCredential type are well-structured and consistent with the existing codebase patterns.

Comment on lines +462 to +472
describe("isObfuscated", () => {
test("should return false where there is no obfuscated data in document w3c", () => {
const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
});

test("should return true where there is obfuscated data in document w3c", () => {
const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
});
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Consider improving test descriptions and adding edge cases.

The test structure follows good practices, but there are opportunities for improvement:

  1. The test descriptions could be more precise
  2. Consider adding edge cases for better coverage
-    test("should return false where there is no obfuscated data in document w3c", () => {
+    test("should return false for W3C document without obfuscated data", () => {
       const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
       expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
     });

-    test("should return true where there is obfuscated data in document w3c", () => {
+    test("should return true for W3C document with obfuscated data", () => {
       const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
       expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
     });

Consider adding edge case tests such as:

  • Invalid W3C document structure
  • W3C document with missing proof property
  • W3C document with unexpected proof types

Let me verify the actual fixture content and the isObfuscated implementation to ensure comprehensive test coverage:


🏁 Script executed:

#!/bin/bash
# Description: Examine the W3C test fixtures and isObfuscated implementation

echo "=== Examining W3C test fixtures ==="
echo "--- w3c-signed.json ---"
cat test/fixtures/w3c/w3c-signed.json | jq '.'

echo "--- w3c-redacted.json ---"
cat test/fixtures/w3c/w3c-redacted.json | jq '.'

echo "=== Examining isObfuscated implementation ==="
cat src/shared/utils/utils.ts | grep -A 20 -B 5 "isObfuscated"

Length of output: 34174


Refine isObfuscated tests and expand coverage

The new describe block correctly validates the two W3C fixtures, but we can improve clarity and robustness:

• Update test descriptions for consistency.
• Add edge-case tests around proof presence/type and unsupported document shapes.

Pinpoint in src/shared/utils/__tests__/utils.test.ts around lines 462–472.

Proposed diff:

 describe("isObfuscated", () => {
-  test("should return false where there is no obfuscated data in document w3c", () => {
+  test("returns false for signed VC with proof.type = BbsBlsSignature2020", () => {
     const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
     expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
   });

-  test("should return true where there is obfuscated data in document w3c", () => {
+  test("returns true for signed VC with proof.type = BbsBlsSignatureProof2020", () => {
     const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
     expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
   });
+
+  test("returns false if proof is missing or proof.type is unexpected", () => {
+    const noProof = { proof: undefined } as SignedVerifiableCredential;
+    const wrongProofType = { proof: { type: "DummyProof2020" } } as SignedVerifiableCredential;
+    expect(utils.isObfuscated(noProof)).toBe(false);
+    expect(utils.isObfuscated(wrongProofType)).toBe(false);
+  });
+
+  test("throws on unsupported document shapes", () => {
+    expect(() => utils.isObfuscated({} as any)).toThrow(
+      /Unsupported document type/
+    );
+  });
 });

Edge cases to cover:

  • Signed VCs without a proof property
  • Signed VCs with an unrelated proof.type
  • Completely invalid document objects (should throw)

These additions will ensure isObfuscated handles all branches in its implementation.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe("isObfuscated", () => {
test("should return false where there is no obfuscated data in document w3c", () => {
const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
});
test("should return true where there is obfuscated data in document w3c", () => {
const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
});
});
describe("isObfuscated", () => {
test("returns false for signed VC with proof.type = BbsBlsSignature2020", () => {
const documentNotObfuscatedW3c = NotObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentNotObfuscatedW3c)).toBe(false);
});
test("returns true for signed VC with proof.type = BbsBlsSignatureProof2020", () => {
const documentObfuscatedW3c = ObfuscatedW3c as SignedVerifiableCredential;
expect(utils.isObfuscated(documentObfuscatedW3c)).toBe(true);
});
test("returns false if proof is missing or proof.type is unexpected", () => {
const noProof = { proof: undefined } as SignedVerifiableCredential;
const wrongProofType = { proof: { type: "DummyProof2020" } } as SignedVerifiableCredential;
expect(utils.isObfuscated(noProof)).toBe(false);
expect(utils.isObfuscated(wrongProofType)).toBe(false);
});
test("throws on unsupported document shapes", () => {
expect(() => utils.isObfuscated({} as any)).toThrow(
/Unsupported document type/
);
});
});
🤖 Prompt for AI Agents
In src/shared/utils/__tests__/utils.test.ts around lines 462 to 472, improve the
isObfuscated test suite by refining test descriptions for clarity and
consistency. Add new tests covering edge cases: one with a signed verifiable
credential missing the proof property, another with a proof property having an
unrelated type, and a test passing a completely invalid document object that
should cause isObfuscated to throw an error. These additions will enhance
coverage and ensure all code branches in isObfuscated are tested.

@rongquan1 rongquan1 merged commit eed6abb into master Jul 25, 2025
10 checks passed
@rongquan1 rongquan1 deleted the fix/w3c-obfuscate-check branch July 25, 2025 06:06
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 6.10.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants