Skip to content

Commit

Permalink
set static Web5.did to use no cache until connect is called
Browse files Browse the repository at this point in the history
  • Loading branch information
mistermoe authored and frankhinek committed Jun 2, 2023
1 parent 16434bc commit 6cd631f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/web5/src/web5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ export class Web5 {
* is called
*/
static did = new DidApi({
didMethodApis : [new DidIonApi(), new DidKeyApi()],
cache : new DidResolutionCache()
didMethodApis: [new DidIonApi(), new DidKeyApi()]
});

/**
Expand All @@ -66,7 +65,6 @@ export class Web5 {

private static APP_DID_KEY = 'WEB5_APP_DID';


private constructor(options: Web5Options) {
this.#connectedDid = options.connectedDid;
this.dwn = new DwnApi(options.web5Agent, this.#connectedDid);
Expand Down Expand Up @@ -98,10 +96,18 @@ export class Web5 {
const profileApi = new ProfileApi();
let [ profile ] = await profileApi.listProfiles();

options.didMethodApis ??= [];

// override default cache used by `Web5.did`
Web5.did = new DidApi({
didMethodApis : [new DidIonApi(), new DidKeyApi(), ...options.didMethodApis],
cache : options.didResolutionCache || new DidResolutionCache()
});

const dwn = await Dwn.create();
const syncManager = new SyncApi({
profileManager : profileApi,
didResolver : Web5.did.resolver,
didResolver : Web5.did.resolver, // share the same resolver to share the same underlying cache
dwn : dwn
});

Expand All @@ -122,7 +128,7 @@ export class Web5 {

const agent = await Web5UserAgent.create({
profileManager : profileApi,
didResolver : Web5.did.resolver,
didResolver : Web5.did.resolver, // share the same resolver to share the same underlying cache
syncManager : syncManager,
dwn : dwn,
});
Expand Down

0 comments on commit 6cd631f

Please sign in to comment.