@gainratio/receipt-ui

中文文档
0.3.0发布于 2026/10/03MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 3451

React components that render and verify an Avow SignedReceipt — a composable badge and panel with a fail-closed, three-state verdict (verified / tampered / untrusted signer).

原始使用文档
文档目录4 节
  1. Install
  2. Use
  3. Localize
  4. Develop

@gainratio/receipt-ui

Render and verify an Avow SignedReceipt in React.

Your app signs a receipt at the engine level; this shows the user whether it actually checks out. Drop in a <ReceiptBadge> or <ReceiptPanel>, hand it the receipt and the one public key you trust, and it verifies on mount and renders one of four clearly-distinct, fail-closed states:

  • Verifying… — the check is in flight (the initial, not-yet-trusted state).
  • Verified — the signature is valid and signed by the pinned key.
  • Not verified — tampered or invalid signature — the verifier rejected it.
  • Not verified — untrusted signer — the receipt's key is not the one you pinned.

Only a resolved verify under the pinned key ever reads as Verified. Anything else — a rejection, an error, an unpinned key, or the moment before the check returns — reads as not-verified. Status is conveyed by icon and text (never color alone) inside an ARIA role="status" live region.

Install

pnpm add @gainratio/receipt-ui @gainratio/avow react

@gainratio/avow and react are peer dependencies — the app provides them, so there is a single avow instance and a single SignedReceipt type across the app and this package.

receipt-ui@gainratio/avow peerReceipt format
0.3.x^0.5.2avow.receipt/v1 (carries a schema field)
0.1.x – 0.2.x^0.1.0pre-schema receipts (published from the old hseshadr/assay repo)

A receipt without the avow.receipt/v1 schema renders as Not verified on 0.3.x: avow 0.5 refuses it, and this package never overrides avow's verdict.

Use

import { ReceiptPanel } from "@gainratio/receipt-ui";

// `receipt` came from your engine (avow `signPayload`); `SIGNER_KEY` is the
// hex public key you trust. `verify` is optional — it defaults to avow's own
// `verifySignature`, so omit it unless your app injects a custom verifier.
<ReceiptPanel
  receipt={receipt}
  expectedPublicKey={SIGNER_KEY}
  renderPayload={(p) => <p>Score: {p.score}</p>}
/>;

ReceiptBadge takes the same receipt / expectedPublicKey / verify props and renders just the one-line verdict; ReceiptPanel adds the envelope metadata (algorithm, shortened signer key, payload hash, signature) and the payload body.

The verdict lives in the useReceiptVerification hook if you want to build your own presentation; StatusPill is the standalone verdict chip.

Localize

Requires @gainratio/receipt-ui 0.2.0 or newer. 0.1.0 has no labels prop — it renders the built-in English strings and silently ignores the object. Check the version you resolved before filing a bug. See CHANGELOG.md.

Every rendered string is injectable: pass a labels object (type ReceiptLabels) to StatusPill, ReceiptBadge or ReceiptPanel. It is a deep partial — omit anything to keep the built-in English default:

<ReceiptPanel
  receipt={receipt}
  expectedPublicKey={SIGNER_KEY}
  labels={{
    status: { verified: { text: t("receipt.verified") } },
    panel: { receipt: t("receipt.section"), algorithm: t("receipt.algorithm") },
  }}
/>;

labels.status overrides the verdict chip per state (checking / verified / invalid / wrong-key, each { text?, icon? }); labels.panel overrides the panel's meta strings (receipt — the section aria-label — plus algorithm, signerKey, payloadHash, signature).

Develop

This package lives in the hseshadr/avow pnpm workspace at ts/packages/receipt-ui and tests against the avow source in ts/, not a published copy.

pnpm --dir ts install
pnpm --dir ts build                      # receipt-ui imports avow from ts/dist
pnpm --dir ts/packages/receipt-ui gate   # biome -> tsc strict -> vitest (+coverage) -> build

Releases are tag-driven and separate from avow's vX.Y.Z tags: bump package.json and CHANGELOG.md, merge, then push receipt-ui-vX.Y.Z. .github/workflows/publish-receipt-ui.yml publishes through npm trusted publishing with provenance.

Tests build real avow receipts (valid, tampered, wrong-key) and replay avow's shared golden vectors (testdata/vectors/receipts.json), asserting the component reflects avow's own verdict — the property, not the shape.

版本与发布记录

@gainratio/receipt-ui 共发布 3 个版本,首次发布于 2026/10/03;过去 12 个月发布了 3 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.0latest2026/10/031 个月前
0.0.0-bootstrap.0bootstrap2026/10/031 个月前
0.0.0-stage2026/10/031 个月前

关于 @gainratio/receipt-ui 的常见问题

@gainratio/receipt-ui 是什么?

React components that render and verify an Avow SignedReceipt — a composable badge and panel with a fail-closed, three-state verdict (verified / tampered / untrusted signer).

如何安装 @gainratio/receipt-ui?

在项目目录运行 npm install @gainratio/receipt-ui,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、@gainratio/avow(^0.5.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@gainratio/receipt-ui 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@gainratio/receipt-ui 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@gainratio/receipt-ui 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.13。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@gainratio/receipt-ui 可以商用吗?

@gainratio/receipt-ui 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gainratio/receipt-ui 的下载量有多少?

根据 npm 官方下载统计,@gainratio/receipt-ui 在 2026/10/16 – 2026/11/14 这 30 天内被下载 3,451 次,日均约 115 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@gainratio/receipt-ui 还在维护吗?

最新版本 0.3.0 发布于 2026/10/03(1 个月前);至今共发布 3 个版本,其中过去 12 个月发布了 3 个;首次发布于 2026/10/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。