Switchboard commit-reveal randomness. This account type controls commit-reveal style randomness employing Intel SGX enclaves as a randomness security mechanism. For this flow, a user must commit to a future slot that would be unknown to all parties at the time of commitment. The user must then reveal the randomness by then sending the future slot hash to the oracle which can then be signed by the secret key secured within the Trusted Execution Environment.

In this manner, the only way for one to predict the randomness is to:

  1. Have access to the randomness oracle
  2. have control of the solana network slot leader at the time of commit
  3. Have an unpatched Intel SGX vulnerability/advisory that the Switchboard protocol failed to auto-prune.

Constructors

Properties

program: Program<Idl>

The Anchor program instance.

pubkey: PublicKey

The public key of the randomness account.

Methods

  • Commit and reveal randomness in a single transaction.

    Parameters

    • callback: TransactionInstruction[]

      The callback to execute after the reveal in the same transaction.

    • signers: Keypair[]

      The signers to sign the transaction.

    • queue: PublicKey

      The queue public key.

    • Optional configs: {
          computeUnitLimit?: number;
          computeUnitPrice?: number;
      }

      The configuration options.

      • Optional computeUnitLimit?: number

        The compute unit limit.

      • Optional computeUnitPrice?: number

        The price per compute unit in microlamports.

    Returns Promise<void>

    A promise that resolves when the transaction is confirmed.

  • Generate a randomness commit solana transaction instruction. This will commit the randomness account to use currentSlot + 1 slothash as the non-repeating randomness seed.

    Parameters

    • queue: PublicKey

      The queue public key for the commit instruction.

    • Optional authority_: PublicKey

      The optional authority public key.

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction.

  • Loads the randomness data for this Randomness account from on chain.

    Returns Promise<any>

    A promise that resolves to the randomness data.

    Throws

    Will throw an error if the randomness account does not exist.

  • Generate a randomness reveal solana transaction instruction. This will reveal the randomness using the assigned oracle.

    Returns Promise<TransactionInstruction>

    A promise that resolves to the transaction instruction.

  • Serialize ix to file.

    Parameters

    • revealIxs: TransactionInstruction[]

      The reveal instruction of a transaction.

    • Optional fileName: string = "serializedIx.bin"

      The name of the file to save the serialized IX to.

    Returns Promise<void>

    A promise that resolves when the file has been written.

    Throws

    Will throw an error if the request fails.

  • Creates a new Randomness account.

    Parameters

    • program: Program<Idl>

      The Anchor program instance.

    • kp: Keypair

      The keypair of the new Randomness account.

    • queue: PublicKey

      The queue account to associate with the new Randomness account.

    • Optional payer_: PublicKey

      The payer for the transaction. If not provided, the default payer from the program provider is used.

    Returns Promise<[Randomness, TransactionInstruction]>

    A promise that resolves to a tuple containing the new Randomness account and the transaction instruction.

  • Creates a new Randomness account and prepares a commit transaction instruction.

    Parameters

    • program: Program<Idl>

      The Anchor program instance.

    • queue: PublicKey

      The queue account to associate with the new Randomness account.

    Returns Promise<[Randomness, Keypair, TransactionInstruction[]]>

    A promise that resolves to a tuple containing the new Randomness instance, the keypair, and an array of transaction instructions.