@cubist-labs/cubesigner-sdk-key-import

中文文档
0.4.284发布于 2026/09/09MIT OR Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 5307

用于 CubeSigner 的客户端密钥导入机械

中文使用文档

立方体Signer 密钥导入

此库执行用于导入密钥的客户端加密 进入CubeSigner.

警告

使用在不可信环境下运行的代码导入密钥 危险 因为密码必须处理秘密的关键材料 例如,进口 用户网页浏览器的密钥为 非常危险: 披露密钥 浏览器中指恶意网页、广告和扩展 可能可以偷你的钥匙。 JS执行环境也很好 目标为侧道攻击者.

只要有可能,Cubist强烈建议使用 createKey API (英语). 我们强烈建议不使用本地键源加 导入以替换真正的灾后恢复备份。 请联系 如果你对灾后恢复规划有疑问或需要帮助的话.

示例

import * as cs from "@cubist-labs/cubesigner-sdk";
import * as csFs from "@cubist-labs/cubesigner-sdk-fs-storage";
import { KeyImporter, type MnemonicToImport } from "@cubist-labs/cubesigner-sdk-key-import";

// create a CubeSigner client from credentials on-disk, which
// you can create by running `cs login` from the CLI.
const client = await cs.CubeSignerClient.create(csFs.defaultManagementSessionManager());

// create the key-importer instance
const keyImporter = new KeyImporter(client.org());

// mnemonics to import directly as EVM keys
const evmMnemonics: MnemonicToImport[] = [
  {
    mnemonic: "car split like parrot uphold faint amount alert inch bean priority custom auction denial reason oyster food duck horn top battle video seed company",
    derivationPath: "m/44'/60'/0'/0/0",
  },
  {
    mnemonic: "force focus walnut scale barrel faint hotel fabric source because heavy provide bridge intact they receive stairs matter fetch family color happy slender accident",
    derivationPath: "m/44'/60'/1'/0/0",
    password: "bip39 passwords are silly",
  },
];
// mnemonic to import directly as Bitcoin Segwit keys
const btcMnemonics: MnemonicToImport[] = [
  {
    mnemonic: "style goddess hair mountain open when train mail fly engage fork walnut end toe mail price priority ocean uncover immune spray person slogan avoid",
    derivationPath: "m/84'/0'/0'/0/0",
  },
  {
    mnemonic: "marine airport maze doll note assume deliver second bus include deal escape detail friend letter captain glide actual resemble nation shell search elephant busy",
    derivationPath: "m/84'/0'/9'/0/1",
  },
];

// import the keys
const evmKeys = await keyImporter.importMnemonics(cs.Secp256k1.Evm, evmMnemonics);
const btcKeys = await keyImporter.importMnemonics(cs.Secp256k1.Btc, btcMnemonics);

// If you want to derive many keys from the same mnemonic, you should import
// the bare mnemonic and use the `deriveKey` and/or `deriveKeys` methods to
// create keys.
const bareMnemonic: MnemonicToImport = {
  mnemonic: "divide impact town typical inhale uncover rifle pet multiply idea long before debate apart pulse type need produce among pony attend cat injury ring",
};

// First, import the bare mnemonic
const mnemonic = (await keyImporter.importMnemonics(cs.Mnemonic, [bareMnemonic]))[0];

// Then derive keys from it.
const deriveResponse = await org.deriveKey(cs.Secp256k1.Taproot, "m/86'/0'/3'/1/0", mnemonic.materialId);
const otherDeriveResponses = await org.deriveKeys(
  cs.Secp256k1.Ava,
  [
    "m/1'/2'/3",
    "m/4'/5/6",
    "m/7/8'/9",
  ],
  mnemonic.materialId,
);

许可证

版权(C)2024 Cubist, Inc. 版权所有.

这个图书馆根据麻省理工学院和Apache-2.0许可证获得许可. 详情见[././NOTICE]档案.

版本与发布记录

@cubist-labs/cubesigner-sdk-key-import 共发布 106 个版本,首次发布于 2024/09/13;过去 12 个月发布了 50 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.4.284latest2026/09/092 个月前
0.4.2812026/08/192 个月前
0.4.2802026/08/142 个月前
0.4.2792026/08/122 个月前
0.4.2762026/08/063 个月前
0.4.2752026/08/043 个月前

关于 @cubist-labs/cubesigner-sdk-key-import 的常见问题

@cubist-labs/cubesigner-sdk-key-import 是什么?

用于 CubeSigner 的客户端密钥导入机械

如何安装 @cubist-labs/cubesigner-sdk-key-import?

在项目目录运行 npm install @cubist-labs/cubesigner-sdk-key-import,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@cubist-labs/cubesigner-sdk(^0.4.284)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cubist-labs/cubesigner-sdk-key-import 支持 TypeScript 吗?

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

@cubist-labs/cubesigner-sdk-key-import 支持 ESM 还是 CommonJS?

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

@cubist-labs/cubesigner-sdk-key-import 可以商用吗?

@cubist-labs/cubesigner-sdk-key-import 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cubist-labs/cubesigner-sdk-key-import 的下载量有多少?

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

@cubist-labs/cubesigner-sdk-key-import 还在维护吗?

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