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

@switchboard-xyz/function-simulator

v1.0.2

Published

type definitions for using the Switchboard function simulator

Downloads

17

Readme

Switchboard Logo

Switchboard Function Simulator

A server run within a secure enclave to help debug Switchboard Functions.

Environment Variables

| Variable | Definition | | ---------------------- | ------------------------------------------------------------------------- | | PORT | The network port to use for the websocket. Defaults to 8080 | | SOLANA_MAINNET_RPC_URL | Solana mainnet RPC URL. Defaults to https://api.mainnet-beta.solana.com | | SOLANA_DEVNET_RPC_URL | Solana devnet RPC URL. Defaults to https://api.devnet.solana.com |

Usage

Once the server is running, start sending data like so:

import WebSocket from "ws";
import * as sb from "@switchboard-xyz/function-simulator";

async function main() {
  const ws = new WebSocket(sb.SIMULATION_SERVER_URL);

  const message: sb.MsgInEcho = {
    event: "echo",
    data: {
      message: "echo this message back to me",
    },
  };

  ws.onopen = (event) => {
    console.log(`sending echo`);
    ws.send(JSON.stringify(message));
  };

  ws.onmessage = (event) => {
    const msg = JSON.parse(event.data.toString("utf-8"));
    console.log("received msg", msg);
    process.exit(0);
  };
}

Message Types

container_verify

Verify a container can be pulled and created.

{
  "event": "containerVerify",
  "data": {
    "container": "switchboardlabs/binance-oracle"
  }
}

measurement

Retrieve the measurement of a given image on dockerhub.

{
  "event": "measurement",
  "data": {
    "containerRegistry": "dockerhub",
    "container": "switchboardlabs/binance-oracle",
    "version": "latest"
  }
}

solana_simulate

Simulate a Solana function with a given set of inputs and stream the container logs to the websocket client.

{
  "event": "solanaSimulate",
  "data": {
    "fnKey": "YOUR_FUNCTION_PUBKEY",
    "cluster": "Devnet",
    "params": {
      // override values
      "containerRegistry": "dockerhub",
      "container": "switchboardlabs/binance-oracle",
      "version": "latest",
      "fnData": "", // hex encoded FunctionAccountData
      "fnRequestKey": "", // pubkey
      "fnRequestData": "", // hex encoded FunctionRequestAccountData
      "payer": "", // pubkey
      "verifier": "", // pubkey
      "rewardReceiver": "" // pubkey
    }
  }
}

Azure Deployment

The secrets server needs to run within a secure enclave. Currently only Microsoft Azure is supported in the docs.

Install the Azure CLI. See the Official Docs - How to install Azure CLI.

# Ubuntu
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash

# Mac OS
brew update && brew install azure-cli

Login

az login

Run the following to create a cluster named function-simulator in uksouth, enable the confidential compute plugin, create a static IP address and assign it to the cluster.

az group create --name Default --location uksouth

az aks create --name function-simulator \
    --resource-group Default \
    --node-vm-size Standard_DC2s_v3 \
    --generate-ssh-keys

az aks enable-addons --addons confcom --name function-simulator --resource-group Default

az network public-ip create --name function-simulator-ip --sku Standard \
  --allocation-method Static \
  --resource-group $(az aks show --resource-group Default --name function-simulator --query nodeResourceGroup -o tsv)

az aks update --name function-simulator \
    --resource-group Default \
    --load-balancer-managed-outbound-ip-count 0 \
    --load-balancer-outbound-ips $(az network public-ip show --resource-group Default --query id --output tsv)

Installing networking stack

helm repo add jetstack https://charts.jetstack.io
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update

az aks get-credentials -g Default -n sb-internal

helm install \
  cert-manager jetstack/cert-manager \
  --namespace cert-manager \
  --create-namespace \
  --version v1.9.1 \
  --set installCRDs=true \
  --set global.leaderElection.namespace=cert-manager

helm install ingress-nginx ingress-nginx/ingress-nginx \
  --namespace ingress-nginx \
  --create-namespace \
  --timeout 600s \
  --debug \
  -f nginx-values.yaml