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

keychain-sdk

v0.8.5

Published

A simpler way to handle Hive Keychain requests

Downloads

167

Readme

keychain-sdk

This class is a way to handle Hive Keychain requests, with Typescript support. The purpose is to allow developers to integrate Keychain in a seemless manner.

Installation

  • npm install keychain-sdk

Basic Usage

Start by creating a new Keychain instance using:

const keychain = new KeychainSDK(window);

The keychain-sdk allows you to set an options parameter, in which you can define an RPC node that will override the one normally determined within Keychain.

This works as follows:

const keychain = new KeychainSDK(window, { rpc: 'https://api.hive.blog' });

After creating the instance you can use it to perform any action you'd need, here requesting for a message to be encoded :

import { KeychainSDK } from "keychain-sdk";
const keychain = new KeychainSDK(window);
try {
  const encodeMessage = await keychain.encode({
    username: 'keychain.tests',
    receiver: 'keychain.tests',
    message: '#Message to encode, # is required to encrypt',
    method: 'Memo',
  });
  console.log({ encodeMessage });
} catch (error) {
  console.log({ error });
}

Overriding the RPC node at the request level

You can also override the RPC node at the request level, by adding it in the options

import { KeychainSDK } from 'keychain-sdk';
const keychain = new KeychainSDK(window, { rpc: 'https://api.hive.blog'}); // Default RPC at the instance level
try {
      const broadcast = await keychain.requestBroadcast(
      {
        username: 'keychain.tests',
        operations: [
          [
            'transfer',
            {
              from: 'keychain.tests',
              to: 'theghost1980',
              amount: '0.001 HIVE',
              memo: 'testing keychain SDK - requestBroadcast',
            },
          ],
        ],
        method: 'active',
      },
      {rpc : 'https://api.deathwing.me'}, // For this particular broadcast, this rpc will be used
      );
      console.log({ broadcast });
    } catch (error) {
      console.log({ error });
    }

Utils

Verifying

Before making any Keychain request, you can check that Keychain is installed and ready to use, as follows:

const isKeychainInstalled = await keychain.isKeychainInstalled();

Login

Handle logins easily with Keychain :

 const keychain = new KeychainSDK(window);
 const data= {
        "username": "keychain.tests",
        "message": "{\"login\":\"123\"}",
        "method": "Posting",
        "title": "Login"
  };
  const login = await keychain
            .login(data as Login);

This saves you some time by taking care of the different steps that usually comprise a Hive login:

  • Requesting a buffer signature
  • Verifying this signature to ensure that the key is correct
  • Returning the public key corresponding to the key used for signing

Requests

Keychain has a long list of available requests. Rather than giving you a boring documentation, we've set up a playground, in which you can discover the different requests, test them and see the corresponding code and results returned by Keychain.

The playground is available here.

Contact us

Should you need to contact us, please open an issue or join our Discord.