
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@alanshaw/drand-client-twitter
Advanced tools
A client for the drand twitter relay.
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
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()
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
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).Feel free to dive in! Open an issue or submit PRs.
MIT © Alan Shaw
FAQs
A client for the drand twitter relay
We found that @alanshaw/drand-client-twitter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.