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

tweedentity

v0.2.4

Published

A library to integrate Tweedentity in any decentralized app.

Downloads

12

Readme

Tweedentity.js

A library to integrate Tweedentity in any decentralized app.

Getting started

To use tweedentity:

npm i tweedentity --save

Client

Example

Instantiate the client:

const tweedentityClient = require('tweedentity/Client')
const tClient = new tweedentityClient(web3js)

API

####load()

Loads the contracts. It must be executed after instantiating the object and before any other commands. Example:

tClient.load()
.then(() => {
  console.log(tClient.contracts.stores.twitter.address)
})

on Ropsten, it should print 0x0de9ccba310161c06ae194f65965c309af167913

####getIdentities(address, reload)

Gets the identities associated to address. The first time it is executed, it saves the results in the property profiles so that in the future it can read quickly from that. The param reload forces the reload of the data from the blockchain.

tClient.getIdentities('0x93a5b8fc1a951894361c4c35523e23ba6bf073b7')
.then(result => {
   console.log(result.twitter)
})

Should print 946957110411005953.

If there isn't any tweedentity set for the specified address, it returns an empty object.

When you have the twitter userId, to recover the profile associated with it you can either use the Twitter API or parse the data using the Server component (see below in the Server section).

####getIdentity(app, address)

Gets the identities associated to address and the specified app. The first parameter can be the nickname of the app, for example twitter, or its id, i.e. 1 for twitter. If the app is not supported it throws new Error('App not supported').

tClient.getIdentity('twitter', '0x93a5b8fc1a951894361c4c35523e23ba6bf073b7')
.then(result => {
   console.log(result)
})

Should print 946957110411005953. Alternatively, it can be called as

tClient.getIdentity(1, '0x93a5b8fc1a951894361c4c35523e23ba6bf073b7')
...

####getFullIdentities__(address)

Returns the same of getIdentities but with the full TID. In the example above, it should return for twitter 1/946957110411005953, where 1 is the twitter appId in Tweedentity.

getFullIdentity(appNickname, address)__

Returns the same of getIdentity but with the full TID.

####totalIdentities()

Returns a summary of the total of set tweedentities.

tClient.totalIdentities()
.then(result) {
  console.log(result)
})

Should print something like

{total: 200, twitter: 140, reddit: 60}

####totalIdentityByApp(app)

Returns the total number of tweedentities set for the specified app.

tClient.totalIdentitiesByApp('twitter')
.then(result) {
  console.log(result)
})

In line with the previous example, it should print 140.

Static methods

####fullify(id)

Returns the TID.

console.log(tweedentityClient.fullify('twitter','87237464536')

Should print 1/87237464536

####isSupported(app)

Returns true if the app is supported.

####normalizeApp(app)

Returns the appNickname, despite if app is already a nickname or is an id.

####appByTID(tid)

Returns the appNickname of a TID.

console.log(tweedentityClient.appByTID('1/78746563'))

Should print twitter

Server

Versions starting from 0.2.0 are not compatible with previous 0.1.x versions.

When you have the tweedentities associated to a wallet you can retrieve the user profile using the app API, for example, the Twitter API. Alternatively, you can use server-side the Tweedentity API to parse the data from the web.

Supposing you are using Express, to get the basic profile about a Reddit tweedentity (userId, username, name and avatar), you could have something like:

const tServer = require('tweedentity').Server

router.post('/data/:webApp', jsonParser, function (req, res, next) {

  const webApp = req.params.webApp
  const provider = new Provider()

  tServer.getDataByTID(webApp, req.body.userId)
    .then(result => {
      res.status(200).json(result)
    })
    .catch(err => {
      res.status(200).json({error: err.message})
    })
})

This should return something like:

{
    "userId": "1ys6ez",
    "username": "mary908345",
    "name": "Bloody Mary",
    "avatar": "https://s.redditmedia....png?...."
}

Or, if the account does not exists:

{
  "error": "Not found"
}

License

MIT.

Copyright

(c) 2018, Francesco Sullo [email protected], 0xNIL