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

@axiasolar-js/ui-keyring

v1.1.0

Published

A wrapper extending the base @axiasolar-js/keyring interface for usage in the browser: Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.

Downloads

1

Readme

@axiasolar-js/ui-keyring

A wrapper extending the base @axiasolar-js/keyring interface for usage in the browser: Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.

Usage Examples

All module methods are exposed through a single default export.

Regular

import keyring from @axiasolar-js/ui-keyring

render () {
  // encode publicKey to ss58 address
  const address = keyring.encodeAddress(publicKey);

  // get keyring pair from ss58 address
  const pair = keyring.getPair(address);

  // ask questions about that particular keyring pair
  const isLocked = pair.isLocked;
  const meta = pair.meta;

  // save account from pair
  keyring.saveAccount(pair, password);

  // save address without unlocking it
  keyring.saveAddress(address, { ...meta });
}

Observables

Option 1: Declarative subscribe/unsubscribe w/ react-with-observable (recommended 'React' way)

import accountObservable from '@axiasolar-js/ui-keyring/observable/accounts';
import { SingleAddress, SubjectInfo } from '@axiasolar-js/ui-keyring/observable/types';
import React from 'react';
import { Subscribe } from 'react-with-observable';
import { map } from 'rxjs';

class MyReactComponent extends React.PureComponent {
  render () {
    <Subscribe>
      {accountObservable.subject.pipe(
        map((allAccounts: SubjectInfo) =>
          !allAccounts
            ? this.renderEmpty()
            : Object.values(allAccounts).map((account: SingleAddress) =>
                // Your component goes here
                console.log(account.json.address)
            )
        ))}
    </Subscribe>
  }

  renderEmpty () {
    return (
      <div> no accounts to display ... </div>
    );
  }
}

Option 2: Imperative subscribe/unsubscribe

import accountObservable from '@axiasolar-js/ui-keyring/observable/accounts';
import { SingleAddress, SubjectInfo } from '@axiasolar-js/ui-keyring/observable/types';
import React from 'react';
import { Subscription } from 'rxjs';

type State = {
  allAccounts?: SubjectInfo,
  subscriptions?: [Subscription]
}

class MyReactComponent extends React.PureComponent<State> {
  componentDidMount () {
    const accountSubscription = accountObservable.subject.subscribe((observedAccounts) => {
      this.setState({
        accounts: observedAccounts
      });
    })

    this.setState({
      subscriptions: [accountSubscription]
    });
  }

  componentWillUnmount () {
    const { subscriptions } = this.state;

    for (s in subscriptions) {
      s.subject.unsubscribe();
    }
  }

  render () {
    const { accounts } = this.state;

    return (
      <h1>All Accounts</h1>
      {
        Object.keys(accounts).map((address: SingleAddress) => {
          return <p> {address} </p>;
        })
      }
    )
  }
}

FAQ

  • Difference between Keyring Accounts and Addresses?
    • From the perspective of the keyring, it saves a particular user's unlocked identities as an account, a la keyring.saveAccount(pair, password). So with these accounts you are able to send and sign transactions.
    • To save addresses without unlocking them (i.e. because a user might want to have easy access to addresses they frequently transact with), use keyring.saveAddress(address, meta)
  • What are 'external' accounts, i.e. when to set the isExternal meta key to true?
    • An external account is one where the keys are not managed by keyring, e.g. in Parity Signer or Ledger Nano.
  • SS58 Encode / Decode?
    • SS58 is a simple address format designed for Substrate based chains. You can read about its specification in more detail in the Parity Wiki.

If you have any unanswered/undocumented questions, please raise an issue here.

Users

Keyring is core to many axiasolar/substrate apps.