Skip to main content

Quick Access

Check out private transfer example:

GitHub

Anchor Implementation

dApp (Coming soon!)

Play Now

Client Implementation

Frontends interface with the Private Ephemeral Rollup (PER) using two concepts: Authorization and Permissions
  • Authorization: Verify RPC integrity, request authorization token and create connection.
  • Permissions: Manage permissions from the client and define members with fine-grained access to permissioned accounts.

Authorization

  1. Verify the TEE RPC server runs on genuine Intel TDX hardware using its TDX quote and Intel-issued attestation certificates
  2. Request and sign challenge to receive an authorization token
  3. Create connection by passing the authorization token inside header or as query parameter
import {
  verifyTeeRpcIntegrity,
  getAuthToken,
} from "@magicblock-labs/ephemeral-rollups-sdk";

// if not using wallet:
// import * as nacl from "tweetnacl";

const teeUrl = "https://tee.magicblock.app";
const teeWsUrl = "wss://tee.magicblock.app";

// 1. Verify the integrity of TEE RPC
const isVerified = await verifyTeeRpcIntegrity(teeUrl);

// 2. Get AuthToken before making request to TEE
const token = await getAuthToken(
  teeUrl,
  wallet.publicKey,
  signMessage
  // if not using wallet:
  // (message: Uint8Array) =>
  //  Promise.resolve(nacl.sign.detached(message, wallet.secretKey))
);

// 3. Create connection with TEE
const connection = new web3.Connection(`${teeUrl}?token=${authToken.token}`, {
  wsEndpoint: `${teeWsUrl}?token=${authToken.token}`,
});

Permissions

Create permissions on Solana, manage and enforce them in the Private Ephemeral Rollup through delegation:
Create permission for account through CPI call to Permission Program:
web3js
import {
  Member,
  createCreatePermissionInstruction,
} from "@magicblock-labs/ephemeral-rollups-sdk";

// Define members
let members: Member[] | null = [
  {
    flags: AUTHORITY_FLAG | TX_LOGS_FLAG,
    pubkey: payer.publicKey,
  },
  {
    flags: TX_LOGS_FLAG,
    pubkey: user2.publicKey,
  },
];

// Build the instruction
const createPermissionIx = createCreatePermissionInstruction(
  {
    permissionedAccount: permissionedAccount.publicKey,
    payer: payer.publicKey,
  },
  {
    members,
  }
);

// Create a transaction
const tx = new Transaction().add(createPermissionIx);

// Send the transaction
const txSig = await sendAndConfirmTransaction(connection, tx, [payer]);
console.log("TX:", txSig);
⬆️ Back to Top
Private Ephemeral Rollup (devnet) endpoint: https://tee.magicblock.app/