SDK
Currently, only the Ethereum Holesky testnet and AO are supported, with plans to gradually expand support to the Ethereum mainnet and other networks in the future.
Overview
The bavo-network-sdk allows developers to utilize BAVO Network, providing trustless and confidential computing capabilities. For more information, visit the Introduction.
Quick Start
Demos
Usage
Installation
Install the package using npm:
bashCopy codenpm install --save @bavolabs/bavo-network-sdkImport WASM
Add lhe.js to your HTML file to automatically load the WASM:
htmlCopy code<script type="text/javascript" src="https://bavo-online.s3.ap-northeast-1.amazonaws.com/resources/v2/lhe.js"></script>If you encounter this browser console error:
vbnetCopy code_stream_writable.js:57 Uncaught ReferenceError: process is not defined
at node_modules/readable-stream/lib/_stream_writable.js (_stream_writable.js:57:18)Refer to the project documentation using vite.
Getting Started
Utils
Generate Key Generate public-private key pairs to submit tasks and retrieve task results:
javascriptCopy codeimport { Utils } from "@bavolabs/bavo-network-sdk";
// Generate key pair for submitTask() and getTaskResult()
const keyInfo = await new Utils().generateKey();BavoNetworkContractClient
Import Client
javascriptCopy codeimport { BavoNetworkContractClient } from '@bavolabs/bavo-network-sdk';Instantiate Client
The constructor for BavoNetworkContractClient:
javascriptCopy codeconstructor(chainName: ChainName, wallet: any, storageType: StorageType = StorageType.ARSEEDING);chainName: The blockchain to connect to.
wallet: The wallet used for blockchain interactions.
storageType: Optional. Defaults to
ARSEEDING.
By default, storageType is set to ARWEAVE for ao and ARSEEDING for holesky or ethereum.
If using ARSEEDING, deposit ETH to EverPay to cover storage and computation costs.
Example
javascriptCopy codeconst chainName = 'holesky';
const storageType = StorageType.ARSEEDING;
const wallet = window.ethereum;
const bavoNetworkClient = new BavoNetworkContractClient(chainName, wallet, storageType);Upload Data
Upload data to the storage chain:
javascriptCopy codeuploadData(data: Uint8Array, dataTag: CommonObject, priceInfo: PriceInfo, permissionCheckers?: string[], encryptionSchema?: EncryptionSchema): Promise<string>;Example
javascriptCopy codeconst data = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
const dataTag = { 'filename': 'testFileName' };
const priceInfo = { price: '200000000', symbol: 'wAR' };
const dataId = await bavoNetworkClient.uploadData(data, dataTag, priceInfo);Submit Task
Submit a task to BAVO Network:
javascriptCopy codesubmitTask(taskType: TaskType, dataId: string, dataUserPk: string): Promise<string>;Example
javascriptCopy codeconst taskId = await bavoNetworkClient.submitTask(TaskType.DATA_SHARING, userDataId, keyInfo.pk);Get Task Result
Retrieve the result of a task:
javascriptCopy codegetTaskResult(taskId: string, dataUserSk: string, timeout?: number): Promise<Uint8Array>;Example
javascriptCopy codeconst data = await bavoNetworkClient.getTaskResult(taskId, keyInfo.sk, 20000);Get Balance and Withdraw Tokens
Get Balance:
javascriptCopy codeconst balance = await bavoNetworkClient.getBalance(address, 'ETH');Withdraw Tokens:
javascriptCopy codeconst transaction = await bavoNetworkClient.withdrawToken(address, 'ETH', amount);Types and Enums
KeyInfo
typescriptCopy codetype KeyInfo = {
pk: string; // public key
sk: string; // private key
};ChainName
typescriptCopy codetype ChainName = 'ao' | 'holesky' | 'ethereum';StorageType
typescriptCopy codeenum StorageType {
ARWEAVE = "arweave",
ARSEEDING = "arseeding"
}TaskType
typescriptCopy codeenum TaskType {
DATA_SHARING = 'dataSharing'
}Solidity: IDataPermission
Developers can implement the IDataPermission contract to define custom permission-checking logic for data access:
solidityCopy codeinterface IDataPermission {
function isPermitted(address dataUser) external returns (bool);
}You can find a whitelist example in WhiteListDataPermission.
Last updated