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

tupelo-client

v0.4.0

Published

Tupelo JavaScript client

Downloads

13

Readme

Tupelo.js

A Node.js API client to both manage Tupelo chain trees and submit chain tree transactions to a notary group for verification, through connecting with a Tupelo RPC server.

Installation and Usage

Basic installation and usage instructions are below. Visit the full API Documentation for more.

RPC Server

The Node.js client cannot directly manage chain trees nor connect to the notary group, so Node.js applications must instead proxy through an RPC server to work with Tupelo.

Installation

To install the server, first contact us to get a Tupelo binary for your platform and save it within your command PATH variable. If you do not wish to save the binary in your PATH, you can still execute it with the fully qualified or relative path to your chosen location for the binary.

Usage

You can run the RPC server by invoking tupelo along with the necessary options.

Connecting to a Local Notary Group

To get started quickly for local development, simply run:

tupelo rpc-server --local-network 3

This will spin up a 3 signer local, in-memory notary group after first generating three random keypairs for the group to use. Then it will start the RPC server and bind it to the local notary group. Note that restarting the server will remove all data stored by the local notary group signers! (You may still have some retained application state.)

Connecting to the Tupelo Alpha Test Network

To connect to the Tupelo alpha test network notary group, contact us to get the public key file corresponding to the running network. Then you can start the server and bind it to the notary group with:

tupelo rpc-server --bootstrap-keys <public key file>
Other Options

tupelo also includes a help command that lists the available options and their descriptions:

% > ./tupelo help rpc-server
Launches a Tupelo RPC Server

Usage:
  tupelo rpc-server [flags]

Flags:
  -k, --bootstrap-keys string   which public keys to bootstrap the notary groups with
  -h, --help                    help for rpc-server
  -l, --local-network int       Run local network with randomly generated keys, specifying number of nodes as argument. Mutually exlusive with bootstrap-*
  -t, --tls                     Encrypt connections with TLS/SSL
  -C, --tls-cert string         TLS certificate file
  -K, --tls-key string          TLS private key file

Node.js Client

Installation

You can install Tupelo.js with npm. Run the following command from your project's directory to add Tupelo.js to the npm project's dependencies.

npm install tupelo-client

Usage

Once you have installed the dependency, require the tupelo-client module from your application.

const tupelo = require('tupelo-client');
Wallet Credentials

The RPC server stores all the chain trees it has access to in an encrypted wallet with a unique name and secret pass phrase. You must initialize the client with the correct credentials for the wallet you'd like to unlock for each RPC request. The wallet credentials should be a WalletCredentials object with walletName and passPhrase keys.

const walletCreds = {
  walletName: 'my-wallet',
  passPhrase: 'super secret password'
};
Obtaining an RPC client connection

The connect function takes the host:port string of the RPC server and the wallet credentials object as arguments and returns an RPC client connection.

const client = tupelo.connect('localhost:50051', walletCreds);
Using the API

See the API docs for full information about the Tupelo.js API.

Here is an example of how to create a new key and then a chain tree owned by that key.

const tupelo = require('tupelo-client');

const createTree = async () => {
  const walletCreds = {
    walletName: 'my-wallet',
    passPhrase: 'super secret password'
  };
  const wallet = tupelo.connect('localhost:50051', walletCreds);

  // register a new wallet, then generate a key and chain tree stored there
  await wallet.register();
  const {keyAddr: walletKey,} = await wallet.generateKey();
  const {chainId,} = await wallet.createTree(walletKey);
  return {wallet, walletKey, chainId,};
};

const main = async () => {
  const {chainId,} = await createTree();
  console.log(chainId);
};

Another example, of how to set data in a tree and resolving it (using the createTree function from the previous example):

const assert = require('assert');

const main = async () => {
  const {chainId, wallet, walletKey,} = await createTree();
  await wallet.setData(chainId, walletKey, 'key', 'value');

  // Resolve the path we just set
  let resp = await wallet.resolveData(chainId, 'key');
  assert.deepStrictEqual(resp.data, ['value']);
  assert.equal(resp.remainingPath, '');

  // Resolve a child path of what we set before; it will resolve, but not for the full path
  resp = await wallet.resolveData(chainId, 'key/child');
  assert.deepStrictEqual(resp.data, ['value']);
  assert.strictEqual(resp.remainingPath, 'child');
};

Tests

There are some RPC integration tests that can be run against a live Tupelo RPC server by running npm test. Note that you will need a working Docker environment setup.

Examples

There are some example apps in the example directory, which should be of help in understanding how to use Tupelo.

transfer-ownership

This example demonstrates Tupelo's feature of transferring the ownership of a chain tree from one party (identified by a public key) to another. See the whitepaper's discussion of the SET_OWNERSHIP transaction type for background on ownership transfer in Tupelo.

timestamper

This is a highly trivial app that simply shows how one may write to chain trees and read back from them.