1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[6539],{3905:(e,t,n)=>{n.d(t,{Zo:()=>d,kt:()=>h});var r=n(7294);function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function s(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function i(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach((function(t){a(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function o(e,t){if(null==e)return{};var n,r,a=function(e,t){if(null==e)return{};var n,r,a={},s=Object.keys(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||(a[n]=e[n]);return a}(e,t);if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(r=0;r<s.length;r++)n=s[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(a[n]=e[n])}return a}var l=r.createContext({}),c=function(e){var t=r.useContext(l),n=t;return e&&(n="function"==typeof e?e(t):i(i({},t),e)),n},d=function(e){var t=c(e.components);return r.createElement(l.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return r.createElement(r.Fragment,{},t)}},m=r.forwardRef((function(e,t){var n=e.components,a=e.mdxType,s=e.originalType,l=e.parentName,d=o(e,["components","mdxType","originalType","parentName"]),p=c(n),m=a,h=p["".concat(l,".").concat(m)]||p[m]||u[m]||s;return n?r.createElement(h,i(i({ref:t},d),{},{components:n})):r.createElement(h,i({ref:t},d))}));function h(e,t){var n=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var s=n.length,i=new Array(s);i[0]=m;var o={};for(var l in t)hasOwnProperty.call(t,l)&&(o[l]=t[l]);o.originalType=e,o[p]="string"==typeof e?e:a,i[1]=o;for(var c=2;c<s;c++)i[c]=n[c];return r.createElement.apply(null,i)}return r.createElement.apply(null,n)}m.displayName="MDXCreateElement"},713:(e,t,n)=>{n.r(t),n.d(t,{assets:()=>d,contentTitle:()=>l,default:()=>h,frontMatter:()=>o,metadata:()=>c,toc:()=>p});var r=n(7462),a=n(3366),s=(n(7294),n(3905)),i=["components"],o={title:"Using the Essentials DID Toolkit"},l=void 0,c={unversionedId:"develop/dids/essentials",id:"develop/dids/essentials",title:"Using the Essentials DID Toolkit",description:"A decentralized identifier (DID) adapter is required to publish transactions to the Elastos Identity (EID) chain.",source:"@site/../docs/3.develop/dids/essentials.md",sourceDirName:"3.develop/dids",slug:"/develop/dids/essentials",permalink:"/develop/dids/essentials",draft:!1,editUrl:"https://github.com/elastos/Elastos.Wiki/edit/master/website/../docs/3.develop/dids/essentials.md",tags:[],version:"current",lastUpdatedBy:"racollette",lastUpdatedAt:1677887670,formattedLastUpdatedAt:"Mar 3, 2023",frontMatter:{title:"Using the Essentials DID Toolkit"},sidebar:"developSidebar",previous:{title:"Add ESC Network Programmatically",permalink:"/develop/add-network"},next:{title:"Working with DIDs in Other Wallets",permalink:"/develop/dids/metamask"}},d={},p=[{value:"Setup",id:"setup",level:3},{value:"Register the Connector",id:"register-the-connector",level:3},{value:"Instantiate the DID Access Helper",id:"instantiate-the-did-access-helper",level:3},{value:"Fetch User DID credentials",id:"fetch-user-did-credentials",level:3}],u={toc:p},m="wrapper";function h(e){var t=e.components,n=(0,a.Z)(e,i);return(0,s.kt)(m,(0,r.Z)({},u,n,{components:t,mdxType:"MDXLayout"}),(0,s.kt)("p",null,"A ",(0,s.kt)("a",{parentName:"p",href:"/learn/dids/method"},"decentralized identifier (DID)")," adapter is required to publish transactions to the ",(0,s.kt)("a",{parentName:"p",href:"/learn/sidechains/eid"},"Elastos Identity (EID)")," chain."),(0,s.kt)("p",null,"The easiest way to work with DIDs on the EID chain is to use the ",(0,s.kt)("a",{parentName:"p",href:"/sdk/general/connectivity/guides/setup"},"Elastos Essentials connector"),", which provides a DID adapter over ",(0,s.kt)("a",{parentName:"p",href:"https://walletconnect.com/"},"WalletConnect"),"."),(0,s.kt)("p",null,"This abstracts most of the logic for developers and lets the wallet handle all transaction signing."),(0,s.kt)("h3",{id:"setup"},"Setup"),(0,s.kt)("p",null,"Start by installing the packages:"),(0,s.kt)("pre",null,(0,s.kt)("code",{parentName:"pre",className:"language-bash"},"# Connectivity SDK\nnpm install @elastosfoundation/elastos-connectivity-sdk-js\n\n# Use at least one connector\nnpm install @elastosfoundation/essentials-connector-client-browser\n\n# Use the DID SDK as it's needed for most interactive operations\nnpm install @elastosfoundation/did-js-sdk\n")),(0,s.kt)("h3",{id:"register-the-connector"},"Register the Connector"),(0,s.kt)("pre",null,(0,s.kt)("code",{parentName:"pre",className:"language-ts"},'import { connectivity } from "@elastosfoundation/elastos-connectivity-sdk-js";\n\nlet essentialsConnector = new EssentialsConnector();\n\n// Let the connectivity SDK know that we are willing to use this connector.\nconnectivity.registerConnector(essentialsConnector);\n')),(0,s.kt)("h3",{id:"instantiate-the-did-access-helper"},"Instantiate the DID Access Helper"),(0,s.kt)("p",null,"The DID access helper makes it easy to execute remote operations in the wallet in just a few lines of code. All of the below examples use an instance of this helper tool that are created as follows:"),(0,s.kt)("pre",null,(0,s.kt)("code",{parentName:"pre",className:"language-ts"},'// Connectivity SDK classes\nimport { DID as ConnDID } from "@elastosfoundation/elastos-connectivity-sdk-js";\n\n// DID SDK classes, used to manipulate inputs/outputs to the connectivity SDK\nimport {\n DID,\n DIDBackend,\
1n DIDStore,\n Issuer,\n Mnemonic,\n RootIdentity,\n VerifiableCredential,\n} from "@elastosfoundation/did-js-sdk";\n\nlet didAccess = new ConnDID.DIDAccess();\n')),(0,s.kt)("h3",{id:"fetch-user-did-credentials"},"Fetch User DID credentials"),(0,s.kt)("p",null,'In order for a third party application to get a user\'s "DID string" (DID identifier) or email, it can request the identity wallet to "get some credentials". Here\'s how it works:'),(0,s.kt)("pre",null,(0,s.kt)("code",{parentName:"pre",className:"language-ts"},'// Request credentials from the wallet\nlet presentation = await didAccess.getCredentials({\n claims: {\n name: true, // Mandatory\n avatar: {\n required: false, // Optional\n reason: "Show who you are to others"\n }\n});\n\n// The returned information is a Verifiable Presentation that contains\n// one or more credentials. The DID SDK can then be used to manipulate\n// those credentials.\nlet nameCredential = presentation.getCredentials().find((c) => {\n // Find the "name" credential\n return c.getId().getFragment() === "name";\n});\n\nconsole.log("Thank you for joining " + nameCredential.getSubject().getProperty("name"));\n')),(0,s.kt)("admonition",{type:"tip"},(0,s.kt)("p",{parentName:"admonition"},"For more operations and complete instructions on using the Essentials connector, visit the ",(0,s.kt)("a",{parentName:"p",href:"/sdk/general/connectivity/guides/setup"},"Connectivity SDK guide"),".")))}h.isMDXComponent=!0}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.