-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cb9259
commit b09da53
Showing
11 changed files
with
178 additions
and
76 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './v-jarm-client-metadata-params.js'; | ||
export * from './v-jarm-server-metadata-params.js'; | ||
export * from './v-jarm-client-metadata.js'; | ||
export * from './v-jarm-server-metadata.js'; | ||
export * from './jarm-validate-metadata.js'; |
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,90 @@ | ||
import * as v from 'valibot'; | ||
|
||
import { | ||
vJarmClientMetadata, | ||
vJarmClientMetadataEncrypt, | ||
vJarmClientMetadataSign, | ||
vJarmClientMetadataSignEncrypt, | ||
} from '../metadata/v-jarm-client-metadata.js'; | ||
import { vJarmServerMetadata } from '../metadata/v-jarm-server-metadata.js'; | ||
import { assertValueSupported } from '../utils.js'; | ||
|
||
export const vJarmAuthResponseValidateMetadataInput = v.object({ | ||
client_metadata: vJarmClientMetadata, | ||
server_metadata: v.partial(vJarmServerMetadata), | ||
}); | ||
export type JarmMetadataValidate = v.InferInput<typeof vJarmAuthResponseValidateMetadataInput>; | ||
|
||
export const vJarmMetadataValidateOut = v.variant('type', [ | ||
v.object({ | ||
type: v.literal('signed'), | ||
client_metadata: vJarmClientMetadataSign, | ||
}), | ||
v.object({ | ||
type: v.literal('encrypted'), | ||
client_metadata: vJarmClientMetadataEncrypt, | ||
}), | ||
v.object({ | ||
type: v.literal('signed encrypted'), | ||
client_metadata: vJarmClientMetadataSignEncrypt, | ||
}), | ||
]); | ||
|
||
export const jarmMetadataValidate = (vJarmMetadataValidate: JarmMetadataValidate): v.InferOutput<typeof vJarmMetadataValidateOut> => { | ||
const { client_metadata, server_metadata } = vJarmMetadataValidate; | ||
|
||
assertValueSupported({ | ||
supported: server_metadata.authorization_signing_alg_values_supported ?? [], | ||
actual: client_metadata.authorization_signed_response_alg, | ||
required: !!client_metadata.authorization_signed_response_alg, | ||
error: new Error('Invalid authorization_signed_response_alg'), | ||
}); | ||
|
||
assertValueSupported({ | ||
supported: server_metadata.authorization_encryption_alg_values_supported ?? [], | ||
actual: client_metadata.authorization_encrypted_response_alg, | ||
required: !!client_metadata.authorization_encrypted_response_alg, | ||
error: new Error('Invalid authorization_encrypted_response_alg'), | ||
}); | ||
|
||
assertValueSupported({ | ||
supported: server_metadata.authorization_encryption_enc_values_supported ?? [], | ||
actual: client_metadata.authorization_encrypted_response_enc, | ||
required: !!client_metadata.authorization_encrypted_response_enc, | ||
error: new Error('Invalid authorization_encrypted_response_enc'), | ||
}); | ||
|
||
if ( | ||
client_metadata.authorization_signed_response_alg && | ||
client_metadata.authorization_encrypted_response_alg && | ||
client_metadata.authorization_encrypted_response_enc | ||
) { | ||
return { | ||
type: 'signed encrypted', | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
client_metadata: client_metadata as any, | ||
}; | ||
} else if ( | ||
client_metadata.authorization_signed_response_alg && | ||
!client_metadata.authorization_encrypted_response_alg && | ||
!client_metadata.authorization_encrypted_response_enc | ||
) { | ||
return { | ||
type: 'signed', | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
client_metadata: client_metadata as any, | ||
}; | ||
} else if ( | ||
!client_metadata.authorization_signed_response_alg && | ||
client_metadata.authorization_encrypted_response_alg && | ||
client_metadata.authorization_encrypted_response_enc | ||
) { | ||
return { | ||
type: 'encrypted', | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
client_metadata: client_metadata as any, | ||
}; | ||
} else { | ||
throw new Error(`Invalid jarm client_metadata combination`); | ||
} | ||
}; |
43 changes: 0 additions & 43 deletions
43
packages/jarm/lib/metadata/v-jarm-client-metadata-params.ts
This file was deleted.
Oops, something went wrong.
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,42 @@ | ||
import * as v from 'valibot'; | ||
|
||
export const vJarmClientMetadataSign = v.object({ | ||
authorization_signed_response_alg: v.pipe( | ||
v.optional(v.string()), // @default 'RS256' This makes no sense with openid4vp if just encrypted can be specified | ||
v.description( | ||
'JWA. If this is specified, the response will be signed using JWS and the configured algorithm. The algorithm none is not allowed.', | ||
), | ||
), | ||
|
||
authorization_encrypted_response_alg: v.optional(v.never()), | ||
authorization_encrypted_response_enc: v.optional(v.never()), | ||
}); | ||
|
||
export const vJarmClientMetadataEncrypt = v.object({ | ||
authorization_signed_response_alg: v.optional(v.never()), | ||
authorization_encrypted_response_alg: v.pipe( | ||
v.string(), | ||
v.description( | ||
'JWE alg algorithm JWA. If both signing and encryption are requested, the response will be signed then encrypted with the provided algorithm.', | ||
), | ||
), | ||
|
||
authorization_encrypted_response_enc: v.pipe( | ||
v.optional(v.string(), 'A128CBC-HS256'), | ||
v.description( | ||
'JWE enc algorithm JWA. If both signing and encryption are requested, the response will be signed then encrypted with the provided algorithm.', | ||
), | ||
), | ||
}); | ||
|
||
export const vJarmClientMetadataSignEncrypt = v.object({ | ||
...v.pick(vJarmClientMetadataSign, ['authorization_signed_response_alg']).entries, | ||
...v.pick(vJarmClientMetadataEncrypt, ['authorization_encrypted_response_alg', 'authorization_encrypted_response_enc']).entries, | ||
}); | ||
|
||
/** | ||
* Clients may register their public encryption keys using the jwks_uri or jwks metadata parameters. | ||
*/ | ||
export const vJarmClientMetadata = v.union([vJarmClientMetadataSign, vJarmClientMetadataEncrypt, vJarmClientMetadataSignEncrypt]); | ||
|
||
export type JarmClientMetadata = v.InferInput<typeof vJarmClientMetadata>; |
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
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