@pagopa/io-wallet-oid4vci 0.4.1 → 0.5.0
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.d.mts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +8 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -9
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ClientAttestationJwtPayload } from '@openid4vc/oauth2';
|
|
2
|
+
import { Openid4vciWalletProvider } from '@openid4vc/openid4vci';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generic error thrown on Oid4vci operations
|
|
6
|
+
*/
|
|
7
|
+
declare class Oid4vciError extends Error {
|
|
8
|
+
readonly statusCode?: number | undefined;
|
|
9
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown in case the DPoP key passed to the
|
|
13
|
+
* {@link WalletProvider.createItWalletAttestationJwt} method
|
|
14
|
+
* doesn't contain a kid
|
|
15
|
+
*/
|
|
16
|
+
declare class WalletProviderError extends Oid4vciError {
|
|
17
|
+
readonly originalError?: unknown;
|
|
18
|
+
constructor(message: string, originalError?: unknown);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when an unexpected error occurs during nonce request.
|
|
22
|
+
*/
|
|
23
|
+
declare class NonceRequestError extends Error {
|
|
24
|
+
readonly statusCode?: number | undefined;
|
|
25
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @interface WalletAttestationOptions
|
|
30
|
+
* @description Defines the options required to create a wallet attestation JWT.
|
|
31
|
+
* This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.
|
|
32
|
+
*/
|
|
33
|
+
interface WalletAttestationOptions {
|
|
34
|
+
/**
|
|
35
|
+
* The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.
|
|
36
|
+
* This key is used to bind the attestation to the client's session.
|
|
37
|
+
* @type {ClientAttestationJwtPayload['cnf']}
|
|
38
|
+
*/
|
|
39
|
+
dpopJwkPublic: ClientAttestationJwtPayload["cnf"]["jwk"];
|
|
40
|
+
/**
|
|
41
|
+
* The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.
|
|
42
|
+
* @type {Date}
|
|
43
|
+
*/
|
|
44
|
+
expiresAt?: Date;
|
|
45
|
+
/**
|
|
46
|
+
* The issuer of the attestation, typically the Wallet Provider's identifier.
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
issuer: string;
|
|
50
|
+
signer: {
|
|
51
|
+
/**
|
|
52
|
+
* An array of JWTs representing the chain of trust from the federation's trust anchor
|
|
53
|
+
* to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.
|
|
54
|
+
* @type {[string, ...string[]]}
|
|
55
|
+
*/
|
|
56
|
+
trustChain: [string, ...string[]];
|
|
57
|
+
/**
|
|
58
|
+
* The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
walletProviderJwkPublicKid: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* An optional deep link or URL that can be used to open or interact with the wallet.
|
|
65
|
+
* @type {string}
|
|
66
|
+
*/
|
|
67
|
+
walletLink?: string;
|
|
68
|
+
/**
|
|
69
|
+
* An optional display name for the wallet.
|
|
70
|
+
* @type {string}
|
|
71
|
+
*/
|
|
72
|
+
walletName?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @class WalletProvider
|
|
76
|
+
* @extends Openid4vciWalletProvider
|
|
77
|
+
* @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).
|
|
78
|
+
* It handles the creation of wallet attestations required during the credential issuance flow.
|
|
79
|
+
*/
|
|
80
|
+
declare class WalletProvider extends Openid4vciWalletProvider {
|
|
81
|
+
/**
|
|
82
|
+
* Creates a wallet attestation JWT.
|
|
83
|
+
*
|
|
84
|
+
* This method constructs a signed JWT that asserts the wallet's control over a specific
|
|
85
|
+
* cryptographic key (DPoP key). This is a security measure to ensure that the entity
|
|
86
|
+
* presenting the credential offer is the legitimate wallet instance.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
* @async
|
|
90
|
+
* @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.
|
|
91
|
+
* @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.
|
|
92
|
+
*/
|
|
93
|
+
createItWalletAttestationJwt(options: WalletAttestationOptions): Promise<string>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { NonceRequestError, Oid4vciError, type WalletAttestationOptions, WalletProvider, WalletProviderError };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { ClientAttestationJwtPayload } from '@openid4vc/oauth2';
|
|
2
|
+
import { Openid4vciWalletProvider } from '@openid4vc/openid4vci';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generic error thrown on Oid4vci operations
|
|
6
|
+
*/
|
|
7
|
+
declare class Oid4vciError extends Error {
|
|
8
|
+
readonly statusCode?: number | undefined;
|
|
9
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown in case the DPoP key passed to the
|
|
13
|
+
* {@link WalletProvider.createItWalletAttestationJwt} method
|
|
14
|
+
* doesn't contain a kid
|
|
15
|
+
*/
|
|
16
|
+
declare class WalletProviderError extends Oid4vciError {
|
|
17
|
+
readonly originalError?: unknown;
|
|
18
|
+
constructor(message: string, originalError?: unknown);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Error thrown when an unexpected error occurs during nonce request.
|
|
22
|
+
*/
|
|
23
|
+
declare class NonceRequestError extends Error {
|
|
24
|
+
readonly statusCode?: number | undefined;
|
|
25
|
+
constructor(message: string, statusCode?: number | undefined);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @interface WalletAttestationOptions
|
|
30
|
+
* @description Defines the options required to create a wallet attestation JWT.
|
|
31
|
+
* This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.
|
|
32
|
+
*/
|
|
33
|
+
interface WalletAttestationOptions {
|
|
34
|
+
/**
|
|
35
|
+
* The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.
|
|
36
|
+
* This key is used to bind the attestation to the client's session.
|
|
37
|
+
* @type {ClientAttestationJwtPayload['cnf']}
|
|
38
|
+
*/
|
|
39
|
+
dpopJwkPublic: ClientAttestationJwtPayload["cnf"]["jwk"];
|
|
40
|
+
/**
|
|
41
|
+
* The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.
|
|
42
|
+
* @type {Date}
|
|
43
|
+
*/
|
|
44
|
+
expiresAt?: Date;
|
|
45
|
+
/**
|
|
46
|
+
* The issuer of the attestation, typically the Wallet Provider's identifier.
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
issuer: string;
|
|
50
|
+
signer: {
|
|
51
|
+
/**
|
|
52
|
+
* An array of JWTs representing the chain of trust from the federation's trust anchor
|
|
53
|
+
* to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.
|
|
54
|
+
* @type {[string, ...string[]]}
|
|
55
|
+
*/
|
|
56
|
+
trustChain: [string, ...string[]];
|
|
57
|
+
/**
|
|
58
|
+
* The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.
|
|
59
|
+
* @type {string}
|
|
60
|
+
*/
|
|
61
|
+
walletProviderJwkPublicKid: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* An optional deep link or URL that can be used to open or interact with the wallet.
|
|
65
|
+
* @type {string}
|
|
66
|
+
*/
|
|
67
|
+
walletLink?: string;
|
|
68
|
+
/**
|
|
69
|
+
* An optional display name for the wallet.
|
|
70
|
+
* @type {string}
|
|
71
|
+
*/
|
|
72
|
+
walletName?: string;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @class WalletProvider
|
|
76
|
+
* @extends Openid4vciWalletProvider
|
|
77
|
+
* @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).
|
|
78
|
+
* It handles the creation of wallet attestations required during the credential issuance flow.
|
|
79
|
+
*/
|
|
80
|
+
declare class WalletProvider extends Openid4vciWalletProvider {
|
|
81
|
+
/**
|
|
82
|
+
* Creates a wallet attestation JWT.
|
|
83
|
+
*
|
|
84
|
+
* This method constructs a signed JWT that asserts the wallet's control over a specific
|
|
85
|
+
* cryptographic key (DPoP key). This is a security measure to ensure that the entity
|
|
86
|
+
* presenting the credential offer is the legitimate wallet instance.
|
|
87
|
+
*
|
|
88
|
+
* @public
|
|
89
|
+
* @async
|
|
90
|
+
* @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.
|
|
91
|
+
* @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.
|
|
92
|
+
*/
|
|
93
|
+
createItWalletAttestationJwt(options: WalletAttestationOptions): Promise<string>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export { NonceRequestError, Oid4vciError, type WalletAttestationOptions, WalletProvider, WalletProviderError };
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
NonceRequestError: () => NonceRequestError,
|
|
23
24
|
Oid4vciError: () => Oid4vciError,
|
|
24
25
|
WalletProvider: () => WalletProvider,
|
|
25
26
|
WalletProviderError: () => WalletProviderError
|
|
@@ -41,6 +42,13 @@ var WalletProviderError = class extends Oid4vciError {
|
|
|
41
42
|
this.name = "WalletProviderError";
|
|
42
43
|
}
|
|
43
44
|
};
|
|
45
|
+
var NonceRequestError = class extends Error {
|
|
46
|
+
constructor(message, statusCode) {
|
|
47
|
+
super(message);
|
|
48
|
+
this.statusCode = statusCode;
|
|
49
|
+
this.name = "NonceRequestError";
|
|
50
|
+
}
|
|
51
|
+
};
|
|
44
52
|
|
|
45
53
|
// src/wallet-provider/WalletProvider.ts
|
|
46
54
|
var import_openid4vci = require("@openid4vc/openid4vci");
|
|
@@ -85,6 +93,7 @@ var WalletProvider = class extends import_openid4vci.Openid4vciWalletProvider {
|
|
|
85
93
|
};
|
|
86
94
|
// Annotate the CommonJS export names for ESM import in node:
|
|
87
95
|
0 && (module.exports = {
|
|
96
|
+
NonceRequestError,
|
|
88
97
|
Oid4vciError,
|
|
89
98
|
WalletProvider,
|
|
90
99
|
WalletProviderError
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/wallet-provider/WalletProvider.ts"],"sourcesContent":["export * from \"./errors\";\nexport * from \"./wallet-provider/WalletProvider\";\n","/**\n * Generic error thrown on Oid4vci operations\n */\nexport class Oid4vciError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vciError\";\n }\n}\n\n/**\n * Error thrown in case the DPoP key passed to the\n * {@link WalletProvider.createItWalletAttestationJwt} method\n * doesn't contain a kid\n */\nexport class WalletProviderError extends Oid4vciError {\n constructor(\n message: string,\n public readonly originalError?: unknown,\n ) {\n super(message);\n this.name = \"WalletProviderError\";\n }\n}\n","import { ClientAttestationJwtPayload } from \"@openid4vc/oauth2\";\nimport { Openid4vciWalletProvider } from \"@openid4vc/openid4vci\";\nimport { addSecondsToDate } from \"@openid4vc/utils\";\n\nimport { WalletProviderError } from \"../errors\";\n\n/**\n * @interface WalletAttestationOptions\n * @description Defines the options required to create a wallet attestation JWT.\n * This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.\n */\nexport interface WalletAttestationOptions {\n /**\n * The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.\n * This key is used to bind the attestation to the client's session.\n * @type {ClientAttestationJwtPayload['cnf']}\n */\n dpopJwkPublic: ClientAttestationJwtPayload[\"cnf\"][\"jwk\"];\n\n /**\n * The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.\n * @type {Date}\n */\n expiresAt?: Date;\n /**\n * The issuer of the attestation, typically the Wallet Provider's identifier.\n * @type {string}\n */\n issuer: string;\n\n signer: {\n /**\n * An array of JWTs representing the chain of trust from the federation's trust anchor\n * to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.\n * @type {[string, ...string[]]}\n */\n trustChain: [string, ...string[]];\n\n /**\n * The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.\n * @type {string}\n */\n walletProviderJwkPublicKid: string;\n };\n\n /**\n * An optional deep link or URL that can be used to open or interact with the wallet.\n * @type {string}\n */\n walletLink?: string;\n\n /**\n * An optional display name for the wallet.\n * @type {string}\n */\n walletName?: string;\n}\n\n/**\n * @class WalletProvider\n * @extends Openid4vciWalletProvider\n * @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).\n * It handles the creation of wallet attestations required during the credential issuance flow.\n */\nexport class WalletProvider extends Openid4vciWalletProvider {\n /**\n * Creates a wallet attestation JWT.\n *\n * This method constructs a signed JWT that asserts the wallet's control over a specific\n * cryptographic key (DPoP key). This is a security measure to ensure that the entity\n * presenting the credential offer is the legitimate wallet instance.\n *\n * @public\n * @async\n * @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.\n * @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.\n */\n public async createItWalletAttestationJwt(\n options: WalletAttestationOptions,\n ): Promise<string> {\n if (!options.dpopJwkPublic.kid) {\n throw new WalletProviderError(\"The DPoP JWK must have a 'kid' property\");\n }\n\n const walletAttestation = await this.createWalletAttestationJwt({\n clientId: options.dpopJwkPublic.kid,\n confirmation: {\n // We use the same key for DPoP as the wallet attestation\n jwk: options.dpopJwkPublic,\n },\n expiresAt:\n options.expiresAt ?? addSecondsToDate(new Date(), 3600 * 24 * 60 * 60),\n issuer: options.issuer,\n signer: {\n alg: \"ES256\",\n kid: options.signer.walletProviderJwkPublicKid,\n method: \"federation\", // Indicates the validation method relies on a trust chain.\n trustChain: options.signer.trustChain,\n },\n walletLink: options.walletLink,\n walletName: options.walletName,\n });\n\n return walletAttestation;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YACE,SACgB,eAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/wallet-provider/WalletProvider.ts"],"sourcesContent":["export * from \"./errors\";\nexport * from \"./wallet-provider/WalletProvider\";\n","/**\n * Generic error thrown on Oid4vci operations\n */\nexport class Oid4vciError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vciError\";\n }\n}\n\n/**\n * Error thrown in case the DPoP key passed to the\n * {@link WalletProvider.createItWalletAttestationJwt} method\n * doesn't contain a kid\n */\nexport class WalletProviderError extends Oid4vciError {\n constructor(\n message: string,\n public readonly originalError?: unknown,\n ) {\n super(message);\n this.name = \"WalletProviderError\";\n }\n}\n\n/**\n * Error thrown when an unexpected error occurs during nonce request.\n */\nexport class NonceRequestError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"NonceRequestError\";\n }\n}\n","import { ClientAttestationJwtPayload } from \"@openid4vc/oauth2\";\nimport { Openid4vciWalletProvider } from \"@openid4vc/openid4vci\";\nimport { addSecondsToDate } from \"@openid4vc/utils\";\n\nimport { WalletProviderError } from \"../errors\";\n\n/**\n * @interface WalletAttestationOptions\n * @description Defines the options required to create a wallet attestation JWT.\n * This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.\n */\nexport interface WalletAttestationOptions {\n /**\n * The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.\n * This key is used to bind the attestation to the client's session.\n * @type {ClientAttestationJwtPayload['cnf']}\n */\n dpopJwkPublic: ClientAttestationJwtPayload[\"cnf\"][\"jwk\"];\n\n /**\n * The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.\n * @type {Date}\n */\n expiresAt?: Date;\n /**\n * The issuer of the attestation, typically the Wallet Provider's identifier.\n * @type {string}\n */\n issuer: string;\n\n signer: {\n /**\n * An array of JWTs representing the chain of trust from the federation's trust anchor\n * to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.\n * @type {[string, ...string[]]}\n */\n trustChain: [string, ...string[]];\n\n /**\n * The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.\n * @type {string}\n */\n walletProviderJwkPublicKid: string;\n };\n\n /**\n * An optional deep link or URL that can be used to open or interact with the wallet.\n * @type {string}\n */\n walletLink?: string;\n\n /**\n * An optional display name for the wallet.\n * @type {string}\n */\n walletName?: string;\n}\n\n/**\n * @class WalletProvider\n * @extends Openid4vciWalletProvider\n * @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).\n * It handles the creation of wallet attestations required during the credential issuance flow.\n */\nexport class WalletProvider extends Openid4vciWalletProvider {\n /**\n * Creates a wallet attestation JWT.\n *\n * This method constructs a signed JWT that asserts the wallet's control over a specific\n * cryptographic key (DPoP key). This is a security measure to ensure that the entity\n * presenting the credential offer is the legitimate wallet instance.\n *\n * @public\n * @async\n * @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.\n * @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.\n */\n public async createItWalletAttestationJwt(\n options: WalletAttestationOptions,\n ): Promise<string> {\n if (!options.dpopJwkPublic.kid) {\n throw new WalletProviderError(\"The DPoP JWK must have a 'kid' property\");\n }\n\n const walletAttestation = await this.createWalletAttestationJwt({\n clientId: options.dpopJwkPublic.kid,\n confirmation: {\n // We use the same key for DPoP as the wallet attestation\n jwk: options.dpopJwkPublic,\n },\n expiresAt:\n options.expiresAt ?? addSecondsToDate(new Date(), 3600 * 24 * 60 * 60),\n issuer: options.issuer,\n signer: {\n alg: \"ES256\",\n kid: options.signer.walletProviderJwkPublicKid,\n method: \"federation\", // Indicates the validation method relies on a trust chain.\n trustChain: options.signer.trustChain,\n },\n walletLink: options.walletLink,\n walletName: options.walletName,\n });\n\n return walletAttestation;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YACE,SACgB,eAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACtCA,wBAAyC;AACzC,mBAAiC;AA8D1B,IAAM,iBAAN,cAA6B,2CAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAa3D,MAAa,6BACX,SACiB;AACjB,QAAI,CAAC,QAAQ,cAAc,KAAK;AAC9B,YAAM,IAAI,oBAAoB,yCAAyC;AAAA,IACzE;AAEA,UAAM,oBAAoB,MAAM,KAAK,2BAA2B;AAAA,MAC9D,UAAU,QAAQ,cAAc;AAAA,MAChC,cAAc;AAAA;AAAA,QAEZ,KAAK,QAAQ;AAAA,MACf;AAAA,MACA,WACE,QAAQ,iBAAa,+BAAiB,oBAAI,KAAK,GAAG,OAAO,KAAK,KAAK,EAAE;AAAA,MACvE,QAAQ,QAAQ;AAAA,MAChB,QAAQ;AAAA,QACN,KAAK;AAAA,QACL,KAAK,QAAQ,OAAO;AAAA,QACpB,QAAQ;AAAA;AAAA,QACR,YAAY,QAAQ,OAAO;AAAA,MAC7B;AAAA,MACA,YAAY,QAAQ;AAAA,MACpB,YAAY,QAAQ;AAAA,IACtB,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -13,6 +13,13 @@ var WalletProviderError = class extends Oid4vciError {
|
|
|
13
13
|
this.name = "WalletProviderError";
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
|
+
var NonceRequestError = class extends Error {
|
|
17
|
+
constructor(message, statusCode) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.statusCode = statusCode;
|
|
20
|
+
this.name = "NonceRequestError";
|
|
21
|
+
}
|
|
22
|
+
};
|
|
16
23
|
|
|
17
24
|
// src/wallet-provider/WalletProvider.ts
|
|
18
25
|
import { Openid4vciWalletProvider } from "@openid4vc/openid4vci";
|
|
@@ -56,6 +63,7 @@ var WalletProvider = class extends Openid4vciWalletProvider {
|
|
|
56
63
|
}
|
|
57
64
|
};
|
|
58
65
|
export {
|
|
66
|
+
NonceRequestError,
|
|
59
67
|
Oid4vciError,
|
|
60
68
|
WalletProvider,
|
|
61
69
|
WalletProviderError
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/wallet-provider/WalletProvider.ts"],"sourcesContent":["/**\n * Generic error thrown on Oid4vci operations\n */\nexport class Oid4vciError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vciError\";\n }\n}\n\n/**\n * Error thrown in case the DPoP key passed to the\n * {@link WalletProvider.createItWalletAttestationJwt} method\n * doesn't contain a kid\n */\nexport class WalletProviderError extends Oid4vciError {\n constructor(\n message: string,\n public readonly originalError?: unknown,\n ) {\n super(message);\n this.name = \"WalletProviderError\";\n }\n}\n","import { ClientAttestationJwtPayload } from \"@openid4vc/oauth2\";\nimport { Openid4vciWalletProvider } from \"@openid4vc/openid4vci\";\nimport { addSecondsToDate } from \"@openid4vc/utils\";\n\nimport { WalletProviderError } from \"../errors\";\n\n/**\n * @interface WalletAttestationOptions\n * @description Defines the options required to create a wallet attestation JWT.\n * This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.\n */\nexport interface WalletAttestationOptions {\n /**\n * The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.\n * This key is used to bind the attestation to the client's session.\n * @type {ClientAttestationJwtPayload['cnf']}\n */\n dpopJwkPublic: ClientAttestationJwtPayload[\"cnf\"][\"jwk\"];\n\n /**\n * The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.\n * @type {Date}\n */\n expiresAt?: Date;\n /**\n * The issuer of the attestation, typically the Wallet Provider's identifier.\n * @type {string}\n */\n issuer: string;\n\n signer: {\n /**\n * An array of JWTs representing the chain of trust from the federation's trust anchor\n * to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.\n * @type {[string, ...string[]]}\n */\n trustChain: [string, ...string[]];\n\n /**\n * The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.\n * @type {string}\n */\n walletProviderJwkPublicKid: string;\n };\n\n /**\n * An optional deep link or URL that can be used to open or interact with the wallet.\n * @type {string}\n */\n walletLink?: string;\n\n /**\n * An optional display name for the wallet.\n * @type {string}\n */\n walletName?: string;\n}\n\n/**\n * @class WalletProvider\n * @extends Openid4vciWalletProvider\n * @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).\n * It handles the creation of wallet attestations required during the credential issuance flow.\n */\nexport class WalletProvider extends Openid4vciWalletProvider {\n /**\n * Creates a wallet attestation JWT.\n *\n * This method constructs a signed JWT that asserts the wallet's control over a specific\n * cryptographic key (DPoP key). This is a security measure to ensure that the entity\n * presenting the credential offer is the legitimate wallet instance.\n *\n * @public\n * @async\n * @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.\n * @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.\n */\n public async createItWalletAttestationJwt(\n options: WalletAttestationOptions,\n ): Promise<string> {\n if (!options.dpopJwkPublic.kid) {\n throw new WalletProviderError(\"The DPoP JWK must have a 'kid' property\");\n }\n\n const walletAttestation = await this.createWalletAttestationJwt({\n clientId: options.dpopJwkPublic.kid,\n confirmation: {\n // We use the same key for DPoP as the wallet attestation\n jwk: options.dpopJwkPublic,\n },\n expiresAt:\n options.expiresAt ?? addSecondsToDate(new Date(), 3600 * 24 * 60 * 60),\n issuer: options.issuer,\n signer: {\n alg: \"ES256\",\n kid: options.signer.walletProviderJwkPublicKid,\n method: \"federation\", // Indicates the validation method relies on a trust chain.\n trustChain: options.signer.trustChain,\n },\n walletLink: options.walletLink,\n walletName: options.walletName,\n });\n\n return walletAttestation;\n }\n}\n"],"mappings":";AAGO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YACE,SACgB,eAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/wallet-provider/WalletProvider.ts"],"sourcesContent":["/**\n * Generic error thrown on Oid4vci operations\n */\nexport class Oid4vciError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"Oid4vciError\";\n }\n}\n\n/**\n * Error thrown in case the DPoP key passed to the\n * {@link WalletProvider.createItWalletAttestationJwt} method\n * doesn't contain a kid\n */\nexport class WalletProviderError extends Oid4vciError {\n constructor(\n message: string,\n public readonly originalError?: unknown,\n ) {\n super(message);\n this.name = \"WalletProviderError\";\n }\n}\n\n/**\n * Error thrown when an unexpected error occurs during nonce request.\n */\nexport class NonceRequestError extends Error {\n constructor(\n message: string,\n public readonly statusCode?: number,\n ) {\n super(message);\n this.name = \"NonceRequestError\";\n }\n}\n","import { ClientAttestationJwtPayload } from \"@openid4vc/oauth2\";\nimport { Openid4vciWalletProvider } from \"@openid4vc/openid4vci\";\nimport { addSecondsToDate } from \"@openid4vc/utils\";\n\nimport { WalletProviderError } from \"../errors\";\n\n/**\n * @interface WalletAttestationOptions\n * @description Defines the options required to create a wallet attestation JWT.\n * This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.\n */\nexport interface WalletAttestationOptions {\n /**\n * The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.\n * This key is used to bind the attestation to the client's session.\n * @type {ClientAttestationJwtPayload['cnf']}\n */\n dpopJwkPublic: ClientAttestationJwtPayload[\"cnf\"][\"jwk\"];\n\n /**\n * The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.\n * @type {Date}\n */\n expiresAt?: Date;\n /**\n * The issuer of the attestation, typically the Wallet Provider's identifier.\n * @type {string}\n */\n issuer: string;\n\n signer: {\n /**\n * An array of JWTs representing the chain of trust from the federation's trust anchor\n * to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.\n * @type {[string, ...string[]]}\n */\n trustChain: [string, ...string[]];\n\n /**\n * The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.\n * @type {string}\n */\n walletProviderJwkPublicKid: string;\n };\n\n /**\n * An optional deep link or URL that can be used to open or interact with the wallet.\n * @type {string}\n */\n walletLink?: string;\n\n /**\n * An optional display name for the wallet.\n * @type {string}\n */\n walletName?: string;\n}\n\n/**\n * @class WalletProvider\n * @extends Openid4vciWalletProvider\n * @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).\n * It handles the creation of wallet attestations required during the credential issuance flow.\n */\nexport class WalletProvider extends Openid4vciWalletProvider {\n /**\n * Creates a wallet attestation JWT.\n *\n * This method constructs a signed JWT that asserts the wallet's control over a specific\n * cryptographic key (DPoP key). This is a security measure to ensure that the entity\n * presenting the credential offer is the legitimate wallet instance.\n *\n * @public\n * @async\n * @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.\n * @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.\n */\n public async createItWalletAttestationJwt(\n options: WalletAttestationOptions,\n ): Promise<string> {\n if (!options.dpopJwkPublic.kid) {\n throw new WalletProviderError(\"The DPoP JWK must have a 'kid' property\");\n }\n\n const walletAttestation = await this.createWalletAttestationJwt({\n clientId: options.dpopJwkPublic.kid,\n confirmation: {\n // We use the same key for DPoP as the wallet attestation\n jwk: options.dpopJwkPublic,\n },\n expiresAt:\n options.expiresAt ?? addSecondsToDate(new Date(), 3600 * 24 * 60 * 60),\n issuer: options.issuer,\n signer: {\n alg: \"ES256\",\n kid: options.signer.walletProviderJwkPublicKid,\n method: \"federation\", // Indicates the validation method relies on a trust chain.\n trustChain: options.signer.trustChain,\n },\n walletLink: options.walletLink,\n walletName: options.walletName,\n });\n\n return walletAttestation;\n }\n}\n"],"mappings":";AAGO,IAAM,eAAN,cAA2B,MAAM;AAAA,EACtC,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAOO,IAAM,sBAAN,cAAkC,aAAa;AAAA,EACpD,YACE,SACgB,eAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;AAKO,IAAM,oBAAN,cAAgC,MAAM;AAAA,EAC3C,YACE,SACgB,YAChB;AACA,UAAM,OAAO;AAFG;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACtCA,SAAS,gCAAgC;AACzC,SAAS,wBAAwB;AA8D1B,IAAM,iBAAN,cAA6B,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAa3D,MAAa,6BACX,SACiB;AACjB,QAAI,CAAC,QAAQ,cAAc,KAAK;AAC9B,YAAM,IAAI,oBAAoB,yCAAyC;AAAA,IACzE;AAEA,UAAM,oBAAoB,MAAM,KAAK,2BAA2B;AAAA,MAC9D,UAAU,QAAQ,cAAc;AAAA,MAChC,cAAc;AAAA;AAAA,QAEZ,KAAK,QAAQ;AAAA,MACf;AAAA,MACA,WACE,QAAQ,aAAa,iBAAiB,oBAAI,KAAK,GAAG,OAAO,KAAK,KAAK,EAAE;AAAA,MACvE,QAAQ,QAAQ;AAAA,MAChB,QAAQ;AAAA,QACN,KAAK;AAAA,QACL,KAAK,QAAQ,OAAO;AAAA,QACpB,QAAQ;AAAA;AAAA,QACR,YAAY,QAAQ,OAAO;AAAA,MAC7B;AAAA,MACA,YAAY,QAAQ;AAAA,MACpB,YAAY,QAAQ;AAAA,IACtB,CAAC;AAED,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/io-wallet-oid4vci",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"module": "./dist/index.mjs",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
8
11
|
"exports": {
|
|
9
12
|
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
10
14
|
"import": "./dist/index.mjs",
|
|
11
|
-
"require": "./dist/index.js"
|
|
12
|
-
"types": "./dist/index.d.ts"
|
|
15
|
+
"require": "./dist/index.js"
|
|
13
16
|
},
|
|
14
17
|
"./package.json": "./package.json"
|
|
15
18
|
},
|
|
@@ -27,13 +30,11 @@
|
|
|
27
30
|
"@openid4vc/oauth2": "0.3.0-alpha-20250714110838",
|
|
28
31
|
"@openid4vc/openid4vci": "0.3.0-alpha-20250714110838",
|
|
29
32
|
"@openid4vc/utils": "0.3.0-alpha-20250714110838",
|
|
30
|
-
"zod": "^3.24.2"
|
|
33
|
+
"zod": "^3.24.2",
|
|
34
|
+
"@pagopa/io-wallet-utils": "0.5.0"
|
|
31
35
|
},
|
|
32
36
|
"scripts": {
|
|
33
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --
|
|
37
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --sourcemap",
|
|
34
38
|
"test": "vitest"
|
|
35
|
-
}
|
|
36
|
-
"main": "./dist/index.js",
|
|
37
|
-
"module": "./dist/index.mjs",
|
|
38
|
-
"types": "./dist/index.d.ts"
|
|
39
|
+
}
|
|
39
40
|
}
|