-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Beginning of the resolveTrustChains
Signed-off-by: Tom Lanser <[email protected]>
- Loading branch information
Showing
7 changed files
with
352 additions
and
2 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
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 @@ | ||
export * from './resolveTrustChains' |
55 changes: 55 additions & 0 deletions
55
packages/core/src/resolveTrustChains/resolveTrustChains.ts
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,55 @@ | ||
// * Fetch the entity configurations, until the trust anchors are hit | ||
// * Fetch the entity statements back until the entityId is hit | ||
// * Merge and apply the policies, trickeling down | ||
// * Return a list of trust chains where the policies are applied, ending up at the `entityId` again | ||
// * Errors | ||
// * when no trust anchor could be found | ||
// * when no trust chain with valid applied could be found | ||
// resolveTrustChains(entityId: string, trustAnchorEntityIds: Array<string>) -> Promise<Array<TrustChain>> | ||
|
||
import { fetchEntityConfigurationChains } from '../entityConfiguration' | ||
import { fetchEntityStatementChain } from '../entityStatement' | ||
import type { VerifyCallback } from '../utils' | ||
|
||
type Options = { | ||
verifyJwtCallback: VerifyCallback | ||
entityId: string | ||
trustAnchorEntityIds: Array<string> | ||
} | ||
|
||
type TrustChain = Awaited<ReturnType<typeof fetchEntityStatementChain>> | ||
|
||
// TODO: Apply the policies | ||
|
||
export const resolveTrustChains = async (options: Options): Promise<Array<TrustChain>> => { | ||
const { entityId, trustAnchorEntityIds, verifyJwtCallback } = options | ||
|
||
const now = new Date() | ||
|
||
const entityConfigurationChains = await fetchEntityConfigurationChains({ | ||
leafEntityId: entityId, | ||
trustAnchorEntityIds, | ||
verifyJwtCallback, | ||
}) | ||
|
||
const trustChains: Array<TrustChain> = [] | ||
|
||
for (const chain of entityConfigurationChains) { | ||
// The last item in the chain is the trust anchor's entity configuration | ||
const entityStatementChain = await fetchEntityStatementChain({ | ||
entityConfigurations: chain, | ||
verifyJwtCallback, | ||
}) | ||
|
||
if (entityStatementChain.some((statement) => statement.exp < now)) { | ||
// Skip expired chains | ||
continue | ||
} | ||
|
||
// TODO: Merge all the policies and check them against the metadata of the leaf entity | ||
|
||
trustChains.push(entityStatementChain) | ||
} | ||
|
||
return trustChains | ||
} |
Oops, something went wrong.