Nifty Purring Manticore

    @elrondnetwork/evertrail.core
    TypeScript icon, indicating that this package has built-in type declarations

    0.0.3 • Public • Published

    @elrondnetwork/evertrail.core

    The core package of the Elrond Evertrail service, built using Node.js and Typescript.

    Requirements

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

    Dependencies

    Usage

    In order to use this package, you'll need to create a Reader object (use the Reader type if in typescript). This Reader object should implement the following functions:

    hasNext: () => Promise<boolean>

    Returns true if there are any remaining chunks to be read

    getNext: () => Promise<ArrayBuffer>

    Returns the next chunk of data to be read, as a javascript ArrayBuffer

    getSize: () => Promise<number>

    Returns the total size in bytes of the file to be read

    getMime: () => Promise<MimeType>

    Returns the mime type of the file to be read

    reset: () => Promise<void>

    Resets the reading process to its original state

    Once the Reader object is created, it can be used as an input for the functions requiring it.

    // Creating a hash
    
    import { hash } from '@elrondnetwork/evertrail.core'
    
    // (reader: Reader) => Promise<HashResult>
    const hashResult = await hash(reader)
    // Creating the evertrail client
    import { evertrail } from '@elrondnetwork/evertrail.core'
    
    // Only one of the following fields should be used at once
    const authorization = {
        token: 'sampleToken', // if you want to authorize the client using an access token
        apiKey: 'sampleApiKey' // if you want to authorize the client using an api key 
    }
    
    const client = evertrail({ authorization })
    
    // The client can then be used to access the trail functions
    
    // Fetching an user's account
    
    // () => Promise<Result>
    const account = await client.account()
    
    // Fetching an user's trails
    
    // Both of the following fields are nullable
    const parameter = {
        sha256: 'some hash', // Last hash after which to fetch trails 
        timeStamp: 'some timestamp' // Last timestamp after which to fetch trails
    }
    
    // (input: TrailParameter) => Promise<Result>
    const trails = await client.trails(parameter)
    
    // Creating a trail 
    
    const input = {
        reader, // The Reader object previously discussed
        options: {
            shouldStoreObject: true // Flag to store generated object alongside trail 
        }
    }
    
    // (input: { reader: Reader, options?: Options }) => Promise<Result> 
    const createResponse = await client.create(input)
    
    // Verifying if a file is already trailed 
    
    const input = "some existing hash" // Or use the reader if you don't already have a hash
    
    const verifyResponse = await client.verify(input)

    Exposed types

    TokenAuthorization: { baseUrl: string, token: string }

    Type to be used for authorizing the client by access token

    ApiKeyAuthorization: { baseUrl: string, apiKey: string }

    Type to be used fot authorizing the client by api key

    Evertrail: { trails, account, create, verify }

    Type of the evertrail client

    TrailParameter: { sha256?: string, timestamp?: string }

    Type of the parameter which is used by the trails function

    Result: { success: boolean, value: any }

    Result type used by all the trail functions

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

    Result type used by the hash function

    Options: { shouldStoreObject?: boolean }

    Optional options parameter to be used by the create function

    Keywords

    none

    Install

    npm i @elrondnetwork/evertrail.core

    DownloadsWeekly Downloads

    6

    Version

    0.0.3

    License

    ISC

    Unpacked Size

    51 kB

    Total Files

    149

    Last publish

    Collaborators

    • cipriand
    • stanislav
    • tanghel
    • lucian.mincu
    • ccorcoveanu
    • titel
    • valentinlup
    • arhtudormorar
    • andreibancioiu