0.1.0 • Published 4 years ago

@elrondnetwork/attest v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

@elrondnetwork/attest

The npm package of the Elrond Attest service, built using Node.js and Typescript.

Requirements

  • Node.js version 14.16.0+
  • Npm version 6.14.0+

Dependencies

Exposed types

  • AttestApi - creates an instance of the AttestApi
  • HashResult - represents the result of a hashing operation

Exposed functions

Note that these may be subject to change

  • webHash - hashes its inputs -> to be used by browser-based applications
  • cliHash - hashes its inputs -> to be used by cli-based applications

Usage

AttestApi

Note that the following methods may be subject to change

// In both examples, base url refers to the url of 
// the ElrondAttest api

// Initialization with api key
const api = AttestApi.withApiKey(apiKey, baseUrl)

// Initialization with access token
const api = AttestApi.withToken(token, baseUrl)

// Fetching account data
api.account() // returns an Axios promise

// Creating a file attestation
const input = {
    type: 'file',
    sha256: 'some hash here'
}

api.create(input) // returns an Axios promise

// Creating an object attestation
const input = {
    type: 'object',
    sha256: 'some hash here',
    object: {
        //...
    }
}

api.create(input) // returns an Axios promise

// Fetching the user's attested files
api.accountRecords() // returns an Axios promise

// Verifying if a file is attested

const hashOfFileToVerify = 'some hash'

api.records(hashOfFileToVerify)

HashResult

type HashResult = {
    type: 'file' | 'object',
    sha256: string,
    object?: object
}

webHash

// An already read file
const file = {}

// Callback for setting progress
// receives a number between 0 & 100 representing progress
// returns void
const setProgress = progress => {}

// Callback called on finalization
// receives a HashResult object representing the hashed file
// returns void
const onFinalize = hashResult => {} 

webHash(file, setProgress, onFinalize)

cliHash

const path = 'Path to file...'

cliHash(path) // Returns Promise<HashResult>