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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jcc_wallet

v4.0.2

Published

Toolkit of wallet to manage multiple chains & support multiple keystores for each chain

Downloads

146

Readme

jcc_wallet

npm build Coverage Status npm downloads PRs Welcome

Preface

jcc_wallet is a wallet toolkit of JCCDex. At present, it can handle the creation and verification of jingtum, moac, ethereum, stm, call & bizain wallet, import and export wallet with keystore file, and set password for wallet.

jcc_wallet是井畅交换平台的钱包处理工具,目前可以处理jingtum, moac, ethereum, stm, call以及bizain钱包的创建和校验,以 keystore 形式导入和导出钱包,设置钱包交易密码。

jcc_wallet Support running in browsers

井畅应用交流群: 557524730

JCCDex Tech support QQ group ID: 557524730

Installtion

npm install jcc_wallet

CDN

jcc_wallet as a global variable.

<script src="https://unpkg.com/jcc_wallet/dist/jcc-wallet.min.js"></script>

Table of Contents

Structure of Jingchang Wallet

For more see IJingchangWalletModel.

API of JingchangWallet

Support multiple wallet keystore for each type.

Usage

const JingchangWallet = require("jcc_wallet").JingchangWallet;
// import { JingchangWallet } from 'jcc_wallet'

constructor

/**
 * Creates an instance of JingchangWallet.
 * @param {IJingchangWalletModel} wallet
 * @param {boolean} [multiple=false] if the value is true, support save multiple wallet keystore
 * for each type, otherwise only support one.
 * @param {boolean} [samePassword=true] if the value is true, use the default swt keystore's password
 * which be generated in the beginning as password for other type.
 * @memberof JingchangWallet
 */

generate

/**
 * create a jingchang wallet
 *
 * @static
 * @param {string} password password for keystore
 * @param {string} [secret] swtc chain's secret
 * @returns {Promise<IJingchangWalletModel>} resolve jingchang wallet if success.
 * @memberof JingchangWallet
 */

isValid

/**
 * check jingchang wallet is valid or not
 *
 * @static
 * @param {*} wallet
 * @returns {boolean} return true if valid.
 * @memberof JingchangWallet
 */

get

/**
 * get jingchang wallet from local storage
 *
 * @static
 * @returns {(IJingchangWalletModel | null)} return jingchang wallet or null.
 * @memberof JingchangWallet
 */

clear

/**
 * clear jingchang wallet from local storage.
 *
 * @static
 * @memberof JingchangWallet
 */

save

/**
 * save jingchang wallet to local storage.
 *
 * @static
 * @param {IJingchangWalletModel} wallet
 * @memberof JingchangWallet
 */

deriveKeyPair

/**
 * derive key pair with secret
 *
 * @static
 * @param {string} secret
 * @param {string} [chain="swt"]
 * @returns {IKeyPair} for privateKey, it's length should be 64 when call `decryptWithPrivateKey`, but the origin derived
 * privateKey's length is 66 that contains prefix `00` for `secp256k1` or `ED` for `ed25519`, so removed it.
 * @memberof JingchangWallet
 */

encryptWithPublicKey

/**
 * encrypt data with public key
 *
 * @static
 * @param {string} message
 * @param {string} publicKey
 * @returns {Promise<IEncrypt>}
 * @memberof JingchangWallet
 */

decryptWithPrivateKey

/**
 * decrypt data with private key
 *
 * @static
 * @param {IEncrypt} message
 * @param {string} privateKey the privateKey's length should be 64
 * @returns {Promise<string>}
 * @memberof JingchangWallet
 */

getWallets

/**
 * get wallets from jingchang wallet.
 *
 * @static
 * @param {IJingchangWalletModel} jcWallet
 * @returns {Array<IKeystoreModel>} return wallets if valid, otherwise return empty array.
 * @memberof JingchangWallet
 */

setJingchangWallet

/**
 * set property of _jingchangWallet
 *
 * @param {IJingchangWalletModel} wallet
 * @memberof JingchangWallet
 */

getAddress

/**
 * get default wallet's keystore address for each type
 *
 * @param {string} [type="swt"]
 * @returns {Promise<string>} resolve address if success
 * @memberof JingchangWallet
 */

getWalletWithType

/**
 * get default wallet keystore with type
 *
 * @param {string} [type="swt"]
 * @returns {Promise<IKeystoreModel>} resolve default wallet keystore if success.
 * @memberof JingchangWallet
 */

getWalletWithAddress

/**
 * get wallet keystore with address
 *
 * @param {string} address
 * @returns {Promise<IKeystoreModel>} resolve wallet keystore if success.
 * @memberof JingchangWallet
 */

hasDefault

/**
 * check if has default wallet for each type
 *
 * @param {string} [type="swt"]
 * @returns {boolean} return true if has default.
 * @memberof JingchangWallet
 */

getSecretWithType

/**
 * get the default wallet keystore's secret with type.
 *
 * @param {string} password
 * @param {string} [type="swt"]
 * @returns {Promise<string>} resolve secret if success.
 * @memberof JingchangWallet
 */

getSecretWithAddress

/**
 * get the wallet keystore's secret with address.
 *
 * @param {string} password
 * @param {string} address
 * @returns {Promise<string>} resolve secret if success.
 * @memberof JingchangWallet
 */

changeWholePassword

/**
 * change the whole jingchang wallet password, if you set property of _samePassword is false,
 * will throw an error
 *
 * @param {string} oldPassword
 * @param {string} newPassword
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

changePasswordWithAddress

/**
 * change the keystore password with address, if you set the property of _samePassword is true,
 * will throw an error
 *
 * @param {string} address
 * @param {string} oldPassword
 * @param {string} newPassword
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

removeWalletWithType

/**
 * remove default wallet keystore of the given type
 * @param {string} [type="swt"]
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

removeWalletWithAddress

/**
 * remove wallet keystore of the given address
 *
 * @param {string} address
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

setDefaultWallet

/**
 * set defalut wallet keystore for each type
 *
 * @param {string} address
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

importSecret

/**
 * import secret
 *
 * @param {string} secret
 * @param {string} password
 * @param {string} type
 * @param {(secret: string) => string} retriveSecret
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

findWallet

/**
 * find wallet keystore according to filter function
 *
 * @protected
 * @param {(wallet: IKeystoreModel) => boolean} filter
 * @returns {IKeystoreModel} return wallet keystore if existent, otherwise throw `keystore is invalid`
 * if the jingchang wallet is invalid or throw `wallet is empty` if the wallet isn't existent
 * @memberof JingchangWallet
 */

getEncryptData

/**
 * encrypt data
 *
 * @protected
 * @param {string} password
 * @param {IKeypairsModel} keypairs
 * @returns {IKeystoreModel}
 * @memberof JingchangWallet
 */

saveWallet

/**
 * save wallet keystore to jingchang wallet
 *
 * @private
 * @param {string} password
 * @param {IKeypairsModel} keypairs
 * @returns {Promise<IJingchangWalletModel>} resolve new jingchang wallet if success
 * @memberof JingchangWallet
 */

HD Wallet

jcc wallet support BIP32/39/44 standard.

more detail see test/hd.spec.js test case.

// normally hd maniuplate
IHDWallet hd = HDWallet.generate({ language: "chinese_simplified" });

// derive bsc wallet
hd.deriveWallet({ chain: BIP44Chain.BSC, account: 0, index: 0 })
hd.getAddress();

// don't worry about address/secret format, hd object have chain type attribute, check it by native chain sdk
hd.validAddress("your address, like jxxxxx or 0x1234");
hd.validSecret("your secret");

// default encode utf-8
hd.hash("message text");

// sign by hd private key automatically
hd.sign("message text");

// verify message signature is sign address signed or not
hd.verify("message text", signature, signAddress);
// or if you don't passby address, you can passby keypair
hd.verify("message test", signature, null, keypair)

Deprecated API

Deprecated api will be removed after 2020.1.1, please update asap.

For more see deprecatedAPI.