1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[2297],{3905:(e,t,a)=>{a.d(t,{Zo:()=>l,kt:()=>m});var n=a(7294);function r(e,t,a){return t in e?Object.defineProperty(e,t,{value:a,enumerable:!0,configurable:!0,writable:!0}):e[t]=a,e}function i(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),a.push.apply(a,n)}return a}function s(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?i(Object(a),!0).forEach((function(t){r(e,t,a[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):i(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))}))}return e}function c(e,t){if(null==e)return{};var a,n,r=function(e,t){if(null==e)return{};var a,n,r={},i=Object.keys(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||(r[a]=e[a]);return r}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)a=i[n],t.indexOf(a)>=0||Object.prototype.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}var d=n.createContext({}),o=function(e){var t=n.useContext(d),a=t;return e&&(a="function"==typeof e?e(t):s(s({},t),e)),a},l=function(e){var t=o(e.components);return n.createElement(d.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},h=n.forwardRef((function(e,t){var a=e.components,r=e.mdxType,i=e.originalType,d=e.parentName,l=c(e,["components","mdxType","originalType","parentName"]),p=o(a),h=r,m=p["".concat(d,".").concat(h)]||p[h]||u[h]||i;return a?n.createElement(m,s(s({ref:t},l),{},{components:a})):n.createElement(m,s({ref:t},l))}));function m(e,t){var a=arguments,r=t&&t.mdxType;if("string"==typeof e||r){var i=a.length,s=new Array(i);s[0]=h;var c={};for(var d in t)hasOwnProperty.call(t,d)&&(c[d]=t[d]);c.originalType=e,c[p]="string"==typeof e?e:r,s[1]=c;for(var o=2;o<i;o++)s[o]=a[o];return n.createElement.apply(null,s)}return n.createElement.apply(null,a)}h.displayName="MDXCreateElement"},3279:(e,t,a)=>{a.r(t),a.d(t,{assets:()=>l,contentTitle:()=>d,default:()=>m,frontMatter:()=>c,metadata:()=>o,toc:()=>p});var n=a(7462),r=a(3366),i=(a(7294),a(3905)),s=["components"],c={title:"DID Backend"},d=void 0,o={unversionedId:"sdk/did/js/guide/backend",id:"sdk/did/js/guide/backend",title:"DID Backend",description:"The whole DID system needs to interact with the chain locally, so it's necessary to initialize the DID Backend, set the rpc server of the chain, the contract address, the data buffer at the initial stage of the DID system, thereby setting the interactive interface with the chain for DID.",source:"@site/../docs/7.sdk/did/js/guide/backend.md",sourceDirName:"7.sdk/did/js/guide",slug:"/sdk/did/js/guide/backend",permalink:"/sdk/did/js/guide/backend",draft:!1,editUrl:"https://github.com/elastos/Elastos.Wiki/edit/master/website/../docs/7.sdk/did/js/guide/backend.md",tags:[],version:"current",lastUpdatedBy:"racollette",lastUpdatedAt:1677260880,formattedLastUpdatedAt:"Feb 24, 2023",frontMatter:{title:"DID Backend"},sidebar:"sdkSidebar",previous:{title:"Build & Introduction",permalink:"/sdk/did/js/install"},next:{title:"Create and Open DIDStore",permalink:"/sdk/did/js/guide/store/create"}},l={},p=[{value:"Example",id:"example",level:3},{value:"Usage",id:"usage",level:3}],u={toc:p},h="wrapper";function m(e){var t=e.components,a=(0,r.Z)(e,s);return(0,i.kt)(h,(0,n.Z)({},u,a,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("p",null,"The whole DID system needs to interact with the chain locally, so it's necessary to initialize the DID Backend, set the rpc server of the chain, the contract address, the data buffer at the initial stage of the DID system, thereby setting the interactive interface with the chain for DID."),(0,i.kt)("h3",{id:"example"},"Example"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-ts"},'let rpcEndpoint = "testnet";\nlet contractAddress = "0xF654c3cBBB60D7F4ac7cDA325d51E62f47ACD436";\nlet adapter = new Web3Adapter(rpcEndpoint, contractAddress, null, null);\nDIDBackend.initialize(adapter);\n')),(0,i.kt)("h3",{id:"usage"},"Usage"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre",className:"language-js"},"private static DEFAULT_CACHE_INITIAL_CAPACITY = 16;\nprivate static DEFAULT_CACHE_MAX_CAPACITY = 64;\nprivate static DEFAULT_CACHE_TTL = 10 * 60 * 1000;\nstatic initialize(\n adapter: DIDAdapter,\n initialCacheCapacity: number = DIDBackend.DEFAULT_CACHE_INITIAL_CAPACITY,\n maxCacheCapacity: number = DIDBackend.DEFAULT_CACHE_MAX_CAPACITY,\n cacheTtl: number = DIDBackend.DEFAULT_CACHE_TTL\n ):void;
1\n")),(0,i.kt)("p",null,"DIDAdapter is the base class, and users need to implement their own subclasses based on it (such as the Web3Adapter in the example0. Web3Adapter is an implementation DIDAdapterter provided by SDK. Users can use or implement DIDAdapter by themselves according to their needs."),(0,i.kt)("p",null,"InitialCacheCapacity and maxCacheCapacity are the initial and maximum capacities of the buffer, respectively. The SDK has a default value, and users can also set the value based on their own needs."),(0,i.kt)("p",null,"CacheTtl is the validity period of the cache, the default value of which is 10 minutes."))}m.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.