nanoseek

0.2.23 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i nanoseek

Weekly Downloads

222

Version

0.2.23

License

Open BSV License

Unpacked Size

19.1 kB

Total Files

7

Last publish

Collaborators

  • tonesnotes
  • braydude
  • tyeverett