generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
92 changed files
with
8,344 additions
and
9,227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@web5/api": patch | ||
--- | ||
|
||
Upgrade `agent` to refelcy the newest `dwn-sdk-js` and `dwn-server` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@web5/api": minor | ||
--- | ||
|
||
Finalize ability to WalletConnect with sync involved |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@web5/api": patch | ||
--- | ||
|
||
Add `records.subscribe()` functionality to the DwnApi |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@web5/api": minor | ||
--- | ||
|
||
connect methods now work with dwn and user agent and are no longer stubbed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { DidResolutionResult, DidResolverCache, DidResolverCacheLevel, DidResolverCacheLevelParams } from '@web5/dids'; | ||
import { Web5PlatformAgent } from './types/agent.js'; | ||
|
||
|
||
/** | ||
* AgentDidResolverCache keeps a stale copy of the Agent's managed Identity DIDs and only evicts and refreshes upon a successful resolution. | ||
* This allows for quick and offline access to the internal DIDs used by the agent. | ||
*/ | ||
export class AgentDidResolverCache extends DidResolverCacheLevel implements DidResolverCache { | ||
|
||
/** | ||
* Holds the instance of a `Web5PlatformAgent` that represents the current execution context for | ||
* the `AgentDidApi`. This agent is used to interact with other Web5 agent components. It's vital | ||
* to ensure this instance is set to correctly contextualize operations within the broader Web5 | ||
* Agent framework. | ||
*/ | ||
private _agent?: Web5PlatformAgent; | ||
|
||
/** A map of DIDs that are currently in-flight. This helps avoid going into an infinite loop */ | ||
private _resolving: Map<string, boolean> = new Map(); | ||
|
||
constructor({ agent, db, location, ttl }: DidResolverCacheLevelParams & { agent?: Web5PlatformAgent }) { | ||
super ({ db, location, ttl }); | ||
this._agent = agent; | ||
} | ||
|
||
get agent() { | ||
if (!this._agent) { | ||
throw new Error('Agent not initialized'); | ||
} | ||
return this._agent; | ||
} | ||
|
||
set agent(agent: Web5PlatformAgent) { | ||
this._agent = agent; | ||
} | ||
|
||
/** | ||
* Get the DID resolution result from the cache for the given DID. | ||
* | ||
* If the DID is managed by the agent, or is the agent's own DID, it will not evict it from the cache until a new resolution is successful. | ||
* This is done to achieve quick and offline access to the agent's own managed DIDs. | ||
*/ | ||
async get(did: string): Promise<DidResolutionResult | void> { | ||
try { | ||
const str = await this.cache.get(did); | ||
const cachedResult = JSON.parse(str); | ||
if (!this._resolving.has(did) && Date.now() >= cachedResult.ttlMillis) { | ||
this._resolving.set(did, true); | ||
if (this.agent.agentDid.uri === did || 'undefined' !== typeof await this.agent.identity.get({ didUri: did })) { | ||
try { | ||
const result = await this.agent.did.resolve(did); | ||
if (!result.didResolutionMetadata.error) { | ||
this.set(did, result); | ||
} | ||
} finally { | ||
this._resolving.delete(did); | ||
} | ||
} else { | ||
this._resolving.delete(did); | ||
this.cache.nextTick(() => this.cache.del(did)); | ||
} | ||
} | ||
return cachedResult.value; | ||
} catch(error: any) { | ||
if (error.notFound) { | ||
return; | ||
} | ||
throw error; | ||
} | ||
} | ||
} |
Oops, something went wrong.