@pagopa/io-wallet-oid4vp 0.4.1
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/README.md +127 -0
- package/dist/index.js +102 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +75 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
## @pagopa/io-wallet-oid4vp
|
|
2
|
+
|
|
3
|
+
This package provides functionalities to manage the **OpenID for Verifiable Presentations (OID4VP)** protocol flow, specifically tailored for the Italian Wallet ecosystem, simplifying QEAA credentials issuance and credentials presentations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
To install the package, use your preferred package manager:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Using pnpm
|
|
11
|
+
pnpm add @pagopa/io-wallet-oid4vp
|
|
12
|
+
|
|
13
|
+
# Using yarn
|
|
14
|
+
yarn add @pagopa/io-wallet-oid4vp
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Verifying a received Request object
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { parseAuthorizeRequest } from '@pagopa/io-wallet-oid4vp';
|
|
23
|
+
|
|
24
|
+
//Request Object JWT containing the requested credentials obtained from the RP
|
|
25
|
+
const requestObjectJwt = "ey..."
|
|
26
|
+
|
|
27
|
+
//Obtain the signer
|
|
28
|
+
const signer = {
|
|
29
|
+
method : 'jwk',
|
|
30
|
+
publicJwk : {/*... jwk details*/},
|
|
31
|
+
alg : 'ES256'
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//Prepare the callbacks
|
|
35
|
+
const callbacks = {
|
|
36
|
+
verifyJwt : async (signer, {header, payload, compact}) => {
|
|
37
|
+
const result = //signature verification
|
|
38
|
+
return {
|
|
39
|
+
verified : result,
|
|
40
|
+
signerJwk : signer.publicJwk //Mandatory only if signature is verified correctly
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//Decode, verify and return the Request Object
|
|
46
|
+
const parsedRequestObject = await parseAuthorizeRequest({
|
|
47
|
+
requestObjectJwt,
|
|
48
|
+
callbacks,
|
|
49
|
+
dpop : {signer}
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API Reference
|
|
54
|
+
|
|
55
|
+
### AuthorizationRequestObject type and Zod parser
|
|
56
|
+
```typescript
|
|
57
|
+
export const zOpenid4vpAuthorizationRequest = z
|
|
58
|
+
.object({
|
|
59
|
+
response_type: z.literal('vp_token'),
|
|
60
|
+
client_id: z.string(),
|
|
61
|
+
response_uri: z.string().url().optional(),
|
|
62
|
+
request_uri: z.string().url().optional(),
|
|
63
|
+
request_uri_method: z.optional(z.string()),
|
|
64
|
+
response_mode: z.literal("direct_post.jwt"),
|
|
65
|
+
nonce: z.string(),
|
|
66
|
+
wallet_nonce: z.string().optional(),
|
|
67
|
+
scope: z.string().optional(),
|
|
68
|
+
dcql_query: z.record(z.string(), z.any()).optional(),
|
|
69
|
+
state: z.string().optional(),
|
|
70
|
+
})
|
|
71
|
+
.passthrough().and(zJwtPayload)
|
|
72
|
+
|
|
73
|
+
export type AuthorizationRequestObject = z.infer<typeof zOpenid4vpAuthorizationRequest>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### parseAuthorizeRequest
|
|
77
|
+
```typescript
|
|
78
|
+
export interface ParseAuthorizeRequestOptions {
|
|
79
|
+
/**
|
|
80
|
+
* The Authorization Request Object JWT.
|
|
81
|
+
*/
|
|
82
|
+
requestObjectJwt : string ;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Callback context for signature verification.
|
|
86
|
+
*/
|
|
87
|
+
callbacks : Pick<CallbackContext, 'verifyJwt'>
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* DPoP options
|
|
91
|
+
*/
|
|
92
|
+
dpop: RequestDpopOptions
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function parseAuthorizeRequest(options: ParseAuthorizeRequestOptions) : Promise<AuthorizationRequestObject> {
|
|
96
|
+
...
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
This method receives a Request Object in JWT format, verifies the signature and returns the decoded Request Object.
|
|
100
|
+
|
|
101
|
+
### Errors
|
|
102
|
+
|
|
103
|
+
```typescript
|
|
104
|
+
export class Oid4vpError extends Error {
|
|
105
|
+
constructor(
|
|
106
|
+
message: string,
|
|
107
|
+
public readonly statusCode?: number,
|
|
108
|
+
) {
|
|
109
|
+
super(message);
|
|
110
|
+
this.name = "Oid4vpError";
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
Generic package level error class which every other package error should extend.
|
|
115
|
+
|
|
116
|
+
```typescript
|
|
117
|
+
export class ParseAuthorizeRequestError extends Oid4vpError {
|
|
118
|
+
constructor(
|
|
119
|
+
message: string,
|
|
120
|
+
public readonly statusCode?: number,
|
|
121
|
+
) {
|
|
122
|
+
super(message);
|
|
123
|
+
this.name = "ParseAuthorizeRequestError";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
Error thrown by `parseAuthorizeRequest` when the passed request object has an invalid signature or unexpected errors are thrown.
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
Oid4vpError: () => Oid4vpError,
|
|
24
|
+
ParseAuthorizeRequestError: () => ParseAuthorizeRequestError,
|
|
25
|
+
parseAuthorizeRequest: () => parseAuthorizeRequest,
|
|
26
|
+
zOpenid4vpAuthorizationRequest: () => zOpenid4vpAuthorizationRequest
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(index_exports);
|
|
29
|
+
|
|
30
|
+
// src/authorization-request/parse-authorization-request.ts
|
|
31
|
+
var import_oauth22 = require("@openid4vc/oauth2");
|
|
32
|
+
var import_utils = require("@openid4vc/utils");
|
|
33
|
+
|
|
34
|
+
// src/errors.ts
|
|
35
|
+
var Oid4vpError = class extends Error {
|
|
36
|
+
constructor(message, statusCode) {
|
|
37
|
+
super(message);
|
|
38
|
+
this.statusCode = statusCode;
|
|
39
|
+
this.name = "Oid4vpError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var ParseAuthorizeRequestError = class extends Oid4vpError {
|
|
43
|
+
constructor(message, statusCode) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.statusCode = statusCode;
|
|
46
|
+
this.name = "ParseAuthorizeRequestError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// src/authorization-request/z-request-object.ts
|
|
51
|
+
var import_oauth2 = require("@openid4vc/oauth2");
|
|
52
|
+
var import_zod = require("zod");
|
|
53
|
+
var zOpenid4vpAuthorizationRequest = import_zod.z.object({
|
|
54
|
+
client_id: import_zod.z.string(),
|
|
55
|
+
dcql_query: import_zod.z.record(import_zod.z.string(), import_zod.z.any()).optional(),
|
|
56
|
+
nonce: import_zod.z.string(),
|
|
57
|
+
request_uri: import_zod.z.string().url().optional(),
|
|
58
|
+
request_uri_method: import_zod.z.optional(import_zod.z.string()),
|
|
59
|
+
response_mode: import_zod.z.literal("direct_post.jwt"),
|
|
60
|
+
response_type: import_zod.z.literal("vp_token"),
|
|
61
|
+
response_uri: import_zod.z.string().url().optional(),
|
|
62
|
+
scope: import_zod.z.string().optional(),
|
|
63
|
+
state: import_zod.z.string().optional(),
|
|
64
|
+
wallet_nonce: import_zod.z.string().optional()
|
|
65
|
+
}).passthrough().and(import_oauth2.zJwtPayload);
|
|
66
|
+
|
|
67
|
+
// src/authorization-request/parse-authorization-request.ts
|
|
68
|
+
async function parseAuthorizeRequest(options) {
|
|
69
|
+
try {
|
|
70
|
+
const decoded = (0, import_oauth22.decodeJwt)({
|
|
71
|
+
jwt: options.requestObjectJwt,
|
|
72
|
+
payloadSchema: zOpenid4vpAuthorizationRequest
|
|
73
|
+
});
|
|
74
|
+
const verificationResult = await options.callbacks.verifyJwt(
|
|
75
|
+
options.dpop.signer,
|
|
76
|
+
{
|
|
77
|
+
compact: options.requestObjectJwt,
|
|
78
|
+
header: decoded.header,
|
|
79
|
+
payload: decoded.payload
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
if (!verificationResult.verified)
|
|
83
|
+
throw new ParseAuthorizeRequestError(
|
|
84
|
+
"Error verifying Request Object signature"
|
|
85
|
+
);
|
|
86
|
+
return decoded.payload;
|
|
87
|
+
} catch (error) {
|
|
88
|
+
if (error instanceof import_utils.ValidationError || error instanceof import_oauth22.Oauth2JwtParseError)
|
|
89
|
+
throw error;
|
|
90
|
+
throw new ParseAuthorizeRequestError(
|
|
91
|
+
`Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
Oid4vpError,
|
|
98
|
+
ParseAuthorizeRequestError,
|
|
99
|
+
parseAuthorizeRequest,
|
|
100
|
+
zOpenid4vpAuthorizationRequest
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/authorization-request/parse-authorization-request.ts","../src/errors.ts","../src/authorization-request/z-request-object.ts"],"sourcesContent":["export * from \"./authorization-request\";\nexport * from \"./errors\";\n","import {\n CallbackContext,\n Oauth2JwtParseError,\n RequestDpopOptions,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\nimport { ValidationError } from \"@openid4vc/utils\";\n\nimport { ParseAuthorizeRequestError } from \"../errors\";\nimport {\n AuthorizationRequestObject,\n zOpenid4vpAuthorizationRequest,\n} from \"./z-request-object\";\n\nexport interface ParseAuthorizeRequestOptions {\n /**\n * Callback context for signature verification.\n */\n callbacks: Pick<CallbackContext, \"verifyJwt\">;\n\n /**\n * DPoP options\n */\n dpop: RequestDpopOptions;\n\n /**\n * The Authorization Request Object JWT.\n */\n requestObjectJwt: string;\n}\n\n/**\n * This method verifies a JWT containing a Request Object and returns its\n * decoded value for further processing\n * @param options {@link ParseAuthorizeRequestOptions}\n * @returns An {@link AuthorizationRequestObject} containing the RP required\n * credentials\n * @throws {@link ValidationError} in case there are errors validating the Request Object structure\n * @throws {@link Oauth2JwtParseError} in case the request object jwt is malformed (e.g missing header, bad encoding)\n * @throws {@link ParseAuthorizeRequestError} in case the JWT signature is invalid or there are unexpected errors\n */\nexport async function parseAuthorizeRequest(\n options: ParseAuthorizeRequestOptions,\n): Promise<AuthorizationRequestObject> {\n try {\n const decoded = decodeJwt({\n jwt: options.requestObjectJwt,\n payloadSchema: zOpenid4vpAuthorizationRequest,\n });\n const verificationResult = await options.callbacks.verifyJwt(\n options.dpop.signer,\n {\n compact: options.requestObjectJwt,\n header: decoded.header,\n payload: decoded.payload,\n },\n );\n\n if (!verificationResult.verified)\n throw new ParseAuthorizeRequestError(\n \"Error verifying Request Object signature\",\n );\n\n return decoded.payload;\n } catch (error) {\n if (\n error instanceof ValidationError ||\n error instanceof Oauth2JwtParseError\n )\n throw error;\n throw new ParseAuthorizeRequestError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","/**\n * Generic error thrown during Oid4vp operations\n */\nexport class Oid4vpError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vpError\";\n }\n}\n\n/**\n * Error thrown by {@link parseAuthorizeRequest} when the passed\n * request object has an invalid signature or unexpected errors\n * are thrown\n */\nexport class ParseAuthorizeRequestError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"ParseAuthorizeRequestError\";\n }\n}\n","import { zJwtPayload } from \"@openid4vc/oauth2\";\nimport { z } from \"zod\";\n\n/**\n * Zod parser that describes a JWT payload\n * containing an OID4VP Request Object\n */\nexport const zOpenid4vpAuthorizationRequest = z\n .object({\n client_id: z.string(),\n dcql_query: z.record(z.string(), z.any()).optional(),\n nonce: z.string(),\n request_uri: z.string().url().optional(),\n request_uri_method: z.optional(z.string()),\n response_mode: z.literal(\"direct_post.jwt\"),\n response_type: z.literal(\"vp_token\"),\n response_uri: z.string().url().optional(),\n scope: z.string().optional(),\n state: z.string().optional(),\n wallet_nonce: z.string().optional(),\n })\n .passthrough()\n .and(zJwtPayload);\n\nexport type AuthorizationRequestObject = z.infer<\n typeof zOpenid4vpAuthorizationRequest\n>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,iBAKO;AACP,mBAAgC;;;ACHzB,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,6BAAN,cAAyC,YAAY;AAAA,EAC1D,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;AC1BA,oBAA4B;AAC5B,iBAAkB;AAMX,IAAM,iCAAiC,aAC3C,OAAO;AAAA,EACN,WAAW,aAAE,OAAO;AAAA,EACpB,YAAY,aAAE,OAAO,aAAE,OAAO,GAAG,aAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACnD,OAAO,aAAE,OAAO;AAAA,EAChB,aAAa,aAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACvC,oBAAoB,aAAE,SAAS,aAAE,OAAO,CAAC;AAAA,EACzC,eAAe,aAAE,QAAQ,iBAAiB;AAAA,EAC1C,eAAe,aAAE,QAAQ,UAAU;AAAA,EACnC,cAAc,aAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACxC,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,aAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,cAAc,aAAE,OAAO,EAAE,SAAS;AACpC,CAAC,EACA,YAAY,EACZ,IAAI,yBAAW;;;AFmBlB,eAAsB,sBACpB,SACqC;AACrC,MAAI;AACF,UAAM,cAAU,0BAAU;AAAA,MACxB,KAAK,QAAQ;AAAA,MACb,eAAe;AAAA,IACjB,CAAC;AACD,UAAM,qBAAqB,MAAM,QAAQ,UAAU;AAAA,MACjD,QAAQ,KAAK;AAAA,MACb;AAAA,QACE,SAAS,QAAQ;AAAA,QACjB,QAAQ,QAAQ;AAAA,QAChB,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAEF,WAAO,QAAQ;AAAA,EACjB,SAAS,OAAO;AACd,QACE,iBAAiB,gCACjB,iBAAiB;AAEjB,YAAM;AACR,UAAM,IAAI;AAAA,MACR,mDAAmD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC3G;AAAA,EACF;AACF;","names":["import_oauth2"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// src/authorization-request/parse-authorization-request.ts
|
|
2
|
+
import {
|
|
3
|
+
Oauth2JwtParseError,
|
|
4
|
+
decodeJwt
|
|
5
|
+
} from "@openid4vc/oauth2";
|
|
6
|
+
import { ValidationError } from "@openid4vc/utils";
|
|
7
|
+
|
|
8
|
+
// src/errors.ts
|
|
9
|
+
var Oid4vpError = class extends Error {
|
|
10
|
+
constructor(message, statusCode) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.statusCode = statusCode;
|
|
13
|
+
this.name = "Oid4vpError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var ParseAuthorizeRequestError = class extends Oid4vpError {
|
|
17
|
+
constructor(message, statusCode) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.statusCode = statusCode;
|
|
20
|
+
this.name = "ParseAuthorizeRequestError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/authorization-request/z-request-object.ts
|
|
25
|
+
import { zJwtPayload } from "@openid4vc/oauth2";
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
var zOpenid4vpAuthorizationRequest = z.object({
|
|
28
|
+
client_id: z.string(),
|
|
29
|
+
dcql_query: z.record(z.string(), z.any()).optional(),
|
|
30
|
+
nonce: z.string(),
|
|
31
|
+
request_uri: z.string().url().optional(),
|
|
32
|
+
request_uri_method: z.optional(z.string()),
|
|
33
|
+
response_mode: z.literal("direct_post.jwt"),
|
|
34
|
+
response_type: z.literal("vp_token"),
|
|
35
|
+
response_uri: z.string().url().optional(),
|
|
36
|
+
scope: z.string().optional(),
|
|
37
|
+
state: z.string().optional(),
|
|
38
|
+
wallet_nonce: z.string().optional()
|
|
39
|
+
}).passthrough().and(zJwtPayload);
|
|
40
|
+
|
|
41
|
+
// src/authorization-request/parse-authorization-request.ts
|
|
42
|
+
async function parseAuthorizeRequest(options) {
|
|
43
|
+
try {
|
|
44
|
+
const decoded = decodeJwt({
|
|
45
|
+
jwt: options.requestObjectJwt,
|
|
46
|
+
payloadSchema: zOpenid4vpAuthorizationRequest
|
|
47
|
+
});
|
|
48
|
+
const verificationResult = await options.callbacks.verifyJwt(
|
|
49
|
+
options.dpop.signer,
|
|
50
|
+
{
|
|
51
|
+
compact: options.requestObjectJwt,
|
|
52
|
+
header: decoded.header,
|
|
53
|
+
payload: decoded.payload
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
if (!verificationResult.verified)
|
|
57
|
+
throw new ParseAuthorizeRequestError(
|
|
58
|
+
"Error verifying Request Object signature"
|
|
59
|
+
);
|
|
60
|
+
return decoded.payload;
|
|
61
|
+
} catch (error) {
|
|
62
|
+
if (error instanceof ValidationError || error instanceof Oauth2JwtParseError)
|
|
63
|
+
throw error;
|
|
64
|
+
throw new ParseAuthorizeRequestError(
|
|
65
|
+
`Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {
|
|
70
|
+
Oid4vpError,
|
|
71
|
+
ParseAuthorizeRequestError,
|
|
72
|
+
parseAuthorizeRequest,
|
|
73
|
+
zOpenid4vpAuthorizationRequest
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/authorization-request/parse-authorization-request.ts","../src/errors.ts","../src/authorization-request/z-request-object.ts"],"sourcesContent":["import {\n CallbackContext,\n Oauth2JwtParseError,\n RequestDpopOptions,\n decodeJwt,\n} from \"@openid4vc/oauth2\";\nimport { ValidationError } from \"@openid4vc/utils\";\n\nimport { ParseAuthorizeRequestError } from \"../errors\";\nimport {\n AuthorizationRequestObject,\n zOpenid4vpAuthorizationRequest,\n} from \"./z-request-object\";\n\nexport interface ParseAuthorizeRequestOptions {\n /**\n * Callback context for signature verification.\n */\n callbacks: Pick<CallbackContext, \"verifyJwt\">;\n\n /**\n * DPoP options\n */\n dpop: RequestDpopOptions;\n\n /**\n * The Authorization Request Object JWT.\n */\n requestObjectJwt: string;\n}\n\n/**\n * This method verifies a JWT containing a Request Object and returns its\n * decoded value for further processing\n * @param options {@link ParseAuthorizeRequestOptions}\n * @returns An {@link AuthorizationRequestObject} containing the RP required\n * credentials\n * @throws {@link ValidationError} in case there are errors validating the Request Object structure\n * @throws {@link Oauth2JwtParseError} in case the request object jwt is malformed (e.g missing header, bad encoding)\n * @throws {@link ParseAuthorizeRequestError} in case the JWT signature is invalid or there are unexpected errors\n */\nexport async function parseAuthorizeRequest(\n options: ParseAuthorizeRequestOptions,\n): Promise<AuthorizationRequestObject> {\n try {\n const decoded = decodeJwt({\n jwt: options.requestObjectJwt,\n payloadSchema: zOpenid4vpAuthorizationRequest,\n });\n const verificationResult = await options.callbacks.verifyJwt(\n options.dpop.signer,\n {\n compact: options.requestObjectJwt,\n header: decoded.header,\n payload: decoded.payload,\n },\n );\n\n if (!verificationResult.verified)\n throw new ParseAuthorizeRequestError(\n \"Error verifying Request Object signature\",\n );\n\n return decoded.payload;\n } catch (error) {\n if (\n error instanceof ValidationError ||\n error instanceof Oauth2JwtParseError\n )\n throw error;\n throw new ParseAuthorizeRequestError(\n `Unexpected error during Request Object parsing: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n}\n","/**\n * Generic error thrown during Oid4vp operations\n */\nexport class Oid4vpError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vpError\";\n }\n}\n\n/**\n * Error thrown by {@link parseAuthorizeRequest} when the passed\n * request object has an invalid signature or unexpected errors\n * are thrown\n */\nexport class ParseAuthorizeRequestError extends Oid4vpError {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"ParseAuthorizeRequestError\";\n }\n}\n","import { zJwtPayload } from \"@openid4vc/oauth2\";\nimport { z } from \"zod\";\n\n/**\n * Zod parser that describes a JWT payload\n * containing an OID4VP Request Object\n */\nexport const zOpenid4vpAuthorizationRequest = z\n .object({\n client_id: z.string(),\n dcql_query: z.record(z.string(), z.any()).optional(),\n nonce: z.string(),\n request_uri: z.string().url().optional(),\n request_uri_method: z.optional(z.string()),\n response_mode: z.literal(\"direct_post.jwt\"),\n response_type: z.literal(\"vp_token\"),\n response_uri: z.string().url().optional(),\n scope: z.string().optional(),\n state: z.string().optional(),\n wallet_nonce: z.string().optional(),\n })\n .passthrough()\n .and(zJwtPayload);\n\nexport type AuthorizationRequestObject = z.infer<\n typeof zOpenid4vpAuthorizationRequest\n>;\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EAEA;AAAA,OACK;AACP,SAAS,uBAAuB;;;ACHzB,IAAM,cAAN,cAA0B,MAAM;AAAA,EACrC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,6BAAN,cAAyC,YAAY;AAAA,EAC1D,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;AC1BA,SAAS,mBAAmB;AAC5B,SAAS,SAAS;AAMX,IAAM,iCAAiC,EAC3C,OAAO;AAAA,EACN,WAAW,EAAE,OAAO;AAAA,EACpB,YAAY,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,IAAI,CAAC,EAAE,SAAS;AAAA,EACnD,OAAO,EAAE,OAAO;AAAA,EAChB,aAAa,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACvC,oBAAoB,EAAE,SAAS,EAAE,OAAO,CAAC;AAAA,EACzC,eAAe,EAAE,QAAQ,iBAAiB;AAAA,EAC1C,eAAe,EAAE,QAAQ,UAAU;AAAA,EACnC,cAAc,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS;AAAA,EACxC,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,cAAc,EAAE,OAAO,EAAE,SAAS;AACpC,CAAC,EACA,YAAY,EACZ,IAAI,WAAW;;;AFmBlB,eAAsB,sBACpB,SACqC;AACrC,MAAI;AACF,UAAM,UAAU,UAAU;AAAA,MACxB,KAAK,QAAQ;AAAA,MACb,eAAe;AAAA,IACjB,CAAC;AACD,UAAM,qBAAqB,MAAM,QAAQ,UAAU;AAAA,MACjD,QAAQ,KAAK;AAAA,MACb;AAAA,QACE,SAAS,QAAQ;AAAA,QACjB,QAAQ,QAAQ;AAAA,QAChB,SAAS,QAAQ;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,CAAC,mBAAmB;AACtB,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAEF,WAAO,QAAQ;AAAA,EACjB,SAAS,OAAO;AACd,QACE,iBAAiB,mBACjB,iBAAiB;AAEjB,YAAM;AACR,UAAM,IAAI;AAAA,MACR,mDAAmD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,IAC3G;AAAA,EACF;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pagopa/io-wallet-oid4vp",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"files": [
|
|
5
|
+
"dist"
|
|
6
|
+
],
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/pagopa/io-wallet-sdk/tree/main/packages/oid4vp",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/pagopa/io-wallet-sdk",
|
|
20
|
+
"directory": "packages/oid4vp"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@openid4vc/oauth2": "0.3.0-alpha-20250714110838",
|
|
27
|
+
"@openid4vc/utils": "0.3.0-alpha-20250714110838",
|
|
28
|
+
"@openid4vc/openid4vp": "0.3.0-alpha-20250714110838",
|
|
29
|
+
"zod": "^3.24.2"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"jose": "^6.1.0"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
|
|
36
|
+
"test": "vitest"
|
|
37
|
+
},
|
|
38
|
+
"main": "./dist/index.js",
|
|
39
|
+
"module": "./dist/index.mjs",
|
|
40
|
+
"types": "./dist/index.d.ts"
|
|
41
|
+
}
|