11/*!
2- * Copyright (c) 2019-2024 Digital Bazaar, Inc. All rights reserved.
2+ * Copyright (c) 2019-2025 Digital Bazaar, Inc. All rights reserved.
33 */
44import * as bedrock from '@bedrock/core' ;
55import * as brZCapStorage from '@bedrock/zcap-storage' ;
@@ -20,6 +20,7 @@ import {defaultModuleManager as moduleManager} from '@bedrock/kms';
2020import { reportOperationUsage } from './metering.js' ;
2121
2222const { config, util : { BedrockError} } = bedrock ;
23+ const { helpers : { inspectCapabilityChain} } = brZCapStorage ;
2324
2425const FIVE_MINUTES = 1000 * 60 * 5 ;
2526
@@ -200,44 +201,6 @@ async function getVerifier({keyId, documentLoader}) {
200201 return { verifier, verificationMethod} ;
201202}
202203
203- async function inspectCapabilityChain ( {
204- capabilityChain, capabilityChainMeta
205- } ) {
206- // if capability chain has only root, there's nothing to check as root
207- // zcaps cannot be revoked
208- if ( capabilityChain . length === 1 ) {
209- return { valid : true } ;
210- }
211-
212- // collect capability IDs and delegators for all delegated capabilities in
213- // chain (skip root) so they can be checked for revocation
214- const capabilities = [ ] ;
215- for ( const [ i , capability ] of capabilityChain . entries ( ) ) {
216- // skip root zcap, it cannot be revoked
217- if ( i === 0 ) {
218- continue ;
219- }
220- const [ { purposeResult} ] = capabilityChainMeta [ i ] . verifyResult . results ;
221- if ( purposeResult && purposeResult . delegator ) {
222- capabilities . push ( {
223- capabilityId : capability . id ,
224- delegator : purposeResult . delegator . id ,
225- } ) ;
226- }
227- }
228-
229- const revoked = await brZCapStorage . revocations . isRevoked ( { capabilities} ) ;
230- if ( revoked ) {
231- return {
232- valid : false ,
233- error : new Error (
234- 'One or more capabilities in the chain have been revoked.' )
235- } ;
236- }
237-
238- return { valid : true } ;
239- }
240-
241204function onError ( { error} ) {
242205 if ( ! ( error instanceof BedrockError ) ) {
243206 // always expose cause message and name; expose cause details as
0 commit comments