BITE API
This section provides detailed technical documentation for BITE’s APIs, both off-chain (TypeScript SDK) and on-chain (Solidity helpers).Off-Chain API (bite-ts)
The@skalenetwork/bite TypeScript library provides methods for encrypting data before submitting to the blockchain.
new BITE(endpoint: string)
Creates a new BITE instance configured with a JSON-RPC endpoint.
Parameters:
endpoint: string– The BITE URL provider (JSON-RPC endpoint)
bite.encryptTransaction(tx)
Encrypts a transaction using BLS threshold encryption. The encrypted transaction will have its to field set to the BITE magic address.
Parameters:
tx: object– Transaction object withdataandtofields as hex strings
Promise<Transaction>– Encrypted transaction with modifieddataandtofields
- RLP encodes original
dataandtofields - Encrypts encoded data using AES with randomly generated key
- Encrypts AES key using BLS threshold encryption
- Creates final payload:
[EPOCH_ID, ENCRYPTED_BITE_DATA]
- Single Committee: AES key encrypted with current BLS public key
- Dual Committee: During rotation, AES key encrypted twice (current + next committee keys)
BITE.encryptTransactionWithCommitteeInfo(tx, committees)
Static method that encrypts using provided committee info, avoiding internal RPC call.
Parameters:
tx: object– Transaction withdataandtofieldscommittees: Array– Committee info objects (fromgetCommitteesInfo)
Promise<Transaction>– Encrypted transaction
bite.encryptMessage(message)
Encrypts a raw hex-encoded message using BLS threshold encryption.
Parameters:
message: string– Hex string to encrypt (with/without0xprefix)
Promise<string>– Encrypted hex string in RLP format with epoch and encryption data
bite.getDecryptedTransactionData(transactionHash)
Retrieves decrypted transaction data after consensus finality using bite_getDecryptedTransactionData JSON-RPC method.
Parameters:
transactionHash: string– The transaction hash
Promise<object>– JSON withdataandtokeys containing original decrypted fields
bite.getCommitteesInfo()
Fetches committee information using bite_getCommitteesInfo JSON-RPC method.
Returns:
Promise<Array>– Array of 1-2 committee objects:commonBLSPublicKey: string– 256-char hex (128-byte BLS public key)epochId: number– Epoch identifier
- 1 element: Normal operation (single active committee)
- 2 elements: Committee rotation period (scheduled for next 3 minutes)
On-Chain API (bite-solidity)
The@skalenetwork/bite-solidity library provides Solidity helpers for creating Conditional Transactions (CTX) that request decryption from within smart contracts.
Installation
Import
BITE.submitCTX(address, gasLimit, encryptedArgs, plaintextArgs)
Creates a Conditional Transaction for decryption.
Parameters:
address: CTX handler address (useBITE.SUBMIT_CTX_ADDRESS)gasLimit: Gas for callback (in gas units, e.g.,msg.value / tx.gasprice)encryptedArgs: Array of encrypted bytes to decryptplaintextArgs: Array of unencrypted bytes to pass through
address – The CTX supplicant address that will call onDecrypt()
IBiteSupplicant.onDecrypt(decryptedArgs, plaintextArgs)
Callback that your contract must implement. Called by SKALE consensus with decrypted data.
Parameters:
decryptedArgs: Array of decrypted byte arraysplaintextArgs: Array of plaintext byte arrays (passed through)
Transaction Structure
BITE Encrypted Transaction Format
BITE transactions modify standard Ethereum transaction structure:Encryption Payload Structure
The encrypteddata field contains RLP-encoded array:
EPOCH_ID: Current committee epochENCRYPTED_BITE_DATA: Contains the encrypted transaction data (AES-encrypted payload with BLS-encrypted AES key)
Important: Gas Limit Requirement When passing a transaction tobite.ts, you must setgasLimitmanually.estimateGasdoes not return proper values for encrypted transactions. IfgasLimitis omitted,bite.tswill automatically set it to 300000.
