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

blossom-drive-sdk

v0.4.1

Published

A library for working with blossom drives

Downloads

205

Readme

🌸 blossom-drive-sdk

blossom-drive-sdk is a library working with drives created in blossom-drive

Documentation

Working with drives

The Drive class can be used to easily manage the file tree inside a drive event k:30563 (Docs)

The Drive class takes two arguments, signer and publisher. The signer is an async method that takes an unsigned nostr event and returns a signed event. The publisher is a method used to "publish" the signed nostr event to some relays so it can be loaded later

The simplest signer and publisher would look something like

import { Relay } from "nostr-tools/relay";
const relay = await Relay.connect("wss://relay.example.com");

async function signer(template) {
  return await window.nostr.signEvent(template);
}
function publisher(event) {
  relay.publish(event);
}

There are generally two ways to create a Drive class.

// create a new empty drive
const drive = new Drive(signer, publisher);
drive.name = "Empty";
drive.description = "an empty drive";

// create a drive from an event
const drive = Drive.fromEvent(event, signer, publisher);

Manage files and folder in a drive

Once you have create a drive you need to add some files to it

// This will create a /bitcoin.pdf file in the drive set to a certain sha256
drive.setFile("/bitcoin.pdf", {
  sha256: "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
  size: 184929,
  type: "application/pdf",
});

// Create an empty folder
drive.getFolder("/New Folder", true);

// Move a file
drive.move("/bitcoin.pdf", "/New Folder/bitcoin.pdf");

// Remove a file
drive.remove("/New Folder/bitcoin.pdf");

You can see all the methods for managing files in the documentation

Working with encrypted drives

Encrypted drives use a different event kind k:30564 than normal drives

The EncryptedDrive class is every similar to the Drive class but it has a few additional methods

  • unlock(password) Attempts to decrypt and drive
  • lock() Forgets the password and resets the drive
  • setPassword(password) Used to set the password on a newly created drive

You can read more here

Examples

Create a new drive

import { Relay } from "nostr-tools/relay";
import { DRIVE_KIND, Drive } from "blossom-drive-sdk";

async function signer(template) {
  return await window.nostr.signEvent(template);
}

const relay = await Relay.connect("wss://relay.example.com");
function publisher(event) {
  relay.publish(event);
}

const drive = new Drive(signer, publisher);
drive.name = "New Drive";
drive.description = "A test drive";

// add a file
drive.setFile("/bitcoin.pdf", {
  sha256: "b1674191a88ec5cdd733e4240a81803105dc412d6c6708d53ab94fc248f4f553",
  size: 184929,
  type: "application/pdf",
});

// create an empty folder
drive.getFolder("/New Folder", true);

// finally save the drive to nostr
await drive.save();

Create a drive from an events

import { Relay } from "nostr-tools/relay";
import { DRIVE_KIND, Drive } from "blossom-drive-sdk";

function signer(template) {
  return window.nostr.signEvent(template);
}
function publisher(event) {
  relay.publish(event);
}

const relay = await Relay.connect("wss://relay.example.com");

const pubkey = await window.nostr.getPublicKey();

const driveEvents = [];
const sub = relay.subscribe([{ kinds: [DRIVE_KIND], author: [pubkey] }], {
  onevent(event) {
    driveEvents.push(event);
  },
  oneose() {
    sub.close();

    const drives = [];
    for (let event of driveEvents) {
      // create drive class from an event
      const drive = Drive.fromEvent(event, signer, publisher);
    }
  },
});

Update a drive from an event

import { Relay } from "nostr-tools/relay";
import { DRIVE_KIND, Drive } from "blossom-drive-sdk";

function signer(template) {
  return window.nostr.signEvent(template);
}

const relay = await Relay.connect("wss://relay.example.com");
function publisher(event) {
  relay.publish(event);
}

const drive = new Drive(signer, publisher);

const driveEvents = [];
const sub = relay.subscribe([{ kinds: [DRIVE_KIND], "#d": ["random"] }], {
  onevent(event) {
    drive.update(event);
  },
});