# @0xbigboss/pocketjs-relayer

> Slim relayer client for the Pocket Network v0 Protocol

Latest version **2.1.1** (published 2022-10-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @0xbigboss/pocketjs-relayer
pnpm add @0xbigboss/pocketjs-relayer
yarn add @0xbigboss/pocketjs-relayer
bun add @0xbigboss/pocketjs-relayer
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.1 |
| Published | 2022-10-30 |
| First published | 2022-10-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 150.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | 0xbigboss |

## Links

- npm: https://www.npmjs.com/package/@0xbigboss/pocketjs-relayer
- npm.io page: https://npm.io/package/@0xbigboss/pocketjs-relayer

## Dependencies (7)

- [debug](https://npm.io/package/debug.md) ^4.3.3
- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [js-sha256](https://npm.io/package/js-sha256.md) ^0.9.0
- [isomorphic-webcrypto](https://npm.io/package/isomorphic-webcrypto.md) ^2.3.8
- [@0xbigboss/pocketjs-signer](https://npm.io/package/@0xbigboss/pocketjs-signer.md) 2.1.1
- [@0xbigboss/pocketjs-provider](https://npm.io/package/@0xbigboss/pocketjs-provider.md) 2.1.1
- [@0xbigboss/pocketjs-abstract-provider](https://npm.io/package/@0xbigboss/pocketjs-abstract-provider.md) 2.1.1

## Recent versions

- 2.1.1 (latest) — 2022-10-30
- 2.1.0 — 2022-10-02

## README

# Relayer

This package houses both the abstract relayer interface we expose to people so that they build their own Relayer, and an actual Relayer ready to use for sending relays and dispatching new sessions.

You'll need a staked aplication in the Pocket Network blockchain to use this package.

To learn more about the relay lifecycle, reach for the [docs](https://docs.pokt.network/home/v0/protocol/servicing).

## Installation
Install through your package manager of choice:
```
pnpm install @pokt-foundation/pocketjs-relayer
```

## Usage

```js 
import { AbstractRelayer, Relayer } from '@pokt-foundation/pocketjs-relayer'

// For the AbstractRelayer, just implement it!
class MyRelayer extends AbstractRelayer {
 // Now override the required methods...
}

// Initializing the relayer is simple:
// 1. Instanciate a provider
export const provider = new JsonRpcProvider({
  rpcUrl: MAINNET_RPC_URL,
  // For a relayer, dispatchers are needed
  dispatchers: DISPATCHERS,
})

// 2. Instanciate a signer for signing the relays
export const signer = await KeyManager.fromPrivateKey(process.env.PRIVATE_KEY)

// 3. Create a new relayer to send relays over the network!
export const relayer = new Relayer({
  keyManager: signer,
  provider,
  dispatchers: DISPATCHERS,
});

// Get a new session
const session = await relayer.getNewSession({
  chain: process.env.APP_CHAIN,
  applicationPubKey: process.env.APP_PUBLIC_KEY,
})

// Send a relay
const relay = await relayer.relay({
  data: process.env.RELAY_DATA,
  blockchain: process.env.APP_CHAIN,
  pocketAAT: POCKET_AAT,
  session: session,
})

```

## Relayer API

### Constructor
#### keyManager
- type: `KeyManager`
The KeyManager instance that holds the staked app in the blockchain.

#### provider
- type: `JsonRpcProvider` | `IsomorphicProvider`
The provider instance with available dispatchers to talk to the network.

#### dispatchers
- type: `String[]`
Backup set of dispatchers.

### Methods
#### getNewSession({ applicationPubKey, chain, sessionBlockHeight, options }): Promise<Session>
Performs a dispatch request to obtain a new session. Fails if no dispatcher is provided through the provider.

Returns `Promise<Session>`: The dispatch response as a session.

| Param                                | Type      | Description                                               |
|--------------------------------------|-----------|-----------------------------------------------------------|
| applicationPubKey                    | `string`  | The application's public key.                             |
| chain                                | `string`  | The chain for the ssions.                                 |
| sessionBlockHeight                   | `number`  | The session block height.                                 |
| options                              | `object`  | The options available to tweak the request itself.        |
| options.retryAttempts                | `number`  | The number of retries to perform if the first call fails. |
| options.rejectSelfSignedCertificates | `boolean` | Option to reject self signed certificates or not.         |
| options.timeout                      | `number`  | Timeout before the call fails. In milliseconds.           |

#### relay({ blockchain, data, headers, method, node, path, pocketAAT, session, options })
Sends a relay to the network.

| Param                                | Type      | Description                                                                 |
|--------------------------------------|-----------|-----------------------------------------------------------------------------|
| blockchain                           | `string`  | The chain for the session.                                                  |
| data                                 | `string`  | The data to send, stringified.                                              |
| headers                              | `object`  | The headers to include in the call, if any.                                 |
| node                                 | `Node`    | The node to send the relay to. The node must belong to the current session. |
| path                                 | `string`  | The path to query in the relay. Useful for chains like AVAX.                |
| pocketAAT                            | `AAT`     | The pocketAAT used to authenticate the relay.                               |
| session                              | `Session` | The current session the app is assigned to.                                 |
| options                              | `object`  | The options available to tweak the request itself.                          |
| options.retryAttempts                | `number`  | The number of retries to perform if the first call fails.                   |
| options.rejectSelfSignedCertificates | `boolean` | Option to reject self signed certificates or not.                           |
| options.timeout                      | `number`  | Timeout before the call fails. In milliseconds.                             |

---
_Source: https://npm.io/package/@0xbigboss/pocketjs-relayer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
