New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

Polygon 🛠 On Chain Verified Credentials with Polygon ID - Rahat Chowdhury

ETHGlobalMon, Oct 9, 2023, 12:00 AM

Join Rahat Chowdhury of Polygon for a workshop titled "On Chain Verified Credentials with Polygon ID" Thank you for joining us for ETHSanFrancisco—our first west-coast hackathon in nearly four years. This was officially our biggest event ever 🎉 👥 1700 attendees 🗺 from 46 countries 🌱 38% new to web3 📮 284 projects And: ETHGlobal just turned five! 5️⃣🎂 Thanks to every single one of you for making this community great 💙 ------------------------- Follow us: https://twitter.com/ETHGlobal​ Check us out: https://ethglobal.co​m Email us at: hello@ethglobal.com #ethereum #web3 #blockchain #eth

Transcript

foreign [Applause] [Music] guys doing today good that was not excited at like whatsoever how are you guys doing today all right a little bit better all right wait I can work with that so thank you all for coming to my workshop we're gonna be talking about on-chain verified credentials with polygon ID um a little bit about me hi I'm Rahat I'm the lead developer relations engineer over at polygon previously been front-end engineer solid engineer I've done some Anonymous work for various nft rugs I never said that out loud um Indie hacker web 3 Enthusiast done some like failed startups in the past so I can tell you everything that went wrong I cannot tell you how to succeed um a few places you can find me on Twitter LinkedIn GitHub Etc uh but right now we're gonna play a game um this image is a claim the claim is that I am a pixelated Punk can you verify that these two images are the same yes or no yes am I am I a pixelated Punk that's not the answer I was looking for yes okay cool so congratulations you just participated in an IRL version of polygon ID what what what the hell was that right what does that actually mean before we get into that a little bit of an introduction onto what polygon ID actually is so it's a blockchain native identity system with programmable privacy that empowers people enables creation of trusted interactions with web3 Services I just read a definition for you so that doesn't actually explain anything to you right um but what it does is it provides you a way of having Universal identity that you can take with you throughout your web 3 Journey right you verify something um at some point from some type of issuer an issuer could be some government facility a DMV issuing you a license someone giving you some credentials saying that you graduated from some college and you as a person are carry around that credential and at some point someone needs to verify that this credential exists right so that's kind of like the flow that I want you to remember as we go through this so this is called the triangle of trust so in this case um the the case that I showed you before here with the game that we played uh the triangle of a tries to exist this way there's an issuer called pixel portraits shout out to pixel portraits if you want a NFC of yourself like that they do this um pastel portraits issued me an nft it is an image of my likeness as a pixelated Punk right the ID holder is me I am holding this nft and I asked all of you to compare this ID this um you know nft to myself and let me know if you think it actually is me or not right so the way that this is done through polygon ID is you have your issuer you that issuer issues some sort of claim can be like I said it can be some type of date of birth credential it can be something like a um you know diploma it can be are you the owner of X item or whatever it is that issuer gives you that credential and you never have to verify that you actually have that credential ever again because now you have different verifiers we just look at that credential and have some sort of trust with that issuer saying okay I know this issuer if this issuer says that this is no the actual um thing I believe it and that is done through ack proof so let's talk about what exactly we're going to be building for today so many social media platforms require you to be 13 years or older to use them Instagram I think Twitter requires that I don't know I don't know how it's enforced or if it is enforced but what we're going to do is we're going to leverage polygon ID to issue a soul bound nft based on a specific age credential so we're going to issue ourselves a claim so we're not going to use some like third party claim we're not going to like you know verify our age or anything we're just going to issue it to ourselves and that ish that claim is going to contain our date of birth we're going to create a smart contract that mints a soul bound nft as long as our age is over 13. and there's going to be a front end where anyone with a polygon ID wallet can claim this nft so all this is contingent upon you folks downloading the polygon ID Wallet app which is available on the App Store as well as Google Play Store there will be resources and links to download all of that when you start hacking it on yourselves but demo and code time so the first thing I wanted to show you was this polygon ID platform so I mentioned that we're going to be issuing the claims to ourselves so we're not going to go through some you know third-party issuer and have them like check our ID or do anything we're just going to do it ourselves just for the sake of this specific Workshop so this uh platform here uh again links will be sent out in Discord I will also tweet them out and this platform here is on the test net right now so what you can do once you've gone on to the platform is create a schema so I'm just going to create a sample schema here we're going to call it MI 13. or older and the attribute name will say is a kyc age credential you can name it whatever you want and there are specific data types that are supported right now through these issue issuing claims you can have a Boolean yes or no you can have a date so in this case we're going to be using a date or you can have a number so these are like different things you can think about when you're trying to issue specific claims so we're just going to use the date because I'm going to be looking at a birthday so if you want to put in the description this will be birth date or whatever um for each of these claims you can add an expiration date if you want to I'm not going to add one so I'm going to uncheck this but now you can either save your schema or save and offer the claim so we're going to go ahead and save and offer the claim so this claim has now been created now inside of this attribute for my kyc age credential I can select a date um I'm not going to use my real birthday but that's say I was born I need to be at least 13 right let's just say 1990 February 7th okay I'm not going to put in an expiration date so this claim is just going to exist forever I'm gonna hit generate claim offer and this claim is going to be generated and now we have this link copy this link head over to it and you'll see that you received a claim offer from Rahat Rahat is me I am the person who issued this claim right so now you would download your polygon ID Wallet app you would scan this QR code and then within your polygon ID app you're going to have a specific credential that says you are this specific age right so this is again a test net version of you issuing yourself a claim to test out your um your polygon dapps cool so now that's the first part this is a claim so this is kind of like the same thing as pixel portraits giving me an nft of you know my pick my my punk right rather than a punk and now I'm getting a QR code with a claim that says I am whatever however old I am cool so now let's look at some smart contracts so all of these contracts are going to be shared and available for you to go through afterwards so I'll drop them into Discord as well as on Twitter so you'll be able to take a look at these but to get this set up to actually start using polygon ID with your smart contracts there's a couple things you need to do you're going to have a couple interfaces libraries and verifiers you don't have to write any of this code you can simply copy and paste from the repositories that are going to be shared with you but just like a quick thing if you just go through these you'll see that these are what's actually powering the ZK proofs and verifiers that are going to be looking at your credential and comparing them within the DAP um all of these again are boilerplate code that you can just copy and paste where we're going to actually focus on and create our own code is going to be in this ERC 721 verifier so you'll see from line 8 through 10 that I imported all of those libraries eventually what I'm hoping to do maybe later on is create like an npm package so you can just install and import those rather than copy and pasting them but that's as we're iterating and building that's what you got to do for now um so for this nft drop I have imported a couple things from open Zeppelin first is going to be the ER 7 erc721 URI storage just to make it easy to set the URI I'm importing counters for the um ID of the nft itself strings which is a really cool utility that I'm going to use to convert numbers of strings which I'll show you in a bit base64 which is going to be helpful for actually creating on-chain nfts so everything that we do here is going to be completely on chain no storage will be used off-chin so let's take a look at the contract itself it's an ERC 721 verifier you can call it whatever you want but it inherits everything from the erc721 urr storage as well as the zkp verifier there's a couple of variables here this is really just keeping track of the addresses that have already minted and making sure that people only mint once I'm using strings which I imported from open Zeppelin for unsigned integers which basically gives all of my unsigned integers the power to become strings um counters which will be for my token IDs Constructor is just going to deploy the erc721 but now we get into the cool part before proof submit this is just some boilerplate code but what before proof submit is going to do is going to check that the challenge input of the proof is equal to the message that's sender so we want to make sure the person who is actually trying to generate this proof that is trying to perform this action is the person who owns this specific proof so that's what this is taken care of after proof submit is where the actual magic happens uh we first check to make sure that this proof has not been submitted before they've only done it once and then inside of this if statement we actually execute the token mint so I'm just incrementing um the token mint right away uh the token ID right away the token ID from counter generally starts at zero I just like starting at one so I increment it I get the current token ID and then I call Safe mint with message.sender as well as the new Item ID and then I set the token URI using the item ID and this get token URI function that I'm going to show you in a bit here next part this is what makes this token a sold out token this before choking transfer is going to override the erc721 before token transfer and prevent you from ever actually being able to transfer this token because your age is your own age and not someone else's do not verify your age for someone else that is a frowned upon action two more functions here generating the SVG for the token as well as getting the actual token URI so I'll just go through this real quick for generating the SVG we just have this large SVG code that is going to be encoded and returned as a string and converted to a data image URL all it is is just like a black square that says you are over 18 I mean over 13. um and I'm using the base64 encode to encode all of that together finally the actual get token URI which is going to take um your metadata so this is the metadata that would appear on your nft so right now I'm just giving it a name description in the image the name is just going to be 13 check I'm sorry I'm really bad at naming things and the actual token ID so this is why I brought in the strings package it gives you this like a nice little two-string utility um description verified credential of age over 13 and then the image which is just going to be this generate SVG for token which returns a string cool so this is this part here is nothing specific to polygon ID this is simply for minting and on chain uh Soul bound nft um nothing special going on there cool so now we've got this ERC 721 kind of written out for us there's two scripts in here that are going to be super super important first of all deploying your contract making sure you deploy it nothing nothing special here I'm just taking my um you know um contract deploying it on safaricon the next part is going to be this set request over here so this is another thing that you'll be able to copy and paste most of this is boilerplate code but there's a couple key things that you can change depending on your use case so the first thing is going to be your the address where your contract was actually deployed so this is my address that I deployed earlier and the actual query that you want to do and you want to check for so the query that I want to check for here is to make sure that the person who supplies their date of birth that this date of birth is less than um or before uh January 1st 2009 I think I did the math correctly that should make you 13.

um but if it's not just pretend it is um and you can take a look at this link here which will show you the ZK query language which is going to help you actually set up this query but this operator here with the number two I believe it means less than so it's going to check if like you're less than your date of birth is less than this so you have your issuer that gave you that credential this query is what's going to check that credential and make sure that you're a 13 or older so we've got that so you run both of those scripts great everything is now on the on the blockchain let's take a look at a front end that actually implements this have a little code sandbox here cool Wi-Fi all right so this is a very basic react application that I forked for my friend Steph who did a version of this in Bogota but here what we're going to do is claim our syllable token on polygon Mumbai all you have to do is make sure you have your polygon ID wallet that you issued yourself a claim that has your date of birth then you scan this so rather than me taking out my phone and doing this here and you not being able to see it I'm going to show you a video of me doing this earlier this is like okay come on Wi-Fi right so this is my polygon ID wallet uh I've opened it up I already have my claims I scanned the QR code it generates a proof request so I hit continue it's going through creating the cryptographic proof and it wants to connect to a wallet so I'm going to connect it to my metamask wallet and through metamask I am just going to make sure that I connect to the actual website once I'm connected to the actual website it's going to fully generate the proof to make and do that check after it does that check the last thing it needs to do is actually mint the nft so we're going to go back to metamask which will just pop up and now actually approve the transaction to Mint the nft so I hit go ahead and confirm that transaction to Mint and once that has been minted pay some gas confirm and it'll finish up the process here so you'll see over here on my polygon scan link about seven hours ago I successfully minted this nft it was a success and this is the nft on openc right now so on openc test Nets you can check out 13 check number one um verify 13 or older uh you cannot transfer this to anyone else this is only available in the wallet this was that this was minted in but now what do I do with this right um I have this specific nft now I've with a proof that I am 13 years of age or older great it's wonderful so now I can do really cool things with it token gated access to social apps built on lens you had you know the whole problem that I mentioned before with Instagram with Twitter do you want to keep sending them your date of birth over and over again on every single platform that you're you know on you're sharing your data across all of these platforms at times if they need to do some deeper you know verification maybe you're asked for an ID like why what is the need to go into all of that and share with them that data using this specific nft they don't need to know your date of birth they know that this was issued by polygon ID through an issuer that they trust in this case it was just us but if it was done through an issue or they trust then they know that they don't need access to your information they know that you own this nft you get access to the platform you never have to share your actual age with social media platforms ever again just a verification of the fact that you're old enough so you're only sharing information that they need to know and nothing more than that and you own your data and you're not actually going forward and sharing all of it so I wanted to make sure you have some additional resources this is you know a new thing A New Concept to kind of like learn these will also be put into the Discord um so first definitely check out Steph's original polygon ID Workshop from Bogota she's here and you can definitely dive a little bit deeper into that as well there are two GitHub repos from Steph and one of our teammates many both of those go into using this with erc20 tokens as well as another example with nfts Manny's um GitHub also lists like some like potential error messages common things that you might run into while you're going through and building all of this so definitely take a look at that and the last thing will be the polygon ID docs and tutorials that you definitely want to go through so while going through this I remember I forgot to actually go over one thing so we're going to go back to the front end just so you're aware of that what that one thing is very vital thing for you to actually do this uh so let's go back where's Ark okay so how did I actually make this QR code work I never told you that part so um in this uh react application we're just using this QR code generator uh to generate a proof request which is just going to be a Json object with a bunch of information um it's going to be a bunch of it again it's going to be boilerplate code once you go to this link over here it'll tell you exactly what you need to fill out some of it is going to be information from the claim that you issued so you have to make sure you have that in there properly as well as the actual deployed contract address which I added up here and uses a variable down here but all of this information needs to be put into your QR code so you take this Json put it into your QR code and that's what's that's how this is generated you scan that with your polygon um ID wallet um it reads all of this information including the contract address as well as the type of credential that it needs to verify and that's what's going to kick off the whole process for doing the nft mint so all of that is going to be available on this link over here on the polygon ID GitHub which will go through the query language on how to create this specific query um throughout the weekend myself and Steph will also be here so we'll be able to help you with any further questions that you may have as well um but again these are some of the resources I will send them in the Discord um after this so that you have them and you don't have to take a picture um and like retype it or whatever I'll also send these slides recording of this will also be available if you did enjoy this Workshop please let us know we're at zero X polygon devs I'm also at our hot codes and um there's a couple minutes left for questions anyone has yes yeah I mean ultimately the um security of your wallet is up to you um so that this is does not solve for that specific problem um there are cool things in the works like account abstraction and things like that that'll hopefully help with things like that so that might be a good way to combine polygon ID with like an account abstraction project yep um so right now um this is all on testnet on mainnet there is an implementation with the polygon down um and through the polygon down there's verification for like age credentials and things like that so that is possible um so as we have as we roll out and put this into um you know mainnet we'll be able to give you more information on that well yeah so in in this specific case I created claims myself um just like to do the test but um the claims would have to be coming from trusted issuers right so whoever is doing the verification has to trust this issuer so um if you're trying to um go on to like a social media platform they might have specific issuers that they work with so they might say get yourself verified through this and if they say that you're good you're good right um so that kind of like falls into that triangle of trust foreign a lot of them will have to be um centralized just because of the nature of like what they're verifying like if they're verifying like their passport ID for like you know proof of personhood or verification of date of birth um that all exists on centralized servers so it has to be from a centralized um kind of like source of truth but um what we're doing here is like taking that verification and allowing you to kind of control where it goes and only share the information with like specific platforms that need it foreign I would so the polygon ID wallet is really just for the holding your claims but the actual like transactions and everything that happens would happen in any wallet you choose so in the demo I showed it went to my metamask wallet um so that side of things the actual transactions will be with whatever wallet you have the polygon and D wallet is really for holding your claims cool question here yeah something like that would definitely be a really good use case yeah Trust so that it allows yeah um I don't know the specifics around that but um I think that's a very good thing to be working on um I don't know like the road map for like how verifiers will work in the future yeah cool any other questions no they just need to trust that the issuer will do their job correctly yeah I mean um so I mean the example I showed here was like doing some like on chain verification um with that nft but you could you know bring in something like ens like this is a person verified to have some EMS credential or whatever um and bring that as like a claim um so that as we kind of like build out the um issuer side of things these are different use cases you could potentially bring in cool well um thank you all for coming out today um we'll be around for any further questions [Applause]

Automatic transcript — names and jargon may be misspelled.