Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added jwt payload to the externalOIDFIdentifier.ts #55

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ErrorMessage, ExternalIdentifierOIDFEntityIdOpts, ExternalIdentifierOID
import { IAgentContext } from '@veramo/core'
import { IOIDFClient } from '@sphereon/ssi-sdk.oidf-client'
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
import { IJwsValidationResult } from '../types/IJwtService'

import {IJwsValidationResult, JwsPayload} from '../types/IJwtService'
import * as u8a from 'uint8arrays'
/**
* Resolves an OIDF Entity ID against multiple trust anchors to establish trusted relationships
*
Expand Down Expand Up @@ -36,6 +36,7 @@ export async function resolveExternalOIDFEntityIdIdentifier(
const errorList: Record<TrustedAnchor, ErrorMessage> = {}
const jwkInfos: Array<ExternalJwkInfo> = []

let payload: JwsPayload | undefined
for (const trustAnchor of trustAnchors) {
const resolveResult = await context.agent.resolveTrustChain({
entityIdentifier: identifier,
Expand Down Expand Up @@ -64,6 +65,7 @@ export async function resolveExternalOIDFEntityIdIdentifier(
continue
}

payload = JSON.parse(u8a.toString(u8a.fromString(jwtVerifyResult.jws.payload, 'base64url')))
const signature = jwtVerifyResult.jws.signatures[0]
if (signature.identifier.jwks.length === 0) {
errorList[trustAnchor] = 'No JWK was present in the trust anchor signature'
Expand All @@ -83,6 +85,7 @@ export async function resolveExternalOIDFEntityIdIdentifier(
trustedAnchors: Array.from(trustedAnchors),
...(Object.keys(errorList).length > 0 && { errorList }),
jwks: jwkInfos,
jwtPayload: payload,
trustEstablished: trustedAnchors.size > 0,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isX5cIdentifier,
JwkInfo,
} from './common'
import {JwsPayload} from "./IJwtService";

/**
* Use whenever we need to resolve an external identifier. We can pass in kids, DIDs, and x5chains
Expand Down Expand Up @@ -172,6 +173,7 @@ export interface ExternalIdentifierOIDFEntityIdResult extends IExternalIdentifie
method: 'entity_id'
trustedAnchors: Array<TrustedAnchor>
errorList?: Record<TrustedAnchor, ErrorMessage>
jwtPayload?: JwsPayload
trustEstablished: boolean
}

Expand Down
Loading