Skip to content

tiagoalvesdulce/dcrtimejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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");

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •