UHRP Downloader
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.
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()
Locates HTTP URLs where content can be downloaded. It uses the passed Confederacy hosts or the default one.
-
obj
Object All parameters are passed in an object. (optional, default{}
)
- 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.
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.
-
obj
Object All parameters are passed in an object. (optional, default{}
)
- 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.
This function takes a query result and returns the associated url(s).
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).
The license for the code in this repository is the Open BSV License.