@gandlaf21/bc-ur

中文文档
1.1.12发布于 2024/02/29MITTypeScriptESM + CJS近 30 天下载 5665

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

中文使用文档
文档目录4 节
  1. 安装
  2. 快速启动
  3. 编码信件
  4. 解码信件

业连-UR

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

安装

要安装, 运行 :

yarn add @gandlaf21/bc-ur

快速启动

编码信件

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)
}

解码信件

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 共发布 7 个版本,首次发布于 2024/02/27;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.1.12latest2024/02/292 年前
1.1.112024/02/282 年前
1.1.102024/02/282 年前
1.1.92024/02/282 年前
1.1.82024/02/282 年前
1.1.72024/02/282 年前

关于 @gandlaf21/bc-ur 的常见问题

@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 和提交记录判断。