@pagopa/io-react-native-wallet 0.27.1 → 0.28.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/lib/commonjs/client/generated/wallet-provider.js +27 -19
- package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +3 -0
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/presentation/01-start-flow.js +14 -24
- package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/commonjs/credential/presentation/03-get-request-object.js +30 -42
- package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
- package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +32 -0
- package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
- package/lib/commonjs/credential/presentation/05-verify-request-object.js +53 -0
- package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
- package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +39 -0
- package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +125 -0
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +289 -0
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
- package/lib/commonjs/credential/presentation/08-send-authorization-response.js +170 -0
- package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
- package/lib/commonjs/credential/presentation/errors.js +69 -1
- package/lib/commonjs/credential/presentation/errors.js.map +1 -1
- package/lib/commonjs/credential/presentation/index.js +29 -1
- package/lib/commonjs/credential/presentation/index.js.map +1 -1
- package/lib/commonjs/credential/presentation/types.js +124 -3
- package/lib/commonjs/credential/presentation/types.js.map +1 -1
- package/lib/commonjs/sd-jwt/index.js +41 -1
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/trust/chain.js +35 -50
- package/lib/commonjs/trust/chain.js.map +1 -1
- package/lib/commonjs/trust/index.js +139 -16
- package/lib/commonjs/trust/index.js.map +1 -1
- package/lib/commonjs/trust/types.js +36 -12
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/trust/utils.js +41 -0
- package/lib/commonjs/trust/utils.js.map +1 -0
- package/lib/commonjs/utils/jwk.js +5 -1
- package/lib/commonjs/utils/jwk.js.map +1 -1
- package/lib/commonjs/wallet-instance/index.js +10 -0
- package/lib/commonjs/wallet-instance/index.js.map +1 -1
- package/lib/module/client/generated/wallet-provider.js +22 -15
- package/lib/module/client/generated/wallet-provider.js.map +1 -1
- package/lib/module/credential/issuance/03-start-user-authorization.js +3 -0
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/module/credential/presentation/01-start-flow.js +14 -24
- package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/module/credential/presentation/03-get-request-object.js +31 -43
- package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
- package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +25 -0
- package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
- package/lib/module/credential/presentation/05-verify-request-object.js +46 -0
- package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
- package/lib/module/credential/presentation/06-fetch-presentation-definition.js +32 -0
- package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js +117 -0
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +278 -0
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
- package/lib/module/credential/presentation/08-send-authorization-response.js +158 -0
- package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
- package/lib/module/credential/presentation/errors.js +64 -0
- package/lib/module/credential/presentation/errors.js.map +1 -1
- package/lib/module/credential/presentation/index.js +6 -2
- package/lib/module/credential/presentation/index.js.map +1 -1
- package/lib/module/credential/presentation/types.js +121 -2
- package/lib/module/credential/presentation/types.js.map +1 -1
- package/lib/module/sd-jwt/index.js +40 -1
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/trust/chain.js +32 -46
- package/lib/module/trust/chain.js.map +1 -1
- package/lib/module/trust/index.js +139 -18
- package/lib/module/trust/index.js.map +1 -1
- package/lib/module/trust/types.js +34 -11
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/trust/utils.js +33 -0
- package/lib/module/trust/utils.js.map +1 -0
- package/lib/module/utils/jwk.js +3 -0
- package/lib/module/utils/jwk.js.map +1 -1
- package/lib/module/wallet-instance/index.js +9 -0
- package/lib/module/wallet-instance/index.js.map +1 -1
- package/lib/typescript/client/generated/wallet-provider.d.ts +91 -54
- package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +26 -5
- package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts +7 -10
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts +23 -0
- package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +18 -0
- package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +21 -0
- package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +20 -0
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +88 -0
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +70 -0
- package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/errors.d.ts +44 -0
- package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/index.d.ts +7 -3
- package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/types.d.ts +747 -10
- package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
- package/lib/typescript/credential/status/types.d.ts +6 -6
- package/lib/typescript/sd-jwt/index.d.ts +31 -12
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +6 -6
- package/lib/typescript/trust/chain.d.ts +4 -9
- package/lib/typescript/trust/chain.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +337 -61
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +4074 -407
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/trust/utils.d.ts +12 -0
- package/lib/typescript/trust/utils.d.ts.map +1 -0
- package/lib/typescript/utils/decoder.d.ts +1 -1
- package/lib/typescript/utils/decoder.d.ts.map +1 -1
- package/lib/typescript/utils/jwk.d.ts +137 -0
- package/lib/typescript/utils/jwk.d.ts.map +1 -1
- package/lib/typescript/wallet-instance/index.d.ts +8 -0
- package/lib/typescript/wallet-instance/index.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +36 -36
- package/package.json +5 -2
- package/src/client/generated/wallet-provider.ts +28 -19
- package/src/credential/issuance/03-start-user-authorization.ts +3 -0
- package/src/credential/presentation/01-start-flow.ts +19 -26
- package/src/credential/presentation/03-get-request-object.ts +35 -58
- package/src/credential/presentation/04-retrieve-rp-jwks.ts +34 -0
- package/src/credential/presentation/05-verify-request-object.ts +52 -0
- package/src/credential/presentation/06-fetch-presentation-definition.ts +48 -0
- package/src/credential/presentation/07-evaluate-dcql-query.ts +166 -0
- package/src/credential/presentation/07-evaluate-input-descriptor.ts +391 -0
- package/src/credential/presentation/08-send-authorization-response.ts +220 -0
- package/src/credential/presentation/errors.ts +64 -0
- package/src/credential/presentation/index.ts +22 -1
- package/src/credential/presentation/types.ts +133 -2
- package/src/sd-jwt/index.ts +49 -1
- package/src/trust/chain.ts +46 -66
- package/src/trust/index.ts +185 -20
- package/src/trust/types.ts +34 -10
- package/src/trust/utils.ts +35 -0
- package/src/utils/decoder.ts +1 -1
- package/src/utils/jwk.ts +8 -1
- package/src/wallet-instance/index.ts +13 -0
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js +0 -138
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +0 -1
- package/lib/module/credential/presentation/04-send-authorization-response.js +0 -128
- package/lib/module/credential/presentation/04-send-authorization-response.js.map +0 -1
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts +0 -34
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +0 -1
- package/src/credential/presentation/04-send-authorization-response.ts +0 -168
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.RequestObject = void 0;
|
6
|
+
exports.WalletMetadata = exports.RequestObjectWalletCapabilities = exports.RequestObject = exports.PresentationDefinition = exports.LegacyDirectAuthorizationBodyPayload = exports.InputDescriptor = exports.DirectAuthorizationBodyPayload = void 0;
|
7
7
|
var _types = require("../../sd-jwt/types");
|
8
8
|
var z = _interopRequireWildcard(require("zod"));
|
9
9
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
@@ -12,6 +12,81 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
12
12
|
* A pair that associate a tokenized Verified Credential with the claims presented or requested to present.
|
13
13
|
*/
|
14
14
|
|
15
|
+
/**
|
16
|
+
* A object that associate the information needed to multiple remote presentation
|
17
|
+
* Used with `presentation_definition`
|
18
|
+
* @deprecated Use `RemotePresentation`
|
19
|
+
*/
|
20
|
+
|
21
|
+
/**
|
22
|
+
* A object that associate the information needed to multiple remote presentation
|
23
|
+
* Used with DCQL queries
|
24
|
+
*/
|
25
|
+
|
26
|
+
const Fields = z.object({
|
27
|
+
path: z.array(z.string().min(1)),
|
28
|
+
// Array of JSONPath string expressions
|
29
|
+
id: z.string().optional(),
|
30
|
+
// Unique string ID
|
31
|
+
purpose: z.string().optional(),
|
32
|
+
// Purpose of the field
|
33
|
+
name: z.string().optional(),
|
34
|
+
// Human-friendly name
|
35
|
+
filter: z.any().optional(),
|
36
|
+
// JSON Schema descriptor for filtering
|
37
|
+
optional: z.boolean().optional(),
|
38
|
+
// Boolean indicating if the field is optional
|
39
|
+
intent_to_retain: z.boolean().optional() // Boolean indicating that the Verifier intends to retain the Claim's data being requested
|
40
|
+
});
|
41
|
+
|
42
|
+
// Define the Constraints Object Schema
|
43
|
+
const Constraints = z.object({
|
44
|
+
fields: z.array(Fields).optional(),
|
45
|
+
// Array of Field Objects
|
46
|
+
limit_disclosure: z.enum(["required", "preferred"]).optional() // Limit disclosure property
|
47
|
+
});
|
48
|
+
|
49
|
+
// Define the Input Descriptor Object Schema
|
50
|
+
|
51
|
+
const InputDescriptor = z.object({
|
52
|
+
id: z.string().min(1),
|
53
|
+
// Mandatory unique string ID
|
54
|
+
name: z.string().optional(),
|
55
|
+
// Human-friendly name
|
56
|
+
purpose: z.string().optional(),
|
57
|
+
// Purpose of the schema
|
58
|
+
format: z.record(z.string(), z.any()).optional(),
|
59
|
+
// Object with Claim Format Designations
|
60
|
+
constraints: Constraints,
|
61
|
+
// Constraints Object (mandatory)
|
62
|
+
group: z.string().optional() // Match one of the grouping strings listed in the "from" values of a Submission Requirement Rule
|
63
|
+
});
|
64
|
+
exports.InputDescriptor = InputDescriptor;
|
65
|
+
const SubmissionRequirement = z.object({
|
66
|
+
name: z.string().optional(),
|
67
|
+
purpose: z.string().optional(),
|
68
|
+
rule: z.string(),
|
69
|
+
// "all": all group's rules must be present, or "pick": at least group's "count" rules must be present
|
70
|
+
from: z.string().optional(),
|
71
|
+
// MUST contain either a "from" or "from_nested" property
|
72
|
+
from_nested: z.array(z.object({
|
73
|
+
name: z.string().optional(),
|
74
|
+
purpose: z.string().optional(),
|
75
|
+
rule: z.string(),
|
76
|
+
from: z.string()
|
77
|
+
})).optional(),
|
78
|
+
count: z.number().optional()
|
79
|
+
//"count", "min", and "max" may be present with a "pick" rule
|
80
|
+
});
|
81
|
+
|
82
|
+
const PresentationDefinition = z.object({
|
83
|
+
id: z.string(),
|
84
|
+
name: z.string().optional(),
|
85
|
+
purpose: z.string().optional(),
|
86
|
+
input_descriptors: z.array(InputDescriptor),
|
87
|
+
submission_requirements: z.array(SubmissionRequirement).optional()
|
88
|
+
});
|
89
|
+
exports.PresentationDefinition = PresentationDefinition;
|
15
90
|
const RequestObject = z.object({
|
16
91
|
iss: z.string(),
|
17
92
|
iat: _types.UnixTime,
|
@@ -19,11 +94,57 @@ const RequestObject = z.object({
|
|
19
94
|
state: z.string(),
|
20
95
|
nonce: z.string(),
|
21
96
|
response_uri: z.string(),
|
97
|
+
response_uri_method: z.string().optional(),
|
22
98
|
response_type: z.literal("vp_token"),
|
23
99
|
response_mode: z.literal("direct_post.jwt"),
|
24
100
|
client_id: z.string(),
|
25
|
-
|
26
|
-
|
101
|
+
dcql_query: z.record(z.string(), z.any()).optional(),
|
102
|
+
// Validation happens within the `dcql` library, no need to duplicate it here
|
103
|
+
scope: z.string().optional(),
|
104
|
+
presentation_definition: PresentationDefinition.optional()
|
27
105
|
});
|
28
106
|
exports.RequestObject = RequestObject;
|
107
|
+
const WalletMetadata = z.object({
|
108
|
+
presentation_definition_uri_supported: z.boolean().optional(),
|
109
|
+
client_id_schemes_supported: z.array(z.string()).optional(),
|
110
|
+
request_object_signing_alg_values_supported: z.array(z.string()).optional(),
|
111
|
+
vp_formats_supported: z.record(z.string(),
|
112
|
+
// TODO [SIW-2110]: use explicit credential format?
|
113
|
+
z.object({
|
114
|
+
"sd-jwt_alg_values": z.array(z.string()).optional() // alg_values_supported?
|
115
|
+
}))
|
116
|
+
// TODO [SIW-2110]: include other metadata?
|
117
|
+
});
|
118
|
+
|
119
|
+
/**
|
120
|
+
* Wallet capabilities that must be submitted to get the Request Object
|
121
|
+
* via POST request when the `request_uri_method` is `post`.
|
122
|
+
*/
|
123
|
+
exports.WalletMetadata = WalletMetadata;
|
124
|
+
const RequestObjectWalletCapabilities = z.object({
|
125
|
+
wallet_metadata: WalletMetadata,
|
126
|
+
wallet_nonce: z.string().optional()
|
127
|
+
});
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Authorization Response payload when using `presentation_definition`.
|
131
|
+
* @deprecated Use `DirectAuthorizationBodyPayload`
|
132
|
+
*/
|
133
|
+
exports.RequestObjectWalletCapabilities = RequestObjectWalletCapabilities;
|
134
|
+
/**
|
135
|
+
* @deprecated Use `DirectAuthorizationBodyPayload`
|
136
|
+
*/
|
137
|
+
const LegacyDirectAuthorizationBodyPayload = z.object({
|
138
|
+
vp_token: z.union([z.string(), z.array(z.string())]).optional(),
|
139
|
+
presentation_submission: z.record(z.string(), z.unknown())
|
140
|
+
});
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Authorization Response payload when using DCQL queries.
|
144
|
+
*/
|
145
|
+
exports.LegacyDirectAuthorizationBodyPayload = LegacyDirectAuthorizationBodyPayload;
|
146
|
+
const DirectAuthorizationBodyPayload = z.object({
|
147
|
+
vp_token: z.record(z.string(), z.string())
|
148
|
+
});
|
149
|
+
exports.DirectAuthorizationBodyPayload = DirectAuthorizationBodyPayload;
|
29
150
|
//# sourceMappingURL=types.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_types","require","z","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","
|
1
|
+
{"version":3,"names":["_types","require","z","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","Fields","object","path","array","string","min","id","optional","purpose","name","filter","any","boolean","intent_to_retain","Constraints","fields","limit_disclosure","enum","InputDescriptor","format","record","constraints","group","exports","SubmissionRequirement","rule","from","from_nested","count","number","PresentationDefinition","input_descriptors","submission_requirements","RequestObject","iss","iat","UnixTime","exp","state","nonce","response_uri","response_uri_method","response_type","literal","response_mode","client_id","dcql_query","scope","presentation_definition","WalletMetadata","presentation_definition_uri_supported","client_id_schemes_supported","request_object_signing_alg_values_supported","vp_formats_supported","RequestObjectWalletCapabilities","wallet_metadata","wallet_nonce","LegacyDirectAuthorizationBodyPayload","vp_token","union","presentation_submission","unknown","DirectAuthorizationBodyPayload"],"sourceRoot":"../../../../src","sources":["credential/presentation/types.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,CAAA,GAAAC,uBAAA,CAAAF,OAAA;AAAyB,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,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CAAC,EAAE5B,CAAC,CAACqF,OAAO,CAAC,CAAC;AAC3D,CAAC,CAAC;;AAEF;AACA;AACA;AAFAtC,OAAA,CAAAkC,oCAAA,GAAAA,oCAAA;AAMO,MAAMK,8BAA8B,GAAGtF,CAAC,CAACyB,MAAM,CAAC;EACrDyD,QAAQ,EAAElF,CAAC,CAAC4C,MAAM,CAAC5C,CAAC,CAAC4B,MAAM,CAAC,CAAC,EAAE5B,CAAC,CAAC4B,MAAM,CAAC,CAAC;AAC3C,CAAC,CAAC;AAACmB,OAAA,CAAAuC,8BAAA,GAAAA,8BAAA"}
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, "SdJwt4VC", {
|
|
10
10
|
return _types.SdJwt4VC;
|
11
11
|
}
|
12
12
|
});
|
13
|
-
exports.verify = exports.disclose = exports.decode = void 0;
|
13
|
+
exports.verify = exports.prepareVpToken = exports.disclose = exports.decode = void 0;
|
14
14
|
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
15
15
|
var _types = require("./types");
|
16
16
|
var _verifier = require("./verifier");
|
@@ -165,5 +165,45 @@ const verify = async (token, publicKey, customSchema) => {
|
|
165
165
|
disclosures: decoded.disclosures.map(d => d.decoded)
|
166
166
|
};
|
167
167
|
};
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Prepares a Verified Presentation (VP) token to be sent as part of an
|
171
|
+
* authorization response in an OpenID 4 Verifiable Presentations flow.
|
172
|
+
*
|
173
|
+
* @param nonce - The nonce provided by the relying party.
|
174
|
+
* @param client_id - The client identifier of the relying party.
|
175
|
+
* @param presentation - An object containing the verifiable credential, the claims to disclose,
|
176
|
+
* and the cryptographic context for signing.
|
177
|
+
* @returns An object containing the signed VP token (`vp_token`).
|
178
|
+
*
|
179
|
+
* @remarks
|
180
|
+
* 1. The `disclose()` function is used to produce a token with only the requested claims.
|
181
|
+
* 2. A KB-JWT is then signed, including sd_hash and `nonce`.
|
182
|
+
* 3. The `vp_token` is composed of the disclosed VP and the KB-JWT.
|
183
|
+
*/
|
168
184
|
exports.verify = verify;
|
185
|
+
const prepareVpToken = async (nonce, client_id, _ref2) => {
|
186
|
+
let [verifiableCredential, requestedClaims, cryptoContext] = _ref2;
|
187
|
+
// Produce a VP token with only requested claims from the verifiable credential
|
188
|
+
const {
|
189
|
+
token: vp
|
190
|
+
} = await disclose(verifiableCredential, requestedClaims);
|
191
|
+
|
192
|
+
// <Issuer-signed JWT>~<Disclosure 1>~<Disclosure N>~
|
193
|
+
const sd_hash = await (0, _ioReactNativeJwt.sha256ToBase64)(`${vp}~`);
|
194
|
+
const kbJwt = await new _ioReactNativeJwt.SignJWT(cryptoContext).setProtectedHeader({
|
195
|
+
typ: "kb+jwt",
|
196
|
+
alg: "ES256"
|
197
|
+
}).setPayload({
|
198
|
+
sd_hash,
|
199
|
+
nonce: nonce
|
200
|
+
}).setAudience(client_id).setIssuedAt().sign();
|
201
|
+
|
202
|
+
// <Issuer-signed JWT>~<Disclosure 1>~...~<Disclosure N>~<KB-JWT>
|
203
|
+
const vp_token = [vp, kbJwt].join("~");
|
204
|
+
return {
|
205
|
+
vp_token
|
206
|
+
};
|
207
|
+
};
|
208
|
+
exports.prepareVpToken = prepareVpToken;
|
169
209
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_ioReactNativeJwt","require","_types","_verifier","Errors","_interopRequireWildcard","exports","_jsBase","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","decodeDisclosure","encoded","utf8String","Base64","decode","decoded","Disclosure","parse","JSON","token","customSchema","slice","rawSdJwt","rawDisclosures","split","decodedJwt","decodeJwt","parser","SdJwt4VC","sdJwt","header","protectedHeader","payload","disclosures","map","disclose","claims","paths","Promise","all","claim","disclosure","find","_ref","name","ClaimsNotFoundBetweenDisclosures","hash","sha256ToBase64","_sd","includes","index","indexOf","path","ClaimsNotFoundInToken","filteredDisclosures","filter","d","disclosedToken","join","verify","publicKey","verifyJwt","verifyDisclosure"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":";;;;;;;;;;;;;AAEA,IAAAA,iBAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAAmCK,OAAA,CAAAF,MAAA,GAAAA,MAAA;AACnC,IAAAG,OAAA,GAAAN,OAAA;AAAmC,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;
|
1
|
+
{"version":3,"names":["_ioReactNativeJwt","require","_types","_verifier","Errors","_interopRequireWildcard","exports","_jsBase","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","decodeDisclosure","encoded","utf8String","Base64","decode","decoded","Disclosure","parse","JSON","token","customSchema","slice","rawSdJwt","rawDisclosures","split","decodedJwt","decodeJwt","parser","SdJwt4VC","sdJwt","header","protectedHeader","payload","disclosures","map","disclose","claims","paths","Promise","all","claim","disclosure","find","_ref","name","ClaimsNotFoundBetweenDisclosures","hash","sha256ToBase64","_sd","includes","index","indexOf","path","ClaimsNotFoundInToken","filteredDisclosures","filter","d","disclosedToken","join","verify","publicKey","verifyJwt","verifyDisclosure","prepareVpToken","nonce","client_id","_ref2","verifiableCredential","requestedClaims","cryptoContext","vp","sd_hash","kbJwt","SignJWT","setProtectedHeader","typ","alg","setPayload","setAudience","setIssuedAt","sign","vp_token"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":";;;;;;;;;;;;;AAEA,IAAAA,iBAAA,GAAAC,OAAA;AAGA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAAmCK,OAAA,CAAAF,MAAA,GAAAA,MAAA;AACnC,IAAAG,OAAA,GAAAN,OAAA;AAAmC,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,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BAAoB,EAAEC,eAAe,CAAC;;EAE3E;EACA,MAAMG,OAAO,GAAG,MAAM,IAAAxB,gCAAc,EAAE,GAAEuB,EAAG,GAAE,CAAC;EAE9C,MAAME,KAAK,GAAG,MAAM,IAAIC,yBAAO,CAACJ,aAAa,CAAC,CAC3CK,kBAAkB,CAAC;IAClBC,GAAG,EAAE,QAAQ;IACbC,GAAG,EAAE;EACP,CAAC,CAAC,CACDC,UAAU,CAAC;IACVN,OAAO;IACPP,KAAK,EAAEA;EACT,CAAC,CAAC,CACDc,WAAW,CAACb,SAAS,CAAC,CACtBc,WAAW,CAAC,CAAC,CACbC,IAAI,CAAC,CAAC;;EAET;EACA,MAAMC,QAAQ,GAAG,CAACX,EAAE,EAAEE,KAAK,CAAC,CAACd,IAAI,CAAC,GAAG,CAAC;EAEtC,OAAO;IAAEuB;EAAS,CAAC;AACrB,CAAC;AAAC/F,OAAA,CAAA6E,cAAA,GAAAA,cAAA"}
|
@@ -5,40 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.renewTrustChain = renewTrustChain;
|
7
7
|
exports.validateTrustChain = validateTrustChain;
|
8
|
-
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
9
8
|
var _types = require("./types");
|
10
9
|
var _errors = require("../utils/errors");
|
11
10
|
var z = _interopRequireWildcard(require("zod"));
|
12
11
|
var _ = require(".");
|
12
|
+
var _utils = require("./utils");
|
13
13
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
14
14
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
15
|
-
// Verify a token signature
|
16
|
-
// The kid is extracted from the token header
|
17
|
-
const verify = async (token, kid, jwks) => {
|
18
|
-
const jwk = jwks.find(k => k.kid === kid);
|
19
|
-
if (!jwk) {
|
20
|
-
throw new Error(`Invalid kid: ${kid}, token: ${token}`);
|
21
|
-
}
|
22
|
-
const {
|
23
|
-
protectedHeader: header,
|
24
|
-
payload
|
25
|
-
} = await (0, _ioReactNativeJwt.verify)(token, jwk);
|
26
|
-
return {
|
27
|
-
header,
|
28
|
-
payload
|
29
|
-
};
|
30
|
-
};
|
31
|
-
const decode = token => {
|
32
|
-
const {
|
33
|
-
protectedHeader: header,
|
34
|
-
payload
|
35
|
-
} = (0, _ioReactNativeJwt.decode)(token);
|
36
|
-
return {
|
37
|
-
header,
|
38
|
-
payload
|
39
|
-
};
|
40
|
-
};
|
41
|
-
|
42
15
|
// The first element of the chain is supposed to be the Entity Configuration for the document issuer
|
43
16
|
const FirstElementShape = _types.EntityConfiguration;
|
44
17
|
// Each element but the first is supposed to be an Entity Statement
|
@@ -51,7 +24,7 @@ const LastElementShape = z.union([_types.EntityStatement, _types.TrustAnchorEnti
|
|
51
24
|
* Validates a provided trust chain against a known trust
|
52
25
|
*
|
53
26
|
* @param trustAnchorEntity The entity configuration of the known trust anchor
|
54
|
-
* @param chain The chain of statements to be
|
27
|
+
* @param chain The chain of statements to be validated
|
55
28
|
* @returns The list of parsed token representing the chain
|
56
29
|
* @throws {IoWalletError} If the chain is not valid
|
57
30
|
*/
|
@@ -71,11 +44,11 @@ async function validateTrustChain(trustAnchorEntity, chain) {
|
|
71
44
|
throw new _errors.IoWalletError(`Cannot select kid: empty token`);
|
72
45
|
}
|
73
46
|
const shape = selectTokenShape(currentIndex);
|
74
|
-
return shape.parse(decode(token)).header.kid;
|
47
|
+
return shape.parse((0, _utils.decode)(token)).header.kid;
|
75
48
|
};
|
76
49
|
|
77
50
|
// select keys from the next token
|
78
|
-
// if the current token is the last, keys
|
51
|
+
// if the current token is the last, keys from trust anchor will be used
|
79
52
|
const selectKeys = currentIndex => {
|
80
53
|
if (currentIndex === chain.length - 1) {
|
81
54
|
return trustAnchorEntity.payload.jwks.keys;
|
@@ -86,12 +59,12 @@ async function validateTrustChain(trustAnchorEntity, chain) {
|
|
86
59
|
throw new _errors.IoWalletError(`Cannot select keys: empty nextToken`);
|
87
60
|
}
|
88
61
|
const shape = selectTokenShape(nextIndex);
|
89
|
-
return shape.parse(decode(nextToken)).payload.jwks.keys;
|
62
|
+
return shape.parse((0, _utils.decode)(nextToken)).payload.jwks.keys;
|
90
63
|
};
|
91
64
|
|
92
65
|
// Iterate the chain and validate each element's signature against the public keys of its next
|
93
|
-
// If there is no next, hence it's the end of the chain and it must be verified by the Trust Anchor
|
94
|
-
return Promise.all(chain.map((token, i) => [token, selectKid(i), selectKeys(i)]).map(args => verify(...args)));
|
66
|
+
// If there is no next, hence it's the end of the chain, and it must be verified by the Trust Anchor
|
67
|
+
return Promise.all(chain.map((token, i) => [token, selectKid(i), selectKeys(i)]).map(args => (0, _utils.verify)(...args)));
|
95
68
|
}
|
96
69
|
|
97
70
|
/**
|
@@ -99,24 +72,36 @@ async function validateTrustChain(trustAnchorEntity, chain) {
|
|
99
72
|
*
|
100
73
|
* @param chain The original chain
|
101
74
|
* @param appFetch (optional) fetch api implementation
|
102
|
-
* @returns A list of signed token that
|
103
|
-
* @throws When an element of the chain fails to parse
|
75
|
+
* @returns A list of signed token that represent the trust chain, in the same order of the provided chain
|
76
|
+
* @throws IoWalletError When an element of the chain fails to parse
|
104
77
|
*/
|
105
|
-
function renewTrustChain(chain) {
|
78
|
+
async function renewTrustChain(chain) {
|
106
79
|
let appFetch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fetch;
|
107
|
-
return Promise.all(chain
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
}
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
80
|
+
return Promise.all(chain.map(async (token, index) => {
|
81
|
+
const decoded = (0, _utils.decode)(token);
|
82
|
+
const entityStatementResult = _types.EntityStatement.safeParse(decoded);
|
83
|
+
const entityConfigurationResult = _types.EntityConfiguration.safeParse(decoded);
|
84
|
+
if (entityConfigurationResult.success) {
|
85
|
+
return (0, _.getSignedEntityConfiguration)(entityConfigurationResult.data.payload.iss, {
|
86
|
+
appFetch
|
87
|
+
});
|
88
|
+
}
|
89
|
+
if (entityStatementResult.success) {
|
90
|
+
const entityStatement = entityStatementResult.data;
|
91
|
+
const parentBaseUrl = entityStatement.payload.iss;
|
92
|
+
const parentECJwt = await (0, _.getSignedEntityConfiguration)(parentBaseUrl, {
|
93
|
+
appFetch
|
94
|
+
});
|
95
|
+
const parentEC = _types.EntityConfiguration.parse((0, _utils.decode)(parentECJwt));
|
96
|
+
const federationFetchEndpoint = parentEC.payload.metadata.federation_entity.federation_fetch_endpoint;
|
97
|
+
if (!federationFetchEndpoint) {
|
98
|
+
throw new _errors.IoWalletError(`Parent EC at ${parentBaseUrl} is missing federation_fetch_endpoint`);
|
99
|
+
}
|
100
|
+
return (0, _.getSignedEntityStatement)(federationFetchEndpoint, entityStatement.payload.sub, {
|
101
|
+
appFetch
|
102
|
+
});
|
103
|
+
}
|
104
|
+
throw new _errors.IoWalletError(`Cannot renew trust chain because element #${index} failed to parse.`);
|
120
105
|
}));
|
121
106
|
}
|
122
107
|
//# sourceMappingURL=chain.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["_types","require","_errors","z","_interopRequireWildcard","_","_utils","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","FirstElementShape","EntityConfiguration","MiddleElementShape","EntityStatement","LastElementShape","union","TrustAnchorEntityConfiguration","validateTrustChain","trustAnchorEntity","chain","length","IoWalletError","selectTokenShape","elementIndex","selectKid","currentIndex","token","shape","parse","decode","header","kid","selectKeys","payload","jwks","keys","nextIndex","nextToken","Promise","all","map","i","args","verify","renewTrustChain","appFetch","arguments","undefined","fetch","index","decoded","entityStatementResult","safeParse","entityConfigurationResult","success","getSignedEntityConfiguration","data","iss","entityStatement","parentBaseUrl","parentECJwt","parentEC","federationFetchEndpoint","metadata","federation_entity","federation_fetch_endpoint","getSignedEntityStatement","sub"],"sourceRoot":"../../../src","sources":["trust/chain.ts"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAMA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,CAAA,GAAAC,uBAAA,CAAAH,OAAA;AACA,IAAAI,CAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAL,OAAA;AAA2D,SAAAM,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAJ,wBAAAQ,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,C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a,CACpB,6CAA4C4B,KAAM,mBACrD,CAAC;EACH,CAAC,CACH,CAAC;AACH"}
|
@@ -3,25 +3,29 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
+
exports.buildTrustChain = buildTrustChain;
|
6
7
|
exports.getEntityConfiguration = exports.getCredentialIssuerEntityConfiguration = void 0;
|
7
8
|
exports.getEntityStatement = getEntityStatement;
|
9
|
+
exports.getFederationList = getFederationList;
|
8
10
|
exports.getRelyingPartyEntityConfiguration = void 0;
|
9
11
|
exports.getSignedEntityConfiguration = getSignedEntityConfiguration;
|
10
12
|
exports.getSignedEntityStatement = getSignedEntityStatement;
|
11
13
|
exports.getWalletProviderEntityConfiguration = exports.getTrustAnchorEntityConfiguration = void 0;
|
12
14
|
exports.verifyTrustChain = verifyTrustChain;
|
15
|
+
var _utils = require("./utils");
|
13
16
|
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
14
17
|
var _types = require("./types");
|
15
18
|
var _chain = require("./chain");
|
16
19
|
var _misc = require("../utils/misc");
|
20
|
+
var _errors = require("../utils/errors");
|
17
21
|
/**
|
18
22
|
* Verify a given trust chain is actually valid.
|
19
23
|
* It can handle fast chain renewal, which means we try to fetch a fresh version of each statement.
|
20
24
|
*
|
21
25
|
* @param trustAnchorEntity The entity configuration of the known trust anchor
|
22
|
-
* @param chain The chain of statements to be
|
23
|
-
* @param
|
24
|
-
* @param
|
26
|
+
* @param chain The chain of statements to be validated
|
27
|
+
* @param renewOnFail Whether to renew the provided chain if the validation fails at first. Default: true
|
28
|
+
* @param appFetch Fetch api implementation. Default: the built-in implementation
|
25
29
|
* @returns The result of the chain validation
|
26
30
|
* @throws {IoWalletError} When either validation or renewal fail
|
27
31
|
*/
|
@@ -46,7 +50,7 @@ async function verifyTrustChain(trustAnchorEntity, chain) {
|
|
46
50
|
* Fetch the signed entity configuration token for an entity
|
47
51
|
*
|
48
52
|
* @param entityBaseUrl The url of the entity to fetch
|
49
|
-
* @param
|
53
|
+
* @param appFetch (optional) fetch api implementation
|
50
54
|
* @returns The signed Entity Configuration token
|
51
55
|
*/
|
52
56
|
async function getSignedEntityConfiguration(entityBaseUrl) {
|
@@ -71,6 +75,7 @@ async function getSignedEntityConfiguration(entityBaseUrl) {
|
|
71
75
|
*
|
72
76
|
* @param entityBaseUrl The base url of the entity.
|
73
77
|
* @param schema The expected schema of the entity configuration, according to the kind of entity we are fetching from.
|
78
|
+
* @param options An optional object with additional options.
|
74
79
|
* @param options.appFetch An optional instance of the http client to be used.
|
75
80
|
* @returns The parsed entity configuration object
|
76
81
|
* @throws {IoWalletError} If the http request fails
|
@@ -103,9 +108,9 @@ const getEntityConfiguration = (entityBaseUrl, options) => fetchAndParseEntityCo
|
|
103
108
|
/**
|
104
109
|
* Fetch and parse the entity statement document for a given federation entity.
|
105
110
|
*
|
106
|
-
* @param accreditationBodyBaseUrl The base url of the
|
111
|
+
* @param accreditationBodyBaseUrl The base url of the accreditation body which holds and signs the required entity statement
|
107
112
|
* @param subordinatedEntityBaseUrl The url that identifies the subordinate entity
|
108
|
-
* @param
|
113
|
+
* @param appFetch An optional instance of the http client to be used.
|
109
114
|
* @returns The parsed entity configuration object
|
110
115
|
* @throws {IoWalletError} If the http request fails
|
111
116
|
* @throws Parse error if the document is not in the expected shape.
|
@@ -128,21 +133,139 @@ async function getEntityStatement(accreditationBodyBaseUrl, subordinatedEntityBa
|
|
128
133
|
/**
|
129
134
|
* Fetch the entity statement document for a given federation entity.
|
130
135
|
*
|
131
|
-
* @param
|
132
|
-
* @param subordinatedEntityBaseUrl The url that identifies the subordinate entity
|
133
|
-
* @param
|
134
|
-
* @returns The signed entity statement token
|
135
|
-
* @throws {IoWalletError} If the http request fails
|
136
|
+
* @param federationFetchEndpoint The exact endpoint provided by the parent EC's metadata.
|
137
|
+
* @param subordinatedEntityBaseUrl The url that identifies the subordinate entity.
|
138
|
+
* @param appFetch An optional instance of the http client to be used.
|
139
|
+
* @returns The signed entity statement token.
|
140
|
+
* @throws {IoWalletError} If the http request fails.
|
136
141
|
*/
|
137
|
-
async function getSignedEntityStatement(
|
142
|
+
async function getSignedEntityStatement(federationFetchEndpoint, subordinatedEntityBaseUrl) {
|
138
143
|
let {
|
139
144
|
appFetch = fetch
|
140
145
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
141
|
-
const url =
|
142
|
-
|
143
|
-
|
144
|
-
return await appFetch(url, {
|
146
|
+
const url = new URL(federationFetchEndpoint);
|
147
|
+
url.searchParams.set("sub", subordinatedEntityBaseUrl);
|
148
|
+
return await appFetch(url.toString(), {
|
145
149
|
method: "GET"
|
146
150
|
}).then((0, _misc.hasStatusOrThrow)(200)).then(res => res.text());
|
147
151
|
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Fetch the federation list document from a given endpoint.
|
155
|
+
*
|
156
|
+
* @param federationListEndpoint The URL of the federation list endpoint.
|
157
|
+
* @param appFetch An optional instance of the http client to be used.
|
158
|
+
* @returns The federation list as an array of strings.
|
159
|
+
* @throws {IoWalletError} If the HTTP request fails or the response cannot be parsed.
|
160
|
+
*/
|
161
|
+
async function getFederationList(federationListEndpoint) {
|
162
|
+
let {
|
163
|
+
appFetch = fetch
|
164
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
165
|
+
return await appFetch(federationListEndpoint, {
|
166
|
+
method: "GET"
|
167
|
+
}).then((0, _misc.hasStatusOrThrow)(200)).then(res => res.json()).then(json => {
|
168
|
+
const result = _types.FederationListResponse.safeParse(json);
|
169
|
+
if (!result.success) {
|
170
|
+
throw new _errors.IoWalletError(`Invalid federation list format received from Trust Anchor: ${result.error.message}`);
|
171
|
+
}
|
172
|
+
return result.data;
|
173
|
+
});
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Build a not-verified trust chain for a given Relying Party (RP) entity.
|
178
|
+
*
|
179
|
+
* @param relyingPartyEntityBaseUrl The base URL of the RP entity
|
180
|
+
* @param trustAnchorKey The public key of the Trust Anchor (TA) entity
|
181
|
+
* @param appFetch An optional instance of the http client to be used.
|
182
|
+
* @returns A list of signed tokens that represent the trust chain, in the order of the chain (from the RP to the Trust Anchor)
|
183
|
+
* @throws {IoWalletError} When an element of the chain fails to parse
|
184
|
+
* The result of this function can be used to validate the trust chain with {@link verifyTrustChain}
|
185
|
+
*/
|
186
|
+
async function buildTrustChain(relyingPartyEntityBaseUrl, trustAnchorKey) {
|
187
|
+
let appFetch = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : fetch;
|
188
|
+
// 1: Recursively gather the trust chain from the RP up to the Trust Anchor
|
189
|
+
const trustChain = await gatherTrustChain(relyingPartyEntityBaseUrl, appFetch);
|
190
|
+
|
191
|
+
// 2: Trust Anchor signature verification
|
192
|
+
const trustAnchorJwt = trustChain[trustChain.length - 1];
|
193
|
+
if (!trustAnchorJwt) {
|
194
|
+
throw new _errors.IoWalletError("Cannot verify trust anchor: missing entity configuration.");
|
195
|
+
}
|
196
|
+
if (!trustAnchorKey.kid) {
|
197
|
+
throw new _errors.IoWalletError("Missing 'kid' in provided Trust Anchor key.");
|
198
|
+
}
|
199
|
+
await (0, _utils.verify)(trustAnchorJwt, trustAnchorKey.kid, [trustAnchorKey]);
|
200
|
+
|
201
|
+
// 3: Check the federation list
|
202
|
+
const trustAnchorConfig = _types.EntityConfiguration.parse((0, _utils.decode)(trustAnchorJwt));
|
203
|
+
const federationListEndpoint = trustAnchorConfig.payload.metadata.federation_entity.federation_list_endpoint;
|
204
|
+
if (federationListEndpoint) {
|
205
|
+
const federationList = await getFederationList(federationListEndpoint, {
|
206
|
+
appFetch
|
207
|
+
});
|
208
|
+
if (!federationList.includes(relyingPartyEntityBaseUrl)) {
|
209
|
+
throw new _errors.IoWalletError("Relying Party entity base URL is not authorized by the Trust Anchor's federation list.");
|
210
|
+
}
|
211
|
+
}
|
212
|
+
return trustChain;
|
213
|
+
}
|
214
|
+
|
215
|
+
/**
|
216
|
+
* Recursively gather the trust chain for an entity and all its superiors.
|
217
|
+
* @param entityBaseUrl The base URL of the entity for which to gather the chain.
|
218
|
+
* @param appFetch An optional instance of the http client to be used.
|
219
|
+
* @param isLeaf Whether the current entity is the leaf of the chain.
|
220
|
+
* @returns A full ordered list of JWTs (ECs and ESs) forming the trust chain.
|
221
|
+
*/
|
222
|
+
async function gatherTrustChain(entityBaseUrl, appFetch) {
|
223
|
+
let isLeaf = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
224
|
+
const chain = [];
|
225
|
+
|
226
|
+
// Fetch self-signed EC (only needed for the leaf)
|
227
|
+
const entityECJwt = await getSignedEntityConfiguration(entityBaseUrl, {
|
228
|
+
appFetch
|
229
|
+
});
|
230
|
+
const entityEC = _types.EntityConfiguration.parse((0, _utils.decode)(entityECJwt));
|
231
|
+
if (isLeaf) {
|
232
|
+
// Only push EC for the leaf
|
233
|
+
chain.push(entityECJwt);
|
234
|
+
}
|
235
|
+
|
236
|
+
// Find authority_hints (parent, if any)
|
237
|
+
const authorityHints = entityEC.payload.authority_hints ?? [];
|
238
|
+
if (authorityHints.length === 0) {
|
239
|
+
// This is the Trust Anchor (no parent)
|
240
|
+
if (!isLeaf) {
|
241
|
+
chain.push(entityECJwt);
|
242
|
+
}
|
243
|
+
return chain;
|
244
|
+
}
|
245
|
+
const parentEntityBaseUrl = authorityHints[0];
|
246
|
+
|
247
|
+
// Fetch parent EC
|
248
|
+
const parentECJwt = await getSignedEntityConfiguration(parentEntityBaseUrl, {
|
249
|
+
appFetch
|
250
|
+
});
|
251
|
+
const parentEC = _types.EntityConfiguration.parse((0, _utils.decode)(parentECJwt));
|
252
|
+
|
253
|
+
// Fetch ES
|
254
|
+
const federationFetchEndpoint = parentEC.payload.metadata.federation_entity.federation_fetch_endpoint;
|
255
|
+
if (!federationFetchEndpoint) {
|
256
|
+
throw new _errors.IoWalletError("Missing federation_fetch_endpoint in parent's configuration.");
|
257
|
+
}
|
258
|
+
const entityStatementJwt = await getSignedEntityStatement(federationFetchEndpoint, entityBaseUrl, {
|
259
|
+
appFetch
|
260
|
+
});
|
261
|
+
// Validate the ES
|
262
|
+
_types.EntityStatement.parse((0, _utils.decode)(entityStatementJwt));
|
263
|
+
|
264
|
+
// Push this ES into the chain
|
265
|
+
chain.push(entityStatementJwt);
|
266
|
+
|
267
|
+
// Recurse into the parent
|
268
|
+
const parentChain = await gatherTrustChain(parentEntityBaseUrl, appFetch, false);
|
269
|
+
return chain.concat(parentChain);
|
270
|
+
}
|
148
271
|
//# sourceMappingURL=index.js.map
|