npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@crisog/pocketjs-relayer

v1.2.0

Published

Slim relayer client for the Pocket Network v0 Protocol

Downloads

7

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.

Installation

Install through your package manager of choice:

pnpm install @crisog/pocketjs-relayer

Usage

import { AbstractRelayer, Relayer } from '@crisog/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

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