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

ara-identity

v0.65.0

Published

Create and resolve decentralized identity based Ara identifiers.

Downloads

42

Readme

ara-identity

Build Status

Ara Identity is an implementation of DIDs, or Decentralized Identifiers, which allows users to interact with services in the Ara network. A DID document in JSON format is called a DDO (DID document object).

Table of Contents

Status

This project is in active development.

Stability

Stability: 1 - Experimental. These features are still under active development and subject to non-backwards compatible changes, or even removal, in any future version. Use of the feature is not recommended in production environments. Experimental features are not subject to the Node.js Semantic Versioning model.

Installation

$ npm install arablocks/ara-identity

Usage

const aid = require('ara-identity')
const context = require('ara-context')()

// Create an Ara ID
const createOpts = {
  context,
  password: 'hello'
}
const identity = aid.create(createOpts)

// Archive an Ara ID
const archiverOpts = {
  secret: 'test-secret',
  network: 'test-archiver',
  keyring: '~/.ara/keyrings/keyring.pub'
}
await aid.archive(identity, archiverOpts)

// Resolve an Ara ID to get DID-document
const resolverOpts = {
  secret: 'test-secret',
  network: 'test-resolver',
  keyring: '~/.ara/keyrings/keyring.pub'
}
const ddo = aid.resolve(identity.identifier, resolverOpts)

// Recover a lost Ara ID using a valid bip39 mnemonic
const recoverOpts = {
  mnemonic: 'glad kangaroo coyote rich detail grief matrix spirit jeans owner heart net',
  password: 'qwerty' // New password to be used for encryption of the identity files
}
const identity = aid.recover(recoverOpts)

API

All functions check for input validity, input correctness, and throw an error if checks do not pass.

aid.archive(identity, opts)

Archive an Ara ID into the Ara network where identity is the Ara Identity object created using create() method. See also Ara Identity Archiver.

const context = require('ara-context')()
const opts = {
  context,
  password: 'hello'
}
const identity = await aid.create(opts)

const archiverOpts = {
  secret: 'test-secret',
  network: 'test-archiver',
  keyring: '~/.ara/keyrings/keyring.pub',
  shallow: true
}

await aid.archive(identity, archiverOpts)

aid.create(opts)

Create an Ara identity encrypted using the provided password.

const context = require('ara-context')()

const opts = {
  context,
  password: 'hello'
}

const identity = await aid.create(opts)

aid.update(identifier, opts)

Updates an identity state. This recreates new signatures for an identity.

const opts = { password: 'hello' }
const identity = await aid.create(opts)
identity.ddo.addPublicKey(aPublicKeyToAdd)
identity.password = password // must include password updates
await aid.update(identity.did.did, identity.ddo)
await aid.save(identity)

aid.save(identity)

Save an Ara identity to disk. Does not work in browser.

const context = require('ara-context')()

const opts = {
  context,
  password: 'hello'
}

const identity = await aid.create(opts)
if (await aid.save(identity)) {
  console.log(await aid.resolve(identity))
}

aid.createIdentityKeyPath(identity)

Generate and retrieve the path to files of an identity stored locally

const context = require('ara-context')()
const opts = {
  context,
  password: 'hello'
}
const identity = await aid.create(opts)

const path = aid.createIdentityKeyPath(identity)

aid.did.create(publicKey)

Create a DID reference document from a given publicKey of a key pair.

const { publicKey, secretKey } = crypto.keyPair()

const didUri = did.create(publicKey)

aid.did.normalize(identifier, method)

Recreate a DID URI from an identifier and DID method.

const identifier = '4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'
const method = 'ara'

const didURI = aid.did.normalize(identifier, method)

console.log(didURI) // 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'

aid.ddo.create(opts)

Create a DID document for a given DID URI.

const { publicKey, secretKey } = crypto.keyPair()
const didUri = did.create(publicKey)
const opts = {
  id: didUri
}

const didDocument = ddo.create(opts)

aid.fs

aid.fs is an an abstract file system interface for reading and writing identity files for an identity on disk or from the network. It provides a familiar FS API exposing functions like readFile and writeFile. Most operations will use the fs module directly, but if a file is not found, it will ask the network for it. This allows services running on servers to bind themselves to identities, without the identity files living on the same machine. More information about remote servers can be found at archiver & resolver.

aid.fs.writeFile(identifier, filename, buffer)

Write a file to its local identity directory based on a given identifier.

const context = require('ara-context')()
const opts = {
  context,
  password: 'hello'
}
const identity = await aid.create(opts)
const files = identity.files

for (let i = 0; i < files.length; i++) {
  await aid.fs.writeFile(identity.identifier, files[i].path, files[i].buffer)
}

/*
Example resulting file structure:
0b86f22e88e1be3c243f3604981683a3f51808103c98bcf99b6b72cfe9646cc1/
├── ddo.json
├── identity
├── keystore
│   ├── ara
│   └── eth
└── schema.proto
*/

aid.fs.readFile(identifier, filename)

Read a file for a given identifier from its local copy or a remote server.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'

const ddo = await aid.fs.readFile(did, 'ddo.json')

aid.fs.readdir(identifier)

Read the contents of the identity directory for a given identifier. The identity directory may be located on a remote server.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'

const files = await aid.fs.readdir(did)
console.log(files) // Displays a list of all files present in that identity directory
  • TODO: Verify method definition to meet with method naming (prashanth)

aid.fs.access(identifier, filename)

Check if a file is present in the identity directory of a given identifier. The identity directory may be located on a remote server.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'
try {
  if( await aid.fs.access(did, 'ddo.json') ) {
    console.log('ddo.json file is present')
  }
} catch(err) {
  throw new Error(err)
}

aid.fs.lstat(identifier, filename)

Retrieve information about a file from the identity directory of a given identifier. The identity directory may be located on a remote server. Throws error if file is not found. Note: This function does not follow symlinks.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'

const stats = await aid.fs.lstat(did, 'ddo.json')
* TODO: put example print out here.

aid.fs.stat(identifier, filename)

Retrieve information about a file from the identity directory of a given identifier. The identity directory may be located on a remote server. Throws error if file is not found. This function will follow symlinks.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'

const stats = await aid.fs.stat(did, 'ddo.json')
* TODO: put example print out here.

aid.list([path])

Return a list all identities present locally in a given path. path defaults to env root path if no path is provided. See ara-runtime-configuration docs for more information about environment variables.

const identities = await list()
* TODO: put example print out here.

aid.recover(opts)

Recover a lost Ara identity by providing the valid bip39 mnemonic returned during creation.

const context = require('ara-context')()

const opts = {
  context,
  password: 'password',
  mnemonic: 'glad kangaroo coyote rich detail grief matrix spirit jeans owner heart net'
}

const identity = await aid.recover(opts)

aid.replicate(did)

Replicate all identity files of a given Ara ID as a Buffer array from a remote server. Note: Ensure .ararc file contains entries to the DNS & DHT server of the remote node.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'
const identityFiles = await aid.replicate(did)

aid.resolve(did, opts)

Return the DID document of an Ara ID from a local copy or a remote server. See Ara Identity Resolver for more information.

const did = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'
const opts = {
  secret: 'test-secret',
  network: 'resolver',
  keyring: '~/.ara/keyrings/keyring.pub'
}
const ddo = await aid.resolve(did, opts)
* TODO: put example print out here. (DID document in JSON format)

aid.revoke(opts)

Revoke an Ara ID using the the valid bip39 mnemonic returned during creation. This action cannot be reverted. Note: Please archive your identity after revoking to publish changes into the ara network.

const context = require('ara-context')()
const opts = {
  context,
  mnemonic: 'glad kangaroo coyote rich detail grief matrix spirit jeans owner heart net',
  password: 'password'
}
const revokedIdentity = await aid.revoke(opts)

aid.sign(identifier, message, opts)

const message = Buffer.from()'hello')
const password = Buffer.from('password')
const identifier = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'
const signature = await aid.sign(identifier, message, { password })

aid.verify(identifier, signature, message, opts)

const message = Buffer.from('hello')
const password = Buffer.from('password')
const identifier = 'did:ara:4d7eba2809e627168054cae10a3a08fbdb9f5d58cd0e26a565c1c14c4157cb45'
const signature = await aid.sign(identifier, message, { password })
const verified = await aid.verify(identifier, signature, message)

CLI

See CLI Readme to use ara-identity from the command line.

Contributing

See Also

License

LGPL-3.0