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

nanoseek

v0.2.36

Published

UHRP Downloader

Downloads

58

Readme

NanoSeek

UHRP Downloader

Overview

This library allows you to download content from the Universal Hash Resolution Protocol (UHRP). Since UHRP URLs are content-addressed, they are self-authenticating. Since any UHRP host can advertise the availability of content, discovery is no longer controlled by a trusted third party as is the case with HTTP.

Example

For an example in React, check out the NanoStore UI, or view it on the web.

The below code can be used in a browser to download a UHRP file, given the URL:

const { download } = require('nanoseek')

// URL of the file you want to download
const downloadURL = 'XUTTCy7KcAn1MdU8SksihCqTnzXc76gbWNXqVMJ5rN1swFTbqbbV'
// The confederacy host URL
const host = 'https://confederacy.babbage.systems'

const { mimeType, data } = await download({ 
    UHRPUrl: downloadURL, 
    confederacyHost: host })

// Create a Blob and download the file with the browser
const blob = new Blob([data], { type: mimeType })
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = downloadURL // Or provide the file name you want to use
link.click()

API

Table of Contents

resolve

Locates HTTP URLs where content can be downloaded. It uses the passed Confederacy hosts or the default one.

Parameters

  • obj Object All parameters are passed in an object. (optional, default {})

    • obj.UHRPUrl String The UHRP url to resolve.
    • obj.confederacyHost string HTTPS URL for for the Confederacy host with default setting. (optional, default 'https://confederacy.babbage.systems')
    • obj.clientPrivateKey String? Key used to resolve the file (for payment)
  • Throws Error If UHRP url parameter invalid or Confederacy hosts is not an array or there is an error retrieving url(s) stored in the UHRP token.

Returns Array<String> An array of HTTP URLs where content can be downloaded.

download

Downloads content from a UHRP url and returns it as a buffer with its mime type, after validating that the hash is correct. It uses the passed Confederacy hosts or the default one.

Parameters

  • obj Object All parameters are passed in an object. (optional, default {})

    • obj.UHRPUrl String The UHRP url to download.
    • obj.confederacyHost String The confederacy host URL (optional, default 'https://confederacy.babbage.systems')
    • obj.clientPrivateKey String? Key used to resolve the file (for payment)
  • Throws Error If UHRP url parameter invalid or Confederacy hosts is not an array or hash is invalid or unable to download using retrieved url(s)

Returns Object An object containing "data" (a buffer) and "mimeType" for the content.

getUrlFromQueryResult

This function takes a query result and returns the associated url(s).

Parameters

  • queryResult object The query result to parse.
  • Throws Error If passed parameter query result is missing or an invalid type.

Returns array The retrieved url(s).

License

The license for the code in this repository is the Open BSV License.