@@ -17,23 +17,15 @@ bedrock.events.on('bedrock.init', async () => {
1717 REFRESHED_ZCAP_CACHE = new LruCache ( cfg . caches . refreshedZcap ) ;
1818} ) ;
1919
20- export async function getRefreshedZcap ( { profileId, delegateId , capability} ) {
21- const key = _createCacheKey ( { profileId, delegateId , capability} ) ;
22- const fn = ( ) => _getUncached ( { profileId, delegateId , capability} ) ;
20+ export async function getRefreshedZcap ( { profileId, capability} ) {
21+ const key = _createCacheKey ( { profileId, capability} ) ;
22+ const fn = ( ) => _getUncached ( { profileId, capability} ) ;
2323 return REFRESHED_ZCAP_CACHE . memoize ( { key, fn} ) ;
2424}
2525
26- function _createCacheKey ( { profileId, delegateId, capability} ) {
27- const json = { profileId, delegateId, canonicalZcap : canonicalize ( capability ) } ;
28- const hash = createHash ( 'sha256' ) . update ( json , 'utf8' ) . digest ( 'base64url' ) ;
29- return hash ;
30- }
31-
32- async function _getUncached ( { profileId, delegateId, capability} ) {
33- // get the policy for the profile + controller (delegate)
34- let policy ;
26+ export async function getRefreshZcapPolicy ( { profileId, delegateId} ) {
3527 try {
36- policy = await brZcapStorage . policies . get ( { profileId, delegateId} ) ;
28+ return brZcapStorage . policies . get ( { profileId, delegateId} ) ;
3729 } catch ( e ) {
3830 // no matching policy, so refresh is denied
3931 if ( e . name === 'NotFoundError' ) {
@@ -46,6 +38,18 @@ async function _getUncached({profileId, delegateId, capability}) {
4638 }
4739 throw e ;
4840 }
41+ }
42+
43+ function _createCacheKey ( { profileId, capability} ) {
44+ const json = { profileId, canonicalZcap : canonicalize ( capability ) } ;
45+ const hash = createHash ( 'sha256' ) . update ( json , 'utf8' ) . digest ( 'base64url' ) ;
46+ return hash ;
47+ }
48+
49+ async function _getUncached ( { profileId, capability} ) {
50+ // get the policy for the profile + controller (delegate)
51+ const { controller : delegateId } = capability ;
52+ const policy = await getRefreshZcapPolicy ( { profileId, delegateId} ) ;
4953
5054 // get the profile signer associated with the policy
5155 // FIXME: perhaps allow "any root profile agent" to be used, requiring
0 commit comments