Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
fix: things
Browse files Browse the repository at this point in the history
  • Loading branch information
auer-martin committed Jun 29, 2024
1 parent 720fba7 commit e269648
Show file tree
Hide file tree
Showing 27 changed files with 96 additions and 186 deletions.
33 changes: 11 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,23 @@ function verifyJwtCallback(): VerifyJwtCallback {
} else if (jwtVerifier.method === 'jwk') {
// verify jwk certificate protected jwt's
} else if (jwtVerifier.method === 'custom') {
// Only called if based on the jwt the verification method could not been determined
throw new Error(`Could not determine jwt verification method`)
// Only called if based on the jwt the verification method could not be determined
throw new Error(`Unsupported JWT verifier method ${jwtIssuer.method}`)
}
}
}

function createJwtCallback(): CreateJwtCallback {
return async (jwtIssuer, jwt) => {
if (jwtVerifier.method === 'did') {
if (jwtIssuer.method === 'did') {
// create didJwt
} else if (jwtVerifier.method === 'x5c') {
} else if (jwtIssuer.method === 'x5c') {
// create x5c certificate protected jwt
} else if (jwtVerifier.method === 'jwk') {
} else if (jwtIssuer.method === 'jwk') {
// create a jwk certificate protected jwt
} else if (jwtVerifier.method === 'custom') {
} else if (jwtIssuer.method === 'custom') {
// Only called if no or a Custom jwtIssuer was passed to the respective methods
throw new Error(`Could not determine jwt verification method`)
throw new Error(`Unsupported JWT issuer method ${jwtIssuer.method}`)
}
}
}
Expand Down Expand Up @@ -786,7 +786,7 @@ export interface VerifiedJWT {
}

export interface VerifyAuthorizationRequestOpts {
verification: InternalVerification | ExternalVerification; // To use internal verification or external hosted verification
verification: Verification
nonce?: string; // If provided the nonce in the request needs to match
verifyCallback?: VerifyCallback;
}
Expand Down Expand Up @@ -819,7 +819,6 @@ static async verifyJWT(jwt:string, opts: SIOP.VerifyAuthorizationRequestOpts): P
````typescript
const verifyOpts: VerifyAuthorizationRequestOpts = {
verification: {
mode: VerificationMode.INTERNAL,
resolveOpts: {
subjectSyntaxTypesSupported: ['did:ethr'],
}
Expand Down Expand Up @@ -874,7 +873,7 @@ export enum PresentationLocation {
}

export interface VerifyAuthorizationRequestOpts {
verification: InternalVerification | ExternalVerification; // To use internal verification or external hosted verification
verification: Verification
nonce?: string; // If provided the nonce in the request needs to match
verifyCallback?: VerifyCallback // Callback function to verify the domain linkage credential
}
Expand Down Expand Up @@ -938,12 +937,7 @@ static async createJWTFromRequestJWT(requestJwt: string, responseOpts: SIOP.Auth
responseMode: ResponseMode.POST,
}
const verifyOpts: VerifyAuthorizationRequestOpts = {
verification: {
resolveOpts: {
subjectSyntaxTypesSupported: ['did:ethr:'],
},
mode: VerificationMode.INTERNAL,
}
verification: { }
}
createJWTFromRequestJWT('ey....', responseOpts, verifyOpts).then(resp => {
console.log(resp.payload.sub);
Expand All @@ -961,12 +955,7 @@ const NONCE = "5c1d29c1-cf7d-4e14-9305-9db46d8c1916";
const verifyOpts: VerifyAuthorizationResponseOpts = {
audience: "https://rp.acme.com/siop/jwts",
nonce: NONCE,
verification: {
resolveOpts: {
subjectSyntaxTypesSupported: ['did:ethr:'],
},
mode: VerificationMode.INTERNAL,
}
verification: { }
}

verifyJWT('ey......', verifyOpts).then(jwt => {
Expand Down
4 changes: 2 additions & 2 deletions docs/services-class-diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ RequestRegistrationOpts --|> RPRegistrationMetadataOpts
class VerifyAuthenticationRequestOpts {
<<interface>>
verification: InternalVerification | ExternalVerification;
verification: Verification
nonce?: string;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ AuthenticationResponseWithJWT --> AuthenticationResponseOpts
class VerifyAuthenticationResponseOpts {
<<interface>>
verification: InternalVerification | ExternalVerification;
verification: Verification
nonce?: string;
state?: string;
audience: string;
Expand Down
2 changes: 1 addition & 1 deletion docs/services-class-diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/authorization-request/Opts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertValidRequestObjectOpts } from '../request-object/Opts';
import { ExternalVerification, InternalVerification, SIOPErrors } from '../types';
import { SIOPErrors, Verification } from '../types';

import { assertValidRequestRegistrationOpts } from './RequestRegistration';
import { CreateAuthorizationRequestOpts, VerifyAuthorizationRequestOpts } from './types';
Expand All @@ -23,11 +23,11 @@ export const assertValidAuthorizationRequestOpts = (opts: CreateAuthorizationReq

export const mergeVerificationOpts = (
classOpts: {
verification?: InternalVerification | ExternalVerification;
verification?: Verification;
},
requestOpts: {
correlationId: string;
verification?: InternalVerification | ExternalVerification;
verification?: Verification;
},
) => {
const presentationVerificationCallback =
Expand Down
6 changes: 2 additions & 4 deletions src/authorization-request/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import { PresentationDefinitionPayloadOpts } from '../authorization-response';
import { RequestObjectOpts } from '../request-object';
import {
ClientMetadataOpts,
ExternalVerification,
IdTokenClaimPayload,
InternalVerification,
ResponseMode,
ResponseType,
Schema,
Scope,
SigningAlgo,
SubjectType,
SupportedVersion,
Verification,
} from '../types';
import { VerifyJwtCallback } from '../types/JwtVerifier';

Expand Down Expand Up @@ -74,9 +73,8 @@ export type CreateAuthorizationRequestOpts = AuthorizationRequestOptsVID1 | Auth
export interface VerifyAuthorizationRequestOpts {
correlationId: string;

verification: InternalVerification | ExternalVerification; // To use internal verification or external hosted verification
verification: Verification;
verifyJwtCallback: VerifyJwtCallback;
// didDocument?: DIDDocument; // If not provided the DID document will be resolved from the request
nonce?: string; // If provided the nonce in the request needs to match
state?: string; // If provided the state in the request needs to match

Expand Down
4 changes: 2 additions & 2 deletions src/authorization-response/Opts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isExternalVerification, isInternalVerification, SIOPErrors } from '../types';
import { SIOPErrors } from '../types';

import { AuthorizationResponseOpts, VerifyAuthorizationResponseOpts } from './types';

Expand All @@ -9,7 +9,7 @@ export const assertValidResponseOpts = (opts: AuthorizationResponseOpts) => {
};

export const assertValidVerifyOpts = (opts: VerifyAuthorizationResponseOpts) => {
if (!opts?.verification || (!isExternalVerification(opts.verification) && !isInternalVerification(opts.verification))) {
if (!opts?.verification || !opts.verifyJwtCallback) {
throw new Error(SIOPErrors.VERIFY_BAD_PARAMS);
}
};
13 changes: 2 additions & 11 deletions src/authorization-response/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ import { IPresentationDefinition, PresentationSignCallBackParams } from '@sphere
import { Format } from '@sphereon/pex-models';
import { CompactSdJwtVc, Hasher, PresentationSubmission, W3CVerifiablePresentation } from '@sphereon/ssi-types';

import {
ExternalVerification,
InternalVerification,
ResponseMode,
ResponseRegistrationOpts,
ResponseURIType,
SupportedVersion,
VerifiablePresentationWithFormat,
} from '../types';
import { ResponseMode, ResponseRegistrationOpts, ResponseURIType, SupportedVersion, VerifiablePresentationWithFormat, Verification } from '../types';
import { CreateJwtCallback, JwtIssuer } from '../types/JwtIssuer';
import { VerifyJwtCallback } from '../types/JwtVerifier';

Expand Down Expand Up @@ -93,10 +85,9 @@ export type PresentationSignCallback = (args: PresentationSignCallBackParams) =>

export interface VerifyAuthorizationResponseOpts {
correlationId: string;
verification: InternalVerification | ExternalVerification;
verification: Verification;
verifyJwtCallback: VerifyJwtCallback;
hasher?: Hasher;
// didDocument?: DIDDocument; // If not provided the DID document will be resolved from the request
nonce?: string; // To verify the response against the supplied nonce
state?: string; // To verify the response against the supplied state

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export async function getDigestAlgorithmFromJwkThumbprintUri(uri: string): Promi
if (!match) {
throw new Error(`Invalid JWK thumbprint URI structure ${uri}`);
}
const algorithm = match[1] as 'sha256' | 'sha384' | 'sha512';
const algorithm = `sha${match[1]}` as 'sha256' | 'sha384' | 'sha512';
if (algorithm !== 'sha256' && algorithm !== 'sha384' && algorithm !== 'sha512') {
throw new Error(`Invalid JWK thumbprint URI digest algorithm ${uri}`);
}
Expand Down
6 changes: 2 additions & 4 deletions src/id-token/IDToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class IDToken {
public async jwt(_jwtIssuer: JwtIssuer): Promise<IDTokenJwt> {
if (!this._jwt) {
if (!this.responseOpts) {
throw Error(SIOPErrors.BAD_SIGNATURE_PARAMS);
throw Error(SIOPErrors.BAD_IDTOKEN_RESPONSE_OPTS);
}

const jwtIssuer: JwtIssuerWithContext = _jwtIssuer
Expand All @@ -98,9 +98,7 @@ export class IDToken {
this._jwt = await this.responseOpts.createJwtCallback(jwtIssuer, { header: {}, payload: this._payload });
} else if (jwtIssuer.method === 'did') {
const did = jwtIssuer.didUrl.split('#')[0];
if (!this._payload.sub) {
this._payload.sub = did;
}
this._payload.sub = did;

const issuer = this._responseOpts.registration.issuer || this._payload.iss;
if (!issuer || !(issuer.includes(ResponseIss.SELF_ISSUED_V2) || issuer === this._payload.sub)) {
Expand Down
12 changes: 4 additions & 8 deletions src/op/OP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
AuthorizationEvent,
AuthorizationEvents,
ContentType,
ExternalVerification,
InternalVerification,
JwtIssuer,
ParsedAuthorizationRequestURI,
RegisterEventListener,
Expand All @@ -28,6 +26,7 @@ import {
SIOPResonse,
SupportedVersion,
UrlEncodingFormat,
Verification,
VerifiedAuthorizationRequest,
} from '../types';

Expand Down Expand Up @@ -56,7 +55,7 @@ export class OP {

public async verifyAuthorizationRequest(
requestJwtOrUri: string | URI,
requestOpts?: { correlationId?: string; verification?: InternalVerification | ExternalVerification },
requestOpts?: { correlationId?: string; verification?: Verification },
): Promise<VerifiedAuthorizationRequest> {
const correlationId = requestOpts?.correlationId || uuidv4();
const authorizationRequest = await AuthorizationRequest.fromUriOrJwt(requestJwtOrUri)
Expand Down Expand Up @@ -100,7 +99,7 @@ export class OP {
correlationId?: string;
audience?: string;
issuer?: ResponseIss | string;
verification?: InternalVerification | ExternalVerification;
verification?: Verification;
presentationExchange?: PresentationExchangeResponseOpts;
},
): Promise<AuthorizationResponseWithCorrelationId> {
Expand Down Expand Up @@ -242,10 +241,7 @@ export class OP {
};
}

private newVerifyAuthorizationRequestOpts(requestOpts: {
correlationId: string;
verification?: InternalVerification | ExternalVerification;
}): VerifyAuthorizationRequestOpts {
private newVerifyAuthorizationRequestOpts(requestOpts: { correlationId: string; verification?: Verification }): VerifyAuthorizationRequestOpts {
const verification: VerifyAuthorizationRequestOpts = {
...this._verifyRequestOptions,
verifyJwtCallback: this._verifyRequestOptions.verifyJwtCallback,
Expand Down
6 changes: 2 additions & 4 deletions src/op/Opts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { VerifyAuthorizationRequestOpts } from '../authorization-request';
import { AuthorizationResponseOpts } from '../authorization-response';
import { LanguageTagUtils } from '../helpers';
import { AuthorizationResponseOptsSchema } from '../schemas';
import { InternalVerification, PassBy, ResponseRegistrationOpts, VerificationMode } from '../types';
import { PassBy, ResponseRegistrationOpts } from '../types';

import { OPBuilder } from './OPBuilder';

Expand Down Expand Up @@ -64,9 +64,7 @@ export const createVerifyRequestOptsFromBuilderOrExistingOpts = (opts: {
? {
verifyJwtCallback: opts.builder.verifyJwtCallback,
hasher: opts.builder.hasher,
verification: {
mode: VerificationMode.INTERNAL,
} as InternalVerification,
verification: {},
supportedVersions: opts.builder.supportedVersions,
correlationId: undefined,
}
Expand Down
2 changes: 1 addition & 1 deletion src/request-object/RequestObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class RequestObject {
this.jwt = await this.opts.createJwtCallback(jwtIssuer, { header, payload: this.payload });
} else if (jwtIssuer.method === 'jwk') {
if (!this.payload.client_id) {
throw new Error('Plaese provide a client_id for the RP');
throw new Error('Please provide a client_id for the RP');
}

const header = { jwk: jwtIssuer.jwk, typ: 'JWT', alg: jwtIssuer.jwk.alg as string };
Expand Down
5 changes: 2 additions & 3 deletions src/rp/Opts.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CreateAuthorizationRequestOpts, PropertyTarget, PropertyTargets, RequestPropertyWithTargets } from '../authorization-request';
import { VerifyAuthorizationResponseOpts } from '../authorization-response';
// import { CreateAuthorizationRequestOptsSchema } from '../schemas';
import { ClientMetadataOpts, InternalVerification, RequestObjectPayload, SIOPErrors, VerificationMode } from '../types';
import { ClientMetadataOpts, RequestObjectPayload, SIOPErrors, Verification } from '../types';

import { RPBuilder } from './RPBuilder';

Expand Down Expand Up @@ -52,15 +52,14 @@ export const createVerifyResponseOptsFromBuilderOrExistingOpts = (opts: { builde
hasher: opts.builder.hasher,
verifyJwtCallback: opts.builder.verifyJwtCallback,
verification: {
mode: VerificationMode.INTERNAL,
presentationVerificationCallback: opts.builder.presentationVerificationCallback,
supportedVersions: opts.builder.supportedVersions,
revocationOpts: {
revocationVerification: opts.builder.revocationVerification,
revocationVerificationCallback: opts.builder.revocationVerificationCallback,
},
replayRegistry: opts.builder.sessionManager,
} as InternalVerification,
} as Verification,
audience: opts.builder.clientId || opts.builder.clientMetadata?.client_id,
}
: opts.verifyOpts;
Expand Down
10 changes: 4 additions & 6 deletions src/rp/RP.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ import {
import { mergeVerificationOpts } from '../authorization-request/Opts';
import { AuthorizationResponse, PresentationDefinitionWithLocation, VerifyAuthorizationResponseOpts } from '../authorization-response';
import { getNonce, getState } from '../helpers';
import { JwtIssuer } from '../types';
import { JwtIssuer, PassBy } from '../types';
import {
AuthorizationEvent,
AuthorizationEvents,
AuthorizationResponsePayload,
ExternalVerification,
InternalVerification,
PassBy,
RegisterEventListener,
ResponseURIType,
SIOPErrors,
SupportedVersion,
Verification,
VerifiedAuthorizationResponse,
} from '../types';

Expand Down Expand Up @@ -143,7 +141,7 @@ export class RP {
audience?: string;
state?: string;
nonce?: string;
verification?: InternalVerification | ExternalVerification;
verification?: Verification;
presentationDefinitions?: PresentationDefinitionWithLocation | PresentationDefinitionWithLocation[];
},
): Promise<VerifiedAuthorizationResponse> {
Expand Down Expand Up @@ -306,7 +304,7 @@ export class RP {
hasher?: Hasher;
state?: string;
nonce?: string;
verification?: InternalVerification | ExternalVerification;
verification?: Verification;
audience?: string;
presentationDefinitions?: PresentationDefinitionWithLocation | PresentationDefinitionWithLocation[];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1068,4 +1068,4 @@ export const AuthorizationRequestPayloadVD12OID4VPD18SchemaObj = {
]
}
}
};
};
6 changes: 1 addition & 5 deletions src/schemas/AuthorizationResponseOpts.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1657,15 +1657,11 @@ export const AuthorizationResponseOptsSchemaObj = {
}
},
"additionalProperties": false
},
"jwkThumbprint": {
"type": "string"
}
},
"required": [
"method",
"jwk",
"jwkThumbprint"
"jwk"
],
"additionalProperties": false
},
Expand Down
Loading

0 comments on commit e269648

Please sign in to comment.