@sphereon/jarm 0.17.0 → 0.17.1-feature.esm.cjs.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +516 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +286 -0
- package/dist/index.d.ts +286 -4
- package/dist/index.js +462 -17
- package/dist/index.js.map +1 -1
- package/package.json +21 -12
- package/dist/index.d.ts.map +0 -1
- package/dist/jarm-auth-response/c-jarm-auth-response.d.ts +0 -55
- package/dist/jarm-auth-response/c-jarm-auth-response.d.ts.map +0 -1
- package/dist/jarm-auth-response/c-jarm-auth-response.js +0 -45
- package/dist/jarm-auth-response/c-jarm-auth-response.js.map +0 -1
- package/dist/jarm-auth-response/index.d.ts +0 -5
- package/dist/jarm-auth-response/index.d.ts.map +0 -1
- package/dist/jarm-auth-response/index.js +0 -21
- package/dist/jarm-auth-response/index.js.map +0 -1
- package/dist/jarm-auth-response/jarm-auth-response.d.ts +0 -48
- package/dist/jarm-auth-response/jarm-auth-response.d.ts.map +0 -1
- package/dist/jarm-auth-response/jarm-auth-response.js +0 -113
- package/dist/jarm-auth-response/jarm-auth-response.js.map +0 -1
- package/dist/jarm-auth-response/v-jarm-auth-response-params.d.ts +0 -31
- package/dist/jarm-auth-response/v-jarm-auth-response-params.d.ts.map +0 -1
- package/dist/jarm-auth-response/v-jarm-auth-response-params.js +0 -67
- package/dist/jarm-auth-response/v-jarm-auth-response-params.js.map +0 -1
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.d.ts +0 -18
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.d.ts.map +0 -1
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.js +0 -38
- package/dist/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.js.map +0 -1
- package/dist/jarm-auth-response-send/index.d.ts +0 -2
- package/dist/jarm-auth-response-send/index.d.ts.map +0 -1
- package/dist/jarm-auth-response-send/index.js +0 -18
- package/dist/jarm-auth-response-send/index.js.map +0 -1
- package/dist/jarm-auth-response-send/jarm-auth-response-send.d.ts +0 -17
- package/dist/jarm-auth-response-send/jarm-auth-response-send.d.ts.map +0 -1
- package/dist/jarm-auth-response-send/jarm-auth-response-send.js +0 -67
- package/dist/jarm-auth-response-send/jarm-auth-response-send.js.map +0 -1
- package/dist/metadata/index.d.ts +0 -4
- package/dist/metadata/index.d.ts.map +0 -1
- package/dist/metadata/index.js +0 -20
- package/dist/metadata/index.js.map +0 -1
- package/dist/metadata/jarm-validate-metadata.d.ts +0 -74
- package/dist/metadata/jarm-validate-metadata.d.ts.map +0 -1
- package/dist/metadata/jarm-validate-metadata.js +0 -98
- package/dist/metadata/jarm-validate-metadata.js.map +0 -1
- package/dist/metadata/v-jarm-client-metadata.d.ts +0 -34
- package/dist/metadata/v-jarm-client-metadata.d.ts.map +0 -1
- package/dist/metadata/v-jarm-client-metadata.js +0 -44
- package/dist/metadata/v-jarm-client-metadata.js.map +0 -1
- package/dist/metadata/v-jarm-server-metadata.d.ts +0 -11
- package/dist/metadata/v-jarm-server-metadata.d.ts.map +0 -1
- package/dist/metadata/v-jarm-server-metadata.js +0 -36
- package/dist/metadata/v-jarm-server-metadata.js.map +0 -1
- package/dist/utils.d.ts +0 -17
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -33
- package/dist/utils.js.map +0 -1
- package/dist/v-response-mode-registry.d.ts +0 -30
- package/dist/v-response-mode-registry.d.ts.map +0 -1
- package/dist/v-response-mode-registry.js +0 -90
- package/dist/v-response-mode-registry.js.map +0 -1
- package/dist/v-response-type-registry.d.ts +0 -9
- package/dist/v-response-type-registry.d.ts.map +0 -1
- package/dist/v-response-type-registry.js +0 -38
- package/dist/v-response-type-registry.js.map +0 -1
- package/lib/__tests__/jarm.spec.ts +0 -5
- package/lib/index.ts +0 -3
- package/lib/jarm-auth-response/c-jarm-auth-response.ts +0 -41
- package/lib/jarm-auth-response/index.ts +0 -4
- package/lib/jarm-auth-response/jarm-auth-response.ts +0 -106
- package/lib/jarm-auth-response/v-jarm-auth-response-params.ts +0 -62
- package/lib/jarm-auth-response/v-jarm-direct-post-jwt-auth-response-params.ts +0 -26
- package/lib/jarm-auth-response-send/index.ts +0 -1
- package/lib/jarm-auth-response-send/jarm-auth-response-send.ts +0 -76
- package/lib/metadata/index.ts +0 -3
- package/lib/metadata/jarm-validate-metadata.ts +0 -80
- package/lib/metadata/v-jarm-client-metadata.ts +0 -42
- package/lib/metadata/v-jarm-server-metadata.ts +0 -29
- package/lib/utils.ts +0 -42
- package/lib/v-response-mode-registry.ts +0 -81
- package/lib/v-response-type-registry.ts +0 -23
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.vResponseType = exports.vTransformedResponseTypes = exports.openid4vpResponseTypes = exports.oAuthMRTEPResponseTypes = exports.oAuthResponseTypes = void 0;
|
|
27
|
-
const v = __importStar(require("valibot"));
|
|
28
|
-
exports.oAuthResponseTypes = v.picklist(['code', 'token']);
|
|
29
|
-
// NOTE: MAKE SURE THAT THE RESPONSE TYPES ARE SORTED CORRECTLY
|
|
30
|
-
exports.oAuthMRTEPResponseTypes = v.picklist(['none', 'id_token', 'code token', 'code id_token', 'id_token token', 'code id_token token']);
|
|
31
|
-
exports.openid4vpResponseTypes = v.picklist(['vp_token', 'id_token vp_token']);
|
|
32
|
-
exports.vTransformedResponseTypes = v.picklist([
|
|
33
|
-
...exports.openid4vpResponseTypes.options,
|
|
34
|
-
...exports.oAuthResponseTypes.options,
|
|
35
|
-
...exports.oAuthMRTEPResponseTypes.options,
|
|
36
|
-
]);
|
|
37
|
-
exports.vResponseType = v.pipe(v.string(), v.transform((val) => val.split(' ').sort().join(' ')), exports.vTransformedResponseTypes);
|
|
38
|
-
//# sourceMappingURL=v-response-type-registry.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"v-response-type-registry.js","sourceRoot":"","sources":["../lib/v-response-type-registry.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA6B;AAEhB,QAAA,kBAAkB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAEhE,+DAA+D;AAClD,QAAA,uBAAuB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,qBAAqB,CAAC,CAAC,CAAC;AAEnI,QAAA,sBAAsB,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAEvE,QAAA,yBAAyB,GAAG,CAAC,CAAC,QAAQ,CAAC;IAClD,GAAG,8BAAsB,CAAC,OAAO;IACjC,GAAG,0BAAkB,CAAC,OAAO;IAC7B,GAAG,+BAAuB,CAAC,OAAO;CACnC,CAAC,CAAC;AAEU,QAAA,aAAa,GAAG,CAAC,CAAC,IAAI,CACjC,CAAC,CAAC,MAAM,EAAE,EACV,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EACrD,iCAAyB,CAC1B,CAAC"}
|
package/lib/index.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
|
|
3
|
-
import { vJarmResponseMode, vOpenid4vpJarmResponseMode } from '../v-response-mode-registry.js';
|
|
4
|
-
import { vResponseType } from '../v-response-type-registry.js';
|
|
5
|
-
|
|
6
|
-
import type { JarmAuthResponseParams } from './v-jarm-auth-response-params.js';
|
|
7
|
-
import type { JarmDirectPostJwtResponseParams } from './v-jarm-direct-post-jwt-auth-response-params.js';
|
|
8
|
-
|
|
9
|
-
export const vAuthRequestParams = v.looseObject({
|
|
10
|
-
state: v.optional(v.string()),
|
|
11
|
-
response_mode: v.optional(v.union([vJarmResponseMode, vOpenid4vpJarmResponseMode])),
|
|
12
|
-
client_id: v.string(),
|
|
13
|
-
response_type: vResponseType,
|
|
14
|
-
client_metadata: v.looseObject({
|
|
15
|
-
jwks: v.optional(
|
|
16
|
-
v.object({
|
|
17
|
-
keys: v.array(v.looseObject({ kid: v.optional(v.string()), kty: v.string() })),
|
|
18
|
-
}),
|
|
19
|
-
),
|
|
20
|
-
jwks_uri: v.optional(v.string()),
|
|
21
|
-
}),
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
export type AuthRequestParams = v.InferInput<typeof vAuthRequestParams>;
|
|
25
|
-
|
|
26
|
-
export const vOAuthAuthRequestGetParamsOut = v.object({
|
|
27
|
-
authRequestParams: vAuthRequestParams,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
export type OAuthAuthRequestGetParamsOut = v.InferOutput<typeof vOAuthAuthRequestGetParamsOut>;
|
|
31
|
-
|
|
32
|
-
export interface JarmDirectPostJwtAuthResponseValidationContext {
|
|
33
|
-
openid4vp: {
|
|
34
|
-
authRequest: {
|
|
35
|
-
getParams: (input: JarmAuthResponseParams | JarmDirectPostJwtResponseParams) => Promise<OAuthAuthRequestGetParamsOut>;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
jwe: {
|
|
39
|
-
decryptCompact: (input: { jwe: string; jwk: { kid: string } }) => Promise<{ plaintext: string }>;
|
|
40
|
-
};
|
|
41
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { decodeProtectedHeader, isJwe, isJws } from '@sphereon/oid4vc-common';
|
|
2
|
-
import * as v from 'valibot';
|
|
3
|
-
|
|
4
|
-
import type { JarmDirectPostJwtResponseParams } from '../index.js';
|
|
5
|
-
|
|
6
|
-
import type { AuthRequestParams, JarmDirectPostJwtAuthResponseValidationContext } from './c-jarm-auth-response.js';
|
|
7
|
-
import { vJarmAuthResponseErrorParams } from './v-jarm-auth-response-params.js';
|
|
8
|
-
import { jarmAuthResponseDirectPostValidateParams, vJarmDirectPostJwtParams } from './v-jarm-direct-post-jwt-auth-response-params.js';
|
|
9
|
-
|
|
10
|
-
export interface JarmDirectPostJwtAuthResponseValidation {
|
|
11
|
-
/**
|
|
12
|
-
* The JARM response parameter conveyed either as url query param, fragment param, or application/x-www-form-urlencoded in the body of a post request
|
|
13
|
-
*/
|
|
14
|
-
response: string;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const parseJarmAuthResponseParams = <Schema extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>>>(
|
|
18
|
-
schema: Schema,
|
|
19
|
-
responseParams: unknown,
|
|
20
|
-
) => {
|
|
21
|
-
if (v.is(vJarmAuthResponseErrorParams, responseParams)) {
|
|
22
|
-
const errorResponseJson = JSON.stringify(responseParams, undefined, 2);
|
|
23
|
-
throw new Error(`Received error response from authorization server. '${errorResponseJson}'`);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return v.parse(schema, responseParams);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const decryptJarmAuthResponse = async (input: { response: string }, ctx: JarmDirectPostJwtAuthResponseValidationContext) => {
|
|
30
|
-
const { response } = input;
|
|
31
|
-
|
|
32
|
-
const responseProtectedHeader = decodeProtectedHeader(response);
|
|
33
|
-
if (!responseProtectedHeader.kid) {
|
|
34
|
-
throw new Error(`Jarm JWE is missing the protected header field 'kid'.`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const { plaintext } = await ctx.jwe.decryptCompact({
|
|
38
|
-
jwe: response,
|
|
39
|
-
jwk: { kid: responseProtectedHeader.kid },
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return plaintext;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Validate a JARM direct_post.jwt compliant authentication response
|
|
47
|
-
* * The decryption key should be resolvable using the the protected header's 'kid' field
|
|
48
|
-
* * The signature verification jwk should be resolvable using the jws protected header's 'kid' field and the payload's 'iss' field.
|
|
49
|
-
*/
|
|
50
|
-
export const jarmAuthResponseDirectPostJwtValidate = async (
|
|
51
|
-
input: JarmDirectPostJwtAuthResponseValidation,
|
|
52
|
-
ctx: JarmDirectPostJwtAuthResponseValidationContext,
|
|
53
|
-
) => {
|
|
54
|
-
const { response } = input;
|
|
55
|
-
|
|
56
|
-
const responseIsEncrypted = isJwe(response);
|
|
57
|
-
const decryptedResponse = responseIsEncrypted ? await decryptJarmAuthResponse(input, ctx) : response;
|
|
58
|
-
|
|
59
|
-
const responseIsSigned = isJws(decryptedResponse);
|
|
60
|
-
if (!responseIsEncrypted && !responseIsSigned) {
|
|
61
|
-
throw new Error('Jarm Auth Response must be either encrypted, signed, or signed and encrypted.');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let authResponseParams: JarmDirectPostJwtResponseParams;
|
|
65
|
-
let authRequestParams: AuthRequestParams;
|
|
66
|
-
|
|
67
|
-
if (responseIsSigned) {
|
|
68
|
-
throw new Error('Signed JARM responses are not supported.');
|
|
69
|
-
//const jwsProtectedHeader = decodeProtectedHeader(decryptedResponse);
|
|
70
|
-
//const jwsPayload = decodeJwt(decryptedResponse);
|
|
71
|
-
|
|
72
|
-
//const schema = v.required(vJarmDirectPostJwtParams, ['iss', 'aud', 'exp']);
|
|
73
|
-
//const responseParams = parseJarmAuthResponseParams(schema, jwsPayload);
|
|
74
|
-
//({ authRequestParams } = await ctx.openid4vp.authRequest.getParams(responseParams));
|
|
75
|
-
|
|
76
|
-
//if (!jwsProtectedHeader.kid) {
|
|
77
|
-
//throw new Error(`Jarm JWS is missing the protected header field 'kid'.`);
|
|
78
|
-
//}
|
|
79
|
-
|
|
80
|
-
//await ctx.jose.jws.verifyJwt({
|
|
81
|
-
//jws: decryptedResponse,
|
|
82
|
-
//jwk: { kid: jwsProtectedHeader.kid, kty: 'auto' },
|
|
83
|
-
//});
|
|
84
|
-
//authResponseParams = responseParams;
|
|
85
|
-
} else {
|
|
86
|
-
const jsonResponse: unknown = JSON.parse(decryptedResponse);
|
|
87
|
-
authResponseParams = parseJarmAuthResponseParams(vJarmDirectPostJwtParams, jsonResponse);
|
|
88
|
-
({ authRequestParams } = await ctx.openid4vp.authRequest.getParams(authResponseParams));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
jarmAuthResponseDirectPostValidateParams({
|
|
92
|
-
authRequestParams,
|
|
93
|
-
authResponseParams,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
let type: 'signed encrypted' | 'encrypted' | 'signed';
|
|
97
|
-
if (responseIsSigned && responseIsEncrypted) type = 'signed encrypted';
|
|
98
|
-
else if (responseIsEncrypted) type = 'encrypted';
|
|
99
|
-
else type = 'signed';
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
authRequestParams,
|
|
103
|
-
authResponseParams,
|
|
104
|
-
type,
|
|
105
|
-
};
|
|
106
|
-
};
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { checkExp } from '@sphereon/oid4vc-common';
|
|
2
|
-
import * as v from 'valibot';
|
|
3
|
-
|
|
4
|
-
export const vJarmAuthResponseErrorParams = v.looseObject({
|
|
5
|
-
error: v.string(),
|
|
6
|
-
state: v.optional(v.string()),
|
|
7
|
-
|
|
8
|
-
error_description: v.pipe(
|
|
9
|
-
v.optional(v.string()),
|
|
10
|
-
v.description('Text providing additional information, used to assist the client developer in understanding the error that occurred.'),
|
|
11
|
-
),
|
|
12
|
-
|
|
13
|
-
error_uri: v.pipe(
|
|
14
|
-
v.optional(v.pipe(v.string(), v.url())),
|
|
15
|
-
v.description(
|
|
16
|
-
'A URI identifying a human-readable web page with information about the error, used to provide the client developer with additional information about the error',
|
|
17
|
-
),
|
|
18
|
-
),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export const vJarmAuthResponseParams = v.looseObject({
|
|
22
|
-
state: v.optional(v.string()),
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The issuer URL of the authorization server that created the response
|
|
26
|
-
*/
|
|
27
|
-
iss: v.string(),
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Expiration of the JWT
|
|
31
|
-
*/
|
|
32
|
-
exp: v.number(),
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The client_id of the client the response is intended for
|
|
36
|
-
*/
|
|
37
|
-
aud: v.string(),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
export type JarmAuthResponseParams = v.InferInput<typeof vJarmAuthResponseParams>;
|
|
41
|
-
|
|
42
|
-
export const validateJarmAuthResponseParams = (input: {
|
|
43
|
-
authRequestParams: { client_id: string; state?: string };
|
|
44
|
-
authResponseParams: JarmAuthResponseParams;
|
|
45
|
-
}) => {
|
|
46
|
-
const { authRequestParams, authResponseParams } = input;
|
|
47
|
-
// 2. The client obtains the state parameter from the JWT and checks its binding to the user agent. If the check fails, the client MUST abort processing and refuse the response.
|
|
48
|
-
if (authRequestParams.state !== authResponseParams.state) {
|
|
49
|
-
throw new Error(`State missmatch in jarm-auth-response. Expected '${authRequestParams.state}' received '${authRequestParams.state}'.`);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 4. The client obtains the aud element from the JWT and checks whether it matches the client id the client used to identify itself in the corresponding authorization request. If the check fails, the client MUST abort processing and refuse the response.
|
|
53
|
-
if (authRequestParams.client_id !== authResponseParams.aud) {
|
|
54
|
-
throw new Error(`Invalid audience in jarm-auth-response. Expected '${authRequestParams.client_id}' received '${authResponseParams.aud}'.`);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 5. The client checks the JWT's exp element to determine if the JWT is still valid. If the check fails, the client MUST abort processing and refuse the response.
|
|
58
|
-
// 120 seconds clock skew
|
|
59
|
-
if (checkExp({ exp: authResponseParams.exp })) {
|
|
60
|
-
throw new Error(`The '${authRequestParams.state}' and the jarm-auth-response.`);
|
|
61
|
-
}
|
|
62
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
|
|
3
|
-
import { vJarmAuthResponseParams } from './v-jarm-auth-response-params.js';
|
|
4
|
-
|
|
5
|
-
export const vJarmDirectPostJwtParams = v.looseObject({
|
|
6
|
-
...v.omit(vJarmAuthResponseParams, ['iss', 'aud', 'exp']).entries,
|
|
7
|
-
...v.partial(v.pick(vJarmAuthResponseParams, ['iss', 'aud', 'exp'])).entries,
|
|
8
|
-
|
|
9
|
-
vp_token: v.union([v.string(), v.array(v.pipe(v.string(), v.nonEmpty()))]),
|
|
10
|
-
presentation_submission: v.unknown(),
|
|
11
|
-
nonce: v.optional(v.string()),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
export type JarmDirectPostJwtResponseParams = v.InferInput<typeof vJarmDirectPostJwtParams>;
|
|
15
|
-
|
|
16
|
-
export const jarmAuthResponseDirectPostValidateParams = (input: {
|
|
17
|
-
authRequestParams: { state?: string };
|
|
18
|
-
authResponseParams: JarmDirectPostJwtResponseParams;
|
|
19
|
-
}) => {
|
|
20
|
-
const { authRequestParams, authResponseParams } = input;
|
|
21
|
-
|
|
22
|
-
// 2. The client obtains the state parameter from the JWT and checks its binding to the user agent. If the check fails, the client MUST abort processing and refuse the response.
|
|
23
|
-
if (authRequestParams.state !== authResponseParams.state) {
|
|
24
|
-
throw new Error(`State missmatch between auth request '${authRequestParams.state}' and the jarm-auth-response.`);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './jarm-auth-response-send.js';
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { appendFragmentParams, appendQueryParams } from '../utils.js';
|
|
2
|
-
import type { JarmResponseMode, Openid4vpJarmResponseMode } from '../v-response-mode-registry.js';
|
|
3
|
-
import { getJarmDefaultResponseMode, validateResponseMode } from '../v-response-mode-registry.js';
|
|
4
|
-
import type { ResponseTypeOut } from '../v-response-type-registry.js';
|
|
5
|
-
|
|
6
|
-
interface JarmAuthResponseSendInput {
|
|
7
|
-
authRequestParams: {
|
|
8
|
-
response_mode?: JarmResponseMode | Openid4vpJarmResponseMode;
|
|
9
|
-
response_type: ResponseTypeOut;
|
|
10
|
-
} & (
|
|
11
|
-
| {
|
|
12
|
-
response_uri: string;
|
|
13
|
-
}
|
|
14
|
-
| {
|
|
15
|
-
redirect_uri: string;
|
|
16
|
-
}
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
authResponse: string;
|
|
20
|
-
state: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const jarmAuthResponseSend = async (input: JarmAuthResponseSendInput): Promise<Response> => {
|
|
24
|
-
const { authRequestParams, authResponse, state } = input;
|
|
25
|
-
|
|
26
|
-
const responseEndpoint = 'response_uri' in authRequestParams ? new URL(authRequestParams.response_uri) : new URL(authRequestParams.redirect_uri);
|
|
27
|
-
|
|
28
|
-
const responseMode =
|
|
29
|
-
authRequestParams.response_mode && authRequestParams.response_mode !== 'jwt'
|
|
30
|
-
? authRequestParams.response_mode
|
|
31
|
-
: getJarmDefaultResponseMode(authRequestParams);
|
|
32
|
-
|
|
33
|
-
validateResponseMode({
|
|
34
|
-
response_type: authRequestParams.response_type,
|
|
35
|
-
response_mode: responseMode,
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
switch (responseMode) {
|
|
39
|
-
case 'direct_post.jwt':
|
|
40
|
-
return handleDirectPostJwt(responseEndpoint, authResponse, state);
|
|
41
|
-
case 'query.jwt':
|
|
42
|
-
return handleQueryJwt(responseEndpoint, authResponse, state);
|
|
43
|
-
case 'fragment.jwt':
|
|
44
|
-
return handleFragmentJwt(responseEndpoint, authResponse, state);
|
|
45
|
-
case 'form_post.jwt':
|
|
46
|
-
throw new Error('Not implemented. form_post.jwt is not yet supported.');
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
async function handleDirectPostJwt(responseEndpoint: URL, responseJwt: string, state: string) {
|
|
51
|
-
const response = await fetch(responseEndpoint, {
|
|
52
|
-
method: 'POST',
|
|
53
|
-
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
54
|
-
body: `response=${responseJwt}&state=${state}`,
|
|
55
|
-
});
|
|
56
|
-
return response;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function handleQueryJwt(responseEndpoint: URL, responseJwt: string, state: string) {
|
|
60
|
-
const responseUrl = appendQueryParams({
|
|
61
|
-
url: responseEndpoint,
|
|
62
|
-
params: { response: responseJwt, state },
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const response = await fetch(responseUrl, { method: 'POST' });
|
|
66
|
-
return response;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
async function handleFragmentJwt(responseEndpoint: URL, responseJwt: string, state: string) {
|
|
70
|
-
const responseUrl = appendFragmentParams({
|
|
71
|
-
url: responseEndpoint,
|
|
72
|
-
fragments: { response: responseJwt, state },
|
|
73
|
-
});
|
|
74
|
-
const response = await fetch(responseUrl, { method: 'POST' });
|
|
75
|
-
return response;
|
|
76
|
-
}
|
package/lib/metadata/index.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
vJarmClientMetadata,
|
|
5
|
-
vJarmClientMetadataEncrypt,
|
|
6
|
-
vJarmClientMetadataSign,
|
|
7
|
-
vJarmClientMetadataSignEncrypt,
|
|
8
|
-
} from '../metadata/v-jarm-client-metadata.js';
|
|
9
|
-
import { vJarmServerMetadata } from '../metadata/v-jarm-server-metadata.js';
|
|
10
|
-
import { assertValueSupported } from '../utils.js';
|
|
11
|
-
|
|
12
|
-
export const vJarmAuthResponseValidateMetadataInput = v.object({
|
|
13
|
-
client_metadata: vJarmClientMetadata,
|
|
14
|
-
server_metadata: v.partial(vJarmServerMetadata),
|
|
15
|
-
});
|
|
16
|
-
export type JarmMetadataValidate = v.InferInput<typeof vJarmAuthResponseValidateMetadataInput>;
|
|
17
|
-
|
|
18
|
-
export const vJarmMetadataValidateOut = v.variant('type', [
|
|
19
|
-
v.object({
|
|
20
|
-
type: v.literal('signed'),
|
|
21
|
-
client_metadata: vJarmClientMetadataSign,
|
|
22
|
-
}),
|
|
23
|
-
v.object({
|
|
24
|
-
type: v.literal('encrypted'),
|
|
25
|
-
client_metadata: vJarmClientMetadataEncrypt,
|
|
26
|
-
}),
|
|
27
|
-
v.object({
|
|
28
|
-
type: v.literal('signed encrypted'),
|
|
29
|
-
client_metadata: vJarmClientMetadataSignEncrypt,
|
|
30
|
-
}),
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
export const jarmMetadataValidate = (vJarmMetadataValidate: JarmMetadataValidate): v.InferOutput<typeof vJarmMetadataValidateOut> => {
|
|
34
|
-
const { client_metadata, server_metadata } = vJarmMetadataValidate;
|
|
35
|
-
const { authorization_encrypted_response_alg, authorization_encrypted_response_enc, authorization_signed_response_alg } = client_metadata;
|
|
36
|
-
|
|
37
|
-
assertValueSupported({
|
|
38
|
-
supported: server_metadata.authorization_signing_alg_values_supported ?? [],
|
|
39
|
-
actual: authorization_signed_response_alg,
|
|
40
|
-
required: !!authorization_signed_response_alg,
|
|
41
|
-
error: new Error('Invalid authorization_signed_response_alg'),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
assertValueSupported({
|
|
45
|
-
supported: server_metadata.authorization_encryption_alg_values_supported ?? [],
|
|
46
|
-
actual: authorization_encrypted_response_alg,
|
|
47
|
-
required: !!authorization_encrypted_response_alg,
|
|
48
|
-
error: new Error('Invalid authorization_encrypted_response_alg'),
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
assertValueSupported({
|
|
52
|
-
supported: server_metadata.authorization_encryption_enc_values_supported ?? [],
|
|
53
|
-
actual: authorization_encrypted_response_enc,
|
|
54
|
-
required: !!authorization_encrypted_response_enc,
|
|
55
|
-
error: new Error('Invalid authorization_encrypted_response_enc'),
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
if (authorization_signed_response_alg && authorization_encrypted_response_alg && authorization_encrypted_response_enc) {
|
|
59
|
-
return {
|
|
60
|
-
type: 'signed encrypted',
|
|
61
|
-
client_metadata: {
|
|
62
|
-
authorization_signed_response_alg,
|
|
63
|
-
authorization_encrypted_response_alg,
|
|
64
|
-
authorization_encrypted_response_enc,
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
} else if (authorization_signed_response_alg && !authorization_encrypted_response_alg && !authorization_encrypted_response_enc) {
|
|
68
|
-
return {
|
|
69
|
-
type: 'signed',
|
|
70
|
-
client_metadata: { authorization_signed_response_alg },
|
|
71
|
-
};
|
|
72
|
-
} else if (!authorization_signed_response_alg && authorization_encrypted_response_alg && authorization_encrypted_response_enc) {
|
|
73
|
-
return {
|
|
74
|
-
type: 'encrypted',
|
|
75
|
-
client_metadata: { authorization_encrypted_response_alg, authorization_encrypted_response_enc },
|
|
76
|
-
};
|
|
77
|
-
} else {
|
|
78
|
-
throw new Error(`Invalid jarm client_metadata combination`);
|
|
79
|
-
}
|
|
80
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
|
|
3
|
-
export const vJarmClientMetadataSign = v.object({
|
|
4
|
-
authorization_signed_response_alg: v.pipe(
|
|
5
|
-
v.optional(v.string()), // @default 'RS256' This makes no sense with openid4vp if just encrypted can be specified
|
|
6
|
-
v.description(
|
|
7
|
-
'JWA. If this is specified, the response will be signed using JWS and the configured algorithm. The algorithm none is not allowed.',
|
|
8
|
-
),
|
|
9
|
-
),
|
|
10
|
-
|
|
11
|
-
authorization_encrypted_response_alg: v.optional(v.never()),
|
|
12
|
-
authorization_encrypted_response_enc: v.optional(v.never()),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
export const vJarmClientMetadataEncrypt = v.object({
|
|
16
|
-
authorization_signed_response_alg: v.optional(v.never()),
|
|
17
|
-
authorization_encrypted_response_alg: v.pipe(
|
|
18
|
-
v.string(),
|
|
19
|
-
v.description(
|
|
20
|
-
'JWE alg algorithm JWA. If both signing and encryption are requested, the response will be signed then encrypted with the provided algorithm.',
|
|
21
|
-
),
|
|
22
|
-
),
|
|
23
|
-
|
|
24
|
-
authorization_encrypted_response_enc: v.pipe(
|
|
25
|
-
v.optional(v.string(), 'A128CBC-HS256'),
|
|
26
|
-
v.description(
|
|
27
|
-
'JWE enc algorithm JWA. If both signing and encryption are requested, the response will be signed then encrypted with the provided algorithm.',
|
|
28
|
-
),
|
|
29
|
-
),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
export const vJarmClientMetadataSignEncrypt = v.object({
|
|
33
|
-
...v.pick(vJarmClientMetadataSign, ['authorization_signed_response_alg']).entries,
|
|
34
|
-
...v.pick(vJarmClientMetadataEncrypt, ['authorization_encrypted_response_alg', 'authorization_encrypted_response_enc']).entries,
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Clients may register their public encryption keys using the jwks_uri or jwks metadata parameters.
|
|
39
|
-
*/
|
|
40
|
-
export const vJarmClientMetadata = v.union([vJarmClientMetadataSign, vJarmClientMetadataEncrypt, vJarmClientMetadataSignEncrypt]);
|
|
41
|
-
|
|
42
|
-
export type JarmClientMetadata = v.InferInput<typeof vJarmClientMetadata>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Authorization servers SHOULD publish the supported algorithms for signing and encrypting the JWT of an authorization response by utilizing OAuth 2.0 Authorization Server Metadata [RFC8414] parameters.
|
|
5
|
-
*/
|
|
6
|
-
export const vJarmServerMetadata = v.object({
|
|
7
|
-
authorization_signing_alg_values_supported: v.pipe(
|
|
8
|
-
v.array(v.string()),
|
|
9
|
-
v.description(
|
|
10
|
-
'JSON array containing a list of the JWS [RFC7515] signing algorithms (alg values) JWA [RFC7518] supported by the authorization endpoint to sign the response.',
|
|
11
|
-
),
|
|
12
|
-
),
|
|
13
|
-
|
|
14
|
-
authorization_encryption_alg_values_supported: v.pipe(
|
|
15
|
-
v.array(v.string()),
|
|
16
|
-
v.description(
|
|
17
|
-
'JSON array containing a list of the JWE [RFC7516] encryption algorithms (alg values) JWA [RFC7518] supported by the authorization endpoint to encrypt the response.',
|
|
18
|
-
),
|
|
19
|
-
),
|
|
20
|
-
|
|
21
|
-
authorization_encryption_enc_values_supported: v.pipe(
|
|
22
|
-
v.array(v.string()),
|
|
23
|
-
v.description(
|
|
24
|
-
'JSON array containing a list of the JWE [RFC7516] encryption algorithms (enc values) JWA [RFC7518] supported by the authorization endpoint to encrypt the response.',
|
|
25
|
-
),
|
|
26
|
-
),
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
export type JarmServerMetadata = v.InferInput<typeof vJarmServerMetadata>;
|
package/lib/utils.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export function appendQueryParams(input: { url: URL; params: Record<string, string | number | boolean> }) {
|
|
2
|
-
const { url, params } = input;
|
|
3
|
-
|
|
4
|
-
// Append the new query parameters from the params object
|
|
5
|
-
for (const [key, value] of Object.entries(params)) {
|
|
6
|
-
url.searchParams.append(key, encodeURIComponent(value));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return url;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export function appendFragmentParams(input: { url: URL; fragments: Record<string, string | number | boolean> }) {
|
|
13
|
-
const { url, fragments } = input;
|
|
14
|
-
|
|
15
|
-
// Convert existing fragment to an object and remove the leading '#'
|
|
16
|
-
const fragmentParams = new URLSearchParams(url.hash.slice(1)); // Remove the leading '#' from the fragment
|
|
17
|
-
|
|
18
|
-
// Append the new fragments from the fragments object
|
|
19
|
-
for (const [key, value] of Object.entries(fragments)) {
|
|
20
|
-
fragmentParams.append(key, encodeURIComponent(value));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Rebuild the fragment string and assign it to the URL
|
|
24
|
-
url.hash = fragmentParams.toString();
|
|
25
|
-
|
|
26
|
-
return url;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface AssertValueSupported<T> {
|
|
30
|
-
supported: T[];
|
|
31
|
-
actual: T;
|
|
32
|
-
error: Error;
|
|
33
|
-
required: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function assertValueSupported<T>(input: AssertValueSupported<T>): T | undefined {
|
|
37
|
-
const { required, error, supported, actual } = input;
|
|
38
|
-
const intersection = supported.find((value) => value === actual);
|
|
39
|
-
|
|
40
|
-
if (required && !intersection) throw error;
|
|
41
|
-
return intersection;
|
|
42
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as v from 'valibot';
|
|
2
|
-
|
|
3
|
-
import type { ResponseTypeOut } from './v-response-type-registry.js';
|
|
4
|
-
|
|
5
|
-
export const vJarmResponseMode = v.picklist(['jwt', 'query.jwt', 'fragment.jwt', 'form_post.jwt']);
|
|
6
|
-
export type JarmResponseMode = v.InferInput<typeof vJarmResponseMode>;
|
|
7
|
-
|
|
8
|
-
export const vOpenid4vpResponseMode = v.picklist(['direct_post']);
|
|
9
|
-
export type Openid4vpResponseMode = v.InferInput<typeof vOpenid4vpResponseMode>;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* * 'direct_post.jwt' The response is send as HTTP POST request using the application/x-www-form-urlencoded content type. The body contains a single parameter response which is the JWT encoded Response as defined in JARM 4.1
|
|
13
|
-
*/
|
|
14
|
-
export const vOpenid4vpJarmResponseMode = v.picklist(['direct_post.jwt']);
|
|
15
|
-
export type Openid4vpJarmResponseMode = v.InferInput<typeof vOpenid4vpJarmResponseMode>;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* The use of this parameter is NOT RECOMMENDED when the Response Mode that would be requested is the default mode specified for the Response Type.
|
|
19
|
-
* * 'query' In this mode, Authorization Response parameters are encoded in the query string added to the redirect_uri when redirecting back to the Client.
|
|
20
|
-
* * 'fragment' In this mode, Authorization Response parameters are encoded in the fragment added to the redirect_uri when redirecting back to the Client.
|
|
21
|
-
* * 'direct_post' the Authorization Response is send to an endpoint controlled by the Verifier via an HTTP POST request.
|
|
22
|
-
*/
|
|
23
|
-
export const vResponseMode = v.pipe(
|
|
24
|
-
v.picklist(['query', 'fragment', ...vOpenid4vpResponseMode.options, ...vJarmResponseMode.options, ...vOpenid4vpJarmResponseMode.options]),
|
|
25
|
-
v.description('Informs the Authorization Server of the mechanism to be used for returning parameters from the Authorization Endpoint.'),
|
|
26
|
-
);
|
|
27
|
-
export type ResponseMode = v.InferInput<typeof vResponseMode>;
|
|
28
|
-
|
|
29
|
-
const getDisAllowedResponseModes = (input: { response_type: ResponseTypeOut }): [ResponseMode, ...ResponseMode[]] | undefined => {
|
|
30
|
-
const { response_type } = input;
|
|
31
|
-
|
|
32
|
-
switch (response_type) {
|
|
33
|
-
case 'code token':
|
|
34
|
-
return ['query'];
|
|
35
|
-
case 'code id_token':
|
|
36
|
-
return ['query'];
|
|
37
|
-
case 'id_token token':
|
|
38
|
-
return ['query'];
|
|
39
|
-
case 'code id_token token':
|
|
40
|
-
return ['query'];
|
|
41
|
-
}
|
|
42
|
-
return undefined;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const getDefaultResponseMode = (input: { response_type: ResponseTypeOut }): 'query' | 'fragment' => {
|
|
46
|
-
const { response_type } = input;
|
|
47
|
-
|
|
48
|
-
switch (response_type) {
|
|
49
|
-
case 'code':
|
|
50
|
-
case 'none':
|
|
51
|
-
return 'query';
|
|
52
|
-
case 'token':
|
|
53
|
-
case 'id_token':
|
|
54
|
-
case 'code token':
|
|
55
|
-
case 'code id_token':
|
|
56
|
-
case 'id_token token':
|
|
57
|
-
case 'code id_token token':
|
|
58
|
-
case 'vp_token':
|
|
59
|
-
case 'id_token vp_token':
|
|
60
|
-
return 'fragment';
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const getJarmDefaultResponseMode = (input: { response_type: ResponseTypeOut }): 'query.jwt' | 'fragment.jwt' => {
|
|
65
|
-
const responseMode = getDefaultResponseMode(input);
|
|
66
|
-
|
|
67
|
-
switch (responseMode) {
|
|
68
|
-
case 'query':
|
|
69
|
-
return 'query.jwt';
|
|
70
|
-
case 'fragment':
|
|
71
|
-
return 'fragment.jwt';
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export const validateResponseMode = (input: { response_type: ResponseTypeOut; response_mode: ResponseMode }) => {
|
|
76
|
-
const disallowedResponseModes = getDisAllowedResponseModes(input);
|
|
77
|
-
|
|
78
|
-
if (disallowedResponseModes?.includes(input.response_mode)) {
|
|
79
|
-
throw new Error(`Response_type '${input.response_type}' is not compatible with response_mode '${input.response_mode}'.`);
|
|
80
|
-
}
|
|
81
|
-
};
|