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

@vennbuild/venn-dapp-sdk

v0.8.5

Published

SDK for interactions with Venn Network

Downloads

70

Readme

Venn DApp SDK

NPM Version TypeScript Jest ESLint
Discord X License

SDK for easy DApp integrations with Venn Security Network

👉 What is Venn?

Table of Contents

🚀 Quick Start

Follow these steps to protect your DApp with Venn:

  1. Install the SDK in your project:

    npm i @vennbuild/venn-dapp-sdk
  2. Instantiate a new VennClient:

    import { VennClient } from '@vennbuild/venn-dapp-sdk';
    
    const vennURL           = process.env.VENN_NODE_URL;
    const vennPolicyAddress = process.env.VENN_POLICY_ADDRESS;
    
    const vennClient = new VennClient({ vennURL, vennPolicyAddress });
  3. Approve your users transactions with Venn:

    const approvedTransaction = await vennClient.approve({
        from,
        to,
        data,
        value
    });
  4. Finally, send the approved transaction onchain as your DApp normally would

    const receipt = await wallet.sendTransaction(approvedTransaction);

📦 Installation

Prerequisites

Install

npm install @vennbuild/venn-dapp-sdk

📚 Usage

Use this SDK to easily integrate your DApp with Venn.
First, make sure you have integrated your smart contracts with the Firewall SDK, and that you have your Venn Policy address readily available.

Approving Transactions

Once your smart contracts protected by Venn, only approved transactions will be allowed to go through. Transactions that are not approved will be reverted onchain.

This SDK will ensure your DApp's Frontend approves transactions with Venn before sending them onchain.

Venn Client

The VennClient is your DApp's entry point for interacting with Venn.
It provides a simple transaction approval interface that seamlessly integrates with your existing DApp's code:

import { VennClient } from '@ironblocks/venn-dapp-sdk';

const vennURL           = process.env.VENN_NODE_URL;
const vennPolicyAddress = process.env.VENN_POLICY_ADDRESS;

const vennClient = new VennClient({ vennURL, vennPolicyAddress });
const approvedTx = await vennClient.approve({ from, to, data, value });

The approved transactions has the same to, from, and value, with an updated data field that now includes a secure signature that will allow the transaction to go through the onchain Firewall

console.log(approvedTx);

/**
 * {
 *      from: original from
 *      to: original to
 *      data: <SECURE SIGNATURE + ORIGINAL DATA> (hex string)
 *      value: original value
 * }

Security Nodes

Venn protects your protocol by leveraging collective intelligence of multiple security node operators, all at once, in real time.

When the VennClient approves a transaction, it takes the original user transaction (in the form of { from, to, data, value }) and sends it to any one of it's security nodes for inspection.

The security nodes propagate the transaction to all nodes on the network via P2P, and responds back with a signed transaction (in the form of { from, to, data, value }) that your DApp can now submit onchain.

Strict Mode

By default, the SDK runs with strict mode enabled.

Enabled

In strict mode, if an error occurs while trying to approve the transaction, or if the transaction was not approved by Venn - the SDK will throw an error.

Your DApp will need to handle this gracefully handle this error:

The signed transactions has the same to, from, and value, with an updated data field that now includes a secure signature that will allow the transaction to go through the onchain Firewall

import { errors } from '@ironblocks/venn-dapp-sdk'

try {
    const approvedTx = await vennClient.approve({
        from,
        to,
        data,
        value
    });
}
catch (e) {
    // handle errors and unapproved transactions
    //
    // for example, alert the user that the transaction did not pass security checks etc

    if (!(e instanceof Error)) return alert(e)

    switch(error.constructor) {
        case errors.InvalidInitParamsError:
            return alert(`Invalid params: ${error.message}`)
        case errors.ConnectionRefused:
            return alert(`Network error: ${error.message}`)
        case errors.TxRejectedError:
            return alert(`Venn Error: Tx Not Approved: ${error.message}`)
        default:
            return alert('Something wrong...')
    }
}

Disabled

When strict mode is disabled, the SDK will gracefully handle any errors internally - including ignoring unapproved transactions.

⚠️
IMPORTANT: While it may make sense for certain DApps to disable strict mode, we strongly encourage you to keep strict mode enabled

⚙️ Configuration

  • vennURL: string
    the Venn security node to connect the client to

  • vennPolicyAddress: string
    the address of your Venn Policy

  • strict: boolean
    whether or not to enable strict mode (default: true)

💬 Support & Documentation

We're here to help.

📜 License

Venn DApp SDK is released under the MIT License.

This SDK demonstrates how to integrate DApps with Venn Network together with Ironblocks Firewall