@dashevo/wasm-dpp2

中文文档
5.0.3发布于 2026/11/04TypeScriptES Module零依赖近 30 天下载 4193

Internal build of the Dash Platform Protocol v2 WebAssembly bindings.

原始使用文档
文档目录3 节
  1. Scripts
  2. Document ids
  3. Checking a contract update

@dashevo/wasm-dpp2

Internal build of the Dash Platform Protocol v2 WebAssembly bindings.

Scripts

  • yarn build – run the unified WASM build and bundle artifacts into dist/
  • yarn build:release – same as build but forces full release optimisations
  • yarn test – execute unit + browser (Karma) tests
  • yarn lint – lint test sources

The build scripts defer to packages/scripts/build-wasm.sh to keep behaviour consistent with other WASM packages such as @dashevo/wasm-sdk.

Document ids

From protocol version 14 the id of a new document commits to the identity contract nonce of its create transition (see the book, Data Model → Documents → Document ID Generation), so a Document built with new Document({...}) and no identityContractNonce carries a placeholder id: the entropy-only derivation of earlier versions, which consensus no longer accepts.

The id becomes final where the nonce is known, and the bindings derive it for you:

const document = new Document({ properties, documentTypeName, dataContractId, ownerId });

// Derives the id from the document's entropy and the nonce, writes it onto
// the transition and back onto `document`: document.id equals transition.base.id.
const transition = new DocumentCreateTransition({ document, identityContractNonce: nonce });

// To know the id before the transition exists (another document in the same
// batch references it):
document.setIdForCreation(nonce);
// or derive it without a Document:
const idBytes = Document.generateId(documentTypeName, ownerId, dataContractId, entropy, nonce);
// or build the document with its final id from the start:
const ready = new Document({ properties, documentTypeName, dataContractId, ownerId, identityContractNonce: nonce });

Each of these takes an optional platformVersion (latest by default); before protocol version 14 the derivation ignores the nonce. Whatever id a Document carried before it is passed to DocumentCreateTransition is replaced: the transition can only carry the id consensus recomputes. For the same reason new Document({...}) refuses an explicit id that disagrees with the one its identityContractNonce derives. No app needs to reimplement the hash.

Checking a contract update

A data contract update is refused when it breaks an update rule: the version must rise by exactly one, the indexes of an existing document type are fixed, a property may be added but not removed, a new required property needs requiredSince, and so on for every keyword (see the book, Contract Keywords, the On update row of each keyword). DataContract.validateUpdate runs those rules with the code consensus runs on the update transition (DataContract::validate_update), so an app, a CI job or a review tool can check a proposed contract before paying for a transition the platform would refuse:

const version = new PlatformVersion(14);
const current = DataContract.fromJSON(currentJson, true, version);
const proposed = DataContract.fromJSON(proposedJson, true, version);

const errors = current.validateUpdate(proposed, undefined, version);
// [] when the update is valid; otherwise ConsensusError objects, e.g.
// errors[0].code === 10217 when an index of an existing type changed

Each error is a ConsensusError with the code a refused transition reaches JS with. The second argument is the BlockInfo of the block the update would be executed in, of which only the time is read (an added token's pre-programmed distributions may not start before it); undefined uses the device clock. The two contracts are compared whatever their ids, as the platform compares the stored contract with the proposed one. Build the proposed contract with full validation, as above, since the transition's structural checks run there. No state is read, so what the platform checks against state on top is not covered: that the contract exists, that group members, identities named by token configurations and appointed moderators exist, that references into other contracts resolve, and the signature, nonce and fees.

This package is built with the crate's validation feature, which the method needs. It also makes full validation (fromJSON(…, true, …), fromObject, fromBytes, new DataContract({ fullValidation: true })) run the document meta-schema, and contract parse errors come back as consensus errors with codes. @dashevo/wasm-sdk and @dashevo/evo-sdk build these bindings without it, to keep their size, so they have no validateUpdate.

版本与发布记录

@dashevo/wasm-dpp2 共发布 72 个版本,首次发布于 2025/11/28;过去 12 个月发布了 72 个版本。

版本发布日期距今
5.0.3latest2026/11/047 天前
5.0.22026/11/029 天前
5.0.12026/10/2714 天前
5.0.02026/10/2715 天前
5.0.0-rc.82026/10/2319 天前
5.0.0-rc.72026/10/2220 天前

其他发布通道:2.2-dev → 2.2.0-dev.2,3.0-dev → 3.0.0-dev.11,3.0-rc → 3.0.0-rc.3,3.0-hotfix → 3.0.1-hotfix.4,3.1-dev → 3.1.0-dev.8,4.0-beta → 4.0.0-beta.4。

关于 @dashevo/wasm-dpp2 的常见问题

@dashevo/wasm-dpp2 是什么?

Internal build of the Dash Platform Protocol v2 WebAssembly bindings.

如何安装 @dashevo/wasm-dpp2?

在项目目录运行 npm install @dashevo/wasm-dpp2,或使用 pnpm add / yarn add / bun add。

@dashevo/wasm-dpp2 支持 TypeScript 吗?

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

@dashevo/wasm-dpp2 支持 ESM 还是 CommonJS?

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

@dashevo/wasm-dpp2 需要什么版本的 Node.js?

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

@dashevo/wasm-dpp2 可以商用吗?

@dashevo/wasm-dpp2 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@dashevo/wasm-dpp2 的下载量有多少?

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

@dashevo/wasm-dpp2 还在维护吗?

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