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

@pushprotocol/node-core

v0.0.9

Published

This package provides access to the Push Network. Visit the [Developer Docs](https://push.org/docs) or [Push.org](https://push.org) to learn more.

Downloads

621

Readme

Push Network Core

This package provides access to the Push Network. Visit the Developer Docs or Push.org to learn more.

Index

How to use in your app?

Installation

yarn add @pushprotocol/node-core@latest

or

npm install @pushprotocol/node-core@latest

Import SDK

import { PushNetwork } from '@pushprotocol/node-core';

Initialize SDK

// Initialize PushNetwork class instance
const userAlice = await PushNetwork.initialize('staging');

Parameters

| Param | Type | Default | Remarks | | -------- | ----- | --------- | --------------------------- | | env * | ENV | staging | API env - 'prod', 'staging' |

* - Optional


About blockchain agnostic address format

In any of the below methods (unless explicitly stated otherwise) we accept -

SDK Features

For PushNetwork Blocks

Initializing PushNetwork class is the first step before proceeding to Block APIs. Please refer Initialize SDK Section

Fetch Blocks

// get block data
const blockRes = await PushNetwork.block.get(
  Math.floor(Date.now() / 1000),
  'DESC',
  true,
  10,
  2
);

Parameters:

| Parameter | Type | Default | Description | | --------------- | ------------ | ------------------ | ------------------------------------------------------------------------ | | startTime * | number | Current Local Time | A number represting current time epoch | | direction* | ASC DESC | ASC | A string represting direction in which blocks are fetched | | showDetails* | boolean | false | A boolean represting whether tx Data shoudl be fetched or not | | page* | number | 1 | A number representing the page of results to retrieve. | | pageSize* | number | 30 | A number representing the maximum number of blocks to retrieve per page. |

* - Optional


Search Block By Hash

// search block with a given block hash
const blockRes = await PushNetwork.block.search('block-hash');

Parameters:

| Parameter | Type | Default | Description | | ----------- | -------- | ------- | ------------------------------- | | blockHash | string | - | An string represting block hash |

* - Optional


Serialize Block

import { Block } from '@pushprotocol/node-core';
const serializedBlock = Block.serialize(blockData);

ts: number; txObj: TransactionObj[]; signers: Signer[]; attestToken: Uint8Array;

Parameters:

| Parameter | Type | Default | Description | | ------------- | ------------ | ------- | ----------------------- | | ts | number | - | Block timestamp | | txObj | object[] | - | Block Transactions | | signers | object[] | - | Block Signers | | attestToken | Uint8Array | - | Block Attestation Token |

* - Optional


Deserialize Block

import { Block } from '@pushprotocol/node-core';
const deserializedBlock = Block.deserialize(blockDataBytes);

Parameters:

| Parameter | Type | Default | Description | | --------- | ------------ | ------- | ----------------------------- | | block | Uint8Array | - | Block encoded in bytes format |

* - Optional


For PushNetwork Transactions

Initializing PushNetwork class is the first step before proceeding to Transaction APIs. Please refer Initialize SDK Section

Fetch Transactions

// fetch transactions
const txRes = await PushNetwork.tx.get(
  Math.floor(Date.now() / 1000),
  'DESC',
  10,
  2
);

Parameters:

| Parameter | Type | Default | Description | | -------------- | ------------ | ------------------ | ------------------------------------------------------------------------------ | | startTime * | number | Current Local Time | A number represting current time epoch | | direction* | ASC DESC | ASC | A string represting direction in which transactions are fetched | | page* | number | 1 | A number representing the page of results to retrieve. | | pageSize* | number | 30 | A number representing the maximum number of transactions to retrieve per page. | | category* | string | - | A string representing the transaction category to be fetched |

* - Optional


Search Transaction By Hash

// search transaction with a given tx hash
const txRes = await PushNetwork.tx.search('tx-hash');

Parameters:

| Parameter | Type | Default | Description | | --------- | -------- | ------- | ------------------------------------- | | txHash | string | - | An string represting transaction hash |

* - Optional


Create Unsigned Transaction

// create an unsigned transaction
const unsignedTx = PushNetwork.tx.createUnsigned(
  'CATEGORY',
  ['RECIPIENT1', 'RECIPIENT2'],
  serializedData
);

Parameters:

| Parameter | Type | Default | Description | | ------------ | ------------ | ------- | ----------------------------------- | | category | string | - | Transaction category | | recipients | string[] | - | Array of recipient addresses | | data | Uint8Array | - | Serialized transaction payload data |

* - Optional


Send Transaction

// send a transaction
const txHash = await PushNetwork.tx.send(unsignedTx, {
  sender: 'SENDER_ADDRESS',
  privKey: 'PRIVATE_KEY',
});

Parameters:

| Parameter | Type | Default | Description | | ------------ | ------------- | ------- | ----------------------------------- | | unsignedTx | Transaction | - | Unsigned transaction object | | session * | Object | - | Optional session object for signing |

* - Optional


Serialize Transaction

import { Tx } from '@pushprotocol/node-core';
const serializedTx = Tx.serialize(txObject);

Parameters:

| Parameter | Type | Default | Description | | --------- | ------------- | ------- | ------------------ | | tx | Transaction | - | Transaction object |

* - Optional


Deserialize Transaction

import { Tx } from '@pushprotocol/node-core';
const deserializedTx = Tx.deserialize(txDataBytes);

Parameters:

| Parameter | Type | Default | Description | | --------- | ------------ | ------- | -------------------------- | | tx | Uint8Array | - | Tx encoded in bytes format |

* - Optional


Serialize Transaction Payload Data

import { Tx, TxCategory } from '@pushprotocol/node-core';
const serializedData = Tx.serializeData(txData, TxCategory.INIT_DID);

Parameters:

| Parameter | Type | Default | Description | | ---------- | ------------------------------ | ------- | ------------------------------- | | txData | InitDid \| InitSessionKey Tx | - | Transaction payload data object | | category | TxCategory | - | Transaction category |

* - Optional


Deserialize Transaction Payload Data

import { Tx, TxCategory } from '@pushprotocol/node-core';
const deserializedData = Tx.deserializeData(
  serializedData,
  TxCategory.INIT_DID
);

Parameters:

| Parameter | Type | Default | Description | | ---------- | ------------ | ------- | -------------------------------------------------- | | txData | Uint8Array | - | Serialized transaction payload | | category | TxCategory | - | Transaction category supported for Deserialization |

* - Optional