-
Notifications
You must be signed in to change notification settings - Fork 2
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
2a9ce37
commit d76efe4
Showing
15 changed files
with
343 additions
and
286 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,3 +1,4 @@ | ||
export * from './jarm-auth-response-create/index.js'; | ||
export * from './jarm-auth-response-send/index.js'; | ||
export * from './jarm-auth-response/index.js'; | ||
export * from './metadata/index.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 @@ | ||
export * from './jarm-auth-response-create.js'; |
78 changes: 78 additions & 0 deletions
78
packages/jarm/src/jarm-auth-response-create/jarm-auth-response-create.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,78 @@ | ||
import type { PickDeep } from '@protokoll/core'; | ||
import * as v from 'valibot'; | ||
|
||
import type { JoseContext } from '@protokoll/jose'; | ||
import { | ||
JoseJweEncryptCompact, | ||
JoseJweEncryptJwt, | ||
JoseJwsSignJwt, | ||
} from '@protokoll/jose'; | ||
|
||
import { vJarmAuthResponseEncrypted as vJarmEncryptedOnlyAuthResponse } from '../jarm-auth-response/v-jarm-auth-response-encrypted.js'; | ||
import { vJarmAuthResponse } from '../jarm-auth-response/v-jarm-auth-response.js'; | ||
|
||
export namespace JarmAuthResponseCreate { | ||
export const vInput = v.variant('type', [ | ||
v.object({ | ||
type: v.literal('signed'), | ||
authResponse: vJarmAuthResponse, | ||
jwsSignJwtInput: v.omit(JoseJwsSignJwt.vInput, ['payload']), | ||
}), | ||
v.object({ | ||
type: v.literal('encrypted'), | ||
authResponse: vJarmEncryptedOnlyAuthResponse, | ||
jweEncryptJwtInput: v.omit(JoseJweEncryptJwt.vInput, ['payload']), | ||
}), | ||
v.object({ | ||
type: v.literal('signed encrypted'), | ||
authResponse: vJarmAuthResponse, | ||
jwsSignJwtInput: v.omit(JoseJwsSignJwt.vInput, ['payload']), | ||
jweEncryptCompactInput: v.omit(JoseJweEncryptCompact.vInput, [ | ||
'plaintext', | ||
]), | ||
}), | ||
]); | ||
export type Input = v.InferOutput<typeof vInput>; | ||
|
||
export const vOut = v.object({ | ||
authResponse: v.string(), | ||
}); | ||
|
||
export type Out = v.InferOutput<typeof vOut>; | ||
|
||
export type Context = PickDeep< | ||
JoseContext, | ||
'jose.jwe.encryptJwt' | 'jose.jws.signJwt' | 'jose.jwe.encryptCompact' | ||
>; | ||
} | ||
|
||
export const jarmAuthResponseCreate = async ( | ||
input: JarmAuthResponseCreate.Input, | ||
ctx: JarmAuthResponseCreate.Context | ||
): Promise<JarmAuthResponseCreate.Out> => { | ||
const { type, authResponse } = input; | ||
if (input.type === 'encrypted') { | ||
const { jwe } = await ctx.jose.jwe.encryptJwt({ | ||
...input.jweEncryptJwtInput, | ||
payload: authResponse, | ||
}); | ||
return { authResponse: jwe }; | ||
} else if (type === 'signed') { | ||
const { jws } = await ctx.jose.jws.signJwt({ | ||
...input.jwsSignJwtInput, | ||
payload: authResponse, | ||
}); | ||
return { authResponse: jws }; | ||
} else { | ||
const { jws } = await ctx.jose.jws.signJwt({ | ||
...input.jwsSignJwtInput, | ||
payload: authResponse, | ||
}); | ||
const { jwe } = await ctx.jose.jwe.encryptCompact({ | ||
...input.jweEncryptCompactInput, | ||
plaintext: jws, | ||
}); | ||
|
||
return { authResponse: jwe }; | ||
} | ||
}; |
7 changes: 0 additions & 7 deletions
7
packages/jarm/src/jarm-auth-response-send/c-jarm-auth-response-send.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
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,4 +1,3 @@ | ||
export * from './c-jarm-auth-response.js'; | ||
export * from './jarm-auth-response.js'; | ||
export * from './jarm-auth-response-encrypted.js'; | ||
export * from './v-jarm-auth-response-encrypted.js'; | ||
export * from './v-jarm-auth-response.js'; | ||
export * from './v-jarm-direct-post-jwt-auth-response.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
2 changes: 1 addition & 1 deletion
2
packages/jarm/src/jarm-auth-response/jarm-auth-response.fixtures.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
Oops, something went wrong.