@pagopa/io-wallet-oid4vci 0.3.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/README.md +68 -0
- package/dist/index.d.mts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +75 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +51 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
## @pagopa/io-wallet-oid4vci
|
|
2
|
+
|
|
3
|
+
This package provides functionalities to manage the **OpenID for Verifiable Credentials Issuance (OID4VCI)** protocol flow, specifically tailored for the Italian Wallet ecosystem. It simplifies the creation of wallet attestations required during the credential issuance process.
|
|
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-oid4vci
|
|
12
|
+
|
|
13
|
+
# Using yarn
|
|
14
|
+
yarn add @pagopa/io-wallet-oid4vci
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Wallet Provider
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { ItWalletProvider } from '@pagopa/io-wallet-oid4vci';
|
|
23
|
+
|
|
24
|
+
// Initialize the provider with required options
|
|
25
|
+
const walletProvider = new ItWalletProvider({
|
|
26
|
+
// Openid4vciWalletProviderOptions configuration
|
|
27
|
+
// Add your specific configuration here
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Creating a Wallet Attestation
|
|
32
|
+
|
|
33
|
+
Create wallet attestations required during the OID4VCI flow:
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { ItWalletProvider, WalletAttestationOptions } from '@pagopa/io-wallet-oid4vci';
|
|
37
|
+
|
|
38
|
+
// Create wallet attestation
|
|
39
|
+
const attestationOptions: WalletAttestationOptions = {
|
|
40
|
+
issuer: "https://wallet-provider.example.com",
|
|
41
|
+
dpopJwkPublic: {
|
|
42
|
+
// JWK public key for DPoP binding
|
|
43
|
+
kid: "dpop-key-id",
|
|
44
|
+
kty: "EC",
|
|
45
|
+
crv: "P-256",
|
|
46
|
+
x: "...",
|
|
47
|
+
y: "..."
|
|
48
|
+
},
|
|
49
|
+
signer: {
|
|
50
|
+
walletProviderJwkPublicKid: "wallet-provider-key-id",
|
|
51
|
+
trustChain: [
|
|
52
|
+
"eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiJ9...", // Trust anchor JWT
|
|
53
|
+
// Additional trust chain JWTs
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
walletName: "My Italian Wallet", // Optional
|
|
57
|
+
walletLink: "https://mywalletapp.com", // Optional
|
|
58
|
+
expiresAt: new Date(Date.now() + 24 * 60 * 60 * 1000) // Optional, defaults to 60 days
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const attestationJwt = await walletProvider.createItWalletAttestationJwt(attestationOptions);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
The wallet attestation JWT can then be used in the OID4VCI protocol flow to prove the wallet's identity and key possession.
|
|
65
|
+
|
|
66
|
+
## API Reference
|
|
67
|
+
|
|
68
|
+
`ItWalletProvider`: A class that extends Openid4vciWalletProvider to provide specialized methods for the Italian Wallet ecosystem.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ClientAttestationJwtPayload } from '@openid4vc/oauth2';
|
|
2
|
+
import { Openid4vciWalletProvider, Openid4vciWalletProviderOptions } from '@openid4vc/openid4vci';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @interface WalletAttestationOptions
|
|
6
|
+
* @description Defines the options required to create a wallet attestation JWT.
|
|
7
|
+
* This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.
|
|
8
|
+
*/
|
|
9
|
+
interface WalletAttestationOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The issuer of the attestation, typically the Wallet Provider's identifier.
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
issuer: string;
|
|
15
|
+
/**
|
|
16
|
+
* The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.
|
|
17
|
+
* This key is used to bind the attestation to the client's session.
|
|
18
|
+
* @type {ClientAttestationJwtPayload['cnf']}
|
|
19
|
+
*/
|
|
20
|
+
dpopJwkPublic: ClientAttestationJwtPayload["cnf"]["jwk"];
|
|
21
|
+
signer: {
|
|
22
|
+
/**
|
|
23
|
+
* The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
walletProviderJwkPublicKid: string;
|
|
27
|
+
/**
|
|
28
|
+
* An array of JWTs representing the chain of trust from the federation's trust anchor
|
|
29
|
+
* to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.
|
|
30
|
+
* @type {[string, ...string[]]}
|
|
31
|
+
*/
|
|
32
|
+
trustChain: [string, ...string[]];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* An optional display name for the wallet.
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
walletName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* An optional deep link or URL that can be used to open or interact with the wallet.
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
43
|
+
walletLink?: string;
|
|
44
|
+
/**
|
|
45
|
+
* The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.
|
|
46
|
+
* @type {Date}
|
|
47
|
+
*/
|
|
48
|
+
expiresAt?: Date;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @class ItWalletProvider
|
|
52
|
+
* @extends Openid4vciWalletProvider
|
|
53
|
+
* @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).
|
|
54
|
+
* It handles the creation of wallet attestations required during the credential issuance flow.
|
|
55
|
+
*/
|
|
56
|
+
declare class ItWalletProvider extends Openid4vciWalletProvider {
|
|
57
|
+
/**
|
|
58
|
+
* @constructor
|
|
59
|
+
* @param {Openid4vciWalletProviderOptions} options - The configuration options for the provider.
|
|
60
|
+
*/
|
|
61
|
+
constructor(options: Openid4vciWalletProviderOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Creates a wallet attestation JWT.
|
|
64
|
+
*
|
|
65
|
+
* This method constructs a signed JWT that asserts the wallet's control over a specific
|
|
66
|
+
* cryptographic key (DPoP key). This is a security measure to ensure that the entity
|
|
67
|
+
* presenting the credential offer is the legitimate wallet instance.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
* @async
|
|
71
|
+
* @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.
|
|
72
|
+
* @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.
|
|
73
|
+
*/
|
|
74
|
+
createItWalletAttestationJwt(options: WalletAttestationOptions): Promise<string>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { ItWalletProvider, type WalletAttestationOptions };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { ClientAttestationJwtPayload } from '@openid4vc/oauth2';
|
|
2
|
+
import { Openid4vciWalletProvider, Openid4vciWalletProviderOptions } from '@openid4vc/openid4vci';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @interface WalletAttestationOptions
|
|
6
|
+
* @description Defines the options required to create a wallet attestation JWT.
|
|
7
|
+
* This attestation is a signed token that proves the wallet's identity and possession of a cryptographic key.
|
|
8
|
+
*/
|
|
9
|
+
interface WalletAttestationOptions {
|
|
10
|
+
/**
|
|
11
|
+
* The issuer of the attestation, typically the Wallet Provider's identifier.
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
issuer: string;
|
|
15
|
+
/**
|
|
16
|
+
* The public part of the DPoP (Demonstrating Proof-of-Possession) key in JWK (JSON Web Key) format.
|
|
17
|
+
* This key is used to bind the attestation to the client's session.
|
|
18
|
+
* @type {ClientAttestationJwtPayload['cnf']}
|
|
19
|
+
*/
|
|
20
|
+
dpopJwkPublic: ClientAttestationJwtPayload["cnf"]["jwk"];
|
|
21
|
+
signer: {
|
|
22
|
+
/**
|
|
23
|
+
* The Key ID (`kid`) of the wallet provider's public key used for signing the attestation.
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
walletProviderJwkPublicKid: string;
|
|
27
|
+
/**
|
|
28
|
+
* An array of JWTs representing the chain of trust from the federation's trust anchor
|
|
29
|
+
* to the wallet provider. This is used in federated identity systems to validate the provider's authenticity.
|
|
30
|
+
* @type {[string, ...string[]]}
|
|
31
|
+
*/
|
|
32
|
+
trustChain: [string, ...string[]];
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* An optional display name for the wallet.
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
walletName?: string;
|
|
39
|
+
/**
|
|
40
|
+
* An optional deep link or URL that can be used to open or interact with the wallet.
|
|
41
|
+
* @type {string}
|
|
42
|
+
*/
|
|
43
|
+
walletLink?: string;
|
|
44
|
+
/**
|
|
45
|
+
* The optional expiration date for the attestation JWT. If not provided, a default lifetime will be used.
|
|
46
|
+
* @type {Date}
|
|
47
|
+
*/
|
|
48
|
+
expiresAt?: Date;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @class ItWalletProvider
|
|
52
|
+
* @extends Openid4vciWalletProvider
|
|
53
|
+
* @description An implementation of a wallet provider for the OpenID4VCI protocol, tailored for a specific ecosystem (e.g., the Italian one).
|
|
54
|
+
* It handles the creation of wallet attestations required during the credential issuance flow.
|
|
55
|
+
*/
|
|
56
|
+
declare class ItWalletProvider extends Openid4vciWalletProvider {
|
|
57
|
+
/**
|
|
58
|
+
* @constructor
|
|
59
|
+
* @param {Openid4vciWalletProviderOptions} options - The configuration options for the provider.
|
|
60
|
+
*/
|
|
61
|
+
constructor(options: Openid4vciWalletProviderOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Creates a wallet attestation JWT.
|
|
64
|
+
*
|
|
65
|
+
* This method constructs a signed JWT that asserts the wallet's control over a specific
|
|
66
|
+
* cryptographic key (DPoP key). This is a security measure to ensure that the entity
|
|
67
|
+
* presenting the credential offer is the legitimate wallet instance.
|
|
68
|
+
*
|
|
69
|
+
* @public
|
|
70
|
+
* @async
|
|
71
|
+
* @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.
|
|
72
|
+
* @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.
|
|
73
|
+
*/
|
|
74
|
+
createItWalletAttestationJwt(options: WalletAttestationOptions): Promise<string>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export { ItWalletProvider, type WalletAttestationOptions };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var index_exports = {};
|
|
21
|
+
__export(index_exports, {
|
|
22
|
+
ItWalletProvider: () => ItWalletProvider
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(index_exports);
|
|
25
|
+
|
|
26
|
+
// src/ItWalletProvider.ts
|
|
27
|
+
var import_openid4vci = require("@openid4vc/openid4vci");
|
|
28
|
+
var import_utils = require("@openid4vc/utils");
|
|
29
|
+
var ItWalletProvider = class extends import_openid4vci.Openid4vciWalletProvider {
|
|
30
|
+
/**
|
|
31
|
+
* @constructor
|
|
32
|
+
* @param {Openid4vciWalletProviderOptions} options - The configuration options for the provider.
|
|
33
|
+
*/
|
|
34
|
+
constructor(options) {
|
|
35
|
+
super(options);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Creates a wallet attestation JWT.
|
|
39
|
+
*
|
|
40
|
+
* This method constructs a signed JWT that asserts the wallet's control over a specific
|
|
41
|
+
* cryptographic key (DPoP key). This is a security measure to ensure that the entity
|
|
42
|
+
* presenting the credential offer is the legitimate wallet instance.
|
|
43
|
+
*
|
|
44
|
+
* @public
|
|
45
|
+
* @async
|
|
46
|
+
* @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.
|
|
47
|
+
* @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.
|
|
48
|
+
*/
|
|
49
|
+
async createItWalletAttestationJwt(options) {
|
|
50
|
+
const walletAttestation = await this.createWalletAttestationJwt({
|
|
51
|
+
clientId: options.dpopJwkPublic.kid,
|
|
52
|
+
confirmation: {
|
|
53
|
+
// We use the same key for DPoP as the wallet attestation
|
|
54
|
+
jwk: options.dpopJwkPublic
|
|
55
|
+
},
|
|
56
|
+
expiresAt: options.expiresAt ?? (0, import_utils.addSecondsToDate)(/* @__PURE__ */ new Date(), 3600 * 24 * 60 * 60),
|
|
57
|
+
issuer: options.issuer,
|
|
58
|
+
signer: {
|
|
59
|
+
alg: "ES256",
|
|
60
|
+
kid: options.signer.walletProviderJwkPublicKid,
|
|
61
|
+
method: "federation",
|
|
62
|
+
// Indicates the validation method relies on a trust chain.
|
|
63
|
+
trustChain: options.signer.trustChain
|
|
64
|
+
},
|
|
65
|
+
walletLink: options.walletLink,
|
|
66
|
+
walletName: options.walletName
|
|
67
|
+
});
|
|
68
|
+
return walletAttestation;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
72
|
+
0 && (module.exports = {
|
|
73
|
+
ItWalletProvider
|
|
74
|
+
});
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/ItWalletProvider.ts"],"sourcesContent":["export * from \"./ItWalletProvider\";\n","import { ClientAttestationJwtPayload } from \"@openid4vc/oauth2\";\nimport {\n Openid4vciWalletProvider,\n Openid4vciWalletProviderOptions,\n} from \"@openid4vc/openid4vci\";\nimport { addSecondsToDate } from \"@openid4vc/utils\";\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 issuer of the attestation, typically the Wallet Provider's identifier.\n * @type {string}\n */\n issuer: string;\n \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 signer: {\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 * 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 /**\n * An optional display name for the wallet.\n * @type {string}\n */\n walletName?: string;\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 * 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\n/**\n * @class ItWalletProvider\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 ItWalletProvider extends Openid4vciWalletProvider {\n /**\n * @constructor\n * @param {Openid4vciWalletProviderOptions} options - The configuration options for the provider.\n */\n constructor(options: Openid4vciWalletProviderOptions) {\n super(options);\n }\n\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 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;;;ACCA,wBAGO;AACP,mBAAiC;AA4D1B,IAAM,mBAAN,cAA+B,2CAAyB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK7D,YAAY,SAA0C;AACpD,UAAM,OAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAa,6BACX,SACiB;AACjB,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
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/ItWalletProvider.ts
|
|
2
|
+
import {
|
|
3
|
+
Openid4vciWalletProvider
|
|
4
|
+
} from "@openid4vc/openid4vci";
|
|
5
|
+
import { addSecondsToDate } from "@openid4vc/utils";
|
|
6
|
+
var ItWalletProvider = class extends Openid4vciWalletProvider {
|
|
7
|
+
/**
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param {Openid4vciWalletProviderOptions} options - The configuration options for the provider.
|
|
10
|
+
*/
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super(options);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a wallet attestation JWT.
|
|
16
|
+
*
|
|
17
|
+
* This method constructs a signed JWT that asserts the wallet's control over a specific
|
|
18
|
+
* cryptographic key (DPoP key). This is a security measure to ensure that the entity
|
|
19
|
+
* presenting the credential offer is the legitimate wallet instance.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
* @async
|
|
23
|
+
* @param {WalletAttestationOptions} options - The necessary parameters to build the attestation.
|
|
24
|
+
* @returns {Promise<string>} A promise that resolves to the signed wallet attestation JWT as a string.
|
|
25
|
+
*/
|
|
26
|
+
async createItWalletAttestationJwt(options) {
|
|
27
|
+
const walletAttestation = await this.createWalletAttestationJwt({
|
|
28
|
+
clientId: options.dpopJwkPublic.kid,
|
|
29
|
+
confirmation: {
|
|
30
|
+
// We use the same key for DPoP as the wallet attestation
|
|
31
|
+
jwk: options.dpopJwkPublic
|
|
32
|
+
},
|
|
33
|
+
expiresAt: options.expiresAt ?? addSecondsToDate(/* @__PURE__ */ new Date(), 3600 * 24 * 60 * 60),
|
|
34
|
+
issuer: options.issuer,
|
|
35
|
+
signer: {
|
|
36
|
+
alg: "ES256",
|
|
37
|
+
kid: options.signer.walletProviderJwkPublicKid,
|
|
38
|
+
method: "federation",
|
|
39
|
+
// Indicates the validation method relies on a trust chain.
|
|
40
|
+
trustChain: options.signer.trustChain
|
|
41
|
+
},
|
|
42
|
+
walletLink: options.walletLink,
|
|
43
|
+
walletName: options.walletName
|
|
44
|
+
});
|
|
45
|
+
return walletAttestation;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
ItWalletProvider
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ItWalletProvider.ts"],"sourcesContent":["import { ClientAttestationJwtPayload } from \"@openid4vc/oauth2\";\nimport {\n Openid4vciWalletProvider,\n Openid4vciWalletProviderOptions,\n} from \"@openid4vc/openid4vci\";\nimport { addSecondsToDate } from \"@openid4vc/utils\";\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 issuer of the attestation, typically the Wallet Provider's identifier.\n * @type {string}\n */\n issuer: string;\n \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 signer: {\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 * 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 /**\n * An optional display name for the wallet.\n * @type {string}\n */\n walletName?: string;\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 * 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\n/**\n * @class ItWalletProvider\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 ItWalletProvider extends Openid4vciWalletProvider {\n /**\n * @constructor\n * @param {Openid4vciWalletProviderOptions} options - The configuration options for the provider.\n */\n constructor(options: Openid4vciWalletProviderOptions) {\n super(options);\n }\n\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 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":";AACA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,wBAAwB;AA4D1B,IAAM,mBAAN,cAA+B,yBAAyB;AAAA;AAAA;AAAA;AAAA;AAAA,EAK7D,YAAY,SAA0C;AACpD,UAAM,OAAO;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcA,MAAa,6BACX,SACiB;AACjB,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
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pagopa/io-wallet-oid4vci",
|
|
3
|
+
"version": "0.3.0",
|
|
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/oid4vci",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/pagopa/io-wallet-sdk",
|
|
20
|
+
"directory": "packages/oid4vci"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@openid-federation/core": "^0.2.0",
|
|
24
|
+
"@openid4vc/oauth2": "0.3.0-alpha-20250513122832",
|
|
25
|
+
"@openid4vc/openid4vci": "0.3.0-alpha-20250513122832",
|
|
26
|
+
"@openid4vc/utils": "^0.2.0",
|
|
27
|
+
"zod": "^3.24.2"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --clean --sourcemap",
|
|
31
|
+
"test": "vitest"
|
|
32
|
+
},
|
|
33
|
+
"main": "./dist/index.js",
|
|
34
|
+
"module": "./dist/index.mjs",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
}
|