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 = 'uhrp:XUTTCy7KcAn1MdU8SksihCqTnzXc76gbWNXqVMJ5rN1swFTbqbbV'
const { mimeType, data } = await download({ URL: downloadURL })
// 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. Uses trusted hosts when possible.
Parameters
obj
Object All parameters are passed in an object. (optional, default{}
)obj.URL
String The UHRP URL to resolve.obj.trustedHosts
Array<String> A set of UHRP hosts given preferential treatmeant. By default, the Babbage host is trusted. Provide an empty array to resolve all URLs. (optional, default['15RLMCYZ738Y3cBb56yDSWa7TkAFxSQtyf']
)obj.limit
Number The number of results to return. (optional, default10
)obj.offset
Number The offset into the total number of results. (optional, default0
)
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. Uses trusted hosts when possible.
Parameters
obj
Object All parameters are passed in an object. (optional, default{}
)obj.URL
String The UHRP URL to download.obj.trustedHosts
Array<String> A set of UHRP hosts given preferential treatmeant. By default, the Babbage host is trusted. Provide an empty array to disable trusted host resolution. (optional, default['15RLMCYZ738Y3cBb56yDSWa7TkAFxSQtyf']
)obj.limit
Number The maximum number of URLs to try downloading from before giving up. (optional, default10
)obj.offset
Number The offset into the list of potential download URLs to start from. (optional, default0
)
Returns Object An object containing "data" (a buffer) and "mimeType" for the content.
License
The license for the code in this repository is the Open BSV License.