@asevault/connect

中文文档
0.3.3发布于 2026/10/19Apache-2.0TypeScriptES Module零依赖近 30 天下载 2299

Connect dApps to the AseVault mobile wallet on Asentum - deep-link/QR connection, ML-DSA-65 signing requests, transaction approvals. A product of Asepad.fun.

原始使用文档
文档目录7 节
  1. Usage
  2. Transports
  3. Relay latency and failures
  4. Reader API
  5. Auto-detection
  6. Protocol (v1)
  7. Security

@asevault/connect

Connect an Asentum dApp to the AseVault mobile wallet (ML-DSA-65 signing). Keys stay on the device; every request needs in-app approval. Zero dependencies.

npm install @asevault/connect

Usage

import { AseVaultProvider } from '@asevault/connect';

const wallet = new AseVaultProvider({ name: 'My dApp' });

await wallet.connect();            // approve in AseVault -> session
const address = wallet.address;    // ase1...

const { txHash } = await wallet.callContract({
  to: 'ase1...',                   // or 0x...
  method: 'swapExactIn',
  args: ['1', '0xeeee...', '1000000000000000000', '990000000000000000'],
});

const { txHash: deployTx, address: contract } = await wallet.deploy(source);

const { txHash: sendTx } = await wallet.sendTransaction({ to: 'ase1...', amount: '1000000000000000000' });

const { signature } = await wallet.signMessage({ message: 'hello' });

const { status, receipt } = await wallet.waitForTx(txHash);
// status: 'confirmed' | 'reverted' | 'timeout'
// timeout: no receipt landed. Reverted txs are dropped without a receipt
// on Asentum, so a timeout usually means dropped or reverted.

const gas = await wallet.estimateGas({ to: 'ase1...', method: 'swapExactIn', args });

wallet.on('chainChanged', (id) => {});
wallet.disconnect();

EIP-1193 style request() is supported with the same method names as the injected provider:

await wallet.request({ method: 'ase_sendCall', params: { to, method: 'mint', args: [] } });
await wallet.request({ method: 'eth_blockNumber' });
await wallet.request({ method: 'estimateGas', params: { to, method: 'mint', args: [] } });
await wallet.accounts();
await wallet.getAddress();
wallet.selectedAddress;
wallet.chainId;

Transports

Picked automatically, or forced via new AseVaultProvider({ transport }):

Where the dApp runsTransportUX
AseVault in-app browserInAppTransportIn-place approval sheets
Mobile browserDeepLinkTransportApp switch, approve, back to tab
Desktop browserRelayTransportQR on screen, phone approves

On desktop the provider defaults to the public relay (relay.asepad.fun) and connect() shows the built-in QR modal. Pass relay: false to opt out (connect then fails with WALLET_NOT_INSTALLED).

const wallet = new AseVaultProvider({ relay: true });
await wallet.connect();              // QR modal opens automatically

// Per-call override:
await wallet.connect({ ui: 'none' });

// Render the QR yourself:
const wallet2 = new AseVaultProvider({ relay: true, ui: 'none' });
wallet2.on('uri', (uri) => renderQr(uri));

// Custom renderer:
const wallet3 = new AseVaultProvider({ relay: true, ui: (uri) => myQr(uri) });

// Custom relay URL:
const wallet4 = new AseVaultProvider({ relay: 'https://your-relay' });

// Explicit transport:
import { RelayTransport } from '@asevault/connect';
const wallet5 = new AseVaultProvider({
  transport: new RelayTransport('https://your-relay', { onUri: (uri) => renderQr(uri) }),
});

Relay latency and failures

The wallet polls its request queue every ~2.5 s while foregrounded, and the result poll is 1 s. Expect a few seconds between callContract() and the approval sheet on the phone. If the wallet is backgrounded, the OS decides when it wakes. Show a "check your phone" hint after ~5 s.

connect() probes the relay before showing the QR. If unreachable it throws RELAY_UNREACHABLE. During a pending request, three consecutive unreachable polls also reject with RELAY_UNREACHABLE.

A zero-dependency dev relay is in scripts/dev-relay.mjs. Run it, serve the dApp on your LAN IP, scan the QR.

Reader API

wallet.client (or new AseVaultReader()) handles reads with endpoint failover and timeouts:

MethodReturns
view(contract, method, args)The unwrapped returnValue. JSON strings parsed, scalars as strings
getBalance(address)bigint (wei)
balanceOf(contract, address)via view
getBlockNumber()number
getBlock(n){ receipts: [{ txHash, success, error, recipient, events }] }
getReceipt(hash)receipt or null (pending/not found)
getTxState(hash)`'pending'
waitForTx(hash, timeoutMs?)`{ status: 'confirmed'
waitReceipt(hash, timeoutMs?)receipt or throws on timeout
getContractEvents(contract, { event?, fromBlock?, toBlock?, limit? })matched events, newest first
estimateGas(contract, method, args)bigint gas units
chainId()decimal string
useRpc(urls) / validateRpc(url)endpoint pool + health probe

The /view RPC returns { ok, returnValue, gasUsed }. view() resolves to returnValue directly, not the envelope.

Auto-detection

Inside the AseVault browser the wallet injects window.__asevaultBridge plus window.asevault/window.asentum aliases (request(), connect(), disconnect(), accounts(), getAddress(), sendCall, sendTransfer, signMessage, ase_deploy). InAppTransport binds to __asevaultBridge, so installAseVaultProvider() can replace window.asevault without breaking the channel. The wallet pushes accountsChanged/disconnect/connect events into the page.

Protocol (v1)

  • asevault://v1/connect?origin=&name=&permissions=&callback=&nonce= -> callback?asevault=1&session=<b64> (session carries the ML-DSA-65 proof over ASEVAULT_CONNECT|<nonce>|<address>)
  • asevault://v1/sign?session=&payload=<b64url>&callback=&nonce=&kind= -> callback?asevault=1&tx=<hash> or ?error=<code>&message=
  • asevault://v1/disconnect?session=
  • Relay: POST/GET {relay}/r/<nonce> results, POST/GET {relay}/q queued requests

Security

  • Keys never leave AseVault. dApps see only address, public key, signatures and broadcast results.
  • Every request requires explicit in-app approval.
  • Sessions are origin-scoped and revocable inside AseVault (Connected Apps).

Full integration guide: CONNECT.md.


A product of Asepad.fun.

版本与发布记录

@asevault/connect 共发布 16 个版本,首次发布于 2026/10/16;过去 12 个月发布了 16 个版本。

版本发布日期距今
0.3.3latest2026/10/1919 天前
0.3.22026/10/1919 天前
0.3.12026/10/1919 天前
0.3.02026/10/1919 天前
0.2.82026/10/1622 天前
0.2.72026/10/1622 天前

关于 @asevault/connect 的常见问题

@asevault/connect 是什么?

Connect dApps to the AseVault mobile wallet on Asentum - deep-link/QR connection, ML-DSA-65 signing requests, transaction approvals. A product of Asepad.fun.

如何安装 @asevault/connect?

在项目目录运行 npm install @asevault/connect,或使用 pnpm add / yarn add / bun add。

@asevault/connect 支持 TypeScript 吗?

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

@asevault/connect 支持 ESM 还是 CommonJS?

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

@asevault/connect 可以商用吗?

@asevault/connect 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@asevault/connect 的下载量有多少?

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

@asevault/connect 还在维护吗?

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