@anywalletkit/keyring

中文文档
0.3.9发布于 2026/11/03Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2258

Multi-account, multi-source keyring for Any Wallet Kit: many accounts from one seed, imported seeds and private keys, account discovery — secrets stay in the app's secure storage.

原始使用文档
文档目录4 节
  1. Install
  2. Derivation (what changes per account)
  3. Private-key formats
  4. Security model

@anywalletkit/keyring

npm

Many accounts from many key sources, the way MetaMask, Phantom or Tonkeeper do it:

Install

npm install @anywalletkit/keyring
# or: pnpm add @anywalletkit/keyring  ·  yarn add @anywalletkit/keyring

On npm: @anywalletkit/keyring, published from the release workflow with provenance.

  • a BIP-39 seed (created or imported, optional passphrase) → accounts 0, 1, 2… on every registered chain;
  • an imported private key → exactly one account on one chain;
  • a TON-native 24-word mnemonic (Tonkeeper, Tonhub, MyTonWallet) → one TON account.
import { Keyring } from '@anywalletkit/keyring'
import { WalletManagerEvm } from '@anywalletkit/wallet-evm'
import { WalletManagerSolana } from '@anywalletkit/wallet-solana'

const keyring = await Keyring.load({
  storage,  // KeyringStorage: names, addresses, flags — no secrets
  secrets,  // SecretStorage: one secure-storage entry per source
  chains: { evm: { Manager: WalletManagerEvm, config: { provider } }, solana: { Manager: WalletManagerSolana, config: { rpcUrl } } },
})

const { mnemonic } = await keyring.createMnemonic()             // show the backup screen once
const next = await keyring.addAccount(keyring.listSources()[0]!.id)
await keyring.importMnemonic(words, { discover: { isUsed } })   // restore: adds used accounts 1, 2, …
await keyring.previewPrivateKey('solana', key)                  // show the address first
await keyring.importPrivateKey('solana', key)

await keyring.withAccount(next.id, 'evm', (account) => account.sendTransaction(tx))

// A chain registered after an account was created: derive what it lacks (one secret read per source).
keyring.missingChains(next.id)                                   // ['zcash'] — no secret read
await keyring.completeAddresses(next.sourceId)

Derivation (what changes per account)

chainaccount isame accounts as
EVMm/44'/60'/0'/0/iMetaMask, Rabby, Trust, Rainbow
Solanam/44'/501'/i'/0'Phantom, Solflare, Backpack
TONm/44'/607'/i' (V5R1)Trust (BIP-39); Tonkeeper words → importTonMnemonic
Tronm/44'/195'/0'/0/iTronLink, Trust
BTCm/84'/0'/0'/0/i (P2WPKH)BIP-84 wallets, address index i
NEARm/44'/397'/i'MyNearWallet, Meteor (implicit)
Zcashm/44'/133'/0'/0/iZashi, YWallet, Ledger, Trezor (transparent t1… receivers)

Golden vectors for i = 0..4 are in test/vectors.test.ts; account 0 matches the public reference vectors and the chain managers' own derivation (no existing address moves).

Private-key formats

EVM / Tron: hex · BTC: compressed WIF or hex · Solana: base58 64-byte secret, the JSON byte array, or a base58 32-byte seed · TON: hex seed or 64-byte secret · NEAR: ed25519:<base58> · Zcash: WIF or 32-byte hex (like BTC). A 64-byte ed25519 secret must match its embedded public key.

Not yet: TON V4R2/V3R2 wallet versions for an imported key (V5R1 only), BTC P2TR/P2PKH scanning for an imported WIF (the BTC manager's configured address type is used), non-English BIP-39 wordlists.

Security model

  • The SDK holds no secret between calls. Each call that signs reads the source's secret from SecretStorage, builds the chain manager, and the returned handle zeroizes the key on dispose() (withAccount disposes for you).
  • KeyringStorage only ever sees public data: labels, addresses, indexes, flags and a fingerprint (a hash of the master public key, or of the imported key's public key).
  • Duplicates are caught by that fingerprint — the same seed, the same seed + passphrase, or the same key in another format — without keeping anything secret around.
  • Error messages never echo words, keys or passphrases.
  • removeSource saves the metadata (with the id as a pending delete) before it deletes the secret, so a failed save never strands a source without its key; a failed delete is retried on the next Keyring.load. SecretStorage.delete must resolve for an id that is not there.
  • Parallel imports are serialized: the duplicate check and the secret write run in one queued change, so the same phrase imported twice at once lands once.
  • exportSecret() returns the secret for a backup screen: gate it behind biometrics in the app.

版本与发布记录

@anywalletkit/keyring 共发布 11 个版本,首次发布于 2026/10/25;过去 12 个月发布了 11 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.9latest2026/11/035 天前
0.3.82026/10/309 天前
0.3.72026/10/2811 天前
0.3.62026/10/2712 天前
0.3.52026/10/2612 天前
0.3.42026/10/2612 天前

关于 @anywalletkit/keyring 的常见问题

@anywalletkit/keyring 是什么?

Multi-account, multi-source keyring for Any Wallet Kit: many accounts from one seed, imported seeds and private keys, account discovery — secrets stay in the app's secure storage.

如何安装 @anywalletkit/keyring?

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

@anywalletkit/keyring 支持 TypeScript 吗?

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

@anywalletkit/keyring 支持 ESM 还是 CommonJS?

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

@anywalletkit/keyring 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anywalletkit/keyring 可以商用吗?

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

@anywalletkit/keyring 的下载量有多少?

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

@anywalletkit/keyring 还在维护吗?

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