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

universa-toolkit

v0.1.0

Published

Javascript library required to perform basic operations with Universa networks

Downloads

3

Readme

universa-toolkit

Minimalistic Javascript library required to perform basic operations with Universa Network, based on universa-minicrypto.

Installation

Node.js

For usage in an existing Node.js project, add it to your dependencies:

$ npm install universa-toolkit

or with yarn:

$ yarn add universa-toolkit

And use it with the following line wherever you need it:

const Universa = require('universa-toolkit');

Web

In root folder of package run

npm install
npm run build

In folder dist there will be toolkit.js.

Simply copy dist/toolkit.js to wherever you keep your vendor scripts and include it as a script:

<script src="path/to/toolkit.js"></script>

Usage

Connecting to network

Connect to network with default topology

const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey);
let response;

try { await network.connect(); }
catch (err) { console.log("network connection error: ", err); }

try { response = await network.command("sping"); }
catch (err) { console.log("on network command:", err); }

Connect to network with topology, provided by file path

const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey, {
  topologyFile: "/path/to/mainnet.json"
});
let response;

try { await network.connect(); }
catch (err) { console.log("network connection error: ", err); }

try { response = await network.command("sping"); }
catch (err) { console.log("on network command:", err); }

Connect to network with provided topology

const { Network, Topology } = Universa;
const { PrivateKey } = Universa.pki;

const topology = Topology.load(require("/path/to/mainnet.json"));

// privateKey is PrivateKey instance
const network = new Network(privateKey, { topology });
let response;

try { await network.connect(); }
catch (err) { console.log("network connection error: ", err); }

try { response = await network.command("sping"); }
catch (err) { console.log("on network command:", err); }

(Browser only) Connect to network and save topology to localStorage

const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey, {
  topologyKey: "local_storage_key_to_store"
});
let response;

try { await network.connect(); }
catch (err) { console.log("network connection error: ", err); }

try { response = await network.command("sping"); }
catch (err) { console.log("on network command:", err); }

Topology

Load topology from file

const { Topology } = Universa;

const topology = Topology.load(require("/path/to/mainnet.json"));

Get topology from network instance

const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey);
await network.connect();

const { topology } = network; // Updated topology instance

Update topology

const { Topology } = Universa;

const topology = Topology.load(require("/path/to/mainnet.json"));
const done = await topology.update(); // updates topology that then can be saved

Pack topology to save as file

const fs = require('fs');
const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey);
const { topology } = network; // Topology instance

const packedTopology = topology.pack();
const json = JSON.stringify(packedTopology);
fs.writeFile('mainnet.json', json);

Running commands

network.command(commandName, parameters) - returns Promise with result

const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey);
let response;

try { await network.connect(); }
catch (err) { console.log("network connection error: ", err); }

try {
  // approvedId is Uint8Array
  response = await network.command("getState", {
    itemId: { __type: "HashId", composite3: approvedId }
  });
}
catch (err) { console.log("on network command:", err); }

Check full contract status

Special command to check contract status over network isApproved(contractId, trustLevel: Double) // Promise[Boolean]

const { Network } = Universa;
const { PrivateKey } = Universa.pki;

// privateKey is PrivateKey instance
const network = new Network(privateKey);
let isApproved; // boolean

try { await network.connect(); }
catch (err) { console.log("network connection error: ", err); }

try {
  // approvedId can be Uint8Array or base64 string
  isApproved = await network.isApproved(approvedId, 0.6);
}
catch (err) { console.log("on network command:", err); }

Running tests

Run tests

npm test

Run coverage

npm run coverage