1"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[1271],{3905:(e,t,r)=>{r.d(t,{Zo:()=>d,kt:()=>f});var a=r(7294);function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);t&&(a=a.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,a)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function i(e,t){if(null==e)return{};var r,a,n=function(e,t){if(null==e)return{};var r,a,n={},o=Object.keys(e);for(a=0;a<o.length;a++)r=o[a],t.indexOf(r)>=0||(n[r]=e[r]);return n}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(a=0;a<o.length;a++)r=o[a],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}var c=a.createContext({}),l=function(e){var t=a.useContext(c),r=t;return e&&(r="function"==typeof e?e(t):s(s({},t),e)),r},d=function(e){var t=l(e.components);return a.createElement(c.Provider,{value:t},e.children)},p="mdxType",u={inlineCode:"code",wrapper:function(e){var t=e.children;return a.createElement(a.Fragment,{},t)}},m=a.forwardRef((function(e,t){var r=e.components,n=e.mdxType,o=e.originalType,c=e.parentName,d=i(e,["components","mdxType","originalType","parentName"]),p=l(r),m=n,f=p["".concat(c,".").concat(m)]||p[m]||u[m]||o;return r?a.createElement(f,s(s({ref:t},d),{},{components:r})):a.createElement(f,s({ref:t},d))}));function f(e,t){var r=arguments,n=t&&t.mdxType;if("string"==typeof e||n){var o=r.length,s=new Array(o);s[0]=m;var i={};for(var c in t)hasOwnProperty.call(t,c)&&(i[c]=t[c]);i.originalType=e,i[p]="string"==typeof e?e:n,s[1]=i;for(var l=2;l<o;l++)s[l]=r[l];return a.createElement.apply(null,s)}return a.createElement.apply(null,r)}m.displayName="MDXCreateElement"},4608:(e,t,r)=>{r.r(t),r.d(t,{assets:()=>d,contentTitle:()=>c,default:()=>f,frontMatter:()=>i,metadata:()=>l,toc:()=>p});var a=r(7462),n=r(3366),o=(r(7294),r(3905)),s=["components"],i={title:"Create and Open DIDStore"},c=void 0,l={unversionedId:"sdk/did/js/guide/store/create",id:"sdk/did/js/guide/store/create",title:"Create and Open DIDStore",description:"DID documents, credentials, private keys, etc. should be saved or read, and DIDStore is a frequently used example in the whole DID system. Before any operation, users can save or read the DID content by opening the DIDStore and obtaining the file storage handle. The DIDStore should be closed after use.",source:"@site/../docs/7.sdk/did/js/guide/store/create.md",sourceDirName:"7.sdk/did/js/guide/store",slug:"/sdk/did/js/guide/store/create",permalink:"/sdk/did/js/guide/store/create",draft:!1,editUrl:"https://github.com/elastos/Elastos.Wiki/edit/master/website/../docs/7.sdk/did/js/guide/store/create.md",tags:[],version:"current",lastUpdatedBy:"racollette",lastUpdatedAt:1677260880,formattedLastUpdatedAt:"Feb 24, 2023",frontMatter:{title:"Create and Open DIDStore"},sidebar:"sdkSidebar",previous:{title:"DID Backend",permalink:"/sdk/did/js/guide/backend"},next:{title:"Access DIDStore",permalink:"/sdk/did/js/guide/store/access"}},d={},p=[{value:"Example",id:"example",level:3},{value:"Usage",id:"usage",level:3}],u={toc:p},m="wrapper";function f(e){var t=e.components,r=(0,n.Z)(e,s);return(0,o.kt)(m,(0,a.Z)({},u,r,{components:t,mdxType:"MDXLayout"}),(0,o.kt)("p",null,"DID documents, credentials, private keys, etc. should be saved or read, and DIDStore is a frequently used example in the whole DID system. Before any operation, users can save or read the DID content by opening the DIDStore and obtaining the file storage handle. The DIDStore should be closed after use."),(0,o.kt)("h3",{id:"example"},"Example"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-ts"},'let rootPath = "root/store";\nlet store = await DIDStore.open(rootPath);\n... ... ... ... ... ... ...\nstore.close();\n')),(0,o.kt)("h3",{id:"usage"},"Usage"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-ts"},"private static CACHE_INITIAL_CAPACITY = 16;\nprivate static CACHE_MAX_CAPACITY = 128;\npublic static async open(\n context: string,\n initialCacheCapacity: number = DIDStore.CACHE_INITIAL_CAPACITY,\n maxCacheCapacity: number = DIDStore.CACHE_MAX_CAPACITY\n): Promise<DIDStore>\uff1b\n")),(0,o.kt)("p",null,"Context is the folder path to be opened. If the folder path does not exist, the SDK will automatically create it."),(0,o.kt)("p",null,"InitialCacheCapacity is the initial cache capacity, and the default value of the SDK is 16, which can also be customized by users."),(0,o.kt)("p",null,"MaxCacheCapacity is the maximum cache capacity, and the default value of the SDK is 128, which can also be customized by users."),(0,o.kt)("p",null,"Clear the cache:"),(0,o.kt)("pre",null,(0,o.kt)("code",{parentName:"pre",className:"language-ts"},"public close():void;\n")))}f.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.