Code Monkey home page Code Monkey logo

superfluid-stream-gated-jwt's Introduction

Superfluid Stream Gating

Streamline your content access with Superfluid Stream Gating.

About Superfluid:

Superfluid is a revolutionary asset streaming protocol that brings subscriptions, salaries, vesting, and rewards to DAOs and crypto-native businesses worldwide - https://www.superfluid.finance/

Problem Statement:

sfsg-idea

Solution Overview:

This project tried to implement superfluid streams gating mechanism as mentioned in the problem statement by providing a serverless function that generates JWTs on-demand for authorized users. This function is built using the Netlify/AWS Lambda serverless architecture and is written in Node.js. It requires a list of authorized API keys and a secret key to generate JWT tokens. When a user sends a request to the function with a valid API key, it uses the Superfluid protocol subgraph to check if a stream exists for the specified sender, receiver, and token. If a stream exists with active flow rate, it generates a JWT token using the secret key and either returns the token and redirect URL or redirects the user to the protected resource with the token appended as a query parameter.

Deployment

To deploy the Superfluid Stream Gating serverless function, you need to have a Netlify account. Follow these steps to deploy the function:

Deploy to Netlify

Click the button above to deploy the function to your Netlify account. Follow the instructions to deploy your function.

Once the function is deployed, you need to update the following environment variables. You can do this by going to the Site settings tab of your Netlify site and clicking on Environment Variables > Select a variable > Options > Edit.

JWT_SECRET=
APP_URL=
SUBGRAPH_URL=
WHITELISTED_API_KEYS=api_key_1,api_key_2,api_key_3

After updating the environment variables, you can access the function endpoint by going to the Functions tab of your Netlify site and clicking on the superfluid-stream-gating function.

Usage

To use the Superfluid Stream Gating function superfluid-stream-gating.js, you need to make a POST request to the deployed function endpoint with the following parameters in the request body:

sender: the Ethereum address of the sender of the stream

receiver: the Ethereum address of the receiver of the stream

token: the Ethereum address of the token being streamed

chain (optional): The Ethereum network where the stream is taking place. Defaults to goerli if not provided. Possible values: goerli, mumbai, matic

Note: This project uses subgraph to verify the existence of the stream before authenticating access. You can specify chain in request body to use the subgraph of the specified chain. The supported chains are goerli, mumbai, matic. If no chain is specified, the function will use the goerli subgraph by default.

x-api-key: the API key in the request header

Here is an example curl command for making a request:

curl -X POST https://superfluid-stream-gating.netlify.app/.netlify/functions/superfluid-stream-gating \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: zaLcG9' \
  -d '{
    "chain": "goerli",
    "sender": "0xc7203561ef179333005a9b81215092413ab86ae9",
    "receiver": "0x7348943c8d263ea253c0541656c36b88becd77b9",
    "token": "0xf2d68898557ccb2cf4c10c3ef2b034b2a69dad00"
  }'

Roadmap:

  • Create a standalone npm package for the Superfluid stream gating function with in-built token verfication functionality. Check out the package super-jwt
  • Add more example integrations with various app frameworks such as React, Nextjs, Nodejs(Server-side).
  • Add support for more Ethereum networks and improve error handling

Credits & Resources:

License

This project is licensed under the MIT License - see the LICENSE file for details

superfluid-stream-gated-jwt's People

Contributors

salmandabbakuti avatar vikpande avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.