@pagopa/io-react-native-wallet 2.2.0 → 2.4.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 +4 -3
- package/lib/commonjs/credential/index.js +3 -1
- package/lib/commonjs/credential/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +24 -6
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +26 -2
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/README.md +155 -18
- package/lib/commonjs/credential/issuance/index.js +9 -1
- package/lib/commonjs/credential/issuance/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js +57 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/02-init-challenge.js +61 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/02-init-challenge.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/03-validate-challenge.js +95 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/03-validate-challenge.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/README.md +92 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/index.js +33 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/index.js.map +1 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/types.js +57 -0
- package/lib/commonjs/credential/issuance/mrtd-pop/types.js.map +1 -0
- package/lib/commonjs/credential/offer/01-start-flow.js +75 -0
- package/lib/commonjs/credential/offer/01-start-flow.js.map +1 -0
- package/lib/commonjs/credential/offer/02-fetch-credential-offer.js +45 -0
- package/lib/commonjs/credential/offer/02-fetch-credential-offer.js.map +1 -0
- package/lib/commonjs/credential/offer/README.md +174 -0
- package/lib/commonjs/credential/offer/errors.js +22 -0
- package/lib/commonjs/credential/offer/errors.js.map +1 -0
- package/lib/commonjs/credential/offer/index.js +25 -0
- package/lib/commonjs/credential/offer/index.js.map +1 -0
- package/lib/commonjs/credential/offer/types.js +51 -0
- package/lib/commonjs/credential/offer/types.js.map +1 -0
- package/lib/commonjs/credential/presentation/01-start-flow.js +1 -1
- package/lib/commonjs/credentials-catalogue/README.md +15 -0
- package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js +42 -0
- package/lib/commonjs/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
- package/lib/commonjs/credentials-catalogue/index.js +13 -0
- package/lib/commonjs/credentials-catalogue/index.js.map +1 -0
- package/lib/commonjs/credentials-catalogue/types.js +99 -0
- package/lib/commonjs/credentials-catalogue/types.js.map +1 -0
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/auth.js +9 -1
- package/lib/commonjs/utils/auth.js.map +1 -1
- package/lib/commonjs/utils/par.js +7 -2
- package/lib/commonjs/utils/par.js.map +1 -1
- package/lib/commonjs/utils/zod.js +28 -0
- package/lib/commonjs/utils/zod.js.map +1 -0
- package/lib/module/credential/index.js +2 -1
- package/lib/module/credential/index.js.map +1 -1
- package/lib/module/credential/issuance/03-start-user-authorization.js +24 -6
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js +25 -2
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/README.md +155 -18
- package/lib/module/credential/issuance/index.js +3 -2
- package/lib/module/credential/issuance/index.js.map +1 -1
- package/lib/module/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js +50 -0
- package/lib/module/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/02-init-challenge.js +52 -0
- package/lib/module/credential/issuance/mrtd-pop/02-init-challenge.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/03-validate-challenge.js +85 -0
- package/lib/module/credential/issuance/mrtd-pop/03-validate-challenge.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/README.md +92 -0
- package/lib/module/credential/issuance/mrtd-pop/index.js +5 -0
- package/lib/module/credential/issuance/mrtd-pop/index.js.map +1 -0
- package/lib/module/credential/issuance/mrtd-pop/types.js +46 -0
- package/lib/module/credential/issuance/mrtd-pop/types.js.map +1 -0
- package/lib/module/credential/offer/01-start-flow.js +66 -0
- package/lib/module/credential/offer/01-start-flow.js.map +1 -0
- package/lib/module/credential/offer/02-fetch-credential-offer.js +38 -0
- package/lib/module/credential/offer/02-fetch-credential-offer.js.map +1 -0
- package/lib/module/credential/offer/README.md +174 -0
- package/lib/module/credential/offer/errors.js +14 -0
- package/lib/module/credential/offer/errors.js.map +1 -0
- package/lib/module/credential/offer/index.js +5 -0
- package/lib/module/credential/offer/index.js.map +1 -0
- package/lib/module/credential/offer/types.js +41 -0
- package/lib/module/credential/offer/types.js.map +1 -0
- package/lib/module/credential/presentation/01-start-flow.js +1 -1
- package/lib/module/credentials-catalogue/README.md +15 -0
- package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js +35 -0
- package/lib/module/credentials-catalogue/fetch-and-parse-catalogue.js.map +1 -0
- package/lib/module/credentials-catalogue/index.js +2 -0
- package/lib/module/credentials-catalogue/index.js.map +1 -0
- package/lib/module/credentials-catalogue/types.js +89 -0
- package/lib/module/credentials-catalogue/types.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/auth.js +8 -0
- package/lib/module/utils/auth.js.map +1 -1
- package/lib/module/utils/par.js +7 -2
- package/lib/module/utils/par.js.map +1 -1
- package/lib/module/utils/zod.js +20 -0
- package/lib/module/utils/zod.js.map +1 -0
- package/lib/typescript/credential/index.d.ts +2 -1
- package/lib/typescript/credential/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -1
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +14 -4
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +9 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/index.d.ts +4 -3
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.d.ts +25 -0
- package/lib/typescript/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/02-init-challenge.d.ts +23 -0
- package/lib/typescript/credential/issuance/mrtd-pop/02-init-challenge.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/03-validate-challenge.d.ts +39 -0
- package/lib/typescript/credential/issuance/mrtd-pop/03-validate-challenge.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/index.d.ts +7 -0
- package/lib/typescript/credential/issuance/mrtd-pop/index.d.ts.map +1 -0
- package/lib/typescript/credential/issuance/mrtd-pop/types.d.ts +201 -0
- package/lib/typescript/credential/issuance/mrtd-pop/types.d.ts.map +1 -0
- package/lib/typescript/credential/offer/01-start-flow.d.ts +172 -0
- package/lib/typescript/credential/offer/01-start-flow.d.ts.map +1 -0
- package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts +20 -0
- package/lib/typescript/credential/offer/02-fetch-credential-offer.d.ts.map +1 -0
- package/lib/typescript/credential/offer/errors.d.ts +10 -0
- package/lib/typescript/credential/offer/errors.d.ts.map +1 -0
- package/lib/typescript/credential/offer/index.d.ts +7 -0
- package/lib/typescript/credential/offer/index.d.ts.map +1 -0
- package/lib/typescript/credential/offer/types.d.ts +264 -0
- package/lib/typescript/credential/offer/types.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +1 -1
- package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts +15 -0
- package/lib/typescript/credentials-catalogue/fetch-and-parse-catalogue.d.ts.map +1 -0
- package/lib/typescript/credentials-catalogue/index.d.ts +3 -0
- package/lib/typescript/credentials-catalogue/index.d.ts.map +1 -0
- package/lib/typescript/credentials-catalogue/types.d.ts +844 -0
- package/lib/typescript/credentials-catalogue/types.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/auth.d.ts +11 -0
- package/lib/typescript/utils/auth.d.ts.map +1 -1
- package/lib/typescript/utils/par.d.ts +34 -4
- package/lib/typescript/utils/par.d.ts.map +1 -1
- package/lib/typescript/utils/zod.d.ts +15 -0
- package/lib/typescript/utils/zod.d.ts.map +1 -0
- package/package.json +21 -2
- package/src/credential/index.ts +2 -1
- package/src/credential/issuance/01-start-flow.ts +1 -1
- package/src/credential/issuance/03-start-user-authorization.ts +30 -7
- package/src/credential/issuance/04-complete-user-authorization.ts +43 -1
- package/src/credential/issuance/README.md +155 -18
- package/src/credential/issuance/index.ts +7 -1
- package/src/credential/issuance/mrtd-pop/01-verify-and-parse-challenge-info.ts +70 -0
- package/src/credential/issuance/mrtd-pop/02-init-challenge.ts +82 -0
- package/src/credential/issuance/mrtd-pop/03-validate-challenge.ts +140 -0
- package/src/credential/issuance/mrtd-pop/README.md +92 -0
- package/src/credential/issuance/mrtd-pop/index.ts +27 -0
- package/src/credential/issuance/mrtd-pop/types.ts +65 -0
- package/src/credential/offer/01-start-flow.ts +89 -0
- package/src/credential/offer/02-fetch-credential-offer.ts +54 -0
- package/src/credential/offer/README.md +174 -0
- package/src/credential/offer/errors.ts +17 -0
- package/src/credential/offer/index.ts +16 -0
- package/src/credential/offer/types.ts +59 -0
- package/src/credential/presentation/01-start-flow.ts +1 -1
- package/src/credentials-catalogue/README.md +15 -0
- package/src/credentials-catalogue/fetch-and-parse-catalogue.ts +54 -0
- package/src/credentials-catalogue/index.ts +2 -0
- package/src/credentials-catalogue/types.ts +97 -0
- package/src/index.ts +2 -0
- package/src/utils/auth.ts +12 -0
- package/src/utils/par.ts +12 -4
- package/src/utils/zod.ts +28 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.initChallenge = void 0;
|
|
7
|
+
var _misc = require("../../../utils/misc");
|
|
8
|
+
var _uuid = require("uuid");
|
|
9
|
+
var _pop = require("../../../utils/pop");
|
|
10
|
+
var WalletInstanceAttestation = _interopRequireWildcard(require("../../../wallet-instance-attestation"));
|
|
11
|
+
var _errors = require("../../../utils/errors");
|
|
12
|
+
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
|
13
|
+
var _types = require("./types");
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
/**
|
|
17
|
+
* Initialaizes the MRTD challenge with the data received from the issuer after the primary authentication.
|
|
18
|
+
* This function must be called after {@link verifyAndParseChallengeInfo}.
|
|
19
|
+
*
|
|
20
|
+
* @param issuerConf - The issuer configuration containing the JWKS for signature verification.
|
|
21
|
+
* @param initUrl - The endpoint to call to initialize the challenge.
|
|
22
|
+
* @param mrtd_auth_session - Session identifier for session binding obtained from the MRTD Proof JWT.
|
|
23
|
+
* @param mrtd_pop_jwt_nonce - Nonce value obtained from the MRTD Proof JWT.
|
|
24
|
+
* @param context - The context containing the WIA crypto context used to retrieve the client public key,
|
|
25
|
+
* the wallet instance attestation and an optional fetch implementation.
|
|
26
|
+
* @returns The payload of the MRTD PoP Challenge JWT.
|
|
27
|
+
*/
|
|
28
|
+
const initChallenge = async (issuerConf, initUrl, mrtd_auth_session, mrtd_pop_jwt_nonce, context) => {
|
|
29
|
+
const {
|
|
30
|
+
appFetch = fetch,
|
|
31
|
+
walletInstanceAttestation,
|
|
32
|
+
wiaCryptoContext
|
|
33
|
+
} = context;
|
|
34
|
+
const aud = issuerConf.openid_credential_issuer.credential_issuer;
|
|
35
|
+
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation).payload.cnf.jwk.kid;
|
|
36
|
+
const signedWiaPoP = await (0, _pop.createPopToken)({
|
|
37
|
+
jti: `${(0, _uuid.v4)()}`,
|
|
38
|
+
aud,
|
|
39
|
+
iss
|
|
40
|
+
}, wiaCryptoContext);
|
|
41
|
+
const requestBody = {
|
|
42
|
+
mrtd_auth_session,
|
|
43
|
+
mrtd_pop_jwt_nonce
|
|
44
|
+
};
|
|
45
|
+
const mrtdPoPChallengeJwt = await appFetch(initUrl, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: {
|
|
48
|
+
"Content-Type": "application/json",
|
|
49
|
+
"OAuth-Client-Attestation": walletInstanceAttestation,
|
|
50
|
+
"OAuth-Client-Attestation-PoP": signedWiaPoP
|
|
51
|
+
},
|
|
52
|
+
body: JSON.stringify(requestBody)
|
|
53
|
+
}).then((0, _misc.hasStatusOrThrow)(202, _errors.IssuerResponseError)).then(res => res.text());
|
|
54
|
+
const mrtdPoPChallengeDecoded = (0, _ioReactNativeJwt.decode)(mrtdPoPChallengeJwt);
|
|
55
|
+
const {
|
|
56
|
+
payload
|
|
57
|
+
} = _types.MrtdPoPChallenge.parse(mrtdPoPChallengeDecoded);
|
|
58
|
+
return payload;
|
|
59
|
+
};
|
|
60
|
+
exports.initChallenge = initChallenge;
|
|
61
|
+
//# sourceMappingURL=02-init-challenge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_misc","require","_uuid","_pop","WalletInstanceAttestation","_interopRequireWildcard","_errors","_ioReactNativeJwt","_types","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","initChallenge","issuerConf","initUrl","mrtd_auth_session","mrtd_pop_jwt_nonce","context","appFetch","fetch","walletInstanceAttestation","wiaCryptoContext","aud","openid_credential_issuer","credential_issuer","iss","decode","payload","cnf","jwk","kid","signedWiaPoP","createPopToken","jti","uuidv4","requestBody","mrtdPoPChallengeJwt","method","headers","body","JSON","stringify","then","hasStatusOrThrow","IssuerResponseError","res","text","mrtdPoPChallengeDecoded","decodeJwt","MrtdPoPChallenge","parse","exports"],"sourceRoot":"../../../../../src","sources":["credential/issuance/mrtd-pop/02-init-challenge.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAEA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,IAAA,GAAAF,OAAA;AACA,IAAAG,yBAAA,GAAAC,uBAAA,CAAAJ,OAAA;AAEA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,iBAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAA2C,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAA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ACF,CAAC,GAAGJ,OAAO;EAEX,MAAMK,GAAG,GAAGT,UAAU,CAACU,wBAAwB,CAACC,iBAAiB;EACjE,MAAMC,GAAG,GAAGxC,yBAAyB,CAACyC,MAAM,CAACN,yBAAyB,CAAC,CACpEO,OAAO,CAACC,GAAG,CAACC,GAAG,CAACC,GAAG;EAEtB,MAAMC,YAAY,GAAG,MAAM,IAAAC,mBAAc,EACvC;IACEC,GAAG,EAAG,GAAE,IAAAC,QAAM,EAAC,CAAE,EAAC;IAClBZ,GAAG;IACHG;EACF,CAAC,EACDJ,gBACF,CAAC;EAED,MAAMc,WAAW,GAAG;IAClBpB,iBAAiB;IACjBC;EACF,CAAC;EAED,MAAMoB,mBAAmB,GAAG,MAAMlB,QAAQ,CAACJ,OAAO,EAAE;IAClDuB,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE,kBAAkB;MAClC,0BAA0B,EAAElB,yBAAyB;MACrD,8BAA8B,EAAEW;IAClC,CAAC;IACDQ,IAAI,EAAEC,IAAI,CAACC,SAAS,CAACN,WAAW;EAClC,CAAC,CAAC,CACCO,IAAI,CAAC,IAAAC,sBAAgB,EAAC,GAAG,EAAEC,2BAAmB,CAAC,CAAC,CAChDF,IAAI,CAAEG,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC;EAE5B,MAAMC,uBAAuB,GAAG,IAAAC,wBAAS,EAACZ,mBAAmB,CAAC;EAC9D,MAAM;IAAET;EAAQ,CAAC,GAAGsB,uBAAgB,CAACC,KAAK,CAACH,uBAAuB,CAAC;EAEnE,OAAOpB,OAAO;AAChB,CAAC;AAACwB,OAAA,CAAAvC,aAAA,GAAAA,aAAA"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.validateChallenge = exports.buildChallengeCallbackUrl = void 0;
|
|
7
|
+
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
|
8
|
+
var _uuid = require("uuid");
|
|
9
|
+
var _errors = require("../../../utils/errors");
|
|
10
|
+
var _misc = require("../../../utils/misc");
|
|
11
|
+
var _pop = require("../../../utils/pop");
|
|
12
|
+
var WalletInstanceAttestation = _interopRequireWildcard(require("../../../wallet-instance-attestation"));
|
|
13
|
+
var _types = require("./types");
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
/**
|
|
17
|
+
* Validates the MRTD signed challenge by sending the MRTD and IAS payloads to the issuer.
|
|
18
|
+
* This function must be called after {@link initChallenge} and after obtaining the MRTD and IAS payloads
|
|
19
|
+
* through the CIE PACE process.
|
|
20
|
+
*
|
|
21
|
+
* @param issuerConf - The issuer configuration containing the JWKS for signature verification.
|
|
22
|
+
* @param verifyUrl - The endpoint to call to validate the challenge.
|
|
23
|
+
* @param mrtd_auth_session - Session identifier for session binding obtained from the MRTD Proof JWT.
|
|
24
|
+
* @param mrtd_pop_nonce - Nonce value obtained from the MRTD Proof JWT.
|
|
25
|
+
* @param mrtd - MRTD validation data containing Data Groups and SOD.
|
|
26
|
+
* @param ias - IAS validation data containing Anti-Cloning Public Key, and SOD.
|
|
27
|
+
* @param context - The context containing the WIA crypto context used to retrieve the client public key,
|
|
28
|
+
* the wallet instance attestation and an optional fetch implementation.
|
|
29
|
+
* @returns The MRTD PoP Verification Result containing the validation nonce and redirect URI to complete the flow.
|
|
30
|
+
*/
|
|
31
|
+
const validateChallenge = async (issuerConf, verifyUrl, mrtd_auth_session, mrtd_pop_nonce, mrtd, ias, context) => {
|
|
32
|
+
const {
|
|
33
|
+
appFetch = fetch,
|
|
34
|
+
walletInstanceAttestation,
|
|
35
|
+
wiaCryptoContext
|
|
36
|
+
} = context;
|
|
37
|
+
const aud = issuerConf.openid_credential_issuer.credential_issuer;
|
|
38
|
+
const iss = WalletInstanceAttestation.decode(walletInstanceAttestation).payload.cnf.jwk.kid;
|
|
39
|
+
const signedWiaPoP = await (0, _pop.createPopToken)({
|
|
40
|
+
jti: `${(0, _uuid.v4)()}`,
|
|
41
|
+
aud,
|
|
42
|
+
iss
|
|
43
|
+
}, wiaCryptoContext);
|
|
44
|
+
const {
|
|
45
|
+
kid
|
|
46
|
+
} = await wiaCryptoContext.getPublicKey();
|
|
47
|
+
const mrtd_validation_jwt = await new _ioReactNativeJwt.SignJWT(wiaCryptoContext).setProtectedHeader({
|
|
48
|
+
typ: "mrtd-ias+jwt",
|
|
49
|
+
kid
|
|
50
|
+
}).setPayload({
|
|
51
|
+
iss,
|
|
52
|
+
aud,
|
|
53
|
+
document_type: "cie",
|
|
54
|
+
mrtd,
|
|
55
|
+
ias
|
|
56
|
+
}).setIssuedAt().setExpirationTime("5m").sign();
|
|
57
|
+
const requestBody = {
|
|
58
|
+
mrtd_validation_jwt,
|
|
59
|
+
mrtd_auth_session,
|
|
60
|
+
mrtd_pop_nonce
|
|
61
|
+
};
|
|
62
|
+
const verifyResult = await appFetch(verifyUrl, {
|
|
63
|
+
method: "POST",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
"OAuth-Client-Attestation": walletInstanceAttestation,
|
|
67
|
+
"OAuth-Client-Attestation-PoP": signedWiaPoP
|
|
68
|
+
},
|
|
69
|
+
body: JSON.stringify(requestBody)
|
|
70
|
+
}).then((0, _misc.hasStatusOrThrow)(202, _errors.IssuerResponseError)).then(res => res.json());
|
|
71
|
+
const verifyResultParsed = _types.MrtdPopVerificationResult.parse(verifyResult);
|
|
72
|
+
return verifyResultParsed;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* WARNING: This function must be called after {@link validateChallenge}. The generated authUrl must be used to open a browser or webview capable of catching the redirectSchema to perform a get request to the authorization endpoint.
|
|
77
|
+
* Builds the callback URL to which the end user should be redirected to continue the authentication flow after the MRTD challenge validation.
|
|
78
|
+
* @param redirectUri - The redirect URI provided by the issuer after the challenge validation to continue the authentication flow.
|
|
79
|
+
* @param valPopNonce - The MRTD validation PoP nonce obtained from the challenge validation response.
|
|
80
|
+
* @param authSession - The MRTD authentication session identifier used for session binding.
|
|
81
|
+
* @returns An object containing the callback URL
|
|
82
|
+
*/
|
|
83
|
+
exports.validateChallenge = validateChallenge;
|
|
84
|
+
const buildChallengeCallbackUrl = async (redirectUri, valPopNonce, authSession) => {
|
|
85
|
+
const params = new URLSearchParams({
|
|
86
|
+
mrtd_val_pop_nonce: valPopNonce,
|
|
87
|
+
mrtd_auth_session: authSession
|
|
88
|
+
});
|
|
89
|
+
const callbackUrl = `${redirectUri}?${params}`;
|
|
90
|
+
return {
|
|
91
|
+
callbackUrl
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
exports.buildChallengeCallbackUrl = buildChallengeCallbackUrl;
|
|
95
|
+
//# sourceMappingURL=03-validate-challenge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_ioReactNativeJwt","require","_uuid","_errors","_misc","_pop","WalletInstanceAttestation","_interopRequireWildcard","_types","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","validateChallenge","issuerConf","verifyUrl","mrtd_auth_session","mrtd_pop_nonce","mrtd","ias","context","appFetch","fetch","walletInstanceAttestation","wiaCryptoContext","aud","openid_credential_issuer","credential_issuer","iss","decode","payload","cnf","jwk","kid","signedWiaPoP","createPopToken","jti","uuidv4","getPublicKey","mrtd_validation_jwt","SignJWT","setProtectedHeader","typ","setPayload","document_type","setIssuedAt","setExpirationTime","sign","requestBody","verifyResult","method","headers","body","JSON","stringify","then","hasStatusOrThrow","IssuerResponseError","res","json","verifyResultParsed","MrtdPopVerificationResult","parse","exports","buildChallengeCallbackUrl","redirectUri","valPopNonce","authSession","params","URLSearchParams","mrtd_val_pop_nonce","callbackUrl"],"sourceRoot":"../../../../../src","sources":["credential/issuance/mrtd-pop/03-validate-challenge.ts"],"mappings":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,IAAA,GAAAJ,OAAA;AACA,IAAAK,yBAAA,GAAAC,uBAAA,CAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAIiB,SAAAQ,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,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,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AAA,iBAAA;AAQO,MAAMmD,yBAAoD,GAAG,MAAAA,CAClEC,WAAW,EACXC,WAAW,EACXC,WAAW,KACR;EACH,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAAC;IACjCC,kBAAkB,EAAEJ,WAAW;IAC/BlD,iBAAiB,EAAEmD;EACrB,CAAC,CAAC;EAEF,MAAMI,WAAW,GAAI,GAAEN,WAAY,IAAGG,MAAO,EAAC;EAC9C,OAAO;IAAEG;EAAY,CAAC;AACxB,CAAC;AAACR,OAAA,CAAAC,yBAAA,GAAAA,yBAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# MRTD PoP flow
|
|
2
|
+
|
|
3
|
+
**MRTD-PoP (Machine Readable Travel Document - Proof of Possession)** flow for the IO Wallet, following the [eID Wallet L2+ Credential Issuance specification](https://italia.github.io/eid-wallet-it-docs/versione-corrente/en/credential-issuance-l2plus.html).
|
|
4
|
+
|
|
5
|
+
The MRTD-PoP flow is used to prove possession of an MRTD (such as a CIE) during the issuance of high-assurance credentials. The process involves a challenge-response protocol between the wallet and the issuer, leveraging JWTs and cryptographic attestation.
|
|
6
|
+
|
|
7
|
+
This flow is part of the [PID issuance flow](../README.md) and must be started after the `continueUserAuthorizationWithMRTDPoPChallenge` function. Once MRTD PoP is completed, the PID issuance flow must continue with the `completeUserAuthorizationWithQueryMode` function with the authorization url obtained from the validation.
|
|
8
|
+
|
|
9
|
+
> **⚠️ Important**: The entire flow must be initiated and concluded within the same web context (e.g., the same WebView instance) to maintain session continuity. Using different contexts (such as switching between an external browser and a WebView) will result in session loss and authentication failures due to cookie/session mismatch (JSESSIONID).
|
|
10
|
+
|
|
11
|
+
## Sequence Diagram
|
|
12
|
+
|
|
13
|
+
```mermaid
|
|
14
|
+
graph TD;
|
|
15
|
+
A@{ shape: subproc, label: "continueUserAuthorizationWithMRTDPoPChallenge" }
|
|
16
|
+
subgraph MRTD PoP
|
|
17
|
+
B[verifyAndParseChallengeInfo]
|
|
18
|
+
C[initChallenge]
|
|
19
|
+
E[validateChallenge]
|
|
20
|
+
end
|
|
21
|
+
F@{ shape: subproc, label: "completeUserAuthorizationWithQueryModeChallenge" }
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
A -.-> B
|
|
25
|
+
B --> C
|
|
26
|
+
C -->E
|
|
27
|
+
E -.-> F
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Example
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
// Verify and parse challenge info and extract challenge data: initialization url, session and nonce
|
|
35
|
+
const {
|
|
36
|
+
htu: initUrl,
|
|
37
|
+
mrtd_auth_session,
|
|
38
|
+
mrtd_pop_jwt_nonce,
|
|
39
|
+
} = await Credential.Issuance.MRTDPoP.verifyAndParseChallengeInfo(
|
|
40
|
+
issuerConf,
|
|
41
|
+
challenge_info,
|
|
42
|
+
{ wiaCryptoContext }
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// Initialize challenge and obtain the challenge text to sign the CIE PACE protocol and validation url
|
|
46
|
+
const {
|
|
47
|
+
htu: validationUrl,
|
|
48
|
+
challenge,
|
|
49
|
+
mrtd_pop_nonce,
|
|
50
|
+
} = await Credential.Issuance.MRTDPoP.initChallenge(
|
|
51
|
+
issuerConf,
|
|
52
|
+
initUrl,
|
|
53
|
+
mrtd_auth_session,
|
|
54
|
+
mrtd_pop_jwt_nonce,
|
|
55
|
+
{
|
|
56
|
+
walletInstanceAttestation,
|
|
57
|
+
wiaCryptoContext,
|
|
58
|
+
appFetch,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// CIE cryptographic interaction: you need to sign the challenge with the CIE through NFC interaction
|
|
63
|
+
const { nis, mrtds } = /* NFC interactions functions */
|
|
64
|
+
|
|
65
|
+
// Validate challenge
|
|
66
|
+
const { mrtd_val_pop_nonce, redirect_uri } =
|
|
67
|
+
await Credential.Issuance.MRTDPoP.validateChallenge(
|
|
68
|
+
issuerConf,
|
|
69
|
+
validationUrl,
|
|
70
|
+
mrtd_auth_session,
|
|
71
|
+
mrtd_pop_nonce,
|
|
72
|
+
mrtd,
|
|
73
|
+
ias,
|
|
74
|
+
{
|
|
75
|
+
walletInstanceAttestation,
|
|
76
|
+
wiaCryptoContext,
|
|
77
|
+
appFetch,
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// Build the callback url
|
|
82
|
+
const { callbackUrl } = await Credential.Issuance.buildChallengeCallbackUrl(
|
|
83
|
+
redirect_uri,
|
|
84
|
+
mrtd_val_pop_nonce,
|
|
85
|
+
mrtd_auth_session
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// The generated authUrl must be used to open a browser or webview capable of catching the redirectSchema to perform a get request to the authorization endpoint.
|
|
89
|
+
const authRedirectUrl = /* From a browser or webview redirect */
|
|
90
|
+
|
|
91
|
+
// Use the authRedirectUrl to continue the PID issuance flow
|
|
92
|
+
```
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "buildChallengeCallbackUrl", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _validateChallenge.buildChallengeCallbackUrl;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "initChallenge", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _initChallenge.initChallenge;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "validateChallenge", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _validateChallenge.validateChallenge;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "verifyAndParseChallengeInfo", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _verifyAndParseChallengeInfo.verifyAndParseChallengeInfo;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var _verifyAndParseChallengeInfo = require("./01-verify-and-parse-challenge-info");
|
|
31
|
+
var _initChallenge = require("./02-init-challenge");
|
|
32
|
+
var _validateChallenge = require("./03-validate-challenge");
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_verifyAndParseChallengeInfo","require","_initChallenge","_validateChallenge"],"sourceRoot":"../../../../../src","sources":["credential/issuance/mrtd-pop/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,4BAAA,GAAAC,OAAA;AAIA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,kBAAA,GAAAF,OAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MrtdProofChallengeInfo = exports.MrtdPopVerificationResult = exports.MrtdPoPChallenge = void 0;
|
|
7
|
+
var z = _interopRequireWildcard(require("zod"));
|
|
8
|
+
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); }
|
|
9
|
+
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; }
|
|
10
|
+
const MrtdProofChallengeInfo = z.object({
|
|
11
|
+
protectedHeader: z.object({
|
|
12
|
+
typ: z.literal("mrtd-ias+jwt"),
|
|
13
|
+
alg: z.string(),
|
|
14
|
+
kid: z.string()
|
|
15
|
+
}),
|
|
16
|
+
payload: z.object({
|
|
17
|
+
iss: z.string(),
|
|
18
|
+
aud: z.string(),
|
|
19
|
+
iat: z.number(),
|
|
20
|
+
exp: z.number(),
|
|
21
|
+
status: z.literal("require_interaction"),
|
|
22
|
+
type: z.literal("mrtd+ias"),
|
|
23
|
+
mrtd_auth_session: z.string(),
|
|
24
|
+
state: z.string(),
|
|
25
|
+
mrtd_pop_jwt_nonce: z.string(),
|
|
26
|
+
htu: z.string(),
|
|
27
|
+
htm: z.literal("POST")
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
exports.MrtdProofChallengeInfo = MrtdProofChallengeInfo;
|
|
31
|
+
const MrtdPoPChallenge = z.object({
|
|
32
|
+
protectedHeader: z.object({
|
|
33
|
+
typ: z.literal("mrtd-ias-pop+jwt"),
|
|
34
|
+
alg: z.string(),
|
|
35
|
+
kid: z.string()
|
|
36
|
+
}),
|
|
37
|
+
payload: z.object({
|
|
38
|
+
iss: z.string(),
|
|
39
|
+
aud: z.string(),
|
|
40
|
+
iat: z.number(),
|
|
41
|
+
exp: z.number(),
|
|
42
|
+
challenge: z.string(),
|
|
43
|
+
mrtd_pop_nonce: z.string(),
|
|
44
|
+
mrz: z.string().optional(),
|
|
45
|
+
htu: z.string(),
|
|
46
|
+
htm: z.literal("POST")
|
|
47
|
+
})
|
|
48
|
+
});
|
|
49
|
+
exports.MrtdPoPChallenge = MrtdPoPChallenge;
|
|
50
|
+
const MrtdPopVerificationResult = z.object({
|
|
51
|
+
status: z.literal("require_interaction"),
|
|
52
|
+
type: z.literal("redirect_to_web"),
|
|
53
|
+
mrtd_val_pop_nonce: z.string(),
|
|
54
|
+
redirect_uri: z.string()
|
|
55
|
+
});
|
|
56
|
+
exports.MrtdPopVerificationResult = MrtdPopVerificationResult;
|
|
57
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","MrtdProofChallengeInfo","object","protectedHeader","typ","literal","alg","string","kid","payload","iss","aud","iat","number","exp","status","type","mrtd_auth_session","state","mrtd_pop_jwt_nonce","htu","htm","exports","MrtdPoPChallenge","challenge","mrtd_pop_nonce","mrz","optional","MrtdPopVerificationResult","mrtd_val_pop_nonce","redirect_uri"],"sourceRoot":"../../../../../src","sources":["credential/issuance/mrtd-pop/types.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAyB,SAAAC,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,SAAAH,wBAAAO,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,GAA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;EACvB,CAAC;AACH,CAAC,CAAC;AAACiB,OAAA,CAAAC,gBAAA,GAAAA,gBAAA;AAiBI,MAAMK,yBAAyB,GAAGpD,CAAC,CAAC0B,MAAM,CAAC;EAChDa,MAAM,EAAEvC,CAAC,CAAC6B,OAAO,CAAC,qBAAqB,CAAC;EACxCW,IAAI,EAAExC,CAAC,CAAC6B,OAAO,CAAC,iBAAiB,CAAC;EAClCwB,kBAAkB,EAAErD,CAAC,CAAC+B,MAAM,CAAC,CAAC;EAC9BuB,YAAY,EAAEtD,CAAC,CAAC+B,MAAM,CAAC;AACzB,CAAC,CAAC;AAACe,OAAA,CAAAM,yBAAA,GAAAA,yBAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.startFlowFromQR = void 0;
|
|
7
|
+
var z = _interopRequireWildcard(require("zod"));
|
|
8
|
+
var _logging = require("../../utils/logging");
|
|
9
|
+
var _zod2 = require("../../utils/zod");
|
|
10
|
+
var _errors = require("./errors");
|
|
11
|
+
var _types = require("./types");
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
const CREDENTIAL_OFFER_SCHEMES = ["openid-credential-offer://", "haip://"];
|
|
15
|
+
const CREDENTIAL_OFFER_PARAM = "credential_offer";
|
|
16
|
+
const CREDENTIAL_OFFER_URI_PARAM = "credential_offer_uri";
|
|
17
|
+
const CredentialOfferParams = z.union([z.object({
|
|
18
|
+
credential_offer: _zod2.stringToJSONSchema.pipe(_types.CredentialOfferSchema),
|
|
19
|
+
credential_offer_uri: z.undefined()
|
|
20
|
+
}), z.object({
|
|
21
|
+
credential_offer: z.undefined(),
|
|
22
|
+
credential_offer_uri: z.string().url()
|
|
23
|
+
})]);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The beginning of the credential offer flow.
|
|
27
|
+
* To be implemented according to the user touchpoint
|
|
28
|
+
*
|
|
29
|
+
* @param params Credential offer encoded url
|
|
30
|
+
* @returns Object containing the credential offer by reference or by value
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Start a credential offer flow by validating and parse an encoded url
|
|
35
|
+
* extracted from a QR code or a deep link.
|
|
36
|
+
*
|
|
37
|
+
* @param params The encoded url to be validated and parsed
|
|
38
|
+
* @returns Object containing the credential offer by reference or by value
|
|
39
|
+
* @throws If the provided encoded url is not valid
|
|
40
|
+
*/
|
|
41
|
+
const startFlowFromQR = encodedUrl => {
|
|
42
|
+
const hasValidScheme = CREDENTIAL_OFFER_SCHEMES.some(prefix => encodedUrl.startsWith(prefix));
|
|
43
|
+
if (!hasValidScheme) {
|
|
44
|
+
throw new _errors.InvalidQRCodeError("Url must have one of the supported schemes");
|
|
45
|
+
}
|
|
46
|
+
const url = new URL(encodedUrl);
|
|
47
|
+
const offerParam = url.searchParams.get(CREDENTIAL_OFFER_PARAM);
|
|
48
|
+
const offerUriParam = url.searchParams.get(CREDENTIAL_OFFER_URI_PARAM);
|
|
49
|
+
if (offerParam) {
|
|
50
|
+
const decoded = decodeURIComponent(offerParam);
|
|
51
|
+
const result = CredentialOfferParams.safeParse({
|
|
52
|
+
credential_offer: decoded
|
|
53
|
+
});
|
|
54
|
+
if (result.success) {
|
|
55
|
+
return result.data;
|
|
56
|
+
}
|
|
57
|
+
_logging.Logger.log(_logging.LogLevel.ERROR, `Invalid credential offer object found in QR Code: ${result.error.message}`);
|
|
58
|
+
throw new _errors.InvalidQRCodeError(result.error.message);
|
|
59
|
+
}
|
|
60
|
+
if (offerUriParam) {
|
|
61
|
+
const decoded = decodeURIComponent(offerUriParam);
|
|
62
|
+
const result = CredentialOfferParams.safeParse({
|
|
63
|
+
credential_offer_uri: decoded
|
|
64
|
+
});
|
|
65
|
+
if (result.success) {
|
|
66
|
+
return result.data;
|
|
67
|
+
}
|
|
68
|
+
_logging.Logger.log(_logging.LogLevel.ERROR, `Invalid credential offer URI found in QR Code: ${result.error.message}`);
|
|
69
|
+
throw new _errors.InvalidQRCodeError(result.error.message);
|
|
70
|
+
}
|
|
71
|
+
_logging.Logger.log(_logging.LogLevel.ERROR, `Invalid credential offer QR Code:`);
|
|
72
|
+
throw new _errors.InvalidQRCodeError("QR Code does not contain valid params");
|
|
73
|
+
};
|
|
74
|
+
exports.startFlowFromQR = startFlowFromQR;
|
|
75
|
+
//# sourceMappingURL=01-start-flow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["z","_interopRequireWildcard","require","_logging","_zod2","_errors","_types","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","CREDENTIAL_OFFER_SCHEMES","CREDENTIAL_OFFER_PARAM","CREDENTIAL_OFFER_URI_PARAM","CredentialOfferParams","union","object","credential_offer","stringToJSONSchema","pipe","CredentialOfferSchema","credential_offer_uri","undefined","string","url","startFlowFromQR","encodedUrl","hasValidScheme","some","prefix","startsWith","InvalidQRCodeError","URL","offerParam","searchParams","offerUriParam","decoded","decodeURIComponent","result","safeParse","success","data","Logger","log","LogLevel","ERROR","error","message","exports"],"sourceRoot":"../../../../src","sources":["credential/offer/01-start-flow.ts"],"mappings":";;;;;;AAAA,IAAAA,CAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAAgD,SAAAK,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,SAAAP,wBAAAW,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,G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+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.fetchCredentialOffer = void 0;
|
|
7
|
+
var _errors = require("../../utils/errors");
|
|
8
|
+
var _logging = require("../../utils/logging");
|
|
9
|
+
var _misc = require("../../utils/misc");
|
|
10
|
+
var _errors2 = require("./errors");
|
|
11
|
+
var _types = require("./types");
|
|
12
|
+
/**
|
|
13
|
+
* Fetches and validates a credential offer from a given URI.
|
|
14
|
+
*
|
|
15
|
+
* This function performs an HTTP GET request to the specified `credentialOfferUri`,
|
|
16
|
+
* expecting a JSON response that matches the `CredentialOfferSchema`. If the response
|
|
17
|
+
* is invalid or does not conform to the schema, an error is logged and an
|
|
18
|
+
* `InvalidCredentialOfferError` is thrown.
|
|
19
|
+
*
|
|
20
|
+
* @param credentialOfferUri - The URI from which to fetch the credential offer.
|
|
21
|
+
* @param context - Optional context object that may provide a custom `appFetch` implementation.
|
|
22
|
+
* @returns The validated credential offer data.
|
|
23
|
+
* @throws {IssuerResponseError} If the HTTP response status is not 200.
|
|
24
|
+
* @throws {InvalidCredentialOfferError} If the response does not match the expected schema.
|
|
25
|
+
*/
|
|
26
|
+
const fetchCredentialOffer = async function (uri) {
|
|
27
|
+
let context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
28
|
+
const {
|
|
29
|
+
appFetch = fetch
|
|
30
|
+
} = context;
|
|
31
|
+
const response = await appFetch(uri, {
|
|
32
|
+
method: "GET",
|
|
33
|
+
headers: {
|
|
34
|
+
Accept: "application/json"
|
|
35
|
+
}
|
|
36
|
+
}).then((0, _misc.hasStatusOrThrow)(200, _errors.IssuerResponseError)).then(reqUri => reqUri.json());
|
|
37
|
+
const credentialOffer = _types.CredentialOfferSchema.safeParse(response);
|
|
38
|
+
if (!credentialOffer.success) {
|
|
39
|
+
_logging.Logger.log(_logging.LogLevel.ERROR, `Invalid credential offer fetched from URI: ${uri} - ${credentialOffer.error.message}`);
|
|
40
|
+
throw new _errors2.InvalidCredentialOfferError(`Invalid credential offer fetched from URI: ${uri} - ${credentialOffer.error.message}`);
|
|
41
|
+
}
|
|
42
|
+
return credentialOffer.data;
|
|
43
|
+
};
|
|
44
|
+
exports.fetchCredentialOffer = fetchCredentialOffer;
|
|
45
|
+
//# sourceMappingURL=02-fetch-credential-offer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","_logging","_misc","_errors2","_types","fetchCredentialOffer","uri","context","arguments","length","undefined","appFetch","fetch","response","method","headers","Accept","then","hasStatusOrThrow","IssuerResponseError","reqUri","json","credentialOffer","CredentialOfferSchema","safeParse","success","Logger","log","LogLevel","ERROR","error","message","InvalidCredentialOfferError","data","exports"],"sourceRoot":"../../../../src","sources":["credential/offer/02-fetch-credential-offer.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,oBAAwC,GAAG,eAAAA,CACtDC,GAAW,EAER;EAAA,IADHC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAEZ,MAAM;IAAEG,QAAQ,GAAGC;EAAM,CAAC,GAAGL,OAAO;EAEpC,MAAMM,QAAQ,GAAG,MAAMF,QAAQ,CAACL,GAAG,EAAE;IACnCQ,MAAM,EAAE,KAAK;IACbC,OAAO,EAAE;MAAEC,MAAM,EAAE;IAAmB;EACxC,CAAC,CAAC,CACCC,IAAI,CAAC,IAAAC,sBAAgB,EAAC,GAAG,EAAEC,2BAAmB,CAAC,CAAC,CAChDF,IAAI,CAAEG,MAAM,IAAKA,MAAM,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