# @elrondnetwork/evertrail.core

> The core package of the __Elrond Evertrail__ service, built using [Node.js](https://nodejs.org/en/) and [Typescript](https://www.typescriptlang.org/).

Latest version **0.0.3** (published 2021-08-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install @elrondnetwork/evertrail.core
pnpm add @elrondnetwork/evertrail.core
yarn add @elrondnetwork/evertrail.core
bun add @elrondnetwork/evertrail.core
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2021-08-19 |
| First published | 2021-07-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 49.8 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | ElrondNetwork |
| Maintainers | tanghel, lucian.mincu, ccorcoveanu, radu.paun, titel, jules00, valentinlup, fixone, arhtudormorar, miiu96, bogdan-rosianu, andreibancioiu |

## Links

- npm: https://www.npmjs.com/package/@elrondnetwork/evertrail.core
- npm.io page: https://npm.io/package/@elrondnetwork/evertrail.core

## Dependencies (4)

- [rxjs](https://npm.io/package/rxjs.md) 6.6.6
- [axios](https://npm.io/package/axios.md) 0.21.1
- [mime-types](https://npm.io/package/mime-types.md) 2.1.29
- [node-object-hash](https://npm.io/package/node-object-hash.md) 2.3.0

## Recent versions

- 0.0.3 (latest) — 2021-08-19
- 0.0.2 — 2021-07-28
- 0.0.1 — 2021-07-28

## README

# @elrondnetwork/evertrail.core
The core package 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
* [axios](https://www.npmjs.com/package/axios) version 0.21.0+
* [mime-types](https://www.npmjs.com/package/mime-types) version 2.1.0+
* [node-object-hash](https://www.npmjs.com/package/node-object-hash) version 2.3.0+
* [rxjs](https://www.npmjs.com/package/rxjs) version 6.6.6+

## 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/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.

```js
// Creating a hash

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

// (reader: Reader) => Promise<HashResult>
const hashResult = await hash(reader)
```

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

---
_Source: https://npm.io/package/@elrondnetwork/evertrail.core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
