Building Web3 Apps with Composable Data - Joel Thorstensson

web3con 2022 · 5 Mar 2022 · 15:40

Joel Thorstensson, co-founder and CTO of the team behind Ceramic, explains how web3 apps can share user data the way smart contracts share logic. He describes Ceramic data models as a shared table of the internet where each user controls their own row, session keys and Sign-In with Ethereum capabilities that avoid signing every update, and self-certifying event streams anchored to a blockchain. The result is composable data and shared network effects across apps without centralized databases.

Speakers

Topics

From web3con 2022, hosted by Developer DAO.

Transcript

this talk is sponsored by polygon polygon is a leading platform for ethereum scaling and infrastructure development its growing suite of products enables developers to build scalable user-friendly dapps with low transaction fees without ever sacrificing on security learn more at polygon.technology hi everyone thanks for having me at web recon i'm joe i'm the cto and co-founder of drevox labs and i've been the leading architect behind ceramic so today i'm going to tell you about how to build web3 apps with composable data so on-chain data as probably most of you know is composable so if you have like a

layer one blockchain that you can deploy smart contracts on this blockchain and anyone can use these contracts so in this example you see here there are two smart contracts and there are three different apps using them so maybe app a created the first smart contract fc created the other one and now a b actually connects to both of these smart contracts and does something completely new for the user so this kind of concept of composability is really powerful and really gives both developers and user kind of a lot of new things that haven't really been possible before but there's a problem on-chain data

is really kind of only or mostly useful for kind of financial things and a lot of applications are not financial if you think about a social network most of the things you do on there like writing posts making comments is inherently non-financial and if we look at kind of what web3 apps have been doing today has been like allowing users to kind of log in and they store data about their users in a centralized database so juicer data isn't really composable yet because now if application a were to disappear uh or application a still exists but application b wants to like

leverage the the user and the growth of application a uh they can use the smart contract but it can't really like learn anything else about the users and the users can't really just like bring their data to the other application and so so far in web3 this has kind of been a problem because we don't really want to end up in kind of the same situation where have these big uh corporations that own and control a lot of the data and actually use this to extract a lot of value from users without kind of without their consent um and so that's kind of what we set out to solve with ceramic so ceramics uh ceramic brings composability to user data and so in the

same way like an l1 blockchain has smart contracts that can interoperate ceramic has data models and these data models can be accessed by multiple applications and the data that's put into ceramic is kind of written to this global namespace where application a and application c might have two different data models but application b can actually read and write to both of these data models and have the kind of same type of composability that you get between smart contracts so this is really powerful and something really new um but one problem though you might think is so on an ll1 blockchain i need to like sign

a transaction with each wallet and do i now also like need to sign every transaction uh when i make a comment when i make a post um in in some kind of social media system or if i'm like drafting a proposal for a dao and like i want to make a small typo edit well because in ceramic everything is kind of cryptographically verifiable so they can actually live on this public network but signing a transaction for each thing like is not really ideal right like um the user experience for doing that in kind of a uh l1 blockchains kind of makes sense because you're always dealing with these

kind of financial interactions and you want to be sure you want to be able to like bits what you actually are doing but if it's like you know typing like a comment it doesn't really matter as much so this would be like a really annoying kind of user experience so there's actually some things that are going in the right direction here for example there's an eip in ethereum land called sign in with ethereum and it basically allows you to sign a message and sign into a back-end so the the flow we talked about before with like each application having their own centralized database well at least you can use your ethereum address to sign in but it's that's obviously not enough we need the shared data layer and so

how do we deal with this in ceramic well uh we have something called session keys and so with a session key you can essentially sign something once and then give this session key [Music] write and read access to specific data models so uh to contrast that from like an l1 blockchain you have to sign a retransaction uh whereas in ceramic you sign once to give permission to the application and you tell the application like hey these are the data models that you can access and that's kind of the only thing that the data that the application can access and so how does this work well we use something called object capabilities

and um the flow looks like something like this we have an application it generates locally kind of in the browser or in the local mobile app a session key then it sends a request to the user's wallet using sign in with ethereum and the neat thing here is like in this sign in with the theory message put the public key of the session key and you put like the identifier of the data model which you want to be able to write to the wallet signs the transaction and what comes out is essentially something we call cacao and a chain agnostic capability object so

this capability object gives the session key kind of like a magic power because the session key can now make updates on behalf of the user's address in ceramic without actually having to request the wall to sign something every time so as long as the session key can produce a signature that corresponds to this public key that was included in this capability object or indesign with clear message in this case they will be authorized to like update um the data that's living in this data model so we think this can really enhance kind of ux of web 3d applications without kind of compromising and like writing

data to centralized databases and so i talked about data models a bunch but what are they actually well [Music] uh one way to think about surrounding kind of like very abstractly is is like this um huge user table of of the internet it's kind of like a shared table where applications can read and write from and so every row in this table would be a user so to the left here you can see that a user is represented by the id which is essentially like the the way we represent the counts in ceramic and every column here you can see is the data model

and so the first one looks like a name second one looks like some kind of metadata and the third one is just a bunch of jumbled encrypted data and so you might ask like why why do we need these data models here couldn't we just have like no column one is name and column two is whatever but the problem if you're trying to build uh composable data applications is that if application a uses the column name and they put string there and now application b uses column name as well but they put you know an object that contains like the first name and the last name then you're gonna run into trouble because if a user goes to the first application then goes to the second application

something is likely going to break because they're expecting different formats for the data and the data model solves this because the data model essentially like describes what type of data is allowed to go into this particular column and i'll touch a little bit more upon that soon so who actually then controls the data inside of this table well uh like if you come from like a web 2 context you might imagine like oh the one who created the data model the application developer might control every entry in this in this column well it's not really it and that wouldn't really kind of give users the control that we hope to give them so instead what happens is

um the user has their own role they have full kind of control of their their role that's cryptographically enforced so only updates that are authorized by the user or the user is giving consent to make some updates will be allowed to happen so the application can't really do anything to like change the data from underneath the user um and so this this is really powerful like it gives the data really kind of uh to be fully controlled by the user and the data model um what does it contain what is actually a data model well it contains some metadata data information about the

data itself so it might be like a name a description and then it contains a data schema so this is really important kind of going back to the thing i talked about before but like expecting particular pieces of data if i'm building an application and i want to pull in i see that there's like a data model that's popular it's really useful for my use case then i want to be sure that like when i pull in the data i know what to expect so the data model actually enforces that the specific data schema is used on this cell for the user so um if the if the application tries to write something in this uh field um or this record for the user they uh that would simply that update

would simply not be allowed all right so that's kind of ceramic on a very high level and so how does it how does ceramic actually work like how do we achieve this well ceramic you can think of as a decentralized network of self-certifying data streams so every object in ceramic is an event stream [Music] where every event is signed by the controller of the stream and so the controller is the basically the public key or the account that's like allowed to make updates to this data stream and every update that is signed we can

verify the history of this and we can look at all the events to reduce the latest state of this object these objects in ceramic are location agnostic so if you're running a ceramic node and you subscribe to some particular streams then and someone else comes online they can you know look up the data on the network and the new node that comes online doesn't really care about if it comes from your node or it comes from some other node they can just verify the integrity of the stream and reduce the state and they'll know that the data they got is correct and so if you think about

you know all these individual objects that's powerful in itself but what we can actually do is create links between these data objects so i might have my social profile the points to also include my my blog posts and so i can create these links between data i can actually link to other people's data um and i'm not linking to some static content i'm actually linking to whatever is the latest update that they created so we're basically creating this open graph of kind of collective shared data or knowledge uh

in our community and and finally that this means that we get shared network effects so if if i'm building an application i onboard 10 000 users to use my data model another application comes online they see that this data model is super useful so they pull that in they already kind of on board with boom without ten thousand users but they're doing really well and they onboard another a hundred thousand users now uh that's great for them but it's also great for me because my application now basically has another hundred thousand onboard users they can just go to my app and kind of like have a seamless experience so diving in a little bit more into like

the data stream itself um this is kind of how it looks like at first there's like a genesis event when you create this stream or the state object and then periodically these updates are anchored into the blockchain and that's what we call an anchor event and so this what this does is provide proof that the previous update was actually created before some point in time this is a proof that um this data existed before this time so we can kind of have like a sequence of like uh when the events took place then we see a signature event um

so this event is just like an update uh to the streams that might contains like this is how the data should be changed and here's the signature that proves that the update was actually made by the account that is allowed to update the stream and then the stream you're going to continue with these types of events for the long is necessary to make like the updates that you need and the cool thing about anchoring the events into the blockchain is that if there is some conflict we can actually always see like which event happened first and select the proper path in this event log and this is important for having a secure key rotation and

in in a fully decentralized data system and so if you want to learn more about this and building on ceramic in general you should go to our developer site developers.surround.network we have a simple demo app called self.id and if you want to share with us just go to chat.sram.network to join our discord and yeah let's create some really cool composable apps together thank you