🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@switchboard-xyz/function-simulator

Package Overview
Dependencies
Maintainers
6
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@switchboard-xyz/function-simulator

type definitions for using the Switchboard function simulator

unpublished
latest
npmnpm
Version
1.0.2
Version published
Maintainers
6
Created
Source

Switchboard Logo

Switchboard Function Simulator

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

Environment Variables

VariableDefinition
PORTThe network port to use for the websocket. Defaults to 8080
SOLANA_MAINNET_RPC_URLSolana mainnet RPC URL. Defaults to https://api.mainnet-beta.solana.com
SOLANA_DEVNET_RPC_URLSolana 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

FAQs

Package last updated on 27 Sep 2023

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