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

@wirelineio/registry-client

v1.1.0-beta.3

Published

Wireline Registry JavaScript Client.

Downloads

45

Readme

registry-client

Usage

import { Account, Registry } from '@wirelineio/registry-client';
const endpoint = 'http://localhost:9473/api';
const registry = new Registry(endpoint);

Generate Private & Public Keys

let mnemonic;

if (!mnemonic) {
  mnemonic = Account.generateMnemonic();
}

const key = Account.generateFromMnemonic(mnemonic);

Query WNS

Get accounts:

const addresses = ['cosmos1sgdt4t6eq6thsewcpe2v9cu6c9ru837w7pj9lm'];
const result = await registry.getAccounts(addresses);

Get records by ids:

let ids = ['QmfKZkWQdWFtUnsJt4Uakp3jSzXKHcafY5sMnyPodR9Ks2'];
let result = await registry.getRecordsByIds(ids);

Query records by attributes:

let attributes = { type: 'wrn:bot' };
let result = await registry.queryRecords(attributes);

Get bonds by ids:

let ids = ['8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3'];
let result = await registry.getBondsByIds(ids);

Query bonds (by owner):

let owner = 'cosmos1zk8etz23phxgtse8re6tggsr3nrfk2vtsesegy';
const result = await registry.queryBonds({ owner });

Write to WNS

Publish record:

// Private key & bond ID.
let payloadKey = '31c90b358117ea94bb45f1e6bbef7dc5bb20b6cb39f71790dd510a2190fe222b';
let bondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';

let record = {
  "type": "wrn:protocol",
  "name": "wireline.io/chess",
  "version": "1.5.2"
};

let result = await registry.setRecord(payloadKey, record, txKey, bondId);

Send coins:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let toAddress = 'cosmos1w5q7xy9sk8hqvlklftdfdkc3kgsd90cxlkwvty';

await registry.sendCoins([{ denom: 'wire', amount: '100' }], toAddress, privateKey);

Create bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let denom = 'uwire';
let amount = '10000';

const result = await registry.createBond([{ denom, amount }], privateKey);

Refill bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let bondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';
let denom = 'uwire';
let amount = '500';

const result = await registry.refillBond(bondId, [{ denom, amount }], privateKey);

Withdraw funds from bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let bondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';
let denom = 'uwire';
let amount = '500';

const result = await registry.withdrawBond(bondId, [{ denom, amount }], privateKey);

Cancel bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let bondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';

const result = await registry.cancelBond(bondId, privateKey);

Associate record with bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let recordId = 'QmfYFV686CmEuDfd12NkoY94AoVYTKqw7ptaovLgiRSxL2';
let bondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';

const result = await registry.associateBond(recordId, bondId, privateKey);

Dissociate record from bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let recordId = 'QmfYFV686CmEuDfd12NkoY94AoVYTKqw7ptaovLgiRSxL2';

const result = await registry.dissociateBond(recordId, privateKey);

Dissociate all records from bond:

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let bondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';

const result = await registry.dissociateRecords(bondId, privateKey);

Reassociate records with new bond (switch bond):

let privateKey = 'b1e4e95dd3e3294f15869b56697b5e3bdcaa24d9d0af1be9ee57d5a59457843a';
let oldBondId = '8e340dd7cf6fc91c27eeefce9cca1406c262e93fd6f3a4f3b1e99b01161fcef3';
let newBondId = 'e205a46f6ec6f662cbfad84f4f926973422bf6217d8d2c2eebff94d148fd486d';

const result = await registry.reassociateRecords(oldBondId, newBondId, privateKey);

Tests

yarn test allows to run tests against an external GQL endpoint (of a real WNS server). By default http://localhost:9473/api endpoint is used, but could be changed by WIRE_WNS_ENDPOINT ENV var.

$ WIRE_WNS_ENDPOINT=http://xbox.local:9473/api yarn test

yarn test:in-mem-wns spins up an in-process mock GQL server for the duration of the tests.

$ yarn test:in-mem-wns

It's also possible to run the mock GQL server standalone and interact with it using the GQL Playground (http://127.0.0.1:4000/).

$ yarn start:in-mem-wns --help
Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --host     GQL server host                     [string] [default: "127.0.0.1"]
  --port     GQL server port                            [number] [default: 4000]

$ yarn start:in-mem-wns
yarn run v1.17.3
$ BABEL_DISABLE_CACHE=1 DEBUG=test babel-node src/mock/main.js
Mock server running on http://127.0.0.1:4000/