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

@kadena/hd-wallet

v0.5.0

Published

Key derivation based on Hierarchical Deterministic (HD)/Mnemonic keys and BIP32, for Kadena

Downloads

1,325

Readme

@kadena/hd-wallet

Key derivation based on Hierarchical Deterministic (HD)/Mnemonic keys and BIP32, for Kadena

Architectural decisions

Check ADRs documents for more information

Getting started

The @kadena/hd-wallet library provides tools to generate mnemonics, derive seeds, and generate and sign transactions with Kadena keys. This README will guide you through installing, using, and understanding the core functionalities of the library.

Installation

To install the library, you can use npm or yarn:

npm install @kadena/hd-wallet

or

yarn add @kadena/hd-wallet

Structure

The library is divided into two parts:

  1. @kadena/hd-wallet - The main library that provides functions to generate mnemonics, derive seeds, and sign transactions.
  2. @kadena/hd-wallet/chainweaver - The Chainweaver-specific library that provides the same functions, but based on the Chainweaver-generated derivation algorithm.

Usage

Below are some common use cases for the @kadena/hd-wallet library.

Generating a Mnemonic

A mnemonic is a set of words that can be used to generate a seed. You can generate a mnemonic using kadenaGenMnemonic:

import { kadenaGenMnemonic } from '@kadena/hd-wallet';

const mnemonic = kadenaGenMnemonic();
console.log(mnemonic); // Outputs a 12-word mnemonic

Converting Mnemonic to Seed

Once you have a mnemonic, you can convert it to a seed using kadenaMnemonicToSeed. This seed can be encrypted with a password for added security:

import { kadenaGenMnemonic, kadenaMnemonicToSeed } from '@kadena/hd-wallet';

const password = 'password';
const mnemonic = kadenaGenMnemonic();
const seed = await kadenaMnemonicToSeed(password, mnemonic);
console.log(seed); // Outputs an encrypted seed string

Signing a Transaction with Seed

You can sign a transaction using a seed and an index. First, create a signer using kadenaSignWithSeed:

import {
  kadenaGenMnemonic,
  kadenaMnemonicToSeed,
  kadenaSignWithSeed,
} from '@kadena/hd-wallet';

const password = 'password';
const mnemonic = kadenaGenMnemonic();
const seed = await kadenaMnemonicToSeed(password, mnemonic);
const index = 0;
const hash = 'transaction-hash';

const signer = kadenaSignWithSeed(password, seed, index);
const signature = await signer(hash);
console.log(signature); // Outputs the signature

Generating a Key Pair from Seed

Generate a key pair (public and private keys) from a seed using kadenaGenKeypairFromSeed:

import {
  kadenaGenKeypairFromSeed,
  kadenaGenMnemonic,
  kadenaMnemonicToSeed,
} from '@kadena/hd-wallet';

const password = 'password';
const mnemonic = kadenaGenMnemonic();
const seed = await kadenaMnemonicToSeed(password, mnemonic);

const [publicKey, privateKey] = await kadenaGenKeypairFromSeed(
  password,
  seed,
  0,
);
// Outputs the public key and encrypted private key
console.log(publicKey, privateKey);

Signing a Transaction with Key Pair

Sign a transaction using a key pair (public and private keys) with kadenaSignWithKeyPair:

import {
  kadenaGenKeypairFromSeed,
  kadenaGenMnemonic,
  kadenaMnemonicToSeed,
  kadenaSignWithKeyPair,
} from '@kadena/hd-wallet';

const password = 'password';
const mnemonic = kadenaGenMnemonic();
const seed = await kadenaMnemonicToSeed(password, mnemonic);
const [publicKey, privateKey] = await kadenaGenKeypairFromSeed(
  password,
  seed,
  0,
);

const txHash = 'tx-hash';
const signer = kadenaSignWithKeyPair(password, publicKey, privateKey);
const signature = await signer(txHash);
console.log(signature); // Outputs the signature

Retrieving Public Keys from Seed

Retrieve public keys from a seed using kadenaGetPublic:

import {
  kadenaGenMnemonic,
  kadenaGetPublic,
  kadenaMnemonicToSeed,
} from '@kadena/hd-wallet';

const password = 'password';
const mnemonic = kadenaGenMnemonic();
const seed = await kadenaMnemonicToSeed(password, mnemonic);

const publicKeyIndex0 = await kadenaGetPublic(password, seed, 0);
const publicKeyIndex1 = await kadenaGetPublic(password, seed, 1);

console.log(publicKeyIndex0, publicKeyIndex1); // Outputs public keys for index 0 and 1

Decrypting Seed or Private Key

Decrypt the encrypted seed or private key using kadenaDecrypt:

import { kadenaDecrypt } from '@kadena/hd-wallet';

const decryptedSeed = kadenaDecrypt(password, seed);
console.log(decryptedSeed); // Outputs the decrypted seed

Conclusion

The @kadena/hd-wallet library offers a robust set of tools for generating mnemonics, deriving seeds, and managing Kadena keys. This README covers the basic usage scenarios. For more detailed documentation, please refer to the library's source code and additional resources.

If you encounter any issues or have any questions, feel free to open an issue on the project's GitHub repository.