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

@alanshaw/drand-client-twitter

v0.2.0

Published

A client for the drand twitter relay

Downloads

10

Readme

drand-client-twitter

dependencies Status JavaScript Style Guide

A client for the drand twitter relay.

Install

In Deno you can grab and use the client from a CDN e.g. https://unpkg.com/@alanshaw/drand-client-twitter?module.

In Node.js, install with:

npm i @alanshaw/drand-client-twitter

Usage

The client uses the user timeline API exclusively. It is best suited for watching or getting the latest randomness generated. It's possible to get historic randomness up to the API limits of around 3,200 tweets. In order to retrieve historic randomness the client will walk the chain of tweets (max 200 per page).

Deno

import Client from 'https://unpkg.com/drand-client/drand.js'
import Twitter from 'https://unpkg.com/@alanshaw/drand-client-twitter?module'

const chainInfo = {
  public_key: '868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31',
  period: 30,
  genesis_time: 1595431050,
  hash: '8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce'
}

async function main () {
  const c = await Client.wrap([
    new Twitter({ screenName: 'loebot', bearerToken: 'AAAAAAAAAAAAAAAAAAAAAHJT...', chainInfo })
  ], { chainInfo })

  for await (const res of c.watch()) {
    console.log(res)
  }
}

main()

Node.js

import Client from 'drand-client'
import Twitter from '@alanshaw/drand-client-twitter'
import fetch from 'node-fetch'
import AbortController from 'abort-controller'

global.fetch = fetch
global.AbortController = AbortController

const chainInfo = {
  public_key: '868f005eb8e6e4ca0a47c8a77ceaa5309a47978a7c71bc5cce96366b5d7a569937c529eeda66c7293784a9402801af31',
  period: 30,
  genesis_time: 1595431050,
  hash: '8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce'
}

async function main () {
  const c = await Client.wrap([
    new Twitter({ screenName: 'loebot', bearerToken: 'AAAAAAAAAAAAAAAAAAAAAHJT...', chainInfo })
  ], { chainInfo })

  for await (const res of c.watch()) {
    console.log(res)
  }
}

main()

Running the examples

Add credentials.json to the examples/ directory like:

{
  "bearerToken": "AAAAAAAAAAAAAAAAAAAAAHJT..."
}

Run a client that watches for randomness and prints it to the console:

node ./examples/node.js
# or
deno run --allow-net --allow-read ./examples/deno.js

API

import Twitter from '@alanshaw/drand-client-twitter'

See the drand client API Reference docs.

new Twitter(config)

Create a new drand Twitter client.

  • config.screenName - screen name of the twitter user that is relaying randomness (required).
  • config.bearerToken - access token for using the Twitter API (required).
  • config.chainInfo - information about the chain of randomness that is being relayed, for beacon verification (required).

Optional configuration:

  • config.latestRoundDelay - expected delay in ms between randomness being generated and it being available on twitter, reduce this for faster latest randomness but more requests to twitter (default 650ms).
  • config.latestRoundRetries - maximum retries for getting the latest round before it fails (default 5).
  • config.latestRoundRetryBackoff - backoff interval in ms between retries - doubled each retry (default 50).

Contribute

Feel free to dive in! Open an issue or submit PRs.

License

MIT © Alan Shaw