@keeex/afterbc
v2.3.0
Published
Provide and parse string that indicate a "not before" date.
Readme
@keeex/afterbc
Library that provide strings that could not have existed before the time of the call.
This version will gather infos either from Ethereum or Bitcoin blockchain from Blockcypher, Mempool or Blockscout. It returns the last block hash value, providing a string that effectively could not be guessed beforehand.
This value, combined with proper timestamping that provide a "not after" date can provide a limited timeframe for the creation of any associated data.
Usage
The library exposes two functions as the default export. A quick example follows:
import {getAfterString, parseAfterString} from "@keeex/afterbc";
const main = async() => {
/**
* Return an unguessable string
* @return {string}
*/
const str = await getAfterString();
// At this point the value of str can be embedded in any data to be
// timestamped
/**
* Parse string response
* @typedef {Object} ParseStringRes
* @property {Date} date
* @property {string} text - human friendly infos in english
* @property {string} checkUrl - url to access the blockchain's block
* @property {number} [height] - height of the blockchain's block
* @property {string} [blockchainName] - name of the blockchain
* @property {string} [hash] - hash of the blochain's block
*/
/**
* Parse an afterbc string
* @param {string} afterbc - afterbc string
* @returns {ParseStringRes}
*/
const ouptut = await parseAfterString(str);
// output contains a `date` property that is a JavaScript Date
console.log("Returned string date: ", output.date);
// it also contains a `checkUrl` property that provides third-party
// verification
console.log("Check URL: ", output.checkUrl);
}Restrictions
The library choose which blockchain and which source to use, you cannot force it. It will first try the ethereum ones, then the bitcoin ones. The output is limited to the resolution of the source.
The library manages a cache that should be acceptable for any given source. Multiple calls that uses the same source will use that cache and avoid hitting the underlying service.
Any string produced in the past should be handled appropriately to some extent.
