Skip to content

Feat/tt 907 encrypt decrypt oa functions#18

Merged
RishabhS7 merged 10 commits into
mainfrom
feat/TT-907-encrypt-decrypt-oa-functions
Feb 26, 2026
Merged

Feat/tt 907 encrypt decrypt oa functions#18
RishabhS7 merged 10 commits into
mainfrom
feat/TT-907-encrypt-decrypt-oa-functions

Conversation

@manishdex25

@manishdex25 manishdex25 commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Added OA encrypt/decrypt CLI commands, plus safe input/output file utilities and clearer CLI error handling.
  • Documentation

    • Expanded docs with encryption/decryption usage, examples, prompts, outputs, and command reference.
  • Tests

    • Added comprehensive tests and fixtures covering encrypt/decrypt workflows and error scenarios.
  • Chores

    • Added a pre-commit hook and package prepare script to enforce linting and format checks before commits.

@coderabbitai

coderabbitai Bot commented Feb 24, 2026

Copy link
Copy Markdown
ℹ️ Recent review info

Configuration used: defaults

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 7f9712c and 1d996ce.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (1)
  • README.md

📝 Walkthrough

Walkthrough

Adds Husky pre-commit hook and prepare script, two new OpenAttestation CLI commands (oa-encrypt, oa-decrypt), CLI error and file I/O utilities, tests and fixture, README updates, and related dependency/devDependency changes.

Changes

Cohort / File(s) Summary
Git hooks & package
\.husky/pre-commit, package.json
Adds executable Husky pre-commit script to run lint and format:check; adds husky devDependency and prepare script; bumps @trustvc/trustvc version.
OA CLI commands
src/commands/oa/encrypt.ts, src/commands/oa/decrypt.ts
New interactive oa-encrypt and oa-decrypt commands: prompt for paths and passphrase, derive 64‑char hex key via SHA‑256, call trustvc encrypt/decrypt, validate/serialize payloads, write outputs, and log user-facing messages and errors.
CLI utilities
src/utils/cli-errors.ts, src/utils/index.ts
Adds CLI error type guards and getCliErrorMessage; re-exports from src/utils/index.ts for centralized user-friendly error messages.
File I/O helpers
src/utils/file-io.ts
Adds input validation helpers (ensureInputFileExists, validateInputFileExists) and resolveOutputJsonPath returning {path, generated} with directory creation and deterministic filename when needed.
Tests & fixtures
tests/commands/oa/encrypt.test.ts, tests/commands/oa/decrypt.test.ts, tests/fixtures/oa/valid-open-attestation-document.json
Adds comprehensive unit tests for encrypt/decrypt flows (prompts, happy paths, trimming, payload validation, ENOENT and other error cases) and a valid OA document fixture.
Documentation
README.md
Updates README to document oa-encrypt/oa-decrypt usage, prompts, outputs, and adds the new commands to command reference and quick start sections.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CLI as "CLI"
    participant FS as "FileSystem"
    participant KD as "KeyDerivation"
    participant ENC as "EncryptLib"

    User->>CLI: run oa-encrypt
    CLI->>User: prompt document path, output path, passphrase
    User->>CLI: provide inputs
    CLI->>FS: read input document
    FS-->>CLI: document content
    CLI->>KD: derive 64-char key (SHA-256)
    KD-->>CLI: derived key
    CLI->>ENC: encrypt document with key
    ENC-->>CLI: cipherText, iv, tag
    CLI->>FS: write encrypted payload (cipherText, iv, tag, type)
    FS-->>CLI: file written
    CLI->>User: log success + key retention warning
Loading
sequenceDiagram
    actor User
    participant CLI as "CLI"
    participant FS as "FileSystem"
    participant Validator as "PayloadValidator"
    participant KD as "KeyDerivation"
    participant DEC as "DecryptLib"

    User->>CLI: run oa-decrypt
    CLI->>User: prompt encrypted path, output path, passphrase
    User->>CLI: provide inputs
    CLI->>FS: read encrypted file
    FS-->>CLI: encrypted payload JSON
    CLI->>Validator: validate payload (cipherText, iv, tag, type)
    Validator-->>CLI: validation result
    CLI->>KD: derive 64-char key (SHA-256)
    KD-->>CLI: derived key
    CLI->>DEC: decrypt cipherText with key
    DEC-->>CLI: plaintext document
    CLI->>FS: write plaintext to output file
    FS-->>CLI: file written
    CLI->>User: log success with output path
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I nibble keys with SHA's bright spark,

I guard the files when nights are dark,
Pre-commit hums before I hop,
Encrypt, decrypt — then tip my top,
Tests and docs make this patch a lark!


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.

Comment thread README.md
@manishdex25 manishdex25 self-assigned this Feb 24, 2026
Comment thread README.md
| **Token Registry** | [`token-registry deploy`](#token-registry-deploy) | Deploy token registry contracts |
| | [`oa-encrypt`](#oa-encrypt) | Encrypt an OA document for safe sharing and storage |
| | [`oa-decrypt`](#oa-decrypt) | Decrypt an OA document encrypted with oa-encrypt |
| **Token Registry** | [`mint`](#mint) | Mint tokens to blockchain registries |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@RishabhS7 please review the readme once

@RishabhS7 RishabhS7 merged commit e3874cd into main Feb 26, 2026
5 checks passed
@RishabhS7 RishabhS7 deleted the feat/TT-907-encrypt-decrypt-oa-functions branch February 26, 2026 05:23
@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