Giter Site home page Giter Site logo

dcrtimejs's Introduction

Dcrtimejs

Javascript wrapper for dcrtime

Table of Contents

Install

If you want to use this library in a Nodejs environment make sure you are using Node v17.5+ because of fetch.

yarn

yarn add dcrtimejs

npm

npm install --save dcrtimejs

Docs

DcrtimeResponse

Properties

Name Type Description
digests array array of objects containing the SHA256, result, servertimestamp and chaininformation if applicable
id String unique identifier

StatusResponse

Properties

Name Type
id String

VersionsResponse

Properties

Name Type
versions Array.<Number>
routeprefixes Array.<String>

LastAnchorResponse

Properties

Name Type Description
chaintimestamp Number chain timestamp if the tx block has more than 6 confirmations
transaction String id of the latest successfully broadcasted tx
blockhash String block hash
blockheight Number block height

GetLastDigestsResponse

Properties

Name Type Description
digests array array of objects containing the SHA256, result, servertimestamp and chaininformation if applicable

setNetwork

Sets the dcrtime server that will be used. Default is mainnet. If network is "testnet", it will be set to testnet. You can also send a custom URL if you want to use your own server

Param Type
network string

getVersions

getVersions returns the versions available and its route prefixes

Returns: Promise.<VersionsResponse> - A promise that returns VersionsResponse if resolved

getLastAnchor

getLastAnchor returns the last successful anchor info request

Returns: Promise.<LastAnchorResponse> - A promise that returns LastAnchorResponse if resolved

getLastDigests

getLastAnchor returns the last n digests submitted

Returns: Promise.<GetLastDigestsResponse> - A promise that returns GetLastDigestsResponse if resolved

getStatus

getStatus is used to ask the server if everything is running properly.

Returns: Promise.<StatusResponse> - A promise that returns StatusResponse if resolved

Param Type Description
id [optional] string Identifier that can be used if a unique identifier is required. A 200 Status and the unique identifier sent will be returned.

timestamp

Timestamps an array of SHA256 hashs using dcrtime.

Param Type Description
digests Array[string] Array of SHA256 hashs
id [optional] string Identifier that can be used if a unique identifier is required

Returns: Promise.<DcrtimeResponse> - The data from dcrtime.

timestampFromBase64

Timestamps an array of base 64 encoded strings using dcrtime.

Param Type Description
base64s Array[string] Array of base64 encoded strings
id [optional] string Identifier that can be used if a unique identifier is required

Returns: Promise.<DcrtimeResponse> - The data from dcrtime.

Timestamp Results

The 'result' key in the returned object means:

Result Description
0 Invalid
1 The HASH has been sent to the dcrtime server to be anchored
2 Hash was already in the server

verify

Verifies if an array of SHA256 hashs is anchored to the blockchain.

Param Type Description
digests Array[string] Array of SHA256 hashs
id [optional] string Identifier that can be used if a unique identifier is required

Returns: Promise.<DcrtimeResponse> - The data from dcrtime.

verifyFromBase64

Verifies if an array of base 64 encoded strings is anchored to the blockchain.

Param Type Description
base64s Array[string] Array of base64 encoded strings
id [optional] string Identifier that can be used if a unique identifier is required

Returns: Promise.<DcrtimeResponse> - The data from dcrtime.

Verify Results

The 'result' key in the returned object means:

Result Description
0 Invalid
1 Digest was found in the server and verified successfully
3 Digest was NOT found in the server and is not anchored

getSHA256fromBase64

Calculates the SHA256 hash of a 64bit encoded string

Param Type Description
base64 string base64 encoded string

Returns: string - The SHA256 hash.

Usage

import dcrtime from "dcrtimejs";

dcrtime.setNetwork("testnet");
dcrtime.timestamp(["9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08"], "dcrtimejs");
dcrtime.timestampFromBase64(["dGVzdA=="], "dcrtimejs");
dcrtime.verify(["9F86D081884C7D659A2FEAA0C55AD015A3BF4F1B2B0B822CD15D6C15B0F00A08"], "dcrtimejs");
dcrtime.verifyFromBase64(["dGVzdA=="], "dcrtimejs");

dcrtimejs's People

Contributors

tiagoalvesdulce avatar dajohi avatar thi4go avatar dependabot[bot] avatar

Watchers

 avatar Marco Peereboom avatar Alex Yocom-Piatt avatar Jake Yocom-Piatt avatar  avatar  avatar

Forkers

dajohi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.