Database Encryption
Data in Verida is encrypted when it is sent to remote servers. You can inspect the local and remote database and see the unencrypted local data and the remote encrypted payload.
See a walk through of the code
Data Encryption is part of our data storage tutorial video.
Try it out
Live Editor
VeridaEncryptionExample = () => {const [veridaContext, setVeridaContext] = useState(undefined)const [localData, setLocalData] = useState("")const [remoteData, setRemoteData] = useState("")this.CONTEXT_NAME = "Verida Tutorial"React.useEffect(async () => {// See the login example for an explaination of thisif (!veridaContext) {if (hasSession(this.CONTEXT_NAME)) {// we know we have a session already// globalLoginFunction is a globally defined version of the login function// See https://developers.verida.io/docs/tutorial/SSOlet ctx = await globalLoginFunction(this.CONTEXT_NAME);Window.ctx = ctxsetVeridaContext(ctx);}}if (Window.db === undefined) {openDatabase();}}, []);openDatabase = async function () {// veridaContext will be undefined if the user isn't logged inif (veridaContext !== undefined && !Window.db) {// Open / create a test databaseWindow.db = await veridaContext.openDatabase("test_db");return true} else {// This method shouldn't be called if no one is logged inconsole.log("veridaContext is null. This means no one has logged in")return false;}}showLocal = async function () {const items = await Window.db.getMany(null, null) // get the database itemsconst last_item = items.slice(-1)[0] // find the last item in the listdata = await Window.db.get(last_item._id) // get the recordconsole.log("Local data", data)setLocalData(data)}showRemote = async function () {const items = await Window.db.getMany(null, null) // get the database itemsconst last_item = items.slice(-1)[0] // find the last item in the listconst remoteDb = await Window.db.getRemoteEncrypted()data = await remoteDb.get(last_item._id) // get the recordconsole.log("Remote data", data)setRemoteData(data)}displayData = function (data) {if (data === "") {return <div></div>}return (<div><textarearows="7"cols="80"defaultValue={JSON.stringify(data, null, 2)}></textarea></div>)}localDataDisplay = displayData(localData)remoteDataDisplay = displayData(remoteData)// if we have a veridaContext we are logged inif (veridaContext) {return (<div><button onClick={this.showLocal}>Show Local Data</button>{localDataDisplay}<div>Note the fields <b>myvalue, insertedAt, modifiedAt</b> are unencrypted</div><button onClick={this.showRemote}>Show Remote Data</button>{remoteDataDisplay}<div>Note the fields all data fields are encrypted</div></div>)} else {return (<div className="admonition admonition-danger alert alert--danger"><h2>Please login <a href="/docs/tutorial/SSO#runcode">here</a></h2></div>)}}
Result
Loading...
Database documentation
See the Verida Database documentation for complete documentation.