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

opensea-submarine

v0.1.1

Published

🏴‍☠️ 🧸 Enabling subversive transactions with OpenSea's GraphQL backend using Express middleware.

Downloads

4

Readme

opensea-submarine

watch me breakdown

OpenSea is the world's foremost NFT marketplace which takes great care to protect its API from abuse by ETH-hungry robots who are desperate to discover profit opportunities the fastest.

OpenSea makes this task difficult in a number of ways:

  • Any request to the backend must be precisely-defined to satisfy strong CloudFlare protection.
  • Robust client-side session management and adherence imposes additional complexity during request formation which dramatically complicates attempts to programmatically fetch the API.
  • The backend enforces that the structure of an individual request must resolve to a known checksum.

If that wasn't enough, the successfully returned contents of pages rendered by OpenSea's SPA are highly obfuscated to make the task of manual scraping slow, unreliable and limited in scalability.

By using a stealthy flavour of Puppeteer, this repository demonstrates that a user can hijack client-side GraphQL requests and repurpose them for custom queries. This enables the client to squat on the complex trusted setup and abstract away request complexity.

🚀 getting started

Using Yarn:

yarn add opensea-submarine

✏️ usage

This package exports an Express middleware which emulates a conventional GraphQL interface. GraphQL requests captured by the middleware are validated, sanitized and curried over into OpenSea's backend via request-squatting:

import cors from 'cors';
import express from 'express';
import axios from 'axios';

import {proxyMiddleware} from 'opensea-submarine';

const openSeaEnvironment = {
  graphQLUri: 'https://opensea.io/__api/graphql/',
  eventHistoryUri: 'https://opensea.io/collection/boredapeyachtclub?tab=activity',
  privacyUri: 'https://opensea.io/privacy',
};

const proxyContext = await createProxyContext(openSeaEnvironment);

const server = await new Promise<Server>(
  async resolve => {
    const server = express()
      .use(cors())
      .use(await proxyMiddleware({
        debug: true,
        proxyContext,
      }))
      .listen(3000, () => resolve(server));
  },
);

Then you're free to query the middleware using queries that are recognized by OpenSea:

import axios from 'axios';

const {data} = await axios({
  url: 'http://localhost:3000/graphql',
  method: 'post',
  data: {"query":"query useIsEditableQuery(\n  $collection: CollectionSlug!\n) {\n  collection(collection: $collection) {\n    isEditable\n    id\n  }\n}\n","variables":{"collection": "boredapeyachtclub"}},
});

// {"collection":{"isEditable":false,"id":"Q29sbGVjdGlvblR5cGU6NDg4NjIx"}}

You can check out the examples for additional insight.

Developers are reminded that the query content and x-signed-query header must be identical to real graphql/ requests sourced from OpenSea, which can be found in your browser's Networking tab.

By contrast, request variables are permitted to change freely.

✌️ license

MIT