# @gandlaf21/bc-ur 中文文档

规范地址：https://npmcn.com/package/%40gandlaf21/bc-ur/

版本：1\.1\.12
npm 元数据更新时间：2024-02-29T01:39:57.196Z
中文译文更新时间：2026-11-15T22:33:08.218Z
软件包许可：MIT

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

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

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

- 包体积（解压后）：176 kB，75 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：7 个
- 首次发布：2024-02-27T06:28:47.192Z
- 最新版本发布：2024-02-29T01:39:56.733Z
- 近 30 天下载量：5665（2026-10-16 至 2026-11-14，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 0 个）

## 中文简介

联合来文1 执行《统一资源条例》

## 安装

```sh
npm install @gandlaf21/bc-ur
```

也可以使用：`pnpm add @gandlaf21/bc-ur`、`yarn add @gandlaf21/bc-ur`、`bun add @gandlaf21/bc-ur`

## README

# 业连-UR

叉从 `@ngraveio/bc-ur` 执行块链共通以字型标统一资源.

## 安装

要安装, 运行 :

```bash
yarn add @gandlaf21/bc-ur
```

## 快速启动

### 编码信件

```js
import {UR, UREncoder} from '@gandalf21/bc-ur'

const message = {any: 'property'}
const messageBuffer = Buffer.from(JSON.stringify(message))

// First step is to create a UR object from a Buffer
const ur = UR.fromBuffer(messageBuffer)

// Then, create the UREncoder object

// The maximum amount of fragments to be generated in total
// For NGRAVE ZERO support please keep to a maximum fragment size of 200
const maxFragmentLength = 200

// The index of the fragment that will be the first to be generated
// If it's more than the "maxFragmentLength", then all the subsequent fragments will only be
// fountain parts
const firstSeqNum = 0

// Create the encoder object
const encoder = new UREncoder(ur, maxFragmentLength, firstSeqNum)

// Keep generating new parts, until a condition is met; for example the user exits the page, or clicks "DONE"
while(!stop) {
  // get the next part in the sequence
  let part = encoder.nextPart()

  // get the part as a string containing the cbor payload and display it with whatever way
  // the part looks like this:
  // ur:bytes/1-9/lpadascfadaxcywenbpljkhdcahkadaemejtswhhylkepmykhhtsytsnoyoyaxaedsuttydmmhhpktpmsrjtdkgslpgh

  displayPart(part)
}
```

### 解码信件

```js
import {URDecoder} from '@gandalf21/bc-ur'

// Create the decoder object
const decoder = new URDecoder()

do {
  // Scan the part from a QRCode
  // the part should look like this:
  // ur:bytes/1-9/lpadascfadaxcywenbpljkhdcahkadaemejtswhhylkepmykhhtsytsnoyoyaxaedsuttydmmhhpktpmsrjtdkgslpgh
  const part = scanQRCode()

  // register the new part with the decoder
  decoder.receivePart(part)

  // check if all the necessary parts have been received to successfully decode the message
} while (!decoder.isComplete())

// If no error has been found
if (decoder.isSuccess()) {
  // Get the UR representation of the message
  const ur = decoder.resultUR()

  // Decode the CBOR message to a Buffer
  const decoded = ur.decodeCBOR()

  // get the original message, assuming it was a JSON object
  const originalMessage = JSON.parse(decoded.toString())
}
else {
  // log and handle the error
  const error = decoder.resultError()
  console.log('Error found while decoding', error)
  handleError(error)
}

```

## 常见问题

### @gandlaf21/bc-ur 是什么？

联合来文1 执行《统一资源条例》

### 如何安装 @gandlaf21/bc-ur？

在项目目录运行 npm install @gandlaf21/bc-ur，或使用 pnpm add / yarn add / bun add。

### @gandlaf21/bc-ur 支持 TypeScript 吗？

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

### @gandlaf21/bc-ur 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @gandlaf21/bc-ur 可以商用吗？

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

### @gandlaf21/bc-ur 的下载量有多少？

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

### @gandlaf21/bc-ur 还在维护吗？

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

