Skip to content

feat: add verify command#7

Merged
rongquan1 merged 22 commits intomainfrom
feat/add-verify-command
Jan 23, 2026
Merged

feat: add verify command#7
rongquan1 merged 22 commits intomainfrom
feat/add-verify-command

Conversation

@pennhan-dex
Copy link
Copy Markdown
Contributor

@pennhan-dex pennhan-dex commented Jan 16, 2026

Implement verify Command for Document Verification (W3C + OA)

Summary

This PR implements a new CLI command, verify, to validate documents. It supports verification for:

  • W3C Verifiable Credentials
    • Non-transferable documents
    • Transferable documents
  • OpenAttestation (OA) documents
    • Wrapped OA documents (v2/v3)

The command outputs verification results for the following fragments:

  • DOCUMENT_INTEGRITY
  • DOCUMENT_STATUS
  • ISSUER_IDENTITY

and indicates if the document credential has expired.

What’s Included

Verification behaviour

  • Automatic chain detection / provider resolution

    • For W3C transferable credentials, the command extracts chainId from the VC and resolves the correct provider automatically.
    • For OA documents, the command reads network.chainId from the document and resolves the provider accordingly.
    • If blockchain/network information is missing for OA, the command fails fast with an explicit error: Could not find blockchain information.
  • Expiration warnings

    • For W3C documents, expiration warnings emitted by the underlying verification library are captured and surfaced as a CLI warning: The document credential has expired.
    • For OA documents, expiration is detected via expirationDate and also produces the same warning message.
  • User experience

    • Prompts user for a document path (@inquirer/prompts) and loads it as JSON.
    • Prints success when a fragment is VALID, otherwise prints warn with the failure reason.

Tests Added

A total of 10 unit tests were added under tests/commands/verify.test.ts, covering both helper utilities and end-to-end verification flows using real fixtures.

Helper function coverage (6 tests)

  • getResultFromFragment
    • Returns the first non-SKIPPED fragment of a given type
    • Throws when no matching non-SKIPPED fragment exists
  • logResultStatus
    • Logs success when status is VALID
    • Logs warn (including reason) when status is not VALID
  • handleExpiredCredentialWarning
    • Logs expiration warning when present
    • Does nothing when warning is not present

CLI prompt coverage (3 tests)

  • Ensures prompt returns a parsed signed VC when a valid path is provided
  • Validates required/empty path handling via the prompt validation function
  • Throws when readJsonFile fails on an invalid path

End-to-end fixture verification coverage (1 parameterized test with 8 cases)

Uses actual documents in tests/fixtures/ to validate full verification behavior end-to-end:

  • 4 W3C fixtures
    • operative
    • expired (expects expiration warning)
    • revoked (expects non-VALID DOCUMENT_STATUS)
    • inoperative
  • 4 OA fixtures
    • operative
    • expired (expects expiration warning)
    • revoked (expects non-VALID DOCUMENT_STATUS)
    • inoperative

The test asserts the command produces outputs for:

  • DOCUMENT_INTEGRITY
  • DOCUMENT_STATUS
  • ISSUER_IDENTITY

and validates warnings are emitted only for the expected scenarios.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added verify command to CLI for validating W3C credentials and OpenAttestation documents
    • Interactive prompts guide users through document verification workflow
    • Displays verification results for document integrity, issuer identity, and document status
  • Tests

    • Added comprehensive test suite with fixture examples for various verification scenarios

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

This PR introduces a new verify CLI command that validates W3C credentials and OpenAttestation documents. It implements verification orchestration with provider-based fallbacks, result handling utilities, warning capture helpers, a comprehensive test suite, and multiple test fixtures for different credential types and verification scenarios.

Changes

Cohort / File(s) Summary
CLI Command & Type Definitions
README.md, src/commands/verify.ts, src/types.ts
Adds verify command with interactive prompts, dual verification paths (W3C and OpenAttestation), provider resolution, result extraction, and logging. Exposes FragmentType enum and public functions (handler, promptQuestions, verify, getResultFromFragment, logResultStatus, handleExpiredCredentialWarning). Updates documentation with usage examples.
Utility Functions
src/utils/formatting.ts, src/utils/networks.ts
Introduces CaptureConsoleWarn and CaptureConsoleWarnAsync for capturing console warnings during execution. Minor import reordering in networks module.
Test Suite
tests/commands/verify.test.ts
Comprehensive unit tests covering helper functions, promptQuestions validation, and end-to-end verification scenarios using fixture discovery matrix. Tests include assertions for fragment results, warning messages, and dynamic expectations based on fixture filenames.
Test Fixtures: OpenAttestation
tests/fixtures/verify/oa/2.0/*, tests/fixtures/verify/oa/3.0/*
Multiple OA document fixtures including DNS-DID, DNS-TXT, DocStore, and TokenRegistry proof types across v2.0 and v3.0 schemas. Includes standard signed/wrapped documents and a variant without network field.
Test Fixtures: W3C
tests/fixtures/verify/w3c/*
Various W3C verifiable credential fixtures using BBS 2020/2023 and ECDSA signature schemes, including transferable records, expired, and revoked credentials for comprehensive verification testing.

Sequence Diagram

sequenceDiagram
    participant User
    participant CLI as Verify Handler
    participant Parser as Document Parser
    participant Router as Type Router
    participant VerifyOA as OA Verification
    participant VerifyW3C as W3C Verification
    participant Provider as Provider/Network
    participant Logger as Result Logger

    User->>CLI: invoke verify command
    CLI->>CLI: promptQuestions (interactive)
    User->>CLI: provide document path
    CLI->>Parser: readJsonFile
    Parser-->>CLI: SignedVerifiableCredential
    CLI->>Router: determine type (OA vs W3C)
    
    alt OpenAttestation Document
        Router->>VerifyOA: verifyOpenAttestationDocument
        VerifyOA->>VerifyOA: checkExpiration
        VerifyOA->>Provider: get ChainId
        VerifyOA->>Provider: provider-based verification
        alt Provider Available
            Provider-->>VerifyOA: verification result
        else Provider Unavailable
            VerifyOA->>VerifyOA: fallback verification
        end
        VerifyOA-->>CLI: fragments + warnings
    else W3C Document
        Router->>VerifyW3C: verifyW3CDocument
        VerifyW3C->>Provider: resolveProviderFromNetwork
        alt Provider Resolved
            VerifyW3C->>Provider: provider-based verification
        else Provider Resolution Fails
            VerifyW3C->>VerifyW3C: fallback verification
        end
        VerifyW3C-->>CLI: fragments + warnings
    end
    
    CLI->>Logger: getResultFromFragment
    CLI->>Logger: logResultStatus
    CLI->>Logger: handleExpiredCredentialWarning
    Logger-->>User: display verification results
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~40 minutes

Poem

🐰 twitches nose at credentials new
W3C and OpenAttestation too!
Fragments dance through verify's gate,
Providers hop to seal the fate—
Signatures blessed, trust ornate! 🔐✨


Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

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

@pennhan-dex pennhan-dex requested a review from rongquan1 January 21, 2026 06:58
@rongquan1 rongquan1 changed the title Feat/add verify command feat: add verify command Jan 23, 2026
@rongquan1 rongquan1 merged commit da85177 into main Jan 23, 2026
5 checks passed
@rongquan1 rongquan1 deleted the feat/add-verify-command branch January 23, 2026 08:03
tradetrustimda pushed a commit that referenced this pull request Mar 10, 2026
# 1.0.0 (2026-03-10)

### Bug Fixes

* add tamper check for all blockchain functions ([#21](#21)) ([ea64760](ea64760))
* base64 file format removal ([514f18b](514f18b))
* ether signer compatibility ([a3c36de](a3c36de))
* handle network selection and add new fixtures ([#15](#15)) ([62b2031](62b2031))
* one line command and interactive terminal fix ([23fb955](23fb955))
* package lock ([2e40722](2e40722))
* remove test output files ([f63a4b3](f63a4b3))
* remove the base64 encoding for the file encryption ([#23](#23)) ([d4600e4](d4600e4))
* remove unnecessary details in the readme ([6a9b8a2](6a9b8a2))
* update cli process ([#8](#8)) ([472a9e6](472a9e6))
* updated the file handling error and folder creation for outputs ([a07c6a3](a07c6a3))
* wallet creation ([#14](#14)) ([6499276](6499276))

### Features

* add mint function command ([#1](#1)) ([22ea11f](22ea11f))
* add verify command ([#7](#7)) ([da85177](da85177))
* add w3c sign function ([#4](#4)) ([ea31015](ea31015))
* added encrypt/decrypt functions to the OA feature ([6dab3e7](6dab3e7))
* added functionality for transaction cancel ([33d73f2](33d73f2))
* added husky for lint checks ([70f3ea5](70f3ea5))
* added the gracefull error handling ([27ef0cf](27ef0cf))
* credential status command ([fb83698](fb83698))
* deploy document store command ([#16](#16)) ([bee4e7a](bee4e7a))
* document store ownership ([#20](#20)) ([a3906da](a3906da))
* fixed the prettier formats ([661c27e](661c27e))
* issue and revoke command ([#17](#17)) ([1df37ff](1df37ff))
* oa sign command ([6fc14cb](6fc14cb))
* reject commands ([#5](#5)) ([f50ce1b](f50ce1b))
* remove example files ([eecf1fb](eecf1fb))
* return commands ([#6](#6)) ([d999e6c](d999e6c))
* token registry command ([#19](#19)) ([0f5c523](0f5c523))
* transfer commands ([#3](#3)) ([8414130](8414130))
* update command process and tests ([#12](#12)) ([97986f5](97986f5))
* update the transfer commands with new input process ([#10](#10)) ([603e534](603e534))
* updated package version for trustvc ([995b43f](995b43f))
* updated packages ([7f9712c](7f9712c))
* updated the readme ([8fa493a](8fa493a))
* wallet creation encryption ([#13](#13)) ([e4d368c](e4d368c))
* wrap unwrap oa command ([#9](#9)) ([4ca75f0](4ca75f0))
@tradetrustimda
Copy link
Copy Markdown

🎉 This PR is included in version 1.0.0 🎉

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.

3 participants