立方体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]档案.