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

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

Client-side key-import machinery for CubeSigner

原始使用文档

CubeSigner key import

This library implements the client-side encryption used to import keys into CubeSigner.

WARNING

Importing keys using code running in an untrusted environment is dangerous because that code must process secret key material. For example, importing keys from a user's web browser is very risky: exposing secret keys in browsers means that malicious web pages, advertisements, and extensions may be able to steal your key. JS execution environments are also great targets for side-channel attackers.

Whenever possible, Cubist strongly recommends generating keys using the createKey API. We strongly recommend against using local keygen plus import as a replacement for real disaster-recovery backup. Please contact us if you have questions about or need help with disaster-recovery planning.

Example

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,
);

License

Copyright (C) 2024 Cubist, Inc. All rights reserved.

This library is licensed under the MIT and Apache-2.0 licenses. See the [../../NOTICE] file for further information.

版本与发布记录

@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 是什么?

Client-side key-import machinery for 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 和提交记录判断。