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

@gnarula/cothority

v3.5.3

Published

A typescript implementation of the cothority

Downloads

3

Readme

Cothority client library in Javascript

This library offers methods to talk to a cothority node. At this point, it offers a socket interface that marshals and unmarshals automatically protobuf messages.

This is fork for the TWINS project with commits from twins-demo-september branch.

Usage

Import the library using

import Cothority from "@dedis/cothority"

Check out the example in index.html for a browser-based usage. For typescript projects, it is easier to directly import from the subfolders:

import {DarcInstance} from "@dedis/cothority/byzcoin/contracts"

Do not import directly from files within the subfolders, as they can be moved or renamed at any time, while the index files will always be correct. So the previous line should not be written as:

import {DarcInstance} from "@dedis/cothority/byzcoin/contracts/darc-instance."

Even though this might work for some time, it might break with an update of the version.

Documentation

Execute npm run doc to generate the documentation and browse doc/index.html

Development

You need to have npm installed. Then

git clone https://github.com/dedis/cothority"
cd cothority/external/js/cothority
npm install

You should be able to run the tests with

npm run test

To run the tests, be sure to have docker installed and make docker executed from the root of this repo.

Protobuf generation

To add a new protobuf file to the library, simply place your *.proto file somewhere in lib/protobuf/build/models and then run

npm run protobuf

That would compile all protobuf definitions into a single JSON file (models.json). This json file is then embedded in the library automatically.

Message classes

You can write a class that will be used when decoding protobuf messages by using this template:

class MyMessage extends Message<MyMessage> {
    /**
     * @see README#Message classes
     */
    static register() {
        registerMessage("abc.MyMessage", MyMessage, MyMessageDependency);
    }

    readonly myField: MyMessageDependency;

    constructor(props?: Properties<MyMessage>) {
        super(props);

        // whatever you need to do for initialization
    }
}

MyMessage.register();

Note that protobuf will instantiate with an empty object and then fill the fields so this happens after the constructor has been called. The register is used to register the dependencies of the message but you also have to use it as a side effect of the package so that as soon as the class is imported, the message will be known by protobuf and used during decoding.

Side note on Buffer

Protobuf definition and classes implemented expect a Buffer for bytes but as you should know, in a browser environment bytes are instantiated with Uint8Array. You should then be aware that the actual type will be Uint8Array when using the library in a browser environment but the buffer interface will be provided thanks to the buffer package.

As this is a polyfill, please check that what you need is implemented or you will need to use a different approach. Of course for NodeJS, you will always get a Buffer.

Use of a development version from an external app

The simplest way to use a cothority development version in an app and being able to add debug-lines and change the code is to add the following to your tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "@dedis/cothority": [
        "../cothority/external/js/cothority/src",
        "node_modules/@dedis/cothority/*"
      ],
      "@dedis/cothority/*": [
        "../cothority/external/js/cothority/src/*",
        "node_modules/@dedis/cothority/*"
      ]
    }
  }
}

This will look for the cothority-sources in the parent directory of your app and include those. If it doesn't find them, it will use the sources found in the node_modules directory.

It is important that the cothority-repository is in the parent directory, else typescript will try to include it in the compilation.

Also, the cothority-sources need to have all the libraries installed with npm ci, else the compilation will fail.

Releases

Please have a look at PUBLISH.md for how to create releases.