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

@lisk-builders/lisk-hd-key

v2.1.0

Published

HD key derivation for Lisk coin

Downloads

35

Readme

Lisk HD Key

Coverage Status A Typescript based module that provides addition functionality for the Key Derivation in the Lisk ecosystem.

Installation

npm i --save @lisk-builders/lisk-hd-key

Examples

getPublicKey(path, seed) In this example we will get the public key for a Lisk address. The function should get the hexadecimal value of the given BIP39 seed.

seed A 256 bits hexadecimal string.

06bae687f0250ab9533be2ac9717ae2a802d69c97d5..

path Derived from BIP0044 we use the same pattern. Extra information on the what and why of the parameter can be found on the given url.

m / purpose' / coin_type' / account' / change' / address_index'

NOTE: Every Lisk wallet that provides hardware wallet integration are simply using the following derivation:

m / purpose' / coin_type' / account'

Usage

const { getPublicKey } = require('lisk-hd-key');

const bip39 = require('bip39');
const path = "m/44'/134'/0'";

const doPubKeyTest = async () => {
    const seed = bip39.generateMnemonic();
    // or custom seed
    // const seed = "future dose defense ..."

    // 18e48e187b700d4596983f2efaf64f63c31ff13b4537abea1157bdf45c1fc9e5c5d8a817048616d24dcd0b7ae638df786cec2dc0749f6847724905988ae56b0e
    const hexSeed = await bip39.mnemonicToSeed(seed);
    
    // <Buffer e7 7d a0 2e 45 ec 11 a3 69 70 58 2e ad 68 11 e2 78 79 7a 14 f3 15 a0 a6 9a 3e fe 9f 6c 76 24 b6>
    const publicKey = getPublicKey(path, hexSeed);
    console.info('publicKey', publicKey);
    console.info('publicKey hex', publicKey.toString('hex'));
    
}

doPubKeyTest();

signTransaction( seed, path, transaction, networkId = liskMainnet ) In this example we will sign a transaction. Signing a transaction means that nobody can alter the content of the transaction without invalidating your signature.

seed A 256 bits hexadecimal string. Ex:

06bae687f0250ab9533be2ac9717ae2a802d69c97d5..

path Derived from BIP0044 we use the same pattern. Extra information on the what and why of the parameter can be found on the given url.

m / purpose' / coin_type' / account' / change' / address_index'

NOTE: Every Lisk wallet that provides hardware wallet integration are simply using the following derivation:

m / purpose' / coin_type' / account'

The apostrophe means that the index is hardened.

transaction This parameter is a Lisk transaction object. It can have the same properties as a transaction described in the given url.

networkId (Lisk mainnet if not provided) the network identifier (as string) of the target chain. By default Lisk Mainnet is used. Ex:

4c09e6a781fc4c7bdb936ee815de8f94190f8a7519becd9de2081832be309a99"

(Lisk Mainnet)

Usage

const { getPublicKey, signTransaction, getBroadcastBytes } = require('lisk-hd-key');

const bip39 = require('bip39');
const path = "m/44'/134'/0'";


const doSignTest = async () => {
    const seed = bip39.generateMnemonic();
    // or with your seed
    // const seed = "bread stock include ...";
    
    // ex: 18e48e187b700d4596983f2efaf64f63c31ff13b4537abea1157bdf45c1fc9e5c5d8a817048616d24dcd0b7ae638df786cec2dc0749f6847724905988ae56b0e
    const hexSeed = await bip39.mnemonicToSeed(seed);
    
    // ex: <Buffer e7 7d a0 2e 45 ec 11 a3 69 70 58 2e ad 68 11 e2 78 79 7a 14 f3 15 a0 a6 9a 3e fe 9f 6c 76 24 b6>
    const publicKey = getPublicKey(path, hexSeed);
    // ex: <Buffer ad 68 11 e2 78 79 7a 14 f3 15 a0 a6 9a 3e fe 9f 6c 76 24 b6>
    const address = cryptography.getAddressFromPublicKey(publicKey);

    const unsignedTransaction = {
        moduleID: 2,
        assetID: 0,
        nonce: BigInt(3),
        fee: BigInt(100000),
        senderPublicKey: publicKey, // If not provided, it will be set automatically
        asset: {
            amount: BigInt(100000000),
            recipientAddress: address, // self-transfer
            data: '',
        }
    };

    // tx to be broadcasted
    const signedTransaction = signTransaction(hexSeed, path, unsignedTransaction);
    // get bytes to be broadcasted
    const txBroadcastBytes = getBroadcastBytes(signedTransaction);
}

doSignTest();

Tests

npm test

References

  • Universal private key derivation - SLIP-0010
  • Hierarchical Deterministic Wallets- BIP-0032
  • Multi-Account Hierarchy for Deterministic Wallets - BIP-0044