Getting Started
Today, we will review the implementation of Switchboard Secrets within your oracle feed! We recommend setting up a simple feed first by following the Developers: Build and Use! page first before attempting to embed a secret in your feed! Switchboard-Secrets is designed for maximum speed, security, and simplicity. Switchboard offers both a Rust and TypeScript SDK for initializing your feed object as well as embedding and retrieving secrets. You may get started with the JavaScript/TypeScript SDKs via:
npm i @switchboard-xyz/on-demand @switchboard-xyz/common
Using these SDK's you can design your data feed to securely embed and use secrets just like your regular Switchboard on-demand data feeds. If you are looking for a more non-technical UI based approach, Switchboard has a dedicated UI builder to create and manage your secrets here!
Step 1: Set Up Your Environment:
Install the required packages.
Initialize your environment variables and key pairs.
Step 2: Create the User Profile and Secret
To embed a secret you will need to setup a user profile and add your secret to the user profile.You can create a user profile like this.
The function sbSecrets.createOrUpdateUserRequest
takes in 3 parameters:
1.
userPubkey
(string
): The public key address of the user.2.
ciphersuite
(string
): Specifies the cryptographic suite used for signing. For Solana, use"ed25519"
, for EVM, use"ethers"
.3.
contactInfo
(string
): This optional field can be used to store stringified contact information, such as an email address or other contact details. Can be left empty""
.
Once created, you can query your user profile like this!
Right, now to add your secret to your user profile..
The function sbSecrets.createSecretRequest
takes in 4 parameters:
userPubkey
(string
): The public key address of the user.ciphersuite
(string
): Specifies the cryptographic suite used for signing. For Solana, use"ed25519"
, for EVM, use"ethers"
.secretName
(string
): Key of the secret, must be unique per user profile.secretValue
(string
): Value of the secret.
Step 3: Create Your Feed
Using the SDK, you can now design your data feed just like your Switchboard-v2 data feeds but now using an embedded secret. Note - due to variable expansion, make sure that the name of your embedded secret in your feed is passed in correctly.
The job definition above does three things.
Invokes a secrets task to fetch the secret to embed in the
httpTask.
Fetching the weather REST service from openweathermap.org for the temperature in Aspen.
Using JSONPATH syntax to parse out the temperature field
Now lets finish creating the feed below and initializing it!
For a more detailed description of configuring your feed visit this page -
Step 4: Whitelist your Feed to your Secret
As an added safety measure, you are required to whitelist your feed to your secret. This is accomplished by obtaining the hash of your feed and whitelisting it ot the secret! Here we go..
The function sbSecrets.createAddMrEnclaveRequest
takes in 4 parameters:
userPubkey
(string
): The public key address of the user.ciphersuite
(string
): Specifies the cryptographic suite used for signing. For Solana, use"ed25519"
, for EVM, use"ethers"
.secretNames
(string[]
): The names of the secrets to whitelist the MrEnclave value for.
Step 5: Fire away!
After the feed has been initialized, we can now request temperature signatures from oracles!
And just like that, you've got Switchboard secured data on chain with embedded secrets!
Last updated