npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

chainmaker-wallet-jssdk

v2.3.4

Published

长安链公私钥模式jssdk

Downloads

56

Readme

长安链钱包(公私钥模式)基础工具包 chainmakerWalletSDK

2.3.0版本+

 import {handler,tool,hdWallet,ndWallet,smCrypt} from 'chainmaker-wallet-sdk';

 

2.2.0及之前的版本使用如下

安装依赖

  npm install chainmaker-wallet-jssdk -S

非确定性钱包 jbok (Just a Bunch Of Keys)

  • 提供非确定性钱包的派生公私钥方法
  • 支持rsa 和 ecc 两种算法

使用

  import chainmakerWalletJSSDK from 'chainmaker-wallet-sdk';
  const { jbokWallet } = chainmakerWalletJSSDK

方法

  • 派生公私钥
//派生ecc 国密椭圆曲线算法的公私钥对
const {pri,pub}= jbokWallet.generateKeypair('EC','sm2p256v1')

//派生rsa算法公私钥对
const {rsaPri,rsaPub}= jbokWallet.generateKeypair('RSA')

分层确定性钱包 hdWallet(hierarchical deterministic)

  • 提供确定性钱包的创建助记词、验证助记词、派生公私钥方法
  • 仅支持ecc : 国密算法sm2p256v1 和 国际标准secp256r1

HdWallet类

支持国密算法sm2p256v1 和 国际标准secp256r1 两套曲线算法

使用

 import chainmakerWalletJSSDK from 'chainmaker-wallet-sdk';
 const { HdWallet } = chainmakerWalletJSSDK;
 const sm2hdw = new HdWallet('sm2p256v1');//国密算法sm2p256v1 钱包实例
 const secp256Hdw = new HdWallect('secp256r1');//国际标准secp256r1 钱包实例

hdWallet实例

国密算法sm2p256v1的钱包实例,等价于 new HdWallet('sm2p256v1')

使用

  import chainmakerWalletJSSDK from 'chainmaker-wallet-sdk';
  const { hdWallet } = chainmakerWalletJSSDK;

方法

  • 创建助记词

  const mnemonics = hdWallet.createMnemonics();
  //future cloth island express vanish shell keen verify palm hard vibrant unusual
  • 验证助记词

  const hdWallet.validateMnemonic(mnemonics);
  • 根据助记词和具体索引派生公私钥,内置路径索引是[66,0,0,0]

  const ketPair = hdWallet.deriveKeyPairByIndex(mnemonics,0); 
   //等价于 hdWallet.deriveKeyPairByFullPath(words,[66, 0, 0, 0 ,0]);
  const { pri,pub } = ketPair;
  • 根据助记词和完整路径索引派生公私钥

  hdWallet.deriveKeyPairByFullPath(words,[66,0,0,0,0]);
  const { pri,pub } = ketPair;

方法库 tools

钱包核心方法 tools.handler

  • 提供私钥转公钥、私钥转地址、公钥转地址、验证私钥格式是否有效、验证地址是否有效、签名、验签方法
  • 支持rsa 和 ecc 两种算法

使用

  import chainmakerWalletJSSDK from 'chainmaker-wallet-sdk';
  const { tools } = chainmakerWalletJSSDK;
  const { handler } = chainmakerWalletJSSDK;

方法

  • 私钥转公钥
  const pub = handler.priKey2PubKey(pri);
  • 私钥转地址
  const address = handler.priKey2Address(pri);
  • 公钥转地址
  const address = handler.pubKey2Address(pub);
  • 验证私钥格式是否有效
  const isValid = handler.checkPriKeyValidity(pri);
  • 验证地址格式是否有效
  const isValid = handler.checkAddressValidity(address);
  • 私钥签名
  // 方式1:options不传,
  // 如果pri是ecc sm2p256v1算法私钥,则默认使用的是大sm3digest摘要算法。
  // 如果pri是ecc 其他曲线算法私钥,则默认使用SHA256withECDSA 摘要算法
  // 如果pri是rsa私钥,则默认使用SHA256withRSA摘要算法。
  const signDataHex = handler.sign(pri,rowDataHex);

  //方式2:可通过option参数,指定alg 摘要算法
  const signDataHex1 = handler.sign(pri,rowDataHex,{
    alg:"SHA256withRSA"
  });
  • 公钥验签
  // 方式1:options不传,
  // 如果pri是ecc sm2p256v1算法私钥,则默认使用的是大sm3digest摘要算法。
  // 如果pri是ecc 其他曲线算法私钥,则默认使用SHA256withECDSA 摘要算法
  // 如果pri是rsa私钥,则默认使用SHA256withRSA摘要算法。
  const isValid = handle.verify(rowDataHex,signDataHex,pub)

  //方式2:可通过option参数,指定alg 摘要算法
  const isValid1 = handle.verify(rowDataHex,signDataHex,pub,{
    alg:"SHA256withRSA"
  })

辅助方法 tools.check

  • 提供一些验证方法,验证是不是 ecc国密算法的密钥、验证是不是非国密的ecc算法密钥、验证是不是rsa密钥、验证是否是pem格式、验证是不是hex字符串

使用

  import chainmakerWalletJSSDK from 'chainmaker-wallet-sdk';
  const { tools } = chainmakerWalletJSSDK;
  const { check } = chainmakerWalletJSSDK;

方法

  • 验证是不是 ecc国密算法sm2p256v1的密钥
  const result = check.isEccSm2p256(pri);
  • 验证是不是非国密的ecc算法密钥
 const result = check.isECC(pri);
  • 验证是不是rsa密钥
const result = check.isRSA(pri);
  • 验证是否是pem格式
  const result = handler.isPem(pri);
  • 验证是不是hex字符串
  const result = handler.isHex(hex);

辅助方法 tools.convert

  • 提供一些类型转换方法, hex、unit8Array、utf8之间转换

使用

  import chainmakerWalletJSSDK from 'chainmaker-wallet-sdk';
  const { tools } = chainmakerWalletJSSDK;
  const { convert } = chainmakerWalletJSSDK;

方法

  • utf8转为hex
  const strHex = convert.utf8ToHex(str);
  • hex转为Uint8Array
 const bytes = convert.hexToBytes(strHex);
  • Uint8Array转为hex
const hex = convert.bytesToHex(uint8arr);
  • Uint8Array转为utf8字符串
const str = convert.bytesToUtf8(uint8arr); 
  • utf8ToBytes转为Uint8Array
  const bytes = convert.utf8ToBytes(str);
  • base64格式转为hex
  const hex = convert.base64ToHex(base64Str);
  • 数组类型 转换为 Uint8Array类型
  const uni8Ary = convert.ary2Uint8Array(arr);
  • Uint8Array类型 转换为 数组类型
  const arr = convert.uint8Array2Ary(uint8arr);