You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@pushprotocol/push-chain

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pushprotocol/push-chain

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.

0.1.7
latest
npmnpm
Version published
Maintainers
0
Created
Source

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

ParamTypeDefaultRemarks
env *ENVstagingAPI 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:

ParameterTypeDefaultDescription
startTime *numberCurrent Local TimeA number represting current time epoch
direction*ASC DESCASCA string represting direction in which blocks are fetched
showDetails*booleanfalseA boolean represting whether tx Data shoudl be fetched or not
page*number1A number representing the page of results to retrieve.
pageSize*number30A 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:

ParameterTypeDefaultDescription
blockHashstring-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:

ParameterTypeDefaultDescription
tsnumber-Block timestamp
txObjobject[]-Block Transactions
signersobject[]-Block Signers
attestTokenUint8Array-Block Attestation Token

* - Optional

Deserialize Block

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

Parameters:

ParameterTypeDefaultDescription
blockUint8Array-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:

ParameterTypeDefaultDescription
startTime *numberCurrent Local TimeA number represting current time epoch
direction*ASC DESCASCA string represting direction in which transactions are fetched
page*number1A number representing the page of results to retrieve.
pageSize*number30A 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:

ParameterTypeDefaultDescription
txHashstring-An string represting transaction hash

* - Optional

Create Unsigned Transaction

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

Parameters:

ParameterTypeDefaultDescription
categorystring-Transaction category
recipientsstring[]-Array of recipient addresses
dataUint8Array-Serialized transaction payload data

* - Optional

Send Transaction

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

Parameters:

ParameterTypeDefaultDescription
unsignedTxTransaction-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:

ParameterTypeDefaultDescription
txTransaction-Transaction object

* - Optional

Deserialize Transaction

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

Parameters:

ParameterTypeDefaultDescription
txUint8Array-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:

ParameterTypeDefaultDescription
txDataInitDid | InitSessionKey Tx-Transaction payload data object
categoryTxCategory-Transaction category

* - Optional

Deserialize Transaction Payload Data

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

Parameters:

ParameterTypeDefaultDescription
txDataUint8Array-Serialized transaction payload
categoryTxCategory-Transaction category supported for Deserialization

* - Optional

FAQs

Package last updated on 29 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts