Skip to content

feat(render-method-2024): add digestMultibase generation via async constructor#25

Merged
ashleythedeveloper merged 2 commits into
nextfrom
feat/digest-multibase
May 15, 2026
Merged

feat(render-method-2024): add digestMultibase generation via async constructor#25
ashleythedeveloper merged 2 commits into
nextfrom
feat/digest-multibase

Conversation

@ashleythedeveloper
Copy link
Copy Markdown
Contributor

This PR adds two new exports: generateDigestMultibase, a primitive that hashes content to a multibase-encoded multihash string, and constructRenderMethodAsync, an async sibling of constructRenderMethod that auto-fills digestMultibase for RenderTemplate2024 outputs when a url is supplied. The synchronous constructRenderMethod is unchanged, so existing callers continue to work without modification.

Gating: digestMultibase is only emitted when the caller signals remote hosting intent by setting url. For inline templates without a url, the digest is redundant since the signed credential already covers the template bytes, so it is omitted. A caller-supplied digestMultibase is preserved verbatim.

The digest is computed over the raw template bytes BEFORE whitespace normalisation, on the precondition that those raw bytes are what the caller intends to host at url. If a caller supplies both inline template and url, the cleaned inline template field stored in the output will NOT hash to digestMultibase; a verifier must hash bytes fetched from url, not the inline field. See the JSDoc on constructRenderMethodAsync for the full contract.

Defaults are sha2-256 and base58btc, matching the conventional choices in UNTP and W3C VC examples. Both are configurable via the helper's options and exported as DEFAULT_DIGEST_ALGORITHM and DEFAULT_DIGEST_BASE for callers who want to be explicit. The implementation builds on the newly published @uncefact/untp-utils MultibaseDigest primitive.

The Jest config gains transformIgnorePatterns plus targeted moduleNameMapper entries so the ESM-only @uncefact/untp-utils and its multiformats subpath imports resolve correctly without a wholesale ESM migration. No changes to existing tests required. The mapper paths are coupled to multiformats's internal dist/ layout; a comment in jest.config.cjs notes the future migration path.

Closes #24

Test plan

  • generateDigestMultibase produces a verifiable sha2-256 + base58btc digest by default
  • Algorithm and base overrides take effect; unsupported values throw
  • Non-ASCII (UTF-8) content hashes correctly
  • constructRenderMethodAsync auto-fills digestMultibase only when url is a non-empty string and the template is non-empty
  • Empty-string url, non-string url, and empty template all skip digest generation
  • A caller-supplied digestMultibase is preserved verbatim; an empty-string digestMultibase triggers regeneration
  • WebRenderingTemplate2022 output is identical to the synchronous constructor
  • Existing test suite still passes (91 tests across 11 suites, 100% lines/statements coverage)

@github-actions
Copy link
Copy Markdown
Contributor

Code Coverage Report

Lines Statements Branches Functions
Coverage: 100%
100% (172/172) 97.91% (47/48) 90.9% (30/33)
Tests Skipped Failures Errors Time
91 0 💤 0 ❌ 0 🔥 2.412s ⏱️

@ashleythedeveloper ashleythedeveloper merged commit 4eeaba5 into next May 15, 2026
4 checks passed
@ashleythedeveloper ashleythedeveloper deleted the feat/digest-multibase branch May 15, 2026 08:20
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.

Generate digestMultibase automatically when constructing a RenderTemplate2024

1 participant