# @auth0/mdl 中文文档

规范地址：https://npmcn.com/package/%40auth0/mdl/

版本：3\.0\.1
npm 元数据更新时间：2026-07-14T10:25:37.792Z
中文译文更新时间：2026-11-07T05:56:07.117Z
软件包许可：Apache-2\.0

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40auth0/mdl
原文对照：https://npmcn.com/package/%40auth0/mdl/?lang=original
项目主页：https://github.com/auth0-lab/mdl#readme
源码仓库：https://github.com/auth0-lab/mdl

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：198 kB，41 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=16\.0\.0
- 运行依赖：10 个
- 首次发布：2024-02-23T14:10:29.542Z
- 最新版本发布：2025-11-20T11:24:09.537Z
- 近 30 天下载量：37767（2026-10-07 至 2026-11-05，npm 官方下载统计）
- 已发布版本数：24（近 12 个月 1 个）

## 中文简介

根据ISO 18013-5分析并验证MDOC CBOR编码二进制.

## 安装

```sh
npm install @auth0/mdl
```

也可以使用：`pnpm add @auth0/mdl`、`yarn add @auth0/mdl`、`bun add @auth0/mdl`

## README

[![npm version](https://badge.fury.io/js/@auth0%2Fmdl.svg)](https://badge.fury.io/js/@auth0%2Fmdl)

# mDL 数据

[ISO 18013-5 (英语)](https://www.iso.org/standard/69084.html) 定义 mDL(移动驱动许可证):数字驱动许可证的ISO标准.

这是用于发布和验证 mDL 的 Node.js 库 [CBOR 编码](https://cbor.io/) 报告 **ISO 18013-7(草案日期:2023-08-02)**。 。 。 .

## 安装

```bash
npm i @auth0/mdl
```

## 验证证书

```javascript
import { Verifier } from "@auth0/mdl";
import { inspect } from "node:util";
import fs from "node:fs";

(async () => {
  const encodedDeviceResponse = Buffer.from(encodedDeviceResponseHex, 'hex');
  const encodedSessionTranscript = Buffer.from(encodedSessionTranscriptHex, 'hex');
  const ephemeralReaderKey = Buffer.from(ephemeralReaderKeyHex, 'hex');

  const trustedCerts = [fs.readFileSync('./caCert1.pem')/*, ... */];
  const verifier = new Verifier(trustedCerts);
  const mdoc = await verifier.verify(encodedDeviceResponse, {
    ephemeralReaderKey,
    encodedSessionTranscript,
  });

  //at this point the issuer and device signature are valids.
  inspect(mdoc);
})();
```

## 获取诊断信息

```javascript
import { Verifier } from "@auth0/mdl";
import { inspect } from "node:util";
import fs from "node:fs";

(async () => {
  const encodedDeviceResponse = Buffer.from(encodedDeviceResponseHex, 'hex');
  const encodedSessionTranscript = Buffer.from(encodedSessionTranscriptHex, 'hex');
  const ephemeralReaderKey = Buffer.from(ephemeralReaderKeyHex, 'hex');

  const trustedCerts = [fs.readFileSync('./caCert1.pem')/*, ... */];
  const verifier = new Verifier(trustedCerts);

  const diagnosticInfo = await verifier.getDiagnosticInformation(encodedDeviceResponse, {
    ephemeralReaderKey,
    encodedSessionTranscript,
  });

  inspect(diagnosticInfo);
})();
```

## 签发证书

```js
import { MDoc, Document } from "@auth0/mdl";
import { inspect } from "node:util";

(async () => {
  const document = await new Document('org.iso.18013.5.1.mDL')
    .addIssuerNameSpace('org.iso.18013.5.1', {
      family_name: 'Jones',
      given_name: 'Ava',
      birth_date: '2007-03-25',
    })
    .useDigestAlgorithm('SHA-256')
    .addValidityInfo({
      signed: new Date(),
    })
    .addDeviceKeyInfo({ deviceKey: publicKeyJWK })
    .sign({
      issuerPrivateKey,
      issuerCertificate,
    });

  const mdoc = new MDoc([document]).encode();

  inspect(encoded);
})();
```

## 生成设备响应

```js
import { DeviceResponse, MDoc } from '@auth0/mdl';

(async () => {
  let issuerMDoc;
  let deviceResponseMDoc;

  /**
   * This is what the MDL issuer does to generate a credential:
   */
  {
    let issuerPrivateKey;
    let issuerCertificate;
    let devicePublicKey; // the public key for the device, as a JWK

    const document = await new Document('org.iso.18013.5.1.mDL')
      .addIssuerNameSpace('org.iso.18013.5.1', {
        family_name: 'Jones',
        given_name: 'Ava',
        birth_date: '2007-03-25',
      })
      .useDigestAlgorithm('SHA-256')
      .addValidityInfo({
        signed: new Date(),
      })
      .addDeviceKeyInfo({ deviceKey: devicePublicKey })
      .sign({
        issuerPrivateKey,
        issuerCertificate,
        alg: 'ES256',
      });

    issuerMDoc = new MDoc([document]).encode();
  }

  /**
   * This is what the DEVICE does to generate a response...
   */
  {
    let devicePrivateKey; // the private key for the device, as a JWK

    // Parameters coming from the OID4VP transaction
    let mdocGeneratedNonce, clientId, responseUri, verifierGeneratedNonce;
    let presentationDefinition = {
      id: 'family_name_only',
      input_descriptors: [
        {
          id: 'org.iso.18013.5.1.mDL',
          format: { mso_mdoc: { alg: ['EdDSA', 'ES256'] } },
          constraints: {
            limit_disclosure: 'required',
            fields: [{
                path: ["$['org.iso.18013.5.1']['family_name']"],
                intent_to_retain: false,
              }],
          },
        },
      ],
    };

    deviceResponseMDoc = await DeviceResponse.from(issuerMDoc)
      .usingPresentationDefinition(presentationDefinition)
      .usingSessionTranscriptForOID4VP(mdocGeneratedNonce, clientId, responseUri, verifierGeneratedNonce)
      .authenticateWithSignature(devicePrivateKey, 'ES256')
      .sign();
  }
})();
```

## 许可证

阿帕奇 - 2.0

## 常见问题

### @auth0/mdl 是什么？

根据ISO 18013-5分析并验证MDOC CBOR编码二进制\.

### 如何安装 @auth0/mdl？

在项目目录运行 npm install @auth0/mdl，或使用 pnpm add / yarn add / bun add。

### @auth0/mdl 支持 TypeScript 吗？

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

### @auth0/mdl 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @auth0/mdl 需要什么版本的 Node\.js？

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

### @auth0/mdl 可以商用吗？

@auth0/mdl 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @auth0/mdl 的下载量有多少？

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

### @auth0/mdl 还在维护吗？

最新版本 3\.0\.1 发布于 2025/11/20（11 个月前）；至今共发布 24 个版本，其中过去 12 个月发布了 1 个；首次发布于 2024/02/23。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

