generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into tshamilov/connect-dwn-integration
- Loading branch information
Showing
22 changed files
with
2,683 additions
and
500 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,8 @@ | ||
--- | ||
"@web5/agent": minor | ||
"@web5/identity-agent": minor | ||
"@web5/proxy-agent": minor | ||
"@web5/user-agent": minor | ||
--- | ||
|
||
Add ability to Sync a subset of protocols as a delegate |
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 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 |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
"ip", | ||
"mysql2", | ||
"braces", | ||
"GHSA-rv95-896h-c2vc" | ||
"GHSA-rv95-896h-c2vc", | ||
"GHSA-952p-6rrq-rcjv" | ||
] | ||
} |
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,66 @@ | ||
import { TtlCache } from '@web5/common'; | ||
import { AgentPermissionsApi } from './permissions-api.js'; | ||
import { Web5Agent } from './types/agent.js'; | ||
import { PermissionGrantEntry } from './types/permissions.js'; | ||
import { DwnInterface } from './types/dwn.js'; | ||
|
||
export class CachedPermissions { | ||
|
||
/** the default value for whether a fetch is cached or not */ | ||
private cachedDefault: boolean; | ||
|
||
/** Holds the instance of {@link AgentPermissionsApi} that helps when dealing with permissions protocol records */ | ||
private permissionsApi: AgentPermissionsApi; | ||
|
||
/** cache for fetching a permission {@link PermissionGrant}, keyed by a specific MessageType and protocol */ | ||
private cachedPermissions: TtlCache<string, PermissionGrantEntry> = new TtlCache({ ttl: 60 * 1000 }); | ||
|
||
constructor({ agent, cachedDefault }:{ agent: Web5Agent, cachedDefault?: boolean }) { | ||
this.permissionsApi = new AgentPermissionsApi({ agent }); | ||
this.cachedDefault = cachedDefault ?? false; | ||
} | ||
|
||
public async getPermission<T extends DwnInterface>({ connectedDid, delegateDid, delegate, messageType, protocol, cached = this.cachedDefault }: { | ||
connectedDid: string; | ||
delegateDid: string; | ||
messageType: T; | ||
protocol?: string; | ||
cached?: boolean; | ||
delegate?: boolean; | ||
}): Promise<PermissionGrantEntry> { | ||
// Currently we only support finding grants based on protocols | ||
// A different approach may be necessary when we introduce `protocolPath` and `contextId` specific impersonation | ||
const cacheKey = [ connectedDid, delegateDid, messageType, protocol ].join('~'); | ||
const cachedGrant = cached ? this.cachedPermissions.get(cacheKey) : undefined; | ||
if (cachedGrant) { | ||
return cachedGrant; | ||
} | ||
|
||
const permissionGrants = await this.permissionsApi.fetchGrants({ | ||
author : delegateDid, | ||
target : delegateDid, | ||
grantor : connectedDid, | ||
grantee : delegateDid, | ||
}); | ||
|
||
// get the delegate grants that match the messageParams and are associated with the connectedDid as the grantor | ||
const grant = await AgentPermissionsApi.matchGrantFromArray( | ||
connectedDid, | ||
delegateDid, | ||
{ messageType, protocol }, | ||
permissionGrants, | ||
delegate | ||
); | ||
|
||
if (!grant) { | ||
throw new Error(`CachedPermissions: No permissions found for ${messageType}: ${protocol}`); | ||
} | ||
|
||
this.cachedPermissions.set(cacheKey, grant); | ||
return grant; | ||
} | ||
|
||
public async clear(): Promise<void> { | ||
this.cachedPermissions.clear(); | ||
} | ||
} |
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
Oops, something went wrong.