@branta-ops/branta

中文文档
4.0.5发布于 2026/11/02MITTypeScriptES Module零依赖近 30 天下载 6378

A JavaScript SDK for the Branta API

原始使用文档
文档目录4 节
  1. Install
  2. Send
  3. Receive
  4. Crypto

@branta-ops/branta

JavaScript SDK for Branta. ESM only.

Use verify() on send and addPayment() on receive. Status handling and parent platforms are in the developer docs.

Install

npm i @branta-ops/branta

Send

import { BrantaEnvironment, BrantaService } from "@branta-ops/branta";

const service = new BrantaService({
  environment: BrantaEnvironment.Production, // Staging everywhere else
});

const result = await service.verify(input); // scanned QR or pasted text

switch (result.status) {
  case "match":
    // Show the card for result.payments[0]. Link it to result.verifyUrl.
    break;
  case "unknown":
    // Not in Branta — show nothing.
    break;
  case "tampered":
    // Destination was altered. Warn. Do not show a verified card.
    break;
  case "incomplete":
    // 5xx, 429, or unreachable. Tell the user. Do not treat as unknown.
    break;
}

On-chain Bitcoin needs a bitcoin: URI with branta_id / branta_secret. bolt11, Ark, and silent payments resolve from the value. A bare address is unknown.

Missing crypto throws crypto_unavailable. Do not treat that as unknown. A 404 is unknown. 5xx, 429, or no network is incomplete.

Receive

import {
  BrantaEnvironment,
  BrantaService,
  DestinationType,
  PaymentBuilder,
} from "@branta-ops/branta";

const service = new BrantaService({
  environment: BrantaEnvironment.Production,
  apiKey: "<api-key>",
});

const payment = new PaymentBuilder()
  .setDescription("Invoice #12345")
  .addDestination("bc1q…", DestinationType.BitcoinAddress)
  .setTtl(600) // seconds
  .build();

const { secret, verifyUrl } = await service.addPayment(payment);

Store secret with the invoice. Put branta_id and branta_secret on the invoice QR.

Crypto

Browsers on HTTPS: nothing to do.

Browsers on HTTP, or React Native / Expo: pass crypto, and use service.createPaymentBuilder() instead of new PaymentBuilder().

React Native / Expo — @noble:

npm i @noble/hashes @noble/ciphers
import { BrantaEnvironment, BrantaService, createNobleCryptoProvider } from "@branta-ops/branta";
import { sha256 } from "@noble/hashes/sha2.js";
import { hmac } from "@noble/hashes/hmac.js";
import { gcm } from "@noble/ciphers/aes.js";
import { randomBytes } from "@noble/hashes/utils.js";

const service = new BrantaService({
  environment: BrantaEnvironment.Production,
  crypto: createNobleCryptoProvider({ sha256, hmac, gcm, randomBytes }),
});

Browser on HTTP — @peculiar/webcrypto:

npm i @peculiar/webcrypto
import { Crypto } from "@peculiar/webcrypto";
import { BrantaEnvironment, BrantaService } from "@branta-ops/branta";

const service = new BrantaService({
  environment: BrantaEnvironment.Production,
  crypto: new Crypto(),
});

Changelog · Security

版本与发布记录

@branta-ops/branta 共发布 35 个版本,首次发布于 2026/02/17;过去 12 个月发布了 35 个版本。

版本发布日期距今
4.0.5latest2026/11/026 天前
4.0.42026/11/026 天前
4.0.32026/11/026 天前
4.0.22026/10/318 天前
4.0.12026/10/318 天前
4.0.02026/10/319 天前

关于 @branta-ops/branta 的常见问题

@branta-ops/branta 是什么?

A JavaScript SDK for the Branta API

如何安装 @branta-ops/branta?

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

@branta-ops/branta 支持 TypeScript 吗?

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

@branta-ops/branta 支持 ESM 还是 CommonJS?

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

@branta-ops/branta 可以商用吗?

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

@branta-ops/branta 的下载量有多少?

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

@branta-ops/branta 还在维护吗?

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