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

obyte-browser-chat

v0.0.6

Published

Library for interacting with Obyte chat

Downloads

8

Readme

Obyte browser chat

A library for establishing chat sessions between your web-based dapp and the user's Obyte wallet. Use the chat to:

  • request payments, including payments in multiple assets;
  • request to sign a message;
  • request user's address (without having to copy/paste);
  • request private profiles (such as real name attestations);
  • request a vote in a poll.

This library uses local storage

Install

yarn add obyte-browser-chat obyte

Use

import browserChat from "obyte-browser-chat"

Example

1. Create an instance of obyte.js client

import obyte from "obyte";

export default new obyte.Client('wss://obyte.org/bb-test'); // or wss://obyte.org/bb for livenet

2. Create an instance of chat

import browserChat from "obyte-browser-chat";

import client from "..."; // obyte.js client instance

export default browserChat({
  name: "mydomain.com", // chat name that'll show up in the user's wallet
  client, // obyte.js client instance
  testnet: true
});

3. Use

import browserChatInstance from "..."; 

const payments = [
  {
    address: "2QVJOY3BRRGWP7IOYL64O5BU3WLUJ4TZ",
    amount: 1e9, // integer, amount in smallest units
    asset: "base"
  },
  {
    address: "EJC4A7WQGHEZEKW6RLO7F26SAR4LAQBU",
    amount: 2e9,
    asset: "base"
  }
];

const paymentJsonBase64 = browserChatInstance.generatePaymentString({ payments });

const message = `Send bytes \n[send](payment:${paymentJsonBase64})`;

const link = browserChatInstance.sendMessageAfterPairing(message);

...

<a href={link}>Click</a>

Methods

getPairingLink - Returns a link for pairing

const pairingLink = browserChatInstance.getPairingLink();

Returns a link that looks like obyte:[email protected]/bb. The user needs to click it to open the chat.

sendMessageAfterPairing - Returns a link for pairing

const pairingLink = browserChatInstance.sendMessageAfterPairing("We're glad to see you");

As above, plus the provided message will be sent to the user immediately after pairing.

onPairing - Callback function triggered after pairing

browserChatInstance.onPairing((msgObject) => {
  console.log("msgObject", msgObject);

  // send a plain text message
  msgObject.reply("Hi there!");

  // request to sign a text message
  msgObject.reply("Please prove ownership of your address by signing this message: [any text](sign-message-request:I confirm for domain.com that I own the address SPV5WIBQQT4DMW7UU5GWCMLYDVNGKECD)");

  // request to sign an object
  const order = {field1: "value1"};
  const orderJsonBase64 = Buffer.from(JSON.stringify(order), 'utf8').toString('base64');
  msgObject.reply(`Please sign an order: [any text](sign-message-request:${orderJsonBase64})`);

  // request a private profile
  msgObject.reply(`Click this link to reveal your private profile to us: [any text](profile-request:first_name,last_name,dob,country,id_type).`);

  // request a vote
  const objVote = {
    poll_unit: '0Vv6lhpjjk3VsKCSGML2NY/5W+WgpsNELQJ1rukhL5Y=',
    choice: 'Institute For the Future of the University of Nicosia',
  };
  const voteJsonBase64 = Buffer.from(JSON.stringify(objVote), 'utf8').toString('base64');
  msgObject.reply(`Click to vote for ${objVote.choice}: [any text](vote:${voteJsonBase64}).`);

});

where msgObject contains:

  • reply - message forwarding function
  • body - object with pairing_secret field
  • sender - sender's public key

onMessage - Callback function triggered when a message is received

browserChatInstance.onMessage((msgObject) => {
  msgObject.reply("Thanks, you said: " + msgObject.body);
});

where msgObject contains:

  • reply - message forwarding function
  • body - received message (string)
  • sender - sender's public key

onReady - Callback function triggered when the device gets connected to the hub

browserChatInstance.onReady(() => {
  console.log("I'm connected to the hub");
});

generatePaymentString - Function that converts the payment object to base64

const payments = [
  {
    address: "2QVJOY3BRRGWP7IOYL64O5BU3WLUJ4TZ",
    amount: 1e9,
    asset: "base"
  },
  {
    address: "EJC4A7WQGHEZEKW6RLO7F26SAR4LAQBU",
    amount: 2e9,
    asset: "base"
  }
];

const paymentJsonBase64 = chatInstance.generatePaymentString({ payments });