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

@iov/lisk

v2.5.0

Published

Transaction codec and client to communicate with the Lisk blockchain

Downloads

102

Readme

@iov/lisk

npm version

Getting started

The primary way to use @iov/lisk is together with @iov/multichain. Alternatively, you can use @iov/lisk to create offline transactions which can be posted manually.

All examples are made for use in @iov/cli and you may need to include some missing symbols if used in a different environment.

Using with @iov/multichain

You can use @iov/lisk as an extension of @iov/multichain to interact with the Lisk blockchain as follows.

import { Ed25519Wallet } from "@iov/keycontrol";
import { passphraseToKeypair, liskCodec, createLiskConnector } from "@iov/lisk";

const wallet = new Ed25519Wallet();
const mainIdentity = await wallet.createIdentity(
  await passphraseToKeypair(
    "oxygen fall sure lava energy veteran enroll frown question detail include maximum",
  ),
);

const profile = new UserProfile();
profile.addWallet(wallet);

const signer = new MultiChainSigner(profile);
await signer.addChain(createLiskConnector("https://testnet.lisk.io"));
const chainId = signer.chainIds()[0];
const connection = signer.connection(chainId);

const mainAddress = signer.identityToAddress(mainIdentity);
console.log((await connection.getAccount({ address: mainAddress })).data[0].balance);

const recipientAddress = "6076671634347365051L" as Address;

const sendTx: SendTransaction = {
  kind: "bcp/send",
  chainId: chainId,
  sender: mainAddress,
  senderPubkey: mainIdentity.pubkey,
  recipient: recipientAddress,
  memo: "We ❤️ developers – iov.one",
  amount: {
    quantity: "144550000",
    fractionalDigits: 8,
    tokenTicker: "LSK" as TokenTicker,
  },
};

console.log("Writing to blockchain. This may take a while …");
await signer.signAndPost(mainIdentity, sendTx);
console.log((await connection.getAccount({ address: recipientAddress })).data[0].balance);

The manual way

This is how you use liskCodec to generate send transactions for Lisk manually, i.e. without the help of @iov/multichain.

import { Ed25519Wallet } from "@iov/keycontrol";
import { passphraseToKeypair, generateNonce, liskCodec } from "@iov/lisk";

const liskTestnet = "lisk-da3ed6a454" as ChainId;

const wallet = new Ed25519Wallet();
const mainIdentity = await wallet.createIdentity(
  await passphraseToKeypair(
    "oxygen fall sure lava energy veteran enroll frown question detail include maximum",
  ),
);
const mainAddress = signer.identityToAddress(mainIdentity);

const recipientAddress = "6076671634347365051L" as Address;

const sendTx: SendTransaction = {
  kind: "bcp/send",
  chainId: liskTestnet,
  sender: mainAddress,
  senderPubkey: mainIdentity.pubkey,
  recipient: recipientAddress,
  memo: "We ❤️ developers – iov.one",
  amount: {
    quantity: "144550000",
    fractionalDigits: 8,
    tokenTicker: "LSK" as TokenTicker,
  },
};

const nonce = generateNonce();
const signingJob = liskCodec.bytesToSign(sendTx, nonce);
const signature = await wallet.createTransactionSignature(
  mainIdentity,
  signingJob.bytes,
  signingJob.prehashType,
  liskTestnet,
);

const signedTransaction = {
  transaction: sendTx,
  primarySignature: {
    nonce: nonce,
    publicKey: mainIdentity.pubkey,
    signature: signature,
  },
  otherSignatures: [],
};

// Signed transacion you can POST to
// https://testnet.lisk.io/api/transactions
const bytesToPost = fromUtf8(liskCodec.bytesToPost(signedTransaction));
console.log(bytesToPost);

Lisk HD wallets

Lisk codec and Ed25519HdWallet combined allow you to create a pure software implementation of the the Lisk wallet on Ledger or Trezor.

Address discovery

The following code snippet shows how to implement address discovery.

import { Ed25519HdWallet } from "@iov/multichain";
import { Slip10RawIndex } from "@iov/crypto";
import { liskCodec, LiskConnection } from "@iov/lisk";

const liskTestnet = "lisk-da3ed6a454" as ChainId;

async function deriveAddress(wallet, a): Promise<Address> {
  // 44'/134'/a' (see https://github.com/trezor/trezor-core/tree/master/docs/coins)
  const path = [Slip10RawIndex.hardened(44), Slip10RawIndex.hardened(134), Slip10RawIndex.hardened(a)];
  const pubkey = (await wallet.createIdentity(path)).pubkey;
  return liskCodec.keyToAddress(pubkey);
}

async function getBalance(searchAddress: Address): Promise<any> {
  const connection = new LiskConnection("https://testnet.lisk.io/", liskTestnet);
  const response = await connection.getAccount({ address: searchAddress });
  return response.data.length > 0 ? response.data[0].balance[0] : undefined;
}

const wallet = Ed25519HdWallet.fromMnemonic(
  "tell fresh liquid vital machine rhythm uncle tomato grow room vacuum neutral",
);

// from https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#address-gap-limit
const gapLimit = 20;

let currentGapSize = 0;
for (let a = 0; currentGapSize < gapLimit; a++) {
  const address = await deriveAddress(wallet, a);
  const balance = await getBalance(address);
  const balanceString = balance ? `${balance.whole + balance.fractional / 100000000} LSK` : "unknown";
  console.log(`${a}: ${address} (${balanceString})`);

  if (balance) {
    currentGapSize = 0;
  } else {
    currentGapSize++;
  }
}
console.log(`Stopping discovery after ${currentGapSize} unused addresses in a row.`);

License

This package is part of the IOV-Core repository, licensed under the Apache License 2.0 (see NOTICE and LICENSE).