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

@fairdatasociety/blossom

v0.5.0

Published

JavaScript library for interaction with the Blossom browser extension

Downloads

19

Readme

Blossom JS Library

A JavaScript library that provides an interface to the Blossom browser extension.

Installation

The library can be installed via npm:

npm install --save @fairdatasociety/blossom

Usage

Blossom class

All interaction with the Blossom browser extension is established through the Blossom class:

import { Blossom } from '@fairdatasociety/blossom'

By default the class will connect to the Blossom browser extension using its ID from the Google store. If you are running your version of the extension the class can be configured with a different extension ID.

const blossom = new Blossom() // Using the default Blossom ID from the Google store
const blossom = new Blossom('Blossom Extension ID...') // Using custom Blossom ID

Each dApp should be executed from a BZZ link (e.g. http://dApp-or-ENS-name.swarm.localhost:1633 or http://localhost:1633/bzz/dApp-or-ENS-name/). In that case dApp's ID is available as blossom.dappId property.

To test if connection with the Blossom extension is established, call the echo method:

const text = await blossom.echo<string>('test')
console.log(text) // 'test'

FDP Storage

Pod access

If the user is logged in, dApp can access its own pod. Each dApp can have only one pod and its name must be the same as the blossom.dappId property.

To check if dApp's pod is already created:

const podIsCreated = await blossom.fdpStorage.personalStorage.isDappPodCreated()

If not created, then it can be created by calling:

const pod = await blossom.fdpStorage.personalStorage.create(blossom.dappId)

If other pod name is provided, that pod can be created/accessed only if the user allows it. Otherwise an Access denied error will be thrown.

For applications that need access to all pods (like file system apps, etc.), they can request full access:

const allowed = await blossom.fdpStorage.personalStorage.requestFullAccess()

File access

dApp can execute various operations with allowed pods, like creating, reading files and directories, etc.

For example, to create a directory:

const directory = await blossom.fdpStorage.directory.create(blossom.dappId, '/example')

Then, to upload a file there:

const file = await blossom.fdpStorage.file.uploadData(blossom.dappId, '/example/new-file.txt', 'File content')

And to download the same file:

const content = await blossom.fdpStorage.file.downloadData(blossom.dappId, '/example/new-file.txt')
console.log(content.text()) // 'File content'

NOTE: For more available methods, check the fdp-storage repo

Signer

dApps can sign any data using their default pod's private key.

const signature = await blossom.signer.signMessage(blossom.dappId, 'Data...')

Wallet

Library provides methods for interaction with Blossom wallet.

To get information about the user:

const info = await blossom.wallet.getAccountInfo()
console.log(info.address) // user's address

NOTE: The user must allow access to this information, othrwise an "Access denied" error is thrown

To get balance of currently logged in user:

const balanceString = await blossom.wallet.getUserBalance()
console.log(BigNumber.from(balanceString)) // result can be converted to BigNumber object

dApp can send funds as well, but the user must allow it:

await blossom.wallet.sendTransaction('0x1234...', '1000000000')

Terminating connection

Once when the instance of the Blossom class is not needed anymore, connection with the extension can be terminated.

blossom.closeConnection()

Development

To watch for changes in the source code and recompile the library on change:

npm start

Build

To build the library:

npm run build

Tests

Tests use the puppeteer project to interact with the library and the Blossom extension. Because of that, tests need web pages that are going to be interacted with. Such test web pages are located inside the test/webpages directory. Each page contains elements that can be interacted with to trigger various events, and placeholder elements that are used to show results of various operations.

Before running tests, the complete environment must be started. To start the environment and the extension check the extension's readme.

To run a web server that will serve the test web pages, execute:

npm run serve

The Blossom extension and the Swarm extension must be compiled. For that, check the readme file of the root project.

Now when the environment is ready, tests are executed by running:

npm test