Catalog npm
Back to packageRELEASE DETAILS

1.0.0-beta-9

npm

3box

Interact with user data

Published11 Oct 2018
Direct dependencies22
Transitive dependenciesNot calculated

README

Version 1.0.0-beta-9 documentation

3box-js

Warning: This project is under active development, APIs are subject to change.

This is a library which allows you to set, get, and remove private and public data associated with an ethereum account. It can be used to store identity data, user settings, etc. by dapps that use a web3 enabled browser. The data will be retrievable as long as the user has access to the private key for the used ethereum account. The data is encrypted and can not be read by any third party that the user hasn't authorized. Currently it supports one shared space which all dapps can access. In the future there will be support for more granular access control using namespaces.

Installation

Install 3box in your npm project:

$ npm install 3box@next

Usage

Import 3Box into your project

Import the 3box module

const ThreeBox = require('3box')

or use the dist build in your html code

<script type="text/javascript" src="../dist/3box.js"></script>

Get the public profile of an address

3Box allows users to create a public profile. In your dapp you might have multiple ethereum addresses that you would like to display a name and picture for. The getProfile method allows you to retrieve the profile of any ethereum address (if it has one). This is a static method so you can call it directly from the ThreeBox object.

Using async/await

const profile = await ThreeBox.getProfile('0x12345abcde')
console.log(profile)

or using .then

ThreeBox.getProfile('0x12345abcde').then(profile => {
  console.log(profile)
})

Get, set, and remove data

To get or modify data in a user's 3Box, first open their 3Box by calling the openBox method. This method prompts the user to authenticate your dapp and returns a promise with a threeBox instance. You can only set, get, and remove data of users that are currently interacting with your dapp. Below web3provider refers to the object that you would get from web3.currentProvider, or request directly from the web3 browser, e.g. MetaMask.

Open 3Box session

Using async/await

const box = await ThreeBox.openBox('0x12345abcde', web3provider)

or using .then

ThreeBox.openBox('0x12345abcde', web3provider).then(box => {
  // interact with 3Box data
})

Interact with 3Box data

You can now use the box instance object to interact with data in the users private store and profile. In both the profile and the private store you use a key to set a value. What keys can I use?

Using async/await

// use the public profile
// get
const nickname = await box.public.get('name')
console.log(nickname)
// set
await box.public.set('name', 'oed')
// remove
await box.public.remove('name')

// use the private store
// get
const email = await box.private.get('email')
console.log(email)
// set
await box.private.set('email', 'oed@email.service')
// remove
await box.private.remove('email')

or using .then

// use the public profile
// get
box.public.get('name').then(nickname => {
  console.log(nickname)
  // set
  box.public.set('name', 'oed').then(() => {
    // remove
    box.public.remove('name').then(() => {
    })
  })
})

// use the private store
// get
box.private.get('email').then(email => {
  console.log(email)
  // set
  box.private.set('email', 'oed@email.service').then(() => {
    // remove
    box.private.remove('email').then(() => {
    })
  })
})

Example

You can quickly run and interact with some code by looking at the files in the /example folder. You run the example with the following command:

$ npm run example:start

This runs a simple server at http://localhost:3000/ that serves the static example/index.html file. This allows it easily interact with metamask. You can edit the example/index.html file to try differnt code.

API Documentation

ThreeBox

Kind: global class

new ThreeBox()

Please use the openBox method to instantiate a ThreeBox

threeBox.public

Kind: instance property of ThreeBox
Properties

NameTypeDescription
publicKeyValueStoreaccess the profile store of the users threeBox

threeBox.private

Kind: instance property of ThreeBox
Properties

NameTypeDescription
privateKeyValueStoreaccess the private store of the users threeBox

threeBox.close()

Closes the 3box instance without clearing the local cache. Should be called after you are done using the 3Box instance, but without logging the user out.

Kind: instance method of ThreeBox

threeBox.logout()

Closes the 3box instance and clears local cache. If you call this, users will need to sign a consent message to log in the next time you call openBox.

Kind: instance method of ThreeBox

ThreeBox.getProfile(address, opts) ⇒ Object

Get the public profile of a given address

Kind: static method of ThreeBox
Returns: Object - a json object with the profile for the given address

ParamTypeDescription
addressStringan ethereum address
optsObjectOptional parameters
opts.ipfsIPFSA custom ipfs instance

ThreeBox.openBox(address, web3provider, opts) ⇒ ThreeBox

Opens the user space associated with the given address

Kind: static method of ThreeBox
Returns: ThreeBox - the threeBox instance for the given address

ParamTypeDescription
addressStringan ethereum address
web3providerWeb3ProviderA Web3 provider
optsObjectOptional parameters
opts.ipfsOptionsObjectA ipfs options object to pass to the js-ipfs constructor
opts.orbitPathStringA custom path for orbitdb storage
opts.consentCallbackfunctionA function that will be called when the user has consented to opening the box

KeyValueStore

Kind: global class

new KeyValueStore()

Please use threeBox.profileStore or threeBox.profileStore to get the instance of this class

keyValueStore.log ⇒ Array.<Object>

Returns array of underlying log entries. In linearized order according to their Lamport clocks. Useful for generating a complete history of all operations on store.

Kind: instance property of KeyValueStore
Returns: Array.<Object> - Array of ordered log entry objects
Example

const log = store.log
 const entry = log[0]
 console.log(entry)
 // { op: 'PUT', key: 'Name', value: 'Botbot', timeStamp: '1538575416068' }

keyValueStore.get(key) ⇒ String

Get the value of the given key

Kind: instance method of KeyValueStore
Returns: String - the value associated with the key

ParamTypeDescription
keyStringthe key

keyValueStore.set(key, value) ⇒ Boolean

Set a value for the given key

Kind: instance method of KeyValueStore
Returns: Boolean - true if successful

ParamTypeDescription
keyStringthe key
valueStringthe value

keyValueStore.remove(key) ⇒ Boolean

Remove the value for the given key

Kind: instance method of KeyValueStore
Returns: Boolean - true if successful

ParamTypeDescription
keyStringthe key

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 22

Native requirements
22 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
ipfs
Environment
{
  "local_name": "ipfs",
  "alias": false,
  "peer_metadata": null
}
^0.32.2runtime
bip39
Environment
{
  "local_name": "bip39",
  "alias": false,
  "peer_metadata": null
}
^2.5.0runtime
store
Environment
{
  "local_name": "store",
  "alias": false,
  "peer_metadata": null
}
^2.0.12runtime
ipfs-api
Environment
{
  "local_name": "ipfs-api",
  "alias": false,
  "peer_metadata": null
}
^24.0.0runtime
orbit-db
Environment
{
  "local_name": "orbit-db",
  "alias": false,
  "peer_metadata": null
}
^0.19.9runtime
js-sha256
Environment
{
  "local_name": "js-sha256",
  "alias": false,
  "peer_metadata": null
}
^0.9.0runtime
muport-core
Environment
{
  "local_name": "muport-core",
  "alias": false,
  "peer_metadata": null
}
^0.4.1runtime
xmlhttprequest
Environment
{
  "local_name": "xmlhttprequest",
  "alias": false,
  "peer_metadata": null
}
^1.8.0runtime
ipfs-pubsub-room
Environment
{
  "local_name": "ipfs-pubsub-room",
  "alias": false,
  "peer_metadata": null
}
^1.4.0runtime
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^23.6.0development
webpack
Environment
{
  "local_name": "webpack",
  "alias": false,
  "peer_metadata": null
}
^4.20.2development
standard
Environment
{
  "local_name": "standard",
  "alias": false,
  "peer_metadata": null
}
^12.0.1development
babel-cli
Environment
{
  "local_name": "babel-cli",
  "alias": false,
  "peer_metadata": null
}
^6.26.0development
ipfsd-ctl
Environment
{
  "local_name": "ipfsd-ctl",
  "alias": false,
  "peer_metadata": null
}
^0.39.1development
babel-core
Environment
{
  "local_name": "babel-core",
  "alias": false,
  "peer_metadata": null
}
^6.26.3development
ganache-cli
Environment
{
  "local_name": "ganache-cli",
  "alias": false,
  "peer_metadata": null
}
^6.1.0development
webpack-cli
Environment
{
  "local_name": "webpack-cli",
  "alias": false,
  "peer_metadata": null
}
^3.1.2development
babel-loader
Environment
{
  "local_name": "babel-loader",
  "alias": false,
  "peer_metadata": null
}
^7.1.5development
babel-preset-env
Environment
{
  "local_name": "babel-preset-env",
  "alias": false,
  "peer_metadata": null
}
^1.6.1development
jsdoc-to-markdown
Environment
{
  "local_name": "jsdoc-to-markdown",
  "alias": false,
  "peer_metadata": null
}
^4.0.1development
babel-plugin-transform-runtime
Environment
{
  "local_name": "babel-plugin-transform-runtime",
  "alias": false,
  "peer_metadata": null
}
^6.23.0development
babel-plugin-transform-object-rest-spread
Environment
{
  "local_name": "babel-plugin-transform-object-rest-spread",
  "alias": false,
  "peer_metadata": null
}
^6.26.0development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "817f557d0aed38e56feffd842e14ee37db0f3f99",
  "tarball": "https://registry.npmjs.org/3box/-/3box-1.0.0-beta-9.tgz",
  "fileCount": 41,
  "integrity": "sha512-a5Zi5Ua6NewVngwsEGL5eeV4gTI5ycgJFOAhZ0SeAQz9jwxfu0x83DASQFSuNlSHQ1LvWeHc9M1ltKsVjLn96A==",
  "signatures": [
    {
      "sig": "MEYCIQDsIgZESpPUVPHoldVJEQfods1JP/JbStOUyfYlc8YKSwIhAJevsNDvd8VwMxi1fkgksdmgRYNs2Girhe6Psbtx5+CW",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 16796723,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbv4YHCRA9TVsSAnZWagAAQh8P/07Ist5MXEZ5WRc+D39B\nn0UvKDauo5RgGGX8n6AmKquuHEsFQ1w2bo5wLiQPyYcRabo2QSpXRkYNzuTh\nrs3UEYP3rD6C+9YCd4YHUmGlI0CuDfvlB9HK8nZP2IotuR2wJCKcQI86cTlI\n/Qj83Wd3u02MN5D0VCDt2//JnIp5myMlA4sQZ8M3e8LVWucihdMdol02Kpnd\nKTZ2V3CS887ZBL3O7SwPA5PnXPG+seoCXLsawAEH/7cSK5YtbOt28NAeZf3d\nRcto5gx8Ak5oc5oQuTgEHuBq5xbThYvAqOA+zF2UC24b8/tXtda7GSeiKBFs\noqCbepwr6UodX7Fw4zJ9yeHme78bg1x6jOTOHSU0cRmEMVLX5NS8FtgkyS8d\nhSfDlEaEca46qsIN7UAA+SdC53okZsjel1nm75NHWpC/IZKsnf8uK8xKbPae\nrGoYJdT2yIqtBzI9T0RoClq7rf1Bt8eJZzM+VuBmIoNFGngJxqzkR9CNKuWd\nLxH5zSDiJtg0FKXb3SCCW9bkKeCbmYtPDTg7X5AbAOTvIpOPx5gvOtC3FN3V\nEMVeuET5XJpP4k2U22HA5p8lGaBIb7W95zVuIawWJLaukPiiRn2PAJYK16P/\naAeNL6/fH7hpybwkScVicVNL1UQJGsxdNWFbLmOH0/qI/IwImd8zXyhgp26C\n/dN6\r\n=WQzd\r\n-----END PGP SIGNATURE-----\r\n"
}

Repository

PENDING
3box/3box-js

Shared repository data · GitHub

License detected in repository
Not collected

Repository

MOVED
uport-project/3box-js

Shared repository data · GitHub

Repository moved · manual review pending

HTTP 301 · detected 21 Oct 2026

Reported destination
License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:30 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:57d5335e01ec3d2b2bf23742fc274c4f73eff1455c59dc2b1bbe5ca338cbd511

Other collected versions

1.19.123 Feb1.22.228 Sept1.22.2-beta.028 Sept1.22.121 Sept1.22.1-alpha.021 Sept1.22.015 SeptView all collected versions →