Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Dec 5, 2024
2 parents fc84496 + 71b35d7 commit 96b5b1b
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions packages/oid4vci-issuer/src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,12 @@ import {
IssuerMetadata,
Jwt,
JwtVerifyResult,
OID4VCICredentialFormat
OID4VCICredentialFormat,
} from '@sphereon/oid4vci-common'
import { JWTHeader, JWTPayload } from '@sphereon/oid4vci-common/lib/types'
import {
CredentialDataSupplier,
CredentialIssuanceInput,
CredentialSignerCallback,
VcIssuer,
VcIssuerBuilder
} from '@sphereon/oid4vci-issuer'
import { CredentialDataSupplier, CredentialIssuanceInput, CredentialSignerCallback, VcIssuer, VcIssuerBuilder } from '@sphereon/oid4vci-issuer'
import { getAgentResolver, IDIDOptions } from '@sphereon/ssi-sdk-ext.did-utils'
import {
legacyKeyRefsToIdentifierOpts,
ManagedIdentifierOptsOrResult
} from '@sphereon/ssi-sdk-ext.identifier-resolution'
import { legacyKeyRefsToIdentifierOpts, ManagedIdentifierOptsOrResult } from '@sphereon/ssi-sdk-ext.identifier-resolution'
import { contextHasPlugin } from '@sphereon/ssi-sdk.agent-config'
import { SdJwtVcPayload } from '@sphereon/ssi-sdk.sd-jwt/dist'
import { IStatusListPlugin } from '@sphereon/ssi-sdk.vc-status-list'
Expand All @@ -35,7 +26,7 @@ export function getJwtVerifyCallback({ verifyOpts }: { verifyOpts?: JWTVerifyOpt
const resolver = getAgentResolver(_context, {
resolverResolution: true,
uniresolverResolution: true,
localResolution: true
localResolution: true,
})
verifyOpts = { ...verifyOpts, resolver: verifyOpts?.resolver } // Resolver separately as that is a function
if (!verifyOpts?.resolver || typeof verifyOpts?.resolver?.resolve !== 'function') {
Expand All @@ -60,25 +51,23 @@ export function getJwtVerifyCallback({ verifyOpts }: { verifyOpts?: JWTVerifyOpt
const payload = jwtDecode<JWTPayload>(args.jwt, { header: false })
return {
alg,
...{ identifier },
jwt: { header, payload }
...identifier,
jwt: { header, payload },
} as JwtVerifyResult<DIDDocument>
}


const decodedJwt = (await decodeJWT(args.jwt)) as Jwt
const kid = args.kid ?? decodedJwt.header.kid

if (!kid || !kid.startsWith('did:')) {
// No DID method present in header. We already performed the validation above. So return that
return {
alg: decodedJwt.header.alg,
jwt: decodedJwt
jwt: decodedJwt,
} as JwtVerifyResult<DIDDocument>
}
const did = kid.split('#')[0]


const didResult = await verifyJWT(args.jwt, verifyOpts)
if (!didResult.verified) {
console.log(`JWT invalid: ${args.jwt}`)
Expand All @@ -96,9 +85,8 @@ export function getJwtVerifyCallback({ verifyOpts }: { verifyOpts?: JWTVerifyOpt
kid,
did,
didDocument: didResolution.didDocument,
jwt: decodedJwt
jwt: decodedJwt,
}

}
}

Expand All @@ -121,7 +109,7 @@ export async function getAccessTokenKeyRef(
*/
didOpts?: IDIDOptions
},
context: IRequiredContext
context: IRequiredContext,
) {
let identifier = legacyKeyRefsToIdentifierOpts(opts)
return await context.agent.identifierManagedGet(identifier)
Expand All @@ -146,7 +134,7 @@ export async function getAccessTokenSignerCallback(
*/
didOpts?: IDIDOptions
},
context: IRequiredContext
context: IRequiredContext,
) {
const signer = async (data: string | Uint8Array) => {
let dataString, encoding: 'base64' | undefined
Expand Down Expand Up @@ -181,7 +169,7 @@ export async function getCredentialSignerCallback(
idOpts: ManagedIdentifierOptsOrResult & {
crypto?: Crypto
},
context: IRequiredContext
context: IRequiredContext,
): Promise<CredentialSignerCallback<DIDDocument>> {
async function issueVCCallback(args: {
credentialRequest: CredentialRequest
Expand Down Expand Up @@ -228,7 +216,7 @@ export async function getCredentialSignerCallback(
removeOriginalFields: false,
fetchRemoteContexts: true,
domain: typeof credential.issuer === 'object' ? credential.issuer.id : credential.issuer,
...(resolution.kid && { header: { kid: resolution.kid } })
...(resolution.kid && { header: { kid: resolution.kid } }),
})
return (proofFormat === 'jwt' && 'jwt' in result.proof ? result.proof.jwt : result) as W3CVerifiableCredential
} else if (CredentialMapper.isSdJwtDecodedCredentialPayload(credential)) {
Expand All @@ -246,13 +234,13 @@ export async function getCredentialSignerCallback(
delete credential['disclosureFrame']
} else {
disclosureFrame = {
_sd: credential['_sd']
_sd: credential['_sd'],
}
}
const result = await context.agent.createSdJwtVc({
credentialPayload: sdJwtPayload,
disclosureFrame: disclosureFrame,
resolution
resolution,
})
return result.credential
} /*else if (CredentialMapper.isMsoMdocDecodedCredential(credential)) {
Expand All @@ -272,7 +260,7 @@ export async function createVciIssuerBuilder(
resolver?: Resolvable
credentialDataSupplier?: CredentialDataSupplier
},
context: IRequiredContext
context: IRequiredContext,
): Promise<VcIssuerBuilder<DIDDocument>> {
const { issuerOpts, issuerMetadata, authorizationServerMetadata } = args

Expand All @@ -291,7 +279,7 @@ export async function createVciIssuerBuilder(
...issuerOpts?.didOpts?.resolveOpts?.jwtVerifyOpts,
...args?.issuerOpts?.resolveOpts?.jwtVerifyOpts,
resolver,
audience: issuerMetadata.credential_issuer as string // FIXME legacy version had {display: NameAndLocale | NameAndLocale[]} as credential_issuer
audience: issuerMetadata.credential_issuer as string, // FIXME legacy version had {display: NameAndLocale | NameAndLocale[]} as credential_issuer
}
builder.withIssuerMetadata(issuerMetadata)
builder.withAuthorizationMetadata(authorizationServerMetadata)
Expand All @@ -314,19 +302,24 @@ export async function createVciIssuer(
issuerOpts,
issuerMetadata,
authorizationServerMetadata,
credentialDataSupplier
credentialDataSupplier,
}: {
issuerOpts: IIssuerOptions
issuerMetadata: IssuerMetadata
authorizationServerMetadata: AuthorizationServerMetadata
credentialDataSupplier?: CredentialDataSupplier
},
context: IRequiredContext
context: IRequiredContext,
): Promise<VcIssuer<DIDDocument>> {
return (await createVciIssuerBuilder({
issuerOpts,
issuerMetadata,
authorizationServerMetadata,
credentialDataSupplier
}, context)).build()
return (
await createVciIssuerBuilder(
{
issuerOpts,
issuerMetadata,
authorizationServerMetadata,
credentialDataSupplier,
},
context,
)
).build()
}

0 comments on commit 96b5b1b

Please # to comment.