@pagopa/io-react-native-wallet 0.13.1 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/cie/component.js +180 -0
- package/lib/commonjs/cie/component.js.map +1 -0
- package/lib/commonjs/cie/error.js +44 -0
- package/lib/commonjs/cie/error.js.map +1 -0
- package/lib/commonjs/cie/index.js +32 -0
- package/lib/commonjs/cie/index.js.map +1 -0
- package/lib/commonjs/cie/manager.js +142 -0
- package/lib/commonjs/cie/manager.js.map +1 -0
- package/lib/commonjs/client/index.js +5 -2
- package/lib/commonjs/client/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +144 -19
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +12 -4
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/index.js +18 -0
- package/lib/commonjs/credential/issuance/index.js.map +1 -1
- package/lib/commonjs/credential/issuance/types.js +9 -1
- package/lib/commonjs/credential/issuance/types.js.map +1 -1
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/trust/types.js +5 -3
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/utils/decoder.js +28 -19
- package/lib/commonjs/utils/decoder.js.map +1 -1
- package/lib/module/cie/component.js +171 -0
- package/lib/module/cie/component.js.map +1 -0
- package/lib/module/cie/error.js +36 -0
- package/lib/module/cie/error.js.map +1 -0
- package/lib/module/cie/index.js +4 -0
- package/lib/module/cie/index.js.map +1 -0
- package/lib/module/cie/manager.js +133 -0
- package/lib/module/cie/manager.js.map +1 -0
- package/lib/module/client/index.js +5 -2
- package/lib/module/client/index.js.map +1 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js +141 -18
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +12 -4
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/issuance/index.js +2 -2
- package/lib/module/credential/issuance/index.js.map +1 -1
- package/lib/module/credential/issuance/types.js +7 -0
- package/lib/module/credential/issuance/types.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/trust/types.js +5 -3
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/utils/decoder.js +28 -19
- package/lib/module/utils/decoder.js.map +1 -1
- package/lib/typescript/cie/component.d.ts +46 -0
- package/lib/typescript/cie/component.d.ts.map +1 -0
- package/lib/typescript/cie/error.d.ts +31 -0
- package/lib/typescript/cie/error.d.ts.map +1 -0
- package/lib/typescript/cie/index.d.ts +4 -0
- package/lib/typescript/cie/index.d.ts.map +1 -0
- package/lib/typescript/cie/manager.d.ts +5 -0
- package/lib/typescript/cie/manager.d.ts.map +1 -0
- package/lib/typescript/client/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +48 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +1 -0
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/index.d.ts +3 -3
- package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/types.d.ts +10 -0
- package/lib/typescript/credential/issuance/types.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +14 -14
- package/lib/typescript/trust/types.d.ts +142 -142
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/utils/decoder.d.ts.map +1 -1
- package/package.json +6 -2
- package/src/cie/component.tsx +216 -0
- package/src/cie/error.ts +58 -0
- package/src/cie/index.ts +4 -0
- package/src/cie/manager.ts +183 -0
- package/src/client/index.ts +4 -1
- package/src/credential/issuance/04-complete-user-authorization.ts +216 -21
- package/src/credential/issuance/07-verify-and-parse-credential.ts +14 -6
- package/src/credential/issuance/index.ts +10 -0
- package/src/credential/issuance/types.ts +7 -0
- package/src/index.ts +2 -0
- package/src/trust/types.ts +8 -6
- package/src/utils/decoder.ts +28 -19
- package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +0 -287
- package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +0 -1
- package/lib/module/credential/issuance/03-start-credential-issuance.js +0 -276
- package/lib/module/credential/issuance/03-start-credential-issuance.js.map +0 -1
- package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +0 -41
- package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +0 -1
- package/src/credential/issuance/03-start-credential-issuance.ts +0 -407
@@ -0,0 +1,180 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.WebViewComponent = exports.CieEvent = void 0;
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
8
|
+
var _reactNative = require("react-native");
|
9
|
+
var _reactNativeWebview = require("react-native-webview");
|
10
|
+
var _manager = require("./manager");
|
11
|
+
var _error = require("./error");
|
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
|
+
/* To obtain the authentication URL on CIE L3 it is necessary to take the
|
15
|
+
* link contained in the "Entra con lettura carta CIE" button.
|
16
|
+
* This link can then be used on CieManager.
|
17
|
+
* This javascript code takes the link in question and sends it to the react native function via postMessage
|
18
|
+
*/
|
19
|
+
const injectedJavaScript = `
|
20
|
+
(function() {
|
21
|
+
function sendDocumentContent() {
|
22
|
+
const idpAuthUrl = [...document.querySelectorAll("a")]
|
23
|
+
.filter(a => a.textContent.includes("lettura carta CIE"))
|
24
|
+
.map(a=>a.href)[0];
|
25
|
+
|
26
|
+
if(idpAuthUrl) {
|
27
|
+
window.ReactNativeWebView.postMessage(idpAuthUrl);
|
28
|
+
}
|
29
|
+
}
|
30
|
+
if (document.readyState === 'complete') {
|
31
|
+
sendDocumentContent();
|
32
|
+
} else {
|
33
|
+
window.addEventListener('load', sendDocumentContent);
|
34
|
+
}
|
35
|
+
})();
|
36
|
+
true;
|
37
|
+
`;
|
38
|
+
let CieEvent = /*#__PURE__*/function (CieEvent) {
|
39
|
+
CieEvent["reading"] = "reading";
|
40
|
+
CieEvent["completed"] = "completed";
|
41
|
+
CieEvent["waiting_card"] = "waiting_card";
|
42
|
+
return CieEvent;
|
43
|
+
}({});
|
44
|
+
exports.CieEvent = CieEvent;
|
45
|
+
/*
|
46
|
+
* To make sure the server recognizes the client as valid iPhone device (iOS only) we use a custom header
|
47
|
+
* on Android it is not required.
|
48
|
+
*/
|
49
|
+
const iOSUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1";
|
50
|
+
const defaultUserAgent = _reactNative.Platform.select({
|
51
|
+
ios: iOSUserAgent,
|
52
|
+
default: undefined
|
53
|
+
});
|
54
|
+
const webView = /*#__PURE__*/(0, _react.createRef)();
|
55
|
+
|
56
|
+
/**
|
57
|
+
* WebViewComponent
|
58
|
+
*
|
59
|
+
* Component that manages authentication via CIE L3 (NFC+PIN) based on WebView (react-native-webview).
|
60
|
+
* In particular, once rendered, it makes a series of calls to the authUrl in the WebView,
|
61
|
+
* extrapolates the authentication URL necessary for CieManager to sign via certificate
|
62
|
+
* and calls the CIE SDK which is responsible for starting card reading via NFC.
|
63
|
+
* At the end of the reading, a redirect is made in the WebView towards the page that asks
|
64
|
+
* the user for consent to send the data to the Service Provider. This moment can be captured
|
65
|
+
* via the onUserInteraction parameter. When the user allows or denies their consent,
|
66
|
+
* a redirect is made to the URL set by the Service Provider.
|
67
|
+
* This url can be configured using the redirectUrl parameter which allows you to close the WebView.
|
68
|
+
* The event can then be captured via the onSuccess parameter.
|
69
|
+
*
|
70
|
+
* @param {CIEParams} params - Parameters required by the component.
|
71
|
+
* @param {string} params.authUrl -The authentication URL of the Service Provider to which to authenticate.
|
72
|
+
* @param {boolean} params.useUat - If set to true it uses the CIE testing environment.
|
73
|
+
* @param {string} params.pin - CIE pin for use with NFC reading.
|
74
|
+
* @param {Function} params.onError - Callback function in case of error. The function is passed the Error parameter.
|
75
|
+
* @param {Function} params.onSuccess - Callback at the end of authentication to which the redirect URL including parameters is passed.
|
76
|
+
* @param {string} params.redirectUrl - Redirect URL set by the Service Provider. It is used to stop the flow and return to the calling function via onSuccess.
|
77
|
+
* @param {Function} params.onEvent - Callback function that is called whenever there is a new CieEvent from the CIE reader.
|
78
|
+
* @returns {JSX.Element} - The configured component with WebView.
|
79
|
+
*/
|
80
|
+
const WebViewComponent = params => {
|
81
|
+
const [webViewUrl, setWebViewUrl] = _react.default.useState(params.authUrl);
|
82
|
+
const [isCardReadingFinished, setCardReadingFinished] = _react.default.useState(false);
|
83
|
+
|
84
|
+
/*
|
85
|
+
* Once the reading of the card with NFC is finished, it is necessary
|
86
|
+
* to change the URL of the WebView by redirecting to the URL returned by
|
87
|
+
* CieManager to allow the user to continue with the consent authorization
|
88
|
+
* */
|
89
|
+
const continueWithUrl = callbackUrl => {
|
90
|
+
setCardReadingFinished(true);
|
91
|
+
setWebViewUrl(callbackUrl);
|
92
|
+
};
|
93
|
+
|
94
|
+
// This function is called from the injected javascript code (postMessage). Which receives the authentication URL
|
95
|
+
const handleMessage = async event => {
|
96
|
+
const cieAuthorizationUri = event.nativeEvent.data;
|
97
|
+
const startCie = _reactNative.Platform.select({
|
98
|
+
ios: _manager.startCieiOS,
|
99
|
+
default: _manager.startCieAndroid
|
100
|
+
});
|
101
|
+
await startCie(params.useUat, params.pin, params.onError, params.onEvent, cieAuthorizationUri, continueWithUrl);
|
102
|
+
};
|
103
|
+
|
104
|
+
//This function is called when authentication with CIE ends and the SP URL containing code and state is returned
|
105
|
+
const handleShouldStartLoading = (onSuccess, redirectUrl) => event => {
|
106
|
+
if (isCardReadingFinished && event.url.includes(redirectUrl)) {
|
107
|
+
onSuccess(event.url);
|
108
|
+
return false;
|
109
|
+
} else {
|
110
|
+
return true;
|
111
|
+
}
|
112
|
+
};
|
113
|
+
const handleOnLoadEnd = (onError, onCieEvent) => e => {
|
114
|
+
const eventTitle = e.nativeEvent.title.toLowerCase();
|
115
|
+
if (eventTitle === "pagina web non disponibile" ||
|
116
|
+
// On Android, if we attempt to access the idp URL twice,
|
117
|
+
// we are presented with an error page titled "ERROR".
|
118
|
+
eventTitle === "errore") {
|
119
|
+
handleOnError(onError)(new Error(eventTitle));
|
120
|
+
}
|
121
|
+
|
122
|
+
/* At the end of loading the page, if the card has already been read
|
123
|
+
* then the WebView has loaded the page to ask the user for consent,
|
124
|
+
* so send the completed event
|
125
|
+
* */
|
126
|
+
if (isCardReadingFinished) {
|
127
|
+
onCieEvent(CieEvent.completed);
|
128
|
+
}
|
129
|
+
};
|
130
|
+
const handleOnError = onError => e => {
|
131
|
+
const error = e;
|
132
|
+
const webViewError = e;
|
133
|
+
const webViewHttpError = e;
|
134
|
+
if (webViewHttpError.nativeEvent.statusCode) {
|
135
|
+
const {
|
136
|
+
description,
|
137
|
+
statusCode
|
138
|
+
} = webViewHttpError.nativeEvent;
|
139
|
+
onError(new _error.CieError({
|
140
|
+
message: `WebView http error: ${description} with status code: ${statusCode}`,
|
141
|
+
type: _error.CieErrorType.WEB_VIEW_ERROR
|
142
|
+
}));
|
143
|
+
} else if (webViewError.nativeEvent) {
|
144
|
+
const {
|
145
|
+
code,
|
146
|
+
description
|
147
|
+
} = webViewError.nativeEvent;
|
148
|
+
onError(new _error.CieError({
|
149
|
+
message: `WebView error: ${description} with code: ${code}`,
|
150
|
+
type: _error.CieErrorType.WEB_VIEW_ERROR
|
151
|
+
}));
|
152
|
+
} else if (error.message !== undefined) {
|
153
|
+
onError(new _error.CieError({
|
154
|
+
message: `${error.message}`,
|
155
|
+
type: _error.CieErrorType.WEB_VIEW_ERROR
|
156
|
+
}));
|
157
|
+
} else {
|
158
|
+
onError(new _error.CieError({
|
159
|
+
message: "An error occurred in the WebView",
|
160
|
+
type: _error.CieErrorType.WEB_VIEW_ERROR
|
161
|
+
}));
|
162
|
+
}
|
163
|
+
};
|
164
|
+
return /*#__PURE__*/_react.default.createElement(_reactNativeWebview.WebView, {
|
165
|
+
ref: webView,
|
166
|
+
userAgent: defaultUserAgent,
|
167
|
+
javaScriptEnabled: true,
|
168
|
+
source: {
|
169
|
+
uri: webViewUrl
|
170
|
+
},
|
171
|
+
onLoadEnd: handleOnLoadEnd(params.onError, params.onEvent),
|
172
|
+
onError: handleOnError(params.onError),
|
173
|
+
onHttpError: handleOnError(params.onError),
|
174
|
+
injectedJavaScript: injectedJavaScript,
|
175
|
+
onShouldStartLoadWithRequest: handleShouldStartLoading(params.onSuccess, params.redirectUrl),
|
176
|
+
onMessage: handleMessage
|
177
|
+
});
|
178
|
+
};
|
179
|
+
exports.WebViewComponent = WebViewComponent;
|
180
|
+
//# sourceMappingURL=component.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeWebview","_manager","_error","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","injectedJavaScript","CieEvent","exports","iOSUserAgent","defaultUserAgent","Platform","select","ios","undefined","webView","createRef","WebViewComponent","params","webViewUrl","setWebViewUrl","React","useState","authUrl","isCardReadingFinished","setCardReadingFinished","continueWithUrl","callbackUrl","handleMessage","event","cieAuthorizationUri","nativeEvent","data","startCie","startCieiOS","startCieAndroid","useUat","pin","onError","onEvent","handleShouldStartLoading","onSuccess","redirectUrl","url","includes","handleOnLoadEnd","onCieEvent","e","eventTitle","title","toLowerCase","handleOnError","Error","completed","error","webViewError","webViewHttpError","statusCode","description","CieError","message","type","CieErrorType","WEB_VIEW_ERROR","code","createElement","WebView","ref","userAgent","javaScriptEnabled","source","uri","onLoadEnd","onHttpError","onShouldStartLoadWithRequest","onMessage"],"sourceRoot":"../../../src","sources":["cie/component.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AASA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAAiD,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,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CwB,OAAO,CACL,IAAIqB,eAAQ,CAAC;QACXC,OAAO,EAAG,GAAEN,KAAK,CAACM,OAAQ,EAAC;QAC3BC,IAAI,EAAEC,mBAAY,CAACC;MACrB,CAAC,CACH,CAAC;IACH,CAAC,MAAM;MACLzB,OAAO,CACL,IAAIqB,eAAQ,CAAC;QACXC,OAAO,EAAE,kCAAkC;QAC3CC,IAAI,EAAEC,mBAAY,CAACC;MACrB,CAAC,CACH,CAAC;IACH;EACF,CAAC;EAEH,oBACEtF,MAAA,CAAAc,OAAA,CAAA0E,aAAA,CAACpF,mBAAA,CAAAqF,OAAO;IACNC,GAAG,EAAEpD,OAAQ;IACbqD,SAAS,EAAE1D,gBAAiB;IAC5B2D,iBAAiB,EAAE,IAAK;IACxBC,MAAM,EAAE;MAAEC,GAAG,EAAEpD;IAAW,CAAE;IAC5BqD,SAAS,EAAE3B,eAAe,CAAC3B,MAAM,CAACoB,OAAO,EAAEpB,MAAM,CAACqB,OAAO,CAAE;IAC3DD,OAAO,EAAEa,aAAa,CAACjC,MAAM,CAACoB,OAAO,CAAE;IACvCmC,WAAW,EAAEtB,aAAa,CAACjC,MAAM,CAACoB,OAAO,CAAE;IAC3ChC,kBAAkB,EAAEA,kBAAmB;IACvCoE,4BAA4B,EAAElC,wBAAwB,CACpDtB,MAAM,CAACuB,SAAS,EAChBvB,MAAM,CAACwB,WACT,CAAE;IACFiC,SAAS,EAAE/C;EAAc,CAC1B,CAAC;AAEN,CAAC;AAACpB,OAAA,CAAAS,gBAAA,GAAAA,gBAAA"}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.CieErrorType = exports.CieError = void 0;
|
7
|
+
let CieErrorType = /*#__PURE__*/function (CieErrorType) {
|
8
|
+
CieErrorType[CieErrorType["GENERIC"] = 0] = "GENERIC";
|
9
|
+
CieErrorType[CieErrorType["TAG_NOT_VALID"] = 1] = "TAG_NOT_VALID";
|
10
|
+
CieErrorType[CieErrorType["WEB_VIEW_ERROR"] = 2] = "WEB_VIEW_ERROR";
|
11
|
+
CieErrorType[CieErrorType["NFC_ERROR"] = 3] = "NFC_ERROR";
|
12
|
+
CieErrorType[CieErrorType["AUTHENTICATION_ERROR"] = 4] = "AUTHENTICATION_ERROR";
|
13
|
+
CieErrorType[CieErrorType["PIN_ERROR"] = 5] = "PIN_ERROR";
|
14
|
+
CieErrorType[CieErrorType["PIN_LOCKED"] = 6] = "PIN_LOCKED";
|
15
|
+
CieErrorType[CieErrorType["CERTIFICATE_ERROR"] = 7] = "CERTIFICATE_ERROR";
|
16
|
+
return CieErrorType;
|
17
|
+
}({});
|
18
|
+
exports.CieErrorType = CieErrorType;
|
19
|
+
class CieError extends Error {
|
20
|
+
constructor(options) {
|
21
|
+
super(options.message);
|
22
|
+
if (options.type) {
|
23
|
+
this.type = options.type;
|
24
|
+
} else {
|
25
|
+
this.type = CieErrorType.GENERIC;
|
26
|
+
}
|
27
|
+
if (this.type === CieErrorType.PIN_ERROR) {
|
28
|
+
this.attemptsLeft = options.attemptsLeft;
|
29
|
+
} else if (this.type === CieErrorType.PIN_LOCKED) {
|
30
|
+
this.attemptsLeft = 0;
|
31
|
+
}
|
32
|
+
this.name = this.constructor.name;
|
33
|
+
}
|
34
|
+
toString() {
|
35
|
+
return JSON.stringify({
|
36
|
+
name: this.name,
|
37
|
+
type: CieErrorType[this.type],
|
38
|
+
message: this.message,
|
39
|
+
attemptsLeft: this.attemptsLeft
|
40
|
+
});
|
41
|
+
}
|
42
|
+
}
|
43
|
+
exports.CieError = CieError;
|
44
|
+
//# sourceMappingURL=error.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["CieErrorType","exports","CieError","Error","constructor","options","message","type","GENERIC","PIN_ERROR","attemptsLeft","PIN_LOCKED","name","toString","JSON","stringify"],"sourceRoot":"../../../src","sources":["cie/error.ts"],"mappings":";;;;;;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
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "CieError", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _error.CieError;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
Object.defineProperty(exports, "CieErrorType", {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _error.CieErrorType;
|
16
|
+
}
|
17
|
+
});
|
18
|
+
Object.defineProperty(exports, "CieEvent", {
|
19
|
+
enumerable: true,
|
20
|
+
get: function () {
|
21
|
+
return _component.CieEvent;
|
22
|
+
}
|
23
|
+
});
|
24
|
+
Object.defineProperty(exports, "WebViewComponent", {
|
25
|
+
enumerable: true,
|
26
|
+
get: function () {
|
27
|
+
return _component.WebViewComponent;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
var _component = require("./component");
|
31
|
+
var _error = require("./error");
|
32
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_component","require","_error"],"sourceRoot":"../../../src","sources":["cie/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA"}
|
@@ -0,0 +1,142 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.startCieiOS = exports.startCieAndroid = void 0;
|
7
|
+
var _reactNativeCie = _interopRequireDefault(require("@pagopa/react-native-cie"));
|
8
|
+
var _reactNative = require("react-native");
|
9
|
+
var _component = require("./component");
|
10
|
+
var _error = require("./error");
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
12
|
+
const BASE_UAT_URL = "https://collaudo.idserver.servizicie.interno.gov.it/idp/";
|
13
|
+
const startCieAndroid = (useCieUat, ciePin, onError, onEvent, cieAuthorizationUri, continueWithUrl) => {
|
14
|
+
try {
|
15
|
+
_reactNativeCie.default.removeAllListeners();
|
16
|
+
_reactNativeCie.default.start().then(async () => {
|
17
|
+
_reactNativeCie.default.onEvent(handleCieEvent(onError, onEvent));
|
18
|
+
_reactNativeCie.default.onError(e => {
|
19
|
+
console.error(e);
|
20
|
+
return onError(new _error.CieError({
|
21
|
+
message: e.message
|
22
|
+
}));
|
23
|
+
});
|
24
|
+
_reactNativeCie.default.onSuccess(handleCieSuccess(continueWithUrl));
|
25
|
+
await _reactNativeCie.default.setPin(ciePin);
|
26
|
+
_reactNativeCie.default.setAuthenticationUrl(cieAuthorizationUri);
|
27
|
+
_reactNativeCie.default.enableLog(useCieUat);
|
28
|
+
_reactNativeCie.default.setCustomIdpUrl(useCieUat ? getCieUatEndpoint() : null);
|
29
|
+
await _reactNativeCie.default.startListeningNFC();
|
30
|
+
onEvent(_component.CieEvent.waiting_card);
|
31
|
+
}).catch(onError);
|
32
|
+
} catch (e) {
|
33
|
+
onError(new _error.CieError({
|
34
|
+
message: `Unable to start CIE NFC manager on Android: ${e}`,
|
35
|
+
type: _error.CieErrorType.NFC_ERROR
|
36
|
+
}));
|
37
|
+
}
|
38
|
+
};
|
39
|
+
exports.startCieAndroid = startCieAndroid;
|
40
|
+
const startCieiOS = async (useCieUat, ciePin, onError, onEvent, cieAuthorizationUri, continueWithUrl) => {
|
41
|
+
try {
|
42
|
+
_reactNativeCie.default.removeAllListeners();
|
43
|
+
_reactNativeCie.default.onEvent(handleCieEvent(onError, onEvent));
|
44
|
+
_reactNativeCie.default.onError(e => onError(new _error.CieError({
|
45
|
+
message: e.message
|
46
|
+
})));
|
47
|
+
_reactNativeCie.default.onSuccess(handleCieSuccess(continueWithUrl));
|
48
|
+
_reactNativeCie.default.enableLog(useCieUat);
|
49
|
+
_reactNativeCie.default.setCustomIdpUrl(useCieUat ? getCieUatEndpoint() : null);
|
50
|
+
await _reactNativeCie.default.setPin(ciePin);
|
51
|
+
_reactNativeCie.default.setAuthenticationUrl(cieAuthorizationUri);
|
52
|
+
_reactNativeCie.default.start().then(async () => {
|
53
|
+
await _reactNativeCie.default.startListeningNFC();
|
54
|
+
onEvent(_component.CieEvent.waiting_card);
|
55
|
+
}).catch(onError);
|
56
|
+
} catch (e) {
|
57
|
+
onError(new _error.CieError({
|
58
|
+
message: `Unable to start CIE NFC manager on iOS: ${e}`,
|
59
|
+
type: _error.CieErrorType.NFC_ERROR
|
60
|
+
}));
|
61
|
+
}
|
62
|
+
};
|
63
|
+
exports.startCieiOS = startCieiOS;
|
64
|
+
const handleCieEvent = (onError, onEvent) => event => {
|
65
|
+
switch (event.event) {
|
66
|
+
// Reading starts
|
67
|
+
case "ON_TAG_DISCOVERED":
|
68
|
+
onEvent(_component.CieEvent.reading);
|
69
|
+
break;
|
70
|
+
// "Function not supported" seems to be TAG_ERROR_NFC_NOT_SUPPORTED
|
71
|
+
// for the iOS SDK
|
72
|
+
case "Function not supported":
|
73
|
+
case "TAG_ERROR_NFC_NOT_SUPPORTED":
|
74
|
+
case "ON_TAG_DISCOVERED_NOT_CIE":
|
75
|
+
onError(new _error.CieError({
|
76
|
+
message: `Invalid CIE card: ${event.event}`,
|
77
|
+
type: _error.CieErrorType.TAG_NOT_VALID
|
78
|
+
}));
|
79
|
+
break;
|
80
|
+
case "AUTHENTICATION_ERROR":
|
81
|
+
case "ON_NO_INTERNET_CONNECTION":
|
82
|
+
onError(new _error.CieError({
|
83
|
+
message: `Authentication error or no internet connection`,
|
84
|
+
type: _error.CieErrorType.AUTHENTICATION_ERROR
|
85
|
+
}));
|
86
|
+
break;
|
87
|
+
case "EXTENDED_APDU_NOT_SUPPORTED":
|
88
|
+
onError(new _error.CieError({
|
89
|
+
message: `APDU not supported`,
|
90
|
+
type: _error.CieErrorType.NFC_ERROR
|
91
|
+
}));
|
92
|
+
break;
|
93
|
+
case "Transmission Error":
|
94
|
+
case "ON_TAG_LOST":
|
95
|
+
onError(new _error.CieError({
|
96
|
+
message: `Trasmission error`,
|
97
|
+
type: _error.CieErrorType.NFC_ERROR
|
98
|
+
}));
|
99
|
+
break;
|
100
|
+
|
101
|
+
// The card is temporarily locked. Unlock is available by CieID app
|
102
|
+
case "PIN Locked":
|
103
|
+
case "ON_CARD_PIN_LOCKED":
|
104
|
+
onError(new _error.CieError({
|
105
|
+
message: `PIN locked`,
|
106
|
+
type: _error.CieErrorType.PIN_LOCKED
|
107
|
+
}));
|
108
|
+
break;
|
109
|
+
case "ON_PIN_ERROR":
|
110
|
+
onError(new _error.CieError({
|
111
|
+
message: `PIN locked`,
|
112
|
+
type: _error.CieErrorType.PIN_ERROR,
|
113
|
+
attemptsLeft: event.attemptsLeft
|
114
|
+
}));
|
115
|
+
break;
|
116
|
+
|
117
|
+
// CIE is Expired or Revoked
|
118
|
+
case "CERTIFICATE_EXPIRED":
|
119
|
+
onError(new _error.CieError({
|
120
|
+
message: `Certificate expired`,
|
121
|
+
type: _error.CieErrorType.CERTIFICATE_ERROR
|
122
|
+
}));
|
123
|
+
break;
|
124
|
+
case "CERTIFICATE_REVOKED":
|
125
|
+
onError(new _error.CieError({
|
126
|
+
message: `Certificate revoked`,
|
127
|
+
type: _error.CieErrorType.CERTIFICATE_ERROR
|
128
|
+
}));
|
129
|
+
break;
|
130
|
+
default:
|
131
|
+
break;
|
132
|
+
}
|
133
|
+
};
|
134
|
+
const handleCieSuccess = continueWithUrl => url => {
|
135
|
+
continueWithUrl(decodeURIComponent(url));
|
136
|
+
};
|
137
|
+
const getCieUatEndpoint = () => _reactNative.Platform.select({
|
138
|
+
ios: `${BASE_UAT_URL}Authn/SSL/Login2`,
|
139
|
+
android: BASE_UAT_URL,
|
140
|
+
default: null
|
141
|
+
});
|
142
|
+
//# sourceMappingURL=manager.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_reactNativeCie","_interopRequireDefault","require","_reactNative","_component","_error","obj","__esModule","default","BASE_UAT_URL","startCieAndroid","useCieUat","ciePin","onError","onEvent","cieAuthorizationUri","continueWithUrl","cieManager","removeAllListeners","start","then","handleCieEvent","e","console","error","CieError","message","onSuccess","handleCieSuccess","setPin","setAuthenticationUrl","enableLog","setCustomIdpUrl","getCieUatEndpoint","startListeningNFC","CieEvent","waiting_card","catch","type","CieErrorType","NFC_ERROR","exports","startCieiOS","event","reading","TAG_NOT_VALID","AUTHENTICATION_ERROR","PIN_LOCKED","PIN_ERROR","attemptsLeft","CERTIFICATE_ERROR","url","decodeURIComponent","Platform","select","ios","android"],"sourceRoot":"../../../src","sources":["cie/manager.ts"],"mappings":";;;;;;AAAA,IAAAA,eAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,UAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAAiD,SAAAD,uBAAAK,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAEjD,MAAMG,YAAY,GAAG,0DAA0D;AAIxE,MAAMC,eAAe,GAAGA,CAC7BC,SAAkB,EAClBC,MAAc,EACdC,OAAgB,EAChBC,OAAmB,EACnBC,mBAA2B,EAC3BC,eAAgC,KAC7B;EACH,IAAI;IACFC,uBAAU,CAACC,kBAAkB,CAAC,CAAC;IAC/BD,uBAAU,CACPE,KAAK,CAAC,CAAC,CACPC,IAAI,CAAC,YAAY;MAChBH,uBAAU,CAACH,OAAO,CAACO,cAAc,CAACR,OAAO,EAAEC,OAAO,CAAC,CAAC;MACpDG,uBAAU,CAACJ,OAAO,CAAES,CAAQ,IAAK;QAC/BC,OAAO,CAACC,KAAK,CAACF,CAAC,CAAC;QAChB,OAAOT,OAAO,CAAC,IAAIY,eAAQ,CAAC;UAAEC,OAAO,EAAEJ,CAAC,CAACI;QAAQ,CAAC,CAAC,CAAC;MACtD,CAAC,CAAC;MACFT,uBAAU,CAACU,SAAS,CAACC,gBAAgB,CAACZ,eAAe,CAAC,CA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
} = context;
|
28
28
|
return (0, _walletProvider.createApiClient)((method, url, params) => appFetch(url, {
|
29
29
|
method,
|
30
|
-
body: params ? JSON.stringify(params.body) : undefined
|
30
|
+
body: params ? JSON.stringify(params.body) : undefined,
|
31
|
+
headers: {
|
32
|
+
"Content-Type": "application/json"
|
33
|
+
}
|
31
34
|
}).then(validateResponse).then(res => {
|
32
35
|
const contentType = res.headers.get("content-type");
|
33
|
-
if (contentType
|
36
|
+
if (contentType !== null && contentType !== void 0 && contentType.includes("application/json")) {
|
34
37
|
return res.json();
|
35
38
|
}
|
36
39
|
return res.text();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_errors","require","_walletProvider","validateResponse","response","ok","problemDetail","ProblemDetail","parse","json","title","WalletProviderResponseError","type","detail","status","getWalletProviderClient","context","walletProviderBaseUrl","appFetch","fetch","createWalletProviderApiClient","method","url","params","body","JSON","stringify","undefined","then","res","contentType","
|
1
|
+
{"version":3,"names":["_errors","require","_walletProvider","validateResponse","response","ok","problemDetail","ProblemDetail","parse","json","title","WalletProviderResponseError","type","detail","status","getWalletProviderClient","context","walletProviderBaseUrl","appFetch","fetch","createWalletProviderApiClient","method","url","params","body","JSON","stringify","undefined","headers","then","res","contentType","get","includes","text","exports"],"sourceRoot":"../../../src","sources":["client/index.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAQA,MAAME,gBAAgB,GAAG,MAAOC,QAAkB,IAAK;EACrD,IAAI,CAACA,QAAQ,CAACC,EAAE,EAAE;IAChB,IAAIC,aAA4B,GAAG,CAAC,CAAC;IACrC,IAAI;MACFA,aAAa,GAAGC,6BAAa,CAACC,KAAK,CAAC,MAAMJ,QAAQ,CAACK,IAAI,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC,MAAM;MACNH,aAAa,GAAG;QACdI,KAAK,EAAE;MACT,CAAC;IACH;IAEA,MAAM,IAAIC,mCAA2B,CACnCL,aAAa,CAACI,KAAK,IAAI,uCAAuC,EAC9DJ,aAAa,CAACM,IAAI,EAClBN,aAAa,CAACO,MAAM,EACpBT,QAAQ,CAACU,MACX,CAAC;EACH;EACA,OAAOV,QAAQ;AACjB,CAAC;AAEM,MAAMW,uBAAuB,GAAIC,OAGvC,IAAK;EACJ,MAAM;IAAEC,qBAAqB;IAAEC,QAAQ,GAAGC;EAAM,CAAC,GAAGH,OAAO;EAE3D,OAAO,IAAAI,+BAA6B,EAClC,CAACC,MAAM,EAAEC,GAAG,EAAEC,MAAM,KAClBL,QAAQ,CAACI,GAAG,EAAE;IACZD,MAAM;IACNG,IAAI,EAAED,MAAM,GAAGE,IAAI,CAACC,SAAS,CAACH,MAAM,CAACC,IAAI,CAAC,GAAGG,SAAS;IACtDC,OAAO,EAAE;MACP,cAAc,EAAE;IAClB;EACF,CAAC,CAAC,CACCC,IAAI,CAAC1B,gBAAgB,CAAC,CACtB0B,IAAI,CAAEC,GAAG,IAAK;IACb,MAAMC,WAAW,GAAGD,GAAG,CAACF,OAAO,CAACI,GAAG,CAAC,cAAc,CAAC;IACnD,IAAID,WAAW,aAAXA,WAAW,eAAXA,WAAW,CAAEE,QAAQ,CAAC,kBAAkB,CAAC,EAAE;MAC7C,OAAOH,GAAG,CAACrB,IAAI,CAAC,CAAC;IACnB;IACA,OAAOqB,GAAG,CAACI,IAAI,CAAC,CAAC;EACnB,CAAC,CAAC,EACNjB,qBACF,CAAC;AACH,CAAC;AAACkB,OAAA,CAAApB,uBAAA,GAAAA,uBAAA"}
|
@@ -3,12 +3,17 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.completeUserAuthorizationWithQueryMode = exports.completeUserAuthorizationWithFormPostJwtMode = void 0;
|
6
|
+
exports.parseAuthroizationResponse = exports.getRequestedCredentialToBePresented = exports.completeUserAuthorizationWithQueryMode = exports.completeUserAuthorizationWithFormPostJwtMode = void 0;
|
7
7
|
var _auth = require("../../utils/auth");
|
8
8
|
var _misc = require("../../utils/misc");
|
9
9
|
var _parseUrl = _interopRequireDefault(require("parse-url"));
|
10
10
|
var _errors = require("../../utils/errors");
|
11
11
|
var _reactNative = require("react-native");
|
12
|
+
var _ioReactNativeJwt = require("@pagopa/io-react-native-jwt");
|
13
|
+
var _types = require("../presentation/types");
|
14
|
+
var _reactNativeUuid = _interopRequireDefault(require("react-native-uuid"));
|
15
|
+
var _types2 = require("./types");
|
16
|
+
var _decoder = require("../../../src/utils/decoder");
|
12
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
18
|
/**
|
14
19
|
* The interface of the phase to complete User authorization via strong identification when the response mode is "query" and the request credential is a PersonIdentificationData.
|
@@ -32,11 +37,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
32
37
|
* @returns the authorization response which contains code, state and iss
|
33
38
|
*/
|
34
39
|
const completeUserAuthorizationWithQueryMode = async (issuerRequestUri, clientId, issuerConf, idpHint, redirectUri, authorizationContext) => {
|
35
|
-
/**
|
36
|
-
* Starts the authorization flow which dependes on the response mode and the request credential.
|
37
|
-
* If the response mode is "query" the authorization flow is handled differently via the authorization context which opens an in-app browser capable of catching the redirectSchema.
|
38
|
-
* The form_post.jwt mode is not currently supported.
|
39
|
-
*/
|
40
40
|
const authzRequestEndpoint = issuerConf.oauth_authorization_server.authorization_endpoint;
|
41
41
|
const params = new URLSearchParams({
|
42
42
|
client_id: clientId,
|
@@ -72,23 +72,148 @@ const completeUserAuthorizationWithQueryMode = async (issuerRequestUri, clientId
|
|
72
72
|
throw new _errors.AuthorizationError("Invalid authentication redirect url");
|
73
73
|
}
|
74
74
|
}
|
75
|
-
const
|
76
|
-
|
77
|
-
|
78
|
-
const authErr = _auth.AuthorizationErrorShape.safeParse(urlParse.query);
|
79
|
-
if (!authErr.success) {
|
80
|
-
throw new _errors.AuthorizationError(authRes.error.message); // an error occured while parsing the result and the error
|
81
|
-
}
|
75
|
+
const query = (0, _parseUrl.default)(authRedirectUrl).query;
|
76
|
+
return parseAuthroizationResponse(query);
|
77
|
+
};
|
82
78
|
|
83
|
-
|
79
|
+
/**
|
80
|
+
* WARNING: This function must be called after {@link startUserAuthorization}. The next function to be called is {@link completeUserAuthorizationWithFormPostJwtMode}.
|
81
|
+
* The interface of the phase to complete User authorization via presentation of existing credentials when the response mode is "form_post.jwt".
|
82
|
+
* It is used as a first step to complete the user authorization by obtaining the requested credential to be presented from the authorization server.
|
83
|
+
* The information is obtained by performing a GET request to the authorization endpoint with request_uri and client_id parameters.
|
84
|
+
* @param issuerRequestUri the URI of the issuer where the request is sent
|
85
|
+
* @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
|
86
|
+
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
|
87
|
+
* @param appFetch (optional) fetch api implementation. Default: built-in fetch
|
88
|
+
* @throws {ValidationFailed} if an error while validating the response
|
89
|
+
* @returns the request object which contains the credential to be presented in order to obtain the requested credential
|
90
|
+
*/
|
91
|
+
exports.completeUserAuthorizationWithQueryMode = completeUserAuthorizationWithQueryMode;
|
92
|
+
const getRequestedCredentialToBePresented = async function (issuerRequestUri, clientId, issuerConf) {
|
93
|
+
let appFetch = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : fetch;
|
94
|
+
const authzRequestEndpoint = issuerConf.oauth_authorization_server.authorization_endpoint;
|
95
|
+
const params = new URLSearchParams({
|
96
|
+
client_id: clientId,
|
97
|
+
request_uri: issuerRequestUri
|
98
|
+
});
|
99
|
+
const requestObject = await appFetch(`${authzRequestEndpoint}?${params.toString()}`, {
|
100
|
+
method: "GET"
|
101
|
+
}).then((0, _misc.hasStatus)(200)).then(res => res.text()).then(jws => (0, _ioReactNativeJwt.decode)(jws)).then(reqObj => _types.RequestObject.safeParse(reqObj.payload));
|
102
|
+
if (!requestObject.success) {
|
103
|
+
throw new _errors.ValidationFailed("Request Object validation failed", requestObject.error.message);
|
84
104
|
}
|
85
|
-
return
|
105
|
+
return requestObject.data;
|
86
106
|
};
|
87
107
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
108
|
+
/**
|
109
|
+
* WARNING: This function must be called after {@link startUserAuthorization}. The next function to be called is {@link completeUserAuthorizationWithFormPostJwtMode}.
|
110
|
+
* The interface of the phase to complete User authorization via presentation of existing credentials when the response mode is "form_post.jwt".
|
111
|
+
* It is used as a first step to complete the user authorization by obtaining the requested credential to be presented from the authorization server.
|
112
|
+
* The information is obtained by performing a GET request to the authorization endpoint with request_uri and client_id parameters.
|
113
|
+
* @param issuerRequestUri the URI of the issuer where the request is sent
|
114
|
+
* @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
|
115
|
+
* @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
|
116
|
+
* @param context.walletInstanceAccestation the Wallet Instance's attestation to be presented
|
117
|
+
* @param context.pid the PID to be presented
|
118
|
+
* @param context.wiaCryptoContext The Wallet Instance's crypto context associated with the walletInstanceAttestation parameter
|
119
|
+
* @param context.pidCryptoContext The PID crypto context associated with the pid parameter
|
120
|
+
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
121
|
+
* @throws {ValidationFailed} if an error while validating the response
|
122
|
+
* @returns the authorization response which contains code, state and iss
|
123
|
+
*/
|
124
|
+
exports.getRequestedCredentialToBePresented = getRequestedCredentialToBePresented;
|
125
|
+
const completeUserAuthorizationWithFormPostJwtMode = async (requestObject, ctx) => {
|
126
|
+
const {
|
127
|
+
wiaCryptoContext,
|
128
|
+
pidCryptoContext,
|
129
|
+
pid,
|
130
|
+
walletInstanceAttestation,
|
131
|
+
appFetch = fetch
|
132
|
+
} = ctx;
|
133
|
+
const wiaWpToken = await new _ioReactNativeJwt.SignJWT(wiaCryptoContext).setProtectedHeader({
|
134
|
+
alg: "ES256",
|
135
|
+
typ: "JWT"
|
136
|
+
}).setPayload({
|
137
|
+
vp: walletInstanceAttestation,
|
138
|
+
jti: _reactNativeUuid.default.v4().toString(),
|
139
|
+
nonce: requestObject.nonce
|
140
|
+
}).setIssuedAt().setExpirationTime("5m").setAudience(requestObject.response_uri).sign();
|
141
|
+
const pidWpToken = await new _ioReactNativeJwt.SignJWT(pidCryptoContext).setProtectedHeader({
|
142
|
+
alg: "ES256",
|
143
|
+
typ: "JWT"
|
144
|
+
}).setPayload({
|
145
|
+
vp: pid,
|
146
|
+
jti: _reactNativeUuid.default.v4().toString(),
|
147
|
+
nonce: requestObject.nonce
|
148
|
+
}).setIssuedAt().setExpirationTime("5m").setAudience(requestObject.response_uri).sign();
|
149
|
+
|
150
|
+
/* The path parameter refers to the vp_token variable of the authzResponsePayload and must point to the plain credential which
|
151
|
+
* is cointaned in the `vp` property of the signed jwt token payload
|
152
|
+
*/
|
153
|
+
const presentationSubmission = {
|
154
|
+
definition_id: `${_reactNativeUuid.default.v4()}`,
|
155
|
+
id: `${_reactNativeUuid.default.v4()}`,
|
156
|
+
descriptor_map: [{
|
157
|
+
id: "PersonIdentificationData",
|
158
|
+
path: "$.vp_token[0].vp",
|
159
|
+
format: "vc+sd-jwt"
|
160
|
+
}, {
|
161
|
+
id: "WalletAttestation",
|
162
|
+
path: "$.vp_token[1].vp",
|
163
|
+
format: "jwt"
|
164
|
+
}]
|
165
|
+
};
|
166
|
+
const authzResponsePayload = (0, _ioReactNativeJwt.encodeBase64)(JSON.stringify({
|
167
|
+
state: requestObject.state,
|
168
|
+
presentation_submission: presentationSubmission,
|
169
|
+
vp_token: [pidWpToken, wiaWpToken]
|
170
|
+
}));
|
171
|
+
|
172
|
+
// Note: according to the spec, the response should be encrypted with the public key of the RP however this is not implemented yet
|
173
|
+
// https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-response
|
174
|
+
// const rsaPublicJwk = chooseRSAPublicKeyToEncrypt(rpConf);
|
175
|
+
// const encrypted = await new EncryptJwe(authzResponsePayload, {
|
176
|
+
// alg: "RSA-OAEP-256",
|
177
|
+
// enc: "A256CBC-HS512",
|
178
|
+
// kid: rsaPublicJwk.kid,
|
179
|
+
// }).encrypt(rsaPublicJwk);
|
180
|
+
|
181
|
+
const body = new URLSearchParams({
|
182
|
+
response: authzResponsePayload
|
183
|
+
}).toString();
|
184
|
+
const resUriRes = await appFetch(requestObject.response_uri, {
|
185
|
+
method: "POST",
|
186
|
+
headers: {
|
187
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
188
|
+
},
|
189
|
+
body
|
190
|
+
}).then((0, _misc.hasStatus)(200)).then(reqUri => reqUri.json());
|
191
|
+
const responseUri = _types2.ResponseUriResultShape.safeParse(resUriRes);
|
192
|
+
if (!responseUri.success) {
|
193
|
+
throw new _errors.ValidationFailed("Response Uri validation failed", responseUri.error.message);
|
194
|
+
}
|
195
|
+
return await appFetch(responseUri.data.redirect_uri).then((0, _misc.hasStatus)(200)).then(res => res.text()).then(_decoder.getJwtFromFormPost).then(cbRes => parseAuthroizationResponse(cbRes.decodedJwt.payload));
|
92
196
|
};
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Parse the authorization response and return the result which contains code, state and iss.
|
200
|
+
* @throws {AuthorizationError} if an error occurs during the parsing process
|
201
|
+
* @throws {AuthorizationIdpError} if an error occurs during the parsing process and the error is related to the IDP
|
202
|
+
* @param authRes the authorization response to be parsed
|
203
|
+
* @returns the authorization result which contains code, state and iss
|
204
|
+
*/
|
93
205
|
exports.completeUserAuthorizationWithFormPostJwtMode = completeUserAuthorizationWithFormPostJwtMode;
|
206
|
+
const parseAuthroizationResponse = authRes => {
|
207
|
+
const authResParsed = _auth.AuthorizationResultShape.safeParse(authRes);
|
208
|
+
if (!authResParsed.success) {
|
209
|
+
const authErr = _auth.AuthorizationErrorShape.safeParse(authRes);
|
210
|
+
if (!authErr.success) {
|
211
|
+
throw new _errors.AuthorizationError(authResParsed.error.message); // an error occured while parsing the result and the error
|
212
|
+
}
|
213
|
+
|
214
|
+
throw new _errors.AuthorizationIdpError(authErr.data.error, authErr.data.error_description);
|
215
|
+
}
|
216
|
+
return authResParsed.data;
|
217
|
+
};
|
218
|
+
exports.parseAuthroizationResponse = parseAuthroizationResponse;
|
94
219
|
//# sourceMappingURL=04-complete-user-authorization.js.map
|