# @elrondnetwork/evertrail.node
The Node implementation of the __Elrond Evertrail__ service, built using [Node.js](https://nodejs.org/en/) and [Typescript](https://www.typescriptlang.org/).

## Requirements
* Node.js version 14.16.0+
* Npm version 6.14.0+
* Typescript version 4.2.3+

## Dependencies
* [rxjs](https://www.npmjs.com/package/rxjs) version 6.6.6+
* [mime-types](https://www.npmjs.com/package/mime-types) version 2.1.28+
* [read-chunk](https://www.npmjs.com/package/read-chunk) version 3.2.0+
* [evertrail.core](https://github.com/ElrondNetwork/evertrail-core)

## Usage

```js
// Creating a hash

import { hash } from '@elrondnetwork/evertrail.node'

// (input: Input) => Promise<HashResult>
const hashResult = await hash({ path: 'path/to/file' })
```

```js
// Creating the evertrail client
import { evertrail } from '@elrondnetwork/evertrail.node'

// 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

// Creating an trail

const input = {
    path: '/path/to/file', // Path to the file to be trailed
    onProgress: progress => {}, // Optional callback to track trail progress
    options: {
        shouldStoreObject: true // Flag to store generated object alongside trail
    }
}

// (input: Input) => Promise<Result> 
const createResponse = await client.create(input)

// Verifying if a file is already trailed

const input = {
    sha256: 'some existing hash',
    path: 'path/to/file', // To be used instead of the sha256 field
    onProgress: progress => {} // Optional callback to track verification progress
} 

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

### `NodeEvertrail: { create, verify }`
> Type of the evertrail client
