@albedo-link/intent

中文文档
0.13.0发布于 2025/06/13MITTypeScriptES Module零依赖近 30 天下载 12.4万

A lightweight browser wrapper for Albedo API that provides a promise-based interface for all supported intents.

原始使用文档
文档目录5 节
  1. Installation
  2. Usage
  3. Intents
  4. Implicit session utils
  5. Development

Intent interface module for Albedo

This library is a lightweight browser wrapper for Albedo API that provides a promise-based interface for all supported intents.

Installation

npm i -S @albedo-link/intent

Usage

Setup

import albedo from '@albedo-link/intent'

Intents

Intent public_key - View public key

Requests account public key. It's a simple way of authentication for Stellar-based applications. The response ensures that a user owns the corresponding secret key.

Parameters

  • token (string) - (optional) Verification token generated by the application (should be unique or random).
  • callback (string) - (optional) Optional URL callback where Albedo will POST a signed token and public key.
  • require_existing (boolean) - (optional) Allow existing Albedo accounts only.

Returns

  • pubkey (string) - User-selected public key.
  • signed_message (string) - HEX-encoded authentication message derived from the public key and verification token.
  • signature (string) - HEX-encoded ED25519 signature of the authentication message that can be further used to verify user's keypair ownership.

Example

albedo.publicKey({
    token: 'r9gbUuThXLr/wOrg2dxWHOO4DQsvQsTpkv1OtfETB3c='
})
    .then(res => console.log(res))

Intent sign_message - Sign text message

Requests arbitrary message signing. Can be used to implement identity/ownership verification.

Parameters

  • message (string) - (required) Text message to sign.
  • pubkey (string) - (optional) Specific public key requested by the application.
  • callback (string) - (optional) Optional URL callback where Albedo will POST a signed message.

Returns

  • pubkey (string) - User-selected public key.
  • original_message (string) - Text message to sign from request.
  • signed_message (string) - HEX-encoded message derived from the public key and original message.
  • message_signature (string) - HEX-encoded ED25519 signature of the signed message.

Example

albedo.signMessage({
    message: 'Alice doesn\'t trust Bob'
})
    .then(res => console.log(res))

Intent tx - Sign transaction

Requests a signature for the transaction. Returns the signed transaction envelope that can be submitted to the network or used for multi-sig coordination.

Parameters

  • xdr (string) - (required) XDR-encoded transaction envelope to sign.
  • pubkey (string) - (optional) Specific public key requested by the application.
  • network (string) - (optional) Stellar network identifier.
  • callback (string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.
  • description (string) - (optional) Optional human-friendly short transaction description provided by developers.
  • submit (boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.

Returns

  • xdr (string) - XDR-encoded transaction envelope from request.
  • tx_hash (string) - HEX-encoded transaction hash.
  • signed_envelope_xdr (string) - XDR-encoded transaction envelope with new signatures.
  • network (string) - Stellar network identifier.
  • result (object) - Optional response from Horizon if the transaction has been submitted automatically.

Example

albedo.tx({
    xdr: 'AAAAALPZeTF.......B0dpb99l'
})
    .then(res => console.log(res))

Intent pay - Make payment

Requests a payment from a user. Works with any Stellar asset, supports transaction memo.

Parameters

  • amount (string) - (required) Requested payment amount.
  • destination (string) - (required) Payment destination address.
  • asset_code (string) - (optional) Asset code (skip for XLM).
  • asset_issuer (string) - (optional) Asset issuer (skip for XLM).
  • memo (string) - (optional) Transaction memo (required for exchanges and some anchors).
  • memo_type (string) - (optional) Transaction memo type.
  • pubkey (string) - (optional) Specific public key requested by the application.
  • network (string) - (optional) Stellar network identifier or private network passphrase.
  • callback (string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.
  • submit (boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.

Returns

  • amount (string) - Payment amount from request.
  • destination (string) - Payment destination address from request.
  • asset_code (string) - Asset code from request.
  • asset_issuer (string) - Asset issuer from request.
  • memo (string) - Transaction memo from request.
  • memo_type (string) - Transaction memo type from request.
  • tx_hash (string) - HEX-encoded transaction hash.
  • signed_envelope_xdr (string) - XDR-encoded transaction envelope with new signatures.
  • pubkey (string) - User-selected public key.
  • network (string) - Stellar network identifier.
  • result (object) - Optional response from Horizon if the transaction has been submitted automatically.

Example

albedo.pay({
    amount: '5',
    asset_code: 'EURT',
    asset_issuer: 'GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S'
})
    .then(res => console.log(res))

Intent trust - Establish trustline

Requests permission to create a trustline to a given Stellar asset. Gradually simplifies the process of creating trustlines for anchors, ICOs, and airdrops.

Parameters

  • asset_code (string) - (required) Trustline asset code.
  • asset_issuer (string) - (required) Trustline asset issuer address.
  • limit (string) - (optional) Trust limit.
  • memo (string) - (optional) Transaction memo (required for exchanges and some anchors).
  • memo_type (string) - (optional) Transaction memo type.
  • pubkey (string) - (optional) Specific public key requested by the application.
  • network (string) - (optional) Stellar network identifier or private network passphrase.
  • callback (string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.
  • submit (boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.

Returns

  • asset_code (string) - Trustline asset code from request.
  • asset_issuer (string) - Trustline asset issuer address from request.
  • limit (string) - Trust limit from request.
  • tx_hash (string) - HEX-encoded transaction hash.
  • signed_envelope_xdr (string) - XDR-encoded transaction envelope with new signatures.
  • pubkey (string) - User-selected public key.
  • network (string) - Stellar network identifier.
  • result (object) - Optional response from Horizon if the transaction has been submitted automatically.

Example

albedo.trust({
    asset_code: 'EURT',
    asset_issuer: 'GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S'
})
    .then(res => console.log(res))

Intent exchange - Swap tokens

Requests permission to buy tokens on Stellar DEX at market price.

Parameters

  • amount (string) - (required) The amount of asset to buy.
  • max_price (string) - (required) Maximum price the user willing to pay.
  • sell_asset_code (string) - (optional) Asset code of the asset to sell.
  • sell_asset_issuer (string) - (optional) Issuer account of the asset to sell.
  • buy_asset_code (string) - (optional) Asset code of the asset to buy.
  • buy_asset_issuer (string) - (optional) Issuer account of the asset to buy.
  • memo (string) - (optional) Transaction memo (required for exchanges and some anchors).
  • memo_type (string) - (optional) Transaction memo type.
  • pubkey (string) - (optional) Specific public key requested by the application.
  • network (string) - (optional) Stellar network identifier or private network passphrase.
  • callback (string) - (optional) Optional URL callback where Albedo will POST the signed transaction XDR instead of submitting it to Horizon.
  • submit (boolean) - (optional) If set, the signed transaction will be submitted to the Horizon server instead of returning it to the application.

Returns

  • amount (string) - The amount of asset to buy from request.
  • max_price (string) - Maximum price the user willing to pay from request.
  • sell_asset_code (string) - Asset code of the asset to sell from request.
  • sell_asset_issuer (string) - Issuer account of the asset to sell from request.
  • buy_asset_code (string) - Asset code of the asset to buy from request.
  • buy_asset_issuer (string) - Issuer account of the asset to buy from request.
  • tx_hash (string) - HEX-encoded transaction hash.
  • signed_envelope_xdr (string) - XDR-encoded transaction envelope with new signatures.
  • pubkey (string) - User-selected public key.
  • network (string) - Stellar network identifier.
  • result (object) - Optional response from Horizon if the transaction has been submitted automatically.

Example

albedo.exchange({
    amount: '5',
    max_price: '3.5',
    sell_asset_code: 'USD',
    sell_asset_issuer: 'GDUKMGUGDZQK6YHYA5Z6AY2G4XDSZPSZ3SW5UN3ARVMO6QSRDWP5YLEX',
    buy_asset_code: 'EURT',
    buy_asset_issuer: 'GAP5LETOV6YIE62YAM56STDANPRDO7ZFDBGSNHJQIYGGKSMOZAHOOS2S'
})
    .then(res => console.log(res))

Intent implicit_flow - Implicit permissions

Requests temporary access token for one or more intents that can be used to execute actions without explicit confirmation from the user. In order to be executed implicitly, an implicit flow permissions for a given intent should be granted and "pubkey" parameter set.

Parameters

  • intents (string|string[]) - (required) Requested implicit flow intents.
  • network (string) - (optional) Stellar network identifier or private network passphrase.

Returns

  • granted (boolean) - Whether a user granted permissions or not.
  • intents (string[]) - Requested implicit flow intents.
  • grants (string[]) - Implicit flow intents that have been granted.
  • session (string) - Unique implicit session id.
  • valid_until (number) - Session expiration timestamp.
  • pubkey (string) - User-selected public key.
  • network (string) - Stellar network identifier.

Example

albedo.implicitFlow({
    intents: 'tx,pay,trust,sign_message'
})
    .then(res => console.log(res))

Intent manage_account - Open account settings

Opens account settings window for a given account.

Parameters

  • pubkey (string) - (required) Specific public key requested by the application.
  • network (string) - (optional) Stellar network identifier or private network passphrase.

Returns

  • pubkey (string) - Public key from intent request.

Example

albedo.manageAccount()
    .then(res => console.log(res))

Intent batch - Intents batch

Requests execution of several tx intents bundled together. This intent is atomic – a user confirms or rejects all bundled requests at once, with the same account and the same Stellar network.

Parameters

  • intents (object[]) - (required) Requested tx intents that should be executed together.
  • pubkey (string) - (optional) Specific public key requested by the application.
  • network (string) - (optional) Stellar network identifier or private network passphrase.

Returns

  • intents (object[]) - Requested tx intents.
  • results (object[]) - Array of results for each requested intent.
  • pubkey (string) - User-selected public key.
  • network (string) - Stellar network identifier.

Example

albedo.batch({
    intents: 'tx,pay,trust,sign_message'
})
    .then(res => console.log(res))

Implicit session utils

Collection of helpers to simplify various operations in the implicit mode.

isImplicitSessionAllowed(intent, pubkey)

Checks whether an implicit session has been granted earlier for an intent + pubkey pair.

Parameters

  • intent (string) - (required) Intent to check.
  • pubkey (string) - (required) Public key of the account which granted access.

Returns

  • true/false

Example

const isAllowed = albedo.isImplicitSessionAllowed(
    'tx', 
    'GBQW4KLMRXIMSDWBEWX4AWQKWYW7R3E7SFPSHTUDTFFT22NNUC6COL72'
)

listImplicitSessions()

Enumerates all currently active implicit sessions.

Returns

  • An array of active session descriptors.

Example

for (let session of albedo.listImplicitSessions()){
    console.log(session.pubkey, session.valid_until, session.grants)
}

forgetImplicitSession(pubkey)

Revokes session permission granted for an account.

Parameters

  • pubkey (string) - (required) Public key of the account which granted access.

Example

const pubkey = 'GBQW4KLMRXIMSDWBEWX4AWQKWYW7R3E7SFPSHTUDTFFT22NNUC6COL72'
albedo.forgetImplicitSession(pubkey)
console.log(albedo.listImplicitSessions().some(s => s.pubkey === pubkey))

Development

To create UMD library bundle, run the following NPM script:

npm run build

It will also automatically update examples and parameters definitions for all available intents.

Running tests:

npm run test

版本与发布记录

@albedo-link/intent 共发布 18 个版本,首次发布于 2020/07/14;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.13.0latest2025/06/131.4 年前
0.12.02022/04/284 年前
0.11.22021/06/155 年前
0.11.12021/05/035 年前
0.11.02021/03/195 年前
0.10.22021/01/295 年前

关于 @albedo-link/intent 的常见问题

@albedo-link/intent 是什么?

A lightweight browser wrapper for Albedo API that provides a promise-based interface for all supported intents.

如何安装 @albedo-link/intent?

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

@albedo-link/intent 支持 TypeScript 吗?

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

@albedo-link/intent 支持 ESM 还是 CommonJS?

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

@albedo-link/intent 可以商用吗?

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

@albedo-link/intent 的下载量有多少?

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

@albedo-link/intent 还在维护吗?

最新版本 0.13.0 发布于 2025/06/13(1.4 年前);至今共发布 18 个版本,其中过去 12 个月发布了 0 个;首次发布于 2020/07/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。